From b09439d97d9dc2c6fe4ca3b4a4ccd9bf8ee57c33 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Wed, 4 Jul 2018 11:19:15 -0700 Subject: [PATCH] Fixed alpha value of translucent parts in PNG files. Fixes #241. --- common/lc_context.cpp | 5 ++++- common/lc_glextensions.cpp | 21 +++++++++++++++++++++ common/lc_glextensions.h | 5 +++++ qt/lc_qaboutdialog.cpp | 5 +++-- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/common/lc_context.cpp b/common/lc_context.cpp index d0ae2c45..245f0d1c 100644 --- a/common/lc_context.cpp +++ b/common/lc_context.cpp @@ -346,7 +346,10 @@ void lcContext::SetDefaultState() glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + if (gSupportsBlendFuncSeparate) + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_ONE); + else + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(0.5f, 0.1f); diff --git a/common/lc_glextensions.cpp b/common/lc_glextensions.cpp index 182fbf4e..9da947df 100644 --- a/common/lc_glextensions.cpp +++ b/common/lc_glextensions.cpp @@ -6,6 +6,7 @@ bool gSupportsVertexBufferObject; bool gSupportsFramebufferObjectARB; bool gSupportsFramebufferObjectEXT; bool gSupportsTexImage2DMultisample; +bool gSupportsBlendFuncSeparate; bool gSupportsAnisotropic; GLfloat gMaxAnisotropy; @@ -117,6 +118,8 @@ PFNGLVERTEXATTRIBPOINTERPROC lcVertexAttribPointer; PFNGLTEXIMAGE2DMULTISAMPLEPROC lcTexImage2DMultisample; +PFNGLBLENDFUNCSEPARATEPROC lcBlendFuncSeparate; + #endif static bool lcIsGLExtensionSupported(const GLubyte* Extensions, const char* Name) @@ -270,6 +273,15 @@ void lcInitializeGLExtensions(const QGLContext* Context) gSupportsFramebufferObjectEXT = true; } + if (lcIsGLExtensionSupported(Extensions, "GL_EXT_blend_func_separate")) + { +#ifdef LC_LOAD_GLEXTENSIONS + lcBlendFuncSeparate = (PFNGLBLENDFUNCSEPARATEPROC)Context->getProcAddress("glBlendFuncSeparateEXT"); +#endif + + gSupportsBlendFuncSeparate = true; + } + const GLubyte* GLSLVersion = glGetString(GL_SHADING_LANGUAGE_VERSION); int GLSLMajor = 0, GLSLMinor = 0; @@ -344,6 +356,15 @@ void lcInitializeGLExtensions(const QGLContext* Context) gSupportsTexImage2DMultisample = true; } + + if (VersionMajor >= 4) + { +#ifdef LC_LOAD_GLEXTENSIONS + lcBlendFuncSeparate = (PFNGLBLENDFUNCSEPARATEPROC)Context->getProcAddress("glBlendFuncSeparate"); +#endif + + gSupportsBlendFuncSeparate = true; + } #endif #ifdef LC_OPENGLES diff --git a/common/lc_glextensions.h b/common/lc_glextensions.h index 00a24afc..1990877a 100644 --- a/common/lc_glextensions.h +++ b/common/lc_glextensions.h @@ -7,6 +7,7 @@ extern bool gSupportsVertexBufferObject; extern bool gSupportsFramebufferObjectARB; extern bool gSupportsFramebufferObjectEXT; extern bool gSupportsTexImage2DMultisample; +extern bool gSupportsBlendFuncSeparate; extern bool gSupportsAnisotropic; extern GLfloat gMaxAnisotropy; @@ -122,6 +123,8 @@ extern PFNGLVERTEXATTRIBPOINTERPROC lcVertexAttribPointer; extern PFNGLTEXIMAGE2DMULTISAMPLEPROC lcTexImage2DMultisample; +extern PFNGLBLENDFUNCSEPARATEPROC lcBlendFuncSeparate; + #define glBindBuffer lcBindBufferARB #define glDeleteBuffers lcDeleteBuffersARB #define glGenBuffers lcGenBuffersARB @@ -228,4 +231,6 @@ extern PFNGLTEXIMAGE2DMULTISAMPLEPROC lcTexImage2DMultisample; #define glTexImage2DMultisample lcTexImage2DMultisample +#define glBlendFuncSeparate lcBlendFuncSeparate + #endif diff --git a/qt/lc_qaboutdialog.cpp b/qt/lc_qaboutdialog.cpp index 9fd9a821..9f2fc2a3 100644 --- a/qt/lc_qaboutdialog.cpp +++ b/qt/lc_qaboutdialog.cpp @@ -23,12 +23,13 @@ lcQAboutDialog::lcQAboutDialog(QWidget *parent) : QString BuffersFormat = tr("Color Buffer: %1 bits %2 %3\nDepth Buffer: %4 bits\nStencil Buffer: %5 bits\n\n"); QString Buffers = BuffersFormat.arg(QString::number(ColorDepth), Format.rgba() ? "RGBA" : tr("indexed"), Format.doubleBuffer() ? tr("double buffered") : QString(), QString::number(Format.depthBufferSize()), QString::number(Format.stencilBufferSize())); - QString ExtensionsFormat = tr("GL_ARB_vertex_buffer_object extension: %1\nGL_ARB_framebuffer_object extension: %2\nGL_EXT_framebuffer_object extension: %3\nGL_EXT_texture_filter_anisotropic extension: %4\n"); + QString ExtensionsFormat = tr("GL_ARB_vertex_buffer_object extension: %1\nGL_ARB_framebuffer_object extension: %2\nGL_EXT_framebuffer_object extension: %3\nGL_EXT_blend_func_separate: %4\nGL_EXT_texture_filter_anisotropic extension: %5\n"); QString VertexBufferObject = gSupportsVertexBufferObject ? tr("Supported") : tr("Not supported"); QString FramebufferObjectARB = gSupportsFramebufferObjectARB ? tr("Supported") : tr("Not supported"); QString FramebufferObjectEXT = gSupportsFramebufferObjectEXT ? tr("Supported") : tr("Not supported"); + QString BlendFuncSeparateEXT = gSupportsBlendFuncSeparate ? tr("Supported") : tr("Not supported"); QString Anisotropic = gSupportsAnisotropic ? tr("Supported (max %1)").arg(gMaxAnisotropy) : tr("Not supported"); - QString Extensions = ExtensionsFormat.arg(VertexBufferObject, FramebufferObjectARB, FramebufferObjectEXT, Anisotropic); + QString Extensions = ExtensionsFormat.arg(VertexBufferObject, FramebufferObjectARB, FramebufferObjectEXT, BlendFuncSeparateEXT, Anisotropic); ui->info->setText(Version + Buffers + Extensions); }