SGCT master (487fac4)
Simple Graphics Cluster Toolkit
Loading...
Searching...
No Matches
sgct::ShaderProgram Class Reference

Class for handling compiling, linking and using shader programs. More...

#include <sgct/shaderprogram.h>

Public Member Functions

 ShaderProgram ()=default
 ShaderProgram (std::string name)
 Default only sets the program name.
 ShaderProgram (const ShaderProgram &)=delete
 ShaderProgram (ShaderProgram &&) noexcept
ShaderProgram & operator= (const ShaderProgram &)=delete
ShaderProgram & operator= (ShaderProgram &&) noexcept
 ~ShaderProgram ()
 The destructor clears the shader data vector but the program can still be used.
void deleteProgram ()
 Will detach all attached shaders, delete them and then delete the program.
void addVertexShader (std::string_view src)
 Will create and add a vertex shader to the program.
void addFragmentShader (std::string_view src)
 Will create and add a fragment shader to the program.
void createAndLinkProgram ()
 Will create the program and link the shaders.
void bind () const
 Use the shader program in the current rendering pipeline.
std::string_view name () const
unsigned int id () const

Static Public Member Functions

static void unbind ()
 Unset the shader program in the current rendering pipeline.

Detailed Description

Class for handling compiling, linking and using shader programs.

Uniform and attribute handling must be managed explicitly.

Constructor & Destructor Documentation

◆ ShaderProgram() [1/4]

sgct::ShaderProgram::ShaderProgram ( )
default

◆ ShaderProgram() [2/4]

sgct::ShaderProgram::ShaderProgram ( std::string name)

Default only sets the program name.

Shaders objects won't be created until any shader source code is set. The program will be created when the createAndLink() function is called. Make sure the shader sources are set before calling it.

Parameters
nameName of the shader program. Must be unique

◆ ShaderProgram() [3/4]

sgct::ShaderProgram::ShaderProgram ( const ShaderProgram & )
delete

◆ ShaderProgram() [4/4]

sgct::ShaderProgram::ShaderProgram ( ShaderProgram && )
noexcept

◆ ~ShaderProgram()

sgct::ShaderProgram::~ShaderProgram ( )

The destructor clears the shader data vector but the program can still be used.

The program have to be destroyed explicitly by calling deleteProgram. This is so that programs can be copied when storing in containers.

Member Function Documentation

◆ addFragmentShader()

void sgct::ShaderProgram::addFragmentShader ( std::string_view src)

Will create and add a fragment shader to the program.

Parameters
srcThe shader source string
Exceptions
std::runtime_errorIf the adding of the shaders failed

◆ addVertexShader()

void sgct::ShaderProgram::addVertexShader ( std::string_view src)

Will create and add a vertex shader to the program.

Parameters
srcThe shader source string
Exceptions
std::runtime_errorIf the adding of the shaders failed

◆ bind()

void sgct::ShaderProgram::bind ( ) const

Use the shader program in the current rendering pipeline.

◆ createAndLinkProgram()

void sgct::ShaderProgram::createAndLinkProgram ( )

Will create the program and link the shaders.

The shader sources must have been set before the program can be linked. After the program is created and linked no modification to the shader sources can be made.

◆ deleteProgram()

void sgct::ShaderProgram::deleteProgram ( )

Will detach all attached shaders, delete them and then delete the program.

◆ id()

unsigned int sgct::ShaderProgram::id ( ) const
Returns
The program ID

◆ name()

std::string_view sgct::ShaderProgram::name ( ) const
Returns
The name of the program

◆ operator=() [1/2]

ShaderProgram & sgct::ShaderProgram::operator= ( const ShaderProgram & )
delete

◆ operator=() [2/2]

ShaderProgram & sgct::ShaderProgram::operator= ( ShaderProgram && )
noexcept

◆ unbind()

void sgct::ShaderProgram::unbind ( )
static

Unset the shader program in the current rendering pipeline.


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