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

#include <safeopenglgraphics.h>

Inheritance diagram for SafeOpenGLGraphics:
Graphics

Public Member Functions

 SafeOpenGLGraphics ()
 
 ~SafeOpenGLGraphics ()
 
void testDraw ()
 
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 setColor (const Color &color)
 
- 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
 
virtual void initArrays (const int vertCount)
 
const ColorgetColor () const
 
int getScale () const
 
void setScale (int scale)
 
virtual void createGLContext (const bool custom)
 
virtual void postInit ()
 
virtual void finalize (ImageCollection *const col)
 
virtual void finalize (ImageVertexes *const vert)
 
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 ()
 
- 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

bool mTexture
 
bool mIsByteColor
 
Color mByteColor
 
float mFloatColor
 
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 50 of file safeopenglgraphics.h.

Constructor & Destructor Documentation

◆ SafeOpenGLGraphics()

SafeOpenGLGraphics::SafeOpenGLGraphics ( )

Definition at line 41 of file safeopenglgraphics.cpp.

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

41  :
42  mTexture(false),
43  mIsByteColor(false),
44  mByteColor(),
45  mFloatColor(1.0F),
46  mColorAlpha(false),
47  mFbo()
48 {
50  mName = "safe OpenGL";
51 }
std::string mName
Definition: graphics.h:548
RenderType mOpenGL
Definition: graphics.h:544

◆ ~SafeOpenGLGraphics()

SafeOpenGLGraphics::~SafeOpenGLGraphics ( )

Definition at line 53 of file safeopenglgraphics.cpp.

54 {
55 }

Member Function Documentation

◆ beginDraw()

void SafeOpenGLGraphics::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 522 of file safeopenglgraphics.cpp.

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

523 {
524  glMatrixMode(GL_TEXTURE);
525  glLoadIdentity();
526 
527  glMatrixMode(GL_PROJECTION);
528  glLoadIdentity();
529 
530  glOrtho(0.0, static_cast<double>(mRect.w),
531  static_cast<double>(mRect.h),
532  0.0, -1.0, 1.0);
533 
534  glMatrixMode(GL_MODELVIEW);
535  glLoadIdentity();
536 
537  setOpenGLFlags();
538  glDisable(GL_LIGHTING);
539  glDisable(GL_FOG);
540  glDisable(GL_COLOR_MATERIAL);
541 
542  glShadeModel(GL_FLAT);
543 
544  pushClipArea(Rect(0, 0, mRect.w, mRect.h));
545 }
Definition: rect.h:72
SDL_Rect mRect
Definition: graphics.h:542
void setOpenGLFlags()
Definition: graphics.cpp:747
void pushClipArea(const Rect &area)

◆ bindTexture()

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

Definition at line 708 of file safeopenglgraphics.cpp.

References mTextureBinded.

Referenced by OpenGLImageHelper::bindTexture(), SafeOpenGLImageHelper::bindTexture(), drawImageCached(), drawImageInline(), drawPatternCached(), drawPatternInline(), drawRescaledImage(), and drawRescaledPattern().

710 {
711  if (mTextureBinded != texture)
712  {
713  mTextureBinded = texture;
714  glBindTexture(target, texture);
715  }
716 }
static GLuint mTextureBinded

◆ calcImageRect()

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

Definition at line 754 of file safeopenglgraphics.cpp.

◆ calcPattern() [1/2]

void SafeOpenGLGraphics::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 449 of file safeopenglgraphics.cpp.

457 {
458 }

◆ calcPattern() [2/2]

void SafeOpenGLGraphics::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 472 of file safeopenglgraphics.cpp.

480 {
481 }

◆ calcPatternInline()

void SafeOpenGLGraphics::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 460 of file safeopenglgraphics.cpp.

469 {
470 }

◆ calcTileCollection()

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

Implements Graphics.

Definition at line 422 of file safeopenglgraphics.cpp.

428 {
429 }

◆ calcTileVertexes()

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

Implements Graphics.

