Browse Source

Removing exceptions

Panagiotis Christopoulos Charitos 11 years ago
parent
commit
bebe8427d8

+ 5 - 11
include/anki/resource/Material.h

@@ -320,7 +320,7 @@ public:
 	}
 
 	// Variable accessors
-	const ResourceVector<MaterialVariable*>& getVariables() const
+	const ResourceDArray<MaterialVariable*>& getVariables() const
 	{
 		return m_vars;
 	}
@@ -330,14 +330,8 @@ public:
 		return m_shaderBlockSize;
 	}
 
-	GlProgramPipelineHandle getProgramPipeline(const RenderingKey& key);
-
-	/// Get by name
-	const MaterialVariable* findVariableByName(const CString& name) const
-	{
-		auto it = m_varDict.find(name);
-		return (it == m_varDict.end()) ? nullptr : it->second;
-	}
+	ANKI_USE_RESULT Error getProgramPipeline(
+		const RenderingKey& key, GlProgramPipelineHandle& out);
 
 	/// Load a material file
 	ANKI_USE_RESULT Error load(
@@ -353,10 +347,10 @@ private:
 	/// Keep it to have access to some stuff at runtime
 	ResourceManager* m_resources = nullptr; 
 		
-	ResourceVector<MaterialVariable*> m_vars;
+	ResourceDArray<MaterialVariable*> m_vars;
 	Dictionary<MaterialVariable*> m_varDict;
 
-	ResourceVector<ProgramResourcePointer> m_progs;
+	ResourceDArray<ProgramResourcePointer> m_progs;
 	ResourceVector<GlProgramPipelineHandle> m_pplines;
 
 	U32 m_shaderBlockSize;

+ 3 - 2
include/anki/util/DArray.h

@@ -121,7 +121,8 @@ public:
 	}
 
 	/// Create the array.
