summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-06-13 13:19:19 +0300
committerAndrei Karas <akaras@inbox.ru>2014-06-13 13:19:19 +0300
commitd607fc8b853adb02827c10cef32d15f5f152a09d (patch)
tree7b565da0aa4c7a558a2abc14a78e07ffd9d00fa0
parente66c54b5ba9469396ede6d9557688f4441c822a2 (diff)
downloadmanaverse-d607fc8b853adb02827c10cef32d15f5f152a09d.tar.gz
manaverse-d607fc8b853adb02827c10cef32d15f5f152a09d.tar.bz2
manaverse-d607fc8b853adb02827c10cef32d15f5f152a09d.tar.xz
manaverse-d607fc8b853adb02827c10cef32d15f5f152a09d.zip
In modernopengl add support for draw cached tile vertexes.
-rw-r--r--src/render/modernopenglgraphics.cpp57
-rw-r--r--src/test/testlauncher.cpp11
2 files changed, 67 insertions, 1 deletions
diff --git a/src/render/modernopenglgraphics.cpp b/src/render/modernopenglgraphics.cpp
index f37e3336a..ea8447c33 100644
--- a/src/render/modernopenglgraphics.cpp
+++ b/src/render/modernopenglgraphics.cpp
@@ -698,10 +698,67 @@ void ModernOpenGLGraphics::calcTileVertexesInline(ImageVertexes *const vert,
const Image *const image,
int dstX, int dstY) const
{
+ if (!vert || !image)
+ return;
+
+ 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;
+
+ const float tw = static_cast<float>(image->mTexWidth);
+ const float th = static_cast<float>(image->mTexHeight);
+ const ClipRect &clipArea = mClipStack.top();
+ const int x2 = dstX + clipArea.xOffset;
+ const int y2 = dstY + clipArea.yOffset;
+
+ const unsigned int vLimit = mMaxVertices * 4;
+
+ OpenGLGraphicsVertexes &ogl = vert->ogl;
+
+ unsigned int vp = ogl.continueVp();
+
+ 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 *const floatArray = ogl.continueFloatTexArray();
+
+ vertFill2D(floatArray,
+ texX1, texY1, texX2, texY2,
+ x2, y2, w, h);
+
+ vp += 24;
+ if (vp >= vLimit)
+ {
+ ogl.switchFloatTexArray();
+ ogl.switchVp(vp);
+ vp = 0;
+ }
+
+ ogl.switchVp(vp);
}
void ModernOpenGLGraphics::drawTileVertexes(const ImageVertexes *const vert)
{
+ if (!vert)
+ return;
+ const Image *const image = vert->image;
+
+ setColorAlpha(image->mAlpha);
+#ifdef DEBUG_BIND_TEXTURE
+ debugBindTexture(image);
+#endif
+ bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage);
+ setTexturingAndBlending(true);
+ bindArrayBufferAndAttributes(mVbo);
+
+ drawVertexes(vert->ogl);
}
void ModernOpenGLGraphics::calcWindow(ImageCollection *const vertCol,
diff --git a/src/test/testlauncher.cpp b/src/test/testlauncher.cpp
index 86d2be370..d3bb5d571 100644
--- a/src/test/testlauncher.cpp
+++ b/src/test/testlauncher.cpp
@@ -370,10 +370,13 @@ int TestLauncher::testDye()
int TestLauncher::testDraw()
{
- Image *img[2];
+ Image *img[3];
img[0] = Theme::getImageFromTheme("graphics/sprites/arrow_left.png");
img[1] = Theme::getImageFromTheme("graphics/sprites/arrow_right.png");
+ img[2] = Theme::getImageFromTheme("graphics/sprites/arrow_up.png");
ImageCollection *const col = new ImageCollection;
+ ImageVertexes *const vert = new ImageVertexes;
+ vert->image = img[2];
mainGraphics->pushClipArea(Rect(10, 20, 790, 580));
mainGraphics->setColor(Color(0xFFU, 0xFFU, 0x00U, 0xFFU));
@@ -384,6 +387,10 @@ int TestLauncher::testDraw()
mainGraphics->drawImage(img[0], 190, 383);
img[0]->setAlpha(1.0f);
+ mainGraphics->calcTileVertexes(vert, img[2], 10, 10);
+ mainGraphics->calcTileVertexes(vert, img[2], 40, 10);
+ mainGraphics->finalize(vert);
+
mainGraphics->setColor(Color(0x80U, 0x00U, 0xA0U, 0x90U));
mainGraphics->fillRectangle(Rect(200, 100, 300, 300));
mainGraphics->popClipArea();
@@ -398,6 +405,8 @@ int TestLauncher::testDraw()
mainGraphics->calcPattern(col, img[1], 500, 400, 150, 100);
mainGraphics->finalize(col);
+ mainGraphics->drawTileVertexes(vert);
+
mainGraphics->drawRescaledImage(img[0], 250, 350, 35, 90);
mainGraphics->setColor(Color(0x00U, 0xFFU, 0x00U, 0x90U));