First phase moving from STBTT to FreeType
This commit is contained in:
@ -24,10 +24,14 @@ void RenderManager::init() {
|
||||
this->lockUIShaderProgram = this->shaderManager.lockShader<SimpleTexturedShader>();
|
||||
this->uiShader = this->shaderManager.getShader<SimpleTexturedShader>(this->lockUIShaderProgram);
|
||||
|
||||
this->lockFontShader = this->shaderManager.lockShader<FontShader>();
|
||||
this->fontShader = this->shaderManager.getShader<FontShader>(this->lockFontShader);
|
||||
|
||||
this->renderPipeline.init();
|
||||
|
||||
// Prepare the initial values
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDepthMask(GL_TRUE);
|
||||
glDepthFunc(GL_LESS);
|
||||
@ -47,6 +51,10 @@ ShaderManager * RenderManager::getShaderManager() {
|
||||
return &this->shaderManager;
|
||||
}
|
||||
|
||||
FontManager * RenderManager::getFontManager() {
|
||||
return &this->fontManager;
|
||||
}
|
||||
|
||||
void RenderManager::setRenderFlags(renderflag_t flags) {
|
||||
this->renderFlags = flags;
|
||||
|
||||
@ -70,4 +78,5 @@ void RenderManager::update() {
|
||||
RenderManager::~RenderManager() {
|
||||
this->shaderManager.releaseShader<SimpleTexturedShader>(this->lockSimpleTextured);
|
||||
this->shaderManager.releaseShader<SimpleTexturedShader>(this->lockUIShaderProgram);
|
||||
this->shaderManager.releaseShader<FontShader>(this->lockFontShader);
|
||||
}
|
@ -8,8 +8,10 @@
|
||||
#include "display/BackBufferRenderTarget.hpp"
|
||||
#include "display/shader/ShaderManager.hpp"
|
||||
#include "display/shader/SimpleTexturedShader.hpp"
|
||||
#include "display/shader/FontShader.hpp"
|
||||
#include "display/shader/UIShaderProgram.hpp"
|
||||
#include "display/RenderPipeline.hpp"
|
||||
#include "display/font/FontManager.hpp"
|
||||
#include "display/font/ExampleFont.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
@ -17,13 +19,16 @@ namespace Dawn {
|
||||
private:
|
||||
RenderPipeline renderPipeline;
|
||||
ShaderManager shaderManager;
|
||||
FontManager fontManager;
|
||||
shaderlock_t lockSimpleTextured = -1;
|
||||
shaderlock_t lockUIShaderProgram = -1;
|
||||
shaderlock_t lockFontShader = -1;
|
||||
|
||||
public:
|
||||
BackBufferRenderTarget backBuffer;
|
||||
SimpleTexturedShader *simpleTexturedShader = nullptr;
|
||||
SimpleTexturedShader *uiShader = nullptr;
|
||||
FontShader *fontShader = nullptr;
|
||||
ExampleFont defaultFont;
|
||||
|
||||
/**
|
||||
@ -34,6 +39,7 @@ namespace Dawn {
|
||||
RenderTarget * getBackBuffer() override;
|
||||
RenderPipeline * getRenderPipeline() override;
|
||||
ShaderManager * getShaderManager() override;
|
||||
FontManager * getFontManager() override;
|
||||
void setRenderFlags(renderflag_t renderFlags) override;
|
||||
void init() override;
|
||||
void update() override;
|
||||
|
@ -30,7 +30,10 @@ int32_t Texture::getHeight() {
|
||||
}
|
||||
|
||||
void Texture::setSize(int32_t width, int32_t height, enum TextureFormat format) {
|
||||
if(this->id != -1) glDeleteTextures(1, &this->id);
|
||||
if(this->id != -1) {
|
||||
glDeleteTextures(1, &this->id);
|
||||
this->id = -1;
|
||||
}
|
||||
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
@ -101,11 +104,13 @@ void Texture::updateTextureProperties() {
|
||||
|
||||
switch(((enum TextureFilterMode)this->filterModeMin)) {
|
||||
case TEXTURE_FILTER_MODE_NEAREST:
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
break;
|
||||
|
||||
case TEXTURE_FILTER_MODE_LINEAR:
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -114,11 +119,13 @@ void Texture::updateTextureProperties() {
|
||||
|
||||
switch(((enum TextureFilterMode)this->filterModeMag)) {
|
||||
case TEXTURE_FILTER_MODE_NEAREST:
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
break;
|
||||
|
||||
case TEXTURE_FILTER_MODE_LINEAR:
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -157,7 +164,7 @@ void Texture::bufferRaw(void *data) {
|
||||
this->width, this->height,
|
||||
0, format, GL_UNSIGNED_BYTE, data
|
||||
);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
// glGenerateMipmap(GL_TEXTURE_2D);
|
||||
this->texturePropertiesNeedUpdating = true;
|
||||
}
|
||||
|
||||
@ -165,6 +172,10 @@ void Texture::buffer(struct Color pixels[]) {
|
||||
this->bufferRaw((void*)pixels);
|
||||
}
|
||||
|
||||
void Texture::buffer(uint8_t pixels[]) {
|
||||
this->bufferRaw((void*)pixels);
|
||||
}
|
||||
|
||||
Texture::~Texture() {
|
||||
if(this->id != -1) glDeleteTextures(1, &this->id);
|
||||
}
|
@ -32,6 +32,7 @@ namespace Dawn {
|
||||
void fill(struct Color) override;
|
||||
bool_t isReady() override;
|
||||
void buffer(struct Color pixels[]) override;
|
||||
void buffer(uint8_t pixels[]) override;
|
||||
|
||||
/**
|
||||
* Binds the texture to the given slot (for use by the shaders).
|
||||
|
@ -7,6 +7,7 @@
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
ShaderProgram.cpp
|
||||
FontShader.cpp
|
||||
SimpleTexturedShader.cpp
|
||||
SimpleBillboardedShader.cpp
|
||||
)
|
69
src/dawnopengl/display/shader/FontShader.cpp
Normal file
69
src/dawnopengl/display/shader/FontShader.cpp
Normal 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;
|
||||
}
|
39
src/dawnopengl/display/shader/FontShader.hpp
Normal file
39
src/dawnopengl/display/shader/FontShader.hpp
Normal 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;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user