summaryrefslogtreecommitdiff
path: root/src/render
diff options
context:
space:
mode:
Diffstat (limited to 'src/render')
-rw-r--r--src/render/graphics.cpp20
-rw-r--r--src/render/graphics.h13
-rw-r--r--src/render/mglx.cpp2
-rw-r--r--src/render/mglx.h2
-rw-r--r--src/render/mglxinit.cpp2
-rw-r--r--src/render/mglxtypes.h5
-rw-r--r--src/render/modernopenglgraphics.cpp6
-rw-r--r--src/render/modernopenglgraphics.h3
8 files changed, 47 insertions, 6 deletions
diff --git a/src/render/graphics.cpp b/src/render/graphics.cpp
index 5bb90e753..5cb45e8ca 100644
--- a/src/render/graphics.cpp
+++ b/src/render/graphics.cpp
@@ -71,6 +71,8 @@
#include "graphicsmanager.h"
#include "logger.h"
+#include "render/mglxinit.h"
+
#include "resources/imagehelper.h"
#include "resources/openglimagehelper.h"
@@ -99,10 +101,10 @@ Graphics::Graphics() :
mWindow(nullptr),
#ifdef USE_SDL2
mRenderer(nullptr),
+#endif
#ifdef USE_OPENGL
mGLContext(nullptr),
#endif
-#endif
mBpp(0),
mAlpha(false),
mFullscreen(false),
@@ -252,11 +254,15 @@ bool Graphics::setOpenGLMode()
mActualWidth, mActualHeight,
mBpp, getOpenGLFlags())))
{
+ logger->log("Window/context creation failed");
mRect.w = 0;
mRect.h = 0;
return false;
}
+#if defined(USE_OPENGL) && defined(USE_X11)
+ Glx::initFunctions();
+#endif
#ifdef USE_SDL2
int w1 = 0;
int h1 = 0;
@@ -264,10 +270,10 @@ bool Graphics::setOpenGLMode()
mRect.w = static_cast<int32_t>(w1 / mScale);
mRect.h = static_cast<int32_t>(h1 / mScale);
- mGLContext = SDL_GL_CreateContext(mWindow);
-
+ createGLContext();
#else // USE_SDL2
+ createGLContext();
mRect.w = static_cast<uint16_t>(mWindow->w / mScale);
mRect.h = static_cast<uint16_t>(mWindow->h / mScale);
@@ -353,6 +359,14 @@ int Graphics::getSoftwareFlags() const
return displayFlags;
}
+#ifdef USE_OPENGL
+void Graphics::createGLContext()
+{
+#ifdef USE_SDL2
+ mGLContext = SDL_GL_CreateContext(mWindow);
+#endif
+}
+#endif
void Graphics::updateMemoryInfo()
{
diff --git a/src/render/graphics.h b/src/render/graphics.h
index 3100971fc..2c4bc57ec 100644
--- a/src/render/graphics.h
+++ b/src/render/graphics.h
@@ -496,6 +496,9 @@ class Graphics notfinal
bool videoInfo();
+#ifdef USE_OPENGL
+ virtual void createGLContext();
+#endif
/**
* Holds the clip area stack.
*/
@@ -505,10 +508,16 @@ class Graphics notfinal
#ifdef USE_SDL2
SDL_Renderer *mRenderer;
+#endif // USE_SDL2
#ifdef USE_OPENGL
+#ifdef USE_SDL2
SDL_GLContext mGLContext;
-#endif
-#endif
+#else // USE_SDL2
+
+ void *mGLContext;
+#endif // USE_SDL2
+#endif // USE_OPENGL
+
int mBpp;
bool mAlpha;
bool mFullscreen;
diff --git a/src/render/mglx.cpp b/src/render/mglx.cpp
index 4c51cba14..73beb959c 100644
--- a/src/render/mglx.cpp
+++ b/src/render/mglx.cpp
@@ -30,5 +30,7 @@ defName(glXCreateContext);
defName(glXGetCurrentContext);
defName(glXCreateContextAttribs);
defName(glXChooseFBConfig);
+defName(glXDestroyContext);
+defName(glXMakeCurrent);
#endif
diff --git a/src/render/mglx.h b/src/render/mglx.h
index ceb916b8d..2e0c93364 100644
--- a/src/render/mglx.h
+++ b/src/render/mglx.h
@@ -32,6 +32,8 @@ defNameE(glXCreateContext);
defNameE(glXGetCurrentContext);
defNameE(glXCreateContextAttribs);
defNameE(glXChooseFBConfig);
+defNameE(glXDestroyContext);
+defNameE(glXMakeCurrent);
#undef defNameE
diff --git a/src/render/mglxinit.cpp b/src/render/mglxinit.cpp
index 81035a37c..bcf9eb31e 100644
--- a/src/render/mglxinit.cpp
+++ b/src/render/mglxinit.cpp
@@ -34,6 +34,8 @@ void Glx::initFunctions()
assignFunction(glXGetCurrentContext, "glXGetCurrentContext");
assignFunction(glXCreateContextAttribs, "glXCreateContextAttribsARB");
assignFunction(glXChooseFBConfig, "glXChooseFBConfig");
+ assignFunction(glXDestroyContext, "glXDestroyContext");
+ assignFunction(glXMakeCurrent, "glXMakeCurrent");
}
#endif
diff --git a/src/render/mglxtypes.h b/src/render/mglxtypes.h
index 700d62287..d8d66bdab 100644
--- a/src/render/mglxtypes.h
+++ b/src/render/mglxtypes.h
@@ -37,10 +37,13 @@
typedef void *(*glXCreateContext_t) (Display *dpy, XVisualInfo *vis,
void *shareList, bool direct);
typedef void *(*glXGetCurrentContext_t) (void);
-typedef void (*glXCreateContextAttribs_t) (Display *dpy, GLXFBConfig config,
+typedef void *(*glXCreateContextAttribs_t) (Display *dpy, GLXFBConfig config,
void *share_context, bool direct, const int *attrib_list);
typedef GLXFBConfig *(*glXChooseFBConfig_t) (Display *dpy, int screen,
const int *attrib_list, int *nelements);
+typedef void (*glXDestroyContext_t) (Display *dpy, void *ctx);
+typedef bool (*glXMakeCurrent_t) (Display *dpy,
+ GLXDrawable drawable, void *ctx);
#endif // USE_OPENGL
#endif // RENDER_MGLXTYPES_H
diff --git a/src/render/modernopenglgraphics.cpp b/src/render/modernopenglgraphics.cpp
index ce7f86f56..3595d6a78 100644
--- a/src/render/modernopenglgraphics.cpp
+++ b/src/render/modernopenglgraphics.cpp
@@ -41,6 +41,7 @@
#include "resources/openglimagehelper.h"
#include "utils/sdlcheckutils.h"
+#include "utils/sdlhelper.h"
#include "debug.h"
@@ -1260,6 +1261,11 @@ void ModernOpenGLGraphics::clearScreen() const
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
}
+void ModernOpenGLGraphics::createGLContext()
+{
+ mGLContext = SDL::createGLContext(mWindow, 3, 3);
+}
+
void ModernOpenGLGraphics::finalize(ImageCollection *const col)
{
FOR_EACH (ImageCollectionIter, it, col->draws)
diff --git a/src/render/modernopenglgraphics.h b/src/render/modernopenglgraphics.h
index 28a7f8bbb..2b27c621e 100644
--- a/src/render/modernopenglgraphics.h
+++ b/src/render/modernopenglgraphics.h
@@ -81,6 +81,9 @@ class ModernOpenGLGraphics final : public Graphics
#include "render/openglgraphicsdefadvanced.hpp"
+ protected:
+ virtual void createGLContext() override final;
+
private:
inline void drawQuad(const Image *const image,
const int srcX, const int srcY,