<html>
<body>
  <div id="body" style="background-color:#ffffff;" >
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head" style="border-bottom-width:1px;border-bottom-style:solid;" ><td class="headtd" style="padding:0;padding-top:.2em;" colspan="4">Commit in <b><tt>lxdream/src</tt></b></td></tr>
<tr><td><tt>drivers/<a href="#file1">gl_fbo.c</a></tt></td><td id="added" class="headtd2" style="padding-left:.3em;padding-right:.3em; background-color:#ddffdd;" align="right">+19</td><td id="removed" class="headtd2" style="padding-left:.3em;padding-right:.3em; background-color:#ffdddd;" align="right">-10</td><td class="headtd2" style="padding-left:.3em;padding-right:.3em;" nowrap="nowrap">13406c35849b -> f405d42a9786</td></tr>
<tr class="alt" style=";" ><td><tt>pvr2/<a href="#file2">gl_sl.c</a></tt></td><td id="addedalt" class="headtd2" style="padding-left:.3em;padding-right:.3em; background-color:#ccf7cc;" align="right">+7</td><td id="removed" class="headtd2" style="padding-left:.3em;padding-right:.3em; background-color:#ffdddd;" align="right">-1</td><td class="headtd2" style="padding-left:.3em;padding-right:.3em;" nowrap="nowrap">13406c35849b -> f405d42a9786</td></tr>
<tr><td></td><td id="added" class="headtd2" style="padding-left:.3em;padding-right:.3em; background-color:#ddffdd;" align="right">+26</td><td id="removed" class="headtd2" style="padding-left:.3em;padding-right:.3em; background-color:#ffdddd;" align="right">-11</td><td></td></tr>
</table>
<small id="info" style="color: #888888;" >2 modified files</small><br />
<pre class="comment" style="white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;padding:4px;border:1px dashed #000000;background-color:#ffffdd;" >
Perform the sanity checks for FBOs and shaders up front rather than on every
use, and remove surplus glGetError() calls
</pre>
<hr /><a name="file1" /><div class="file" style="border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;" >
<span class="pathname" style="font-family:monospace; float:right;" >lxdream/src/drivers</span><br />
<div class="fileheader" style="margin-bottom:.5em;" ><big><b>gl_fbo.c</b></big> <small id="info" style="color: #888888;" >13406c35849b -> f405d42a9786</small></div>
<pre class="diff" style="margin:0;" ><small id="info" style="color: #888888;" >--- lxdream/src/drivers/gl_fbo.c
+++ lxdream/src/drivers/gl_fbo.c
@@ -42,6 +42,7 @@
</small></pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" > static void gl_fbo_display_render_buffer( render_buffer_t buffer );
 static void gl_fbo_load_frame_buffer( frame_buffer_t frame, render_buffer_t buffer );
 static void gl_fbo_display_blank( uint32_t colour );
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" >+static gboolean gl_fbo_test_framebuffer( );
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" > static gboolean gl_fbo_read_render_buffer( unsigned char *target, render_buffer_t buffer, int rowstride, int format );
 
 extern uint32_t video_width, video_height;
</pre><pre class="diff" style="margin:0;" ><small id="info" style="color: #888888;" >@@ -112,6 +113,7 @@
</small></pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >     driver->display_blank = gl_fbo_display_blank;
     driver->read_render_buffer = gl_fbo_read_render_buffer;
 
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" >+    gl_fbo_test_framebuffer();
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
 }
 
</pre><pre class="diff" style="margin:0;" ><small id="info" style="color: #888888;" >@@ -214,18 +216,27 @@
</small></pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >     glDrawBuffer(ATTACHMENT_POINT(attach));
     glReadBuffer(ATTACHMENT_POINT(attach)); 
 
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" >+    return ATTACHMENT_POINT(attach);
+}
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" > 
</pre><pre id="removed" class="diff" style="margin:0; background-color:#ffdddd;" >-    GLint status = glGetError();
-    if( status != GL_NO_ERROR ) {
-        ERROR( "GL error setting render target (%x)!", status );
-    }
-    status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" >+static gboolean gl_fbo_test_framebuffer( )
+{
+    gboolean result = TRUE;
+    glGetError(); /* Clear error state just in case */
+    render_buffer_t buffer = gl_fbo_create_render_buffer( 640, 480, 0 );
+    gl_fbo_set_render_target(buffer);
+
+    GLint status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >     if( status != GL_FRAMEBUFFER_COMPLETE_EXT ) {
         ERROR( "Framebuffer failure: %x", status );
</pre><pre id="removed" class="diff" style="margin:0; background-color:#ffdddd;" >-        exit(1);
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" >+        result = FALSE;
+    }
+    if( result ) {
+        result = gl_check_error( "Setting up framebuffer" );
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >     }
 
</pre><pre id="removed" class="diff" style="margin:0; background-color:#ffdddd;" >-    return ATTACHMENT_POINT(attach);
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" >+    gl_fbo_destroy_render_buffer( buffer );
+    return result;
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" > }
 
 static render_buffer_t gl_fbo_create_render_buffer( uint32_t width, uint32_t height, GLuint tex_id )
</pre><pre class="diff" style="margin:0;" ><small id="info" style="color: #888888;" >@@ -294,7 +305,6 @@
</small></pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" > 
 static gboolean gl_fbo_set_render_target( render_buffer_t buffer )
 {
</pre><pre id="removed" class="diff" style="margin:0; background-color:#ffdddd;" >-    glGetError();
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >     int fb = gl_fbo_get_framebuffer( buffer->width, buffer->height );
     gl_fbo_attach_texture( fb, buffer->buf_id );
     /* setup the gl context */
</pre><pre class="diff" style="margin:0;" ><small id="info" style="color: #888888;" >@@ -306,7 +316,6 @@
</small></pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" > static void gl_fbo_finish_render( render_buffer_t buffer )
 {
     glFinish();
</pre><pre id="removed" class="diff" style="margin:0; background-color:#ffdddd;" >-    glGetError();
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >     gl_fbo_detach_render_buffer(buffer);
 }
 
</pre><pre class="diff" style="margin:0;" ><small id="info" style="color: #888888;" >@@ -338,12 +347,12 @@
</small></pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >     /* Make sure texture attachment is not a current draw/read buffer */
     glDrawBuffer( GL_FRONT );
     glReadBuffer( GL_FRONT );
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" >+    display_driver->swap_buffers();
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" > }    
 
 static gboolean gl_fbo_read_render_buffer( unsigned char *target, render_buffer_t buffer, 
                                            int rowstride, int format )
 {
</pre><pre id="removed" class="diff" style="margin:0; background-color:#ffdddd;" >-    glGetError();
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >     int fb = gl_fbo_get_framebuffer( buffer->width, buffer->height );
     gl_fbo_attach_texture( fb, buffer->buf_id );
     return gl_read_render_buffer( target, buffer, rowstride, format );
</pre></div>
<hr /><a name="file2" /><div class="file" style="border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;" >
<span class="pathname" style="font-family:monospace; float:right;" >lxdream/src/pvr2</span><br />
<div class="fileheader" style="margin-bottom:.5em;" ><big><b>gl_sl.c</b></big> <small id="info" style="color: #888888;" >13406c35849b -> f405d42a9786</small></div>
<pre class="diff" style="margin:0;" ><small id="info" style="color: #888888;" >--- lxdream/src/pvr2/gl_sl.c
+++ lxdream/src/pvr2/gl_sl.c
@@ -139,7 +139,6 @@
</small></pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" > void glsl_use_program(gl_program_t program)
 {
     glUseProgramObjectARB(program);
</pre><pre id="removed" class="diff" style="margin:0; background-color:#ffdddd;" >-    glsl_check_program_error( "Failed to activate shader program", program );
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" > }
 
 void glsl_destroy_shader(gl_shader_t shader)
</pre><pre class="diff" style="margin:0;" ><small id="info" style="color: #888888;" >@@ -376,6 +375,11 @@
</small></pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >             ok = FALSE;
             break;
         } else {
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" >+            /* Check that we can actually use the program (can this really fail?) */
+            glsl_use_program(program);
+            if( !glsl_check_program_error( "Failed to activate shader program", program ) ) {
+                ok = FALSE;
+            }
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >             program_array[i] = program;
         }
     }
</pre><pre class="diff" style="margin:0;" ><small id="info" style="color: #888888;" >@@ -396,6 +400,8 @@
</small></pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >         glsl_unload_shaders();
         return FALSE;
     }
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" >+    
+    glsl_use_program(0);
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >     return TRUE;
 }
 
</pre></div>
<center><small>Chaos Theory</small></center>
</div></body></html>