Kaydet (Commit) 8c39739a authored tarafından Markus Mohrhard's avatar Markus Mohrhard

add method for creating framebuffer objects to OpenGLHelper

Change-Id: I08bd2e58ee98a68accae256fcbcc288a8c56ae0b
üst e634b0dc
......@@ -29,6 +29,13 @@ public:
static void renderToFile(long nWidth, long nHeight, const OUString& rFileName);
static const char* GLErrorString(GLenum errorCode);
/**
* The caller is responsible for deleting the buffer objects identified by
* nFramebufferId, nRenderbufferId and nTexturebufferId
*/
static void createFramebuffer(long nWidth, long nHeight,
GLuint& nFramebufferId, GLuint& nRenderbufferId, GLuint& nTexturebufferId);
};
VCLOPENGL_DLLPUBLIC std::ostream& operator<<(std::ostream& rStrm, const glm::mat4& rMatrix);
......
......@@ -268,5 +268,41 @@ std::ostream& operator<<(std::ostream& rStrm, const glm::mat4& rMatrix)
return rStrm;
}
void OpenGLHelper::createFramebuffer(long nWidth, long nHeight,
GLuint& nFramebufferId, GLuint& nRenderbufferId, GLuint& nTexturebufferId)
{
// create a renderbuffer
glGenRenderbuffers(1, &nRenderbufferId);
glBindRenderbuffer(GL_RENDERBUFFER, nRenderbufferId);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, nWidth, nHeight);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
// create a texture
glGenTextures(1, &nTexturebufferId);
glBindTexture(GL_TEXTURE_2D, nTexturebufferId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, nWidth, nHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, 0);
// create a framebuffer object and attach renderbuffer and texture
glGenFramebuffers(1, &nFramebufferId);
glCheckFramebufferStatus(GL_FRAMEBUFFER);
glBindFramebuffer(GL_FRAMEBUFFER, nFramebufferId);
glBindTexture(GL_TEXTURE_2D, nTexturebufferId);
// attach a texture to FBO color attachement point
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, nTexturebufferId, 0);
glCheckFramebufferStatus(GL_FRAMEBUFFER);
glBindTexture(GL_TEXTURE_2D, 0);
// attach a renderbuffer to depth attachment point
glBindRenderbuffer(GL_RENDERBUFFER, nRenderbufferId);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, nRenderbufferId);
glCheckFramebufferStatus(GL_FRAMEBUFFER);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment