From e5e234b864e75862a2de72ee6c3b8bda47f41c23 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 10 Dec 2015 16:42:56 +0100 Subject: OPENGL: Refactor GL extension handling slightly. --- backends/graphics/opengl/opengl-graphics.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'backends/graphics/opengl/opengl-graphics.h') diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index 9578839383..2a03b878ce 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -280,6 +280,12 @@ private: // OpenGL utilities // + /** + * Checks for availability of extensions we want to use and initializes them + * when available. + */ + void initializeGLExtensions(); + /** * Try to determine the internal parameters for a given pixel format. * -- cgit v1.2.3 From 8f3783da0994703e9fe6fcfc666d194c9eb00865 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Fri, 11 Dec 2015 23:51:21 +0100 Subject: OPENGL: Add functionality to query OpenGL functions on runtime. This can and will be used for future extension usage support. Tizen changes have been untested. --- backends/graphics/opengl/opengl-graphics.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'backends/graphics/opengl/opengl-graphics.h') diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index 2a03b878ce..f83c9537ec 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -286,6 +286,21 @@ private: */ void initializeGLExtensions(); +protected: + /** + * Query the address of an OpenGL function by name. + * + * This can only be used after a context has been created. + * Please note that this function can return valid addresses even if the + * OpenGL context does not support the function. + * + * @param name The name of the OpenGL function. + * @return An function pointer for the requested OpenGL function or + * nullptr in case of failure. + */ + virtual void *getProcAddress(const char *name) const = 0; + +private: /** * Try to determine the internal parameters for a given pixel format. * -- cgit v1.2.3 From 4a781737c1da77015df4547f64f2f88966816343 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 12 Dec 2015 01:18:46 +0100 Subject: OPENGL: Resolve OpenGL functions on run-time. Formerly we relied on static linkage. However, in the presense of modern OpenGL (ES) implementations it is not easily identifable which library to link against. For example, on Linux amd64 with nVidia drivers and SDL2 setup to create a GLES 1.1 context one would need to link against libGL.so. However, traditionally GLES 1.1 required to link against libGLESv1_CM.so. To prevent a huge mess we simply resolve the OpenGL functions on run-time now and stop linking against a static library (in most cases). GLES support needs to be enabled manually on configure time for now. Tizen changes have NOT been tested. --- backends/graphics/opengl/opengl-graphics.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.h') diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index f83c9537ec..3d5f74b387 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -281,10 +281,9 @@ private: // /** - * Checks for availability of extensions we want to use and initializes them - * when available. + * Initialize the active context for use. */ - void initializeGLExtensions(); + void initializeGLContext(); protected: /** -- cgit v1.2.3 From d6d3e17d53754acedce0b1706e73f929d29b5eb8 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 12 Dec 2015 22:08:33 +0100 Subject: OPENGL: Allow runtime specification of OpenGL mode. Formerly, we required that the OpenGL mode was fixed at compile time. Now we allow the code to work with whatever it is given at runtime. It is still possible to force a context type on compile time. --- backends/graphics/opengl/opengl-graphics.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.h') diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index 3d5f74b387..5f0436c0b5 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -116,6 +116,16 @@ public: virtual void grabPalette(byte *colors, uint start, uint num); protected: + /** + * Whether an OpenGL (context) is active. + */ + bool isInitialized() const { return g_context.ready; } + + /** + * Whether an GLES context is active. + */ + bool isGLESContext() const { return g_context.type == kContextGLES; } + /** * Set up the actual screen size available for the OpenGL code to do any * drawing. @@ -133,8 +143,9 @@ protected: * (this is used for the CLUT8 game screens). * @param defaultFormatAlpha The new default format with an alpha channel * (this is used for the overlay and cursor). + * @param type Type of the created context. */ - void notifyContextCreate(const Graphics::PixelFormat &defaultFormat, const Graphics::PixelFormat &defaultFormatAlpha); + void notifyContextCreate(const Graphics::PixelFormat &defaultFormat, const Graphics::PixelFormat &defaultFormatAlpha, ContextType type); /** * Notify the manager that the OpenGL context is about to be destroyed. @@ -282,8 +293,10 @@ private: /** * Initialize the active context for use. + * + * @param type Type of the context to initialize. */ - void initializeGLContext(); + void initializeGLContext(ContextType type); protected: /** -- cgit v1.2.3 From af727afe0ceb66eaf51985ceceb2ac842b3358ee Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Fri, 18 Dec 2015 21:14:48 +0100 Subject: OPENGL: Simplify context type setting. --- backends/graphics/opengl/opengl-graphics.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.h') diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index 5f0436c0b5..5a2b1bb373 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -116,11 +116,6 @@ public: virtual void grabPalette(byte *colors, uint start, uint num); protected: - /** - * Whether an OpenGL (context) is active. - */ - bool isInitialized() const { return g_context.ready; } - /** * Whether an GLES context is active. */ @@ -135,6 +130,16 @@ protected: */ void setActualScreenSize(uint width, uint height); + /** + * Sets the OpenGL (ES) type the graphics manager shall work with. + * + * This needs to be called at least once (and before ever calling + * notifyContextCreate). + * + * @param type Type of the OpenGL (ES) contexts to be created. + */ + void setContextType(ContextType type); + /** * Notify the manager of a OpenGL context change. This should be the first * thing to call after you created an OpenGL (ES) context! @@ -143,9 +148,8 @@ protected: * (this is used for the CLUT8 game screens). * @param defaultFormatAlpha The new default format with an alpha channel * (this is used for the overlay and cursor). - * @param type Type of the created context. */ - void notifyContextCreate(const Graphics::PixelFormat &defaultFormat, const Graphics::PixelFormat &defaultFormatAlpha, ContextType type); + void notifyContextCreate(const Graphics::PixelFormat &defaultFormat, const Graphics::PixelFormat &defaultFormatAlpha); /** * Notify the manager that the OpenGL context is about to be destroyed. @@ -293,10 +297,8 @@ private: /** * Initialize the active context for use. - * - * @param type Type of the context to initialize. */ - void initializeGLContext(ContextType type); + void initializeGLContext(); protected: /** -- cgit v1.2.3 From fe88375ff376cbb0d940c96ac6ec1667be4acab0 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 20 Dec 2015 05:42:54 +0100 Subject: OPENGL: Support GLES2 contexts. --- backends/graphics/opengl/opengl-graphics.h | 31 ++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.h') diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index 5a2b1bb373..37ab1f8591 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -41,6 +41,9 @@ namespace OpenGL { #define USE_OSD 1 class Texture; +#if !USE_FORCED_GL && !USE_FORCED_GLES +class Shader; +#endif enum { GFX_LINEAR = 0, @@ -117,9 +120,9 @@ public: protected: /** - * Whether an GLES context is active. + * Whether an GLES or GLES2 context is active. */ - bool isGLESContext() const { return g_context.type == kContextGLES; } + bool isGLESContext() const { return g_context.type == kContextGLES || g_context.type == kContextGLES2; } /** * Set up the actual screen size available for the OpenGL code to do any @@ -300,6 +303,14 @@ private: */ void initializeGLContext(); + /** + * Set color which shall be multiplied with each pixel. + * + * This serves as a wrapper around glColor4f for fixed-function and our + * shader pipeline. + */ + void setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a); + protected: /** * Query the address of an OpenGL function by name. @@ -518,6 +529,22 @@ private: */ uint _scissorOverride; +#if !USE_FORCED_GL && !USE_FORCED_GLES + // + // Shaders + // + + /** + * Active shader. + */ + Shader *_shader; + + /** + * Projection matrix used. + */ + GLfloat _projectionMatrix[4*4]; +#endif + #ifdef USE_OSD // // OSD -- cgit v1.2.3 From fee1aa550203c3f46ff19afbe19a7baa4771a5cd Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 20 Dec 2015 09:30:11 +0100 Subject: OPENGL: Add support for shaders with GL contexts. --- backends/graphics/opengl/opengl-graphics.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.h') diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index 37ab1f8591..55e18cf7f0 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -41,7 +41,7 @@ namespace OpenGL { #define USE_OSD 1 class Texture; -#if !USE_FORCED_GL && !USE_FORCED_GLES +#if !USE_FORCED_GLES class Shader; #endif @@ -529,7 +529,7 @@ private: */ uint _scissorOverride; -#if !USE_FORCED_GL && !USE_FORCED_GLES +#if !USE_FORCED_GLES // // Shaders // -- cgit v1.2.3 From c7c870bf7f269229d069d47c22b61c237737cdae Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 21 Dec 2015 05:05:37 +0100 Subject: OPENGL: (Partly) move context specific handling to Context. This does not include (most) shader setup, and projection matrices yet. --- backends/graphics/opengl/opengl-graphics.h | 8 -------- 1 file changed, 8 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.h') diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index 55e18cf7f0..b6e3c1321b 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -303,14 +303,6 @@ private: */ void initializeGLContext(); - /** - * Set color which shall be multiplied with each pixel. - * - * This serves as a wrapper around glColor4f for fixed-function and our - * shader pipeline. - */ - void setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a); - protected: /** * Query the address of an OpenGL function by name. -- cgit v1.2.3 From de3846923c9a00ff6a8563e33858e12a72bfebda Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 2 Jan 2016 05:54:08 +0100 Subject: OPENGL: Introduce simple abstraction for surfaces. This is basically an interface extracted from Texture without any knowledge about any actual implementation, except for copyRectToTexture, fill, and dirty rect handling. These are convenient helpers. --- backends/graphics/opengl/opengl-graphics.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.h') diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index b6e3c1321b..40605f0259 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -40,7 +40,7 @@ namespace OpenGL { // SurfaceSDL backend enables it and disabling it can cause issues in sdl.cpp. #define USE_OSD 1 -class Texture; +class Surface; #if !USE_FORCED_GLES class Shader; #endif @@ -190,15 +190,15 @@ protected: private: /** - * Create a texture with the specified pixel format. + * Create a surface with the specified pixel format. * - * @param format The pixel format the Texture object should accept as + * @param format The pixel format the Surface object should accept as * input. - * @param wantAlpha For CLUT8 textures this marks whether an alpha + * @param wantAlpha For CLUT8 surfaces this marks whether an alpha * channel should be used. - * @return A pointer to the texture or nullptr on failure. + * @return A pointer to the surface or nullptr on failure. */ - Texture *createTexture(const Graphics::PixelFormat &format, bool wantAlpha = false); + Surface *createSurface(const Graphics::PixelFormat &format, bool wantAlpha = false); // // Transaction support @@ -386,7 +386,7 @@ private: /** * The virtual game screen. */ - Texture *_gameScreen; + Surface *_gameScreen; /** * The game palette if in CLUT8 mode. @@ -405,7 +405,7 @@ private: /** * The overlay screen. */ - Texture *_overlay; + Surface *_overlay; /** * Whether the overlay is visible or not. @@ -424,7 +424,7 @@ private: /** * The cursor image. */ - Texture *_cursor; + Surface *_cursor; /** * X coordinate of the cursor in phyiscal coordinates. @@ -551,7 +551,7 @@ private: /** * The OSD's contents. */ - Texture *_osd; + Surface *_osd; /** * Current opacity level of the OSD. -- cgit v1.2.3 From f5f1b6eba0d409abcda2a3c037a177d6f6e41a2e Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 4 Jan 2016 06:41:10 +0100 Subject: OPENGL: Introduce pipeline abstraction to cleanup code. --- backends/graphics/opengl/opengl-graphics.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'backends/graphics/opengl/opengl-graphics.h') diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index 40605f0259..95ba4e7377 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -41,6 +41,7 @@ namespace OpenGL { #define USE_OSD 1 class Surface; +class Pipeline; #if !USE_FORCED_GLES class Shader; #endif @@ -303,6 +304,11 @@ private: */ void initializeGLContext(); + /** + * OpenGL pipeline used for rendering. + */ + Pipeline *_pipeline; + protected: /** * Query the address of an OpenGL function by name. -- cgit v1.2.3 From 5498982a3754edccb498521587c553e0ecbe7328 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 4 Jan 2016 07:07:37 +0100 Subject: OPENGL: Introduce ShaderManager to handle builtin shaders. --- backends/graphics/opengl/opengl-graphics.h | 5 ----- 1 file changed, 5 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.h') diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index 95ba4e7377..f3cd4c437f 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -532,11 +532,6 @@ private: // Shaders // - /** - * Active shader. - */ - Shader *_shader; - /** * Projection matrix used. */ -- cgit v1.2.3 From c4e65732befdfb675111387c3c7edb616bf2f976 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 4 Jan 2016 10:18:15 +0100 Subject: OPENGL: Introduce abstraction for framebuffer. This allows us to use various framebuffer settings easily. Now the GPU accelerated CLUT8 surface implementation does not need to query former framebuffer state anymore. --- backends/graphics/opengl/opengl-graphics.h | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.h') diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index f3cd4c437f..35435c156e 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -24,6 +24,7 @@ #define BACKENDS_GRAPHICS_OPENGL_OPENGL_GRAPHICS_H #include "backends/graphics/opengl/opengl-sys.h" +#include "backends/graphics/opengl/framebuffer.h" #include "backends/graphics/graphics.h" #include "common/frac.h" @@ -304,6 +305,11 @@ private: */ void initializeGLContext(); + /** + * Render back buffer. + */ + Backbuffer _backBuffer; + /** * OpenGL pipeline used for rendering. */ @@ -527,17 +533,6 @@ private: */ uint _scissorOverride; -#if !USE_FORCED_GLES - // - // Shaders - // - - /** - * Projection matrix used. - */ - GLfloat _projectionMatrix[4*4]; -#endif - #ifdef USE_OSD // // OSD -- cgit v1.2.3