droid: Add Android MediaCodec for DVDPlayer
[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   m_hCoord0Matrix = 0;
43
44   m_proj   = NULL;
45   m_model  = NULL;
46 }
47
48 void CGUIShader::OnCompiledAndLinked()
49 {
50   // This is called after CompileAndLink()
51
52   // Variables passed directly to the Fragment shader
53   m_hTex0   = glGetUniformLocation(ProgramHandle(), "m_samp0");
54   m_hTex1   = glGetUniformLocation(ProgramHandle(), "m_samp1");
55   m_hUniCol   = glGetUniformLocation(ProgramHandle(), "m_unicol");
56
57   // Variables passed directly to the Vertex shader
58   m_hProj  = glGetUniformLocation(ProgramHandle(), "m_proj");
59   m_hModel = glGetUniformLocation(ProgramHandle(), "m_model");
60   m_hCoord0Matrix = glGetUniformLocation(ProgramHandle(), "m_coord0Matrix");
61
62   // Vertex attributes
63   m_hPos    = glGetAttribLocation(ProgramHandle(),  "m_attrpos");
64   m_hCol    = glGetAttribLocation(ProgramHandle(),  "m_attrcol");
65   m_hCord0  = glGetAttribLocation(ProgramHandle(),  "m_attrcord0");
66   m_hCord1  = glGetAttribLocation(ProgramHandle(),  "m_attrcord1");
67
68   // It's okay to do this only one time. Textures units never change.
69   glUseProgram( ProgramHandle() );
70   glUniform1i(m_hTex0, 0);
71   glUniform1i(m_hTex1, 1);
72   glUniform4f(m_hUniCol, 1.0, 1.0, 1.0, 1.0);
73
74   const float identity[16] = {
75     1.0f, 0.0f, 0.0f, 0.0f,
76     0.0f, 1.0f, 0.0f, 0.0f,
77     0.0f, 0.0f, 1.0f, 0.0f,
78     0.0f, 0.0f, 0.0f, 1.0f
79   };
80   glUniformMatrix4fv(m_hCoord0Matrix,  1, GL_FALSE, identity);
81
82   glUseProgram( 0 );
83 }
84
85 bool CGUIShader::OnEnabled()
86 {
87   // This is called after glUseProgram()
88
89   glUniformMatrix4fv(m_hProj,  1, GL_FALSE, g_matrices.GetMatrix(MM_PROJECTION));
90   glUniformMatrix4fv(m_hModel, 1, GL_FALSE, g_matrices.GetMatrix(MM_MODELVIEW));
91
92   return true;
93 }
94
95 void CGUIShader::Free()
96 {
97   // Do Cleanup here
98   CGLSLShaderProgram::Free();
99 }
100
101 #endif