ManaPlus
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes
ModernOpenGLGraphics Class Reference

#include <modernopenglgraphics.h>

Inheritance diagram for ModernOpenGLGraphics:
Graphics

Public Member Functions

 ModernOpenGLGraphics ()
 
 ~ModernOpenGLGraphics ()
 
void postInit ()
 
void setColor (const Color &color)
 
void screenResized ()
 
void finalize (ImageCollection *const col)
 
void finalize (ImageVertexes *const vert)
 
void testDraw ()
 
void removeArray (const uint32_t id, uint32_t *const arr)
 
void createGLContext (const bool custom)
 
void drawImageRect (int x, int y, int w, int h, const ImageRect &imgRect)
 
void beginDraw ()
 
void endDraw ()
 
void pushClipArea (const Rect &area)
 
void popClipArea ()
 
void drawRescaledImage (const Image *const image, int dstX, int dstY, const int desiredWidth, const int desiredHeight)
 
void drawPattern (const Image *const image, const int x, const int y, const int w, const int h)
 
void drawPatternInline (const Image *const image, const int x, const int y, const int w, const int h) A_INLINE
 
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 calcPattern (ImageVertexes *const vert, const Image *const image, const int x, const int y, const int w, const int h) const
 
void calcPattern (ImageCollection *const vert, const Image *const image, const int x, const int y, const int w, const int h) const
 
void calcTileVertexes (ImageVertexes *const vert, const Image *const image, int x, int y) const
 
void calcTileCollection (ImageCollection *const vertCol, const Image *const image, int x, int y)
 
void drawTileVertexes (const ImageVertexes *const vert)
 
void drawTileCollection (const ImageCollection *const vertCol)
 
void updateScreen ()
 
void calcWindow (ImageCollection *const vertCol, const int x, const int y, const int w, const int h, const ImageRect &imgRect)
 
void drawRectangle (const Rect &rect)
 
void fillRectangle (const Rect &rect)
 
void drawPoint (int x, int y)
 
void drawLine (int x1, int y1, int x2, int y2)
 
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 drawImage (const Image *const image, int dstX, int dstY)
 
void copyImage (const Image *const image, int dstX, int dstY)
 
void drawImageCached (const Image *const image, int x, int y)
 
void drawPatternCached (const Image *const image, const int x, const int y, const int w, const int h)
 
void completeCache ()
 
void drawRectangle (const Rect &rect, const bool filled)
 
void drawNet (const int x1, const int y1, const int x2, const int y2, const int width, const int height)
 
int getMemoryUsage ()
 
void updateTextureFormat ()
 
bool isAllowScale () const
 
void clearScreen () const
 
void deleteArrays ()
 
void drawVertexes (const OpenGLGraphicsVertexes &ogl) A_INLINE
 
void initArrays (const int vertCount)
 
- Public Member Functions inherited from Graphics
virtual ~Graphics ()
 
void setWindow (SDL_Surface *const window, const int width, const int height)
 
SDL_Surface * getWindow () const
 
void setSync (const bool sync)
 
bool getSync () const
 
bool setFullscreen (const bool fs)
 
virtual bool resizeScreen (const int width, const int height)
 
virtual void restoreContext ()
 
virtual void calcTileSDL (ImageVertexes *const vert, int x, int y) const
 
void setWindowSize (const int width, const int height)
 
int getWidth () const
 
int getHeight () const
 
int getMemoryUsage () const
 
ClipRectgetTopClip () const
 
void setRedraw (const bool n)
 
bool getRedraw () const
 
void setSecure (const bool n)
 
bool getSecure () const
 
int getBpp () const
 
bool getFullScreen () const
 
bool getHWAccel () const
 
bool getDoubleBuffer () const
 
RenderType getOpenGL () const
 
void setNoFrame (const bool n)
 
const std::string & getName () const
 
const ColorgetColor () const
 
int getScale () const
 
void setScale (int scale)
 

Static Public Member Functions

static void dumpSettings ()
 
static void bindTexture (const GLenum target, const GLuint texture)
 
- Static Public Member Functions inherited from Graphics
static void cleanUp ()
 

Static Public Attributes

static GLuint mTextureBinded = 0
 

Protected Member Functions

void enableTexturingAndBlending ()
 
void disableTexturingAndBlending ()
 
void debugBindTexture (const Image *const image)
 
void deleteArraysInternal ()
 
- Protected Member Functions inherited from Graphics
 Graphics ()
 
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)
 
int getOpenGLFlags () const
 
int getSoftwareFlags () const
 
bool setOpenGLMode ()
 
void updateMemoryInfo ()
 
bool videoInfo ()
 
void setOpenGLFlags ()
 

Private Member Functions

void calcImageRect (ImageVertexes *const vert, int x, int y, int w, int h, const ImageRect &imgRect) A_INLINE
 
void calcPatternInline (ImageVertexes *const vert, const Image *const image, const int x, const int y, const int w, const int h) const A_INLINE
 
void calcTileVertexesInline (ImageVertexes *const vert, const Image *const image, int x, int y) const A_INLINE
 
void drawImageInline (const Image *const image, int dstX, int dstY) A_INLINE
 
void setColorAlpha (const float alpha) A_INLINE
 
void restoreColor () A_INLINE
 
void deleteGLObjects ()
 
void drawQuad (const int srcX, const int srcY, const int dstX, const int dstY, const int width, const int height) A_INLINE
 
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 drawTriangleArray (const int size) A_INLINE
 
void drawTriangleArray (const GLint *const array, const int size) A_INLINE
 
void drawLineArrays (const int size) A_INLINE
 
void bindArrayBuffer (const GLuint vbo) A_INLINE
 
void bindArrayBufferAndAttributes (const GLuint vbo) A_INLINE
 
void bindAttributes () A_INLINE
 
void bindElementBuffer (const GLuint ebo) A_INLINE
 

Private Attributes

GLint * mIntArray
 
GLint * mIntArrayCached
 
ShaderProgrammProgram
 
float mAlphaCached
 
int mVpCached
 
float mFloatColor
 
int mMaxVertices
 
GLuint mProgramId
 
GLuint mSimpleColorUniform
 
GLint mPosAttrib
 
GLint mTextureColorUniform
 
GLuint mScreenUniform
 
GLuint mDrawTypeUniform
 
GLuint mVao
 
GLuint mVbo
 
GLuint mEbo
 
GLuint mVboBinded
 
GLuint mEboBinded
 
GLuint mAttributesBinded
 
bool mColorAlpha
 
bool mTextureDraw
 
FBOInfo mFbo
 

Additional Inherited Members

- Public Types inherited from Graphics
enum  Alignment { LEFT = 0, CENTER, RIGHT }
 
- Data Fields inherited from Graphics
int mWidth
 
int mHeight
 
int mActualWidth
 
int mActualHeight
 
- Protected Attributes inherited from Graphics
MStack< ClipRectmClipStack
 
SDL_Surface * mWindow
 
int mBpp
 
bool mAlpha
 
bool mFullscreen
 
bool mHWAccel
 
bool mRedraw
 
bool mDoubleBuffer
 
SDL_Rect mRect
 
bool mSecure
 
RenderType mOpenGL
 
bool mEnableResize
 
bool mNoFrame
 
bool mAllowHighDPI
 
std::string mName
 
int mStartFreeMem
 
bool mSync
 
int mScale
 
Color mColor
 
- Static Protected Attributes inherited from Graphics
static void * mGLContext = 0
 

Detailed Description

Definition at line 56 of file modernopenglgraphics.h.

Constructor & Destructor Documentation

◆ ModernOpenGLGraphics()

ModernOpenGLGraphics::ModernOpenGLGraphics ( )

Definition at line 88 of file modernopenglgraphics.cpp.

References Graphics::mName, Graphics::mOpenGL, and RENDER_MODERN_OPENGL.

88  :
89  mIntArray(nullptr),
90  mIntArrayCached(nullptr),
91  mProgram(nullptr),
92  mAlphaCached(1.0F),
93  mVpCached(0),
94  mFloatColor(1.0F),
95  mMaxVertices(500),
96  mProgramId(0U),
98  mPosAttrib(0),
100  mScreenUniform(0U),
101  mDrawTypeUniform(0U),
102  mVao(0U),
103  mVbo(0U),
104  mEbo(0U),
105  mVboBinded(0U),
106  mEboBinded(0U),
107  mAttributesBinded(0U),
108  mColorAlpha(false),
109  mTextureDraw(false),
110 #ifdef DEBUG_BIND_TEXTURE
111  mOldTexture(),
112  mOldTextureId(0),
113 #endif // DEBUG_BIND_TEXTURE
114  mFbo()
115 {
117  mName = "modern OpenGL";
118 }
std::string mName
Definition: graphics.h:548
RenderType mOpenGL
Definition: graphics.h:544

◆ ~ModernOpenGLGraphics()

ModernOpenGLGraphics::~ModernOpenGLGraphics ( )

Definition at line 120 of file modernopenglgraphics.cpp.

References deleteArraysInternal(), and deleteGLObjects().

Member Function Documentation

◆ beginDraw()

void ModernOpenGLGraphics::beginDraw ( )
virtual

Initializes drawing. Called by the Gui when Gui::draw() is called. It is needed by some implementations of Graphics to perform preparations before drawing. An example of such an implementation is the OpenGLGraphics.

NOTE: You will never need to call this function yourself, unless you use a Graphics object outside of Guichan.

See also
endDraw, Gui::draw

Reimplemented from Graphics.

Definition at line 889 of file modernopenglgraphics.cpp.

References mglDisable, mglHint, Graphics::mRect, pushClipArea(), and Graphics::setOpenGLFlags().

890 {
891  setOpenGLFlags();
892  mglDisable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB);
893  mglHint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB, GL_FASTEST);
894  pushClipArea(Rect(0, 0, mRect.w, mRect.h));
895 }
#define mglHint(...)
Definition: mgl.hpp:86
Definition: rect.h:72
void pushClipArea(const Rect &area)
SDL_Rect mRect
Definition: graphics.h:542
void setOpenGLFlags()
Definition: graphics.cpp:747
#define mglDisable(...)
Definition: mgl.hpp:84

◆ bindArrayBuffer()

void ModernOpenGLGraphics::bindArrayBuffer ( const GLuint  vbo)
inlineprivate

Definition at line 1152 of file modernopenglgraphics.cpp.

References GL_ARRAY_BUFFER, mAttributesBinded, and mVboBinded.

Referenced by finalize(), and postInit().

1153 {
1154  if (mVboBinded != vbo)
1155  {
1156  mVboBinded = vbo;
1157 // logger->log("bind array: %u", vbo);
1158  mglBindBuffer(GL_ARRAY_BUFFER, vbo);
1159 /*
1160  if (mglIsBuffer(vbo) != GL_TRUE)
1161  logger->log("bind wrong buffer: %u", vbo);
1162 */
1163  mAttributesBinded = 0U;
1164  }
1165 }
#define GL_ARRAY_BUFFER
Definition: mgldefines.h:83

◆ bindArrayBufferAndAttributes()

void ModernOpenGLGraphics::bindArrayBufferAndAttributes ( const GLuint  vbo)
inlineprivate

Definition at line 1181 of file modernopenglgraphics.cpp.

References GL_ARRAY_BUFFER, mAttributesBinded, and mVboBinded.

Referenced by drawImageInline(), drawLine(), drawNet(), drawPatternInline(), drawPoint(), drawRectangle(), drawRescaledImage(), drawRescaledPattern(), drawTileVertexes(), drawVertexes(), and fillRectangle().

1183 {
1184  if (mVboBinded != vbo)
1185  {
1186  mVboBinded = vbo;
1187 // logger->log("bind array: %u", vbo);
1188  mglBindBuffer(GL_ARRAY_BUFFER, vbo);
1189 /*
1190  if (mglIsBuffer(vbo) != GL_TRUE)
1191  logger->log("bind wrong buffer: %u", vbo);
1192 */
1193 
1195 // logger->log("bind vertex buffer: %u", mVboBinded);
1196  mglBindVertexBuffer(0, mVboBinded, 0, 4 * sizeof(GLint));
1197 // mglVertexAttribIPointer(mPosAttrib, 4, GL_INT, 4 * sizeof(GLint), 0);
1198 // mglVertexAttribBinding(mPosAttrib, 0);
1199  }
1200  else if (mAttributesBinded != mVboBinded)
1201  {
1203 // logger->log("bind vertex buffer: %u", mVboBinded);
1204  mglBindVertexBuffer(0, mVboBinded, 0, 4 * sizeof(GLint));
1205 // mglVertexAttribIPointer(mPosAttrib, 4, GL_INT, 4 * sizeof(GLint), 0);
1206 // mglVertexAttribBinding(mPosAttrib, 0);
1207  }
1208 }
#define GL_ARRAY_BUFFER
Definition: mgldefines.h:83

◆ bindAttributes()

void ModernOpenGLGraphics::bindAttributes ( )
inlineprivate

Definition at line 1210 of file modernopenglgraphics.cpp.

References mAttributesBinded, and mVboBinded.

1211 {
1213  {
1215  mglBindVertexBuffer(0, mVboBinded, 0, 4 * sizeof(GLint));
1216 // mglVertexAttribIPointer(mPosAttrib, 4, GL_INT, 4 * sizeof(GLint), 0);
1217 // mglVertexAttribBinding(mPosAttrib, 0);
1218  }
1219 }

◆ bindElementBuffer()

void ModernOpenGLGraphics::bindElementBuffer ( const GLuint  ebo)
inlineprivate

Definition at line 1167 of file modernopenglgraphics.cpp.

References GL_ELEMENT_ARRAY_BUFFER, Logger::log(), logger, and mEboBinded.

Referenced by postInit().

1168 {
1169  if (mEboBinded != ebo)
1170  {
1171  mEboBinded = ebo;
1172  logger->log("bind element: %u", ebo);
1173  mglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
1174 /*
1175  if (mglIsBuffer(ebo) != GL_TRUE)
1176  logger->log("bind wrong buffer: %u", vbo);
1177 */
1178  }
1179 }
Logger * logger
Definition: logger.cpp:88
#define GL_ELEMENT_ARRAY_BUFFER
Definition: mgldefines.h:84
void log(const char *const log_text,...)
Definition: logger.cpp:264

◆ bindTexture()

void ModernOpenGLGraphics::bindTexture ( const GLenum  target,
const GLuint  texture 
)
static

Definition at line 1130 of file modernopenglgraphics.cpp.

References mglBindTexture, and mTextureBinded.

Referenced by OpenGLImageHelper::bindTexture(), SafeOpenGLImageHelper::bindTexture(), drawImageInline(), drawPatternInline(), drawRescaledImage(), drawRescaledPattern(), drawTileCollection(), and drawTileVertexes().

1132 {
1133  if (mTextureBinded != texture)
1134  {
1135  mTextureBinded = texture;
1136  mglBindTexture(target, texture);
1137  }
1138 }
#define mglBindTexture(...)
Definition: mgl.hpp:92

◆ calcImageRect()

void ModernOpenGLGraphics::calcImageRect ( ImageVertexes *const  vert,
int  x,
int  y,
int  w,
int  h,
const ImageRect imgRect 
)
inlineprivate

Definition at line 1249 of file modernopenglgraphics.cpp.

Referenced by calcWindow().

◆ calcPattern() [1/2]

void ModernOpenGLGraphics::calcPattern ( ImageVertexes *const  vert,
const Image *const  image,
const int  x,
const int  y,
const int  w,
const int  h 
) const
virtual

Implements Graphics.

Definition at line 627 of file modernopenglgraphics.cpp.

References calcPatternInline(), x, and y.

633 {
634  calcPatternInline(vert, image, x, y, w, h);
635 }
void calcPatternInline(ImageVertexes *const vert, const Image *const image, const int x, const int y, const int w, const int h) const A_INLINE

◆ calcPattern() [2/2]

void ModernOpenGLGraphics::calcPattern ( ImageCollection *const  vert,
const Image *const  image,
const int  x,
const int  y,
const int  w,
const int  h 
) const
virtual

Implements Graphics.

Definition at line 747 of file modernopenglgraphics.cpp.

References calcPatternInline(), ImageVertexes::image, x, and y.

753 {
754  if (vertCol == nullptr || image == nullptr)
755  return;
756  ImageVertexes *vert = nullptr;
757  if (vertCol->currentGLImage != image->mGLImage)
758  {
759  vert = new ImageVertexes;
760  vertCol->currentGLImage = image->mGLImage;
761  vertCol->currentVert = vert;
762  vert->image = image;
763  vertCol->draws.push_back(vert);
764  }
765  else
766  {
767  vert = vertCol->currentVert;
768  }
769 
770  calcPatternInline(vert, image, x, y, w, h);
771 }
const Image * image
Definition: imagevertexes.h:47
void calcPatternInline(ImageVertexes *const vert, const Image *const image, const int x, const int y, const int w, const int h) const A_INLINE
GLuint mGLImage
Definition: image.h:182

◆ calcPatternInline()

void ModernOpenGLGraphics::calcPatternInline ( ImageVertexes *const  vert,
const Image *const  image,
const int  x,
const int  y,
const int  w,
const int  h 
) const
inlineprivate

Definition at line 637 of file modernopenglgraphics.cpp.

References OpenGLGraphicsVertexes::continueIntTexArray(), OpenGLGraphicsVertexes::continueVp(), Graphics::mClipStack, mMaxVertices, OpenGLGraphicsVertexes::switchIntTexArray(), OpenGLGraphicsVertexes::switchVp(), MStack< T >::top(), vertFill2D, x, ClipRect::xOffset, y, and ClipRect::yOffset.

Referenced by calcPattern().

644 {
645  if (image == nullptr || vert == nullptr)
646  return;
647 
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;
653 
654  if (iw == 0 || ih == 0)
655  return;
656 
657  const ClipRect &clipArea = mClipStack.top();
658  const int x2 = x + clipArea.xOffset;
659  const int y2 = y + clipArea.yOffset;
660 
661  const unsigned int vLimit = mMaxVertices * 4;
662 
663  OpenGLGraphicsVertexes &ogl = vert->ogl;
664  unsigned int vp = ogl.continueVp();
665 
666  GLint *intArray = ogl.continueIntTexArray();
667 
668  for (int py = 0; py < h; py += ih)
669  {
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)
674  {
675  const int width = (px + iw >= w) ? w - px : iw;
676  const int dstX = x2 + px;
677  const int texX2 = srcX + width;
678 
679  vertFill2D(intArray,
680  srcX, srcY, texX2, texY2,
681  dstX, dstY, width, height);
682 
683  vp += 24;
684  if (vp >= vLimit)
685  {
686  intArray = ogl.switchIntTexArray();
687  ogl.switchVp(vp);
688  vp = 0;
689  }
690  }
691  }
692  ogl.switchVp(vp);
693 }
int yOffset
Definition: cliprect.h:126
int xOffset
Definition: cliprect.h:121
#define vertFill2D(var, x1, y1, x2, y2, dstX, dstY, w, h)
MStack< ClipRect > mClipStack
Definition: graphics.h:520
SDL_Rect mBounds
Definition: image.h:210
T & top() const
Definition: mstack.h:72
OpenGLGraphicsVertexes ogl
Definition: imagevertexes.h:49

◆ calcTileCollection()

void ModernOpenGLGraphics::calcTileCollection ( ImageCollection *const  vertCol,
const Image *const  image,
int  x,
int  y 
)
virtual

Implements Graphics.

Definition at line 695 of file modernopenglgraphics.cpp.

References calcTileVertexesInline(), ImageVertexes::image, x, and y.

700 {
701  if (vertCol == nullptr || image == nullptr)
702  return;
703  if (vertCol->currentGLImage != image->mGLImage)
704  {
705  ImageVertexes *const vert = new ImageVertexes;
706  vertCol->currentGLImage = image->mGLImage;
707  vertCol->currentVert = vert;
708  vert->image = image;
709  vertCol->draws.push_back(vert);
710  calcTileVertexesInline(vert, image, x, y);
711  }
712  else
713  {
714  calcTileVertexesInline(vertCol->currentVert, image, x, y);
715  }
716 }
void calcTileVertexesInline(ImageVertexes *const vert, const Image *const image, int x, int y) const A_INLINE
const Image * image
Definition: imagevertexes.h:47
ImageVertexesVector draws
ImageVertexes * currentVert
GLuint mGLImage
Definition: image.h:182

◆ calcTileVertexes()

void ModernOpenGLGraphics::calcTileVertexes ( ImageVertexes *const  vert,
const Image *const  image,
int  x,
int  y 
) const
virtual

Implements Graphics.

Definition at line 773 of file modernopenglgraphics.cpp.

References calcTileVertexesInline().

776 {
777  calcTileVertexesInline(vert, image, dstX, dstY);
778 }
void calcTileVertexesInline(ImageVertexes *const vert, const Image *const image, int x, int y) const A_INLINE

◆ calcTileVertexesInline()

