Browse Source

Minor refactoring

Panagiotis Christopoulos Charitos 12 years ago
parent
commit
01a6c4f1a4

+ 3 - 3
include/anki/renderer/Drawer.h

@@ -2,11 +2,11 @@
 #define ANKI_RENDERER_DRAWER_H
 
 #include "anki/util/StdTypes.h"
-#include "anki/resource/PassLevelKey.h"
+#include "anki/resource/PassLodKey.h"
 
 namespace anki {
 
-class PassLevelKey;
+class PassLodKey;
 class Renderer;
 class FrustumComponent;
 class SceneNode;
@@ -43,7 +43,7 @@ private:
 	Renderer* r;
 
 	void setupShaderProg(
-		const PassLevelKey& key,
+		const PassLodKey& key,
 		const FrustumComponent& fr,
 		const ShaderProgram& prog,
 		RenderComponent& renderable,

+ 4 - 4
include/anki/resource/Material.h

@@ -3,7 +3,7 @@
 
 #include "anki/resource/Resource.h"
 #include "anki/resource/ShaderProgramResource.h"
-#include "anki/resource/PassLevelKey.h"
+#include "anki/resource/PassLodKey.h"
 #include "anki/Math.h"
 #include "anki/util/Visitor.h"
 #include "anki/util/Dictionary.h"
@@ -77,7 +77,7 @@ public:
 	/// Given a key return the uniform. If the uniform is not present in the
 	/// LOD pass key then returns nullptr
 	const ShaderProgramUniformVariable* findShaderProgramUniformVariable(
-		const PassLevelKey& key) const
+		const PassLodKey& key) const
 	{
 		return progVars[key.pass][key.level];
 	}
@@ -325,13 +325,13 @@ public:
 	}
 	/// @}
 
-	const ShaderProgram& findShaderProgram(const PassLevelKey& key) const
+	const ShaderProgram& findShaderProgram(const PassLodKey& key) const
 	{
 		ANKI_ASSERT(progs[key.pass][key.level].isLoaded());
 		return *progs[key.pass][key.level];
 	}
 
