Label rendering a bit better

This commit is contained in:
2023-12-14 23:29:54 -06:00
parent 9eee482883
commit 2074cc9211
13 changed files with 201 additions and 61 deletions

View File

@ -33,14 +33,14 @@ void UIShader::getStages(
"vec4 quad;\n"
"vec4 uv;\n"
"vec4 color;\n"
"float texture;\n"
"vec4 style;\n"
"};\n"
"layout (std140) uniform ub_Quad {\n"
"UIShaderQuad quads[" MACRO_STRINGIFY(UI_SHADER_QUAD_COUNT) "];\n"
"};\n"
"out vec2 v_TextCoord;\n"
"out vec4 v_Color;\n"
"out float v_TextureIndex;\n"
"out vec4 v_Style;\n"
"void main() {\n"
"vec4 pos;\n"
"vec2 coord;\n"
@ -52,29 +52,29 @@ void UIShader::getStages(
"pos.x = quad.quad.x;\n"
"pos.y = quad.quad.y;\n"
"coord.x = quad.uv.x;\n"
"coord.y = quad.uv.w;\n"
"coord.y = quad.uv.y;\n"
"} else if(vertexIndex == 1) {\n"
"pos.x = quad.quad.z;\n"
"pos.y = quad.quad.y;\n"
"coord.x = quad.uv.z;\n"
"coord.y = quad.uv.w;\n"
"coord.y = quad.uv.y;\n"
"} else if(vertexIndex == 2) {\n"
"pos.y = quad.quad.w;\n"
"pos.x = quad.quad.x;\n"
"coord.x = quad.uv.x;\n"
"coord.y = quad.uv.y;\n"
"coord.y = quad.uv.w;\n"
"} else if(vertexIndex == 3) {\n"
"pos.x = quad.quad.z;\n"
"pos.y = quad.quad.w;\n"
"coord.x = quad.uv.z;\n"
"coord.y = quad.uv.y;\n"
"coord.y = quad.uv.w;\n"
"}\n"
"pos.z = 0;\n"
"pos.w = 1;\n"
"gl_Position = u_Projection * u_View * u_Model * pos;\n"
"v_TextCoord = coord;\n"
"v_Color = quad.color;\n"
"v_TextureIndex = quad.texture;\n"
"v_Style = quad.style;\n"
"}"
);
@ -83,12 +83,13 @@ void UIShader::getStages(
"#version 330 core\n"
"in vec2 v_TextCoord;\n"
"in vec4 v_Color;\n"
"in float v_TextureIndex;\n"
"in vec4 v_Style;\n"
"uniform sampler2D u_Texture[" MACRO_STRINGIFY(UI_SHADER_TEXTURE_COUNT) "];\n"
"out vec4 o_Color;\n"
"void main() {\n"
"vec4 texColor = vec4(1, 1, 1, 1);\n"
"int vTextInd = int(round(v_TextureIndex));\n"
"int vStyle = int(round(v_Style[0]));\n"
"int vTextInd = int(round(v_Style[1]));\n"
"switch(vTextInd) {\n"
"case -1:\n"
"texColor = vec4(1, 1, 1, 1);\n"
@ -112,7 +113,15 @@ void UIShader::getStages(
"texColor = texture(u_Texture[5], v_TextCoord);\n"
"break;\n"
"}\n"
"o_Color = texColor * v_Color;\n"
"switch(vStyle) {\n"
"case 0:\n"
"o_Color = texColor * v_Color;\n"
"break;\n"
"case 1:\n"
"o_Color.rgb = v_Color.rgb;\n"
"o_Color.a = texColor.r * v_Color.a;\n"
"break;\n"
"}\n"
"}\n"
);
break;
@ -157,27 +166,27 @@ void UIShader::getStages(
ShaderOpenGLStructureType::STD140,
[&](const struct UIShaderQuad &rel, std::vector<struct ShaderParameter> &parameters) {
parameters.push_back(ShaderParameter(
"u_Quad",
"quad",
&rel.quad,
ShaderParameterType::VEC4
));
parameters.push_back(ShaderParameter(
"u_UV",
"uv",
&rel.uv,
ShaderParameterType::VEC4
));
parameters.push_back(ShaderParameter(
"u_Color",
"color",
&rel.color,
ShaderParameterType::COLOR
));
parameters.push_back(ShaderParameter(
"u_Texture",
&rel.texture,
ShaderParameterType::TEXTURE
"style",
&rel.style,
ShaderParameterType::VEC4
));
},
UI_SHADER_QUAD_COUNT

View File

@ -10,12 +10,16 @@ namespace Dawn {
#define UI_SHADER_QUAD_COUNT 1024
#define UI_SHADER_TEXTURE_COUNT 16
enum class UIShaderQuadStyle {
TEXTURED = 0,
FONT = 1
};
struct UIShaderQuad {
glm::vec4 quad;
glm::vec4 uv;
struct Color color;
float_t texture;
glm::vec3 padding;
glm::vec4 style;
};
struct UIShaderData {