Browse Source

Start designing the multi mesh support (= faster rendering)

Panagiotis Christopoulos Charitos 13 years ago
parent
commit
97455f8bd9
4 changed files with 112 additions and 14 deletions
  1. 72 5
      include/anki/resource/Mesh.h
  2. 5 7
      shaders/IsLpGeneric.glsl
  3. 2 2
      shaders/IsLpVertex.glsl
  4. 33 0
      src/resource/Mesh.cpp

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

@@ -37,15 +37,34 @@ public:
 		const VertexAttribute attrib, const Vbo*& vbo,
 		U32& size, GLenum& type, U32& stride, U32& offset) const = 0;
 
+	virtual U32 getTextureChannelsCount() const = 0;
+
+	virtual Bool hasWeights() const = 0;
+
+	/// Used only to clone the VBO
 	virtual U32 getVerticesCount() const = 0;
 
 	virtual U32 getIndicesCount() const = 0;
 
-	virtual U32 getTextureChannelsCount() const = 0;
+	virtual const Obb& getBoundingShape() const = 0;
 
-	virtual Bool hasWeights() const = 0;
+	virtual U32 getIndicesCountSub(U32 subMeshId, U32& offset) const
+	{
+		ANKI_ASSERT(subMeshId == 0);
+		offset = 0;
+		return getIndicesCount();
+	}
 
-	virtual const Obb& getBoundingShape() const = 0;
+	virtual const Obb& getBoundingShapeSub(U32 subMeshId) const
+	{
+		ANKI_ASSERT(subMeshId == 0);
+		return getBoundingShape();
+	}
+
+	virtual U32 getSubMeshesCount() const
+	{
+		return 1;
+	}
 };
 
 /// Mesh Resource. It contains the geometry packed in VBOs
@@ -102,10 +121,10 @@ public:
 		U32& size, GLenum& type, U32& stride, U32& offset) const;
 	/// @}
 
-	/// Load from a file
+	/// Load from a .mesh file
 	void load(const char* filename);
 
-private:
+protected:
 	U32 vertsCount;
 	U32 indicesCount; ///< Indices count per level
 	U32 texChannelsCount;
@@ -121,6 +140,54 @@ private:
 	U32 calcVertexSize() const;
 };
 
+/// A mesh that behaves as a mesh and as a collection of separate meshes
+class MultiMesh: public Mesh
+{
+	/// Default constructor. Do nothing
+	MultiMesh()
+	{}
+
+	/// Load file
+	MultiMesh(const char* filename)
+	{
+		load(filename);
+	}
+	/// @}
+
+	/// Does nothing
+	~MultiMesh()
+	{}
+
+	/// @name MeshBase implementers
+	/// @{
+	U32 getIndicesCountSub(U32 subMeshId, U32& offset) const
+	{
+		ANKI_ASSERT(subMeshId < subIndicesCount.size());
+		offset = subIndicesOffsets[subMeshId];
+		return subIndicesCount[subMeshId];
+	}
+
+	const Obb& getBoundingShapeSub(U32 subMeshId) const
+	{
+		ANKI_ASSERT(subMeshId < subVisibilityShapes.size());
+		return subVisibilityShapes[subMeshId];
+	}
+
+	U32 getSubMeshesCount() const
+	{
+		return subIndicesCount.size();
+	}
+	/// @}
+
+	/// Load from a .mmesh file
+	void load(const char* filename);
+
+private:
+	Vector<U32> subIndicesCount;
+	Vector<U32> subIndicesOffsets;
+	Vector<Obb> subVisibilityShapes;
+};
+
 } // end namespace anki
 
 #endif

+ 5 - 7
shaders/IsLpGeneric.glsl

@@ -79,7 +79,7 @@ uniform sampler2DArrayShadow shadowMapArr;
 /// @{
 in vec2 vTexCoords;
 flat in int vInstanceId;
-in vec2 vLimitsOfNoearPlaneOpt;
+in vec2 vLimitsOfNearPlaneOpt;
 /// @}
 
 /// @name Output
@@ -94,11 +94,9 @@ vec3 getFragPosVSpace()
 	const float depth = texture(msDepthFai, vTexCoords).r;
 
 	vec3 fragPosVspace;
-	/// XXX OPT: Why negative planes.y?
-	fragPosVspace.z = -planes.y / (planes.x + depth);
-
-	/// XXX OPT: Do that a varying
-	fragPosVspace.xy = vLimitsOfNoearPlaneOpt * (-fragPosVspace.z);
+	fragPosVspace.z = planes.y / (planes.x + depth);
+	fragPosVspace.xy = vLimitsOfNearPlaneOpt * fragPosVspace.z;
+	fragPosVspace.z = -fragPosVspace.z;
 
 	return fragPosVspace;
 }
@@ -293,7 +291,7 @@ void main()
 #endif
 
 #if 0
-	fColor = fColor * 0.005 + vec3(vLimitsOfNoearPlaneOpt, 1.0);
+	fColor = fColor * 0.005 + vec3(vLimitsOfNearPlaneOpt, 1.0);
 #endif
 
 #if 0

+ 2 - 2
shaders/IsLpVertex.glsl

@@ -8,7 +8,7 @@ uniform vec4 limitsOfNearPlane;
 
 out vec2 vTexCoords;
 flat out int vInstanceId;
-out vec2 vLimitsOfNoearPlaneOpt;
+out vec2 vLimitsOfNearPlaneOpt;
 
 void main()
 {
@@ -24,6 +24,6 @@ void main()
 	vec2 vertPosNdc = vTexCoords * 2.0 - 1.0;
 	gl_Position = vec4(vertPosNdc, 0.0, 1.0);
 
-	vLimitsOfNoearPlaneOpt = 
+	vLimitsOfNearPlaneOpt = 
 		(vTexCoords * limitsOfNearPlane.zw) - limitsOfNearPlane.xy;
 }

+ 33 - 0
src/resource/Mesh.cpp

@@ -3,9 +3,14 @@
 #include "anki/resource/MeshLoader.h"
 #include "anki/gl/Vbo.h"
 #include "anki/util/Functions.h"
+#include "anki/misc/Xml.h"
 
 namespace anki {
 
+//==============================================================================
+// Mesh                                                                        =
+//==============================================================================
+
 //==============================================================================
 void Mesh::load(const char* filename)
 {
@@ -188,4 +193,32 @@ void Mesh::getVboInfo(const VertexAttribute attrib, const Vbo*& v, U32& size,
 	}
 }
 
+//==============================================================================
+// MultiMesh                                                                   =
+//==============================================================================
+
+//==============================================================================
+void MultiMesh::load(const char* filename)
+{
+	try
+	{
+		XmlDocument doc;
+		doc.loadFile(filename);
+
+		XmlElement rootEl = doc.getChildElement("multiMesh");
+		XmlElement meshesEl = rootEl.getChildElement("meshes");
+
+		XmlElement meshEl = meshesEl.getChildElement("mesh");
+
+		do
+		{
+			meshesEl = meshesEl.getNextSiblingElement("mesh");
+		} while(meshesEl);
+	}
+	catch(std::exception& e)
+	{
+		throw ANKI_EXCEPTION("MultiMesh loading failed: " + filename) << e;
+	}
+}
+
 } // end namespace anki