Browse Source

Bug fixes

Panagiotis Christopoulos Charitos 11 years ago
parent
commit
2cca83b827

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

@@ -28,6 +28,7 @@ private:
 	// 1st pass
 	ProgramResourcePointer m_reflectionFrag;
 	GlProgramPipelineHandle m_reflectionPpline;
+	GlSamplerHandle m_depthMapSampler;
 
 	// 2nd pass: blit
 	ProgramResourcePointer m_blitFrag;

+ 2 - 2
shaders/BsCommonFrag.glsl

@@ -53,7 +53,7 @@ void particleSoftTextureAlpha(in sampler2D depthMap, in sampler2D tex,
 	float depth = texture(depthMap, gl_FragCoord.xy * screenSize).r;
 
 	float delta = depth - gl_FragCoord.z;
-	float softalpha = clamp(delta * 100.0, 0.0, 1.0);
+	float softalpha = clamp(delta * 50.0, 0.0, 1.0);
 
 	vec4 color = texture(tex, gl_PointCoord);
 	color.a *= alpha * softalpha;
@@ -71,7 +71,7 @@ void particleSoftColorAlpha(in sampler2D depthMap, in vec3 icolor,
 	float depth = texture(depthMap, gl_FragCoord.xy * screenSize).r;
 
 	float delta = depth - gl_FragCoord.z;
-	float softalpha = clamp(delta * 100.0, 0.0, 1.0);
+	float softalpha = clamp(delta * 50.0, 0.0, 1.0);
 
 	vec2 pix = (1.0 - abs(gl_PointCoord * 2.0 - 1.0));
 	float roundFactor = pix.x * pix.y;

+ 2 - 5
src/collision/TestsObbObb.cpp

@@ -211,10 +211,7 @@ static void cullPoints(I n, F32 p[], I m, I i0, I iret[])
 			a -= 2.0 * getPi<F32>();
 		}
 
-		F32 maxdiff = 1e9, diff;
-#if ANKI_DEBUG == 1
-		*iret = i0;			// iret is not allowed to keep this value
-#endif
+		F32 maxdiff = MAX_F32, diff;
 		for(i = 0; i < n; i++) 
 		{
 			if(avail[i]) 
@@ -234,7 +231,7 @@ static void cullPoints(I n, F32 p[], I m, I i0, I iret[])
 			}
 		}
 
-		ANKI_ASSERT(*iret != i0);
+		ANKI_ASSERT(maxdiff != MAX_F32);
 		avail[*iret] = 0;
 		iret++;
 	}

+ 135 - 122
src/gl/GlTextureHandle.cpp

