浏览代码

Bug fixes and minor opts

Panagiotis Christopoulos Charitos 12 年之前
父节点
当前提交
92e93cce79

+ 1 - 0
include/anki/renderer/Renderer.h

@@ -78,6 +78,7 @@ struct RendererInitializer
 			F32 sideBlurFactor = 1.0;
 			F32 sideBlurFactor = 1.0;
 		} bl;
 		} bl;
 		Bool enabled = false;
 		Bool enabled = false;
+		Bool sharpen = false;
 	} pps;
 	} pps;
 
 
 	// Dbg
 	// Dbg

+ 7 - 1
include/anki/scene/Movable.h

@@ -20,10 +20,16 @@ public:
 	enum MovableFlag
 	enum MovableFlag
 	{
 	{
 		MF_NONE = 0,
 		MF_NONE = 0,
+
 		/// Get the parent's world transform
 		/// Get the parent's world transform
 		MF_IGNORE_LOCAL_TRANSFORM = 1 << 1,
 		MF_IGNORE_LOCAL_TRANSFORM = 1 << 1,
+
+		/// Dont make assumptions with the parent. Beeng a parent doesn't mean
+		/// that it needs to contribute to this movable position in any way
+		MF_IGNORE_PARENT = 1 << 2,
+
 		/// If dirty then is marked for update
 		/// If dirty then is marked for update
-		MF_TRANSFORM_DIRTY = 1 << 2
+		MF_TRANSFORM_DIRTY = 1 << 3,
 	};
 	};
 
 
 	/// @name Constructors & destructor
 	/// @name Constructors & destructor

+ 4 - 0
include/anki/scene/SceneObject.h

@@ -6,6 +6,8 @@
 
 
 namespace anki {
 namespace anki {
 
 
+#if 0
+
 // Forward
 // Forward
 class SceneGraph;
 class SceneGraph;
 
 
@@ -45,6 +47,8 @@ public:
 	SceneGraph* scene;
 	SceneGraph* scene;
 };
 };
 
 
+#endif
+
 } // end namespace anki
 } // end namespace anki
 
 
 #endif
 #endif

+ 34 - 12
include/anki/util/Object.h

@@ -15,29 +15,47 @@ namespace anki {
 /// @addtogroup patterns
 /// @addtogroup patterns
 /// @{
 /// @{
 
 
-/// The default object deleter. It does nothing
+/// The default set of callbacks. They do nothing
 template<typename T>
 template<typename T>
-struct ObjectDeleter
+struct ObjectCallbackCollection
 {
 {
-	void operator()(T*)
+	/// Called when a child is been removed from a parent
+	void onChildRemoved(T* child, T* parent)
 	{
 	{
+		ANKI_ASSERT(child);
+		// Do nothing
+	}
+
+	/// Called when a child is been added to a parent
+	void onChildAdded(T* child, T* parent)
+	{
+		ANKI_ASSERT(child && parent);
 		// Do nothing
 		// Do nothing
 	}
 	}
 };
 };
 
 
 /// A hierarchical object
 /// A hierarchical object
 template<typename T, typename Alloc = Allocator<T>,
 template<typename T, typename Alloc = Allocator<T>,
-	typename Deleter = ObjectDeleter<T>>
+	typename TCallbackCollection = ObjectCallbackCollection<T>>
 class Object: public NonCopyable
 class Object: public NonCopyable
 {
 {
 public:
 public:
 	typedef T Value;
 	typedef T Value;
 	typedef Vector<Value*, Alloc> Container;
 	typedef Vector<Value*, Alloc> Container;
+	typedef TCallbackCollection CallbackCollection;
 
 
 	/// Calls addChild if parent is not nullptr
 	/// Calls addChild if parent is not nullptr
-	Object(Value* parent_, const Alloc& alloc = Alloc(),
-		const Deleter& del = Deleter())
-		: parent(nullptr), children(alloc), deleter(del)
+	///
+	/// @param parent_ The parent. Can be nullptr
+	/// @param alloc The allocator to use on internal allocations
+	/// @param callbacks_ A set of callbacks
+	Object(
+		Value* parent_, 
+		const Alloc& alloc = Alloc(),
+		const CallbackCollection& callbacks_ = CallbackCollection())
+		:	parent(nullptr), // Set to nullptr or prepare for assertion
+			children(alloc), 
+			callbacks(callbacks_)
 	{
 	{
 		if(parent_ != nullptr)
 		if(parent_ != nullptr)
 		{
 		{
@@ -53,14 +71,14 @@ public:
 			parent->removeChild(getSelf());
 			parent->removeChild(getSelf());
 		}
 		}
 
 
-		Alloc alloc = children.get_allocator();
-
 		// Remove all children (fast version)
 		// Remove all children (fast version)
 		for(Value* child : children)
 		for(Value* child : children)
 		{
 		{
 			child->parent = nullptr;
 			child->parent = nullptr;
 
 
-			deleter(child);
+			// Pass the parent as nullptr because at this point there is 
+			// nothing you should do with a deleteding parent
+			callbacks.onChildRemoved(child, nullptr);
 		}
 		}
 	}
 	}
 
 
@@ -115,6 +133,8 @@ public:
 
 
 		child->parent = getSelf();
 		child->parent = getSelf();
 		children.push_back(child);
 		children.push_back(child);
+
+		callbacks.onChildAdded(child, getSelf());
 	}
 	}
 
 
 	/// Remove a child
 	/// Remove a child
@@ -129,9 +149,11 @@ public:
 
 
 		children.erase(it);
 		children.erase(it);
 		child->parent = nullptr;
 		child->parent = nullptr;
+
+		callbacks.onChildRemoved(child, getSelf());
 	}
 	}
 
 