void ModernOpenGLGraphics::calcTileVertexesInline ( ImageVertexes *const  vert,
const Image *const  image,
int  x,
int  y 
) const
inlineprivate

Definition at line 780 of file modernopenglgraphics.cpp.

References OpenGLGraphicsVertexes::continueIntTexArray(), OpenGLGraphicsVertexes::continueVp(), Graphics::mClipStack, mMaxVertices, OpenGLGraphicsVertexes::switchIntTexArray(), OpenGLGraphicsVertexes::switchVp(), MStack< T >::top(), vertFill2D, ClipRect::xOffset, and ClipRect::yOffset.

Referenced by calcTileCollection(), and calcTileVertexes().

786 {
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;
792 
793  if (w == 0 || h == 0)
794  return;
795 
796  const ClipRect &clipArea = mClipStack.top();
797  const int x2 = dstX + clipArea.xOffset;
798  const int y2 = dstY + clipArea.yOffset;
799 
800  const unsigned int vLimit = mMaxVertices * 4;
801 
802  OpenGLGraphicsVertexes &ogl = vert->ogl;
803 
804  unsigned int vp = ogl.continueVp();
805 
806  int texX2 = srcX + w;
807  int texY2 = srcY + h;
808 
809  GLint *const intArray = ogl.continueIntTexArray();
810 
811  vertFill2D(intArray,
812  srcX, srcY, texX2, texY2,
813  x2, y2, w, h);
814 
815  vp += 24;
816  if (vp >= vLimit)
817  {
818  ogl.switchIntTexArray();
819  ogl.switchVp(vp);
820  vp = 0;
821  }
822 
823  ogl.switchVp(vp);
824 }
int yOffset
Definition: cliprect.h:126
int xOffset
Definition: cliprect.h:121
#define vertFill2D(var, x1, y1, x2, y2, dstX, dstY, w, h)
MStack< ClipRect > mClipStack
Definition: graphics.h:520
SDL_Rect mBounds
Definition: image.h:210
T & top() const
Definition: mstack.h:72
OpenGLGraphicsVertexes ogl
Definition: imagevertexes.h:49

◆ calcWindow()

void ModernOpenGLGraphics::calcWindow ( ImageCollection *const  vertCol,
const int  x,
const int  y,
const int  w,
const int  h,
const ImageRect imgRect 
)
virtual

Implements Graphics.

Definition at line 845 of file modernopenglgraphics.cpp.

References calcImageRect(), ImageVertexes::image, Image::mGLImage, x, and y.

850 {
851  ImageVertexes *vert = nullptr;
852  const Image *const image = imgRect.grid[4];
853  if (image == nullptr)
854  return;
855  if (vertCol->currentGLImage != image->mGLImage)
856  {
857  vert = new ImageVertexes;
858  vertCol->currentGLImage = image->mGLImage;
859  vertCol->currentVert = vert;
860  vert->image = image;
861  vertCol->draws.push_back(vert);
862  }
863  else
864  {
865  vert = vertCol->currentVert;
866  }
867  calcImageRect(vert, x, y, w, h, imgRect);
868 }
void calcImageRect(ImageVertexes *const vert, int x, int y, int w, int h, const ImageRect &imgRect) A_INLINE
const Image * image
Definition: imagevertexes.h:47
ImageVertexesVector draws
ImageVertexes * currentVert
Image * grid[9]
Definition: imagerect.h:41
GLuint mGLImage
Definition: image.h:182
Definition: image.h:61

◆ clearScreen()

void ModernOpenGLGraphics::clearScreen ( ) const
virtual

Reimplemented from Graphics.

Definition at line 1258 of file modernopenglgraphics.cpp.

References mglClear.

1259 {
1260  mglClear(GL_COLOR_BUFFER_BIT |
1261  GL_DEPTH_BUFFER_BIT |
1262  GL_STENCIL_BUFFER_BIT);
1263 }
#define mglClear(...)
Definition: mgl.hpp:96

◆ completeCache()

void ModernOpenGLGraphics::completeCache ( )
virtual

Implements Graphics.

Definition at line 418 of file modernopenglgraphics.cpp.

419 {
420 }

◆ copyImage()

void ModernOpenGLGraphics::copyImage ( const Image *const  image,
int  dstX,
int  dstY 
)
virtual

Implements Graphics.

Definition at line 369 of file modernopenglgraphics.cpp.

References drawImageInline().

371 {
372  drawImageInline(image, dstX, dstY);
373 }
void drawImageInline(const Image *const image, int dstX, int dstY) A_INLINE

◆ createGLContext()

void ModernOpenGLGraphics::createGLContext ( const bool  custom)
virtual

Reimplemented from Graphics.

Definition at line 1265 of file modernopenglgraphics.cpp.

References SDL::createGLContext(), Graphics::createGLContext(), SDL::makeCurrentContext(), Graphics::mGLContext, and Graphics::mWindow.

1266 {
1267  if (custom)
1268  {
1269  if (mGLContext != nullptr)
1271  else
1272  mGLContext = SDL::createGLContext(mWindow, 3, 3, 0x01);
1273  }
1274  else
1275  {
1277  }
1278 }
SDL_Surface * mWindow
Definition: graphics.h:522
void * createGLContext(SDL_Surface *const window, const int major, const int minor, const int profile)
Definition: sdlhelper.cpp:173
static void * mGLContext
Definition: graphics.h:532
void makeCurrentContext(void *const context)
Definition: sdlhelper.cpp:181
virtual void createGLContext(const bool custom)
Definition: graphics.cpp:417

◆ debugBindTexture()

void ModernOpenGLGraphics::debugBindTexture ( const Image *const  image)
protected

◆ deleteArrays()

void ModernOpenGLGraphics::deleteArrays ( )
virtual

Reimplemented from Graphics.

Definition at line 221 of file modernopenglgraphics.cpp.

References deleteArraysInternal().

222 {
224 }

◆ deleteArraysInternal()

void ModernOpenGLGraphics::deleteArraysInternal ( )
protected

Definition at line 226 of file modernopenglgraphics.cpp.

References mIntArray, and mIntArrayCached.

Referenced by deleteArrays(), and ~ModernOpenGLGraphics().

227 {
228  delete [] mIntArray;
229  mIntArray = nullptr;
230  delete [] mIntArrayCached;
231  mIntArrayCached = nullptr;
232 }

◆ deleteGLObjects()

void ModernOpenGLGraphics::deleteGLObjects ( )
private

Definition at line 126 of file modernopenglgraphics.cpp.

References delete2, mEbo, mProgram, mVao, and mVbo.

Referenced by screenResized(), and ~ModernOpenGLGraphics().

127 {
128  delete2(mProgram);
129  if (mVbo != 0u)
130  {
131 // logger->log("delete buffer vbo: %u", mVbo);
132  mglDeleteBuffers(1, &mVbo);
133  }
134  if (mEbo != 0u)
135  {
136 // logger->log("delete buffer ebo: %u", mEbo);
137  mglDeleteBuffers(1, &mEbo);
138  }
139  if (mVao != 0u)
140  mglDeleteVertexArrays(1, &mVao);
141 }
#define delete2(var)
Definition: delete2.h:24

◆ disableTexturingAndBlending()

void ModernOpenGLGraphics::disableTexturingAndBlending ( )
protected

Definition at line 1044 of file modernopenglgraphics.cpp.

References Graphics::mAlpha, mColorAlpha, mDrawTypeUniform, mglDisable, mglEnable, and mTextureDraw.

Referenced by drawLine(), drawNet(), drawPoint(), drawRectangle(), and fillRectangle().

1045 {
1046  if (mTextureDraw)
1047  {
1048  mTextureDraw = false;
1049  mglUniform1f(mDrawTypeUniform, 0.0f);
1050  }
1051  if (mAlpha && !mColorAlpha)
1052  {
1053  mglDisable(GL_BLEND);
1054  mAlpha = false;
1055  }
1056  else if (!mAlpha && mColorAlpha)
1057  {
1058  mglEnable(GL_BLEND);
1059  mAlpha = true;
1060  }
1061 }
bool mAlpha
Definition: graphics.h:537
#define mglDisable(...)
Definition: mgl.hpp:84
#define mglEnable(...)
Definition: mgl.hpp:90

◆ drawImage()

void ModernOpenGLGraphics::drawImage ( const Image *const  image,
int  dstX,
int  dstY 
)
virtual

Blits an image onto the screen.

Returns
true if the image was blitted properly false otherwise.

Implements Graphics.

Definition at line 341 of file modernopenglgraphics.cpp.

References drawImageInline().

343 {
344  drawImageInline(image, dstX, dstY);
345 }
void drawImageInline(const Image *const image, int dstX, int dstY) A_INLINE

◆ drawImageCached()

void ModernOpenGLGraphics::drawImageCached ( const Image *const  image,
int  x,
int  y 
)
virtual

Implements Graphics.

Definition at line 402 of file modernopenglgraphics.cpp.

406 {
407 }

◆ drawImageInline()

void ModernOpenGLGraphics::drawImageInline ( const Image *const  image,
int  dstX,
int  dstY 
)
inlineprivate

Definition at line 347 of file modernopenglgraphics.cpp.

References bindArrayBufferAndAttributes(), bindTexture(), debugBindTexture(), drawQuad(), enableTexturingAndBlending(), FUNC_BLOCK, Graphics::mClipStack, mVbo, setColorAlpha(), MStack< T >::top(), ClipRect::xOffset, and ClipRect::yOffset.

Referenced by copyImage(), drawImage(), and drawRescaledImage().

349 {
350  FUNC_BLOCK("Graphics::drawImage", 1)
351  if (image == nullptr)
352  return;
353 
354 #ifdef DEBUG_BIND_TEXTURE
355  debugBindTexture(image);
356 #endif // DEBUG_BIND_TEXTURE
357  bindTexture(GL_TEXTURE_2D, image->mGLImage);
360  setColorAlpha(image->mAlpha);
361 
362  const ClipRect &clipArea = mClipStack.top();
363  const SDL_Rect &imageRect = image->mBounds;
364  drawQuad(imageRect.x, imageRect.y,
365  dstX + clipArea.xOffset, dstY + clipArea.yOffset,
366  imageRect.w, imageRect.h);
367 }
void drawQuad(const int srcX, const int srcY, const int dstX, const int dstY, const int width, const int height) A_INLINE
if(!vert) return
int yOffset
Definition: cliprect.h:126
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
int xOffset
Definition: cliprect.h:121
float mAlpha
Definition: image.h:212
#define FUNC_BLOCK(name, id)
Definition: perfomance.h:80
GLuint mGLImage
Definition: image.h:182
static void bindTexture(const GLenum target, const GLuint texture)
void setColorAlpha(const float alpha) A_INLINE
MStack< ClipRect > mClipStack
Definition: graphics.h:520
SDL_Rect mBounds
Definition: image.h:210
T & top() const
Definition: mstack.h:72
void debugBindTexture(const Image *const image)

