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

#include <mobileopengl2graphics.h>

Inheritance diagram for MobileOpenGL2Graphics:
Graphics

Public Member Functions

 MobileOpenGL2Graphics ()
 
 ~MobileOpenGL2Graphics ()
 
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 = 0U
 

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 GLfloat *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
 

Static Private Member Functions

static void bindTexture2 (const GLenum target, const Image *const image)
 

Private Attributes

GLfloat * mFloatArray
 
GLfloat * mFloatArrayCached
 
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 mVboBinded
 
GLuint mAttributesBinded
 
bool mColorAlpha
 
bool mTextureDraw
 
FBOInfo mFbo
 

Static Private Attributes

static GLuint mTextureSizeUniform = 0U
 
static int mTextureWidth = 1
 
static int mTextureHeight = 1
 

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 mobileopengl2graphics.h.

Constructor & Destructor Documentation

◆ MobileOpenGL2Graphics()

MobileOpenGL2Graphics::MobileOpenGL2Graphics ( )

Definition at line 91 of file mobileopengl2graphics.cpp.

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

91  :
92  mFloatArray(nullptr),
93  mFloatArrayCached(nullptr),
94  mProgram(nullptr),
95  mAlphaCached(1.0F),
96  mVpCached(0),
97  mFloatColor(1.0F),
98  mMaxVertices(500),
99  mProgramId(0U),
101  mPosAttrib(0),
103  mScreenUniform(0U),
104  mDrawTypeUniform(0U),
105 #ifndef __native_client__
106  mVao(0U),
107 #endif // __native_client__
108  mVbo(0U),
109  mVboBinded(0U),
110  mAttributesBinded(0U),
111  mColorAlpha(false),
112  mTextureDraw(false),
113 #ifdef DEBUG_BIND_TEXTURE
114  mOldTexture(),
115  mOldTextureId(0),
116 #endif // DEBUG_BIND_TEXTURE
117  mFbo()
118 {
120  mName = "mobile OpenGL ES 2";
121 }
std::string mName
Definition: graphics.h:548
RenderType mOpenGL
Definition: graphics.h:544

◆ ~MobileOpenGL2Graphics()

MobileOpenGL2Graphics::~MobileOpenGL2Graphics ( )

Member Function Documentation

◆ beginDraw()

void MobileOpenGL2Graphics::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 901 of file mobileopengl2graphics.cpp.

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

902 {
903  setOpenGLFlags();
904 #ifndef __native_client__
905  mglDisable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB);
906  mglHint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB, GL_FASTEST);
907 #endif // __native_client__
908  pushClipArea(Rect(0, 0, mRect.w, mRect.h));
909 }
#define mglHint(...)
Definition: mgl.hpp:86
Definition: rect.h:72
SDL_Rect mRect
Definition: graphics.h:542
void setOpenGLFlags()
Definition: graphics.cpp:747
void pushClipArea(const Rect &area)
#define mglDisable(...)
Definition: mgl.hpp:84

◆ bindArrayBuffer()

void MobileOpenGL2Graphics::bindArrayBuffer ( const GLuint  vbo)
inlineprivate

Definition at line 1185 of file mobileopengl2graphics.cpp.

References GL_ARRAY_BUFFER, mAttributesBinded, and mVboBinded.

Referenced by finalize(), and postInit().

1186 {
1187  if (mVboBinded != vbo)
1188  {
1189  mVboBinded = vbo;
1190  mglBindBuffer(GL_ARRAY_BUFFER, vbo);
1191  mAttributesBinded = 0U;
1192  }
1193 }
#define GL_ARRAY_BUFFER
Definition: mgldefines.h:83

◆ bindArrayBufferAndAttributes()

void MobileOpenGL2Graphics::bindArrayBufferAndAttributes ( const GLuint  vbo)
inlineprivate

Definition at line 1195 of file mobileopengl2graphics.cpp.

References GL_ARRAY_BUFFER, mAttributesBinded, and mVboBinded.

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

1197 {
1198  if (mVboBinded != vbo)
1199  {
1200  mVboBinded = vbo;
1201  mglBindBuffer(GL_ARRAY_BUFFER, vbo);
1202 
1204  mglVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
1205  }
1206  else if (mAttributesBinded != mVboBinded)
1207  {
1209  mglVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
1210  }
1211 }
#define GL_ARRAY_BUFFER
Definition: mgldefines.h:83

◆ bindAttributes()

void MobileOpenGL2Graphics::bindAttributes ( )
inlineprivate

Definition at line 1213 of file mobileopengl2graphics.cpp.

References mAttributesBinded, and mVboBinded.

1214 {
1216  {
1218  mglVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
1219  }
1220 }

◆ bindTexture()

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

Definition at line 1163 of file mobileopengl2graphics.cpp.

References mglBindTexture, and mTextureBinded.

Referenced by OpenGLImageHelper::bindTexture(), and SafeOpenGLImageHelper::bindTexture().

1165 {
1166  if (mTextureBinded != texture)
1167  {
1168  // for safty not storing textures because cant update size uniform
1169  mTextureBinded = 0;
1170  mglBindTexture(target, texture);
1171  }
1172 }
#define mglBindTexture(...)
Definition: mgl.hpp:92

◆ bindTexture2()

void MobileOpenGL2Graphics::bindTexture2 ( const GLenum  target,
const Image *const  image 
)
staticprivate

Definition at line 1143 of file mobileopengl2graphics.cpp.

References mglBindTexture, mTextureBinded, mTextureHeight, mTextureSizeUniform, and mTextureWidth.

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

1145 {
1146  const GLuint texture = image->mGLImage;
1147  if (mTextureBinded != texture)
1148  {
1149  mTextureBinded = texture;
1150  mglBindTexture(target, texture);
1151  if (mTextureWidth != image->mTexWidth ||
1152  mTextureHeight != image->mTexHeight)
1153  {
1154  mTextureWidth = image->mTexWidth;
1155  mTextureHeight = image->mTexHeight;
1156  mglUniform2f(mTextureSizeUniform,
1157  static_cast<GLfloat>(image->mTexWidth),
1158  static_cast<GLfloat>(image->mTexHeight));
1159  }
1160  }
1161 }
#define mglBindTexture(...)
Definition: mgl.hpp:92
int mTexHeight
Definition: image.h:184
GLuint mGLImage
Definition: image.h:182
int mTexWidth
Definition: image.h:183

◆ calcImageRect()

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

Definition at line 1250 of file mobileopengl2graphics.cpp.

Referenced by calcWindow().

◆ calcPattern() [1/2]

void MobileOpenGL2Graphics::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 636 of file mobileopengl2graphics.cpp.

References calcPatternInline(), x, and y.

642 {
643  calcPatternInline(vert, image, x, y, w, h);
644 }
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 MobileOpenGL2Graphics::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 754 of file mobileopengl2graphics.cpp.

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

761 {
762  if (vertCol == nullptr || image == nullptr)
763  return;
764  ImageVertexes *vert = nullptr;
765  if (vertCol->currentGLImage != image->mGLImage)
766  {
767  vert = new ImageVertexes;
768  vertCol->currentGLImage = image->mGLImage;
769  vertCol->currentVert = vert;
770  vert->image = image;
771  vertCol->draws.push_back(vert);
772  }
773  else
774  {
775  vert = vertCol->currentVert;
776  }
777 
778  calcPatternInline(vert, image, x, y, w, h);
779 }
void calcPatternInline(ImageVertexes *const vert, const Image *const image, const int x, const int y, const int w, const int h) const A_INLINE
const Image * image
Definition: imagevertexes.h:47
GLuint mGLImage
Definition: image.h:182

