Skip to content

Commit

Permalink
[GLES] speed up blending
Browse files Browse the repository at this point in the history
(texture * color) costs us an extra operation on Mali when sent as varying.
Instead, since textures use the same color for the entire render, send it as
a uniform instead.

This does not apply to fonts, since the font and its shadow are rendered
together, and may not share a color (tested and looks bad).

This increases fps anywhere heavy blending is done.
  • Loading branch information
theuni authored and t-nelson committed Sep 13, 2013
1 parent 597fb4f commit 3c2ebba
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 4 deletions.
4 changes: 2 additions & 2 deletions system/shaders/guishader_frag_multi_blendcolor.glsl
Expand Up @@ -23,10 +23,10 @@ uniform sampler2D m_samp0;
uniform sampler2D m_samp1;
varying vec4 m_cord0;
varying vec4 m_cord1;
varying lowp vec4 m_colour;
uniform lowp vec4 m_unicol;

// SM_MULTI shader
void main ()
{
gl_FragColor.rgba = (texture2D(m_samp0, m_cord0.xy) * texture2D(m_samp1, m_cord1.xy)).rgba * m_colour;
gl_FragColor.rgba = (texture2D(m_samp0, m_cord0.xy) * texture2D(m_samp1, m_cord1.xy)).rgba * m_unicol;
}
4 changes: 2 additions & 2 deletions system/shaders/guishader_frag_texture.glsl
Expand Up @@ -20,11 +20,11 @@

precision mediump float;
uniform sampler2D m_samp0;
uniform lowp vec4 m_unicol;
varying vec4 m_cord0;
varying lowp vec4 m_colour;

// SM_TEXTURE shader
void main ()
{
gl_FragColor.rgba = vec4(texture2D(m_samp0, m_cord0.xy).rgba * m_colour);
gl_FragColor.rgba = vec4(texture2D(m_samp0, m_cord0.xy).rgba * m_unicol);
}
2 changes: 2 additions & 0 deletions xbmc/cores/VideoRenderers/OverlayRendererGL.cpp
Expand Up @@ -552,6 +552,7 @@ void COverlayTextureGL::Render(SRenderState& state)
GLint posLoc = g_Windowing.GUIShaderGetPos();
GLint colLoc = g_Windowing.GUIShaderGetCol();
GLint tex0Loc = g_Windowing.GUIShaderGetCoord0();
GLint uniColLoc= g_Windowing.GUIShaderGetUniCol();

glVertexAttribPointer(posLoc, 2, GL_FLOAT, 0, 0, ver);
glVertexAttribPointer(colLoc, 4, GL_FLOAT, 0, 0, col);
Expand All @@ -567,6 +568,7 @@ void COverlayTextureGL::Render(SRenderState& state)
col[i][0] = col[i][1] = col[i][2] = col[i][3] = 1.0f;
}

glUniform4f(uniColLoc,(col[0][0]), (col[0][1]), (col[0][2]), (col[0][3]));
// Setup vertex position values
ver[0][0] = ver[3][0] = rd.left;
ver[0][1] = ver[1][1] = rd.top;
Expand Down
4 changes: 4 additions & 0 deletions xbmc/guilib/GUIShader.cpp
Expand Up @@ -38,6 +38,7 @@ CGUIShader::CGUIShader( const char *shader ) : CGLSLShaderProgram("guishader_ver
m_hCol = 0;
m_hCord0 = 0;
m_hCord1 = 0;
m_hUniCol = 0;

m_proj = NULL;
m_model = NULL;
Expand All @@ -50,6 +51,8 @@ void CGUIShader::OnCompiledAndLinked()
// Variables passed directly to the Fragment shader
m_hTex0 = glGetUniformLocation(ProgramHandle(), "m_samp0");
m_hTex1 = glGetUniformLocation(ProgramHandle(), "m_samp1");
m_hUniCol = glGetUniformLocation(ProgramHandle(), "m_unicol");

// Variables passed directly to the Vertex shader
m_hProj = glGetUniformLocation(ProgramHandle(), "m_proj");
m_hModel = glGetUniformLocation(ProgramHandle(), "m_model");
Expand All @@ -62,6 +65,7 @@ void CGUIShader::OnCompiledAndLinked()
glUseProgram( ProgramHandle() );
glUniform1i(m_hTex0, 0);
glUniform1i(m_hTex1, 1);
glUniform4f(m_hUniCol, 1.0, 1.0, 1.0, 1.0);
glUseProgram( 0 );
}

