Search
lxdream.org :: lxdream/src/pvr2/glrender.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/glrender.c
changeset 1139:9af81878480b
prev1138:3bcb705a7ebc
next1140:7dc1c71ece76
author nkeynes
date Sun Oct 24 15:22:59 2010 +1000 (11 years ago)
permissions -rw-r--r--
last change Eliminate GL_REPLACE tex mode in favour of GL_MODULATE (by setting colour
values to 1.0) - one less case for shaders to care about later
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/scene.h"
    25 #include "pvr2/glutil.h"
    27 #define IS_EMPTY_TILE_LIST(p) ((*((uint32_t *)(pvr2_main_ram+(p))) >> 28) == 0x0F)
    29 int pvr2_poly_depthmode[8] = { GL_NEVER, GL_LESS, GL_EQUAL, GL_LEQUAL,
    30         GL_GREATER, GL_NOTEQUAL, GL_GEQUAL, 
    31         GL_ALWAYS };
    32 int pvr2_poly_srcblend[8] = { 
    33         GL_ZERO, GL_ONE, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
    34         GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, 
    35         GL_ONE_MINUS_DST_ALPHA };
    36 int pvr2_poly_dstblend[8] = {
    37         GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
    38         GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA,
    39         GL_ONE_MINUS_DST_ALPHA };
    40 int pvr2_poly_texblend[4] = {
    41         GL_REPLACE, 
    42         GL_MODULATE,  
    43         GL_DECAL, 
    44         GL_MODULATE 
    45 };
    47 /**
    48  * Clip the tile bounds to the clipping plane. 
    49  * @return TRUE if the tile was not clipped completely.
    50  */
    51 static gboolean clip_tile_bounds( uint32_t *tile, float *clip )
    52 {
    53     if( tile[0] < clip[0] ) tile[0] = clip[0];
    54     if( tile[1] > clip[1] ) tile[1] = clip[1];
    55     if( tile[2] < clip[2] ) tile[2] = clip[2];
    56     if( tile[3] > clip[3] ) tile[3] = clip[3];
    57     return tile[0] < tile[1] && tile[2] < tile[3];
    58 }
    60 void pvr2_scene_load_textures()
    61 {
    62     int i;
    64     texcache_begin_scene( MMIO_READ( PVR2, RENDER_PALETTE ) & 0x03,
    65                          (MMIO_READ( PVR2, RENDER_TEXSIZE ) & 0x003F) << 5 );
    67     for( i=0; i < pvr2_scene.poly_count; i++ ) {
    68         struct polygon_struct *poly = &pvr2_scene.poly_array[i];
    69         if( POLY1_TEXTURED(poly->context[0]) ) {
    70             poly->tex_id = texcache_get_texture( poly->context[1], poly->context[2] );
    71             if( poly->mod_vertex_index != -1 ) {
    72                 if( pvr2_scene.shadow_mode == SHADOW_FULL ) {
    73                     poly->mod_tex_id = texcache_get_texture( poly->context[3], poly->context[4] );
    74                 } else {
    75                     poly->mod_tex_id = poly->tex_id;
    76                 }
    77             }
    78         } else {
    79             poly->tex_id = 0;
    80             poly->mod_tex_id = 0;
    81         }
    82     }
    83 }
    87 /**
    88  * Once-off call to setup the OpenGL context.
    89  */
    90 void pvr2_setup_gl_context()
    91 {
    93     if( glsl_is_supported() ) {
    94         if( !glsl_load_shaders( ) ) {
    95             WARN( "Unable to load GL shaders" );
    96         }
    97     }
    99     texcache_gl_init(); // Allocate texture IDs
   100     glDisable( GL_CULL_FACE );
   101     glEnable( GL_BLEND );
   102     glEnable( GL_DEPTH_TEST );
   103     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
   104     glMatrixMode(GL_MODELVIEW);
   105     glLoadIdentity();
   107 #ifdef HAVE_OPENGL_CLAMP_COLOR
   108     if( isGLExtensionSupported("GL_ARB_color_buffer_float") ) {
   109         glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, GL_FALSE );
   110         glClampColorARB(GL_CLAMP_FRAGMENT_COLOR_ARB, GL_FALSE );
   111     }
   112 #endif
   114     glEnableClientState( GL_COLOR_ARRAY );
   115     glEnableClientState( GL_VERTEX_ARRAY );
   116     glEnableClientState( GL_TEXTURE_COORD_ARRAY );
   117     glEnableClientState( GL_SECONDARY_COLOR_ARRAY );
   118     glEnableClientState( GL_FOG_COORDINATE_ARRAY_EXT );
   120     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
   121     glClearDepth(0);
   122     glClearStencil(0);
   124     glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
   125     glFogi(GL_FOG_MODE, GL_LINEAR);
   126     glFogf(GL_FOG_START, 0.0);
   127     glFogf(GL_FOG_END, 1.0);
   128 }
   130 /**
   131  * Setup the basic context that's shared between normal and modified modes -
   132  * depth, culling
   133  */
   134 static void render_set_base_context( uint32_t poly1, gboolean set_depth )
   135 {
   136     if( set_depth ) {
   137         glDepthFunc( POLY1_DEPTH_MODE(poly1) );
   138     }
   140     glDepthMask( POLY1_DEPTH_WRITE(poly1) ? GL_TRUE : GL_FALSE );
   141 }
   143 /**
   144  * Setup the texture/shading settings (TSP) which vary between mod/unmod modes.
   145  */
   146 void render_set_tsp_context( uint32_t poly1, uint32_t poly2 )
   147 {
   148     glShadeModel( POLY1_SHADE_MODEL(poly1) );
   149     if( POLY1_TEXTURED(poly1) ) {
   150         if( POLY2_TEX_BLEND(poly2) == 2 )
   151             glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
   152         else
   153             glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
   154      }
   156      switch( POLY2_FOG_MODE(poly2) ) {
   157      case PVR2_POLY_FOG_LOOKUP:
   158          glFogfv( GL_FOG_COLOR, pvr2_scene.fog_lut_colour );
   159          break;
   160      case PVR2_POLY_FOG_VERTEX:
   161          glFogfv( GL_FOG_COLOR, pvr2_scene.fog_vert_colour );
   162          break;
   163      }
   165      int srcblend = POLY2_SRC_BLEND(poly2);
   166      int destblend = POLY2_DEST_BLEND(poly2);
   167      glBlendFunc( srcblend, destblend );
   169      if( POLY2_SRC_BLEND_TARGET(poly2) || POLY2_DEST_BLEND_TARGET(poly2) ) {
   170          WARN( "Accumulation buffer not supported" );
   171      }   
   172 }
   174 /**
   175  * Setup the GL context for the supplied polygon context.
   176  * @param context pointer to 3 or 5 words of polygon context
   177  * @param depth_mode force depth mode, or 0 to use the polygon's
   178  * depth mode.
   179  */
   180 void render_set_context( uint32_t *context, gboolean set_depth )
   181 {
   182     render_set_base_context(context[0], set_depth);
   183     render_set_tsp_context(context[0],context[1]);
   184 }
   186 static inline void gl_draw_vertexes( struct polygon_struct *poly )
   187 {
   188     do {
   189         glDrawArrays(GL_TRIANGLE_STRIP, poly->vertex_index, poly->vertex_count);
   190         poly = poly->sub_next;
   191     } while( poly != NULL );
   192 }
   194 static inline void gl_draw_mod_vertexes( struct polygon_struct *poly )
   195 {
   196     do {
   197         glDrawArrays(GL_TRIANGLE_STRIP, poly->mod_vertex_index, poly->vertex_count);
   198         poly = poly->sub_next;
   199     } while( poly != NULL );
   200 }
   202 static void gl_render_poly( struct polygon_struct *poly, gboolean set_depth)
   203 {
   204     if( poly->vertex_count == 0 )
   205         return; /* Culled */
   207     glBindTexture(GL_TEXTURE_2D, poly->tex_id);
   208     if( poly->mod_vertex_index == -1 ) {
   209         render_set_context( poly->context, set_depth );
   210         gl_draw_vertexes(poly);
   211     }  else {
   212         glEnable( GL_STENCIL_TEST );
   213         render_set_base_context( poly->context[0], set_depth );
   214         render_set_tsp_context( poly->context[0], poly->context[1] );
   215         glStencilFunc(GL_EQUAL, 0, 2);
   216         gl_draw_vertexes(poly);
   218         if( pvr2_scene.shadow_mode == SHADOW_FULL ) {
   219             if( poly->mod_tex_id != poly->tex_id ) {
   220                 glBindTexture(GL_TEXTURE_2D, poly->mod_tex_id);
   221             }
   222             render_set_tsp_context( poly->context[0], poly->context[3] );
   223         }
   224         glStencilFunc(GL_EQUAL, 2, 2);
   225         gl_draw_mod_vertexes(poly);
   226         glDisable( GL_STENCIL_TEST );
   227     }
   228 }
   230 static void gl_render_bkgnd( struct polygon_struct *poly )
   231 {
   232     glBindTexture(GL_TEXTURE_2D, poly->tex_id);
   233     render_set_tsp_context( poly->context[0], poly->context[1] );
   234     glDisable( GL_DEPTH_TEST );
   235     glBlendFunc( GL_ONE, GL_ZERO );
   236     gl_draw_vertexes(poly);
   237     glEnable( GL_DEPTH_TEST );
   238 }
   240 void gl_render_tilelist( pvraddr_t tile_entry, gboolean set_depth )
   241 {
   242     uint32_t *tile_list = (uint32_t *)(pvr2_main_ram+tile_entry);
   243     int strip_count;
   244     struct polygon_struct *poly;
   246     if( !IS_TILE_PTR(tile_entry) )
   247         return;
   249     while(1) {
   250         uint32_t entry = *tile_list++;
   251         switch( entry >> 28 ) {
   252         case 0x0F:
   253             return; // End-of-list
   254         case 0x0E:
   255             tile_list = (uint32_t *)(pvr2_main_ram + (entry&0x007FFFFF));
   256             break;
   257         case 0x08: case 0x09: case 0x0A: case 0x0B:
   258             strip_count = ((entry >> 25) & 0x0F)+1;
   259             poly = pvr2_scene.buf_to_poly_map[entry&0x000FFFFF];
   260             while( strip_count > 0 ) {
   261                 assert( poly != NULL );
   262                 gl_render_poly( poly, set_depth );
   263                 poly = poly->next;
   264                 strip_count--;
   265             }
   266             break;
   267         default:
   268             if( entry & 0x7E000000 ) {
   269                 poly = pvr2_scene.buf_to_poly_map[entry&0x000FFFFF];
   270                 gl_render_poly( poly, set_depth );
   271             }
   272         }
   273     }       
   274 }
   276 /**
   277  * Render the tilelist with depthbuffer updates only. 
   278  */
   279 void gl_render_tilelist_depthonly( pvraddr_t tile_entry )
   280 {
   281     uint32_t *tile_list = (uint32_t *)(pvr2_main_ram+tile_entry);
   282     int strip_count;
   283     struct polygon_struct *poly;
   285     if( !IS_TILE_PTR(tile_entry) )
   286         return;
   288     while(1) {
   289         uint32_t entry = *tile_list++;
   290         switch( entry >> 28 ) {
   291         case 0x0F:
   292             return; // End-of-list
   293         case 0x0E:
   294             tile_list = (uint32_t *)(pvr2_main_ram + (entry&0x007FFFFF));
   295             break;
   296         case 0x08: case 0x09: case 0x0A: case 0x0B:
   297             strip_count = ((entry >> 25) & 0x0F)+1;
   298             poly = pvr2_scene.buf_to_poly_map[entry&0x000FFFFF];
   299             while( strip_count > 0 ) {
   300                 if( poly->vertex_count != 0 ) {
   301                     render_set_base_context(poly->context[0],TRUE);
   302                     gl_draw_vertexes(poly);
   303                 }
   304                 poly = poly->next;
   305                 strip_count--;
   306             }
   307             break;
   308         default:
   309             if( entry & 0x7E000000 ) {
   310                 poly = pvr2_scene.buf_to_poly_map[entry&0x000FFFFF];
   311                 if( poly->vertex_count != 0 ) {
   312                     render_set_base_context(poly->context[0],TRUE);
   313                     gl_draw_vertexes(poly);
   314                 }
   315             }
   316         }
   317     }           
   318 }
   320 static void drawrect2d( uint32_t tile_bounds[], float z )
   321 {
   322     glBegin( GL_QUADS );
   323     glVertex3f( tile_bounds[0], tile_bounds[2], z );
   324     glVertex3f( tile_bounds[1], tile_bounds[2], z );
   325     glVertex3f( tile_bounds[1], tile_bounds[3], z );
   326     glVertex3f( tile_bounds[0], tile_bounds[3], z );
   327     glEnd();
   328 }
   330 void gl_render_modifier_polygon( struct polygon_struct *poly, uint32_t tile_bounds[] )
   331 {
   332     /* A bit of explanation:
   333      * In theory it works like this: generate a 1-bit stencil for each polygon
   334      * volume, and then AND or OR it against the overall 1-bit tile stencil at 
   335      * the end of the volume. 
   336      * 
   337      * The implementation here uses a 2-bit stencil buffer, where each volume
   338      * is drawn using only stencil bit 0, and then a 'flush' polygon is drawn
   339      * to update bit 1 accordingly and clear bit 0.
   340      * 
   341      * This could probably be more efficient, but at least it works correctly 
   342      * now :)
   343      */
   345     if( poly->vertex_count == 0 )
   346         return; /* Culled */
   348     gl_draw_vertexes(poly);
   352     int poly_type = POLY1_VOLUME_MODE(poly->context[0]);
   353     if( poly_type == PVR2_VOLUME_REGION0 ) {
   354         /* 00 => 00
   355          * 01 => 00
   356          * 10 => 10
   357          * 11 => 00
   358          */
   359         glStencilMask( 0x03 );
   360         glStencilFunc(GL_EQUAL, 0x02, 0x03);
   361         glStencilOp(GL_ZERO, GL_KEEP, GL_KEEP);
   362         glDisable( GL_DEPTH_TEST );
   364         drawrect2d( tile_bounds, pvr2_scene.bounds[4] );
   366         glEnable( GL_DEPTH_TEST );
   367         glStencilMask( 0x01 );
   368         glStencilFunc( GL_ALWAYS, 0, 1 );
   369         glStencilOp( GL_KEEP,GL_INVERT, GL_KEEP ); 
   370     } else if( poly_type == PVR2_VOLUME_REGION1 ) {
   371         /* This is harder with the standard stencil ops - do it in two passes
   372          * 00 => 00 | 00 => 10
   373          * 01 => 10 | 01 => 10
   374          * 10 => 10 | 10 => 00
   375          * 11 => 10 | 11 => 10
   376          */
   377         glStencilMask( 0x02 );
   378         glStencilOp( GL_INVERT, GL_INVERT, GL_INVERT );
   379         glDisable( GL_DEPTH_TEST );
   381         drawrect2d( tile_bounds, pvr2_scene.bounds[4] );
   383         glStencilMask( 0x03 );
   384         glStencilFunc( GL_NOTEQUAL,0x02, 0x03);
   385         glStencilOp( GL_ZERO, GL_REPLACE, GL_REPLACE );
   387         drawrect2d( tile_bounds, pvr2_scene.bounds[4] );
   389         glEnable( GL_DEPTH_TEST );
   390         glStencilMask( 0x01 );
   391         glStencilFunc( GL_ALWAYS, 0, 1 );
   392         glStencilOp( GL_KEEP,GL_INVERT, GL_KEEP );         
   393     }
   394 }
   396 void gl_render_modifier_tilelist( pvraddr_t tile_entry, uint32_t tile_bounds[] )
   397 {
   398     uint32_t *tile_list = (uint32_t *)(pvr2_main_ram+tile_entry);
   399     int strip_count;
   400     struct polygon_struct *poly;
   402     if( !IS_TILE_PTR(tile_entry) )
   403         return;
   405     glEnable( GL_STENCIL_TEST );
   406     glEnable( GL_DEPTH_TEST );
   407     glDepthFunc( GL_LEQUAL );
   409     glStencilFunc( GL_ALWAYS, 0, 1 );
   410     glStencilOp( GL_KEEP,GL_INVERT, GL_KEEP ); 
   411     glStencilMask( 0x01 );
   412     glDepthMask( GL_FALSE );
   414     while(1) {
   415         uint32_t entry = *tile_list++;
   416         switch( entry >> 28 ) {
   417         case 0x0F:
   418             glDepthMask( GL_TRUE );
   419             glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
   420             glDisable( GL_STENCIL_TEST );
   421             return; // End-of-list
   422         case 0x0E:
   423             tile_list = (uint32_t *)(pvr2_main_ram + (entry&0x007FFFFF));
   424             break;
   425         case 0x08: case 0x09: case 0x0A: case 0x0B:
   426             strip_count = ((entry >> 25) & 0x0F)+1;
   427             poly = pvr2_scene.buf_to_poly_map[entry&0x000FFFFF];
   428             while( strip_count > 0 ) {
   429                 gl_render_modifier_polygon( poly, tile_bounds );
   430                 poly = poly->next;
   431                 strip_count--;
   432             }
   433             break;
   434         default:
   435             if( entry & 0x7E000000 ) {
   436                 poly = pvr2_scene.buf_to_poly_map[entry&0x000FFFFF];
   437                 gl_render_modifier_polygon( poly, tile_bounds );
   438             }
   439         }
   440     }
   442 }
   445 /**
   446  * Render the currently defined scene in pvr2_scene
   447  */
   448 void pvr2_scene_render( render_buffer_t buffer )
   449 {
   450     /* Scene setup */
   451     struct timeval start_tv, tex_tv, end_tv;
   453     gettimeofday(&start_tv, NULL);
   454     display_driver->set_render_target(buffer);
   455     pvr2_check_palette_changed();
   456     pvr2_scene_load_textures();
   458     gettimeofday( &tex_tv, NULL );
   459     uint32_t ms = (tex_tv.tv_sec - start_tv.tv_sec) * 1000 +
   460     (tex_tv.tv_usec - start_tv.tv_usec)/1000;
   461     DEBUG( "Scene setup in %dms", ms );
   463     /* Setup view projection matrix */
   464     glMatrixMode(GL_PROJECTION);
   465     glLoadIdentity();
   466     float nearz = pvr2_scene.bounds[4];
   467     float farz = pvr2_scene.bounds[5];
   468     if( nearz == farz ) {
   469         farz*= 4.0;
   470     }
   471     glOrtho( 0, pvr2_scene.buffer_width, pvr2_scene.buffer_height, 0, 
   472              -farz, -nearz );
   473     float alphaRef = ((float)(MMIO_READ(PVR2, RENDER_ALPHA_REF)&0xFF)+1)/256.0;
   474     glAlphaFunc( GL_GEQUAL, alphaRef );
   476     /* Clear the buffer (FIXME: May not want always want to do this) */
   477     glDisable( GL_SCISSOR_TEST );
   478     glDepthMask( GL_TRUE );
   479     glStencilMask( 0x03 );
   480     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
   482     /* Setup vertex array pointers */
   483     glVertexPointer(3, GL_FLOAT, sizeof(struct vertex_struct), &pvr2_scene.vertex_array[0].x);
   484     glColorPointer(4, GL_FLOAT, sizeof(struct vertex_struct), &pvr2_scene.vertex_array[0].rgba[0]);
   485     glTexCoordPointer(2, GL_FLOAT, sizeof(struct vertex_struct), &pvr2_scene.vertex_array[0].u);
   486     glSecondaryColorPointerEXT(3, GL_FLOAT, sizeof(struct vertex_struct), pvr2_scene.vertex_array[0].offset_rgba );
   487     glFogCoordPointerEXT(GL_FLOAT, sizeof(struct vertex_struct), &pvr2_scene.vertex_array[0].offset_rgba[3] );
   488     /* Turn on the shaders (if available) */
   489     glsl_set_shader(DEFAULT_PROGRAM);
   491     /* Render the background */
   492     gl_render_bkgnd( pvr2_scene.bkgnd_poly );
   494     glEnable( GL_SCISSOR_TEST );
   495     glEnable( GL_COLOR_SUM );
   496     glEnable( GL_FOG );
   497     glEnable( GL_TEXTURE_2D );
   499     /* Process the segment list */
   500     struct tile_segment *segment = pvr2_scene.segment_list;
   501     do {
   502         int tilex = SEGMENT_X(segment->control);
   503         int tiley = SEGMENT_Y(segment->control);
   505         uint32_t tile_bounds[4] = { tilex << 5, (tilex+1)<<5, tiley<<5, (tiley+1)<<5 };
   506         if( !clip_tile_bounds(tile_bounds, pvr2_scene.bounds) ) {
   507             continue; // fully clipped, skip tile
   508         }
   510         /* Clip to the visible part of the tile */
   511         glScissor( tile_bounds[0], pvr2_scene.buffer_height-tile_bounds[3], 
   512                    tile_bounds[1]-tile_bounds[0], tile_bounds[3] - tile_bounds[2] );
   513         if( display_driver->capabilities.stencil_bits >= 2 && 
   514                 IS_TILE_PTR(segment->opaquemod_ptr) &&
   515                 !IS_EMPTY_TILE_LIST(segment->opaquemod_ptr) ) {
   516             /* Don't do this unless there's actually some shadow polygons */
   518             /* Use colormask instead of drawbuffer for simplicity */
   519             glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
   520             gl_render_tilelist_depthonly(segment->opaque_ptr);
   521             gl_render_modifier_tilelist(segment->opaquemod_ptr, tile_bounds);
   522             glClear( GL_DEPTH_BUFFER_BIT );
   523             glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
   524         }
   525         gl_render_tilelist(segment->opaque_ptr,TRUE);
   526         if( IS_TILE_PTR(segment->punchout_ptr) ) {
   527             glEnable(GL_ALPHA_TEST );
   528             glDepthFunc(GL_GEQUAL);
   529             gl_render_tilelist(segment->punchout_ptr, FALSE );
   530             glDisable(GL_ALPHA_TEST );
   531         }
   533         if( IS_TILE_PTR(segment->trans_ptr) ) {
   534             if( pvr2_scene.sort_mode == SORT_NEVER || 
   535                     (pvr2_scene.sort_mode == SORT_TILEFLAG && (segment->control&SEGMENT_SORT_TRANS))) {
   536                 gl_render_tilelist(segment->trans_ptr, TRUE);
   537             } else {
   538                 render_autosort_tile(segment->trans_ptr, RENDER_NORMAL );
   539             }
   540         }
   541     } while( !IS_LAST_SEGMENT(segment++) );
   542     glDisable( GL_SCISSOR_TEST );
   543     glDisable( GL_COLOR_SUM );
   544     glDisable( GL_FOG );
   545     glsl_clear_shader();
   547     gettimeofday( &end_tv, NULL );
   548     ms = (end_tv.tv_sec - tex_tv.tv_sec) * 1000 +
   549     (end_tv.tv_usec - tex_tv.tv_usec)/1000;
   550     DEBUG( "Scene render in %dms", ms );
   551 }
.