◆ drawImageRect()

void ModernOpenGLGraphics::drawImageRect ( int  x,
int  y,
int  w,
int  h,
const ImageRect imgRect 
)
virtual

Draws a rectangle using images. 4 corner images, 4 side images and 1 image for the inside.

Implements Graphics.

Definition at line 1241 of file modernopenglgraphics.cpp.

◆ drawLine()

void ModernOpenGLGraphics::drawLine ( int  x1,
int  y1,
int  x2,
int  y2 
)
virtual

Ddraws a line.

Parameters
x1The first x coordinate.
y1The first y coordinate.
x2The second x coordinate.
y2The second y coordinate.

Implements Graphics.

Definition at line 949 of file modernopenglgraphics.cpp.

References bindArrayBufferAndAttributes(), disableTexturingAndBlending(), GL_ARRAY_BUFFER, GL_STREAM_DRAW, graphicsManager, GraphicsManager::logError(), Graphics::mClipStack, mglDrawArrays, mVbo, MStack< T >::top(), ClipRect::xOffset, and ClipRect::yOffset.

951 {
954  const ClipRect &clipArea = mClipStack.top();
955  GLint vertices[] =
956  {
957  x1 + clipArea.xOffset, y1 + clipArea.yOffset, 0, 0,
958  x2 + clipArea.xOffset, y2 + clipArea.yOffset, 0, 0
959  };
960 // logger->log("allocate: %d, %ld", mVboBinded, sizeof(vertices));
961  mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
962  vertices, GL_STREAM_DRAW);
963 #ifdef DEBUG_DRAW_CALLS
964  mDrawCalls ++;
965 #endif // DEBUG_DRAW_CALLS
966  mglDrawArrays(GL_LINES, 0, 2);
967 #ifdef OPENGLERRORS
969 #endif // OPENGLERRORS
970 }
#define GL_ARRAY_BUFFER
Definition: mgldefines.h:83
int yOffset
Definition: cliprect.h:126
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
int xOffset
Definition: cliprect.h:121
#define GL_STREAM_DRAW
Definition: mgldefines.h:88
#define mglDrawArrays(...)
Definition: mgl.hpp:82
static void logError()
MStack< ClipRect > mClipStack
Definition: graphics.h:520
T & top() const
Definition: mstack.h:72
GraphicsManager graphicsManager

◆ drawLineArrays()

void ModernOpenGLGraphics::drawLineArrays ( const int  size)
inlineprivate

Definition at line 1366 of file modernopenglgraphics.cpp.

References debugBindTexture(), GL_ARRAY_BUFFER, GL_STREAM_DRAW, graphicsManager, Logger::log(), GraphicsManager::logError(), logger, mglDrawArrays, mIntArray, restrict, and restrict2.

Referenced by drawNet().

1367 {
1368 // logger->log("allocate: %d, %ld", mVboBinded, size * sizeof(GLint));
1369  mglBufferData(GL_ARRAY_BUFFER, size * sizeof(GLint),
1371 #ifdef DEBUG_DRAW_CALLS
1372  mDrawCalls ++;
1373 #endif // DEBUG_DRAW_CALLS
1374  mglDrawArrays(GL_LINES, 0, size / 4);
1375 #ifdef OPENGLERRORS
1377 #endif // OPENGLERRORS
1378 }
#define GL_ARRAY_BUFFER
Definition: mgldefines.h:83
#define GL_STREAM_DRAW
Definition: mgldefines.h:88
#define mglDrawArrays(...)
Definition: mgl.hpp:82
static void logError()
GraphicsManager graphicsManager

◆ drawNet()

void ModernOpenGLGraphics::drawNet ( const int  x1,
const int  y1,
const int  x2,
const int  y2,
const int  width,
const int  height 
)
virtual

Reimplemented from Graphics.

Definition at line 1068 of file modernopenglgraphics.cpp.

References bindArrayBufferAndAttributes(), disableTexturingAndBlending(), drawLineArrays(), Graphics::mClipStack, mIntArray, mMaxVertices, mVbo, MStack< T >::top(), x, ClipRect::xOffset, y, and ClipRect::yOffset.

1071 {
1072  unsigned int vp = 0;
1073  const unsigned int vLimit = mMaxVertices * 4;
1074 
1077  const ClipRect &clipArea = mClipStack.top();
1078  const GLint dx = clipArea.xOffset;
1079  const GLint dy = clipArea.yOffset;
1080 
1081  const GLint xs1 = x1 + dx;
1082  const GLint xs2 = x2 + dx;
1083  const GLint ys1 = y1 + dy;
1084  const GLint ys2 = y2 + dy;
1085 
1086  for (int y = y1; y < y2; y += height)
1087  {
1088  mIntArray[vp + 0] = xs1;
1089  mIntArray[vp + 1] = y;
1090  mIntArray[vp + 2] = 0;
1091  mIntArray[vp + 3] = 0;
1092 
1093  mIntArray[vp + 4] = xs2;
1094  mIntArray[vp + 5] = y;
1095  mIntArray[vp + 6] = 0;
1096  mIntArray[vp + 7] = 0;
1097 
1098  vp += 8;
1099  if (vp >= vLimit)
1100  {
1101  drawLineArrays(vp);
1102  vp = 0;
1103  }
1104  }
1105 
1106  for (int x = x1; x < x2; x += width)
1107  {
1108  mIntArray[vp + 0] = x;
1109  mIntArray[vp + 1] = ys1;
1110  mIntArray[vp + 2] = 0.0f;
1111  mIntArray[vp + 3] = 0.0f;
1112 
1113  mIntArray[vp + 4] = x;
1114  mIntArray[vp + 5] = ys2;
1115  mIntArray[vp + 6] = 0.0f;
1116  mIntArray[vp + 7] = 0.0f;
1117 
1118  vp += 8;
1119  if (vp >= vLimit)
1120  {
1121  drawLineArrays(vp);
1122  vp = 0;
1123  }
1124  }
1125 
1126  if (vp > 0)
1127  drawLineArrays(vp);
1128 }
void drawLineArrays(const int size) A_INLINE
int yOffset
Definition: cliprect.h:126
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
int xOffset
Definition: cliprect.h:121
MStack< ClipRect > mClipStack
Definition: graphics.h:520
T & top() const
Definition: mstack.h:72

◆ drawPattern()

void ModernOpenGLGraphics::drawPattern ( const Image *const  image,
const int  x,
const int  y,
const int  w,
const int  h 
)
virtual

Implements Graphics.

Definition at line 455 of file modernopenglgraphics.cpp.

References drawPatternInline(), x, and y.

458 {
459  drawPatternInline(image, x, y, w, h);
460 }
void drawPatternInline(const Image *const image, const int x, const int y, const int w, const int h) A_INLINE

◆ drawPatternCached()

void ModernOpenGLGraphics::drawPatternCached ( const Image *const  image,
const int  x,
const int  y,
const int  w,
const int  h 
)
virtual

Implements Graphics.

Definition at line 409 of file modernopenglgraphics.cpp.

415 {
416 }

◆ drawPatternInline()

void ModernOpenGLGraphics::drawPatternInline ( const Image *const  image,
const int  x,
const int  y,
const int  w,
const int  h 
)
inline

Definition at line 462 of file modernopenglgraphics.cpp.

References bindArrayBufferAndAttributes(), bindTexture(), debugBindTexture(), drawTriangleArray(), enableTexturingAndBlending(), Graphics::mClipStack, mIntArray, mMaxVertices, OpenGLImageHelper::mTextureType, mVbo, setColorAlpha(), MStack< T >::top(), vertFill2D, x, ClipRect::xOffset, y, and ClipRect::yOffset.

Referenced by drawPattern().

467 {
468  if (image == nullptr)
469  return;
470 
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;
476 
477  if (iw == 0 || ih == 0)
478  return;
479 
480  const ClipRect &clipArea = mClipStack.top();
481  const int x2 = x + clipArea.xOffset;
482  const int y2 = y + clipArea.yOffset;
483 
484 #ifdef DEBUG_BIND_TEXTURE
485  debugBindTexture(image);
486 #endif // DEBUG_BIND_TEXTURE
487 
489 
492  setColorAlpha(image->mAlpha);
493 
494  unsigned int vp = 0;
495  const unsigned int vLimit = mMaxVertices * 4;
496 
497  for (int py = 0; py < h; py += ih)
498  {
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)
503  {
504  const int width = (px + iw >= w) ? w - px : iw;
505  const int dstX = x2 + px;
506 
507  const int texX2 = srcX + width;
508 
510  srcX, srcY, texX2, texY2,
511  dstX, dstY, width, height);
512 
513  vp += 24;
514  if (vp >= vLimit)
515  {
516  drawTriangleArray(vp);
517  vp = 0;
518  }
519  }
520  }
521  if (vp > 0)
522  drawTriangleArray(vp);
523 }
int yOffset
Definition: cliprect.h:126
void drawTriangleArray(const int size) A_INLINE
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
int xOffset
Definition: cliprect.h:121
#define vertFill2D(var, x1, y1, x2, y2, dstX, dstY, w, h)
float mAlpha
Definition: image.h:212
GLuint mGLImage
Definition: image.h:182
static void bindTexture(const GLenum target, const GLuint texture)
void setColorAlpha(const float alpha) A_INLINE
MStack< ClipRect > mClipStack
Definition: graphics.h:520
SDL_Rect mBounds
Definition: image.h:210
T & top() const
Definition: mstack.h:72
void debugBindTexture(const Image *const image)

◆ drawPoint()

void ModernOpenGLGraphics::drawPoint ( int  x,
int  y 
)
virtual

Draws a single point/pixel.

Parameters
xThe x coordinate.
yThe y coordinate.

Implements Graphics.

Definition at line 928 of file modernopenglgraphics.cpp.

References bindArrayBufferAndAttributes(), disableTexturingAndBlending(), GL_ARRAY_BUFFER, GL_STREAM_DRAW, graphicsManager, GraphicsManager::logError(), Graphics::mClipStack, mglDrawArrays, mVbo, MStack< T >::top(), x, ClipRect::xOffset, y, and ClipRect::yOffset.

