PDA

View Full Version : Program Object Management for an Engine (Kind of)



MoMack20
01-21-2016, 02:49 PM
I have been working to fix up my sloppy code by wrapping a lot of it in classes and I think I've run into a problem with the Shader Objects because of the way they cannot be copied. At first I figured that since they are just referred to by an int, that there wouldn't be any problem moving them around in an std::vector. I was wrong.

Here is the cpp. for my class. All it has is a string for the name of the shader and a GLuint that refers to the value you get after creating the program.

Shader::Shader(string name, GLuint program) {
mName = name;
mProg = program;
}

void Shader::Draw() {
glUseProgram(mProg);
}

string Shader::getName() {
return mName;
}

GLuint Shader::getProg() {
return mProg;
}


mShaders.emplace_back(new Shader(name, program));

^^ Is how I put the new Shader class object into a vector after going through the loading process for the code. Name is just a string given such as "Standard Blinn Phong", and the program is the GLuint value that i was given from GL.


This is the place where my code breaks:
void Object::Draw() {
if(mMeshComponent != NULL)
{
GLuint prog = mMaterial->getShader()->getProg();
glUseProgram(prog); //This causes my application to stop and my debugger to stop.

CAMERA_MANAGER->getActiveCamera()->Draw(prog);
LIGHT_MANAGER->drawLights(prog);

GLuint loc;
loc = glGetUniformLocation(prog, "WorldMatrix");
glUniformMatrix4fv(loc, 1, GL_FALSE, &mWorldMatrix[0][0]);

mMaterial->Draw();

mMeshComponent->Draw();
}
else
cout << "Tried to draw object with no mesh" << endl;
}

I was looking else where on the forums and saw that using emplace_back might fix my problem, but I'm still crashing. Any help on fixing this or a better way to wrap and manipulate Program Objects would be greatly appreciated.