From f593ea29e7a893b0b59484dd02192d10d0174c91 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Fri, 6 Nov 2009 10:38:07 +0000 Subject: [PATCH] Fixed alpha-blended drawables getting incorrect alpha values when rendered through a RenderImage Replaced internal calls to glewIsSupported with the corresponding constants (faster checks) git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1264 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Graphics/Batch.cpp | 24 +++++++++++++++---- src/SFML/Graphics/GeometryRendererVA.cpp | 8 +++---- src/SFML/Graphics/GeometryRendererVA.hpp | 1 - src/SFML/Graphics/GeometryRendererVBO.cpp | 2 +- src/SFML/Graphics/Image.cpp | 2 +- src/SFML/Graphics/RenderImageImplFBO.cpp | 2 +- src/SFML/Graphics/Shader.cpp | 8 +++---- .../Graphics/Win32/RenderImageImplPBuffer.cpp | 3 +-- 8 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/SFML/Graphics/Batch.cpp b/src/SFML/Graphics/Batch.cpp index 403e02a01..9b2475592 100644 --- a/src/SFML/Graphics/Batch.cpp +++ b/src/SFML/Graphics/Batch.cpp @@ -90,14 +90,28 @@ void Batch::Render(GeometryRenderer& renderer) const { GLCheck(glEnable(GL_BLEND)); - // @todo the resulting alpha may not be correct, which matters when target is a RenderImage. - // find a fix for this (glBlendFuncSeparate -- but not supported by every graphics card) switch (myBlendMode) { + // Alpha blending + // glBlendFuncSeparateEXT is used when available to avoid an incorrect alpha value when the target + // is a RenderImage -- in this case the alpha value must be written directly to the target buffer default : - case Blend::Alpha : GLCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); break; - case Blend::Add : GLCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE)); break; - case Blend::Multiply : GLCheck(glBlendFunc(GL_DST_COLOR, GL_ZERO)); break; + case Blend::Alpha : + if (GLEW_EXT_blend_func_separate) + GLCheck(glBlendFuncSeparateEXT(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO)); + else + GLCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); + break; + + // Additive blending + case Blend::Add : + GLCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE)); + break; + + // Multiplicative blending + case Blend::Multiply : + GLCheck(glBlendFunc(GL_DST_COLOR, GL_ZERO)); + break; } } diff --git a/src/SFML/Graphics/GeometryRendererVA.cpp b/src/SFML/Graphics/GeometryRendererVA.cpp index 4325a23a2..b4b7e0a91 100644 --- a/src/SFML/Graphics/GeometryRendererVA.cpp +++ b/src/SFML/Graphics/GeometryRendererVA.cpp @@ -38,7 +38,7 @@ bool GeometryRendererVA::IsSupported() { priv::EnsureGlewInit(); - return glewIsSupported("GL_EXT_vertex_array") != 0; + return GLEW_EXT_vertex_array != 0; } @@ -47,8 +47,6 @@ GeometryRendererVA::GeometryRendererVA() : myIndices(NULL) { priv::EnsureGlewInit(); - - myCanLock = glewIsSupported("GL_EXT_compiled_vertex_array") != 0; } @@ -71,7 +69,7 @@ void GeometryRendererVA::Begin(const float* vertices, std::size_t verticesCount, GLCheck(glTexCoordPointer(2, GL_FLOAT, stride, vertices + 6)); // Lock (compile) the vertex array if supported - if (myCanLock) + if (GLEW_EXT_compiled_vertex_array) GLCheck(glLockArraysEXT(0, verticesCount / 8)); // Store indices for later use @@ -83,7 +81,7 @@ void GeometryRendererVA::Begin(const float* vertices, std::size_t verticesCount, void GeometryRendererVA::End() { // Unlock the vertex array if it was locked - if (myCanLock) + if (GLEW_EXT_compiled_vertex_array) GLCheck(glUnlockArraysEXT()); } diff --git a/src/SFML/Graphics/GeometryRendererVA.hpp b/src/SFML/Graphics/GeometryRendererVA.hpp index f4f050024..cd05f5bb1 100644 --- a/src/SFML/Graphics/GeometryRendererVA.hpp +++ b/src/SFML/Graphics/GeometryRendererVA.hpp @@ -96,7 +96,6 @@ public : //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - bool myCanLock; ///< Is geometry locking supported? const unsigned int* myIndices; ///< Pointer to the indices to render }; diff --git a/src/SFML/Graphics/GeometryRendererVBO.cpp b/src/SFML/Graphics/GeometryRendererVBO.cpp index 412932bd4..32291380f 100644 --- a/src/SFML/Graphics/GeometryRendererVBO.cpp +++ b/src/SFML/Graphics/GeometryRendererVBO.cpp @@ -37,7 +37,7 @@ bool GeometryRendererVBO::IsSupported() { priv::EnsureGlewInit(); - return glewIsSupported("GL_ARB_vertex_buffer_object") != 0; + return GLEW_ARB_vertex_buffer_object != 0; } diff --git a/src/SFML/Graphics/Image.cpp b/src/SFML/Graphics/Image.cpp index 5d584dd71..83e816790 100644 --- a/src/SFML/Graphics/Image.cpp +++ b/src/SFML/Graphics/Image.cpp @@ -584,7 +584,7 @@ unsigned int Image::GetValidTextureSize(unsigned int size) // Make sure that GLEW is initialized priv::EnsureGlewInit(); - if (glewIsSupported("GL_ARB_texture_non_power_of_two") != 0) + if (GLEW_ARB_texture_non_power_of_two) { // If hardware supports NPOT textures, then just return the unmodified size return size; diff --git a/src/SFML/Graphics/RenderImageImplFBO.cpp b/src/SFML/Graphics/RenderImageImplFBO.cpp index 753587380..85bae7e5e 100644 --- a/src/SFML/Graphics/RenderImageImplFBO.cpp +++ b/src/SFML/Graphics/RenderImageImplFBO.cpp @@ -75,7 +75,7 @@ bool RenderImageImplFBO::IsSupported() // Make sure that GLEW is initialized priv::EnsureGlewInit(); - return glewIsSupported("GL_EXT_framebuffer_object") != 0; + return GLEW_EXT_framebuffer_object != 0; } diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index 799620b6b..b7d7b0d77 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -309,10 +309,10 @@ bool Shader::IsAvailable() // Make sure that GLEW is initialized priv::EnsureGlewInit(); - return glewIsSupported("GL_ARB_shading_language_100") != 0 && - glewIsSupported("GL_ARB_shader_objects") != 0 && - glewIsSupported("GL_ARB_vertex_shader") != 0 && - glewIsSupported("GL_ARB_fragment_shader") != 0; + return GLEW_ARB_shading_language_100 && + GLEW_ARB_shader_objects && + GLEW_ARB_vertex_shader && + GLEW_ARB_fragment_shader; } diff --git a/src/SFML/Graphics/Win32/RenderImageImplPBuffer.cpp b/src/SFML/Graphics/Win32/RenderImageImplPBuffer.cpp index 52a5b1e6c..44e90f608 100644 --- a/src/SFML/Graphics/Win32/RenderImageImplPBuffer.cpp +++ b/src/SFML/Graphics/Win32/RenderImageImplPBuffer.cpp @@ -79,8 +79,7 @@ bool RenderImageImplPBuffer::IsSupported() // Make sure that GLEW is initialized priv::EnsureGlewInit(); - return wglewIsSupported("WGL_ARB_pbuffer") && - wglewIsSupported("WGL_ARB_pixel_format"); + return WGLEW_ARB_pbuffer && WGLEW_ARB_pixel_format; }