929 {
932  const ClipRect &clipArea = mClipStack.top();
933  GLint vertices[] =
934  {
935  x + clipArea.xOffset, y + clipArea.yOffset, 0, 0
936  };
937 // logger->log("allocate: %d, %ld", mVboBinded, sizeof(vertices));
938  mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
939  vertices, GL_STREAM_DRAW);
940 #ifdef DEBUG_DRAW_CALLS
941  mDrawCalls ++;
942 #endif // DEBUG_DRAW_CALLS
943  mglDrawArrays(GL_POINTS, 0, 1);
944 #ifdef OPENGLERRORS
946 #endif // OPENGLERRORS
947 }
#define GL_ARRAY_BUFFER
Definition: mgldefines.h:83
int yOffset
Definition: cliprect.h:126
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
int xOffset
Definition: cliprect.h:121
#define GL_STREAM_DRAW
Definition: mgldefines.h:88
#define mglDrawArrays(...)
Definition: mgl.hpp:82
static void logError()
MStack< ClipRect > mClipStack
Definition: graphics.h:520
T & top() const
Definition: mstack.h:72
GraphicsManager graphicsManager

◆ drawQuad()

void ModernOpenGLGraphics::drawQuad ( const int  srcX,
const int  srcY,
const int  dstX,
const int  dstY,
const int  width,
const int  height 
)
inlineprivate

Definition at line 278 of file modernopenglgraphics.cpp.

References GL_ARRAY_BUFFER, GL_STREAM_DRAW, graphicsManager, GraphicsManager::logError(), and mglDrawArrays.

Referenced by drawImageInline().

284 {
285  const int texX2 = srcX + width;
286  const int texY2 = srcY + height;
287  const int x2 = dstX + width;
288  const int y2 = dstY + height;
289 
290  GLint vertices[] =
291  {
292  dstX, dstY, srcX, srcY,
293  x2, dstY, texX2, srcY,
294  dstX, y2, srcX, texY2,
295  x2, y2, texX2, texY2
296  };
297 
298 // logger->log("allocate: %d, %ld", mVboBinded, sizeof(vertices));
299  mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
300  vertices, GL_STREAM_DRAW);
301 #ifdef DEBUG_DRAW_CALLS
302  mDrawCalls ++;
303 #endif // DEBUG_DRAW_CALLS
304  mglDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
305 #ifdef OPENGLERRORS
307 #endif // OPENGLERRORS
308 }
#define GL_ARRAY_BUFFER
Definition: mgldefines.h:83
#define GL_STREAM_DRAW
Definition: mgldefines.h:88
#define mglDrawArrays(...)
Definition: mgl.hpp:82
static void logError()
GraphicsManager graphicsManager

◆ drawRectangle() [1/2]

void ModernOpenGLGraphics::drawRectangle ( const Rect rect,
const bool  filled 
)

Definition at line 1063 of file modernopenglgraphics.cpp.

1065 {
1066 }

◆ drawRectangle() [2/2]

void ModernOpenGLGraphics::drawRectangle ( const Rect rectangle)
virtual

Draws a simple, non-filled, rectangle with a one pixel width.

Parameters
rectangleThe rectangle to draw.

Implements Graphics.

Definition at line 972 of file modernopenglgraphics.cpp.

References bindArrayBufferAndAttributes(), disableTexturingAndBlending(), GL_ARRAY_BUFFER, GL_STREAM_DRAW, graphicsManager, GraphicsManager::logError(), Graphics::mClipStack, mglDrawArrays, mVbo, MStack< T >::top(), Rect::x, ClipRect::xOffset, and ClipRect::yOffset.

973 {
976  const ClipRect &clipArea = mClipStack.top();
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;
981  GLint vertices[] =
982  {
983  x1, y1, 0, 0,
984  x1, y2, 0, 0,
985  x2, y2, 0, 0,
986  x2, y1, 0, 0
987  };
988 
989 // logger->log("allocate: %d, %ld", mVboBinded, sizeof(vertices));
990  mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
991  vertices, GL_STREAM_DRAW);
992 #ifdef DEBUG_DRAW_CALLS
993  mDrawCalls ++;
994 #endif // DEBUG_DRAW_CALLS
995  mglDrawArrays(GL_LINE_LOOP, 0, 4);
996 #ifdef OPENGLERRORS
998 #endif // OPENGLERRORS
999 }
#define GL_ARRAY_BUFFER
Definition: mgldefines.h:83
int yOffset
Definition: cliprect.h:126
int x
Definition: rect.h:208
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
int xOffset
Definition: cliprect.h:121
#define GL_STREAM_DRAW
Definition: mgldefines.h:88
#define mglDrawArrays(...)
Definition: mgl.hpp:82
static void logError()
MStack< ClipRect > mClipStack
Definition: graphics.h:520
T & top() const
Definition: mstack.h:72
GraphicsManager graphicsManager

◆ drawRescaledImage()

void ModernOpenGLGraphics::drawRescaledImage ( const Image *const  image,
int  dstX,
int  dstY,
const int  desiredWidth,
const int  desiredHeight 
)
virtual

Draws a resclaled version of the image

Implements Graphics.

Definition at line 422 of file modernopenglgraphics.cpp.

References bindArrayBufferAndAttributes(), bindTexture(), debugBindTexture(), drawImageInline(), drawRescaledQuad(), enableTexturingAndBlending(), Graphics::mClipStack, OpenGLImageHelper::mTextureType, mVbo, setColorAlpha(), MStack< T >::top(), ClipRect::xOffset, and ClipRect::yOffset.

426 {
427  if (image == nullptr)
428  return;
429 
430  const SDL_Rect &imageRect = image->mBounds;
431 
432  // Just draw the image normally when no resizing is necessary,
433  if (imageRect.w == desiredWidth && imageRect.h == desiredHeight)
434  {
435  drawImageInline(image, dstX, dstY);
436  return;
437  }
438 
439  setColorAlpha(image->mAlpha);
440 #ifdef DEBUG_BIND_TEXTURE
441  debugBindTexture(image);
442 #endif // DEBUG_BIND_TEXTURE
446 
447  const ClipRect &clipArea = mClipStack.top();
448  // Draw a textured quad.
449  drawRescaledQuad(imageRect.x, imageRect.y,
450  dstX + clipArea.xOffset, dstY + clipArea.yOffset,
451  imageRect.w, imageRect.h,
452  desiredWidth, desiredHeight);
453 }
int yOffset
Definition: cliprect.h:126
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
int xOffset
Definition: cliprect.h:121
float mAlpha
Definition: image.h:212
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
GLuint mGLImage
Definition: image.h:182
void drawImageInline(const Image *const image, int dstX, int dstY) A_INLINE
static void bindTexture(const GLenum target, const GLuint texture)
void setColorAlpha(const float alpha) A_INLINE
MStack< ClipRect > mClipStack
Definition: graphics.h:520
SDL_Rect mBounds
Definition: image.h:210
T & top() const
Definition: mstack.h:72
void debugBindTexture(const Image *const image)

◆ drawRescaledPattern()

void ModernOpenGLGraphics::drawRescaledPattern ( const Image *const  image,
const int  x,
const int  y,
const int  w,
const int  h,
const int  scaledWidth,
const int  scaledHeight 
)
virtual

Draw a pattern based on a rescaled version of the given image...

Implements Graphics.

Definition at line 525 of file modernopenglgraphics.cpp.

References bindArrayBufferAndAttributes(), bindTexture(), debugBindTexture(), drawTriangleArray(), enableTexturingAndBlending(), Graphics::mClipStack, mIntArray, mMaxVertices, OpenGLImageHelper::mTextureType, mVbo, setColorAlpha(), MStack< T >::top(), vertFill2D, x, ClipRect::xOffset, y, and ClipRect::yOffset.

532 {
533  if (image == nullptr)
534  return;
535 
536  if (scaledWidth == 0 || scaledHeight == 0)
537  return;
538 
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)
545  return;
546 
547 #ifdef DEBUG_BIND_TEXTURE
548  debugBindTexture(image);
549 #endif // DEBUG_BIND_TEXTURE
550 
552 
555  setColorAlpha(image->mAlpha);
556 
557  unsigned int vp = 0;
558  const unsigned int vLimit = mMaxVertices * 4;
559 
560  const ClipRect &clipArea = mClipStack.top();
561  const int x2 = x + clipArea.xOffset;
562  const int y2 = y + clipArea.yOffset;
563 
564  const float scaleFactorW = static_cast<float>(scaledWidth) / iw;
565  const float scaleFactorH = static_cast<float>(scaledHeight) / ih;
566 
567  for (int py = 0; py < h; py += scaledHeight)
568  {
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)
574  {
575  const int width = (px + scaledWidth >= w)
576  ? w - px : scaledWidth;
577  const int dstX = x2 + px;
578  const int scaledX = srcX + width / scaleFactorW;
579 
581  srcX, srcY, scaledX, scaledY,
582  dstX, dstY, width, height);
583 
584  vp += 24;
585  if (vp >= vLimit)
586  {
587  drawTriangleArray(vp);
588  vp = 0;
589  }
590  }
591  }
592  if (vp > 0)
593  drawTriangleArray(vp);
594 }
int yOffset
Definition: cliprect.h:126
void drawTriangleArray(const int size) A_INLINE
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
int xOffset
Definition: cliprect.h:121
#define vertFill2D(var, x1, y1, x2, y2, dstX, dstY, w, h)
float mAlpha
Definition: image.h:212
GLuint mGLImage
Definition: image.h:182
static void bindTexture(const GLenum target, const GLuint texture)
void setColorAlpha(const float alpha) A_INLINE
MStack< ClipRect > mClipStack
Definition: graphics.h:520
SDL_Rect mBounds
Definition: image.h:210
T & top() const
Definition: mstack.h:72
void debugBindTexture(const Image *const image)

◆ drawRescaledQuad()

void ModernOpenGLGraphics::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 
)
inlineprivate

Definition at line 310 of file modernopenglgraphics.cpp.

References GL_ARRAY_BUFFER, GL_STREAM_DRAW, graphicsManager, GraphicsManager::logError(), and mglDrawArrays.

Referenced by drawRescaledImage().

