Search
lxdream.org :: lxdream/src/drivers/gl_fbo.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/gl_fbo.c
changeset 736:a02d1475ccfd
prev669:ab344e42bca9
next758:99ae000d4e09
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (14 years ago)
permissions -rw-r--r--
last change Re-indent everything consistently
Fix include guards for consistency as well
file annotate diff log raw
1.1 --- a/src/drivers/gl_fbo.c Mon May 12 10:00:13 2008 +0000
1.2 +++ b/src/drivers/gl_fbo.c Mon Jul 14 07:44:42 2008 +0000
1.3 @@ -58,8 +58,8 @@
1.4
1.5 static struct gl_fbo_info fbo[MAX_FRAMEBUFFERS];
1.6 const static int ATTACHMENT_POINTS[MAX_TEXTURES_PER_FB] = {
1.7 - GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT,
1.8 - GL_COLOR_ATTACHMENT2_EXT, GL_COLOR_ATTACHMENT3_EXT };
1.9 + GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT,
1.10 + GL_COLOR_ATTACHMENT2_EXT, GL_COLOR_ATTACHMENT3_EXT };
1.11 static int last_used_fbo;
1.12
1.13 gboolean gl_fbo_is_supported()
1.14 @@ -76,18 +76,18 @@
1.15 int i,j;
1.16 GLuint fbids[MAX_FRAMEBUFFERS];
1.17 GLuint rbids[MAX_FRAMEBUFFERS*2]; /* depth buffer, stencil buffer per fb */
1.18 -
1.19 +
1.20 glGenFramebuffersEXT( MAX_FRAMEBUFFERS, &fbids[0] );
1.21 glGenRenderbuffersEXT( MAX_FRAMEBUFFERS*2, &rbids[0] );
1.22 for( i=0; i<MAX_FRAMEBUFFERS; i++ ) {
1.23 - fbo[i].fb_id = fbids[i];
1.24 - fbo[i].depth_id = rbids[i*2];
1.25 - fbo[i].stencil_id = rbids[i*2+1];
1.26 - fbo[i].width = -1;
1.27 - fbo[i].height = -1;
1.28 - for( j=0; j<MAX_TEXTURES_PER_FB; j++ ) {
1.29 - fbo[i].tex_ids[j] = -1;
1.30 - }
1.31 + fbo[i].fb_id = fbids[i];
1.32 + fbo[i].depth_id = rbids[i*2];
1.33 + fbo[i].stencil_id = rbids[i*2+1];
1.34 + fbo[i].width = -1;
1.35 + fbo[i].height = -1;
1.36 + for( j=0; j<MAX_TEXTURES_PER_FB; j++ ) {
1.37 + fbo[i].tex_ids[j] = -1;
1.38 + }
1.39 }
1.40 last_used_fbo = 0;
1.41
1.42 @@ -109,8 +109,8 @@
1.43 int i;
1.44 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );
1.45 for( i=0; i<MAX_FRAMEBUFFERS; i++ ) {
1.46 - glDeleteFramebuffersEXT( 1, &fbo[i].fb_id );
1.47 - glDeleteRenderbuffersEXT( 2, &fbo[i].depth_id );
1.48 + glDeleteFramebuffersEXT( 1, &fbo[i].fb_id );
1.49 + glDeleteRenderbuffersEXT( 2, &fbo[i].depth_id );
1.50 }
1.51 }
1.52
1.53 @@ -120,13 +120,13 @@
1.54 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo[bufno].depth_id);
1.55 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, width, height);
1.56 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
1.57 - GL_RENDERBUFFER_EXT, fbo[bufno].depth_id);
1.58 + GL_RENDERBUFFER_EXT, fbo[bufno].depth_id);
1.59 /* Stencil doesn't work on ATI, and we're not using it at the moment anyway, so...
1.60 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo[bufno].stencil_id);
1.61 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_STENCIL_INDEX, width, height);
1.62 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
1.63 GL_RENDERBUFFER_EXT, fbo[bufno].stencil_id);
1.64 - */
1.65 + */
1.66 fbo[bufno].width = width;
1.67 fbo[bufno].height = height;
1.68 }
1.69 @@ -136,24 +136,24 @@
1.70 int bufno = -1, i;
1.71 /* find a compatible framebuffer context */
1.72 for( i=0; i<MAX_FRAMEBUFFERS; i++ ) {
1.73 - if( fbo[i].width == -1 && bufno == -1 ) {
1.74 - bufno = i;
1.75 - } else if( fbo[i].width == width && fbo[i].height == height ) {
1.76 - bufno = i;
1.77 - break;
1.78 - }
1.79 + if( fbo[i].width == -1 && bufno == -1 ) {
1.80 + bufno = i;
1.81 + } else if( fbo[i].width == width && fbo[i].height == height ) {
1.82 + bufno = i;
1.83 + break;
1.84 + }
1.85 }
1.86 if( bufno == -1 ) {
1.87 - bufno = last_used_fbo + 1;
1.88 - if( bufno > MAX_FRAMEBUFFERS ) {
1.89 - bufno = 0;
1.90 - }
1.91 - last_used_fbo = bufno;
1.92 + bufno = last_used_fbo + 1;
1.93 + if( bufno > MAX_FRAMEBUFFERS ) {
1.94 + bufno = 0;
1.95 + }
1.96 + last_used_fbo = bufno;
1.97 }
1.98 if( fbo[bufno].width == width && fbo[bufno].height == height ) {
1.99 - glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fbo[bufno].fb_id );
1.100 + glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fbo[bufno].fb_id );
1.101 } else {
1.102 - gl_fbo_setup_framebuffer( bufno, width, height );
1.103 + gl_fbo_setup_framebuffer( bufno, width, height );
1.104 }
1.105 return bufno;
1.106 }
1.107 @@ -165,22 +165,22 @@
1.108 static GLint gl_fbo_attach_texture( int fbo_no, GLint tex_id ) {
1.109 int attach = -1, i;
1.110 for( i=0; i<MAX_TEXTURES_PER_FB; i++ ) {
1.111 - if( fbo[fbo_no].tex_ids[i] == tex_id ) {
1.112 - glDrawBuffer(ATTACHMENT_POINTS[i]);
1.113 - glReadBuffer(ATTACHMENT_POINTS[i]);
1.114 - return ATTACHMENT_POINTS[i]; // already attached
1.115 - } else if( fbo[fbo_no].tex_ids[i] == -1 && attach == -1 ) {
1.116 - attach = i;
1.117 - }
1.118 + if( fbo[fbo_no].tex_ids[i] == tex_id ) {
1.119 + glDrawBuffer(ATTACHMENT_POINTS[i]);
1.120 + glReadBuffer(ATTACHMENT_POINTS[i]);
1.121 + return ATTACHMENT_POINTS[i]; // already attached
1.122 + } else if( fbo[fbo_no].tex_ids[i] == -1 && attach == -1 ) {
1.123 + attach = i;
1.124 + }
1.125 }
1.126 if( attach == -1 ) {
1.127 - /* should never happen */
1.128 - attach = 0;
1.129 + /* should never happen */
1.130 + attach = 0;
1.131 }
1.132 fbo[fbo_no].tex_ids[attach] = tex_id;
1.133 glBindTexture( GL_TEXTURE_RECTANGLE_ARB, 0 ); // Ensure the output texture is unbound
1.134 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, ATTACHMENT_POINTS[attach],
1.135 - GL_TEXTURE_RECTANGLE_ARB, tex_id, 0 );
1.136 + GL_TEXTURE_RECTANGLE_ARB, tex_id, 0 );
1.137 /* Set draw/read buffers by default */
1.138 glDrawBuffer(ATTACHMENT_POINTS[attach]);
1.139 glReadBuffer(ATTACHMENT_POINTS[attach]);
1.140 @@ -188,12 +188,12 @@
1.141
1.142 GLint status = glGetError();
1.143 if( status != GL_NO_ERROR ) {
1.144 - ERROR( "GL error setting render target (%x)!", status );
1.145 + ERROR( "GL error setting render target (%x)!", status );
1.146 }
1.147 status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
1.148 if( status != GL_FRAMEBUFFER_COMPLETE_EXT ) {
1.149 - ERROR( "Framebuffer failure: %x", status );
1.150 - exit(1);
1.151 + ERROR( "Framebuffer failure: %x", status );
1.152 + exit(1);
1.153 }
1.154
1.155 return ATTACHMENT_POINTS[attach];
1.156 @@ -218,16 +218,16 @@
1.157 {
1.158 int i,j;
1.159 for( i=0; i<MAX_FRAMEBUFFERS; i++ ) {
1.160 - for( j=0; j < MAX_TEXTURES_PER_FB; j++ ) {
1.161 - if( fbo[i].tex_ids[j] == buffer->buf_id ) {
1.162 - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo[i].fb_id);
1.163 - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, ATTACHMENT_POINTS[j],
1.164 - GL_TEXTURE_RECTANGLE_ARB, GL_NONE, 0 );
1.165 - fbo[i].tex_ids[j] = -1;
1.166 - }
1.167 - }
1.168 + for( j=0; j < MAX_TEXTURES_PER_FB; j++ ) {
1.169 + if( fbo[i].tex_ids[j] == buffer->buf_id ) {
1.170 + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo[i].fb_id);
1.171 + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, ATTACHMENT_POINTS[j],
1.172 + GL_TEXTURE_RECTANGLE_ARB, GL_NONE, 0 );
1.173 + fbo[i].tex_ids[j] = -1;
1.174 + }
1.175 + }
1.176 }
1.177 -
1.178 +
1.179 glDeleteTextures( 1, &buffer->buf_id );
1.180 buffer->buf_id = 0;
1.181 free( buffer );
1.182 @@ -241,7 +241,7 @@
1.183 gl_fbo_attach_texture( fb, buffer->buf_id );
1.184 /* setup the gl context */
1.185 glViewport( 0, 0, buffer->width, buffer->height );
1.186 -
1.187 +
1.188 return TRUE;
1.189 }
1.190
1.191 @@ -278,7 +278,7 @@
1.192 }
1.193
1.194 static gboolean gl_fbo_read_render_buffer( unsigned char *target, render_buffer_t buffer,
1.195 - int rowstride, int format )
1.196 + int rowstride, int format )
1.197 {
1.198 int fb = gl_fbo_get_framebuffer( buffer->width, buffer->height );
1.199 gl_fbo_attach_texture( fb, buffer->buf_id );
.