ManaPlus
Public Types | Public Member Functions | Static Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends
Graphics Class Referenceabstract

#include <graphics.h>

Inheritance diagram for Graphics:
ImegeGraphics MobileOpenGL2Graphics MobileOpenGLGraphics ModernOpenGLGraphics NormalOpenGLGraphics NullOpenGLGraphics SafeOpenGLGraphics SDLGraphics SurfaceGraphics

Public Types

enum  Alignment { LEFT = 0, CENTER, RIGHT }
 

Public Member Functions

virtual ~Graphics ()
 
void setWindow (SDL_Surface *const window, const int width, const int height)
 
SDL_Surface * getWindow () const
 
void setSync (const bool sync)
 
bool getSync () const
 
virtual bool setVideoMode (const int w, const int h, const int scale, const int bpp, const bool fs, const bool hwaccel, const bool resize, const bool noFrame, const bool allowHighDPI)=0
 
bool setFullscreen (const bool fs)
 
virtual bool resizeScreen (const int width, const int height)
 
virtual void restoreContext ()
 
virtual void drawRescaledImage (const Image *const image, int dstX, int dstY, const int desiredWidth, const int desiredHeight)=0
 
virtual void drawPattern (const Image *const image, const int x, const int y, const int w, const int h)=0
 
virtual void drawRescaledPattern (const Image *const image, const int x, const int y, const int w, const int h, const int scaledWidth, const int scaledHeight)=0
 
