2 * $Id: render.c,v 1.24 2007-02-11 10:09:32 nkeynes Exp $
4 * PVR2 Renderer support. This part is primarily
6 * Copyright (c) 2005 Nathan Keynes.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 #include "pvr2/pvr2.h"
23 int pvr2_render_font_list = -1;
24 int pvr2_render_trace = 0;
26 int glPrintf( int x, int y, const char *fmt, ... )
28 va_list ap; /* our argument pointer */
31 if (fmt == NULL) /* if there is no string to draw do nothing */
34 len = vsnprintf(buf, sizeof(buf), fmt, ap);
38 glPushAttrib(GL_LIST_BIT);
39 glDisable( GL_DEPTH_TEST );
40 glDisable( GL_BLEND );
41 glDisable( GL_TEXTURE_2D );
42 glDisable( GL_ALPHA_TEST );
43 glDisable( GL_CULL_FACE );
44 glListBase(pvr2_render_font_list - 32);
45 glColor3f( 1.0, 1.0, 1.0 );
46 glRasterPos2i( x, y );
47 glCallLists(len, GL_UNSIGNED_BYTE, buf);
53 void glDrawGrid( int width, int height )
56 glDisable( GL_DEPTH_TEST );
60 glColor4f( 1.0, 1.0, 1.0, 1.0 );
61 for( i=32; i<width; i+=32 ) {
62 glVertex3f( i, 0.0, 3.0 );
63 glVertex3f( i,height-1, 3.0 );
66 for( i=32; i<height; i+=32 ) {
67 glVertex3f( 0.0, i, 3.0 );
68 glVertex3f( width, i, 3.0 );
75 * Prepare the OpenGL context to receive instructions for a new frame.
77 static void pvr2_render_prepare_context( render_buffer_t buffer,
78 float bgplanez, float nearz )
80 /* Select and initialize the render context */
81 display_driver->set_render_target(buffer);
83 if( pvr2_render_font_list == -1 ) {
84 pvr2_render_font_list = video_glx_load_font( "-*-helvetica-*-r-normal--16-*-*-*-p-*-iso8859-1");
87 pvr2_check_palette_changed();
89 /* Setup the display model */
90 glShadeModel(GL_SMOOTH);
91 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
92 glMatrixMode(GL_PROJECTION);
94 glOrtho( 0, buffer->width, buffer->height, 0, -bgplanez, -nearz );
95 glMatrixMode(GL_MODELVIEW);
97 glCullFace( GL_BACK );
100 /* Clear out the buffers */
101 glDisable( GL_SCISSOR_TEST );
102 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
104 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
108 * Render a complete scene into the OpenGL back buffer.
109 * Note: this will probably need to be broken up eventually once timings are
112 void pvr2_render_scene( render_buffer_t buffer )
114 struct tile_descriptor *tile_desc =
115 (struct tile_descriptor *)mem_get_region(PVR2_RAM_BASE + MMIO_READ( PVR2, RENDER_TILEBASE ));
117 float bgplanez = 1/MMIO_READF( PVR2, RENDER_FARCLIP );
118 pvr2_render_prepare_context( buffer, bgplanez, 0 );
120 int clip_x = MMIO_READ( PVR2, RENDER_HCLIP ) & 0x03FF;
121 int clip_y = MMIO_READ( PVR2, RENDER_VCLIP ) & 0x03FF;
122 int clip_width = ((MMIO_READ( PVR2, RENDER_HCLIP ) >> 16) & 0x03FF) - clip_x + 1;
123 int clip_height= ((MMIO_READ( PVR2, RENDER_VCLIP ) >> 16) & 0x03FF) - clip_y + 1;
125 /* Fog setup goes here? */
127 /* Render the background plane */
129 uint32_t bgplane_mode = MMIO_READ(PVR2, RENDER_BGPLANE);
130 uint32_t *display_list =
131 (uint32_t *)mem_get_region(PVR2_RAM_BASE + MMIO_READ( PVR2, RENDER_POLYBASE ));
133 uint32_t *bgplane = display_list + (((bgplane_mode & 0x00FFFFFF)) >> 3) ;
134 render_backplane( bgplane, buffer->width, buffer->height, bgplane_mode );
136 pvr2_render_tilebuffer( buffer->width, buffer->height, clip_x, clip_y,
137 clip_x + clip_width, clip_y + clip_height );
139 DEBUG( "Rendered frame %d to %08X", pvr2_get_frame_count(), buffer->address );
.