summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-06-12 12:48:22 +0300
committerAndrei Karas <akaras@inbox.ru>2014-06-12 13:39:56 +0300
commit0a28edcfc315f4e907fa8f37efe3300efe88c8b8 (patch)
treeff29efa6c77ebb5a9a041f2b5b8e49ea9ddbd787 /src
parent1f1e02d2b0143dd1f89720cc204bb0da36b302e9 (diff)
downloadplus-0a28edcfc315f4e907fa8f37efe3300efe88c8b8.tar.gz
plus-0a28edcfc315f4e907fa8f37efe3300efe88c8b8.tar.bz2
plus-0a28edcfc315f4e907fa8f37efe3300efe88c8b8.tar.xz
plus-0a28edcfc315f4e907fa8f37efe3300efe88c8b8.zip
In modernopengl add rescaleddraw.
Also fix drawpattern.
Diffstat (limited to 'src')
-rw-r--r--src/render/modernopenglgraphics.cpp75
-rw-r--r--src/test/testlauncher.cpp5
2 files changed, 76 insertions, 4 deletions
diff --git a/src/render/modernopenglgraphics.cpp b/src/render/modernopenglgraphics.cpp
index 91b393ed9..3d4cf68a1 100644
--- a/src/render/modernopenglgraphics.cpp
+++ b/src/render/modernopenglgraphics.cpp
@@ -442,12 +442,12 @@ void ModernOpenGLGraphics::drawPatternInline(const Image *const image,
texX1, texY1, texX2, texY2,
dstX, dstY, width, height);
+ vp += 24;
if (vp >= vLimit)
{
drawTriangleArray(vp);
vp = 0;
}
- vp += 24;
}
}
if (vp > 0)
@@ -460,6 +460,74 @@ void ModernOpenGLGraphics::drawRescaledPattern(const Image *const image,
const int scaledWidth,
const int scaledHeight)
{
+ if (!image)
+ return;
+
+ if (scaledWidth == 0 || scaledHeight == 0)
+ return;
+
+ 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;
+
+#ifdef DEBUG_BIND_TEXTURE
+ debugBindTexture(image);
+#endif
+ bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage);
+
+ setTexturingAndBlending(true);
+ setColorAlpha(image->mAlpha);
+
+ unsigned int vp = 0;
+ const unsigned int vLimit = mMaxVertices * 4;
+
+ const float tw = static_cast<float>(image->mTexWidth);
+ const float th = static_cast<float>(image->mTexHeight);
+ const ClipRect &clipArea = mClipStack.top();
+ const int x2 = x + clipArea.xOffset;
+ const int y2 = y + clipArea.yOffset;
+
+ const float texX1 = static_cast<float>(srcX) / tw;
+ const float texY1 = static_cast<float>(srcY) / th;
+
+ const float tFractionW = iw / tw;
+ const float tFractionH = ih / th;
+
+ for (int py = 0; py < h; py += scaledHeight)
+ {
+ const int height = (py + scaledHeight >= h)
+ ? h - py : scaledHeight;
+ const int dstY = y2 + py;
+ const float visibleFractionH = static_cast<float>(height)
+ / scaledHeight;
+ const float texY2 = texY1 + tFractionH * visibleFractionH;
+ for (int px = 0; px < w; px += scaledWidth)
+ {
+ const int width = (px + scaledWidth >= w)
+ ? w - px : scaledWidth;
+ const int dstX = x2 + px;
+ const float visibleFractionW = static_cast<float>(width)
+ / scaledWidth;
+ const float texX2 = texX1 + tFractionW * visibleFractionW;
+
+ vertFill2D(mFloatArray,
+ texX1, texY1, texX2, texY2,
+ dstX, dstY, width, height);
+
+ vp += 24;
+ if (vp >= vLimit)
+ {
+ drawTriangleArray(vp);
+ vp = 0;
+ }
+ }
+ }
+ if (vp > 0)
+ drawTriangleArray(vp);
}
inline void ModernOpenGLGraphics::drawVertexes(const
@@ -888,11 +956,12 @@ void ModernOpenGLGraphics::clearScreen() const
void ModernOpenGLGraphics::drawTriangleArray(const int size)
{
- mglBufferData(GL_ARRAY_BUFFER, size, mFloatArray, GL_DYNAMIC_DRAW);
+ mglBufferData(GL_ARRAY_BUFFER, size * sizeof(GLfloat),
+ mFloatArray, GL_DYNAMIC_DRAW);
#ifdef DEBUG_DRAW_CALLS
mDrawCalls ++;
#endif
- glDrawArrays(GL_TRIANGLES, 0, size / 2);;
+ glDrawArrays(GL_TRIANGLES, 0, size / 4);
}
#ifdef DEBUG_BIND_TEXTURE
diff --git a/src/test/testlauncher.cpp b/src/test/testlauncher.cpp
index d5aaa4c0e..25cb639a4 100644
--- a/src/test/testlauncher.cpp
+++ b/src/test/testlauncher.cpp
@@ -393,7 +393,7 @@ int TestLauncher::testDraw()
boldFont->drawString(mainGraphics,
"test test test test test test test test ", 300, 100);
- mainGraphics->drawPattern(img[0], 10, 400, 100, 200);
+ mainGraphics->drawPattern(img[0], 10, 400, 300, 180);
mainGraphics->calcPattern(col, img[1], 500, 400, 150, 100);
mainGraphics->drawTileCollection(col);
@@ -403,6 +403,9 @@ int TestLauncher::testDraw()
mainGraphics->setColor(Color(0x00U, 0xFFU, 0x00U, 0x90U));
mainGraphics->drawNet(450, 10, 600, 300, 32, 20);
+ img[0]->setAlpha(0.3f);
+ mainGraphics->drawRescaledPattern(img[0], 250, 150, 250, 300, 30, 100);
+
for (int f = 0; f < 255; f ++)
{
mainGraphics->setColor(Color(0x20U, 0x60U, f, 0x90U));