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

#include <mobileopenglgraphics.h>

Inheritance diagram for MobileOpenGLGraphics:
Graphics

Public Member Functions

 MobileOpenGLGraphics ()
 
 ~MobileOpenGLGraphics ()
 
void postInit ()
 
void drawTriangleArrayfs (const GLshort *const shortVertArray, const GLfloat *const floatTexArray, const int size) A_INLINE
 
void drawTriangleArrayfs (const int size) A_INLINE
 
void drawTriangleArrayfsCached (const int size) A_INLINE
 
void drawLineArrays (const int size) A_INLINE
 
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 setColor (const Color &color)
 
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)
 
virtual void createGLContext (const bool custom)
 
virtual void finalize (ImageCollection *const col)
 
virtual void finalize (ImageVertexes *const vert)
 
virtual void testDraw ()
 
virtual void removeArray (const uint32_t sz, uint32_t *const arr)
 
virtual void screenResized ()
 

Static Public Member Functions

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

Static Public Attributes

static GLuint mTextureBinded = 0
 

Protected Member Functions

void enableTexturingAndBlending ()
 
void disableTexturingAndBlending ()
 
void debugBindTexture (const Image *const image)
 
void deleteArraysInternal ()
 
- Protected Member Functions inherited from Graphics
 Graphics ()
 
void setMainFlags (const int w, const int h, const int scale, const int bpp, const bool fs, const bool hwaccel, const bool resize, const bool noFrame, const bool allowHighDPI)
 
int getOpenGLFlags () const
 
int getSoftwareFlags () const
 
bool setOpenGLMode ()
 
void updateMemoryInfo ()
 
bool videoInfo ()
 
void setOpenGLFlags ()
 

Private Member Functions

void calcImageRect (ImageVertexes *const vert, int x, int y, int w, int h, const ImageRect &imgRect) A_INLINE
 
void calcPatternInline (ImageVertexes *const vert, const Image *const image, const int x, const int y, const int w, const int h) const A_INLINE
 
void calcTileVertexesInline (ImageVertexes *const vert, const Image *const image, int x, int y) const A_INLINE
 
void drawImageInline (const Image *const image, int dstX, int dstY) A_INLINE
 
void setColorAlpha (const float alpha) A_INLINE
 
void restoreColor () A_INLINE
 

Private Attributes

GLfloat * mFloatTexArray
 
GLshort * mShortVertArray
 
GLfloat * mFloatTexArrayCached
 
GLshort * mShortVertArrayCached
 
float mAlphaCached
 
int mVpCached
 
bool mTexture
 
bool mIsByteColor
 
Color mByteColor
 
GLuint mImageCached
 
float mFloatColor
 
int mMaxVertices
 
bool mColorAlpha
 
FBOInfo mFbo
 

Additional Inherited Members

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

Detailed Description

Definition at line 55 of file mobileopenglgraphics.h.

Constructor & Destructor Documentation

◆ MobileOpenGLGraphics()

MobileOpenGLGraphics::MobileOpenGLGraphics ( )

Definition at line 79 of file mobileopenglgraphics.cpp.

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

79  :
80  mFloatTexArray(nullptr),
81  mShortVertArray(nullptr),
82  mFloatTexArrayCached(nullptr),
83  mShortVertArrayCached(nullptr),
84  mAlphaCached(1.0F),
85  mVpCached(0),
86  mTexture(false),
87  mIsByteColor(false),
88  mByteColor(),
89  mImageCached(0),
90  mFloatColor(1.0F),
91  mMaxVertices(500),
92  mColorAlpha(false),
93 #ifdef DEBUG_BIND_TEXTURE
94  mOldTexture(),
95  mOldTextureId(0),
96 #endif // DEBUG_BIND_TEXTURE
97  mFbo()
98 {
100  mName = "mobile OpenGL ES";
101 }
std::string mName
Definition: graphics.h:548
RenderType mOpenGL
Definition: graphics.h:544

◆ ~MobileOpenGLGraphics()

MobileOpenGLGraphics::~MobileOpenGLGraphics ( )

Definition at line 103 of file mobileopenglgraphics.cpp.

References deleteArraysInternal().

104 {
106 }

Member Function Documentation

◆ beginDraw()

void MobileOpenGLGraphics::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 924 of file mobileopenglgraphics.cpp.

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

925 {
926  glMatrixMode(GL_TEXTURE);
927  glLoadIdentity();
928 
929  glMatrixMode(GL_PROJECTION);
930  glLoadIdentity();
931 
932 #ifdef ANDROID
933  glOrthof(0.0, static_cast<float>(mRect.w),
934  static_cast<float>(mRect.h),
935  0.0, -1.0, 1.0);
936 #else // ANDROID
937 
938  glOrtho(0.0, static_cast<double>(mRect.w),
939  static_cast<double>(mRect.h),
940  0.0, -1.0, 1.0);
941 #endif // ANDROID
942 
943  glMatrixMode(GL_MODELVIEW);
944  glLoadIdentity();
945 
946  setOpenGLFlags();
947  mglDisable(GL_LIGHTING);
948  mglDisable(GL_FOG);
949  mglDisable(GL_COLOR_MATERIAL);
950 
951  glShadeModel(GL_FLAT);
952 
953  glEnableClientState(GL_VERTEX_ARRAY);
954  glDisableClientState(GL_TEXTURE_COORD_ARRAY);
955 
956 #ifndef ANDROID
957  mglHint(GL_LINE_SMOOTH_HINT, GL_FASTEST);
958  mglHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
959  mglHint(GL_POINT_SMOOTH_HINT, GL_FASTEST);
960  mglHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
961 #endif // ANDROID
962 
963  pushClipArea(Rect(0, 0, mRect.w, mRect.h));
964 }
#define mglHint(...)
Definition: mgl.hpp:86
void pushClipArea(const Rect &area)
Definition: rect.h:72
SDL_Rect mRect
Definition: graphics.h:542
void setOpenGLFlags()
Definition: graphics.cpp:747
#define mglDisable(...)
Definition: mgl.hpp:84

◆ bindTexture()

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

Definition at line 1219 of file mobileopenglgraphics.cpp.

References mglBindTexture, and mTextureBinded.

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

1221 {
1222  if (mTextureBinded != texture)
1223  {
1224  mTextureBinded = texture;
1225  mglBindTexture(target, texture);
1226  }
1227 }
#define mglBindTexture(...)
Definition: mgl.hpp:92

◆ calcImageRect()

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

Definition at line 1344 of file mobileopenglgraphics.cpp.

Referenced by calcWindow().

◆ calcPattern() [1/2]

void MobileOpenGLGraphics::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 653 of file mobileopenglgraphics.cpp.

References calcPatternInline(), x, and y.

659 {
660  calcPatternInline(vert, image, x, y, w, h);
661 }
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 MobileOpenGLGraphics::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 773 of file mobileopenglgraphics.cpp.

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

779 {
780  if (vertCol == nullptr || image == nullptr)
781  return;
782  ImageVertexes *vert = nullptr;
783  if (vertCol->currentGLImage != image->mGLImage)
784  {
785  vert = new ImageVertexes;
786  vertCol->currentGLImage = image->mGLImage;
787  vertCol->currentVert = vert;
788  vert->image = image;
789  vertCol->draws.push_back(vert);
790  }
791  else
792  {
793  vert = vertCol->currentVert;
794  }
795 
796  calcPatternInline(vert, image, x, y, w, h);
797 }
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 MobileOpenGLGraphics::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 663 of file mobileopenglgraphics.cpp.

References OpenGLGraphicsVertexes::continueFloatTexArray(), OpenGLGraphicsVertexes::continueShortVertArray(), OpenGLGraphicsVertexes::continueVp(), mMaxVertices, OpenGLGraphicsVertexes::switchFloatTexArray(), OpenGLGraphicsVertexes::switchShortVertArray(), OpenGLGraphicsVertexes::switchVp(), vertFill2D, x, and y.

Referenced by calcPattern().

670 {
671  if (image == nullptr || vert == nullptr)
672  return;
673 
674  const SDL_Rect &imageRect = image->mBounds;
675  const int srcX = imageRect.x;
676  const int srcY = imageRect.y;
677  const int iw = imageRect.w;
678  const int ih = imageRect.h;
679 
680  if (iw == 0 || ih == 0)
681  return;
682 
683  const float tw = static_cast<float>(image->mTexWidth);
684  const float th = static_cast<float>(image->mTexHeight);
685 
686  const unsigned int vLimit = mMaxVertices * 4;
687 
688  OpenGLGraphicsVertexes &ogl = vert->ogl;
689  unsigned int vp = ogl.continueVp();
690 
691  // Draw a set of textured rectangles
692 // if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
693  {
694  const float texX1 = static_cast<float>(srcX) / tw;
695  const float texY1 = static_cast<float>(srcY) / th;
696 
697  GLfloat *floatTexArray = ogl.continueFloatTexArray();
698  GLshort *shortVertArray = ogl.continueShortVertArray();
699 
700  for (int py = 0; py < h; py += ih)
701  {
702  const int height = (py + ih >= h) ? h - py : ih;
703  const int dstY = y + py;
704  const float texY2 = static_cast<float>(srcY + height) / th;
705  for (int px = 0; px < w; px += iw)
706  {
707  const int width = (px + iw >= w) ? w - px : iw;
708  const int dstX = x + px;
709  const float texX2 = static_cast<float>(srcX + width) / tw;
710 
711  vertFill2D(floatTexArray, shortVertArray,
712  texX1, texY1, texX2, texY2,
713  dstX, dstY, width, height);
714 
715  vp += 12;
716  if (vp >= vLimit)
717  {
718  floatTexArray = ogl.switchFloatTexArray();
719  shortVertArray = ogl.switchShortVertArray();
720  ogl.switchVp(vp);
721  vp = 0;
722  }
723  }
724  }
725  }
726  ogl.switchVp(vp);
727 }
int mTexHeight
Definition: image.h:184
#define vertFill2D(tVar, vVar, x1, y1, x2, y2, dstX, dstY, w, h)
SDL_Rect mBounds
Definition: image.h:210
OpenGLGraphicsVertexes ogl
Definition: imagevertexes.h:49
int mTexWidth
Definition: image.h:183

◆ calcTileCollection()

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

Implements Graphics.

Definition at line 729 of file mobileopenglgraphics.cpp.

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

734 {
735  if (vertCol == nullptr || image == nullptr)
736  return;
737  if (vertCol->currentGLImage != image->mGLImage)
738  {
739  ImageVertexes *const vert = new ImageVertexes;
740  vertCol->currentGLImage = image->mGLImage;
741  vertCol->currentVert = vert;
742  vert->image = image;
743  vertCol->draws.push_back(vert);
744  calcTileVertexesInline(vert, image, x, y);
745  }
746  else
747  {
748  calcTileVertexesInline(vertCol->currentVert, image, x, y);
749  }
750 }
const Image * image
Definition: imagevertexes.h:47
ImageVertexesVector draws
ImageVertexes * currentVert
void calcTileVertexesInline(ImageVertexes *const vert, const Image *const image, int x, int y) const A_INLINE
GLuint mGLImage
Definition: image.h:182

◆ calcTileVertexes()

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

Implements Graphics.

Definition at line 799 of file mobileopenglgraphics.cpp.

References calcTileVertexesInline().

802 {
803  calcTileVertexesInline(vert, image, dstX, dstY);
804 }
void calcTileVertexesInline(ImageVertexes *const vert, const Image *const image, int x, int y) const A_INLINE

◆ calcTileVertexesInline()

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

Definition at line 806 of file mobileopenglgraphics.cpp.

References OpenGLGraphicsVertexes::continueFloatTexArray(), OpenGLGraphicsVertexes::continueShortVertArray(), OpenGLGraphicsVertexes::continueVp(), mMaxVertices, OpenGLGraphicsVertexes::switchFloatTexArray(), OpenGLGraphicsVertexes::switchShortVertArray(), OpenGLGraphicsVertexes::switchVp(), and vertFill2D.

Referenced by calcTileCollection(), and calcTileVertexes().

812 {
813  const SDL_Rect &imageRect = image->mBounds;
814  const int srcX = imageRect.x;
815  const int srcY = imageRect.y;
816  const int w = imageRect.w;
817  const int h = imageRect.h;
818 
819  if (w == 0 || h == 0)
820  return;
821 
822  const float tw = static_cast<float>(image->mTexWidth);
823  const float th = static_cast<float>(image->mTexHeight);
824 
825  const unsigned int vLimit = mMaxVertices * 4;
826 
827  OpenGLGraphicsVertexes &ogl = vert->ogl;
828 
829 // STD_VECTOR<int> *vps = ogl.getVp();
830  unsigned int vp = ogl.continueVp();
831 
832  // Draw a set of textured rectangles
833 // if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
834  {
835  float texX1 = static_cast<float>(srcX) / tw;
836  float texY1 = static_cast<float>(srcY) / th;
837  float texX2 = static_cast<float>(srcX + w) / tw;
838  float texY2 = static_cast<float>(srcY + h) / th;
839 
840  GLfloat *const floatTexArray = ogl.continueFloatTexArray();
841  GLshort *const shortVertArray = ogl.continueShortVertArray();
842 
843  vertFill2D(floatTexArray, shortVertArray,
844  texX1, texY1, texX2, texY2,
845  dstX, dstY, w, h);
846 
847  vp += 12;
848  if (vp >= vLimit)
849  {
850  ogl.switchFloatTexArray();
851  ogl.switchShortVertArray();
852  ogl.switchVp(vp);
853  vp = 0;
854  }
855  }
856  ogl.switchVp(vp);
857 }
int mTexHeight
Definition: image.h:184
#define vertFill2D(tVar, vVar, x1, y1, x2, y2, dstX, dstY, w, h)
SDL_Rect mBounds
Definition: image.h:210
OpenGLGraphicsVertexes ogl
Definition: imagevertexes.h:49
int mTexWidth
Definition: image.h:183

◆ calcWindow()

void MobileOpenGLGraphics::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 875 of file mobileopenglgraphics.cpp.

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

