2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
14 #include "system_gl.h"
18 //////////////////////////////////////////////////////////////////////
19 // CShader - base class
20 //////////////////////////////////////////////////////////////////////
25 virtual ~CShader() = default;
26 virtual bool Compile() = 0;
27 virtual void Free() = 0;
28 virtual GLuint
Handle() = 0;
29 virtual void SetSource(const std::string
& src
) { m_source
= src
; }
30 virtual bool LoadSource(const std::string
& filename
, const std::string
& prefix
= "");
31 virtual bool AppendSource(const std::string
& filename
);
32 virtual bool InsertSource(const std::string
& filename
, const std::string
& loc
);
33 bool OK() const { return m_compiled
; }
35 std::string
GetName() const { return m_filenames
; }
36 std::string
GetSourceWithLineNumbers() const;
40 std::string m_lastLog
;
41 std::vector
<std::string
> m_attr
;
42 bool m_compiled
= false;
45 std::string m_filenames
;
49 //////////////////////////////////////////////////////////////////////
50 // CVertexShader - vertex shader class
51 //////////////////////////////////////////////////////////////////////
52 class CVertexShader
: public CShader
55 CVertexShader() = default;
56 ~CVertexShader() override
{ Free(); }
57 void Free() override
{}
58 GLuint
Handle() override
{ return m_vertexShader
; }
61 GLuint m_vertexShader
= 0;
64 class CGLSLVertexShader
: public CVertexShader
68 bool Compile() override
;
72 //////////////////////////////////////////////////////////////////////
73 // CPixelShader - abstract pixel shader class
74 //////////////////////////////////////////////////////////////////////
75 class CPixelShader
: public CShader
78 CPixelShader() = default;
79 ~CPixelShader() override
{ Free(); }
80 void Free() override
{}
81 GLuint
Handle() override
{ return m_pixelShader
; }
84 GLuint m_pixelShader
= 0;
87 class CGLSLPixelShader
: public CPixelShader
91 bool Compile() override
;
94 //////////////////////////////////////////////////////////////////////
95 // CShaderProgram - the complete shader consisting of both the vertex
96 // and pixel programs. (abstract)
97 //////////////////////////////////////////////////////////////////////
101 CShaderProgram() = default;
103 virtual ~CShaderProgram()
110 virtual bool Enable() = 0;
112 // disable the shader
113 virtual void Disable() = 0;
115 // returns true if shader is compiled and linked
116 bool OK() const { return m_ok
; }
118 // return the vertex shader object
119 CVertexShader
* VertexShader() { return m_pVP
; }
121 // return the pixel shader object
122 CPixelShader
* PixelShader() { return m_pFP
; }
124 // compile and link the shaders
125 virtual bool CompileAndLink() = 0;
127 // override to perform custom tasks on successful compilation
128 // and linkage. E.g. obtaining handles to shader attributes.
129 virtual void OnCompiledAndLinked() {}
131 // override to perform custom tasks before shader is enabled
132 // and after it is disabled. Return false in OnDisabled() to
134 // E.g. setting attributes, disabling texture unites, etc
135 virtual bool OnEnabled() { return true; }
136 virtual void OnDisabled() { }
138 virtual GLuint
ProgramHandle() { return m_shaderProgram
; }
141 CVertexShader
* m_pVP
= nullptr;
142 CPixelShader
* m_pFP
= nullptr;
143 GLuint m_shaderProgram
= 0;
148 class CGLSLShaderProgram
: virtual public CShaderProgram
151 CGLSLShaderProgram();
152 CGLSLShaderProgram(const std::string
& vert
153 , const std::string
& frag
);
154 ~CGLSLShaderProgram() override
;
157 bool Enable() override
;
159 // disable the shader
160 void Disable() override
;
162 // compile and link the shaders
163 bool CompileAndLink() override
;
169 bool m_validated
= false;