Browse Source

Minor build fixes

Panagiotis Christopoulos Charitos 13 years ago
parent
commit
79db3ba2ea

+ 1 - 1
CMakeLists.txt

@@ -138,7 +138,7 @@ ADD_DEFINITIONS("-Dthread_local=__thread")
 #
 # Compiler flags
 #
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors -pedantic -ansi -Wall -W -Wextra -Wwrite-strings -Wno-unused -Wunused-variable -Werror -msse4 -std=c++11 ")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors -pedantic -ansi -Wall -W -Wextra -Wwrite-strings -Wno-unused -Wundef -Wunused-variable -Werror -msse4 -std=c++11 ")
 
 IF(CMAKE_BUILD_TYPE STREQUAL Debug)
 	# Removed because they do not work with boost::regexpr and who knows what

+ 2 - 2
include/anki/Config.h.cmake

@@ -23,8 +23,8 @@
 #	define ANKI_GL ANKI_GL_ES
 #endif
 
-#if !NDEBUG
-#	define ANKI_DEBUG 1
+#if defined(NDEBUG)
+#	define ANKI_DEBUG NDEBUG
 #else
 #	define ANKI_DEBUG 0
 #endif

+ 1 - 1
include/anki/gl/BufferObject.h

@@ -146,7 +146,7 @@ private:
 	GLenum usage; ///< GL_STREAM_DRAW or GL_STATIC_DRAW or GL_DYNAMIC_DRAW
 	U32 sizeInBytes; ///< The size of the buffer
 
-#if !NDEBUG
+#if ANKI_DEBUG
 	Bool mapped = false; ///< Only in debug
 #endif
 };

+ 3 - 1
include/anki/gl/GlException.h

@@ -1,13 +1,15 @@
 #ifndef ANKI_GL_GL_EXCEPTION_H
 #define ANKI_GL_GL_EXCEPTION_H
 
+#include "anki/Config.h"
+
 namespace anki {
 
 /// The function throws an exception if there is an OpenGL error. Use it with
 /// the ANKI_CHECK_GL_ERROR macro
 void glConditionalThrowException(const char* file, int line, const char* func);
 
-#if !defined(NDEBUG)
+#if ANKI_DEBUG
 #	define ANKI_CHECK_GL_ERROR() \
 		glConditionalThrowException(__FILE__, __LINE__, __func__)
 #else

+ 1 - 1
include/anki/gl/Ogl.h

@@ -17,7 +17,7 @@
 // The following macros are used for sanity checks in non sharable GL objects.
 // They help us avoid binding those objects from other than the creation 
 // threads. They are enabled only on debug
-#if NDEBUG
+#if !ANKI_DEBUG
 #	include <thread>
 
 #	define ANKI_GL_NON_SHARABLE std::thread::id creationThreadId;

+ 6 - 1
include/anki/gl/ShaderProgram.h

@@ -117,6 +117,11 @@ public:
 		return *this;
 	}
 
+	const ShaderProgramUniformBlock* getUniformBlock() const
+	{
+		return block;
+	}
+
 	/// @name Set the var
 	/// @{
 	void set(const F32 x) const;
@@ -203,7 +208,7 @@ private:
 
 	/// Do common checks
 	template<typename T>
-	void setClientMemoryChecks(U32 buffSize, U32 size) const;
+	void setClientMemorySanityChecks(U32 buffSize, U32 size) const;
 
 	/// Do the actual job of setClientMemory
 	template<typename T>

+ 0 - 4
include/anki/gl/Vao.h

@@ -102,12 +102,10 @@ public:
 	    GLsizei stride,
 	    const GLvoid* pointer);
 
-#if !defined(NDEBUG)
 	int getAttachmentsCount() const
 	{
 		return attachments;
 	}
-#endif
 
 	/// Attach an element array buffer VBO
 	void attachElementArrayBufferVbo(const Vbo& vbo);
@@ -140,9 +138,7 @@ public:
 private:
 	static thread_local const Vao* current;
 	GLuint glId = 0; ///< The OpenGL id
-#if !defined(NDEBUG)
 	U32 attachments = 0;
