diff options
author | jmarshallnz <jmarshallnz@svn> | 2010-06-16 21:36:46 +0000 |
---|---|---|
committer | jmarshallnz <jmarshallnz@svn> | 2010-06-16 21:36:46 +0000 |
commit | 6be31d3e23636afcf6350dc8df4de5a18ac79af6 (patch) | |
tree | aec60a8848d19c5465fbe53fdf01a51cece872a5 | |
parent | 1afc5900309239252786dc73ca931e7796901f9e (diff) |
fixed: GLES blending performance enhancements and color fixes. Ticket #9351, thanks to Phaeodaria.
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@31128 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
-rw-r--r-- | guilib/GUIShader.h | 2 | ||||
-rw-r--r-- | guilib/GUITextureGLES.cpp | 30 | ||||
-rw-r--r-- | guilib/Texture.cpp | 8 | ||||
-rw-r--r-- | guilib/Texture.h | 3 | ||||
-rw-r--r-- | system/shaders/guishader_frag1.glsl | 3 | ||||
-rw-r--r-- | system/shaders/guishader_frag4.glsl | 13 | ||||
-rw-r--r-- | xbmc/RenderSystemGLES.h | 2 | ||||
-rw-r--r-- | xbmc/SlideShowPicture.cpp | 2 |
8 files changed, 52 insertions, 11 deletions
diff --git a/guilib/GUIShader.h b/guilib/GUIShader.h index 403f495863..debd85af42 100644 --- a/guilib/GUIShader.h +++ b/guilib/GUIShader.h @@ -34,6 +34,8 @@ enum ESHADERMETHOD SM_TEXTURE = 1, SM_MULTI = 2, SM_FONTS = 3, + SM_TEXTURE_NOBLEND = 4, + SM_ESHADERCOUNT }; class CGUIShader : public CGLSLShaderProgram diff --git a/guilib/GUITextureGLES.cpp b/guilib/GUITextureGLES.cpp index 08929423b5..6fcd3692cf 100644 --- a/guilib/GUITextureGLES.cpp +++ b/guilib/GUITextureGLES.cpp @@ -20,7 +20,9 @@ */ #include "system.h" +#if defined(HAS_GLES) #include "GUITextureGLES.h" +#endif #include "Texture.h" #include "utils/log.h" #include "WindowingFactory.h" @@ -43,16 +45,11 @@ void CGUITextureGLES::Begin(color_t color) glBindTexture(GL_TEXTURE_2D, texture->GetTextureObject()); glEnable(GL_TEXTURE_2D); - glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); // Turn Blending On - if (m_diffuse.size()) { glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, m_diffuse.m_textures[0]->GetTextureObject()); glEnable(GL_TEXTURE_2D); - - g_Windowing.EnableGUIShader(SM_MULTI); } else { @@ -64,7 +61,7 @@ void CGUITextureGLES::Begin(color_t color) GLint tex0Loc = g_Windowing.GUIShaderGetCoord0(); glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, 0, m_vert); - glVertexAttribPointer(colLoc, 4, GL_UNSIGNED_BYTE, 0, 0, m_col); + glVertexAttribPointer(colLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, m_col); glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, 0, m_tex0); glEnableVertexAttribArray(posLoc); @@ -76,8 +73,24 @@ void CGUITextureGLES::Begin(color_t color) GLint tex1Loc = g_Windowing.GUIShaderGetCoord1(); glVertexAttribPointer(tex1Loc, 2, GL_FLOAT, 0, 0, m_tex1); glEnableVertexAttribArray(tex1Loc); + glEnable( GL_BLEND ); + g_Windowing.EnableGUIShader(SM_MULTI); + } + else + { + CBaseTexture* textureObject = m_texture.m_textures[m_currentFrame]; + if (textureObject->HasAlpha() || m_col[0][3] < 255 ) + { + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); // Turn Blending On + g_Windowing.EnableGUIShader(SM_TEXTURE); + } + else + { + glDisable(GL_BLEND); + g_Windowing.EnableGUIShader(SM_TEXTURE_NOBLEND); + } } - // Setup Colors for (int i = 0; i < 4; i++) { @@ -102,6 +115,7 @@ void CGUITextureGLES::End() glDisableVertexAttribArray(g_Windowing.GUIShaderGetCol()); glDisableVertexAttribArray(g_Windowing.GUIShaderGetCoord0()); + glEnable(GL_BLEND); g_Windowing.DisableGUIShader(); } @@ -211,7 +225,7 @@ void CGUITextureGLES::DrawQuad(const CRect &rect, color_t color, CBaseTexture *t GLint tex0Loc = g_Windowing.GUIShaderGetCoord0(); glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, 0, ver); - glVertexAttribPointer(colLoc, 4, GL_UNSIGNED_BYTE, 0, 0, col); + glVertexAttribPointer(colLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, col); glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, 0, tex); glEnableVertexAttribArray(posLoc); diff --git a/guilib/Texture.cpp b/guilib/Texture.cpp index 988655edd4..a45dc5fb1f 100644 --- a/guilib/Texture.cpp +++ b/guilib/Texture.cpp @@ -31,6 +31,7 @@ /* */ /************************************************************************/ CBaseTexture::CBaseTexture(unsigned int width, unsigned int height, unsigned int format) + : m_hasAlpha( true ) { #ifndef HAS_DX m_texture = NULL; @@ -178,6 +179,8 @@ bool CBaseTexture::LoadFromFile(const CStdString& texturePath, unsigned int maxW return false; } + m_hasAlpha = NULL != image.alpha; + Allocate(image.width, image.height, XB_FMT_A8R8G8B8); if (autoRotate && image.exifInfo.Orientation) m_orientation = image.exifInfo.Orientation - 1; @@ -303,3 +306,8 @@ unsigned int CBaseTexture::GetBlockSize() const return 4; } } + +bool CBaseTexture::HasAlpha() const +{ + return m_hasAlpha; +} diff --git a/guilib/Texture.h b/guilib/Texture.h index 1e659c4931..f54df0e73c 100644 --- a/guilib/Texture.h +++ b/guilib/Texture.h @@ -61,6 +61,8 @@ public: bool LoadFromMemory(unsigned int width, unsigned int height, unsigned int pitch, unsigned int format, unsigned char* pixels); bool LoadPaletted(unsigned int width, unsigned int height, unsigned int pitch, unsigned int format, const unsigned char *pixels, const COLOR *palette); + bool HasAlpha() const; + virtual void CreateTextureObject() = 0; virtual void DestroyTextureObject() = 0; virtual void LoadToGPU() = 0; @@ -107,6 +109,7 @@ protected: bool m_loadedToGPU; unsigned int m_format; int m_orientation; + bool m_hasAlpha; }; #if defined(HAS_GL) || defined(HAS_GLES) diff --git a/system/shaders/guishader_frag1.glsl b/system/shaders/guishader_frag1.glsl index 73c6f3929f..4f5cad7b4a 100644 --- a/system/shaders/guishader_frag1.glsl +++ b/system/shaders/guishader_frag1.glsl @@ -6,7 +6,8 @@ varying vec4 m_cord1; varying vec4 m_colour; uniform int m_method; +// SM_TEXTURE void main () { - gl_FragColor.rgba = texture2D(m_samp0, m_cord0.xy).bgra; + gl_FragColor.rgba = vec4(texture2D(m_samp0, m_cord0.xy).bgra * m_colour); } diff --git a/system/shaders/guishader_frag4.glsl b/system/shaders/guishader_frag4.glsl new file mode 100644 index 0000000000..2a1d62eb2c --- /dev/null +++ b/system/shaders/guishader_frag4.glsl @@ -0,0 +1,13 @@ +precision mediump float;
+uniform sampler2D m_samp0;
+uniform sampler2D m_samp1;
+varying vec4 m_cord0;
+varying vec4 m_cord1;
+varying vec4 m_colour;
+uniform int m_method;
+
+// SM_TEXTURE_NOBLEND
+void main ()
+{
+ gl_FragColor.rgba = vec4(texture2D(m_samp0, m_cord0.xy).bgra);
+}
diff --git a/xbmc/RenderSystemGLES.h b/xbmc/RenderSystemGLES.h index c3762319b7..bcbfe6946a 100644 --- a/xbmc/RenderSystemGLES.h +++ b/xbmc/RenderSystemGLES.h @@ -83,7 +83,7 @@ protected: CStdString m_RenderExtensions; - CGUIShader *m_pGUIshader[4]; // One GUI shader for each method + CGUIShader **m_pGUIshader; // One GUI shader for each method int m_method; }; diff --git a/xbmc/SlideShowPicture.cpp b/xbmc/SlideShowPicture.cpp index 64af78fbc7..7c62ae78d3 100644 --- a/xbmc/SlideShowPicture.cpp +++ b/xbmc/SlideShowPicture.cpp @@ -757,7 +757,7 @@ void CSlideShowPic::Render(float *x, float *y, CBaseTexture* pTexture, color_t c GLint tex0Loc = g_Windowing.GUIShaderGetCoord0(); glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, 0, ver); - glVertexAttribPointer(colLoc, 4, GL_UNSIGNED_BYTE, 0, 0, col); + glVertexAttribPointer(colLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, col); glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, 0, tex); glEnableVertexAttribArray(posLoc); |