Created
October 5, 2014 23:40
-
-
Save terryjsmith/dae7c989487231a9f7de to your computer and use it in GitHub Desktop.
Evolution ShaderLoader Load
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Once we get here, it's time to figure out which attributes and uniforms we have | |
GLint activeAttribs = 0; | |
GLint activeUniforms = 0; | |
glGetProgramiv(p, GL_ACTIVE_ATTRIBUTES, &activeAttribs); | |
glGetProgramiv(p, GL_ACTIVE_UNIFORMS, &activeUniforms); | |
// Start with the uniform variables | |
for(int i = 0; i < activeUniforms; i++) { | |
int size = 0; | |
int length = 0; | |
unsigned int type = 0; | |
char name[256]; | |
memset(name, 0, 256); | |
// Get the name of the uniform from the program | |
glGetActiveUniform(p, i, 256, &length, &size, &type, name); | |
char* actual = (char*)malloc(length + 1); | |
strcpy(actual, name); | |
// Then tell the program to go get and store its location | |
int location = program->uniform(actual); | |
if(location < 0) { | |
// problem | |
} | |
} | |
// Then do the same for vertex attributes | |
for(int i = 0; i < activeAttribs; i++) { | |
int size = 0; | |
int length = 0; | |
unsigned int type = 0; | |
char name[256]; | |
memset(name, 0, 256); | |
// Get the name of the uniform from the program | |
glGetActiveAttrib(p, i, 256, &length, &size, &type, name); | |
// Then tell the program to go get and store its location | |
program->attribute(name); | |
} | |
// If we make it here, we have successfully loaded our shader, store it as a resource | |
Resource<ShaderProgram*>* resource = new Resource<ShaderProgram*>(); | |
resource->filename = (char*)malloc(strlen(shader) + 1); | |
strcpy(resource->filename, shader); | |
resource->resource = program; | |
this->Add(resource); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment