Drawable Renderer (#1570), Move generic shader lookup to context virtual
This commit is contained in:
committed by
Bart Louwers
parent
7cf910129b
commit
c7299eaf20
@@ -24,6 +24,7 @@ class DrawableBuilder;
|
||||
class DrawableTweaker;
|
||||
class OffscreenTexture;
|
||||
class ShaderProgramBase;
|
||||
class ShaderRegistry;
|
||||
|
||||
using DrawablePtr = std::shared_ptr<Drawable>;
|
||||
using UniqueDrawableBuilder = std::unique_ptr<DrawableBuilder>;
|
||||
@@ -106,6 +107,9 @@ public:
|
||||
|
||||
/// Create a new drawable tweaker
|
||||
virtual DrawableTweakerPtr createDrawableTweaker() = 0;
|
||||
|
||||
/// Get the generic shader with the specified name
|
||||
virtual gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) = 0;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include <mbgl/gl/context.hpp>
|
||||
|
||||
#include <mbgl/gfx/shader_registry.hpp>
|
||||
#include <mbgl/gl/command_encoder.hpp>
|
||||
#include <mbgl/gl/defines.hpp>
|
||||
#include <mbgl/gl/drawable_gl.hpp>
|
||||
@@ -487,6 +489,10 @@ gfx::DrawableTweakerPtr Context::createDrawableTweaker() {
|
||||
return std::make_shared<gl::DrawableGLTweaker>();
|
||||
}
|
||||
|
||||
gfx::ShaderProgramBasePtr Context::getGenericShader(gfx::ShaderRegistry& shaders, const std::string& name) {
|
||||
return shaders.get<gl::ShaderProgramGL>(name);
|
||||
}
|
||||
|
||||
void Context::clear(std::optional<mbgl::Color> color,
|
||||
std::optional<float> depth,
|
||||
std::optional<int32_t> stencil) {
|
||||
|
||||
@@ -107,6 +107,8 @@ public:
|
||||
gfx::UniqueDrawableBuilder createDrawableBuilder(std::string name) override;
|
||||
gfx::DrawableTweakerPtr createDrawableTweaker() override;
|
||||
|
||||
gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) override;
|
||||
|
||||
private:
|
||||
RendererBackend& backend;
|
||||
bool cleanupOnDestruction = true;
|
||||
|
||||
@@ -31,25 +31,15 @@ bool BackgroundLayer::Impl::hasLayoutDifference(const Layer::Impl&) const {
|
||||
|
||||
constexpr auto shaderName = "background_generic";
|
||||
|
||||
struct ShaderHack final : public gfx::ShaderProgramBase {
|
||||
static constexpr std::string_view Name{"GenericGLShader"};
|
||||
const std::string_view typeName() const noexcept override { return Name; }
|
||||
const gfx::VertexAttributeArray& getUniforms() const override { return *dummy; }
|
||||
const gfx::VertexAttributeArray& getVertexAttributes() const override { return *dummy; }
|
||||
gfx::VertexAttributeArray& mutableUniforms() override { return *dummy; }
|
||||
gfx::VertexAttributeArray& mutableVertexAttributes() override { return *dummy; }
|
||||
gfx::VertexAttributeArray* dummy = nullptr;
|
||||
};
|
||||
|
||||
void BackgroundLayer::Impl::layerAdded(gfx::ShaderRegistry& shaders,
|
||||
gfx::Context&,
|
||||
gfx::Context& context,
|
||||
const TransformState&,
|
||||
const PropertyEvaluationParameters&,
|
||||
UniqueChangeRequestVec&) const {
|
||||
{
|
||||
std::unique_lock<std::mutex> guard(mutex);
|
||||
if (!shader) {
|
||||
shader = shaders.get<ShaderHack>(shaderName);
|
||||
shader = context.getGenericShader(shaders, shaderName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user