Fixed some bugs with buffers during font building
This commit is contained in:
@ -37,8 +37,7 @@ void BackBufferRenderTarget::setClearColor(struct Color color) {
|
||||
}
|
||||
|
||||
void BackBufferRenderTarget::clear(flag8_t clearFlags) {
|
||||
auto clear = this->clearColor.precision();
|
||||
glClearColor(clear.r, clear.g, clear.b, clear.a);
|
||||
glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
|
@ -67,12 +67,11 @@ void TextureRenderTarget::setClearColor(struct Color color) {
|
||||
}
|
||||
|
||||
void TextureRenderTarget::clear(flag8_t clearFlags) {
|
||||
auto clear = this->clearColor.precision();
|
||||
glClearColor(
|
||||
clear.r,
|
||||
clear.g,
|
||||
clear.b,
|
||||
clear.a
|
||||
clearColor.r,
|
||||
clearColor.g,
|
||||
clearColor.b,
|
||||
clearColor.a
|
||||
);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
@ -105,8 +105,7 @@ void Shader::setBoolean(shaderparameter_t uni, bool value) {
|
||||
}
|
||||
|
||||
void Shader::setColor(shaderparameter_t uniform, struct Color color) {
|
||||
auto precise = color.precision();
|
||||
glUniform4f(uniform, precise.r, precise.g, precise.b, precise.a);
|
||||
glUniform4f(uniform, color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
void Shader::setVector3(shaderparameter_t uniform, glm::vec3 vector) {
|
||||
|
@ -29,6 +29,10 @@ namespace Dawn {
|
||||
glBufferData(GL_UNIFORM_BUFFER, this->size, NULL, GL_DYNAMIC_DRAW);
|
||||
}
|
||||
|
||||
bool_t isReady() {
|
||||
return this->id != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic buffer method. Buffers the entire contents of the data struct to
|
||||
* this shader parameter buffer.
|
||||
@ -36,11 +40,11 @@ namespace Dawn {
|
||||
* @param data Data to buffer to the parameter.
|
||||
*/
|
||||
void buffer(T *data) {
|
||||
this->bind(0);
|
||||
this->bufferRaw((void*)data);
|
||||
}
|
||||
|
||||
void bind(shaderbufferslot_t location) override {
|
||||
assertTrue(this->isReady());
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, this->id);
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, location, this->id);
|
||||
}
|
||||
@ -63,6 +67,7 @@ namespace Dawn {
|
||||
* @param length Length of the data to buffer.
|
||||
*/
|
||||
void bufferRaw(void *data, size_t start, size_t length) {
|
||||
assertTrue(this->isReady());
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, this->id);
|
||||
glBufferSubData(GL_UNIFORM_BUFFER, start, length, (void*)((size_t)data + start));
|
||||
}
|
||||
@ -99,8 +104,10 @@ namespace Dawn {
|
||||
* Destroys this shader parameter buffer.
|
||||
*/
|
||||
~ShaderParameterBuffer() {
|
||||
glDeleteBuffers(1, &this->id);
|
||||
this->id = -1;
|
||||
if(this->id != -1) {
|
||||
glDeleteBuffers(1, &this->id);
|
||||
this->id = -1;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
@ -18,37 +18,46 @@ 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"
|
||||
"};\n"
|
||||
|
||||
"layout (std140) uniform ub_Font {\n"
|
||||
"FontShaderPart u_FontParts[" MACRO_STRINGIFY(FONT_SHADER_PARTS_MAX) "];\n"
|
||||
"int u_FontPartsCount;\n"
|
||||
"};\n"
|
||||
|
||||
"uniform mat4 u_Proj;\n"
|
||||
"uniform mat4 u_View;\n"
|
||||
"uniform mat4 u_Model;\n"
|
||||
|
||||
"out vec2 o_TextCoord;\n"
|
||||
"out vec4 o_VertColor;\n"
|
||||
|
||||
"void main() {\n"
|
||||
"gl_Position = u_Proj * u_View * u_Model * vec4(aPos, 1.0);\n"
|
||||
"gl_Position = u_Projection * u_View * u_Model * vec4(aPos, 1.0);\n"
|
||||
"o_TextCoord = vec2(aTexCoord.x, aTexCoord.y);\n"
|
||||
"o_VertColor = u_FontParts[9].color;\n"
|
||||
"}",
|
||||
|
||||
// Fragment Shader
|
||||
"#version 330 core\n"
|
||||
"in vec2 o_TextCoord;\n"
|
||||
"in vec4 o_VertColor;\n"
|
||||
"out vec4 o_Color;\n"
|
||||
"uniform vec4 u_Color;\n"
|
||||
"uniform bool u_HasTexture;\n"
|
||||
"uniform sampler2D u_Text;\n"
|
||||
|
||||
"void main() {\n"
|
||||
"o_Color = u_Color;\n"
|
||||
"o_Color.a *= texture(u_Text, o_TextCoord).r;\n"
|
||||
"o_Color = o_VertColor;\n"
|
||||
"}\n"
|
||||
);
|
||||
#else
|
||||
#error Shader Type unknown
|
||||
#endif
|
||||
|
||||
this->paramProjection = this->getParameterByName("u_Proj");
|
||||
this->paramView = this->getParameterByName("u_View");
|
||||
this->paramModel = this->getParameterByName("u_Model");
|
||||
this->paramColor = this->getParameterByName("u_Color");
|
||||
this->paramTexture = this->getParameterByName("u_Text");
|
||||
this->bufferUiCanvas = this->getBufferLocationByName("ub_UICanvas");
|
||||
this->bufferFont = this->getBufferLocationByName("ub_Font");
|
||||
}
|
@ -2,17 +2,32 @@
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/shader/Shader.hpp"
|
||||
#include "UIShader.hpp"
|
||||
#include "util/macro.hpp"
|
||||
|
||||
#define FONT_SHADER_PARTS_MAX 32
|
||||
|
||||
namespace Dawn {
|
||||
struct FontShaderPart {
|
||||
struct Color color;
|
||||
};
|
||||
|
||||
struct FontShaderBufferData {
|
||||
struct FontShaderPart fontParts[FONT_SHADER_PARTS_MAX];
|
||||
int32_t fontPartsCount;
|
||||
};
|
||||
|
||||
class FontShaderBuffer : public ShaderParameterBuffer<struct FontShaderBufferData> {
|
||||
|
||||
};
|
||||
|
||||
class FontShader : public Shader {
|
||||
public:
|
||||
shaderparameter_t paramProjection;
|
||||
shaderparameter_t paramView;
|
||||
shaderparameter_t paramModel;
|
||||
shaderparameter_t paramColor;
|
||||
shaderparameter_t paramTexture;
|
||||
shaderbufferlocation_t bufferUiCanvas;
|
||||
shaderbufferlocation_t bufferFont;
|
||||
|
||||
void compile() override;
|
||||
};
|
||||
|
@ -21,8 +21,6 @@ void SimpleTexturedShader::compile() {
|
||||
|
||||
RenderPipelineShaderBuffer::getShaderUniform() + ""
|
||||
|
||||
// "uniform mat4 u_Proj;\n"
|
||||
// "uniform mat4 u_View;\n"
|
||||
"uniform mat4 u_Model;\n"
|
||||
|
||||
"out vec2 o_TextCoord;\n"
|
||||
|
Reference in New Issue
Block a user