880 {
881  ImageVertexes *vert = nullptr;
882  const Image *const image = imgRect.grid[4];
883  if (image == nullptr)
884  return;
885  if (vertCol->currentGLImage != image->mGLImage)
886  {
887  vert = new ImageVertexes;
888  vertCol->currentGLImage = image->mGLImage;
889  vertCol->currentVert = vert;
890  vert->image = image;
891  vertCol->draws.push_back(vert);
892  }
893  else
894  {
895  vert = vertCol->currentVert;
896  }
897  calcImageRect(vert, x, y, w, h, imgRect);
898 }
void calcImageRect(ImageVertexes *const vert, int x, int y, int w, int h, const ImageRect &imgRect) A_INLINE
const Image * image
Definition: imagevertexes.h:47
ImageVertexesVector draws
ImageVertexes * currentVert
Image * grid[9]
Definition: imagerect.h:41
GLuint mGLImage
Definition: image.h:182
Definition: image.h:61

◆ clearScreen()

void MobileOpenGLGraphics::clearScreen ( ) const
virtual

Reimplemented from Graphics.

Definition at line 1353 of file mobileopenglgraphics.cpp.

References debugBindTexture(), Logger::log(), logger, mglClear, restrict, and restrict2.

1354 {
1355  mglClear(GL_COLOR_BUFFER_BIT |
1356  GL_DEPTH_BUFFER_BIT |
1357  GL_STENCIL_BUFFER_BIT);
1358 }
#define mglClear(...)
Definition: mgl.hpp:96

◆ completeCache()

void MobileOpenGLGraphics::completeCache ( )
virtual

Implements Graphics.

Definition at line 428 of file mobileopenglgraphics.cpp.

References bindTexture(), drawTriangleArrayfsCached(), enableTexturingAndBlending(), mAlphaCached, mImageCached, OpenGLImageHelper::mTextureType, mVpCached, and setColorAlpha().

Referenced by drawImageCached(), and drawPatternCached().

429 {
430  if (mImageCached == 0u)
431  return;
432 
434 #ifdef DEBUG_BIND_TEXTURE
435 // debugBindTexture(image);
436 #endif // DEBUG_BIND_TEXTURE
439 
441  mImageCached = 0;
442  mVpCached = 0;
443 }
static void bindTexture(const GLenum target, const GLuint texture)
void drawTriangleArrayfsCached(const int size) A_INLINE
void setColorAlpha(const float alpha) A_INLINE

◆ copyImage()

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

Implements Graphics.

Definition at line 309 of file mobileopenglgraphics.cpp.

References drawImageInline().

311 {
312  drawImageInline(image, dstX, dstY);
313 }
void drawImageInline(const Image *const image, int dstX, int dstY) A_INLINE

◆ debugBindTexture()

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

◆ deleteArrays()

void MobileOpenGLGraphics::deleteArrays ( )
virtual

Reimplemented from Graphics.

Definition at line 134 of file mobileopenglgraphics.cpp.

References deleteArraysInternal().

135 {
137 }

◆ deleteArraysInternal()

void MobileOpenGLGraphics::deleteArraysInternal ( )
protected

Definition at line 139 of file mobileopenglgraphics.cpp.

References mFloatTexArray, mFloatTexArrayCached, mShortVertArray, and mShortVertArrayCached.

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

140 {
141  delete [] mFloatTexArray;
142  mFloatTexArray = nullptr;
143  delete [] mShortVertArray;
144  mShortVertArray = nullptr;
145  delete [] mFloatTexArrayCached;
146  mFloatTexArrayCached = nullptr;
147  delete [] mShortVertArrayCached;
148  mShortVertArrayCached = nullptr;
149 }

◆ disableTexturingAndBlending()

void MobileOpenGLGraphics::disableTexturingAndBlending ( )
protected

Definition at line 1087 of file mobileopenglgraphics.cpp.

References Graphics::mAlpha, mColorAlpha, mglDisable, mglEnable, mTexture, mTextureBinded, and OpenGLImageHelper::mTextureType.

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

1088 {
1089  mTextureBinded = 0;
1090  if (mAlpha && !mColorAlpha)
1091  {
1092  mglDisable(GL_BLEND);
1093  mAlpha = false;
1094  }
1095  else if (!mAlpha && mColorAlpha)
1096  {
1097  mglEnable(GL_BLEND);
1098  mAlpha = true;
1099  }
1100 
1101  if (mTexture)
1102  {
1104  glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1105  mTexture = false;
1106  }
1107 }
bool mAlpha
Definition: graphics.h:537
#define mglDisable(...)
Definition: mgl.hpp:84
#define mglEnable(...)
Definition: mgl.hpp:90

◆ drawImage()

void MobileOpenGLGraphics::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 284 of file mobileopenglgraphics.cpp.

References drawImageInline().

286 {
287  drawImageInline(image, dstX, dstY);
288 }
void drawImageInline(const Image *const image, int dstX, int dstY) A_INLINE

◆ drawImageCached()

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

Implements Graphics.

Definition at line 315 of file mobileopenglgraphics.cpp.

References completeCache(), mAlphaCached, mFloatTexArrayCached, mImageCached, mMaxVertices, mShortVertArrayCached, mVpCached, vertFill2D, x, and y.

317 {
318  if (image == nullptr)
319  return;
320 
321  if (image->mGLImage != mImageCached)
322  {
323  completeCache();
324  mImageCached = image->mGLImage;
325  mAlphaCached = image->mAlpha;
326  }
327 
328  const SDL_Rect &imageRect = image->mBounds;
329  const int srcX = imageRect.x;
330  const int srcY = imageRect.y;
331  const int w = imageRect.w;
332  const int h = imageRect.h;
333 
334  if (w == 0 || h == 0)
335  return;
336 
337  const float tw = static_cast<float>(image->mTexWidth);
338  const float th = static_cast<float>(image->mTexHeight);
339 
340  const unsigned int vLimit = mMaxVertices * 4;
341 
342  unsigned int vp = mVpCached;
343 
344  // Draw a set of textured rectangles
345 // if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
346  {
347  float texX1 = static_cast<float>(srcX) / tw;
348  float texY1 = static_cast<float>(srcY) / th;
349  float texX2 = static_cast<float>(srcX + w) / tw;
350  float texY2 = static_cast<float>(srcY + h) / th;
351 
353  texX1, texY1, texX2, texY2,
354  x, y, w, h);
355 
356  vp += 12;
357  if (vp >= vLimit)
358  {
359  completeCache();
360  vp = 0;
361  }
362  else
363  {
364  mVpCached = vp;
365  }
366  }
367 }
int mTexHeight
Definition: image.h:184
float mAlpha
Definition: image.h:212
#define vertFill2D(tVar, vVar, x1, y1, x2, y2, dstX, dstY, w, h)
GLuint mGLImage
Definition: image.h:182
SDL_Rect mBounds
Definition: image.h:210
int mTexWidth
Definition: image.h:183

◆ drawImageInline()

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

Definition at line 290 of file mobileopenglgraphics.cpp.

References bindTexture(), debugBindTexture(), drawQuad(), enableTexturingAndBlending(), FUNC_BLOCK, OpenGLImageHelper::mTextureType, and setColorAlpha().

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

292 {
293  FUNC_BLOCK("Graphics::drawImage", 1)
294  if (image == nullptr)
295  return;
296 
297  setColorAlpha(image->mAlpha);
298 #ifdef DEBUG_BIND_TEXTURE
299  debugBindTexture(image);
300 #endif // DEBUG_BIND_TEXTURE
303 
304  const SDL_Rect &imageRect = image->mBounds;
305  drawQuad(image, imageRect.x, imageRect.y,
306  dstX, dstY, imageRect.w, imageRect.h);
307 }
static void bindTexture(const GLenum target, const GLuint texture)
if(!vert) return
static void drawQuad(const Image *const image, const int srcX, const int srcY, const int dstX, const int dstY, const int width, const int height) A_INLINE
bool mAlpha
Definition: graphics.h:537
void debugBindTexture(const Image *const image)
#define FUNC_BLOCK(name, id)
Definition: perfomance.h:80
GLuint mGLImage
Definition: image.h:182
void setColorAlpha(const float alpha) A_INLINE
SDL_Rect mBounds
Definition: image.h:210

◆ drawImageRect()

void MobileOpenGLGraphics::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 1336 of file mobileopenglgraphics.cpp.

◆ drawLine()

void MobileOpenGLGraphics::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 1047 of file mobileopenglgraphics.cpp.

References disableTexturingAndBlending(), drawLineArrays(), mShortVertArray, and restoreColor().

1049 {
1051  restoreColor();
1052 
1053  mShortVertArray[0] = static_cast<GLshort>(x1);
1054  mShortVertArray[1] = static_cast<GLshort>(y1);
1055  mShortVertArray[2] = static_cast<GLshort>(x2);
1056  mShortVertArray[3] = static_cast<GLshort>(y2);
1057 
1058  drawLineArrays(4);
1059 }
void drawLineArrays(const int size) A_INLINE

◆ drawLineArrays()

void MobileOpenGLGraphics::drawLineArrays ( const int  size)
inline

Definition at line 1279 of file mobileopenglgraphics.cpp.

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

Referenced by drawLine(), and drawNet().

1280 {
1281  glVertexPointer(2, GL_SHORT, 0, mShortVertArray);
1282 
1283 #ifdef DEBUG_DRAW_CALLS
1284  mDrawCalls ++;
1285 #endif // DEBUG_DRAW_CALLS
1286 
1287  mglDrawArrays(GL_LINES, 0, size / 2);
1288 #ifdef OPENGLERRORS
1290 #endif // OPENGLERRORS
1291 }
#define mglDrawArrays(...)
Definition: mgl.hpp:82
static void logError()
GraphicsManager graphicsManager

◆ drawNet()

void MobileOpenGLGraphics::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 1166 of file mobileopenglgraphics.cpp.

References CAST_S16, disableTexturingAndBlending(), drawLineArrays(), mMaxVertices, mShortVertArray, restoreColor(), x, and y.

1169 {
1170  unsigned int vp = 0;
1171  const unsigned int vLimit = mMaxVertices * 4;
1172 
1174  restoreColor();
1175 
1176  const GLshort xs1 = static_cast<GLshort>(x1);
1177  const GLshort xs2 = static_cast<GLshort>(x2);
1178  const GLshort ys1 = static_cast<GLshort>(y1);
1179  const GLshort ys2 = static_cast<GLshort>(y2);
1180  const int16_t width1 = CAST_S16(width);
1181  const int16_t height1 = CAST_S16(height);
1182 
1183  for (int16_t y = CAST_S16(y1); y < y2; y += height1)
1184  {
1185  mShortVertArray[vp + 0] = xs1;
1186  mShortVertArray[vp + 1] = y;
1187 
1188  mShortVertArray[vp + 2] = xs2;
1189  mShortVertArray[vp + 3] = y;
1190 
1191  vp += 4;
1192  if (vp >= vLimit)
1193  {
1194  drawLineArrays(vp);
1195  vp = 0;
1196  }
1197  }
1198 
1199  for (int16_t x = CAST_S16(x1); x < x2; x += width1)
1200  {
1201  mShortVertArray[vp + 0] = x;
1202  mShortVertArray[vp + 1] = ys1;
1203 
1204  mShortVertArray[vp + 2] = x;
1205  mShortVertArray[vp + 3] = ys2;
1206 
1207  vp += 4;
1208  if (vp >= vLimit)
1209  {
1210  drawLineArrays(vp);
1211  vp = 0;
1212  }
1213  }
1214 
1215  if (vp > 0)
1216  drawLineArrays(vp);
1217 }
void drawLineArrays(const int size) A_INLINE
#define CAST_S16
Definition: cast.h:27

◆ drawPattern()

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

Implements Graphics.

Definition at line 475 of file mobileopenglgraphics.cpp.

References drawPatternInline(), x, and y.

478 {
479  drawPatternInline(image, x, y, w, h);
480 }
void drawPatternInline(const Image *const image, const int x, const int y, const int w, const int h) A_INLINE

◆ drawPatternCached()

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

Implements Graphics.

Definition at line 369 of file mobileopenglgraphics.cpp.

References completeCache(), mFloatTexArrayCached, mImageCached, mMaxVertices, mShortVertArrayCached, mVpCached, vertFill2D, x, and y.

374 {
375  if (image == nullptr)
376  return;
377 
378  if (image->mGLImage != mImageCached)
379  {
380  completeCache();
381  mImageCached = image->mGLImage;
382  }
383 
384  const SDL_Rect &imageRect = image->mBounds;
385  const int srcX = imageRect.x;
386  const int srcY = imageRect.y;
387  const int iw = imageRect.w;
388  const int ih = imageRect.h;
389 
390  if (iw == 0 || ih == 0)
391  return;
392 
393  const float tw = static_cast<float>(image->mTexWidth);
394  const float th = static_cast<float>(image->mTexHeight);
395 
396  unsigned int vp = mVpCached;
397  const unsigned int vLimit = mMaxVertices * 4;
398  const float texX1 = static_cast<float>(srcX) / tw;
399  const float texY1 = static_cast<float>(srcY) / th;
400 
401  for (int py = 0; py < h; py += ih)
402  {
403  const int height = (py + ih >= h) ? h - py : ih;
404  const float texY2 = static_cast<float>(srcY + height) / th;
405  const int dstY = y + py;
406  for (int px = 0; px < w; px += iw)
407  {
408  const int width = (px + iw >= w) ? w - px : iw;
409  const int dstX = x + px;
410 
411  const float texX2 = static_cast<float>(srcX + width) / tw;
412 
414  texX1, texY1, texX2, texY2,
415  dstX, dstY, width, height);
416 
417  vp += 12;
418  if (vp >= vLimit)
419  {
420  completeCache();
421  vp = 0;
422  }
423  }
424  }
425  mVpCached = vp;
426 }
int mTexHeight
Definition: image.h:184
#define vertFill2D(tVar, vVar, x1, y1, x2, y2, dstX, dstY, w, h)
GLuint mGLImage
Definition: image.h:182
SDL_Rect mBounds
Definition: image.h:210
int mTexWidth
Definition: image.h:183

◆ drawPatternInline()

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

Definition at line 482 of file mobileopenglgraphics.cpp.

References bindTexture(), debugBindTexture(), drawTriangleArrayfs(), enableTexturingAndBlending(), FUNC_BLOCK, mFloatTexArray, mMaxVertices, mShortVertArray, OpenGLImageHelper::mTextureType, setColorAlpha(), vertFill2D, x, and y.

Referenced by drawPattern().

