diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-11-21 21:13:31 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-12-01 22:58:18 +0300 |
commit | 04916c1b451e4400a496ae210b3faa10154c65ac (patch) | |
tree | fe7414434dcb6bcc1405b0d608d82348bc3ca466 /src/mobileopenglgraphics.cpp | |
parent | d48e360ea40536e9f3e7fb4ce381b7fdc2ee5954 (diff) | |
download | manaverse-04916c1b451e4400a496ae210b3faa10154c65ac.tar.gz manaverse-04916c1b451e4400a496ae210b3faa10154c65ac.tar.bz2 manaverse-04916c1b451e4400a496ae210b3faa10154c65ac.tar.xz manaverse-04916c1b451e4400a496ae210b3faa10154c65ac.zip |
Add batch drawing for any images.
Add this drawing to Button.
Diffstat (limited to 'src/mobileopenglgraphics.cpp')
-rw-r--r-- | src/mobileopenglgraphics.cpp | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/src/mobileopenglgraphics.cpp b/src/mobileopenglgraphics.cpp index 52e013f41..92afbc741 100644 --- a/src/mobileopenglgraphics.cpp +++ b/src/mobileopenglgraphics.cpp @@ -654,6 +654,163 @@ void MobileOpenGLGraphics::calcImagePattern(GraphicsVertexes *const vert, vert->incPtr(1); } +void MobileOpenGLGraphics::calcImagePattern(ImageVertexes *const vert, + const Image *const image, + const int x, const int y, + const int w, const int h) const +{ + 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; + + const float tw = static_cast<float>(image->mTexWidth); + const float th = static_cast<float>(image->mTexHeight); + + const unsigned int vLimit = mMaxVertices * 4; + + NormalOpenGLGraphicsVertexes &ogl = vert->ogl; + unsigned int vp = ogl.continueVp(); + + // 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; + + GLfloat *floatTexArray = ogl.continueFloatTexArray(); + GLshort *shortVertArray = ogl.continueShortVertArray(); + + for (int py = 0; py < h; py += ih) + { + const int height = (py + ih >= h) ? h - py : ih; + 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; + + float texX2 = static_cast<float>(srcX + width) / tw; + float texY2 = static_cast<float>(srcY + height) / th; + + floatTexArray[vp + 0] = texX1; + floatTexArray[vp + 1] = texY1; + + floatTexArray[vp + 2] = texX2; + floatTexArray[vp + 3] = texY1; + + floatTexArray[vp + 4] = texX2; + floatTexArray[vp + 5] = texY2; + + floatTexArray[vp + 6] = texX1; + floatTexArray[vp + 7] = texY1; + + floatTexArray[vp + 8] = texX1; + floatTexArray[vp + 9] = texY2; + + floatTexArray[vp + 10] = texX2; + floatTexArray[vp + 11] = texY2; + + + shortVertArray[vp + 0] = dstX; + shortVertArray[vp + 1] = dstY; + + shortVertArray[vp + 2] = dstX + width; + shortVertArray[vp + 3] = dstY; + + shortVertArray[vp + 4] = dstX + width; + shortVertArray[vp + 5] = dstY + height; + + shortVertArray[vp + 6] = dstX; + shortVertArray[vp + 7] = dstY; + + shortVertArray[vp + 8] = dstX; + shortVertArray[vp + 9] = dstY + height; + + shortVertArray[vp + 10] = dstX + width; + shortVertArray[vp + 11] = dstY + height; + + vp += 12; + if (vp >= vLimit) + { + floatTexArray = ogl.switchFloatTexArray(); + shortVertArray = ogl.switchShortVertArray(); + ogl.switchVp(vp); + vp = 0; + } + } + } + } + ogl.switchVp(vp); +} + +void MobileOpenGLGraphics::calcTile(ImageCollection *const vertCol, + const Image *const image, + int x, int y) +{ + if (vertCol->currentGLImage != image->mGLImage) + { + ImageVertexes *const vert = new ImageVertexes(); + vertCol->currentGLImage = image->mGLImage; + vertCol->currentVert = vert; + vert->image = image; + vertCol->draws.push_back(vert); + calcTile(vert, image, x, y); + } + else + { + calcTile(vertCol->currentVert, image, x, y); + } +} + +void MobileOpenGLGraphics::drawTile(const ImageCollection *const vertCol) +{ + const ImageVertexesVector &draws = vertCol->draws; + const ImageCollectionCIter it_end = draws.end(); + for (ImageCollectionCIter it = draws.begin(); it != it_end; ++ it) + { + const ImageVertexes *const vert = *it; + const Image *const image = vert->image; + + setColorAlpha(image->mAlpha); +#ifdef DEBUG_BIND_TEXTURE + debugBindTexture(image); +#endif + bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); + setTexturingAndBlending(true); + drawVertexes(vert->ogl); + } +} + +void MobileOpenGLGraphics::calcImagePattern(ImageCollection* const vertCol, + const Image *const image, + const int x, const int y, + const int w, const int h) const +{ + ImageVertexes *vert = nullptr; + if (vertCol->currentGLImage != image->mGLImage) + { + vert = new ImageVertexes(); + vertCol->currentGLImage = image->mGLImage; + vertCol->currentVert = vert; + vert->image = image; + vertCol->draws.push_back(vert); + } + else + { + vert = vertCol->currentVert; + } + + calcImagePattern(vert, image, x, y, w, h); +} + void MobileOpenGLGraphics::calcTile(ImageVertexes *const vert, const Image *const image, int dstX, int dstY) const @@ -755,6 +912,32 @@ void MobileOpenGLGraphics::drawTile(const ImageVertexes *const vert) drawVertexes(vert->ogl); } +bool MobileOpenGLGraphics::calcWindow(ImageCollection *const vertCol, + const int x, const int y, + const int w, const int h, + const ImageRect &imgRect) +{ + ImageVertexes *vert = nullptr; + Image *const image = imgRect.grid[4]; + if (vertCol->currentGLImage != image->mGLImage) + { + vert = new ImageVertexes(); + vertCol->currentGLImage = image->mGLImage; + vertCol->currentVert = vert; + vert->image = image; + vertCol->draws.push_back(vert); + } + else + { + vert = vertCol->currentVert; + } + + return calcImageRect(vert, x, y, w, h, + imgRect.grid[0], imgRect.grid[2], imgRect.grid[6], imgRect.grid[8], + imgRect.grid[1], imgRect.grid[5], imgRect.grid[7], imgRect.grid[3], + imgRect.grid[4]); +} + void MobileOpenGLGraphics::updateScreen() { BLOCK_START("Graphics::updateScreen") |