Browse Source

Added some GL shader helper functions.

tags/2021-05-28
jules 11 years ago
parent
commit
751ad2ed6e
2 changed files with 24 additions and 3 deletions
  1. +13
    -2
      modules/juce_opengl/opengl/juce_OpenGLShaderProgram.cpp
  2. +11
    -1
      modules/juce_opengl/opengl/juce_OpenGLShaderProgram.h

+ 13
- 2
modules/juce_opengl/opengl/juce_OpenGLShaderProgram.cpp View File

@@ -51,10 +51,18 @@ double OpenGLShaderProgram::getLanguageVersion()
#endif #endif
} }
bool OpenGLShaderProgram::addShader (const char* const code, GLenum type)
bool OpenGLShaderProgram::addShader (StringRef code, GLenum type)
{ {
GLuint shaderID = context.extensions.glCreateShader (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); context.extensions.glCompileShader (shaderID);
GLint status = GL_FALSE; GLint status = GL_FALSE;
@@ -83,6 +91,9 @@ bool OpenGLShaderProgram::addShader (const char* const code, GLenum type)
return true; 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 bool OpenGLShaderProgram::link() noexcept
{ {
context.extensions.glLinkProgram (programID); context.extensions.glLinkProgram (programID);


+ 11
- 1
modules/juce_opengl/opengl/juce_OpenGLShaderProgram.h View File

@@ -59,7 +59,17 @@ public:
@returns true if the shader compiled successfully. If not, you can call @returns true if the shader compiled successfully. If not, you can call
getLastError() to find out what happened. 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. /** Links all the compiled shaders into a usable program.
If your app is built in debug mode, this method will assert if the program If your app is built in debug mode, this method will assert if the program


Loading…
Cancel
Save