Browse Source

Fixing bugs

Panagiotis Christopoulos Charitos 10 years ago
parent
commit
abecf79c94

+ 3 - 0
include/anki/gr/gl/PipelineImpl.h

@@ -56,6 +56,8 @@ private:
 	};
 	};
 
 
 	Bool8 m_compute = false; ///< Is compute
 	Bool8 m_compute = false; ///< Is compute
+	Bool8 m_tessellation = false;
+	Bool8 m_blendEnabled = false;
 
 
 	/// Input values.
 	/// Input values.
 	PipelineInitializer m_in;
 	PipelineInitializer m_in;
@@ -93,6 +95,7 @@ private:
 
 
 	void initVertexState();
 	void initVertexState();
 	void initInputAssemblerState();
 	void initInputAssemblerState();
+	void initTessellationState();
 	void initRasterizerState();
 	void initRasterizerState();
 	void initDepthStencilState();
 	void initDepthStencilState();
 	void initColorState();
 	void initColorState();

+ 1 - 1
include/anki/gr/gl/RenderingThread.h

@@ -15,7 +15,7 @@ namespace anki {
 /// @addtogroup opengl
 /// @addtogroup opengl
 /// @{
 /// @{
 
 
-#define ANKI_DISABLE_GL_RENDERING_THREAD 1
+#define ANKI_DISABLE_GL_RENDERING_THREAD 0
 
 
 /// Command queue. It's essentialy a queue of command buffers waiting for
 /// Command queue. It's essentialy a queue of command buffers waiting for
 /// execution and a server
 /// execution and a server

+ 1 - 1
include/anki/renderer/Is.h

@@ -53,7 +53,7 @@ public:
 
 
 	ANKI_USE_RESULT Error run(CommandBufferPtr& cmdBuff);
 	ANKI_USE_RESULT Error run(CommandBufferPtr& cmdBuff);
 
 
-	TexturePtr& _getRt()
+	TexturePtr& getRt()
 	{
 	{
 		return m_rt;
 		return m_rt;
 	}
 	}

+ 9 - 9
shaders/IsLp.vert.glsl

@@ -28,17 +28,17 @@ void main()
 	const vec2 SIZES =
 	const vec2 SIZES =
 		vec2(1.0 / float(TILES_X_COUNT), 1.0 / float(TILES_Y_COUNT));
 		vec2(1.0 / float(TILES_X_COUNT), 1.0 / float(TILES_Y_COUNT));
 
 
-	const vec2 POSITIONS[4] = vec2[](
-		vec2(-1.0, -1.0),
-		vec2(1.0, -1.0),
-		vec2(-1.0, 1.0),
-		vec2(1.0, 1.0));
+	const vec2 UVS[4] = vec2[](
+		vec2(0.0, 0.0) * SIZES,
+		vec2(1.0, 0.0) * SIZES,
+		vec2(0.0, 1.0) * SIZES,
+		vec2(1.0, 1.0) * SIZES);
 
 
-	out_texCoord = (POSITIONS[gl_VertexID] + ij) * SIZES;
-	vec2 vertPosNdc = out_texCoord * 2.0 - 1.0;
-	gl_Position = vec4(vertPosNdc, 0.0, 1.0);
+	out_texCoord = UVS[gl_VertexID] + ij * SIZES;
+	vec2 pos = out_texCoord * 2.0 - 1.0;
 
 
-	out_projectionParams = u_projectionParams.xy * vertPosNdc;
+	gl_Position = vec4(pos, 0.0, 1.0);
+	out_projectionParams = u_projectionParams.xy * pos;
 }
 }
 
 
 
 

+ 74 - 15
src/gr/gl/PipelineImpl.cpp

