Search
lxdream.org :: lxdream/src/pvr2/render.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/render.c
changeset 352:f0df7a6d4703
prev338:8c68d9097846
next429:e581b90c3fb3
author nkeynes
date Sun Feb 11 10:09:32 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Bug 27: Implement opengl framebuffer objects
Rewrite much of the final video output stage. Now uses generic "render
buffers", implemented on GL using framebuffer objects + textures.
file annotate diff log raw
nkeynes@100
     1
/**
nkeynes@352
     2
 * $Id: render.c,v 1.24 2007-02-11 10:09:32 nkeynes Exp $
nkeynes@100
     3
 *
nkeynes@189
     4
 * PVR2 Renderer support. This part is primarily
nkeynes@100
     5
 *
nkeynes@100
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@100
     7
 *
nkeynes@100
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@100
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@100
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@100
    11
 * (at your option) any later version.
nkeynes@100
    12
 *
nkeynes@100
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@100
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@100
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@100
    16
 * GNU General Public License for more details.
nkeynes@100
    17
 */
nkeynes@100
    18
nkeynes@100
    19
#include "pvr2/pvr2.h"
nkeynes@100
    20
#include "asic.h"
nkeynes@103
    21
nkeynes@103
    22
nkeynes@108
    23
int pvr2_render_font_list = -1;
nkeynes@132
    24
int pvr2_render_trace = 0;
nkeynes@108
    25
nkeynes@132
    26
int glPrintf( int x, int y, const char *fmt, ... )
nkeynes@108
    27
{
nkeynes@108
    28
    va_list ap;     /* our argument pointer */
nkeynes@108
    29
    char buf[256];
nkeynes@108
    30
    int len;
nkeynes@108
    31
    if (fmt == NULL)    /* if there is no string to draw do nothing */
nkeynes@108
    32
        return;
nkeynes@108
    33
    va_start(ap, fmt); 
nkeynes@108
    34
    len = vsnprintf(buf, sizeof(buf), fmt, ap);
nkeynes@108
    35
    va_end(ap);
nkeynes@108
    36
nkeynes@108
    37
nkeynes@108
    38
    glPushAttrib(GL_LIST_BIT);
nkeynes@132
    39
    glDisable( GL_DEPTH_TEST );
nkeynes@132
    40
    glDisable( GL_BLEND );
nkeynes@132
    41
    glDisable( GL_TEXTURE_2D );
nkeynes@132
    42
    glDisable( GL_ALPHA_TEST );
nkeynes@189
    43
    glDisable( GL_CULL_FACE );
nkeynes@108
    44
    glListBase(pvr2_render_font_list - 32);
nkeynes@132
    45
    glColor3f( 1.0, 1.0, 1.0 );
nkeynes@132
    46
    glRasterPos2i( x, y );
nkeynes@108
    47
    glCallLists(len, GL_UNSIGNED_BYTE, buf);
nkeynes@108
    48
    glPopAttrib();
nkeynes@108
    49
nkeynes@108
    50
    return len;
nkeynes@108
    51
}
nkeynes@108
    52
nkeynes@189
    53
void glDrawGrid( int width, int height )
nkeynes@189
    54
{
nkeynes@189
    55
    int i;
nkeynes@189
    56
    glDisable( GL_DEPTH_TEST );
nkeynes@189
    57
    glLineWidth(1);
nkeynes@189
    58
    
nkeynes@189
    59
    glBegin( GL_LINES );
nkeynes@189
    60
    glColor4f( 1.0, 1.0, 1.0, 1.0 );
nkeynes@189
    61
    for( i=32; i<width; i+=32 ) {
nkeynes@189
    62
	glVertex3f( i, 0.0, 3.0 );
nkeynes@189
    63
	glVertex3f( i,height-1, 3.0 );
nkeynes@189
    64
    }
nkeynes@189
    65
nkeynes@189
    66
    for( i=32; i<height; i+=32 ) {
nkeynes@189
    67
	glVertex3f( 0.0, i, 3.0 );
nkeynes@189
    68
	glVertex3f( width, i, 3.0 );
nkeynes@189
    69
    }
nkeynes@189
    70
    glEnd();
nkeynes@189
    71
	
nkeynes@189
    72
}
nkeynes@189
    73
nkeynes@103
    74
/**
nkeynes@103
    75
 * Prepare the OpenGL context to receive instructions for a new frame.
nkeynes@103
    76
 */
nkeynes@352
    77
static void pvr2_render_prepare_context( render_buffer_t buffer,
nkeynes@352
    78
					 float bgplanez, float nearz ) 