-	ANKI_USE_RESULT Error create(Allocator alloc, PtrSize size)
+	template<typename... TArgs>
+	ANKI_USE_RESULT Error create(Allocator alloc, PtrSize size, TArgs... args)
 	{
 		ANKI_ASSERT(m_data == nullptr && m_size == 0);
 		ANKI_ASSERT(size);
@@ -129,7 +130,7 @@ public:
 
 		destroy(alloc);
 
-		m_data = alloc.template newArray<Value>(size);
+		m_data = alloc.template newArray<Value>(size, args...);
 		if(m_data)
 		{
 			m_size = size;

+ 35 - 13
src/resource/Material.cpp

@@ -137,22 +137,24 @@ U32 MaterialVariable::getArraySize() const
 
 //==============================================================================
 Material::Material(ResourceAllocator<U8>& alloc)
-:	m_vars(alloc),
-	m_varDict(10, Dictionary<MaterialVariable*>::hasher(),
+:	m_varDict(10, Dictionary<MaterialVariable*>::hasher(),
 		Dictionary<MaterialVariable*>::key_equal(), alloc),
-	m_progs(alloc),
 	m_pplines(alloc)
 {}
 
 //==============================================================================
 Material::~Material()
 {
-	auto alloc = m_vars.get_allocator();
+	auto alloc = m_resources->_getAllocator();
+
+	m_progs.destroy(alloc);
 
 	for(auto it : m_vars)
 	{
 		alloc.deleteInstance(it);
 	}
+
+	m_vars.destroy(alloc);
 }
 
 //==============================================================================
@@ -271,12 +273,14 @@ ProgramResourcePointer& Material::getProgram(
 }
 
 //==============================================================================
-GlProgramPipelineHandle Material::getProgramPipeline(
-	const RenderingKey& key)
+Error Material::getProgramPipeline(
+	const RenderingKey& key, GlProgramPipelineHandle& out)
 {
 	ANKI_ASSERT(enumToType(key.m_pass) < m_passesCount);
 	ANKI_ASSERT(key.m_lod < m_lodsCount);
 
+	Error err = ErrorCode::NONE;
+
 	U tessCount = 1;
 	if(m_tessellation)
 	{
@@ -314,14 +318,16 @@ GlProgramPipelineHandle Material::getProgramPipeline(
 
 		GlDevice& gl = m_resources->_getGlDevice();
 		GlCommandBufferHandle cmdBuff;
-		cmdBuff.create(&gl);
+		ANKI_CHECK(cmdBuff.create(&gl));
 
-		ppline.create(cmdBuff, &progs[0], &progs[0] + progCount);
+		ANKI_CHECK(ppline.create(cmdBuff, &progs[0], &progs[0] + progCount));
 
 		cmdBuff.flush();
 	}
 
-	return ppline;
+	out = ppline;
+
+	return err;
 }
 
 //==============================================================================
@@ -337,6 +343,8 @@ Error Material::load(const CString& filename, ResourceInitializer& init)
 	XmlElement el;
 	ANKI_CHECK(doc.getChildElement("material", el));
 	ANKI_CHECK(parseMaterialTag(el , init));
+
+	return err;
 }
 
 //==============================================================================
@@ -433,12 +441,12 @@ Error Material::parseMaterialTag(const XmlElement& materialEl,
 	U tessCount = m_tessellation ? 2 : 1;
 
 	// Alloc program vector
-	m_progs.resize(
+	ANKI_CHECK(m_progs.create(rinit.m_alloc,
 		countShaders(ShaderType::VERTEX) 
 		+ countShaders(ShaderType::TESSELLATION_CONTROL)
 		+ countShaders(ShaderType::TESSELLATION_EVALUATION)
 		+ countShaders(ShaderType::GEOMETRY)
-		+ countShaders(ShaderType::FRAGMENT));
+		+ countShaders(ShaderType::FRAGMENT)));
 
 	// Aloc progam descriptors
 	m_pplines.resize(m_passesCount * m_lodsCount * tessCount);
@@ -512,7 +520,7 @@ Error Material::parseMaterialTag(const XmlElement& materialEl,
 	ANKI_CHECK(populateVariables(loader));
 
 	// Get uniform block size
-	ANKI_ASSERT(m_progs.size() > 0);
+	ANKI_ASSERT(m_progs.getSize() > 0);
 
 	auto blk = m_progs[0]->getGlProgram().tryFindBlock("bDefaultBlock");
 	if(blk == nullptr)
@@ -561,6 +569,20 @@ Error Material::createProgramSourceToCache(
 //==============================================================================
 Error Material::populateVariables(const MaterialProgramCreator& loader)
 {
+	Error err = ErrorCode::NONE;
+
+	U varCount = 0;
+	for(auto in : loader.getInputVariables())
+	{
+		if(!in.m_constant)
+		{
+			++varCount;
+		}
+	}
+
+	ANKI_CHECK(m_vars.create(m_resources->_getAllocator(), varCount));
+
+	varCount = 0;
 	for(auto in : loader.getInputVariables())
 	{
 		if(in.m_constant)
@@ -652,7 +674,7 @@ Error Material::populateVariables(const MaterialProgramCreator& loader)
 			return ErrorCode::USER_DATA;
 		}
 
-		m_vars.push_back(mtlvar);
+		m_vars[varCount++] = mtlvar;
 	}
 
 	return ErrorCode::NONE;

+ 3 - 3
src/resource/Model.cpp

@@ -107,7 +107,7 @@ void ModelPatchBase::getRenderingDataSub(
 	mtlKey.m_lod = 
 		std::min(key.m_lod, (U8)(getMaterial().getLevelsOfDetail() - 1));
 
-	ppline = m_mtl->getProgramPipeline(mtlKey);
+	m_mtl->getProgramPipeline(mtlKey, ppline);
 
 	// Mesh and indices
 	RenderingKey meshKey = key;
@@ -188,8 +188,8 @@ void ModelPatchBase::create(GlDevice* gl)
 			shaderKey.m_lod = std::min(key.m_lod, 
 				(U8)(getMaterial().getLevelsOfDetail() - 1));
 
-			GlProgramPipelineHandle ppline =
-				m_mtl->getProgramPipeline(shaderKey);
+			GlProgramPipelineHandle ppline;
+			m_mtl->getProgramPipeline(shaderKey, ppline);
 			prog = ppline.getAttachedProgram(GL_VERTEX_SHADER);
 			
 			// Create vert descriptor

+ 2 - 2
src/scene/ParticleEmitter.cpp

@@ -284,8 +284,8 @@ void ParticleEmitter::buildRendering(RenderingBuildData& data)
 	RenderingKey key = data.m_key;
 	key.m_lod = 0;
 
-	GlProgramPipelineHandle ppline = 
-		m_particleEmitterResource->getMaterial().getProgramPipeline(key);
+	GlProgramPipelineHandle ppline;
+	m_particleEmitterResource->getMaterial().getProgramPipeline(key, ppline);
 
 	ppline.bind(data.m_jobs);
 

+ 1 - 1
src/scene/RenderComponent.cpp

@@ -114,7 +114,7 @@ void RenderComponent::init()
 	CreateNewRenderComponentVariableVisitor vis;
 	vis.m_vars = &m_vars;
 
-	m_vars.reserve(mtl.getVariables().size());
+	m_vars.reserve(mtl.getVariables().getSize());
 
 	for(const MaterialVariable* mv : mtl.getVariables())
 	{