Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches

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...

Topics

 Child Functions
 

Class: kodi::gui::gl::CShaderProgram child functions


 

Functions

 kodi::gui::gl::CShaderProgram::CShaderProgram ()=default
 Construct a new shader.
 
 kodi::gui::gl::CShaderProgram::CShaderProgram (const std::string &vert, const std::string &frag)
 Construct a new shader and load defined shader files.
 
virtual kodi::gui::gl::CShaderProgram::~CShaderProgram ()
 Destructor.
 
bool kodi::gui::gl::CShaderProgram::LoadShaderFiles (const std::string &vert, const std::string &frag)
 To load manually the needed shader files.
 
bool kodi::gui::gl::CShaderProgram::CompileAndLink (const std::string &vertexExtraBegin="", const std::string &vertexExtraEnd="", const std::string &fragmentExtraBegin="", const std::string &fragmentExtraEnd="")
 To compile and link the shader to the GL interface.
 
bool kodi::gui::gl::CShaderProgram::EnableShader ()
 To activate the shader and use it on the GPU.
 
void kodi::gui::gl::CShaderProgram::DisableShader ()
 To deactivate the shader use on the GPU.
 
ATTR_FORCEINLINE bool kodi::gui::gl::CShaderProgram::ShaderOK () const
 Used to check if shader has been loaded before.
 
ATTR_FORCEINLINE CVertexShaderkodi::gui::gl::CShaderProgram::VertexShader ()
 To get the vertex shader class used by Kodi at the addon.
 
ATTR_FORCEINLINE CPixelShaderkodi::gui::gl::CShaderProgram::PixelShader ()
 To get the fragment shader class used by Kodi at the addon.
 
ATTR_FORCEINLINE GLuint kodi::gui::gl::CShaderProgram::ProgramHandle ()
 Used to get the definition created in the OpenGL itself.
 

Detailed Description

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:

...
class ATTR_DLL_LOCAL CExample
: ...,
{
public:
CExample() = default;
bool Start();
void Render();
// override functions for kodi::gui::gl::CShaderProgram
void OnCompiledAndLinked() override;
bool OnEnabled() override;
private:
...
GLint m_aPosition = -1;
GLint m_aColor = -1;
};
bool CExample::Start()
{
// Define shaders and load
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);
#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

Function Documentation

◆ 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

Construct a new shader.

Load must be done later with LoadShaderFiles.

◆ 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]vertPath to used GL vertext shader
[in]fragPath 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]vertPath to used GL vertext shader
[in]fragPath 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()

ATTR_FORCEINLINE CPixelShader & kodi::gui::gl::CShaderProgram::PixelShader ( )
inline

To get the fragment shader class used by Kodi at the addon.

Returns
pointer to fragment shader class

◆ ProgramHandle()

ATTR_FORCEINLINE GLuint kodi::gui::gl::CShaderProgram::ProgramHandle ( )
inline

Used to get the definition created in the OpenGL itself.

Returns
GLuint of GL shader program handler

◆ ShaderOK()

ATTR_FORCEINLINE bool kodi::gui::gl::CShaderProgram::ShaderOK ( ) const
inline

Used to check if shader has been loaded before.

Returns
true if enable was successfully done
Note
The CompileAndLink call sets these values

◆ VertexShader()

ATTR_FORCEINLINE CVertexShader & kodi::gui::gl::CShaderProgram::VertexShader ( )
inline

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

Destructor.