23 #if defined(USE_OPENGL) && !defined(ANDROID) && !defined(__native_client__) 30 #ifdef __native_client__ 32 #endif // __native_client__ 51 #define vertFill2D(var, x1, y1, x2, y2, dstX, dstY, w, h) \ 57 var[vp + 4] = dstX + w; \ 62 var[vp + 8] = dstX + w; \ 63 var[vp + 9] = dstY + h; \ 67 var[vp + 12] = dstX; \ 68 var[vp + 13] = dstY; \ 72 var[vp + 16] = dstX; \ 73 var[vp + 17] = dstY + h; \ 77 var[vp + 20] = dstX + w; \ 78 var[vp + 21] = dstY + h; \ 83 #ifdef DEBUG_DRAW_CALLS 84 unsigned int ModernOpenGLGraphics::mDrawCalls = 0;
85 unsigned int ModernOpenGLGraphics::mLastDrawCalls = 0;
86 #endif // DEBUG_DRAW_CALLS 97 mSimpleColorUniform(0U),
99 mTextureColorUniform(0U),
101 mDrawTypeUniform(0U),
107 mAttributesBinded(0U),
110 #ifdef DEBUG_BIND_TEXTURE
117 mName =
"modern OpenGL";
132 mglDeleteBuffers(1, &
mVbo);
137 mglDeleteBuffers(1, &
mEbo);
140 mglDeleteVertexArrays(1, &
mVao);
162 mglGenVertexArrays(1, &
mVao);
163 mglBindVertexArray(
mVao);
164 mglGenBuffers(1, &
mVbo);
167 mglGenBuffers(1, &
mEbo);
182 logger->
log(
"Shaders compilation done.");
187 mglVertexAttribIFormat(
mPosAttrib, 4, GL_INT, 0);
196 mglBindVertexBuffer(0,
mVbo, 0, 4 *
sizeof(GLint));
202 static_cast<float>(
mWidth) / 2.0f,
203 static_cast<float>(
mHeight) / 2.0f);
262 static_cast<float>(color.r) / 255.0F,
263 static_cast<float>(color.g) / 255.0F,
264 static_cast<float>(color.b) / 255.0F,
265 static_cast<float>(color.a) / 255.0F);
285 const int texX2 = srcX + width;
286 const int texY2 = srcY + height;
287 const int x2 = dstX + width;
288 const int y2 = dstY + height;
292 dstX, dstY, srcX, srcY,
293 x2, dstY, texX2, srcY,
294 dstX, y2, srcX, texY2,
301 #ifdef DEBUG_DRAW_CALLS 303 #endif // DEBUG_DRAW_CALLS 307 #endif // OPENGLERRORS 311 const int dstX,
const int dstY,
312 const int width,
const int height,
313 const int desiredWidth,
316 const int texX2 = srcX + width;
317 const int texY2 = srcY + height;
318 const int x2 = dstX + desiredWidth;
319 const int y2 = dstY + desiredHeight;
323 dstX, dstY, srcX, srcY,
324 x2, dstY, texX2, srcY,
325 dstX, y2, srcX, texY2,
332 #ifdef DEBUG_DRAW_CALLS 334 #endif // DEBUG_DRAW_CALLS 338 #endif // OPENGLERRORS 351 if (image ==
nullptr)
354 #ifdef DEBUG_BIND_TEXTURE 356 #endif // DEBUG_BIND_TEXTURE 363 const SDL_Rect &imageRect = image->mBounds;
366 imageRect.w, imageRect.h);
392 #ifdef DEBUG_DRAW_CALLS 394 #endif // DEBUG_DRAW_CALLS 399 #endif // OPENGLERRORS 411 const int x A_UNUSED,
412 const int y A_UNUSED,
413 const int w A_UNUSED,
424 const int desiredWidth,
427 if (image ==
nullptr)
430 const SDL_Rect &imageRect = image->mBounds;
433 if (imageRect.w == desiredWidth && imageRect.h == desiredHeight)
440 #ifdef DEBUG_BIND_TEXTURE 442 #endif // DEBUG_BIND_TEXTURE 451 imageRect.w, imageRect.h,
452 desiredWidth, desiredHeight);
456 const int x,
const int y,
468 if (image ==
nullptr)
471 const SDL_Rect &imageRect = image->mBounds;
472 const int srcX = imageRect.x;
473 const int srcY = imageRect.y;
474 const int iw = imageRect.w;
475 const int ih = imageRect.h;
477 if (iw == 0 || ih == 0)
481 const int x2 =
x + clipArea.
xOffset;
482 const int y2 =
y + clipArea.
yOffset;
484 #ifdef DEBUG_BIND_TEXTURE 486 #endif // DEBUG_BIND_TEXTURE 497 for (
int py = 0; py < h; py += ih)
499 const int height = (py + ih >= h) ? h - py : ih;
500 const int texY2 = srcY + height;
501 const int dstY = y2 + py;
502 for (
int px = 0; px < w; px += iw)
504 const int width = (px + iw >= w) ? w - px : iw;
505 const int dstX = x2 + px;
507 const int texX2 = srcX + width;
510 srcX, srcY, texX2, texY2,
511 dstX, dstY, width, height);
527 const int x,
const int y,
528 const int w,
const int h,
529 const int scaledWidth,
530 const int scaledHeight)
533 if (image ==
nullptr)
536 if (scaledWidth == 0 || scaledHeight == 0)
539 const SDL_Rect &imageRect = image->mBounds;
540 const int srcX = imageRect.x;
541 const int srcY = imageRect.y;
542 const int iw = imageRect.w;
543 const int ih = imageRect.h;
544 if (iw == 0 || ih == 0)
547 #ifdef DEBUG_BIND_TEXTURE 549 #endif // DEBUG_BIND_TEXTURE 561 const int x2 =
x + clipArea.
xOffset;
562 const int y2 =
y + clipArea.
yOffset;
564 const float scaleFactorW =
static_cast<float>(scaledWidth) / iw;
565 const float scaleFactorH =
static_cast<float>(scaledHeight) / ih;
567 for (
int py = 0; py < h; py += scaledHeight)
569 const int height = (py + scaledHeight >= h)
570 ? h - py : scaledHeight;
571 const int dstY = y2 + py;
572 const int scaledY = srcY + height / scaleFactorH;
573 for (
int px = 0; px < w; px += scaledWidth)
575 const int width = (px + scaledWidth >= w)
576 ? w - px : scaledWidth;
577 const int dstX = x2 + px;
578 const int scaledX = srcX + width / scaleFactorW;
581 srcX, srcY, scaledX, scaledY,
582 dstX, dstY, width, height);
600 const STD_VECTOR<int> &vp = ogl.mVp;
601 const STD_VECTOR<GLuint> &vbos = ogl.mVbo;
602 STD_VECTOR<int>::const_iterator ivp;
603 STD_VECTOR<GLuint>::const_iterator ivbo;
604 const STD_VECTOR<int>::const_iterator ivp_end = vp.end();
611 for (ivp = vp.begin(), ivbo = vbos.begin();
616 #ifdef DEBUG_DRAW_CALLS 618 #endif // DEBUG_DRAW_CALLS 623 #endif // OPENGLERRORS 645 if (image ==
nullptr || vert ==
nullptr)
648 const SDL_Rect &imageRect = image->mBounds;
649 const int srcX = imageRect.x;
650 const int srcY = imageRect.y;
651 const int iw = imageRect.w;
652 const int ih = imageRect.h;
654 if (iw == 0 || ih == 0)
658 const int x2 =
x + clipArea.
xOffset;
659 const int y2 =
y + clipArea.
yOffset;
668 for (
int py = 0; py < h; py += ih)
670 const int height = (py + ih >= h) ? h - py : ih;
671 const int dstY = y2 + py;
672 const int texY2 = srcY + height;
673 for (
int px = 0; px < w; px += iw)
675 const int width = (px + iw >= w) ? w - px : iw;
676 const int dstX = x2 + px;
677 const int texX2 = srcX + width;
680 srcX, srcY, texX2, texY2,
681 dstX, dstY, width, height);
701 if (vertCol ==
nullptr || image ==
nullptr)
703 if (vertCol->currentGLImage != image->mGLImage)
706 vertCol->currentGLImage = image->mGLImage;
707 vertCol->currentVert = vert;
709 vertCol->draws.push_back(vert);
738 #ifdef DEBUG_BIND_TEXTURE 740 #endif // DEBUG_BIND_TEXTURE 754 if (vertCol ==
nullptr || image ==
nullptr)
757 if (vertCol->currentGLImage != image->mGLImage)
760 vertCol->currentGLImage = image->mGLImage;
761 vertCol->currentVert = vert;
763 vertCol->draws.push_back(vert);
767 vert = vertCol->currentVert;
787 const SDL_Rect &imageRect = image->mBounds;
788 const int srcX = imageRect.x;
789 const int srcY = imageRect.y;
790 const int w = imageRect.w;
791 const int h = imageRect.h;
793 if (w == 0 || h == 0)
797 const int x2 = dstX + clipArea.
xOffset;
798 const int y2 = dstY + clipArea.
yOffset;
806 int texX2 = srcX + w;
807 int texY2 = srcY + h;
812 srcX, srcY, texX2, texY2,
831 const Image *
const image = vert->image;
834 #ifdef DEBUG_BIND_TEXTURE 836 #endif // DEBUG_BIND_TEXTURE 846 const int x,
const int y,
847 const int w,
const int h,
852 const Image *
const image = imgRect.grid[4];
853 if (image ==
nullptr)
855 if (vertCol->currentGLImage != image->
mGLImage)
858 vertCol->currentGLImage = image->
mGLImage;
859 vertCol->currentVert = vert;
861 vertCol->draws.push_back(vert);
865 vert = vertCol->currentVert;
873 #ifdef DEBUG_DRAW_CALLS 874 mLastDrawCalls = mDrawCalls;
876 #endif // DEBUG_DRAW_CALLS 880 SDL_GL_SwapBuffers();
884 mglFrameTerminator();
885 #endif // DEBUG_OPENGL 893 mglHint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB, GL_FASTEST);
940 #ifdef DEBUG_DRAW_CALLS 942 #endif // DEBUG_DRAW_CALLS 946 #endif // OPENGLERRORS 963 #ifdef DEBUG_DRAW_CALLS 965 #endif // DEBUG_DRAW_CALLS 969 #endif // OPENGLERRORS 977 const int x1 = rect.
x + clipArea.
xOffset;
978 const int y1 = rect.y + clipArea.
yOffset;
979 const int x2 = x1 + rect.width;
980 const int y2 = y1 + rect.height;
992 #ifdef DEBUG_DRAW_CALLS 994 #endif // DEBUG_DRAW_CALLS 998 #endif // OPENGLERRORS 1006 const int x1 = rect.
x + clipArea.
xOffset;
1007 const int y1 = rect.y + clipArea.
yOffset;
1008 const int x2 = x1 + rect.width;
1009 const int y2 = y1 + rect.height;
1021 #ifdef DEBUG_DRAW_CALLS 1023 #endif // DEBUG_DRAW_CALLS 1027 #endif // OPENGLERRORS 1069 const int x2,
const int y2,
1070 const int width,
const int height)
restrict2 1072 unsigned int vp = 0;
1078 const GLint dx = clipArea.
xOffset;
1079 const GLint dy = clipArea.
yOffset;
1081 const GLint xs1 = x1 + dx;
1082 const GLint xs2 = x2 + dx;
1083 const GLint ys1 = y1 + dy;
1084 const GLint ys2 = y2 + dy;
1086 for (
int y = y1;
y < y2;
y += height)
1106 for (
int x = x1;
x < x2;
x += width)
1131 const GLuint texture)
1143 mglDeleteBuffers(sz, arr);
1144 for (
size_t f = 0; f < sz; f ++)
1196 mglBindVertexBuffer(0,
mVboBinded, 0, 4 *
sizeof(GLint));
1204 mglBindVertexBuffer(0,
mVboBinded, 0, 4 *
sizeof(GLint));
1215 mglBindVertexBuffer(0,
mVboBinded, 0, 4 *
sizeof(GLint));
1226 for (
int f = 0; f < 65535; f ++)
1233 if (test[0] != 0 || test[1] != 0 || test[2] != 0 || test[3] != 0)
1236 test[0], test[1], test[2], test[3]);
1242 const int w,
const int h,
1250 const int x,
const int y,
1251 const int w,
const int h,
1261 GL_DEPTH_BUFFER_BIT |
1262 GL_STENCIL_BUFFER_BIT);
1294 if (vert ==
nullptr)
1297 const STD_VECTOR<int> &vp = ogl.
mVp;
1298 STD_VECTOR<int>::const_iterator ivp;
1299 const STD_VECTOR<int>::const_iterator ivp_end = vp.end();
1301 STD_VECTOR<GLint*>::const_iterator ft;
1302 const STD_VECTOR<GLint*>::const_iterator ft_end = intTexPool.end();
1303 STD_VECTOR<GLuint> &vbos = ogl.
mVbo;
1304 STD_VECTOR<GLuint>::const_iterator ivbo;
1306 const int sz =
CAST_S32(intTexPool.size());
1310 mglGenBuffers(sz, &vbos[0]);
1316 for (ft = intTexPool.begin(), ivp = vp.begin(), ivbo = vbos.begin();
1317 ft != ft_end && ivp != ivp_end;
1318 ++ ft, ++ ivp, ++ ivbo)
1329 for (STD_VECTOR<GLint*>::iterator it = intTexPool.begin();
1330 it != intTexPool.end(); ++ it)
1342 #ifdef DEBUG_DRAW_CALLS 1344 #endif // DEBUG_DRAW_CALLS 1348 #endif // OPENGLERRORS 1357 #ifdef DEBUG_DRAW_CALLS 1359 #endif // DEBUG_DRAW_CALLS 1363 #endif // OPENGLERRORS 1371 #ifdef DEBUG_DRAW_CALLS 1373 #endif // DEBUG_DRAW_CALLS 1377 #endif // OPENGLERRORS 1380 #ifdef DEBUG_BIND_TEXTURE 1384 const std::string texture = image->mIdPath;
1385 if (mOldTexture != texture)
1387 if ((!mOldTexture.empty() || !texture.empty())
1388 && mOldTextureId != image->mGLImage)
1390 logger->
log(
"bind: %s (%d) to %s (%d)", mOldTexture.c_str(),
1391 mOldTextureId, texture.c_str(), image->mGLImage);
1393 mOldTextureId = image->mGLImage;
1394 mOldTexture = texture;
1397 #else // DEBUG_BIND_TEXTURE 1402 #endif // DEBUG_BIND_TEXTURE 1404 #endif // defined(USE_OPENGL) && !defined(ANDROID) && void bindElementBuffer(const GLuint ebo) A_INLINE
static GLuint mTextureBinded
#define FOR_EACH(type, iter, array)
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
GLint * continueIntTexArray()
void drawTileVertexes(const ImageVertexes *const vert)
void drawQuad(const int srcX, const int srcY, const int dstX, const int dstY, const int width, const int height) A_INLINE
void drawLineArrays(const int size) A_INLINE
#define isGLNotNull(func)
void * createGLContext(SDL_Surface *const window, const int major, const int minor, const int profile)
void drawVertexes(const OpenGLGraphicsVertexes &ogl) A_INLINE
void calcImageRect(ImageVertexes *const vert, int x, int y, int w, int h, const ImageRect &imgRect) A_INLINE
std::vector< ImageVertexes * > ImageVertexesVector
void bindArrayBuffer(const GLuint vbo) A_INLINE
void calcTileVertexesInline(ImageVertexes *const vert, const Image *const image, int x, int y) const A_INLINE
#define BLOCK_START(name)
void drawPoint(int x, int y)
#define mglBindTexture(...)
unsigned int vertexBufSize
GLint mTextureColorUniform
void drawImageRect(int x, int y, int w, int h, const ImageRect &imgRect)
ImageVertexesVector::iterator ImageCollectionIter
virtual void popClipArea()
void drawRescaledPattern(const Image *const image, const int x, const int y, const int w, const int h, const int scaledWidth, const int scaledHeight)
unsigned int getProgramId() const
void drawRectangle(const Rect &rect)
void calcPatternInline(ImageVertexes *const vert, const Image *const image, const int x, const int y, const int w, const int h) const A_INLINE
ImageVertexesVector::const_iterator ImageCollectionCIter
GLint * switchIntTexArray()
void initArrays(const int vertCount)
void switchVp(const int n)
void removeArray(const uint32_t id, uint32_t *const arr)
void drawTriangleArray(const int size) A_INLINE
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
GLuint mSimpleColorUniform
void safeError(const std::string &error_text) __attribute__((noreturn))
void drawLine(int x1, int y1, int x2, int y2)
void pushClipArea(const Rect &area)
void calcWindow(ImageCollection *const vertCol, const int x, const int y, const int w, const int h, const ImageRect &imgRect)
#define vertFill2D(var, x1, y1, x2, y2, dstX, dstY, w, h)
void drawNet(const int x1, const int y1, const int x2, const int y2, const int width, const int height)
#define mglDrawArrays(...)
void calcTileVertexes(ImageVertexes *const vert, const Image *const image, int x, int y) const
void enableTexturingAndBlending()
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 drawPatternInline(const Image *const image, const int x, const int y, const int w, const int h) A_INLINE
void createGLContext(const bool custom)
void makeCurrentContext(void *const context)
void drawRescaledImage(const Image *const image, int dstX, int dstY, const int desiredWidth, const int desiredHeight)
void drawImage(const Image *const image, int dstX, int dstY)
void drawPattern(const Image *const image, const int x, const int y, const int w, const int h)
void drawImageCached(const Image *const image, int x, int y)
#define FUNC_BLOCK(name, id)
std::vector< GLint * > mIntTexPool
void setColor(const Color &color)
void drawPatternCached(const Image *const image, const int x, const int y, const int w, const int h)
void calcTileCollection(ImageCollection *const vertCol, const Image *const image, int x, int y)
void disableTexturingAndBlending()
virtual void createGLContext(const bool custom)
void drawImageInline(const Image *const image, int dstX, int dstY) A_INLINE
static void bindTexture(const GLenum target, const GLuint texture)
void bindAttributes() A_INLINE
void fillRectangle(const Rect &rect)
void calcPattern(ImageVertexes *const vert, const Image *const image, const int x, const int y, const int w, const int h) const
void finalize(ImageCollection *const col)
void setColorAlpha(const float alpha) A_INLINE
void drawTileCollection(const ImageCollection *const vertCol)
static void dumpSettings()
#define mglGetIntegerv(...)
MStack< ClipRect > mClipStack
#define GL_ELEMENT_ARRAY_BUFFER
virtual void pushClipArea(const Rect &area)
void error(const std::string &error_text) __attribute__((noreturn))
void log(const char *const log_text,...)
OpenGLGraphicsVertexes ogl
void copyImage(const Image *const image, int dstX, int dstY)
GraphicsManager graphicsManager
void debugBindTexture(const Image *const image)
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 deleteArraysInternal()
ShaderProgram * getSimpleProgram()