◆ calcPatternInline()

void MobileOpenGL2Graphics::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 646 of file mobileopengl2graphics.cpp.

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

Referenced by calcPattern().

654 {
655  if (image == nullptr || vert == nullptr)
656  return;
657 
658  const SDL_Rect &imageRect = image->mBounds;
659  const int iw = imageRect.w;
660  const int ih = imageRect.h;
661 
662  if (iw == 0 || ih == 0)
663  return;
664 
665  const int srcX = imageRect.x;
666  const int srcY = imageRect.y;
667  const GLfloat srcX2 = toGL(srcX);
668  const GLfloat srcY2 = toGL(srcY);
669 
670  const ClipRect &clipArea = mClipStack.top();
671  const int x2 = x + clipArea.xOffset;
672  const int y2 = y + clipArea.yOffset;
673 
674  const unsigned int vLimit = mMaxVertices * 4;
675 
676  OpenGLGraphicsVertexes &ogl = vert->ogl;
677  unsigned int vp = ogl.continueVp();
678 
679  GLfloat *floatArray = ogl.continueFloatTexArray();
680 
681  for (int py = 0; py < h; py += ih)
682  {
683  const GLfloat height = static_cast<GLfloat>(
684  (py + ih >= h) ? h - py : ih);
685  const GLfloat dstY = static_cast<GLfloat>(y2 + py);
686  const GLfloat texY2 = srcY + height;
687  for (int px = 0; px < w; px += iw)
688  {
689  const GLfloat width = static_cast<GLfloat>(
690  (px + iw >= w) ? w - px : iw);
691  const GLfloat dstX = static_cast<GLfloat>(x2 + px);
692  const GLfloat texX2 = srcX2 + width;
693 
694  vertFill2D(floatArray,
695  srcX2, srcY2, texX2, texY2,
696  dstX, dstY, width, height);
697 
698  vp += 24;
699  if (vp >= vLimit)
700  {
701  floatArray = ogl.switchFloatTexArray();
702  ogl.switchVp(vp);
703  vp = 0;
704  }
705  }
706  }
707  ogl.switchVp(vp);
708 }
#define toGL
int yOffset
Definition: cliprect.h:126
#define vertFill2D(var, x1, y1, x2, y2, dstX, dstY, w, h)
int xOffset
Definition: cliprect.h:121
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 MobileOpenGL2Graphics::calcTileCollection ( ImageCollection *const  vertCol,
const Image *const  image,
int  x,
int  y 
)
virtual

Implements Graphics.

Definition at line 710 of file mobileopengl2graphics.cpp.

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

715 {
716  if (vertCol == nullptr || image == nullptr)
717  return;
718  if (vertCol->currentGLImage != image->mGLImage)
719  {
720  ImageVertexes *const vert = new ImageVertexes;
721  vertCol->currentGLImage = image->mGLImage;
722  vertCol->currentVert = vert;
723  vert->image = image;
724  vertCol->draws.push_back(vert);
725  calcTileVertexesInline(vert, image, x, y);
726  }
727  else
728  {
729  calcTileVertexesInline(vertCol->currentVert, image, x, y);
730  }
731 }
const Image * image
Definition: imagevertexes.h:47
ImageVertexesVector draws
ImageVertexes * currentVert
GLuint mGLImage
Definition: image.h:182
void calcTileVertexesInline(ImageVertexes *const vert, const Image *const image, int x, int y) const A_INLINE

◆ calcTileVertexes()

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

Implements Graphics.

Definition at line 781 of file mobileopengl2graphics.cpp.

References calcTileVertexesInline().

786 {
787  calcTileVertexesInline(vert, image, dstX, dstY);
788 }
void calcTileVertexesInline(ImageVertexes *const vert, const Image *const image, int x, int y) const A_INLINE

◆ calcTileVertexesInline()

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

Definition at line 790 of file mobileopengl2graphics.cpp.

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

Referenced by calcTileCollection(), and calcTileVertexes().

796 {
797  const SDL_Rect &imageRect = image->mBounds;
798  const int w = imageRect.w;
799  const int h = imageRect.h;
800 
801  if (w == 0 || h == 0)
802  return;
803 
804  const int srcX = imageRect.x;
805  const int srcY = imageRect.y;
806  const GLfloat srcX2 = toGL(srcX);
807  const GLfloat srcY2 = toGL(srcY);
808 
809  const ClipRect &clipArea = mClipStack.top();
810  const GLfloat x2 = static_cast<GLfloat>(dstX + clipArea.xOffset);
811  const GLfloat y2 = static_cast<GLfloat>(dstY + clipArea.yOffset);
812 
813  const unsigned int vLimit = mMaxVertices * 4;
814 
815  OpenGLGraphicsVertexes &ogl = vert->ogl;
816 
817  unsigned int vp = ogl.continueVp();
818 
819  GLfloat texX2 = static_cast<GLfloat>(srcX + w);
820  GLfloat texY2 = static_cast<GLfloat>(srcY + h);
821 
822  GLfloat *const floatArray = ogl.continueFloatTexArray();
823 
824  vertFill2D(floatArray,
825  srcX2, srcY2, texX2, texY2,
826  x2, y2, w, h);
827 
828  vp += 24;
829  if (vp >= vLimit)
830  {
831  ogl.switchFloatTexArray();
832  ogl.switchVp(vp);
833  vp = 0;
834  }
835 
836  ogl.switchVp(vp);
837 }
#define toGL
int yOffset
Definition: cliprect.h:126
#define vertFill2D(var, x1, y1, x2, y2, dstX, dstY, w, h)
int xOffset
Definition: cliprect.h:121
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 MobileOpenGL2Graphics::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 857 of file mobileopengl2graphics.cpp.

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

862 {
863  ImageVertexes *vert = nullptr;
864  const Image *const image = imgRect.grid[4];
865  if (image == nullptr)
866  return;
867  if (vertCol->currentGLImage != image->mGLImage)
868  {
869  vert = new ImageVertexes;
870  vertCol->currentGLImage = image->mGLImage;
871  vertCol->currentVert = vert;
872  vert->image = image;
873  vertCol->draws.push_back(vert);
874  }
875  else
876  {
877  vert = vertCol->currentVert;
878  }
879  calcImageRect(vert, x, y, w, h, imgRect);
880 }
const Image * image
Definition: imagevertexes.h:47
ImageVertexesVector draws
ImageVertexes * currentVert
Image * grid[9]
Definition: imagerect.h:41
void calcImageRect(ImageVertexes *const vert, int x, int y, int w, int h, const ImageRect &imgRect) A_INLINE
GLuint mGLImage
Definition: image.h:182
Definition: image.h:61

◆ clearScreen()

void MobileOpenGL2Graphics::clearScreen ( ) const
virtual

Reimplemented from Graphics.

Definition at line 1259 of file mobileopengl2graphics.cpp.

References mglClear.

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

◆ completeCache()

void MobileOpenGL2Graphics::completeCache ( )
virtual

Implements Graphics.

Definition at line 423 of file mobileopengl2graphics.cpp.

424 {
425 }

◆ copyImage()

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

Implements Graphics.

Definition at line 377 of file mobileopengl2graphics.cpp.

References drawImageInline().

379 {
380  drawImageInline(image, dstX, dstY);
381 }
void drawImageInline(const Image *const image, int dstX, int dstY) A_INLINE

