Skip to content

Commit 3928fc2

Browse files
mpcJaCzekanski
mpc
authored andcommitted
OpenGL transparency bug fix
1 parent e89773d commit 3928fc2

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

Diff for: src/renderer/opengl/opengl.cpp

+11-13
Original file line numberDiff line numberDiff line change
@@ -293,21 +293,19 @@ void OpenGL::renderVertices(gpu::GPU* gpu) {
293293
continue;
294294
}
295295

296+
bool isTextured = bitsToDepth(buffer[i].bitcount) != ColorDepth::NONE;
296297
if (buffer[i].flags & gpu::Vertex::SemiTransparency) {
297298
auto semi = static_cast<Transparency>((buffer[i].flags >> 5) & 3);
298-
// TODO: Refactor and batch
299-
if (semi == Transparency::Bby2plusFby2) {
300-
glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
301-
glBlendFuncSeparate(GL_CONSTANT_ALPHA, GL_CONSTANT_ALPHA, GL_ONE, GL_ZERO);
302-
} else if (semi == Transparency::BplusF) {
303-
glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
304-
glBlendFuncSeparate(GL_ONE, GL_ONE, GL_ONE, GL_ZERO);
305-
} else if (semi == Transparency::BminusF) {
306-
glBlendEquationSeparate(GL_FUNC_REVERSE_SUBTRACT, GL_FUNC_ADD);
307-
glBlendFuncSeparate(GL_ONE, GL_ONE, GL_ONE, GL_ZERO);
308-
} else if (semi == Transparency::BplusFby4) {
309-
glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
310-
glBlendFuncSeparate(GL_CONSTANT_COLOR, GL_ONE, GL_ONE, GL_ZERO);
299+
300+
glBlendEquationSeparate(semi == Transparency::BminusF ? GL_FUNC_REVERSE_SUBTRACT : GL_FUNC_ADD, GL_FUNC_ADD);
301+
switch (semi) {
302+
case Transparency::Bby2plusFby2:
303+
isTextured ? glBlendFunc(GL_ONE, GL_SRC_ALPHA) : glBlendFunc(GL_CONSTANT_ALPHA, GL_CONSTANT_ALPHA); break;
304+
case Transparency::BplusF:
305+
case Transparency::BminusF:
306+
isTextured ? glBlendFunc(GL_ONE, GL_SRC_ALPHA) : glBlendFunc(GL_ONE, GL_ONE); break;
307+
case Transparency::BplusFby4:
308+
isTextured ? glBlendFunc(GL_CONSTANT_COLOR, GL_SRC_ALPHA) : glBlendFunc(GL_CONSTANT_COLOR, GL_ONE); break;
311309
}
312310

313311
glEnable(GL_BLEND);

0 commit comments

Comments
 (0)