23 #if defined(USE_OPENGL) && !defined(__native_client__) 29 #endif // OPENGLERRORS 32 #ifdef __native_client__ 34 #endif // __native_client__ 47 #define vertFill2D(tVar, vVar, x1, y1, x2, y2, dstX, dstY, w, h) \ 60 vVar[vp + 0] = static_cast<GLshort>(dstX); \ 61 vVar[vp + 1] = static_cast<GLshort>(dstY); \ 62 vVar[vp + 2] = static_cast<GLshort>(dstX + w); \ 63 vVar[vp + 3] = static_cast<GLshort>(dstY); \ 64 vVar[vp + 4] = static_cast<GLshort>(dstX + w); \ 65 vVar[vp + 5] = static_cast<GLshort>(dstY + h); \ 66 vVar[vp + 6] = static_cast<GLshort>(dstX); \ 67 vVar[vp + 7] = static_cast<GLshort>(dstY); \ 68 vVar[vp + 8] = static_cast<GLshort>(dstX); \ 69 vVar[vp + 9] = static_cast<GLshort>(dstY + h); \ 70 vVar[vp + 10] = static_cast<GLshort>(dstX + w); \ 71 vVar[vp + 11] = static_cast<GLshort>(dstY + h); 74 #ifdef DEBUG_DRAW_CALLS 75 unsigned int MobileOpenGLGraphics::mDrawCalls = 0;
76 unsigned int MobileOpenGLGraphics::mLastDrawCalls = 0;
77 #endif // DEBUG_DRAW_CALLS 93 #ifdef DEBUG_BIND_TEXTURE
100 mName =
"mobile OpenGL ES";
190 const float tw =
static_cast<float>(image->mTexWidth);
191 const float th =
static_cast<float>(image->mTexHeight);
193 const float texX1 =
static_cast<float>(srcX) / tw;
194 const float texY1 =
static_cast<float>(srcY) / th;
195 const float texX2 =
static_cast<float>(srcX + width) / tw;
196 const float texY2 =
static_cast<float>(srcY + height) / th;
208 static_cast<GLshort
>(dstX), static_cast<GLshort>(dstY),
209 static_cast<GLshort
>(dstX + width), static_cast<GLshort>(dstY),
210 static_cast<GLshort
>(dstX), static_cast<GLshort>(dstY + height),
211 static_cast<GLshort
>(dstX + width),
212 static_cast<GLshort>(dstY + height)
215 glVertexPointer(2, GL_SHORT, 0, &vert);
216 glTexCoordPointer(2, GL_FLOAT, 0, &tex);
218 #ifdef DEBUG_DRAW_CALLS 219 MobileOpenGLGraphics::mDrawCalls ++;
220 #endif // DEBUG_DRAW_CALLS 224 #endif // OPENGLERRORS 229 const int srcX,
const int srcY,
230 const int dstX,
const int dstY,
231 const int width,
const int height,
232 const int desiredWidth,
233 const int desiredHeight)
237 const int srcX,
const int srcY,
238 const int dstX,
const int dstY,
239 const int width,
const int height,
240 const int desiredWidth,
241 const int desiredHeight)
245 const float tw =
static_cast<float>(image->mTexWidth);
246 const float th =
static_cast<float>(image->mTexHeight);
248 const float texX1 =
static_cast<float>(srcX) / tw;
249 const float texY1 =
static_cast<float>(srcY) / th;
250 const float texX2 =
static_cast<float>(srcX + width) / tw;
251 const float texY2 =
static_cast<float>(srcY + height) / th;
263 static_cast<GLshort
>(dstX), static_cast<GLshort>(dstY),
264 static_cast<GLshort
>(dstX + desiredWidth),
265 static_cast<GLshort>(dstY),
266 static_cast<GLshort
>(dstX), static_cast<GLshort>(
267 dstY + desiredHeight),
268 static_cast<GLshort
>(dstX + desiredWidth),
269 static_cast<GLshort>(dstY + desiredHeight)
271 glVertexPointer(2, GL_SHORT, 0, &vert);
272 glTexCoordPointer(2, GL_FLOAT, 0, &tex);
274 #ifdef DEBUG_DRAW_CALLS 275 MobileOpenGLGraphics::mDrawCalls ++;
276 #endif // DEBUG_DRAW_CALLS 280 #endif // OPENGLERRORS 294 if (image ==
nullptr)
298 #ifdef DEBUG_BIND_TEXTURE 300 #endif // DEBUG_BIND_TEXTURE 304 const SDL_Rect &imageRect = image->mBounds;
305 drawQuad(image, imageRect.x, imageRect.y,
306 dstX, dstY, imageRect.w, imageRect.h);
318 if (image ==
nullptr)
328 const SDL_Rect &imageRect = image->mBounds;
329 const int srcX = imageRect.x;
330 const int srcY = imageRect.y;
331 const int w = imageRect.w;
332 const int h = imageRect.h;
334 if (w == 0 || h == 0)
337 const float tw =
static_cast<float>(image->mTexWidth);
338 const float th =
static_cast<float>(image->mTexHeight);
347 float texX1 =
static_cast<float>(srcX) / tw;
348 float texY1 =
static_cast<float>(srcY) / th;
349 float texX2 =
static_cast<float>(srcX + w) / tw;
350 float texY2 =
static_cast<float>(srcY + h) / th;
353 texX1, texY1, texX2, texY2,
375 if (image ==
nullptr)
384 const SDL_Rect &imageRect = image->mBounds;
385 const int srcX = imageRect.x;
386 const int srcY = imageRect.y;
387 const int iw = imageRect.w;
388 const int ih = imageRect.h;
390 if (iw == 0 || ih == 0)
393 const float tw =
static_cast<float>(image->mTexWidth);
394 const float th =
static_cast<float>(image->mTexHeight);
398 const float texX1 =
static_cast<float>(srcX) / tw;
399 const float texY1 =
static_cast<float>(srcY) / th;
401 for (
int py = 0; py < h; py += ih)
403 const int height = (py + ih >= h) ? h - py : ih;
404 const float texY2 =
static_cast<float>(srcY + height) / th;
405 const int dstY =
y + py;
406 for (
int px = 0; px < w; px += iw)
408 const int width = (px + iw >= w) ? w - px : iw;
409 const int dstX =
x + px;
411 const float texX2 =
static_cast<float>(srcX + width) / tw;
414 texX1, texY1, texX2, texY2,
415 dstX, dstY, width, height);
434 #ifdef DEBUG_BIND_TEXTURE 436 #endif // DEBUG_BIND_TEXTURE 447 const int desiredWidth,
451 if (image ==
nullptr)
454 const SDL_Rect &imageRect = image->mBounds;
457 if (imageRect.w == desiredWidth && imageRect.h == desiredHeight)
464 #ifdef DEBUG_BIND_TEXTURE 466 #endif // DEBUG_BIND_TEXTURE 472 imageRect.w, imageRect.h, desiredWidth, desiredHeight);
476 const int x,
const int y,
489 if (image ==
nullptr)
492 const SDL_Rect &imageRect = image->mBounds;
493 const int srcX = imageRect.x;
494 const int srcY = imageRect.y;
495 const int iw = imageRect.w;
496 const int ih = imageRect.h;
498 if (iw == 0 || ih == 0)
501 const float tw =
static_cast<float>(image->mTexWidth);
502 const float th =
static_cast<float>(image->mTexHeight);
506 #ifdef DEBUG_BIND_TEXTURE 508 #endif // DEBUG_BIND_TEXTURE 516 const float texX1 =
static_cast<float>(srcX) / tw;
517 const float texY1 =
static_cast<float>(srcY) / th;
519 for (
int py = 0; py < h; py += ih)
521 const int height = (py + ih >= h) ? h - py : ih;
522 const float texY2 =
static_cast<float>(srcY + height) / th;
523 const int dstY =
y + py;
524 for (
int px = 0; px < w; px += iw)
526 const int width = (px + iw >= w) ? w - px : iw;
527 const int dstX =
x + px;
529 const float texX2 =
static_cast<float>(srcX + width) / tw;
532 texX1, texY1, texX2, texY2,
533 dstX, dstY, width, height);
549 const int x,
const int y,
550 const int w,
const int h,
551 const int scaledWidth,
552 const int scaledHeight)
555 if (image ==
nullptr)
558 if (scaledWidth == 0 || scaledHeight == 0)
561 const SDL_Rect &imageRect = image->mBounds;
562 const int srcX = imageRect.x;
563 const int srcY = imageRect.y;
564 const int iw = imageRect.w;
565 const int ih = imageRect.h;
566 if (iw == 0 || ih == 0)
571 #ifdef DEBUG_BIND_TEXTURE 573 #endif // DEBUG_BIND_TEXTURE 582 const float tw =
static_cast<float>(image->mTexWidth);
583 const float th =
static_cast<float>(image->mTexHeight);
585 const float texX1 =
static_cast<float>(srcX) / tw;
586 const float texY1 =
static_cast<float>(srcY) / th;
588 const float tFractionW = iw / tw;
589 const float tFractionH = ih / th;
591 for (
int py = 0; py < h; py += scaledHeight)
593 const int height = (py + scaledHeight >= h)
594 ? h - py : scaledHeight;
595 const int dstY =
y + py;
596 const float visibleFractionH =
static_cast<float>(height)
598 const float texY2 = texY1 + tFractionH * visibleFractionH;
599 for (
int px = 0; px < w; px += scaledWidth)
601 const int width = (px + scaledWidth >= w)
602 ? w - px : scaledWidth;
603 const int dstX =
x + px;
604 const float visibleFractionW =
static_cast<float>(width)
606 const float texX2 = texX1 + tFractionW * visibleFractionW;
609 texX1, texY1, texX2, texY2,
610 dstX, dstY, width, height);
628 const STD_VECTOR<GLshort*> &shortVertPool = ogl.mShortVertPool;
629 STD_VECTOR<GLshort*>::const_iterator iv;
630 const STD_VECTOR<GLshort*>::const_iterator iv_end = shortVertPool.end();
631 const STD_VECTOR<int> &vp = ogl.mVp;
632 STD_VECTOR<int>::const_iterator ivp;
633 const STD_VECTOR<int>::const_iterator ivp_end = vp.end();
638 const STD_VECTOR<GLfloat*> &floatTexPool = ogl.mFloatTexPool;
639 STD_VECTOR<GLfloat*>::const_iterator ft;
640 const STD_VECTOR<GLfloat*>::const_iterator
641 ft_end = floatTexPool.end();
643 for (iv = shortVertPool.begin(), ft = floatTexPool.begin(),
645 iv != iv_end && ft != ft_end && ivp != ivp_end;
646 ++ iv, ++ ft, ++ ivp)
671 if (image ==
nullptr || vert ==
nullptr)
674 const SDL_Rect &imageRect = image->mBounds;
675 const int srcX = imageRect.x;
676 const int srcY = imageRect.y;
677 const int iw = imageRect.w;
678 const int ih = imageRect.h;
680 if (iw == 0 || ih == 0)
683 const float tw =
static_cast<float>(image->mTexWidth);
684 const float th =
static_cast<float>(image->mTexHeight);
694 const float texX1 =
static_cast<float>(srcX) / tw;
695 const float texY1 =
static_cast<float>(srcY) / th;
700 for (
int py = 0; py < h; py += ih)
702 const int height = (py + ih >= h) ? h - py : ih;
703 const int dstY =
y + py;
704 const float texY2 =
static_cast<float>(srcY + height) / th;
705 for (
int px = 0; px < w; px += iw)
707 const int width = (px + iw >= w) ? w - px : iw;
708 const int dstX =
x + px;
709 const float texX2 =
static_cast<float>(srcX + width) / tw;
712 texX1, texY1, texX2, texY2,
713 dstX, dstY, width, height);
735 if (vertCol ==
nullptr || image ==
nullptr)
737 if (vertCol->currentGLImage != image->mGLImage)
740 vertCol->currentGLImage = image->mGLImage;
741 vertCol->currentVert = vert;
743 vertCol->draws.push_back(vert);
764 #ifdef DEBUG_BIND_TEXTURE 766 #endif // DEBUG_BIND_TEXTURE 780 if (vertCol ==
nullptr || image ==
nullptr)
783 if (vertCol->currentGLImage != image->mGLImage)
786 vertCol->currentGLImage = image->mGLImage;
787 vertCol->currentVert = vert;
789 vertCol->draws.push_back(vert);
793 vert = vertCol->currentVert;
813 const SDL_Rect &imageRect = image->mBounds;
814 const int srcX = imageRect.x;
815 const int srcY = imageRect.y;
816 const int w = imageRect.w;
817 const int h = imageRect.h;
819 if (w == 0 || h == 0)
822 const float tw =
static_cast<float>(image->mTexWidth);
823 const float th =
static_cast<float>(image->mTexHeight);
835 float texX1 =
static_cast<float>(srcX) / tw;
836 float texY1 =
static_cast<float>(srcY) / th;
837 float texX2 =
static_cast<float>(srcX + w) / tw;
838 float texY2 =
static_cast<float>(srcY + h) / th;
844 texX1, texY1, texX2, texY2,
864 const Image *
const image = vert->image;
867 #ifdef DEBUG_BIND_TEXTURE 869 #endif // DEBUG_BIND_TEXTURE 876 const int x,
const int y,
877 const int w,
const int h,
882 const Image *
const image = imgRect.grid[4];
883 if (image ==
nullptr)
885 if (vertCol->currentGLImage != image->
mGLImage)
888 vertCol->currentGLImage = image->
mGLImage;
889 vertCol->currentVert = vert;
891 vertCol->draws.push_back(vert);
895 vert = vertCol->currentVert;
906 #ifdef DEBUG_DRAW_CALLS 907 mLastDrawCalls = mDrawCalls;
909 #endif // DEBUG_DRAW_CALLS 914 SDL_GL_SwapBuffers();
918 mglFrameTerminator();
919 #endif // DEBUG_OPENGL 926 glMatrixMode(GL_TEXTURE);
929 glMatrixMode(GL_PROJECTION);
933 glOrthof(0.0, static_cast<float>(
mRect.w),
934 static_cast<float>(
mRect.h),
938 glOrtho(0.0, static_cast<double>(
mRect.w),
939 static_cast<double>(
mRect.h),
943 glMatrixMode(GL_MODELVIEW);
951 glShadeModel(GL_FLAT);
953 glEnableClientState(GL_VERTEX_ARRAY);
954 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
957 mglHint(GL_LINE_SMOOTH_HINT, GL_FASTEST);
958 mglHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
959 mglHint(GL_POINT_SMOOTH_HINT, GL_FASTEST);
960 mglHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
989 if (transX != 0 || transY != 0)
991 glTranslatef(static_cast<GLfloat>(transX),
992 static_cast<GLfloat>(transY), 0);
1006 int transX = -clipArea1.
xOffset;
1007 int transY = -clipArea1.
yOffset;
1017 if (transX != 0 || transY != 0)
1019 glTranslatef(static_cast<GLfloat>(transX),
1020 static_cast<GLfloat>(transY), 0);
1076 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1104 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1116 const GLshort
x =
static_cast<GLshort
>(rect.x);
1117 const GLshort
y =
static_cast<GLshort
>(rect.y);
1118 const GLshort width =
static_cast<GLshort
>(rect.width);
1119 const GLshort height =
static_cast<GLshort
>(rect.height);
1120 const GLshort xw =
static_cast<GLshort
>(rect.x + width);
1121 const GLshort yh =
static_cast<GLshort
>(rect.y + height);
1133 glVertexPointer(2, GL_SHORT, 0, &vert);
1134 #ifdef DEBUG_DRAW_CALLS 1136 #endif // DEBUG_DRAW_CALLS 1141 #endif // OPENGLERRORS 1153 glVertexPointer(2, GL_SHORT, 0, &vert);
1154 #ifdef DEBUG_DRAW_CALLS 1156 #endif // DEBUG_DRAW_CALLS 1161 #endif // OPENGLERRORS 1167 const int x2,
const int y2,
1168 const int width,
const int height)
restrict2 1170 unsigned int vp = 0;
1176 const GLshort xs1 =
static_cast<GLshort
>(x1);
1177 const GLshort xs2 =
static_cast<GLshort
>(x2);
1178 const GLshort ys1 =
static_cast<GLshort
>(y1);
1179 const GLshort ys2 =
static_cast<GLshort
>(y2);
1180 const int16_t width1 =
CAST_S16(width);
1181 const int16_t height1 =
CAST_S16(height);
1183 for (int16_t
y =
CAST_S16(y1);
y < y2;
y += height1)
1199 for (int16_t
x =
CAST_S16(x1);
x < x2;
x += width1)
1220 const GLuint texture)
1234 #ifdef DEBUG_DRAW_CALLS 1236 #endif // DEBUG_DRAW_CALLS 1241 #endif // OPENGLERRORS 1250 #ifdef DEBUG_DRAW_CALLS 1252 #endif // DEBUG_DRAW_CALLS 1257 #endif // OPENGLERRORS 1261 const shortVertArray,
1263 const floatTexArray,
1266 glVertexPointer(2, GL_SHORT, 0, shortVertArray);
1267 glTexCoordPointer(2, GL_FLOAT, 0, floatTexArray);
1269 #ifdef DEBUG_DRAW_CALLS 1271 #endif // DEBUG_DRAW_CALLS 1276 #endif // OPENGLERRORS 1283 #ifdef DEBUG_DRAW_CALLS 1285 #endif // DEBUG_DRAW_CALLS 1290 #endif // OPENGLERRORS 1298 for (
int f = 0; f < 65535; f ++)
1305 if (test[0] != 0 || test[1] != 0 || test[2] != 0 || test[3] != 0)
1308 test[0], test[1], test[2], test[3]);
1318 glColor4f(1.0F, 1.0F, 1.0F, alpha);
1328 glColor4ub(static_cast<GLubyte>(
mColor.
r),
1329 static_cast<GLubyte>(
mColor.
g),
1330 static_cast<GLubyte>(
mColor.
b),
1331 static_cast<GLubyte>(
mColor.
a));
1337 const int w,
const int h,
1345 const int x,
const int y,
1346 const int w,
const int h,
1356 GL_DEPTH_BUFFER_BIT |
1357 GL_STENCIL_BUFFER_BIT);
1360 #ifdef DEBUG_BIND_TEXTURE 1364 const std::string texture = image->mIdPath;
1365 if (mOldTexture != texture)
1367 if ((!mOldTexture.empty() || !texture.empty())
1368 && mOldTextureId != image->mGLImage)
1370 logger->
log(
"bind: %s (%d) to %s (%d)", mOldTexture.c_str(),
1371 mOldTextureId, texture.c_str(), image->mGLImage);
1373 mOldTextureId = image->mGLImage;
1374 mOldTexture = texture;
1377 #else // DEBUG_BIND_TEXTURE 1383 #endif // DEBUG_BIND_TEXTURE 1385 #endif // defined(USE_OPENGL) && !defined(__native_client__) void drawVertexes(const OpenGLGraphicsVertexes &ogl) A_INLINE
void disableTexturingAndBlending()
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)
void pushClipArea(const Rect &area)
void calcImageRect(ImageVertexes *const vert, int x, int y, int w, int h, const ImageRect &imgRect) A_INLINE
void drawPattern(const Image *const image, const int x, const int y, const int w, const int h)
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)
std::vector< ImageVertexes * > ImageVertexesVector
void drawRescaledPattern(const Image *const image, const int x, const int y, const int w, const int h, const int scaledWidth, const int scaledHeight)
static void dumpSettings()
void drawPatternInline(const Image *const image, const int x, const int y, const int w, const int h) A_INLINE
#define BLOCK_START(name)
void calcPattern(ImageVertexes *const vert, const Image *const image, const int x, const int y, const int w, const int h) const
#define mglBindTexture(...)
unsigned int vertexBufSize
static void bindTexture(const GLenum target, const GLuint texture)
void drawNet(const int x1, const int y1, const int x2, const int y2, const int width, const int height)
void calcTileCollection(ImageCollection *const vertCol, const Image *const image, int x, int y)
void drawRescaledImage(const Image *const image, int dstX, int dstY, const int desiredWidth, const int desiredHeight)
virtual void popClipArea()
static void drawRescaledQuad(const Image *const image, 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 copyImage(const Image *const image, int dstX, int dstY)
ImageVertexesVector::const_iterator ImageCollectionCIter
void drawImage(const Image *const image, int dstX, int dstY)
void switchVp(const int n)
GLfloat * switchFloatTexArray()
void drawRectangle(const Rect &rect)
void drawLine(int x1, int y1, int x2, int y2)
void initArrays(const int vertCount)
void calcTileVertexesInline(ImageVertexes *const vert, const Image *const image, int x, int y) const A_INLINE
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)
static void drawQuad(const Image *const image, const int srcX, const int srcY, const int dstX, const int dstY, const int width, const int height) A_INLINE
#define mglDrawArrays(...)
void restoreColor() A_INLINE
GLfloat * mFloatTexArrayCached
void debugBindTexture(const Image *const image)
GLshort * mShortVertArray
void drawTriangleArrayfsCached(const int size) A_INLINE
#define FUNC_BLOCK(name, id)
#define vertFill2D(tVar, vVar, x1, y1, x2, y2, dstX, dstY, w, h)
void setColorAlpha(const float alpha) A_INLINE
void drawImageInline(const Image *const image, int dstX, int dstY) A_INLINE
void deleteArraysInternal()
void drawPatternCached(const Image *const image, const int x, const int y, const int w, const int h)
#define mglGetIntegerv(...)
void enableTexturingAndBlending()
void drawPoint(int x, int y)
MStack< ClipRect > mClipStack
void calcTileVertexes(ImageVertexes *const vert, const Image *const image, int x, int y) const
void drawLineArrays(const int size) A_INLINE
virtual void pushClipArea(const Rect &area)
GLshort * continueShortVertArray()
void calcWindow(ImageCollection *const vertCol, const int x, const int y, const int w, const int h, const ImageRect &imgRect)
void drawTileVertexes(const ImageVertexes *const vert)
GLshort * switchShortVertArray()
void log(const char *const log_text,...)
OpenGLGraphicsVertexes ogl
void fillRectangle(const Rect &rect)
GLshort * mShortVertArrayCached
void drawImageCached(const Image *const image, int x, int y)
GraphicsManager graphicsManager
GLfloat * continueFloatTexArray()
void drawTriangleArrayfs(const GLshort *const shortVertArray, const GLfloat *const floatTexArray, const int size) A_INLINE
void drawTileCollection(const ImageCollection *const vertCol)
void drawImageRect(int x, int y, int w, int h, const ImageRect &imgRect)