summaryrefslogtreecommitdiff
path: root/src/normalopenglgraphics.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/normalopenglgraphics.cpp')
-rw-r--r--src/normalopenglgraphics.cpp219
1 files changed, 219 insertions, 0 deletions
diff --git a/src/normalopenglgraphics.cpp b/src/normalopenglgraphics.cpp
index 11cc8ab5f..f7ca7b802 100644
--- a/src/normalopenglgraphics.cpp
+++ b/src/normalopenglgraphics.cpp
@@ -823,6 +823,199 @@ void NormalOpenGLGraphics::calcImagePattern(GraphicsVertexes *const vert,
vert->incPtr(1);
}
+void NormalOpenGLGraphics::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();
+ GLint *intVertArray = ogl.continueIntVertArray();
+
+ 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] = texY2;
+
+ intVertArray[vp + 0] = dstX;
+ intVertArray[vp + 1] = dstY;
+
+ intVertArray[vp + 2] = dstX + width;
+ intVertArray[vp + 3] = dstY;
+
+ intVertArray[vp + 4] = dstX + width;
+ intVertArray[vp + 5] = dstY + height;
+
+ intVertArray[vp + 6] = dstX;
+ intVertArray[vp + 7] = dstY + height;
+
+ vp += 8;
+ if (vp >= vLimit)
+ {
+ floatTexArray = ogl.switchFloatTexArray();
+ intVertArray = ogl.switchIntVertArray();
+ ogl.switchVp(vp);
+ vp = 0;
+ }
+ }
+ }
+ }
+ else
+ {
+ GLint *intTexArray = ogl.continueIntTexArray();
+ GLint *intVertArray = ogl.continueIntVertArray();
+
+ 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;
+
+ intTexArray[vp + 0] = srcX;
+ intTexArray[vp + 1] = srcY;
+
+ intTexArray[vp + 2] = srcX + width;
+ intTexArray[vp + 3] = srcY;
+
+ intTexArray[vp + 4] = srcX + width;
+ intTexArray[vp + 5] = srcY + height;
+
+ intTexArray[vp + 6] = srcX;
+ intTexArray[vp + 7] = srcY + height;
+
+ intVertArray[vp + 0] = dstX;
+ intVertArray[vp + 1] = dstY;
+
+ intVertArray[vp + 2] = dstX + width;
+ intVertArray[vp + 3] = dstY;
+
+ intVertArray[vp + 4] = dstX + width;
+ intVertArray[vp + 5] = dstY + height;
+
+ intVertArray[vp + 6] = dstX;
+ intVertArray[vp + 7] = dstY + height;
+
+ vp += 8;
+ if (vp >= vLimit)
+ {
+ intTexArray = ogl.switchIntTexArray();
+ intVertArray = ogl.switchIntVertArray();
+ ogl.switchVp(vp);
+ vp = 0;
+ }
+ }
+ }
+ }
+ ogl.switchVp(vp);
+}
+
+void NormalOpenGLGraphics::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 NormalOpenGLGraphics::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 NormalOpenGLGraphics::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 NormalOpenGLGraphics::calcTile(ImageVertexes *const vert,
const Image *const image,
int dstX, int dstY) const
@@ -950,6 +1143,32 @@ void NormalOpenGLGraphics::drawTile(const ImageVertexes *const vert)
drawVertexes(vert->ogl);
}
+bool NormalOpenGLGraphics::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 NormalOpenGLGraphics::updateScreen()
{
BLOCK_START("Graphics::updateScreen")