@@ -113,6 +113,7 @@ Error PipelineImpl::create(const Initializer& init)
 	{
 	{
 		initVertexState();
 		initVertexState();
 		initInputAssemblerState();
 		initInputAssemblerState();
+		initTessellationState();
 		initRasterizerState();
 		initRasterizerState();
 		initDepthStencilState();
 		initDepthStencilState();
 		initColorState();
 		initColorState();
@@ -188,6 +189,12 @@ Error PipelineImpl::createGlPipeline()
 			GLbitfield bit;
 			GLbitfield bit;
 			computeGlShaderType(static_cast<ShaderType>(i), &bit);
 			computeGlShaderType(static_cast<ShaderType>(i), &bit);
 			glUseProgramStages(m_glName, bit, shader.get().getGlName());
 			glUseProgramStages(m_glName, bit, shader.get().getGlName());
+
+			if(i == U(ShaderType::TESSELLATION_CONTROL)
+				|| i == U(ShaderType::TESSELLATION_EVALUATION))
+			{
+				m_tessellation = true;
+			}
 		}
 		}
 	}
 	}
 
 
@@ -334,6 +341,13 @@ void PipelineImpl::initInputAssemblerState()
 		computeHash(&m_in.m_inputAssembler, sizeof(m_in.m_inputAssembler));
 		computeHash(&m_in.m_inputAssembler, sizeof(m_in.m_inputAssembler));
 }
 }
 
 
+//==============================================================================
+void PipelineImpl::initTessellationState()
+{
+	m_hashes.m_tessellation =
+		computeHash(&m_in.m_tessellation, sizeof(m_in.m_tessellation));
+}
+
 //==============================================================================
 //==============================================================================
 void PipelineImpl::initRasterizerState()
 void PipelineImpl::initRasterizerState()
 {
 {
@@ -413,10 +427,19 @@ void PipelineImpl::initColorState()
 			ANKI_ASSERT(0);
 			ANKI_ASSERT(0);
 		}
 		}
 
 
-		out.m_channelWriteMask[0] = in.m_channelWriteMask | ColorBit::RED;
-		out.m_channelWriteMask[1] = in.m_channelWriteMask | ColorBit::GREEN;
-		out.m_channelWriteMask[2] = in.m_channelWriteMask | ColorBit::BLUE;
-		out.m_channelWriteMask[3] = in.m_channelWriteMask | ColorBit::ALPHA;
+		out.m_channelWriteMask[0] =
+			(in.m_channelWriteMask | ColorBit::RED) != 0;
+		out.m_channelWriteMask[1] =
+			(in.m_channelWriteMask | ColorBit::GREEN) != 0;
+		out.m_channelWriteMask[2] =
+			(in.m_channelWriteMask | ColorBit::BLUE) != 0;
+		out.m_channelWriteMask[3] =
+			(in.m_channelWriteMask | ColorBit::ALPHA) != 0;
+
+		if(!(out.m_srcBlendMethod == GL_ONE && out.m_dstBlendMethod == GL_ZERO))
+		{
+			m_blendEnabled = true;
+		}
 	}
 	}
 
 
 	m_hashes.m_color = computeHash(&m_in.m_color, sizeof(m_in.m_color));
 	m_hashes.m_color = computeHash(&m_in.m_color, sizeof(m_in.m_color));
@@ -430,10 +453,15 @@ void PipelineImpl::setVertexState(GlState& state) const
 		return;
 		return;
 	}
 	}
 
 
+	state.m_stateHashes.m_vertex = m_hashes.m_vertex;
+
 	for(U i = 0; i < m_in.m_vertex.m_attributeCount; ++i)
 	for(U i = 0; i < m_in.m_vertex.m_attributeCount; ++i)
 	{
 	{
 		const Attribute& attrib = m_cache.m_attribs[i];
 		const Attribute& attrib = m_cache.m_attribs[i];
 		ANKI_ASSERT(attrib.m_type);
 		ANKI_ASSERT(attrib.m_type);
+
+		glEnableVertexAttribArray(i);
+
 		glVertexAttribFormat(i, attrib.m_compCount, attrib.m_type,
 		glVertexAttribFormat(i, attrib.m_compCount, attrib.m_type,
 			attrib.m_normalized, m_in.m_vertex.m_attributes[i].m_offset);
 			attrib.m_normalized, m_in.m_vertex.m_attributes[i].m_offset);
 
 
@@ -454,6 +482,8 @@ void PipelineImpl::setInputAssemblerState(GlState& state) const
 		return;
 		return;
 	}
 	}
 
 