Expand Down
2 changes: 2 additions & 0 deletions xbmc/guilib/GUIShader.h
Expand Up @@ -39,10 +39,12 @@ class CGUIShader : public CGLSLShaderProgram
GLint GetColLoc() { return m_hCol; }
GLint GetCord0Loc() { return m_hCord0; }
GLint GetCord1Loc() { return m_hCord1; }
GLint GetUniColLoc() { return m_hUniCol; }

protected:
GLint m_hTex0;
GLint m_hTex1;
GLint m_hUniCol;
GLint m_hProj;
GLint m_hModel;
GLint m_hPos;
Expand Down
5 changes: 5 additions & 0 deletions xbmc/guilib/GUITextureGLES.cpp
Expand Up @@ -91,7 +91,9 @@ void CGUITextureGLES::Begin(color_t color)
GLint posLoc = g_Windowing.GUIShaderGetPos();
GLint colLoc = g_Windowing.GUIShaderGetCol();
GLint tex0Loc = g_Windowing.GUIShaderGetCoord0();
GLint uniColLoc= g_Windowing.GUIShaderGetUniCol();

glUniform4f(uniColLoc,(m_col[0][0] / 255.0), (m_col[0][1] / 255.0), (m_col[0][2] / 255.0), (m_col[0][3] / 255.0));
glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, 0, m_vert);
if(colLoc >= 0)
glVertexAttribPointer(colLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, m_col);
Expand Down Expand Up @@ -234,6 +236,7 @@ void CGUITextureGLES::DrawQuad(const CRect &rect, color_t color, CBaseTexture *t
GLint posLoc = g_Windowing.GUIShaderGetPos();
GLint colLoc = g_Windowing.GUIShaderGetCol();
GLint tex0Loc = g_Windowing.GUIShaderGetCoord0();
GLint uniColLoc= g_Windowing.GUIShaderGetUniCol();

glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, 0, ver);
if(colLoc >= 0)
Expand All @@ -256,6 +259,8 @@ void CGUITextureGLES::DrawQuad(const CRect &rect, color_t color, CBaseTexture *t
col[i][3] = (GLubyte)GET_A(color);
}

glUniform4f(uniColLoc,col[0][0] / 255, col[0][1] / 255, col[0][2] / 255, col[0][3] / 255);

// Setup vertex position values
#define ROUND_TO_PIXEL(x) (float)(MathUtils::round_int(x))
ver[0][0] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalXCoord(rect.x1, rect.y1));
Expand Down
2 changes: 2 additions & 0 deletions xbmc/pictures/SlideShowPicture.cpp
Expand Up @@ -887,6 +887,7 @@ void CSlideShowPic::Render(float *x, float *y, CBaseTexture* pTexture, color_t c
GLint posLoc = g_Windowing.GUIShaderGetPos();
GLint colLoc = g_Windowing.GUIShaderGetCol();
GLint tex0Loc = g_Windowing.GUIShaderGetCoord0();
GLint uniColLoc= g_Windowing.GUIShaderGetUniCol();

glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, 0, ver);
glVertexAttribPointer(colLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, col);
Expand Down Expand Up @@ -915,6 +916,7 @@ void CSlideShowPic::Render(float *x, float *y, CBaseTexture* pTexture, color_t c
tex[1][0] = tex[2][0] = u2;
tex[2][1] = tex[3][1] = v2;

glUniform4f(uniColLoc,(col[0][0] / 255.0), (col[0][1] / 255.0), (col[0][2] / 255.0), (col[0][3] / 255.0));
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, idx);

glDisableVertexAttribArray(posLoc);
Expand Down
8 changes: 8 additions & 0 deletions xbmc/rendering/gles/RenderSystemGLES.cpp
Expand Up @@ -627,4 +627,12 @@ GLint CRenderSystemGLES::GUIShaderGetCoord1()
return -1;
}

GLint CRenderSystemGLES::GUIShaderGetUniCol()
{
if (m_pGUIshader[m_method])
return m_pGUIshader[m_method]->GetUniColLoc();

return -1;
}

#endif
1 change: 1 addition & 0 deletions xbmc/rendering/gles/RenderSystemGLES.h
Expand Up @@ -85,6 +85,7 @@ class CRenderSystemGLES : public CRenderSystemBase
GLint GUIShaderGetCol();
GLint GUIShaderGetCoord0();
GLint GUIShaderGetCoord1();
GLint GUIShaderGetUniCol();

protected:
virtual void SetVSyncImpl(bool enable) = 0;
Expand Down

0 comments on commit 3c2ebba

Please sign in to comment.