487 {
488  FUNC_BLOCK("Graphics::drawPattern", 1)
489  if (image == nullptr)
490  return;
491 
492  const SDL_Rect &imageRect = image->mBounds;
493  const int srcX = imageRect.x;
494  const int srcY = imageRect.y;
495  const int iw = imageRect.w;
496  const int ih = imageRect.h;
497 
498  if (iw == 0 || ih == 0)
499  return;
500 
501  const float tw = static_cast<float>(image->mTexWidth);
502  const float th = static_cast<float>(image->mTexHeight);
503 
504  setColorAlpha(image->mAlpha);
505 
506 #ifdef DEBUG_BIND_TEXTURE
507  debugBindTexture(image);
508 #endif // DEBUG_BIND_TEXTURE
510 
512 
513  unsigned int vp = 0;
514  const unsigned int vLimit = mMaxVertices * 4;
515  // Draw a set of textured rectangles
516  const float texX1 = static_cast<float>(srcX) / tw;
517  const float texY1 = static_cast<float>(srcY) / th;
518 
519  for (int py = 0; py < h; py += ih)
520  {
521  const int height = (py + ih >= h) ? h - py : ih;
522  const float texY2 = static_cast<float>(srcY + height) / th;
523  const int dstY = y + py;
524  for (int px = 0; px < w; px += iw)
525  {
526  const int width = (px + iw >= w) ? w - px : iw;
527  const int dstX = x + px;
528 
529  const float texX2 = static_cast<float>(srcX + width) / tw;
530 
532  texX1, texY1, texX2, texY2,
533  dstX, dstY, width, height);
534 
535  vp += 12;
536  if (vp >= vLimit)
537  {
539  vp = 0;
540  }
541  }
542  }
543  if (vp > 0)
545 }
static void bindTexture(const GLenum target, const GLuint texture)
if(!vert) return
bool mAlpha
Definition: graphics.h:537
void debugBindTexture(const Image *const image)
#define FUNC_BLOCK(name, id)
Definition: perfomance.h:80
#define vertFill2D(tVar, vVar, x1, y1, x2, y2, dstX, dstY, w, h)
GLuint mGLImage
Definition: image.h:182
void setColorAlpha(const float alpha) A_INLINE
void drawTriangleArrayfs(const GLshort *const shortVertArray, const GLfloat *const floatTexArray, const int size) A_INLINE

◆ drawPoint()

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

Draws a single point/pixel.

Parameters
xThe x coordinate.
yThe y coordinate.

Implements Graphics.

Definition at line 1031 of file mobileopenglgraphics.cpp.

References disableTexturingAndBlending(), restoreColor(), x, and y.

Referenced by popClipArea().

1033 {
1035  restoreColor();
1036 
1037 #ifdef ANDROID
1038  // TODO need fix
1039 #else // ANDROID
1040 
1041  glBegin(GL_POINTS);
1042  glVertex2i(x, y);
1043  glEnd();
1044 #endif // ANDROID
1045 }

◆ drawRectangle() [1/2]

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

Definition at line 1109 of file mobileopenglgraphics.cpp.

References BLOCK_END, BLOCK_START, disableTexturingAndBlending(), graphicsManager, GraphicsManager::logError(), mglDrawArrays, restoreColor(), x, and y.

1111 {
1112  BLOCK_START("Graphics::drawRectangle")
1114  restoreColor();
1115 
1116  const GLshort x = static_cast<GLshort>(rect.x);
1117  const GLshort y = static_cast<GLshort>(rect.y);
1118  const GLshort width = static_cast<GLshort>(rect.width);
1119  const GLshort height = static_cast<GLshort>(rect.height);
1120  const GLshort xw = static_cast<GLshort>(rect.x + width);
1121  const GLshort yh = static_cast<GLshort>(rect.y + height);
1122 
1123  if (filled)
1124  {
1125  GLshort vert[] =
1126  {
1127  x, y,
1128  xw, y,
1129  x, yh,
1130  xw, yh
1131  };
1132 
1133  glVertexPointer(2, GL_SHORT, 0, &vert);
1134 #ifdef DEBUG_DRAW_CALLS
1135  mDrawCalls ++;
1136 #endif // DEBUG_DRAW_CALLS
1137 
1138  mglDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
1139 #ifdef OPENGLERRORS
1141 #endif // OPENGLERRORS
1142  }
1143  else
1144  {
1145  GLshort vert[] =
1146  {
1147  x, y,
1148  xw, y,
1149  xw, yh,
1150  x, yh
1151  };
1152 
1153  glVertexPointer(2, GL_SHORT, 0, &vert);
1154 #ifdef DEBUG_DRAW_CALLS
1155  mDrawCalls ++;
1156 #endif // DEBUG_DRAW_CALLS
1157 
1158  mglDrawArrays(GL_LINE_LOOP, 0, 4);
1159 #ifdef OPENGLERRORS
1161 #endif // OPENGLERRORS
1162  }
1163  BLOCK_END("Graphics::drawRectangle")
1164 }
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
#define mglDrawArrays(...)
Definition: mgl.hpp:82
static void logError()
GraphicsManager graphicsManager

◆ drawRectangle() [2/2]

void MobileOpenGLGraphics::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 1061 of file mobileopenglgraphics.cpp.

Referenced by fillRectangle().

1062 {
1063  drawRectangle(rect, false);
1064 }
void drawRectangle(const Rect &rect)

◆ drawRescaledImage()

void MobileOpenGLGraphics::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 445 of file mobileopenglgraphics.cpp.

References bindTexture(), debugBindTexture(), drawImageInline(), drawRescaledQuad(), enableTexturingAndBlending(), FUNC_BLOCK, OpenGLImageHelper::mTextureType, and setColorAlpha().

449 {
450  FUNC_BLOCK("Graphics::drawRescaledImage", 1)
451  if (image == nullptr)
452  return;
453 
454  const SDL_Rect &imageRect = image->mBounds;
455 
456  // Just draw the image normally when no resizing is necessary,
457  if (imageRect.w == desiredWidth && imageRect.h == desiredHeight)
458  {
459  drawImageInline(image, dstX, dstY);
460  return;
461  }
462 
463  setColorAlpha(image->mAlpha);
464 #ifdef DEBUG_BIND_TEXTURE
465  debugBindTexture(image);
466 #endif // DEBUG_BIND_TEXTURE
469 
470  // Draw a textured quad.
471  drawRescaledQuad(image, imageRect.x, imageRect.y, dstX, dstY,
472  imageRect.w, imageRect.h, desiredWidth, desiredHeight);
473 }
static void bindTexture(const GLenum target, const GLuint texture)
if(!vert) return
static void drawRescaledQuad(const Image *const image, const int srcX, const int srcY, const int dstX, const int dstY, const int width, const int height, const int desiredWidth, const int desiredHeight) A_INLINE
float mAlpha
Definition: image.h:212
void debugBindTexture(const Image *const image)
#define FUNC_BLOCK(name, id)
Definition: perfomance.h:80
GLuint mGLImage
Definition: image.h:182
void setColorAlpha(const float alpha) A_INLINE
void drawImageInline(const Image *const image, int dstX, int dstY) A_INLINE

◆ drawRescaledPattern()

void MobileOpenGLGraphics::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 547 of file mobileopenglgraphics.cpp.

References bindTexture(), debugBindTexture(), drawTriangleArrayfs(), enableTexturingAndBlending(), mFloatTexArray, mMaxVertices, mShortVertArray, OpenGLImageHelper::mTextureType, setColorAlpha(), vertFill2D, x, and y.

