Jason McKesson avatar Jason McKesson committed fa20b3a

Tut17: Lighting works with real parameters. Still needs textures.

Comments (0)

Files changed (6)

Tut 17 Spotlight on Textures/Double Projection.cpp

 
 Framework::UniformVec4Binder g_blueBinder;
 Framework::UniformVec4Binder g_redBinder;
+Framework::UniformIntBinder g_lightNumBinder;
+
+GLint g_unlitModelToCameraMatrixUnif;
+GLint g_unlitObjectColorUnif;
+GLuint g_unlitProg;
+Framework::Mesh *g_pSphereMesh = NULL;
 
 void LoadAndSetupScene()
 {
 	g_nodes.clear();
-	g_pScene = new Framework::Scene("dp_scene.xml");
 
-	g_nodes.push_back(g_pScene->FindNode("blueSphere"));
-	g_nodes.push_back(g_pScene->FindNode("redSphere"));
+	std::auto_ptr<Framework::Scene> pScene(new Framework::Scene("dp_scene.xml"));
+
+	std::vector<Framework::NodeRef> nodes;
+	nodes.push_back(pScene->FindNode("blueSphere"));
+	nodes.push_back(pScene->FindNode("redSphere"));
+
+	GLuint unlit = pScene->FindProgram("p_unlit");
+	Framework::Mesh *pSphereMesh = pScene->FindMesh("m_sphere");
+
+	g_lightNumBinder.AssociateWithProgram(nodes[0].GetProgram(), "numberOfLights");
+	g_lightNumBinder.AssociateWithProgram(nodes[1].GetProgram(), "numberOfLights");
+	nodes[0].SetStateBinder(&g_lightNumBinder);
+	nodes[1].SetStateBinder(&g_lightNumBinder);
+
+	g_blueBinder.AssociateWithProgram(nodes[0].GetProgram(), "objectColor");
+	g_blueBinder.SetValue(glm::vec4(0.3f, 0.3f, 1.0f, 1.0f));
+	nodes[0].SetStateBinder(&g_blueBinder);
+	g_redBinder.AssociateWithProgram(nodes[1].GetProgram(), "objectColor");
+	g_redBinder.SetValue(glm::vec4(1.0f, 0.1f, 0.1f, 1.0f));
+	nodes[1].SetStateBinder(&g_redBinder);
 
 	//No more things that can throw.
-	g_blueBinder.AssociateWithProgram(g_nodes[0].GetProgram(), "objectColor");
-	g_blueBinder.SetValue(glm::vec4(0.3f, 0.3f, 1.0f, 1.0f));
-	g_nodes[0].SetStateBinder(&g_blueBinder);
-	g_redBinder.AssociateWithProgram(g_nodes[1].GetProgram(), "objectColor");
-	g_redBinder.SetValue(glm::vec4(1.0f, 0.1f, 0.1f, 1.0f));
-	g_nodes[1].SetStateBinder(&g_redBinder);
+	g_unlitProg = unlit;
+	g_unlitModelToCameraMatrixUnif = glGetUniformLocation(unlit, "modelToCameraMatrix");
+	g_unlitObjectColorUnif = glGetUniformLocation(unlit, "objectColor");
+
+	std::swap(nodes, g_nodes);
+	nodes.clear();	//If something was there already, delete it.
+
+	std::swap(pSphereMesh, g_pSphereMesh);
+
+	Framework::Scene *pOldScene = g_pScene;
+	g_pScene = pScene.release();
+	pScene.reset(pOldScene);	//If something was there already, delete it.
 }
 
+struct PerLight
+{
+	glm::vec4 cameraSpaceLightPos;
+	glm::vec4 lightIntensity;
+};
+
+const int MAX_NUMBER_OF_LIGHTS = 4;
+
+struct LightBlock
+{
+	glm::vec4 ambientIntensity;
+	float lightAttenuation;
+	float maxIntensity;
+	float padding[2];
+	PerLight lights[MAX_NUMBER_OF_LIGHTS];
+};
+
+
 //Called after the window and OpenGL are initialized. Called exactly once, before the main loop.
 void init()
 {
 		throw;
 	}
 
