Testing Font shader setup for arrays

This commit is contained in:
2023-06-01 10:10:34 -07:00
parent 1b84efe0d6
commit af75bb546a
3 changed files with 34 additions and 14 deletions

View File

@ -14,12 +14,32 @@ UILabelNew::UILabelNew(SceneItem *item) : UIComponentRenderable(item) {
void UILabelNew::onStart() {
std::cout << "Hello new Label" << std::endl;
QuadMesh::initQuadMesh(&this->mesh,
glm::vec2(0, 0), glm::vec2(0, 0),
glm::vec2(32, 32), glm::vec2(1, 1),
0.0f
);
this->shaderBuffer.init();
struct FontShaderBufferData fontData;
int32_t n = 4 * 4;
this->mesh.createBuffers(n * QUAD_VERTICE_COUNT, n * QUAD_INDICE_COUNT);
for(int32_t i = 0; i < n; i++) {
glm::vec2 size = glm::vec2(32, 32);
glm::vec2 pos = glm::vec2(size.x * i, 0) + glm::vec2(2 * i, 0);
QuadMesh::bufferQuadMeshWithZ(&this->mesh,
pos, glm::vec2(0, 0),
pos + size, glm::vec2(1, 1),
0.0f, i * QUAD_VERTICE_COUNT, i * QUAD_INDICE_COUNT
);
fontData.fontQuadParts[i] = i / 4;
}
fontData.fontParts[0].color = COLOR_RED;
fontData.fontParts[1].color = COLOR_GREEN;
fontData.fontParts[2].color = COLOR_BLUE;
fontData.fontParts[3].color = COLOR_MAGENTA;
fontData.fontParts[4].color = COLOR_BLACK;
fontData.fontParts[5].color = COLOR_WHITE;
shaderBuffer.buffer(&fontData);
}
std::vector<struct ShaderPassItem> UILabelNew::getUIRenderPasses() {
@ -33,10 +53,6 @@ std::vector<struct ShaderPassItem> UILabelNew::getUIRenderPasses() {
item.parameterBuffers[shader->bufferUiCanvas] = &canvas->shaderBuffer;
item.parameterBuffers[shader->bufferFont] = &this->shaderBuffer;
struct FontShaderBufferData fontData;
fontData.fontParts[9].color = COLOR_BLUE;
shaderBuffer.buffer(&fontData);
return { item };
}

View File

@ -4,6 +4,7 @@
// https://opensource.org/licenses/MIT
#include "FontShader.hpp"
#include "display/mesh/QuadMesh.hpp"
using namespace Dawn;
@ -30,7 +31,7 @@ void FontShader::compile() {
"layout (std140) uniform ub_Font {\n"
"FontShaderPart u_FontParts[" MACRO_STRINGIFY(FONT_SHADER_PARTS_MAX) "];\n"
"int u_FontPartsCount;\n"
"int u_FontQuadParts[" MACRO_STRINGIFY(FONT_SHADER_QUADS_MAX) "];\n"
"};\n"
"uniform mat4 u_Model;\n"
@ -38,9 +39,11 @@ void FontShader::compile() {
"out vec4 o_VertColor;\n"
"void main() {\n"
"gl_Position = u_Projection * u_View * u_Model * vec4(aPos, 1.0);\n"
"gl_Position = u_Projection * u_View * u_Model * vec4(aPos.xy, 0, 1.0);\n"
"o_TextCoord = vec2(aTexCoord.x, aTexCoord.y);\n"
"o_VertColor = u_FontParts[9].color;\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

View File

@ -7,7 +7,8 @@
#include "UIShader.hpp"
#include "util/macro.hpp"
#define FONT_SHADER_PARTS_MAX 32
#define FONT_SHADER_PARTS_MAX 16
#define FONT_SHADER_QUADS_MAX 16
namespace Dawn {
struct FontShaderPart {
@ -16,7 +17,7 @@ namespace Dawn {
struct FontShaderBufferData {
struct FontShaderPart fontParts[FONT_SHADER_PARTS_MAX];
int32_t fontPartsCount;
int32_t fontQuadParts[FONT_SHADER_QUADS_MAX];
};
class FontShaderBuffer : public ShaderParameterBuffer<struct FontShaderBufferData> {