554 {
555  if (image == nullptr)
556  return;
557 
558  if (scaledWidth == 0 || scaledHeight == 0)
559  return;
560 
561  const SDL_Rect &imageRect = image->mBounds;
562  const int srcX = imageRect.x;
563  const int srcY = imageRect.y;
564  const int iw = imageRect.w;
565  const int ih = imageRect.h;
566  if (iw == 0 || ih == 0)
567  return;
568 
569  setColorAlpha(image->mAlpha);
570 
571 #ifdef DEBUG_BIND_TEXTURE
572  debugBindTexture(image);
573 #endif // DEBUG_BIND_TEXTURE
575 
577 
578  unsigned int vp = 0;
579  const unsigned int vLimit = mMaxVertices * 4;
580 
581  // Draw a set of textured rectangles
582  const float tw = static_cast<float>(image->mTexWidth);
583  const float th = static_cast<float>(image->mTexHeight);
584 
585  const float texX1 = static_cast<float>(srcX) / tw;
586  const float texY1 = static_cast<float>(srcY) / th;
587 
588  const float tFractionW = iw / tw;
589  const float tFractionH = ih / th;
590 
591  for (int py = 0; py < h; py += scaledHeight)
592  {
593  const int height = (py + scaledHeight >= h)
594  ? h - py : scaledHeight;
595  const int dstY = y + py;
596  const float visibleFractionH = static_cast<float>(height)
597  / scaledHeight;
598  const float texY2 = texY1 + tFractionH * visibleFractionH;
599  for (int px = 0; px < w; px += scaledWidth)
600  {
601  const int width = (px + scaledWidth >= w)
602  ? w - px : scaledWidth;
603  const int dstX = x + px;
604  const float visibleFractionW = static_cast<float>(width)
605  / scaledWidth;
606  const float texX2 = texX1 + tFractionW * visibleFractionW;
607 
609  texX1, texY1, texX2, texY2,
610  dstX, dstY, width, height);
611 
612  vp += 12;
613  if (vp >= vLimit)
614  {
616  vp = 0;
617  }
618  }
619  }
620  if (vp > 0)
622 }
static void bindTexture(const GLenum target, const GLuint texture)
int mTexHeight
Definition: image.h:184
float mAlpha
Definition: image.h:212
void debugBindTexture(const Image *const image)
#define vertFill2D(tVar, vVar, x1, y1, x2, y2, dstX, dstY, w, h)
GLuint mGLImage
Definition: image.h:182
void setColorAlpha(const float alpha) A_INLINE
SDL_Rect mBounds
Definition: image.h:210
int mTexWidth
Definition: image.h:183
void drawTriangleArrayfs(const GLshort *const shortVertArray, const GLfloat *const floatTexArray, const int size) A_INLINE

◆ drawTileCollection()

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

Implements Graphics.

Definition at line 752 of file mobileopenglgraphics.cpp.

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

755 {
756  const ImageVertexesVector &draws = vertCol->draws;
757  const ImageCollectionCIter it_end = draws.end();
758  for (ImageCollectionCIter it = draws.begin(); it != it_end; ++ it)
759  {
760  const ImageVertexes *const vert = *it;
761  const Image *const image = vert->image;
762 
763  setColorAlpha(image->mAlpha);
764 #ifdef DEBUG_BIND_TEXTURE
765  debugBindTexture(image);
766 #endif // DEBUG_BIND_TEXTURE
769  drawVertexes(vert->ogl);
770  }
771 }
void drawVertexes(const OpenGLGraphicsVertexes &ogl) A_INLINE
std::vector< ImageVertexes * > ImageVertexesVector
Definition: imagevertexes.h:55
const Image * image
Definition: imagevertexes.h:47
static void bindTexture(const GLenum target, const GLuint texture)
ImageVertexesVector draws
ImageVertexesVector::const_iterator ImageCollectionCIter
Definition: imagevertexes.h:57
float mAlpha
Definition: image.h:212
void debugBindTexture(const Image *const image)
GLuint mGLImage
Definition: image.h:182
void setColorAlpha(const float alpha) A_INLINE
Definition: image.h:61
OpenGLGraphicsVertexes ogl
Definition: imagevertexes.h:49

◆ drawTileVertexes()

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

Implements Graphics.

Definition at line 859 of file mobileopenglgraphics.cpp.

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

861 {
862  if (vert == nullptr)
863  return;
864  const Image *const image = vert->image;
865 
866  setColorAlpha(image->mAlpha);
867 #ifdef DEBUG_BIND_TEXTURE
868  debugBindTexture(image);
869 #endif // DEBUG_BIND_TEXTURE
872  drawVertexes(vert->ogl);
873 }
void drawVertexes(const OpenGLGraphicsVertexes &ogl) A_INLINE
const Image * image
Definition: imagevertexes.h:47
static void bindTexture(const GLenum target, const GLuint texture)
float mAlpha
Definition: image.h:212
void debugBindTexture(const Image *const image)
GLuint mGLImage
Definition: image.h:182
void setColorAlpha(const float alpha) A_INLINE
Definition: image.h:61
OpenGLGraphicsVertexes ogl
Definition: imagevertexes.h:49

◆ drawTriangleArrayfs() [1/2]

void MobileOpenGLGraphics::drawTriangleArrayfs ( const GLshort *const  shortVertArray,
const GLfloat *const  floatTexArray,
const int  size 
)
inline

Definition at line 1260 of file mobileopenglgraphics.cpp.

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

Referenced by drawPatternInline(), drawRescaledPattern(), and drawVertexes().

1265 {
1266  glVertexPointer(2, GL_SHORT, 0, shortVertArray);
1267  glTexCoordPointer(2, GL_FLOAT, 0, floatTexArray);
1268 
1269 #ifdef DEBUG_DRAW_CALLS
1270  mDrawCalls ++;
1271 #endif // DEBUG_DRAW_CALLS
1272 
1273  mglDrawArrays(GL_TRIANGLES, 0, size / 2);
1274 #ifdef OPENGLERRORS
1276 #endif // OPENGLERRORS
1277 }
#define mglDrawArrays(...)
Definition: mgl.hpp:82
static void logError()
GraphicsManager graphicsManager

◆ drawTriangleArrayfs() [2/2]

void MobileOpenGLGraphics::drawTriangleArrayfs ( const int  size)
inline

Definition at line 1229 of file mobileopenglgraphics.cpp.

References graphicsManager, GraphicsManager::logError(), mFloatTexArray, mglDrawArrays, mShortVertArray, and ServerCommandType::size.

1230 {
1231  glVertexPointer(2, GL_SHORT, 0, mShortVertArray);
1232  glTexCoordPointer(2, GL_FLOAT, 0, mFloatTexArray);
1233 
1234 #ifdef DEBUG_DRAW_CALLS
1235  mDrawCalls ++;
1236 #endif // DEBUG_DRAW_CALLS
1237 
1238  mglDrawArrays(GL_TRIANGLES, 0, size / 2);
1239 #ifdef OPENGLERRORS
1241 #endif // OPENGLERRORS
1242 }
#define mglDrawArrays(...)
Definition: mgl.hpp:82
static void logError()
GraphicsManager graphicsManager