-	const ShaderProgram* tryFindShaderProgram(const PassLevelKey& key) const
+	const ShaderProgram* tryFindShaderProgram(const PassLodKey& key) const
 	{
 		if(progs[key.pass][key.level].isLoaded())
 		{

+ 7 - 7
include/anki/resource/Model.h

@@ -4,7 +4,7 @@
 #include "anki/resource/Resource.h"
 #include "anki/gl/Vao.h"
 #include "anki/collision/Obb.h"
-#include "anki/resource/PassLevelKey.h"
+#include "anki/resource/PassLodKey.h"
 #include "anki/resource/Mesh.h"
 #include "anki/resource/Material.h"
 #include "anki/resource/Skeleton.h"
@@ -30,7 +30,7 @@ public:
 		return *modelPatchProtected.mtl;
 	}
 
-	const Mesh& getMesh(const PassLevelKey& key) const
+	const Mesh& getMesh(const PassLodKey& key) const
 	{
 		ANKI_ASSERT(key.level < modelPatchProtected.meshes.size());
 		return *modelPatchProtected.meshes[key.level];
@@ -43,31 +43,31 @@ public:
 
 	const Obb& getBoundingShape() const
 	{
-		PassLevelKey key(COLOR_PASS, 0);
+		PassLodKey key(COLOR_PASS, 0);
 		return getMesh(key).getBoundingShape();
 	}
 
 	const Obb& getBoundingShapeSub(U32 subMeshId) const
 	{
-		PassLevelKey key(COLOR_PASS, 0);
+		PassLodKey key(COLOR_PASS, 0);
 		return getMesh(key).getBoundingShapeSub(subMeshId);
 	}
 
 	U32 getSubMeshesCount() const
 	{
-		PassLevelKey key(COLOR_PASS, 0);
+		PassLodKey key(COLOR_PASS, 0);
 		return getMesh(key).getSubMeshesCount();
 	}
 
 	/// Given a pass lod key retrieve variables useful for rendering
-	void getRenderingData(const PassLevelKey& key, const Vao*& vao,
+	void getRenderingData(const PassLodKey& key, const Vao*& vao,
 		const ShaderProgram*& prog, U32& indicesCount) const;
 
 	/// Get information for multiDraw rendering.
 	/// Given an array of submeshes that are visible return the correct indices
 	/// offsets and counts
 	void getRenderingDataSub(
-		const PassLevelKey& key, 
+		const PassLodKey& key, 
 		const Vao*& vao, 
 		const ShaderProgram*& prog,
 		const U32* subMeshIndicesArray, U subMeshIndicesCount,

+ 4 - 4
include/anki/resource/PassLevelKey.h → include/anki/resource/PassLodKey.h

@@ -20,24 +20,24 @@ enum Pass
 const U MAX_LOD = 3;
 
 /// A key that consistst of the rendering pass and the level of detail
-struct PassLevelKey
+struct PassLodKey
 {
 	U8 pass;
 	U8 level;
 
-	PassLevelKey()
+	PassLodKey()
 		: pass(COLOR_PASS), level(0)
 	{
 		ANKI_ASSERT(level <= MAX_LOD);
 	}
 
-	PassLevelKey(const PassLevelKey& b)
+	PassLodKey(const PassLodKey& b)
 		: pass(b.pass), level(b.level)
 	{
 		ANKI_ASSERT(level <= MAX_LOD);
 	}
 
-	explicit PassLevelKey(const U8 pass_, const U8 level_)
+	explicit PassLodKey(const U8 pass_, const U8 level_)
 		: pass(pass_), level(level_)
 	{
 		ANKI_ASSERT(level <= MAX_LOD);

+ 12 - 1
include/anki/resource/ShaderProgramPrePreprocessor.h

@@ -68,7 +68,14 @@ public:
 
 	const std::string& getShaderSource(ShaderType type)
 	{
-		return shaderSources[type];
+		if((type == ST_TC || type == ST_TE) && !enableTess)
+		{
+			return emptyString;
+		}
+		else
+		{
+			return shaderSources[type];
+		}
 	}
 
 	XfbBufferMode getXfbBufferMode() const
@@ -101,6 +108,10 @@ protected:
 	StringList sourceLines;
 	Array<CodeBeginningPragma, ST_NUM> shaderStarts;
 
+	Bool enableTess = true;
+
+	std::string emptyString;
+
 	/// Parse a PrePreprocessor formated GLSL file. Use the accessors to get 
 	/// the output
 	///

+ 1 - 1
include/anki/scene/ModelNode.h

@@ -73,7 +73,7 @@ public:
 
 	/// Implements RenderComponent::getRenderingData
 	void getRenderingData(
-		const PassLevelKey& key, 
+		const PassLodKey& key, 
 		const Vao*& vao, const ShaderProgram*& prog,
 		const U32* subMeshIndicesArray, U subMeshIndicesCount,
 		Array<U32, ANKI_MAX_MULTIDRAW_PRIMITIVES>& indicesCountArray,

+ 1 - 1
include/anki/scene/ParticleEmitter.h

@@ -162,7 +162,7 @@ public:
 
 	/// Implements RenderComponent::getRenderingData
 	void getRenderingData(
-		const PassLevelKey& key, 
+		const PassLodKey& key, 
 		const Vao*& vao, const ShaderProgram*& prog,
 		const U32* subMeshIndicesArray, U subMeshIndicesCount,
 		Array<U32, ANKI_MAX_MULTIDRAW_PRIMITIVES>& indicesCountArray,

+ 2 - 2
include/anki/scene/RenderComponent.h

@@ -95,7 +95,7 @@ public:
 	/// @}
 
 	const ShaderProgramUniformVariable* tryFindShaderProgramUniformVariable(
-		const PassLevelKey key) const
+		const PassLodKey key) const
 	{
 		return mvar->findShaderProgramUniformVariable(key);
 	}
@@ -173,7 +173,7 @@ public:
 	/// Given an array of submeshes that are visible return the correct indices
 	/// offsets and counts
 	virtual void getRenderingData(
-		const PassLevelKey& key, 
+		const PassLodKey& key, 
 		const Vao*& vao, const ShaderProgram*& prog,
 		const U32* subMeshIndicesArray, U subMeshIndicesCount,
 		Array<U32, ANKI_MAX_MULTIDRAW_PRIMITIVES>& indicesCountArray,

+ 4 - 4
include/anki/scene/SkinNode.h

@@ -92,16 +92,16 @@ public:
 
 	/// @name Accessors
 	/// @{
-	SkinMesh& getSkinMesh(const PassLevelKey& key)
+	SkinMesh& getSkinMesh(const PassLodKey& key)
 	{
 		return *skinMeshes[key.level];
 	}
-	const SkinMesh& getSkinMesh(const PassLevelKey& key) const
+	const SkinMesh& getSkinMesh(const PassLodKey& key) const
 	{
 		return *skinMeshes[key.level];
 	}
 
-	const Vao& getTransformFeedbackVao(const PassLevelKey& key) const
+	const Vao& getTransformFeedbackVao(const PassLodKey& key) const
 	{
 		return xfbVaos[key.level];
 	}
@@ -109,7 +109,7 @@ public:
 
 	/// @name Implementations of ModelPatchBase virtuals
 	/// @{
-	const MeshBase& getMeshBase(const PassLevelKey& key) const
+	const MeshBase& getMeshBase(const PassLodKey& key) const
 	{
 		return *skinMeshes[key.level];
 	}

+ 1 - 1
include/anki/scene/StaticGeometryNode.h

@@ -42,7 +42,7 @@ public:
 
 	/// Implements RenderComponent::getRenderingData
 	void getRenderingData(
-		const PassLevelKey& key, 
+		const PassLodKey& key, 
 		const Vao*& vao, const ShaderProgram*& prog,
 		const U32* subMeshIndicesArray, U subMeshIndicesCount,
 		Array<U32, ANKI_MAX_MULTIDRAW_PRIMITIVES>& indicesCountArray,

+ 4 - 0
shaders/MsCommonFrag.glsl

@@ -1,6 +1,10 @@
 #define DEFAULT_FLOAT_PRECISION highp
 #pragma anki include "shaders/Common.glsl"
 
+#if !GL_ES && __VERSION__ > 400
+layout(early_fragment_tests) in;
+#endif
+
 #pragma anki include "shaders/Pack.glsl"
 #pragma anki include "shaders/MsBsCommon.glsl"
 

+ 2 - 2
src/renderer/Deformer.cpp

@@ -32,8 +32,8 @@ void Deformer::deform(SkinNode& skinNode, SkinPatchNode& node) const
 	//
 	const ShaderProgram* sProg;
 
-	/*if(mtl.variableExistsAndInKey("normal", PassLevelKey(0, 0))
-		&& mtl.variableExistsAndInKey("tangent", PassLevelKey(0, 0)))
+	/*if(mtl.variableExistsAndInKey("normal", PassLodKey(0, 0))
+		&& mtl.variableExistsAndInKey("tangent", PassLodKey(0, 0)))
 	{*/
 		sProg = tfHwSkinningAllSProg.get();
 	/*}

+ 3 - 3
src/renderer/Drawer.cpp

@@ -260,7 +260,7 @@ void SetupRenderableVariableVisitor::uniSet<TextureResourcePointer>(
 }
 
 //==============================================================================
-void RenderableDrawer::setupShaderProg(const PassLevelKey& key_,
+void RenderableDrawer::setupShaderProg(const PassLodKey& key_,
 	const FrustumComponent& fr, const ShaderProgram &prog,
 	RenderComponent& renderable, 
 	U32* subSpatialIndices, U subSpatialIndicesCount,
@@ -277,7 +277,7 @@ void RenderableDrawer::setupShaderProg(const PassLevelKey& key_,
 	vis.subSpatialIndicesCount = subSpatialIndicesCount;
 	vis.flod = flod;
 
-	PassLevelKey key(key_.pass,
+	PassLodKey key(key_.pass,
 		std::min(key_.level,
 		U8(renderable.getMaterial().getLevelsOfDetail() - 1)));
 
@@ -366,7 +366,7 @@ void RenderableDrawer::render(SceneNode& frsn, RenderingStage stage,
 		(rsn.getSpatialComponent()->getSpatialOrigin() - camPos).getLength();
 	F32 lod = r->calculateLod(dist);
 
-	PassLevelKey key(pass, lod);
+	PassLodKey key(pass, lod);
 
 	// Get rendering useful stuff
 	const ShaderProgram* prog;

+ 10 - 10
src/resource/Model.cpp

@@ -72,7 +72,7 @@ void ModelPatchBase::createVao(const ShaderProgram& prog,
 }
 
 //==============================================================================
-void ModelPatchBase::getRenderingData(const PassLevelKey& key, const Vao*& vao,
+void ModelPatchBase::getRenderingData(const PassLodKey& key, const Vao*& vao,
 	const ShaderProgram*& prog, U32& indicesCount) const
 {
 	const U meshLods = getMeshesCount();
@@ -89,7 +89,7 @@ void ModelPatchBase::getRenderingData(const PassLevelKey& key, const Vao*& vao,
 	vao = &modelPatchProtected.vaos[index];
 
 	// Mesh and indices
-	PassLevelKey meshKey;
+	PassLodKey meshKey;
 	meshKey.pass = key.pass;
 	meshKey.level = std::min(key.level, (U8)(meshLods - 1));
 
@@ -97,7 +97,7 @@ void ModelPatchBase::getRenderingData(const PassLevelKey& key, const Vao*& vao,
 	indicesCount = mesh.getIndicesCount();
 
 	// Prog
-	PassLevelKey mtlKey;
+	PassLodKey mtlKey;
 	mtlKey.pass = key.pass;
 	mtlKey.level = std::min(key.level, (U8)(mtlLods - 1));
 
@@ -105,7 +105,7 @@ void ModelPatchBase::getRenderingData(const PassLevelKey& key, const Vao*& vao,
 }
 
 //==============================================================================
-void ModelPatchBase::getRenderingDataSub(const PassLevelKey& key,
+void ModelPatchBase::getRenderingDataSub(const PassLodKey& key,
 	const Vao*& vao, const ShaderProgram*& prog, 
 	const U32* subMeshIndexArray, U subMeshIndexCount,
 	Array<U32, ANKI_MAX_MULTIDRAW_PRIMITIVES>& indicesCountArray,
@@ -126,14 +126,14 @@ void ModelPatchBase::getRenderingDataSub(const PassLevelKey& key,
 	vao = &modelPatchProtected.vaos[vaoindex];
 
 	// Prog
-	PassLevelKey mtlKey;
+	PassLodKey mtlKey;
 	mtlKey.pass = key.pass;
 	mtlKey.level = std::min(key.level, (U8)(mtlLods - 1));
 
 	prog = &getMaterial().findShaderProgram(mtlKey);
 
 	// Mesh and indices
-	PassLevelKey meshKey;
+	PassLodKey meshKey;
 	meshKey.pass = key.pass;
 	meshKey.level = std::min(key.level, (U8)(meshLods - 1));
 
@@ -198,19 +198,19 @@ void ModelPatchBase::create()
 	{
 		for(U pass = 0; pass < mtl.getPassesCount(); ++pass)
 		{
-			PassLevelKey key(pass, lod);
+			PassLodKey key(pass, lod);
 			const ShaderProgram* prog;
 			const Mesh* mesh;
 
 			// Get mesh
 			ANKI_ASSERT(getMeshesCount() > 0);
-			PassLevelKey meshKey = key;
+			PassLodKey meshKey = key;
 			meshKey.level = std::min(key.level, (U8)(getMeshesCount() - 1));
 			mesh = &getMesh(meshKey);
 
 			// Get shader prog
 			ANKI_ASSERT(getMaterial().getLevelsOfDetail() > 0);
-			PassLevelKey shaderKey = key;
+			PassLodKey shaderKey = key;
 			shaderKey.level = std::min(key.level,
 				(U8)(getMaterial().getLevelsOfDetail() - 1));
 			prog = getMaterial().tryFindShaderProgram(shaderKey);
@@ -329,7 +329,7 @@ void Model::load(const char* filename)
 		}
 
 		// Calculate compound bounding volume
-		PassLevelKey key;
+		PassLodKey key;
 		key.level = 0;
 		visibilityShape = modelPatches[0]->getMesh(key).getBoundingShape();
 

+ 7 - 2
src/resource/ShaderProgramPrePreprocessor.cpp

@@ -13,7 +13,7 @@ namespace anki {
 
 // Keep the strings in that order so that the start pragmas will match to the
 // ShaderType enums
-static Array<const char*, 9> commands = {{
+static Array<const char*, 10> commands = {{
 	"#pragma anki start vertexShader",
 	"#pragma anki start tcShader",
 	"#pragma anki start teShader",
@@ -22,7 +22,8 @@ static Array<const char*, 9> commands = {{
 	"#pragma anki start computeShader",
 	"#pragma anki include",
 	"#pragma anki transformFeedbackVaryings separate",
-	"#pragma anki transformFeedbackVaryings interleaved"}};
+	"#pragma anki transformFeedbackVaryings interleaved"
+	"#pragma anki disable tess"}};
 
 static_assert(ST_VERTEX == 0 && ST_COMPUTE == 5, "See file");
 
@@ -116,6 +117,10 @@ void ShaderProgramPrePreprocessor::parseFileForPragmas(
 			trffbVaryings = StringList::splitString(slist.c_str(), ' ');
 			xfbBufferMode = XFBBM_INTERLEAVED;
 		}
+		else if((npos = line.find(commands[9])) == 0)
+		{
+			enableTess = false;	
+		}
 		else
 		{
 			gotPragmaAnki = false;

+ 2 - 2
src/resource/Skin.cpp

@@ -3,7 +3,7 @@
 #include "anki/resource/Skeleton.h"
 #include "anki/resource/SkelAnim.h"
 #include "anki/resource/Mesh.h"
-#include "anki/resource/PassLevelKey.h"
+#include "anki/resource/PassLodKey.h"
 #include "anki/resource/Model.h"
 #include "anki/resource/Material.h"
 #include "anki/misc/Xml.h"
@@ -73,7 +73,7 @@ void Skin::load(const char* filename)
 		{
 			for(U i = 0; i < patch->getMeshesCount(); i++)
 			{
-				PassLevelKey key;
+				PassLodKey key;
 				key.level = i;
 				const Mesh& meshBase = patch->getMesh(key);
 				if(!meshBase.hasWeights())

+ 1 - 1
src/scene/ParticleEmitter.cpp

@@ -271,7 +271,7 @@ ParticleEmitter::~ParticleEmitter()
 
 //==============================================================================
 void ParticleEmitter::getRenderingData(
-	const PassLevelKey& key, 
+	const PassLodKey& key, 
 	const Vao*& vao, const ShaderProgram*& prog,
 	const U32* subMeshIndicesArray, U subMeshIndicesCount,
 	Array<U32, ANKI_MAX_MULTIDRAW_PRIMITIVES>& indicesCountArray,

+ 2 - 2
src/scene/SkinNode.cpp

@@ -71,7 +71,7 @@ SkinModelPatch::SkinModelPatch(const ModelPatchBase* mpatch_,
 	skinMeshes.resize(mpatch->getMeshesCount());
 	for(U i = 0; i < mpatch->getMeshesCount(); i++)
 	{
-		PassLevelKey key;
+		PassLodKey key;
 		key.level = i;
 		skinMeshes[i].reset(new SkinMesh(&mpatch->getMeshBase(key)));
 	}
@@ -99,7 +99,7 @@ SkinModelPatch::SkinModelPatch(const ModelPatchBase* mpatch_,
 		U i = 0;
 		for(auto a : attribs)
 		{
-			PassLevelKey key;
+			PassLodKey key;
 			key.level = i;
 
 			mpatch->getMeshBase(key).getVboInfo(