-#endif
 
 	bool isCreated() const
 	{

+ 19 - 19
include/anki/resource/Material.h

@@ -43,7 +43,7 @@ public:
 	MaterialVariable(
 		const char* shaderProgVarName,
 		PassLevelToShaderProgramHashMap& sProgs,
-		bool init_)
+		Bool init_)
 		: initialized(init_)
 	{
 		init(shaderProgVarName, sProgs);
@@ -84,7 +84,7 @@ public:
 	/// Get the name of all the shader program variables
 	const std::string& getName() const;
 
-	bool getInitialized() const
+	Bool getInitialized() const
 	{
 		return initialized;
 	}
@@ -94,7 +94,7 @@ private:
 	/// If not initialized then there is no value given in the XML so it is
 	/// probably build in and the renderer should set the value on the shader
 	/// program setup
-	bool initialized;
+	Bool initialized;
 	PassLevelToShaderProgramUniformVariableHashMap sProgVars;
 
 	/// Keep one ShaderProgramVariable here for easy access of the common
@@ -117,7 +117,7 @@ public:
 		const char* shaderProgVarName,
 		PassLevelToShaderProgramHashMap& sProgs,
 		const Data& val,
-		bool init_)
+		Bool init_)
 		: MaterialVariable(shaderProgVarName, sProgs, init_)
 	{
 		setupVisitable(&data);
@@ -162,57 +162,57 @@ public:
 		return passes;
 	}
 
-	uint getLevelsOfDetail() const
+	U32 getLevelsOfDetail() const
 	{
 		return levelsOfDetail;
 	}
 
-	bool getShadow() const
+	Bool getShadow() const
 	{
 		return shadow;
 	}
 
-	int getBlendingSfactor() const
+	GLenum getBlendingSfactor() const
 	{
 		return blendingSfactor;
 	}
 
-	int getBlendingDfactor() const
+	GLenum getBlendingDfactor() const
 	{
 		return blendingDfactor;
 	}
 
-	bool getDepthTestingEnabled() const
+	Bool getDepthTestingEnabled() const
 	{
 		return depthTesting;
 	}
 
-	bool getWireframe() const
+	Bool getWireframe() const
 	{
 		return wireframe;
 	}
 	/// @}
 
 	/// Check if blending is enabled
-	bool isBlendingEnabled() const
+	Bool isBlendingEnabled() const
 	{
 		return blendingSfactor != GL_ONE || blendingDfactor != GL_ZERO;
 	}
 protected:
-	uint renderingStage = 0;
+	U32 renderingStage = 0;
 
 	StringList passes;
 
-	uint levelsOfDetail = 1;
+	U32 levelsOfDetail = 1;
 
-	bool shadow = true;
+	Bool shadow = true;
 
-	int blendingSfactor = GL_ONE; ///< Default GL_ONE
-	int blendingDfactor = GL_ZERO; ///< Default GL_ZERO
+	GLenum blendingSfactor = GL_ONE; ///< Default GL_ONE
+	GLenum blendingDfactor = GL_ZERO; ///< Default GL_ZERO
 
-	bool depthTesting = true;
+	Bool depthTesting = true;
 
-	bool wireframe = false;
+	Bool wireframe = false;
 };
 
 /// Material resource
@@ -331,7 +331,7 @@ public:
 	void load(const char* filename);
 
 	/// For sorting
-	bool operator<(const Material& b) const
+	Bool operator<(const Material& b) const
 	{
 		return fname < b.fname;
 	}

+ 3 - 1
include/anki/util/Assert.h

@@ -1,9 +1,11 @@
 #ifndef ANKI_UTIL_ASSERT_H
 #define ANKI_UTIL_ASSERT_H
 
+#include "anki/Config.h"
+
 /// Assertion. Print an error and stop the debugger (if it runs through a
 /// debugger) and then abort
-#if defined(NDEBUG)
+#if !ANKI_DEBUG
 #	define ANKI_ASSERT(x) ((void)0)
 #	define ANKI_ASSERTS_ENABLED 0
 #else

+ 7 - 7
include/anki/util/Visitor.h

