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.
21 #include "pvr2/pvr2.h"
25 int pvr2_render_trace = 0;
28 int pvr2_render_font_list = -1;
29 int glPrintf( int x, int y, const char *fmt, ... )
31 va_list ap; /* our argument pointer */
34 if (fmt == NULL) /* if there is no string to draw do nothing */
37 len = vsnprintf(buf, sizeof(buf), fmt, ap);
41 glPushAttrib(GL_LIST_BIT);
42 glDisable( GL_DEPTH_TEST );
43 glDisable( GL_BLEND );
44 glDisable( GL_TEXTURE_2D );
45 glDisable( GL_ALPHA_TEST );
46 glDisable( GL_CULL_FACE );
47 glListBase(pvr2_render_font_list - 32);
48 glColor3f( 1.0, 1.0, 1.0 );
49 glRasterPos2i( x, y );
50 glCallLists(len, GL_UNSIGNED_BYTE, buf);
57 void glDrawGrid( int width, int height )
60 glDisable( GL_DEPTH_TEST );
64 glColor4f( 1.0, 1.0, 1.0, 1.0 );
65 for( i=32; i<width; i+=32 ) {
66 glVertex3f( i, 0.0, 3.0 );
67 glVertex3f( i,height-1, 3.0 );
70 for( i=32; i<height; i+=32 ) {
71 glVertex3f( 0.0, i, 3.0 );
72 glVertex3f( width, i, 3.0 );
79 * Prepare the OpenGL context to receive instructions for a new frame.
81 static void pvr2_render_prepare_context( render_buffer_t buffer,
82 float bgplanez, float nearz )
84 /* Select and initialize the render context */
85 display_driver->set_render_target(buffer);
87 if( pvr2_render_font_list == -1 ) {
88 pvr2_render_font_list = video_glx_load_font( "-*-helvetica-*-r-normal--16-*-*-*-p-*-iso8859-1");
91 pvr2_check_palette_changed();
93 /* Setup the display model */
94 glShadeModel(GL_SMOOTH);
95 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
96 glMatrixMode(GL_PROJECTION);
98 glOrtho( 0, buffer->width, buffer->height, 0, -bgplanez, -nearz );
99 glMatrixMode(GL_MODELVIEW);
101 glCullFace( GL_BACK );
102 glEnable( GL_BLEND );
104 /* Clear out the buffers */
105 glDisable( GL_SCISSOR_TEST );
106 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
108 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
109 glEnableClientState( GL_COLOR_ARRAY );
110 glEnableClientState( GL_VERTEX_ARRAY );
114 * Render a complete scene into the OpenGL back buffer.
115 * Note: this will probably need to be broken up eventually once timings are
118 void pvr2_render_scene( render_buffer_t buffer )
120 struct timeval tva, tvb;
122 gettimeofday(&tva, NULL);
124 float bgplanez = 1/MMIO_READF( PVR2, RENDER_FARCLIP );
125 pvr2_render_prepare_context( buffer, bgplanez, 0 );
127 int clip_x = MMIO_READ( PVR2, RENDER_HCLIP ) & 0x03FF;
128 int clip_y = MMIO_READ( PVR2, RENDER_VCLIP ) & 0x03FF;
129 int clip_width = ((MMIO_READ( PVR2, RENDER_HCLIP ) >> 16) & 0x03FF) - clip_x + 1;
130 int clip_height= ((MMIO_READ( PVR2, RENDER_VCLIP ) >> 16) & 0x03FF) - clip_y + 1;
132 /* Fog setup goes here? */
134 /* Render the background plane */
136 uint32_t bgplane_mode = MMIO_READ(PVR2, RENDER_BGPLANE);
137 uint32_t *display_list =
138 (uint32_t *)mem_get_region(PVR2_RAM_BASE + MMIO_READ( PVR2, RENDER_POLYBASE ));
140 uint32_t *bgplane = display_list + (((bgplane_mode & 0x00FFFFFF)) >> 3) ;
141 render_backplane( bgplane, buffer->width, buffer->height, bgplane_mode );
143 pvr2_render_tilebuffer( buffer->width, buffer->height, clip_x, clip_y,
144 clip_x + clip_width, clip_y + clip_height );
146 gettimeofday( &tvb, NULL );
147 uint32_t ms = (tvb.tv_sec - tva.tv_sec) * 1000 +
148 (tvb.tv_usec - tva.tv_usec)/1000;
149 DEBUG( "Rendered frame %d to %08X in %dms", pvr2_get_frame_count(), buffer->address, ms );
.