Browse Source

Minor stuff

Panagiotis Christopoulos Charitos 13 years ago
parent
commit
ac74245147
2 changed files with 20 additions and 9 deletions
  1. 11 6
      include/anki/gl/ShaderProgram.h
  2. 9 3
      src/gl/ShaderProgram.cpp

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

@@ -5,7 +5,6 @@
 #include "anki/util/Assert.h"
 #include "anki/util/Assert.h"
 #include "anki/util/Flags.h"
 #include "anki/util/Flags.h"
 #include "anki/math/Forward.h"
 #include "anki/math/Forward.h"
-#include "anki/util/NonCopyable.h"
 #include "anki/gl/Ogl.h"
 #include "anki/gl/Ogl.h"
 #include "anki/util/Vector.h"
 #include "anki/util/Vector.h"
 #include "anki/util/StdTypes.h"
 #include "anki/util/StdTypes.h"
@@ -34,7 +33,8 @@ public:
 		SPVT_UNIFORM
 		SPVT_UNIFORM
 	};
 	};
 
 
-	ShaderProgramVariable()
+	ShaderProgramVariable(ShaderProgramVariableType type_)
+		: type(type_)
 	{}
 	{}
 	virtual ~ShaderProgramVariable()
 	virtual ~ShaderProgramVariable()
 	{}
 	{}
@@ -66,7 +66,7 @@ public:
 		return type;
 		return type;
 	}
 	}
 
 
-	size_t getSize() const
+	PtrSize getSize() const
 	{
 	{
 		return size;
 		return size;
 	}
 	}
@@ -74,11 +74,11 @@ public:
 
 
 	ShaderProgramVariable& operator=(const ShaderProgramVariable& b)
 	ShaderProgramVariable& operator=(const ShaderProgramVariable& b)
 	{
 	{
+		ANKI_ASSERT(type == b.type)
 		loc = b.loc;
 		loc = b.loc;
 		name = b.name;
 		name = b.name;
 		glDataType = b.glDataType;
 		glDataType = b.glDataType;
 		size = b.size;
 		size = b.size;
-		type = b.type;
 		fatherSProg = b.fatherSProg;
 		fatherSProg = b.fatherSProg;
 		return *this;
 		return *this;
 	}
 	}
@@ -89,7 +89,7 @@ private:
 	/// GL_FLOAT, GL_FLOAT_VEC2 etc. See
 	/// GL_FLOAT, GL_FLOAT_VEC2 etc. See
 	/// http://www.opengl.org/sdk/docs/man/xhtml/glGetActiveUniform.xml
 	/// http://www.opengl.org/sdk/docs/man/xhtml/glGetActiveUniform.xml
 	GLenum glDataType;
 	GLenum glDataType;
-	size_t size; ///< Its 1 if it is a single or >1 if it is an array
+	PtrSize size; ///< Its 1 if it is a single or >1 if it is an array
 	ShaderProgramVariableType type;
 	ShaderProgramVariableType type;
 	/// We need the ShaderProg of this variable mainly for sanity checks
 	/// We need the ShaderProg of this variable mainly for sanity checks
 	const ShaderProgram* fatherSProg;
 	const ShaderProgram* fatherSProg;
@@ -103,6 +103,7 @@ class ShaderProgramUniformVariable: public ShaderProgramVariable
 
 
 public:
 public:
 	ShaderProgramUniformVariable()
 	ShaderProgramUniformVariable()
+		: ShaderProgramVariable(SPVT_UNIFORM)
 	{}
 	{}
 
 
 	/// @name Set the var
 	/// @name Set the var
@@ -160,7 +161,7 @@ private:
 
 
 	/// Offset inside the uniform block. -1 if it's inside the default uniform 
 	/// Offset inside the uniform block. -1 if it's inside the default uniform 
 	/// block
 	/// block
-	GLint offset; 
+	GLint offset = -1; 
 
 
 	/// "An array identifying the stride between elements, in basic machine 
 	/// "An array identifying the stride between elements, in basic machine 
 	/// units, of each of the uniforms specified by the corresponding array of
 	/// units, of each of the uniforms specified by the corresponding array of
@@ -182,6 +183,10 @@ private:
 class ShaderProgramAttributeVariable: public ShaderProgramVariable
 class ShaderProgramAttributeVariable: public ShaderProgramVariable
 {
 {
 	friend class ShaderProgram;
 	friend class ShaderProgram;
+
+	ShaderProgramAttributeVariable()
+		: ShaderProgramVariable(SPVT_ATTRIBUTE)
+	{}
 };
 };
 
 
 /// Uniform shader block
 /// Uniform shader block

+ 9 - 3
src/gl/ShaderProgram.cpp

@@ -349,7 +349,7 @@ void ShaderProgram::link() const
 	glLinkProgram(glId);
 	glLinkProgram(glId);
 
 
 	// check if linked correctly
 	// check if linked correctly
-	int success;
+	GLint success;
 	glGetProgramiv(glId, GL_LINK_STATUS, &success);
 	glGetProgramiv(glId, GL_LINK_STATUS, &success);
 
 
 	if(!success)
 	if(!success)
@@ -425,7 +425,6 @@ void ShaderProgram::initUniAndAttribVars()
 		var.name = &name_[0];
 		var.name = &name_[0];
 		var.glDataType = type;
 		var.glDataType = type;
 		var.size = size;
 		var.size = size;
-		var.type = ShaderProgramVariable::SPVT_ATTRIBUTE;
 		var.fatherSProg = this;
 		var.fatherSProg = this;
 
 
 		nameToAttribVar[var.name.c_str()] = &var;
 		nameToAttribVar[var.name.c_str()] = &var;
@@ -452,7 +451,6 @@ void ShaderProgram::initUniAndAttribVars()
 		var.name = &name_[0];
 		var.name = &name_[0];
 		var.glDataType = type;
 		var.glDataType = type;
 		var.size = size;
 		var.size = size;
-		var.type = ShaderProgramVariable::SPVT_UNIFORM;
 		var.fatherSProg = this;
 		var.fatherSProg = this;
 
 
 		var.index = (GLuint)i;
 		var.index = (GLuint)i;
@@ -506,6 +504,7 @@ void ShaderProgram::initUniformBlocks()
 	// Connect uniforms and blocks
 	// Connect uniforms and blocks
 	for(ShaderProgramUniformVariable& uni : unis)
 	for(ShaderProgramUniformVariable& uni : unis)
 	{
 	{
+		/* Block index */
 		GLint blockIndex;
 		GLint blockIndex;
 		glGetActiveUniformsiv(glId, 1, &(uni.index),  GL_UNIFORM_BLOCK_INDEX, 
 		glGetActiveUniformsiv(glId, 1, &(uni.index),  GL_UNIFORM_BLOCK_INDEX, 
 			&blockIndex);
 			&blockIndex);
@@ -517,6 +516,13 @@ void ShaderProgram::initUniformBlocks()
 
 
 		uni.block = &blocks[blockIndex];
 		uni.block = &blocks[blockIndex];
 		blocks[blockIndex].uniforms.push_back(&uni);
 		blocks[blockIndex].uniforms.push_back(&uni);
+
+		/* Offset in block */
+		GLint offset;
+		glGetActiveUniformsiv(glId, 1, &(uni.index),  GL_UNIFORM_OFFSET, 
+			&blockIndex);
+		ANKI_ASSERT(offset != -1); // If -1 then it should break before
+		uni.offset = offset;
 	}
 	}
 }
 }