Drawable Renderer (#1570), [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
committed by
Bart Louwers
parent
b2a3e518c7
commit
caee9cc12f
@@ -35,7 +35,7 @@ public:
|
||||
const util::SimpleIdentity& getId() const { return uniqueID; }
|
||||
|
||||
/// Draw the drawable
|
||||
virtual void draw(const PaintParameters &) const = 0;
|
||||
virtual void draw(const PaintParameters&) const = 0;
|
||||
|
||||
/// Drawable name is used for debugging and troubleshooting
|
||||
const std::string& getName() const { return name; }
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
|
||||
DepthMaskType getDepthType() const { return depthType; }
|
||||
void setDepthType(DepthMaskType value) { depthType = value; }
|
||||
|
||||
|
||||
/// Get the number of vertexes
|
||||
std::size_t getVertexCount() const { return getVertexAttributes().getMaxCount(); }
|
||||
|
||||
@@ -71,7 +71,9 @@ public:
|
||||
/// Attach a tweaker to be run on this drawable for each frame
|
||||
void addTweaker(DrawableTweakerPtr tweaker) { tweakers.emplace_back(std::move(tweaker)); }
|
||||
template <typename TIter>
|
||||
void addTweakers(TIter beg, TIter end) { tweakers.insert(tweakers.end(), beg, end); }
|
||||
void addTweakers(TIter beg, TIter end) {
|
||||
tweakers.insert(tweakers.end(), beg, end);
|
||||
}
|
||||
|
||||
/// Get the tweakers attached to this drawable
|
||||
const std::vector<DrawableTweakerPtr>& getTweakers() const { return tweakers; }
|
||||
@@ -86,7 +88,7 @@ protected:
|
||||
mat4 matrix; //= matrix::identity4();
|
||||
std::optional<OverscaledTileID> tileID;
|
||||
DrawPriority drawPriority = 0;
|
||||
DepthMaskType depthType;// = DepthMaskType::ReadOnly;
|
||||
DepthMaskType depthType; // = DepthMaskType::ReadOnly;
|
||||
|
||||
std::vector<DrawableTweakerPtr> tweakers;
|
||||
};
|
||||
|
||||
@@ -60,7 +60,10 @@ public:
|
||||
const Color& getColor() const;
|
||||
void setColor(const Color& value);
|
||||
|
||||
enum class ColorMode { PerDrawable, PerVertex };
|
||||
enum class ColorMode {
|
||||
PerDrawable,
|
||||
PerVertex
|
||||
};
|
||||
/// Set how the color value is used
|
||||
/// This should not be changed while a build is in progress
|
||||
void setColorMode(ColorMode mode) { colorMode = mode; }
|
||||
|
||||
@@ -62,4 +62,3 @@ enum class AttributeDataType : uint8_t {
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mbgl
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ inline constexpr bool is_shader_v = std::is_base_of_v<gfx::Shader, T> &&
|
||||
/// @brief A shader is used as the base class for all programs across any supported
|
||||
/// backend API. Shaders are registered with a `gfx::ShaderRegistry` instance.
|
||||
class Shader {
|
||||
public:
|
||||
virtual ~Shader() noexcept = default;
|
||||
public:
|
||||
virtual ~Shader() noexcept = default;
|
||||
|
||||
/// @brief Get the type name of this shader
|
||||
/// @return Shader type name
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
using mat2 = std::array<double, 2*2>;
|
||||
using mat3 = std::array<double, 3*3>;
|
||||
using mat4 = std::array<double, 4*4>;
|
||||
using mat2 = std::array<double, 2 * 2>;
|
||||
using mat3 = std::array<double, 3 * 3>;
|
||||
using mat4 = std::array<double, 4 * 4>;
|
||||
|
||||
namespace gfx {
|
||||
|
||||
@@ -27,34 +27,29 @@ public:
|
||||
using float2 = std::array<float, 2>;
|
||||
using float3 = std::array<float, 3>;
|
||||
using float4 = std::array<float, 4>;
|
||||
using matf2 = std::array<float, 2*2>;
|
||||
using matf3 = std::array<float, 3*3>;
|
||||
using matf4 = std::array<float, 4*4>;
|
||||
using matf2 = std::array<float, 2 * 2>;
|
||||
using matf3 = std::array<float, 3 * 3>;
|
||||
using matf4 = std::array<float, 4 * 4>;
|
||||
using int2 = std::array<std::int32_t, 2>;
|
||||
using int3 = std::array<std::int32_t, 3>;
|
||||
using int4 = std::array<std::int32_t, 4>;
|
||||
|
||||
using ElementType = std::variant<std::int32_t, int2, int3, int4,
|
||||
float, float2, float3, float4,
|
||||
matf3, matf4>;
|
||||
using ElementType = std::variant<std::int32_t, int2, int3, int4, float, float2, float3, float4, matf3, matf4>;
|
||||
|
||||
// Can only be created by VertexAttributeArray implementations
|
||||
protected:
|
||||
VertexAttribute(int index_, AttributeDataType dataType_,
|
||||
int size_, std::size_t count_, std::size_t stride_)
|
||||
VertexAttribute(int index_, AttributeDataType dataType_, int size_, std::size_t count_, std::size_t stride_)
|
||||
: index(index_),
|
||||
size(size_),
|
||||
stride((int)stride_),
|
||||
dataType(dataType_),
|
||||
items(count_) {
|
||||
}
|
||||
VertexAttribute(const VertexAttribute &) = default;
|
||||
items(count_) {}
|
||||
VertexAttribute(const VertexAttribute&) = default;
|
||||
VertexAttribute(VertexAttribute&& other)
|
||||
: index(other.index),
|
||||
size(other.size),
|
||||
dataType(other.dataType),
|
||||
items(std::move(other.items)) {
|
||||
}
|
||||
items(std::move(other.items)) {}
|
||||
|
||||
public:
|
||||
~VertexAttribute() = default;
|
||||
@@ -77,7 +72,7 @@ public:
|
||||
const ElementType& set(std::size_t i, T value) {
|
||||
if (items.size() < i + 1) {
|
||||
items.resize(std::max(items.size(), i + 1));
|
||||
setDirty(); // need to rebuild the raw data next time
|
||||
setDirty(); // need to rebuild the raw data next time
|
||||
}
|
||||
if (!isDirty()) {
|
||||
if (std::holds_alternative<T>(items[i])) {
|
||||
@@ -135,7 +130,7 @@ public:
|
||||
using AttributeMap = std::unordered_map<std::string, std::unique_ptr<VertexAttribute>>;
|
||||
|
||||
VertexAttributeArray(int initCapacity = 10);
|
||||
VertexAttributeArray(VertexAttributeArray &&);
|
||||
VertexAttributeArray(VertexAttributeArray&&);
|
||||
// Would need to use the virtual assignment operator
|
||||
VertexAttributeArray(const VertexAttributeArray&) = delete;
|
||||
virtual ~VertexAttributeArray() = default;
|
||||
@@ -175,7 +170,7 @@ public:
|
||||
// Set a value if the element is present
|
||||
template <typename T>
|
||||
bool set(const std::string& name, std::size_t i, T value) {
|
||||
if (auto *item = get(name)) {
|
||||
if (auto* item = get(name)) {
|
||||
return item->set(i, value);
|
||||
}
|
||||
return false;
|
||||
@@ -183,8 +178,8 @@ public:
|
||||
|
||||
/// Indicates whether any values have changed
|
||||
bool isDirty() const {
|
||||
return std::any_of(attrs.begin(), attrs.end(),
|
||||
[](const auto& kv){ return kv.second && kv.second->isDirty(); });
|
||||
return std::any_of(
|
||||
attrs.begin(), attrs.end(), [](const auto& kv) { return kv.second && kv.second->isDirty(); });
|
||||
}
|
||||
|
||||
using ResolveDelegate = std::function<void(const std::string&, const VertexAttribute&, const VertexAttribute*)>;
|
||||
@@ -193,8 +188,8 @@ public:
|
||||
|
||||
/// Apply to the active program
|
||||
virtual void applyUniforms(const ShaderProgramBase&) = 0;
|
||||
|
||||
VertexAttributeArray& operator=(VertexAttributeArray &&);
|
||||
|
||||
VertexAttributeArray& operator=(VertexAttributeArray&&);
|
||||
VertexAttributeArray& operator=(const VertexAttributeArray&);
|
||||
|
||||
protected:
|
||||
@@ -208,8 +203,10 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
virtual std::unique_ptr<VertexAttribute> create(int index, AttributeDataType dataType,
|
||||
int size, std::size_t count) = 0;
|
||||
virtual std::unique_ptr<VertexAttribute> create(int index,
|
||||
AttributeDataType dataType,
|
||||
int size,
|
||||
std::size_t count) = 0;
|
||||
virtual std::unique_ptr<VertexAttribute> copy(const VertexAttribute& attr) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -25,11 +25,9 @@ public:
|
||||
DrawableGL(std::string name);
|
||||
~DrawableGL() override;
|
||||
|
||||
void draw(const PaintParameters &) const override;
|
||||
void draw(const PaintParameters&) const override;
|
||||
|
||||
void setIndexData(std::vector<uint16_t> indexes,
|
||||
std::size_t indexOffset = 0,
|
||||
std::size_t indexLength = 0);
|
||||
void setIndexData(std::vector<uint16_t> indexes, std::size_t indexOffset = 0, std::size_t indexLength = 0);
|
||||
std::vector<std::uint16_t>& getIndexData() const override;
|
||||
|
||||
const gfx::VertexAttributeArray& getVertexAttributes() const override;
|
||||
@@ -49,18 +47,19 @@ public:
|
||||
|
||||
static gfx::VertexAttribute::float4 colorAttrValue(const Color& color) {
|
||||
const auto components = color.toArray();
|
||||
return { static_cast<float>(components[0]/255.0),
|
||||
static_cast<float>(components[1]/255.0),
|
||||
static_cast<float>(components[2]/255.0),
|
||||
static_cast<float>(components[3]) };
|
||||
return {static_cast<float>(components[0] / 255.0),
|
||||
static_cast<float>(components[1] / 255.0),
|
||||
static_cast<float>(components[2] / 255.0),
|
||||
static_cast<float>(components[3])};
|
||||
}
|
||||
|
||||
protected:
|
||||
class Impl;
|
||||
const std::unique_ptr<Impl> impl;
|
||||
|
||||
// For testing only.
|
||||
DrawableGL(std::unique_ptr<Impl>);
|
||||
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
@@ -11,20 +11,20 @@ namespace gl {
|
||||
*/
|
||||
class DrawableGLBuilder final : public gfx::DrawableBuilder {
|
||||
public:
|
||||
DrawableGLBuilder(std::string name_) : gfx::DrawableBuilder(std::move(name_)) {
|
||||
}
|
||||
DrawableGLBuilder(std::string name_)
|
||||
: gfx::DrawableBuilder(std::move(name_)) {}
|
||||
~DrawableGLBuilder() override = default;
|
||||
|
||||
const gfx::VertexAttributeArray& getVertexAttributes() const override { return vertexAttributes; }
|
||||
void setVertexAttributes(const VertexAttributeArrayGL& value) { vertexAttributes = value; }
|
||||
void setVertexAttributes(VertexAttributeArrayGL&& value) { vertexAttributes = std::move(value); }
|
||||
|
||||
|
||||
protected:
|
||||
gfx::DrawablePtr createDrawable() const override;
|
||||
|
||||
|
||||
/// Setup the SDK-specific aspects after all the values are present
|
||||
void init() override;
|
||||
|
||||
|
||||
private:
|
||||
VertexAttributeArrayGL vertexAttributes;
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
namespace mbgl {
|
||||
|
||||
namespace gfx {
|
||||
class Drawable;
|
||||
class Drawable;
|
||||
}
|
||||
|
||||
namespace gl {
|
||||
|
||||
@@ -14,17 +14,14 @@ class VertexAttributeGL final : public gfx::VertexAttribute {
|
||||
private:
|
||||
friend VertexAttributeArrayGL;
|
||||
VertexAttributeGL(int index_, gfx::AttributeDataType dataType_, int size_, std::size_t count_)
|
||||
: VertexAttribute(index_, dataType_, size_, count_, /*stride_=*/0) {
|
||||
}
|
||||
: VertexAttribute(index_, dataType_, size_, count_, /*stride_=*/0) {}
|
||||
VertexAttributeGL(const VertexAttributeGL& other)
|
||||
: VertexAttribute(other),
|
||||
glType(other.glType) {
|
||||
}
|
||||
glType(other.glType) {}
|
||||
VertexAttributeGL(VertexAttributeGL&& other)
|
||||
: VertexAttribute(std::move(other)),
|
||||
glType(other.glType) {
|
||||
}
|
||||
|
||||
glType(other.glType) {}
|
||||
|
||||
public:
|
||||
platform::GLenum getGLType() const { return glType; }
|
||||
void setGLType(platform::GLenum value);
|
||||
@@ -50,11 +47,13 @@ private:
|
||||
/// Stores a collection of vertex attributes by name
|
||||
class VertexAttributeArrayGL final : public gfx::VertexAttributeArray {
|
||||
public:
|
||||
VertexAttributeArrayGL(int initCapacity = 10) : VertexAttributeArray(initCapacity) { }
|
||||
VertexAttributeArrayGL(VertexAttributeArrayGL &&other) : VertexAttributeArray(std::move(other)) { }
|
||||
VertexAttributeArrayGL(int initCapacity = 10)
|
||||
: VertexAttributeArray(initCapacity) {}
|
||||
VertexAttributeArrayGL(VertexAttributeArrayGL&& other)
|
||||
: VertexAttributeArray(std::move(other)) {}
|
||||
VertexAttributeArrayGL(const VertexAttributeArrayGL&) = delete;
|
||||
|
||||
VertexAttributeArrayGL& operator=(VertexAttributeArrayGL &&other) {
|
||||
|
||||
VertexAttributeArrayGL& operator=(VertexAttributeArrayGL&& other) {
|
||||
VertexAttributeArray::operator=(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
@@ -62,18 +61,21 @@ public:
|
||||
VertexAttributeArray::operator=(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void applyUniforms(const gfx::ShaderProgramBase&) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<gfx::VertexAttribute> create(int index, gfx::AttributeDataType dataType,
|
||||
int size, std::size_t count) override {
|
||||
std::unique_ptr<gfx::VertexAttribute> create(int index,
|
||||
gfx::AttributeDataType dataType,
|
||||
int size,
|
||||
std::size_t count) override {
|
||||
return std::unique_ptr<gfx::VertexAttribute>(new VertexAttributeGL(index, dataType, size, count));
|
||||
}
|
||||
std::unique_ptr<gfx::VertexAttribute> copy(const gfx::VertexAttribute& attr) override {
|
||||
return std::unique_ptr<gfx::VertexAttribute>(new VertexAttributeGL(static_cast<const VertexAttributeGL&>(attr)));
|
||||
return std::unique_ptr<gfx::VertexAttribute>(
|
||||
new VertexAttributeGL(static_cast<const VertexAttributeGL&>(attr)));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace gl
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -11,10 +11,9 @@ namespace mbgl {
|
||||
class RenderOrchestrator;
|
||||
|
||||
namespace gfx {
|
||||
class Drawable;
|
||||
using DrawablePtr = std::shared_ptr<Drawable>;
|
||||
} // namespace gfx
|
||||
|
||||
class Drawable;
|
||||
using DrawablePtr = std::shared_ptr<Drawable>;
|
||||
} // namespace gfx
|
||||
|
||||
/**
|
||||
Base class for changes to be made to the scene
|
||||
@@ -40,24 +39,22 @@ using UniqueChangeRequestVec = std::vector<UniqueChangeRequest>;
|
||||
*/
|
||||
class DrawableRefChangeRequest : public ChangeRequest {
|
||||
protected:
|
||||
DrawableRefChangeRequest(util::SimpleIdentity id) : drawableID(id) { }
|
||||
DrawableRefChangeRequest(const DrawableRefChangeRequest&) = default;
|
||||
DrawableRefChangeRequest(util::SimpleIdentity id)
|
||||
: drawableID(id) {}
|
||||
DrawableRefChangeRequest(const DrawableRefChangeRequest &) = default;
|
||||
|
||||
util::SimpleIdentity drawableID;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Add a new drawable to the scene
|
||||
*/
|
||||
class AddDrawableRequest : public ChangeRequest {
|
||||
public:
|
||||
AddDrawableRequest(gfx::DrawablePtr drawable_)
|
||||
: drawable(std::move(drawable_)) {
|
||||
}
|
||||
AddDrawableRequest(AddDrawableRequest&& other)
|
||||
: drawable(std::move(other.drawable)) {
|
||||
}
|
||||
: drawable(std::move(drawable_)) {}
|
||||
AddDrawableRequest(AddDrawableRequest &&other)
|
||||
: drawable(std::move(other.drawable)) {}
|
||||
|
||||
void execute(RenderOrchestrator &) override;
|
||||
|
||||
@@ -65,29 +62,27 @@ protected:
|
||||
gfx::DrawablePtr drawable;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Remove a drawable from the scene
|
||||
*/
|
||||
class RemoveDrawableRequest : public DrawableRefChangeRequest {
|
||||
public:
|
||||
RemoveDrawableRequest(util::SimpleIdentity id) : DrawableRefChangeRequest(id) { }
|
||||
RemoveDrawableRequest(const RemoveDrawableRequest&) = default;
|
||||
RemoveDrawableRequest(util::SimpleIdentity id)
|
||||
: DrawableRefChangeRequest(id) {}
|
||||
RemoveDrawableRequest(const RemoveDrawableRequest &) = default;
|
||||
|
||||
void execute(RenderOrchestrator &) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Change the color of all vertexes
|
||||
*/
|
||||
class ResetColorRequest : public DrawableRefChangeRequest {
|
||||
public:
|
||||
ResetColorRequest(util::SimpleIdentity id, Color color) :
|
||||
DrawableRefChangeRequest(id),
|
||||
newColor(color)
|
||||
{ }
|
||||
ResetColorRequest(const ResetColorRequest& other) = default;
|
||||
ResetColorRequest(util::SimpleIdentity id, Color color)
|
||||
: DrawableRefChangeRequest(id),
|
||||
newColor(color) {}
|
||||
ResetColorRequest(const ResetColorRequest &other) = default;
|
||||
|
||||
void execute(RenderOrchestrator &) override;
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
|
||||
/// Coalescing updates is up to the implementer
|
||||
virtual void update(std::shared_ptr<UpdateParameters>) = 0;
|
||||
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
|
||||
@@ -10,20 +10,17 @@ namespace gl {
|
||||
class ShaderProgramGL final : public gfx::ShaderProgramBase {
|
||||
public:
|
||||
ShaderProgramGL(UniqueProgram&& glProgram_);
|
||||
ShaderProgramGL(UniqueProgram&&,
|
||||
VertexAttributeArrayGL&& uniforms,
|
||||
VertexAttributeArrayGL&& attributes);
|
||||
ShaderProgramGL(UniqueProgram&&, VertexAttributeArrayGL&& uniforms, VertexAttributeArrayGL&& attributes);
|
||||
ShaderProgramGL(ShaderProgramGL&& other);
|
||||
~ShaderProgramGL() noexcept override = default;
|
||||
|
||||
static constexpr std::string_view Name{"GenericGLShader"};
|
||||
const std::string_view typeName() const noexcept override { return Name; }
|
||||
|
||||
static std::shared_ptr<ShaderProgramGL> create(
|
||||
Context&,
|
||||
std::string_view name,
|
||||
std::string_view vertexSource,
|
||||
std::string_view fragmentSource) noexcept(false);
|
||||
static std::shared_ptr<ShaderProgramGL> create(Context&,
|
||||
std::string_view name,
|
||||
std::string_view vertexSource,
|
||||
std::string_view fragmentSource) noexcept(false);
|
||||
|
||||
const gfx::VertexAttributeArray& getUniforms() const override { return uniforms; }
|
||||
|
||||
|
||||
@@ -7,17 +7,18 @@ namespace mtl {
|
||||
|
||||
class ShaderProgramMTL : public gfx::ShaderProgramBase {
|
||||
public:
|
||||
ShaderProgramMTL() : ShaderProgramBase() { }
|
||||
ShaderProgramMTL()
|
||||
: ShaderProgramBase() {}
|
||||
~ShaderProgramMTL() noexcept override = default;
|
||||
|
||||
static constexpr std::string_view Name{"GenericMTLShader"};
|
||||
const std::string_view typeName() const noexcept override { return Name; }
|
||||
|
||||
//bool compile(std::string_view vert, std::string_view frag);
|
||||
// Load compiled Metal functions from the default library in a bundle
|
||||
//bool load(NSBundle*, std::string_view vertFuncName, std::string_view fragFuncName);
|
||||
// Load compiled Metal functions from a specific library
|
||||
//bool load(id<MTLLibrary>, std::string_view vertFuncName, std::string_view fragFuncName);
|
||||
// bool compile(std::string_view vert, std::string_view frag);
|
||||
// Load compiled Metal functions from the default library in a bundle
|
||||
// bool load(NSBundle*, std::string_view vertFuncName, std::string_view fragFuncName);
|
||||
// Load compiled Metal functions from a specific library
|
||||
// bool load(id<MTLLibrary>, std::string_view vertFuncName, std::string_view fragFuncName);
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
@@ -11,13 +11,13 @@ namespace gfx {
|
||||
|
||||
class ShaderProgramBase : public gfx::Shader {
|
||||
protected:
|
||||
ShaderProgramBase() { }
|
||||
ShaderProgramBase(ShaderProgramBase&&) { }
|
||||
ShaderProgramBase() {}
|
||||
ShaderProgramBase(ShaderProgramBase&&) {}
|
||||
~ShaderProgramBase() noexcept override = default;
|
||||
|
||||
template <typename T>
|
||||
bool set(gfx::VertexAttributeArray& attrs, const std::string& name, std::size_t i, T value) {
|
||||
auto *item = attrs.get(name);
|
||||
auto* item = attrs.get(name);
|
||||
if (item && i < item->getCount()) {
|
||||
item->set(i, value);
|
||||
return true;
|
||||
|
||||
@@ -12,7 +12,9 @@ namespace util {
|
||||
*/
|
||||
class SimpleIdentity final {
|
||||
private:
|
||||
constexpr SimpleIdentity(std::int64_t id) : uniqueID(id) { }
|
||||
constexpr SimpleIdentity(std::int64_t id)
|
||||
: uniqueID(id) {}
|
||||
|
||||
public:
|
||||
SimpleIdentity();
|
||||
SimpleIdentity(const SimpleIdentity&) = default;
|
||||
@@ -35,7 +37,6 @@ private:
|
||||
std::int64_t uniqueID;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Base class for objects that inherit an automatically-assigned unique identity
|
||||
*/
|
||||
@@ -46,13 +47,13 @@ protected:
|
||||
virtual ~SimpleIdentifiable() = default;
|
||||
|
||||
const util::SimpleIdentity& getId() const { return uniqueID; }
|
||||
|
||||
|
||||
protected:
|
||||
util::SimpleIdentity uniqueID;
|
||||
};
|
||||
|
||||
inline std::string toString(const util::SimpleIdentity& ident) {
|
||||
return "{"+std::to_string(ident.id())+"}";
|
||||
return "{" + std::to_string(ident.id()) + "}";
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
|
||||
@@ -5,13 +5,19 @@ namespace util {
|
||||
|
||||
/// Wrapper that doesn't participate in copying.
|
||||
/// This allows a default-copyable object to have members that aren't copied
|
||||
template<typename T> struct SuppressCopies {
|
||||
template <typename T>
|
||||
struct SuppressCopies {
|
||||
SuppressCopies() = default;
|
||||
SuppressCopies(SuppressCopies const&) {}
|
||||
SuppressCopies(SuppressCopies&& other) : value(std::forward<T>(other.value)) {}
|
||||
SuppressCopies& operator=(SuppressCopies o) { std::swap(value, o.value); return *this; }
|
||||
SuppressCopies(SuppressCopies&& other)
|
||||
: value(std::forward<T>(other.value)) {}
|
||||
SuppressCopies& operator=(SuppressCopies o) {
|
||||
std::swap(value, o.value);
|
||||
return *this;
|
||||
}
|
||||
operator T&() { return value; }
|
||||
T& get() { return value; }
|
||||
T& get() { return value; }
|
||||
|
||||
private:
|
||||
T value;
|
||||
};
|
||||
|
||||
@@ -31,7 +31,6 @@ using UniqueDrawableBuilder = std::unique_ptr<DrawableBuilder>;
|
||||
using DrawableTweakerPtr = std::shared_ptr<DrawableTweaker>;
|
||||
using ShaderProgramBasePtr = std::shared_ptr<ShaderProgramBase>;
|
||||
|
||||
|
||||
class Context {
|
||||
protected:
|
||||
Context(uint32_t maximumVertexBindingCount_)
|
||||
@@ -96,18 +95,17 @@ public:
|
||||
#endif
|
||||
|
||||
virtual void clearStencilBuffer(int32_t) = 0;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
/// Activate the shader, vertex attributes, etc., specified by the drawable
|
||||
virtual bool setupDraw(const PaintParameters&, const gfx::Drawable&) = 0;
|
||||
|
||||
/// Create a new drawable builder
|
||||
virtual UniqueDrawableBuilder createDrawableBuilder(std::string name) = 0;
|
||||
|
||||
|
||||
/// 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;
|
||||
};
|
||||
|
||||
@@ -5,13 +5,10 @@
|
||||
namespace mbgl {
|
||||
namespace gfx {
|
||||
|
||||
Drawable::Drawable(std::string name_) :
|
||||
name(name_),
|
||||
matrix(matrix::identity4()),
|
||||
depthType(DepthMaskType::ReadOnly)
|
||||
{
|
||||
}
|
||||
Drawable::Drawable(std::string name_)
|
||||
: name(name_),
|
||||
matrix(matrix::identity4()),
|
||||
depthType(DepthMaskType::ReadOnly) {}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mbgl
|
||||
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
namespace mbgl {
|
||||
namespace gfx {
|
||||
|
||||
DrawableBuilder::DrawableBuilder(std::string name_) :
|
||||
name(std::move(name_)),
|
||||
impl(std::make_unique<Impl>()) {
|
||||
}
|
||||
DrawableBuilder::DrawableBuilder(std::string name_)
|
||||
: name(std::move(name_)),
|
||||
impl(std::make_unique<Impl>()) {}
|
||||
|
||||
DrawableBuilder::~DrawableBuilder() = default;
|
||||
|
||||
@@ -59,17 +58,17 @@ void DrawableBuilder::setDrawPriority(DrawPriority value) {
|
||||
|
||||
void DrawableBuilder::resetDrawPriority(DrawPriority value) {
|
||||
setDrawPriority(value);
|
||||
for (auto &drawble : drawables) {
|
||||
for (auto& drawble : drawables) {
|
||||
drawble->setDrawPriority(value);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawableBuilder::addTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2) {
|
||||
const auto n = (uint16_t)impl->vertices.elements();
|
||||
impl->vertices.emplace_back(Impl::VT({{{ x0, y0 }}}));
|
||||
impl->vertices.emplace_back(Impl::VT({{{ x1, y1 }}}));
|
||||
impl->vertices.emplace_back(Impl::VT({{{ x2, y2 }}}));
|
||||
impl->indexes.emplace_back(n, n+1, n+2);
|
||||
impl->vertices.emplace_back(Impl::VT({{{x0, y0}}}));
|
||||
impl->vertices.emplace_back(Impl::VT({{{x1, y1}}}));
|
||||
impl->vertices.emplace_back(Impl::VT({{{x2, y2}}}));
|
||||
impl->indexes.emplace_back(n, n + 1, n + 2);
|
||||
if (colorMode == ColorMode::PerVertex) {
|
||||
impl->colors.insert(impl->colors.end(), 3, impl->currentColor);
|
||||
}
|
||||
@@ -77,8 +76,8 @@ void DrawableBuilder::addTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1
|
||||
|
||||
void DrawableBuilder::appendTriangle(int16_t x0, int16_t y0) {
|
||||
const auto n = (uint16_t)impl->vertices.elements();
|
||||
impl->vertices.emplace_back(Impl::VT({{{ x0, y0 }}}));
|
||||
impl->indexes.emplace_back(n-2, n-1, n);
|
||||
impl->vertices.emplace_back(Impl::VT({{{x0, y0}}}));
|
||||
impl->indexes.emplace_back(n - 2, n - 1, n);
|
||||
if (colorMode == ColorMode::PerVertex) {
|
||||
impl->colors.emplace_back(impl->currentColor);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace mbgl {
|
||||
namespace gfx {
|
||||
|
||||
struct DrawableBuilder::Impl {
|
||||
using VT = gfx::detail::VertexType<gfx::AttributeType<std::int16_t,2>>;
|
||||
using VT = gfx::detail::VertexType<gfx::AttributeType<std::int16_t, 2>>;
|
||||
gfx::VertexVector<VT> vertices;
|
||||
gfx::IndexVector<gfx::Triangles> indexes;
|
||||
SegmentVector<TypeList<void>> segments;
|
||||
@@ -20,4 +20,3 @@ struct DrawableBuilder::Impl {
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mbgl
|
||||
|
||||
|
||||
@@ -8,21 +8,19 @@ namespace mbgl {
|
||||
namespace gfx {
|
||||
|
||||
VertexAttributeArray::VertexAttributeArray(int initCapacity)
|
||||
: attrs(initCapacity) {
|
||||
}
|
||||
: attrs(initCapacity) {}
|
||||
|
||||
VertexAttributeArray::VertexAttributeArray(VertexAttributeArray &&other)
|
||||
: attrs(std::move(other.attrs)) {
|
||||
}
|
||||
VertexAttributeArray::VertexAttributeArray(VertexAttributeArray&& other)
|
||||
: attrs(std::move(other.attrs)) {}
|
||||
|
||||
VertexAttributeArray& VertexAttributeArray::operator=(VertexAttributeArray &&other) {
|
||||
VertexAttributeArray& VertexAttributeArray::operator=(VertexAttributeArray&& other) {
|
||||
attrs = std::move(other.attrs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
VertexAttributeArray& VertexAttributeArray::operator=(const VertexAttributeArray& other) {
|
||||
attrs.clear();
|
||||
for (const auto &kv : other.attrs) {
|
||||
for (const auto& kv : other.attrs) {
|
||||
add(kv.first, copy(*kv.second));
|
||||
}
|
||||
return *this;
|
||||
@@ -33,8 +31,8 @@ VertexAttribute* VertexAttributeArray::get(const std::string& name) const {
|
||||
return (result != attrs.end()) ? result->second.get() : nullptr;
|
||||
}
|
||||
|
||||
VertexAttribute* VertexAttributeArray::add(std::string name, int index,
|
||||
AttributeDataType dataType, int size, std::size_t count) {
|
||||
VertexAttribute* VertexAttributeArray::add(
|
||||
std::string name, int index, AttributeDataType dataType, int size, std::size_t count) {
|
||||
const auto result = attrs.insert(std::make_pair(std::move(name), std::unique_ptr<VertexAttribute>()));
|
||||
if (result.second) {
|
||||
result.first->second = create(index, dataType, size, count);
|
||||
@@ -44,15 +42,14 @@ VertexAttribute* VertexAttributeArray::add(std::string name, int index,
|
||||
}
|
||||
}
|
||||
|
||||
VertexAttribute* VertexAttributeArray::getOrAdd(std::string name, int index,
|
||||
AttributeDataType dataType, int size, std::size_t count) {
|
||||
//attrs.emplace_back(std::make_unique<VertexAttribute>(dataType, count));
|
||||
VertexAttribute* VertexAttributeArray::getOrAdd(
|
||||
std::string name, int index, AttributeDataType dataType, int size, std::size_t count) {
|
||||
// attrs.emplace_back(std::make_unique<VertexAttribute>(dataType, count));
|
||||
const auto result = attrs.insert(std::make_pair(std::move(name), std::unique_ptr<VertexAttribute>()));
|
||||
if (result.second) {
|
||||
result.first->second = create(index, dataType, size, count);
|
||||
} else if (result.first->second->getDataType() != dataType ||
|
||||
result.first->second->getSize() != (std::size_t)size ||
|
||||
result.first->second->getCount() != count) {
|
||||
result.first->second->getSize() != (std::size_t)size || result.first->second->getCount() != count) {
|
||||
return nullptr;
|
||||
}
|
||||
return result.first->second.get();
|
||||
@@ -65,14 +62,12 @@ std::size_t VertexAttributeArray::getTotalSize() const {
|
||||
}
|
||||
|
||||
std::size_t VertexAttributeArray::getMaxCount() const {
|
||||
return std::accumulate(attrs.begin(), attrs.end(), std::size_t(0),
|
||||
[](const auto acc, const auto& kv) {
|
||||
return std::max(acc, kv.second->getCount());
|
||||
});
|
||||
return std::accumulate(attrs.begin(), attrs.end(), std::size_t(0), [](const auto acc, const auto& kv) {
|
||||
return std::max(acc, kv.second->getCount());
|
||||
});
|
||||
}
|
||||
|
||||
void VertexAttributeArray::resolve(const VertexAttributeArray& overrides,
|
||||
ResolveDelegate delegate) const {
|
||||
void VertexAttributeArray::resolve(const VertexAttributeArray& overrides, ResolveDelegate delegate) const {
|
||||
for (auto& kv : attrs) {
|
||||
delegate(kv.first, *kv.second, overrides.get(kv.first));
|
||||
}
|
||||
|
||||
@@ -453,7 +453,7 @@ void Context::setDirtyState() {
|
||||
}
|
||||
|
||||
bool Context::setupDraw(const PaintParameters& parameters, const gfx::Drawable& drawable) {
|
||||
if (const auto &shader = drawable.getShader()) {
|
||||
if (const auto& shader = drawable.getShader()) {
|
||||
const auto& shaderGL = static_cast<const ShaderProgramGL&>(*shader);
|
||||
if (shaderGL.getGLProgramID() != program.getCurrentValue()) {
|
||||
program = shaderGL.getGLProgramID();
|
||||
@@ -473,7 +473,7 @@ bool Context::setupDraw(const PaintParameters& parameters, const gfx::Drawable&
|
||||
auto& drawableGL = static_cast<const DrawableGL&>(drawable);
|
||||
auto& vao = drawableGL.getVertexArray();
|
||||
if (vao.isValid()) {
|
||||
bindVertexArray = vao.getID(); // glBindVertexArray
|
||||
bindVertexArray = vao.getID(); // glBindVertexArray
|
||||
return true;
|
||||
} else {
|
||||
bindVertexArray = value::BindVertexArray::Default;
|
||||
|
||||
@@ -5,19 +5,17 @@
|
||||
namespace mbgl {
|
||||
namespace gl {
|
||||
|
||||
DrawableGL::DrawableGL(std::string name_) :
|
||||
Drawable(std::move(name_)),
|
||||
impl(std::make_unique<Impl>()) {
|
||||
}
|
||||
DrawableGL::DrawableGL(std::string name_)
|
||||
: Drawable(std::move(name_)),
|
||||
impl(std::make_unique<Impl>()) {}
|
||||
|
||||
DrawableGL::~DrawableGL() {
|
||||
impl->vertexArray = { { nullptr, false } };
|
||||
impl->indexBuffer = { 0, nullptr };
|
||||
impl->vertexArray = {{nullptr, false}};
|
||||
impl->indexBuffer = {0, nullptr};
|
||||
impl->attributeBuffer.reset();
|
||||
}
|
||||
|
||||
void DrawableGL::draw(const PaintParameters ¶meters) const
|
||||
{
|
||||
void DrawableGL::draw(const PaintParameters& parameters) const {
|
||||
impl->draw(parameters);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,4 +50,3 @@ void DrawableGLBuilder::init() {
|
||||
|
||||
} // namespace gl
|
||||
} // namespace mbgl
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ namespace gl {
|
||||
using namespace platform;
|
||||
|
||||
class DrawableGL::Impl final {
|
||||
|
||||
public:
|
||||
Impl() = default;
|
||||
~Impl() = default;
|
||||
@@ -33,19 +32,19 @@ public:
|
||||
}
|
||||
|
||||
const gfx::Triangles drawMode;
|
||||
//const gfx::DrawModeType type = gfx::DrawModeType::Triangles;
|
||||
// const gfx::DrawModeType type = gfx::DrawModeType::Triangles;
|
||||
|
||||
//ShaderID shaderId;
|
||||
//RenderbufferID renderTarget;
|
||||
// ShaderID shaderId;
|
||||
// RenderbufferID renderTarget;
|
||||
std::vector<TextureID> textures;
|
||||
|
||||
//std::vector<std::uint8_t> vertData;
|
||||
// std::vector<std::uint8_t> vertData;
|
||||
std::vector<std::uint16_t> indexes;
|
||||
|
||||
VertexAttributeArrayGL vertexAttributes;
|
||||
|
||||
VertexArray vertexArray = { { nullptr, false } };
|
||||
gfx::IndexBuffer indexBuffer = { 0, nullptr };
|
||||
VertexArray vertexArray = {{nullptr, false}};
|
||||
gfx::IndexBuffer indexBuffer = {0, nullptr};
|
||||
gfx::UniqueVertexBufferResource attributeBuffer;
|
||||
|
||||
std::size_t indexOffset = 0;
|
||||
@@ -55,10 +54,10 @@ public:
|
||||
gfx::StencilMode stencilMode;
|
||||
gfx::ColorMode colorMode;
|
||||
gfx::CullFaceMode cullFaceMode;
|
||||
//gfx::UniformValues<typename Program<>::UniformList> uniformValues;
|
||||
//Segment<Program<>::AttributeList> segment;
|
||||
//gfx::AttributeBindings<Program<>::AttributeList> attributeBindings;
|
||||
//gfx::TextureBindings<Program<>::TextureList> textureBindings;
|
||||
// gfx::UniformValues<typename Program<>::UniformList> uniformValues;
|
||||
// Segment<Program<>::AttributeList> segment;
|
||||
// gfx::AttributeBindings<Program<>::AttributeList> attributeBindings;
|
||||
// gfx::TextureBindings<Program<>::TextureList> textureBindings;
|
||||
GLfloat pointSize = 0.0f;
|
||||
};
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
namespace mbgl {
|
||||
namespace gl {
|
||||
|
||||
void DrawableGLTweaker::execute(gfx::Drawable& drawable, const PaintParameters &) {
|
||||
void DrawableGLTweaker::execute(gfx::Drawable& drawable, const PaintParameters&) {
|
||||
auto& drawGL = (gl::DrawableGL&)drawable;
|
||||
// apply expressions based on current state, update attributes, uniforms, etc.
|
||||
drawGL.getId();
|
||||
@@ -13,4 +13,3 @@ void DrawableGLTweaker::execute(gfx::Drawable& drawable, const PaintParameters &
|
||||
|
||||
} // namespace gl
|
||||
} // namespace mbgl
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ void RendererBackend::initShaders(gfx::ShaderRegistry& shaders) {
|
||||
shader = gl::ShaderProgramGL::create(glContext, shaderName, vert, frag);
|
||||
if (shader) {
|
||||
// Set default values
|
||||
//shader->setAttribute("a_color", gfx::VertexAttribute::matf4{ 1.0f, 1.0f, 1.0f, 1.0f });
|
||||
// shader->setAttribute("a_color", gfx::VertexAttribute::matf4{ 1.0f, 1.0f, 1.0f, 1.0f });
|
||||
|
||||
// Add to the registry
|
||||
if (!shaders.registerShader(shader, shaderName)) {
|
||||
@@ -109,7 +109,7 @@ void RendererBackend::initShaders(gfx::ShaderRegistry& shaders) {
|
||||
Log::Warning(Event::General, "Shader create failed - " + std::string(shaderName));
|
||||
return;
|
||||
}
|
||||
} catch (const std::runtime_error& ex) {
|
||||
} catch (const std::runtime_error& ex) {
|
||||
Log::Warning(Event::General, "Shader create exception - " + std::string(ex.what()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -132,12 +132,11 @@ static void pad(std::vector<T>& vector, std::size_t size, T value) {
|
||||
}
|
||||
|
||||
gfx::AttributeBindingArray UploadPass::buildAttributeBindings(
|
||||
const std::size_t vertexCount,
|
||||
const gfx::VertexAttributeArray& defaults,
|
||||
const gfx::VertexAttributeArray& overrides,
|
||||
const gfx::BufferUsageType usage,
|
||||
/*out*/ std::unique_ptr<gfx::VertexBufferResource>& outBuffer) {
|
||||
|
||||
const std::size_t vertexCount,
|
||||
const gfx::VertexAttributeArray& defaults,
|
||||
const gfx::VertexAttributeArray& overrides,
|
||||
const gfx::BufferUsageType usage,
|
||||
/*out*/ std::unique_ptr<gfx::VertexBufferResource>& outBuffer) {
|
||||
AttributeBindingArray bindings;
|
||||
bindings.resize(defaults.size());
|
||||
|
||||
@@ -148,55 +147,55 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings(
|
||||
allData.reserve(defaults.getTotalSize() * vertexCount);
|
||||
|
||||
// For each attribute in the program, with the corresponding default and optional override...
|
||||
defaults.resolve(overrides, [&](const std::string& name,
|
||||
const gfx::VertexAttribute& defaultAttr,
|
||||
const gfx::VertexAttribute* overrideAttr)->void {
|
||||
defaults.resolve(overrides,
|
||||
[&](const std::string& name,
|
||||
const gfx::VertexAttribute& defaultAttr,
|
||||
const gfx::VertexAttribute* overrideAttr) -> void {
|
||||
const auto& effectiveAttr = overrideAttr ? *overrideAttr : defaultAttr;
|
||||
const auto& effectiveGL = static_cast<const gl::VertexAttributeGL&>(effectiveAttr);
|
||||
const auto& defaultGL = static_cast<const gl::VertexAttributeGL&>(defaultAttr);
|
||||
const auto stride = defaultAttr.getStride();
|
||||
const auto offset = static_cast<uint8_t>(allData.size());
|
||||
|
||||
const auto& effectiveAttr = overrideAttr ? *overrideAttr : defaultAttr;
|
||||
const auto& effectiveGL = static_cast<const gl::VertexAttributeGL&>(effectiveAttr);
|
||||
const auto& defaultGL = static_cast<const gl::VertexAttributeGL&>(defaultAttr);
|
||||
const auto stride = defaultAttr.getStride();
|
||||
const auto offset = static_cast<uint8_t>(allData.size());
|
||||
// Get the raw data for the values in the desired format
|
||||
const auto& rawData = effectiveGL.getRaw(defaultGL.getGLType());
|
||||
|
||||
// Get the raw data for the values in the desired format
|
||||
const auto& rawData = effectiveGL.getRaw(defaultGL.getGLType());
|
||||
if (rawData.size() == stride * vertexCount) {
|
||||
// The override provided a value for each vertex, append it as-is
|
||||
allData.insert(allData.end(), rawData.begin(), rawData.end());
|
||||
} else if (rawData.size() == stride) {
|
||||
// We only have one value, append a copy for each vertex
|
||||
for (std::size_t i = 0; i < vertexCount; ++i) {
|
||||
allData.insert(allData.end(), rawData.begin(), rawData.end());
|
||||
}
|
||||
} else {
|
||||
// something else, the binding is invalid
|
||||
// TODO: throw?
|
||||
Log::Warning(Event::General,
|
||||
"Got " + util::toString(rawData.size()) + " bytes for attribute '" + name +
|
||||
"' (" + util::toString(defaultGL.getIndex()) + "), expected " +
|
||||
util::toString(stride) + " or " + util::toString(stride * vertexCount));
|
||||
return;
|
||||
}
|
||||
|
||||
if (rawData.size() == stride * vertexCount) {
|
||||
// The override provided a value for each vertex, append it as-is
|
||||
allData.insert(allData.end(), rawData.begin(), rawData.end());
|
||||
} else if (rawData.size() == stride) {
|
||||
// We only have one value, append a copy for each vertex
|
||||
for (std::size_t i = 0; i < vertexCount; ++i) {
|
||||
allData.insert(allData.end(), rawData.begin(), rawData.end());
|
||||
}
|
||||
} else {
|
||||
// something else, the binding is invalid
|
||||
// TODO: throw?
|
||||
Log::Warning(Event::General,
|
||||
"Got " + util::toString(rawData.size()) + " bytes for attribute '" + name +
|
||||
"' (" + util::toString(defaultGL.getIndex()) + "), expected " +
|
||||
util::toString(stride) + " or " + util::toString(stride * vertexCount));
|
||||
return;
|
||||
}
|
||||
bindings[defaultGL.getIndex()] = {
|
||||
/*.attribute = */ {defaultAttr.getDataType(), offset},
|
||||
/*.vertexStride = */ static_cast<uint8_t>(stride),
|
||||
/*.vertexBufferResource = */ nullptr, // buffer pointer established later
|
||||
/*.vertexOffset = */ 0,
|
||||
};
|
||||
|
||||
bindings[defaultGL.getIndex()] = {
|
||||
/*.attribute = */ { defaultAttr.getDataType(), offset },
|
||||
/*.vertexStride = */ static_cast<uint8_t>(stride),
|
||||
/*.vertexBufferResource = */nullptr, // buffer pointer established later
|
||||
/*.vertexOffset = */ 0,
|
||||
};
|
||||
|
||||
pad(allData, align, padding);
|
||||
});
|
||||
pad(allData, align, padding);
|
||||
});
|
||||
|
||||
auto vertBuf = createVertexBufferResource(allData.data(), allData.size(), usage);
|
||||
|
||||
// Go back and fill in the newly-allocated buffer in each binding that was generated
|
||||
std::for_each(bindings.begin(), bindings.end(), [&](auto& b) {
|
||||
if (b) {
|
||||
b->vertexBufferResource = vertBuf.get();
|
||||
}
|
||||
});
|
||||
if (b) {
|
||||
b->vertexBufferResource = vertBuf.get();
|
||||
}
|
||||
});
|
||||
|
||||
outBuffer = std::move(vertBuf);
|
||||
return bindings;
|
||||
|
||||
@@ -17,33 +17,55 @@ using namespace platform;
|
||||
|
||||
int VertexAttributeGL::getSize(GLenum glType) {
|
||||
switch (glType) {
|
||||
case GL_FLOAT: return 4*1;
|
||||
case GL_FLOAT_VEC2: return 4*2;
|
||||
case GL_FLOAT_VEC3: return 4*3;
|
||||
case GL_FLOAT_VEC4: return 4*4;
|
||||
case GL_FLOAT_MAT2: return 4*4;
|
||||
case GL_INT: return 4*1;
|
||||
case GL_UNSIGNED_INT: return 4*1;
|
||||
case GL_INT_VEC2: return 4*2;
|
||||
case GL_INT_VEC3: return 4*3;
|
||||
case GL_INT_VEC4: return 4*4;
|
||||
default: return 0;
|
||||
case GL_FLOAT:
|
||||
return 4 * 1;
|
||||
case GL_FLOAT_VEC2:
|
||||
return 4 * 2;
|
||||
case GL_FLOAT_VEC3:
|
||||
return 4 * 3;
|
||||
case GL_FLOAT_VEC4:
|
||||
return 4 * 4;
|
||||
case GL_FLOAT_MAT2:
|
||||
return 4 * 4;
|
||||
case GL_INT:
|
||||
return 4 * 1;
|
||||
case GL_UNSIGNED_INT:
|
||||
return 4 * 1;
|
||||
case GL_INT_VEC2:
|
||||
return 4 * 2;
|
||||
case GL_INT_VEC3:
|
||||
return 4 * 3;
|
||||
case GL_INT_VEC4:
|
||||
return 4 * 4;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int VertexAttributeGL::getStride(GLenum glType) {
|
||||
switch (glType) {
|
||||
case GL_FLOAT: return 4*1;
|
||||
case GL_FLOAT_VEC2: return 4*2;
|
||||
case GL_FLOAT_VEC3: return 4*4;
|
||||
case GL_FLOAT_VEC4: return 4*4;
|
||||
case GL_FLOAT_MAT2: return 4*4;
|
||||
case GL_INT: return 4*1;
|
||||
case GL_UNSIGNED_INT: return 4*1;
|
||||
case GL_INT_VEC2: return 4*2;
|
||||
case GL_INT_VEC3: return 4*4;
|
||||
case GL_INT_VEC4: return 4*4;
|
||||
default: return 0;
|
||||
case GL_FLOAT:
|
||||
return 4 * 1;
|
||||
case GL_FLOAT_VEC2:
|
||||
return 4 * 2;
|
||||
case GL_FLOAT_VEC3:
|
||||
return 4 * 4;
|
||||
case GL_FLOAT_VEC4:
|
||||
return 4 * 4;
|
||||
case GL_FLOAT_MAT2:
|
||||
return 4 * 4;
|
||||
case GL_INT:
|
||||
return 4 * 1;
|
||||
case GL_UNSIGNED_INT:
|
||||
return 4 * 1;
|
||||
case GL_INT_VEC2:
|
||||
return 4 * 2;
|
||||
case GL_INT_VEC3:
|
||||
return 4 * 4;
|
||||
case GL_INT_VEC4:
|
||||
return 4 * 4;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,40 +82,56 @@ static bool get(const gfx::VertexAttribute::ElementType& element, uint8_t* buffe
|
||||
// Copy the value into the buffer with a simple cast, returning true if it works.
|
||||
template <typename T, typename R>
|
||||
static bool get(const gfx::VertexAttribute::ElementType& element, uint8_t* buffer) {
|
||||
return get<T,R>(element, buffer, [](T x)->R{ return static_cast<R>(x); });
|
||||
return get<T, R>(element, buffer, [](T x) -> R { return static_cast<R>(x); });
|
||||
}
|
||||
|
||||
// Copy a particular type from the variant into the specified buffer, returning true if it works.
|
||||
template <typename T>
|
||||
static bool get(const gfx::VertexAttribute::ElementType& element, uint8_t* buffer) {
|
||||
return get<T,T>(element, buffer, [](T x)->T{ return x; });
|
||||
return get<T, T>(element, buffer, [](T x) -> T { return x; });
|
||||
}
|
||||
|
||||
template <typename T, typename R> R cast(T x) { return static_cast<R>(x); }
|
||||
template <typename T, typename R>
|
||||
R cast(T x) {
|
||||
return static_cast<R>(x);
|
||||
}
|
||||
|
||||
// Copy the variant value into the buffer, converting the type if necessary and possible
|
||||
bool VertexAttributeGL::get(const gfx::VertexAttribute::ElementType& element, GLenum glType, uint8_t* buffer) {
|
||||
// TODO: do we need to handle unsigned inputs?
|
||||
switch (glType) {
|
||||
case GL_FLOAT: return gl::get<float>(element, buffer) ||
|
||||
gl::get<float,std::int32_t>(element, buffer);
|
||||
case GL_FLOAT_VEC2: return gl::get<float2>(element, buffer) ||
|
||||
gl::get<int2,float2>(element, buffer, [](int2 x){ return float2{(float)x[0],(float)x[1]}; });
|
||||
case GL_FLOAT_VEC3: return gl::get<float3>(element, buffer);
|
||||
case GL_FLOAT:
|
||||
return gl::get<float>(element, buffer) || gl::get<float, std::int32_t>(element, buffer);
|
||||
case GL_FLOAT_VEC2:
|
||||
return gl::get<float2>(element, buffer) || gl::get<int2, float2>(element, buffer, [](int2 x) {
|
||||
return float2{(float)x[0], (float)x[1]};
|
||||
});
|
||||
case GL_FLOAT_VEC3:
|
||||
return gl::get<float3>(element, buffer);
|
||||
case GL_FLOAT_VEC4:
|
||||
case GL_FLOAT_MAT2: return gl::get<float4>(element, buffer);
|
||||
case GL_INT: return gl::get<std::int32_t>(element, buffer) ||
|
||||
gl::get<float, std::int32_t> (element, buffer);
|
||||
case GL_UNSIGNED_INT: return gl::get<std::int32_t,std::uint32_t>(element, buffer) ||
|
||||
gl::get<float, std::uint32_t>(element, buffer);
|
||||
case GL_INT_VEC2: return gl::get<int2>(element, buffer) ||
|
||||
gl::get<float2,int2>(element, buffer, [](float2 x){ return int2{(std::int32_t)x[0],(std::int32_t)x[1]}; });
|
||||
case GL_UNSIGNED_INT_VEC2: return false; // TODO
|
||||
case GL_INT_VEC3: return gl::get<int3>(element, buffer);
|
||||
case GL_UNSIGNED_INT_VEC3: return false; // TODO
|
||||
case GL_INT_VEC4: return gl::get<int4>(element, buffer);
|
||||
case GL_UNSIGNED_INT_VEC4: return false; // TODO
|
||||
default: return false;
|
||||
case GL_FLOAT_MAT2:
|
||||
return gl::get<float4>(element, buffer);
|
||||
case GL_INT:
|
||||
return gl::get<std::int32_t>(element, buffer) || gl::get<float, std::int32_t>(element, buffer);
|
||||
case GL_UNSIGNED_INT:
|
||||
return gl::get<std::int32_t, std::uint32_t>(element, buffer) ||
|
||||
gl::get<float, std::uint32_t>(element, buffer);
|
||||
case GL_INT_VEC2:
|
||||
return gl::get<int2>(element, buffer) || gl::get<float2, int2>(element, buffer, [](float2 x) {
|
||||
return int2{(std::int32_t)x[0], (std::int32_t)x[1]};
|
||||
});
|
||||
case GL_UNSIGNED_INT_VEC2:
|
||||
return false; // TODO
|
||||
case GL_INT_VEC3:
|
||||
return gl::get<int3>(element, buffer);
|
||||
case GL_UNSIGNED_INT_VEC3:
|
||||
return false; // TODO
|
||||
case GL_INT_VEC4:
|
||||
return gl::get<int4>(element, buffer);
|
||||
case GL_UNSIGNED_INT_VEC4:
|
||||
return false; // TODO
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +147,7 @@ std::size_t VertexAttributeGL::getStride() const {
|
||||
const std::vector<std::uint8_t>& VertexAttributeGL::getRaw(platform::GLenum type) const {
|
||||
if (dirty || rawType != type) {
|
||||
const auto count = getCount();
|
||||
//const auto size_ = getSize(type);
|
||||
// const auto size_ = getSize(type);
|
||||
const auto stride_ = getStride(type);
|
||||
|
||||
rawData.resize(stride_ * count);
|
||||
@@ -132,24 +170,38 @@ const std::vector<std::uint8_t>& VertexAttributeGL::getRaw(platform::GLenum type
|
||||
}
|
||||
|
||||
namespace {
|
||||
template <typename T> void applyUniform(GLint, const T&);
|
||||
template <> void applyUniform(GLint, const std::int32_t&) { }
|
||||
template <> void applyUniform(GLint, const gfx::VertexAttribute::int2&) { }
|
||||
template <> void applyUniform(GLint, const gfx::VertexAttribute::int3&) { }
|
||||
template <> void applyUniform(GLint, const gfx::VertexAttribute::int4&) { }
|
||||
template <> void applyUniform(GLint, const float& ) { }
|
||||
template <> void applyUniform(GLint, const gfx::VertexAttribute::float2& ) { }
|
||||
template <> void applyUniform(GLint, const gfx::VertexAttribute::float3& ) { }
|
||||
template <> void applyUniform(GLint, const gfx::VertexAttribute::float4& ) { }
|
||||
template <> void applyUniform(GLint, const gfx::VertexAttribute::matf3& ) { }
|
||||
template <> void applyUniform(GLint location, const gfx::VertexAttribute::matf4& value) {
|
||||
MBGL_CHECK_ERROR(glUniformMatrix4fv(location, 1, GL_FALSE, value.data()));
|
||||
}
|
||||
template <typename T>
|
||||
void applyUniform(GLint, const T&);
|
||||
template <>
|
||||
void applyUniform(GLint, const std::int32_t&) {}
|
||||
template <>
|
||||
void applyUniform(GLint, const gfx::VertexAttribute::int2&) {}
|
||||
template <>
|
||||
void applyUniform(GLint, const gfx::VertexAttribute::int3&) {}
|
||||
template <>
|
||||
void applyUniform(GLint, const gfx::VertexAttribute::int4&) {}
|
||||
template <>
|
||||
void applyUniform(GLint, const float&) {}
|
||||
template <>
|
||||
void applyUniform(GLint, const gfx::VertexAttribute::float2&) {}
|
||||
template <>
|
||||
void applyUniform(GLint, const gfx::VertexAttribute::float3&) {}
|
||||
template <>
|
||||
void applyUniform(GLint, const gfx::VertexAttribute::float4&) {}
|
||||
template <>
|
||||
void applyUniform(GLint, const gfx::VertexAttribute::matf3&) {}
|
||||
template <>
|
||||
void applyUniform(GLint location, const gfx::VertexAttribute::matf4& value) {
|
||||
MBGL_CHECK_ERROR(glUniformMatrix4fv(location, 1, GL_FALSE, value.data()));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
struct ApplyUniform {
|
||||
GLint location;
|
||||
template <typename T> void operator()(const T& value) { applyUniform(location, value); }
|
||||
template <typename T>
|
||||
void operator()(const T& value) {
|
||||
applyUniform(location, value);
|
||||
}
|
||||
};
|
||||
|
||||
void VertexAttributeArrayGL::applyUniforms(const gfx::ShaderProgramBase& shader) {
|
||||
@@ -165,10 +217,9 @@ void VertexAttributeArrayGL::applyUniforms(const gfx::ShaderProgramBase& shader)
|
||||
Log::Warning(Event::General, "Uniform '" + name + "' = " + std::to_string(index));
|
||||
uniform->setIndex(index);
|
||||
}
|
||||
std::visit(ApplyUniform { uniform->getIndex() }, uniform->get(0));
|
||||
std::visit(ApplyUniform{uniform->getIndex()}, uniform->get(0));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace gl
|
||||
} // namespace mbgl
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ void RemoveDrawableRequest::execute(RenderOrchestrator &orchestrator) {
|
||||
}
|
||||
|
||||
void ResetColorRequest::execute(RenderOrchestrator &orchestrator) {
|
||||
if (auto& drawable = orchestrator.getDrawable(drawableID)) {
|
||||
if (auto &drawable = orchestrator.getDrawable(drawableID)) {
|
||||
drawable->resetColor(newColor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ std::optional<Color> RenderBackgroundLayer::getSolidBackground() const {
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
//return { evaluated.get<BackgroundColor>() * evaluated.get<BackgroundOpacity>() };
|
||||
// return { evaluated.get<BackgroundColor>() * evaluated.get<BackgroundOpacity>() };
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
namespace mbgl {
|
||||
|
||||
namespace gfx {
|
||||
class Drawable;
|
||||
using DrawablePtr = std::shared_ptr<Drawable>;
|
||||
} // namespace gfc
|
||||
class Drawable;
|
||||
using DrawablePtr = std::shared_ptr<Drawable>;
|
||||
} // namespace gfx
|
||||
|
||||
class ChangeRequest;
|
||||
|
||||
|
||||
@@ -138,7 +138,6 @@ void RenderOrchestrator::setObserver(RendererObserver* observer_) {
|
||||
|
||||
std::unique_ptr<RenderTree> RenderOrchestrator::createRenderTree(
|
||||
const std::shared_ptr<UpdateParameters>& updateParameters) {
|
||||
|
||||
layersAdded.clear();
|
||||
layersRemoved.clear();
|
||||
|
||||
@@ -723,8 +722,8 @@ bool RenderOrchestrator::isLoaded() const {
|
||||
if (!imageManager->isLoaded()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const auto& entry: renderSources) {
|
||||
|
||||
for (const auto& entry : renderSources) {
|
||||
if (!entry.second->isLoaded()) {
|
||||
return false;
|
||||
}
|
||||
@@ -751,9 +750,8 @@ void RenderOrchestrator::clearData() {
|
||||
}
|
||||
|
||||
void RenderOrchestrator::addChanges(UniqueChangeRequestVec& changes) {
|
||||
pendingChanges.insert(pendingChanges.end(),
|
||||
std::make_move_iterator(changes.begin()),
|
||||
std::make_move_iterator(changes.end()));
|
||||
pendingChanges.insert(
|
||||
pendingChanges.end(), std::make_move_iterator(changes.begin()), std::make_move_iterator(changes.end()));
|
||||
changes.clear();
|
||||
}
|
||||
|
||||
@@ -780,25 +778,25 @@ void RenderOrchestrator::updateLayers(gfx::ShaderRegistry& shaders,
|
||||
gfx::Context& context,
|
||||
const TransformState& state,
|
||||
const std::shared_ptr<UpdateParameters>& updateParameters) {
|
||||
|
||||
const bool isMapModeContinuous = updateParameters->mode == MapMode::Continuous;
|
||||
const auto transitionOptions = isMapModeContinuous ? updateParameters->transitionOptions : style::TransitionOptions();
|
||||
const auto transitionOptions = isMapModeContinuous ? updateParameters->transitionOptions
|
||||
: style::TransitionOptions();
|
||||
const auto defDuration = isMapModeContinuous ? util::DEFAULT_TRANSITION_DURATION : Duration::zero();
|
||||
const PropertyEvaluationParameters evalParameters {
|
||||
const PropertyEvaluationParameters evalParameters{
|
||||
getZoomHistory(),
|
||||
updateParameters->timePoint,
|
||||
transitionOptions.duration.value_or(defDuration),
|
||||
};
|
||||
|
||||
std::vector<std::unique_ptr<ChangeRequest>> changes;
|
||||
|
||||
|
||||
for (auto& kv : layersRemoved) {
|
||||
kv.second->layerRemoved(changes);
|
||||
}
|
||||
for (auto& kv : layersAdded) {
|
||||
kv.second->layerAdded(shaders, context, state, evalParameters, changes);
|
||||
}
|
||||
|
||||
|
||||
for (auto& impl : *layerImpls) {
|
||||
impl->update(context, state, evalParameters, changes);
|
||||
}
|
||||
@@ -808,7 +806,7 @@ void RenderOrchestrator::updateLayers(gfx::ShaderRegistry& shaders,
|
||||
|
||||
void RenderOrchestrator::processChanges() {
|
||||
auto localChanges = std::move(pendingChanges);
|
||||
for (auto &change : localChanges) {
|
||||
for (auto& change : localChanges) {
|
||||
change->execute(*this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,11 +35,11 @@ class CrossTileSymbolIndex;
|
||||
class RenderTree;
|
||||
|
||||
namespace gfx {
|
||||
class Drawable;
|
||||
class ShaderRegistry;
|
||||
class Drawable;
|
||||
class ShaderRegistry;
|
||||
|
||||
using DrawablePtr = std::shared_ptr<Drawable>;
|
||||
} // namespace gfx
|
||||
using DrawablePtr = std::shared_ptr<Drawable>;
|
||||
} // namespace gfx
|
||||
|
||||
namespace style {
|
||||
class LayerProperties;
|
||||
|
||||
@@ -104,7 +104,7 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
|
||||
staticData->upload(*uploadPass);
|
||||
renderTree.getLineAtlas().upload(*uploadPass);
|
||||
renderTree.getPatternAtlas().upload(*uploadPass);
|
||||
|
||||
|
||||
for (const auto& pair : orchestrator.getDrawables()) {
|
||||
auto& drawable = *pair.second;
|
||||
|
||||
@@ -117,35 +117,30 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
|
||||
auto& shader = drawable.getShader();
|
||||
|
||||
// Generate a vertex array object for the drawable state, if necessary
|
||||
if (shader && (!drawableGL.getVertexArray().isValid() ||
|
||||
drawableGL.getVertexAttributes().isDirty())) {
|
||||
if (shader && (!drawableGL.getVertexArray().isValid() || drawableGL.getVertexAttributes().isDirty())) {
|
||||
const auto usage = gfx::BufferUsageType::StaticDraw;
|
||||
|
||||
// Build index buffer
|
||||
const auto& indexData = drawable.getIndexData();
|
||||
auto indexBuffer = gfx::IndexBuffer {
|
||||
auto indexBuffer = gfx::IndexBuffer{
|
||||
indexData.size(),
|
||||
uploadPass->createIndexBufferResource(
|
||||
indexData.data(),
|
||||
indexData.size() * sizeof(indexData[0]),
|
||||
usage)
|
||||
};
|
||||
indexData.data(), indexData.size() * sizeof(indexData[0]), usage)};
|
||||
|
||||
// Apply drawable values to shader defaults
|
||||
const auto& defaults = shader->getVertexAttributes();
|
||||
const auto& overrides = drawable.getVertexAttributes();
|
||||
const auto vertexCount = drawable.getVertexCount();
|
||||
std::unique_ptr<gfx::VertexBufferResource> vertexBuffer;
|
||||
auto bindings = uploadPass->buildAttributeBindings(vertexCount, defaults, overrides, usage, vertexBuffer);
|
||||
auto bindings = uploadPass->buildAttributeBindings(
|
||||
vertexCount, defaults, overrides, usage, vertexBuffer);
|
||||
|
||||
auto& glContext = static_cast<gl::Context&>(context);
|
||||
auto vertexArray = glContext.createVertexArray();
|
||||
vertexArray.bind(glContext, indexBuffer, bindings);
|
||||
glContext.bindVertexArray = gl::value::BindVertexArray::Default;
|
||||
|
||||
drawableGL.setVertexArray(std::move(vertexArray),
|
||||
std::move(vertexBuffer),
|
||||
std::move(indexBuffer));
|
||||
drawableGL.setVertexArray(std::move(vertexArray), std::move(vertexBuffer), std::move(indexBuffer));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -203,7 +198,7 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
|
||||
parameters.depthRangeSize = 1 - (1 + 2) * parameters.numSublayers * parameters.depthEpsilon;
|
||||
const auto debugGroup(parameters.renderPass->createDebugGroup("drawables"));
|
||||
|
||||
for (const auto &pair : orchestrator.getDrawables()) {
|
||||
for (const auto& pair : orchestrator.getDrawables()) {
|
||||
const auto& drawable = *pair.second;
|
||||
|
||||
if (!context.setupDraw(parameters, drawable)) {
|
||||
@@ -234,7 +229,6 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
|
||||
// - OPAQUE PASS -------------------------------------------------------------------------------
|
||||
// Render everything top-to-bottom by using reverse iterators. Render opaque objects first.
|
||||
{
|
||||
|
||||
parameters.pass = RenderPass::Opaque;
|
||||
const auto debugGroup(parameters.renderPass->createDebugGroup("opaque"));
|
||||
|
||||
|
||||
@@ -14,58 +14,72 @@ namespace gl {
|
||||
static gfx::AttributeDataType mapType(platform::GLenum attrType) {
|
||||
using T = gfx::AttributeDataType;
|
||||
switch (attrType) {
|
||||
case GL_FLOAT: return T::Float;
|
||||
case GL_FLOAT_VEC2: return T::Float2;
|
||||
case GL_FLOAT_VEC3: return T::Float3;
|
||||
case GL_FLOAT_VEC4: return T::Float4;
|
||||
case GL_FLOAT_MAT2: return T::Float4; // does that work ?
|
||||
case GL_FLOAT:
|
||||
return T::Float;
|
||||
case GL_FLOAT_VEC2:
|
||||
return T::Float2;
|
||||
case GL_FLOAT_VEC3:
|
||||
return T::Float3;
|
||||
case GL_FLOAT_VEC4:
|
||||
return T::Float4;
|
||||
case GL_FLOAT_MAT2:
|
||||
return T::Float4; // does that work ?
|
||||
case GL_FLOAT_MAT3:
|
||||
case GL_FLOAT_MAT4: return T::Float4;
|
||||
case GL_INT: return T::Int;
|
||||
case GL_INT_VEC2: return T::Int2;
|
||||
case GL_INT_VEC3: return T::Int3;
|
||||
case GL_INT_VEC4: return T::Int4;
|
||||
case GL_UNSIGNED_INT: return T::UInt;
|
||||
case GL_FLOAT_MAT4:
|
||||
return T::Float4;
|
||||
case GL_INT:
|
||||
return T::Int;
|
||||
case GL_INT_VEC2:
|
||||
return T::Int2;
|
||||
case GL_INT_VEC3:
|
||||
return T::Int3;
|
||||
case GL_INT_VEC4:
|
||||
return T::Int4;
|
||||
case GL_UNSIGNED_INT:
|
||||
return T::UInt;
|
||||
// ES3 stuff that isn't defined yet:
|
||||
//case GL_FLOAT_MAT2x3:
|
||||
//case GL_FLOAT_MAT2x4:
|
||||
//case GL_FLOAT_MAT3x2:
|
||||
//case GL_FLOAT_MAT3x4:
|
||||
//case GL_FLOAT_MAT4x2:
|
||||
//case GL_FLOAT_MAT4x3: return T::Invalid;
|
||||
//case GL_UNSIGNED_INT_VEC2: return T::UInt2;
|
||||
//case GL_UNSIGNED_INT_VEC3: return T::UInt3;
|
||||
//case GL_UNSIGNED_INT_VEC4: return T::UInt4;
|
||||
//case GL_DOUBLE: return T::Float;
|
||||
//case GL_DOUBLE_VEC2: return T::Float2;
|
||||
//case GL_DOUBLE_VEC3: return T::Float3;
|
||||
//case GL_DOUBLE_VEC4: return T::Float4;
|
||||
//case GL_DOUBLE_MAT2: return T::Float4;
|
||||
//case GL_DOUBLE_MAT3:
|
||||
//case GL_DOUBLE_MAT4:
|
||||
//case GL_DOUBLE_MAT2x3:
|
||||
//case GL_DOUBLE_MAT2x4:
|
||||
//case GL_DOUBLE_MAT3x2:
|
||||
//case GL_DOUBLE_MAT3x4:
|
||||
//case GL_DOUBLE_MAT4x2:
|
||||
//case GL_DOUBLE_MAT4x3:
|
||||
default: return T::Invalid;
|
||||
// case GL_FLOAT_MAT2x3:
|
||||
// case GL_FLOAT_MAT2x4:
|
||||
// case GL_FLOAT_MAT3x2:
|
||||
// case GL_FLOAT_MAT3x4:
|
||||
// case GL_FLOAT_MAT4x2:
|
||||
// case GL_FLOAT_MAT4x3: return T::Invalid;
|
||||
// case GL_UNSIGNED_INT_VEC2: return T::UInt2;
|
||||
// case GL_UNSIGNED_INT_VEC3: return T::UInt3;
|
||||
// case GL_UNSIGNED_INT_VEC4: return T::UInt4;
|
||||
// case GL_DOUBLE: return T::Float;
|
||||
// case GL_DOUBLE_VEC2: return T::Float2;
|
||||
// case GL_DOUBLE_VEC3: return T::Float3;
|
||||
// case GL_DOUBLE_VEC4: return T::Float4;
|
||||
// case GL_DOUBLE_MAT2: return T::Float4;
|
||||
// case GL_DOUBLE_MAT3:
|
||||
// case GL_DOUBLE_MAT4:
|
||||
// case GL_DOUBLE_MAT2x3:
|
||||
// case GL_DOUBLE_MAT2x4:
|
||||
// case GL_DOUBLE_MAT3x2:
|
||||
// case GL_DOUBLE_MAT3x4:
|
||||
// case GL_DOUBLE_MAT4x2:
|
||||
// case GL_DOUBLE_MAT4x3:
|
||||
default:
|
||||
return T::Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
// No `AttributeDataType` for 4x4, so we have to account for it separately...
|
||||
static int mapCount(const platform::GLenum attrType) {
|
||||
switch (attrType) {
|
||||
case GL_FLOAT_MAT3: return 3;
|
||||
case GL_FLOAT_MAT4: return 4;
|
||||
default: return 1;
|
||||
case GL_FLOAT_MAT3:
|
||||
return 3;
|
||||
case GL_FLOAT_MAT4:
|
||||
return 4;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
ShaderProgramGL::ShaderProgramGL(UniqueProgram&& glProgram_)
|
||||
: ShaderProgramBase(),
|
||||
glProgram(std::move(glProgram_)) {
|
||||
}
|
||||
glProgram(std::move(glProgram_)) {}
|
||||
|
||||
ShaderProgramGL::ShaderProgramGL(UniqueProgram&& program,
|
||||
VertexAttributeArrayGL&& uniforms_,
|
||||
@@ -73,20 +87,18 @@ ShaderProgramGL::ShaderProgramGL(UniqueProgram&& program,
|
||||
: ShaderProgramBase(),
|
||||
glProgram(std::move(program)),
|
||||
uniforms(std::move(uniforms_)),
|
||||
vertexAttributes(std::move(attributes_)) {
|
||||
}
|
||||
vertexAttributes(std::move(attributes_)) {}
|
||||
|
||||
ShaderProgramGL::ShaderProgramGL(ShaderProgramGL&& other)
|
||||
: ShaderProgramBase(std::forward<ShaderProgramBase&&>(other)),
|
||||
glProgram(std::move(other.glProgram)),
|
||||
uniforms(std::move(other.uniforms)),
|
||||
vertexAttributes(std::move(other.vertexAttributes)) {
|
||||
}
|
||||
vertexAttributes(std::move(other.vertexAttributes)) {}
|
||||
|
||||
using namespace platform;
|
||||
|
||||
static void addAttr(VertexAttributeArrayGL& attrs, const char* name, GLint index,
|
||||
GLsizei length, GLint count, GLenum glType) {
|
||||
static void addAttr(
|
||||
VertexAttributeArrayGL& attrs, const char* name, GLint index, GLsizei length, GLint count, GLenum glType) {
|
||||
const auto elementType = mapType(glType);
|
||||
const auto elementCount = mapCount(glType); // number of `elementType`, hopefully temporary
|
||||
if (elementType != gfx::AttributeDataType::Invalid && length > 0) {
|
||||
@@ -97,22 +109,21 @@ static void addAttr(VertexAttributeArrayGL& attrs, const char* name, GLint index
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<ShaderProgramGL> ShaderProgramGL::create(
|
||||
Context& context,
|
||||
std::string_view /*name*/,
|
||||
std::string_view vertexSource,
|
||||
std::string_view fragmentSource) noexcept(false) {
|
||||
|
||||
std::shared_ptr<ShaderProgramGL> ShaderProgramGL::create(Context& context,
|
||||
std::string_view /*name*/,
|
||||
std::string_view vertexSource,
|
||||
std::string_view fragmentSource) noexcept(false) {
|
||||
const auto firstAttrib = "a_pos";
|
||||
|
||||
// throws on compile error
|
||||
auto vertProg = context.createShader(ShaderType::Vertex, std::initializer_list<const char*>{vertexSource.data()});
|
||||
auto fragProg = context.createShader(ShaderType::Fragment, std::initializer_list<const char*>{fragmentSource.data()});
|
||||
auto fragProg = context.createShader(ShaderType::Fragment,
|
||||
std::initializer_list<const char*>{fragmentSource.data()});
|
||||
auto program = context.createProgram(vertProg, fragProg, firstAttrib);
|
||||
|
||||
// GLES3.1
|
||||
//GLint numAttribs;
|
||||
//glGetProgramInterfaceiv(program, GL_PROGRAM_INPUT, GL_ACTIVE_RESOURCES, &numAttribs);
|
||||
// GLint numAttribs;
|
||||
// glGetProgramInterfaceiv(program, GL_PROGRAM_INPUT, GL_ACTIVE_RESOURCES, &numAttribs);
|
||||
|
||||
VertexAttributeArrayGL uniforms;
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
namespace mbgl {
|
||||
namespace mtl {
|
||||
|
||||
//bool ShaderProgramMTL::compile(std::string_view vert, std::string_view frag) {
|
||||
// return false;
|
||||
//}
|
||||
// bool ShaderProgramMTL::compile(std::string_view vert, std::string_view frag) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
} // namespace mtl
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <mbgl/shaders/shader_program_base.hpp>
|
||||
|
||||
#include <mbgl/gfx/vertex_attribute.hpp>
|
||||
|
||||
|
||||
@@ -66,14 +66,14 @@ public:
|
||||
virtual void update(gfx::Context&,
|
||||
const TransformState&,
|
||||
const PropertyEvaluationParameters&,
|
||||
UniqueChangeRequestVec&) const { }
|
||||
UniqueChangeRequestVec&) const {}
|
||||
|
||||
virtual void layerAdded(gfx::ShaderRegistry&,
|
||||
gfx::Context&,
|
||||
const TransformState&,
|
||||
const PropertyEvaluationParameters&,
|
||||
UniqueChangeRequestVec&) const { }
|
||||
virtual void layerRemoved(UniqueChangeRequestVec&) const { }
|
||||
UniqueChangeRequestVec&) const {}
|
||||
virtual void layerRemoved(UniqueChangeRequestVec&) const {}
|
||||
|
||||
std::string id;
|
||||
std::string source;
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
#include <mbgl/gl/context.hpp>
|
||||
#include <mbgl/renderer/change_request.hpp>
|
||||
#include <mbgl/renderer/paint_parameters.hpp>
|
||||
//#include <mbgl/shaders/gl/shader_program_gl.hpp>
|
||||
//#include <mbgl/shaders/gl/shader_program_gl.hpp>
|
||||
// #include <mbgl/shaders/gl/shader_program_gl.hpp>
|
||||
// #include <mbgl/shaders/gl/shader_program_gl.hpp>
|
||||
#include <mbgl/shaders/shader_program_base.hpp>
|
||||
#include <mbgl/style/layer_properties.hpp>
|
||||
#include <mbgl/util/logging.hpp>
|
||||
@@ -17,13 +17,11 @@
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
|
||||
BackgroundLayer::Impl::Impl(const Impl& other) :
|
||||
Layer::Impl(other),
|
||||
tileDrawables(other.tileDrawables),
|
||||
lastColor(other.lastColor),
|
||||
paint(other.paint)
|
||||
{
|
||||
}
|
||||
BackgroundLayer::Impl::Impl(const Impl& other)
|
||||
: Layer::Impl(other),
|
||||
tileDrawables(other.tileDrawables),
|
||||
lastColor(other.lastColor),
|
||||
paint(other.paint) {}
|
||||
|
||||
bool BackgroundLayer::Impl::hasLayoutDifference(const Layer::Impl&) const {
|
||||
return false;
|
||||
@@ -55,8 +53,7 @@ void BackgroundLayer::Impl::layerRemoved(UniqueChangeRequestVec& changes) const
|
||||
}
|
||||
|
||||
removeDrawables<decltype(localDrawables)::const_iterator>(
|
||||
localDrawables.cbegin(), localDrawables.cend(), changes,
|
||||
[](auto& ii) { return ii->second->getId(); });
|
||||
localDrawables.cbegin(), localDrawables.cend(), changes, [](auto& ii) { return ii->second->getId(); });
|
||||
}
|
||||
|
||||
void BackgroundLayer::Impl::update(gfx::Context& context,
|
||||
@@ -71,7 +68,7 @@ void BackgroundLayer::Impl::update(gfx::Context& context,
|
||||
const auto evaluated = unevaluated->evaluate(evalParameters);
|
||||
|
||||
// TODO: If background is solid, we can skip drawables and rely on the clear color
|
||||
//const auto passes = eval.get<style::BackgroundOpacity>() == 0.0f
|
||||
// const auto passes = eval.get<style::BackgroundOpacity>() == 0.0f
|
||||
// ? RenderPass::None
|
||||
// : (!uneval.get<style::BackgroundPattern>().isUndefined()
|
||||
// || eval.get<style::BackgroundOpacity>() < 1.0f
|
||||
@@ -79,8 +76,8 @@ void BackgroundLayer::Impl::update(gfx::Context& context,
|
||||
// ? RenderPass::Translucent
|
||||
// : RenderPass::Opaque | RenderPass::Translucent; // evaluated based on opaquePassCutoff in render()
|
||||
|
||||
//unevaluated.hasTransition();
|
||||
//getCrossfade<BackgroundLayerProperties>(evaluatedProperties).t != 1;
|
||||
// unevaluated.hasTransition();
|
||||
// getCrossfade<BackgroundLayerProperties>(evaluatedProperties).t != 1;
|
||||
|
||||
std::optional<Color> color;
|
||||
if (evaluated.get<BackgroundPattern>().from.empty()) {
|
||||
@@ -93,8 +90,7 @@ void BackgroundLayer::Impl::update(gfx::Context& context,
|
||||
// If the result is transparent or missing, just remove any existing drawables and stop
|
||||
if (!color) {
|
||||
removeDrawables<decltype(tileDrawables)::const_iterator>(
|
||||
tileDrawables.cbegin(), tileDrawables.cend(), changes,
|
||||
[](auto& ii) { return ii->second->getId(); });
|
||||
tileDrawables.cbegin(), tileDrawables.cend(), changes, [](auto& ii) { return ii->second->getId(); });
|
||||
tileDrawables.clear();
|
||||
return;
|
||||
}
|
||||
@@ -106,7 +102,7 @@ void BackgroundLayer::Impl::update(gfx::Context& context,
|
||||
const auto tileCover = util::tileCover(state, zoom);
|
||||
|
||||
// Drawables per overscaled or canonical tile?
|
||||
//const UnwrappedTileID unwrappedTileID = tileID.toUnwrapped();
|
||||
// const UnwrappedTileID unwrappedTileID = tileID.toUnwrapped();
|
||||
|
||||
// Put the tile cover into a searchable form.
|
||||
// TODO: Likely better to sort and `std::binary_search` the vector.
|
||||
@@ -114,14 +110,15 @@ void BackgroundLayer::Impl::update(gfx::Context& context,
|
||||
const std::unordered_set<OverscaledTileID> newTileIDs(tileCover.begin(), tileCover.end());
|
||||
|
||||
// For each existing tile drawable...
|
||||
for (auto iter = tileDrawables.begin(); iter != tileDrawables.end(); ) {
|
||||
for (auto iter = tileDrawables.begin(); iter != tileDrawables.end();) {
|
||||
const auto& drawable = iter->second;
|
||||
|
||||
// Has this tile dropped out of the cover set?
|
||||
if (newTileIDs.find(iter->first) == newTileIDs.end()) {
|
||||
// remove it
|
||||
changes.emplace_back(std::make_unique<RemoveDrawableRequest>(drawable->getId()));
|
||||
//Log::Warning(Event::General, "Removing drawable for " + util::toString(iter->first) + " total " + std::to_string(stats.tileDrawablesRemoved+1));
|
||||
// Log::Warning(Event::General, "Removing drawable for " + util::toString(iter->first) + " total " +
|
||||
// std::to_string(stats.tileDrawablesRemoved+1));
|
||||
iter = tileDrawables.erase(iter);
|
||||
++stats.tileDrawablesRemoved;
|
||||
continue;
|
||||
@@ -158,7 +155,7 @@ void BackgroundLayer::Impl::update(gfx::Context& context,
|
||||
|
||||
// Tile coordinates are fixed...
|
||||
builder->addQuad(0, 0, util::EXTENT, util::EXTENT);
|
||||
|
||||
|
||||
// ... they're placed with the matrix in the uniforms, which changes with the view
|
||||
builder->setMatrix(/*parameters.matrixForTile(tileID.toUnwrapped())*/ matrix::identity4());
|
||||
|
||||
@@ -171,7 +168,8 @@ void BackgroundLayer::Impl::update(gfx::Context& context,
|
||||
result.first->second = drawable;
|
||||
changes.emplace_back(std::make_unique<AddDrawableRequest>(std::move(drawable)));
|
||||
++stats.tileDrawablesAdded;
|
||||
//Log::Warning(Event::General, "Adding drawable for " + util::toString(tileID) + " total " + std::to_string(stats.tileDrawablesAdded+1));
|
||||
// Log::Warning(Event::General, "Adding drawable for " + util::toString(tileID) + " total " +
|
||||
// std::to_string(stats.tileDrawablesAdded+1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,9 @@ public:
|
||||
private:
|
||||
// Add a deletion change request for each drawable in a collection
|
||||
template <typename T>
|
||||
static void removeDrawables(T beg, const T end, UniqueChangeRequestVec& changes,
|
||||
static void removeDrawables(T beg,
|
||||
const T end,
|
||||
UniqueChangeRequestVec& changes,
|
||||
std::function<util::SimpleIdentity(const T&)> f) {
|
||||
for (; beg != end; ++beg) {
|
||||
changes.emplace_back(std::make_unique<RemoveDrawableRequest>(f(beg)));
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
#include <atomic>
|
||||
|
||||
namespace {
|
||||
// This is not in the class declaration to minimize include dependencies
|
||||
std::atomic<std::int64_t> nextId = 1;
|
||||
} // anonymous namespace
|
||||
// This is not in the class declaration to minimize include dependencies
|
||||
std::atomic<std::int64_t> nextId = 1;
|
||||
} // anonymous namespace
|
||||
|
||||
namespace mbgl {
|
||||
namespace util {
|
||||
@@ -13,11 +13,7 @@ namespace util {
|
||||
const SimpleIdentity SimpleIdentity::Empty = {emptyID};
|
||||
|
||||
SimpleIdentity::SimpleIdentity()
|
||||
: uniqueID(nextId++)
|
||||
{
|
||||
}
|
||||
|
||||
: uniqueID(nextId++) {}
|
||||
|
||||
} // namespace util
|
||||
} // namespace mbgl
|
||||
|
||||
|
||||
@@ -33,8 +33,12 @@ using matf4 = std::array<float, 16>;
|
||||
namespace matrix {
|
||||
|
||||
void identity(mat4& out);
|
||||
constexpr mat4 identity4() { return { 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1 }; }
|
||||
constexpr matf4 identity4f() { return { 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1 }; }
|
||||
constexpr mat4 identity4() {
|
||||
return {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
|
||||
}
|
||||
constexpr matf4 identity4f() {
|
||||
return {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
|
||||
}
|
||||
|
||||
bool invert(mat4& out, const mat4& a);
|
||||
void ortho(mat4& out, double left, double right, double bottom, double top, double near, double far);
|
||||
|
||||
Reference in New Issue
Block a user