Browse Source

Fixing bugs

Panagiotis Christopoulos Charitos 11 years ago
parent
commit
5c0ae087ad

+ 0 - 3
.gitignore

@@ -5,8 +5,5 @@
 !*.cc
 !*.hpp
 !*.h
-!*.txt
-!*.py
 !*.glsl
-!*.sh
 build/*

+ 2 - 1
include/anki/renderer/Sm.h

@@ -67,7 +67,8 @@ private:
 	U32 m_resolution;
 
 	Sm(Renderer* r)
-		: RenderingPass(r)
+	:	RenderingPass(r),
+		m_sms(getAllocator())
 	{}
 
 	void init(const ConfigSet& initializer);

+ 7 - 12
include/anki/renderer/Tiler.h

@@ -6,16 +6,13 @@
 #ifndef ANKI_RENDERER_TILER_H
 #define ANKI_RENDERER_TILER_H
 
-#include "anki/util/StdTypes.h"
 #include "anki/Collision.h"
-#include "anki/Gl.h"
-#include "anki/resource/Resource.h"
+#include "anki/renderer/RenderingPass.h"
 #include "anki/core/Timestamp.h"
 #include <bitset>
 
 namespace anki {
 
-class Renderer;
 class Camera;
 class ShaderProgramUniformVariable;
 class Frustumable;
@@ -24,19 +21,19 @@ class Frustumable;
 /// @{
 
 /// Tiler used for visibility tests
-class Tiler
+class Tiler: public RenderingPass
 {
 	friend struct UpdateTilesPlanesPerspectiveCameraJob;
 	friend struct UpdatePlanesPerspectiveCameraJob;
 
 public:
-	typedef std::bitset<
-		ANKI_RENDERER_MAX_TILES_X * ANKI_RENDERER_MAX_TILES_Y> Bitset;
+	using Bitset = std::bitset<
+		ANKI_RENDERER_MAX_TILES_X * ANKI_RENDERER_MAX_TILES_Y>;
 
-	Tiler();
+	Tiler(Renderer* r);
 	~Tiler();
 
-	void init(Renderer* r);
+	void init();
 
 	/// Issue the GPU job
 	void runMinMax(const GlTextureHandle& depthMap);
@@ -78,15 +75,13 @@ private:
 	ProgramResourcePointer m_frag;
 	GlProgramPipelineHandle m_ppline;
 
-	Renderer* m_r = nullptr;
-
 	/// Used to check if the camera is changed and we need to update the planes
 	const Camera* m_prevCam = nullptr;
 
 	/// Timestamp for the same reason as prevCam
 	Timestamp m_planes4UpdateTimestamp = getGlobTimestamp();
 
-	void initInternal(Renderer* r);
+	void initInternal();
 
 	void testRange(const CollisionShape& cs, Bool nearPlane,
 		U iFrom, U iTo, U jFrom, U jTo, Bitset& bitset) const;

+ 2 - 2
shaders/Final.frag.glsl

@@ -8,8 +8,8 @@
 #pragma anki type frag
 
 #define DEFAULT_FLOAT_PRECISION lowp
-#pragma anki include shaders/Common.glsl
-#pragma anki include shaders/Pack.glsl
+#pragma anki include "shaders/Common.glsl"
+#pragma anki include "shaders/Pack.glsl"
 
 layout(binding = 0) uniform sampler2D uRasterImage;
 

+ 3 - 3
shaders/Quad.vert.glsl

@@ -7,17 +7,17 @@
 #pragma anki include "shaders/Common.glsl"
 
 /// the vert coords are NDC
-layout(location = POSITION_LOCATION) in F32Vec2 inPosition;
+layout(location = POSITION_LOCATION) in vec2 inPosition;
 
 layout(location = 0) out F32Vec2 outTexCoord;
 
 out gl_PerVertex
 {
-	F32Vec4 gl_Position;
+	vec4 gl_Position;
 };
 
 void main()
 {
 	outTexCoord = (inPosition * 0.5) + 0.5;
-	gl_Position = F32Vec4(inPosition, 0.0, 1.0);
+	gl_Position = vec4(inPosition, 0.0, 1.0);
 }

+ 1 - 1
shaders/TilerMinMax.frag.glsl

@@ -4,7 +4,7 @@
 // http://www.anki3d.org/LICENSE
 
 #pragma anki type frag
-#pragma anki include shaders/Common.glsl
+#pragma anki include "shaders/Common.glsl"
 
 #if !defined(TILES_X_COUNT) || !defined(TILES_Y_COUNT) || !defined(RENDERER_WIDTH) || !defined(RENDERER_HEIGHT)
 #error Forgot to define something

+ 19 - 22
src/core/App.cpp

@@ -118,7 +118,23 @@ void App::init(const ConfigSet& config)
 		Logger::InitFlags::WITH_SYSTEM_MESSAGE_HANDLER, m_heapAlloc,
 		&m_cacheDir[0]);
 
-	printAppInfo();
+	// Print a message
+	String msg(getAllocator());
+	msg.sprintf(
+		"Initializing application ("
+		"version %u.%u, "
+		"build %s %s, "
+		"commit %s)...",
+		ANKI_VERSION_MAJOR, ANKI_VERSION_MINOR,
+#if !ANKI_DEBUG
+		"release",
+#else
+		"debug",
+#endif
+		__DATE__,
+		ANKI_REVISION);
+
+	ANKI_LOGI(&msg[0]);
 
 	m_timerTick = 1.0 / 60.0; // in sec. 1.0 / period
 
@@ -175,6 +191,8 @@ void App::init(const ConfigSet& config)
 
 	// Script
 	m_script = m_heapAlloc.newInstance<ScriptManager>(m_heapAlloc);
+
+	ANKI_LOGI("Application initialized");
 }
 
 //==============================================================================
@@ -238,27 +256,6 @@ void App::initDirs()
 void App::quit(int code)
 {}
 
-//==============================================================================
-void App::printAppInfo()
-{
-	String msg(getAllocator());
-	msg.sprintf(
-		"App info: "
-		"version %u.%u, "
-		"build %s %s, "
-		"commit %s",
-		ANKI_VERSION_MAJOR, ANKI_VERSION_MINOR,
-#if !ANKI_DEBUG
-		"Release",
-#else
-		"Debug",
-#endif
-		__DATE__,
-		ANKI_REVISION);
-
-	ANKI_LOGI(&msg[0]);
-}
-
 //==============================================================================
 void App::mainLoop(UserMainLoopCallback callback, void* userData)
 {

+ 5 - 0
src/core/NativeWindowSdl.cpp

@@ -29,6 +29,9 @@ void NativeWindow::create(Initializer& init, HeapAllocator<U8>& alloc)
 	//
 	// Set GL attributes
 	//
+	ANKI_LOGI("Creating SDL window (OpenGL context to be requested %u.%u)...", 
+		init.m_majorVersion, init.m_minorVersion);
+
 	if(SDL_GL_SetAttribute(SDL_GL_RED_SIZE, init.m_rgbaBits[0]) != 0
 		|| SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, init.m_rgbaBits[1]) != 0
 		|| SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, init.m_rgbaBits[2]) != 0
@@ -108,6 +111,8 @@ void NativeWindow::create(Initializer& init, HeapAllocator<U8>& alloc)
 		throw ANKI_EXCEPTION("GLEW initialization failed");
 	}
 	glGetError();
+
+	ANKI_LOGI("SDL window created");
 }
 
 //==============================================================================

+ 13 - 14
src/gl/GlProgram.cpp

@@ -13,9 +13,6 @@
 #	include "anki/util/File.h"
 #endif
 
-#include <sstream>
-#include <iomanip>
-
 namespace anki {
 
 //==============================================================================
@@ -349,33 +346,33 @@ void GlProgram::createInternal(GLenum type, const CString& source,
 		switch(m_type)
 		{
 		case GL_VERTEX_SHADER:
-			ext = ".vert";
+			ext = "vert";
 			break;
 		case GL_TESS_CONTROL_SHADER:
-			ext = ".tesc";
+			ext = "tesc";
 			break;
 		case GL_TESS_EVALUATION_SHADER:
-			ext = ".tese";
+			ext = "tese";
 			break;
 		case GL_GEOMETRY_SHADER:
-			ext = ".geom";
+			ext = "geom";
 			break;
 		case GL_FRAGMENT_SHADER:
-			ext = ".frag";
+			ext = "frag";
 			break;
 		case GL_COMPUTE_SHADER:
-			ext = ".comp";
+			ext = "comp";
 			break;
 		default:
 			ext = nullptr;
 			ANKI_ASSERT(0);
 		}
 
-		std::stringstream fname;
-		fname << cacheDir << "/" 
-			<< std::setfill('0') << std::setw(4) << (U32)m_glName << ext;
+		String fname(alloc);
+		fname.sprintf(
+			"%s/%05u.%s", &cacheDir[0], static_cast<U32>(m_glName), ext);
 
-		File file(fname.str().c_str(), File::OpenFlag::WRITE);
+		File file(fname.toCString(), File::OpenFlag::WRITE);
 		file.writeText("%s", &fullSrc[0]);
 	}
 #endif
@@ -500,7 +497,9 @@ void GlProgram::createInternal(GLenum type, const CString& source,
 			U, 
 			std::hash<U>,
 			std::equal_to<U>,
-			HeapAllocator<std::pair<U, U>>> unitToCount;
+			HeapAllocator<std::pair<U, U>>> 
+			unitToCount(10, std::hash<U>(), std::equal_to<U>(), alloc);
+
 		for(const GlProgramVariable& var : m_data->m_variables)
 		{
 			if(isSampler(var.m_dataType))

+ 1 - 1
src/gl/GlQueue.cpp

@@ -142,7 +142,7 @@ void GlQueue::prepare()
 	// Ignore the first error
 	glGetError();
 
-	ANKI_LOGI("OpenGL info: OGL %s, GLSL %s",
+	ANKI_LOGI("OpenGL async thread started: OpenGL version %s, GLSL version %s",
 		reinterpret_cast<const char*>(glGetString(GL_VERSION)),
 		reinterpret_cast<const char*>(
 		glGetString(GL_SHADING_LANGUAGE_VERSION)));

+ 2 - 1
src/renderer/Renderer.cpp

@@ -28,6 +28,7 @@ Renderer::Renderer(
 	m_pps(this),
 	m_bs(this),
 	m_dbg(this), 
+	m_tiler(this),
 	m_sceneDrawer(this)
 {}
 
@@ -78,7 +79,7 @@ void Renderer::init(const ConfigSet& config)
 	m_drawQuadVert.load("shaders/Quad.vert.glsl", m_resources);
 
 	// Init the stages. Careful with the order!!!!!!!!!!
-	m_tiler.init(this);
+	m_tiler.init();
 
 	m_ms.init(config);
 	m_is.init(config);

+ 12 - 12
src/renderer/Tiler.cpp

@@ -200,7 +200,8 @@ struct UpdatePlanesPerspectiveCameraJob: Threadpool::Task
 //==============================================================================
 
 //==============================================================================
-Tiler::Tiler()
+Tiler::Tiler(Renderer* r)
+:	RenderingPass(r)
 {}
 
 //==============================================================================
@@ -208,11 +209,11 @@ Tiler::~Tiler()
 {}
 
 //==============================================================================
-void Tiler::init(Renderer* r)
+void Tiler::init()
 {
 	try
 	{
-		initInternal(r);
+		initInternal();
 	}
 	catch(const std::exception& e)
 	{
@@ -221,12 +222,10 @@ void Tiler::init(Renderer* r)
 }
 
 //==============================================================================
-void Tiler::initInternal(Renderer* r)
+void Tiler::initInternal()
 {
-	m_r = r;
-
 	// Load the program
-	String pps(r->_getAllocator());
+	String pps(getAllocator());
 	pps.sprintf(
 		"#define TILES_X_COUNT %u\n"
 		"#define TILES_Y_COUNT %u\n"
@@ -237,7 +236,7 @@ void Tiler::initInternal(Renderer* r)
 		m_r->getWidth(),
 		m_r->getHeight());
 
-	m_frag.loadToCache(&m_r->_getResourceManager(),
+	m_frag.loadToCache(&getResourceManager(),
 		"shaders/TilerMinMax.frag.glsl", pps.toCString(), "r_");
 
 	m_ppline = m_r->createDrawQuadProgramPipeline(m_frag->getGlProgram());
@@ -246,7 +245,7 @@ void Tiler::initInternal(Renderer* r)
 	m_r->createRenderTarget(m_r->getTilesCount().x(), m_r->getTilesCount().y(),
 		GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT, 1, m_rt);
 
-	GlCommandBufferHandle cmdBuff(&m_r->_getGlDevice());
+	GlCommandBufferHandle cmdBuff(&getGlDevice());
 
 	m_fb = GlFramebufferHandle(cmdBuff, {{m_rt, GL_COLOR_ATTACHMENT0}});
 
@@ -260,10 +259,11 @@ void Tiler::initInternal(Renderer* r)
 	// Init planes. One plane for each direction, plus near/far plus the world
 	// space of those
 	U planesCount = 
-		(r->getTilesCount().x() - 1) * 2 // planes J
-		+ (r->getTilesCount().y() - 1) * 2  // planes I
-		+ (r->getTilesCount().x() * r->getTilesCount().y() * 2); // near+far
+		(m_r->getTilesCount().x() - 1) * 2 // planes J
+		+ (m_r->getTilesCount().y() - 1) * 2  // planes I
+		+ (m_r->getTilesCount().x() * m_r->getTilesCount().y() * 2); // near+far
 
+	m_allPlanes = std::move(Vector<Plane>(getAllocator()));
 	m_allPlanes.resize(planesCount);
 
 	m_planesX = &m_allPlanes[0];

+ 1 - 1
src/resource/Image.cpp

@@ -467,7 +467,7 @@ void Image::load(const CString& filename, U32 maxTextureSize)
 	HeapAllocator<U8> alloc = m_surfaces.get_allocator();
 	String ext = getFileExtension(filename, alloc);
 	
-	if(ext == nullptr)
+	if(ext.isEmpty())
 	{
 		throw ANKI_EXCEPTION("Failed to get filename extension");
 	}

+ 22 - 28
src/resource/ProgramPrePreprocessor.cpp

@@ -82,49 +82,43 @@ void ProgramPrePreprocessor::parseFileForPragmas(
 	for(const PPPString& line : lines)
 	{
 		PtrSize npos = 0;
-		Bool expectPragmaAnki = false;
-		Bool gotPragmaAnki = true;
 
 		if(line.find("#pragma anki") == 0)
 		{
-			expectPragmaAnki = true;
-		}
+			Bool malformed = true;
 
-		if(parseType(line))
-		{
-			// Do nothing
-		}
-		else if((npos = line.find(commands[6])) == 0)
-		{
-			// Include
-
-			if(line.getLength() >= std::strlen(commands[6]) + 2)
+			if(parseType(line))
+			{
+				malformed = false; // All OK
+			}
+			else if((npos = line.find(commands[6])) == 0)
 			{
-				PPPString filen(
-					line.begin() + std::strlen(commands[6]), 
-					line.end() - 2, 
-					alloc);
+				// Include
 
-				filen = m_manager->fixResourceFilename(filen.toCString());
+				if(line.getLength() >= std::strlen(commands[6]) + 2)
+				{
+					PPPString filen(
+						line.begin() + std::strlen(commands[6]), 
+						line.end() - 1, 
+						alloc);
 
-				parseFileForPragmas(filen, depth + 1);
+					filen = m_manager->fixResourceFilename(filen.toCString());
+
+					parseFileForPragmas(filen, depth + 1);
+
+					malformed = false; // All OK
+				}
 			}
-			else
+
+			if(malformed)
 			{
-				gotPragmaAnki = false;
+				throw ANKI_EXCEPTION("Malformed pragma anki: %s", &line[0]);
 			}
 		}
 		else
 		{
-			gotPragmaAnki = false;
 			m_sourceLines.push_back(line);
 		}
-
-		// Sanity check
-		if(expectPragmaAnki && !gotPragmaAnki)
-		{
-			throw ANKI_EXCEPTION("Malformed pragma anki: %s", &line[0]);
-		}
 	}
 
 	// Sanity checks