virtual void drawImageRect (const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0
 
virtual void calcPattern (ImageVertexes *const vert, const Image *const image, const int x, const int y, const int w, const int h) const =0
 
virtual void calcPattern (ImageCollection *const vert, const Image *const image, const int x, const int y, const int w, const int h) const =0
 
virtual void calcTileVertexes (ImageVertexes *const vert, const Image *const image, int x, int y) const =0
 
virtual void calcTileSDL (ImageVertexes *const vert, int x, int y) const
 
virtual void drawTileVertexes (const ImageVertexes *const vert)=0
 
virtual void drawTileCollection (const ImageCollection *const vertCol)=0
 
virtual void calcTileCollection (ImageCollection *const vertCol, const Image *const image, int x, int y)=0
 
virtual void calcWindow (ImageCollection *const vertCol, const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0
 
virtual void fillRectangle (const Rect &rectangle)=0
 
virtual void updateScreen ()=0
 
void setWindowSize (const int width, const int height) A_CONST
 
int getWidth () const
 
int getHeight () const
 
int getMemoryUsage () const
 
virtual void drawNet (const int x1, const int y1, const int x2, const int y2, const int width, const int height)
 
ClipRectgetTopClip () const
 
void setRedraw (const bool n)
 
bool getRedraw () const
 
void setSecure (const bool n)
 
bool getSecure () const
 
int getBpp () const
 
bool getFullScreen () const
 
bool getHWAccel () const
 
bool getDoubleBuffer () const
 
RenderType getOpenGL () const
 
void setNoFrame (const bool n)
 
const std::string & getName () const
 
virtual void initArrays (const int vertCount)
 
virtual void setColor (const Color &color)
 
const ColorgetColor () const
 
virtual void drawImage (const Image *const image, int dstX, int dstY)=0
 
virtual void copyImage (const Image *const image, int dstX, int dstY)=0
 
virtual void drawImageCached (const Image *const image, int srcX, int srcY)=0
 
virtual void drawPatternCached (const Image *const image, const int x, const int y, const int w, const int h)=0
 
virtual void completeCache ()=0
 
int getScale () const
 
virtual bool isAllowScale () const
 
void setScale (int scale)
 
virtual void pushClipArea (const Rect &area)
 
virtual void popClipArea ()
 
virtual void drawLine (int x1, int y1, int x2, int y2)=0
 
virtual void drawRectangle (const Rect &rectangle)=0
 
virtual void createGLContext (const bool custom) A_CONST
 
virtual void drawPoint (int x, int y)=0
 
virtual void beginDraw ()
 
virtual void endDraw ()
 
virtual void clearScreen () const
 
virtual void deleteArrays ()
 
virtual void postInit ()
 
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 cleanUp ()
 

Data Fields

int mWidth
 
int mHeight
 
int mActualWidth
 
int mActualHeight
 

Protected Member Functions

 Graphics ()
 
void setMainFlags (const int w, const int h, const int scale, const int bpp, const bool fs, const bool hwaccel, const bool resize, const bool noFrame, const bool allowHighDPI)
 
int getOpenGLFlags () const
 
int getSoftwareFlags () const
 
bool setOpenGLMode ()
 
void updateMemoryInfo ()
 
bool videoInfo ()
 
void setOpenGLFlags ()
 

Protected Attributes

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

static void * mGLContext = 0
 

Friends

class OpenGLScreenshotHelper
 
class SdlScreenshotHelper
 

Detailed Description

A central point of control for graphics.

Definition at line 107 of file graphics.h.

Member Enumeration Documentation

◆ Alignment

Alignments for text drawing.

Enumerator
LEFT 
CENTER 
RIGHT 

Definition at line 128 of file graphics.h.

129  {
130  LEFT = 0,
131  CENTER,
132  RIGHT
133  };

Constructor & Destructor Documentation

◆ ~Graphics()

Graphics::~Graphics ( )
virtual

Destructor.

Definition at line 153 of file graphics.cpp.

References endDraw().

154 {
155  endDraw();
156 }
virtual void endDraw()
Definition: graphics.h:452

◆ Graphics()

Graphics::Graphics ( )
protected

Constructor.

Definition at line 122 of file graphics.cpp.

References mRect.

122  :
123  mWidth(0),
124  mHeight(0),
125  mActualWidth(0),
126  mActualHeight(0),
127  mClipStack(1000),
128  mWindow(nullptr),
129  mBpp(0),
130  mAlpha(false),
131  mFullscreen(false),
132  mHWAccel(false),
133  mRedraw(false),
134  mDoubleBuffer(false),
135  mRect(),
136  mSecure(false),
138  mEnableResize(false),
139  mNoFrame(false),
140  mAllowHighDPI(false),
141  mName("Unknown"),
142  mStartFreeMem(0),
143  mSync(false),
144  mScale(1),
145  mColor()
146 {
147  mRect.x = 0;
148  mRect.y = 0;
149  mRect.w = 0;
150  mRect.h = 0;
151 }
std::string mName
Definition: graphics.h:548
bool mRedraw
Definition: graphics.h:540
SDL_Surface * mWindow
Definition: graphics.h:522
RenderType mOpenGL
Definition: graphics.h:544
int mWidth
Definition: graphics.h:483
bool mHWAccel
Definition: graphics.h:539
bool mNoFrame
Definition: graphics.h:546
Color mColor
Definition: graphics.h:552
bool mSecure
Definition: graphics.h:543
bool mAlpha
Definition: graphics.h:537
int mActualHeight
Definition: graphics.h:486
int mHeight
Definition: graphics.h:484
bool mDoubleBuffer
Definition: graphics.h:541
bool mSync
Definition: graphics.h:550
SDL_Rect mRect
Definition: graphics.h:542
bool mEnableResize
Definition: graphics.h:545
bool mAllowHighDPI
Definition: graphics.h:547
bool mFullscreen
Definition: graphics.h:538
int mScale
Definition: graphics.h:551
int mStartFreeMem
Definition: graphics.h:549
MStack< ClipRect > mClipStack
Definition: graphics.h:520
int mActualWidth
Definition: graphics.h:485
int mBpp
Definition: graphics.h:536

Member Function Documentation

◆ beginDraw()

virtual void Graphics::beginDraw ( )
inlinevirtual

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 in ImegeGraphics, SurfaceGraphics, MobileOpenGL2Graphics, MobileOpenGLGraphics, ModernOpenGLGraphics, NormalOpenGLGraphics, NullOpenGLGraphics, SafeOpenGLGraphics, and SDLGraphics.

Definition at line 440 of file graphics.h.

Referenced by Client::initConfigListeners(), Client::initGraphics(), and resizeScreen().

441  { }

◆ calcPattern() [1/2]

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

◆ calcPattern() [2/2]

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

◆ calcTileCollection()

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

◆ calcTileSDL()

virtual void Graphics::calcTileSDL ( ImageVertexes *const  vert,
int  x,
int  y 
) const
inlinevirtual

◆ calcTileVertexes()

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

◆ calcWindow()

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

◆ cleanUp()

void Graphics::cleanUp ( )
static

Definition at line 158 of file graphics.cpp.

References mGLContext.

Referenced by Client::gameClear(), and Client::initConfigListeners().

159 {
160 #ifdef USE_SDL2
161  if (mRenderer)
162  {
163  SDL_DestroyRenderer(mRenderer);
164  mRenderer = nullptr;
165  }
166 #ifdef USE_OPENGL
167  if (mGLContext)
168  {
169  SDL_GL_DeleteContext(mGLContext);
170  mGLContext = nullptr;
171  }
172 #endif // USE_OPENGL
173 #endif // USE_SDL2
174 }
static void * mGLContext
Definition: graphics.h:532

◆ clearScreen()

virtual void Graphics::clearScreen ( ) const
inlinevirtual

◆ completeCache()

virtual void Graphics::completeCache ( )
pure virtual

◆ copyImage()

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

◆ createGLContext()

void Graphics::createGLContext ( const bool  custom)
virtual

Reimplemented in MobileOpenGL2Graphics, and ModernOpenGLGraphics.

Definition at line 417 of file graphics.cpp.

References mGLContext, and mWindow.

Referenced by MobileOpenGL2Graphics::createGLContext(), ModernOpenGLGraphics::createGLContext(), GraphicsManager::detectGraphics(), isAllowScale(), and setOpenGLMode().

418 {
419 #ifdef USE_SDL2
420  mGLContext = SDL_GL_CreateContext(mWindow);
421 #endif // USE_SDL2
422 }
SDL_Surface * mWindow
Definition: graphics.h:522
static void * mGLContext
Definition: graphics.h:532

◆ deleteArrays()

virtual void Graphics::deleteArrays ( )
inlinevirtual

◆ drawImage()

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

Blits an image onto the screen.

Returns
true if the image was blitted properly false otherwise.

Implemented in SurfaceGraphics, ImegeGraphics, MobileOpenGL2Graphics, MobileOpenGLGraphics, ModernOpenGLGraphics, NormalOpenGLGraphics, NullOpenGLGraphics, SafeOpenGLGraphics, and SDLGraphics.

Referenced by ExtendedListBox::draw(), ImageSprite::draw(), ItemShortcutContainer::draw(), SpellShortcutContainer::draw(), VirtShortcutContainer::draw(), OutfitWindow::draw(), ShopListBox::draw(), SimpleAnimation::draw(), Desktop::draw(), EquipmentWindow::draw(), Icon::draw(), DropDown::draw(), ItemContainer::draw(), ProgressBar::draw(), Text::draw(), MapItem::draw(), StaticBrowserBox::draw(), CheckBox::draw(), BrowserBox::draw(), TextField::draw(), Label::draw(), RadioButton::draw(), Window::draw(), Gui::draw(), Button::draw(), Minimap::draw2(), RadioButton::drawBox(), CheckBox::drawBox(), DropDown::drawButton(), ScrollArea::drawButton(), Being::drawCompound(), CompoundSprite::drawSimple(), Font::drawString(), getColor(), PRAGMA45(), AvatarListBox::safeDraw(), EmotePage::safeDraw(), SpellShortcutContainer::safeDraw(), ItemShortcutContainer::safeDraw(), VirtShortcutContainer::safeDraw(), OutfitWindow::safeDraw(), EquipmentWindow::safeDraw(), Icon::safeDraw(), ItemContainer::safeDraw(), ProgressBar::safeDraw(), Tab::safeDraw(), Slider::safeDraw(), Window::safeDraw(), TouchManager::safeDraw(), Button::safeDraw(), ShortcutContainer::safeDrawBackground(), TestLauncher::testBackend(), TestLauncher::testDraw(), TestLauncher::testFps2(), and TestLauncher::testTextures().

◆ drawImageCached()

virtual void Graphics::drawImageCached ( const Image *const  image,
int  srcX,
int  srcY 
)
pure virtual

◆ drawImageRect()

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

◆ drawLine()

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

◆ drawNet()

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

Reimplemented in SurfaceGraphics, ImegeGraphics, MobileOpenGL2Graphics, MobileOpenGLGraphics, ModernOpenGLGraphics, NormalOpenGLGraphics, NullOpenGLGraphics, and SafeOpenGLGraphics.

Definition at line 652 of file graphics.cpp.

References drawLine(), mWindow, restrict2, setWindowSize(), x, and y.

Referenced by calcTileSDL(), and TestLauncher::testDraw().

655 {
656  for (int y = y1; y < y2; y += height)
657  drawLine(x1, y, x2, y);
658 
659  for (int x = x1; x < x2; x += width)
660  drawLine(x, y1, x, y2);
661 }
virtual void drawLine(int x1, int y1, int x2, int y2)=0

◆ drawPattern()

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

◆ drawPatternCached()

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

◆ drawPoint()

virtual void Graphics::drawPoint ( int  x,
int  y 
)
pure virtual

Draws a single point/pixel.

Parameters
xThe x coordinate.
yThe y coordinate.

Implemented in SurfaceGraphics, ImegeGraphics, MobileOpenGL2Graphics, MobileOpenGLGraphics, ModernOpenGLGraphics, NormalOpenGLGraphics, NullOpenGLGraphics, SafeOpenGLGraphics, and SDLGraphics.

Referenced by isAllowScale(), and TestLauncher::testDraw().

◆ drawRectangle()

virtual void Graphics::drawRectangle ( const Rect rectangle)
pure virtual

◆ drawRescaledImage()

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

◆ drawRescaledPattern()

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

◆ drawTileCollection()

virtual void Graphics::drawTileCollection ( const ImageCollection *const  vertCol)
pure virtual

◆ drawTileVertexes()

virtual void Graphics::drawTileVertexes ( const ImageVertexes *const  vert)
pure virtual

◆ endDraw()

virtual void Graphics::endDraw ( )
inlinevirtual

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 in ImegeGraphics, SurfaceGraphics, MobileOpenGL2Graphics, MobileOpenGLGraphics, ModernOpenGLGraphics, NormalOpenGLGraphics, NullOpenGLGraphics, SafeOpenGLGraphics, and SDLGraphics.

Definition at line 452 of file graphics.h.

Referenced by resizeScreen(), and ~Graphics().

453  { }

◆ fillRectangle()

virtual void Graphics::fillRectangle ( const Rect rectangle)
pure virtual

◆ finalize() [1/2]

virtual void Graphics::finalize ( ImageCollection *const  col)
inlinevirtual

◆ finalize() [2/2]

virtual void Graphics::finalize ( ImageVertexes *const  vert)
inlinevirtual

Reimplemented in MobileOpenGL2Graphics, and ModernOpenGLGraphics.

Definition at line 468 of file graphics.h.

470  { }

◆ getBpp()

int Graphics::getBpp ( ) const
inline

Definition at line 295 of file graphics.h.

References mBpp.

Referenced by Actions::doSit().

296  { return mBpp; }
int mBpp
Definition: graphics.h:536

◆ getColor()

const Color& Graphics::getColor ( ) const
inline

◆ getDoubleBuffer()

bool Graphics::getDoubleBuffer ( ) const
inline

Definition at line 304 of file graphics.h.

References mDoubleBuffer.

Referenced by Actions::doSit().

305  { return mDoubleBuffer; }
bool mDoubleBuffer
Definition: graphics.h:541

◆ getFullScreen()

bool Graphics::getFullScreen ( ) const
inline

Definition at line 298 of file graphics.h.

References mFullscreen.

Referenced by Actions::doSit().

299  { return mFullscreen; }
bool mFullscreen
Definition: graphics.h:538

◆ getHeight()

int Graphics::getHeight ( ) const

Returns the height of the screen.

Definition at line 647 of file graphics.cpp.

References mHeight.

Referenced by calcTileSDL(), ChatWindow::ChatWindow(), Actions::doSit(), Minimap::draw2(), CharCreateDialog::setButtonsPosition(), setConfigDefaults2(), PopupMenu::showPopup(), Client::stateGame(), and Client::stateGame1().

648 {
649  return mHeight;
650 }
int mHeight
Definition: graphics.h:484

◆ getHWAccel()

bool Graphics::getHWAccel ( ) const
inline

Definition at line 301 of file graphics.h.

References mHWAccel.

Referenced by Actions::doSit().

302  { return mHWAccel; }
bool mHWAccel
Definition: graphics.h:539

◆ getMemoryUsage()

int Graphics::getMemoryUsage ( ) const

Definition at line 440 of file graphics.cpp.

References CAST_SIZE, GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, graphicsManager, Actions::info(), Logger::log(), logger, mStartFreeMem, restrict, restrict2, ServerCommandType::str, and GraphicsManager::supportExtension().

Referenced by calcTileSDL(), and TestLauncher::testTextures().

441 {
442 #ifdef USE_OPENGL
443  if (mStartFreeMem == 0)
444  return 0;
445 
446  if (graphicsManager.supportExtension("GL_NVX_gpu_memory_info"))
447  {
448  GLint val;
450  &val);
451  return mStartFreeMem - val;
452  }
453 #endif // USE_OPENGL
454  return 0;
455 }
bool supportExtension(const std::string &ext) const
int mStartFreeMem
Definition: graphics.h:549
#define GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX
Definition: graphics.cpp:104
GraphicsManager graphicsManager

◆ getName()

const std::string& Graphics::getName ( ) const
inline

Definition at line 313 of file graphics.h.

References mName.

Referenced by setMainFlags(), and UserAgent::update().

314  { return mName; }
std::string mName
Definition: graphics.h:548

◆ getOpenGL()

RenderType Graphics::getOpenGL ( ) const
inline

Definition at line 307 of file graphics.h.

References mOpenGL.

Referenced by Actions::doSit(), Game::Game(), setOpenGLMode(), and Game::slowLogic().

308  { return mOpenGL; }
RenderType mOpenGL
Definition: graphics.h:544

◆ getOpenGLFlags()

int Graphics::getOpenGLFlags ( ) const
protected

< Allow any video depth/pixel-format

< Create an OpenGL rendering context

< Surface is a full screen display

< This video mode may be resized

< No window caption or edge frame

Definition at line 241 of file graphics.cpp.

References mAllowHighDPI, mEnableResize, mFullscreen, and mNoFrame.

Referenced by setOpenGLMode().

242 {
243 #ifdef USE_OPENGL
244 
245 #ifdef USE_SDL2
246  int displayFlags = SDL_WINDOW_OPENGL;
247  if (mFullscreen)
248  displayFlags |= SDL_WINDOW_FULLSCREEN;
249 #if SDL_VERSION_ATLEAST(2, 0, 1)
250  if (mAllowHighDPI)
251  displayFlags |= SDL_WINDOW_ALLOW_HIGHDPI;
252 #endif // SDL_VERSION_ATLEAST(2, 0, 1)
253 #else // USE_SDL2
254 
255  int displayFlags = SDL_ANYFORMAT | SDL_OPENGL;
256 #endif // USE_SDL2
257 
258  if (mFullscreen)
259  {
260  displayFlags |= SDL_FULLSCREEN;
261  }
262  else
263  {
264  // Resizing currently not supported on Windows, where it would require
265  // reuploading all textures.
266 #if !defined(_WIN32)
267  if (mEnableResize)
268  displayFlags |= SDL_RESIZABLE;
269 #endif // !defined(_WIN32)
270  }
271 
272  if (mNoFrame)
273  displayFlags |= SDL_NOFRAME;
274 
275  return displayFlags;
276 #else // USE_OPENGL
277 
278  return 0;
279 #endif // USE_OPENGL
280 }
bool mNoFrame
Definition: graphics.h:546
bool mEnableResize
Definition: graphics.h:545
bool mAllowHighDPI
Definition: graphics.h:547
bool mFullscreen
Definition: graphics.h:538

◆ getRedraw()

bool Graphics::getRedraw ( ) const
inline

◆ getScale()

int Graphics::getScale ( ) const
inline

Definition at line 365 of file graphics.h.

References mScale.

Referenced by WindowManager::applyScale(), Gui::getMouseState(), and SDLInput::pushInput().

366  { return mScale; }
int mScale
Definition: graphics.h:551

◆ getSecure()

bool Graphics::getSecure ( ) const
inline

Definition at line 292 of file graphics.h.

References mSecure.

Referenced by AvatarListBox::draw(), and AvatarListBox::safeDraw().

293  { return mSecure; }
bool mSecure
Definition: graphics.h:543

◆ getSoftwareFlags()

int Graphics::getSoftwareFlags ( ) const
protected

< Allow any video depth/pixel-format

< Surface is in video memory

< Set up double-buffered video mode

< Surface is in system memory

< Surface is a full screen display

< This video mode may be resized

< No window caption or edge frame

Definition at line 388 of file graphics.cpp.

References mAllowHighDPI, mEnableResize, mFullscreen, mHWAccel, and mNoFrame.

Referenced by SDLGraphics::setVideoMode().

389 {
390 #ifdef USE_SDL2
391  int displayFlags = SDL_WINDOW_SHOWN;
392 #if SDL_VERSION_ATLEAST(2, 0, 1)
393  if (mAllowHighDPI)
394  displayFlags |= SDL_WINDOW_ALLOW_HIGHDPI;
395 #endif // SDL_VERSION_ATLEAST(2, 0, 1)
396 #else // USE_SDL2
397 
398  int displayFlags = SDL_ANYFORMAT;
399 
400  if (mHWAccel)
401  displayFlags |= SDL_HWSURFACE | SDL_DOUBLEBUF;
402  else
403  displayFlags |= SDL_SWSURFACE;
404 #endif // USE_SDL2
405 
406  if (mFullscreen)
407  displayFlags |= SDL_FULLSCREEN;
408  else if (mEnableResize)
409  displayFlags |= SDL_RESIZABLE;
410 
411  if (mNoFrame)
412  displayFlags |= SDL_NOFRAME;
413  return displayFlags;
414 }
bool mHWAccel
Definition: graphics.h:539
bool mNoFrame
Definition: graphics.h:546
bool mEnableResize
Definition: graphics.h:545
bool mAllowHighDPI
Definition: graphics.h:547
bool mFullscreen
Definition: graphics.h:538

◆ getSync()

bool Graphics::getSync ( ) const
inline

Definition at line 152 of file graphics.h.

References mSync, resizeScreen(), restrict2, setFullscreen(), and setVideoMode().

153  { return mSync; }
bool mSync
Definition: graphics.h:550

◆ getTopClip()

ClipRect& Graphics::getTopClip ( ) const
inline

Definition at line 280 of file graphics.h.

References mClipStack, and MStack< T >::top().

Referenced by StaticBrowserBox::draw(), BrowserBox::draw(), Button::draw(), TextField::drawCaret(), and ScrollArea::updateCalcFlag().

281  { return mClipStack.top(); }
MStack< ClipRect > mClipStack
Definition: graphics.h:520
T & top() const
Definition: mstack.h:72

◆ getWidth()

int Graphics::getWidth ( ) const

Returns the width of the screen.

Definition at line 642 of file graphics.cpp.

References mWidth.

Referenced by calcTileSDL(), CharacterDisplay::CharacterDisplay(), CharSelectDialog::CharSelectDialog(), ChatWindow::ChatWindow(), Actions::doSit(), Minimap::draw2(), Client::stateGame(), and Client::stateGame1().

643 {
644  return mWidth;
645 }
int mWidth
Definition: graphics.h:483

◆ getWindow()

SDL_Surface* Graphics::getWindow ( ) const
inline

◆ initArrays()

virtual void Graphics::initArrays ( const int  vertCount)
inlinevirtual

Reimplemented in MobileOpenGL2Graphics, MobileOpenGLGraphics, ModernOpenGLGraphics, NormalOpenGLGraphics, and NullOpenGLGraphics.

Definition at line 316 of file graphics.h.

Referenced by setOpenGLMode().

317  { }

◆ isAllowScale()

virtual bool Graphics::isAllowScale ( ) const
inlinevirtual

◆ popClipArea()

void Graphics::popClipArea ( )
virtual

◆ postInit()

virtual void Graphics::postInit ( )
inlinevirtual

◆ pushClipArea()

void Graphics::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 in ImegeGraphics, SurfaceGraphics, MobileOpenGL2Graphics, MobileOpenGLGraphics, ModernOpenGLGraphics, NormalOpenGLGraphics, NullOpenGLGraphics, SafeOpenGLGraphics, and SDLGraphics.

Definition at line 676 of file graphics.cpp.

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

Referenced by GuiTable::draw(), Gui::draw(), Minimap::draw2(), isAllowScale(), SafeOpenGLGraphics::pushClipArea(), ModernOpenGLGraphics::pushClipArea(), NormalOpenGLGraphics::pushClipArea(), MobileOpenGLGraphics::pushClipArea(), SDLGraphics::pushClipArea(), NullOpenGLGraphics::pushClipArea(), MobileOpenGL2Graphics::pushClipArea(), GuiTable::safeDraw(), and TestLauncher::testDraw().

677 {
678  // Ignore area with a negate width or height
679  // by simple pushing an empty clip area
680  // to the stack.
681  if (area.width < 0 || area.height < 0)
682  {
683  ClipRect &carea = mClipStack.push();
684  carea.x = 0;
685  carea.y = 0;
686  carea.width = 0;
687  carea.height = 0;
688  carea.xOffset = 0;
689  carea.yOffset = 0;
690  return;
691  }
692 
693  if (mClipStack.empty())
694  {
695  ClipRect &carea = mClipStack.push();
696  carea.x = area.x;
697  carea.y = area.y;
698  carea.width = area.width;
699  carea.height = area.height;
700  carea.xOffset = area.x;
701  carea.yOffset = area.y;
702  return;
703  }
704 
705  const ClipRect &top = mClipStack.top();
706  ClipRect &carea = mClipStack.push();
707  carea.x = area.x + top.xOffset;
708  carea.y = area.y + top.yOffset;
709  carea.width = area.width;
710  carea.height = area.height;
711  carea.xOffset = top.xOffset + area.x;
712  carea.yOffset = top.yOffset + area.y;
713 
714  // Clamp the pushed clip rectangle.
715  if (carea.x < top.x)
716  carea.x = top.x;
717 
718  if (carea.y < top.y)
719  carea.y = top.y;
720 
721  if (carea.x + carea.width > top.x + top.width)
722  {
723  carea.width = top.x + top.width - carea.x;
724 
725  if (carea.width < 0)
726  carea.width = 0;
727  }
728 
729  if (carea.y + carea.height > top.y + top.height)
730  {
731  carea.height = top.y + top.height - carea.y;
732 
733  if (carea.height < 0)
734  carea.height = 0;
735  }
736 }
int width
Definition: rect.h:218
int yOffset
Definition: cliprect.h:126
const Image *restrict const top
int x
Definition: rect.h:208
int xOffset
Definition: cliprect.h:121
int y
Definition: rect.h:213
int height
Definition: rect.h:223
T & push()
Definition: mstack.h:47
MStack< ClipRect > mClipStack
Definition: graphics.h:520
T & top() const
Definition: mstack.h:72
bool empty() const
Definition: mstack.h:87

◆ removeArray()

virtual void Graphics::removeArray ( const uint32_t  sz,
uint32_t *const  arr 
)
inlinevirtual

Reimplemented in MobileOpenGL2Graphics, and ModernOpenGLGraphics.

Definition at line 475 of file graphics.h.

Referenced by OpenGLGraphicsVertexes::clear().

478  { }

◆ resizeScreen()

bool Graphics::resizeScreen ( const int  width,
const int  height 
)
virtual

Resize the window to the specified size.

Definition at line 557 of file graphics.cpp.

References beginDraw(), CAST_S32, endDraw(), mActualHeight, mActualWidth, mAllowHighDPI, mBpp, mEnableResize, mFullscreen, mHeight, mHWAccel, mNoFrame, mOpenGL, mRect, mScale, mWidth, RENDER_SOFTWARE, screenResized(), and setVideoMode().

Referenced by getSync(), and WindowManager::resizeVideo().

559 {
560 #ifdef USE_SDL2
561  endDraw();
562 
563  mRect.w = CAST_S32(width / mScale);
564  mRect.h = CAST_S32(height / mScale);
565  mWidth = width / mScale;
566  mHeight = height / mScale;
567  mActualWidth = width;
568  mActualHeight = height;
569 
570 #ifdef USE_OPENGL
571  // +++ probably this way will not work in windows/mac
572  // Setup OpenGL
573  glViewport(0, 0, mActualWidth, mActualHeight);
574  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
575 #else // USE_OPENGL
576  // +++ need impliment resize in soft mode
577 #endif // USE_OPENGL
578 
579  screenResized();
580  beginDraw();
581  return true;
582 
583 #else // USE_SDL2
584 
585  const int prevWidth = mWidth;
586  const int prevHeight = mHeight;
587 
588  endDraw();
589 
590  bool success = true;
591 #ifdef __native_client__
592  if (mOpenGL != RENDER_SOFTWARE)
593  {
594  mRect.w = CAST_S32(width / mScale);
595  mRect.h = CAST_S32(height / mScale);
596  mWidth = width / mScale;
597  mHeight = height / mScale;
598  mActualWidth = width;
599  mActualHeight = height;
600 #ifdef USE_OPENGL
601  naclResizeBuffers(mActualWidth, mActualHeight);
602  glViewport(0, 0, mActualWidth, mActualHeight);
603 #endif // USE_OPENGL
604  }
605  else
606 #endif // __native_client__
607  {
608  success = setVideoMode(width, height,
609  mScale,
610  mBpp,
611  mFullscreen,
612  mHWAccel,
614  mNoFrame,
615  mAllowHighDPI);
616 
617  // If it didn't work, try to restore the previous size. If that didn't
618  // work either, bail out (but then we're in deep trouble).
619  if (!success)
620  {
621  if (!setVideoMode(prevWidth, prevHeight,
622  mScale,
623  mBpp,
624  mFullscreen,
625  mHWAccel,
627  mNoFrame,
628  mAllowHighDPI))
629  {
630  return false;
631  }
632  }
633  }
634 
635  screenResized();
636  beginDraw();
637 
638  return success;
639 #endif // USE_SDL2
640 }
virtual void endDraw()
Definition: graphics.h:452
RenderType mOpenGL
Definition: graphics.h:544
int mWidth
Definition: graphics.h:483
bool mHWAccel
Definition: graphics.h:539
bool mNoFrame
Definition: graphics.h:546
virtual void screenResized()
Definition: graphics.h:480
#define CAST_S32
Definition: cast.h:29
virtual void beginDraw()
Definition: graphics.h:440
int mActualHeight
Definition: graphics.h:486
int mHeight
Definition: graphics.h:484
SDL_Rect mRect
Definition: graphics.h:542
bool mEnableResize
Definition: graphics.h:545
bool mAllowHighDPI
Definition: graphics.h:547
bool mFullscreen
Definition: graphics.h:538
int mScale
Definition: graphics.h:551
virtual bool setVideoMode(const int w, const int h, const int scale, const int bpp, const bool fs, const bool hwaccel, const bool resize, const bool noFrame, const bool allowHighDPI)=0
int mActualWidth
Definition: graphics.h:485
int mBpp
Definition: graphics.h:536

◆ restoreContext()

virtual void Graphics::restoreContext ( )
inlinevirtual

◆ screenResized()

virtual void Graphics::screenResized ( )
inlinevirtual

Reimplemented in MobileOpenGL2Graphics, and ModernOpenGLGraphics.

Definition at line 480 of file graphics.h.

Referenced by resizeScreen().

481  { }

◆ setColor()

virtual void Graphics::setColor ( const Color color)
inlinevirtual

◆ setFullscreen()

bool Graphics::setFullscreen ( const bool  fs)

Set fullscreen mode.

Definition at line 541 of file graphics.cpp.

References mActualHeight, mActualWidth, mAllowHighDPI, mBpp, mEnableResize, mFullscreen, mHWAccel, mNoFrame, mScale, and setVideoMode().

Referenced by getSync(), and WindowManager::setFullScreen().

542 {
543  if (mFullscreen == fs)
544  return true;
545 
546  return setVideoMode(mActualWidth,
548  mScale,
549  mBpp,
550  fs,
551  mHWAccel,
553  mNoFrame,
554  mAllowHighDPI);
555 }
bool mHWAccel
Definition: graphics.h:539
bool mNoFrame
Definition: graphics.h:546
int mActualHeight
Definition: graphics.h:486
bool mEnableResize
Definition: graphics.h:545
bool mAllowHighDPI
Definition: graphics.h:547
bool mFullscreen
Definition: graphics.h:538
int mScale
Definition: graphics.h:551
virtual bool setVideoMode(const int w, const int h, const int scale, const int bpp, const bool fs, const bool hwaccel, const bool resize, const bool noFrame, const bool allowHighDPI)=0
int mActualWidth
Definition: graphics.h:485
int mBpp
Definition: graphics.h:536

◆ setMainFlags()

void Graphics::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 
)
protected