Definition at line 431 of file safeopenglgraphics.cpp.

437 {
438 }

◆ calcTileVertexesInline()

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

Definition at line 440 of file safeopenglgraphics.cpp.

446 {
447 }

◆ calcWindow()

void SafeOpenGLGraphics::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 513 of file safeopenglgraphics.cpp.

519 {
520 }

◆ clearScreen()

void SafeOpenGLGraphics::clearScreen ( ) const
virtual

Reimplemented from Graphics.

Definition at line 741 of file safeopenglgraphics.cpp.

742 {
743  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
744 }

◆ completeCache()

void SafeOpenGLGraphics::completeCache ( )
virtual

Implements Graphics.

Definition at line 295 of file safeopenglgraphics.cpp.

296 {
297 }

◆ copyImage()

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

Implements Graphics.

Definition at line 202 of file safeopenglgraphics.cpp.

References drawImageInline().

204 {
205  drawImageInline(image, dstX, dstY);
206 }
void drawImageInline(const Image *const image, int dstX, int dstY) A_INLINE

◆ deleteArrays()

void SafeOpenGLGraphics::deleteArrays ( )
virtual

Reimplemented from Graphics.

Definition at line 57 of file safeopenglgraphics.cpp.

58 {
59 }

◆ disableTexturingAndBlending()

void SafeOpenGLGraphics::disableTexturingAndBlending ( )
protected

Definition at line 665 of file safeopenglgraphics.cpp.

References Graphics::mAlpha, mColorAlpha, mTexture, mTextureBinded, and SafeOpenGLImageHelper::mTextureType.

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

666 {
667  mTextureBinded = 0;
668  if (mAlpha && !mColorAlpha)
669  {
670  glDisable(GL_BLEND);
671  mAlpha = false;
672  }
673  else if (!mAlpha && mColorAlpha)
674  {
675  glEnable(GL_BLEND);
676  mAlpha = true;
677  }
678 
679  if (mTexture)
680  {
682  mTexture = false;
683  }
684 }
static GLuint mTextureBinded
bool mAlpha
Definition: graphics.h:537

◆ drawImage()

void SafeOpenGLGraphics::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 177 of file safeopenglgraphics.cpp.

References drawImageInline().

179 {
180  drawImageInline(image, dstX, dstY);
181 }
void drawImageInline(const Image *const image, int dstX, int dstY) A_INLINE

◆ drawImageCached()

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

Implements Graphics.

Definition at line 238 of file safeopenglgraphics.cpp.

References bindTexture(), drawQuad(), enableTexturingAndBlending(), FUNC_BLOCK, SafeOpenGLImageHelper::mTextureType, setColorAlpha(), x, and y.

240 {
241  FUNC_BLOCK("Graphics::drawImageCached", 1)
242  if (image == nullptr)
243  return;
244 
245  setColorAlpha(image->mAlpha);
246  bindTexture(SafeOpenGLImageHelper::mTextureType, image->mGLImage);
248 
249  const SDL_Rect &bounds = image->mBounds;
250  // Draw a textured quad.
251  glBegin(GL_QUADS);
252  drawQuad(image, bounds.x, bounds.y, x, y, bounds.w, bounds.h);
253  glEnd();
254 }
void setColorAlpha(const float alpha) A_INLINE
static void drawQuad(const Image *image, const int srcX, const int srcY, const int dstX, const int dstY, const int width, const int height) A_INLINE
if(!vert) return
bool mAlpha
Definition: graphics.h:537
#define FUNC_BLOCK(name, id)
Definition: perfomance.h:80
static void bindTexture(const GLenum target, const GLuint texture)

◆ drawImageInline()

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

Definition at line 183 of file safeopenglgraphics.cpp.

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

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

