![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsGLEXTFrameBufferObject.cpp 00003 ******************************************************************************/ 00009 /****************************************************************************** 00010 SUKITTI PUNAK (10/27/2006) 00011 UPDATE (11/03/2006) 00012 ******************************************************************************/ 00013 #include "TAPsGLEXTFrameBufferObject.hpp" 00014 // Using Inclusion Model (i.e. definitions are included in declarations) 00015 // (this name.cpp is included in name.hpp) 00016 // Each friend is defined directly inside its declaration. 00017 00018 BEGIN_NAMESPACE_TAPs__OpenGL 00019 //============================================================================= 00020 // Global Variables 00021 //----------------------------------------------------------------------------- 00022 // empty! 00023 //----------------------------------------------------------------------------- 00024 //============================================================================= 00025 //----------------------------------------------------------------------------- 00026 // Static Variable(s) 00027 unsigned int GLEXTFrameBufferObject::g_uiObjCounters = 0; 00028 //----------------------------------------------------------------------------- 00029 // Constructor 00030 GLEXTFrameBufferObject::GLEXTFrameBufferObject ( 00031 BufferType eBufferType, GLuint gluiSize ) 00032 : m_eBufferType( eBufferType ), m_gluiSize( gluiSize ), 00033 m_pgluiID( NULL ), m_pgluiID_StackValue( NULL ) 00034 { 00035 switch ( m_eBufferType ) { 00036 case FRAME_BUFFER: 00037 GenFrameBuffers(); 00038 break; 00039 //case TEXTURE_BUFFER: 00040 // break; 00041 case RENDER_BUFFER: 00042 GenRenderBuffers(); 00043 break; 00044 } 00045 //--------------------------------------------------------------- 00046 ++g_uiObjCounters; 00047 } 00048 //----------------------------------------------------------------------------- 00049 // Destructor 00050 GLEXTFrameBufferObject::~GLEXTFrameBufferObject () 00051 { 00052 switch ( m_eBufferType ) { 00053 case FRAME_BUFFER: 00054 DeleteFrameBuffers(); 00055 break; 00056 //case TEXTURE_BUFFER: 00057 // break; 00058 case RENDER_BUFFER: 00059 DeleteRenderBuffers(); 00060 break; 00061 } 00062 //--------------------------------------------------------------- 00063 delete [] m_pgluiID; 00064 delete [] m_pgluiID_StackValue; 00065 --g_uiObjCounters; 00066 } 00067 //----------------------------------------------------------------------------- 00068 //============================================================================= 00069 //***************************************************************************** 00070 //============================================================================= 00071 //----------------------------------------------------------------------------- 00072 void GLEXTFrameBufferObject::AttachTextureBuffer ( 00073 GLuint i, 00074 GLenum attachment, 00075 GLenum textarget, 00076 GLuint texture, 00077 GLint level, 00078 GLint zoffset ) 00079 { 00080 assert( i < GetSize() ); 00081 assert( m_eBufferType == FRAME_BUFFER ); 00082 //--------------------------------------------------------------- 00083 ProtectedBindFrameBuffer( i ); 00084 //--------------------------------------------------------------- 00085 #ifdef TAPs_DEBUG_MODE 00086 // Get Attached ID 00087 GLint id = GetFrameBufferAttachmentParameter( 00088 i, attachment, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 00089 ); 00090 if ( id != m_pgluiID[i] ) { 00091 #endif 00092 //--------------------------------------------------------------- 00093 switch ( textarget ) { 00094 case GL_TEXTURE_2D: 00095 FrameBufferTexture2D( attachment, textarget, texture, level ); 00096 break; 00097 case GL_TEXTURE_3D: 00098 FrameBufferTexture3D( attachment, textarget, texture, level, zoffset ); 00099 break; 00100 case GL_TEXTURE_1D: 00101 FrameBufferTexture1D( attachment, textarget, texture, level ); 00102 break; 00103 } 00104 //--------------------------------------------------------------- 00105 #ifdef TAPs_DEBUG_MODE 00106 } 00107 #endif 00108 //--------------------------------------------------------------- 00109 ProtectedUnbindFrameBuffer( i ); 00110 } 00111 //----------------------------------------------------------------------------- 00112 void GLEXTFrameBufferObject::AttachRenderBuffer ( 00113 GLuint i, GLenum attachment, GLuint renderbufferID ) 00114 { 00115 assert( i < GetSize() ); 00116 assert( m_eBufferType == FRAME_BUFFER ); 00117 //--------------------------------------------------------------- 00118 ProtectedBindFrameBuffer( i ); 00119 //--------------------------------------------------------------- 00120 #ifdef TAPs_DEBUG_MODE 00121 // Get Attached ID 00122 GLint id = GetFrameBufferAttachmentParameter( 00123 i, attachment, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 00124 ); 00125 if ( id != m_pgluiID[i] ) { 00126 #endif 00127 //--------------------------------------------------------------- 00128 FrameBufferRenderBuffer( attachment, renderbufferID ); 00129 //--------------------------------------------------------------- 00130 #ifdef TAPs_DEBUG_MODE 00131 } 00132 #endif 00133 //--------------------------------------------------------------- 00134 ProtectedUnbindFrameBuffer( i ); 00135 } 00136 //----------------------------------------------------------------------------- 00137 //void GLEXTFrameBufferObject::Unattach ( GLenum attachment ) 00138 //{} 00139 //----------------------------------------------------------------------------- 00140 //============================================================================= 00141 //***************************************************************************** 00142 //============================================================================= 00143 // Render Buffer Object 00144 //--------------------------------------------------------- 00145 bool GLEXTFrameBufferObject::IsRenderBuffer ( GLuint i ) 00146 { 00147 assert( i < GetSize() ); 00148 if ( glIsRenderbufferEXT( m_pgluiID[i] ) == GL_TRUE ) 00149 return true; 00150 return false; 00151 } 00152 //--------------------------------------------------------- 00153 void GLEXTFrameBufferObject::BindRenderBuffer ( GLuint i ) 00154 { 00155 assert( i < GetSize() ); 00156 assert( m_eBufferType == RENDER_BUFFER ); 00157 assert( m_pgluiID != NULL ); 00158 glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, m_pgluiID[i] ); 00159 } 00160 //--------------------------------------------------------- 00161 void GLEXTFrameBufferObject::DeleteRenderBuffers () 00162 { 00163 assert( m_eBufferType == RENDER_BUFFER ); 00164 assert( m_pgluiID != NULL ); 00165 glDeleteRenderbuffersEXT( m_gluiSize, m_pgluiID ); 00166 } 00167 //--------------------------------------------------------- 00168 void GLEXTFrameBufferObject::GenRenderBuffers () 00169 { 00170 if ( m_pgluiID != NULL ) { 00171 delete [] m_pgluiID; 00172 delete [] m_pgluiID_StackValue; 00173 } 00174 //------------------------------------------- 00175 m_pgluiID = new GLuint[ m_gluiSize ]; 00176 m_pgluiID_StackValue = new GLuint[ m_gluiSize ]; 00177 //------------------------------------------- 00178 glGenRenderbuffersEXT( m_gluiSize, m_pgluiID ); 00179 } 00180 //--------------------------------------------------------- 00181 void GLEXTFrameBufferObject::RenderBufferStorage ( GLuint i, 00182 GLenum internalformat, GLsizei width, GLsizei height ) 00183 { 00184 //--------------------------------------------------------------- 00185 // Check againt max size 00186 GLint maxSize = InquireMaxRenderBufferSize(); 00187 if ( width > maxSize || height > maxSize ) { 00188 return; 00189 #ifdef TAPs_USE_WXWIDGETS 00190 wxLogError( wxT( 00191 "ERROR: GLEXTFrameBufferObject::RenderBufferStorage(): \ 00192 Max size (%d) is less than width (%d) and/or height (%d)!" ), 00193 maxSize, width, height ); 00194 #else 00195 std::cerr << "ERROR: GLEXTFrameBufferObject::RenderBufferStorage(): " 00196 << "Max size (" << maxSize << ") is less than width (" 00197 << width << ") and/or height (" << height << ")!" 00198 << std::endl; 00199 #endif 00200 return; 00201 } 00202 //--------------------------------------------------------------- 00203 ProtectedBindRenderBuffer( i ); 00204 //--------------------------------------------------------------- 00205 glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, internalformat, width, height ); 00206 //--------------------------------------------------------------- 00207 ProtectedUnbindRenderBuffer( i ); 00208 //--------------------------------------------------------------- 00209 } 00210 //--------------------------------------------------------- 00211 void GLEXTFrameBufferObject::GetRenderBufferParameter () 00212 { 00213 00214 } 00215 //----------------------------------------------------------------------------- 00216 //============================================================================= 00217 //***************************************************************************** 00218 //============================================================================= 00219 // Frame Buffer Object 00220 //----------------------------------------------------------------------------- 00221 bool GLEXTFrameBufferObject::IsFrameBuffer ( GLuint i ) 00222 { 00223 assert( i < GetSize() ); 00224 if ( glIsFramebufferEXT( m_pgluiID[i] ) == GL_TRUE ) 00225 return true; 00226 return false; 00227 } 00228 //--------------------------------------------------------- 00229 void GLEXTFrameBufferObject::BindFrameBuffer ( GLuint i ) 00230 { 00231 assert( i < GetSize() ); 00232 assert( m_eBufferType == FRAME_BUFFER ); 00233 assert( m_pgluiID != NULL ); 00234 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_pgluiID[i] ); 00235 } 00236 //--------------------------------------------------------- 00237 void GLEXTFrameBufferObject::DeleteFrameBuffers () 00238 { 00239 assert( m_eBufferType == FRAME_BUFFER ); 00240 assert( m_pgluiID != NULL ); 00241 glDeleteFramebuffersEXT( m_gluiSize, m_pgluiID ); 00242 } 00243 //--------------------------------------------------------- 00244 void GLEXTFrameBufferObject::GenFrameBuffers () 00245 { 00246 if ( m_pgluiID != NULL ) { 00247 delete [] m_pgluiID; 00248 delete [] m_pgluiID_StackValue; 00249 } 00250 //------------------------------------------- 00251 m_pgluiID = new GLuint[ m_gluiSize ]; 00252 m_pgluiID_StackValue = new GLuint[ m_gluiSize ]; 00253 //------------------------------------------- 00254 glGenFramebuffersEXT( m_gluiSize, m_pgluiID ); 00255 } 00256 //----------------------------------------------------------------------------- 00257 //============================================================================= 00258 //***************************************************************************** 00259 //============================================================================= 00260 //----------------------------------------------------------------------------- 00261 #ifndef TAPs_DEBUG_MODE 00262 bool GLEXTFrameBufferObject::CheckFrameBufferStatus ( GLuint i ) 00263 { 00264 assert ( i < GetSize() ); 00265 //--------------------------------------------------------------- 00266 ProtectedBindFrameBuffer( i ); 00267 //--------------------------------------------------------------- 00268 switch ( glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT ) ) { 00269 case GL_FRAMEBUFFER_COMPLETE_EXT: 00270 return true; 00271 break; 00272 case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: 00273 #ifdef TAPs_USE_WXWIDGETS 00274 wxLogError( wxT( "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT" ) ); 00275 #else 00276 std::cout << "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT" << std::endl; 00277 #endif 00278 break; 00279 case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: 00280 #ifdef TAPs_USE_WXWIDGETS 00281 wxLogError( wxT( "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT" ) ); 00282 #else 00283 std::cout << "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT" << std::endl; 00284 #endif 00285 break; 00286 case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: 00287 #ifdef TAPs_USE_WXWIDGETS 00288 wxLogError( wxT( "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT" ) ); 00289 #else 00290 std::cout << "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT" << std::endl; 00291 #endif 00292 break; 00293 case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: 00294 #ifdef TAPs_USE_WXWIDGETS 00295 wxLogError( wxT( "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT" ) ); 00296 #else 00297 std::cout << "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT" << std::endl; 00298 #endif 00299 break; 00300 case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: 00301 #ifdef TAPs_USE_WXWIDGETS 00302 wxLogError( wxT( "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT" ) ); 00303 #else 00304 std::cout << "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT" << std::endl; 00305 #endif 00306 break; 00307 case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: 00308 #ifdef TAPs_USE_WXWIDGETS 00309 wxLogError( wxT( "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT" ) ); 00310 #else 00311 std::cout << "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT" << std::endl; 00312 #endif 00313 break; 00314 case GL_FRAMEBUFFER_UNSUPPORTED_EXT: 00315 #ifdef TAPs_USE_WXWIDGETS 00316 wxLogError( wxT( "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_UNSUPPORTED_EXT" ) ); 00317 #else 00318 std::cout << "ERROR (GLEXTFrameBufferObject): GL_FRAMEBUFFER_UNSUPPORTED_EXT" << std::endl; 00319 #endif 00320 break; 00321 default: 00322 #ifdef TAPs_USE_WXWIDGETS 00323 wxLogError( wxT( "ERROR (GLEXTFrameBufferObject): UNKNOWN ERROR!" ) ); 00324 #else 00325 std::cout << "ERROR (GLEXTFrameBufferObject): UNKNOWN ERROR!" << std::endl; 00326 #endif 00327 break; 00328 } 00329 //--------------------------------------------------------------- 00330 ProtectedUnbindFrameBuffer( i ); 00331 //--------------------------------------------------------------- 00332 return false; 00333 } 00334 #endif 00335 //----------------------------------------------------------------------------- 00336 void GLEXTFrameBufferObject::FrameBufferTexture1D ( 00337 GLenum attachment, 00338 GLenum textarget, 00339 GLuint texture, 00340 GLint level ) 00341 { 00342 glFramebufferTexture1DEXT( GL_FRAMEBUFFER_EXT, attachment, 00343 GL_TEXTURE_1D, texture, level ); 00344 } 00345 //----------------------------------------------------------------------------- 00346 void GLEXTFrameBufferObject::FrameBufferTexture2D ( 00347 GLenum attachment, 00348 GLenum textarget, 00349 GLuint texture, 00350 GLint level ) 00351 { 00352 glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, attachment, 00353 textarget, texture, level ); 00354 } 00355 //----------------------------------------------------------------------------- 00356 void GLEXTFrameBufferObject::FrameBufferTexture3D ( 00357 GLenum attachment, 00358 GLenum textarget, 00359 GLuint texture, 00360 GLint level, 00361 GLint zoffset ) 00362 { 00363 glFramebufferTexture3DEXT( GL_FRAMEBUFFER_EXT, attachment, 00364 GL_TEXTURE_3D, texture, level, zoffset ); 00365 } 00366 //----------------------------------------------------------------------------- 00367 void GLEXTFrameBufferObject::FrameBufferRenderBuffer ( 00368 GLenum attachment, 00369 GLuint renderbuffer ) 00370 { 00371 glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, attachment, 00372 GL_RENDERBUFFER_EXT, renderbuffer ); 00373 } 00374 //----------------------------------------------------------------------------- 00375 GLint GLEXTFrameBufferObject::GetFrameBufferAttachmentParameter ( 00376 GLuint i, 00377 GLenum attachment, 00378 GLenum pname ) 00379 { 00380 assert( i < GetSize() ); 00381 //--------------------------------------------------------------- 00382 ProtectedBindFrameBuffer( i ); 00383 GLint result; 00384 glGetFramebufferAttachmentParameterivEXT( 00385 GL_FRAMEBUFFER_EXT, attachment, pname, &result ); 00386 ProtectedUnbindFrameBuffer( i ); 00387 return result; 00388 } 00389 //----------------------------------------------------------------------------- 00390 GLint GLEXTFrameBufferObject::GetRenderbufferParameter ( 00391 GLuint i, 00392 GLenum attachment, 00393 GLenum pname ) 00394 { 00395 assert( i < GetSize() ); 00396 //--------------------------------------------------------------- 00397 ProtectedBindFrameBuffer( i ); 00398 GLint result; 00399 glGetRenderbufferParameterivEXT( 00400 GL_RENDERBUFFER_EXT, pname, &result ); 00401 ProtectedUnbindFrameBuffer( i ); 00402 return result; 00403 } 00404 //----------------------------------------------------------------------------- 00405 void GLEXTFrameBufferObject::GenerateMipmap () 00406 { 00407 } 00408 //----------------------------------------------------------------------------- 00409 //============================================================================= 00410 //***************************************************************************** 00411 //============================================================================= 00412 // Static Member Functions 00413 //----------------------------------------------------------------------------- 00414 GLint GLEXTFrameBufferObject::InquireMaxColorAttachments () 00415 { 00416 GLint max = 0; 00417 glGetIntegerv( GL_MAX_COLOR_ATTACHMENTS_EXT, &max ); 00418 return max; 00419 } 00420 //----------------------------------------------------------------------------- 00421 GLint GLEXTFrameBufferObject::InquireMaxRenderBufferSize () 00422 { 00423 GLint max = 0; 00424 glGetIntegerv( GL_MAX_RENDERBUFFER_SIZE_EXT, &max ); 00425 return max; 00426 } 00427 //----------------------------------------------------------------------------- 00428 void GLEXTFrameBufferObject::DisableAllRenderBuffers () 00429 { 00430 glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, 0 ); 00431 } 00432 //----------------------------------------------------------------------------- 00433 void GLEXTFrameBufferObject::DisableAllFrameBuffers () 00434 { 00435 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 00436 } 00437 //----------------------------------------------------------------------------- 00438 //============================================================================= 00439 //***************************************************************************** 00440 //============================================================================= 00441 // Protected Member Functions 00442 //----------------------------------------------------------------------------- 00443 // ProtectedBindFrameBuffer 00444 void GLEXTFrameBufferObject::ProtectedBindFrameBuffer ( GLuint i ) 00445 { 00446 GLint bindingID; 00447 glGetIntegerv( GL_FRAMEBUFFER_BINDING_EXT, &bindingID ); 00448 m_pgluiID_StackValue[i] = static_cast<GLuint>( bindingID ); 00449 if ( m_pgluiID[i] != m_pgluiID_StackValue[i] ) { 00450 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_pgluiID[i] ); 00451 } 00452 } 00453 //----------------------------------------------------------------------------- 00454 // ProtectedUnbindFrameBuffer 00455 void GLEXTFrameBufferObject::ProtectedUnbindFrameBuffer ( GLuint i ) 00456 { 00457 if ( m_pgluiID[i] != m_pgluiID_StackValue[i] ) { 00458 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_pgluiID_StackValue[i] ); 00459 } 00460 } 00461 //----------------------------------------------------------------------------- 00462 // ProtectedBindRenderBuffer 00463 void GLEXTFrameBufferObject::ProtectedBindRenderBuffer ( GLuint i ) 00464 { 00465 GLint bindingID; 00466 glGetIntegerv( GL_RENDERBUFFER_BINDING_EXT, &bindingID ); 00467 m_pgluiID_StackValue[i] = static_cast<GLuint>( bindingID ); 00468 if ( m_pgluiID[i] != m_pgluiID_StackValue[i] ) { 00469 glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, m_pgluiID[i] ); 00470 } 00471 } 00472 //----------------------------------------------------------------------------- 00473 // ProtectedUnbindRenderBuffer 00474 void GLEXTFrameBufferObject::ProtectedUnbindRenderBuffer ( GLuint i ) 00475 { 00476 if ( m_pgluiID[i] != m_pgluiID_StackValue[i] ) { 00477 glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, m_pgluiID_StackValue[i] ); 00478 } 00479 } 00480 //----------------------------------------------------------------------------- 00481 //*/ 00482 //============================================================================= 00483 END_NAMESPACE_TAPs__OpenGL 00484 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00485 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----