Browse Source

Make AnKi build with Visual Studio 2017

Panagiotis Christopoulos Charitos 8 years ago
parent
commit
0f7e51a97c

+ 59 - 51
CMakeLists.txt

@@ -138,10 +138,12 @@ set(LINKER_FLAGS "")
 
 
 add_definitions(-D_NEWTON_STATIC_LIB -D_CUSTOM_JOINTS_STATIC_LIB)
 add_definitions(-D_NEWTON_STATIC_LIB -D_CUSTOM_JOINTS_STATIC_LIB)
 
 
-if(ARCH_64)
-	add_definitions(-D_POSIX_VER_64)
-else()
-	add_definitions(-D_POSIX_VER_32)
+if(NOT MSVC)
+	if(ARCH_64)
+		add_definitions(-D_POSIX_VER_64)
+	else()
+		add_definitions(-D_POSIX_VER_32)
+	endif()
 endif()
 endif()
 
 
 # Newton wants that
 # Newton wants that
@@ -159,65 +161,67 @@ add_definitions(-DGLEW_NO_GLU)
 add_definitions(-DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
 add_definitions(-DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
 add_definitions(-DANKI_BUILD)
 add_definitions(-DANKI_BUILD)
 
 
-# When building AnKi define this special flag
-set(COMPILER_FLAGS "${COMPILER_FLAGS} -fPIC ")
+if(NOT MSVC)
+	# When building AnKi define this special flag
+	set(COMPILER_FLAGS "${COMPILER_FLAGS} -fPIC ")
 
 
-if(NOT ANKI_CPU_ADDR_SPACE STREQUAL "0")
-	set(LINKER_FLAGS "${LINKER_FLAGS} -m${ANKI_CPU_ADDR_SPACE} ")
-	set(COMPILER_FLAGS "${COMPILER_FLAGS} -m${ANKI_CPU_ADDR_SPACE} ")
-endif()
+	if(NOT ANKI_CPU_ADDR_SPACE STREQUAL "0")
+		set(LINKER_FLAGS "${LINKER_FLAGS} -m${ANKI_CPU_ADDR_SPACE} ")
+		set(COMPILER_FLAGS "${COMPILER_FLAGS} -m${ANKI_CPU_ADDR_SPACE} ")
+	endif()
 
 
-set(COMPILER_FLAGS "${COMPILER_FLAGS} -fno-exceptions ")
+	set(COMPILER_FLAGS "${COMPILER_FLAGS} -fno-exceptions ")
 
 
-if(GCC AND NOT CLANG)
-	set(CXX_FLAGS "${CXX_FLAGS} -static-libstdc++ ")
-endif()
+	if(GCC AND NOT CLANG)
+		set(CXX_FLAGS "${CXX_FLAGS} -static-libstdc++ ")
+	endif()
 
 
-if(ANKI_ENABLE_SIMD)
-	if(LINUX OR MACOS OR WINDOWS)
-		set(COMPILER_FLAGS "${COMPILER_FLAGS} -msse4 ")
-	else()
-		set(COMPILER_FLAGS "${COMPILER_FLAGS} -mfpu=neon ")
+	if(ANKI_ENABLE_SIMD)
+		if(LINUX OR MACOS OR WINDOWS)
+			set(COMPILER_FLAGS "${COMPILER_FLAGS} -msse4 ")
+		else()
+			set(COMPILER_FLAGS "${COMPILER_FLAGS} -mfpu=neon ")
+		endif()
 	endif()
 	endif()
-endif()
 
 
-if(ANKI_LTO)
-	set(COMPILER_FLAGS "${COMPILER_FLAGS} -flto ")
-	set(LINKER_FLAGS "${LINKER_FLAGS} -flto ")
-endif()
+	if(ANKI_LTO)
+		set(COMPILER_FLAGS "${COMPILER_FLAGS} -flto ")
+		set(LINKER_FLAGS "${LINKER_FLAGS} -flto ")
+	endif()
 
 
-if(ANKI_STRIP)
-	set(LINKER_FLAGS "${LINKER_FLAGS} -s ")
-	set(COMPILER_FLAGS "${COMPILER_FLAGS} -s ")
-endif()
+	if(ANKI_STRIP)
+		set(LINKER_FLAGS "${LINKER_FLAGS} -s ")
+		set(COMPILER_FLAGS "${COMPILER_FLAGS} -s ")
+	endif()
 
 
-if(ANKI_ADDRESS_SANITIZER)
-	set(COMPILER_FLAGS "${COMPILER_FLAGS} -fsanitize=address ")
-endif()
+	if(ANKI_ADDRESS_SANITIZER)
+		set(COMPILER_FLAGS "${COMPILER_FLAGS} -fsanitize=address ")
+	endif()
 
 
-if(${CMAKE_BUILD_TYPE} STREQUAL "Release")
-	set(COMPILER_FLAGS "${COMPILER_FLAGS} -O3 -DNDEBUG ")
+	if(${CMAKE_BUILD_TYPE} STREQUAL "Release")
+		set(COMPILER_FLAGS "${COMPILER_FLAGS} -O3 -DNDEBUG ")
 
 
-	set(CMAKE_CXX_FLAGS_RELEASE "")
-	set(CMAKE_C_FLAGS_RELEASE "")
-elseif(${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
-	set(COMPILER_FLAGS "${COMPILER_FLAGS} -O3 -g3 ")
+		set(CMAKE_CXX_FLAGS_RELEASE "")
+		set(CMAKE_C_FLAGS_RELEASE "")
+	elseif(${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
+		set(COMPILER_FLAGS "${COMPILER_FLAGS} -O3 -g3 ")
 
 
-	set(CMAKE_CXX_FLAGS_RELWITHDBGINFO "")
-	set(CMAKE_C_FLAGS_RELWITHDBGINFO "")
-elseif(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
-	set(COMPILER_FLAGS "${COMPILER_FLAGS} -O0 -g3 ")
+		set(CMAKE_CXX_FLAGS_RELWITHDBGINFO "")
+		set(CMAKE_C_FLAGS_RELWITHDBGINFO "")
+	elseif(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
+		set(COMPILER_FLAGS "${COMPILER_FLAGS} -O0 -g3 ")
 
 
-	set(CMAKE_CXX_FLAGS_DEBUG "")
-	set(CMAKE_C_FLAGS_DEBUG "")
-else()
-	message(FATAL_ERROR "Wrong CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
-endif()
+		set(CMAKE_CXX_FLAGS_DEBUG "")
+		set(CMAKE_C_FLAGS_DEBUG "")
+	else()
+		message(FATAL_ERROR "Wrong CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
+	endif()
 
 
-# Set the flags to cmake now
-set(CMAKE_CXX_FLAGS "${CXX_FLAGS} ${COMPILER_FLAGS}")
-set(CMAKE_C_FLAGS "${COMPILER_FLAGS}")
-set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}")
+	# Set the flags to cmake now
+	set(CMAKE_CXX_FLAGS "${CXX_FLAGS} ${COMPILER_FLAGS}")
+	set(CMAKE_C_FLAGS "${COMPILER_FLAGS}")
+	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}")
+endif()
 
 
 ################################################################################
 ################################################################################
 # Thirdparty                                                                   #
 # Thirdparty                                                                   #
@@ -364,7 +368,11 @@ if(ANDROID)
 endif()
 endif()
 
 
 # AnKi compiler flags (Mainly warnings)
 # AnKi compiler flags (Mainly warnings)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -W -Wextra -Wstrict-aliasing -Wwrite-strings -Wunused -Wunused-variable -Wno-unused-parameter -Wundef -Wno-ignored-attributes -Wunused-result -std=c++14")
+if(NOT MSVC)
+	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -W -Wextra -Wstrict-aliasing -Wwrite-strings -Wunused -Wunused-variable -Wno-unused-parameter -Wundef -Wno-ignored-attributes -Wunused-result -std=c++14")
+else()
+	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4996 /wd4244 /wd4262 /wd4267")
+endif()
 
 
 # Set platform specific
 # Set platform specific
 if(LINUX)
 if(LINUX)

+ 5 - 5
samples/common/Framework.cpp

@@ -29,10 +29,10 @@ Error SampleApp::init(int argc, char** argv, CString sampleName)
 	// Input
 	// Input
 	getInput().lockCursor(true);
 	getInput().lockCursor(true);
 	getInput().hideCursor(true);
 	getInput().hideCursor(true);
-	getInput().moveCursor(Vec2(0.0));
+	getInput().moveCursor(Vec2(0.0f));
 
 
 	// Some renderer stuff
 	// Some renderer stuff
-	getMainRenderer().getOffscreenRenderer().getVolumetric().setFogParticleColor(Vec3(1.0, 0.9, 0.9) * 0.0001);
+	getMainRenderer().getOffscreenRenderer().getVolumetric().setFogParticleColor(Vec3(1.0f, 0.9f, 0.9f) * 0.0001f);
 
 
 	ANKI_CHECK(sampleExtraInit());
 	ANKI_CHECK(sampleExtraInit());
 
 
@@ -41,9 +41,9 @@ Error SampleApp::init(int argc, char** argv, CString sampleName)
 
 
 Error SampleApp::userMainLoop(Bool& quit)
 Error SampleApp::userMainLoop(Bool& quit)
 {
 {
-	const F32 MOVE_DISTANCE = 0.1;
-	const F32 ROTATE_ANGLE = toRad(2.5);
-	const F32 MOUSE_SENSITIVITY = 9.0;
+	const F32 MOVE_DISTANCE = 0.1f;
+	const F32 ROTATE_ANGLE = toRad(2.5f);
+	const F32 MOUSE_SENSITIVITY = 9.0f;
 	quit = false;
 	quit = false;
 
 
 	SceneGraph& scene = getSceneGraph();
 	SceneGraph& scene = getSceneGraph();

+ 16 - 0
src/anki/Config.h.cmake

@@ -82,6 +82,16 @@
 #	else
 #	else
 #		error "Unknown CPU arch"
 #		error "Unknown CPU arch"
 #	endif
 #	endif
+#elif ANKI_COMPILER == ANKI_COMPILER_MSVC
+#	if defined(_M_ARM)
+#		define ANKI_CPU_ARCH ANKI_CPU_ARCH_ARM
+#		define ANKI_CPU_ARCH_STR "ANKI_CPU_ARCH_ARM"
+#	elif defined(_M_X64) || defined(_M_IX86)
+#		define ANKI_CPU_ARCH ANKI_CPU_ARCH_INTEL
+#		define ANKI_CPU_ARCH_STR "ANKI_CPU_ARCH_INTEL"
+#	else
+#		error "Unknown CPU arch"
+#	endif
 #else
 #else
 #	error "Unsupported compiler"
 #	error "Unsupported compiler"
 #endif
 #endif
@@ -163,6 +173,12 @@
 #	define ANKI_END_PACKED_STRUCT _Pragma("pack (pop)")
 #	define ANKI_END_PACKED_STRUCT _Pragma("pack (pop)")
 #endif
 #endif
 
 
+// Popcount
+#ifdef _MSC_VER
+#	include <intrin.h>
+#	define __builtin_popcount __popcnt
+#endif
+
 #ifdef ANKI_BUILD
 #ifdef ANKI_BUILD
 #	define anki_internal public
 #	define anki_internal public
 #else
 #else

+ 1 - 1
src/anki/core/App.cpp

@@ -182,7 +182,7 @@ Error App::initInternal(const ConfigSet& config_, AllocAlignedCallback allocCb,
 	m_timerTick = 1.0 / 60.0; // in sec. 1.0 / period
 	m_timerTick = 1.0 / 60.0; // in sec. 1.0 / period
 
 
 // Check SIMD support
 // Check SIMD support
-#if ANKI_SIMD == ANKI_SIMD_SSE
+#if ANKI_SIMD == ANKI_SIMD_SSE && ANKI_COMPILER != ANKI_COMPILER_MSVC
 	if(!__builtin_cpu_supports("sse4.2"))
 	if(!__builtin_cpu_supports("sse4.2"))
 	{
 	{
 		ANKI_CORE_LOGF(
 		ANKI_CORE_LOGF(

+ 1 - 1
src/anki/core/App.h

@@ -164,7 +164,7 @@ private:
 	ThreadHive* m_threadHive = nullptr;
 	ThreadHive* m_threadHive = nullptr;
 	String m_settingsDir; ///< The path that holds the configuration
 	String m_settingsDir; ///< The path that holds the configuration
 	String m_cacheDir; ///< This is used as a cache
 	String m_cacheDir; ///< This is used as a cache
-	F32 m_timerTick;
+	Second m_timerTick;
 	U64 m_resourceCompletedAsyncTaskCount = 0;
 	U64 m_resourceCompletedAsyncTaskCount = 0;
 
 
 	ANKI_USE_RESULT Error initInternal(const ConfigSet& config, AllocAlignedCallback allocCb, void* allocCbUserData);
 	ANKI_USE_RESULT Error initInternal(const ConfigSet& config, AllocAlignedCallback allocCb, void* allocCbUserData);

+ 1 - 1
src/anki/core/CMakeLists.txt

@@ -1,4 +1,4 @@
-set(SOURCES App.cpp StdinListener.cpp Config.cpp Trace.cpp StagingGpuMemoryManager.cpp)
+set(SOURCES App.cpp Config.cpp Trace.cpp StagingGpuMemoryManager.cpp)
 
 
 if(SDL)
 if(SDL)
 	set(SOURCES ${SOURCES} NativeWindowSdl.cpp)
 	set(SOURCES ${SOURCES} NativeWindowSdl.cpp)

+ 1 - 1
src/anki/gr/gl/GlState.cpp

@@ -40,7 +40,7 @@ static const GlDbg gldbgseverity[] = {{GL_DEBUG_SEVERITY_LOW, "GL_DEBUG_SEVERITY
 	{GL_DEBUG_SEVERITY_MEDIUM, "GL_DEBUG_SEVERITY_MEDIUM"},
 	{GL_DEBUG_SEVERITY_MEDIUM, "GL_DEBUG_SEVERITY_MEDIUM"},
 	{GL_DEBUG_SEVERITY_HIGH, "GL_DEBUG_SEVERITY_HIGH"}};
 	{GL_DEBUG_SEVERITY_HIGH, "GL_DEBUG_SEVERITY_HIGH"}};
 
 
-#if ANKI_OS == ANKI_OS_WINDOWS
+#if ANKI_OS == ANKI_OS_WINDOWS && ANKI_COMPILER != ANKI_COMPILER_MSVC
 __stdcall
 __stdcall
 #endif
 #endif
 	void
 	void

+ 1 - 7
src/anki/gr/vulkan/Common.h

@@ -15,13 +15,7 @@
 #error TODO
 #error TODO
 #endif
 #endif
 #include <vulkan/vulkan.h>
 #include <vulkan/vulkan.h>
-
-// I wonder whose stupid idea was to pollute the global namespace with defines like ERROR, near and far
-#if ANKI_OS == ANKI_OS_WINDOWS
-#undef ERROR
-#undef near
-#undef far
-#endif
+#include <anki/util/CleanupWindows.h> // Clean global namespace
 
 
 namespace anki
 namespace anki
 {
 {

+ 5 - 3
src/anki/math/Mat3x4.h

@@ -216,14 +216,16 @@ public:
 
 
 // Forward declare specializations
 // Forward declare specializations
 
 
+using TMat3x4F32Base = TMat3x4<F32>::Base;
+
 template<>
 template<>
-TMat3x4<F32>::Base::TMat(const TMat3x4<F32>::Base& b);
+TMat3x4F32Base::TMat(const TMat3x4F32Base& b);
 
 
 template<>
 template<>
-TMat3x4<F32>::Base::TMat(const F32 f);
+TMat3x4F32Base::TMat(const F32 f);
 
 
 template<>
 template<>
-inline TVec3<F32> TMat3x4<F32>::Base::operator*(const TVec4<F32>& b) const;
+inline TVec3<F32> TMat3x4F32Base::operator*(const TVec4<F32>& b) const;
 
 
 template<>
 template<>
 TMat3x4<F32> TMat3x4<F32>::combineTransformations(const TMat3x4<F32>& b) const;
 TMat3x4<F32> TMat3x4<F32>::combineTransformations(const TMat3x4<F32>& b) const;

+ 3 - 3
src/anki/math/Mat3x4.inl.h

@@ -11,7 +11,7 @@ namespace anki
 #if ANKI_SIMD == ANKI_SIMD_SSE
 #if ANKI_SIMD == ANKI_SIMD_SSE
 
 
 template<>
 template<>
-inline TMat3x4<F32>::Base::TMat(const TMat3x4<F32>::Base& b)
+inline TMat3x4F32Base::TMat(const TMat3x4F32Base& b)
 {
 {
 	for(U i = 0; i < 3; i++)
 	for(U i = 0; i < 3; i++)
 	{
 	{
@@ -20,7 +20,7 @@ inline TMat3x4<F32>::Base::TMat(const TMat3x4<F32>::Base& b)
 }
 }
 
 
 template<>
 template<>
-inline TMat3x4<F32>::Base::TMat(const F32 f)
+inline TMat3x4F32Base::TMat(const F32 f)
 {
 {
 	for(U i = 0; i < 3; i++)
 	for(U i = 0; i < 3; i++)
 	{
 	{
@@ -29,7 +29,7 @@ inline TMat3x4<F32>::Base::TMat(const F32 f)
 }
 }
 
 
 template<>
 template<>
-inline TVec3<F32> TMat3x4<F32>::Base::operator*(const TVec4<F32>& b) const
+inline TVec3<F32> TMat3x4F32Base::operator*(const TVec4<F32>& b) const
 {
 {
 	TVec3<F32> v;
 	TVec3<F32> v;
 
 

+ 14 - 12
src/anki/math/Mat4.h

@@ -470,41 +470,43 @@ public:
 
 
 // Forward declare specializations
 // Forward declare specializations
 
 
+using TMat4F32Base = TMat4<F32>::Base;
+
 template<>
 template<>
-TMat4<F32>::Base::TMat(const TMat4<F32>::Base& b);
+TMat4F32Base::TMat(const TMat4F32Base& b);
 
 
 template<>
 template<>
-TMat4<F32>::Base::TMat(const F32 f);
+TMat4F32Base::TMat(const F32 f);
 
 
 template<>
 template<>
-TMat4<F32>& TMat4<F32>::Base::operator=(const TMat4<F32>& b);
+TMat4<F32>& TMat4F32Base::operator=(const TMat4<F32>& b);
 
 
 template<>
 template<>
-TMat4<F32> TMat4<F32>::Base::operator+(const TMat4<F32>& b) const;
+TMat4<F32> TMat4F32Base::operator+(const TMat4<F32>& b) const;
 
 
 template<>
 template<>
-TMat4<F32>& TMat4<F32>::Base::operator+=(const TMat4<F32>& b);
+TMat4<F32>& TMat4F32Base::operator+=(const TMat4<F32>& b);
 
 
 template<>
 template<>
-TMat4<F32> TMat4<F32>::Base::operator-(const TMat4<F32>& b) const;
+TMat4<F32> TMat4F32Base::operator-(const TMat4<F32>& b) const;
 
 
 template<>
 template<>
-TMat4<F32>& TMat4<F32>::Base::operator-=(const TMat4<F32>& b);
+TMat4<F32>& TMat4F32Base::operator-=(const TMat4<F32>& b);
 
 
 template<>
 template<>
-TMat4<F32> TMat4<F32>::Base::operator*(const TMat4<F32>& b) const;
+TMat4<F32> TMat4F32Base::operator*(const TMat4<F32>& b) const;
 
 
 template<>
 template<>
-TVec4<F32> TMat4<F32>::Base::operator*(const TVec4<F32>& b) const;
+TVec4<F32> TMat4F32Base::operator*(const TVec4<F32>& b) const;
 
 
 template<>
 template<>
-void TMat4<F32>::Base::setRows(const TVec4<F32>& a, const TVec4<F32>& b, const TVec4<F32>& c, const TVec4<F32>& d);
+void TMat4F32Base::setRows(const TVec4<F32>& a, const TVec4<F32>& b, const TVec4<F32>& c, const TVec4<F32>& d);
 
 
 template<>
 template<>
-void TMat4<F32>::Base::setRow(const U i, const TVec4<F32>& v);
+void TMat4F32Base::setRow(const U i, const TVec4<F32>& v);
 
 
 template<>
 template<>
-void TMat4<F32>::Base::transpose();
+void TMat4F32Base::transpose();
 
 
 #elif ANKI_SIMD == ANKI_SIMD_NEON
 #elif ANKI_SIMD == ANKI_SIMD_NEON
 
 

+ 12 - 13
src/anki/math/Mat4.inl.h

@@ -49,7 +49,7 @@ TMat4<T> operator/(const T f, const TMat4<T>& m4)
 #if ANKI_SIMD == ANKI_SIMD_SSE
 #if ANKI_SIMD == ANKI_SIMD_SSE
 
 
 template<>
 template<>
-inline TMat4<F32>::Base::TMat(const TMat4<F32>::Base& b)
+inline TMat4F32Base::TMat(const TMat4F32Base& b)
 {
 {
 	for(U i = 0; i < 4; i++)
 	for(U i = 0; i < 4; i++)
 	{
 	{
@@ -58,7 +58,7 @@ inline TMat4<F32>::Base::TMat(const TMat4<F32>::Base& b)
 }
 }
 
 
 template<>
 template<>
-inline TMat4<F32>::Base::TMat(const F32 f)
+inline TMat4F32Base::TMat(const F32 f)
 {
 {
 	for(U i = 0; i < 4; i++)
 	for(U i = 0; i < 4; i++)
 	{
 	{
@@ -67,7 +67,7 @@ inline TMat4<F32>::Base::TMat(const F32 f)
 }
 }
 
 
 template<>
 template<>
-inline TMat4<F32>& TMat4<F32>::Base::operator=(const TMat4<F32>& b)
+inline TMat4<F32>& TMat4F32Base::operator=(const TMat4<F32>& b)
 {
 {
 	for(U i = 0; i < 4; i++)
 	for(U i = 0; i < 4; i++)
 	{
 	{
@@ -77,7 +77,7 @@ inline TMat4<F32>& TMat4<F32>::Base::operator=(const TMat4<F32>& b)
 }
 }
 
 
 template<>
 template<>
-inline TMat4<F32> TMat4<F32>::Base::operator+(const TMat4<F32>& b) const
+inline TMat4<F32> TMat4F32Base::operator+(const TMat4<F32>& b) const
 {
 {
 	TMat4<F32> c;
 	TMat4<F32> c;
 	for(U i = 0; i < 4; i++)
 	for(U i = 0; i < 4; i++)
@@ -88,7 +88,7 @@ inline TMat4<F32> TMat4<F32>::Base::operator+(const TMat4<F32>& b) const
 }
 }
 
 
 template<>
 template<>
-inline TMat4<F32>& TMat4<F32>::Base::operator+=(const TMat4<F32>& b)
+inline TMat4<F32>& TMat4F32Base::operator+=(const TMat4<F32>& b)
 {
 {
 	for(U i = 0; i < 4; i++)
 	for(U i = 0; i < 4; i++)
 	{
 	{
@@ -98,7 +98,7 @@ inline TMat4<F32>& TMat4<F32>::Base::operator+=(const TMat4<F32>& b)
 }
 }
 
 
 template<>
 template<>
-inline TMat4<F32> TMat4<F32>::Base::operator-(const TMat4<F32>& b) const
+inline TMat4<F32> TMat4F32Base::operator-(const TMat4<F32>& b) const
 {
 {
 	TMat4<F32> c;
 	TMat4<F32> c;
 	for(U i = 0; i < 4; i++)
 	for(U i = 0; i < 4; i++)
@@ -109,7 +109,7 @@ inline TMat4<F32> TMat4<F32>::Base::operator-(const TMat4<F32>& b) const
 }
 }
 
 
 template<>
 template<>
-inline TMat4<F32>& TMat4<F32>::Base::operator-=(const TMat4<F32>& b)
+inline TMat4<F32>& TMat4F32Base::operator-=(const TMat4<F32>& b)
 {
 {
 	for(U i = 0; i < 4; i++)
 	for(U i = 0; i < 4; i++)
 	{
 	{
@@ -119,7 +119,7 @@ inline TMat4<F32>& TMat4<F32>::Base::operator-=(const TMat4<F32>& b)
 }
 }
 
 
 template<>
 template<>
-inline TMat4<F32> TMat4<F32>::Base::operator*(const TMat4<F32>& b) const
+inline TMat4<F32> TMat4F32Base::operator*(const TMat4<F32>& b) const
 {
 {
 	TMat4<F32> out;
 	TMat4<F32> out;
 	const TMat4<F32>& m = *static_cast<const TMat4<F32>*>(this);
 	const TMat4<F32>& m = *static_cast<const TMat4<F32>*>(this);
@@ -144,7 +144,7 @@ inline TMat4<F32> TMat4<F32>::Base::operator*(const TMat4<F32>& b) const
 }
 }
 
 
 template<>
 template<>
-inline TVec4<F32> TMat4<F32>::Base::operator*(const TVec4<F32>& b) const
+inline TVec4<F32> TMat4F32Base::operator*(const TVec4<F32>& b) const
 {
 {
 	TVec4<F32> v;
 	TVec4<F32> v;
 
 
@@ -157,8 +157,7 @@ inline TVec4<F32> TMat4<F32>::Base::operator*(const TVec4<F32>& b) const
 }
 }
 
 
 template<>
 template<>
-inline void TMat4<F32>::Base::setRows(
-	const TVec4<F32>& a, const TVec4<F32>& b, const TVec4<F32>& c, const TVec4<F32>& d)
+inline void TMat4F32Base::setRows(const TVec4<F32>& a, const TVec4<F32>& b, const TVec4<F32>& c, const TVec4<F32>& d)
 {
 {
 	m_simd[0] = a.getSimd();
 	m_simd[0] = a.getSimd();
 	m_simd[1] = b.getSimd();
 	m_simd[1] = b.getSimd();
@@ -167,13 +166,13 @@ inline void TMat4<F32>::Base::setRows(
 }
 }
 
 
 template<>
 template<>
-inline void TMat4<F32>::Base::setRow(const U i, const TVec4<F32>& v)
+inline void TMat4F32Base::setRow(const U i, const TVec4<F32>& v)
 {
 {
 	m_simd[i] = v.getSimd();
 	m_simd[i] = v.getSimd();
 }
 }
 
 
 template<>
 template<>
-inline void TMat4<F32>::Base::transpose()
+inline void TMat4F32Base::transpose()
 {
 {
 	_MM_TRANSPOSE4_PS(m_simd[0], m_simd[1], m_simd[2], m_simd[3]);
 	_MM_TRANSPOSE4_PS(m_simd[0], m_simd[1], m_simd[2], m_simd[3]);
 }
 }

+ 3 - 1
src/anki/physics/Common.h

@@ -10,9 +10,11 @@
 #include <anki/util/Ptr.h>
 #include <anki/util/Ptr.h>
 #include <anki/Math.h>
 #include <anki/Math.h>
 
 
-// Common newton libs
+// Have all the newton headers here because they polute the global namespace
 #include <Newton.h>
 #include <Newton.h>
 #include <dLinearAlgebra.h>
 #include <dLinearAlgebra.h>
+#include <dCustomPlayerControllerManager.h>
+#include <anki/util/CleanupWindows.h>
 
 
 namespace anki
 namespace anki
 {
 {

+ 2 - 2
src/anki/physics/PhysicsBody.cpp

@@ -120,8 +120,8 @@ void PhysicsBody::applyGravityForce(const NewtonBody* body, dFloat timestep, int
 
 
 	NewtonBodyGetMass(body, &mass, &Ixx, &Iyy, &Izz);
 	NewtonBodyGetMass(body, &mass, &Ixx, &Iyy, &Izz);
 
 
-	const F32 GRAVITY = -9.8;
-	Vec4 force(0.0, mass * GRAVITY, 0.0, 0.0);
+	const F32 GRAVITY = -9.8f;
+	Vec4 force(0.0f, mass * GRAVITY, 0.0f, 0.0f);
 	NewtonBodySetForce(body, &force[0]);
 	NewtonBodySetForce(body, &force[0]);
 }
 }
 
 

+ 2 - 2
src/anki/physics/PhysicsBody.h

@@ -73,8 +73,8 @@ private:
 	NewtonBody* m_body = nullptr;
 	NewtonBody* m_body = nullptr;
 	void* m_sceneCollisionProxy = nullptr;
 	void* m_sceneCollisionProxy = nullptr;
 	Transform m_trf = Transform::getIdentity();
 	Transform m_trf = Transform::getIdentity();
-	F32 m_friction = 0.03;
-	F32 m_elasticity = 0.1;
+	F32 m_friction = 0.03f;
+	F32 m_elasticity = 0.1f;
 	PhysicsMaterialBit m_materialBits = PhysicsMaterialBit::ALL;
 	PhysicsMaterialBit m_materialBits = PhysicsMaterialBit::ALL;
 	Bool8 m_updated = true;
 	Bool8 m_updated = true;
 
 

+ 6 - 7
src/anki/physics/PhysicsPlayerController.h

@@ -6,7 +6,6 @@
 #pragma once
 #pragma once
 
 
 #include <anki/physics/PhysicsObject.h>
 #include <anki/physics/PhysicsObject.h>
-#include <dCustomPlayerControllerManager.h>
 
 
 namespace anki
 namespace anki
 {
 {
@@ -33,12 +32,12 @@ public:
 class PhysicsPlayerControllerInitInfo
 class PhysicsPlayerControllerInitInfo
 {
 {
 public:
 public:
-	F32 m_mass = 83.0;
-	F32 m_innerRadius = 0.30;
-	F32 m_outerRadius = 0.50;
-	F32 m_height = 1.9;
-	F32 m_stepHeight = 1.9 * 0.33;
-	Vec4 m_position = Vec4(0.0);
+	F32 m_mass = 83.0f;
+	F32 m_innerRadius = 0.30f;
+	F32 m_outerRadius = 0.50f;
+	F32 m_height = 1.9f;
+	F32 m_stepHeight = 1.9f * 0.33f;
+	Vec4 m_position = Vec4(0.0f);
 };
 };
 
 
 /// A player controller that walks the world.
 /// A player controller that walks the world.

+ 2 - 2
src/anki/physics/PhysicsWorld.cpp

@@ -141,8 +141,8 @@ void PhysicsWorld::onContactCallback(const NewtonJoint* contactJoint, F32 timest
 	const NewtonBody* body0 = NewtonJointGetBody0(contactJoint);
 	const NewtonBody* body0 = NewtonJointGetBody0(contactJoint);
 	const NewtonBody* body1 = NewtonJointGetBody1(contactJoint);
 	const NewtonBody* body1 = NewtonJointGetBody1(contactJoint);
 
 
-	F32 friction0 = 0.01;
-	F32 elasticity0 = 0.001;
+	F32 friction0 = 0.01f;
+	F32 elasticity0 = 0.001f;
 	F32 friction1 = friction0;
 	F32 friction1 = friction0;
 	F32 elasticity1 = elasticity0;
 	F32 elasticity1 = elasticity0;
 
 

+ 1 - 1
src/anki/physics/PhysicsWorld.h

@@ -75,7 +75,7 @@ private:
 	mutable NewtonWorld* m_world = nullptr;
 	mutable NewtonWorld* m_world = nullptr;
 	NewtonCollision* m_sceneCollision = nullptr;
 	NewtonCollision* m_sceneCollision = nullptr;
 	NewtonBody* m_sceneBody = nullptr;
 	NewtonBody* m_sceneBody = nullptr;
-	Vec4 m_gravity = Vec4(0.0, -9.8, 0.0, 0.0);
+	Vec4 m_gravity = Vec4(0.0f, -9.8f, 0.0f, 0.0f);
 	Second m_dt = 0.0;
 	Second m_dt = 0.0;
 
 
 	/// @note Don't delete it. Newton will
 	/// @note Don't delete it. Newton will

+ 2 - 6
src/anki/resource/Common.h

@@ -34,12 +34,8 @@ class TransferGpuAllocatorHandle;
 /// @{
 /// @{
 const U MAX_LOD_COUNT = 3;
 const U MAX_LOD_COUNT = 3;
 const U MAX_INSTANCES = 64;
 const U MAX_INSTANCES = 64;
-const U MAX_SUB_DRAWCALLS = 64;
-
-/// The number of instance groups. Eg First group is 1 instance, 2nd group 2 instances, 3rd is 4 instances. The
-/// expression is: @code log2(MAX_INSTANCES) + 1 @endcode but since Clang doesn't like log2 in constant expressions use
-/// an alternative way.
-const U MAX_INSTANCE_GROUPS = __builtin_popcount(MAX_INSTANCES - 1) + 1;
+const U MAX_SUB_DRAWCALLS = 64; ///< @warning If changed don't forget to change MAX_INSTANCE_GROUPS
+const U MAX_INSTANCE_GROUPS = 7; ///< It's log2(MAX_INSTANCES) + 1
 /// @}
 /// @}
 
 
 /// Deleter for ResourcePtr.
 /// Deleter for ResourcePtr.

+ 1 - 1
src/anki/resource/ShaderProgramResource.h

@@ -61,7 +61,7 @@ class ShaderProgramResourceMutation
 public:
 public:
 	const ShaderProgramResourceMutator* m_mutator;
 	const ShaderProgramResourceMutator* m_mutator;
 	ShaderProgramResourceMutatorValue m_value;
 	ShaderProgramResourceMutatorValue m_value;
-	U8 _padding[sizeof(void*) - sizeof(m_value)];
+	U8 _padding[sizeof(void*) - sizeof(ShaderProgramResourceMutatorValue)];
 
 
 	ShaderProgramResourceMutation()
 	ShaderProgramResourceMutation()
 	{
 	{

+ 1 - 1
src/anki/scene/DecalComponent.h

@@ -22,7 +22,7 @@ class DecalComponent : public SceneComponent
 public:
 public:
 	static const SceneComponentType CLASS_TYPE = SceneComponentType::DECAL;
 	static const SceneComponentType CLASS_TYPE = SceneComponentType::DECAL;
 
 
-	static constexpr F32 FRUSTUM_NEAR_PLANE = 0.1 / 4.0;
+	static constexpr F32 FRUSTUM_NEAR_PLANE = 0.1f / 4.0f;
 	static constexpr U ATLAS_SUB_TEXTURE_MARGIN = 16;
 	static constexpr U ATLAS_SUB_TEXTURE_MARGIN = 16;
 
 
 	DecalComponent(SceneNode* node);
 	DecalComponent(SceneNode* node);

+ 1 - 1
src/anki/scene/LightComponent.h

@@ -30,7 +30,7 @@ public:
 
 
 	/// The near plane on the shadow map frustums.
 	/// The near plane on the shadow map frustums.
 	/// WARNING: If you change here update the shaders.
 	/// WARNING: If you change here update the shaders.
-	static constexpr F32 FRUSTUM_NEAR_PLANE = 0.1 / 4.0;
+	static constexpr F32 FRUSTUM_NEAR_PLANE = 0.1f / 4.0f;
 
 
 	LightComponent(SceneNode* node, LightComponentType type);
 	LightComponent(SceneNode* node, LightComponentType type);
 
 

+ 2 - 2
src/anki/scene/ReflectionProbe.h

@@ -22,8 +22,8 @@ class ReflectionProbe : public SceneNode
 	friend class ReflectionProbeMoveFeedbackComponent;
 	friend class ReflectionProbeMoveFeedbackComponent;
 
 
 public:
 public:
-	const F32 FRUSTUM_NEAR_PLANE = 0.1 / 4.0;
-	const F32 EFFECTIVE_DISTANCE = 256.0;
+	const F32 FRUSTUM_NEAR_PLANE = 0.1f / 4.0f;
+	const F32 EFFECTIVE_DISTANCE = 256.0f;
 
 
 	ReflectionProbe(SceneGraph* scene, CString name)
 	ReflectionProbe(SceneGraph* scene, CString name)
 		: SceneNode(scene, name)
 		: SceneNode(scene, name)

+ 1 - 1
src/anki/scene/SceneGraph.cpp

@@ -96,7 +96,7 @@ Error SceneGraph::init(AllocAlignedCallback allocCb,
 
 
 	// Init the default main camera
 	// Init the default main camera
 	ANKI_CHECK(newSceneNode<PerspectiveCamera>("mainCamera", m_defaultMainCam));
 	ANKI_CHECK(newSceneNode<PerspectiveCamera>("mainCamera", m_defaultMainCam));
-	m_defaultMainCam->setAll(toRad(60.0), toRad(60.0), 0.1, 1000.0);
+	m_defaultMainCam->setAll(toRad(60.0f), toRad(60.0f), 0.1f, 1000.0f);
 	m_mainCam = m_defaultMainCam;
 	m_mainCam = m_defaultMainCam;
 
 
 	return Error::NONE;
 	return Error::NONE;

+ 9 - 5
src/anki/script/ScriptManager.cpp

@@ -9,6 +9,14 @@
 namespace anki
 namespace anki
 {
 {
 
 
+// Forward
+#define ANKI_SCRIPT_CALL_WRAP(x_) void wrapModule##x_(lua_State*)
+ANKI_SCRIPT_CALL_WRAP(Math);
+ANKI_SCRIPT_CALL_WRAP(Renderer);
+ANKI_SCRIPT_CALL_WRAP(Scene);
+ANKI_SCRIPT_CALL_WRAP(Event);
+#undef ANKI_SCRIPT_CALL_WRAP
+
 ScriptManager::ScriptManager()
 ScriptManager::ScriptManager()
 {
 {
 }
 }
@@ -31,15 +39,11 @@ Error ScriptManager::init(AllocAlignedCallback allocCb, void* allocCbData, Scene
 	// Wrap stuff
 	// Wrap stuff
 	lua_State* l = m_lua.getLuaState();
 	lua_State* l = m_lua.getLuaState();
 
 
-#define ANKI_SCRIPT_CALL_WRAP(x_)           \
-	extern void wrapModule##x_(lua_State*); \
-	wrapModule##x_(l);
-
+#define ANKI_SCRIPT_CALL_WRAP(x_) wrapModule##x_(l)
 	ANKI_SCRIPT_CALL_WRAP(Math);
 	ANKI_SCRIPT_CALL_WRAP(Math);
 	ANKI_SCRIPT_CALL_WRAP(Renderer);
 	ANKI_SCRIPT_CALL_WRAP(Renderer);
 	ANKI_SCRIPT_CALL_WRAP(Scene);
 	ANKI_SCRIPT_CALL_WRAP(Scene);
 	ANKI_SCRIPT_CALL_WRAP(Event);
 	ANKI_SCRIPT_CALL_WRAP(Event);
-
 #undef ANKI_SCRIPT_CALL_WRAP
 #undef ANKI_SCRIPT_CALL_WRAP
 
 
 	return Error::NONE;
 	return Error::NONE;

+ 41 - 0
src/anki/util/CleanupWindows.h

@@ -0,0 +1,41 @@
+// Copyright (C) 2009-2017, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+/// @file
+/// Clean the global namespace from windows.h crap
+
+#include <anki/Config.h>
+
+#if ANKI_OS == ANKI_OS_WINDOWS
+
+#ifdef near
+#undef near
+#endif
+
+#ifdef far
+#undef far
+#endif
+
+#ifdef ERROR
+#undef ERROR
+#endif
+
+#ifdef DELETE
+#undef DELETE
+#endif
+
+#ifdef OUT
+#undef OUT
+#endif
+
+#ifdef min
+#undef min
+#endif
+
+#ifdef max
+#undef max
+#endif
+
+#endif

+ 3 - 3
src/anki/util/DynamicArray.inl.h

@@ -26,7 +26,7 @@ void DynamicArray<T>::resizeStorage(TAllocator& alloc, PtrSize newSize)
 			for(PtrSize i = 0; i < m_size; ++i)
 			for(PtrSize i = 0; i < m_size; ++i)
 			{
 			{
 				::new(&newStorage[i]) Value(std::move(m_data[i]));
 				::new(&newStorage[i]) Value(std::move(m_data[i]));
-				m_data[i].~Value();
+				m_data[i].~T();
 			}
 			}
 
 
 			alloc.getMemoryPool().free(m_data);
 			alloc.getMemoryPool().free(m_data);
@@ -43,7 +43,7 @@ void DynamicArray<T>::resizeStorage(TAllocator& alloc, PtrSize newSize)
 		// Delete remaining stuff
 		// Delete remaining stuff
 		for(U i = newSize; i < m_size; ++i)
 		for(U i = newSize; i < m_size; ++i)
 		{
 		{
-			m_data[i].~Value();
+			m_data[i].~T();
 		}
 		}
 
 
 		m_size = newSize;
 		m_size = newSize;
@@ -61,7 +61,7 @@ void DynamicArray<T>::resizeStorage(TAllocator& alloc, PtrSize newSize)
 				for(PtrSize i = 0; i < m_size; ++i)
 				for(PtrSize i = 0; i < m_size; ++i)
 				{
 				{
 					::new(&newStorage[i]) Value(std::move(m_data[i]));
 					::new(&newStorage[i]) Value(std::move(m_data[i]));
-					m_data[i].~Value();
+					m_data[i].~T();
 				}
 				}
 
 
 				alloc.getMemoryPool().free(m_data);
 				alloc.getMemoryPool().free(m_data);