Panagiotis Christopoulos Charitos 13 years ago
parent
commit
9c37c36e66
3 changed files with 28 additions and 16 deletions
  1. 6 9
      include/anki/gl/ShaderProgram.h
  2. 17 4
      src/gl/ShaderProgram.cpp
  3. 5 3
      src/gl/Texture.cpp

+ 6 - 9
include/anki/gl/ShaderProgram.h

@@ -34,15 +34,12 @@ public:
 	ShaderProgramVariable& operator=(const ShaderProgramVariable&) = delete;
 
 	ShaderProgramVariable(
-		GLint loc_, 
-		const char* name_,
-		GLenum glDataType_, 
-		size_t size_,
-		ShaderProgramVariableType type_, 
-		const ShaderProgram* fatherSProg_)
-		: loc(loc_), name(name_), glDataType(glDataType_), size(size_), 
-			type(type_), fatherSProg(fatherSProg_)
-	{}
+		GLint loc,
+		const char* name,
+		GLenum glDataType, 
+		size_t size,
+		ShaderProgramVariableType type, 
+		const ShaderProgram* fatherSProg);
 
 	virtual ~ShaderProgramVariable()
 	{}

+ 17 - 4
src/gl/ShaderProgram.cpp

@@ -10,14 +10,28 @@ namespace anki {
 // ShaderProgramVariable                                                       =
 //==============================================================================
 
+//==============================================================================
+ShaderProgramVariable(
+	GLint loc_, 
+	const char* name_,
+	GLenum glDataType_, 
+	size_t size_,
+	ShaderProgramVariableType type_, 
+	const ShaderProgram* fatherSProg_)
+	: loc(loc_), name(name_), glDataType(glDataType_), size(size_), 
+		type(type_), fatherSProg(fatherSProg_)
+{
+	name.shrink_to_fit();
+	ANKI_ASSERT(loc == 
+		getUniformLocation(fatherSProg->getGlId(), name.c_str()));
+}
+
 //==============================================================================
 void ShaderProgramUniformVariable::doCommonSetCode()
 {
 	ANKI_ASSERT(getLocation() != -1);
 	ANKI_ASSERT(ShaderProgram::getCurrentProgramGlId() == 
 		getFatherShaderProgram().getGlId());
-	ANKI_ASSERT(glGetUniformLocation(getFatherShaderProgram().getGlId(),
-		getName().c_str()) == getLocation());
 
 	enableFlag(SPUVF_DIRTY);
 }
@@ -109,8 +123,7 @@ void ShaderProgramUniformVariable::set(const Texture& tex)
 	ANKI_ASSERT(getGlDataType() == GL_SAMPLER_2D 
 		|| getGlDataType() == GL_SAMPLER_2D_SHADOW);
 	
-	tex.bind();
-	glUniform1i(getLocation(), tex.getUnit());
+	glUniform1i(getLocation(), tex.bind());
 }
 
 //==============================================================================

+ 5 - 3
src/gl/Texture.cpp

@@ -107,7 +107,7 @@ uint32_t TextureUnits::choseUnit(const Texture& tex, bool& allreadyBinded)
 }
 
 //==============================================================================
-void TextureUnits::bindTexture(const Texture& tex)
+uint32_t TextureUnits::bindTexture(const Texture& tex)
 {
 	bool allreadyBinded;
 	uint32_t unit = choseUnit(tex, allreadyBinded);
@@ -117,6 +117,8 @@ void TextureUnits::bindTexture(const Texture& tex)
 		activateUnit(unit);
 		glBindTexture(tex.getTarget(), tex.getGlId());
 	}
+
+	return unit;
 }
 
 //==============================================================================
@@ -238,9 +240,9 @@ void Texture::create(const Initializer& init)
 }
 
 //==============================================================================
-void Texture::bind() const
+uint32_t Texture::bind() const
 {
-	TextureUnitsSingleton::get().bindTexture(*this);
+	return TextureUnitsSingleton::get().bindTexture(*this);
 }
 
 //==============================================================================