nkeynes@103
    79
{
nkeynes@103
    80
    /* Select and initialize the render context */
nkeynes@352
    81
    display_driver->set_render_target(buffer);
nkeynes@103
    82
nkeynes@132
    83
    if( pvr2_render_font_list == -1 ) {
nkeynes@132
    84
	pvr2_render_font_list = video_glx_load_font( "-*-helvetica-*-r-normal--16-*-*-*-p-*-iso8859-1");
nkeynes@132
    85
    }
nkeynes@132
    86
nkeynes@337
    87
    pvr2_check_palette_changed();
nkeynes@337
    88
nkeynes@103
    89
    /* Setup the display model */
nkeynes@103
    90
    glShadeModel(GL_SMOOTH);
nkeynes@103
    91
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
nkeynes@103
    92
    glMatrixMode(GL_PROJECTION);
nkeynes@103
    93
    glLoadIdentity();
nkeynes@352
    94
    glOrtho( 0, buffer->width, buffer->height, 0, -bgplanez, -nearz );
nkeynes@103
    95
    glMatrixMode(GL_MODELVIEW);
nkeynes@103
    96
    glLoadIdentity();
nkeynes@108
    97
    glCullFace( GL_BACK );
nkeynes@308
    98
    glEnable( GL_BLEND );
nkeynes@103
    99
nkeynes@103
   100
    /* Clear out the buffers */
nkeynes@189
   101
    glDisable( GL_SCISSOR_TEST );
nkeynes@103
   102
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
nkeynes@299
   103
    glClearDepth(0);
nkeynes@103
   104
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
nkeynes@103
   105
}
nkeynes@103
   106
nkeynes@128
   107
/**
nkeynes@103
   108
 * Render a complete scene into the OpenGL back buffer.
nkeynes@103
   109
 * Note: this will probably need to be broken up eventually once timings are
nkeynes@100
   110
 * determined.
nkeynes@100
   111
 */
nkeynes@352
   112
void pvr2_render_scene( render_buffer_t buffer )
nkeynes@100
   113
{
nkeynes@103
   114
    struct tile_descriptor *tile_desc =
nkeynes@191
   115
	(struct tile_descriptor *)mem_get_region(PVR2_RAM_BASE + MMIO_READ( PVR2, RENDER_TILEBASE ));
nkeynes@100
   116
nkeynes@331
   117
    float bgplanez = 1/MMIO_READF( PVR2, RENDER_FARCLIP );
nkeynes@352
   118
    pvr2_render_prepare_context( buffer, bgplanez, 0 );
nkeynes@103
   119
nkeynes@191
   120
    int clip_x = MMIO_READ( PVR2, RENDER_HCLIP ) & 0x03FF;
nkeynes@191
   121
    int clip_y = MMIO_READ( PVR2, RENDER_VCLIP ) & 0x03FF;
nkeynes@191
   122
    int clip_width = ((MMIO_READ( PVR2, RENDER_HCLIP ) >> 16) & 0x03FF) - clip_x + 1;
nkeynes@191
   123
    int clip_height= ((MMIO_READ( PVR2, RENDER_VCLIP ) >> 16) & 0x03FF) - clip_y + 1;
nkeynes@103
   124
nkeynes@352
   125
    /* Fog setup goes here? */
nkeynes@103
   126
nkeynes@128
   127
    /* Render the background plane */
nkeynes@352
   128
nkeynes@191
   129
    uint32_t bgplane_mode = MMIO_READ(PVR2, RENDER_BGPLANE);
nkeynes@189
   130
    uint32_t *display_list = 
nkeynes@191
   131
	(uint32_t *)mem_get_region(PVR2_RAM_BASE + MMIO_READ( PVR2, RENDER_POLYBASE ));
nkeynes@189
   132
nkeynes@189
   133
    uint32_t *bgplane = display_list + (((bgplane_mode & 0x00FFFFFF)) >> 3) ;
nkeynes@352
   134
    render_backplane( bgplane, buffer->width, buffer->height, bgplane_mode );
nkeynes@352
   135
    
nkeynes@352
   136
    pvr2_render_tilebuffer( buffer->width, buffer->height, clip_x, clip_y, 
nkeynes@189
   137
			    clip_x + clip_width, clip_y + clip_height );
nkeynes@352
   138
    
nkeynes@352
   139
    DEBUG( "Rendered frame %d to %08X", pvr2_get_frame_count(), buffer->address );
nkeynes@100
   140
}
.