Definition at line 181 of file graphics.cpp.

References getName(), Logger::log(), logger, mActualHeight, mActualWidth, mAllowHighDPI, mBpp, mEnableResize, mFullscreen, mHWAccel, mNoFrame, and setScale().

Referenced by MobileOpenGL2Graphics::setVideoMode(), SDLGraphics::setVideoMode(), SafeOpenGLGraphics::setVideoMode(), NullOpenGLGraphics::setVideoMode(), NormalOpenGLGraphics::setVideoMode(), ModernOpenGLGraphics::setVideoMode(), and MobileOpenGLGraphics::setVideoMode().

189 {
190  logger->log("graphics backend: %s", getName().c_str());
191  logger->log("Setting video mode %dx%d %s",
192  w, h, fs ? "fullscreen" : "windowed");
193 
194  mBpp = bpp;
195  mFullscreen = fs;
196  mHWAccel = hwaccel;
197  mEnableResize = resize;
198  mNoFrame = noFrame;
199  mAllowHighDPI = allowHighDPI;
200  mActualWidth = w;
201  mActualHeight = h;
202  setScale(scale);
203 }
bool mHWAccel
Definition: graphics.h:539
bool mNoFrame
Definition: graphics.h:546
Logger * logger
Definition: logger.cpp:95
const std::string & getName() const
Definition: graphics.h:313
void setScale(int scale)
Definition: graphics.cpp:205
int mActualHeight
Definition: graphics.h:486
bool mEnableResize
Definition: graphics.h:545
bool mAllowHighDPI
Definition: graphics.h:547
bool mFullscreen
Definition: graphics.h:538
int mActualWidth
Definition: graphics.h:485
void log(const char *const log_text,...)
Definition: logger.cpp:243
int mBpp
Definition: graphics.h:536

