From 1e37ebb4eb808f56bbbd522dbab524c24439d92b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 24 Mar 2013 00:21:41 +0300 Subject: improve safeopenglgraphics class. --- src/safeopenglgraphics.cpp | 69 +++++++++++++++++++++------------------------- src/safeopenglgraphics.h | 4 +-- 2 files changed, 34 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/safeopenglgraphics.cpp b/src/safeopenglgraphics.cpp index 5802691ec..0cd00d60d 100644 --- a/src/safeopenglgraphics.cpp +++ b/src/safeopenglgraphics.cpp @@ -64,20 +64,21 @@ bool SafeOpenGLGraphics::setVideoMode(const int w, const int h, const int bpp, } static inline void drawQuad(const Image *image, - int srcX, int srcY, int dstX, int dstY, - int width, int height) + const int srcX, const int srcY, + const int dstX, const int dstY, + const int width, const int height) { if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) { // Find OpenGL normalized texture coordinates. - float texX1 = static_cast(srcX) + const float texX1 = static_cast(srcX) / static_cast(image->mTexWidth); - float texY1 = static_cast(srcY) + const float texY1 = static_cast(srcY) + / static_cast(image->mTexHeight); + const float texX2 = static_cast(srcX + width) + / static_cast(image->mTexWidth); + const float texY2 = static_cast(srcY + height) / static_cast(image->mTexHeight); - float texX2 = static_cast(srcX + width) / static_cast( - image->mTexWidth); - float texY2 = static_cast(srcY + height) / static_cast( - image->mTexHeight); glTexCoord2f(texX1, texY1); glVertex2i(dstX, dstY); @@ -102,21 +103,22 @@ static inline void drawQuad(const Image *image, } static inline void drawRescaledQuad(const Image *const image, - int srcX, int srcY, - int dstX, int dstY, int width, int height, - int desiredWidth, int desiredHeight) + const int srcX, const int srcY, + const int dstX, const int dstY, + const int width, const int height, + const int desiredWidth, const int desiredHeight) { if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) { // Find OpenGL normalized texture coordinates. - float texX1 = static_cast(srcX) + const float texX1 = static_cast(srcX) + / static_cast(image->mTexWidth); + const float texY1 = static_cast(srcY) + / static_cast(image->mTexHeight); + const float texX2 = static_cast(srcX + width) / static_cast(image->mTexWidth); - float texY1 = static_cast(srcY) + const float texY2 = static_cast(srcY + height) / static_cast(image->mTexHeight); - float texX2 = static_cast(srcX + width) / static_cast( - image->mTexWidth); - float texY2 = static_cast(srcY + height) / static_cast( - image->mTexHeight); glTexCoord2f(texX1, texY1); glVertex2i(dstX, dstY); @@ -251,18 +253,16 @@ void SafeOpenGLGraphics::drawImagePattern(const Image *const image, if (!image) return; - const int srcX = image->mBounds.x; - const int srcY = image->mBounds.y; - const int iw = image->mBounds.w; const int ih = image->mBounds.h; if (iw == 0 || ih == 0) return; - setColorAlpha(image->mAlpha); + const int srcX = image->mBounds.x; + const int srcY = image->mBounds.y; + setColorAlpha(image->mAlpha); bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - setTexturingAndBlending(true); // Draw a set of textured rectangles @@ -276,7 +276,6 @@ void SafeOpenGLGraphics::drawImagePattern(const Image *const image, { int width = (px + iw >= w) ? w - px : iw; int dstX = x + px; - drawQuad(image, srcX, srcY, dstX, dstY, width, height); } } @@ -293,18 +292,16 @@ void SafeOpenGLGraphics::drawRescaledImagePattern(const Image *const image, if (!image) return; - const int srcX = image->mBounds.x; - const int srcY = image->mBounds.y; - const int iw = scaledWidth; const int ih = scaledHeight; if (iw == 0 || ih == 0) return; - setColorAlpha(image->mAlpha); + const int srcX = image->mBounds.x; + const int srcY = image->mBounds.y; + setColorAlpha(image->mAlpha); bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - setTexturingAndBlending(true); // Draw a set of textured rectangles @@ -406,10 +403,8 @@ SDL_Surface* SafeOpenGLGraphics::getScreenshot() const int w = mTarget->w - (mTarget->w % 4); GLint pack = 1; - SDL_Surface *screenshot = SDL_CreateRGBSurface( - SDL_SWSURFACE, - w, h, 24, - 0xff0000, 0x00ff00, 0x0000ff, 0x000000); + SDL_Surface *const screenshot = SDL_CreateRGBSurface( + SDL_SWSURFACE, w, h, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000); if (!screenshot) return nullptr; @@ -428,9 +423,9 @@ SDL_Surface* SafeOpenGLGraphics::getScreenshot() for (int i = 0; i < (h / 2); i++) { - GLubyte *top = static_cast( + GLubyte *const top = static_cast( screenshot->pixels) + lineSize * i; - GLubyte *bot = static_cast( + GLubyte *const bot = static_cast( screenshot->pixels) + lineSize * (h - 1 - i); memcpy(buf, top, lineSize); @@ -463,7 +458,7 @@ bool SafeOpenGLGraphics::pushClipArea(gcn::Rectangle area) transY = -clipArea.yOffset; } - bool result = gcn::Graphics::pushClipArea(area); + const bool result = gcn::Graphics::pushClipArea(area); const gcn::ClipRectangle &clipArea = mClipStack.top(); transX += clipArea.xOffset; @@ -531,7 +526,7 @@ void SafeOpenGLGraphics::setTargetPlane(int width A_UNUSED, { } -void SafeOpenGLGraphics::setTexturingAndBlending(bool enable) +void SafeOpenGLGraphics::setTexturingAndBlending(const bool enable) { if (enable) { @@ -591,7 +586,7 @@ void SafeOpenGLGraphics::drawRectangle(const gcn::Rectangle& rect, BLOCK_END("Graphics::drawRectangle") } -void SafeOpenGLGraphics::bindTexture(GLenum target, GLuint texture) +void SafeOpenGLGraphics::bindTexture(const GLenum target, const GLuint texture) { if (mLastImage != texture) { diff --git a/src/safeopenglgraphics.h b/src/safeopenglgraphics.h index e9650c6b9..d9b7af5bd 100644 --- a/src/safeopenglgraphics.h +++ b/src/safeopenglgraphics.h @@ -127,7 +127,7 @@ class SafeOpenGLGraphics final : public Graphics void prepareScreenshot() override; - static void bindTexture(GLenum target, GLuint texture); + static void bindTexture(const GLenum target, const GLuint texture); static GLuint mLastImage; @@ -138,7 +138,7 @@ class SafeOpenGLGraphics final : public Graphics const int width, const int height, const bool useColor); - void setTexturingAndBlending(bool enable); + void setTexturingAndBlending(const bool enable); private: void inline setColorAlpha(float alpha); -- cgit v1.2.3-70-g09d2