Skip to content

Commit

Permalink
OpenGL transparency bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mpc authored and JaCzekanski committed Nov 21, 2020
1 parent e89773d commit 3928fc2
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/renderer/opengl/opengl.cpp
Expand Up @@ -293,21 +293,19 @@ void OpenGL::renderVertices(gpu::GPU* gpu) {
continue;
}

bool isTextured = bitsToDepth(buffer[i].bitcount) != ColorDepth::NONE;
if (buffer[i].flags & gpu::Vertex::SemiTransparency) {
auto semi = static_cast<Transparency>((buffer[i].flags >> 5) & 3);
// TODO: Refactor and batch
if (semi == Transparency::Bby2plusFby2) {
glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
glBlendFuncSeparate(GL_CONSTANT_ALPHA, GL_CONSTANT_ALPHA, GL_ONE, GL_ZERO);
} else if (semi == Transparency::BplusF) {
glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
glBlendFuncSeparate(GL_ONE, GL_ONE, GL_ONE, GL_ZERO);
} else if (semi == Transparency::BminusF) {
glBlendEquationSeparate(GL_FUNC_REVERSE_SUBTRACT, GL_FUNC_ADD);
glBlendFuncSeparate(GL_ONE, GL_ONE, GL_ONE, GL_ZERO);
} else if (semi == Transparency::BplusFby4) {
glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
glBlendFuncSeparate(GL_CONSTANT_COLOR, GL_ONE, GL_ONE, GL_ZERO);

glBlendEquationSeparate(semi == Transparency::BminusF ? GL_FUNC_REVERSE_SUBTRACT : GL_FUNC_ADD, GL_FUNC_ADD);
switch (semi) {
case Transparency::Bby2plusFby2:
isTextured ? glBlendFunc(GL_ONE, GL_SRC_ALPHA) : glBlendFunc(GL_CONSTANT_ALPHA, GL_CONSTANT_ALPHA); break;
case Transparency::BplusF:
case Transparency::BminusF:
isTextured ? glBlendFunc(GL_ONE, GL_SRC_ALPHA) : glBlendFunc(GL_ONE, GL_ONE); break;
case Transparency::BplusFby4:
isTextured ? glBlendFunc(GL_CONSTANT_COLOR, GL_SRC_ALPHA) : glBlendFunc(GL_CONSTANT_COLOR, GL_ONE); break;
}

glEnable(GL_BLEND);
Expand Down

0 comments on commit 3928fc2

Please sign in to comment.