Font round 1
This commit is contained in:
@ -184,7 +184,7 @@ void Texture::bufferRaw(void *data) {
|
||||
this->texturePropertiesNeedUpdating = true;
|
||||
}
|
||||
|
||||
void Texture::buffer(struct Color pixels[]) {
|
||||
void Texture::buffer(struct ColorU8 pixels[]) {
|
||||
this->bufferRaw((void*)pixels);
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ namespace Dawn {
|
||||
void fill(struct Color) override;
|
||||
void fill(uint8_t) override;
|
||||
bool_t isReady() override;
|
||||
void buffer(struct Color pixels[]) override;
|
||||
void buffer(struct ColorU8 pixels[]) override;
|
||||
void buffer(uint8_t pixels[]) override;
|
||||
|
||||
/**
|
||||
|
@ -22,7 +22,6 @@ namespace Dawn {
|
||||
void init() {
|
||||
assertTrue(this->id == -1);
|
||||
this->size = sizeof(T);
|
||||
|
||||
glGenBuffers(1, &this->id);
|
||||
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, this->id);
|
||||
|
@ -19,24 +19,22 @@ 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 (std140) uniform ub_Font {\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"
|
||||
"};\n"
|
||||
|
||||
"uniform mat4 u_Model;\n"
|
||||
"out vec2 o_TextCoord;\n"
|
||||
"out vec4 o_VertColor;\n"
|
||||
"flat out int o_TextIndex;\n"
|
||||
|
||||
"void main() {\n"
|
||||
"gl_Position = u_Projection * u_View * u_Model * vec4(aPos.xy, 0, 1.0);\n"
|
||||
@ -44,16 +42,27 @@ void FontShader::compile() {
|
||||
"int quadIndex = gl_VertexID / " MACRO_STRINGIFY(QUAD_VERTICE_COUNT) ";\n"
|
||||
"int partIndex = u_FontQuadParts[quadIndex];\n"
|
||||
"o_VertColor = u_FontParts[partIndex].color;\n"
|
||||
"o_TextIndex = u_FontParts[partIndex].texture;\n"
|
||||
"}",
|
||||
|
||||
// Fragment Shader
|
||||
"#version 330 core\n"
|
||||
"in vec2 o_TextCoord;\n"
|
||||
"in vec4 o_VertColor;\n"
|
||||
"flat in int o_TextIndex;\n"
|
||||
"out vec4 o_Color;\n"
|
||||
"uniform sampler2D u_Text0;\n"
|
||||
"uniform sampler2D u_Text1;\n"
|
||||
|
||||
"void main() {\n"
|
||||
"o_Color = o_VertColor;\n"
|
||||
"vec4 textColor;\n"
|
||||
"if(o_TextIndex == 0) {\n"
|
||||
"textColor = texture(u_Text0, o_TextCoord);"
|
||||
"} else {\n"
|
||||
"textColor = texture(u_Text1, o_TextCoord);"
|
||||
"}\n"
|
||||
"o_Color.a *= textColor.r;\n"
|
||||
"}\n"
|
||||
);
|
||||
#else
|
||||
@ -63,4 +72,6 @@ void FontShader::compile() {
|
||||
this->paramModel = this->getParameterByName("u_Model");
|
||||
this->bufferUiCanvas = this->getBufferLocationByName("ub_UICanvas");
|
||||
this->bufferFont = this->getBufferLocationByName("ub_Font");
|
||||
this->paramTexture0 = this->getParameterByName("u_Text0");
|
||||
this->paramTexture1 = this->getParameterByName("u_Text1");
|
||||
}
|
@ -7,12 +7,14 @@
|
||||
#include "UIShader.hpp"
|
||||
#include "util/macro.hpp"
|
||||
|
||||
#define FONT_SHADER_PARTS_MAX 16
|
||||
#define FONT_SHADER_QUADS_MAX 16
|
||||
#define FONT_SHADER_PARTS_MAX 6
|
||||
#define FONT_SHADER_QUADS_MAX 64
|
||||
#define FONT_SHADER_TEXTURE_MAX 8
|
||||
|
||||
namespace Dawn {
|
||||
struct FontShaderPart {
|
||||
struct Color color;
|
||||
int32_t texture;
|
||||
};
|
||||
|
||||
struct FontShaderBufferData {
|
||||
@ -27,6 +29,8 @@ namespace Dawn {
|
||||
class FontShader : public Shader {
|
||||
public:
|
||||
shaderparameter_t paramModel;
|
||||
shaderparameter_t paramTexture0;
|
||||
shaderparameter_t paramTexture1;
|
||||
shaderbufferlocation_t bufferUiCanvas;
|
||||
shaderbufferlocation_t bufferFont;
|
||||
|
||||
|
@ -44,6 +44,8 @@ void UIShader::compile() {
|
||||
"void main() {\n"
|
||||
"if(u_HasTexture) {\n"
|
||||
"o_Color = texture(u_Text, o_TextCoord) * u_Color;\n"
|
||||
// "o_Color = u_Color;\n"
|
||||
// "o_Color.a = texture(u_Text, o_TextCoord).r;\n"
|
||||
"} else {\n"
|
||||
"o_Color = u_Color;"
|
||||
"}\n"
|
||||
|
Reference in New Issue
Block a user