TTF Prog
This commit is contained in:
@ -19,18 +19,18 @@ void FontShader::compile() {
|
||||
"#version 330 core\n"
|
||||
"layout (location = 0) in vec3 aPos;\n"
|
||||
"layout (location = 1) in vec2 aTexCoord;\n"
|
||||
|
||||
"layout (std140) uniform ub_UICanvas {\n"
|
||||
"mat4 u_View;\n"
|
||||
"mat4 u_Projection;\n"
|
||||
"};"
|
||||
"struct FontShaderPart {\n"
|
||||
"vec4 color;\n"
|
||||
"int texture;\n"
|
||||
"};\n"
|
||||
|
||||
"layout (shared) uniform ub_Font {\n"
|
||||
"FontShaderPart u_FontParts[" MACRO_STRINGIFY(FONT_SHADER_PARTS_MAX) "];\n"
|
||||
"int u_FontQuadParts[" MACRO_STRINGIFY(FONT_SHADER_QUADS_MAX) "];\n"
|
||||
"int u_FontQuadMappings[" MACRO_STRINGIFY(FONT_SHADER_QUADS_MAX) "];\n"
|
||||
"int u_FontTextures[" MACRO_STRINGIFY(FONT_SHADER_PARTS_MAX) "];\n"
|
||||
"vec4 u_FontColors[" MACRO_STRINGIFY(FONT_SHADER_PARTS_MAX) "];\n"
|
||||
"};\n"
|
||||
|
||||
"uniform mat4 u_Model;\n"
|
||||
"out vec2 o_TextCoord;\n"
|
||||
"out vec4 o_VertColor;\n"
|
||||
@ -40,10 +40,9 @@ void FontShader::compile() {
|
||||
"gl_Position = u_Projection * u_View * u_Model * vec4(aPos.xy, 0, 1.0);\n"
|
||||
"o_TextCoord = vec2(aTexCoord.x, aTexCoord.y);\n"
|
||||
"int quadIndex = gl_VertexID / " MACRO_STRINGIFY(QUAD_VERTICE_COUNT) ";\n"
|
||||
"int partIndex = quadIndex < 5 ? 0 : 1;\n"
|
||||
// "int partIndex = u_FontQuadParts[0];\n"
|
||||
"o_VertColor = u_FontParts[partIndex].color;\n"
|
||||
"o_TextIndex = u_FontParts[partIndex].texture;\n"
|
||||
"int partIndex = u_FontQuadMappings[quadIndex];\n"
|
||||
"o_VertColor = u_FontColors[partIndex];\n"
|
||||
"o_TextIndex = u_FontTextures[partIndex];\n"
|
||||
"}",
|
||||
|
||||
// Fragment Shader
|
||||
@ -54,16 +53,19 @@ void FontShader::compile() {
|
||||
"out vec4 o_Color;\n"
|
||||
"uniform sampler2D u_Text0;\n"
|
||||
"uniform sampler2D u_Text1;\n"
|
||||
"uniform sampler2D u_Text2;\n"
|
||||
|
||||
"void main() {\n"
|
||||
"o_Color = o_VertColor;\n"
|
||||
"vec4 textColor;\n"
|
||||
"vec4 tColor;"
|
||||
"if(o_TextIndex == 0) \n{"
|
||||
"textColor = texture(u_Text0, o_TextCoord);\n"
|
||||
"tColor = texture(u_Text0, o_TextCoord);\n"
|
||||
"} else if(o_TextIndex == 1) \n{"
|
||||
"tColor = texture(u_Text1, o_TextCoord);\n"
|
||||
"} else {\n"
|
||||
"textColor = texture(u_Text1, o_TextCoord);\n"
|
||||
"tColor = texture(u_Text2, o_TextCoord);\n"
|
||||
"}\n"
|
||||
"o_Color.a = textColor.r;\n"
|
||||
"o_Color.a *= tColor.r;\n"
|
||||
"}\n"
|
||||
);
|
||||
#else
|
||||
@ -75,4 +77,5 @@ void FontShader::compile() {
|
||||
this->bufferFont = this->getBufferLocationByName("ub_Font");
|
||||
this->paramTexture0 = this->getParameterByName("u_Text0");
|
||||
this->paramTexture1 = this->getParameterByName("u_Text1");
|
||||
this->paramTexture2 = this->getParameterByName("u_Text2");
|
||||
}
|
@ -7,24 +7,18 @@
|
||||
#include "UIShader.hpp"
|
||||
#include "util/macro.hpp"
|
||||
|
||||
#define FONT_SHADER_PARTS_MAX 6
|
||||
#define FONT_SHADER_QUADS_MAX 64
|
||||
#define FONT_SHADER_PARTS_MAX 4
|
||||
#define FONT_SHADER_QUADS_MAX 32
|
||||
#define FONT_SHADER_TEXTURE_MAX 8
|
||||
|
||||
namespace Dawn {
|
||||
#pragma pack(push, 1)
|
||||
struct FontShaderPart {
|
||||
struct Color color;
|
||||
int32_t texture;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push, 1)
|
||||
// #pragma pack(push, 4)
|
||||
struct FontShaderBufferData {
|
||||
struct FontShaderPart fontParts[FONT_SHADER_PARTS_MAX];
|
||||
int32_t fontQuadParts[FONT_SHADER_QUADS_MAX];
|
||||
int32_t fontQuadMappings[FONT_SHADER_QUADS_MAX];
|
||||
int32_t textures[FONT_SHADER_PARTS_MAX];
|
||||
struct Color colors[FONT_SHADER_PARTS_MAX];
|
||||
};
|
||||
#pragma pack(pop)
|
||||
// #pragma pack(pop)
|
||||
|
||||
class FontShaderBuffer : public ShaderParameterBuffer<struct FontShaderBufferData> {
|
||||
|
||||
@ -35,6 +29,7 @@ namespace Dawn {
|
||||
shaderparameter_t paramModel;
|
||||
shaderparameter_t paramTexture0;
|
||||
shaderparameter_t paramTexture1;
|
||||
shaderparameter_t paramTexture2;
|
||||
shaderbufferlocation_t bufferUiCanvas;
|
||||
shaderbufferlocation_t bufferFont;
|
||||
|
||||
|
Reference in New Issue
Block a user