+	state.m_stateHashes.m_inputAssembler = m_hashes.m_inputAssembler;
+
 	if(m_in.m_inputAssembler.m_primitiveRestartEnabled)
 	if(m_in.m_inputAssembler.m_primitiveRestartEnabled)
 	{
 	{
 		glEnable(GL_PRIMITIVE_RESTART);
 		glEnable(GL_PRIMITIVE_RESTART);
@@ -467,11 +497,14 @@ void PipelineImpl::setInputAssemblerState(GlState& state) const
 //==============================================================================
 //==============================================================================
 void PipelineImpl::setTessellationState(GlState& state) const
 void PipelineImpl::setTessellationState(GlState& state) const
 {
 {
-	if(state.m_stateHashes.m_tessellation == m_hashes.m_tessellation)
+	if(!m_tessellation
+		|| state.m_stateHashes.m_tessellation == m_hashes.m_tessellation)
 	{
 	{
 		return;
 		return;
 	}
 	}
 
 
+	state.m_stateHashes.m_tessellation = m_hashes.m_tessellation;
+
 	glPatchParameteri(GL_PATCH_VERTICES,
 	glPatchParameteri(GL_PATCH_VERTICES,
 		m_in.m_tessellation.m_patchControlPointsCount);
 		m_in.m_tessellation.m_patchControlPointsCount);
 }
 }
@@ -484,8 +517,11 @@ void PipelineImpl::setRasterizerState(GlState& state) const
 		return;
 		return;
 	}
 	}
 
 
+	state.m_stateHashes.m_rasterizer = m_hashes.m_rasterizer;
+
 	glPolygonMode(GL_FRONT_AND_BACK, m_cache.m_fillMode);
 	glPolygonMode(GL_FRONT_AND_BACK, m_cache.m_fillMode);
 	glCullFace(m_cache.m_cullMode);
 	glCullFace(m_cache.m_cullMode);
+	glEnable(GL_CULL_FACE);
 }
 }
 
 
 //==============================================================================
 //==============================================================================
@@ -496,6 +532,8 @@ void PipelineImpl::setDepthStencilState(GlState& state) const
 		return;
 		return;
 	}
 	}
 
 
+	state.m_stateHashes.m_depthStencil = m_hashes.m_depthStencil;
+
 	if(m_cache.m_depthCompareFunction == GL_ALWAYS)
 	if(m_cache.m_depthCompareFunction == GL_ALWAYS)
 	{
 	{
 		glDisable(GL_DEPTH_TEST);
 		glDisable(GL_DEPTH_TEST);
@@ -508,13 +546,13 @@ void PipelineImpl::setDepthStencilState(GlState& state) const
 	if(m_in.m_depthStencil.m_polygonOffsetFactor == 0.0
 	if(m_in.m_depthStencil.m_polygonOffsetFactor == 0.0
 		&& m_in.m_depthStencil.m_polygonOffsetUnits == 0.0)
 		&& m_in.m_depthStencil.m_polygonOffsetUnits == 0.0)
 	{
 	{
-		glEnable(GL_POLYGON_OFFSET_FILL);
-		glPolygonOffset(m_in.m_depthStencil.m_polygonOffsetFactor,
-			m_in.m_depthStencil.m_polygonOffsetUnits);
+		glDisable(GL_POLYGON_OFFSET_FILL);
 	}
 	}
 	else
 	else
 	{
 	{
-		glDisable(GL_POLYGON_OFFSET_FILL);
+		glEnable(GL_POLYGON_OFFSET_FILL);
+		glPolygonOffset(m_in.m_depthStencil.m_polygonOffsetFactor,
+			m_in.m_depthStencil.m_polygonOffsetUnits);
 	}
 	}
 
 
 	glDepthFunc(m_cache.m_depthCompareFunction);
 	glDepthFunc(m_cache.m_depthCompareFunction);
@@ -528,14 +566,35 @@ void PipelineImpl::setColorState(GlState& state) const
 		return;
 		return;
 	}
 	}
 
 