◆ setNoFrame()

void Graphics::setNoFrame ( const bool  n)
inline

Definition at line 310 of file graphics.h.

References mNoFrame.

311  { mNoFrame = n; }
bool mNoFrame
Definition: graphics.h:546

◆ setOpenGLFlags()

void Graphics::setOpenGLFlags ( )
protected

Definition at line 747 of file graphics.cpp.

References GL_DEPTH_BOUNDS_TEST_EXT, GL_DEPTH_CLAMP, GL_POLYGON_SMOOTH, GL_RASTERIZER_DISCARD, GL_SAMPLE_MASK, and GL_TEXTURE_COMPRESSION_HINT_ARB.

Referenced by MobileOpenGL2Graphics::beginDraw(), SafeOpenGLGraphics::beginDraw(), NormalOpenGLGraphics::beginDraw(), ModernOpenGLGraphics::beginDraw(), and MobileOpenGLGraphics::beginDraw().

748 {
749  // here disable/enable probably need convert to mgl
750 
751  glEnable(GL_SCISSOR_TEST);
752 
753  glDisable(GL_MULTISAMPLE);
754  glDisable(GL_DITHER);
755  glDisable(GL_DEPTH_TEST);
756  glDisable(GL_LINE_SMOOTH);
757  glDisable(GL_POLYGON_SMOOTH);
758  glDisable(GL_STENCIL_TEST);
759  glDisable(GL_COLOR_LOGIC_OP);
760  glDisable(GL_DEPTH_BOUNDS_TEST_EXT);
761  glDisable(GL_DEPTH_CLAMP);
762  glDisable(GL_RASTERIZER_DISCARD);
763  glDisable(GL_SAMPLE_MASK);
764 
765 #ifndef ANDROID
766 #ifndef __MINGW32__
767  glHint(GL_TEXTURE_COMPRESSION_HINT, GL_FASTEST);
768 #endif // __MINGW32__
769 #endif // ANDROID
770 
771  glHint(GL_TEXTURE_COMPRESSION_HINT_ARB, GL_FASTEST);
772 
773  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
774 }
#define GL_DEPTH_CLAMP
Definition: mgldefines.h:103
#define GL_TEXTURE_COMPRESSION_HINT_ARB
Definition: mgldefines.h:117
#define GL_SAMPLE_MASK
Definition: mgldefines.h:105
#define GL_POLYGON_SMOOTH
Definition: mgldefines.h:109
#define GL_RASTERIZER_DISCARD
Definition: mgldefines.h:104
#define GL_DEPTH_BOUNDS_TEST_EXT
Definition: mgldefines.h:113

