diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2017-02-27 18:33:16 +0100 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-03-23 14:50:11 -0700 |
commit | e67abfbe67d7c08e90fdbd8727c4e9ed17dfa1ed (patch) | |
tree | 8bf1a6ae813afdfe44bd8d6210337141acd53bae /src/mbgl/gl/context.hpp | |
parent | 234384ece9c70f2a803ed2b1d1eb55b248ec43d1 (diff) | |
download | qtlocation-mapboxgl-e67abfbe67d7c08e90fdbd8727c4e9ed17dfa1ed.tar.gz |
[core] Refactor OpenGL extension loading mechanism
Previously, we initialized global variables that held pointers to the extension functions. While this seemed to work, the spec doesn't guarantee that the function pointers are identical for different OpenGL contexts. Therefore, we are now making them a member variable of the Context object.
Diffstat (limited to 'src/mbgl/gl/context.hpp')
-rw-r--r-- | src/mbgl/gl/context.hpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index 10ff4360d3..14af299baa 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -30,11 +30,23 @@ class View; namespace gl { constexpr size_t TextureMax = 64; +using ProcAddress = void (*)(); + +namespace extension { +class VertexArray; +class Debugging; +class ProgramBinary; +} // namespace extension class Context : private util::noncopyable { public: + Context(); ~Context(); + void initializeExtensions(const std::function<gl::ProcAddress(const char*)>&); + + void enableDebugging(); + UniqueShader createShader(ShaderType type, const std::string& source); UniqueProgram createProgram(ShaderID vertexShader, ShaderID fragmentShader); UniqueProgram createProgram(BinaryProgramFormat binaryFormat, const std::string& binaryProgram); @@ -164,11 +176,27 @@ public: void setDirtyState(); + extension::Debugging* getDebuggingExtension() const { + return debugging.get(); + } + + extension::VertexArray* getVertexArrayExtension() const { + return vertexArray.get(); + } + +private: + std::unique_ptr<extension::Debugging> debugging; + std::unique_ptr<extension::VertexArray> vertexArray; +#if MBGL_HAS_BINARY_PROGRAMS + std::unique_ptr<extension::ProgramBinary> programBinary; +#endif + +public: State<value::ActiveTexture> activeTexture; State<value::BindFramebuffer> bindFramebuffer; State<value::Viewport> viewport; std::array<State<value::BindTexture>, 2> texture; - State<value::BindVertexArray> vertexArrayObject; + State<value::BindVertexArray, const Context&> vertexArrayObject { *this }; State<value::Program> program; State<value::BindVertexBuffer> vertexBuffer; State<value::BindElementBuffer> elementBuffer; |