-/*
 	glGenBuffers(1, &g_lightUniformBuffer);
 	glBindBuffer(GL_UNIFORM_BUFFER, g_lightUniformBuffer);
 	glBufferData(GL_UNIFORM_BUFFER, sizeof(LightBlock), NULL, GL_STREAM_DRAW);
 		0, sizeof(LightBlock));
 
 	glBindBuffer(GL_UNIFORM_BUFFER, 0);
-*/
 
 //	LoadTextures();
 //	CreateSamplers();
 int g_displayWidth = 700;
 int g_displayHeight = 350;
 
+void BuildLights( const glm::mat4 &camMatrix )
+{
+	LightBlock lightData;
+	lightData.ambientIntensity = glm::vec4(0.2, 0.2, 0.2, 1.0);
+	lightData.lightAttenuation = 1.0f / (5.0f * 5.0f);
+	lightData.maxIntensity = 3.0f;
+	lightData.lights[0].lightIntensity = glm::vec4(2.0, 2.0, 2.5, 1.0);
+	lightData.lights[0].cameraSpaceLightPos = camMatrix *
+		glm::normalize(glm::vec4(0.0f, 0.5f, 0.5f, 0.0f));
+	lightData.lights[1].lightIntensity = glm::vec4(7.0, 9.0, 6.5, 1.0);
+	lightData.lights[1].cameraSpaceLightPos = camMatrix *
+		glm::vec4(5.0f, 4.0f, 0.5f, 1.0f);
+
+	g_lightNumBinder.SetValue(2);
+
+	glBindBuffer(GL_UNIFORM_BUFFER, g_lightUniformBuffer);
+	glBufferData(GL_UNIFORM_BUFFER, sizeof(LightBlock), &lightData, GL_STREAM_DRAW);
+}
+
 //Called to update the display.
 //You should call glutSwapBuffers after all of your rendering to display what you rendered.
 //If you need continuous updates of the screen, call glutPostRedisplay() at the end of the function.
 	glClearDepth(1.0f);
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
+	glutil::MatrixStack modelMatrix;
+	modelMatrix *= g_viewPole.CalcMatrix();
+
+	BuildLights(modelMatrix.Top());
+
 	g_nodes[0].NodeSetOrient(glm::rotate(glm::fquat(),
 		360.0f * g_timer.GetAlpha(), glm::vec3(0.0f, 1.0f, 0.0f)));
 
 	}
 
 	glViewport(0, 0, (GLsizei)displaySize.x, (GLsizei)displaySize.y);
-	g_pScene->Render(g_viewPole.CalcMatrix());
+	g_pScene->Render(modelMatrix.Top());
+
+	if(g_bDrawCameraPos)
+	{
+		glutil::PushStack stackPush(modelMatrix);
+		//Draw lookat point.
+		modelMatrix.SetIdentity();
+		modelMatrix.Translate(glm::vec3(0.0f, 0.0f, -g_viewPole.GetView().radius));
+
+		glDisable(GL_DEPTH_TEST);
+		glDepthMask(GL_FALSE);
+		glUseProgram(g_unlitProg);
+		glUniformMatrix4fv(g_unlitModelToCameraMatrixUnif, 1, GL_FALSE,
+			glm::value_ptr(modelMatrix.Top()));
+		glUniform4f(g_unlitObjectColorUnif, 0.25f, 0.25f, 0.25f, 1.0f);
+		g_pSphereMesh->Render("flat");
+		glDepthMask(GL_TRUE);
+		glEnable(GL_DEPTH_TEST);
+		glUniform4f(g_unlitObjectColorUnif, 1.0f, 1.0f, 1.0f, 1.0f);
+		g_pSphereMesh->Render("flat");
+	}
 
 	{
 		glutil::MatrixStack persMatrix;
 
 	glViewport(displaySize.x + (g_displayWidth % 2), 0,
 		(GLsizei)displaySize.x, (GLsizei)displaySize.y);
-	g_pScene->Render(g_viewPole.CalcMatrix());
-
-/*
-    if(!g_pLightEnv)
-        return;
-
-	glEnable(GL_FRAMEBUFFER_SRGB);
-
-	g_pLightEnv->UpdateTime();
-
-	glm::vec4 bgColor = g_pLightEnv->GetBackgroundColor();
-	glClearColor(bgColor.x, bgColor.y, bgColor.z, bgColor.w);
-	glClearDepth(1.0f);
-	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
-	glutil::MatrixStack modelMatrix;
-	modelMatrix.ApplyMatrix(g_viewPole.CalcMatrix());
-
-	LightBlock lightData = g_pLightEnv->GetLightBlock(g_viewPole.CalcMatrix());
-
-	glBindBuffer(GL_UNIFORM_BUFFER, g_lightUniformBuffer);
-	glBufferData(GL_UNIFORM_BUFFER, sizeof(LightBlock), &lightData, GL_STREAM_DRAW);
-	glBindBuffer(GL_UNIFORM_BUFFER, 0);
-
-	if(g_pSphere && g_pTerrain)
-	{
-		glutil::PushStack push(modelMatrix);
-		modelMatrix.RotateX(-90.0f);
-
-		glUseProgram(g_progStandard.theProgram);
-		glUniformMatrix4fv(g_progStandard.modelToCameraMatrixUnif, 1, GL_FALSE,
-			glm::value_ptr(modelMatrix.Top()));
-		glUniform1i(g_progStandard.numberOfLightsUnif, g_pLightEnv->GetNumLights());
-
-		glActiveTexture(GL_TEXTURE0 + g_colorTexUnit);
-		glBindTexture(GL_TEXTURE_2D, g_linearTexture);
-		glBindSampler(g_colorTexUnit, g_samplers[g_currSampler]);
-
-		g_pTerrain->Render("lit-tex");
-
-		glBindSampler(g_colorTexUnit, 0);
-		glBindTexture(GL_TEXTURE_2D, 0);
-
-		glUseProgram(0);
-
-
-		push.ResetStack();
-
-		//Render the sun
-		{
-			glm::vec3 sunlightDir(g_pLightEnv->GetSunlightDirection());
-			modelMatrix.Translate(sunlightDir * 500.0f);
-			modelMatrix.Scale(30.0f, 30.0f, 30.0f);
-
-			glUseProgram(g_progUnlit.theProgram);
-			glUniformMatrix4fv(g_progUnlit.modelToCameraMatrixUnif, 1, GL_FALSE,
-				glm::value_ptr(modelMatrix.Top()));
-
-			glm::vec4 lightColor = g_pLightEnv->GetSunlightScaledIntensity(), gamma;
-			glUniform4fv(g_progUnlit.objectColorUnif, 1, glm::value_ptr(lightColor));
-			g_pSphere->Render("flat");
-		}
-
-		//Draw lights
-		for(int light = 0; light < g_pLightEnv->GetNumPointLights(); light++)
-		{
-			push.ResetStack();
-
-			modelMatrix.Translate(g_pLightEnv->GetPointLightWorldPos(light));
-
-			glUseProgram(g_progUnlit.theProgram);
-			glUniformMatrix4fv(g_progUnlit.modelToCameraMatrixUnif, 1, GL_FALSE,
-				glm::value_ptr(modelMatrix.Top()));
-
-			glm::vec4 lightColor = g_pLightEnv->GetPointLightScaledIntensity(light);
-			glUniform4fv(g_progUnlit.objectColorUnif, 1, glm::value_ptr(lightColor));
-			g_pSphere->Render("flat");
-		}
-
-
-		push.ResetStack();
-
-		if(g_bDrawCameraPos)
-		{
-			//Draw lookat point.
-			modelMatrix.SetIdentity();
-			modelMatrix.Translate(glm::vec3(0.0f, 0.0f, -g_viewPole.GetView().radius));
-
-			glDisable(GL_DEPTH_TEST);
-			glDepthMask(GL_FALSE);
-			glUseProgram(g_progUnlit.theProgram);
-			glUniformMatrix4fv(g_progUnlit.modelToCameraMatrixUnif, 1, GL_FALSE,
-				glm::value_ptr(modelMatrix.Top()));
-			glUniform4f(g_progUnlit.objectColorUnif, 0.25f, 0.25f, 0.25f, 1.0f);
-			g_pSphere->Render("flat");
-			glDepthMask(GL_TRUE);
-			glEnable(GL_DEPTH_TEST);
-			glUniform4f(g_progUnlit.objectColorUnif, 1.0f, 1.0f, 1.0f, 1.0f);
-			g_pSphere->Render("flat");
-		}
-	}
-
-	*/
+	g_pScene->Render(modelMatrix.Top());
 
     glutPostRedisplay();
 	glutSwapBuffers();
 	case 32:
 		g_persViewPole.Reset();
 		break;
+	case 'y':
+		g_bDrawCameraPos = !g_bDrawCameraPos;
+		break;
 	case 'p':
+		g_timer.TogglePause();
+		break;
+	case '\r': //Enter key.
 		{
-			glm::mat4 tm = g_persViewPole.CalcMatrix();
-			printf("%f\t%f\t%f\t%f\n", tm[0][0], tm[1][0], tm[2][0], tm[3][0]);
-			printf("%f\t%f\t%f\t%f\n", tm[0][1], tm[1][1], tm[2][1], tm[3][1]);
-			printf("%f\t%f\t%f\t%f\n", tm[0][2], tm[1][2], tm[2][2], tm[3][2]);
-			printf("%f\t%f\t%f\t%f\n", tm[0][3], tm[1][3], tm[2][3], tm[3][3]);
-		}
-		break;
-	case '\r':
-		{
-			std::auto_ptr<Framework::Scene> pOldScene(g_pScene);
-			g_pScene = NULL;
-			std::vector<Framework::NodeRef> tmpNodes;
-			tmpNodes.swap(g_nodes);
 			try
 			{
 				LoadAndSetupScene();
 			catch(std::exception &except)
 			{
 				printf("Failed to reload, due to: %s\n", except.what());
-				if(g_pScene)
-					delete g_pScene;
-				g_pScene = pOldScene.release();
-				g_nodes.swap(tmpNodes);
 				return;
 			}
 		}
 	height = g_displayHeight;
 	return displayMode | GLUT_SRGB;
 }
+

Tut 17 Spotlight on Textures/data/dp_scene.xml

     <mesh xml:id="m_sphere" file="UnitSphere.xml"/>
     <mesh xml:id="m_cube" file="UnitCube.xml"/>
     <prog
-        xml:id="p_untex"
+        xml:id="p_unlit"
         vert="Unlit.vert"
         frag="Unlit.frag"
         model-to-camera="modelToCameraMatrix">
         model-to-camera="modelToCameraMatrix"
         normal-model-to-camera="normalModelToCameraMatrix">
         <block name="Projection" binding="0"/>
+		<block name="Light" binding="1"/>
     </prog>
     <node
         name="blueSphere"

Tut 17 Spotlight on Textures/data/litTexture.frag

 
 uniform vec4 objectColor;
 
-/*
-
 uniform Light
 {
 	vec4 ambientIntensity;
 	
 	return (1 / ( 1.0 + Lgt.lightAttenuation * lightDistanceSqr));
 }
-*/
 
 vec4 ComputeLighting(in vec4 diffuseColor, in PerLight lightData)
 {
 	vec3 lightDir;
 	vec4 lightIntensity;
-	/*
 	if(lightData.cameraSpaceLightPos.w == 0.0)
 	{
-	*/
 		lightDir = vec3(lightData.cameraSpaceLightPos);
 		lightIntensity = lightData.lightIntensity;
-		/*
 	}
 	else
 	{
 			lightData.cameraSpaceLightPos.xyz, lightDir);
 		lightIntensity = atten * lightData.lightIntensity;
 	}
-	*/
 	
 	vec3 surfaceNormal = normalize(cameraSpaceNormal);
 	float cosAngIncidence = dot(surfaceNormal, lightDir);
 	return lighting;
 }
 
-uniform sampler2D diffuseColorTex;
+//uniform sampler2D diffuseColorTex;
 
 void main()
 {
 	currLight.cameraSpaceLightPos = normalize(vec4(0.0, 0.5, 0.5, 0.0));
 	currLight.lightIntensity = vec4(2.0, 2.0, 2.5, 1.0);
 	
-	vec4 accumLighting = vec4(0.2, 0.2, 0.2, 1.0);
-	accumLighting += ComputeLighting(objectColor, currLight);
+	vec4 accumLighting = objectColor * Lgt.ambientIntensity;
+	for(int light = 0; light < numberOfLights; light++)
+	{
+		accumLighting += ComputeLighting(objectColor, Lgt.lights[light]);
+	}
 	
-	outputColor = accumLighting / 3.0;
+	outputColor = accumLighting / Lgt.maxIntensity;
 
 //	outputColor = diffuseColor;
 }

framework/Scene.cpp

 		template<typename DeleteType>
 		void DeleteThis(DeleteType &value) { delete value; }
 
-		void BindBinder(const StateBinder *pState) {pState->BindState();}
-		void UnbindBinder(const StateBinder *pState) {pState->UnbindState();}
+		struct BindBinder
+		{
+			BindBinder(GLuint prog) : m_prog(prog){}
+			void operator()(const StateBinder *pState) const {pState->BindState(m_prog);}
+			GLuint m_prog;
+		};
+
+		struct UnbindBinder
+		{
+			UnbindBinder(GLuint prog) : m_prog(prog){}
+			void operator()(const StateBinder *pState) const {pState->UnbindState(m_prog);}
+			GLuint m_prog;
+		};
 	}
 
 	class SceneMesh
 			m_pMesh->Render();
 		}
 
+		Mesh *GetMesh() {return m_pMesh;}
+
 	private:
-		Framework::Mesh *m_pMesh;
+		Mesh *m_pMesh;
 	};
 
 	class SceneProgram
 					glm::value_ptr(normMat));
 			}
 
-			std::for_each(m_binders.begin(), m_binders.end(), BindBinder);
+			std::for_each(m_binders.begin(), m_binders.end(), BindBinder(m_pProg->GetProgram()));
 			m_pMesh->Render();
-			std::for_each(m_binders.rbegin(), m_binders.rend(), UnbindBinder);
+			std::for_each(m_binders.rbegin(), m_binders.rend(), UnbindBinder(m_pProg->GetProgram()));
 			glUseProgram(0);
 		}
 
 			return theIt->second->GetProgram();
 		}
 
+		Mesh *FindMesh(const std::string &meshName)
+		{
+			MeshMap::iterator theIt = m_meshes.find(meshName);
+			if(theIt == m_meshes.end())
+				throw std::runtime_error("Could not find the mesh named: " + meshName);
+
+			return theIt->second->GetMesh();
+		}
+
+
 
 	private:
 
 			SceneMesh *pMesh = new SceneMesh(make_string(*pFilenameNode));
 
 			m_meshes[name] = pMesh;
-
-			std::cout << "Mesh: \"" << pNameNode->value() << "\", \"" << pFilenameNode->value()
-				<< "\"" << std::endl;
 		}
 
 		void ReadPrograms(const xml_node<> &scene)
 
 			m_progs[name] = new SceneProgram(program, matrixLoc, normalMatLoc);
 