-	/// Visit
+	/// Visit this object and move to the children
 	template<typename Visitor>
 	template<typename Visitor>
 	void visitTreeDepth(Visitor& vis)
 	void visitTreeDepth(Visitor& vis)
 	{
 	{
@@ -146,7 +168,7 @@ public:
 private:
 private:
 	Value* parent; ///< May be nullptr
 	Value* parent; ///< May be nullptr
 	Container children;
 	Container children;
-	Deleter deleter;
+	CallbackCollection callbacks; /// A set of callbacks
 
 
 	/// Cast the Object to the given type
 	/// Cast the Object to the given type
 	Value* getSelf()
 	Value* getSelf()

+ 1 - 7
shaders/Final.glsl

@@ -14,12 +14,6 @@ layout(location = 0) out lowp vec3 fFragColor;
 
 
 void main()
 void main()
 {
 {
-#if 1
-	lowp vec3 col = texture(rasterImage, vTexCoords).rgb;
+	lowp vec3 col = textureLod(rasterImage, vTexCoords, 0.0).rgb;
 	fFragColor = col;
 	fFragColor = col;
-#else
-	uvec2 msAll = texture(rasterImage, vTexCoords).rg;
-	vec4 diffuseAndSpec = unpackUnorm4x8(msAll[0]);
-	fFragColor = vec3(diffuseAndSpec.rgb);
-#endif
 }
 }

+ 1 - 1
shaders/IsLp.glsl

@@ -216,7 +216,7 @@ float calcShadowFactor(in SpotTexLight light, in vec3 fragPosVspace,
 void main()
 void main()
 {
 {
 	// Read texture first. Optimize for future out of order HW
 	// Read texture first. Optimize for future out of order HW
-	uvec2 msAll = texture(msFai0, vTexCoords).rg;
+	uvec2 msAll = textureLod(msFai0, vTexCoords, 0.0).rg;
 
 
 	// get frag pos in view space
 	// get frag pos in view space
 	vec3 fragPosVspace = getFragPosVSpace();
 	vec3 fragPosVspace = getFragPosVSpace();

+ 14 - 11
shaders/Pps.glsl

@@ -7,10 +7,10 @@
 #pragma anki include "shaders/photoshop_filters.glsl"
 #pragma anki include "shaders/photoshop_filters.glsl"
 #pragma anki include "shaders/LinearDepth.glsl"
 #pragma anki include "shaders/LinearDepth.glsl"
 
 
-uniform sampler2D msDepthFai;
-uniform sampler2D isFai;
-uniform sampler2D ppsHdrFai;
-uniform sampler2D ppsSsaoFai;
+uniform highp sampler2D msDepthFai;
+uniform lowp sampler2D isFai;
+uniform lowp sampler2D ppsHdrFai;
+uniform lowp sampler2D ppsSsaoFai;
 
 
 in vec2 vTexCoords;
 in vec2 vTexCoords;
 
 
@@ -61,12 +61,12 @@ vec3 sharpen(in sampler2D tex, in vec2 texCoords)
 {
 {
 	const float sharpenFactor = 0.25;
 	const float sharpenFactor = 0.25;
 
 
-	vec3 col = texture(tex, texCoords).rgb;
+	vec3 col = textureLod(tex, texCoords, 0.0).rgb;
 
 
-	vec3 col2 = texture(tex, texCoords + KERNEL[0]).rgb;
+	vec3 col2 = textureLod(tex, texCoords + KERNEL[0], 0.0).rgb;
 	for(int i = 1; i < 8; i++)
 	for(int i = 1; i < 8; i++)
 	{
 	{
-		col2 += texture(tex, texCoords + KERNEL[i]).rgb;
+		col2 += textureLod(tex, texCoords + KERNEL[i], 0.0).rgb;
 	}
 	}
 
 
 	return col * (9.0 * sharpenFactor + 1.0 - sharpenFactor) 
 	return col * (9.0 * sharpenFactor + 1.0 - sharpenFactor) 
@@ -80,7 +80,7 @@ vec3 erosion(in sampler2D tex, in vec2 texCoords)
 
 
     for (int i = 0; i < 8; i++)
     for (int i = 0; i < 8; i++)
     {
     {
-        vec3 tmpCol = texture(tex, texCoords + KERNEL[i]).rgb;
+        vec3 tmpCol = textureLod(tex, texCoords + KERNEL[i], 0.0).rgb;
         minValue = min(tmpCol, minValue);
         minValue = min(tmpCol, minValue);
     }
     }
 
 
@@ -90,17 +90,20 @@ vec3 erosion(in sampler2D tex, in vec2 texCoords)
 //==============================================================================
 //==============================================================================
 void main(void)
 void main(void)
 {
 {
+#if SHARPEN_ENABLED
 	fColor = sharpen(isFai, vTexCoords);
 	fColor = sharpen(isFai, vTexCoords);
+#else
+	fColor = textureLod(isFai, vTexCoords, 0.0).rgb;
+#endif
 	//fColor = erosion(isFai, vTexCoords);
 	//fColor = erosion(isFai, vTexCoords);
-	//fColor = texture(isFai, vTexCoords).rgb;
 
 
 #if defined(HDR_ENABLED)
 #if defined(HDR_ENABLED)
-	vec3 hdr = texture(ppsHdrFai, vTexCoords).rgb;
+	vec3 hdr = textureLod(ppsHdrFai, vTexCoords, 0.0).rgb;
 	fColor += hdr;
 	fColor += hdr;
 #endif
 #endif
 
 
 #if defined(SSAO_ENABLED)
 #if defined(SSAO_ENABLED)
-	float ssao = texture(ppsSsaoFai, vTexCoords).r;
+	float ssao = textureLod(ppsSsaoFai, vTexCoords, 0.0).r;
 	fColor *= ssao;
 	fColor *= ssao;
 #endif
 #endif
 
 

+ 5 - 0
src/renderer/Pps.cpp

@@ -47,6 +47,11 @@ void Pps::initInternal(const RendererInitializer& initializer)
 		pps += "#define HDR_ENABLED\n";
 		pps += "#define HDR_ENABLED\n";
 	}
 	}
 
 
+	if(initializer.pps.sharpen)
+	{
+		pps += "#define SHARPEN_ENABLED\n";
+	}
+
 	pps += "#define FBO_WIDTH " + std::to_string(r->getWidth()) + "\n";
 	pps += "#define FBO_WIDTH " + std::to_string(r->getWidth()) + "\n";
 	pps += "#define FBO_HEIGHT " + std::to_string(r->getHeight()) + "\n";
 	pps += "#define FBO_HEIGHT " + std::to_string(r->getHeight()) + "\n";
 
 

+ 1 - 5
src/scene/ModelNode.cpp

@@ -92,7 +92,7 @@ ModelPatchNode::ModelPatchNode(
 		{
 		{
 			ModelPatchNodeInstance* instance = ANKI_NEW(
 			ModelPatchNodeInstance* instance = ANKI_NEW(
 				ModelPatchNodeInstance, getSceneAllocator(), 
 				ModelPatchNodeInstance, getSceneAllocator(), 
-				nullptr, scene, this, Movable::MF_NONE,
+				nullptr, scene, this, Movable::MF_IGNORE_PARENT,
 				modelPatch);
 				modelPatch);
 
 
 			instance->setLocalOrigin(pos);
 			instance->setLocalOrigin(pos);
@@ -193,10 +193,6 @@ ModelNode::ModelNode(
 {
 {
 	sceneNodeProtected.movable = this;
 	sceneNodeProtected.movable = this;
 
 
-	{
-		SceneVector<int> lala(getSceneAllocator());
-	}
-
 	model.load(modelFname);
 	model.load(modelFname);
 
 
 	patches.reserve(model->getModelPatches().size());
 	patches.reserve(model->getModelPatches().size());

+ 6 - 5
src/scene/Movable.cpp

@@ -35,16 +35,17 @@ void Movable::update()
 void Movable::updateWorldTransform()
 void Movable::updateWorldTransform()
 {
 {
 	prevWTrf = wTrf;
 	prevWTrf = wTrf;
-	const Movable* parent = 
-		node->getParent() 
-		? node->getParent()->getMovable() 
-		: nullptr;
 	const Bool dirty = bitsEnabled(MF_TRANSFORM_DIRTY);
 	const Bool dirty = bitsEnabled(MF_TRANSFORM_DIRTY);
 
 
 	// If dirty then update world transform
 	// If dirty then update world transform
 	if(dirty)
 	if(dirty)
 	{
 	{
-		if(parent)
+		const Movable* parent = 
+			node->getParent() 
+			? node->getParent()->getMovable() 
+			: nullptr;
+
+		if(parent && !bitsEnabled(MF_IGNORE_PARENT))
 		{
 		{
 			if(bitsEnabled(MF_IGNORE_LOCAL_TRANSFORM))
 			if(bitsEnabled(MF_IGNORE_LOCAL_TRANSFORM))
 			{
 			{

+ 2 - 0
src/scene/SceneGraph.cpp

@@ -269,6 +269,8 @@ void SceneGraph::load(const char* filename)
 				if(i == 0)
 				if(i == 0)
 				{
 				{
 					node->setLocalTransform(Transform(el.getMat4()));
 					node->setLocalTransform(Transform(el.getMat4()));
+					node->setInstanceLocalTransform(
+						i, Transform(el.getMat4()));
 				}
 				}
 				else
 				else
 				{
 				{

+ 4 - 0
src/scene/SceneObject.cpp

@@ -3,6 +3,8 @@
 
 
 namespace anki {
 namespace anki {
 
 
+#if 0
+
 //==============================================================================
 //==============================================================================
 SceneObject::SceneObject(SceneObject* parent, SceneGraph* scene_)
 SceneObject::SceneObject(SceneObject* parent, SceneGraph* scene_)
 	: Base(parent, scene_->getAllocator()), scene(scene_)
 	: Base(parent, scene_->getAllocator()), scene(scene_)
@@ -22,4 +24,6 @@ SceneAllocator<U8> SceneObject::getSceneFrameAllocator() const
 	return scene->getFrameAllocator();
 	return scene->getFrameAllocator();
 }
 }
 
 
+#endif
+
 } // end namespace anki
 } // end namespace anki

+ 2 - 1
tools/2anki/Main.cpp

@@ -162,7 +162,7 @@ static const aiScene& load(
 	LOGI("Loading file %s\n", filename.c_str());
 	LOGI("Loading file %s\n", filename.c_str());
 
 
 	const aiScene* scene = importer.ReadFile(filename, 0
 	const aiScene* scene = importer.ReadFile(filename, 0
-		| aiProcess_FindInstances
+		//| aiProcess_FindInstances
 		| aiProcess_Triangulate
 		| aiProcess_Triangulate
 		| aiProcess_JoinIdenticalVertices
 		| aiProcess_JoinIdenticalVertices
 		//| aiProcess_SortByPType
 		//| aiProcess_SortByPType
@@ -854,6 +854,7 @@ static void exportScene(const aiScene& scene, Config& config)
 			file << "\t\t<transform>";
 			file << "\t\t<transform>";
 
 
 			aiMatrix4x4 trf = mesh.transforms[j];
 			aiMatrix4x4 trf = mesh.transforms[j];
+
 			for(uint32_t a = 0; a < 4; a++)
 			for(uint32_t a = 0; a < 4; a++)
 			{
 			{
 				for(uint32_t b = 0; b < 4; b++)
 				for(uint32_t b = 0; b < 4; b++)