◆ createGLContext()

void MobileOpenGL2Graphics::createGLContext ( const bool  custom)
virtual

Reimplemented from Graphics.

Definition at line 1266 of file mobileopengl2graphics.cpp.

References Graphics::createGLContext().

1267 {
1268  Graphics::createGLContext(custom);
1269 /*
1270  if (mGLContext)
1271  SDL::makeCurrentContext(mGLContext);
1272  else
1273  mGLContext = SDL::createGLContext(mWindow, 2, 0, 0x04);
1274 */
1275 }
virtual void createGLContext(const bool custom)
Definition: graphics.cpp:417

◆ debugBindTexture()

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

◆ deleteArrays()

void MobileOpenGL2Graphics::deleteArrays ( )
virtual

Reimplemented from Graphics.

Definition at line 220 of file mobileopengl2graphics.cpp.

References deleteArraysInternal().

221 {
223 }

◆ deleteArraysInternal()

void MobileOpenGL2Graphics::deleteArraysInternal ( )
protected

Definition at line 225 of file mobileopengl2graphics.cpp.

References mFloatArray, and mFloatArrayCached.

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

226 {
227  delete [] mFloatArray;
228  mFloatArray = nullptr;
229  delete [] mFloatArrayCached;
230  mFloatArrayCached = nullptr;
231 }

◆ deleteGLObjects()

void MobileOpenGL2Graphics::deleteGLObjects ( )
private

Definition at line 129 of file mobileopengl2graphics.cpp.

References delete2, mProgram, mVao, and mVbo.

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

130 {
131  delete2(mProgram);
132  if (mVbo != 0u)
133  mglDeleteBuffers(1, &mVbo);
134 #ifndef __native_client__
135  if (mVao != 0u)
136  mglDeleteVertexArrays(1, &mVao);
137 #endif // __native_client__
138 }
#define delete2(var)
Definition: delete2.h:24

◆ disableTexturingAndBlending()

void MobileOpenGL2Graphics::disableTexturingAndBlending ( )
protected

Definition at line 1054 of file mobileopengl2graphics.cpp.

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

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

1055 {
1056  if (mTextureDraw)
1057  {
1058  mTextureDraw = false;
1059  mglUniform1f(mDrawTypeUniform, 0.0f);
1060  }
1061  if (mAlpha && !mColorAlpha)
1062  {
1063  mglDisable(GL_BLEND);
1064  mAlpha = false;
1065  }
1066  else if (!mAlpha && mColorAlpha)
1067  {
1068  mglEnable(GL_BLEND);
1069  mAlpha = true;
1070  }
1071 }
bool mAlpha
Definition: graphics.h:537
#define mglDisable(...)
Definition: mgl.hpp:84
#define mglEnable(...)
Definition: mgl.hpp:90

◆ drawImage()

void MobileOpenGL2Graphics::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 346 of file mobileopengl2graphics.cpp.

References drawImageInline().

348 {
349  drawImageInline(image, dstX, dstY);
350 }
void drawImageInline(const Image *const image, int dstX, int dstY) A_INLINE

◆ drawImageCached()

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

Implements Graphics.

Definition at line 407 of file mobileopengl2graphics.cpp.

411 {
412 }

◆ drawImageInline()

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

Definition at line 352 of file mobileopengl2graphics.cpp.

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

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

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

◆ drawImageRect()

void MobileOpenGL2Graphics::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 1242 of file mobileopengl2graphics.cpp.

◆ drawLine()

void MobileOpenGL2Graphics::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 962 of file mobileopengl2graphics.cpp.

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

964 {
967  const ClipRect &clipArea = mClipStack.top();
968  GLfloat vertices[] =
969  {
970  toGL(x1 + clipArea.xOffset), toGL(y1 + clipArea.yOffset), 0.0f, 0.0f,
971  toGL(x2 + clipArea.xOffset), toGL(y2 + clipArea.yOffset), 0.0f, 0.0f
972  };
973  mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
974  vertices, GL_STREAM_DRAW);
975 #ifdef DEBUG_DRAW_CALLS
976  mDrawCalls ++;
977 #endif // DEBUG_DRAW_CALLS
978  mglDrawArrays(GL_LINES, 0, 2);
979 #ifdef OPENGLERRORS
981 #endif // OPENGLERRORS
982 }
#define GL_ARRAY_BUFFER
Definition: mgldefines.h:83
#define toGL
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
int yOffset
Definition: cliprect.h:126
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 MobileOpenGL2Graphics::drawLineArrays ( const int  size)
inlineprivate

Definition at line 1354 of file mobileopengl2graphics.cpp.

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

Referenced by drawNet().

