Browse Source

Interleaved mesh. Won't compile

Panagiotis Christopoulos Charitos 13 years ago
parent
commit
0938f1b888
4 changed files with 61 additions and 53 deletions
  1. 5 4
      include/anki/resource/Mesh.h
  2. 3 2
      include/anki/resource/Model.h
  3. 10 3
      src/resource/Mesh.cpp
  4. 43 44
      src/resource/Model.cpp

+ 5 - 4
include/anki/resource/Mesh.h

@@ -21,6 +21,7 @@ public:
 		VA_NORMALS,
 		VA_NORMALS,
 		VA_TANGENTS,
 		VA_TANGENTS,
 		VA_TEXTURE_COORDS,
 		VA_TEXTURE_COORDS,
+		VA_TEXTURE_COORDS_1,
 		VA_WEIGHTS_BONE_COUNT,
 		VA_WEIGHTS_BONE_COUNT,
 		VA_WEIGHTS_BONE_IDS,
 		VA_WEIGHTS_BONE_IDS,
 		VA_WEIGHTS_BONE_WEIGHTS,
 		VA_WEIGHTS_BONE_WEIGHTS,
@@ -33,8 +34,8 @@ public:
 
 
 	/// Get info on how to attach a VBO to a VAO
 	/// Get info on how to attach a VBO to a VAO
 	virtual void getVboInfo(
 	virtual void getVboInfo(
-		const VertexAttribute attrib, const U32 lod, const U32 texChannel,
-		Vbo* vbo, U32& size, GLenum& type, U32& stride, U32& offset) = 0;
+		const VertexAttribute attrib, const U32 lod, Vbo* vbo, 
+		U32& size, GLenum& type, U32& stride, U32& offset) = 0;
 
 
 	U32 getVerticesCount() const
 	U32 getVerticesCount() const
 	{
 	{
@@ -101,8 +102,8 @@ public:
 
 
 	/// Implements MeshBase::getVboInfo
 	/// Implements MeshBase::getVboInfo
 	void getVboInfo(
 	void getVboInfo(
-		const VertexAttribute attrib, const U32 lod, const U32 texChannel,
-		Vbo* vbo, U32& size, GLenum& type, U32& stride, U32& offset);
+		const VertexAttribute attrib, const U32 lod, Vbo* vbo, 
+		U32& size, GLenum& type, U32& stride, U32& offset);
 
 
 private:
 private:
 	Vbo vbo;
 	Vbo vbo;

+ 3 - 2
include/anki/resource/Model.h

@@ -58,9 +58,10 @@ protected:
 private:
 private:
 	/// Called by @a createVaos multiple times to create and populate a single
 	/// Called by @a createVaos multiple times to create and populate a single
 	/// VAO
 	/// VAO
-	static Vao* createNewVao(const Material& mtl,
+	static void createVao(const Material& mtl,
 		const MeshBase& mesh,
 		const MeshBase& mesh,
-		const PassLevelKey& key);
+		const PassLevelKey& key,
+		Vao& vao);
 };
 };
 
 
 /// Its a chunk of a model. Its very important class and it binds the material
 /// Its a chunk of a model. Its very important class and it binds the material

+ 10 - 3
src/resource/Mesh.cpp

@@ -112,8 +112,8 @@ void Mesh::createVbos(const MeshLoader& meshData)
 
 
 //==============================================================================
 //==============================================================================
 void Mesh::getVboInfo(
 void Mesh::getVboInfo(
-	const VertexAttribute attrib, const U32 lod, const U32 texChannel,
-	Vbo* v, U32& size, GLenum& type, U32& stride, U32& offset)
+	const VertexAttribute attrib, const U32 lod, Vbo* v, U32& size, 
+	GLenum& type, U32& stride, U32& offset)
 {
 {
 	stride = calcVertexSize();
 	stride = calcVertexSize();
 
 
@@ -141,7 +141,14 @@ void Mesh::getVboInfo(
 		v = &vbo;
 		v = &vbo;
 		size = 2;
 		size = 2;
 		type = GL_FLOAT;
 		type = GL_FLOAT;
-		offset = sizeof(Vec3) * 2 + sizeof(Vec4) + texChannel * sizeof(Vec2);
+		offset = sizeof(Vec3) * 2 + sizeof(Vec4) + sizeof(Vec2);
+		break;
+	case VA_TEXTURE_COORDS_1:
+		ANKI_ASSERT(texChannelsCount > 1);
+		v = &vbo;
+		size = 2;
+		type = GL_FLOAT;
+		offset = sizeof(Vec3) * 2 + sizeof(Vec4) + sizeof(Vec2) * 2;
 		break;
 		break;
 	case VA_WEIGHTS_BONE_COUNT:
 	case VA_WEIGHTS_BONE_COUNT:
 		v = &vbo;
 		v = &vbo;

+ 43 - 44
src/resource/Model.cpp

@@ -13,60 +13,58 @@ namespace anki {
 // ModelPatchBase                                                              =
 // ModelPatchBase                                                              =
 //==============================================================================
 //==============================================================================
 
 
+struct Attrib
+{
+	const char* name;
+	MeshBase::VertexAttribute id;
+};
+
+static const Array<Attrib, MeshBase::VA_COUNT - 1> attribs = {{
+	{"position", MeshBase::VA_POSITION},
+	{"normal", MeshBase::VA_NORMAL},
+	{"tangent", MeshBase::VA_TANGENT},
+	{"texCoords", MeshBase::VA_TEXTURE_COORDS},
+	{"texCoords1", MeshBase::VA_TEXTURE_COORDS_1},
+	{"bonesCount", MeshBase::VA_WEIGHTS_BONE_COUNT},
+	{"boneIds", MeshBase::VA_WEIGHTS_BONE_IDS},
+	{"boneWeights", MeshBase::VA_WEIGHTS_BONE_WEIGHTS}
+}};
+
 //==============================================================================
 //==============================================================================
-Vao* ModelPatchBase::createNewVao(const Material& mtl,
-	const MeshBase& meshb,
-	const PassLevelKey& key)
+Vao* ModelPatchBase::createVao(const Material& mtl,const MeshBase& meshb,
+	const PassLevelKey& key, Vao& vao)
 {
 {
-	Vao* vao = new Vao;
-	vao->create();
+	vao.create();
 
 
-	const ShaderProgramAttributeVariable* attrib;
 	const ShaderProgram& prog = mtl.findShaderProgram(key);
 	const ShaderProgram& prog = mtl.findShaderProgram(key);
 
 
-	attrib = prog.tryFindAttributeVariable("position");
-	if(attrib)
-	{
-		const Vbo* vbo = meshb.getVbo(Mesh::VBO_POSITIONS);
-		ANKI_ASSERT(vbo != nullptr);
-
-		vao->attachArrayBufferVbo(*vbo, *attrib, 3, GL_FLOAT, GL_FALSE, 0,
-			nullptr);
-	}
-
-	attrib = prog.tryFindAttributeVariable("normal");
-	if(attrib)
+	for(const Attrib& attrib : attribs)
 	{
 	{
-		const Vbo* vbo = meshb.getVbo(Mesh::VBO_NORMALS);
-		ANKI_ASSERT(vbo != nullptr);
+		const ShaderProgramAttributeVariable* attrib = 
+			prog.tryFindAttributeVariable(attrib.name);
 
 
-		vao->attachArrayBufferVbo(*vbo, *attrib, 3, GL_FLOAT, GL_FALSE, 0,
-			nullptr);
-	}
-
-	attrib = prog.tryFindAttributeVariable("tangent");
-	if(attrib)
-	{
-		const Vbo* vbo = meshb.getVbo(Mesh::VBO_TANGENTS);
-		ANKI_ASSERT(vbo != nullptr);
+		if(name == nullptr)
+		{
+			continue;
+		}
 
 
-		vao->attachArrayBufferVbo(*vbo, *attrib, 4, GL_FLOAT, GL_FALSE, 0,
-			nullptr);
-	}
+		Vbo* vbo;
+		U32 size;
+		GLenum type;
+		U32 stride;
+		U32 offset;
 
 
-	attrib = prog.tryFindAttributeVariable("texCoords");
-	if(attrib)
-	{
-		const Vbo* vbo = meshb.getVbo(Mesh::VBO_TEX_COORDS);
-		ANKI_ASSERT(vbo != nullptr);
+		meshb.getVboInfo(attrib.id, key.lod, vbo, size, type,
+			stride, offset);
 
 
-		vao->attachArrayBufferVbo(*vbo, *attrib, 2, GL_FLOAT, GL_FALSE, 0,
-			nullptr);
+		vao.attachArrayBufferVbo(*vbo, *attrib, size, type, GL_FALSE, stride,
+			offset);
 	}
 	}
 
 
-	vao->attachElementArrayBufferVbo(*meshb.getVbo(Mesh::VBO_INDICES));
+	meshb.getVboInfo(MeshBase::VA_INDICES, key.lod, vbo, size, type,
+			stride, offset);
 
 
-	return vao;
+	vao.attachElementArrayBufferVbo(*vbo);
 }
 }
 
 
 //==============================================================================
 //==============================================================================
@@ -81,10 +79,11 @@ void ModelPatchBase::createVaos(const Material& mtl,
 		{
 		{
 			PassLevelKey key(pass, level);
 			PassLevelKey key(pass, level);
 
 
-			Vao* vao = createNewVao(mtl, meshb, key);
+			Vao vao;
+			createVao(mtl, meshb, key, vao);
 
 
-			vaos.push_back(vao);
-			vaosMap[key] = vao;
+			vaos.push_back(std::move(vao));
+			vaosMap[key] = &vaos.back();
 		}
 		}
 	}
 	}
 }
 }