66 lines
1.8 KiB
C++

// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "FontShader.hpp"
#include "display/mesh/QuadMesh.hpp"
using namespace Dawn;
void FontShader::compile() {
#if DAWN_OPENGL_GLSL
this->compileShader(
{
{ "aPos", 0 },
{ "aTexCoord", 1 }
},
// Vertex Shader
"#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"
"};\n"
"layout (std140) uniform ub_Font {\n"
"FontShaderPart u_FontParts[" MACRO_STRINGIFY(FONT_SHADER_PARTS_MAX) "];\n"
"int u_FontQuadParts[" MACRO_STRINGIFY(FONT_SHADER_QUADS_MAX) "];\n"
"};\n"
"uniform mat4 u_Model;\n"
"out vec2 o_TextCoord;\n"
"out vec4 o_VertColor;\n"
"void main() {\n"
"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 = u_FontQuadParts[quadIndex];\n"
"o_VertColor = u_FontParts[partIndex].color;\n"
"}",
// Fragment Shader
"#version 330 core\n"
"in vec2 o_TextCoord;\n"
"in vec4 o_VertColor;\n"
"out vec4 o_Color;\n"
"void main() {\n"
"o_Color = o_VertColor;\n"
"}\n"
);
#else
#error Shader Type unknown
#endif
this->paramModel = this->getParameterByName("u_Model");
this->bufferUiCanvas = this->getBufferLocationByName("ub_UICanvas");
this->bufferFont = this->getBufferLocationByName("ub_Font");
}