1355 {
1356  mglBufferData(GL_ARRAY_BUFFER, size * sizeof(GLfloat),
1358 #ifdef DEBUG_DRAW_CALLS
1359  mDrawCalls ++;
1360 #endif // DEBUG_DRAW_CALLS
1361  mglDrawArrays(GL_LINES, 0, size / 4);
1362 #ifdef OPENGLERRORS
1364 #endif // OPENGLERRORS
1365 }
#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 MobileOpenGL2Graphics::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 1078 of file mobileopengl2graphics.cpp.

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

1084 {
1085  unsigned int vp = 0;
1086  const unsigned int vLimit = mMaxVertices * 4;
1087 
1090  const ClipRect &clipArea = mClipStack.top();
1091  const GLfloat dx = static_cast<GLfloat>(clipArea.xOffset);
1092  const GLfloat dy = static_cast<GLfloat>(clipArea.yOffset);
1093 
1094  const GLfloat xs1 = x1 + dx;
1095  const GLfloat xs2 = x2 + dx;
1096  const GLfloat ys1 = y1 + dy;
1097  const GLfloat ys2 = y2 + dy;
1098 
1099  for (int y = y1; y < y2; y += height)
1100  {
1101  mFloatArray[vp + 0] = xs1;
1102  mFloatArray[vp + 1] = toGL(y);
1103  mFloatArray[vp + 2] = 0.0f;
1104  mFloatArray[vp + 3] = 0.0f;
1105 
1106  mFloatArray[vp + 4] = xs2;
1107  mFloatArray[vp + 5] = toGL(y);
1108  mFloatArray[vp + 6] = 0.0f;
1109  mFloatArray[vp + 7] = 0.0f;
1110 
1111  vp += 8;
1112  if (vp >= vLimit)
1113  {
1114  drawLineArrays(vp);
1115  vp = 0;
1116  }
1117  }
1118 
1119  for (int x = x1; x < x2; x += width)
1120  {
1121  mFloatArray[vp + 0] = toGL(x);
1122  mFloatArray[vp + 1] = ys1;
1123  mFloatArray[vp + 2] = 0.0f;
1124  mFloatArray[vp + 3] = 0.0f;
1125 
1126  mFloatArray[vp + 4] = toGL(x);
1127  mFloatArray[vp + 5] = ys2;
1128  mFloatArray[vp + 6] = 0.0f;
1129  mFloatArray[vp + 7] = 0.0f;
1130 
1131  vp += 8;
1132  if (vp >= vLimit)
1133  {
1134  drawLineArrays(vp);
1135  vp = 0;
1136  }
1137  }
1138 
1139  if (vp > 0)
1140  drawLineArrays(vp);
1141 }
#define toGL
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
int yOffset
Definition: cliprect.h:126
int xOffset
Definition: cliprect.h:121
void drawLineArrays(const int size) A_INLINE
MStack< ClipRect > mClipStack
Definition: graphics.h:520
T & top() const
Definition: mstack.h:72

◆ drawPattern()

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

Implements Graphics.

Definition at line 466 of file mobileopengl2graphics.cpp.

References drawPatternInline(), x, and y.

469 {
470  drawPatternInline(image, x, y, w, h);
471 }
void drawPatternInline(const Image *const image, const int x, const int y, const int w, const int h) A_INLINE

◆ drawPatternCached()

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

Implements Graphics.

Definition at line 414 of file mobileopengl2graphics.cpp.

420 {
421 }

◆ drawPatternInline()

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

Definition at line 473 of file mobileopengl2graphics.cpp.

References bindArrayBufferAndAttributes(), bindTexture2(), debugBindTexture(), drawTriangleArray(), enableTexturingAndBlending(), Graphics::mClipStack, mFloatArray, mMaxVertices, mVbo, setColorAlpha(), toGL, MStack< T >::top(), vertFill2D, x, ClipRect::xOffset, y, and ClipRect::yOffset.

Referenced by drawPattern().

478 {
479  if (image == nullptr)
480  return;
481 
482  const SDL_Rect &imageRect = image->mBounds;
483  const int iw = imageRect.w;
484  const int ih = imageRect.h;
485 
486  if (iw == 0 || ih == 0)
487  return;
488 
489  const int srcX = imageRect.x;
490  const int srcY = imageRect.y;
491  const GLfloat srcX2 = toGL(srcX);
492  const GLfloat srcY2 = toGL(srcY);
493  const ClipRect &clipArea = mClipStack.top();
494  const int x2 = x + clipArea.xOffset;
495  const int y2 = y + clipArea.yOffset;
496 
497 #ifdef DEBUG_BIND_TEXTURE
498  debugBindTexture(image);
499 #endif // DEBUG_BIND_TEXTURE
500  bindTexture2(GL_TEXTURE_2D, image);
501 
504  setColorAlpha(image->mAlpha);
505 
506  unsigned int vp = 0;
507  const unsigned int vLimit = mMaxVertices * 4;
508 
509  for (int py = 0; py < h; py += ih)
510  {
511  const int height = (py + ih >= h) ? h - py : ih;
512  const GLfloat texY2 = static_cast<GLfloat>(srcY + height);
513  const GLfloat dstY = static_cast<GLfloat>(y2 + py);
514  for (int px = 0; px < w; px += iw)
515  {
516  const int width = (px + iw >= w) ? w - px : iw;
517  const GLfloat dstX = static_cast<GLfloat>(x2 + px);
518  const GLfloat texX2 = static_cast<GLfloat>(srcX + width);
519 
521  srcX2, srcY2, texX2, texY2,
522  dstX, dstY, width, height);
523 
524  vp += 24;
525  if (vp >= vLimit)
526  {
527  drawTriangleArray(vp);
528  vp = 0;
529  }
530  }
531  }
532  if (vp > 0)
533  drawTriangleArray(vp);
534 }
static void bindTexture2(const GLenum target, const Image *const image)
void drawTriangleArray(const int size) A_INLINE
#define toGL
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
int yOffset
Definition: cliprect.h:126
#define vertFill2D(var, x1, y1, x2, y2, dstX, dstY, w, h)
int xOffset
Definition: cliprect.h:121
void debugBindTexture(const Image *const image)
float mAlpha
Definition: image.h:212
MStack< ClipRect > mClipStack
Definition: graphics.h:520
SDL_Rect mBounds
Definition: image.h:210
T & top() const
Definition: mstack.h:72
void setColorAlpha(const float alpha) A_INLINE

◆ drawPoint()

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

Draws a single point/pixel.

Parameters
xThe x coordinate.
yThe y coordinate.

Implements Graphics.

Definition at line 942 of file mobileopengl2graphics.cpp.

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

943 {
946  const ClipRect &clipArea = mClipStack.top();
947  GLfloat vertices[] =
948  {
949  toGL(x + clipArea.xOffset), toGL(y + clipArea.yOffset), 0.0f, 0.0f
950  };
951  mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
952  vertices, GL_STREAM_DRAW);
953 #ifdef DEBUG_DRAW_CALLS
954  mDrawCalls ++;
955 #endif // DEBUG_DRAW_CALLS
956  mglDrawArrays(GL_POINTS, 0, 1);
957 #ifdef OPENGLERRORS
959 #endif // OPENGLERRORS
960 }
#define GL_ARRAY_BUFFER
Definition: mgldefines.h:83
#define toGL
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
int yOffset
Definition: cliprect.h:126
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 MobileOpenGL2Graphics::drawQuad ( const int  srcX,
const int  srcY,
const int  dstX,
const int  dstY,
const int  width,
const int  height 
)
inlineprivate

Definition at line 277 of file mobileopengl2graphics.cpp.

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

Referenced by drawImageInline().

283 {
284  const GLfloat texX2 = static_cast<GLfloat>(srcX + width);
285  const GLfloat texY2 = static_cast<GLfloat>(srcY + height);
286  const GLfloat x2 = static_cast<GLfloat>(dstX + width);
287  const GLfloat y2 = static_cast<GLfloat>(dstY + height);
288  const GLfloat srcX2 = toGL(srcX);
289  const GLfloat srcY2 = toGL(srcY);
290  const GLfloat dstX2 = toGL(dstX);
291  const GLfloat dstY2 = toGL(dstY);
292 
293  GLfloat vertices[] =
294  {
295  dstX2, dstY2, srcX2, srcY2,
296  x2, dstY2, texX2, srcY2,
297  dstX2, y2, srcX2, texY2,
298  x2, y2, texX2, texY2
299  };
300 
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 }
#define GL_ARRAY_BUFFER
Definition: mgldefines.h:83
#define toGL
#define GL_STREAM_DRAW
Definition: mgldefines.h:88
#define mglDrawArrays(...)
Definition: mgl.hpp:82
static void logError()
GraphicsManager graphicsManager

◆ drawRectangle() [1/2]

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

Definition at line 1073 of file mobileopengl2graphics.cpp.

1075 {
1076 }

◆ drawRectangle() [2/2]

void MobileOpenGL2Graphics::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 984 of file mobileopengl2graphics.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.

985 {
988  const ClipRect &clipArea = mClipStack.top();
989  const GLfloat x1 = static_cast<GLfloat>(rect.x + clipArea.xOffset);
990  const GLfloat y1 = static_cast<GLfloat>(rect.y + clipArea.yOffset);
991  const GLfloat x2 = x1 + static_cast<GLfloat>(rect.width);
992  const GLfloat y2 = y1 + static_cast<GLfloat>(rect.height);
993  GLfloat vertices[] =
994  {
995  x1, y1, 0.0f, 0.0f,
996  x1, y2, 0.0f, 0.0f,
997  x2, y2, 0.0f, 0.0f,
998  x2, y1, 0.0f, 0.0f
999  };
1000 
1001  mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
1002  vertices, GL_STREAM_DRAW);
1003 #ifdef DEBUG_DRAW_CALLS
1004  mDrawCalls ++;
1005 #endif // DEBUG_DRAW_CALLS
1006  mglDrawArrays(GL_LINE_LOOP, 0, 4);
1007 #ifdef OPENGLERRORS
1009 #endif // OPENGLERRORS
1010 }
#define GL_ARRAY_BUFFER
Definition: mgldefines.h:83
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
int yOffset
Definition: cliprect.h:126
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 MobileOpenGL2Graphics::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 427 of file mobileopengl2graphics.cpp.

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

