KWin
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
KWin::ShaderManager Class Reference

Manager for Shaders. More...

#include <glshadermanager.h>

Public Member Functions

 ShaderManager ()
 
 ~ShaderManager ()
 
GLShadershader (ShaderTraits traits)
 
GLShadergetBoundShader () const
 
bool isShaderBound () const
 
GLShaderpushShader (ShaderTraits traits)
 
void pushShader (GLShader *shader)
 
void popShader ()
 
std::unique_ptr< GLShaderloadShaderFromCode (const QByteArray &vertexSource, const QByteArray &fragmentSource)
 
std::unique_ptr< GLShadergenerateCustomShader (ShaderTraits traits, const QByteArray &vertexSource=QByteArray(), const QByteArray &fragmentSource=QByteArray())
 
std::unique_ptr< GLShadergenerateShaderFromFile (ShaderTraits traits, const QString &vertexFile=QString(), const QString &fragmentFile=QString())
 

Static Public Member Functions

static ShaderManagerinstance ()
 
static void cleanup ()
 

Detailed Description

Manager for Shaders.

This class provides some built-in shaders to be used by both compositing scene and effects. The ShaderManager provides methods to bind a built-in or a custom shader and keeps track of the shaders which have been bound. When a shader is unbound the previously bound shader will be rebound.

Author
Martin Gräßlin mgrae.nosp@m.ssli.nosp@m.n@kde.nosp@m..org
Since
4.7

Definition at line 47 of file glshadermanager.h.

Constructor & Destructor Documentation

◆ ShaderManager()

KWin::ShaderManager::ShaderManager ( )
explicit

Definition at line 38 of file glshadermanager.cpp.

◆ ~ShaderManager()

KWin::ShaderManager::~ShaderManager ( )

Definition at line 42 of file glshadermanager.cpp.

Member Function Documentation

◆ cleanup()

void KWin::ShaderManager::cleanup ( )
static

Definition at line 33 of file glshadermanager.cpp.

◆ generateCustomShader()

std::unique_ptr< GLShader > KWin::ShaderManager::generateCustomShader ( ShaderTraits traits,
const QByteArray & vertexSource = QByteArray(),
const QByteArray & fragmentSource = QByteArray() )

Creates a custom shader with the given traits and custom vertexSource and or fragmentSource. If the vertexSource is empty a vertex shader with the given traits is generated. If it is not empty the vertexSource is used as the source for the vertex shader.

The same applies for argument fragmentSource just for the fragment shader.

So if both vertesSource and fragmentSource are provided the traits are ignored. If neither are provided a new shader following the traits is generated.

Parameters
traitsThe shader traits for generating the shader
vertexSourceoptional vertex shader source code to be used instead of shader traits
fragmentSourceoptional fragment shader source code to be used instead of shader traits
Returns
new generated shader
Since
5.6

Definition at line 245 of file glshadermanager.cpp.

◆ generateShaderFromFile()

std::unique_ptr< GLShader > KWin::ShaderManager::generateShaderFromFile ( ShaderTraits traits,
const QString & vertexFile = QString(),
const QString & fragmentFile = QString() )

Creates a custom shader with the given traits and custom vertexFile and or fragmentFile.

If the vertexFile is empty a vertex shader with the given traits is generated. If it is not empty the vertexFile is used as the source for the vertex shader.

The same applies for argument fragmentFile just for the fragment shader.

So if both vertexFile and fragmentFile are provided the traits are ignored. If neither are provided a new shader following the traits is generated.

If a custom shader stage is provided and core profile is used, the final file path will be resolved by appending "_core" to the basename.

Parameters
traitsThe shader traits for generating the shader
vertexFileoptional vertex shader source code to be used instead of shader traits
fragmentFileoptional fragment shader source code to be used instead of shader traits
Returns
new generated shader
See also
generateCustomShader

Definition at line 287 of file glshadermanager.cpp.

◆ getBoundShader()

GLShader * KWin::ShaderManager::getBoundShader ( ) const
Returns
The currently bound shader or null if no shader is bound.

Definition at line 323 of file glshadermanager.cpp.

◆ instance()

ShaderManager * KWin::ShaderManager::instance ( )
static
Returns
a pointer to the ShaderManager instance

Definition at line 25 of file glshadermanager.cpp.

◆ isShaderBound()

bool KWin::ShaderManager::isShaderBound ( ) const
Returns
true if a shader is bound, false otherwise

Definition at line 332 of file glshadermanager.cpp.

◆ loadShaderFromCode()

std::unique_ptr< GLShader > KWin::ShaderManager::loadShaderFromCode ( const QByteArray & vertexSource,
const QByteArray & fragmentSource )

Creates a GLShader with the specified sources. The difference to GLShader is that it does not need to be loaded from files.

Parameters
vertexSourceThe source code of the vertex shader
fragmentSourceThe source code of the fragment shader.
Returns
The created shader

Definition at line 379 of file glshadermanager.cpp.

◆ popShader()

void KWin::ShaderManager::popShader ( )

Unbinds the currently bound shader and rebinds a previous stored shader. If there is no previous shader, no shader will be rebound. It is not safe to call this method if there is no bound shader.

See also
pushShader
getBoundShader

Definition at line 353 of file glshadermanager.cpp.

◆ pushShader() [1/2]

void KWin::ShaderManager::pushShader ( GLShader * shader)

Binds the shader. To unbind the shader use popShader. A previous bound shader will be rebound. To bind a built-in shader use the more specific method.

Parameters
shaderThe shader to be bound
See also
popShader

Definition at line 344 of file glshadermanager.cpp.

◆ pushShader() [2/2]

GLShader * KWin::ShaderManager::pushShader ( ShaderTraits traits)

Pushes the current shader onto the stack and binds a shader with the given traits.

Definition at line 337 of file glshadermanager.cpp.

◆ shader()

GLShader * KWin::ShaderManager::shader ( ShaderTraits traits)

Returns a shader with the given traits, creating it if necessary.

Definition at line 314 of file glshadermanager.cpp.


The documentation for this class was generated from the following files: