Loading...
Searching...
No Matches
juce::OpenGLShaderProgram Class Reference

## Detailed Description

Manages an OpenGL shader program.

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

- juce_opengl/opengl/juce_OpenGLShaderProgram.h

## Classes

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

## Public Member Functions

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

## Static Public Member Functions

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

## Constructors and Destructors

## OpenGLShaderProgram()

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

noexcept

Creates a shader for use in a particular GL context.

Referenced by juce::OpenGLShaderProgram::Attribute::Attribute(), getProgramID(), and juce::OpenGLShaderProgram::Uniform::Uniform().

## ~OpenGLShaderProgram()

juce::OpenGLShaderProgram::~OpenGLShaderProgram | ( |  | ) |

noexcept

Destructor.

## Member Functions

## getLanguageVersion()

double juce::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...
}
juce::OpenGLShaderProgram::getLanguageVersion
static double getLanguageVersion()
Returns the version of GLSL that the current context supports.

References getLanguageVersion().

Referenced by getLanguageVersion().

## addShader()

bool juce::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.

References addShader().

Referenced by addShader().

## addVertexShader()

bool juce::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.

References addVertexShader().

Referenced by addVertexShader().

## addFragmentShader()

bool juce::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.

References addFragmentShader().

Referenced by addFragmentShader().

## link()

bool juce::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.

References link().

Referenced by link().

## getLastError()

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

inline noexcept

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

References getLastError().

Referenced by getLastError().

## use()

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

noexcept

Selects this program into the current context.

## release()

void juce::OpenGLShaderProgram::release | ( |  | ) |

noexcept

Deletes the program.

References release().

Referenced by release().

## getUniformIDFromName()

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

noexcept

Get the uniform ID from the variable name.

References getUniformIDFromName().

Referenced by getUniformIDFromName().

## setUniform() [1/7]

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

noexcept

Sets a float uniform.

References setUniform().

Referenced by setUniform(), setUniform(), setUniform(), setUniform(), setUniform(), setUniform(), and setUniform().

## setUniform() [2/7]

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

noexcept

Sets an int uniform.

References setUniform().

## setUniform() [3/7]

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

noexcept

Sets a vec2 uniform.

References setUniform(), x, and y.

## setUniform() [4/7]

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

noexcept

Sets a vec3 uniform.

References setUniform(), x, and y.

## setUniform() [5/7]

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

noexcept

Sets a vec4 uniform.

References setUniform(), w, x, and y.

## setUniform() [6/7]

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

noexcept

Sets a vec4 uniform.

References setUniform(), w, x, and y.

## setUniform() [7/7]

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

noexcept

Sets a vector float uniform.

References setUniform().

## setUniformMat2()

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

noexcept

Sets a 2x2 matrix float uniform.

References setUniformMat2().

Referenced by setUniformMat2().

## setUniformMat3()

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

noexcept

Sets a 3x3 matrix float uniform.

References setUniformMat3().

Referenced by setUniformMat3().

## setUniformMat4()

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

noexcept

Sets a 4x4 matrix float uniform.

References setUniformMat4().

Referenced by setUniformMat4().

## getProgramID()

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

noexcept

The ID number of the compiled program.

References JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR, and OpenGLShaderProgram().

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited