a3eb94ab8102578c1b007c7bd20a0ad721bdf491
[vuplus_xbmc] / xbmc / guilib / GUIShader.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21
22 #include "system.h"
23
24 #if HAS_GLES == 2
25
26 #include "GUIShader.h"
27 #include "MatrixGLES.h"
28 #include "utils/log.h"
29
30 CGUIShader::CGUIShader( const char *shader ) : CGLSLShaderProgram("guishader_vert.glsl", shader)
31 {
32   // Initialise values
33   m_hTex0   = 0;
34   m_hTex1   = 0;
35   m_hProj   = 0;
36   m_hModel  = 0;
37   m_hPos    = 0;
38   m_hCol    = 0;
39   m_hCord0  = 0;
40   m_hCord1  = 0;
41   m_hUniCol = 0;
42
43   m_proj   = NULL;
44   m_model  = NULL;
45 }
46
47 void CGUIShader::OnCompiledAndLinked()
48 {
49   // This is called after CompileAndLink()
50
51   // Variables passed directly to the Fragment shader
52   m_hTex0   = glGetUniformLocation(ProgramHandle(), "m_samp0");
53   m_hTex1   = glGetUniformLocation(ProgramHandle(), "m_samp1");
54   m_hUniCol   = glGetUniformLocation(ProgramHandle(), "m_unicol");
55
56   // Variables passed directly to the Vertex shader
57   m_hProj   = glGetUniformLocation(ProgramHandle(), "m_proj");
58   m_hModel  = glGetUniformLocation(ProgramHandle(), "m_model");
59   m_hPos    = glGetAttribLocation(ProgramHandle(),  "m_attrpos");
60   m_hCol    = glGetAttribLocation(ProgramHandle(),  "m_attrcol");
61   m_hCord0  = glGetAttribLocation(ProgramHandle(),  "m_attrcord0");
62   m_hCord1  = glGetAttribLocation(ProgramHandle(),  "m_attrcord1");
63
64   // It's okay to do this only one time. Textures units never change.
65   glUseProgram( ProgramHandle() );
66   glUniform1i(m_hTex0, 0);
67   glUniform1i(m_hTex1, 1);
68   glUniform4f(m_hUniCol, 1.0, 1.0, 1.0, 1.0);
69   glUseProgram( 0 );
70 }
71
72 bool CGUIShader::OnEnabled()
73 {
74   // This is called after glUseProgram()
75
76   glUniformMatrix4fv(m_hProj,  1, GL_FALSE, g_matrices.GetMatrix(MM_PROJECTION));
77   glUniformMatrix4fv(m_hModel, 1, GL_FALSE, g_matrices.GetMatrix(MM_MODELVIEW));
78
79   return true;
80 }
81
82 void CGUIShader::Free()
83 {
84   // Do Cleanup here
85   CGLSLShaderProgram::Free();
86 }
87
88 #endif