◆ drawTriangleArrayfsCached()

void MobileOpenGLGraphics::drawTriangleArrayfsCached ( const int  size)
inline

Definition at line 1244 of file mobileopenglgraphics.cpp.

References graphicsManager, GraphicsManager::logError(), mFloatTexArrayCached, mglDrawArrays, mShortVertArrayCached, and ServerCommandType::size.

Referenced by completeCache().

1246 {
1247  glVertexPointer(2, GL_SHORT, 0, mShortVertArrayCached);
1248  glTexCoordPointer(2, GL_FLOAT, 0, mFloatTexArrayCached);
1249 
1250 #ifdef DEBUG_DRAW_CALLS
1251  mDrawCalls ++;
1252 #endif // DEBUG_DRAW_CALLS
1253 
1254  mglDrawArrays(GL_TRIANGLES, 0, size / 2);
1255 #ifdef OPENGLERRORS
1257 #endif // OPENGLERRORS
1258 }
#define mglDrawArrays(...)
Definition: mgl.hpp:82
static void logError()
GraphicsManager graphicsManager

◆ drawVertexes()

void MobileOpenGLGraphics::drawVertexes ( const OpenGLGraphicsVertexes ogl)
inline

Definition at line 624 of file mobileopenglgraphics.cpp.

References drawTriangleArrayfs().

Referenced by drawTileCollection(), and drawTileVertexes().

627 {
628  const STD_VECTOR<GLshort*> &shortVertPool = ogl.mShortVertPool;
629  STD_VECTOR<GLshort*>::const_iterator iv;
630  const STD_VECTOR<GLshort*>::const_iterator iv_end = shortVertPool.end();
631  const STD_VECTOR<int> &vp = ogl.mVp;
632  STD_VECTOR<int>::const_iterator ivp;
633  const STD_VECTOR<int>::const_iterator ivp_end = vp.end();
634 
635  // Draw a set of textured rectangles
636 // if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
637  {
638  const STD_VECTOR<GLfloat*> &floatTexPool = ogl.mFloatTexPool;
639  STD_VECTOR<GLfloat*>::const_iterator ft;
640  const STD_VECTOR<GLfloat*>::const_iterator
641  ft_end = floatTexPool.end();
642 
643  for (iv = shortVertPool.begin(), ft = floatTexPool.begin(),
644  ivp = vp.begin();
645  iv != iv_end && ft != ft_end && ivp != ivp_end;
646  ++ iv, ++ ft, ++ ivp)
647  {
648  drawTriangleArrayfs(*iv, *ft, *ivp);
649  }
650  }
651 }
std::vector< GLshort * > mShortVertPool
std::vector< GLfloat * > mFloatTexPool
void drawTriangleArrayfs(const GLshort *const shortVertArray, const GLfloat *const floatTexArray, const int size) A_INLINE

◆ dumpSettings()

void MobileOpenGLGraphics::dumpSettings ( )
static

Definition at line 1293 of file mobileopenglgraphics.cpp.

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

1294 {
1295  GLint test[1000];
1296  logger->log("\n\n");
1297  logger->log("start opengl dump");
1298  for (int f = 0; f < 65535; f ++)
1299  {
1300  test[0] = 0;
1301  test[1] = 0;
1302  test[2] = 0;
1303  test[3] = 0;
1304  mglGetIntegerv(f, &test[0]);
1305  if (test[0] != 0 || test[1] != 0 || test[2] != 0 || test[3] != 0)
1306  {
1307  logger->log("\n%d = %d, %d, %d, %d", f,
1308  test[0], test[1], test[2], test[3]);
1309  }
1310  }
1311 }
Logger * logger
Definition: logger.cpp:95
#define mglGetIntegerv(...)
Definition: mgl.hpp:94
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ enableTexturingAndBlending()

void MobileOpenGLGraphics::enableTexturingAndBlending ( )
protected

Definition at line 1071 of file mobileopenglgraphics.cpp.

References Graphics::mAlpha, mglEnable, mTexture, and OpenGLImageHelper::mTextureType.

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

1072 {
1073  if (!mTexture)
1074  {
1076  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1077  mTexture = true;
1078  }
1079 
1080  if (!mAlpha)
1081  {
1082  mglEnable(GL_BLEND);
1083  mAlpha = true;
1084  }
1085 }
bool mAlpha
Definition: graphics.h:537
#define mglEnable(...)
Definition: mgl.hpp:90

◆ endDraw()

void MobileOpenGLGraphics::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 966 of file mobileopenglgraphics.cpp.

References popClipArea().

967 {
968  popClipArea();
969 }

◆ fillRectangle()

void MobileOpenGLGraphics::fillRectangle ( const Rect rect)
virtual

Implements Graphics.

Definition at line 1066 of file mobileopenglgraphics.cpp.

References drawRectangle().

1067 {
1068  drawRectangle(rect, true);
1069 }
void drawRectangle(const Rect &rect)

◆ getMemoryUsage()

int MobileOpenGLGraphics::getMemoryUsage ( )

◆ initArrays()

void MobileOpenGLGraphics::initArrays ( const int  vertCount)
virtual

Reimplemented from Graphics.

Definition at line 113 of file mobileopenglgraphics.cpp.

References mFloatTexArray, mFloatTexArrayCached, mMaxVertices, mShortVertArray, mShortVertArrayCached, and vertexBufSize.

114 {
115  mMaxVertices = vertCount;
116  if (mMaxVertices < 500)
117  mMaxVertices = 500;
118  else if (mMaxVertices > 1024)
119  mMaxVertices = 1024;
120 
121  // need alocate small size, after if limit reached reallocate to double size
122  const size_t sz = mMaxVertices * 4 + 30;
124  if (mFloatTexArray == nullptr)
125  mFloatTexArray = new GLfloat[sz];
126  if (mShortVertArray == nullptr)
127  mShortVertArray = new GLshort[sz];
128  if (mFloatTexArrayCached == nullptr)
129  mFloatTexArrayCached = new GLfloat[sz];
130  if (mShortVertArrayCached == nullptr)
131  mShortVertArrayCached = new GLshort[sz];
132 }
unsigned int vertexBufSize

◆ isAllowScale()

bool MobileOpenGLGraphics::isAllowScale ( ) const
inlinevirtual

Reimplemented from Graphics.

Definition at line 40 of file mobileopenglgraphics.h.

55  : public Graphics

◆ popClipArea()

void MobileOpenGLGraphics::popClipArea ( )
virtual

Removes the top most clip area from the stack.

Exceptions
Exceptionif the stack is empty.

Reimplemented from Graphics.

Definition at line 1000 of file mobileopenglgraphics.cpp.

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

Referenced by endDraw().

