Finished UI Render Context

This commit is contained in:
2023-12-13 22:55:13 -06:00
parent 952db756a0
commit d2c057cd53
12 changed files with 163 additions and 68 deletions

View File

@ -57,7 +57,7 @@ ShaderStage::ShaderStage(
GLchar *log = new GLchar[logLength];
glGetShaderInfoLog(this->id, logLength, NULL, log);
assertNoGLError();
assertUnreachable("Failed to compile shader stage:\n%s", log);
assertUnreachable("Failed to compile shader stage %i:\n%s", type, log);
}
}

View File

@ -33,19 +33,21 @@ void UIShader::getStages(
"vec4 quad;\n"
"vec4 uv;\n"
"vec4 color;\n"
"float texture;\n"
"};\n"
"layout (std140) uniform ub_Quad {\n"
"UIShaderQuad quads[" MACRO_STRINGIFY(UI_SHADER_QUAD_COUNT) "];\n"
"};\n"
"out vec2 o_TextCoord;\n"
"out vec2 v_TextCoord;\n"
"out vec4 v_Color;\n"
"out float v_TextureIndex;\n"
"void main() {\n"
"vec4 pos;\n"
"vec2 coord;\n"
"int index = int(aPos.z);\n"
"int quadIndex = index / 4;\n"
"int vertexIndex = index % 4;\n"
"struct UIShaderQuad quad = quads[quadIndex];\n"
"UIShaderQuad quad = quads[quadIndex];\n"
"if(vertexIndex == 0) {\n"
"pos.x = quad.quad.x;\n"
"pos.y = quad.quad.y;\n"
@ -70,19 +72,44 @@ void UIShader::getStages(
"pos.z = 0;\n"
"pos.w = 1;\n"
"gl_Position = u_Projection * u_View * u_Model * pos;\n"
"o_TextCoord = coord;\n"
"v_TextCoord = coord;\n"
"v_Color = quad.color;\n"
"v_TextureIndex = quad.texture;\n"
"}"
);
fragment = std::make_shared<ShaderStage>(
ShaderStageType::FRAGMENT,
"#version 330 core\n"
"in vec2 o_TextCoord;\n"
"in vec2 v_TextCoord;\n"
"in vec4 v_Color;\n"
"out vec4 o_Color;\n"
"in float v_TextureIndex;\n"
"uniform sampler2D u_Texture[" MACRO_STRINGIFY(UI_SHADER_TEXTURE_COUNT) "];\n"
"out vec4 o_Color;\n"
"void main() {\n"
"o_Color = v_Color;\n"
"vec4 texColor = vec4(1, 1, 1, 1);\n"
// "switch(int(v_TextureIndex)) {\n"
// "case 0:\n"
// "texColor = texture(u_Texture[0], v_TextCoord);\n"
// "break;\n"
// "case 1:\n"
// "texColor = texture(u_Texture[1], v_TextCoord);\n"
// "break;\n"
// "case 2:\n"
// "texColor = texture(u_Texture[2], v_TextCoord);\n"
// "break;\n"
// "case 3:\n"
// "texColor = texture(u_Texture[3], v_TextCoord);\n"
// "break;\n"
// "case 4:\n"
// "texColor = texture(u_Texture[4], v_TextCoord);\n"
// "break;\n"
// "case 5:\n"
// "texColor = texture(u_Texture[5], v_TextCoord);\n"
// "break;\n"
// "}\n"
"texColor = texture(u_Texture[0], v_TextCoord);\n"
"o_Color = texColor * v_Color;\n"
"}\n"
);
break;
@ -113,6 +140,13 @@ void UIShader::getStages(
&rel->model,
ShaderParameterType::MAT4
));
parameters.push_back(ShaderParameter(
"u_Texture",
&rel->textures,
ShaderParameterType::TEXTURE,
UI_SHADER_TEXTURE_COUNT
));
structures.push_back(ShaderStructure<struct UIShaderQuad>(
"ub_Quad",
@ -136,6 +170,12 @@ void UIShader::getStages(
&rel.color,
ShaderParameterType::COLOR
));
parameters.push_back(ShaderParameter(
"u_Texture",
&rel.texture,
ShaderParameterType::TEXTURE
));
},
UI_SHADER_QUAD_COUNT
));

View File

@ -8,17 +8,20 @@
namespace Dawn {
#define UI_SHADER_QUAD_COUNT 32
#define UI_SHADER_TEXTURE_COUNT 6
struct UIShaderQuad {
glm::vec4 quad;
glm::vec4 uv;
struct Color color;
float_t texture;
};
struct UIShaderData {
glm::mat4 projection;
glm::mat4 view;
glm::mat4 model;
shadertexturebinding_t textures[UI_SHADER_TEXTURE_COUNT];
struct UIShaderQuad quads[UI_SHADER_QUAD_COUNT];
};