◆ setOpenGLMode()

bool Graphics::setOpenGLMode ( )
protected

Definition at line 282 of file graphics.cpp.

References CAST_S32, CAST_U16, config, createGLContext(), GraphicsManager::createWindow(), Configuration::getBoolValue(), OpenGLImageHelper::getInternalTextureType(), GraphicsManager::getMaxVertices(), getOpenGL(), getOpenGLFlags(), GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, GL_TEXTURE_RECTANGLE_ARB, graphicsManager, initArrays(), GraphicsManager::initOpenGL(), GraphicsManager::isUseTextureSampler(), Logger::log(), Logger::log1(), logger, GraphicsManager::logVersion(), mActualHeight, mActualWidth, mBpp, mRect, mScale, mSync, OpenGLImageHelper::mTextureSize, SafeOpenGLImageHelper::mTextureSize, OpenGLImageHelper::mTextureType, SafeOpenGLImageHelper::mTextureType, mWindow, RENDER_GLES2_OPENGL, RENDER_GLES_OPENGL, RENDER_MODERN_OPENGL, GraphicsManager::setGLVersion(), GraphicsManager::supportExtension(), updateMemoryInfo(), GraphicsManager::updateTextureCompressionFormat(), GraphicsManager::updateTextureFormat(), and videoInfo().