-	for(U i = 0; i < m_in.m_color.m_attachmentCount; ++i)
+	state.m_stateHashes.m_color = m_hashes.m_color;
+
+	if(m_blendEnabled)
 	{
 	{
-		const Attachment& att = m_cache.m_attachments[i];
+		glEnable(GL_BLEND);
+
+		for(U i = 0; i < m_in.m_color.m_attachmentCount; ++i)
+		{
+			const Attachment& att = m_cache.m_attachments[i];
 
 
-		glBlendFunci(i, att.m_srcBlendMethod, att.m_dstBlendMethod);
-		glBlendEquationi(i, att.m_blendFunction);
-		glColorMaski(i, att.m_channelWriteMask[0], att.m_channelWriteMask[1],
-			att.m_channelWriteMask[2], att.m_channelWriteMask[3]);
+			glBlendFunci(i, att.m_srcBlendMethod, att.m_dstBlendMethod);
+			glBlendEquationi(i, att.m_blendFunction);
+			glColorMaski(i, att.m_channelWriteMask[0],
+				att.m_channelWriteMask[1], att.m_channelWriteMask[2],
+				att.m_channelWriteMask[3]);
+		}
+	}
+	else
+	{
+		glDisable(GL_BLEND);
+
+		for(U i = 0; i < m_in.m_color.m_attachmentCount; ++i)
+		{
+			const Attachment& att = m_cache.m_attachments[i];
+
+			glColorMaski(i, att.m_channelWriteMask[0],
+				att.m_channelWriteMask[1], att.m_channelWriteMask[2],
+				att.m_channelWriteMask[3]);
+		}
 	}
 	}
 }
 }
 
 

+ 1 - 1
src/gr/gl/PipelinePtr.cpp

@@ -70,7 +70,7 @@ public:
 };
 };
 
 
 //==============================================================================
 //==============================================================================
-// PipelinePtr                                                              =
+// PipelinePtr                                                                 =
 //==============================================================================
 //==============================================================================
 
 
 //==============================================================================
 //==============================================================================

+ 1 - 1
src/renderer/Bloom.cpp

@@ -166,7 +166,7 @@ void Bloom::run(CommandBufferPtr& cmdb)
 		m_commonUboUpdateTimestamp = getGlobalTimestamp();
 		m_commonUboUpdateTimestamp = getGlobalTimestamp();
 	}
 	}
 
 
-	m_r->getIs()._getRt().bind(cmdb, 0);
+	m_r->getIs().getRt().bind(cmdb, 0);
 	m_commonBuff.bindShaderBuffer(cmdb, 0);
 	m_commonBuff.bindShaderBuffer(cmdb, 0);
 	m_r->getPps().getTm().getAverageLuminanceBuffer().bindShaderBuffer(cmdb, 0);
 	m_r->getPps().getTm().getAverageLuminanceBuffer().bindShaderBuffer(cmdb, 0);
 
 

+ 1 - 1
src/renderer/Dbg.cpp

@@ -51,7 +51,7 @@ Error Dbg::init(const ConfigSet& initializer)
 	}
 	}
 	else
 	else
 	{
 	{
-		fbInit.m_colorAttachments[0].m_texture = m_r->getIs()._getRt();
+		fbInit.m_colorAttachments[0].m_texture = m_r->getIs().getRt();
 	}
 	}
 	fbInit.m_colorAttachments[0].m_loadOperation =
 	fbInit.m_colorAttachments[0].m_loadOperation =
 		AttachmentLoadOperation::LOAD;
 		AttachmentLoadOperation::LOAD;