185 {
186  FUNC_BLOCK("Graphics::drawImage", 1)
187  if (image == nullptr)
188  return;
189 
190  setColorAlpha(image->mAlpha);
191  bindTexture(SafeOpenGLImageHelper::mTextureType, image->mGLImage);
193 
194  const SDL_Rect &bounds = image->mBounds;
195  // Draw a textured quad.
196  glBegin(GL_QUADS);
197  drawQuad(image, bounds.x, bounds.y,
198  dstX, dstY, bounds.w, bounds.h);
199  glEnd();
200 }
void setColorAlpha(const float alpha) A_INLINE
static void drawQuad(const Image *image, const int srcX, const int srcY, const int dstX, const int dstY, const int width, const int height) A_INLINE
if(!vert) return
bool mAlpha
Definition: graphics.h:537
#define FUNC_BLOCK(name, id)
Definition: perfomance.h:80
static void bindTexture(const GLenum target, const GLuint texture)

◆ drawImageRect()

void SafeOpenGLGraphics::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 746 of file safeopenglgraphics.cpp.

◆ drawLine()

void SafeOpenGLGraphics::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 628 of file safeopenglgraphics.cpp.

References disableTexturingAndBlending(), and restoreColor().

630 {
632  restoreColor();
633 
634  glBegin(GL_LINES);
635  glVertex2f(static_cast<float>(x1) + 0.5F, static_cast<float>(y1) + 0.5F);
636  glVertex2f(static_cast<float>(x2) + 0.5F, static_cast<float>(y2) + 0.5F);
637  glEnd();
638 }
void restoreColor() A_INLINE

◆ drawNet()

void SafeOpenGLGraphics::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 602 of file safeopenglgraphics.cpp.

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

605 {
607  restoreColor();
608 
609  glBegin(GL_LINES);
610  for (int y = y1; y < y2; y += height)
611  {
612  glVertex2f(static_cast<float>(x1) + 0.5F,
613  static_cast<float>(y) + 0.5F);
614  glVertex2f(static_cast<float>(x2) + 0.5F,
615  static_cast<float>(y) + 0.5F);
616  }
617 
618  for (int x = x1; x < x2; x += width)
619  {
620  glVertex2f(static_cast<float>(x) + 0.5F,
621  static_cast<float>(y1) + 0.5F);
622  glVertex2f(static_cast<float>(x) + 0.5F,
623  static_cast<float>(y2) + 0.5F);
624  }
625  glEnd();
626 }
void restoreColor() A_INLINE

◆ drawPattern()

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

Implements Graphics.

Definition at line 328 of file safeopenglgraphics.cpp.

References drawPatternInline(), x, and y.

331 {
332  drawPatternInline(image, x, y, w, h);
333 }
void drawPatternInline(const Image *const image, const int x, const int y, const int w, const int h) A_INLINE

◆ drawPatternCached()

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

Implements Graphics.

Definition at line 256 of file safeopenglgraphics.cpp.

References bindTexture(), drawQuad(), enableTexturingAndBlending(), FUNC_BLOCK, SafeOpenGLImageHelper::mTextureType, setColorAlpha(), x, and y.

259 {
260  FUNC_BLOCK("Graphics::drawPatternCached", 1)
261  if (image == nullptr)
262  return;
263 
264  const SDL_Rect &imageRect = image->mBounds;
265  const int iw = imageRect.w;
266  const int ih = imageRect.h;
267  if (iw == 0 || ih == 0)
268  return;
269 
270  const int srcX = imageRect.x;
271  const int srcY = imageRect.y;
272 
273  setColorAlpha(image->mAlpha);
274  bindTexture(SafeOpenGLImageHelper::mTextureType, image->mGLImage);
276 
277  // Draw a set of textured rectangles
278  glBegin(GL_QUADS);
279 
280  for (int py = 0; py < h; py += ih)
281  {
282  const int height = (py + ih >= h) ? h - py : ih;
283  const int dstY = y + py;
284  for (int px = 0; px < w; px += iw)
285  {
286  int width = (px + iw >= w) ? w - px : iw;
287  int dstX = x + px;
288  drawQuad(image, srcX, srcY, dstX, dstY, width, height);
289  }
290  }
291 
292  glEnd();
293 }
void setColorAlpha(const float alpha) A_INLINE
static void drawQuad(const Image *image, const int srcX, const int srcY, const int dstX, const int dstY, const int width, const int height) A_INLINE
if(!vert) return
bool mAlpha
Definition: graphics.h:537
#define FUNC_BLOCK(name, id)
Definition: perfomance.h:80
static void bindTexture(const GLenum target, const GLuint texture)

◆ drawPatternInline()

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

Definition at line 335 of file safeopenglgraphics.cpp.

References bindTexture(), drawQuad(), enableTexturingAndBlending(), FUNC_BLOCK, SafeOpenGLImageHelper::mTextureType, setColorAlpha(), x, and y.

Referenced by drawPattern().

338 {
339  FUNC_BLOCK("Graphics::drawPattern", 1)
340  if (image == nullptr)
341  return;
342 
343  const SDL_Rect &imageRect = image->mBounds;
344  const int iw = imageRect.w;
345  const int ih = imageRect.h;
346  if (iw == 0 || ih == 0)
347  return;
348 
349  const int srcX = imageRect.x;
350  const int srcY = imageRect.y;
351 
352  setColorAlpha(image->mAlpha);
353  bindTexture(SafeOpenGLImageHelper::mTextureType, image->mGLImage);
355 
356  // Draw a set of textured rectangles
357  glBegin(GL_QUADS);
358 
359  for (int py = 0; py < h; py += ih)
360  {
361  const int height = (py + ih >= h) ? h - py : ih;
362  const int dstY = y + py;
363  for (int px = 0; px < w; px += iw)
364  {
365  int width = (px + iw >= w) ? w - px : iw;
366  int dstX = x + px;
367  drawQuad(image, srcX, srcY, dstX, dstY, width, height);
368  }
369  }
370 
371  glEnd();
372 }
void setColorAlpha(const float alpha) A_INLINE
static void drawQuad(const Image *image, const int srcX, const int srcY, const int dstX, const int dstY, const int width, const int height) A_INLINE
if(!vert) return
bool mAlpha
Definition: graphics.h:537
#define FUNC_BLOCK(name, id)
Definition: perfomance.h:80
static void bindTexture(const GLenum target, const GLuint texture)

◆ drawPoint()

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

Draws a single point/pixel.

Parameters
xThe x coordinate.
yThe y coordinate.

Implements Graphics.

Definition at line 592 of file safeopenglgraphics.cpp.

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

593 {
595  restoreColor();
596 
597  glBegin(GL_POINTS);
598  glVertex2i(x, y);
599  glEnd();
600 }
void restoreColor() A_INLINE

◆ drawRectangle() [1/2]

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

Definition at line 686 of file safeopenglgraphics.cpp.

References BLOCK_END, BLOCK_START, disableTexturingAndBlending(), and restoreColor().

688 {
689  BLOCK_START("Graphics::drawRectangle")
690  const float offset = filled ? 0 : 0.5F;
691 
693  restoreColor();
694 
695  glBegin(filled ? GL_QUADS : GL_LINE_LOOP);
696  glVertex2f(static_cast<float>(rect.x) + offset,
697  static_cast<float>(rect.y) + offset);
698  glVertex2f(static_cast<float>(rect.x + rect.width) - offset,
699  static_cast<float>(rect.y) + offset);
700  glVertex2f(static_cast<float>(rect.x + rect.width) - offset,
701  static_cast<float>(rect.y + rect.height) - offset);
702  glVertex2f(static_cast<float>(rect.x) + offset,
703  static_cast<float>(rect.y + rect.height) - offset);
704  glEnd();
706 }
#define BLOCK_START(name)
Definition: perfomance.h:78
#define BLOCK_END(name)
Definition: perfomance.h:79
void drawRectangle(const Rect &rect)
void restoreColor() A_INLINE

◆ drawRectangle() [2/2]

void SafeOpenGLGraphics::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 640 of file safeopenglgraphics.cpp.

Referenced by fillRectangle().

641 {
642  drawRectangle(rect, false);
643 }
void drawRectangle(const Rect &rect)

◆ drawRescaledImage()

void SafeOpenGLGraphics::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 299 of file safeopenglgraphics.cpp.

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

303 {
304  FUNC_BLOCK("Graphics::drawRescaledImage", 1)
305  if (image == nullptr)
306  return;
307 
308  const SDL_Rect &imageRect = image->mBounds;
309 
310  // Just draw the image normally when no resizing is necessary,
311  if (imageRect.w == desiredWidth && imageRect.h == desiredHeight)
312  {
313  drawImageInline(image, dstX, dstY);
314  return;
315  }
316 
317  setColorAlpha(image->mAlpha);
320 
321  // Draw a textured quad.
322  glBegin(GL_QUADS);
323  drawRescaledQuad(image, imageRect.x, imageRect.y, dstX, dstY,
324  imageRect.w, imageRect.h, desiredWidth, desiredHeight);
325  glEnd();
326 }
void setColorAlpha(const float alpha) A_INLINE
void drawImageInline(const Image *const image, int dstX, int dstY) A_INLINE
if(!vert) return
float mAlpha
Definition: image.h:212
#define FUNC_BLOCK(name, id)
Definition: perfomance.h:80
GLuint mGLImage
Definition: image.h:182
static void bindTexture(const GLenum target, const GLuint texture)
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

◆ drawRescaledPattern()

void SafeOpenGLGraphics::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 374 of file safeopenglgraphics.cpp.

References bindTexture(), drawRescaledQuad(), enableTexturingAndBlending(), SafeOpenGLImageHelper::mTextureType, setColorAlpha(), x, and y.

379 {
380  if (image == nullptr)
381  return;
382 
383  const int iw = scaledWidth;
384  const int ih = scaledHeight;
385  if (iw == 0 || ih == 0)
386  return;
387 
388  const SDL_Rect &imageRect = image->mBounds;
389  const int srcX = imageRect.x;
390  const int srcY = imageRect.y;
391 
392  setColorAlpha(image->mAlpha);
395 
396  // Draw a set of textured rectangles
397  glBegin(GL_QUADS);
398 
399  const float scaleFactorW = static_cast<float>(scaledWidth)
400  / image->getWidth();
401  const float scaleFactorH = static_cast<float>(scaledHeight)
402  / image->getHeight();
403 
404  for (int py = 0; py < h; py += ih)
405  {
406  const int height = (py + ih >= h) ? h - py : ih;
407  const int dstY = y + py;
408  for (int px = 0; px < w; px += iw)
409  {
410  int width = (px + iw >= w) ? w - px : iw;
411  int dstX = x + px;
412 
413  drawRescaledQuad(image, srcX, srcY, dstX, dstY,
414  width / scaleFactorW, height / scaleFactorH,
415  scaledWidth, scaledHeight);
416  }
417  }
418 
419  glEnd();
420 }
void setColorAlpha(const float alpha) A_INLINE
float mAlpha
Definition: image.h:212
GLuint mGLImage
Definition: image.h:182
static void bindTexture(const GLenum target, const GLuint texture)
int getWidth() const A_INLINE
Definition: image.h:116
SDL_Rect mBounds
Definition: image.h:210
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
int getHeight() const A_INLINE
Definition: image.h:122

◆ drawTileCollection()

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

Implements Graphics.

Definition at line 489 of file safeopenglgraphics.cpp.

492 {
493 }

◆ drawTileVertexes()

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

Implements Graphics.

Definition at line 483 of file safeopenglgraphics.cpp.

486 {
487 }

◆ dumpSettings()

static void SafeOpenGLGraphics::dumpSettings ( )
static

◆ enableTexturingAndBlending()

void SafeOpenGLGraphics::enableTexturingAndBlending ( )
protected

Definition at line 650 of file safeopenglgraphics.cpp.

References Graphics::mAlpha, mTexture, and SafeOpenGLImageHelper::mTextureType.

