|
@@ -250,8 +250,8 @@ namespace graphics { namespace shaders {
|
|
|
return id;
|
|
return id;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- unsigned int init(flyweight<shader> const & fragmentShader,
|
|
|
|
|
- flyweight<shader> const & vertexShader) {
|
|
|
|
|
|
|
+ unsigned int init(identity<shader> const & fragmentShader,
|
|
|
|
|
+ identity<shader> const & vertexShader) {
|
|
|
// 9. Create a new shader program ID
|
|
// 9. Create a new shader program ID
|
|
|
unsigned int id = glCreateProgram();
|
|
unsigned int id = glCreateProgram();
|
|
|
|
|
|
|
@@ -274,16 +274,17 @@ namespace graphics { namespace shaders {
|
|
|
glGetProgramiv(id, GL_LINK_STATUS, &return_code);
|
|
glGetProgramiv(id, GL_LINK_STATUS, &return_code);
|
|
|
|
|
|
|
|
if (return_code != GL_TRUE) {
|
|
if (return_code != GL_TRUE) {
|
|
|
- error_formatter::shader_program_error(id, fragmentShader.actual().path,
|
|
|
|
|
- vertexShader.actual().path);
|
|
|
|
|
|
|
+ // error_formatter::shader_program_error(id,
|
|
|
|
|
+ // fragmentShader.actual().path,
|
|
|
|
|
+ // vertexShader.actual().path);
|
|
|
throw linker_error("Could not link shader program");
|
|
throw linker_error("Could not link shader program");
|
|
|
}
|
|
}
|
|
|
return id;
|
|
return id;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- void activate(unsigned int id) {
|
|
|
|
|
|
|
+ void activate(identity<shader_program> program) {
|
|
|
// 100. Use the shader program ID to "turn it on" for all subsequent drawing
|
|
// 100. Use the shader program ID to "turn it on" for all subsequent drawing
|
|
|
- glUseProgram(id);
|
|
|
|
|
|
|
+ glUseProgram(program.id);
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
// 101. Enable texturing and Bind texture(s) to GPU texture units
|
|
// 101. Enable texturing and Bind texture(s) to GPU texture units
|
|
@@ -306,13 +307,13 @@ namespace graphics { namespace shaders {
|
|
|
|
|
|
|
|
// 102. Get the location # of each named uniform you wish to pass in to the
|
|
// 102. Get the location # of each named uniform you wish to pass in to the
|
|
|
// shader
|
|
// shader
|
|
|
- int timeUniformLocation = glGetUniformLocation(id, "u_time");
|
|
|
|
|
- int scale = glGetUniformLocation(id, "Scale");
|
|
|
|
|
- int diffuseMapUniformLocation = glGetUniformLocation(id, "u_diffuseMap");
|
|
|
|
|
- int normalMapUniformLocation = glGetUniformLocation(id, "u_normalMap");
|
|
|
|
|
- int specularMapUniformLocation = glGetUniformLocation(id, "u_specularMap");
|
|
|
|
|
- int emissiveMapUniformLocation = glGetUniformLocation(id, "u_emissiveMap");
|
|
|
|
|
- int debugWave = glGetUniformLocation(id, "g_debugWave");
|
|
|
|
|
|
|
+ int timeUniformLocation = glGetUniformLocation(program.id, "u_time");
|
|
|
|
|
+ int scale = glGetUniformLocation(program.id, "Scale");
|
|
|
|
|
+ int diffuseMap = glGetUniformLocation(program.id, "u_diffuseMap");
|
|
|
|
|
+ int normalMap = glGetUniformLocation(program.id, "u_normalMap");
|
|
|
|
|
+ int specularMap = glGetUniformLocation(program.id, "u_specularMap");
|
|
|
|
|
+ int emissiveMap = glGetUniformLocation(program.id, "u_emissiveMap");
|
|
|
|
|
+ int debugWave = glGetUniformLocation(program.id, "g_debugWave");
|
|
|
|
|
|
|
|
// 103. Set the uniform values, including the texture unit numbers for
|
|
// 103. Set the uniform values, including the texture unit numbers for
|
|
|
// texture (sampler) uniforms
|
|
// texture (sampler) uniforms
|
|
@@ -321,22 +322,23 @@ namespace graphics { namespace shaders {
|
|
|
glUniform1f(scale, 2.f);
|
|
glUniform1f(scale, 2.f);
|
|
|
glUniform1i(debugWave, 1); // TODO: m_waveEffectOn in ShaderProgram??
|
|
glUniform1i(debugWave, 1); // TODO: m_waveEffectOn in ShaderProgram??
|
|
|
// for GL_TEXTURE0, texture unit 0
|
|
// for GL_TEXTURE0, texture unit 0
|
|
|
- glUniform1i(diffuseMapUniformLocation, 0);
|
|
|
|
|
|
|
+ glUniform1i(diffuseMap, 0);
|
|
|
// for GL_TEXTURE1, texture unit 1
|
|
// for GL_TEXTURE1, texture unit 1
|
|
|
- glUniform1i(normalMapUniformLocation, 1);
|
|
|
|
|
|
|
+ glUniform1i(normalMap, 1);
|
|
|
// for GL_TEXTURE2, texture unit 2
|
|
// for GL_TEXTURE2, texture unit 2
|
|
|
- glUniform1i(specularMapUniformLocation, 2);
|
|
|
|
|
|
|
+ glUniform1i(specularMap, 2);
|
|
|
// for GL_TEXTURE3, texture unit 3
|
|
// for GL_TEXTURE3, texture unit 3
|
|
|
- glUniform1i(emissiveMapUniformLocation, 3);
|
|
|
|
|
|
|
+ glUniform1i(emissiveMap, 3);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- int uniform_location(unsigned int id, std::string const & uniform) {
|
|
|
|
|
- return glGetUniformLocation(id, uniform.c_str());
|
|
|
|
|
|
|
+ int uniform_location(identity<shader_program> program,
|
|
|
|
|
+ std::string const & uniform) {
|
|
|
|
|
+ return glGetUniformLocation(program.id, uniform.c_str());
|
|
|
}
|
|
}
|
|
|
}}
|
|
}}
|
|
|
|
|
|
|
|
namespace graphics { namespace materials {
|
|
namespace graphics { namespace materials {
|
|
|
- void activate(flyweight<shader_program> program,
|
|
|
|
|
|
|
+ void activate(identity<shader_program> program,
|
|
|
std::vector<uniform> const & uniforms) {
|
|
std::vector<uniform> const & uniforms) {
|
|
|
glUseProgram(program.id);
|
|
glUseProgram(program.id);
|
|
|
|
|
|