OpenGLShaderProgram Class Reference
juce_opengl » opengl

Manages an OpenGL shader program. More...

## Classes

struct | Attribute
| Represents an openGL vertex attribute value. More...
struct | Uniform
| Represents an openGL uniform value. More...

## Public Member Functions

| OpenGLShaderProgram (const OpenGLContext &) noexcept
| Creates a shader for use in a particular GL context. More...
| ~OpenGLShaderProgram () noexcept
| Destructor. More...
bool | addShader (const String &shaderSourceCode, GLenum shaderType)
| Compiles and adds a shader to this program. More...
bool | addVertexShader (const String &shaderSourceCode)
| Compiles and adds a fragment shader to this program. More...
bool | addFragmentShader (const String &shaderSourceCode)
| Compiles and adds a fragment shader to this program. More...
bool | link () noexcept
| Links all the compiled shaders into a usable program. More...
const String & | getLastError () const noexcept
| Get the output for the last shader compilation or link that failed. More...
void | use () const noexcept
| Selects this program into the current context. More...
void | release () noexcept
| Deletes the program. More...
GLint | getUniformIDFromName (const char *uniformName) const noexcept
| Get the uniform ID from the variable name. More...
void | setUniform (const char *uniformName, GLfloat value) noexcept
| Sets a float uniform. More...
void | setUniform (const char *uniformName, GLint value) noexcept
| Sets an int uniform. More...
void | setUniform (const char *uniformName, GLfloat x, GLfloat y) noexcept
| Sets a vec2 uniform. More...
void | setUniform (const char *uniformName, GLfloat x, GLfloat y, GLfloat z) noexcept
| Sets a vec3 uniform. More...
void | setUniform (const char *uniformName, GLfloat x, GLfloat y, GLfloat z, GLfloat w) noexcept
| Sets a vec4 uniform. More...
void | setUniform (const char *uniformName, GLint x, GLint y, GLint z, GLint w) noexcept
| Sets a vec4 uniform. More...
void | setUniform (const char *uniformName, const GLfloat *values, GLsizei numValues) noexcept
| Sets a vector float uniform. More...
void | setUniformMat2 (const char *uniformName, const GLfloat *values, GLint count, GLboolean transpose) noexcept
| Sets a 2x2 matrix float uniform. More...
void | setUniformMat3 (const char *uniformName, const GLfloat *values, GLint count, GLboolean transpose) noexcept
| Sets a 3x3 matrix float uniform. More...
void | setUniformMat4 (const char *uniformName, const GLfloat *values, GLint count, GLboolean transpose) noexcept
| Sets a 4x4 matrix float uniform. More...
GLuint | getProgramID () const noexcept
| The ID number of the compiled program. More...

## Static Public Member Functions

static double | getLanguageVersion ()
| Returns the version of GLSL that the current context supports. More...

## Detailed Description

Manages an OpenGL shader program.

## Constructor & Destructor Documentation

## OpenGLShaderProgram()

OpenGLShaderProgram::OpenGLShaderProgram | ( | const OpenGLContext & |  | ) |

noexcept

Creates a shader for use in a particular GL context.

## ~OpenGLShaderProgram()

OpenGLShaderProgram::~OpenGLShaderProgram | ( |  | ) |

noexcept

Destructor.

## Member Function Documentation

## getLanguageVersion()

static double OpenGLShaderProgram::getLanguageVersion | ( |  | ) |

static

Returns the version of GLSL that the current context supports.

E.g.

if (OpenGLShaderProgram::getLanguageVersion() > 1.199)
{
// ..do something that requires GLSL 1.2 or above..
}

## addShader()

bool OpenGLShaderProgram::addShader | ( | const String & | shaderSourceCode,
|  | GLenum | shaderType
| ) |  |

Compiles and adds a shader to this program.

After adding all your shaders, remember to call link() to link them into a usable program.

If your app is built in debug mode, this method will assert if the program fails to compile correctly.

The shaderType parameter could be GL_VERTEX_SHADER, GL_FRAGMENT_SHADER, etc.

Returns
  true if the shader compiled successfully. If not, you can call getLastError() to find out what happened.

## addVertexShader()

