67 #include "render/graphics.h"
74 #if defined(USE_OPENGL) && defined(USE_X11)
83 #ifdef __native_client__
95 #include <OpenGL/OpenGL.h>
98 RENDER_OPENGL_MGLDEFINES_H
104 #ifndef GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX
105 #define GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX 0x9049
112 SDL_Renderer *
restrict Graphics::mRenderer =
nullptr;
135 mDoubleBuffer(false),
139 mEnableResize(false),
141 mAllowHighDPI(false),
164 SDL_DestroyRenderer(mRenderer);
192 logger->
log(
"Setting video mode %dx%d %s",
193 w, h, fs ?
"fullscreen" :
"windowed");
198 mEnableResize = resize;
200 mAllowHighDPI = allowHighDPI;
212 int scaleW = mActualWidth / scale;
213 int scaleH = mActualHeight / scale;
216 scale = mActualWidth / 470;
219 scaleH = mActualHeight / scale;
223 scale = mActualHeight / 320;
229 mWidth = mActualWidth / mScale;
230 mHeight = mActualHeight / mScale;
235 mWidth = mActualWidth;
236 mHeight = mActualHeight;
238 mRect.w =
static_cast<RectSize>(mWidth);
239 mRect.h =
static_cast<RectSize>(mHeight);
247 int displayFlags = SDL_WINDOW_OPENGL;
249 displayFlags |= SDL_WINDOW_FULLSCREEN;
250 #if SDL_VERSION_ATLEAST(2, 0, 1)
252 displayFlags |= SDL_WINDOW_ALLOW_HIGHDPI;
256 int displayFlags = SDL_ANYFORMAT | SDL_OPENGL;
261 displayFlags |= SDL_FULLSCREEN;
269 displayFlags |= SDL_RESIZABLE;
274 displayFlags |= SDL_NOFRAME;
286 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
291 logger->
log(
"Window/context creation failed");
298 Glx::initFunctions();
300 #ifdef __native_client__
301 NaclGles::initGles();
307 SDL_GetWindowSize(
mWindow, &w1, &h1);
324 CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL);
333 int gotDoubleBuffer = 0;
334 SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &gotDoubleBuffer);
335 logger->
log(
"Using OpenGL %s double buffering.",
336 (gotDoubleBuffer != 0 ?
"with" :
"without"));
346 "GL_ARB_texture_rectangle") ||
357 logger->
log1(
"using GL_ARB_texture_rectangle");
362 logger->
log(
"OpenGL texture size: %d pixels (rectangle textures)",
364 #if !defined(ANDROID) && !defined(__SWITCH__)
371 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize);
374 #if !defined(ANDROID) && !defined(__SWITCH__)
379 logger->
log(
"OpenGL texture size: %d pixels",
392 int displayFlags = SDL_WINDOW_SHOWN;
393 #if SDL_VERSION_ATLEAST(2, 0, 1)
395 displayFlags |= SDL_WINDOW_ALLOW_HIGHDPI;
399 int displayFlags = SDL_ANYFORMAT;
402 displayFlags |= SDL_HWSURFACE | SDL_DOUBLEBUF;
404 displayFlags |= SDL_SWSURFACE;
408 displayFlags |= SDL_FULLSCREEN;
410 displayFlags |= SDL_RESIZABLE;
413 displayFlags |= SDL_NOFRAME;
421 mGLContext = SDL_GL_CreateContext(mWindow);
459 void Graphics::dumpRendererInfo(
const char *
restrict const str,
465 if (
info.flags & SDL_RENDERER_SOFTWARE)
467 if (
info.flags & SDL_RENDERER_ACCELERATED)
469 if (
info.flags & SDL_RENDERER_PRESENTVSYNC)
471 if (
info.flags & SDL_RENDERER_TARGETTEXTURE)
474 info.max_texture_width,
475 info.max_texture_height);
478 for (
size_t f = 0; f < sz; f ++)
487 logger->
log(
"Using video driver: %s", SDL_GetCurrentVideoDriver());
491 SDL_RendererInfo
info;
492 SDL_GetRendererInfo(mRenderer, &
info);
493 dumpRendererInfo(
"Current SDL renderer name: %s",
info);
495 const int num = SDL_GetNumRenderDrivers();
497 for (
int f = 0; f < num; f ++)
499 if (!SDL_GetRenderDriverInfo(f, &
info))
500 dumpRendererInfo(
"renderer name: %s",
info);
505 char videoDriverName[65];
506 if (SDL_VideoDriverName(videoDriverName, 64) !=
nullptr)
507 logger->
log(
"Using video driver: %s", videoDriverName);
515 const SDL_VideoInfo *
restrict const vi = SDL_GetVideoInfo();
519 logger->
log(
"Possible to create hardware surfaces: %s",
520 ((vi->hw_available) != 0U ?
"yes" :
"no"));
521 logger->
log(
"Window manager available: %s",
522 ((vi->wm_available) != 0U ?
"yes" :
"no"));
523 logger->
log(
"Accelerated hardware to hardware blits: %s",
524 ((vi->blit_hw) != 0U ?
"yes" :
"no"));
525 logger->
log(
"Accelerated hardware to hardware colorkey blits: %s",
526 ((vi->blit_hw_CC) != 0U ?
"yes" :
"no"));
527 logger->
log(
"Accelerated hardware to hardware alpha blits: %s",
528 ((vi->blit_hw_A) != 0U ?
"yes" :
"no"));
529 logger->
log(
"Accelerated software to hardware blits: %s",
530 ((vi->blit_sw) != 0U ?
"yes" :
"no"));
531 logger->
log(
"Accelerated software to hardware colorkey blits: %s",
532 ((vi->blit_sw_CC) != 0U ?
"yes" :
"no"));
533 logger->
log(
"Accelerated software to hardware alpha blits: %s",
534 ((vi->blit_sw_A) != 0U ?
"yes" :
"no"));
535 logger->
log(
"Accelerated color fills: %s",
536 ((vi->blit_fill) != 0U ?
"yes" :
"no"));
544 if (mFullscreen == fs)
565 mRect.h =
CAST_S32(height / mScale);
566 mWidth = width / mScale;
567 mHeight = height / mScale;
568 mActualWidth = width;
569 mActualHeight = height;
574 glViewport(0, 0, mActualWidth, mActualHeight);
575 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
586 const int prevWidth = mWidth;
587 const int prevHeight = mHeight;
592 #ifdef __native_client__
596 mRect.h =
CAST_S32(height / mScale);
597 mWidth = width / mScale;
598 mHeight = height / mScale;
599 mActualWidth = width;
600 mActualHeight = height;
602 naclResizeBuffers(mActualWidth, mActualHeight);
603 glViewport(0, 0, mActualWidth, mActualHeight);
654 const int x2,
const int y2,
655 const int width,
const int height)
restrict2
657 for (
int y = y1;
y < y2;
y += height)
660 for (
int x = x1;
x < x2;
x += width)
668 SDL_SetWindowSize(mWindow, width, height);
682 if (area.width < 0 || area.height < 0)
684 ClipRect &carea = mClipStack.push();
694 if (mClipStack.empty())
696 ClipRect &carea = mClipStack.push();
699 carea.
width = area.width;
700 carea.
height = area.height;
707 ClipRect &carea = mClipStack.push();
708 carea.
x = area.x +
top.xOffset;
709 carea.
y = area.y +
top.yOffset;
710 carea.
width = area.width;
711 carea.
height = area.height;
752 glEnable(GL_SCISSOR_TEST);
754 glDisable(GL_MULTISAMPLE);
755 glDisable(GL_DITHER);
756 glDisable(GL_DEPTH_TEST);
757 glDisable(GL_LINE_SMOOTH);
759 glDisable(GL_STENCIL_TEST);
760 glDisable(GL_COLOR_LOGIC_OP);
768 glHint(GL_TEXTURE_COMPRESSION_HINT, GL_FASTEST);
774 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
bool getBoolValue(const std::string &key) const
static void updateTextureFormat()
bool supportExtension(const std::string &ext) const
void updateTextureCompressionFormat() const
static SDL_Surface * createWindow(const int w, const int h, const int bpp, const int flags)
bool isUseTextureSampler() const
int getMaxVertices() const
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)
RenderType getOpenGL() const
virtual void popClipArea()
void setSync(const bool sync)
virtual bool resizeScreen(const int width, const int height)
virtual void createGLContext(const bool custom)
MStack< ClipRect > mClipStack
bool setFullscreen(const bool fs)
void setWindowSize(const int width, const int height)
virtual void initArrays(const int vertCount)
int getMemoryUsage() const
virtual void pushClipArea(const Rect &area)
int getSoftwareFlags() const
virtual void drawNet(const int x1, const int y1, const int x2, const int y2, const int width, const int height)
int getOpenGLFlags() const
static void dumpSurfaceFormat(const SDL_Surface *const image)
void log(const char *const log_text,...)
void log1(const char *const log_text)
static int getInternalTextureType()
#define GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX
const Image *restrict const top
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) restrict2 override final
void endDraw() restrict2 override final
void drawLine(int x1, int y1, int x2, int y2) restrict2 override final
void beginDraw() restrict2 override final
GraphicsManager graphicsManager
#define GL_POLYGON_SMOOTH
#define GL_RASTERIZER_DISCARD
#define GL_TEXTURE_COMPRESSION_HINT_ARB
#define GL_DEPTH_BOUNDS_TEST_EXT
bool info(InputEvent &event)
const std::string & getName(const int id)
bool isAllowScale() const restrict2 noexcept 2 override final
#define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB
#define GL_TEXTURE_RECTANGLE_ARB