-			std::cout << "Program: \"" << pNameNode->value() << "\"" << std::endl;
-			std::cout << "\tVertex Shader: \"" << pVertexShaderNode->value() << "\"" << std::endl;
-			if(pGeometryShaderNode)
-				std::cout << "\tGeometry Shader: \"" << pGeometryShaderNode->value() << "\"" << std::endl;
-			std::cout << "\tFragment Shader: \"" << pFragmentShaderNode->value() << "\"" << std::endl;
-			std::cout << "\tModel Matrix uniform: \"" << pModelMatrixNode->value() << "\"" << std::endl;
-			if(pNormalMatrixNode)
-				std::cout << "\tNormal Matrix uniform: \"" << pNormalMatrixNode->value() << "\"" << std::endl;
-
 			ReadProgramContents(program, progNode);
 		}
 
 
 					int bindPoint = rapidxml::attrib_to_int(*pBindingNode, ThrowAttrib);
 					glUniformBlockBinding(program, blockIx, bindPoint);
-
-					std::cout << "\t->Block: \"" << pNameNode->value() << "\", "
-						<< bindPoint << std::endl;
 				}
 				else if(childName == "sampler")
 				{
 					glUseProgram(program);
 					glUniform1i(samplerLoc, textureUnit);
 					glUseProgram(0);
-
-					std::cout << "\t->Sampler: \"" << pNameNode->value() << "\", "
-						<<textureUnit << std::endl;
 				}
 				else
 				{
 				}
 			}
 