bool OpenGLShaderProgram::addVertexShader | ( | const String & | shaderSourceCode | ) |

Compiles and adds a fragment shader to this program.

This is equivalent to calling addShader() with a type of GL_VERTEX_SHADER.

## addFragmentShader()

bool OpenGLShaderProgram::addFragmentShader | ( | const String & | shaderSourceCode | ) |

Compiles and adds a fragment shader to this program.

This is equivalent to calling addShader() with a type of GL_FRAGMENT_SHADER.

## link()

bool OpenGLShaderProgram::link | ( |  | ) |

noexcept

Links all the compiled shaders into a usable program.

If your app is built in debug mode, this method will assert if the program fails to link correctly.

Returns
  true if the program linked successfully. If not, you can call getLastError() to find out what happened.

## getLastError()

const String& OpenGLShaderProgram::getLastError | ( |  | ) | const

noexcept

Get the output for the last shader compilation or link that failed.

## use()

void OpenGLShaderProgram::use | ( |  | ) | const

noexcept

Selects this program into the current context.

## release()

void OpenGLShaderProgram::release | ( |  | ) |

noexcept

Deletes the program.

## getUniformIDFromName()

GLint OpenGLShaderProgram::getUniformIDFromName | ( | const char * | uniformName | ) | const

noexcept

Get the uniform ID from the variable name.

## setUniform() [1/7]

void OpenGLShaderProgram::setUniform | ( | const char * | uniformName,
|  | GLfloat | value
| ) |  |

noexcept

Sets a float uniform.

## setUniform() [2/7]

void OpenGLShaderProgram::setUniform | ( | const char * | uniformName,
|  | GLint | value
| ) |  |

noexcept

Sets an int uniform.

## setUniform() [3/7]

void OpenGLShaderProgram::setUniform | ( | const char * | uniformName,
|  | GLfloat | x,
|  | GLfloat | y
| ) |  |

noexcept

Sets a vec2 uniform.

## setUniform() [4/7]

void OpenGLShaderProgram::setUniform | ( | const char * | uniformName,
|  | GLfloat | x,
|  | GLfloat | y,
|  | GLfloat | z
| ) |  |

noexcept

Sets a vec3 uniform.

## setUniform() [5/7]

void OpenGLShaderProgram::setUniform | ( | const char * | uniformName,
|  | GLfloat | x,
|  | GLfloat | y,
|  | GLfloat | z,
|  | GLfloat | w
| ) |  |

noexcept

Sets a vec4 uniform.

## setUniform() [6/7]

void OpenGLShaderProgram::setUniform | ( | const char * | uniformName,
|  | GLint | x,
|  | GLint | y,
|  | GLint | z,
|  | GLint | w
| ) |  |

noexcept

Sets a vec4 uniform.

## setUniform() [7/7]

void OpenGLShaderProgram::setUniform | ( | const char * | uniformName,
|  | const GLfloat * | values,
|  | GLsizei | numValues
| ) |  |

noexcept

Sets a vector float uniform.

## setUniformMat2()

void OpenGLShaderProgram::setUniformMat2 | ( | const char * | uniformName,
|  | const GLfloat * | values,
|  | GLint | count,
|  | GLboolean | transpose
| ) |  |

noexcept

Sets a 2x2 matrix float uniform.

## setUniformMat3()

void OpenGLShaderProgram::setUniformMat3 | ( | const char * | uniformName,
|  | const GLfloat * | values,
|  | GLint | count,
|  | GLboolean | transpose
| ) |  |

noexcept

Sets a 3x3 matrix float uniform.

## setUniformMat4()

void OpenGLShaderProgram::setUniformMat4 | ( | const char * | uniformName,
|  | const GLfloat * | values,
|  | GLint | count,
|  | GLboolean | transpose
| ) |  |

noexcept

Sets a 4x4 matrix float uniform.

## getProgramID()

GLuint OpenGLShaderProgram::getProgramID | ( |  | ) | const

noexcept

The ID number of the compiled program.

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

- juce_OpenGLShaderProgram.h

OpenGLShaderProgram::getLanguageVersion
static double getLanguageVersion()
Returns the version of GLSL that the current context supports.