24 #if defined USE_OPENGL && !defined ANDROID && !defined(__SWITCH__)
42 SafeOpenGLGraphics::SafeOpenGLGraphics() :
51 mName =
"safe OpenGL";
54 SafeOpenGLGraphics::~SafeOpenGLGraphics()
80 return setOpenGLMode();
101 const float tw =
static_cast<float>(image->mTexWidth);
102 const float th =
static_cast<float>(image->mTexHeight);
104 const float texX1 =
static_cast<float>(srcX) / tw;
105 const float texY1 =
static_cast<float>(srcY) / th;
106 const float texX2 =
static_cast<float>(srcX + width) / tw;
107 const float texY2 =
static_cast<float>(srcY + height) / th;
109 glTexCoord2f(texX1, texY1);
110 glVertex2i(dstX, dstY);
111 glTexCoord2f(texX2, texY1);
112 glVertex2i(dstX + width, dstY);
113 glTexCoord2f(texX2, texY2);
114 glVertex2i(dstX + width, dstY + height);
115 glTexCoord2f(texX1, texY2);
116 glVertex2i(dstX, dstY + height);
120 glTexCoord2i(srcX, srcY);
121 glVertex2i(dstX, dstY);
122 glTexCoord2i(srcX + width, srcY);
123 glVertex2i(dstX + width, dstY);
124 glTexCoord2i(srcX + width, srcY + height);
125 glVertex2i(dstX + width, dstY + height);
126 glTexCoord2i(srcX, srcY + height);
127 glVertex2i(dstX, dstY + height);
132 const int srcX,
const int srcY,
133 const int dstX,
const int dstY,
134 const int width,
const int height,
135 const int desiredWidth,
136 const int desiredHeight)
140 const
int srcX, const
int srcY,
141 const
int dstX, const
int dstY,
142 const
int width, const
int height,
143 const
int desiredWidth,
144 const
int desiredHeight)
148 const float tw =
static_cast<float>(image->mTexWidth);
149 const float th =
static_cast<float>(image->mTexHeight);
151 const float texX1 =
static_cast<float>(srcX) / tw;
152 const float texY1 =
static_cast<float>(srcY) / th;
153 const float texX2 =
static_cast<float>(srcX + width) / tw;
154 const float texY2 =
static_cast<float>(srcY + height) / th;
156 glTexCoord2f(texX1, texY1);
157 glVertex2i(dstX, dstY);
158 glTexCoord2f(texX2, texY1);
159 glVertex2i(dstX + desiredWidth, dstY);
160 glTexCoord2f(texX2, texY2);
161 glVertex2i(dstX + desiredWidth, dstY + desiredHeight);
162 glTexCoord2f(texX1, texY2);
163 glVertex2i(dstX, dstY + desiredHeight);
167 glTexCoord2i(srcX, srcY);
168 glVertex2i(dstX, dstY);
169 glTexCoord2i(srcX + width, srcY);
170 glVertex2i(dstX + desiredWidth, dstY);
171 glTexCoord2i(srcX + width, srcY + height);
172 glVertex2i(dstX + desiredWidth, dstY + desiredHeight);
173 glTexCoord2i(srcX, srcY + height);
174 glVertex2i(dstX, dstY + desiredHeight);
188 if (image ==
nullptr)
195 const SDL_Rect &bounds = image->mBounds;
199 dstX, dstY, bounds.w, bounds.h);
209 void SafeOpenGLGraphics::testDraw()
restrict2
214 glTexCoord2f(0.0F, 0.781250F);
216 glTexCoord2f(0.0F, 0.781250F);
218 glTexCoord2f(0.0F, 0.585938F);
219 glVertex2i(800, 600);
220 glTexCoord2f(0.0F, 0.585938F);
229 glTexCoord2i(800, 0);
231 glTexCoord2i(800, 600);
232 glVertex2i(800, 600);
233 glTexCoord2i(0, 600);
243 if (image ==
nullptr)
250 const SDL_Rect &bounds = image->mBounds;
253 drawQuad(image, bounds.
x, bounds.
y,
x,
y, bounds.w, bounds.h);
258 const
int x, const
int y,
262 if (image ==
nullptr)
265 const SDL_Rect &imageRect = image->mBounds;
266 const
int iw = imageRect.w;
267 const
int ih = imageRect.h;
268 if (iw == 0 || ih == 0)
271 const
int srcX = imageRect.
x;
272 const
int srcY = imageRect.
y;
281 for (
int py = 0; py < h; py += ih)
283 const int height = (py + ih >= h) ? h - py : ih;
284 const int dstY =
y + py;
285 for (
int px = 0; px < w; px += iw)
287 int width = (px + iw >= w) ? w - px : iw;
289 drawQuad(image, srcX, srcY, dstX, dstY, width, height);
302 const int desiredWidth,
306 if (image ==
nullptr)
309 const SDL_Rect &imageRect = image->mBounds;
312 if (imageRect.w == desiredWidth && imageRect.h == desiredHeight)
325 imageRect.w, imageRect.h, desiredWidth, desiredHeight);
330 const int x,
const int y,
337 const int x,
const int y,
341 if (image ==
nullptr)
344 const SDL_Rect &imageRect = image->mBounds;
345 const
int iw = imageRect.w;
346 const
int ih = imageRect.h;
347 if (iw == 0 || ih == 0)
350 const
int srcX = imageRect.
x;
351 const
int srcY = imageRect.
y;
360 for (
int py = 0; py < h; py += ih)
362 const int height = (py + ih >= h) ? h - py : ih;
363 const int dstY =
y + py;
364 for (
int px = 0; px < w; px += iw)
366 int width = (px + iw >= w) ? w - px : iw;
368 drawQuad(image, srcX, srcY, dstX, dstY, width, height);
376 const int x,
const int y,
377 const int w,
const int h,
378 const int scaledWidth,
381 if (image ==
nullptr)
384 const int iw = scaledWidth;
385 const int ih = scaledHeight;
386 if (iw == 0 || ih == 0)
389 const SDL_Rect &imageRect = image->mBounds;
390 const int srcX = imageRect.x;
391 const int srcY = imageRect.y;
400 const float scaleFactorW =
static_cast<float>(scaledWidth)
402 const float scaleFactorH =
static_cast<float>(scaledHeight)
403 / image->getHeight();
405 for (
int py = 0; py < h; py += ih)
407 const int height = (py + ih >= h) ? h - py : ih;
408 const int dstY =
y + py;
409 for (
int px = 0; px < w; px += iw)
411 int width = (px + iw >= w) ? w - px : iw;
415 width / scaleFactorW, height / scaleFactorH,
416 scaledWidth, scaledHeight);
502 SDL_GL_SwapWindow(mWindow);
504 SDL_GL_SwapBuffers();
508 mglFrameTerminator();
525 glMatrixMode(GL_TEXTURE);
528 glMatrixMode(GL_PROJECTION);
531 glOrtho(0.0,
static_cast<double>(mRect.w),
532 static_cast<double>(mRect.h),
535 glMatrixMode(GL_MODELVIEW);
539 glDisable(GL_LIGHTING);
541 glDisable(GL_COLOR_MATERIAL);
543 glShadeModel(GL_FLAT);
558 if (!mClipStack.empty())
560 const ClipRect &clipArea = mClipStack.top();
567 const ClipRect &clipArea = mClipStack.top();
570 glTranslatef(
static_cast<GLfloat
>(transX + clipArea.
xOffset),
571 static_cast<GLfloat
>(transY + clipArea.
yOffset), 0);
572 glScissor(clipArea.
x * mScale,
573 (mRect.h - clipArea.
y - clipArea.
height) * mScale,
574 clipArea.
width * mScale,
575 clipArea.
height * mScale);
582 if (mClipStack.empty())
586 const ClipRect &clipArea = mClipStack.top();
587 glScissor(clipArea.
x * mScale,
588 (mRect.h - clipArea.
y - clipArea.
height) * mScale,
589 clipArea.
width * mScale,
590 clipArea.
height * mScale);
604 const int x2,
const int y2,
605 const int width,
const int height)
restrict2
611 for (
int y = y1;
y < y2;
y += height)
613 glVertex2f(
static_cast<float>(x1) + 0.5F,
614 static_cast<float>(
y) + 0.5F);
615 glVertex2f(
static_cast<float>(x2) + 0.5F,
616 static_cast<float>(
y) + 0.5F);
619 for (
int x = x1;
x < x2;
x += width)
621 glVertex2f(
static_cast<float>(
x) + 0.5F,
622 static_cast<float>(y1) + 0.5F);
623 glVertex2f(
static_cast<float>(
x) + 0.5F,
624 static_cast<float>(y2) + 0.5F);
636 glVertex2f(
static_cast<float>(x1) + 0.5F,
static_cast<float>(y1) + 0.5F);
637 glVertex2f(
static_cast<float>(x2) + 0.5F,
static_cast<float>(y2) + 0.5F);
669 if (mAlpha && !mColorAlpha)
674 else if (!mAlpha && mColorAlpha)
691 const
float offset = filled ? 0 : 0.5F;
696 glBegin(filled ? GL_QUADS : GL_LINE_LOOP);
697 glVertex2f(static_cast<
float>(rect.
x) + offset,
698 static_cast<
float>(rect.
y) + offset);
699 glVertex2f(static_cast<
float>(rect.
x + rect.width) - offset,
700 static_cast<
float>(rect.
y) + offset);
701 glVertex2f(static_cast<
float>(rect.
x + rect.width) - offset,
702 static_cast<
float>(rect.
y + rect.height) - offset);
703 glVertex2f(static_cast<
float>(rect.
x) + offset,
704 static_cast<
float>(rect.
y + rect.height) - offset);
709 void SafeOpenGLGraphics::
bindTexture(const GLenum target,
710 const GLuint texture)
715 glBindTexture(target, texture);
721 if (!mIsByteColor && mFloatColor == alpha)
724 glColor4f(1.0F, 1.0F, 1.0F, alpha);
725 mIsByteColor =
false;
731 if (mIsByteColor && mByteColor == mColor)
734 glColor4ub(
static_cast<GLubyte
>(mColor.r),
735 static_cast<GLubyte
>(mColor.g),
736 static_cast<GLubyte
>(mColor.b),
737 static_cast<GLubyte
>(mColor.a));
744 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
748 const int w,
const int h,
756 const int x,
const int y,
757 const int w,
const int h,
virtual void popClipArea()
virtual void pushClipArea(const Rect &area)
void calcPatternInline(ImageVertexes *restrict const vert, const Image *restrict const image, const int x, const int y, const int w, const int h) const restrict2 A_INLINE
void calcTileVertexes(ImageVertexes *restrict const vert, const Image *restrict const image, int x, int y) const restrict2 override final A_NONNULL(2
void calcWindow(ImageCollection *restrict const vertCol, const int x, const int y, const int w, const int h, const ImageRect &restrict imgRect) restrict2 override final A_NONNULL(2)
void drawPatternInline(const Image *restrict const image, const int x, const int y, const int w, const int h) restrict2 A_INLINE
void drawRectangle(const Rect &restrict rect) restrict2 override final
void drawRescaledPattern(const Image *restrict const image, const int x, const int y, const int w, const int h, const int scaledWidth, const int scaledHeight) restrict2 override final
void copyImage(const Image *restrict const image, int dstX, int dstY) restrict2 override final
void calcPattern(ImageVertexes *restrict const vert, const Image *restrict const image, const int x, const int y, const int w, const int h) const restrict2 override final
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) restrict2 override final
void drawPoint(int x, int y) restrict2 override final
void drawRescaledImage(const Image *restrict const image, int dstX, int dstY, const int desiredWidth, const int desiredHeight) restrict2 override final
void endDraw() restrict2 override final
void drawTileVertexes(const ImageVertexes *restrict const vert) restrict2 override final
void void drawImageInline(const Image *restrict const image, int dstX, int dstY) restrict2 A_INLINE
void calcTileVertexesInline(ImageVertexes *restrict const vert, const Image *restrict const image, int x, int y) const restrict2 A_INLINE A_NONNULL(2
void drawImageRect(int x, int y, int w, int h, const ImageRect &restrict imgRect) restrict2 override final
void fillRectangle(const Rect &restrict rect) restrict2 override final
void drawLine(int x1, int y1, int x2, int y2) restrict2 override final
void popClipArea() restrict2 override final
void drawTileCollection(const ImageCollection *restrict const vertCol) restrict2 override final A_NONNULL(2)
void drawImage(const Image *restrict const image, int dstX, int dstY) restrict2 override final
void updateScreen() restrict2 override final
void void calcTileCollection(ImageCollection *restrict const vertCol, const Image *restrict const image, int x, int y) restrict2 override final
void drawPattern(const Image *restrict const image, const int x, const int y, const int w, const int h) restrict2 override final
void calcImageRect(ImageVertexes *restrict const vert, int x, int y, int w, int h, const ImageRect &restrict imgRect) restrict2 A_INLINE
void pushClipArea(const Rect &restrict area) restrict2 override final
void drawImageCached(const Image *restrict const image, int x, int y) restrict2 override final
void completeCache() restrict2 override final
void beginDraw() restrict2 override final
void drawPatternCached(const Image *restrict const image, const int x, const int y, const int w, const int h) restrict2 override final
#define isGLNotNull(func)
void drawNet(const int x1, const int y1, const int x2, const int y2, const int width, const int height) restrict2 override final
void deleteArrays() restrict2 override final
void enableTexturingAndBlending() restrict2
static GLuint mTextureBinded
void clearScreen() const restrict2 override final
void disableTexturingAndBlending() restrict2
static void bindTexture(const GLenum target, const GLuint texture)
void restoreColor() restrict2 A_INLINE
void setColorAlpha(const float alpha) restrict2 A_INLINE
#define FUNC_BLOCK(name, id)
#define BLOCK_START(name)
static void drawQuad(const Image *image, const int srcX, const int srcY, const int dstX, const int dstY, const int width, const int height) A_INLINE
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