Fixed blending (for now)

This commit is contained in:
2023-06-26 18:36:58 -07:00
parent 2eb6c6a91f
commit ee7963fb1a
6 changed files with 17 additions and 83 deletions

View File

@ -19,82 +19,6 @@ RenderPipeline::RenderPipeline(RenderManager *renderManager) {
}
void RenderPipeline::init() {
// FT_Face face;
// if(FT_New_Face(ft, "C:\\Windows\\Fonts\\Arial.ttf", 0, &face)) {
// std::cout << "ERROR::FREETYPE: Failed to load font" << std::endl;
// assertUnreachable();
// }
// // TESTING FONT
// // glGenTextures(1, &texture);
// // glBindTexture(GL_TEXTURE_2D, texture);
// // glTexImage2D(
// // GL_TEXTURE_2D,
// // 0,
// // GL_RED,
// // face->glyph->bitmap.width,
// // face->glyph->bitmap.rows,
// // 0,
// // GL_RED,
// // GL_UNSIGNED_BYTE,
// // face->glyph->bitmap.buffer
// // );
// // // set texture options
// // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
// // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// Mesh glyphMesh;
// FT_Set_Pixel_Sizes(face, 0, 36);
// FT_UInt glyph_index = FT_Get_Char_Index(face, 'B');
// auto error = FT_Load_Glyph(
// face, /* handle to face object */
// glyph_index, /* glyph index */
// FT_LOAD_DEFAULT ); /* load flags, see below */
// if(error) {
// std::cout << "Error loading glyph" << std::endl;
// assertUnreachable();
// }
// /* convert to an anti-aliased bitmap */
// error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL );
// if(error) {
// std::cout << "Error rendering glyph" << std::endl;
// assertUnreachable();
// }
// // Shader
// auto shdr = &this->renderManager->simpleTexturedShader->program;
// shdr->bind();
// shdr->setMatrix(shdr->paramProjection, camera->getProjection());
// shdr->setMatrix(shdr->paramView, camera->transform->getWorldTransform());
// shdr->setMatrix(shdr->paramModel, glm::mat4(1.0f));
// shdr->setColor(shdr->paramColor, COLOR_WHITE);
// // Texture
// Texture texture;
// texture.setSize(
// face->glyph->bitmap.width,
// face->glyph->bitmap.rows,
// TEXTURE_FORMAT_R
// );
// texture.wrapModeX = TEXTURE_WRAP_MODE_CLAMP_TO_EDGE;
// texture.wrapModeY = TEXTURE_WRAP_MODE_CLAMP_TO_EDGE;
// texture.buffer((uint8_t*)face->glyph->bitmap.buffer);
// shdr->setBoolean(shdr->paramHasTexture, true);
// shdr->setTexture(shdr->paramTexture, 0);
// texture.bind(0);
// this->renderManager->setRenderFlags(RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST | RENDER_MANAGER_RENDER_FLAG_BLEND);
// auto faceCloneForDebugging = face;
// QuadMesh::initQuadMesh(&glyphMesh,
// glm::vec2(face->glyph->bitmap.width, face->glyph->bitmap.rows), glm::vec2(1, 0),
// glm::vec2(0, 0), glm::vec2(0, 1),
// 0.0f
// );
// glyphMesh.draw(MESH_DRAW_MODE_TRIANGLES, 0, -1);
this->shaderBuffer.init();
}

View File

@ -32,7 +32,7 @@ void RenderManager::init() {
// Prepare the initial values
glEnable(GL_TEXTURE_2D);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LESS);
}

View File

@ -7,7 +7,7 @@
#include "display/shader/Shader.hpp"
#include "display/shader/buffers/RenderPipelineShaderBuffer.hpp"
#define UI_SHADER_PROGRAM_PRIORITY 100
#define UI_SHADER_PROGRAM_PRIORITY 1000
namespace Dawn {
struct UICanvasShaderParameterBufferData {

View File

@ -36,9 +36,17 @@ std::vector<struct ShaderPassItem> SimpleTexturedMaterial::getRenderPasses(IRend
onlyPass.matrixValues[shader->paramModel] = this->transform->getWorldTransform();
onlyPass.parameterBuffers[shader->bufferRenderPipeline] = &context.renderPipeline->shaderBuffer;
onlyPass.renderFlags = (
RENDER_MANAGER_RENDER_FLAG_BLEND
);
if(this->opaque) {
onlyPass.renderFlags = (
RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST
);
} else {
onlyPass.priority = 100;
onlyPass.renderFlags = (
RENDER_MANAGER_RENDER_FLAG_BLEND
);
}
if(this->texture != nullptr) {
onlyPass.boolValues[shader->paramHasTexture] = true;

View File

@ -17,6 +17,8 @@ namespace Dawn {
Texture *texture = nullptr;
// @optional
struct Color color = COLOR_WHITE;
// @optional
bool_t opaque = true;
/**
* SimpleTexturedShader scene item component interface.

View File

@ -88,7 +88,7 @@ int32_t TextureTool::start() {
STBIR_TYPE_UINT8,
STBI_rgb_alpha, -1, 0,
STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP,
STBIR_FILTER_BOX, STBIR_FILTER_BOX,
STBIR_FILTER_DEFAULT, STBIR_FILTER_DEFAULT,
STBIR_COLORSPACE_LINEAR, NULL,
s0, t0, s1, t1
);
@ -108,7 +108,7 @@ int32_t TextureTool::start() {
bufferCurrent, currentWidth, currentHeight, 0,
bufferTemporary, scaleWidth, scaleHeight, 0,
STBI_rgb_alpha, -1, 0,
STBIR_EDGE_CLAMP, STBIR_FILTER_TRIANGLE, STBIR_COLORSPACE_LINEAR,
STBIR_EDGE_CLAMP, STBIR_FILTER_DEFAULT, STBIR_COLORSPACE_LINEAR,
NULL
);
memcpy(bufferCurrent, bufferTemporary, sizeof(uint8_t) * len);