Class: kodi::gui::gl::CShaderProgram
Class to manage an OpenGL shader program
With this class the used GL shader code can be defined on the GPU and its variables can be managed between CPU and GPU.
It has the header #include <kodi/gui/gl/Shader.h> be included to enjoy it.
Example:
#include <kodi/gui/gl/Shader.h>
...
class ATTRIBUTE_HIDDEN CExample
: ...,
{
public:
CExample() = default;
bool Start();
void Render();
void OnCompiledAndLinked() override;
bool OnEnabled() override;
private:
...
GLint m_aPosition = -1;
GLint m_aColor = -1;
};
bool CExample::Start()
{
std::string fraqShader =
kodi::GetAddonPath(
"resources/shaders/" GL_TYPE_STRING
"/glsl.frag");
std::string vertShader =
kodi::GetAddonPath(
"resources/shaders/" GL_TYPE_STRING
"/glsl.vert");
if (!LoadShaderFiles(vertShader, fraqShader) || !CompileAndLink())
return false;
...
return true;
}
...
void CExample::Render()
{
...
EnableShader();
...
DO WORK
...
DisableShader();
}
void CExample::OnCompiledAndLinked()
{
...
DO YOUR WORK HERE FOR WHAT IS ONE TIME REQUIRED DURING COMPILE OF SHADER, E.G.:
m_aPosition = glGetAttribLocation(ProgramHandle(), "a_position");
m_aColor = glGetAttribLocation(ProgramHandle(), "a_color");
}
bool OnEnabled() override
{
...
DO YOUR WORK HERE FOR WHAT REQUIRED DURING ENABLE OF SHADER
...
return true;
}
ADDONCREATOR(CExample);
std::string ATTRIBUTE_HIDDEN GetAddonPath(const std::string &append="")
To get the addon system installation folder.
Definition: AddonBase.h:649
◆ CShaderProgram() [1/2]
◆ CShaderProgram() [2/2]
Construct a new shader and load defined shader files.
- Parameters
-
[in] | vert | Path to used GL vertext shader |
[in] | frag | Path to used GL fragment shader |
◆ ~CShaderProgram()
◆ LoadShaderFiles()
bool LoadShaderFiles |
( |
const std::string & |
vert, |
|
|
const std::string & |
frag |
|
) |
| |
|
inline |
To load manually the needed shader files.
- Parameters
-
[in] | vert | Path to used GL vertext shader |
[in] | frag | Path to used GL fragment shader |
- Note
- The use of the files is optional, but it must either be passed over here or via CompileAndLink, or both of the source code.
◆ CompileAndLink()
bool CompileAndLink |
( |
const std::string & |
vertexExtraBegin = "" , |
|
|
const std::string & |
vertexExtraEnd = "" , |
|
|
const std::string & |
fragmentExtraBegin = "" , |
|
|
const std::string & |
fragmentExtraEnd = "" |
|
) |
| |
|
inline |
To compile and link the shader to the GL interface.
Optionally, additional source code can be transferred here, or it can be used independently without any files
- Parameters
-
[in] | vertexExtraBegin | [opt] To additionally add vextex source code to the beginning of the loaded file source code |
[in] | vertexExtraEnd | [opt] To additionally add vextex source code to the end of the loaded file source code |
[in] | fragmentExtraBegin | [opt] To additionally add fragment source code to the beginning of the loaded file source code |
[in] | fragmentExtraEnd | [opt] To additionally add fragment source code to the end of the loaded file source code |
- Returns
- true if compile was successed
- Note
- In the case of a compile error, it will be written once into the Kodi log and in addition to the console output to quickly detect the errors when writing the damage.
◆ EnableShader()
To activate the shader and use it on the GPU.
- Returns
- true if enable was successfull done
- Note
- During this call, the OnEnabled stored in the child is also called
◆ DisableShader()
To deactivate the shader use on the GPU.
◆ ShaderOK()
ATTRIBUTE_FORCEINLINE bool ShaderOK |
( |
| ) |
const |
|
inline |
Used to check if shader has been loaded before.
- Returns
- true if enable was successfull done
- Note
- The CompileAndLink call sets these values
◆ VertexShader()
To get the vertex shader class used by Kodi at the addon.
- Returns
- pointer to vertex shader class
◆ PixelShader()
To get the fragment shader class used by Kodi at the addon.
- Returns
- pointer to fragment shader class
◆ ProgramHandle()
ATTRIBUTE_FORCEINLINE GLuint ProgramHandle |
( |
| ) |
|
|
inline |
Used to get the definition created in the OpenGL itself.
- Returns
- GLuint of GL shader program handler