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:
parent
4de9768ecb
commit
751ad2ed6e
2 changed files with 24 additions and 3 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue