filename | src/pvr2/glrender.c |
changeset | 1275:83b15705cdde |
prev | 1257:e1314ad3e7cc |
next | 1280:38f2b0e60261 |
author | nkeynes |
date | Tue Mar 20 08:29:38 2012 +1000 (12 years ago) |
permissions | -rw-r--r-- |
last change | More android WIP - Implement onPause/onResume (although resume is not actually working yet) - Implement BGRA => RGBA texture conversion (BGRA doesn't seem to work on the TFP) Boot swirl is now displayed, albeit depth buffering seems to be broken. |
view | annotate | diff | log | raw |
1 /**
2 * $Id$
3 *
4 * Standard OpenGL rendering engine.
5 *
6 * Copyright (c) 2005 Nathan Keynes.
7 *
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.
12 *
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.
17 */
19 #include <assert.h>
20 #include <sys/time.h>
21 #include "display.h"
22 #include "pvr2/pvr2.h"
23 #include "pvr2/pvr2mmio.h"
24 #include "pvr2/glutil.h"
25 #include "pvr2/scene.h"
26 #include "pvr2/tileiter.h"
27 #include "pvr2/shaders.h"
29 #ifdef APPLE_BUILD
30 #include "OpenGL/CGLCurrent.h"
31 #include "OpenGL/CGLMacro.h"
33 static CGLContextObj CGL_MACRO_CONTEXT;
34 #endif
36 #define IS_NONEMPTY_TILE_LIST(p) (IS_TILE_PTR(p) && ((*((uint32_t *)(pvr2_main_ram+(p))) >> 28) != 0x0F))
38 int pvr2_poly_depthmode[8] = { GL_NEVER, GL_LESS, GL_EQUAL, GL_LEQUAL,
39 GL_GREATER, GL_NOTEQUAL, GL_GEQUAL,
40 GL_ALWAYS };
41 int pvr2_poly_srcblend[8] = {
42 GL_ZERO, GL_ONE, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
43 GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA,
44 GL_ONE_MINUS_DST_ALPHA };
45 int pvr2_poly_dstblend[8] = {
46 GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
47 GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA,
48 GL_ONE_MINUS_DST_ALPHA };
50 static gboolean have_shaders = FALSE;
51 static int currentTexId = -1;
53 static inline void bind_texture(int texid)
54 {
55 if( currentTexId != texid ) {
56 currentTexId = texid;
57 glBindTexture(GL_TEXTURE_2D, texid);
58 }
59 }
61 /**
62 * Clip the tile bounds to the clipping plane.
63 * @return TRUE if the tile was not clipped completely.
64 */
65 static gboolean clip_tile_bounds( uint32_t *tile, uint32_t *clip )
66 {
67 if( tile[0] < clip[0] ) tile[0] = clip[0];
68 if( tile[1] > clip[1] ) tile[1] = clip[1];
69 if( tile[2] < clip[2] ) tile[2] = clip[2];
70 if( tile[3] > clip[3] ) tile[3] = clip[3];
71 return tile[0] < tile[1] && tile[2] < tile[3];
72 }
74 static void drawrect2d( uint32_t tile_bounds[], float z )
75 {
76 /* FIXME: Find a non-fixed-func way to do this */
77 #ifdef HAVE_OPENGL_FIXEDFUNC
78 glBegin( GL_TRIANGLE_STRIP );
79 glVertex3f( tile_bounds[0], tile_bounds[2], z );
80 glVertex3f( tile_bounds[1], tile_bounds[2], z );
81 glVertex3f( tile_bounds[0], tile_bounds[3], z );
82 glVertex3f( tile_bounds[1], tile_bounds[3], z );
83 glEnd();
84 #endif
85 }
87 static void pvr2_scene_load_textures()
88 {
89 int i;
91 texcache_begin_scene( MMIO_READ( PVR2, RENDER_PALETTE ) & 0x03,
92 (MMIO_READ( PVR2, RENDER_TEXSIZE ) & 0x003F) << 5 );
94 for( i=0; i < pvr2_scene.poly_count; i++ ) {
95 struct polygon_struct *poly = &pvr2_scene.poly_array[i];
96 if( POLY1_TEXTURED(poly->context[0]) ) {
97 poly->tex_id = texcache_get_texture( poly->context[1], poly->context[2] );
98 if( poly->mod_vertex_index != -1 ) {
99 if( pvr2_scene.shadow_mode == SHADOW_FULL ) {
100 poly->mod_tex_id = texcache_get_texture( poly->context[3], poly->context[4] );
101 } else {
102 poly->mod_tex_id = poly->tex_id;
103 }
104 }
105 } else {
106 poly->tex_id = 0;
107 poly->mod_tex_id = 0;
108 }
109 }
110 }
113 /**
114 * Once-off call to setup the OpenGL context.
115 */
116 void pvr2_setup_gl_context()
117 {
118 have_shaders = display_driver->capabilities.has_sl;
119 #ifdef APPLE_BUILD
120 CGL_MACRO_CONTEXT = CGLGetCurrentContext();
121 #endif
122 texcache_gl_init(); // Allocate texture IDs
124 /* Global settings */
125 glDisable( GL_CULL_FACE );
126 glEnable( GL_BLEND );
127 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
129 #ifdef HAVE_OPENGL_CLAMP_COLOR
130 if( isGLExtensionSupported("GL_ARB_color_buffer_float") ) {
131 glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, GL_FALSE );
132 glClampColorARB(GL_CLAMP_FRAGMENT_COLOR_ARB, GL_FALSE );
133 }
134 #endif
136 #ifdef HAVE_OPENGL_FIXEDFUNC
137 /* Setup defaults for perspective correction + matrices */
138 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
139 glMatrixMode(GL_MODELVIEW);
140 glLoadIdentity();
141 glMatrixMode(GL_PROJECTION);
142 #endif
145 #ifdef HAVE_OPENGL_CLEAR_DEPTHF
146 glClearDepthf(0);
147 #else
148 glClearDepth(0);
149 #endif
150 glClearStencil(0);
151 }
153 void pvr2_shutdown_gl_context()
154 {
155 texcache_gl_shutdown();
156 }
158 /**
159 * Setup the basic context that's shared between normal and modified modes -
160 * depth, culling
161 */
162 static void render_set_base_context( uint32_t poly1, gboolean set_depth )
163 {
164 if( set_depth ) {
165 glDepthFunc( POLY1_DEPTH_MODE(poly1) );
166 }
168 glDepthMask( POLY1_DEPTH_WRITE(poly1) ? GL_TRUE : GL_FALSE );
169 }
171 /**
172 * Setup the texture/shading settings (TSP) which vary between mod/unmod modes.
173 */
174 static void render_set_tsp_context( uint32_t poly1, uint32_t poly2 )
175 {
176 #ifdef HAVE_OPENGL_FIXEDFUNC
177 glShadeModel( POLY1_SHADE_MODEL(poly1) );
179 if( !have_shaders ) {
180 if( POLY1_TEXTURED(poly1) ) {
181 if( POLY2_TEX_BLEND(poly2) == 2 )
182 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
183 else
184 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
186 }
188 switch( POLY2_FOG_MODE(poly2) ) {
189 case PVR2_POLY_FOG_LOOKUP:
190 glFogfv( GL_FOG_COLOR, pvr2_scene.fog_lut_colour );
191 break;
192 case PVR2_POLY_FOG_VERTEX:
193 glFogfv( GL_FOG_COLOR, pvr2_scene.fog_vert_colour );
194 break;
195 }
196 }
197 #endif
199 int srcblend = POLY2_SRC_BLEND(poly2);
200 int destblend = POLY2_DEST_BLEND(poly2);
201 glBlendFunc( srcblend, destblend );
203 if( POLY2_SRC_BLEND_TARGET(poly2) || POLY2_DEST_BLEND_TARGET(poly2) ) {
204 WARN( "Accumulation buffer not supported" );
205 }
206 }
208 /**
209 * Setup the GL context for the supplied polygon context.
210 * @param context pointer to 3 or 5 words of polygon context
211 * @param depth_mode force depth mode, or 0 to use the polygon's
212 * depth mode.
213 */
214 static void render_set_context( uint32_t *context, gboolean set_depth )
215 {
216 render_set_base_context(context[0], set_depth);
217 render_set_tsp_context(context[0],context[1]);
218 }
220 static inline void gl_draw_vertexes( struct polygon_struct *poly )
221 {
222 do {
223 glDrawArrays(GL_TRIANGLE_STRIP, poly->vertex_index, poly->vertex_count);
224 poly = poly->sub_next;
225 } while( poly != NULL );
226 }
228 static inline void gl_draw_mod_vertexes( struct polygon_struct *poly )
229 {
230 do {
231 glDrawArrays(GL_TRIANGLE_STRIP, poly->mod_vertex_index, poly->vertex_count);
232 poly = poly->sub_next;
233 } while( poly != NULL );
234 }
236 static void gl_render_poly( struct polygon_struct *poly, gboolean set_depth)
237 {
238 if( poly->vertex_count == 0 )
239 return; /* Culled */
241 bind_texture(poly->tex_id);
242 if( poly->mod_vertex_index == -1 ) {
243 render_set_context( poly->context, set_depth );
244 gl_draw_vertexes(poly);
245 } else {
246 glEnable( GL_STENCIL_TEST );
247 render_set_base_context( poly->context[0], set_depth );
248 render_set_tsp_context( poly->context[0], poly->context[1] );
249 glStencilFunc(GL_EQUAL, 0, 2);
250 gl_draw_vertexes(poly);
252 if( pvr2_scene.shadow_mode == SHADOW_FULL ) {
253 bind_texture(poly->mod_tex_id);
254 render_set_tsp_context( poly->context[0], poly->context[3] );
255 }
256 glStencilFunc(GL_EQUAL, 2, 2);
257 gl_draw_mod_vertexes(poly);
258 glDisable( GL_STENCIL_TEST );
259 }
260 }
263 static void gl_render_modifier_polygon( struct polygon_struct *poly, uint32_t tile_bounds[] )
264 {
265 /* A bit of explanation:
266 * In theory it works like this: generate a 1-bit stencil for each polygon
267 * volume, and then AND or OR it against the overall 1-bit tile stencil at
268 * the end of the volume.
269 *
270 * The implementation here uses a 2-bit stencil buffer, where each volume
271 * is drawn using only stencil bit 0, and then a 'flush' polygon is drawn
272 * to update bit 1 accordingly and clear bit 0.
273 *
274 * This could probably be more efficient, but at least it works correctly
275 * now :)
276 */
278 if( poly->vertex_count == 0 )
279 return; /* Culled */
281 gl_draw_vertexes(poly);
285 int poly_type = POLY1_VOLUME_MODE(poly->context[0]);
286 if( poly_type == PVR2_VOLUME_REGION0 ) {
287 /* 00 => 00
288 * 01 => 00
289 * 10 => 10
290 * 11 => 00
291 */
292 glStencilMask( 0x03 );
293 glStencilFunc(GL_EQUAL, 0x02, 0x03);
294 glStencilOp(GL_ZERO, GL_KEEP, GL_KEEP);
295 glDisable( GL_DEPTH_TEST );
297 drawrect2d( tile_bounds, pvr2_scene.bounds[4] );
299 glEnable( GL_DEPTH_TEST );
300 glStencilMask( 0x01 );
301 glStencilFunc( GL_ALWAYS, 0, 1 );
302 glStencilOp( GL_KEEP,GL_INVERT, GL_KEEP );
303 } else if( poly_type == PVR2_VOLUME_REGION1 ) {
304 /* This is harder with the standard stencil ops - do it in two passes
305 * 00 => 00 | 00 => 10
306 * 01 => 10 | 01 => 10
307 * 10 => 10 | 10 => 00
308 * 11 => 10 | 11 => 10
309 */
310 glStencilMask( 0x02 );
311 glStencilOp( GL_INVERT, GL_INVERT, GL_INVERT );
312 glDisable( GL_DEPTH_TEST );
314 drawrect2d( tile_bounds, pvr2_scene.bounds[4] );
316 glStencilMask( 0x03 );
317 glStencilFunc( GL_NOTEQUAL,0x02, 0x03);
318 glStencilOp( GL_ZERO, GL_REPLACE, GL_REPLACE );
320 drawrect2d( tile_bounds, pvr2_scene.bounds[4] );
322 glEnable( GL_DEPTH_TEST );
323 glStencilMask( 0x01 );
324 glStencilFunc( GL_ALWAYS, 0, 1 );
325 glStencilOp( GL_KEEP,GL_INVERT, GL_KEEP );
326 }
327 }
329 static void gl_render_bkgnd( struct polygon_struct *poly )
330 {
331 bind_texture(poly->tex_id);
332 render_set_tsp_context( poly->context[0], poly->context[1] );
333 glDisable( GL_DEPTH_TEST );
334 glBlendFunc( GL_ONE, GL_ZERO );
335 gl_draw_vertexes(poly);
336 glEnable( GL_DEPTH_TEST );
337 }
339 void gl_render_triangle( struct polygon_struct *poly, int index )
340 {
341 bind_texture(poly->tex_id);
342 render_set_tsp_context( poly->context[0], poly->context[1] );
343 glDrawArrays(GL_TRIANGLE_STRIP, poly->vertex_index + index, 3 );
345 }
347 void gl_render_tilelist( pvraddr_t tile_entry, gboolean set_depth )
348 {
349 tileentryiter list;
351 FOREACH_TILEENTRY(list, tile_entry) {
352 struct polygon_struct *poly = pvr2_scene.buf_to_poly_map[TILEENTRYITER_POLYADDR(list)];
353 if( poly != NULL ) {
354 do {
355 gl_render_poly(poly, set_depth);
356 poly = poly->next;
357 } while( list.strip_count-- > 0 );
358 }
359 }
360 }
362 /**
363 * Render the tilelist with depthbuffer updates only.
364 */
365 static void gl_render_tilelist_depthonly( pvraddr_t tile_entry )
366 {
367 tileentryiter list;
369 FOREACH_TILEENTRY(list, tile_entry) {
370 struct polygon_struct *poly = pvr2_scene.buf_to_poly_map[TILEENTRYITER_POLYADDR(list)];
371 if( poly != NULL ) {
372 do {
373 render_set_base_context(poly->context[0],TRUE);
374 gl_draw_vertexes(poly);
375 poly = poly->next;
376 } while( list.strip_count-- > 0 );
377 }
378 }
379 }
381 static void gl_render_modifier_tilelist( pvraddr_t tile_entry, uint32_t tile_bounds[] )
382 {
383 tileentryiter list;
385 FOREACH_TILEENTRY(list, tile_entry ) {
386 struct polygon_struct *poly = pvr2_scene.buf_to_poly_map[TILEENTRYITER_POLYADDR(list)];
387 if( poly != NULL ) {
388 do {
389 gl_render_modifier_polygon( poly, tile_bounds );
390 poly = poly->next;
391 } while( list.strip_count-- > 0 );
392 }
393 }
394 }
397 #ifdef HAVE_OPENGL_FIXEDFUNC
398 void pvr2_scene_setup_fixed( GLfloat *viewMatrix )
399 {
400 glLoadMatrixf(viewMatrix);
401 glEnable( GL_DEPTH_TEST );
403 glEnable( GL_FOG );
404 glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
405 glFogi(GL_FOG_MODE, GL_LINEAR);
406 glFogf(GL_FOG_START, 0.0);
407 glFogf(GL_FOG_END, 1.0);
409 glEnable( GL_ALPHA_TEST );
410 glAlphaFunc( GL_GEQUAL, 0 );
412 glEnable( GL_COLOR_SUM );
414 glEnableClientState( GL_VERTEX_ARRAY );
415 glEnableClientState( GL_COLOR_ARRAY );
416 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
417 glEnableClientState( GL_SECONDARY_COLOR_ARRAY );
418 glEnableClientState( GL_FOG_COORDINATE_ARRAY_EXT );
420 /* Vertex array pointers */
421 glVertexPointer(3, GL_FLOAT, sizeof(struct vertex_struct), &pvr2_scene.vertex_array[0].x);
422 glColorPointer(4, GL_FLOAT, sizeof(struct vertex_struct), &pvr2_scene.vertex_array[0].rgba[0]);
423 glTexCoordPointer(2, GL_FLOAT, sizeof(struct vertex_struct), &pvr2_scene.vertex_array[0].u);
424 glSecondaryColorPointerEXT(3, GL_FLOAT, sizeof(struct vertex_struct), pvr2_scene.vertex_array[0].offset_rgba );
425 glFogCoordPointerEXT(GL_FLOAT, sizeof(struct vertex_struct), &pvr2_scene.vertex_array[0].offset_rgba[3] );
426 }
428 void pvr2_scene_set_alpha_fixed( float alphaRef )
429 {
430 glAlphaFunc( GL_GEQUAL, alphaRef );
431 }
433 void pvr2_scene_cleanup_fixed()
434 {
435 glDisable( GL_COLOR_SUM );
436 glDisable( GL_FOG );
437 glDisable( GL_ALPHA_TEST );
438 glDisable( GL_DEPTH_TEST );
440 glDisableClientState( GL_VERTEX_ARRAY );
441 glDisableClientState( GL_COLOR_ARRAY );
442 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
443 glDisableClientState( GL_SECONDARY_COLOR_ARRAY );
444 glDisableClientState( GL_FOG_COORDINATE_ARRAY_EXT );
446 }
447 #else
448 void pvr2_scene_setup_fixed( GLfloat *viewMatrix )
449 {
450 }
451 void pvr2_scene_set_alpha_fixed( float alphaRef )
452 {
453 }
454 void pvr2_scene_cleanup_fixed()
455 {
456 }
457 #endif
459 void pvr2_scene_setup_shader( GLfloat *viewMatrix )
460 {
461 glEnable( GL_DEPTH_TEST );
463 glsl_use_pvr2_shader();
464 glsl_set_pvr2_shader_view_matrix(viewMatrix);
465 glsl_set_pvr2_shader_fog_colour1(pvr2_scene.fog_vert_colour);
466 glsl_set_pvr2_shader_fog_colour2(pvr2_scene.fog_lut_colour);
467 glsl_set_pvr2_shader_in_vertex_vec3_pointer(&pvr2_scene.vertex_array[0].x, sizeof(struct vertex_struct));
468 glsl_set_pvr2_shader_in_colour_pointer(&pvr2_scene.vertex_array[0].rgba[0], sizeof(struct vertex_struct));
469 glsl_set_pvr2_shader_in_colour2_pointer(&pvr2_scene.vertex_array[0].offset_rgba[0], sizeof(struct vertex_struct));
470 glsl_set_pvr2_shader_in_texcoord_pointer(&pvr2_scene.vertex_array[0].u, sizeof(struct vertex_struct));
471 glsl_set_pvr2_shader_alpha_ref(0.0);
472 glsl_set_pvr2_shader_primary_texture(0);
473 glsl_set_pvr2_shader_palette_texture(1);
474 }
476 void pvr2_scene_cleanup_shader( )
477 {
478 glsl_clear_shader();
480 glDisable( GL_DEPTH_TEST );
481 }
483 void pvr2_scene_set_alpha_shader( float alphaRef )
484 {
485 glsl_set_pvr2_shader_alpha_ref(alphaRef);
486 }
488 /**
489 * Render the currently defined scene in pvr2_scene
490 */
491 void pvr2_scene_render( render_buffer_t buffer )
492 {
493 /* Scene setup */
494 struct timeval start_tv, tex_tv, end_tv;
495 int i;
496 GLfloat viewMatrix[16];
497 uint32_t clip_bounds[4];
500 gettimeofday(&start_tv, NULL);
501 display_driver->set_render_target(buffer);
502 pvr2_check_palette_changed();
503 pvr2_scene_load_textures();
504 currentTexId = -1;
506 gettimeofday( &tex_tv, NULL );
507 uint32_t ms = (tex_tv.tv_sec - start_tv.tv_sec) * 1000 +
508 (tex_tv.tv_usec - start_tv.tv_usec)/1000;
509 DEBUG( "Texture load in %dms", ms );
511 float alphaRef = ((float)(MMIO_READ(PVR2, RENDER_ALPHA_REF)&0xFF)+1)/256.0;
512 float nearz = pvr2_scene.bounds[4];
513 float farz = pvr2_scene.bounds[5];
514 if( nearz == farz ) {
515 farz*= 4.0;
516 }
518 /* Generate integer clip boundaries */
519 for( i=0; i<4; i++ ) {
520 clip_bounds[i] = (uint32_t)pvr2_scene.bounds[i];
521 }
523 defineOrthoMatrix(viewMatrix, pvr2_scene.buffer_width, pvr2_scene.buffer_height, -farz, -nearz);
525 if( have_shaders ) {
526 pvr2_scene_setup_shader(viewMatrix);
527 } else {
528 pvr2_scene_setup_fixed(viewMatrix);
529 }
532 /* Clear the buffer (FIXME: May not want always want to do this) */
533 glDisable( GL_SCISSOR_TEST );
534 glDepthMask( GL_TRUE );
535 glStencilMask( 0x03 );
536 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
538 /* Render the background */
539 gl_render_bkgnd( pvr2_scene.bkgnd_poly );
541 glEnable( GL_SCISSOR_TEST );
542 glEnable( GL_TEXTURE_2D );
544 struct tile_segment *segment;
546 #define FOREACH_SEGMENT(segment) \
547 segment = pvr2_scene.segment_list; \
548 do { \
549 int tilex = SEGMENT_X(segment->control); \
550 int tiley = SEGMENT_Y(segment->control); \
551 \
552 uint32_t tile_bounds[4] = { tilex << 5, (tilex+1)<<5, tiley<<5, (tiley+1)<<5 }; \
553 if( !clip_tile_bounds(tile_bounds, clip_bounds) ) { \
554 continue; \
555 }
556 #define END_FOREACH_SEGMENT() \
557 } while( !IS_LAST_SEGMENT(segment++) );
558 #define CLIP_TO_SEGMENT() \
559 glScissor( tile_bounds[0], pvr2_scene.buffer_height-tile_bounds[3], tile_bounds[1]-tile_bounds[0], tile_bounds[3] - tile_bounds[2] )
561 /* Build up the opaque stencil map */
562 if( display_driver->capabilities.stencil_bits >= 2 ) {
563 glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
564 FOREACH_SEGMENT(segment)
565 if( IS_NONEMPTY_TILE_LIST(segment->opaquemod_ptr) ) {
566 CLIP_TO_SEGMENT();
567 gl_render_tilelist_depthonly(segment->opaque_ptr);
568 }
569 END_FOREACH_SEGMENT()
571 glEnable( GL_STENCIL_TEST );
572 glStencilFunc( GL_ALWAYS, 0, 1 );
573 glStencilOp( GL_KEEP,GL_INVERT, GL_KEEP );
574 glStencilMask( 0x01 );
575 glDepthFunc( GL_LEQUAL );
576 glDepthMask( GL_FALSE );
577 FOREACH_SEGMENT(segment)
578 if( IS_NONEMPTY_TILE_LIST(segment->opaquemod_ptr) ) {
579 CLIP_TO_SEGMENT();
580 gl_render_modifier_tilelist(segment->opaquemod_ptr, tile_bounds);
581 }
582 END_FOREACH_SEGMENT()
583 glDepthMask( GL_TRUE );
584 glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
585 glDisable( GL_SCISSOR_TEST );
586 glClear( GL_DEPTH_BUFFER_BIT );
587 glEnable( GL_SCISSOR_TEST );
588 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
589 }
591 /* Render the opaque polygons */
592 FOREACH_SEGMENT(segment)
593 CLIP_TO_SEGMENT();
594 gl_render_tilelist(segment->opaque_ptr,TRUE);
595 END_FOREACH_SEGMENT()
596 glDisable( GL_STENCIL_TEST );
598 /* Render the punch-out polygons */
599 if( have_shaders )
600 pvr2_scene_set_alpha_shader(alphaRef);
601 else
602 pvr2_scene_set_alpha_fixed(alphaRef);
603 glDepthFunc(GL_GEQUAL);
604 FOREACH_SEGMENT(segment)
605 CLIP_TO_SEGMENT();
606 gl_render_tilelist(segment->punchout_ptr, FALSE );
607 END_FOREACH_SEGMENT()
608 if( have_shaders )
609 pvr2_scene_set_alpha_shader(0.0);
610 else
611 pvr2_scene_set_alpha_fixed(0.0);
613 /* Render the translucent polygons */
614 FOREACH_SEGMENT(segment)
615 if( IS_NONEMPTY_TILE_LIST(segment->trans_ptr) ) {
616 CLIP_TO_SEGMENT();
617 if( pvr2_scene.sort_mode == SORT_NEVER ||
618 (pvr2_scene.sort_mode == SORT_TILEFLAG && (segment->control&SEGMENT_SORT_TRANS))) {
619 gl_render_tilelist(segment->trans_ptr, TRUE);
620 } else {
621 render_autosort_tile(segment->trans_ptr, RENDER_NORMAL );
622 }
623 }
624 END_FOREACH_SEGMENT()
626 glDisable( GL_SCISSOR_TEST );
628 if( have_shaders ) {
629 pvr2_scene_cleanup_shader();
630 } else {
631 pvr2_scene_cleanup_fixed();
632 }
634 pvr2_scene_finished();
636 gettimeofday( &end_tv, NULL );
637 ms = (end_tv.tv_sec - tex_tv.tv_sec) * 1000 +
638 (end_tv.tv_usec - tex_tv.tv_usec)/1000;
639 DEBUG( "Scene render in %dms", ms );
640 }
.