1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added some GL shader helper functions.

This commit is contained in:
jules 2013-11-01 10:44:32 +00:00
parent 4de9768ecb
commit 751ad2ed6e
2 changed files with 24 additions and 3 deletions

View file

@ -51,10 +51,18 @@ double OpenGLShaderProgram::getLanguageVersion()
#endif
}
bool OpenGLShaderProgram::addShader (const char* const code, GLenum type)
bool OpenGLShaderProgram::addShader (StringRef code, GLenum type)
{
GLuint shaderID = context.extensions.glCreateShader (type);
context.extensions.glShaderSource (shaderID, 1, (const GLchar**) &code, nullptr);
#if JUCE_STRING_UTF_TYPE == 8
const GLchar* c = code.text;
#else
String codeString (code.text);
const GLchar* c = codeString.toRawUTF8();
#endif
context.extensions.glShaderSource (shaderID, 1, &c, nullptr);
context.extensions.glCompileShader (shaderID);
GLint status = GL_FALSE;
@ -83,6 +91,9 @@ bool OpenGLShaderProgram::addShader (const char* const code, GLenum type)
return true;
}
bool OpenGLShaderProgram::addVertexShader (StringRef code) { return addShader (code, GL_VERTEX_SHADER); }
bool OpenGLShaderProgram::addFragmentShader (StringRef code) { return addShader (code, GL_FRAGMENT_SHADER); }
bool OpenGLShaderProgram::link() noexcept
{
context.extensions.glLinkProgram (programID);

View file

@ -59,7 +59,17 @@ public:
@returns true if the shader compiled successfully. If not, you can call
getLastError() to find out what happened.
*/
bool addShader (const char* const shaderSourceCode, GLenum shaderType);
bool addShader (StringRef shaderSourceCode, GLenum shaderType);
/** Compiles and adds a fragment shader to this program.
This is equivalent to calling addShader() with a type of GL_VERTEX_SHADER.
*/
bool addVertexShader (StringRef shaderSourceCode);
/** Compiles and adds a fragment shader to this program.
This is equivalent to calling addShader() with a type of GL_FRAGMENT_SHADER.
*/
bool addFragmentShader (StringRef shaderSourceCode);
/** Links all the compiled shaders into a usable program.
If your app is built in debug mode, this method will assert if the program