Referenced by drawImageCached(), drawImageInline(), drawPatternCached(), drawPatternInline(), drawRescaledImage(), and drawRescaledPattern().

651 {
652  if (!mTexture)
653  {
655  mTexture = true;
656  }
657 
658  if (!mAlpha)
659  {
660  glEnable(GL_BLEND);
661  mAlpha = true;
662  }
663 }
bool mAlpha
Definition: graphics.h:537

◆ endDraw()

void SafeOpenGLGraphics::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 547 of file safeopenglgraphics.cpp.

References popClipArea().

548 {
549  popClipArea();
550 }

◆ fillRectangle()

void SafeOpenGLGraphics::fillRectangle ( const Rect rect)
virtual

Implements Graphics.

Definition at line 645 of file safeopenglgraphics.cpp.

References drawRectangle().

646 {
647  drawRectangle(rect, true);
648 }
void drawRectangle(const Rect &rect)

◆ getMemoryUsage()

int SafeOpenGLGraphics::getMemoryUsage ( )

◆ isAllowScale()

bool SafeOpenGLGraphics::isAllowScale ( ) const
inlinevirtual

Reimplemented from Graphics.

Definition at line 40 of file safeopenglgraphics.h.

50  : public Graphics

◆ popClipArea()

void SafeOpenGLGraphics::popClipArea ( )
virtual

Removes the top most clip area from the stack.

Exceptions
Exceptionif the stack is empty.

Reimplemented from Graphics.

Definition at line 577 of file safeopenglgraphics.cpp.

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

Referenced by endDraw().

578 {
580 
581  if (mClipStack.empty())
582  return;
583 
584  glPopMatrix();
585  const ClipRect &clipArea = mClipStack.top();
586  glScissor(clipArea.x * mScale,
587  (mRect.h - clipArea.y - clipArea.height) * mScale,
588  clipArea.width * mScale,
589  clipArea.height * mScale);
590 }
int width
Definition: rect.h:218
virtual void popClipArea()
Definition: graphics.cpp:738
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

◆ pushClipArea()

void SafeOpenGLGraphics::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 552 of file safeopenglgraphics.cpp.

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

Referenced by beginDraw().

553 {
554  int transX = 0;
555  int transY = 0;
556 
557  if (!mClipStack.empty())
558  {
559  const ClipRect &clipArea = mClipStack.top();
560  transX = -clipArea.xOffset;
561  transY = -clipArea.yOffset;
562  }
563 
565 
566  const ClipRect &clipArea = mClipStack.top();
567 
568  glPushMatrix();
569  glTranslatef(static_cast<GLfloat>(transX + clipArea.xOffset),
570  static_cast<GLfloat>(transY + clipArea.yOffset), 0);
571  glScissor(clipArea.x * mScale,
572  (mRect.h - clipArea.y - clipArea.height) * mScale,
573  clipArea.width * mScale,
574  clipArea.height * mScale);
575 }
int width
Definition: rect.h:218
int yOffset
Definition: cliprect.h:126
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 SafeOpenGLGraphics::restoreColor ( )
inlineprivate

Definition at line 728 of file safeopenglgraphics.cpp.

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

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

729 {
730  if (mIsByteColor && mByteColor == mColor)
731  return;
732 
733  glColor4ub(static_cast<GLubyte>(mColor.r),
734  static_cast<GLubyte>(mColor.g),
735  static_cast<GLubyte>(mColor.b),
736  static_cast<GLubyte>(mColor.a));
737  mIsByteColor = true;
738  mByteColor = mColor;
739 }
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 SafeOpenGLGraphics::setColor ( const Color color)
inlinevirtual

Reimplemented from Graphics.

Definition at line 27 of file safeopenglgraphics.h.

50  : public Graphics

◆ setColorAlpha()

void SafeOpenGLGraphics::setColorAlpha ( const float  alpha)
inlineprivate

Definition at line 718 of file safeopenglgraphics.cpp.

References mFloatColor, and mIsByteColor.

Referenced by drawImageCached(), drawImageInline(), drawPatternCached(), drawPatternInline(), drawRescaledImage(), and drawRescaledPattern().

719 {
720  if (!mIsByteColor && mFloatColor == alpha)
721  return;
722 
723  glColor4f(1.0F, 1.0F, 1.0F, alpha);
724  mIsByteColor = false;
725  mFloatColor = alpha;
726 }

◆ setVideoMode()

bool SafeOpenGLGraphics::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 61 of file safeopenglgraphics.cpp.

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

69 {
70  setMainFlags(w, h,
71  scale,
72  bpp,
73  fs,
74  hwaccel,
75  resize,
76  noFrame,
77  allowHighDPI);
78 
79  return setOpenGLMode();
80 }
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 SafeOpenGLGraphics::testDraw ( )
virtual

Reimplemented from Graphics.

Definition at line 208 of file safeopenglgraphics.cpp.

References SafeOpenGLImageHelper::mTextureType.

209 {
210  if (SafeOpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
211  {
212  glBegin(GL_QUADS);
213  glTexCoord2f(0.0f, 0.781250f);
214  glVertex2i(0, 0);
215  glTexCoord2f(0.0f, 0.781250f);
216  glVertex2i(800, 0);
217  glTexCoord2f(0.0f, 0.585938f);
218  glVertex2i(800, 600);
219  glTexCoord2f(0.0f, 0.585938f);
220  glVertex2i(0, 600);
221  glEnd();
222  }
223  else
224  {
225  glBegin(GL_QUADS);
226  glTexCoord2i(0, 0);
227  glVertex2i(0, 0);
228  glTexCoord2i(800, 0);
229  glVertex2i(800, 0);
230  glTexCoord2i(800, 600);
231  glVertex2i(800, 600);
232  glTexCoord2i(0, 600);
233  glVertex2i(0, 600);
234  glEnd();
235  }
236 }

◆ updateScreen()

void SafeOpenGLGraphics::updateScreen ( )
virtual

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

Implements Graphics.

Definition at line 495 of file safeopenglgraphics.cpp.

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

496 {
497  BLOCK_START("Graphics::updateScreen")
498  glFlush();
499  glFinish();
500 #ifdef USE_SDL2
501  SDL_GL_SwapWindow(mWindow);
502 #else
503  SDL_GL_SwapBuffers();
504 #endif // USE_SDL2
505 #ifdef DEBUG_OPENGL
506  if (isGLNotNull(mglFrameTerminator))
507  mglFrameTerminator();
508 #endif // DEBUG_OPENGL
509 
510  BLOCK_END("Graphics::updateScreen")
511 }
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 SafeOpenGLGraphics::updateTextureFormat ( )

Field Documentation

◆ mByteColor

Color SafeOpenGLGraphics::mByteColor
private

Definition at line 73 of file safeopenglgraphics.h.

Referenced by restoreColor().

◆ mColorAlpha

bool SafeOpenGLGraphics::mColorAlpha
private

Definition at line 75 of file safeopenglgraphics.h.

Referenced by disableTexturingAndBlending().

◆ mFbo

FBOInfo SafeOpenGLGraphics::mFbo
private

Definition at line 76 of file safeopenglgraphics.h.

◆ mFloatColor

float SafeOpenGLGraphics::mFloatColor
private

Definition at line 74 of file safeopenglgraphics.h.

Referenced by setColorAlpha().

◆ mIsByteColor

bool SafeOpenGLGraphics::mIsByteColor
private

Definition at line 72 of file safeopenglgraphics.h.

Referenced by restoreColor(), and setColorAlpha().

◆ mTexture

bool SafeOpenGLGraphics::mTexture
private

Definition at line 71 of file safeopenglgraphics.h.

Referenced by disableTexturingAndBlending(), and enableTexturingAndBlending().

◆ mTextureBinded

GLuint SafeOpenGLGraphics::mTextureBinded = 0
static

Definition at line 49 of file safeopenglgraphics.h.

Referenced by bindTexture(), and disableTexturingAndBlending().


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