@@ -269,7 +269,7 @@ class VisitableCommonBase
 {
 public:
 
-#if !defined(NDEBUG)
+#if ANKI_DEBUG
 	// Allow dynamic cast in acceptVisitor
 	virtual ~VisitableCommonBase()
 	{}
@@ -291,11 +291,11 @@ public:
 	void acceptVisitor(TVisitor& v)
 	{
 		ANKI_ASSERT(what != -1);
-#if defined(NDEBUG)
-		TBase* base = static_cast<TBase*>(this);
-#else
+#if ANKI_DEBUG
 		TBase* base = dynamic_cast<TBase*>(this);
 		ANKI_ASSERT(base != nullptr);
+#else
+		TBase* base = static_cast<TBase*>(this);
 #endif
 		visitor_detail::VisitorWrapperCommonBase<TVisitor, TBase, Types...>::
 			jumpTable[what](v, *base);
@@ -307,11 +307,11 @@ public:
 	{
 		typedef const TBase CTBase;
 		ANKI_ASSERT(what != -1);
-#if defined(NDEBUG)
-		CTBase* base = static_cast<CTBase*>(this);
-#else
+#if ANKI_DEBUG
 		CTBase* base = dynamic_cast<CTBase*>(this);
 		ANKI_ASSERT(base != nullptr);
+#else
+		CTBase* base = static_cast<CTBase*>(this);
 #endif
 		visitor_detail::VisitorWrapperCommonBase
 			<TVisitor,CTBase, const Types...>::

+ 1 - 1
src/core/App.cpp

@@ -116,7 +116,7 @@ void App::printAppInfo()
 	std::stringstream msg;
 	msg << "App info: ";
 	msg << "AnKi " << ANKI_VERSION_MAJOR << "." << ANKI_VERSION_MINOR << ", ";
-#if NDEBUG
+#if !ANKI_DEBUG
 	msg << "Release";
 #else
 	msg << "Debug";

+ 4 - 4
src/gl/BufferObject.cpp

@@ -52,14 +52,14 @@ void BufferObject::create(GLenum target_, U32 sizeInBytes_,
 void* BufferObject::map(U32 offset, U32 length, GLuint flags)
 {
 	ANKI_ASSERT(isCreated());
-#if !NDEBUG
+#if ANKI_DEBUG
 	ANKI_ASSERT(mapped == false);
 #endif
 	bind();
 	ANKI_ASSERT(offset + length <= sizeInBytes);
 	void* mappedMem = glMapBufferRange(target, offset, length, flags);
 	ANKI_ASSERT(mappedMem != nullptr);
-#if !NDEBUG
+#if ANKI_DEBUG
 	mapped = true;
 #endif
 	return mappedMem;
@@ -69,12 +69,12 @@ void* BufferObject::map(U32 offset, U32 length, GLuint flags)
 void BufferObject::unmap()
 {
 	ANKI_ASSERT(isCreated());
-#if !NDEBUG
+#if ANKI_DEBUG
 	ANKI_ASSERT(mapped == true);
 #endif
 	bind();
 	glUnmapBuffer(target);
-#if !NDEBUG
+#if ANKI_DEBUG
 	mapped = false;
 #endif
 }

+ 8 - 8
src/gl/ShaderProgram.cpp

@@ -165,7 +165,7 @@ Bool checkType<Mat4>(GLenum glDataType)
 
 //==============================================================================
 template<typename T>
-void ShaderProgramUniformVariable::setClientMemoryChecks(
+void ShaderProgramUniformVariable::setClientMemorySanityChecks(
 	U32 buffSize, U32 size) const
 {
 	ANKI_ASSERT(checkType<T>(getGlDataType()));
@@ -180,7 +180,7 @@ template<typename T>
 void ShaderProgramUniformVariable::setClientMemoryInternal(
 	void* buff_, U32 buffSize, const T arr[], U32 size) const
 {
-	setClientMemoryChecks<T>(buffSize, size);
+	setClientMemorySanityChecks<T>(buffSize, size);
 	U8* buff = (U8*)buff_ + offset;
 
 	for(U32 i = 0; i < size; i++)
@@ -196,7 +196,7 @@ template<typename T, typename Vec>
 void ShaderProgramUniformVariable::setClientMemoryInternalMatrix(
 	void* buff_, U32 buffSize, const T arr[], U32 size) const
 {
-	setClientMemoryChecks<T>(buffSize, size);
+	setClientMemorySanityChecks<T>(buffSize, size);
 	ANKI_ASSERT(matrixStride >= (GLint)sizeof(Vec));
 	U8* buff = (U8*)buff_ + offset;
 
@@ -281,14 +281,14 @@ ShaderProgramUniformBlock& ShaderProgramUniformBlock::operator=(
 const char* ShaderProgram::stdSourceCode =
 	"#version 420 core\n"
 	//"precision lowp float;\n"
-#if defined(NDEBUG)
-	"#pragma optimize(on)\n"
-	"#pragma debug(off)\n"
-	"#extension GL_ARB_gpu_shader5 : enable\n";
-#else
+#if ANKI_DEBUG
 	"#pragma optimize(off)\n"
 	"#pragma debug(on)\n"
 	"#extension GL_ARB_gpu_shader5 : enable\n";
+#else
+	"#pragma optimize(on)\n"
+	"#pragma debug(off)\n"
+	"#extension GL_ARB_gpu_shader5 : enable\n";
 #endif
 
 thread_local const ShaderProgram* ShaderProgram::current = nullptr;

+ 0 - 4
src/gl/Vao.cpp

@@ -38,9 +38,7 @@ void Vao::attachArrayBufferVbo(const Vbo& vbo, GLuint attribVarLocation,
 
 	ANKI_CHECK_GL_ERROR();
 
-#if !defined(NDEBUG)
 	++attachments;
-#endif
 }
 
 //==============================================================================
@@ -66,9 +64,7 @@ void Vao::attachElementArrayBufferVbo(const Vbo& vbo)
 	unbind();
 	ANKI_CHECK_GL_ERROR();
 
-#if !defined(NDEBUG)
 	++attachments;
-#endif
 }
 
 } // end namespace anki

+ 5 - 4
src/math/Functions.cpp

@@ -1,4 +1,5 @@
 #include "anki/math/Functions.h"
+#include "anki/Config.h"
 
 namespace anki {
 
@@ -14,7 +15,10 @@ static Scalar polynomialSinQuadrant(const Scalar a)
 template<typename Scalar>
 static void sinCosInternal(const Scalar a_, Scalar& sina, Scalar& cosa)
 {
-#if NDEBUG
+#if ANKI_DEBUG
+	sina = sin(a_);
+	cosa = cos(a_);
+#else
 	Bool negative = false;
 	Scalar a = a_;
 	if(a < 0.0)
@@ -57,9 +61,6 @@ static void sinCosInternal(const Scalar a_, Scalar& sina, Scalar& cosa)
 	{
 		sina = -sina;
 	}
-#else
-	sina = sin(a_);
-	cosa = cos(a_);
 #endif
 }
 

+ 0 - 2
src/renderer/Drawer.cpp

@@ -706,9 +706,7 @@ void RenderableDrawer::render(const Frustumable& fr, uint pass,
 		renderable.getModelPatchBase().getIndecesNumber(0);
 
 	const Vao& vao = renderable.getModelPatchBase().getVao(key);
-#if !NDEBUG
 	ANKI_ASSERT(vao.getAttachmentsCount() > 1);
-#endif
 	vao.bind();
 	glDrawElements(GL_TRIANGLES, indecesNum, GL_UNSIGNED_SHORT, 0);
 	vao.unbind();

+ 1 - 1
src/resource/TextureResource.cpp

@@ -78,7 +78,7 @@ void TextureResource::load(const Image& img)
 	case Image::DC_NONE:
 		break;
 
-#if !DRIVER_CAN_COMPRESS
+#if DRIVER_CAN_COMPRESS
 	case Image::DC_DXT1:
 		init.internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
 		break;

+ 2 - 1
src/util/Assert.cpp

@@ -1,9 +1,10 @@
+#include "anki/util/Assert.h"
 #include <cstdlib>
 #include <iostream>
 
 namespace anki {
 
-#if !defined(NDEBUG)
+#if ANKI_DEBUG
 
 //==============================================================================
 void akassert(bool expr, const char* exprTxt, const char* file, int line,

+ 10 - 2
src/util/HighRezTimerPosix.cpp

@@ -1,10 +1,18 @@
 #include "anki/util/HighRezTimer.h"
 #include "anki/util/Assert.h"
-
 #include <sys/time.h>
 #include <signal.h>
 #include <unistd.h>
 #include <errno.h>
+
+#if !defined(HAVE_NANOSLEEP)
+#	define HAVE_NANOSLEEP 0
+#endif
+
+#if !defined(HAVE_CLOCK_GETTIME)
+#	define HAVE_CLOCK_GETTIME 0
+#endif
+
 #if HAVE_NANOSLEEP || HAVE_CLOCK_GETTIME
 #	include <time.h>
 #endif
@@ -13,7 +21,7 @@ namespace anki {
 
 //==============================================================================
 // The first ticks value of the application
-#ifdef HAVE_CLOCK_GETTIME
+#if HAVE_CLOCK_GETTIME
 static struct timespec gstart;
 #else
 static struct timeval gstart;