Drawable Renderer (#1570), Rebase on main, squash trivial commits
This commit is contained in:
committed by
Bart Louwers
parent
a646cbf938
commit
f76fb98745
@@ -33,7 +33,9 @@ public:
|
||||
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, matf2, 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:
|
||||
@@ -75,7 +77,7 @@ public:
|
||||
|
||||
protected:
|
||||
VertexAttribute& operator=(const VertexAttribute&) = default;
|
||||
VertexAttribute& operator=(const VertexAttribute&& other) {
|
||||
VertexAttribute& operator=(VertexAttribute&& other) {
|
||||
index = other.index;
|
||||
size = other.size;
|
||||
dataType = other.dataType;
|
||||
@@ -101,7 +103,8 @@ public:
|
||||
|
||||
VertexAttributeArray(int initCapacity = 10);
|
||||
VertexAttributeArray(VertexAttributeArray &&);
|
||||
VertexAttributeArray(const VertexAttributeArray&);
|
||||
// Would need to use the virtual assignment operator
|
||||
VertexAttributeArray(const VertexAttributeArray&) = delete;
|
||||
virtual ~VertexAttributeArray() = default;
|
||||
|
||||
std::size_t size() const { return attrs.size(); }
|
||||
@@ -123,10 +126,11 @@ public:
|
||||
|
||||
// Set a value if the element is present
|
||||
template <typename T>
|
||||
const VertexAttribute::ElementType& set(const std::string& name, std::size_t i, T value) {
|
||||
bool set(const std::string& name, std::size_t i, T value) {
|
||||
if (auto *item = get(name)) {
|
||||
item->set(i, value);
|
||||
return item->set(i, value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Indicates whether any values have changed
|
||||
|
||||
@@ -46,7 +46,7 @@ class VertexAttributeArrayGL final : public gfx::VertexAttributeArray {
|
||||
public:
|
||||
VertexAttributeArrayGL(int initCapacity = 10) : VertexAttributeArray(initCapacity) { }
|
||||
VertexAttributeArrayGL(VertexAttributeArrayGL &&other) : VertexAttributeArray(std::move(other)) { }
|
||||
VertexAttributeArrayGL(const VertexAttributeArrayGL& other) : VertexAttributeArray(other) { }
|
||||
VertexAttributeArrayGL(const VertexAttributeArrayGL&) = delete;
|
||||
~VertexAttributeArrayGL() = default;
|
||||
|
||||
VertexAttributeArrayGL& operator=(VertexAttributeArrayGL &&other) {
|
||||
|
||||
@@ -26,7 +26,7 @@ DrawablePtr DrawableBuilder::getCurrentDrawable(bool createIfNone) {
|
||||
|
||||
void DrawableBuilder::flush() {
|
||||
if (!impl->vertices.empty()) {
|
||||
auto draw = getCurrentDrawable(/*create=*/true);
|
||||
auto draw = getCurrentDrawable(/*createIfNone=*/true);
|
||||
currentDrawable->setDrawPriority(drawPriority);
|
||||
currentDrawable->setShader(shader);
|
||||
currentDrawable->setVertexAttributes(getVertexAttributes());
|
||||
|
||||
@@ -11,11 +11,6 @@ VertexAttributeArray::VertexAttributeArray(VertexAttributeArray &&other)
|
||||
: attrs(std::move(other.attrs)) {
|
||||
}
|
||||
|
||||
VertexAttributeArray::VertexAttributeArray(const VertexAttributeArray& other)
|
||||
: attrs(other.attrs.size()) {
|
||||
operator=(other);
|
||||
}
|
||||
|
||||
VertexAttributeArray& VertexAttributeArray::operator=(VertexAttributeArray &&other) {
|
||||
attrs = std::move(other.attrs);
|
||||
return *this;
|
||||
|
||||
@@ -75,8 +75,7 @@ void RendererBackend::initShaders(gfx::ShaderRegistry& shaders) {
|
||||
|
||||
auto shader = shaders.get<gl::ShaderProgramGL>(shaderName);
|
||||
if (!shader) {
|
||||
constexpr auto vert = R"(
|
||||
#version 300 es
|
||||
constexpr auto vert = R"(#version 300 es
|
||||
precision highp float;
|
||||
|
||||
in vec2 a_pos;
|
||||
@@ -94,8 +93,7 @@ void RendererBackend::initShaders(gfx::ShaderRegistry& shaders) {
|
||||
gl_Position = u_matrix * vec4(gl_Position.xy * 8192.0, 0, 1);
|
||||
//gl_Position = u_matrix * vec4(a_pos, 0, 1);
|
||||
})";
|
||||
constexpr auto frag = R"(
|
||||
#version 300 es
|
||||
constexpr auto frag = R"(#version 300 es
|
||||
precision highp float;
|
||||
in vec4 pos;
|
||||
out vec4 color;
|
||||
|
||||
@@ -71,22 +71,25 @@ const std::vector<uint8_t>& VertexAttributeGL::getRaw() const {
|
||||
return rawData;
|
||||
}
|
||||
|
||||
struct ApplyUniform {
|
||||
GLint location;
|
||||
template <typename T> void operator()(const T&);
|
||||
|
||||
template <> void operator()(const std::int32_t&) { }
|
||||
template <> void operator()(const gfx::VertexAttribute::int2&) { }
|
||||
template <> void operator()(const gfx::VertexAttribute::int3&) { }
|
||||
template <> void operator()(const gfx::VertexAttribute::int4&) { }
|
||||
template <> void operator()(const float& ) { }
|
||||
template <> void operator()(const gfx::VertexAttribute::float2& ) { }
|
||||
template <> void operator()(const gfx::VertexAttribute::float3& ) { }
|
||||
template <> void operator()(const gfx::VertexAttribute::float4& ) { }
|
||||
template <> void operator()(const gfx::VertexAttribute::matf3& ) { }
|
||||
template <> void operator()(const gfx::VertexAttribute::matf4& value) {
|
||||
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[0]));
|
||||
}
|
||||
}
|
||||
|
||||
struct ApplyUniform {
|
||||
GLint location;
|
||||
template <typename T> void operator()(const T& value) { applyUniform(location, value); }
|
||||
};
|
||||
|
||||
void VertexAttributeArrayGL::applyUniforms(const gfx::ShaderProgramBase& shader) {
|
||||
|
||||
@@ -119,13 +119,13 @@ std::shared_ptr<ShaderProgramGL> ShaderProgramGL::create(
|
||||
MBGL_CHECK_ERROR(glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &count));
|
||||
MBGL_CHECK_ERROR(glGetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength));
|
||||
|
||||
auto name = std::make_unique<GLchar[]>(maxLength);
|
||||
auto name = std::vector<GLchar>(maxLength);
|
||||
for (GLint index = 0; index < count; ++index) {
|
||||
GLsizei length = 0;
|
||||
GLint size = 0;
|
||||
GLenum glType = 0;
|
||||
MBGL_CHECK_ERROR(glGetActiveUniform(program, index, maxLength, &length, &size, &glType, name.get()));
|
||||
addAttr(uniforms, name.get(), index, length, size, glType);
|
||||
MBGL_CHECK_ERROR(glGetActiveUniform(program, index, maxLength, &length, &size, &glType, &name[0]));
|
||||
addAttr(uniforms, &name[0], index, length, size, glType);
|
||||
}
|
||||
|
||||
VertexAttributeArrayGL attrs;
|
||||
@@ -133,12 +133,13 @@ std::shared_ptr<ShaderProgramGL> ShaderProgramGL::create(
|
||||
count = 0;
|
||||
MBGL_CHECK_ERROR(glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &count));
|
||||
MBGL_CHECK_ERROR(glGetProgramiv(program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxLength));
|
||||
name.resize(maxLength);
|
||||
for (GLint index = 0; index < count; ++index) {
|
||||
GLsizei length = 0; // "number of characters actually written in name (excluding the null terminator)"
|
||||
GLint size = 0; // "size of the attribute variable, in units of the type returned in type"
|
||||
GLenum glType = 0;
|
||||
MBGL_CHECK_ERROR(glGetActiveAttrib(program, index, maxLength, &length, &size, &glType, name.get()));
|
||||
addAttr(attrs, name.get(), index, length, size, glType);
|
||||
MBGL_CHECK_ERROR(glGetActiveAttrib(program, index, maxLength, &length, &size, &glType, &name[0]));
|
||||
addAttr(attrs, &name[0], index, length, size, glType);
|
||||
}
|
||||
|
||||
return std::make_shared<ShaderProgramGL>(std::move(program), std::move(uniforms), std::move(attrs));
|
||||
|
||||
Reference in New Issue
Block a user