433 {
434  if (image == nullptr)
435  return;
436 
437  const SDL_Rect &imageRect = image->mBounds;
438 
439  // Just draw the image normally when no resizing is necessary,
440  if (imageRect.w == desiredWidth && imageRect.h == desiredHeight)
441  {
442  drawImageInline(image, dstX, dstY);
443  return;
444  }
445 
446  setColorAlpha(image->mAlpha);
447 #ifdef DEBUG_BIND_TEXTURE
448  debugBindTexture(image);
449 #endif // DEBUG_BIND_TEXTURE
450  bindTexture2(GL_TEXTURE_2D, image);
453 
454  const ClipRect &clipArea = mClipStack.top();
455  // Draw a textured quad.
456  drawRescaledQuad(imageRect.x,
457  imageRect.y,
458  dstX + clipArea.xOffset,
459  dstY + clipArea.yOffset,
460  imageRect.w,
461  imageRect.h,
462  desiredWidth,
463  desiredHeight);
464 }
static void bindTexture2(const GLenum target, const Image *const image)
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 bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
int yOffset
Definition: cliprect.h:126
void drawImageInline(const Image *const image, int dstX, int dstY) A_INLINE
int xOffset
Definition: cliprect.h:121
void debugBindTexture(const Image *const image)
float mAlpha
Definition: image.h:212
MStack< ClipRect > mClipStack
Definition: graphics.h:520
SDL_Rect mBounds
Definition: image.h:210
T & top() const
Definition: mstack.h:72
void setColorAlpha(const float alpha) A_INLINE

◆ drawRescaledPattern()

void MobileOpenGL2Graphics::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 536 of file mobileopengl2graphics.cpp.

References bindArrayBufferAndAttributes(), bindTexture2(), debugBindTexture(), drawTriangleArray(), enableTexturingAndBlending(), Graphics::mClipStack, mFloatArray, mMaxVertices, mVbo, setColorAlpha(), toGL, MStack< T >::top(), vertFill2D, x, ClipRect::xOffset, y, and ClipRect::yOffset.

543 {
544  if (image == nullptr)
545  return;
546 
547  if (scaledWidth == 0 || scaledHeight == 0)
548  return;
549 
550  const SDL_Rect &imageRect = image->mBounds;
551  const int iw = imageRect.w;
552  const int ih = imageRect.h;
553  if (iw == 0 || ih == 0)
554  return;
555 
556  const int srcX = imageRect.x;
557  const int srcY = imageRect.y;
558  const GLfloat srcX2 = toGL(srcX);
559  const GLfloat srcY2 = toGL(srcY);
560 
561 #ifdef DEBUG_BIND_TEXTURE
562  debugBindTexture(image);
563 #endif // DEBUG_BIND_TEXTURE
564  bindTexture2(GL_TEXTURE_2D, image);
565 
568  setColorAlpha(image->mAlpha);
569 
570  unsigned int vp = 0;
571  const unsigned int vLimit = mMaxVertices * 4;
572 
573  const ClipRect &clipArea = mClipStack.top();
574  const int x2 = x + clipArea.xOffset;
575  const int y2 = y + clipArea.yOffset;
576 
577  const float scaleFactorW = static_cast<float>(scaledWidth) / iw;
578  const float scaleFactorH = static_cast<float>(scaledHeight) / ih;
579 
580  for (int py = 0; py < h; py += scaledHeight)
581  {
582  const int height = (py + scaledHeight >= h)
583  ? h - py : scaledHeight;
584  const GLfloat dstY = static_cast<GLfloat>(y2 + py);
585  const GLfloat scaledY = srcY + height / scaleFactorH;
586  for (int px = 0; px < w; px += scaledWidth)
587  {
588  const int width = (px + scaledWidth >= w)
589  ? w - px : scaledWidth;
590  const GLfloat dstX = static_cast<GLfloat>(x2 + px);
591  const GLfloat scaledX = srcX + width / scaleFactorW;
592 
594  srcX2, srcY2,
595  scaledX, scaledY,
596  dstX, dstY,
597  static_cast<GLfloat>(width), static_cast<GLfloat>(height));
598 
599  vp += 24;
600  if (vp >= vLimit)
601  {
602  drawTriangleArray(vp);
603  vp = 0;
604  }
605  }
606  }
607  if (vp > 0)
608  drawTriangleArray(vp);
609 }
static void bindTexture2(const GLenum target, const Image *const image)
void drawTriangleArray(const int size) A_INLINE
#define toGL
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
int yOffset
Definition: cliprect.h:126
#define vertFill2D(var, x1, y1, x2, y2, dstX, dstY, w, h)
int xOffset
Definition: cliprect.h:121
void debugBindTexture(const Image *const image)
float mAlpha
Definition: image.h:212
MStack< ClipRect > mClipStack
Definition: graphics.h:520
SDL_Rect mBounds
Definition: image.h:210
T & top() const
Definition: mstack.h:72
void setColorAlpha(const float alpha) A_INLINE

◆ drawRescaledQuad()

void MobileOpenGL2Graphics::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 mobileopengl2graphics.cpp.

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

Referenced by drawRescaledImage().

317 {
318  const GLfloat texX2 = static_cast<GLfloat>(srcX + width);
319  const GLfloat texY2 = static_cast<GLfloat>(srcY + height);
320  const GLfloat x2 = static_cast<GLfloat>(dstX + desiredWidth);
321  const GLfloat y2 = static_cast<GLfloat>(dstY + desiredHeight);
322  const GLfloat srcX2 = toGL(srcX);
323  const GLfloat srcY2 = toGL(srcY);
324  const GLfloat dstX2 = toGL(dstX);
325  const GLfloat dstY2 = toGL(dstY);
326 
327  GLfloat vertices[] =
328  {
329  dstX2, dstY2, srcX2, srcY2,
330  x2, dstY2, texX2, srcY2,
331  dstX2, y2, srcX2, texY2,
332  x2, y2, texX2, texY2
333  };
334 
335  mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
336  vertices, GL_STREAM_DRAW);
337 #ifdef DEBUG_DRAW_CALLS
338  mDrawCalls ++;
339 #endif // DEBUG_DRAW_CALLS
340  mglDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
341 #ifdef OPENGLERRORS
343 #endif // OPENGLERRORS
344 }
#define GL_ARRAY_BUFFER
Definition: mgldefines.h:83
#define toGL
#define GL_STREAM_DRAW
Definition: mgldefines.h:88
#define mglDrawArrays(...)
Definition: mgl.hpp:82
static void logError()
GraphicsManager graphicsManager

◆ drawTileCollection()

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

Implements Graphics.

Definition at line 733 of file mobileopengl2graphics.cpp.

References bindTexture2(), debugBindTexture(), drawVertexes(), enableTexturingAndBlending(), ImageVertexes::image, Image::mAlpha, ImageVertexes::ogl, and setColorAlpha().

736 {
738  const ImageVertexesVector &draws = vertCol->draws;
739  const ImageCollectionCIter it_end = draws.end();
740  for (ImageCollectionCIter it = draws.begin(); it != it_end; ++ it)
741  {
742  const ImageVertexes *const vert = *it;
743  const Image *const image = vert->image;
744 
745  setColorAlpha(image->mAlpha);
746 #ifdef DEBUG_BIND_TEXTURE
747  debugBindTexture(image);
748 #endif // DEBUG_BIND_TEXTURE
749  bindTexture2(GL_TEXTURE_2D, image);
750  drawVertexes(vert->ogl);
751  }
752 }
static void bindTexture2(const GLenum target, const Image *const image)
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
void drawVertexes(const OpenGLGraphicsVertexes &ogl) A_INLINE
void debugBindTexture(const Image *const image)
float mAlpha
Definition: image.h:212
Definition: image.h:61
OpenGLGraphicsVertexes ogl
Definition: imagevertexes.h:49
void setColorAlpha(const float alpha) A_INLINE

◆ drawTileVertexes()

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

Implements Graphics.

Definition at line 839 of file mobileopengl2graphics.cpp.

References bindArrayBufferAndAttributes(), bindTexture2(), debugBindTexture(), drawVertexes(), enableTexturingAndBlending(), Image::mAlpha, mVbo, and setColorAlpha().

841 {
842  if (vert == nullptr)
843  return;
844  const Image *const image = vert->image;
845 
846  setColorAlpha(image->mAlpha);
847 #ifdef DEBUG_BIND_TEXTURE
848  debugBindTexture(image);
849 #endif // DEBUG_BIND_TEXTURE
850  bindTexture2(GL_TEXTURE_2D, image);
853 
854  drawVertexes(vert->ogl);
855 }
static void bindTexture2(const GLenum target, const Image *const image)
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
const Image * image
Definition: imagevertexes.h:47
void drawVertexes(const OpenGLGraphicsVertexes &ogl) A_INLINE
void debugBindTexture(const Image *const image)
float mAlpha
Definition: image.h:212
Definition: image.h:61
OpenGLGraphicsVertexes ogl
Definition: imagevertexes.h:49
void setColorAlpha(const float alpha) A_INLINE

◆ drawTriangleArray() [1/2]

void MobileOpenGL2Graphics::drawTriangleArray ( const int  size)
inlineprivate

Definition at line 1326 of file mobileopengl2graphics.cpp.

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

Referenced by drawPatternInline(), and drawRescaledPattern().

1327 {
1328  mglBufferData(GL_ARRAY_BUFFER, size * sizeof(GLfloat),
1330 #ifdef DEBUG_DRAW_CALLS
1331  mDrawCalls ++;
1332 #endif // DEBUG_DRAW_CALLS
1333  mglDrawArrays(GL_TRIANGLES, 0, size / 4);
1334 #ifdef OPENGLERRORS
1336 #endif // OPENGLERRORS
1337 }
#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 MobileOpenGL2Graphics::drawTriangleArray ( const GLfloat *const  array,
const int  size 
)
inlineprivate

Definition at line 1339 of file mobileopengl2graphics.cpp.

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

1342 {
1343  mglBufferData(GL_ARRAY_BUFFER, size * sizeof(GLfloat),
1344  array, GL_STREAM_DRAW);
1345 #ifdef DEBUG_DRAW_CALLS
1346  mDrawCalls ++;
1347 #endif // DEBUG_DRAW_CALLS
1348  mglDrawArrays(GL_TRIANGLES, 0, size / 4);
1349 #ifdef OPENGLERRORS
1351 #endif // OPENGLERRORS
1352 }
#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 MobileOpenGL2Graphics::drawVertexes ( const OpenGLGraphicsVertexes ogl)
inline

Definition at line 611 of file mobileopengl2graphics.cpp.

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

Referenced by drawTileCollection(), and drawTileVertexes().

614 {
615  const STD_VECTOR<int> &vp = ogl.mVp;
616  const STD_VECTOR<GLuint> &vbos = ogl.mVbo;
617  STD_VECTOR<int>::const_iterator ivp;
618  STD_VECTOR<GLuint>::const_iterator ivbo;
619  const STD_VECTOR<int>::const_iterator ivp_end = vp.end();
620 
621  for (ivp = vp.begin(), ivbo = vbos.begin();
622  ivp != ivp_end;
623  ++ ivp, ++ ivbo)
624  {
626 #ifdef DEBUG_DRAW_CALLS
627  mDrawCalls ++;
628 #endif // DEBUG_DRAW_CALLS
629  mglDrawArrays(GL_TRIANGLES, 0, *ivp / 4);
630 #ifdef OPENGLERRORS
632 #endif // OPENGLERRORS
633  }
634 }
std::vector< GLuint > mVbo
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
#define mglDrawArrays(...)
Definition: mgl.hpp:82
static void logError()
GraphicsManager graphicsManager

◆ dumpSettings()

void MobileOpenGL2Graphics::dumpSettings ( )
static

Definition at line 1222 of file mobileopengl2graphics.cpp.

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

1223 {
1224  GLint test[1000];
1225  logger->log("\n\n");
1226  logger->log("start opengl dump");
1227  for (int f = 0; f < 65535; f ++)
1228  {
1229  test[0] = 0;
1230  test[1] = 0;
1231  test[2] = 0;
1232  test[3] = 0;
1233  mglGetIntegerv(f, &test[0]);
1234  if (test[0] != 0 || test[1] != 0 || test[2] != 0 || test[3] != 0)
1235  {
1236  logger->log("\n%d = %d, %d, %d, %d", f,
1237  test[0], test[1], test[2], test[3]);
1238  }
1239  }
1240 }
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 MobileOpenGL2Graphics::enableTexturingAndBlending ( )
protected

Definition at line 1040 of file mobileopengl2graphics.cpp.

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

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

1041 {
1042  if (!mTextureDraw)
1043  {
1044  mTextureDraw = true;
1045  mglUniform1f(mDrawTypeUniform, 1.0f);
1046  }
1047  if (!mAlpha)
1048  {
1049  mglEnable(GL_BLEND);
1050  mAlpha = true;
1051  }
1052 }
bool mAlpha
Definition: graphics.h:537
#define mglEnable(...)
Definition: mgl.hpp:90

◆ endDraw()

void MobileOpenGL2Graphics::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 911 of file mobileopengl2graphics.cpp.

References popClipArea().

912 {
913  popClipArea();
914 }

◆ fillRectangle()

void MobileOpenGL2Graphics::fillRectangle ( const Rect rect)
virtual

Implements Graphics.

Definition at line 1012 of file mobileopengl2graphics.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.

1013 {
1016  const ClipRect &clipArea = mClipStack.top();
1017  const GLfloat x1 = static_cast<GLfloat>(rect.x + clipArea.xOffset);
1018  const GLfloat y1 = static_cast<GLfloat>(rect.y + clipArea.yOffset);
1019  const GLfloat x2 = x1 + static_cast<GLfloat>(rect.width);
1020  const GLfloat y2 = y1 + static_cast<GLfloat>(rect.height);
1021  GLfloat vertices[] =
1022  {
1023  x1, y1, 0.0f, 0.0f,
1024  x2, y1, 0.0f, 0.0f,
1025  x1, y2, 0.0f, 0.0f,
1026  x2, y2, 0.0f, 0.0f
1027  };
1028 
1029  mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
1030  vertices, GL_STREAM_DRAW);
1031 #ifdef DEBUG_DRAW_CALLS
1032  mDrawCalls ++;
1033 #endif // DEBUG_DRAW_CALLS
1034  mglDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
1035 #ifdef OPENGLERRORS
1037 #endif // OPENGLERRORS
1038 }
int width
Definition: rect.h:218
#define GL_ARRAY_BUFFER
Definition: mgldefines.h:83
void bindArrayBufferAndAttributes(const GLuint vbo) A_INLINE
int yOffset
Definition: cliprect.h:126
int x
Definition: rect.h:208
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 MobileOpenGL2Graphics::finalize ( ImageCollection *const  col)
virtual

