13T2FrameBuffer::T2FrameBuffer()
19 m_aAttachments[ i ] = 0;
23T2FrameBuffer::~T2FrameBuffer()
28void T2FrameBuffer::Create()
33 glGenFramebuffers( 1, &m_uiFBO );
38void T2FrameBuffer::Bind()
45 glBindFramebuffer( GL_FRAMEBUFFER, m_uiFBO );
49void T2FrameBuffer::Unbind()
51 if ( g_uiBoundFBO != 0 )
54 glBindFramebuffer( GL_FRAMEBUFFER, 0 );
58void T2FrameBuffer::Destroy()
62 glDeleteFramebuffers( 1, &m_uiFBO );
67 if ( m_aAttachments[ i ] != 0 )
69 T2Render::DestroyTexture( m_aAttachments[ i ] );
70 m_aAttachments[ i ] = 0;
74 if ( m_uiDepthTexture != 0 )
76 T2Render::DestroyTexture( m_uiDepthTexture );
82void T2FrameBuffer::CreateDepthTexture( GLsizei a_iWidth, GLsizei a_iHeight )
87 TASSERT( m_uiDepthTexture == 0 );
89 T2FrameBuffer::Bind();
90 GLuint uiTexture = T2Render::CreateTexture( a_iWidth, a_iHeight, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_FLOAT,
TFALSE,
TNULL );
91 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
92 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
94 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER );
95 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER );
97 TFLOAT borderColor[] = { 1.0f, 1.0f, 1.0f, 1.0f };
98 glTexParameterfv( GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor );
100 glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, uiTexture, 0 );
101 m_uiDepthTexture = uiTexture;
104void T2FrameBuffer::CreateAttachment(
TINT a_iAttachment, GLsizei a_iWidth, GLsizei a_iHeight, GLenum a_eInternalFormat, GLenum a_eFormat, GLenum a_ePixelType )
109 TASSERT( m_aAttachments[ a_iAttachment ] == 0 );
111 T2FrameBuffer::Bind();
112 GLuint uiTexture = T2Render::CreateTexture( a_iWidth, a_iHeight, a_eInternalFormat, a_eFormat, a_ePixelType,
TFALSE,
TNULL );
113 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
114 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
116 glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + a_iAttachment, GL_TEXTURE_2D, uiTexture, 0 );
117 m_aAttachments[ a_iAttachment ] = uiTexture;
120void T2FrameBuffer::SetDrawBuffer( GLenum a_eDrawBuffer )
122 T2FrameBuffer::Bind();
123 glDrawBuffer( GL_NONE );
124 glReadBuffer( GL_NONE );
#define TOSHI_NAMESPACE_START
#define TARRAYSIZE(ARRAY)
#define TOSHI_NAMESPACE_END