Referenced by MobileOpenGL2Graphics::setVideoMode(), SafeOpenGLGraphics::setVideoMode(), NullOpenGLGraphics::setVideoMode(), NormalOpenGLGraphics::setVideoMode(), ModernOpenGLGraphics::setVideoMode(), and MobileOpenGLGraphics::setVideoMode().

283 {
284 #ifdef USE_OPENGL
285  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
288  mBpp, getOpenGLFlags())) == nullptr)
289  {
290  logger->log("Window/context creation failed");
291  mRect.w = 0;
292  mRect.h = 0;
293  return false;
294  }
295 
296 #if defined(USE_X11)
297  Glx::initFunctions();
298 #endif // defined(USE_X11)
299 #ifdef __native_client__
300  NaclGles::initGles();
301 #endif // __native_client__
302 
303 #ifdef USE_SDL2
304  int w1 = 0;
305  int h1 = 0;
306  SDL_GetWindowSize(mWindow, &w1, &h1);
307  mRect.w = CAST_S32(w1 / mScale);
308  mRect.h = CAST_S32(h1 / mScale);
309 
310  createGLContext(config.getBoolValue("openglContext"));
311 #else // USE_SDL2
312 
313  createGLContext(config.getBoolValue("openglContext"));
314  mRect.w = CAST_U16(mWindow->w / mScale);
315  mRect.h = CAST_U16(mWindow->h / mScale);
316 
317 #endif // USE_SDL2
318 
319 #ifdef __APPLE__
320  if (mSync)
321  {
322  const GLint VBL = 1;
323  CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL);
324  }
325 #endif // __APPLE__
326 
329 
330  // Setup OpenGL
331  glViewport(0, 0, mActualWidth, mActualHeight);
332  int gotDoubleBuffer = 0;
333  SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &gotDoubleBuffer);
334  logger->log("Using OpenGL %s double buffering.",
335  (gotDoubleBuffer != 0 ? "with" : "without"));
336 
342 
343  GLint texSize;
344  bool rectTex = graphicsManager.supportExtension(
345  "GL_ARB_texture_rectangle") ||
346  graphicsManager.supportExtension("GL_EXT_texture_rectangle");
347 
348  if (rectTex
353  && config.getBoolValue("rectangulartextures")
355  {
356  logger->log1("using GL_ARB_texture_rectangle");
358  glEnable(GL_TEXTURE_RECTANGLE_ARB);
359  glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &texSize);
361  logger->log("OpenGL texture size: %d pixels (rectangle textures)",
363 #ifndef ANDROID
366 #endif // ANDROID
367  }
368  else
369  {
370  glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize);
371  OpenGLImageHelper::mTextureType = GL_TEXTURE_2D;
373 #ifndef ANDROID
374  SafeOpenGLImageHelper::mTextureType = GL_TEXTURE_2D;
376 #endif // ANDROID
377 
378  logger->log("OpenGL texture size: %d pixels",
380  }
381  return videoInfo();
382 #else // USE_OPENGL
383 
384  return false;
385 #endif // USE_OPENGL
386 }
SDL_Surface * createWindow(const int w, const int h, const int bpp, const int flags)
void log1(const char *const log_text)
Definition: logger.cpp:222
SDL_Surface * mWindow
Definition: graphics.h:522
bool supportExtension(const std::string &ext) const
bool isUseTextureSampler() const
static void updateTextureFormat()
Configuration config
int getMaxVertices() const
Logger * logger
Definition: logger.cpp:95
#define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB
static int getInternalTextureType()
#define CAST_U16
Definition: cast.h:28
bool getBoolValue(const std::string &key) const
virtual void initArrays(const int vertCount)
Definition: graphics.h:316
#define CAST_S32
Definition: cast.h:29
int getOpenGLFlags() const
Definition: graphics.cpp:241
void logVersion() const
RenderType getOpenGL() const
Definition: graphics.h:307
virtual void createGLContext(const bool custom) A_CONST
Definition: graphics.cpp:417
int mActualHeight
Definition: graphics.h:486
bool mSync
Definition: graphics.h:550
SDL_Rect mRect
Definition: graphics.h:542
void updateTextureCompressionFormat() const
int mScale
Definition: graphics.h:551
bool videoInfo()
Definition: graphics.cpp:482
int mActualWidth
Definition: graphics.h:485
void log(const char *const log_text,...)
Definition: logger.cpp:243
void updateMemoryInfo()
Definition: graphics.cpp:425
GraphicsManager graphicsManager
#define GL_TEXTURE_RECTANGLE_ARB
int mBpp
Definition: graphics.h:536

