ManaPlus
Public 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)
 
- 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
 
virtual bool 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)=0
 
bool setFullscreen (const bool fs)
 
virtual bool resizeScreen (const int width, const int height)
 
virtual void restoreContext ()
 
virtual void drawRescaledImage (const Image *const image, int dstX, int dstY, const int desiredWidth, const int desiredHeight)=0
 
virtual void drawPattern (const Image *const image, const int x, const int y, const int w, const int h)=0
 
virtual void drawRescaledPattern (const Image *const image, const int x, const int y, const int w, const int h, const int scaledWidth, const int scaledHeight)=0
 
virtual void drawImageRect (const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0
 
virtual void calcPattern (ImageVertexes *const vert, const Image *const image, const int x, const int y, const int w, const int h) const =0
 
virtual void calcPattern (ImageCollection *const vert, const Image *const image, const int x, const int y, const int w, const int h) const =0
 
virtual void calcTileVertexes (ImageVertexes *const vert, const Image *const image, int x, int y) const =0
 
virtual void calcTileSDL (ImageVertexes *const vert, int x, int y) const
 
virtual void drawTileVertexes (const ImageVertexes *const vert)=0
 
virtual void drawTileCollection (const ImageCollection *const vertCol)=0
 
virtual void calcTileCollection (ImageCollection *const vertCol, const Image *const image, int x, int y)=0
 
virtual void calcWindow (ImageCollection *const vertCol, const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0
 
virtual void fillRectangle (const Rect &rectangle)=0
 
virtual void updateScreen ()=0
 
void setWindowSize (const int width, const int height)
 
int getWidth () const
 
int getHeight () const
 
int getMemoryUsage () const
 
virtual void drawNet (const int x1, const int y1, const int x2, const int y2, const int width, const int height)
 
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
 
virtual void initArrays (const int vertCount)
 
const ColorgetColor () const
 
virtual void drawImage (const Image *const image, int dstX, int dstY)=0
 
virtual void copyImage (const Image *const image, int dstX, int dstY)=0
 
virtual void drawImageCached (const Image *const image, int srcX, int srcY)=0
 
virtual void drawPatternCached (const Image *const image, const int x, const int y, const int w, const int h)=0
 
virtual void completeCache ()=0
 
int getScale () const
 
virtual bool isAllowScale () const
 
void setScale (int scale)
 
virtual void pushClipArea (const Rect &area)
 
virtual void popClipArea ()
 
virtual void drawLine (int x1, int y1, int x2, int y2)=0
 
virtual void drawRectangle (const Rect &rectangle)=0
 
virtual void drawPoint (int x, int y)=0
 
virtual void beginDraw ()
 
virtual void endDraw ()
 
virtual void clearScreen () const
 
virtual void deleteArrays ()
 

Private Member Functions

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 }
 
- Static Public Member Functions inherited from Graphics
static void cleanUp ()
 
- Data Fields inherited from Graphics
int mWidth
 
int mHeight
 
int mActualWidth
 
int mActualHeight
 
- 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 ()
 
- 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 65 of file modernopenglgraphics.h.

Constructor & Destructor Documentation

◆ ModernOpenGLGraphics()

ModernOpenGLGraphics::ModernOpenGLGraphics ( )

Definition at line 90 of file modernopenglgraphics.cpp.

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

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

◆ ~ModernOpenGLGraphics()

ModernOpenGLGraphics::~ModernOpenGLGraphics ( )

Definition at line 122 of file modernopenglgraphics.cpp.

123 {
125  deleteGLObjects();
126 }
void deleteArraysInternal() restrict2

References deleteArraysInternal(), and deleteGLObjects().

Member Function Documentation

◆ bindArrayBuffer()

void ModernOpenGLGraphics::bindArrayBuffer ( const GLuint  vbo)
inlineprivate

Definition at line 1154 of file modernopenglgraphics.cpp.

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

References GL_ARRAY_BUFFER.

Referenced by postInit().

◆ bindArrayBufferAndAttributes()

void ModernOpenGLGraphics::bindArrayBufferAndAttributes ( const GLuint  vbo)
inlineprivate

Definition at line 1183 of file modernopenglgraphics.cpp.

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

References GL_ARRAY_BUFFER.

◆ bindAttributes()

void ModernOpenGLGraphics::bindAttributes ( )
inlineprivate

Definition at line 1212 of file modernopenglgraphics.cpp.

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

References mAttributesBinded, and mVboBinded.

◆ bindElementBuffer()

void ModernOpenGLGraphics::bindElementBuffer ( const GLuint  ebo)
inlineprivate

Definition at line 1169 of file modernopenglgraphics.cpp.

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

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

Referenced by postInit().

◆ createGLContext()

void ModernOpenGLGraphics::createGLContext ( const bool  custom)
virtual

Reimplemented from Graphics.

Definition at line 1267 of file modernopenglgraphics.cpp.

1268 {
1269  if (custom)
1270  {
1271  if (mGLContext != nullptr)
1273  else
1274  mGLContext = SDL::createGLContext(mWindow, 3, 3, 0x01);
1275  }
1276  else
1277  {
1279  }
1280 }
virtual void createGLContext(const bool custom)
Definition: graphics.cpp:418
SDL_Surface * mWindow
Definition: graphics.h:523
static void * mGLContext
Definition: graphics.h:533
void makeCurrentContext(void *const context)
Definition: sdlhelper.cpp:182
void * createGLContext(SDL_Surface *const window, const int major, const int minor, const int profile)
Definition: sdlhelper.cpp:174

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

◆ deleteGLObjects()

void ModernOpenGLGraphics::deleteGLObjects ( )
private

Definition at line 128 of file modernopenglgraphics.cpp.

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

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

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

◆ drawLineArrays()

void ModernOpenGLGraphics::drawLineArrays ( const int  size)
inlineprivate

Definition at line 1368 of file modernopenglgraphics.cpp.

1369 {
1370 // logger->log("allocate: %d, %ld", mVboBinded, size * sizeof(GLint));
1371  mglBufferData(GL_ARRAY_BUFFER, size * sizeof(GLint),
1373 #ifdef DEBUG_DRAW_CALLS
1374  mDrawCalls ++;
1375 #endif // DEBUG_DRAW_CALLS
1376  mglDrawArrays(GL_LINES, 0, size / 4);
1377 #ifdef OPENGLERRORS
1379 #endif // OPENGLERRORS
1380 }
static void logError()
GraphicsManager graphicsManager
#define mglDrawArrays(...)
Definition: mgl.hpp:83
#define GL_STREAM_DRAW
Definition: mgldefines.h:89
int size()
Definition: emotedb.cpp:306

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

◆ 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 280 of file modernopenglgraphics.cpp.

286 {
287  const int texX2 = srcX + width;
288  const int texY2 = srcY + height;
289  const int x2 = dstX + width;
290  const int y2 = dstY + height;
291 
292  GLint vertices[] =
293  {
294  dstX, dstY, srcX, srcY,
295  x2, dstY, texX2, srcY,
296  dstX, y2, srcX, texY2,
297  x2, y2, texX2, texY2
298  };
299 
300 // logger->log("allocate: %d, %ld", mVboBinded, sizeof(vertices));
301  mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
302  vertices, GL_STREAM_DRAW);
303 #ifdef DEBUG_DRAW_CALLS
304  mDrawCalls ++;
305 #endif // DEBUG_DRAW_CALLS
306  mglDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
307 #ifdef OPENGLERRORS
309 #endif // OPENGLERRORS
310 }

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

◆ 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 312 of file modernopenglgraphics.cpp.

317 {
318  const int texX2 = srcX + width;
319  const int texY2 = srcY + height;
320  const int x2 = dstX + desiredWidth;
321  const int y2 = dstY + desiredHeight;
322 
323  GLint vertices[] =
324  {
325  dstX, dstY, srcX, srcY,
326  x2, dstY, texX2, srcY,
327  dstX, y2, srcX, texY2,
328  x2, y2, texX2, texY2
329  };
330 
331 // logger->log("allocate: %d, %ld", mVboBinded, sizeof(vertices));
332  mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
333  vertices, GL_STREAM_DRAW);
334 #ifdef DEBUG_DRAW_CALLS
335  mDrawCalls ++;
336 #endif // DEBUG_DRAW_CALLS
337  mglDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
338 #ifdef OPENGLERRORS
340 #endif // OPENGLERRORS
341 }

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

