Search
lxdream.org :: lxdream :: r798:eb5c0d1863cd
lxdream 0.9.1
released Jun 29
Download Now
changeset798:eb5c0d1863cd
parent797:3bb52a384b64
child799:8aeb9906d7b9
authornkeynes
dateSun Aug 03 02:55:27 2008 +0000 (12 years ago)
Check the MAX_COLOR_ATTACHMENTS value rather than assuming it's at least 4, since
it may in fact be less.
src/drivers/gl_fbo.c
1.1 --- a/src/drivers/gl_fbo.c Fri Aug 01 03:58:25 2008 +0000
1.2 +++ b/src/drivers/gl_fbo.c Sun Aug 03 02:55:27 2008 +0000
1.3 @@ -33,7 +33,7 @@
1.4 #ifdef HAVE_OPENGL_FBO
1.5
1.6 #define MAX_FRAMEBUFFERS 2
1.7 -#define MAX_TEXTURES_PER_FB 4
1.8 +#define MAX_TEXTURES_PER_FB 16
1.9
1.10 static render_buffer_t gl_fbo_create_render_buffer( uint32_t width, uint32_t height );
1.11 static void gl_fbo_destroy_render_buffer( render_buffer_t buffer );
1.12 @@ -56,10 +56,10 @@
1.13 int width, height;
1.14 };
1.15
1.16 +static GLint gl_fbo_max_attachments = 0;
1.17 static struct gl_fbo_info fbo[MAX_FRAMEBUFFERS];
1.18 -const static int ATTACHMENT_POINTS[MAX_TEXTURES_PER_FB] = {
1.19 - GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT,
1.20 - GL_COLOR_ATTACHMENT2_EXT, GL_COLOR_ATTACHMENT3_EXT };
1.21 +
1.22 +#define ATTACHMENT_POINT(n) (GL_COLOR_ATTACHMENT0_EXT+(n))
1.23 static int last_used_fbo;
1.24
1.25 gboolean gl_fbo_is_supported()
1.26 @@ -77,6 +77,7 @@
1.27 GLuint fbids[MAX_FRAMEBUFFERS];
1.28 GLuint rbids[MAX_FRAMEBUFFERS*2]; /* depth buffer, stencil buffer per fb */
1.29
1.30 + glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &gl_fbo_max_attachments);
1.31 glGenFramebuffersEXT( MAX_FRAMEBUFFERS, &fbids[0] );
1.32 glGenRenderbuffersEXT( MAX_FRAMEBUFFERS*2, &rbids[0] );
1.33 for( i=0; i<MAX_FRAMEBUFFERS; i++ ) {
1.34 @@ -164,26 +165,25 @@
1.35 */
1.36 static GLint gl_fbo_attach_texture( int fbo_no, GLint tex_id ) {
1.37 int attach = -1, i;
1.38 - for( i=0; i<MAX_TEXTURES_PER_FB; i++ ) {
1.39 + for( i=0; i<gl_fbo_max_attachments; i++ ) {
1.40 if( fbo[fbo_no].tex_ids[i] == tex_id ) {
1.41 - glDrawBuffer(ATTACHMENT_POINTS[i]);
1.42 - glReadBuffer(ATTACHMENT_POINTS[i]);
1.43 - return ATTACHMENT_POINTS[i]; // already attached
1.44 + glDrawBuffer(ATTACHMENT_POINT(i));
1.45 + glReadBuffer(ATTACHMENT_POINT(i));
1.46 + return ATTACHMENT_POINT(i); // already attached
1.47 } else if( fbo[fbo_no].tex_ids[i] == -1 && attach == -1 ) {
1.48 attach = i;
1.49 }
1.50 }
1.51 if( attach == -1 ) {
1.52 - /* should never happen */
1.53 attach = 0;
1.54 }
1.55 fbo[fbo_no].tex_ids[attach] = tex_id;
1.56 glBindTexture( GL_TEXTURE_RECTANGLE_ARB, 0 ); // Ensure the output texture is unbound
1.57 - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, ATTACHMENT_POINTS[attach],
1.58 + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, ATTACHMENT_POINT(attach),
1.59 GL_TEXTURE_RECTANGLE_ARB, tex_id, 0 );
1.60 /* Set draw/read buffers by default */
1.61 - glDrawBuffer(ATTACHMENT_POINTS[attach]);
1.62 - glReadBuffer(ATTACHMENT_POINTS[attach]);
1.63 + glDrawBuffer(ATTACHMENT_POINT(attach));
1.64 + glReadBuffer(ATTACHMENT_POINT(attach));
1.65
1.66
1.67 GLint status = glGetError();
1.68 @@ -196,7 +196,7 @@
1.69 exit(1);
1.70 }
1.71
1.72 - return ATTACHMENT_POINTS[attach];
1.73 + return ATTACHMENT_POINT(attach);
1.74 }
1.75
1.76 static render_buffer_t gl_fbo_create_render_buffer( uint32_t width, uint32_t height )
1.77 @@ -224,7 +224,7 @@
1.78 for( j=0; j < MAX_TEXTURES_PER_FB; j++ ) {
1.79 if( fbo[i].tex_ids[j] == buffer->buf_id ) {
1.80 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo[i].fb_id);
1.81 - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, ATTACHMENT_POINTS[j],
1.82 + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, ATTACHMENT_POINT(j),
1.83 GL_TEXTURE_RECTANGLE_ARB, GL_NONE, 0 );
1.84 fbo[i].tex_ids[j] = -1;
1.85 }
.