#include <rTextureRenderTarget.h>
Public Member Functions | |
void | Clear () |
clears the texture | |
~rTextureRenderTarget () | |
rTextureRenderTarget (int width, int height) | |
creates a render target texture of the specified dimensions | |
void | Push () |
makes this texture the active render target | |
void | Pop () |
removes this texture as the active render target | |
bool | IsTarget () const |
int | GetHeight () const |
int | GetWidth () const |
Static Public Member Functions | |
static void | Restore () |
restores current render target if it was overwritten by an evil manual glBindFramebuffer call | |
Protected Member Functions | |
virtual void | OnSelect (bool) |
Selects the texture for rendering. | |
virtual void | OnUnload () |
Unloads the texture from OpenGL and memory. | |
Private Attributes | |
rGLuintObjectTexture | texture_ |
the texture render target | |
rGLuintObjectRenderbuffer | depthBuffer_ |
the depth buffer | |
rGLuintObjectFramebuffer | frameBuffer_ |
the frame buffer | |
rTextureRenderTarget * | previous |
int | width_ |
int | height_ |
GLenum | colorMode |
GLenum | depthMode |
Static Private Attributes | |
static rTextureRenderTarget * | anchor = 0 |
Definition at line 36 of file rTextureRenderTarget.h.
rTextureRenderTarget::~rTextureRenderTarget | ( | ) |
Definition at line 59 of file rTextureRenderTarget.cpp.
References Clear(), IsTarget(), and Pop().
rTextureRenderTarget::rTextureRenderTarget | ( | int | width, | |
int | height | |||
) |
creates a render target texture of the specified dimensions
Definition at line 69 of file rTextureRenderTarget.cpp.
References depthBuffer_, height_, NULL, Pop(), previous, Push(), sr_CheckGLError(), tASSERT, texture_, and width_.
00070 { 00071 #ifndef DEDICATED 00072 sr_CheckGLError(); 00073 00074 width_ = width; 00075 height_ = height; 00076 previous = 0; 00077 00078 #ifdef GLEW_EXT_framebuffer_object 00079 if ( GLEW_EXT_framebuffer_object ) 00080 { 00081 Push(); 00082 sr_CheckGLError(); 00083 00084 // generate texture 00085 glBindTexture( GL_TEXTURE_2D, texture_ ); 00086 sr_CheckGLError(); 00087 00088 // make texture 00089 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL ); 00090 sr_CheckGLError(); 00091 00092 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 00093 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 00094 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); 00095 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); 00096 00097 glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texture_, 0 ); 00098 sr_CheckGLError(); 00099 00100 glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, depthBuffer_ ); 00101 sr_CheckGLError(); 00102 00103 glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT32, width, height ); 00104 sr_CheckGLError(); 00105 00106 glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthBuffer_ ); 00107 sr_CheckGLError(); 00108 00109 GLenum status = glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT); 00110 switch ( status ) 00111 { 00112 case GL_FRAMEBUFFER_COMPLETE_EXT: 00113 break; 00114 case GL_FRAMEBUFFER_UNSUPPORTED_EXT: 00115 throw rExceptionGLEW( "Unsupported frame buffer operation" ); 00116 default: 00117 tASSERT( 0 ); 00118 } 00119 00120 sr_CheckGLError(); 00121 00122 Pop(); 00123 00124 return; 00125 } 00126 #endif // GLEW_EXT_framebuffer_object 00127 00128 throw rExceptionGLEW( "frame buffer extension not supported" ); 00129 #endif 00130 }
void rTextureRenderTarget::Clear | ( | void | ) |
clears the texture
texture that can be used as a target for rendering
@return |
Definition at line 50 of file rTextureRenderTarget.cpp.
References depthBuffer_, frameBuffer_, IsTarget(), tASSERT, and texture_.
Referenced by ~rTextureRenderTarget().
00051 { 00052 tASSERT( !IsTarget() ); 00053 00054 texture_.Delete(); 00055 depthBuffer_.Delete(); 00056 frameBuffer_.Delete(); 00057 }
void rTextureRenderTarget::Push | ( | ) |
makes this texture the active render target
Definition at line 132 of file rTextureRenderTarget.cpp.
References anchor, frameBuffer_, previous, and sr_CheckGLError().
Referenced by rTextureRenderTarget(), and sr_MotionBlurCore().
00133 { 00134 #ifndef DEDICATED 00135 previous = anchor; 00136 anchor = this; 00137 00138 #ifdef GLEW_EXT_framebuffer_object 00139 sr_CheckGLError(); 00140 00141 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, frameBuffer_ ); 00142 00143 sr_CheckGLError(); 00144 #endif 00145 #endif 00146 }
void rTextureRenderTarget::Pop | ( | ) |
removes this texture as the active render target
Definition at line 148 of file rTextureRenderTarget.cpp.
References anchor, IsTarget(), previous, Restore(), and tASSERT.
Referenced by rTextureRenderTarget(), sr_MotionBlurCore(), and ~rTextureRenderTarget().
00149 { 00150 #ifndef DEDICATED 00151 tASSERT( IsTarget() ); 00152 00153 anchor = previous; 00154 00155 Restore(); 00156 #endif 00157 }
void rTextureRenderTarget::Restore | ( | ) | [static] |
restores current render target if it was overwritten by an evil manual glBindFramebuffer call
Definition at line 159 of file rTextureRenderTarget.cpp.
References anchor, frameBuffer_, and sr_CheckGLError().
Referenced by Pop().
00160 { 00161 #ifdef GLEW_EXT_framebuffer_object 00162 sr_CheckGLError(); 00163 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, anchor ? anchor->frameBuffer_ : 0 ); 00164 sr_CheckGLError(); 00165 #endif 00166 }
bool rTextureRenderTarget::IsTarget | ( | ) | const [inline] |
Definition at line 56 of file rTextureRenderTarget.h.
References anchor.
Referenced by Clear(), Pop(), sr_MotionBlurCore(), and ~rTextureRenderTarget().
00057 { 00058 return anchor == this; 00059 }
int rTextureRenderTarget::GetHeight | ( | ) | const [inline] |
Definition at line 61 of file rTextureRenderTarget.h.
References height_.
Referenced by sr_MotionBlurCore().
00062 { 00063 return height_; 00064 }
int rTextureRenderTarget::GetWidth | ( | ) | const [inline] |
Definition at line 66 of file rTextureRenderTarget.h.
References width_.
Referenced by sr_MotionBlurCore().
00067 { 00068 return width_; 00069 }
void rTextureRenderTarget::OnSelect | ( | bool | enforce | ) | [protected, virtual] |
Selects the texture for rendering.
enforce | enforce when set to true, the texture should be loaded even if the configuration says it should not |
Implements rITexture.
Definition at line 168 of file rTextureRenderTarget.cpp.
References texture_.
00169 { 00170 #ifndef DEDICATED 00171 glBindTexture( GL_TEXTURE_2D, texture_ ); 00172 #endif 00173 }
virtual void rTextureRenderTarget::OnUnload | ( | void | ) | [inline, protected, virtual] |
Unloads the texture from OpenGL and memory.
Implements rITexture.
Definition at line 74 of file rTextureRenderTarget.h.
rGLuintObjectTexture rTextureRenderTarget::texture_ [private] |
the texture render target
Definition at line 76 of file rTextureRenderTarget.h.
Referenced by Clear(), OnSelect(), and rTextureRenderTarget().
rGLuintObjectRenderbuffer rTextureRenderTarget::depthBuffer_ [private] |
the depth buffer
Definition at line 77 of file rTextureRenderTarget.h.
Referenced by Clear(), and rTextureRenderTarget().
rGLuintObjectFramebuffer rTextureRenderTarget::frameBuffer_ [private] |
rTextureRenderTarget * rTextureRenderTarget::anchor = 0 [static, private] |
Definition at line 81 of file rTextureRenderTarget.h.
Referenced by IsTarget(), Pop(), Push(), and Restore().
Definition at line 82 of file rTextureRenderTarget.h.
Referenced by Pop(), Push(), and rTextureRenderTarget().
int rTextureRenderTarget::width_ [private] |
Definition at line 84 of file rTextureRenderTarget.h.
Referenced by GetWidth(), and rTextureRenderTarget().
int rTextureRenderTarget::height_ [private] |
Definition at line 84 of file rTextureRenderTarget.h.
Referenced by GetHeight(), and rTextureRenderTarget().
GLenum rTextureRenderTarget::colorMode [private] |
Definition at line 85 of file rTextureRenderTarget.h.
GLenum rTextureRenderTarget::depthMode [private] |
Definition at line 85 of file rTextureRenderTarget.h.