Search
lxdream.org :: lxdream :: r1166:f405d42a9786
lxdream 0.9.1
released Jun 29
Download Now
changeset1166:f405d42a9786
parent1165:13406c35849b
child1167:2cc6c50d0dd2
authornkeynes
dateFri Jan 28 16:14:57 2011 +1000 (8 years ago)
Perform the sanity checks for FBOs and shaders up front rather than on every
use, and remove surplus glGetError() calls
src/drivers/gl_fbo.c
src/pvr2/gl_sl.c
1.1 --- a/src/drivers/gl_fbo.c Fri Jan 28 15:58:34 2011 +1000
1.2 +++ b/src/drivers/gl_fbo.c Fri Jan 28 16:14:57 2011 +1000
1.3 @@ -42,6 +42,7 @@
1.4 static void gl_fbo_display_render_buffer( render_buffer_t buffer );
1.5 static void gl_fbo_load_frame_buffer( frame_buffer_t frame, render_buffer_t buffer );
1.6 static void gl_fbo_display_blank( uint32_t colour );
1.7 +static gboolean gl_fbo_test_framebuffer( );
1.8 static gboolean gl_fbo_read_render_buffer( unsigned char *target, render_buffer_t buffer, int rowstride, int format );
1.9
1.10 extern uint32_t video_width, video_height;
1.11 @@ -112,6 +113,7 @@
1.12 driver->display_blank = gl_fbo_display_blank;
1.13 driver->read_render_buffer = gl_fbo_read_render_buffer;
1.14
1.15 + gl_fbo_test_framebuffer();
1.16 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
1.17 }
1.18
1.19 @@ -214,18 +216,27 @@
1.20 glDrawBuffer(ATTACHMENT_POINT(attach));
1.21 glReadBuffer(ATTACHMENT_POINT(attach));
1.22
1.23 + return ATTACHMENT_POINT(attach);
1.24 +}
1.25
1.26 - GLint status = glGetError();
1.27 - if( status != GL_NO_ERROR ) {
1.28 - ERROR( "GL error setting render target (%x)!", status );
1.29 - }
1.30 - status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
1.31 +static gboolean gl_fbo_test_framebuffer( )
1.32 +{
1.33 + gboolean result = TRUE;
1.34 + glGetError(); /* Clear error state just in case */
1.35 + render_buffer_t buffer = gl_fbo_create_render_buffer( 640, 480, 0 );
1.36 + gl_fbo_set_render_target(buffer);
1.37 +
1.38 + GLint status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
1.39 if( status != GL_FRAMEBUFFER_COMPLETE_EXT ) {
1.40 ERROR( "Framebuffer failure: %x", status );
1.41 - exit(1);
1.42 + result = FALSE;
1.43 + }
1.44 + if( result ) {
1.45 + result = gl_check_error( "Setting up framebuffer" );
1.46 }
1.47
1.48 - return ATTACHMENT_POINT(attach);
1.49 + gl_fbo_destroy_render_buffer( buffer );
1.50 + return result;
1.51 }
1.52
1.53 static render_buffer_t gl_fbo_create_render_buffer( uint32_t width, uint32_t height, GLuint tex_id )
1.54 @@ -294,7 +305,6 @@
1.55
1.56 static gboolean gl_fbo_set_render_target( render_buffer_t buffer )
1.57 {
1.58 - glGetError();
1.59 int fb = gl_fbo_get_framebuffer( buffer->width, buffer->height );
1.60 gl_fbo_attach_texture( fb, buffer->buf_id );
1.61 /* setup the gl context */
1.62 @@ -306,7 +316,6 @@
1.63 static void gl_fbo_finish_render( render_buffer_t buffer )
1.64 {
1.65 glFinish();
1.66 - glGetError();
1.67 gl_fbo_detach_render_buffer(buffer);
1.68 }
1.69
1.70 @@ -338,12 +347,12 @@
1.71 /* Make sure texture attachment is not a current draw/read buffer */
1.72 glDrawBuffer( GL_FRONT );
1.73 glReadBuffer( GL_FRONT );
1.74 + display_driver->swap_buffers();
1.75 }
1.76
1.77 static gboolean gl_fbo_read_render_buffer( unsigned char *target, render_buffer_t buffer,
1.78 int rowstride, int format )
1.79 {
1.80 - glGetError();
1.81 int fb = gl_fbo_get_framebuffer( buffer->width, buffer->height );
1.82 gl_fbo_attach_texture( fb, buffer->buf_id );
1.83 return gl_read_render_buffer( target, buffer, rowstride, format );
2.1 --- a/src/pvr2/gl_sl.c Fri Jan 28 15:58:34 2011 +1000
2.2 +++ b/src/pvr2/gl_sl.c Fri Jan 28 16:14:57 2011 +1000
2.3 @@ -139,7 +139,6 @@
2.4 void glsl_use_program(gl_program_t program)
2.5 {
2.6 glUseProgramObjectARB(program);
2.7 - glsl_check_program_error( "Failed to activate shader program", program );
2.8 }
2.9
2.10 void glsl_destroy_shader(gl_shader_t shader)
2.11 @@ -376,6 +375,11 @@
2.12 ok = FALSE;
2.13 break;
2.14 } else {
2.15 + /* Check that we can actually use the program (can this really fail?) */
2.16 + glsl_use_program(program);
2.17 + if( !glsl_check_program_error( "Failed to activate shader program", program ) ) {
2.18 + ok = FALSE;
2.19 + }
2.20 program_array[i] = program;
2.21 }
2.22 }
2.23 @@ -396,6 +400,8 @@
2.24 glsl_unload_shaders();
2.25 return FALSE;
2.26 }
2.27 +
2.28 + glsl_use_program(0);
2.29 return TRUE;
2.30 }
2.31
.