◆ setRedraw()

void Graphics::setRedraw ( const bool  n)
inline

Definition at line 283 of file graphics.h.

References mRedraw.

Referenced by Window::draw(), and ScrollArea::draw().

284  { mRedraw = n; }
bool mRedraw
Definition: graphics.h:540

◆ setScale()

void Graphics::setScale ( int  scale)

Definition at line 205 of file graphics.cpp.

References isAllowScale(), Logger::log(), logger, mActualHeight, mActualWidth, mHeight, mRect, mScale, mWidth, and RectSize.

Referenced by WindowManager::applyScale(), isAllowScale(), and setMainFlags().

206 {
207  if (isAllowScale())
208  {
209  if (scale == 0)
210  scale = 1;
211  int scaleW = mActualWidth / scale;
212  int scaleH = mActualHeight / scale;
213  if (scaleW < 470)
214  {
215  scale = mActualWidth / 470;
216  if (scale < 1)
217  scale = 1;
218  scaleH = mActualHeight / scale;
219  }
220  if (scaleH < 320)
221  {
222  scale = mActualHeight / 320;
223  if (scale < 1)
224  scale = 1;
225  }
226  logger->log("set scale: %d", scale);
227  mScale = scale;
230  }
231  else
232  {
233  mScale = 1;
236  }
237  mRect.w = static_cast<RectSize>(mWidth);
238  mRect.h = static_cast<RectSize>(mHeight);
239 }
virtual bool isAllowScale() const
Definition: graphics.h:368
int mWidth
Definition: graphics.h:483
Logger * logger
Definition: logger.cpp:95
int mActualHeight
Definition: graphics.h:486
int mHeight
Definition: graphics.h:484
SDL_Rect mRect
Definition: graphics.h:542
#define RectSize
Definition: graphics.h:94
int mScale
Definition: graphics.h:551
int mActualWidth
Definition: graphics.h:485
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ setSecure()

void Graphics::setSecure ( const bool  n)
inline

Definition at line 289 of file graphics.h.

References mSecure.

Referenced by Game::createScreenshot().

290  { mSecure = n; }
bool mSecure
Definition: graphics.h:543

◆ setSync()

void Graphics::setSync ( const bool  sync)

Sets whether vertical refresh syncing is enabled. Takes effect after the next call to setVideoMode(). Only implemented on MacOS for now.

Definition at line 176 of file graphics.cpp.

References mSync.

Referenced by getWindow().

177 {
178  mSync = sync;
179 }
bool mSync
Definition: graphics.h:550

◆ setVideoMode()

virtual bool Graphics::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 
)
pure virtual

◆ setWindow()

void Graphics::setWindow ( SDL_Surface *const  window,
const int  width,
const int  height 
)
inline

Definition at line 135 of file graphics.h.

References mRect, mWindow, and RectSize.

Referenced by GraphicsManager::detectGraphics().

137  {
138  mWindow = window;
139  mRect.w = static_cast<RectSize>(width);
140  mRect.h = static_cast<RectSize>(height);
141  }
SDL_Surface * mWindow
Definition: graphics.h:522
SDL_Rect mRect
Definition: graphics.h:542
#define RectSize
Definition: graphics.h:94

◆ setWindowSize()

void Graphics::setWindowSize ( const int  width,
const int  height 
)

Definition at line 670 of file graphics.cpp.

Referenced by Setup_Video::action(), calcTileSDL(), and drawNet().

672 {
673 }

◆ testDraw()

virtual void Graphics::testDraw ( )
inlinevirtual

Reimplemented in NormalOpenGLGraphics, MobileOpenGL2Graphics, ModernOpenGLGraphics, and SafeOpenGLGraphics.

Definition at line 472 of file graphics.h.

Referenced by TestLauncher::testFps2().

473  { }

◆ updateMemoryInfo()

void Graphics::updateMemoryInfo ( )
protected

Definition at line 425 of file graphics.cpp.

References GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, graphicsManager, Logger::log(), logger, mStartFreeMem, and GraphicsManager::supportExtension().

Referenced by setOpenGLMode().

426 {
427 #ifdef USE_OPENGL
428  if (mStartFreeMem != 0)
429  return;
430 
431  if (graphicsManager.supportExtension("GL_NVX_gpu_memory_info"))
432  {
434  &mStartFreeMem);
435  logger->log("free video memory: %d", mStartFreeMem);
436  }
437 #endif // USE_OPENGL
438 }
bool supportExtension(const std::string &ext) const
Logger * logger
Definition: logger.cpp:95
int mStartFreeMem
Definition: graphics.h:549
#define GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX
Definition: graphics.cpp:104
void log(const char *const log_text,...)
Definition: logger.cpp:243
GraphicsManager graphicsManager

◆ updateScreen()

virtual void Graphics::updateScreen ( )
pure virtual

◆ videoInfo()

bool Graphics::videoInfo ( )
protected

< Set up double-buffered video mode

< Set up double-buffered video mode

Definition at line 482 of file graphics.cpp.

References ImageHelper::dumpSurfaceFormat(), Actions::info(), Logger::log(), Logger::log1(), logger, mDoubleBuffer, mWindow, and restrict.

Referenced by setOpenGLMode(), and SDLGraphics::setVideoMode().

