summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-03-10 17:04:53 +0300
committerAndrei Karas <akaras@inbox.ru>2013-03-10 18:19:52 +0300
commit4b00aaef2f780339719de516fa392de2de9c9943 (patch)
tree8a622f53490b55be9e89879036b0587bcc10604e /src
parent2ca9a8ee8e3e2532fec2b7c3540c2d3f9b6264db (diff)
downloadplus-4b00aaef2f780339719de516fa392de2de9c9943.tar.gz
plus-4b00aaef2f780339719de516fa392de2de9c9943.tar.bz2
plus-4b00aaef2f780339719de516fa392de2de9c9943.tar.xz
plus-4b00aaef2f780339719de516fa392de2de9c9943.zip
Improve mobileopenglgraphics class.
Diffstat (limited to 'src')
-rw-r--r--src/mobileopenglgraphics.cpp151
-rw-r--r--src/mobileopenglgraphics.h8
2 files changed, 80 insertions, 79 deletions
diff --git a/src/mobileopenglgraphics.cpp b/src/mobileopenglgraphics.cpp
index b1eab09cd..f0ec87d36 100644
--- a/src/mobileopenglgraphics.cpp
+++ b/src/mobileopenglgraphics.cpp
@@ -86,11 +86,12 @@ void MobileOpenGLGraphics::initArrays()
mMaxVertices = 1024;
// need alocate small size, after if limit reached reallocate to double size
+ const int sz = mMaxVertices * 4 + 30;
vertexBufSize = mMaxVertices;
- mFloatTexArray = new GLfloat[mMaxVertices * 4 + 30];
- mIntTexArray = new GLint[mMaxVertices * 4 + 30];
- mIntVertArray = new GLint[mMaxVertices * 4 + 30];
- mShortVertArray = new GLshort[mMaxVertices * 4 + 30];
+ mFloatTexArray = new GLfloat[sz];
+ mIntTexArray = new GLint[sz];
+ mIntVertArray = new GLint[sz];
+ mShortVertArray = new GLshort[sz];
}
bool MobileOpenGLGraphics::setVideoMode(const int w, const int h,
@@ -103,9 +104,10 @@ bool MobileOpenGLGraphics::setVideoMode(const int w, const int h,
return setOpenGLMode();
}
-static inline void drawQuad(const Image *image,
- int srcX, int srcY, int dstX, int dstY,
- int width, int height)
+static inline void drawQuad(const Image *const image,
+ const int srcX, const int srcY,
+ const int dstX, const int dstY,
+ const int width, const int height)
{
// if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
{
@@ -147,9 +149,11 @@ 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)
{
@@ -202,8 +206,9 @@ bool MobileOpenGLGraphics::drawImage2(const Image *const image,
if (!image)
return false;
- srcX += image->mBounds.x;
- srcY += image->mBounds.y;
+ const SDL_Rect &imageRect = image->mBounds;
+ srcX += imageRect.x;
+ srcY += imageRect.y;
if (!useColor)
setColorAlpha(image->mAlpha);
@@ -260,8 +265,9 @@ bool MobileOpenGLGraphics::drawRescaledImage(const Image *const image,
if (width > desiredWidth && height > desiredHeight)
smooth = false;
- srcX += image->mBounds.x;
- srcY += image->mBounds.y;
+ const SDL_Rect &imageRect = image->mBounds;
+ srcX += imageRect.x;
+ srcY += imageRect.y;
if (!useColor)
setColorAlpha(image->mAlpha);
@@ -302,11 +308,11 @@ void MobileOpenGLGraphics::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;
+ const SDL_Rect &imageRect = image->mBounds;
+ const int srcX = imageRect.x;
+ const int srcY = imageRect.y;
+ const int iw = imageRect.w;
+ const int ih = imageRect.h;
if (iw == 0 || ih == 0)
return;
@@ -328,20 +334,20 @@ void MobileOpenGLGraphics::drawImagePattern(const Image *const image,
// Draw a set of textured rectangles
// if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
// {
- float texX1 = static_cast<float>(srcX) / tw;
- float texY1 = static_cast<float>(srcY) / th;
+ const float texX1 = static_cast<float>(srcX) / tw;
+ const float texY1 = static_cast<float>(srcY) / th;
for (int py = 0; py < h; py += ih)
{
const int height = (py + ih >= h) ? h - py : ih;
+ const float texY2 = static_cast<float>(srcY + height) / th;
const int dstY = y + py;
for (int px = 0; px < w; px += iw)
{
- int width = (px + iw >= w) ? w - px : iw;
- int dstX = x + px;
+ const int width = (px + iw >= w) ? w - px : iw;
+ const int dstX = x + px;
- float texX2 = static_cast<float>(srcX + width) / tw;
- float texY2 = static_cast<float>(srcY + height) / th;
+ const float texX2 = static_cast<float>(srcX + width) / tw;
mFloatTexArray[vp + 0] = texX1; //1
mFloatTexArray[vp + 1] = texY1;
@@ -358,7 +364,7 @@ void MobileOpenGLGraphics::drawImagePattern(const Image *const image,
mFloatTexArray[vp + 8] = texX1; //4
mFloatTexArray[vp + 9] = texY2;
- mFloatTexArray[vp + 10] = texX2; //3
+ mFloatTexArray[vp + 10] = texX2; //3
mFloatTexArray[vp + 11] = texY2;
mShortVertArray[vp + 0] = static_cast<GLshort>(dstX);
@@ -404,11 +410,11 @@ void MobileOpenGLGraphics::drawRescaledImagePattern(const Image *const image,
if (scaledWidth == 0 || scaledHeight == 0)
return;
- const int srcX = image->mBounds.x;
- const int srcY = image->mBounds.y;
-
- const int iw = image->getWidth();
- const int ih = image->getHeight();
+ const SDL_Rect &imageRect = image->mBounds;
+ const int srcX = imageRect.x;
+ const int srcY = imageRect.y;
+ const int iw = imageRect.w;
+ const int ih = imageRect.h;
if (iw == 0 || ih == 0)
return;
@@ -441,17 +447,16 @@ void MobileOpenGLGraphics::drawRescaledImagePattern(const Image *const image,
const int height = (py + scaledHeight >= h)
? h - py : scaledHeight;
const int dstY = y + py;
+ const float visibleFractionH = static_cast<float>(height)
+ / scaledHeight;
+ const float texY2 = texY1 + tFractionH * visibleFractionH;
for (int px = 0; px < w; px += scaledWidth)
{
- int width = (px + scaledWidth >= w) ? w - px : scaledWidth;
- int dstX = x + px;
+ const int width = (px + scaledWidth >= w) ? w - px : scaledWidth;
+ const int dstX = x + px;
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;
mFloatTexArray[vp + 0] = texX1;
mFloatTexArray[vp + 1] = texY1;
@@ -540,11 +545,11 @@ void MobileOpenGLGraphics::calcImagePattern(ImageVertexes *const vert,
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;
+ const SDL_Rect &imageRect = image->mBounds;
+ const int srcX = imageRect.x;
+ const int srcY = imageRect.y;
+ const int iw = imageRect.w;
+ const int ih = imageRect.h;
if (iw == 0 || ih == 0)
return;
@@ -560,8 +565,8 @@ void MobileOpenGLGraphics::calcImagePattern(ImageVertexes *const vert,
// Draw a set of textured rectangles
// if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
{
- float texX1 = static_cast<float>(srcX) / tw;
- float texY1 = static_cast<float>(srcY) / th;
+ const float texX1 = static_cast<float>(srcX) / tw;
+ const float texY1 = static_cast<float>(srcY) / th;
GLfloat *floatTexArray = ogl.continueFloatTexArray();
GLshort *shortVertArray = ogl.continueShortVertArray();
@@ -570,13 +575,12 @@ void MobileOpenGLGraphics::calcImagePattern(ImageVertexes *const vert,
{
const int height = (py + ih >= h) ? h - py : ih;
const int dstY = y + py;
+ const float texY2 = static_cast<float>(srcY + height) / th;
for (int px = 0; px < w; px += iw)
{
- int width = (px + iw >= w) ? w - px : iw;
- int dstX = x + px;
-
- float texX2 = static_cast<float>(srcX + width) / tw;
- float texY2 = static_cast<float>(srcY + height) / th;
+ const int width = (px + iw >= w) ? w - px : iw;
+ const int dstX = x + px;
+ const float texX2 = static_cast<float>(srcX + width) / tw;
floatTexArray[vp + 0] = texX1;
floatTexArray[vp + 1] = texY1;
@@ -596,7 +600,6 @@ void MobileOpenGLGraphics::calcImagePattern(ImageVertexes *const vert,
floatTexArray[vp + 10] = texX2;
floatTexArray[vp + 11] = texY2;
-
shortVertArray[vp + 0] = dstX;
shortVertArray[vp + 1] = dstY;
@@ -696,11 +699,11 @@ void MobileOpenGLGraphics::calcTile(ImageVertexes *const vert,
if (!vert || !image)
return;
- const int srcX = image->mBounds.x;
- const int srcY = image->mBounds.y;
-
- const int w = image->mBounds.w;
- const int h = image->mBounds.h;
+ const SDL_Rect &imageRect = image->mBounds;
+ const int srcX = imageRect.x;
+ const int srcY = imageRect.y;
+ const int w = imageRect.w;
+ const int h = imageRect.h;
if (w == 0 || h == 0)
return;
@@ -720,12 +723,11 @@ void MobileOpenGLGraphics::calcTile(ImageVertexes *const vert,
{
float texX1 = static_cast<float>(srcX) / tw;
float texY1 = static_cast<float>(srcY) / th;
-
float texX2 = static_cast<float>(srcX + w) / tw;
float texY2 = static_cast<float>(srcY + h) / th;
- GLfloat *floatTexArray = ogl.continueFloatTexArray();
- GLshort *shortVertArray = ogl.continueShortVertArray();
+ GLfloat *const floatTexArray = ogl.continueFloatTexArray();
+ GLshort *const shortVertArray = ogl.continueShortVertArray();
floatTexArray[vp + 0] = texX1;
floatTexArray[vp + 1] = texY1;
@@ -779,7 +781,7 @@ void MobileOpenGLGraphics::drawTile(const ImageVertexes *const vert)
{
if (!vert)
return;
- const Image *image = vert->image;
+ const Image *const image = vert->image;
setColorAlpha(image->mAlpha);
#ifdef DEBUG_BIND_TEXTURE
@@ -796,7 +798,7 @@ bool MobileOpenGLGraphics::calcWindow(ImageCollection *const vertCol,
const ImageRect &imgRect)
{
ImageVertexes *vert = nullptr;
- Image *const image = imgRect.grid[4];
+ const Image *const image = imgRect.grid[4];
if (vertCol->currentGLImage != image->mGLImage)
{
vert = new ImageVertexes();
@@ -898,10 +900,9 @@ SDL_Surface* MobileOpenGLGraphics::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;
@@ -915,14 +916,14 @@ SDL_Surface* MobileOpenGLGraphics::getScreenshot()
glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, screenshot->pixels);
// Flip the screenshot, as OpenGL has 0,0 in bottom left
- unsigned int lineSize = 3 * w;
- GLubyte* buf = static_cast<GLubyte*>(malloc(lineSize));
+ const unsigned int lineSize = 3 * w;
+ GLubyte *const buf = static_cast<GLubyte*>(malloc(lineSize));
for (int i = 0; i < (h / 2); i++)
{
- GLubyte *top = static_cast<GLubyte*>(
+ GLubyte *const top = static_cast<GLubyte*>(
screenshot->pixels) + lineSize * i;
- GLubyte *bot = static_cast<GLubyte*>(
+ GLubyte *const bot = static_cast<GLubyte*>(
screenshot->pixels) + lineSize * (h - 1 - i);
memcpy(buf, top, lineSize);
@@ -955,7 +956,7 @@ bool MobileOpenGLGraphics::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;
@@ -1032,7 +1033,7 @@ void MobileOpenGLGraphics::setTargetPlane(int width A_UNUSED,
{
}
-void MobileOpenGLGraphics::setTexturingAndBlending(bool enable)
+void MobileOpenGLGraphics::setTexturingAndBlending(const bool enable)
{
if (enable)
{
@@ -1174,7 +1175,7 @@ bool MobileOpenGLGraphics::drawNet(const int x1, const int y1,
return true;
}
-void MobileOpenGLGraphics::bindTexture(GLenum target, GLuint texture)
+void MobileOpenGLGraphics::bindTexture(const GLenum target, const GLuint texture)
{
if (mLastImage != texture)
{
@@ -1194,9 +1195,9 @@ inline void MobileOpenGLGraphics::drawTriangleArrayfs(const int size)
glDrawArrays(GL_TRIANGLES, 0, size / 2);
}
-inline void MobileOpenGLGraphics::drawTriangleArrayfs(GLshort *const
+inline void MobileOpenGLGraphics::drawTriangleArrayfs(const GLshort *const
shortVertArray,
- GLfloat *const
+ const GLfloat *const
floatTexArray,
const int size)
{
@@ -1263,7 +1264,7 @@ void MobileOpenGLGraphics::restoreColor()
}
#ifdef DEBUG_BIND_TEXTURE
-void MobileOpenGLGraphics::debugBindTexture(const Image *image)
+void MobileOpenGLGraphics::debugBindTexture(const Image *const image)
{
const std::string texture = image->getIdPath();
if (mOldTexture != texture)
@@ -1279,7 +1280,7 @@ void MobileOpenGLGraphics::debugBindTexture(const Image *image)
}
}
#else
-void MobileOpenGLGraphics::debugBindTexture(const Image *image A_UNUSED)
+void MobileOpenGLGraphics::debugBindTexture(const Image *const image A_UNUSED)
{
}
#endif
diff --git a/src/mobileopenglgraphics.h b/src/mobileopenglgraphics.h
index b59b33583..0bb57f28e 100644
--- a/src/mobileopenglgraphics.h
+++ b/src/mobileopenglgraphics.h
@@ -144,8 +144,8 @@ class MobileOpenGLGraphics final : public Graphics
void setTargetPlane(int width, int height);
- inline void drawTriangleArrayfs(GLshort *shortVertArray,
- GLfloat *floatTexArray,
+ inline void drawTriangleArrayfs(const GLshort *const shortVertArray,
+ const GLfloat *const floatTexArray,
const int size);
inline void drawTriangleArrayfs(const int size);
@@ -181,7 +181,7 @@ class MobileOpenGLGraphics final : public Graphics
static unsigned int mLastDrawCalls;
#endif
- static void bindTexture(GLenum target, GLuint texture);
+ static void bindTexture(const GLenum target, const GLuint texture);
static GLuint mLastImage;
@@ -192,7 +192,7 @@ class MobileOpenGLGraphics final : public Graphics
const int width, const int height,
const bool useColor) override;
- void setTexturingAndBlending(bool enable);
+ void setTexturingAndBlending(const bool enable);
void updateMemoryInfo();