1001 {
1002  if (mClipStack.empty())
1003  return;
1004 
1005  const ClipRect &clipArea1 = mClipStack.top();
1006  int transX = -clipArea1.xOffset;
1007  int transY = -clipArea1.yOffset;
1008 
1010 
1011  if (mClipStack.empty())
1012  return;
1013 
1014  const ClipRect &clipArea = mClipStack.top();
1015  transX += clipArea.xOffset;
1016  transY += clipArea.yOffset;
1017  if (transX != 0 || transY != 0)
1018  {
1019  glTranslatef(static_cast<GLfloat>(transX),
1020  static_cast<GLfloat>(transY), 0);
1021  }
1022  mglScissor(clipArea.x * mScale,
1023  (mRect.h - clipArea.y - clipArea.height) * mScale,
1024  clipArea.width * mScale,
1025  clipArea.height * mScale);
1026 }
int width
Definition: rect.h:218
int yOffset
Definition: cliprect.h:126
virtual void popClipArea()
Definition: graphics.cpp:738
#define mglScissor(...)
Definition: mgl.hpp:88
int x
Definition: rect.h:208
int xOffset
Definition: cliprect.h:121
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 MobileOpenGLGraphics::postInit ( )
virtual

Reimplemented from Graphics.

Definition at line 108 of file mobileopenglgraphics.cpp.

109 {
110 // glesTest();
111 }

◆ pushClipArea()

void MobileOpenGLGraphics::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 971 of file mobileopenglgraphics.cpp.

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

Referenced by beginDraw().

972 {
973  int transX = 0;
974  int transY = 0;
975 
976  if (!mClipStack.empty())
977  {
978  const ClipRect &clipArea = mClipStack.top();
979  transX = -clipArea.xOffset;
980  transY = -clipArea.yOffset;
981  }
982 
984 
985  const ClipRect &clipArea = mClipStack.top();
986  transX += clipArea.xOffset;
987  transY += clipArea.yOffset;
988 
989  if (transX != 0 || transY != 0)
990  {
991  glTranslatef(static_cast<GLfloat>(transX),
992  static_cast<GLfloat>(transY), 0);
993  }
994  mglScissor(clipArea.x * mScale,
995  (mRect.h - clipArea.y - clipArea.height) * mScale,
996  clipArea.width * mScale,
997  clipArea.height * mScale);
998 }
int width
Definition: rect.h:218
int yOffset
Definition: cliprect.h:126
#define mglScissor(...)
Definition: mgl.hpp:88
int x
Definition: rect.h:208
int xOffset
Definition: cliprect.h:121
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
bool empty() const
Definition: mstack.h:87

◆ restoreColor()

void MobileOpenGLGraphics::restoreColor ( )
inlineprivate

Definition at line 1323 of file mobileopenglgraphics.cpp.

References Color::a, Color::b, Color::g, mByteColor, Graphics::mColor, mIsByteColor, and Color::r.

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

1324 {
1325  if (mIsByteColor && mByteColor == mColor)
1326  return;
1327 
1328  glColor4ub(static_cast<GLubyte>(mColor.r),
1329  static_cast<GLubyte>(mColor.g),
1330  static_cast<GLubyte>(mColor.b),
1331  static_cast<GLubyte>(mColor.a));
1332  mIsByteColor = true;
1333  mByteColor = mColor;
1334 }
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

◆ setColor()

void MobileOpenGLGraphics::setColor ( const Color color)
inlinevirtual

Reimplemented from Graphics.

Definition at line 27 of file mobileopenglgraphics.h.

55  : public Graphics

◆ setColorAlpha()

void MobileOpenGLGraphics::setColorAlpha ( const float  alpha)
inlineprivate

Definition at line 1313 of file mobileopenglgraphics.cpp.

References mFloatColor, and mIsByteColor.

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

1314 {
1315  if (!mIsByteColor && mFloatColor == alpha)
1316  return;
1317 
1318  glColor4f(1.0F, 1.0F, 1.0F, alpha);
1319  mIsByteColor = false;
1320  mFloatColor = alpha;
1321 }

◆ setVideoMode()

bool MobileOpenGLGraphics::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 151 of file mobileopenglgraphics.cpp.

References A_NONNULL, drawQuad(), restrict, Graphics::setMainFlags(), and Graphics::setOpenGLMode().

159 {
160  setMainFlags(w, h,
161  scale,
162  bpp,
163  fs,
164  hwaccel,
165  resize,
166  noFrame,
167  allowHighDPI);
168 
169  return setOpenGLMode();
170 }
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

◆ updateScreen()

void MobileOpenGLGraphics::updateScreen ( )
virtual

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

Implements Graphics.

Definition at line 901 of file mobileopenglgraphics.cpp.

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

902 {
903  BLOCK_START("Graphics::updateScreen")
904 // glFlush();
905 // glFinish();
906 #ifdef DEBUG_DRAW_CALLS
907  mLastDrawCalls = mDrawCalls;
908  mDrawCalls = 0;
909 #endif // DEBUG_DRAW_CALLS
910 #ifdef USE_SDL2
911  SDL_GL_SwapWindow(mWindow);
912 #else // USE_SDL2
913 
914  SDL_GL_SwapBuffers();
915 #endif // USE_SDL2
916 #ifdef DEBUG_OPENGL
917  if (isGLNotNull(mglFrameTerminator))
918  mglFrameTerminator();
919 #endif // DEBUG_OPENGL
920 
921  BLOCK_END("Graphics::updateScreen")
922 }
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 MobileOpenGLGraphics::updateTextureFormat ( )

Field Documentation

◆ mAlphaCached

float MobileOpenGLGraphics::mAlphaCached
private

Definition at line 96 of file mobileopenglgraphics.h.

Referenced by completeCache(), and drawImageCached().

◆ mByteColor

Color MobileOpenGLGraphics::mByteColor
private

Definition at line 101 of file mobileopenglgraphics.h.

Referenced by restoreColor().

◆ mColorAlpha

bool MobileOpenGLGraphics::mColorAlpha
private

Definition at line 105 of file mobileopenglgraphics.h.

Referenced by disableTexturingAndBlending().

◆ mFbo

FBOInfo MobileOpenGLGraphics::mFbo
private

Definition at line 111 of file mobileopenglgraphics.h.

◆ mFloatColor

float MobileOpenGLGraphics::mFloatColor
private

Definition at line 103 of file mobileopenglgraphics.h.

Referenced by setColorAlpha().

◆ mFloatTexArray

GLfloat* MobileOpenGLGraphics::mFloatTexArray
private

◆ mFloatTexArrayCached

GLfloat* MobileOpenGLGraphics::mFloatTexArrayCached
private

◆ mImageCached

GLuint MobileOpenGLGraphics::mImageCached
private

Definition at line 102 of file mobileopenglgraphics.h.

Referenced by completeCache(), drawImageCached(), and drawPatternCached().

◆ mIsByteColor

bool MobileOpenGLGraphics::mIsByteColor
private

Definition at line 100 of file mobileopenglgraphics.h.

Referenced by restoreColor(), and setColorAlpha().

◆ mMaxVertices

int MobileOpenGLGraphics::mMaxVertices
private

◆ mShortVertArray

GLshort* MobileOpenGLGraphics::mShortVertArray
private

◆ mShortVertArrayCached

GLshort* MobileOpenGLGraphics::mShortVertArrayCached
private

◆ mTexture

bool MobileOpenGLGraphics::mTexture
private

◆ mTextureBinded

GLuint MobileOpenGLGraphics::mTextureBinded = 0
static

Definition at line 49 of file mobileopenglgraphics.h.

Referenced by bindTexture(), and disableTexturingAndBlending().

◆ mVpCached

int MobileOpenGLGraphics::mVpCached
private

Definition at line 97 of file mobileopenglgraphics.h.

Referenced by completeCache(), drawImageCached(), and drawPatternCached().


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