Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "define.h"
- #include "fbo.h"
- //-----------------------------------------------------------------------------
- // Constructor
- //-----------------------------------------------------------------------------
- FBO::FBO()
- {
- m_FrameBuffer=0;
- m_DepthRenderBuffer=0;
- m_ColorTextureID=0;
- m_DepthTextureID=0;
- m_width = 256;
- m_height = 256;
- //Create texture.
- glGenTextures(1, &m_ColorTextureID);
- glBindTexture(GL_TEXTURE_2D, m_ColorTextureID);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glBindTexture(GL_TEXTURE_2D, 0);
- glGenTextures(1, &m_DepthTextureID);
- glBindTexture(GL_TEXTURE_2D, m_DepthTextureID);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
- glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glBindTexture(GL_TEXTURE_2D, 0);
- //Make buffer
- glGenFramebuffers(1, &m_FrameBuffer);
- glBindFramebuffer(GL_FRAMEBUFFER_EXT, m_FrameBuffer);
- glGenRenderbuffers(1, &m_DepthRenderBuffer);
- glBindRenderbuffer(GL_RENDERBUFFER_EXT, m_DepthRenderBuffer);
- glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, m_width, m_height);
- glBindRenderbuffer(GL_RENDERBUFFER_EXT, 0);
- glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_ColorTextureID, 0);
- glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT, m_DepthRenderBuffer);
- glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
- }
- //-----------------------------------------------------------------------------
- // Destructor
- //-----------------------------------------------------------------------------
- FBO::~FBO()
- {
- glDeleteTextures(1, &m_ColorTextureID);
- glDeleteTextures(1, &m_DepthTextureID);
- glDeleteFramebuffers(1, &m_FrameBuffer);
- glDeleteRenderbuffers(1, &m_DepthRenderBuffer);
- }
- //-----------------------------------------------------------------------------
- // Enable
- //-----------------------------------------------------------------------------
- void FBO::Enable(void)
- {
- glBindFramebuffer(GL_FRAMEBUFFER_EXT, m_FrameBuffer);
- glViewport(0,0,m_width,m_height);
- glPushMatrix();
- }
- //-----------------------------------------------------------------------------
- // Disable
- //-----------------------------------------------------------------------------
- void FBO::Disable(void)
- {
- glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
- glViewport(0,0,SCREENX,SCREENY);
- glPopMatrix();
- }
- //-----------------------------------------------------------------------------
- // SetSize
- //-----------------------------------------------------------------------------
- void FBO::SetSize( int width, int height )
- {
- m_width = width;
- m_height = height;
- glBindRenderbuffer(GL_RENDERBUFFER_EXT, m_DepthRenderBuffer);
- glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT32, m_width, m_height);
- glBindRenderbuffer(GL_RENDERBUFFER_EXT, 0);
- //Create color texture.
- glBindTexture(GL_TEXTURE_2D, m_ColorTextureID);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- glBindTexture(GL_TEXTURE_2D, m_DepthTextureID);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
- glBindTexture(GL_TEXTURE_2D, 0);
- }
- /*//-----------------------------------------------------------------------------
- // GetSize
- //-----------------------------------------------------------------------------
- ivec2& FBO::GetSize(void)
- {
- return m_size;
- }*/
- //-----------------------------------------------------------------------------
- // GetColor
- //-----------------------------------------------------------------------------
- GLuint FBO::GetColor(void)
- {
- return m_ColorTextureID;
- }
- //-----------------------------------------------------------------------------
- // GetDepth
- //-----------------------------------------------------------------------------
- GLuint FBO::GetDepth(void)
- {
- return m_DepthTextureID;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement