summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/Makefile.am1
-rw-r--r--src/graphicsmanager.cpp68
-rw-r--r--src/graphicsmanager.h6
-rw-r--r--src/normalopenglgraphics.cpp66
-rw-r--r--src/normalopenglgraphics.h8
-rw-r--r--src/safeopenglgraphics.cpp64
-rw-r--r--src/safeopenglgraphics.h6
8 files changed, 94 insertions, 126 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e5556fccb..0ce99f292 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -415,6 +415,7 @@ SET(SRCS
resources/dye.h
resources/emotedb.cpp
resources/emotedb.h
+ resources/fboinfo.h
resources/image.cpp
resources/image.h
resources/imagehelper.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index ada4d657b..699caf64c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -426,6 +426,7 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
resources/dye.h \
resources/emotedb.cpp \
resources/emotedb.h \
+ resources/fboinfo.h \
resources/image.cpp \
resources/image.h \
resources/imagehelper.cpp \
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
+}
diff --git a/src/graphicsmanager.h b/src/graphicsmanager.h
index 85fe5f548..a82739bc5 100644
--- a/src/graphicsmanager.h
+++ b/src/graphicsmanager.h
@@ -26,6 +26,8 @@
class Graphics;
+struct FBOInfo;
+
class GraphicsManager
{
public:
@@ -53,6 +55,10 @@ class GraphicsManager
bool checkGLVersion(int major, int minor) const;
+ void createFBO(int width, int height, FBOInfo *fbo);
+
+ void deleteFBO(FBOInfo *fbo);
+
private:
std::set<std::string> mExtensions;
diff --git a/src/normalopenglgraphics.cpp b/src/normalopenglgraphics.cpp
index 1114f1620..ae28e2030 100644
--- a/src/normalopenglgraphics.cpp
+++ b/src/normalopenglgraphics.cpp
@@ -24,6 +24,7 @@
#ifdef USE_OPENGL
+#include "graphicsmanager.h"
#include "graphicsvertexes.h"
#include "normalopenglgraphics.h"
#include "configuration.h"
@@ -53,14 +54,11 @@ NormalOpenGLGraphics::NormalOpenGLGraphics():
mIntVertArray(new GLint[vertexBufSize * 4 + 30]),
mAlpha(false),
mTexture(false),
- mColorAlpha(false),
- mFboId(0),
- mTextureId(0),
#ifdef DEBUG_BIND_TEXTURE
- mRboId(0),
+ mColorAlpha(false),
mOldTextureId(0)
#else
- mRboId(0)
+ mColorAlpha(false)
#endif
{
mOpenGL = 1;
@@ -1007,43 +1005,7 @@ void NormalOpenGLGraphics::prepareScreenshot()
{
#if !defined(_WIN32)
if (config.getBoolValue("usefbo"))
- {
- int h = mTarget->h;
- int w = mTarget->w;
-
- // create a texture object
- glGenTextures(1, &mTextureId);
- glBindTexture(GL_TEXTURE_2D, mTextureId);
- 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, w, h, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
- glBindTexture(GL_TEXTURE_2D, 0);
-
- // create a renderbuffer object to store depth info
- glGenRenderbuffersEXT(1, &mRboId);
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, mRboId);
- glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,
- GL_DEPTH_COMPONENT, w, h);
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
-
- // create a framebuffer object
- glGenFramebuffersEXT(1, &mFboId);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFboId);
-
- // attach the texture to FBO color attachment point
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
- GL_TEXTURE_2D, mTextureId, 0);
-
- // attach the renderbuffer to depth attachment point
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
- GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, mRboId);
-
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFboId);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- }
+ graphicsManager.createFBO(mTarget->w, mTarget->h, &mFbo);
#endif
}
@@ -1089,25 +1051,7 @@ SDL_Surface* NormalOpenGLGraphics::getScreenshot()
#if !defined(_WIN32)
if (config.getBoolValue("usefbo"))
- {
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- if (mFboId)
- {
- glDeleteFramebuffersEXT(1, &mFboId);
- mFboId = 0;
- }
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
- if (mRboId)
- {
- glDeleteRenderbuffersEXT(1, &mRboId);
- mRboId = 0;
- }
- if (mTextureId)
- {
- glDeleteTextures(1, &mTextureId);
- mTextureId = 0;
- }
- }
+ graphicsManager.deleteFBO(&mFbo);
#endif
glPixelStorei(GL_PACK_ALIGNMENT, pack);
diff --git a/src/normalopenglgraphics.h b/src/normalopenglgraphics.h
index 5c86f40e4..875b04bee 100644
--- a/src/normalopenglgraphics.h
+++ b/src/normalopenglgraphics.h
@@ -29,11 +29,13 @@
#include "main.h"
#include "graphics.h"
+#include "resources/fboinfo.h"
+
//#define NO_SDL_GLEXT
#define GL_GLEXT_PROTOTYPES 1
#include <SDL_opengl.h>
-//#include <GL/glext.h>
+#include <GL/glext.h>
#include <set>
@@ -162,9 +164,7 @@ class NormalOpenGLGraphics : public Graphics
GLint *mIntVertArray;
bool mAlpha, mTexture;
bool mColorAlpha;
- GLuint mFboId;
- GLuint mTextureId;
- GLuint mRboId;
+ FBOInfo mFbo;
#ifdef DEBUG_BIND_TEXTURE
std::string mOldTexture;
unsigned mOldTextureId;
diff --git a/src/safeopenglgraphics.cpp b/src/safeopenglgraphics.cpp
index 055a996d1..adc49795c 100644
--- a/src/safeopenglgraphics.cpp
+++ b/src/safeopenglgraphics.cpp
@@ -26,6 +26,7 @@
#include "safeopenglgraphics.h"
#include "configuration.h"
+#include "graphicsmanager.h"
#include "graphicsvertexes.h"
#include "logger.h"
@@ -44,8 +45,9 @@
GLuint SafeOpenGLGraphics::mLastImage = 0;
SafeOpenGLGraphics::SafeOpenGLGraphics():
- mAlpha(false), mTexture(false), mColorAlpha(false),
- mFboId(0), mTextureId(0), mRboId(0)
+ mAlpha(false),
+ mTexture(false),
+ mColorAlpha(false)
{
mOpenGL = 2;
mName = "safe OpenGL";
@@ -425,43 +427,7 @@ void SafeOpenGLGraphics::prepareScreenshot()
{
#if !defined(_WIN32)
if (config.getBoolValue("usefbo"))
- {
- int h = mTarget->h;
- int w = mTarget->w;
-
- // create a texture object
- glGenTextures(1, &mTextureId);
- glBindTexture(GL_TEXTURE_2D, mTextureId);
- 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, w, h, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
- glBindTexture(GL_TEXTURE_2D, 0);
-
- // create a renderbuffer object to store depth info
- glGenRenderbuffersEXT(1, &mRboId);
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, mRboId);
- glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,
- GL_DEPTH_COMPONENT, w, h);
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
-
- // create a framebuffer object
- glGenFramebuffersEXT(1, &mFboId);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFboId);
-
- // attach the texture to FBO color attachment point
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
- GL_TEXTURE_2D, mTextureId, 0);
-
- // attach the renderbuffer to depth attachment point
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
- GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, mRboId);
-
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFboId);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- }
+ graphicsManager.createFBO(mTarget->w, mTarget->h, &mFbo);
#endif
}
@@ -507,25 +473,7 @@ SDL_Surface* SafeOpenGLGraphics::getScreenshot()
#if !defined(_WIN32)
if (config.getBoolValue("usefbo"))
- {
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- if (mFboId)
- {
- glDeleteFramebuffersEXT(1, &mFboId);
- mFboId = 0;
- }
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
- if (mRboId)
- {
- glDeleteRenderbuffersEXT(1, &mRboId);
- mRboId = 0;
- }
- if (mTextureId)
- {
- glDeleteTextures(1, &mTextureId);
- mTextureId = 0;
- }
- }
+ graphicsManager.deleteFBO(&mFbo);
#endif
glPixelStorei(GL_PACK_ALIGNMENT, pack);
diff --git a/src/safeopenglgraphics.h b/src/safeopenglgraphics.h
index 304c62d85..8a5f7bc17 100644
--- a/src/safeopenglgraphics.h
+++ b/src/safeopenglgraphics.h
@@ -28,6 +28,8 @@
#include "graphics.h"
+#include "resources/fboinfo.h"
+
//#define NO_SDL_GLEXT
#define GL_GLEXT_PROTOTYPES 1
@@ -132,9 +134,7 @@ class SafeOpenGLGraphics : public Graphics
private:
bool mAlpha, mTexture;
bool mColorAlpha;
- GLuint mFboId;
- GLuint mTextureId;
- GLuint mRboId;
+ FBOInfo mFbo;
};
#endif