+ 1 - 5
src/renderer/Drawer.cpp

@@ -331,11 +331,7 @@ Error RenderableDrawer::render(SceneNode& frsn, VisibleNode& visibleNode)
 	build.m_subMeshIndicesCount = visibleNode.m_spatialsCount;
 	build.m_subMeshIndicesCount = visibleNode.m_spatialsCount;
 	build.m_cmdb = m_cmdBuff;
 	build.m_cmdb = m_cmdBuff;
 
 
-	Error err = renderable.buildRendering(build);
-	if(err)
-	{
-		return err;
-	}
+	ANKI_CHECK(renderable.buildRendering(build));
 
 
 	return ErrorCode::NONE;
 	return ErrorCode::NONE;
 }
 }

+ 1 - 1
src/renderer/Fs.cpp

@@ -21,7 +21,7 @@ Error Fs::init(const ConfigSet&)
 {
 {
 	FramebufferPtr::Initializer fbInit;
 	FramebufferPtr::Initializer fbInit;
 	fbInit.m_colorAttachmentsCount = 1;
 	fbInit.m_colorAttachmentsCount = 1;
-	fbInit.m_colorAttachments[0].m_texture = m_r->getIs()._getRt();
+	fbInit.m_colorAttachments[0].m_texture = m_r->getIs().getRt();
 	fbInit.m_colorAttachments[0].m_loadOperation =
 	fbInit.m_colorAttachments[0].m_loadOperation =
 		AttachmentLoadOperation::LOAD;
 		AttachmentLoadOperation::LOAD;
 	fbInit.m_depthStencilAttachment.m_texture = m_r->getMs().getDepthRt();
 	fbInit.m_depthStencilAttachment.m_texture = m_r->getMs().getDepthRt();

+ 2 - 2
src/renderer/MainRenderer.cpp

@@ -139,10 +139,10 @@ Error MainRenderer::render(SceneGraph& scene)
 		}
 		}
 		else
 		else
 		{
 		{
-			rt = &m_r->getIs()._getRt();
+			rt = &m_r->getIs().getRt();
 		}
 		}
 
 
-		//rt = &m_r->getMs().getRt2();
+		//rt = &m_r->getIs().getRt();
 		//rt = &getPps().getHdr()._getRt();
 		//rt = &getPps().getHdr()._getRt();
 
 
 		rt->bind(cmdb, 0);
 		rt->bind(cmdb, 0);

+ 3 - 0
src/renderer/Ms.cpp

@@ -53,10 +53,13 @@ Error Ms::createRt(U32 index, U32 samples)
 	fbInit.m_colorAttachmentsCount = ATTACHMENT_COUNT;
 	fbInit.m_colorAttachmentsCount = ATTACHMENT_COUNT;
 	fbInit.m_colorAttachments[0].m_texture = plane.m_rt0;
 	fbInit.m_colorAttachments[0].m_texture = plane.m_rt0;
 	fbInit.m_colorAttachments[0].m_loadOperation = loadop;
 	fbInit.m_colorAttachments[0].m_loadOperation = loadop;
+	fbInit.m_colorAttachments[0].m_clearValue.m_colorf = {{1.0, 0.0, 0.0, 0.0}};
 	fbInit.m_colorAttachments[1].m_texture = plane.m_rt1;
 	fbInit.m_colorAttachments[1].m_texture = plane.m_rt1;
 	fbInit.m_colorAttachments[1].m_loadOperation = loadop;
 	fbInit.m_colorAttachments[1].m_loadOperation = loadop;
+	fbInit.m_colorAttachments[1].m_clearValue.m_colorf = {{0.0, 1.0, 0.0, 0.0}};
 	fbInit.m_colorAttachments[2].m_texture = plane.m_rt2;
 	fbInit.m_colorAttachments[2].m_texture = plane.m_rt2;
 	fbInit.m_colorAttachments[2].m_loadOperation = loadop;
 	fbInit.m_colorAttachments[2].m_loadOperation = loadop;