Reimplemented from Graphics.

Definition at line 1277 of file mobileopengl2graphics.cpp.

References FOR_EACH.

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

◆ finalize() [2/2]

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

Reimplemented from Graphics.

Definition at line 1286 of file mobileopengl2graphics.cpp.

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

1288 {
1289  // in future need convert in each switchVp/continueVp
1290 
1291  if (vert == nullptr)
1292  return;
1293  OpenGLGraphicsVertexes &ogl = vert->ogl;
1294  const STD_VECTOR<int> &vp = ogl.mVp;
1295  STD_VECTOR<int>::const_iterator ivp;
1296  const STD_VECTOR<int>::const_iterator ivp_end = vp.end();
1297  STD_VECTOR<GLfloat*> &floatTexPool = ogl.mFloatTexPool;
1298  STD_VECTOR<GLfloat*>::const_iterator ft;
1299  const STD_VECTOR<GLfloat*>::const_iterator ft_end = floatTexPool.end();
1300  STD_VECTOR<GLuint> &vbos = ogl.mVbo;
1301  STD_VECTOR<GLuint>::const_iterator ivbo;
1302 
1303  const int sz = CAST_S32(floatTexPool.size());
1304  if (sz == 0)
1305  return;
1306  vbos.resize(sz);
1307  mglGenBuffers(sz, &vbos[0]);
1308 
1309  for (ft = floatTexPool.begin(), ivp = vp.begin(), ivbo = vbos.begin();
1310  ft != ft_end && ivp != ivp_end;
1311  ++ ft, ++ ivp, ++ ivbo)
1312  {
1313  bindArrayBuffer(*ivbo);
1314  mglBufferData(GL_ARRAY_BUFFER, (*ivp) * sizeof(GLfloat),
1315  *ft, GL_STATIC_DRAW);
1316  }
1317 
1318  for (STD_VECTOR<GLfloat*>::iterator it = floatTexPool.begin();
1319  it != floatTexPool.end(); ++ it)
1320  {
1321  delete [] (*it);
1322  }
1323  floatTexPool.clear();
1324 }
std::vector< GLuint > mVbo
#define GL_ARRAY_BUFFER
Definition: mgldefines.h:83
#define CAST_S32
Definition: cast.h:29
#define GL_STATIC_DRAW
Definition: mgldefines.h:89
std::vector< GLfloat * > mFloatTexPool
void bindArrayBuffer(const GLuint vbo) A_INLINE
OpenGLGraphicsVertexes ogl
Definition: imagevertexes.h:49

◆ getMemoryUsage()

int MobileOpenGL2Graphics::getMemoryUsage ( )

◆ initArrays()

void MobileOpenGL2Graphics::initArrays ( const int  vertCount)
virtual

Reimplemented from Graphics.

Definition at line 140 of file mobileopengl2graphics.cpp.

References mFloatArray, mFloatArrayCached, mMaxVertices, and vertexBufSize.

141 {
142  mMaxVertices = vertCount;
143  if (mMaxVertices < 500)
144  mMaxVertices = 500;
145  else if (mMaxVertices > 1024)
146  mMaxVertices = 1024;
147 
148  // need alocate small size, after if limit reached reallocate to double size
149  const size_t sz = mMaxVertices * 4 + 30;
151  if (mFloatArray == nullptr)
152  mFloatArray = new GLfloat[sz];
153  if (mFloatArrayCached == nullptr)
154  mFloatArrayCached = new GLfloat[sz];
155 }
unsigned int vertexBufSize

◆ isAllowScale()

bool MobileOpenGL2Graphics::isAllowScale ( ) const
inlinevirtual

Reimplemented from Graphics.

Definition at line 40 of file mobileopengl2graphics.h.

56  : public Graphics

◆ popClipArea()

void MobileOpenGL2Graphics::popClipArea ( )
virtual

Removes the top most clip area from the stack.

Exceptions
Exceptionif the stack is empty.

Reimplemented from Graphics.

Definition at line 927 of file mobileopengl2graphics.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().

928 {
929  if (mClipStack.empty())
930  return;
932  if (mClipStack.empty())
933  return;
934 
935  const ClipRect &clipArea = mClipStack.top();
936  mglScissor(clipArea.x * mScale,
937  (mRect.h - clipArea.y - clipArea.height) * mScale,
938  clipArea.width * mScale,
939  clipArea.height * mScale);
940 }
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 MobileOpenGL2Graphics::postInit ( )
virtual

Reimplemented from Graphics.

Definition at line 157 of file mobileopengl2graphics.cpp.

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

Referenced by screenResized().

158 {
159 #ifndef __native_client__
160  mglGenVertexArrays(1, &mVao);
161  mglBindVertexArray(mVao);
162 #endif // __native_client__
163  mglGenBuffers(1, &mVbo);
164 // logger->log("gen vbo buffer: %u", mVbo);
166 
167  logger->log("Compiling shaders");
169  if (mProgram == nullptr)
170  {
172  logger->safeError("Shader creation error. See manaplus.log.");
173  }
175  if (mProgramId == 0u)
176  logger->safeError("Shaders compilation error.");
177 
178  logger->log("Shaders compilation done.");
179  mglUseProgram(mProgramId);
180 
181  mPosAttrib = 0;
182 
183  mSimpleColorUniform = mglGetUniformLocation(mProgramId, "color");
184  mScreenUniform = mglGetUniformLocation(mProgramId, "screen");
185  mDrawTypeUniform = mglGetUniformLocation(mProgramId, "drawType");
186  mTextureColorUniform = mglGetUniformLocation(mProgramId, "alpha");
187  mTextureSizeUniform = mglGetUniformLocation(mProgramId, "textureSize");
188 
189  mglUniform1f(mTextureColorUniform, 1.0f);
190 
191  mglVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
192  mglEnableVertexAttribArray(0);
194 
195  mglUniform2f(mScreenUniform,
196  static_cast<float>(mWidth) / 2.0f,
197  static_cast<float>(mHeight) / 2.0f);
198  // for safty init texture size to 1x1
199  mglUniform2f(mTextureSizeUniform,
200  1.0f,
201  1.0f);
202  mglUniform4f(mSimpleColorUniform,
203  0.0F,
204  0.0F,
205  0.0F,
206  0.0F);
207 
208  mglActiveTexture(GL_TEXTURE0);
209 }
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 bindArrayBuffer(const GLuint vbo) A_INLINE
void log(const char *const log_text,...)
Definition: logger.cpp:264
GraphicsManager graphicsManager
ShaderProgram * getGles2Program()

◆ pushClipArea()

void MobileOpenGL2Graphics::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 916 of file mobileopengl2graphics.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().

917 {
919  const ClipRect &clipArea = mClipStack.top();
920 
921  mglScissor(clipArea.x * mScale,
922  (mRect.h - clipArea.y - clipArea.height) * mScale,
923  clipArea.width * mScale,
924  clipArea.height * mScale);
925 }
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 MobileOpenGL2Graphics::removeArray ( const uint32_t  id,
uint32_t *const  arr 
)
virtual

Reimplemented from Graphics.

Definition at line 1174 of file mobileopengl2graphics.cpp.

References mVboBinded.

1176 {
1177  mglDeleteBuffers(sz, arr);
1178  for (size_t f = 0; f < sz; f ++)
1179  {
1180  if (arr[f] == mVboBinded)
1181  mVboBinded = 0;
1182  }
1183 }

◆ restoreColor()

void MobileOpenGL2Graphics::restoreColor ( )
inlineprivate

◆ screenResized()

void MobileOpenGL2Graphics::screenResized ( )
virtual

Reimplemented from Graphics.

Definition at line 211 of file mobileopengl2graphics.cpp.

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

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

◆ setColor()

void MobileOpenGL2Graphics::setColor ( const Color color)
virtual

Reimplemented from Graphics.

Definition at line 254 of file mobileopengl2graphics.cpp.

References Graphics::mColor, mColorAlpha, and mSimpleColorUniform.

255 {
256  mColorAlpha = (color.a != 255);
257  if (mColor != color)
258  {
259  mColor = color;
260  mglUniform4f(mSimpleColorUniform,
261  static_cast<float>(color.r) / 255.0F,
262  static_cast<float>(color.g) / 255.0F,
263  static_cast<float>(color.b) / 255.0F,
264  static_cast<float>(color.a) / 255.0F);
265  }
266 }
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 MobileOpenGL2Graphics::setColorAlpha ( const float  alpha)
inlineprivate

Definition at line 268 of file mobileopengl2graphics.cpp.

References mAlphaCached, and mTextureColorUniform.

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

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

◆ setVideoMode()

bool MobileOpenGL2Graphics::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 233 of file mobileopengl2graphics.cpp.

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

241 {
242  setMainFlags(w, h,
243  scale,
244  bpp,
245  fs,
246  hwaccel,
247  resize,
248  noFrame,
249  allowHighDPI);
250 
251  return setOpenGLMode();
252 }
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 MobileOpenGL2Graphics::testDraw ( )
virtual

Reimplemented from Graphics.

Definition at line 383 of file mobileopengl2graphics.cpp.

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

384 {
385 /*
386  GLfloat vertices[] =
387  {
388  0, 0, 0, 0,
389  800, 0, 800, 0,
390  0, 600, 0, 600,
391  800, 600, 800, 600
392  };
393 */
394 // logger->log("allocate: %d, %ld", mVboBinded, sizeof(vertices));
395 // mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
396 // vertices, GL_STREAM_DRAW);
397 #ifdef DEBUG_DRAW_CALLS
398  mDrawCalls ++;
399 #endif // DEBUG_DRAW_CALLS
400  mglDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
401 // glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, 0);
402 #ifdef OPENGLERRORS
404 #endif // OPENGLERRORS
405 }
#define mglDrawArrays(...)
Definition: mgl.hpp:82
static void logError()
GraphicsManager graphicsManager

◆ updateScreen()

void MobileOpenGL2Graphics::updateScreen ( )
virtual

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

Implements Graphics.

Definition at line 882 of file mobileopengl2graphics.cpp.

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

883 {
884  BLOCK_START("Graphics::updateScreen")
885 #ifdef DEBUG_DRAW_CALLS
886  mLastDrawCalls = mDrawCalls;
887  mDrawCalls = 0;
888 #endif // DEBUG_DRAW_CALLS
889 #ifdef USE_SDL2
890  SDL_GL_SwapWindow(mWindow);
891 #else // USE_SDL2
892  SDL_GL_SwapBuffers();
893 #endif // USE_SDL2
894 #ifdef DEBUG_OPENGL
895  if (isGLNotNull(mglFrameTerminator))
896  mglFrameTerminator();
897 #endif // DEBUG_OPENGL
898  BLOCK_END("Graphics::updateScreen")
899 }
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 MobileOpenGL2Graphics::updateTextureFormat ( )

Field Documentation

◆ mAlphaCached

float MobileOpenGL2Graphics::mAlphaCached
private

Definition at line 135 of file mobileopengl2graphics.h.

Referenced by setColorAlpha().

◆ mAttributesBinded

GLuint MobileOpenGL2Graphics::mAttributesBinded
private

◆ mColorAlpha

bool MobileOpenGL2Graphics::mColorAlpha
private

Definition at line 153 of file mobileopengl2graphics.h.

Referenced by disableTexturingAndBlending(), and setColor().

◆ mDrawTypeUniform

GLuint MobileOpenGL2Graphics::mDrawTypeUniform
private

◆ mFbo

FBOInfo MobileOpenGL2Graphics::mFbo
private

Definition at line 160 of file mobileopengl2graphics.h.

◆ mFloatArray

GLfloat* MobileOpenGL2Graphics::mFloatArray
private

◆ mFloatArrayCached

GLfloat* MobileOpenGL2Graphics::mFloatArrayCached
private

Definition at line 133 of file mobileopengl2graphics.h.

Referenced by deleteArraysInternal(), and initArrays().

◆ mFloatColor

float MobileOpenGL2Graphics::mFloatColor
private

Definition at line 138 of file mobileopengl2graphics.h.

◆ mMaxVertices

int MobileOpenGL2Graphics::mMaxVertices
private

◆ mPosAttrib

GLint MobileOpenGL2Graphics::mPosAttrib
private

Definition at line 142 of file mobileopengl2graphics.h.

Referenced by postInit().

◆ mProgram

ShaderProgram* MobileOpenGL2Graphics::mProgram
private

Definition at line 134 of file mobileopengl2graphics.h.

Referenced by deleteGLObjects(), and postInit().

◆ mProgramId

GLuint MobileOpenGL2Graphics::mProgramId
private

Definition at line 140 of file mobileopengl2graphics.h.

Referenced by postInit().

◆ mScreenUniform

GLuint MobileOpenGL2Graphics::mScreenUniform
private

Definition at line 144 of file mobileopengl2graphics.h.

Referenced by postInit().

◆ mSimpleColorUniform

GLuint MobileOpenGL2Graphics::mSimpleColorUniform
private

Definition at line 141 of file mobileopengl2graphics.h.

Referenced by postInit(), and setColor().

◆ mTextureBinded

GLuint MobileOpenGL2Graphics::mTextureBinded = 0U
static

Definition at line 49 of file mobileopengl2graphics.h.

Referenced by bindTexture(), and bindTexture2().

◆ mTextureColorUniform

GLint MobileOpenGL2Graphics::mTextureColorUniform
private

Definition at line 143 of file mobileopengl2graphics.h.

Referenced by postInit(), and setColorAlpha().

◆ mTextureDraw

bool MobileOpenGL2Graphics::mTextureDraw
private

◆ mTextureHeight

int MobileOpenGL2Graphics::mTextureHeight = 1
staticprivate

Definition at line 130 of file mobileopengl2graphics.h.

Referenced by bindTexture2().

◆ mTextureSizeUniform

GLuint MobileOpenGL2Graphics::mTextureSizeUniform = 0U
staticprivate

Definition at line 128 of file mobileopengl2graphics.h.

Referenced by bindTexture2(), and postInit().

◆ mTextureWidth

int MobileOpenGL2Graphics::mTextureWidth = 1
staticprivate

Definition at line 129 of file mobileopengl2graphics.h.

Referenced by bindTexture2().

◆ mVao

GLuint MobileOpenGL2Graphics::mVao
private

Definition at line 147 of file mobileopengl2graphics.h.

Referenced by deleteGLObjects(), and postInit().

◆ mVbo

GLuint MobileOpenGL2Graphics::mVbo
private

◆ mVboBinded

GLuint MobileOpenGL2Graphics::mVboBinded
private

◆ mVpCached

int MobileOpenGL2Graphics::mVpCached
private

Definition at line 136 of file mobileopengl2graphics.h.


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