◆ drawTriangleArray() [1/2]

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

Definition at line 1353 of file modernopenglgraphics.cpp.

1355 {
1356 // logger->log("allocate: %d, %ld", mVboBinded, size * sizeof(GLint));
1357  mglBufferData(GL_ARRAY_BUFFER, size * sizeof(GLint),
1358  array, GL_STREAM_DRAW);
1359 #ifdef DEBUG_DRAW_CALLS
1360  mDrawCalls ++;
1361 #endif // DEBUG_DRAW_CALLS
1362  mglDrawArrays(GL_TRIANGLES, 0, size / 4);
1363 #ifdef OPENGLERRORS
1365 #endif // OPENGLERRORS
1366 }

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

◆ drawTriangleArray() [2/2]

void ModernOpenGLGraphics::drawTriangleArray ( const int  size)
inlineprivate

Definition at line 1339 of file modernopenglgraphics.cpp.

1340 {
1341 // logger->log("allocate: %d, %ld", mVboBinded, size * sizeof(GLint));
1342  mglBufferData(GL_ARRAY_BUFFER, size * sizeof(GLint),
1344 #ifdef DEBUG_DRAW_CALLS
1345  mDrawCalls ++;
1346 #endif // DEBUG_DRAW_CALLS
1347  mglDrawArrays(GL_TRIANGLES, 0, size / 4);
1348 #ifdef OPENGLERRORS
1350 #endif // OPENGLERRORS
1351 }

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

◆ finalize() [1/2]

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

Reimplemented from Graphics.

Definition at line 1282 of file modernopenglgraphics.cpp.

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

References FOR_EACH.

◆ finalize() [2/2]

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

Reimplemented from Graphics.

Definition at line 1291 of file modernopenglgraphics.cpp.

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

References CAST_S32, GL_ARRAY_BUFFER, GL_STATIC_DRAW, and ImageVertexes::ogl.

◆ postInit()

void ModernOpenGLGraphics::postInit ( )
virtual

Reimplemented from Graphics.

Definition at line 162 of file modernopenglgraphics.cpp.

163 {
164  mglGenVertexArrays(1, &mVao);
165  mglBindVertexArray(mVao);
166  mglGenBuffers(1, &mVbo);
167 // logger->log("gen vbo buffer: %u", mVbo);
169  mglGenBuffers(1, &mEbo);
170 // logger->log("gen ebo buffer: %u", mEbo);
172 
173  logger->log("Compiling shaders");
175  if (mProgram == nullptr)
176  {
178  logger->safeError("Shader creation error. See manaplus.log.");
179  }
181  if (mProgramId == 0U)
182  logger->error("Shaders compilation error.");
183 
184  logger->log("Shaders compilation done.");
185  mglUseProgram(mProgramId);
186 
187  mPosAttrib = mglGetAttribLocation(mProgramId, "position");
188  mglEnableVertexAttribArray(mPosAttrib);
189  mglVertexAttribIFormat(mPosAttrib, 4, GL_INT, 0);
190 
191  mSimpleColorUniform = mglGetUniformLocation(mProgramId, "color");
192  mScreenUniform = mglGetUniformLocation(mProgramId, "screen");
193  mDrawTypeUniform = mglGetUniformLocation(mProgramId, "drawType");
194  mTextureColorUniform = mglGetUniformLocation(mProgramId, "alpha");
195 
196  mglUniform1f(mTextureColorUniform, 1.0F);
197 
198  mglBindVertexBuffer(0, mVbo, 0, 4 * sizeof(GLint));
199  mglVertexAttribBinding(mPosAttrib, 0);
200 // mglVertexAttribIPointer(mPosAttrib, 4, GL_INT, 4 * sizeof(GLint), 0);
202 
203  mglUniform2f(mScreenUniform,
204  static_cast<float>(mWidth) / 2.0F,
205  static_cast<float>(mHeight) / 2.0F);
206  mglUniform4f(mSimpleColorUniform,
207  0.0F,
208  0.0F,
209  0.0F,
210  0.0F);
211 }
int mWidth
Definition: graphics.h:484
int mHeight
Definition: graphics.h:485
void safeError(const std::string &error_text) __attribute__((noreturn))
Definition: logger.cpp:435
void error(const std::string &error_text) __attribute__((noreturn))
Definition: logger.cpp:472
void bindElementBuffer(const GLuint ebo) A_INLINE
unsigned int getProgramId() const
Definition: shaderprogram.h:42
ShaderProgram * getSimpleProgram()
ShadersManager shaders

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().

◆ removeArray()

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

Reimplemented from Graphics.

Definition at line 1142 of file modernopenglgraphics.cpp.

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

◆ screenResized()

void ModernOpenGLGraphics::screenResized ( )
virtual

Reimplemented from Graphics.

Definition at line 213 of file modernopenglgraphics.cpp.

214 {
215  deleteGLObjects();
216  mVboBinded = 0U;
217  mEboBinded = 0U;
218  mAttributesBinded = 0U;
219  mColor = Color(0, 0, 0, 0);
220  postInit();
221 }
Definition: color.h:76
Color mColor
Definition: graphics.h:553

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

◆ setColor()

void ModernOpenGLGraphics::setColor ( const Color color)
virtual

Reimplemented from Graphics.

Definition at line 257 of file modernopenglgraphics.cpp.

258 {
259  mColorAlpha = (color.a != 255);
260  if (mColor != color)
261  {
262  mColor = color;
263  mglUniform4f(mSimpleColorUniform,
264  static_cast<float>(color.r) / 255.0F,
265  static_cast<float>(color.g) / 255.0F,
266  static_cast<float>(color.b) / 255.0F,
267  static_cast<float>(color.a) / 255.0F);
268  }
269 }
unsigned int a
Definition: color.h:251
unsigned int b
Definition: color.h:245
unsigned int r
Definition: color.h:235
unsigned int g
Definition: color.h:240

◆ testDraw()

void ModernOpenGLGraphics::testDraw ( )
virtual

Reimplemented from Graphics.

Definition at line 377 of file modernopenglgraphics.cpp.

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

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

Field Documentation

◆ mAlphaCached

float ModernOpenGLGraphics::mAlphaCached
private

Definition at line 139 of file modernopenglgraphics.h.

◆ mAttributesBinded

GLuint ModernOpenGLGraphics::mAttributesBinded
private

Definition at line 155 of file modernopenglgraphics.h.

Referenced by bindAttributes(), postInit(), and screenResized().

◆ mColorAlpha

bool ModernOpenGLGraphics::mColorAlpha
private

Definition at line 156 of file modernopenglgraphics.h.

◆ mDrawTypeUniform

GLuint ModernOpenGLGraphics::mDrawTypeUniform
private

Definition at line 149 of file modernopenglgraphics.h.

Referenced by postInit().

◆ mEbo

GLuint ModernOpenGLGraphics::mEbo
private

Definition at line 152 of file modernopenglgraphics.h.

Referenced by deleteGLObjects(), and postInit().

◆ mEboBinded

GLuint ModernOpenGLGraphics::mEboBinded
private

Definition at line 154 of file modernopenglgraphics.h.

Referenced by screenResized().

◆ mFbo

FBOInfo ModernOpenGLGraphics::mFbo
private

Definition at line 163 of file modernopenglgraphics.h.

◆ mFloatColor

float ModernOpenGLGraphics::mFloatColor
private

Definition at line 142 of file modernopenglgraphics.h.

◆ mIntArray

GLint* ModernOpenGLGraphics::mIntArray
private

Definition at line 136 of file modernopenglgraphics.h.

Referenced by drawLineArrays().

◆ mIntArrayCached

GLint* ModernOpenGLGraphics::mIntArrayCached
private

Definition at line 137 of file modernopenglgraphics.h.

◆ mMaxVertices

int ModernOpenGLGraphics::mMaxVertices
private

Definition at line 143 of file modernopenglgraphics.h.

◆ mPosAttrib

GLint ModernOpenGLGraphics::mPosAttrib
private

Definition at line 146 of file modernopenglgraphics.h.

Referenced by postInit().

◆ mProgram

ShaderProgram* ModernOpenGLGraphics::mProgram
private

Definition at line 138 of file modernopenglgraphics.h.

Referenced by deleteGLObjects(), and postInit().

◆ mProgramId

GLuint ModernOpenGLGraphics::mProgramId
private

Definition at line 144 of file modernopenglgraphics.h.

Referenced by postInit().

◆ mScreenUniform

GLuint ModernOpenGLGraphics::mScreenUniform
private

Definition at line 148 of file modernopenglgraphics.h.

Referenced by postInit().

◆ mSimpleColorUniform

GLuint ModernOpenGLGraphics::mSimpleColorUniform
private

Definition at line 145 of file modernopenglgraphics.h.

Referenced by postInit().

◆ mTextureColorUniform

GLint ModernOpenGLGraphics::mTextureColorUniform
private

Definition at line 147 of file modernopenglgraphics.h.

Referenced by postInit().

◆ mTextureDraw

bool ModernOpenGLGraphics::mTextureDraw
private

Definition at line 157 of file modernopenglgraphics.h.

◆ mVao

GLuint ModernOpenGLGraphics::mVao
private

Definition at line 150 of file modernopenglgraphics.h.

Referenced by deleteGLObjects(), and postInit().

◆ mVbo

GLuint ModernOpenGLGraphics::mVbo
private

Definition at line 151 of file modernopenglgraphics.h.

Referenced by deleteGLObjects(), and postInit().

◆ mVboBinded

GLuint ModernOpenGLGraphics::mVboBinded
private

Definition at line 153 of file modernopenglgraphics.h.

Referenced by bindAttributes(), and screenResized().

◆ mVpCached

int ModernOpenGLGraphics::mVpCached
private

Definition at line 140 of file modernopenglgraphics.h.


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