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.
More...
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:
...
: ...,
{
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;
}
#define ATTR_DLL_LOCAL
Definition addon_base.h:86
Definition addons/kodi-dev-kit/include/kodi/gui/gl/Shader.h:277
#define ADDONCREATOR(AddonClass)
Definition kodi-dev-kit/include/kodi/AddonBase.h:2047
◆ CompileAndLink()
bool kodi::gui::gl::CShaderProgram::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.
◆ CShaderProgram() [1/2]
kodi::gui::gl::CShaderProgram::CShaderProgram |
( |
| ) |
|
|
default |
◆ CShaderProgram() [2/2]
kodi::gui::gl::CShaderProgram::CShaderProgram |
( |
const std::string & | vert, |
|
|
const std::string & | frag ) |
|
inline |
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 |
◆ DisableShader()
void kodi::gui::gl::CShaderProgram::DisableShader |
( |
| ) |
|
|
inline |
To deactivate the shader use on the GPU.
◆ EnableShader()
bool kodi::gui::gl::CShaderProgram::EnableShader |
( |
| ) |
|
|
inline |
To activate the shader and use it on the GPU.
- Returns
- true if enable was successfully done
- Note
- During this call, the OnEnabled stored in the child is also called
◆ LoadShaderFiles()
bool kodi::gui::gl::CShaderProgram::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.
◆ PixelShader()
To get the fragment shader class used by Kodi at the addon.
- Returns
- pointer to fragment shader class
◆ ProgramHandle()
Used to get the definition created in the OpenGL itself.
- Returns
- GLuint of GL shader program handler
◆ ShaderOK()
Used to check if shader has been loaded before.
- Returns
- true if enable was successfully 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
◆ ~CShaderProgram()
virtual kodi::gui::gl::CShaderProgram::~CShaderProgram |
( |
| ) |
|
|
inlinevirtual |