-			std::cout << "Node: \"" << pNameNode->value() << "\"";
-			std::cout << "\tMesh: \"" << pMeshNode->value() << "\"";
-			std::cout << "\tProgram: \"" << pProgNode->value() << "\"" << std::endl;
-
-			std::cout << "\tPosition:    " << pPositionNode->value() << "\"" << std::endl;
-			if(pOrientNode)
-				std::cout << "\tOrientation: " << pOrientNode->value() << "\"" << std::endl;
-			if(pScaleNode)
-				std::cout << "\tScale:       " << pScaleNode->value() << "\"" << std::endl;
-
 			ReadNodeNotes(nodeNode);
 		}
 
 				const xml_node<> &noteNode = *pNoteNode;
 				const xml_attribute<> *pNameNode = noteNode.first_attribute("name");
 				PARSE_THROW(pNameNode, "Notations on nodes must have a `name` attribute.");
-
-				std::cout << "\t->Note: \"" << pNameNode->value() << "\"" << std::endl;
-				std::cout << "\t\t->" << noteNode.value() << "<-" << std::endl;
 			}
 		}
 	};
 	{
 		return m_pImpl->FindProgram(progName);
 	}
+
+	Mesh * Scene::FindMesh( const std::string &meshName )
+	{
+		return m_pImpl->FindMesh(meshName);
+	}
 }

framework/Scene.h

 	class SceneImpl;
 	class SceneNode;
 
+	class Mesh;
+
 	class StateBinder;
 
 	class NodeRef
 
 		GLuint FindProgram(const std::string &progName);
 
+		Mesh *FindMesh(const std::string &meshName);
+
 	private:
 		SceneImpl *m_pImpl;
 	};

framework/SceneBinders.h

 #define FRAMEWORK_SCENE_BINDERS_H
 
 #include <string>
+#include <map>
 #include <glm/glm.hpp>
 #include <glm/gtc/type_ptr.hpp>
 
 		virtual ~StateBinder() {}
 
 		//The current program will be in use when this is called.
-		virtual void BindState() const = 0;
+		virtual void BindState(GLuint prog) const = 0;
 
 		//The current program will be in use when this is called.
-		virtual void UnbindState() const = 0;
+		virtual void UnbindState(GLuint prog) const = 0;
 	};
 
 	class UniformBinderBase : public StateBinder
 	{
 	public:
-		UniformBinderBase() : m_unifLoc(-1) {}
+		UniformBinderBase() {}
 
 		void AssociateWithProgram(GLuint prog, const std::string &unifName)
 		{
-			m_unifLoc = glGetUniformLocation(prog, unifName.c_str());
+			m_progUnifLoc[prog] = glGetUniformLocation(prog, unifName.c_str());
 		}
 
 	protected:
-		GLint GetUniformLoc() const {return m_unifLoc;}
+		GLint GetUniformLoc(GLuint prog) const
+		{
+			std::map<GLuint, GLint>::const_iterator loc = m_progUnifLoc.find(prog);
+			if(loc == m_progUnifLoc.end())
+				return -1;
+
+			return loc->second;
+		}
 
 	private:
-		GLint m_unifLoc;
+		std::map<GLuint, GLint> m_progUnifLoc;
 	};
 
 	class UniformVec4Binder : public UniformBinderBase
 
 		void SetValue(const glm::vec4 &val)	{ m_val = val; }
 
-		virtual void BindState() const
+		virtual void BindState(GLuint prog) const
 		{
-			glUniform4fv(GetUniformLoc(), 1, glm::value_ptr(m_val));
+			glUniform4fv(GetUniformLoc(prog), 1, glm::value_ptr(m_val));
 		}
 
-		virtual void UnbindState() const {}
+		virtual void UnbindState(GLuint prog) const {}
 
 	private:
 		glm::vec4 m_val;
 
 		void SetValue(const glm::vec3 &val)	{ m_val = val; }
 
-		virtual void BindState() const
+		virtual void BindState(GLuint prog) const
 		{
-			glUniform3fv(GetUniformLoc(), 1, glm::value_ptr(m_val));
+			glUniform3fv(GetUniformLoc(prog), 1, glm::value_ptr(m_val));
 		}
 
-		virtual void UnbindState() const {}
+		virtual void UnbindState(GLuint prog) const {}
 
 	private:
 		glm::vec3 m_val;
 
 		void SetValue(const glm::vec2 &val)	{ m_val = val; }
 
-		virtual void BindState() const
+		virtual void BindState(GLuint prog) const
 		{
-			glUniform2fv(GetUniformLoc(), 1, glm::value_ptr(m_val));
+			glUniform2fv(GetUniformLoc(prog), 1, glm::value_ptr(m_val));
 		}
 
-		virtual void UnbindState() const {}
+		virtual void UnbindState(GLuint prog) const {}
 
 	private:
 		glm::vec2 m_val;
 
 		void SetValue(const float &val)	{ m_val = val; }
 
-		virtual void BindState() const
+		virtual void BindState(GLuint prog) const
 		{
-			glUniform1f(GetUniformLoc(), m_val);
+			glUniform1f(GetUniformLoc(prog), m_val);
 		}
 
-		virtual void UnbindState() const {}
+		virtual void UnbindState(GLuint prog) const {}
 
 	private:
 		float m_val;
 
 		void SetValue(const int &val)	{ m_val = val; }
 
-		virtual void BindState() const
+		virtual void BindState(GLuint prog) const
 		{
-			glUniform1i(GetUniformLoc(), m_val);
+			glUniform1i(GetUniformLoc(prog), m_val);
 		}
 
-		virtual void UnbindState() const {}
+		virtual void UnbindState(GLuint prog) const {}
 
 	private:
 		int m_val;
 			m_samplerObj = samplerObj;
 		}
 
-		virtual void BindState() const
+		virtual void BindState(GLuint prog) const
 		{
 			glActiveTexture(GL_TEXTURE0 + m_texUnit);
 			glBindTexture(m_texType, m_texObj);
 			glBindSampler(m_texUnit, m_samplerObj);
 		}
 
-		virtual void UnbindState() const
+		virtual void UnbindState(GLuint prog) const
 		{
 			glActiveTexture(GL_TEXTURE0 + m_texUnit);
 			glBindTexture(m_texType, 0);
 			m_buffSize = buffSize;
 		}
 
-		virtual void BindState() const
+		virtual void BindState(GLuint prog) const
 		{
 			glBindBufferRange(GL_UNIFORM_BUFFER, m_blockIndex, m_unifBuffer,
 				m_buffOffset, m_buffSize);
 		}
 
-		virtual void UnbindState() const
+		virtual void UnbindState(GLuint prog) const
 		{
 			glBindBufferBase(GL_UNIFORM_BUFFER, m_blockIndex, 0);
 		}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.