315 {
316  const int texX2 = srcX + width;
317  const int texY2 = srcY + height;
318  const int x2 = dstX + desiredWidth;
319  const int y2 = dstY + desiredHeight;
320 
321  GLint vertices[] =
322  {
323  dstX, dstY, srcX, srcY,
324  x2, dstY, texX2, srcY,
325  dstX, y2, srcX, texY2,
326  x2, y2, texX2, texY2
327  };
328 
329 // logger->log("allocate: %d, %ld", mVboBinded, sizeof(vertices));
330  mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
331  vertices, GL_STREAM_DRAW);
332 #ifdef DEBUG_DRAW_CALLS
333  mDrawCalls ++;
334 #endif // DEBUG_DRAW_CALLS
335  mglDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
336 #ifdef OPENGLERRORS
338 #endif // OPENGLERRORS
339 }
#define GL_ARRAY_BUFFER
Definition: mgldefines.h:83
#define GL_STREAM_DRAW
Definition: mgldefines.h:88
#define mglDrawArrays(...)
Definition: mgl.hpp:82
static void logError()
GraphicsManager graphicsManager

◆ drawTileCollection()

void ModernOpenGLGraphics::drawTileCollection ( const ImageCollection *const  vertCol)
virtual

Implements Graphics.

Definition at line 718 of file modernopenglgraphics.cpp.

References bindTexture(), debugBindTexture(), drawVertexes(), enableTexturingAndBlending(), ImageVertexes::image, Image::mAlpha, Image::mGLImage, OpenGLImageHelper::mTextureType, ImageVertexes::ogl, and setColorAlpha().

721 {
723 /*
724  if (!vertCol)
725  {
726  logger->log("ModernOpenGLGraphics::drawTileCollection"
727  " vertCol is nullptr");
728  }
729 */
730  const ImageVertexesVector &draws = vertCol->draws;
731  const ImageCollectionCIter it_end = draws.end();
732  for (ImageCollectionCIter it = draws.begin(); it != it_end; ++ it)
733  {
734  const ImageVertexes *const vert = *it;
735  const Image *const image = vert->image;
736 
737  setColorAlpha(image->mAlpha);
738 #ifdef DEBUG_BIND_TEXTURE
739  debugBindTexture(image);
740 #endif // DEBUG_BIND_TEXTURE
741 
743  drawVertexes(vert->ogl);
744  }
745 }
void drawVertexes(const OpenGLGraphicsVertexes &ogl) A_INLINE
std::vector< ImageVertexes * > ImageVertexesVector
Definition: imagevertexes.h:55
const Image * image
Definition: imagevertexes.h:47
ImageVertexesVector draws
ImageVertexesVector::const_iterator ImageCollectionCIter
Definition: imagevertexes.h:57
float mAlpha
Definition: image.h:212
GLuint mGLImage
Definition: image.h:182
static void bindTexture(const GLenum target, const GLuint texture)
void setColorAlpha(const float alpha) A_INLINE
Definition: image.h:61
OpenGLGraphicsVertexes ogl
Definition: imagevertexes.h:49
void debugBindTexture(const Image *const image)

◆ drawTileVertexes()

void ModernOpenGLGraphics::drawTileVertexes ( const ImageVertexes *const  vert)
virtual

Implements Graphics.

Definition at line 826 of file modernopenglgraphics.cpp.

References bindArrayBufferAndAttributes(), bindTexture(), debugBindTexture(), drawVertexes(), enableTexturingAndBlending(), Image::mAlpha, Image::mGLImage, OpenGLImageHelper::mTextureType, mVbo, and setColorAlpha().

828 {
829  if (vert == nullptr)
830  return;
831  const Image *const image = vert->image;
832 
833  setColorAlpha(image->mAlpha);
834 #ifdef DEBUG_BIND_TEXTURE
835  debugBindTexture(image);
836 #endif // DEBUG_BIND_TEXTURE
837 
841 
842  drawVertexes(vert->ogl);
843 }
void drawVertexes(const OpenGLGraphicsVertexes &ogl) A_INLINE
const Image * image
Definition: imagevertexes.h:47
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
float mAlpha
Definition: image.h:212
GLuint mGLImage
Definition: image.h:182
static void bindTexture(const GLenum target, const GLuint texture)
void setColorAlpha(const float alpha) A_INLINE
Definition: image.h:61
OpenGLGraphicsVertexes ogl
Definition: imagevertexes.h:49
void debugBindTexture(const Image *const image)

◆ drawTriangleArray() [1/2]

void ModernOpenGLGraphics::drawTriangleArray ( const int  size)
inlineprivate

Definition at line 1337 of file modernopenglgraphics.cpp.

References GL_ARRAY_BUFFER, GL_STREAM_DRAW, graphicsManager, GraphicsManager::logError(), mglDrawArrays, mIntArray, and ServerCommandType::size.

Referenced by drawPatternInline(), and drawRescaledPattern().

1338 {
1339 // logger->log("allocate: %d, %ld", mVboBinded, size * sizeof(GLint));
1340  mglBufferData(GL_ARRAY_BUFFER, size * sizeof(GLint),
1342 #ifdef DEBUG_DRAW_CALLS
1343  mDrawCalls ++;
1344 #endif // DEBUG_DRAW_CALLS
1345  mglDrawArrays(GL_TRIANGLES, 0, size / 4);
1346 #ifdef OPENGLERRORS
1348 #endif // OPENGLERRORS
1349 }
#define GL_ARRAY_BUFFER
Definition: mgldefines.h:83
#define GL_STREAM_DRAW
Definition: mgldefines.h:88
#define mglDrawArrays(...)
Definition: mgl.hpp:82
static void logError()
GraphicsManager graphicsManager

◆ drawTriangleArray() [2/2]

void ModernOpenGLGraphics::drawTriangleArray ( const GLint *const  array,
const int  size 
)
inlineprivate

Definition at line 1351 of file modernopenglgraphics.cpp.

References GL_ARRAY_BUFFER, GL_STREAM_DRAW, graphicsManager, GraphicsManager::logError(), mglDrawArrays, and ServerCommandType::size.

1353 {
1354 // logger->log("allocate: %d, %ld", mVboBinded, size * sizeof(GLint));
1355  mglBufferData(GL_ARRAY_BUFFER, size * sizeof(GLint),
1356  array, GL_STREAM_DRAW);
1357 #ifdef DEBUG_DRAW_CALLS
1358  mDrawCalls ++;
1359 #endif // DEBUG_DRAW_CALLS
1360  mglDrawArrays(GL_TRIANGLES, 0, size / 4);
1361 #ifdef OPENGLERRORS
1363 #endif // OPENGLERRORS
1364 }
#define GL_ARRAY_BUFFER
Definition: mgldefines.h:83
#define GL_STREAM_DRAW
Definition: mgldefines.h:88
#define mglDrawArrays(...)
Definition: mgl.hpp:82
static void logError()
GraphicsManager graphicsManager

◆ drawVertexes()

void ModernOpenGLGraphics::drawVertexes ( const OpenGLGraphicsVertexes ogl)
inline

Definition at line 596 of file modernopenglgraphics.cpp.

References bindArrayBufferAndAttributes(), graphicsManager, GraphicsManager::logError(), and mglDrawArrays.

Referenced by drawTileCollection(), and drawTileVertexes().

599 {
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();
605 
606 /*
607  if (vp.size() != vbos.size())
608  logger->log("different size in vp and vbos");
609 */
610 
611  for (ivp = vp.begin(), ivbo = vbos.begin();
612  ivp != ivp_end;
613  ++ ivp, ++ ivbo)
614  {
616 #ifdef DEBUG_DRAW_CALLS
617  mDrawCalls ++;
618 #endif // DEBUG_DRAW_CALLS
619 // logger->log("draw from array: %u", *ivbo);
620  mglDrawArrays(GL_TRIANGLES, 0, *ivp / 4);
621 #ifdef OPENGLERRORS
623 #endif // OPENGLERRORS
624  }
625 }
std::vector< GLuint > mVbo
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
#define mglDrawArrays(...)
Definition: mgl.hpp:82
static void logError()
GraphicsManager graphicsManager

◆ dumpSettings()

void ModernOpenGLGraphics::dumpSettings ( )
static

Definition at line 1221 of file modernopenglgraphics.cpp.

References Logger::log(), logger, and mglGetIntegerv.

1222 {
1223  GLint test[1000];
1224  logger->log("\n\n");
1225  logger->log("start opengl dump");
1226  for (int f = 0; f < 65535; f ++)
1227  {
1228  test[0] = 0;
1229  test[1] = 0;
1230  test[2] = 0;
1231  test[3] = 0;
1232  mglGetIntegerv(f, &test[0]);
1233  if (test[0] != 0 || test[1] != 0 || test[2] != 0 || test[3] != 0)
1234  {
1235  logger->log("\n%d = %d, %d, %d, %d", f,
1236  test[0], test[1], test[2], test[3]);
1237  }
1238  }
1239 }
Logger * logger
Definition: logger.cpp:88
#define mglGetIntegerv(...)
Definition: mgl.hpp:94
void log(const char *const log_text,...)
Definition: logger.cpp:264

◆ enableTexturingAndBlending()

void ModernOpenGLGraphics::enableTexturingAndBlending ( )
protected

Definition at line 1030 of file modernopenglgraphics.cpp.

References Graphics::mAlpha, mDrawTypeUniform, mglEnable, and mTextureDraw.

Referenced by drawImageInline(), drawPatternInline(), drawRescaledImage(), drawRescaledPattern(), drawTileCollection(), and drawTileVertexes().

1031 {
1032  if (!mTextureDraw)
1033  {
1034  mTextureDraw = true;
1035  mglUniform1f(mDrawTypeUniform, 1.0f);
1036  }
1037  if (!mAlpha)
1038  {
1039  mglEnable(GL_BLEND);
1040  mAlpha = true;
1041  }
1042 }
bool mAlpha
Definition: graphics.h:537
#define mglEnable(...)
Definition: mgl.hpp:90

◆ endDraw()

void ModernOpenGLGraphics::endDraw ( )
virtual

Deinitializes drawing. Called by the Gui when a Gui::draw() is done. done. It should reset any state changes made by beginDraw().

NOTE: You will never need to call this function yourself, unless you use a Graphics object outside of Guichan.

See also
beginDraw, Gui::draw

Reimplemented from Graphics.

Definition at line 897 of file modernopenglgraphics.cpp.

References popClipArea().

898 {
899  popClipArea();
900 }

◆ fillRectangle()

void ModernOpenGLGraphics::fillRectangle ( const Rect rect)
virtual

Implements Graphics.

Definition at line 1001 of file modernopenglgraphics.cpp.

References bindArrayBufferAndAttributes(), disableTexturingAndBlending(), GL_ARRAY_BUFFER, GL_STREAM_DRAW, graphicsManager, GraphicsManager::logError(), Graphics::mClipStack, mglDrawArrays, mVbo, MStack< T >::top(), Rect::x, ClipRect::xOffset, and ClipRect::yOffset.

1002 {
1005  const ClipRect &clipArea = mClipStack.top();
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;
1010  GLint vertices[] =
1011  {
1012  x1, y1, 0, 0,
1013  x2, y1, 0, 0,
1014  x1, y2, 0, 0,
1015  x2, y2, 0, 0
1016  };
1017 
1018 // logger->log("allocate: %d, %ld", mVboBinded, sizeof(vertices));
1019  mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
1020  vertices, GL_STREAM_DRAW);
1021 #ifdef DEBUG_DRAW_CALLS
1022  mDrawCalls ++;
1023 #endif // DEBUG_DRAW_CALLS
1024  mglDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
1025 #ifdef OPENGLERRORS
1027 #endif // OPENGLERRORS
1028 }
int width
Definition: rect.h:218
#define GL_ARRAY_BUFFER
Definition: mgldefines.h:83
int yOffset
Definition: cliprect.h:126
int x
Definition: rect.h:208
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
int xOffset
Definition: cliprect.h:121
int y
Definition: rect.h:213
#define GL_STREAM_DRAW
Definition: mgldefines.h:88
#define mglDrawArrays(...)
Definition: mgl.hpp:82
int height
Definition: rect.h:223
static void logError()
MStack< ClipRect > mClipStack
Definition: graphics.h:520
T & top() const
Definition: mstack.h:72
GraphicsManager graphicsManager

◆ finalize() [1/2]

void ModernOpenGLGraphics::finalize ( ImageCollection *const  col)
virtual

Reimplemented from Graphics.

Definition at line 1280 of file modernopenglgraphics.cpp.

References FOR_EACH.

1282 {
1283  if (col == nullptr)
1284  return;
1285  FOR_EACH (ImageCollectionIter, it, col->draws)
1286  finalize(*it);
1287 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
ImageVertexesVector::iterator ImageCollectionIter
Definition: imagevertexes.h:56
ImageVertexesVector draws
void finalize(ImageCollection *const col)

◆ finalize() [2/2]

void ModernOpenGLGraphics::finalize ( ImageVertexes *const  vert)
virtual

Reimplemented from Graphics.

Definition at line 1289 of file modernopenglgraphics.cpp.

References bindArrayBuffer(), CAST_S32, GL_ARRAY_BUFFER, GL_STATIC_DRAW, OpenGLGraphicsVertexes::mIntTexPool, OpenGLGraphicsVertexes::mVbo, and OpenGLGraphicsVertexes::mVp.

1291 {
1292  // in future need convert in each switchVp/continueVp
1293 
1294  if (vert == nullptr)
1295  return;
1296  OpenGLGraphicsVertexes &ogl = vert->ogl;
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();
1300  STD_VECTOR<GLint*> &intTexPool = ogl.mIntTexPool;
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;
1305 
1306  const int sz = CAST_S32(intTexPool.size());
1307  if (sz == 0)
1308  return;
1309  vbos.resize(sz);
1310  mglGenBuffers(sz, &vbos[0]);
1311 /*
1312  for (int f = 0; f < sz; f ++)
1313  logger->log("gen buffers: %u", vbos[f]);
1314 */
1315 
1316  for (ft = intTexPool.begin(), ivp = vp.begin(), ivbo = vbos.begin();
1317  ft != ft_end && ivp != ivp_end;
1318  ++ ft, ++ ivp, ++ ivbo)
1319  {
1320  bindArrayBuffer(*ivbo);
1321 /*
1322  logger->log("allocate: %d, %ld", mVboBinded,
1323  (*ivp) * sizeof(GLint));
1324 */
1325  mglBufferData(GL_ARRAY_BUFFER, (*ivp) * sizeof(GLint),
1326  *ft, GL_STATIC_DRAW);
1327  }
1328 
1329  for (STD_VECTOR<GLint*>::iterator it = intTexPool.begin();
1330  it != intTexPool.end(); ++ it)
1331  {
1332  delete [] (*it);
1333  }
1334  intTexPool.clear();
1335 }
std::vector< GLuint > mVbo
#define GL_ARRAY_BUFFER
Definition: mgldefines.h:83
void bindArrayBuffer(const GLuint vbo) A_INLINE
#define CAST_S32
Definition: cast.h:29
#define GL_STATIC_DRAW
Definition: mgldefines.h:89
std::vector< GLint * > mIntTexPool
OpenGLGraphicsVertexes ogl
Definition: imagevertexes.h:49

◆ getMemoryUsage()

int ModernOpenGLGraphics::getMemoryUsage ( )

◆ initArrays()

void ModernOpenGLGraphics::initArrays ( const int  vertCount)
virtual

Reimplemented from Graphics.

Definition at line 143 of file modernopenglgraphics.cpp.

References mIntArray, mIntArrayCached, mMaxVertices, and vertexBufSize.

144 {
145  mMaxVertices = vertCount;
146  if (mMaxVertices < 500)
147  mMaxVertices = 500;
148  else if (mMaxVertices > 1024)
149  mMaxVertices = 1024;
150 
151  // need alocate small size, after if limit reached reallocate to double size
152  const size_t sz = mMaxVertices * 4 + 30;
154  if (mIntArray == nullptr)
155  mIntArray = new GLint[sz];
156  if (mIntArrayCached == nullptr)
157  mIntArrayCached = new GLint[sz];
158 }
unsigned int vertexBufSize

◆ isAllowScale()

bool ModernOpenGLGraphics::isAllowScale ( ) const
inlinevirtual

Reimplemented from Graphics.

Definition at line 40 of file modernopenglgraphics.h.

56  : public Graphics

◆ popClipArea()

void ModernOpenGLGraphics::popClipArea ( )
virtual

Removes the top most clip area from the stack.

Exceptions
Exceptionif the stack is empty.

Reimplemented from Graphics.

Definition at line 913 of file modernopenglgraphics.cpp.

References MStack< T >::empty(), Rect::height, Graphics::mClipStack, mglScissor, Graphics::mRect, Graphics::mScale, Graphics::popClipArea(), MStack< T >::top(), Rect::width, Rect::x, and Rect::y.

Referenced by endDraw().

914 {
915  if (mClipStack.empty())
916  return;
918  if (mClipStack.empty())
919  return;
920 
921  const ClipRect &clipArea = mClipStack.top();
922  mglScissor(clipArea.x * mScale,
923  (mRect.h - clipArea.y - clipArea.height) * mScale,
924  clipArea.width * mScale,
925  clipArea.height * mScale);
926 }
int width
Definition: rect.h:218
virtual void popClipArea()
Definition: graphics.cpp:738
#define mglScissor(...)
Definition: mgl.hpp:88
int x
Definition: rect.h:208
int y
Definition: rect.h:213
int height
Definition: rect.h:223
SDL_Rect mRect
Definition: graphics.h:542
int mScale
Definition: graphics.h:551
MStack< ClipRect > mClipStack
Definition: graphics.h:520
T & top() const
Definition: mstack.h:72
bool empty() const
Definition: mstack.h:87

◆ postInit()

void ModernOpenGLGraphics::postInit ( )
virtual

Reimplemented from Graphics.

Definition at line 160 of file modernopenglgraphics.cpp.

References bindArrayBuffer(), bindElementBuffer(), Logger::error(), ShaderProgram::getProgramId(), ShadersManager::getSimpleProgram(), graphicsManager, Logger::log(), GraphicsManager::logError(), logger, mAttributesBinded, mDrawTypeUniform, mEbo, Graphics::mHeight, mPosAttrib, mProgram, mProgramId, mScreenUniform, mSimpleColorUniform, mTextureColorUniform, mVao, mVbo, Graphics::mWidth, Logger::safeError(), and shaders.

Referenced by screenResized().

161 {
162  mglGenVertexArrays(1, &mVao);
163  mglBindVertexArray(mVao);
164  mglGenBuffers(1, &mVbo);
165 // logger->log("gen vbo buffer: %u", mVbo);
167  mglGenBuffers(1, &mEbo);
168 // logger->log("gen ebo buffer: %u", mEbo);
170 
171  logger->log("Compiling shaders");
173  if (mProgram == nullptr)
174  {
176  logger->safeError("Shader creation error. See manaplus.log.");
177  }
179  if (mProgramId == 0u)
180  logger->error("Shaders compilation error.");
181 
182  logger->log("Shaders compilation done.");
183  mglUseProgram(mProgramId);
184 
185  mPosAttrib = mglGetAttribLocation(mProgramId, "position");
186  mglEnableVertexAttribArray(mPosAttrib);
187  mglVertexAttribIFormat(mPosAttrib, 4, GL_INT, 0);
188 
189  mSimpleColorUniform = mglGetUniformLocation(mProgramId, "color");
190  mScreenUniform = mglGetUniformLocation(mProgramId, "screen");
191  mDrawTypeUniform = mglGetUniformLocation(mProgramId, "drawType");
192  mTextureColorUniform = mglGetUniformLocation(mProgramId, "alpha");
193 
194  mglUniform1f(mTextureColorUniform, 1.0f);
195 
196  mglBindVertexBuffer(0, mVbo, 0, 4 * sizeof(GLint));
197  mglVertexAttribBinding(mPosAttrib, 0);
198 // mglVertexAttribIPointer(mPosAttrib, 4, GL_INT, 4 * sizeof(GLint), 0);
200 
201  mglUniform2f(mScreenUniform,
202  static_cast<float>(mWidth) / 2.0f,
203  static_cast<float>(mHeight) / 2.0f);
204  mglUniform4f(mSimpleColorUniform,
205  0.0F,
206  0.0F,
207  0.0F,
208  0.0F);
209 }
void bindElementBuffer(const GLuint ebo) A_INLINE
void bindArrayBuffer(const GLuint vbo) A_INLINE
int mWidth
Definition: graphics.h:483
unsigned int getProgramId() const
Definition: shaderprogram.h:41
Logger * logger
Definition: logger.cpp:88
void safeError(const std::string &error_text) __attribute__((noreturn))
Definition: logger.cpp:430
int mHeight
Definition: graphics.h:484
ShadersManager shaders
static void logError()
void error(const std::string &error_text) __attribute__((noreturn))
Definition: logger.cpp:467
void log(const char *const log_text,...)
Definition: logger.cpp:264
GraphicsManager graphicsManager
ShaderProgram * getSimpleProgram()

◆ pushClipArea()

void ModernOpenGLGraphics::pushClipArea ( const Rect area)
virtual

Pushes a clip area onto the stack. The x and y coordinates in the rectangle is relative to the last pushed clip area. If the new area falls outside the current clip area, it will be clipped as necessary.

If a clip area is outside of the top clip area a clip area with zero width and height will be pushed.

Parameters
areaThe clip area to be pushed onto the stack.

Reimplemented from Graphics.

Definition at line 902 of file modernopenglgraphics.cpp.

References Rect::height, Graphics::mClipStack, mglScissor, Graphics::mRect, Graphics::mScale, Graphics::pushClipArea(), MStack< T >::top(), Rect::width, Rect::x, and Rect::y.

Referenced by beginDraw().

903 {
905  const ClipRect &clipArea = mClipStack.top();
906 
907  mglScissor(clipArea.x * mScale,
908  (mRect.h - clipArea.y - clipArea.height) * mScale,
909  clipArea.width * mScale,
910  clipArea.height * mScale);
911 }
int width
Definition: rect.h:218
#define mglScissor(...)
Definition: mgl.hpp:88
int x
Definition: rect.h:208
int y
Definition: rect.h:213
int height
Definition: rect.h:223
SDL_Rect mRect
Definition: graphics.h:542
int mScale
Definition: graphics.h:551
MStack< ClipRect > mClipStack
Definition: graphics.h:520
virtual void pushClipArea(const Rect &area)
Definition: graphics.cpp:676
T & top() const
Definition: mstack.h:72

◆ removeArray()

void ModernOpenGLGraphics::removeArray ( const uint32_t  id,
uint32_t *const  arr 
)
virtual

Reimplemented from Graphics.

Definition at line 1140 of file modernopenglgraphics.cpp.

References mVboBinded.

1142 {
1143  mglDeleteBuffers(sz, arr);
1144  for (size_t f = 0; f < sz; f ++)
1145  {
1146  if (arr[f] == mVboBinded)
1147  mVboBinded = 0;
1148 // logger->log("delete buffers: %u", arr[f]);
1149  }
1150 }

◆ restoreColor()

void ModernOpenGLGraphics::restoreColor ( )
inlineprivate

◆ screenResized()

void ModernOpenGLGraphics::screenResized ( )
virtual

Reimplemented from Graphics.

Definition at line 211 of file modernopenglgraphics.cpp.

References deleteGLObjects(), mAttributesBinded, Graphics::mColor, mEboBinded, mVboBinded, and postInit().

212 {
213  deleteGLObjects();
214  mVboBinded = 0U;
215  mEboBinded = 0U;
216  mAttributesBinded = 0U;
217  mColor = Color(0, 0, 0, 0);
218  postInit();
219 }
Color mColor
Definition: graphics.h:552
Definition: color.h:74

◆ setColor()

void ModernOpenGLGraphics::setColor ( const Color color)
virtual

Reimplemented from Graphics.

Definition at line 255 of file modernopenglgraphics.cpp.

References Graphics::mColor, mColorAlpha, and mSimpleColorUniform.

256 {
257  mColorAlpha = (color.a != 255);
258  if (mColor != color)
259  {
260  mColor = color;
261  mglUniform4f(mSimpleColorUniform,
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);
266  }
267 }
unsigned int a
Definition: color.h:250
unsigned int g
Definition: color.h:239
Color mColor
Definition: graphics.h:552
unsigned int b
Definition: color.h:244
unsigned int r
Definition: color.h:234

◆ setColorAlpha()

void ModernOpenGLGraphics::setColorAlpha ( const float  alpha)
inlineprivate

Definition at line 269 of file modernopenglgraphics.cpp.

References mAlphaCached, and mTextureColorUniform.

Referenced by drawImageInline(), drawPatternInline(), drawRescaledImage(), drawRescaledPattern(), drawTileCollection(), and drawTileVertexes().

270 {
271  if (mAlphaCached != alpha)
272  {
273  mAlphaCached = alpha;
274  mglUniform1f(mTextureColorUniform, alpha);
275  }
276 }

◆ setVideoMode()

bool ModernOpenGLGraphics::setVideoMode ( 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 
)
virtual

Try to create a window with the given settings.

Implements Graphics.

Definition at line 234 of file modernopenglgraphics.cpp.

References Graphics::setMainFlags(), and Graphics::setOpenGLMode().

242 {
243  setMainFlags(w, h,
244  scale,
245  bpp,
246  fs,
247  hwaccel,
248  resize,
249  noFrame,
250  allowHighDPI);
251 
252  return setOpenGLMode();
253 }
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)
Definition: graphics.cpp:181
bool setOpenGLMode()
Definition: graphics.cpp:282

