summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-09 12:18:46 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-09 12:18:46 +0200
commitb581b559fe426f39b1d548ca27f03cb22dd2ed22 (patch)
treee43be0a41f0e3d8908fd24a1122bbc81d895230d
parent9c9f083b8130c13c4e861f8e876c618e1eab38e8 (diff)
.
-rw-r--r--CMakeLists.txt8
-rw-r--r--compat/arch.hpp45
-rw-r--r--compat/fpu.hpp40
-rw-r--r--compat/prelude.hpp6
-rw-r--r--main/app.cpp2
5 files changed, 101 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 413b9d79..00cf1df3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -58,6 +58,14 @@ if(NOT BOOTSTRAP_DEPENDS)
include_directories(.)
include_directories(src)
+if(MSVC)
+ add_definitions(-FI"compat/prelude.hpp")
+else()
+ # GCC or Clang
+ add_definitions(-include compat/prelude.hpp)
+endif()
+
+ add_definitions(-DGAME_PROJECT_NAME=floormat)
add_subdirectory(src)
add_subdirectory(draw)
add_subdirectory(main)
diff --git a/compat/arch.hpp b/compat/arch.hpp
new file mode 100644
index 00000000..0b58b65a
--- /dev/null
+++ b/compat/arch.hpp
@@ -0,0 +1,45 @@
+#pragma once
+
+#if defined _MSC_VER
+# ifdef __clang__
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wreserved-id-macro"
+# pragma clang diagnostic ignored "-Wunused-macros"
+# endif
+
+# if defined _M_AMD64
+# undef __x86_64__
+# define __x86_64__ 1
+# elif defined _M_IX86
+# undef __i386__
+# define __i386__ 1
+# endif
+
+# if defined __AVX__ || defined __x86_64__ || \
+ defined _M_IX86 && _M_IX86_FP >= 2
+# undef __SSE__
+# undef __SSE2__
+# undef __SSE3__
+# define __SSE__ 1
+# define __SSE2__ 1
+# define __SSE3__ 1
+# endif
+
+# ifdef __clang__
+# pragma clang diagnostic pop
+# endif
+#endif
+
+#if defined __SSE3__
+# define FLOORMAT_ARCH_DENORM_DAZ
+# include <pmmintrin.h>
+#elif defined __SSE2__
+# define FLOORMAT_ARCH_DENORM_FTZ
+# include <emmintrin.h>
+#endif
+
+#if defined __SSE2__
+# define FLOORMAT_ARCH_FPU_MASK
+# include <xmmintrin.h>
+#endif
+
diff --git a/compat/fpu.hpp b/compat/fpu.hpp
new file mode 100644
index 00000000..1b3776f9
--- /dev/null
+++ b/compat/fpu.hpp
@@ -0,0 +1,40 @@
+#pragma once
+#include "arch.hpp"
+
+#ifdef __MINGW32__
+extern "C" __declspec(dllimport) unsigned __cdecl _controlfp(unsigned, unsigned);
+#endif
+
+static inline void set_fp_mask()
+{
+#if defined FLOORMAT_ARCH_DENORM_DAZ
+ _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
+#elif defined FLOORMAT_ARCH_DENORM_FTZ
+ _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
+#endif
+
+#ifdef FLOORMAT_ARCH_FPU_MASK
+ _MM_SET_EXCEPTION_MASK(_MM_MASK_MASK);
+#endif
+
+#ifdef __APPLE__
+ fesetenv(FE_DFL_DISABLE_SSE_DENORMS_ENV);
+#endif
+
+#ifdef _WIN32
+# ifdef __clang__
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wreserved-id-macro"
+# endif
+# ifndef _DN_FLUSH
+# define _DN_FLUSH 0x01000000
+# endif
+# ifndef _MCW_DN
+# define _MCW_DN 0x03000000
+# endif
+# ifdef __clang__
+# pragma clang diagnostic pop
+# endif
+ _controlfp(_DN_FLUSH, _MCW_DN);
+#endif
+}
diff --git a/compat/prelude.hpp b/compat/prelude.hpp
new file mode 100644
index 00000000..8b0387c5
--- /dev/null
+++ b/compat/prelude.hpp
@@ -0,0 +1,6 @@
+#pragma once
+
+namespace Magnum {}
+namespace GAME_PROJECT_NAME {
+ using namespace ::Magnum;
+} // namespace GAME_PROJECT_NAME
diff --git a/main/app.cpp b/main/app.cpp
index b0acda2e..6d2474b4 100644
--- a/main/app.cpp
+++ b/main/app.cpp
@@ -1,4 +1,5 @@
#include "app.hpp"
+#include "compat/fpu.hpp"
namespace Magnum::Examples {
@@ -14,6 +15,7 @@ app::app(const Arguments& arguments):
.setFlags(GLConfiguration::Flag::GpuValidation)
}
{
+ set_fp_mask();
reset_camera_offset();
update_window_scale(windowSize());
timeline.start();