483 {
484  logger->log("SDL video info");
485 #ifdef USE_SDL2
486  logger->log("Using video driver: %s", SDL_GetCurrentVideoDriver());
487 
488  if (mRenderer)
489  {
490  SDL_RendererInfo info;
491  SDL_GetRendererInfo(mRenderer, &info);
492  dumpRendererInfo("Current SDL renderer name: %s", info);
493 
494  const int num = SDL_GetNumRenderDrivers();
495  logger->log("Known renderers");
496  for (int f = 0; f < num; f ++)
497  {
498  if (!SDL_GetRenderDriverInfo(f, &info))
499  dumpRendererInfo("renderer name: %s", info);
500  }
501  }
502 #else // USE_SDL2
503 
504  char videoDriverName[65];
505  if (SDL_VideoDriverName(videoDriverName, 64) != nullptr)
506  logger->log("Using video driver: %s", videoDriverName);
507  else
508  logger->log1("Using video driver: unknown");
509  mDoubleBuffer = ((mWindow->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF);
510  logger->log("Double buffer mode: %s", mDoubleBuffer ? "yes" : "no");
511 
513 
514  const SDL_VideoInfo *restrict const vi = SDL_GetVideoInfo();
515  if (vi == nullptr)
516  return false;
517 
518  logger->log("Possible to create hardware surfaces: %s",
519  ((vi->hw_available) != 0u ? "yes" : "no"));
520  logger->log("Window manager available: %s",
521  ((vi->wm_available) != 0u ? "yes" : "no"));
522  logger->log("Accelerated hardware to hardware blits: %s",
523  ((vi->blit_hw) != 0u ? "yes" : "no"));
524  logger->log("Accelerated hardware to hardware colorkey blits: %s",
525  ((vi->blit_hw_CC) != 0u ? "yes" : "no"));
526  logger->log("Accelerated hardware to hardware alpha blits: %s",
527  ((vi->blit_hw_A) != 0u ? "yes" : "no"));
528  logger->log("Accelerated software to hardware blits: %s",
529  ((vi->blit_sw) != 0u ? "yes" : "no"));
530  logger->log("Accelerated software to hardware colorkey blits: %s",
531  ((vi->blit_sw_CC) != 0u ? "yes" : "no"));
532  logger->log("Accelerated software to hardware alpha blits: %s",
533  ((vi->blit_sw_A) != 0u ? "yes" : "no"));
534  logger->log("Accelerated color fills: %s",
535  ((vi->blit_fill) != 0u ? "yes" : "no"));
536 #endif // USE_SDL2
537 
538  return true;
539 }
void log1(const char *const log_text)
Definition: logger.cpp:222
SDL_Surface * mWindow
Definition: graphics.h:522
Logger * logger
Definition: logger.cpp:95
bool info(InputEvent &event)
Definition: commands.cpp:56
bool mDoubleBuffer
Definition: graphics.h:541
#define restrict
Definition: localconsts.h:176
void log(const char *const log_text,...)
Definition: logger.cpp:243
static void dumpSurfaceFormat(const SDL_Surface *const image)

Friends And Related Function Documentation

◆ OpenGLScreenshotHelper

friend class OpenGLScreenshotHelper
friend

Definition at line 111 of file graphics.h.

◆ SdlScreenshotHelper

friend class SdlScreenshotHelper
friend

Definition at line 114 of file graphics.h.

Field Documentation

◆ mActualHeight

int Graphics::mActualHeight

◆ mActualWidth

int Graphics::mActualWidth

◆ mAllowHighDPI

bool Graphics::mAllowHighDPI
protected

◆ mAlpha

bool Graphics::mAlpha
protected

◆ mBpp

int Graphics::mBpp
protected

Definition at line 536 of file graphics.h.

Referenced by getBpp(), resizeScreen(), setFullscreen(), setMainFlags(), and setOpenGLMode().

◆ mClipStack

MStack<ClipRect> Graphics::mClipStack
protected

Holds the clip area stack.

Definition at line 520 of file graphics.h.

Referenced by MobileOpenGL2Graphics::calcPatternInline(), ModernOpenGLGraphics::calcPatternInline(), SDLGraphics::calcPatternInline(), SDLGraphics::calcTileSDL(), MobileOpenGL2Graphics::calcTileVertexesInline(), ModernOpenGLGraphics::calcTileVertexesInline(), SDLGraphics::drawHLine(), SDLGraphics::drawImageCached(), MobileOpenGL2Graphics::drawImageInline(), ModernOpenGLGraphics::drawImageInline(), SDLGraphics::drawImageInline(), MobileOpenGL2Graphics::drawLine(), ModernOpenGLGraphics::drawLine(), MobileOpenGL2Graphics::drawNet(), ModernOpenGLGraphics::drawNet(), SDLGraphics::drawPatternCached(), SDLGraphics::drawPatternInline(), ModernOpenGLGraphics::drawPatternInline(), MobileOpenGL2Graphics::drawPatternInline(), SDLGraphics::drawPoint(), MobileOpenGL2Graphics::drawPoint(), ModernOpenGLGraphics::drawPoint(), MobileOpenGL2Graphics::drawRectangle(), ModernOpenGLGraphics::drawRectangle(), SDLGraphics::drawRescaledImage(), MobileOpenGL2Graphics::drawRescaledImage(), ModernOpenGLGraphics::drawRescaledImage(), SDLGraphics::drawRescaledPattern(), ModernOpenGLGraphics::drawRescaledPattern(), MobileOpenGL2Graphics::drawRescaledPattern(), SDLGraphics::drawVLine(), SDLGraphics::fillRectangle(), MobileOpenGL2Graphics::fillRectangle(), ModernOpenGLGraphics::fillRectangle(), getTopClip(), NormalOpenGLGraphics::popClipArea(), NullOpenGLGraphics::popClipArea(), MobileOpenGLGraphics::popClipArea(), MobileOpenGL2Graphics::popClipArea(), SafeOpenGLGraphics::popClipArea(), ModernOpenGLGraphics::popClipArea(), SDLGraphics::popClipArea(), popClipArea(), NormalOpenGLGraphics::pushClipArea(), SDLGraphics::pushClipArea(), ModernOpenGLGraphics::pushClipArea(), MobileOpenGLGraphics::pushClipArea(), NullOpenGLGraphics::pushClipArea(), MobileOpenGL2Graphics::pushClipArea(), SafeOpenGLGraphics::pushClipArea(), and pushClipArea().

◆ mColor

Color Graphics::mColor
protected

◆ mDoubleBuffer

bool Graphics::mDoubleBuffer
protected

Definition at line 541 of file graphics.h.

Referenced by getDoubleBuffer(), SDLGraphics::updateScreen(), and videoInfo().

◆ mEnableResize

bool Graphics::mEnableResize
protected

◆ mFullscreen

bool Graphics::mFullscreen
protected

◆ mGLContext

void * Graphics::mGLContext = 0
staticprotected

Definition at line 532 of file graphics.h.

Referenced by cleanUp(), ModernOpenGLGraphics::createGLContext(), and createGLContext().

◆ mHeight

int Graphics::mHeight

◆ mHWAccel

bool Graphics::mHWAccel
protected

Definition at line 539 of file graphics.h.

Referenced by getHWAccel(), getSoftwareFlags(), resizeScreen(), setFullscreen(), and setMainFlags().

◆ mName

std::string Graphics::mName
protected

◆ mNoFrame

bool Graphics::mNoFrame
protected

◆ mOpenGL

RenderType Graphics::mOpenGL
protected

◆ mRect

SDL_Rect Graphics::mRect
protected

◆ mRedraw

bool Graphics::mRedraw
protected

Definition at line 540 of file graphics.h.

Referenced by getRedraw(), and setRedraw().

◆ mScale

int Graphics::mScale
protected

◆ mSecure

bool Graphics::mSecure
protected

Definition at line 543 of file graphics.h.

Referenced by getSecure(), and setSecure().

◆ mStartFreeMem

int Graphics::mStartFreeMem
protected

Definition at line 549 of file graphics.h.

Referenced by getMemoryUsage(), and updateMemoryInfo().

◆ mSync

bool Graphics::mSync
protected

Definition at line 550 of file graphics.h.

Referenced by getSync(), setOpenGLMode(), and setSync().

◆ mWidth

int Graphics::mWidth

◆ mWindow

SDL_Surface* Graphics::mWindow
protected

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