diff options
Diffstat (limited to 'src/openglgraphics.cpp')
-rw-r--r-- | src/openglgraphics.cpp | 114 |
1 files changed, 103 insertions, 11 deletions
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index bcf46e18b..9dd655420 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -26,6 +26,7 @@ #include "graphicsvertexes.h" #include "openglgraphics.h" +#include "configuration.h" #include "logger.h" #include "resources/image.h" @@ -50,8 +51,8 @@ const unsigned int vertexBufSize = 500; GLuint OpenGLGraphics::mLastImage = 0; OpenGLGraphics::OpenGLGraphics(): - mAlpha(false), mTexture(false), mColorAlpha(false), - mSync(false) + mAlpha(false), mTexture(false), mColorAlpha(false), mSync(false), + mFboId(0), mTextureId(0), mRboId(0) { mOpenGL = 1; mFloatTexArray = new GLfloat[vertexBufSize * 4 + 30]; @@ -554,8 +555,10 @@ void OpenGLGraphics::drawRescaledImagePattern(Image *image, { int width = (px + scaledWidth >= w) ? w - px : scaledWidth; int dstX = x + px; - const float visibleFractionW = (float) width / scaledWidth; - const float visibleFractionH = (float) height / scaledHeight; + const float visibleFractionW = static_cast<float>(width) + / scaledWidth; + const float visibleFractionH = static_cast<float>(height) + / scaledHeight; const float texX2 = texX1 + tFractionW * visibleFractionW; const float texY2 = texY1 + tFractionH * visibleFractionH; @@ -597,8 +600,8 @@ void OpenGLGraphics::drawRescaledImagePattern(Image *image, } else { - const float scaleFactorW = (float) scaledWidth / iw; - const float scaleFactorH = (float) scaledHeight / ih; + const float scaleFactorW = static_cast<float>(scaledWidth) / iw; + const float scaleFactorH = static_cast<float>(scaledHeight) / ih; for (int py = 0; py < h; py += scaledHeight) { @@ -1011,7 +1014,6 @@ void OpenGLGraphics::_beginDraw() glLoadIdentity(); glEnable(GL_SCISSOR_TEST); - glEnableClientState(GL_VERTEX_ARRAY); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -1037,10 +1039,54 @@ void OpenGLGraphics::_endDraw() popClipArea(); } +void OpenGLGraphics::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); + } +#endif +} + SDL_Surface* OpenGLGraphics::getScreenshot() { - int h = mTarget->h; - int w = mTarget->w; + const int h = mTarget->h; + const int w = mTarget->w - (mTarget->w % 4); GLint pack = 1; SDL_Surface *screenshot = SDL_CreateRGBSurface( @@ -1077,6 +1123,29 @@ SDL_Surface* OpenGLGraphics::getScreenshot() free(buf); +#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; + } + } +#endif + glPixelStorei(GL_PACK_ALIGNMENT, pack); if (SDL_MUSTLOCK(screenshot)) @@ -1104,8 +1173,11 @@ bool OpenGLGraphics::pushClipArea(gcn::Rectangle area) transY += clipArea.yOffset; glPushMatrix(); - glTranslatef(static_cast<GLfloat>(transX), - static_cast<GLfloat>(transY), 0); + if (transX || transY) + { + glTranslatef(static_cast<GLfloat>(transX), + static_cast<GLfloat>(transY), 0); + } glScissor(clipArea.x, mTarget->h - clipArea.y - clipArea.height, clipArea.width, clipArea.height); @@ -1349,4 +1421,24 @@ inline void OpenGLGraphics::drawLineArrayf(int size) glDrawArrays(GL_LINES, 0, size / 2); } +void OpenGLGraphics::dumpSettings() +{ + GLint test[1000]; + logger->log("\n\n"); + logger->log("start opengl dump"); + for (int f = 0; f < 65535; f ++) + { + test[0] = 0; + test[1] = 0; + test[2] = 0; + test[3] = 0; + glGetIntegerv(f, &test[0]); + if (test[0] || test[1] || test[2] || test[3]) + { + logger->log("\n%d = %d, %d, %d, %d", f, + test[0], test[1], test[2], test[3]); + } + } +} + #endif // USE_OPENGL |