void RenderContextPolicy< ShaderCollection::VertexSolidVertexColor, ShaderCollection::FragmentSolidVertexColor, ShaderCollection::No>::BindParameters(const CoreState& params) { const Math::mat4 proj_view_world = params.m_projection * params.m_view * params.m_world; SetUniformMatrix4f(uProjViewWorld, &proj_view_world[0]); SetUpOpenGL(params); }
void Shader::UpdateUniforms(const Transform& transform, const Material& material, const RenderingEngine& renderingEngine, const Camera& camera) const { Matrix4f worldMatrix = transform.GetTransformation(); Matrix4f projectedMatrix = camera.GetViewProjection() * worldMatrix; for(unsigned int i = 0; i < m_shaderData->GetUniformNames().size(); i++) { std::string uniformName = m_shaderData->GetUniformNames()[i]; std::string uniformType = m_shaderData->GetUniformTypes()[i]; if(uniformName.substr(0, 2) == "R_") { std::string unprefixedName = uniformName.substr(2, uniformName.length()); if(unprefixedName == "lightMatrix") SetUniformMatrix4f(uniformName, renderingEngine.GetLightMatrix() * worldMatrix); else if(uniformType == "sampler2D") { int samplerSlot = renderingEngine.GetSamplerSlot(unprefixedName); renderingEngine.GetTexture(unprefixedName).Bind(samplerSlot); SetUniformi(uniformName, samplerSlot); } else if(uniformType == "vec3") SetUniformVector3f(uniformName, renderingEngine.GetVector3f(unprefixedName)); else if(uniformType == "float") SetUniformf(uniformName, renderingEngine.GetFloat(unprefixedName)); else if(uniformType == "DirectionalLight") SetUniformDirectionalLight(uniformName, *(const DirectionalLight*)&renderingEngine.GetActiveLight()); else if(uniformType == "PointLight") SetUniformPointLight(uniformName, *(const PointLight*)&renderingEngine.GetActiveLight()); else if(uniformType == "SpotLight") SetUniformSpotLight(uniformName, *(const SpotLight*)&renderingEngine.GetActiveLight()); else renderingEngine.UpdateUniformStruct(transform, material, *this, uniformName, uniformType); } else if(uniformType == "sampler2D") { int samplerSlot = renderingEngine.GetSamplerSlot(uniformName); material.GetTexture(uniformName).Bind(samplerSlot); SetUniformi(uniformName, samplerSlot); } else if(uniformName.substr(0, 2) == "T_") { if(uniformName == "T_MVP") SetUniformMatrix4f(uniformName, projectedMatrix); else if(uniformName == "T_model") SetUniformMatrix4f(uniformName, worldMatrix); else throw "Invalid Transform Uniform: " + uniformName; } else if(uniformName.substr(0, 2) == "C_") { if(uniformName == "C_eyePos") SetUniformVector3f(uniformName, camera.GetTransform().GetTransformedPos()); else throw "Invalid Camera Uniform: " + uniformName; } else { if(uniformType == "vec3") SetUniformVector3f(uniformName, material.GetVector3f(uniformName)); else if(uniformType == "float") SetUniformf(uniformName, material.GetFloat(uniformName)); else throw uniformType + " is not supported by the Material class"; } } }