diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2019-03-14 12:05:13 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2019-03-15 11:55:30 +0100 |
commit | 4c236085e04925394bd5591c4e76b8f3968f168c (patch) | |
tree | 4f00387befa1f677260d930eac11dcc74a808ffc | |
parent | fc770441146e33c4cdebd5df4094e7e573ccf106 (diff) | |
download | qtlocation-mapboxgl-4c236085e04925394bd5591c4e76b8f3968f168c.tar.gz |
[core] introduce abstract gfx::Program base type
-rw-r--r-- | src/mbgl/gfx/program.hpp | 49 | ||||
-rw-r--r-- | src/mbgl/gl/program.hpp | 23 | ||||
-rw-r--r-- | src/mbgl/programs/collision_box_program.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/programs/program.hpp | 7 | ||||
-rw-r--r-- | src/mbgl/programs/symbol_program.hpp | 4 |
5 files changed, 69 insertions, 18 deletions
diff --git a/src/mbgl/gfx/program.hpp b/src/mbgl/gfx/program.hpp new file mode 100644 index 0000000000..b72aea4b30 --- /dev/null +++ b/src/mbgl/gfx/program.hpp @@ -0,0 +1,49 @@ +#pragma once + +#include <cstddef> + +namespace mbgl { +namespace gfx { + +class Context; +class DrawMode; +class DepthMode; +class StencilMode; +class ColorMode; +class CullFaceMode; +class DrawScope; +class IndexBuffer; +template <class> class UniformValues; +template <class> class AttributeBindings; +template <class> class TextureBindings; + +template <class AttributeList, class UniformList, class TextureList> +class Program { +protected: + Program() = default; + +public: + virtual ~Program() = default; + + Program(Program&&) = delete; + Program(const Program&) = delete; + Program& operator=(Program&&) = delete; + Program& operator=(const Program&) = delete; + + virtual void draw(Context&, + const DrawMode&, + const DepthMode&, + const StencilMode&, + const ColorMode&, + const CullFaceMode&, + const UniformValues<UniformList>&, + DrawScope&, + const AttributeBindings<AttributeList>&, + const TextureBindings<TextureList>&, + const IndexBuffer&, + std::size_t indexOffset, + std::size_t indexLength) = 0; +}; + +} // namespace gfx +} // namespace mbgl diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp index a3c09f1de6..921362e4f3 100644 --- a/src/mbgl/gl/program.hpp +++ b/src/mbgl/gl/program.hpp @@ -1,5 +1,6 @@ #pragma once +#include <mbgl/gfx/program.hpp> #include <mbgl/gl/types.hpp> #include <mbgl/gl/object.hpp> #include <mbgl/gl/context.hpp> @@ -25,7 +26,7 @@ namespace mbgl { namespace gl { template <class AttributeList, class UniformList, class TextureList> -class Program { +class Program final : public gfx::Program<AttributeList, UniformList, TextureList> { public: Program(Context& context, const std::string& vertexSource, const std::string& fragmentSource) : program( @@ -51,11 +52,11 @@ public: textureStates.loadNamedLocations(binaryProgram); } - static Program createProgram(gl::Context& context, - const ProgramParameters& programParameters, - const char* name, - const char* vertexSource_, - const char* fragmentSource_) { + static std::unique_ptr<Program> createProgram(gl::Context& context, + const ProgramParameters& programParameters, + const char* name, + const char* vertexSource_, + const char* fragmentSource_) { const std::string vertexSource = shaders::vertexSource(programParameters, vertexSource_); const std::string fragmentSource = shaders::fragmentSource(programParameters, fragmentSource_); @@ -68,7 +69,7 @@ public: if (auto cachedBinaryProgram = util::readFile(*cachePath)) { const BinaryProgram binaryProgram(std::move(*cachedBinaryProgram)); if (binaryProgram.identifier() == identifier) { - return Program { context, binaryProgram }; + return std::make_unique<Program>(context, binaryProgram); } else { Log::Warning(Event::OpenGL, "Cached program %s changed. Recompilation required.", @@ -81,11 +82,11 @@ public: } // Compile the shader - Program result{ context, vertexSource, fragmentSource }; + auto result = std::make_unique<Program>(context, vertexSource, fragmentSource); try { if (const auto binaryProgram = - result.template get<BinaryProgram>(context, identifier)) { + result->template get<BinaryProgram>(context, identifier)) { util::write_file(*cachePath, binaryProgram->serialize()); Log::Warning(Event::OpenGL, "Caching program in: %s", (*cachePath).c_str()); } @@ -98,7 +99,7 @@ public: #endif (void)name; - return Program { context, vertexSource, fragmentSource }; + return std::make_unique<Program>(context, vertexSource, fragmentSource); } template <class BinaryProgram> @@ -126,7 +127,7 @@ public: const gfx::TextureBindings<TextureList>& textureBindings, const gfx::IndexBuffer& indexBuffer, std::size_t indexOffset, - std::size_t indexLength) { + std::size_t indexLength) override { auto& context = reinterpret_cast<gl::Context&>(genericContext); context.setDepthMode(depthMode); diff --git a/src/mbgl/programs/collision_box_program.hpp b/src/mbgl/programs/collision_box_program.hpp index 94c6963909..ce536ff491 100644 --- a/src/mbgl/programs/collision_box_program.hpp +++ b/src/mbgl/programs/collision_box_program.hpp @@ -94,7 +94,7 @@ public: drawScopeIt = segment.drawScopes.emplace(layerID, context.createDrawScope()).first; } - program.draw( + program->draw( context, std::move(drawMode), std::move(depthMode), @@ -180,7 +180,7 @@ public: drawScopeIt = segment.drawScopes.emplace(layerID, context.createDrawScope()).first; } - program.draw( + program->draw( context, std::move(drawMode), std::move(depthMode), diff --git a/src/mbgl/programs/program.hpp b/src/mbgl/programs/program.hpp index eb9c2168f7..917947c95c 100644 --- a/src/mbgl/programs/program.hpp +++ b/src/mbgl/programs/program.hpp @@ -19,7 +19,7 @@ template <class Shaders, gfx::PrimitiveType Primitive, class LayoutAttributeList, class LayoutUniformList, - class TextureList, + class Textures, class PaintProps> class Program { public: @@ -37,11 +37,12 @@ public: using LayoutUniformValues = gfx::UniformValues<LayoutUniformList>; using UniformValues = gfx::UniformValues<UniformList>; + using TextureList = Textures; using TextureBindings = gfx::TextureBindings<TextureList>; using ProgramType = gl::Program<AttributeList, UniformList, TextureList>; - ProgramType program; + std::unique_ptr<gfx::Program<AttributeList, UniformList, TextureList>> program; Program(gl::Context& context, const ProgramParameters& programParameters) : program(ProgramType::createProgram( @@ -94,7 +95,7 @@ public: drawScopeIt = segment.drawScopes.emplace(layerID, context.createDrawScope()).first; } - program.draw( + program->draw( context, drawMode, depthMode, diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp index 63c61baf71..3ed8325817 100644 --- a/src/mbgl/programs/symbol_program.hpp +++ b/src/mbgl/programs/symbol_program.hpp @@ -268,7 +268,7 @@ public: using ProgramType = gl::Program<AttributeList, UniformList, TextureList>; - ProgramType program; + std::unique_ptr<ProgramType> program; SymbolProgram(gl::Context& context, const ProgramParameters& programParameters) : program(ProgramType::createProgram( @@ -328,7 +328,7 @@ public: drawScopeIt = segment.drawScopes.emplace(layerID, context.createDrawScope()).first; } - program.draw( + program->draw( context, drawMode, depthMode, |