From 9e0d994c8b3db7c122b52b911290102c7e63c422 Mon Sep 17 00:00:00 2001 From: sarbes Date: Mon, 13 Jun 2022 18:12:06 +0200 Subject: [PATCH 1/2] Clamp textures with alpha to transparent color --- xbmc/guilib/TextureGL.cpp | 58 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/xbmc/guilib/TextureGL.cpp b/xbmc/guilib/TextureGL.cpp index ef01bdf540196..3ced9c5ace507 100644 --- a/xbmc/guilib/TextureGL.cpp +++ b/xbmc/guilib/TextureGL.cpp @@ -88,8 +88,62 @@ void CGLTexture::LoadToGPU() } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + +#ifdef HAS_GL + if (HasAlpha()) + { + float color[] = {0.0f, 0.0f, 0.0f, 0.0f}; + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + } + else + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + } +#else + + if (HasAlpha()) + { + if (CServiceBroker::GetRenderSystem()->IsExtSupported("GL_OES_texture_border_clamp")) + { + float color[] = {0.0f, 0.0f, 0.0f, 0.0f}; + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR_OES, color); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER_OES); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER_OES); + } + else if (CServiceBroker::GetRenderSystem()->IsExtSupported("GL_EXT_texture_border_clamp")) + { + float color[] = {0.0f, 0.0f, 0.0f, 0.0f}; + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR_EXT, color); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER_EXT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER_EXT); + } + else if (CServiceBroker::GetRenderSystem()->IsExtSupported("GL_NV_texture_border_clamp")) + { + float color[] = {0.0f, 0.0f, 0.0f, 0.0f}; + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR_NV, color); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER_NV); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER_NV); + } + else + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + } + } + else + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + } +#endif + unsigned int maxSize = CServiceBroker::GetRenderSystem()->GetMaxTextureSize(); if (m_textureHeight > maxSize) From 7ce583f990ccd34b84dc4beac3a98e9ca3a4daf9 Mon Sep 17 00:00:00 2001 From: sarbes Date: Mon, 13 Jun 2022 21:23:40 +0200 Subject: [PATCH 2/2] Define texture border parameters --- xbmc/guilib/TextureGL.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/xbmc/guilib/TextureGL.cpp b/xbmc/guilib/TextureGL.cpp index 3ced9c5ace507..69e24d184669a 100644 --- a/xbmc/guilib/TextureGL.cpp +++ b/xbmc/guilib/TextureGL.cpp @@ -105,6 +105,25 @@ void CGLTexture::LoadToGPU() } #else +#ifndef GL_TEXTURE_BORDER_COLOR_OES +#define GL_TEXTURE_BORDER_COLOR_OES 0x1004 +#endif +#ifndef GL_CLAMP_TO_BORDER_OES +#define GL_CLAMP_TO_BORDER_OES 0x812D +#endif +#ifndef GL_TEXTURE_BORDER_COLOR_EXT +#define GL_TEXTURE_BORDER_COLOR_EXT 0x1004 +#endif +#ifndef GL_CLAMP_TO_BORDER_EXT +#define GL_CLAMP_TO_BORDER_EXT 0x812D +#endif +#ifndef GL_TEXTURE_BORDER_COLOR_NV +#define GL_TEXTURE_BORDER_COLOR_NV 0x1004 +#endif +#ifndef GL_CLAMP_TO_BORDER_NV +#define GL_CLAMP_TO_BORDER_NV 0x812D +#endif + if (HasAlpha()) { if (CServiceBroker::GetRenderSystem()->IsExtSupported("GL_OES_texture_border_clamp")) @@ -144,7 +163,6 @@ void CGLTexture::LoadToGPU() } #endif - unsigned int maxSize = CServiceBroker::GetRenderSystem()->GetMaxTextureSize(); if (m_textureHeight > maxSize) {