Shader uniform slots get their own glue type.

This commit is contained in:
Chinmay Garde
2021-06-22 17:10:12 -07:00
committed by Dan Field
parent 5814885863
commit e79a7fff79
7 changed files with 25 additions and 17 deletions

View File

@@ -44,13 +44,9 @@ struct {{camel_case(shader_name)}}{{camel_case(shader_stage)}}Info {
// ===========================================================================
{% for uniform in uniform_buffers %}
static constexpr auto kUniform{{camel_case(uniform.name)}} = ShaderStageIOSlot { // {{uniform.name}}
"{{uniform.name}}", // name
{{uniform.location}}u, // attribute location
{{uniform.type.type_name}}, // type
{{uniform.type.bit_width}}u, // bit width of type
{{uniform.type.vec_size}}u, // vec size
{{uniform.type.columns}}u // number of columns
static constexpr auto kUniform{{camel_case(uniform.name)}} = ShaderUniformSlot<{{uniform.name}}> { // {{uniform.name}}
"{{uniform.name}}", // name
{{uniform.binding}}u, // binding
};
{% endfor %}

View File

@@ -92,6 +92,8 @@ struct ColorAttachmentDescriptor {
/// } else {
/// final_color = new_color;
/// }
/// // IMPORTANT: The write mask is applied irrespective of whether
/// // blending_enabled is set.
/// final_color = final_color & write_mask;
/// ```

View File

@@ -40,6 +40,7 @@ bool EntityRenderer::OnRender(RenderPass& pass) {
pass.SetLabel("EntityRenderer Render Pass");
shader::BoxVertexInfo::UniformBuffer uniforms;
uniforms.color = Color::Blue();
uniforms.mvp = Matrix::MakeOrthographic({800, 600});
VertexBufferBuilder vertex_builder;
vertex_builder.AddVertices({
@@ -54,11 +55,10 @@ bool EntityRenderer::OnRender(RenderPass& pass) {
Command cmd;
cmd.label = "Box";
cmd.pipeline = box_primitive_->GetPipeline();
// Vertex buffer.
cmd.vertex_bindings.buffers[box_primitive_->GetVertexBufferIndex()] =
vertex_builder.CreateVertexBuffer(pass.GetTransientsBuffer());
// Uniform buffer.
cmd.vertex_bindings.buffers[0u] =
cmd.vertex_bindings
.buffers[shader::BoxVertexInfo::kUniformUniformBuffer.binding] =
pass.GetTransientsBuffer().EmplaceUniform(uniforms);
cmd.index_buffer =
vertex_builder.CreateIndexBuffer(pass.GetTransientsBuffer());

View File

@@ -7,6 +7,7 @@
#include <cmath>
#include <string>
#include "impeller/geometry/color.h"
#include "impeller/geometry/point.h"
#include "impeller/geometry/scalar.h"
#include "impeller/geometry/size.h"
@@ -25,6 +26,8 @@ struct Vector3 {
constexpr Vector3(){};
constexpr Vector3(const Color& c) : x(c.red), y(c.green), z(c.blue) {}
constexpr Vector3(const Point& p) : x(p.x), y(p.y) {}
constexpr Vector3(const Size& s) : x(s.width), y(s.height) {}
@@ -112,6 +115,9 @@ struct Vector4 {
constexpr Vector4() {}
constexpr Vector4(const Color& c)
: x(c.red), y(c.green), z(c.blue), w(c.alpha) {}
constexpr Vector4(Scalar x, Scalar y, Scalar z, Scalar w)
: x(x), y(y), z(z), w(w) {}

View File

@@ -7,5 +7,5 @@ in vec3 color;
out vec4 fragColor;
void main() {
fragColor = vec4(0.0, 1.0, 0.0, 1.0);
fragColor = vec4(color, 1.0);
}

View File

@@ -4,16 +4,13 @@
uniform UniformBuffer {
mat4 mvp;
} uniforms;
uniform UB2 {
vec3 color;
} ub2;
} uniforms;
in vec3 vertexPosition;
out vec3 color;
void main() {
gl_Position = uniforms.mvp * vec4(vertexPosition, 1.0);
color = ub2.color;
gl_Position = vec4(vertexPosition, 1.0);
color = uniforms.color;
}

View File

@@ -40,6 +40,13 @@ enum class ShaderType {
kSampler,
};
template <class T>
struct ShaderUniformSlot {
using Type = T;
const char* name;
size_t binding;
};
struct ShaderStageIOSlot {
const char* name;
size_t location;