◆ testDraw()

void ModernOpenGLGraphics::testDraw ( )
virtual

Reimplemented from Graphics.

Definition at line 375 of file modernopenglgraphics.cpp.

References graphicsManager, GraphicsManager::logError(), and mglDrawArrays.

376 {
377 /*
378  GLint vertices[] =
379  {
380  0, 0, 0, 0,
381  800, 0, 800, 0,
382  0, 600, 0, 600,
383  800, 600, 800, 600
384  };
385 */
386 // logger->log("allocate: %d, %ld", mVboBinded, sizeof(vertices));
387 // logger->log("allocate ebo: %d, %ld", mEboBinded, sizeof(elements));
388 // mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
389 // vertices, GL_STREAM_DRAW);
390 // mglBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements),
391 // elements, GL_STREAM_DRAW);
392 #ifdef DEBUG_DRAW_CALLS
393  mDrawCalls ++;
394 #endif // DEBUG_DRAW_CALLS
395  mglDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
396 // glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, 0);
397 #ifdef OPENGLERRORS
399 #endif // OPENGLERRORS
400 }
#define mglDrawArrays(...)
Definition: mgl.hpp:82
static void logError()
GraphicsManager graphicsManager

◆ updateScreen()

void ModernOpenGLGraphics::updateScreen ( )
virtual

Updates the screen. This is done by either copying the buffer to the screen or swapping pages.

Implements Graphics.

Definition at line 870 of file modernopenglgraphics.cpp.

References BLOCK_END, BLOCK_START, isGLNotNull, and Graphics::mWindow.

871 {
872  BLOCK_START("Graphics::updateScreen")
873 #ifdef DEBUG_DRAW_CALLS
874  mLastDrawCalls = mDrawCalls;
875  mDrawCalls = 0;
876 #endif // DEBUG_DRAW_CALLS
877 #ifdef USE_SDL2
878  SDL_GL_SwapWindow(mWindow);
879 #else // USE_SDL2
880  SDL_GL_SwapBuffers();
881 #endif // USE_SDL2
882 #ifdef DEBUG_OPENGL
883  if (isGLNotNull(mglFrameTerminator))
884  mglFrameTerminator();
885 #endif // DEBUG_OPENGL
886  BLOCK_END("Graphics::updateScreen")
887 }
SDL_Surface * mWindow
Definition: graphics.h:522
#define isGLNotNull(func)
Definition: mglcheck.h:27
#define BLOCK_START(name)
Definition: perfomance.h:78
#define BLOCK_END(name)
Definition: perfomance.h:79

◆ updateTextureFormat()

void ModernOpenGLGraphics::updateTextureFormat ( )

Field Documentation

◆ mAlphaCached

float ModernOpenGLGraphics::mAlphaCached
private

Definition at line 130 of file modernopenglgraphics.h.

Referenced by setColorAlpha().

◆ mAttributesBinded

GLuint ModernOpenGLGraphics::mAttributesBinded
private

◆ mColorAlpha

bool ModernOpenGLGraphics::mColorAlpha
private

Definition at line 147 of file modernopenglgraphics.h.

Referenced by disableTexturingAndBlending(), and setColor().

◆ mDrawTypeUniform

GLuint ModernOpenGLGraphics::mDrawTypeUniform
private

◆ mEbo

GLuint ModernOpenGLGraphics::mEbo
private

Definition at line 143 of file modernopenglgraphics.h.

Referenced by deleteGLObjects(), and postInit().

◆ mEboBinded

GLuint ModernOpenGLGraphics::mEboBinded
private

Definition at line 145 of file modernopenglgraphics.h.

Referenced by bindElementBuffer(), and screenResized().

◆ mFbo

FBOInfo ModernOpenGLGraphics::mFbo
private

Definition at line 154 of file modernopenglgraphics.h.

◆ mFloatColor

float ModernOpenGLGraphics::mFloatColor
private

Definition at line 133 of file modernopenglgraphics.h.

◆ mIntArray

GLint* ModernOpenGLGraphics::mIntArray
private

◆ mIntArrayCached

GLint* ModernOpenGLGraphics::mIntArrayCached
private

Definition at line 128 of file modernopenglgraphics.h.

Referenced by deleteArraysInternal(), and initArrays().

◆ mMaxVertices

int ModernOpenGLGraphics::mMaxVertices
private

◆ mPosAttrib

GLint ModernOpenGLGraphics::mPosAttrib
private

Definition at line 137 of file modernopenglgraphics.h.

Referenced by postInit().

◆ mProgram

ShaderProgram* ModernOpenGLGraphics::mProgram
private

Definition at line 129 of file modernopenglgraphics.h.

Referenced by deleteGLObjects(), and postInit().

◆ mProgramId

GLuint ModernOpenGLGraphics::mProgramId
private

Definition at line 135 of file modernopenglgraphics.h.

Referenced by postInit().

◆ mScreenUniform

GLuint ModernOpenGLGraphics::mScreenUniform
private

Definition at line 139 of file modernopenglgraphics.h.

Referenced by postInit().

◆ mSimpleColorUniform

GLuint ModernOpenGLGraphics::mSimpleColorUniform
private

Definition at line 136 of file modernopenglgraphics.h.

Referenced by postInit(), and setColor().

◆ mTextureBinded

GLuint ModernOpenGLGraphics::mTextureBinded = 0
static

Definition at line 49 of file modernopenglgraphics.h.

Referenced by bindTexture().

◆ mTextureColorUniform

GLint ModernOpenGLGraphics::mTextureColorUniform
private

Definition at line 138 of file modernopenglgraphics.h.

Referenced by postInit(), and setColorAlpha().

◆ mTextureDraw

bool ModernOpenGLGraphics::mTextureDraw
private

◆ mVao

GLuint ModernOpenGLGraphics::mVao
private

Definition at line 141 of file modernopenglgraphics.h.

Referenced by deleteGLObjects(), and postInit().

◆ mVbo

GLuint ModernOpenGLGraphics::mVbo
private

◆ mVboBinded

GLuint ModernOpenGLGraphics::mVboBinded
private

◆ mVpCached

int ModernOpenGLGraphics::mVpCached
private

Definition at line 131 of file modernopenglgraphics.h.


The documentation for this class was generated from the following files: