23 #if defined USE_OPENGL && !defined ANDROID 30 #ifdef __native_client__ 32 #endif // __native_client__ 49 #define vertFill2D(var, x1, y1, x2, y2, dstX, dstY, w, h) \ 55 var[vp + 4] = dstX + w; \ 60 var[vp + 8] = dstX + w; \ 61 var[vp + 9] = dstY + h; \ 65 var[vp + 12] = dstX; \ 66 var[vp + 13] = dstY; \ 70 var[vp + 16] = dstX; \ 71 var[vp + 17] = dstY + h; \ 75 var[vp + 20] = dstX + w; \ 76 var[vp + 21] = dstY + h; \ 80 #define toGL static_cast<GLfloat> 86 #ifdef DEBUG_DRAW_CALLS 87 unsigned int MobileOpenGL2Graphics::mDrawCalls = 0U;
88 unsigned int MobileOpenGL2Graphics::mLastDrawCalls = 0U;
89 #endif // DEBUG_DRAW_CALLS 100 mSimpleColorUniform(0U),
102 mTextureColorUniform(0U),
104 mDrawTypeUniform(0U),
105 #ifndef __native_client__
110 mAttributesBinded(0U),
113 #ifdef DEBUG_BIND_TEXTURE
120 mName =
"mobile OpenGL ES 2";
133 mglDeleteBuffers(1, &
mVbo);
134 #ifndef __native_client__ 136 mglDeleteVertexArrays(1, &
mVao);
137 #endif // __native_client__ 159 #ifndef __native_client__ 160 mglGenVertexArrays(1, &
mVao);
161 mglBindVertexArray(
mVao);
162 #endif // __native_client__ 163 mglGenBuffers(1, &
mVbo);
178 logger->
log(
"Shaders compilation done.");
191 mglVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0,
nullptr);
192 mglEnableVertexAttribArray(0);
196 static_cast<float>(
mWidth) / 2.0f,
197 static_cast<float>(
mHeight) / 2.0f);
208 mglActiveTexture(GL_TEXTURE0);
261 static_cast<float>(color.r) / 255.0F,
262 static_cast<float>(color.g) / 255.0F,
263 static_cast<float>(color.b) / 255.0F,
264 static_cast<float>(color.a) / 255.0F);
284 const GLfloat texX2 =
static_cast<GLfloat
>(srcX + width);
285 const GLfloat texY2 =
static_cast<GLfloat
>(srcY + height);
286 const GLfloat x2 =
static_cast<GLfloat
>(dstX + width);
287 const GLfloat y2 =
static_cast<GLfloat
>(dstY + height);
288 const GLfloat srcX2 =
toGL(srcX);
289 const GLfloat srcY2 =
toGL(srcY);
290 const GLfloat dstX2 =
toGL(dstX);
291 const GLfloat dstY2 =
toGL(dstY);
295 dstX2, dstY2, srcX2, srcY2,
296 x2, dstY2, texX2, srcY2,
297 dstX2, y2, srcX2, texY2,
303 #ifdef DEBUG_DRAW_CALLS 305 #endif // DEBUG_DRAW_CALLS 309 #endif // OPENGLERRORS 313 const int dstX,
const int dstY,
314 const int width,
const int height,
315 const int desiredWidth,
318 const GLfloat texX2 =
static_cast<GLfloat
>(srcX + width);
319 const GLfloat texY2 =
static_cast<GLfloat
>(srcY + height);
320 const GLfloat x2 =
static_cast<GLfloat
>(dstX + desiredWidth);
321 const GLfloat y2 =
static_cast<GLfloat
>(dstY + desiredHeight);
322 const GLfloat srcX2 =
toGL(srcX);
323 const GLfloat srcY2 =
toGL(srcY);
324 const GLfloat dstX2 =
toGL(dstX);
325 const GLfloat dstY2 =
toGL(dstY);
329 dstX2, dstY2, srcX2, srcY2,
330 x2, dstY2, texX2, srcY2,
331 dstX2, y2, srcX2, texY2,
337 #ifdef DEBUG_DRAW_CALLS 339 #endif // DEBUG_DRAW_CALLS 343 #endif // OPENGLERRORS 356 if (image ==
nullptr)
359 #ifdef DEBUG_BIND_TEXTURE 361 #endif // DEBUG_BIND_TEXTURE 368 const SDL_Rect &imageRect = image->mBounds;
397 #ifdef DEBUG_DRAW_CALLS 399 #endif // DEBUG_DRAW_CALLS 404 #endif // OPENGLERRORS 416 const int x A_UNUSED,
417 const int y A_UNUSED,
418 const int w A_UNUSED,
430 const int desiredWidth,
431 const int desiredHeight)
434 if (image ==
nullptr)
437 const SDL_Rect &imageRect = image->mBounds;
440 if (imageRect.w == desiredWidth && imageRect.h == desiredHeight)
447 #ifdef DEBUG_BIND_TEXTURE 449 #endif // DEBUG_BIND_TEXTURE 467 const int x,
const int y,
475 const int x,
const int y,
476 const int w,
const int h)
479 if (image ==
nullptr)
482 const SDL_Rect &imageRect = image->mBounds;
483 const int iw = imageRect.w;
484 const int ih = imageRect.h;
486 if (iw == 0 || ih == 0)
489 const int srcX = imageRect.x;
490 const int srcY = imageRect.y;
491 const GLfloat srcX2 =
toGL(srcX);
492 const GLfloat srcY2 =
toGL(srcY);
494 const int x2 =
x + clipArea.
xOffset;
495 const int y2 =
y + clipArea.
yOffset;
497 #ifdef DEBUG_BIND_TEXTURE 499 #endif // DEBUG_BIND_TEXTURE 509 for (
int py = 0; py < h; py += ih)
511 const int height = (py + ih >= h) ? h - py : ih;
512 const GLfloat texY2 =
static_cast<GLfloat
>(srcY + height);
513 const GLfloat dstY =
static_cast<GLfloat
>(y2 + py);
514 for (
int px = 0; px < w; px += iw)
516 const int width = (px + iw >= w) ? w - px : iw;
517 const GLfloat dstX =
static_cast<GLfloat
>(x2 + px);
518 const GLfloat texX2 =
static_cast<GLfloat
>(srcX + width);
521 srcX2, srcY2, texX2, texY2,
522 dstX, dstY, width, height);
538 const int x,
const int y,
539 const int w,
const int h,
540 const int scaledWidth,
541 const int scaledHeight)
544 if (image ==
nullptr)
547 if (scaledWidth == 0 || scaledHeight == 0)
550 const SDL_Rect &imageRect = image->mBounds;
551 const int iw = imageRect.w;
552 const int ih = imageRect.h;
553 if (iw == 0 || ih == 0)
556 const int srcX = imageRect.x;
557 const int srcY = imageRect.y;
558 const GLfloat srcX2 =
toGL(srcX);
559 const GLfloat srcY2 =
toGL(srcY);
561 #ifdef DEBUG_BIND_TEXTURE 563 #endif // DEBUG_BIND_TEXTURE 574 const int x2 =
x + clipArea.
xOffset;
575 const int y2 =
y + clipArea.
yOffset;
577 const float scaleFactorW =
static_cast<float>(scaledWidth) / iw;
578 const float scaleFactorH =
static_cast<float>(scaledHeight) / ih;
580 for (
int py = 0; py < h; py += scaledHeight)
582 const int height = (py + scaledHeight >= h)
583 ? h - py : scaledHeight;
584 const GLfloat dstY =
static_cast<GLfloat
>(y2 + py);
585 const GLfloat scaledY = srcY + height / scaleFactorH;
586 for (
int px = 0; px < w; px += scaledWidth)
588 const int width = (px + scaledWidth >= w)
589 ? w - px : scaledWidth;
590 const GLfloat dstX =
static_cast<GLfloat
>(x2 + px);
591 const GLfloat scaledX = srcX + width / scaleFactorW;
597 static_cast<GLfloat>(width), static_cast<GLfloat>(height));
615 const STD_VECTOR<int> &vp = ogl.mVp;
616 const STD_VECTOR<GLuint> &vbos = ogl.mVbo;
617 STD_VECTOR<int>::const_iterator ivp;
618 STD_VECTOR<GLuint>::const_iterator ivbo;
619 const STD_VECTOR<int>::const_iterator ivp_end = vp.end();
621 for (ivp = vp.begin(), ivbo = vbos.begin();
626 #ifdef DEBUG_DRAW_CALLS 628 #endif // DEBUG_DRAW_CALLS 632 #endif // OPENGLERRORS 655 if (image ==
nullptr || vert ==
nullptr)
658 const SDL_Rect &imageRect = image->mBounds;
659 const int iw = imageRect.w;
660 const int ih = imageRect.h;
662 if (iw == 0 || ih == 0)
665 const int srcX = imageRect.x;
666 const int srcY = imageRect.y;
667 const GLfloat srcX2 =
toGL(srcX);
668 const GLfloat srcY2 =
toGL(srcY);
671 const int x2 =
x + clipArea.
xOffset;
672 const int y2 =
y + clipArea.
yOffset;
681 for (
int py = 0; py < h; py += ih)
683 const GLfloat height =
static_cast<GLfloat
>(
684 (py + ih >= h) ? h - py : ih);
685 const GLfloat dstY =
static_cast<GLfloat
>(y2 + py);
686 const GLfloat texY2 = srcY + height;
687 for (
int px = 0; px < w; px += iw)
689 const GLfloat width =
static_cast<GLfloat
>(
690 (px + iw >= w) ? w - px : iw);
691 const GLfloat dstX =
static_cast<GLfloat
>(x2 + px);
692 const GLfloat texX2 = srcX2 + width;
695 srcX2, srcY2, texX2, texY2,
696 dstX, dstY, width, height);
716 if (vertCol ==
nullptr || image ==
nullptr)
718 if (vertCol->currentGLImage != image->mGLImage)
721 vertCol->currentGLImage = image->mGLImage;
722 vertCol->currentVert = vert;
724 vertCol->draws.push_back(vert);
746 #ifdef DEBUG_BIND_TEXTURE 748 #endif // DEBUG_BIND_TEXTURE 762 if (vertCol ==
nullptr || image ==
nullptr)
765 if (vertCol->currentGLImage != image->mGLImage)
768 vertCol->currentGLImage = image->mGLImage;
769 vertCol->currentVert = vert;
771 vertCol->draws.push_back(vert);
775 vert = vertCol->currentVert;
797 const SDL_Rect &imageRect = image->mBounds;
798 const int w = imageRect.w;
799 const int h = imageRect.h;
801 if (w == 0 || h == 0)
804 const int srcX = imageRect.x;
805 const int srcY = imageRect.y;
806 const GLfloat srcX2 =
toGL(srcX);
807 const GLfloat srcY2 =
toGL(srcY);
810 const GLfloat x2 =
static_cast<GLfloat
>(dstX + clipArea.
xOffset);
811 const GLfloat y2 =
static_cast<GLfloat
>(dstY + clipArea.
yOffset);
819 GLfloat texX2 =
static_cast<GLfloat
>(srcX + w);
820 GLfloat texY2 =
static_cast<GLfloat
>(srcY + h);
825 srcX2, srcY2, texX2, texY2,
844 const Image *
const image = vert->image;
847 #ifdef DEBUG_BIND_TEXTURE 849 #endif // DEBUG_BIND_TEXTURE 858 const int x,
const int y,
859 const int w,
const int h,
864 const Image *
const image = imgRect.grid[4];
865 if (image ==
nullptr)
867 if (vertCol->currentGLImage != image->
mGLImage)
870 vertCol->currentGLImage = image->
mGLImage;
871 vertCol->currentVert = vert;
873 vertCol->draws.push_back(vert);
877 vert = vertCol->currentVert;
885 #ifdef DEBUG_DRAW_CALLS 886 mLastDrawCalls = mDrawCalls;
888 #endif // DEBUG_DRAW_CALLS 892 SDL_GL_SwapBuffers();
896 mglFrameTerminator();
897 #endif // DEBUG_OPENGL 904 #ifndef __native_client__ 906 mglHint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB, GL_FASTEST);
907 #endif // __native_client__ 953 #ifdef DEBUG_DRAW_CALLS 955 #endif // DEBUG_DRAW_CALLS 959 #endif // OPENGLERRORS 975 #ifdef DEBUG_DRAW_CALLS 977 #endif // DEBUG_DRAW_CALLS 981 #endif // OPENGLERRORS 989 const GLfloat x1 =
static_cast<GLfloat
>(rect.x + clipArea.
xOffset);
990 const GLfloat y1 =
static_cast<GLfloat
>(rect.y + clipArea.
yOffset);
991 const GLfloat x2 = x1 +
static_cast<GLfloat
>(rect.width);
992 const GLfloat y2 = y1 +
static_cast<GLfloat
>(rect.height);
1003 #ifdef DEBUG_DRAW_CALLS 1005 #endif // DEBUG_DRAW_CALLS 1009 #endif // OPENGLERRORS 1017 const GLfloat x1 =
static_cast<GLfloat
>(rect.x + clipArea.
xOffset);
1018 const GLfloat y1 =
static_cast<GLfloat
>(rect.y + clipArea.
yOffset);
1019 const GLfloat x2 = x1 +
static_cast<GLfloat
>(rect.width);
1020 const GLfloat y2 = y1 +
static_cast<GLfloat
>(rect.height);
1021 GLfloat vertices[] =
1031 #ifdef DEBUG_DRAW_CALLS 1033 #endif // DEBUG_DRAW_CALLS 1037 #endif // OPENGLERRORS 1085 unsigned int vp = 0;
1091 const GLfloat dx =
static_cast<GLfloat
>(clipArea.
xOffset);
1092 const GLfloat dy =
static_cast<GLfloat
>(clipArea.
yOffset);
1094 const GLfloat xs1 = x1 + dx;
1095 const GLfloat xs2 = x2 + dx;
1096 const GLfloat ys1 = y1 + dy;
1097 const GLfloat ys2 = y2 + dy;
1099 for (
int y = y1;
y < y2;
y += height)
1119 for (
int x = x1;
x < x2;
x += width)
1146 const GLuint texture = image->mGLImage;
1157 static_cast<GLfloat>(image->mTexWidth),
1158 static_cast<GLfloat>(image->mTexHeight));
1164 const GLuint texture)
1177 mglDeleteBuffers(sz, arr);
1178 for (
size_t f = 0; f < sz; f ++)
1204 mglVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0,
nullptr);
1209 mglVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0,
nullptr);
1218 mglVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0,
nullptr);
1227 for (
int f = 0; f < 65535; f ++)
1234 if (test[0] != 0 || test[1] != 0 || test[2] != 0 || test[3] != 0)
1237 test[0], test[1], test[2], test[3]);
1243 const int w,
const int h,
1251 const int x,
const int y,
1252 const int w,
const int h,
1262 GL_DEPTH_BUFFER_BIT |
1263 GL_STENCIL_BUFFER_BIT);
1291 if (vert ==
nullptr)
1294 const STD_VECTOR<int> &vp = ogl.
mVp;
1295 STD_VECTOR<int>::const_iterator ivp;
1296 const STD_VECTOR<int>::const_iterator ivp_end = vp.end();
1298 STD_VECTOR<GLfloat*>::const_iterator ft;
1299 const STD_VECTOR<GLfloat*>::const_iterator ft_end = floatTexPool.end();
1300 STD_VECTOR<GLuint> &vbos = ogl.
mVbo;
1301 STD_VECTOR<GLuint>::const_iterator ivbo;
1303 const int sz =
CAST_S32(floatTexPool.size());
1307 mglGenBuffers(sz, &vbos[0]);
1309 for (ft = floatTexPool.begin(), ivp = vp.begin(), ivbo = vbos.begin();
1310 ft != ft_end && ivp != ivp_end;
1311 ++ ft, ++ ivp, ++ ivbo)
1318 for (STD_VECTOR<GLfloat*>::iterator it = floatTexPool.begin();
1319 it != floatTexPool.end(); ++ it)
1323 floatTexPool.clear();
1330 #ifdef DEBUG_DRAW_CALLS 1332 #endif // DEBUG_DRAW_CALLS 1336 #endif // OPENGLERRORS 1345 #ifdef DEBUG_DRAW_CALLS 1347 #endif // DEBUG_DRAW_CALLS 1351 #endif // OPENGLERRORS 1358 #ifdef DEBUG_DRAW_CALLS 1360 #endif // DEBUG_DRAW_CALLS 1364 #endif // OPENGLERRORS 1367 #ifdef DEBUG_BIND_TEXTURE 1371 const std::string texture = image->mIdPath;
1372 if (mOldTexture != texture)
1374 if ((!mOldTexture.empty() || !texture.empty())
1375 && mOldTextureId != image->mGLImage)
1377 logger->
log(
"bind: %s (%d) to %s (%d)", mOldTexture.c_str(),
1378 mOldTextureId, texture.c_str(), image->mGLImage);
1380 mOldTextureId = image->mGLImage;
1381 mOldTexture = texture;
1384 #else // DEBUG_BIND_TEXTURE 1389 #endif // DEBUG_BIND_TEXTURE 1391 #endif // USE_OPENGL static void bindTexture2(const GLenum target, const Image *const image)
#define FOR_EACH(type, iter, array)
GLuint mSimpleColorUniform
void setMainFlags(const int w, const int h, const int scale, const int bpp, const bool fs, const bool hwaccel, const bool resize, const bool noFrame, const bool allowHighDPI)
std::vector< GLuint > mVbo
void drawTriangleArray(const int size) A_INLINE
static GLuint mTextureBinded
void calcPatternInline(ImageVertexes *const vert, const Image *const image, const int x, const int y, const int w, const int h) const A_INLINE
#define isGLNotNull(func)
void drawRescaledQuad(const int srcX, const int srcY, const int dstX, const int dstY, const int width, const int height, const int desiredWidth, const int desiredHeight) A_INLINE
void finalize(ImageCollection *const col)
void removeArray(const uint32_t id, uint32_t *const arr)
std::vector< ImageVertexes * > ImageVertexesVector
void disableTexturingAndBlending()
void calcTileVertexes(ImageVertexes *const vert, const Image *const image, int x, int y) const
#define BLOCK_START(name)
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
#define mglBindTexture(...)
unsigned int vertexBufSize
void fillRectangle(const Rect &rect)
ImageVertexesVector::iterator ImageCollectionIter
void drawRectangle(const Rect &rect)
static void dumpSettings()
virtual void popClipArea()
unsigned int getProgramId() const
void copyImage(const Image *const image, int dstX, int dstY)
GLfloat * mFloatArrayCached
void drawNet(const int x1, const int y1, const int x2, const int y2, const int width, const int height)
#define vertFill2D(var, x1, y1, x2, y2, dstX, dstY, w, h)
ImageVertexesVector::const_iterator ImageCollectionCIter
bool setVideoMode(const int w, const int h, const int scalle, const int bpp, const bool fs, const bool hwaccel, const bool resize, const bool noFrame, const bool allowHighDPI)
void setColor(const Color &color)
void switchVp(const int n)
void drawImageInline(const Image *const image, int dstX, int dstY) A_INLINE
GLfloat * switchFloatTexArray()
void drawLine(int x1, int y1, int x2, int y2)
static void bindTexture(const GLenum target, const GLuint texture)
void drawPatternCached(const Image *const image, const int x, const int y, const int w, const int h)
void calcPattern(ImageVertexes *const vert, const Image *const image, const int x, const int y, const int w, const int h) const
void calcImageRect(ImageVertexes *const vert, int x, int y, int w, int h, const ImageRect &imgRect) A_INLINE
void safeError(const std::string &error_text) __attribute__((noreturn))
void bindAttributes() A_INLINE
void drawVertexes(const OpenGLGraphicsVertexes &ogl) A_INLINE
void drawPattern(const Image *const image, const int x, const int y, const int w, const int h)
void debugBindTexture(const Image *const image)
void drawPoint(int x, int y)
#define mglDrawArrays(...)
void deleteArraysInternal()
void drawTileCollection(const ImageCollection *const vertCol)
void calcTileCollection(ImageCollection *const vertCol, const Image *const image, int x, int y)
#define FUNC_BLOCK(name, id)
void drawRescaledPattern(const Image *const image, const int x, const int y, const int w, const int h, const int scaledWidth, const int scaledHeight)
void drawImageRect(int x, int y, int w, int h, const ImageRect &imgRect)
void drawTileVertexes(const ImageVertexes *const vert)
static GLuint mTextureSizeUniform
void drawLineArrays(const int size) A_INLINE
virtual void createGLContext(const bool custom)
std::vector< GLfloat * > mFloatTexPool
void initArrays(const int vertCount)
#define mglGetIntegerv(...)
MStack< ClipRect > mClipStack
void createGLContext(const bool custom)
void drawRescaledImage(const Image *const image, int dstX, int dstY, const int desiredWidth, const int desiredHeight)
void pushClipArea(const Rect &area)
virtual void pushClipArea(const Rect &area)
void drawImage(const Image *const image, int dstX, int dstY)
void enableTexturingAndBlending()
void drawImageCached(const Image *const image, int x, int y)
void bindArrayBuffer(const GLuint vbo) A_INLINE
void log(const char *const log_text,...)
OpenGLGraphicsVertexes ogl
void calcTileVertexesInline(ImageVertexes *const vert, const Image *const image, int x, int y) const A_INLINE
void calcWindow(ImageCollection *const vertCol, const int x, const int y, const int w, const int h, const ImageRect &imgRect)
void drawQuad(const int srcX, const int srcY, const int dstX, const int dstY, const int width, const int height) A_INLINE
GraphicsManager graphicsManager
GLfloat * continueFloatTexArray()
void setColorAlpha(const float alpha) A_INLINE
static int mTextureHeight
void drawPatternInline(const Image *const image, const int x, const int y, const int w, const int h) A_INLINE
GLint mTextureColorUniform
ShaderProgram * getGles2Program()