First phase moving from STBTT to FreeType

This commit is contained in:
2023-05-22 11:25:59 -07:00
parent 4a0c817a1c
commit 8328dba55c
22 changed files with 332 additions and 21 deletions

View File

@ -7,6 +7,7 @@
target_sources(${DAWN_TARGET_NAME}
PRIVATE
ShaderProgram.cpp
FontShader.cpp
SimpleTexturedShader.cpp
SimpleBillboardedShader.cpp
)

View File

@ -0,0 +1,69 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "FontShader.hpp"
#include "scene/components/display/mesh/MeshRenderer.hpp"
#include "scene/components/display/Camera.hpp"
using namespace Dawn;
void FontShaderProgram::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"
"uniform mat4 u_Proj;\n"
"uniform mat4 u_View;\n"
"uniform mat4 u_Model;\n"
"out vec2 o_TextCoord;\n"
"void main() {\n"
"gl_Position = u_Proj * u_View * u_Model * vec4(aPos, 1.0);\n"
"o_TextCoord = vec2(aTexCoord.x, aTexCoord.y);\n"
"}",
// Fragment Shader
"#version 330 core\n"
"in vec2 o_TextCoord;\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"
"}\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");
}
void FontShader::compile() {
this->program.compile();
}
std::vector<struct ShaderPassItem> FontShader::getPassItems(
Mesh *mesh,
Material *material,
Camera *camera
) {
std::vector<struct ShaderPassItem> passes;
return passes;
}

View File

@ -0,0 +1,39 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "display/shader/ShaderManager.hpp"
namespace Dawn {
class FontShaderProgram : public ShaderProgram {
public:
shaderparameter_t paramProjection;
shaderparameter_t paramView;
shaderparameter_t paramModel;
shaderparameter_t paramColor;
shaderparameter_t paramTexture;
void compile() override;
};
class FontShader : public Shader {
public:
FontShaderProgram program;
void compile() override;
std::vector<struct ShaderPassItem> getPassItems(
Mesh *mesh,
Material *material,
Camera *camera
) override;
};
}