@@ -10,137 +10,81 @@ namespace anki {
 //==============================================================================
 
 //==============================================================================
-/// Create texture job
-class GlTextureCreateJob: public GlJob
-{
-public:
-	GlTextureHandle m_tex;
-	GlTextureHandle::Initializer m_init;
-
-	GlTextureCreateJob(
-		GlTextureHandle tex, 
-		const GlTextureHandle::Initializer& init)
-		: m_tex(tex), m_init(init)
-	{}
+GlTextureHandle::GlTextureHandle()
+{}
 
-	void operator()(GlJobChain* jobs)
+//==============================================================================
+GlTextureHandle::GlTextureHandle(
+	GlJobChainHandle& jobs, const Initializer& init)
+{
+	class Job: public GlJob
 	{
-		ANKI_ASSERT(jobs);
-		GlTexture::Initializer init;
+	public:
+		GlTextureHandle m_tex;
+		GlTextureHandle::Initializer m_init;
 
-		static_cast<GlTextureInitializerBase&>(init) = m_init;
+		Job(
+			GlTextureHandle tex, 
+			const GlTextureHandle::Initializer& init)
+			: m_tex(tex), m_init(init)
+		{}
 
-		U layers = 0;
-		switch(m_init.m_target)
+		void operator()(GlJobChain* jobs)
 		{
-		case GL_TEXTURE_CUBE_MAP:
-			layers = 6;
-			break;
-		case GL_TEXTURE_2D_ARRAY:
-		case GL_TEXTURE_3D:
-			layers = m_init.m_depth;
-			break;
-		case GL_TEXTURE_2D:
-		case GL_TEXTURE_2D_MULTISAMPLE:
-			layers = 1;
-			break;
-		default:
-			ANKI_ASSERT(0);
-		}
+			ANKI_ASSERT(jobs);
+			GlTexture::Initializer init;
 
-		for(U level = 0; level < m_init.m_mipmapsCount; level++)
-		{
-			for(U layer = 0; layer < layers; ++layer)
+			static_cast<GlTextureInitializerBase&>(init) = m_init;
+
+			U layers = 0;
+			switch(m_init.m_target)
 			{
-				auto& buff = m_init.m_data[level][layer];
-				auto& initBuff = init.m_data[level][layer];
+			case GL_TEXTURE_CUBE_MAP:
+				layers = 6;
+				break;
+			case GL_TEXTURE_2D_ARRAY:
+			case GL_TEXTURE_3D:
+				layers = m_init.m_depth;
+				break;
+			case GL_TEXTURE_2D:
+			case GL_TEXTURE_2D_MULTISAMPLE:
+				layers = 1;
+				break;
+			default:
+				ANKI_ASSERT(0);
+			}
 
-				if(buff.isCreated())
-				{
-					initBuff.m_ptr = buff.getBaseAddress();
-					initBuff.m_size = buff.getSize();
-				}
-				else
+			for(U level = 0; level < m_init.m_mipmapsCount; level++)
+			{
+				for(U layer = 0; layer < layers; ++layer)
 				{
-					initBuff.m_ptr = nullptr;
-					initBuff.m_size = 0;
+					auto& buff = m_init.m_data[level][layer];
+					auto& initBuff = init.m_data[level][layer];
+
+					if(buff.isCreated())
+					{
+						initBuff.m_ptr = buff.getBaseAddress();
+						initBuff.m_size = buff.getSize();
+					}
+					else
+					{
+						initBuff.m_ptr = nullptr;
+						initBuff.m_size = 0;
+					}
 				}
 			}
-		}
-
-		auto alloc = jobs->getGlobalAllocator();
-		GlTexture newTex(init, alloc);
-
-		m_tex._get() = std::move(newTex);
-
-		GlHandleState oldState = m_tex._setState(GlHandleState::CREATED);
-		ANKI_ASSERT(oldState == GlHandleState::TO_BE_CREATED);
-		(void)oldState;
-	}
-};
-
-//==============================================================================
-/// Set texture filter job
-class GlTextureSetFilterJob: public GlJob
-{
-public:
-	GlTextureHandle m_tex;
-	GlTexture::Filter m_filter;
 
-	GlTextureSetFilterJob(GlTextureHandle tex, GlTexture::Filter filter)
-		: m_tex(tex), m_filter(filter)
-	{}
+			auto alloc = jobs->getGlobalAllocator();
+			GlTexture newTex(init, alloc);
 
-	void operator()(GlJobChain*)
-	{
-		m_tex._get().setFilter(m_filter);
-	}
-};
-
-//==============================================================================
-/// Generate mipmaps job
-class GlTextureGenMipsJob: public GlJob
-{
-public:
-	GlTextureHandle m_tex;
-
-	GlTextureGenMipsJob(GlTextureHandle tex)
-		: m_tex(tex)
-	{}
-
-	void operator()(GlJobChain*)
-	{
-		m_tex._get().generateMipmaps();
-	}
-};
+			m_tex._get() = std::move(newTex);
 
-//==============================================================================
-/// Set texture parameter job
-class GlTextureSetParameterJob: public GlJob
-{
-public:
-	GlTextureHandle m_tex;
-	GLenum m_param;
-	GLint m_value;
-
-	GlTextureSetParameterJob(GlTextureHandle& tex, GLenum param, GLint value)
-		: m_tex(tex), m_param(param), m_value(value)
-	{}
-
-	void operator()(GlJobChain*)
-	{
-		m_tex._get().setParameter(m_param, m_value);
-	}
-};
-
-//==============================================================================
-GlTextureHandle::GlTextureHandle()
-{}
+			GlHandleState oldState = m_tex._setState(GlHandleState::CREATED);
+			ANKI_ASSERT(oldState == GlHandleState::TO_BE_CREATED);
+			(void)oldState;
+		}
+	};
 
-//==============================================================================
-GlTextureHandle::GlTextureHandle(
-	GlJobChainHandle& jobs, const Initializer& init)
-{
 	ANKI_ASSERT(!isCreated());
 
 	typedef GlGlobalHeapAllocator<GlTexture> Alloc;
@@ -159,7 +103,7 @@ GlTextureHandle::GlTextureHandle(
 	_setState(GlHandleState::TO_BE_CREATED);
 
 	// Fire the job
-	jobs._pushBackNewJob<GlTextureCreateJob>(*this, init);
+	jobs._pushBackNewJob<Job>(*this, init);
 }
 
 //==============================================================================
@@ -185,21 +129,53 @@ void GlTextureHandle::bind(GlJobChainHandle& jobs, U32 unit)
 		}
 	};
 
+	ANKI_ASSERT(isCreated());
 	jobs._pushBackNewJob<Job>(*this, unit);
 }
 
 //==============================================================================
 void GlTextureHandle::setFilter(GlJobChainHandle& jobs, Filter filter)
 {
+	class Job: public GlJob
+	{
+	public:
+		GlTextureHandle m_tex;
+		GlTexture::Filter m_filter;
+
+		Job(GlTextureHandle tex, GlTexture::Filter filter)
+			: m_tex(tex), m_filter(filter)
+		{}
+
+		void operator()(GlJobChain*)
+		{
+			m_tex._get().setFilter(m_filter);
+		}
+	};
+
 	ANKI_ASSERT(isCreated());
-	jobs._pushBackNewJob<GlTextureSetFilterJob>(*this, filter);
+	jobs._pushBackNewJob<Job>(*this, filter);
 }
 
 //==============================================================================
 void GlTextureHandle::generateMipmaps(GlJobChainHandle& jobs)
 {
+	class Job: public GlJob
+	{
+	public:
+		GlTextureHandle m_tex;
+
+		Job(GlTextureHandle tex)
+			: m_tex(tex)
+		{}
+
+		void operator()(GlJobChain*)
+		{
+			m_tex._get().generateMipmaps();
+		}
+	};
+
 	ANKI_ASSERT(isCreated());
-	jobs._pushBackNewJob<GlTextureGenMipsJob>(*this);
+	jobs._pushBackNewJob<Job>(*this);
 }
 
 //==============================================================================
@@ -207,7 +183,26 @@ void GlTextureHandle::setParameter(GlJobChainHandle& jobs, GLenum param,
 	GLint value)
 {
 	ANKI_ASSERT(isCreated());
-	jobs._pushBackNewJob<GlTextureSetParameterJob>(*this, param, value);
+
+	class Job: public GlJob
+	{
+	public:
+		GlTextureHandle m_tex;
+		GLenum m_param;
+		GLint m_value;
+
+		Job(GlTextureHandle& tex, GLenum param, GLint value)
+			: m_tex(tex), m_param(param), m_value(value)
+		{}
+
+		void operator()(GlJobChain*)
+		{
+			m_tex._get().setParameter(m_param, m_value);
+		}
+	};
+
+	ANKI_ASSERT(isCreated());
+	jobs._pushBackNewJob<Job>(*this, param, value);
 }
 
 //==============================================================================
@@ -264,6 +259,21 @@ GlSamplerHandle::GlSamplerHandle(GlJobChainHandle& jobs)
 		}
 	};
 
+	typedef GlGlobalHeapAllocator<GlSampler> Alloc;
+
+	typedef GlDeleteObjectJob<
+		GlSampler, 
+		Alloc> DeleteJob;
+
+	typedef GlHandleDeferredDeleter<GlSampler, Alloc, DeleteJob>
+		Deleter;
+
+	*static_cast<Base::Base*>(this) = Base::Base(
+		&jobs._getJobManager().getManager(),
+		jobs._getJobManager().getManager()._getAllocator(), 
+		Deleter());
+	_setState(GlHandleState::TO_BE_CREATED);
+
 	jobs._pushBackNewJob<Job>(*this);
 }
 
@@ -290,6 +300,7 @@ void GlSamplerHandle::bind(GlJobChainHandle& jobs, U32 unit)
 		}
 	};
 
+	ANKI_ASSERT(isCreated());
 	jobs._pushBackNewJob<Job>(*this, unit);
 }
 