+	fbInit.m_colorAttachments[2].m_clearValue.m_colorf = {{0.0, 0.0, 1.0, 0.0}};
 	fbInit.m_depthStencilAttachment.m_texture = plane.m_depthRt;
 	fbInit.m_depthStencilAttachment.m_texture = plane.m_depthRt;
 	fbInit.m_depthStencilAttachment.m_loadOperation =
 	fbInit.m_depthStencilAttachment.m_loadOperation =
 		AttachmentLoadOperation::CLEAR;
 		AttachmentLoadOperation::CLEAR;

+ 1 - 1
src/renderer/Pps.cpp

@@ -164,7 +164,7 @@ void Pps::run(CommandBufferPtr& cmdb)
 
 
 	m_ppline.bind(cmdb);
 	m_ppline.bind(cmdb);
 
 
-	m_r->getIs()._getRt().bind(cmdb, 0);
+	m_r->getIs().getRt().bind(cmdb, 0);
 
 
 	if(m_ssao->getEnabled())
 	if(m_ssao->getEnabled())
 	{
 	{

+ 1 - 1
src/renderer/Sslr.cpp

@@ -89,7 +89,7 @@ void Sslr::run(CommandBufferPtr& cmdBuff)
 	m_reflectionPpline.bind(cmdBuff);
 	m_reflectionPpline.bind(cmdBuff);
 
 
 	Array<TexturePtr, 4> tarr = {{
 	Array<TexturePtr, 4> tarr = {{
-		m_r->getIs()._getRt(),
+		m_r->getIs().getRt(),
 		m_r->getMs().getDepthRt(),
 		m_r->getMs().getDepthRt(),
 		m_r->getMs().getRt1(),
 		m_r->getMs().getRt1(),
 		m_r->getMs().getRt2()}};
 		m_r->getMs().getRt2()}};

+ 1 - 1
src/renderer/Tm.cpp

@@ -45,7 +45,7 @@ void Tm::run(CommandBufferPtr& cmdb)
 {
 {
 	m_luminancePpline.bind(cmdb);
 	m_luminancePpline.bind(cmdb);
 	m_luminanceBuff.bindShaderBuffer(cmdb, 0);
 	m_luminanceBuff.bindShaderBuffer(cmdb, 0);
-	m_r->getIs()._getRt().bind(cmdb, 0);
+	m_r->getIs().getRt().bind(cmdb, 0);
 
 
 	cmdb.dispatchCompute(1, 1, 1);
 	cmdb.dispatchCompute(1, 1, 1);
 }
 }

+ 2 - 2
testapp/Main.cpp

@@ -59,7 +59,7 @@ Error init()
 	MainRenderer& renderer = app->getMainRenderer();
 	MainRenderer& renderer = app->getMainRenderer();
 	ResourceManager& resources = app->getResourceManager();
 	ResourceManager& resources = app->getResourceManager();
 
 
-	scene.setAmbientColor(Vec4(1.0) * 0.0001);
+	scene.setAmbientColor(Vec4(1.0) * 0.05);
 
 
 	if(getenv("PROFILE"))
 	if(getenv("PROFILE"))
 	{
 	{
@@ -507,7 +507,7 @@ Error initSubsystems(int argc, char* argv[])
 	config.set("samples", 1);
 	config.set("samples", 1);
 	config.set("tessellation", true);
 	config.set("tessellation", true);
 	//config.set("maxTextureSize", 256);
 	//config.set("maxTextureSize", 256);
-	config.set("fullscreenDesktopResolution", false);
+	config.set("fullscreenDesktopResolution", true);
 	config.set("debugContext", false);
 	config.set("debugContext", false);
 	config.set("dataPaths", "assets");
 	config.set("dataPaths", "assets");