summaryrefslogtreecommitdiff
path: root/src/graphicsmanager.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-08-11 17:49:09 +0300
committerAndrei Karas <akaras@inbox.ru>2012-08-11 17:49:09 +0300
commit2274758726d1138a2b65535244e84225c3de5304 (patch)
treef55922ce637b797ea42fe0392126961b2cc3cc32 /src/graphicsmanager.cpp
parent7de8936d864564b2a9fafaa74af84ec10e755388 (diff)
downloadmv-2274758726d1138a2b65535244e84225c3de5304.tar.gz
mv-2274758726d1138a2b65535244e84225c3de5304.tar.bz2
mv-2274758726d1138a2b65535244e84225c3de5304.tar.xz
mv-2274758726d1138a2b65535244e84225c3de5304.zip
Move fbo code to GraphicsManager from opengl backends.
Diffstat (limited to 'src/graphicsmanager.cpp')
-rw-r--r--src/graphicsmanager.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/graphicsmanager.cpp b/src/graphicsmanager.cpp
index cb5b2698b..d18b79c41 100644
--- a/src/graphicsmanager.cpp
+++ b/src/graphicsmanager.cpp
@@ -25,6 +25,7 @@
#include "graphicsvertexes.h"
#include "logger.h"
+#include "resources/fboinfo.h"
#include "resources/imagehelper.h"
#include "resources/openglimagehelper.h"
#include "resources/sdlimagehelper.h"
@@ -328,3 +329,70 @@ bool GraphicsManager::checkGLVersion(int major, int minor) const
{
return mMajor > major || (mMajor == major && mMinor >= minor);
}
+
+void GraphicsManager::createFBO(int width, int height, FBOInfo *fbo)
+{
+#ifdef USE_OPENGL
+ if (!fbo)
+ return;
+
+ // create a texture object
+ glGenTextures(1, &fbo->textureId);
+ glBindTexture(GL_TEXTURE_2D, fbo->textureId);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
+ glBindTexture(GL_TEXTURE_2D, 0);
+
+ // create a renderbuffer object to store depth info
+ glGenRenderbuffersEXT(1, &fbo->rboId);
+ glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo->rboId);
+ glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,
+ GL_DEPTH_COMPONENT, width, height);
+ glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
+
+ // create a framebuffer object
+ glGenFramebuffersEXT(1, &fbo->fboId);
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo->fboId);
+
+ // attach the texture to FBO color attachment point
+ glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
+ GL_TEXTURE_2D, fbo->textureId, 0);
+
+ // attach the renderbuffer to depth attachment point
+ glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
+ GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, fbo->rboId);
+
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo->fboId);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+#endif
+}
+
+void GraphicsManager::deleteFBO(FBOInfo *fbo)
+{
+#ifdef USE_OPENGL
+ if (!fbo)
+ return;
+
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ if (fbo->fboId)
+ {
+ glDeleteFramebuffersEXT(1, &fbo->fboId);
+ fbo->fboId = 0;
+ }
+ glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
+ if (fbo->rboId)
+ {
+ glDeleteRenderbuffersEXT(1, &fbo->rboId);
+ fbo->rboId = 0;
+ }
+ if (fbo->textureId)
+ {
+ glDeleteTextures(1, &fbo->textureId);
+ fbo->textureId = 0;
+ }
+#endif
+}