@@ -312,6 +323,7 @@ void GlSamplerHandle::setFilter(GlJobChainHandle& jobs, Filter filter)
 		}
 	};
 
+	ANKI_ASSERT(isCreated());
 	jobs._pushBackNewJob<Job>(*this, filter);
 }
 
@@ -336,6 +348,7 @@ void GlSamplerHandle::setParameter(
 		}
 	};
 
+	ANKI_ASSERT(isCreated());
 	jobs._pushBackNewJob<Job>(*this, param, value);
 }
 
@@ -353,11 +366,11 @@ void GlSamplerHandle::bindDefault(GlJobChainHandle& jobs, U32 unit)
 
 		void operator()(GlJobChain*)
 		{
-			GlSamper::unbind(m_unit);
+			GlSampler::unbind(m_unit);
 		}
 	};
 
-	jobs._pushBackNewJob<Job>(*this, unit);
+	jobs._pushBackNewJob<Job>(unit);
 }
 
 } // end namespace anki

+ 1 - 1
src/renderer/MainRenderer.cpp

@@ -76,7 +76,7 @@ void MainRenderer::render(SceneGraph& scene)
 			rt = &getIs()._getRt();
 		}
 
-		//rt = &getPps().getSslr()._getRt();
+		//rt = &getIs()._getRt();
 		//rt = &getPps().getSsao().getRt();
 
 		rt->setFilter(lastJobs, GlTextureHandle::Filter::LINEAR);

+ 1 - 1
src/renderer/Ms.cpp

@@ -61,7 +61,7 @@ void Ms::init(const RendererInitializer& initializer)
 			GlManager& gl = GlManagerSingleton::get();
 			GlJobChainHandle jobs(&gl);
 
-			//m_smallDepthRt.setFilter(jobs, GlTextureHandle::Filter::LINEAR);
+			m_smallDepthRt.setFilter(jobs, GlTextureHandle::Filter::LINEAR);
 
 			m_smallDepthFb = GlFramebufferHandle(
 				jobs,

+ 11 - 5
src/renderer/Sslr.cpp

@@ -37,6 +37,12 @@ void Sslr::init(const RendererInitializer& initializer)
 	m_reflectionPpline = m_r->createDrawQuadProgramPipeline(
 		m_reflectionFrag->getGlProgram());
 
+	// Sampler
+	GlManager& gl = GlManagerSingleton::get();
+	GlJobChainHandle jobs(&gl);
+	m_depthMapSampler = GlSamplerHandle(jobs);
+	m_depthMapSampler.setFilter(jobs, GlSamplerHandle::Filter::NEAREST);
+
 	// Blit
 	m_blitFrag.load("shaders/Blit.frag.glsl");
 	m_blitPpline = m_r->createDrawQuadProgramPipeline(
@@ -49,9 +55,6 @@ void Sslr::init(const RendererInitializer& initializer)
 	}
 	else
 	{
-		GlManager& gl = GlManagerSingleton::get();
-		GlJobChainHandle jobs(&gl);
-
 		Direction& dir = m_dirs[(U)DirectionEnum::VERTICAL];
 
 		m_r->createRenderTarget(m_width, m_height, GL_RGB8, GL_RGB, 
@@ -64,9 +67,9 @@ void Sslr::init(const RendererInitializer& initializer)
 		// Create FB
 		dir.m_fb = GlFramebufferHandle(
 			jobs, {{dir.m_rt, GL_COLOR_ATTACHMENT0}});
-
-		jobs.finish();
 	}
+
+	jobs.finish();
 }
 
 //==============================================================================
@@ -82,11 +85,14 @@ void Sslr::run(GlJobChainHandle& jobs)
 	m_reflectionPpline.bind(jobs);
 	m_r->getIs()._getRt().bind(jobs, 0);
 	m_r->getMs()._getSmallDepthRt().bind(jobs, 1);
+	m_depthMapSampler.bind(jobs, 1);
 	m_r->getMs()._getRt1().bind(jobs, 2);
 	m_r->getPps().getSsao().m_uniformsBuff.bindShaderBuffer(jobs, 0);
 
 	m_r->drawQuad(jobs);
 
+	GlSamplerHandle::bindDefault(jobs, 1); // Unbind the sampler
+
 	// Blurring
 	//
 	if(m_blurringIterationsCount > 0)