From a24fcc0c036f69ed7e40b8d558cf1d991433ebc3 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Fri, 23 Nov 2012 11:34:25 +0000 Subject: [PATCH 01/47] Add C++11 compiler support detection feature This is currently copied from http://quickgit.kde.org/index.php?p=scratch%2Fdakon%2Fcmake-cxx11.git but there is a chance that in future it will be merged into CMake proper. --- cmake/Modules/CheckCXX11Features.cmake | 132 ++++++++++++++++++ .../cxx11-test-__func__.cpp | 8 ++ .../CheckCXX11Features/cxx11-test-auto.cpp | 12 ++ .../cxx11-test-auto_fail_compile.cpp | 7 + .../cxx11-test-auto_ret_type.cpp | 8 ++ .../cxx11-test-class_override_final.cpp | 21 +++ ...test-class_override_final_fail_compile.cpp | 25 ++++ .../cxx11-test-constexpr.cpp | 19 +++ .../CheckCXX11Features/cxx11-test-cstdint.cpp | 11 ++ .../cxx11-test-decltype.cpp | 10 ++ .../cxx11-test-initializer_list.cpp | 27 ++++ .../CheckCXX11Features/cxx11-test-lambda.cpp | 5 + .../cxx11-test-long_long.cpp | 7 + .../CheckCXX11Features/cxx11-test-nullptr.cpp | 6 + .../cxx11-test-nullptr_fail_compile.cpp | 6 + .../CheckCXX11Features/cxx11-test-regex.cpp | 26 ++++ .../cxx11-test-rvalue-references.cpp | 57 ++++++++ .../cxx11-test-sizeof_member.cpp | 14 ++ .../cxx11-test-sizeof_member_fail.cpp | 9 ++ .../cxx11-test-static_assert.cpp | 5 + .../cxx11-test-static_assert_fail_compile.cpp | 5 + .../cxx11-test-variadic_templates.cpp | 23 +++ 22 files changed, 443 insertions(+) create mode 100644 cmake/Modules/CheckCXX11Features.cmake create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-__func__.cpp create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-auto.cpp create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-auto_fail_compile.cpp create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-auto_ret_type.cpp create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-class_override_final.cpp create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-class_override_final_fail_compile.cpp create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-constexpr.cpp create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-cstdint.cpp create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-decltype.cpp create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-initializer_list.cpp create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-lambda.cpp create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-long_long.cpp create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-nullptr.cpp create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-nullptr_fail_compile.cpp create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-regex.cpp create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-rvalue-references.cpp create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-sizeof_member.cpp create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-sizeof_member_fail.cpp create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-static_assert.cpp create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-static_assert_fail_compile.cpp create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-variadic_templates.cpp diff --git a/cmake/Modules/CheckCXX11Features.cmake b/cmake/Modules/CheckCXX11Features.cmake new file mode 100644 index 00000000..0699f48e --- /dev/null +++ b/cmake/Modules/CheckCXX11Features.cmake @@ -0,0 +1,132 @@ +# - Check which parts of the C++11 standard the compiler supports +# +# When found it will set the following variables +# +# CXX11_COMPILER_FLAGS - the compiler flags needed to get C++11 features +# +# HAS_CXX11_AUTO - auto keyword +# HAS_CXX11_AUTO_RET_TYPE - function declaration with deduced return types +# HAS_CXX11_CLASS_OVERRIDE - override and final keywords for classes and methods +# HAS_CXX11_CONSTEXPR - constexpr keyword +# HAS_CXX11_CSTDINT_H - cstdint header +# HAS_CXX11_DECLTYPE - decltype keyword +# HAS_CXX11_FUNC - __func__ preprocessor constant +# HAS_CXX11_INITIALIZER_LIST - initializer list +# HAS_CXX11_LAMBDA - lambdas +# HAS_CXX11_LIB_REGEX - regex library +# HAS_CXX11_LONG_LONG - long long signed & unsigned types +# HAS_CXX11_NULLPTR - nullptr +# HAS_CXX11_RVALUE_REFERENCES - rvalue references +# HAS_CXX11_SIZEOF_MEMBER - sizeof() non-static members +# HAS_CXX11_STATIC_ASSERT - static_assert() +# HAS_CXX11_VARIADIC_TEMPLATES - variadic templates + +#============================================================================= +# Copyright 2011,2012 Rolf Eike Beer +# Copyright 2012 Andreas Weis +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +if (NOT CMAKE_CXX_COMPILER_LOADED) + message(FATAL_ERROR "CheckCXX11Features modules only works if language CXX is enabled") +endif () + +cmake_minimum_required(VERSION 2.8.3) + +# +### Check for needed compiler flags +# +include(CheckCXXCompilerFlag) +check_cxx_compiler_flag("-std=c++11" _HAS_CXX11_FLAG) +if (NOT _HAS_CXX11_FLAG) + check_cxx_compiler_flag("-std=c++0x" _HAS_CXX0X_FLAG) +endif () + +if (_HAS_CXX11_FLAG) + set(CXX11_COMPILER_FLAGS "-std=c++11") +elseif (_HAS_CXX0X_FLAG) + set(CXX11_COMPILER_FLAGS "-std=c++0x") +endif () + +function(cxx11_check_feature FEATURE_NAME RESULT_VAR) + if (NOT DEFINED ${RESULT_VAR}) + set(_bindir "${CMAKE_CURRENT_BINARY_DIR}/cxx11_${FEATURE_NAME}") + + set(_SRCFILE_BASE ${CMAKE_CURRENT_LIST_DIR}/CheckCXX11Features/cxx11-test-${FEATURE_NAME}) + set(_LOG_NAME "\"${FEATURE_NAME}\"") + message(STATUS "Checking C++11 support for ${_LOG_NAME}") + + set(_SRCFILE "${_SRCFILE_BASE}.cpp") + set(_SRCFILE_FAIL "${_SRCFILE_BASE}_fail.cpp") + set(_SRCFILE_FAIL_COMPILE "${_SRCFILE_BASE}_fail_compile.cpp") + + if (CROSS_COMPILING) + try_compile(${RESULT_VAR} "${_bindir}" "${_SRCFILE}" + COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}") + if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL}) + try_compile(${RESULT_VAR} "${_bindir}_fail" "${_SRCFILE_FAIL}" + COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}") + endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL}) + else (CROSS_COMPILING) + try_run(_RUN_RESULT_VAR _COMPILE_RESULT_VAR + "${_bindir}" "${_SRCFILE}" + COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}") + if (_COMPILE_RESULT_VAR AND NOT _RUN_RESULT_VAR) + set(${RESULT_VAR} TRUE) + else (_COMPILE_RESULT_VAR AND NOT _RUN_RESULT_VAR) + set(${RESULT_VAR} FALSE) + endif (_COMPILE_RESULT_VAR AND NOT _RUN_RESULT_VAR) + if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL}) + try_run(_RUN_RESULT_VAR _COMPILE_RESULT_VAR + "${_bindir}_fail" "${_SRCFILE_FAIL}" + COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}") + if (_COMPILE_RESULT_VAR AND _RUN_RESULT_VAR) + set(${RESULT_VAR} TRUE) + else (_COMPILE_RESULT_VAR AND _RUN_RESULT_VAR) + set(${RESULT_VAR} FALSE) + endif (_COMPILE_RESULT_VAR AND _RUN_RESULT_VAR) + endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL}) + endif (CROSS_COMPILING) + if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL_COMPILE}) + try_compile(_TMP_RESULT "${_bindir}_fail_compile" "${_SRCFILE_FAIL_COMPILE}" + COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}") + if (_TMP_RESULT) + set(${RESULT_VAR} FALSE) + else (_TMP_RESULT) + set(${RESULT_VAR} TRUE) + endif (_TMP_RESULT) + endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL_COMPILE}) + + if (${RESULT_VAR}) + message(STATUS "Checking C++11 support for ${_LOG_NAME}: works") + else (${RESULT_VAR}) + message(STATUS "Checking C++11 support for ${_LOG_NAME}: not supported") + endif (${RESULT_VAR}) + set(${RESULT_VAR} ${${RESULT_VAR}} CACHE INTERNAL "C++11 support for ${_LOG_NAME}") + endif (NOT DEFINED ${RESULT_VAR}) +endfunction(cxx11_check_feature) + +cxx11_check_feature("__func__" HAS_CXX11_FUNC) +cxx11_check_feature("auto" HAS_CXX11_AUTO) +cxx11_check_feature("auto_ret_type" HAS_CXX11_AUTO_RET_TYPE) +cxx11_check_feature("class_override_final" HAS_CXX11_CLASS_OVERRIDE) +cxx11_check_feature("constexpr" HAS_CXX11_CONSTEXPR) +cxx11_check_feature("cstdint" HAS_CXX11_CSTDINT_H) +cxx11_check_feature("decltype" HAS_CXX11_DECLTYPE) +cxx11_check_feature("initializer_list" HAS_CXX11_INITIALIZER_LIST) +cxx11_check_feature("lambda" HAS_CXX11_LAMBDA) +cxx11_check_feature("long_long" HAS_CXX11_LONG_LONG) +cxx11_check_feature("nullptr" HAS_CXX11_NULLPTR) +cxx11_check_feature("regex" HAS_CXX11_LIB_REGEX) +cxx11_check_feature("rvalue-references" HAS_CXX11_RVALUE_REFERENCES) +cxx11_check_feature("sizeof_member" HAS_CXX11_SIZEOF_MEMBER) +cxx11_check_feature("static_assert" HAS_CXX11_STATIC_ASSERT) +cxx11_check_feature("variadic_templates" HAS_CXX11_VARIADIC_TEMPLATES) diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-__func__.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-__func__.cpp new file mode 100644 index 00000000..3bfd8a89 --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-__func__.cpp @@ -0,0 +1,8 @@ +int main(void) +{ + if (!__func__) + return 1; + if (!(*__func__)) + return 1; + return 0; +} diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-auto.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-auto.cpp new file mode 100644 index 00000000..948648e9 --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-auto.cpp @@ -0,0 +1,12 @@ + +int main() +{ + auto i = 5; + auto f = 3.14159f; + auto d = 3.14159; + bool ret = ( + (sizeof(f) < sizeof(d)) && + (sizeof(i) == sizeof(int)) + ); + return ret ? 0 : 1; +} diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-auto_fail_compile.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-auto_fail_compile.cpp new file mode 100644 index 00000000..3c0e3f2e --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-auto_fail_compile.cpp @@ -0,0 +1,7 @@ +int main(void) +{ + // must fail because there is no initializer + auto i; + + return 0; +} diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-auto_ret_type.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-auto_ret_type.cpp new file mode 100644 index 00000000..937b6835 --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-auto_ret_type.cpp @@ -0,0 +1,8 @@ +auto foo(int i) -> int { + return i - 1; +} + +int main() +{ + return foo(1); +} diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-class_override_final.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-class_override_final.cpp new file mode 100644 index 00000000..f5870b19 --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-class_override_final.cpp @@ -0,0 +1,21 @@ +class base { +public: + virtual int foo(int a) + { return 4 + a; } + int bar(int a) final + { return a - 2; } +}; + +class sub final : public base { +public: + virtual int foo(int a) override + { return 8 + 2 * a; }; +}; + +int main(void) +{ + base b; + sub s; + + return (b.foo(2) * 2 == s.foo(2)) ? 0 : 1; +} diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-class_override_final_fail_compile.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-class_override_final_fail_compile.cpp new file mode 100644 index 00000000..bc00b278 --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-class_override_final_fail_compile.cpp @@ -0,0 +1,25 @@ +class base { +public: + virtual int foo(int a) + { return 4 + a; } + virtual int bar(int a) final + { return a - 2; } +}; + +class sub final : public base { +public: + virtual int foo(int a) override + { return 8 + 2 * a; }; + virtual int bar(int a) + { return a; } +}; + +class impossible : public sub { }; + +int main(void) +{ + base b; + sub s; + + return 1; +} diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-constexpr.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-constexpr.cpp new file mode 100644 index 00000000..ed624512 --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-constexpr.cpp @@ -0,0 +1,19 @@ +constexpr int square(int x) +{ + return x*x; +} + +constexpr int the_answer() +{ + return 42; +} + +int main() +{ + int test_arr[square(3)]; + bool ret = ( + (square(the_answer()) == 1764) && + (sizeof(test_arr)/sizeof(test_arr[0]) == 9) + ); + return ret ? 0 : 1; +} diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-cstdint.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-cstdint.cpp new file mode 100644 index 00000000..ca2c72dd --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-cstdint.cpp @@ -0,0 +1,11 @@ +#include + +int main() +{ + bool test = + (sizeof(int8_t) == 1) && + (sizeof(int16_t) == 2) && + (sizeof(int32_t) == 4) && + (sizeof(int64_t) == 8); + return test ? 0 : 1; +} diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-decltype.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-decltype.cpp new file mode 100644 index 00000000..0dbb1cc5 --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-decltype.cpp @@ -0,0 +1,10 @@ +bool check_size(int i) +{ + return sizeof(int) == sizeof(decltype(i)); +} + +int main() +{ + bool ret = check_size(42); + return ret ? 0 : 1; +} diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-initializer_list.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-initializer_list.cpp new file mode 100644 index 00000000..35e6c384 --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-initializer_list.cpp @@ -0,0 +1,27 @@ +#include + +class seq { +public: + seq(std::initializer_list list); + + int length() const; +private: + std::vector m_v; +}; + +seq::seq(std::initializer_list list) + : m_v(list) +{ +} + +int seq::length() const +{ + return m_v.size(); +} + +int main(void) +{ + seq a = {18, 20, 2, 0, 4, 7}; + + return (a.length() == 6) ? 0 : 1; +} diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-lambda.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-lambda.cpp new file mode 100644 index 00000000..4c33ed58 --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-lambda.cpp @@ -0,0 +1,5 @@ +int main() +{ + int ret = 0; + return ([&ret]() -> int { return ret; })(); +} diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-long_long.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-long_long.cpp new file mode 100644 index 00000000..09111275 --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-long_long.cpp @@ -0,0 +1,7 @@ +int main(void) +{ + long long l; + unsigned long long ul; + + return ((sizeof(l) >= 8) && (sizeof(ul) >= 8)) ? 0 : 1; +} diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-nullptr.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-nullptr.cpp new file mode 100644 index 00000000..9f410715 --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-nullptr.cpp @@ -0,0 +1,6 @@ +int main(void) +{ + void *v = nullptr; + + return v ? 1 : 0; +} diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-nullptr_fail_compile.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-nullptr_fail_compile.cpp new file mode 100644 index 00000000..6a002bcb --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-nullptr_fail_compile.cpp @@ -0,0 +1,6 @@ +int main(void) +{ + int i = nullptr; + + return 1; +} diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-regex.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-regex.cpp new file mode 100644 index 00000000..2fe01c4f --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-regex.cpp @@ -0,0 +1,26 @@ +#include +#include + +int parse_line(std::string const& line) +{ + std::string tmp; + if(std::regex_search(line, std::regex("(\\s)+(-)?(\\d)+//(-)?(\\d)+(\\s)+"))) { + tmp = std::regex_replace(line, std::regex("(-)?(\\d)+//(-)?(\\d)+"), std::string("V")); + } else if(std::regex_search(line, std::regex("(\\s)+(-)?(\\d)+/(-)?(\\d)+(\\s)+"))) { + tmp = std::regex_replace(line, std::regex("(-)?(\\d)+/(-)?(\\d)+"), std::string("V")); + } else if(std::regex_search(line, std::regex("(\\s)+(-)?(\\d)+/(-)?(\\d)+/(-)?(\\d)+(\\s)+"))) { + tmp = std::regex_replace(line, std::regex("(-)?(\\d)+/(-)?(\\d)+/(-)?(\\d)+"), std::string("V")); + } else { + tmp = std::regex_replace(line, std::regex("(-)?(\\d)+"), std::string("V")); + } + return static_cast(std::count(tmp.begin(), tmp.end(), 'V')); +} + +int main() +{ + bool test = (parse_line("f 7/7/7 -3/3/-3 2/-2/2") == 3) && + (parse_line("f 7//7 3//-3 -2//2") == 3) && + (parse_line("f 7/7 3/-3 -2/2") == 3) && + (parse_line("f 7 3 -2") == 3); + return test ? 0 : 1; +} diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-rvalue-references.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-rvalue-references.cpp new file mode 100644 index 00000000..e6e7e5a9 --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-rvalue-references.cpp @@ -0,0 +1,57 @@ +#include + +class rvmove { +public: + void *ptr; + char *array; + + rvmove() + : ptr(0), + array(new char[10]) + { + ptr = this; + } + + rvmove(rvmove &&other) + : ptr(other.ptr), + array(other.array) + { + other.array = 0; + other.ptr = 0; + } + + ~rvmove() + { + assert(((ptr != 0) && (array != 0)) || ((ptr == 0) && (array == 0))); + delete[] array; + } + + rvmove &operator=(rvmove &&other) + { + delete[] array; + ptr = other.ptr; + array = other.array; + other.array = 0; + other.ptr = 0; + return *this; + } + + static rvmove create() + { + return rvmove(); + } +private: + rvmove(const rvmove &); + rvmove &operator=(const rvmove &); +}; + +int main() +{ + rvmove mine; + if (mine.ptr != &mine) + return 1; + mine = rvmove::create(); + if (mine.ptr == &mine) + return 1; + return 0; +} diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-sizeof_member.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-sizeof_member.cpp new file mode 100644 index 00000000..4902fc73 --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-sizeof_member.cpp @@ -0,0 +1,14 @@ +struct foo { + char bar; + int baz; +}; + +int main(void) +{ + bool ret = ( + (sizeof(foo::bar) == 1) && + (sizeof(foo::baz) >= sizeof(foo::bar)) && + (sizeof(foo) >= sizeof(foo::bar) + sizeof(foo::baz)) + ); + return ret ? 0 : 1; +} diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-sizeof_member_fail.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-sizeof_member_fail.cpp new file mode 100644 index 00000000..0348c2ce --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-sizeof_member_fail.cpp @@ -0,0 +1,9 @@ +struct foo { + int baz; + double bar; +}; + +int main(void) +{ + return (sizeof(foo::bar) == 4) ? 0 : 1; +} diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-static_assert.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-static_assert.cpp new file mode 100644 index 00000000..47c2fefb --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-static_assert.cpp @@ -0,0 +1,5 @@ +int main(void) +{ + static_assert(0 < 1, "your ordering of integers is screwed"); + return 0; +} diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-static_assert_fail_compile.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-static_assert_fail_compile.cpp new file mode 100644 index 00000000..362fcdde --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-static_assert_fail_compile.cpp @@ -0,0 +1,5 @@ +int main(void) +{ + static_assert(1 < 0, "your ordering of integers is screwed"); + return 0; +} diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-variadic_templates.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-variadic_templates.cpp new file mode 100644 index 00000000..4518e886 --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-variadic_templates.cpp @@ -0,0 +1,23 @@ +int Accumulate() +{ + return 0; +} + +template +int Accumulate(T v, Ts... vs) +{ + return v + Accumulate(vs...); +} + +template +int CountElements() +{ + return sizeof...(Is); +} + +int main() +{ + int acc = Accumulate(1, 2, 3, 4, -5); + int count = CountElements<1,2,3,4,5>(); + return ((acc == 5) && (count == 5)) ? 0 : 1; +} From 596bf12877caae5bef908603904a4801a2f68d31 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Fri, 23 Nov 2012 11:40:56 +0000 Subject: [PATCH 02/47] Run the feature detection at CMake time --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e8bbf35..a1004858 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,6 +69,8 @@ if(CMAKE_CXX_COMPILER MATCHES "clang") ADD_DEFINITIONS(-std=c++0x) #Enable C++0x mode endif() +INCLUDE(cmake/Modules/CheckCXX11Features.cmake) + ADD_SUBDIRECTORY(library) OPTION(ENABLE_EXAMPLES "Should the examples be built" ON) From 3902e00a0f6a27a6e01d81386fd017ca4e4bdee2 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Fri, 23 Nov 2012 11:45:13 +0000 Subject: [PATCH 03/47] Add a CompilerCapabilities.h.in file which is filled in by CMake It will #define a each of the basic features detected by CMake which can then be used by other headers (like TypeDef.h) to set things up for PolyVox. It is this file which you will have to manually edit and rename if you want to skip using CMake. --- examples/Basic/CMakeLists.txt | 2 +- examples/OpenGL/CMakeLists.txt | 2 +- examples/Paging/CMakeLists.txt | 2 +- examples/SmoothLOD/CMakeLists.txt | 2 +- library/PolyVoxCore/CMakeLists.txt | 5 ++++- .../include/PolyVoxCore/Impl/CompilerCapabilities.h.in | 6 ++++++ library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h | 2 ++ library/PolyVoxUtil/CMakeLists.txt | 2 +- library/bindings/CMakeLists.txt | 2 +- tests/CMakeLists.txt | 2 +- 10 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h.in diff --git a/examples/Basic/CMakeLists.txt b/examples/Basic/CMakeLists.txt index a17c1eeb..741aa5a0 100644 --- a/examples/Basic/CMakeLists.txt +++ b/examples/Basic/CMakeLists.txt @@ -50,7 +50,7 @@ SOURCE_GROUP("Headers" FILES ${INC_FILES}) FIND_PACKAGE(OpenGL REQUIRED) #Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location) -INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include ${PolyVoxCore_BINARY_DIR}/include) LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}) #Build diff --git a/examples/OpenGL/CMakeLists.txt b/examples/OpenGL/CMakeLists.txt index 5b61f759..e90fc80a 100644 --- a/examples/OpenGL/CMakeLists.txt +++ b/examples/OpenGL/CMakeLists.txt @@ -56,7 +56,7 @@ SOURCE_GROUP("Headers" FILES ${INC_FILES}) FIND_PACKAGE(OpenGL REQUIRED) #Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location) -INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include ${PolyVoxCore_BINARY_DIR}/include) LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}) #Build diff --git a/examples/Paging/CMakeLists.txt b/examples/Paging/CMakeLists.txt index 88fb5b6f..7b07b742 100644 --- a/examples/Paging/CMakeLists.txt +++ b/examples/Paging/CMakeLists.txt @@ -52,7 +52,7 @@ SOURCE_GROUP("Headers" FILES ${INC_FILES}) FIND_PACKAGE(OpenGL REQUIRED) #Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location) -INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include ${PolyVoxCore_BINARY_DIR}/include) LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}) #Build diff --git a/examples/SmoothLOD/CMakeLists.txt b/examples/SmoothLOD/CMakeLists.txt index 86923a0a..c911c6a1 100644 --- a/examples/SmoothLOD/CMakeLists.txt +++ b/examples/SmoothLOD/CMakeLists.txt @@ -50,7 +50,7 @@ SOURCE_GROUP("Headers" FILES ${INC_FILES}) FIND_PACKAGE(OpenGL REQUIRED) #Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location) -INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include ${PolyVoxCore_BINARY_DIR}/include) LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}) #Build diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index e4b4f443..8fc62c0a 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -24,6 +24,9 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(PolyVoxCore) +#Set up the C++11 feature header file based on the CheckCXX11Features script +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/PolyVoxCore/Impl/CompilerCapabilities.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/PolyVoxCore/Impl/CompilerCapabilities.h) + #Projects source files SET(CORE_SRC_FILES source/ArraySizes.cpp @@ -128,7 +131,7 @@ SOURCE_GROUP("Sources\\Impl" FILES ${IMPL_SRC_FILES}) SOURCE_GROUP("Headers\\Impl" FILES ${IMPL_INC_FILES}) #Tell CMake the paths -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}/include) #Core #Build diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h.in b/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h.in new file mode 100644 index 00000000..6876d1a7 --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h.in @@ -0,0 +1,6 @@ +#ifndef __PolyVox_CompilerCapabilities_H__ +#define __PolyVox_CompilerCapabilities_H__ + +#cmakedefine HAS_CXX11_CONSTEXPR + +#endif diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h index 8feb34bd..113ccfd8 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h @@ -24,6 +24,8 @@ freely, subject to the following restrictions: #ifndef __PolyVox_TypeDef_H__ #define __PolyVox_TypeDef_H__ +#include "PolyVoxCore/Impl/CompilerCapabilities.h" + //Definitions needed to make library functions accessable // See http://gcc.gnu.org/wiki/Visibility for more info. #if defined _WIN32 || defined __CYGWIN__ diff --git a/library/PolyVoxUtil/CMakeLists.txt b/library/PolyVoxUtil/CMakeLists.txt index 97dbb8da..38425346 100644 --- a/library/PolyVoxUtil/CMakeLists.txt +++ b/library/PolyVoxUtil/CMakeLists.txt @@ -45,7 +45,7 @@ SOURCE_GROUP("Sources" FILES ${UTIL_SRC_FILES}) SOURCE_GROUP("Headers" FILES ${UTIL_INC_FILES}) #Tell CMake the paths -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${PolyVoxCore_BINARY_DIR}/include) #There has to be a better way! LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/debug ${PolyVoxCore_BINARY_DIR}/release ${PolyVoxCore_BINARY_DIR}) diff --git a/library/bindings/CMakeLists.txt b/library/bindings/CMakeLists.txt index e976c015..33172fdb 100644 --- a/library/bindings/CMakeLists.txt +++ b/library/bindings/CMakeLists.txt @@ -36,7 +36,7 @@ if(ENABLE_BINDINGS) include(${SWIG_USE_FILE}) include_directories(${PYTHON_INCLUDE_PATH}) - include_directories(${PolyVoxCore_SOURCE_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include/PolyVoxCore) + include_directories(${PolyVoxCore_SOURCE_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include/PolyVoxCore ${PolyVoxCore_BINARY_DIR}/include) link_directories(${PolyVoxCore_BINARY_DIR}) set(CMAKE_SWIG_FLAGS "") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6c6fe163..693a7026 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -39,7 +39,7 @@ MACRO(CREATE_TEST headerfile sourcefile executablename) SET_PROPERTY(TARGET ${executablename} PROPERTY FOLDER "Tests") ENDMACRO(CREATE_TEST) -INCLUDE_DIRECTORIES(${PolyVox_SOURCE_DIR}/PolyVoxCore/include ${CMAKE_CURRENT_BINARY_DIR}) +INCLUDE_DIRECTORIES(${PolyVox_SOURCE_DIR}/PolyVoxCore/include ${PolyVoxCore_BINARY_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}) REMOVE_DEFINITIONS(-DQT_GUI_LIB) #Make sure the tests don't link to the QtGui # Test Template. Copy and paste this template for consistant naming. From c8657943c8155ff37deca951346e391861a398ad Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Fri, 23 Nov 2012 11:51:55 +0000 Subject: [PATCH 04/47] Create polyvox_constexpr macros based on the detected features We now have a two new polyvox_ macros: * polyvox_constexpr which is 'constexpr' is supported and '' otherwise * polyvox_constexpr_const constexpr which is also 'constexpr' is supported but falls back to 'const' otherwise. These macros should be safe to use liberally without worrying about which compiler you're on. --- library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h index 113ccfd8..20866217 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h @@ -104,4 +104,12 @@ freely, subject to the following restrictions: //#define static_assert static_assert //we can use this #endif +#if defined(HAS_CXX11_CONSTEXPR) + #define polyvox_constexpr_const constexpr //constexpr which falls back to const + #define polyvox_constexpr constexpr //constexpr which falls back to nothing +#else + #define polyvox_constexpr_const const + #define polyvox_constexpr +#endif + #endif From 4b2c899dc6244c92e4dd913d760a3408e79eda48 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Fri, 23 Nov 2012 12:02:57 +0000 Subject: [PATCH 05/47] Define static_assert in the same way Hopefully this won't change anything as we already had a check for it. However, it is now based compiler checks rather than version numbers. We haven't use static_assert anywhere in code yet anyway. --- .../PolyVoxCore/Impl/CompilerCapabilities.h.in | 2 ++ .../PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h.in b/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h.in index 6876d1a7..8c1638c3 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h.in +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h.in @@ -3,4 +3,6 @@ #cmakedefine HAS_CXX11_CONSTEXPR +#cmakedefine HAS_CXX11_STATIC_ASSERT + #endif diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h index 20866217..e16b3b5a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h @@ -77,9 +77,6 @@ freely, subject to the following restrictions: #define polyvox_bind boost::bind #define polyvox_placeholder_1 _1 #define polyvox_placeholder_2 _2 - - #include - #define static_assert BOOST_STATIC_ASSERT //As long as we're requiring boost, we'll use it to compensate @@ -101,7 +98,6 @@ freely, subject to the following restrictions: #define polyvox_bind std::bind #define polyvox_placeholder_1 std::placeholders::_1 #define polyvox_placeholder_2 std::placeholders::_2 - //#define static_assert static_assert //we can use this #endif #if defined(HAS_CXX11_CONSTEXPR) @@ -112,4 +108,11 @@ freely, subject to the following restrictions: #define polyvox_constexpr #endif +#if defined(HAS_CXX11_STATIC_ASSERT) + //In this case we can just use static_assert +#else + #include + #define static_assert BOOST_STATIC_ASSERT +#endif + #endif From dbb5832d52aa2d7d006fc727181ab1bb09a4dc15 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Fri, 23 Nov 2012 12:59:16 +0000 Subject: [PATCH 06/47] Move the cstdint detection to the new framework Again, hopefully nothing will change but a test on MSVC 2008/2005 might be needed. --- .../Impl/CompilerCapabilities.h.in | 2 ++ .../include/PolyVoxCore/Impl/TypeDef.h | 24 +++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h.in b/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h.in index 8c1638c3..0a5cfed1 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h.in +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h.in @@ -5,4 +5,6 @@ #cmakedefine HAS_CXX11_STATIC_ASSERT +#cmakedefine HAS_CXX11_CSTDINT_H + #endif diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h index e16b3b5a..0f9c832e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h @@ -77,20 +77,8 @@ freely, subject to the following restrictions: #define polyvox_bind boost::bind #define polyvox_placeholder_1 _1 #define polyvox_placeholder_2 _2 - - - //As long as we're requiring boost, we'll use it to compensate - //for the missing cstdint header too. - #include - using boost::int8_t; - using boost::int16_t; - using boost::int32_t; - using boost::uint8_t; - using boost::uint16_t; - using boost::uint32_t; #else //We have a decent compiler - use real C++0x features - #include #include #include #define polyvox_shared_ptr std::shared_ptr @@ -115,4 +103,16 @@ freely, subject to the following restrictions: #define static_assert BOOST_STATIC_ASSERT #endif +#if defined(HAS_CXX11_CSTDINT_H) + #include +#else + #include + using boost::int8_t; + using boost::int16_t; + using boost::int32_t; + using boost::uint8_t; + using boost::uint16_t; + using boost::uint32_t; +#endif + #endif From 989e6ea5894f65d08ef015360bbfbf77d8bb889a Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Fri, 23 Nov 2012 14:04:14 +0000 Subject: [PATCH 07/47] Fix SWIG complaining about redefining uint8_t etc. --- library/bindings/PolyVoxCore.i | 1 + 1 file changed, 1 insertion(+) diff --git a/library/bindings/PolyVoxCore.i b/library/bindings/PolyVoxCore.i index 09fa805e..370f0b6b 100644 --- a/library/bindings/PolyVoxCore.i +++ b/library/bindings/PolyVoxCore.i @@ -1,6 +1,7 @@ %module PolyVoxCore #define POLYVOX_API +%include "PolyVoxCore/Impl/CompilerCapabilities.h" %include "Impl/TypeDef.h" #define __attribute__(x) //Silence DEPRECATED errors From 9f5fe452c9b66fb8e5d66f8d939d975c8393e81d Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Fri, 23 Nov 2012 14:16:23 +0000 Subject: [PATCH 08/47] Give shared_ptr the same treatment. Here I have defined my own test for the feature. It's not an extensive test but it checks for the presence of the class. --- cmake/Modules/CheckCXX11Features.cmake | 1 + .../CheckCXX11Features/cxx11-test-shared_ptr.cpp | 7 +++++++ .../PolyVoxCore/Impl/CompilerCapabilities.h.in | 2 ++ .../PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h | 13 ++++++++----- 4 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 cmake/Modules/CheckCXX11Features/cxx11-test-shared_ptr.cpp diff --git a/cmake/Modules/CheckCXX11Features.cmake b/cmake/Modules/CheckCXX11Features.cmake index 0699f48e..5373ba6a 100644 --- a/cmake/Modules/CheckCXX11Features.cmake +++ b/cmake/Modules/CheckCXX11Features.cmake @@ -130,3 +130,4 @@ cxx11_check_feature("rvalue-references" HAS_CXX11_RVALUE_REFERENCES) cxx11_check_feature("sizeof_member" HAS_CXX11_SIZEOF_MEMBER) cxx11_check_feature("static_assert" HAS_CXX11_STATIC_ASSERT) cxx11_check_feature("variadic_templates" HAS_CXX11_VARIADIC_TEMPLATES) +cxx11_check_feature("shared_ptr" HAS_CXX11_SHARED_PTR) diff --git a/cmake/Modules/CheckCXX11Features/cxx11-test-shared_ptr.cpp b/cmake/Modules/CheckCXX11Features/cxx11-test-shared_ptr.cpp new file mode 100644 index 00000000..2d9c6bd1 --- /dev/null +++ b/cmake/Modules/CheckCXX11Features/cxx11-test-shared_ptr.cpp @@ -0,0 +1,7 @@ +#include + +int main() +{ + std::shared_ptr test; + return 0; +} diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h.in b/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h.in index 0a5cfed1..5518dfb2 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h.in +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h.in @@ -7,4 +7,6 @@ #cmakedefine HAS_CXX11_CSTDINT_H +#cmakedefine HAS_CXX11_SHARED_PTR + #endif diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h index 0f9c832e..996414ca 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h @@ -67,9 +67,6 @@ freely, subject to the following restrictions: //To support old (pre-vc2010) Microsoft compilers we use boost to replace the //std::shared_ptr and potentially other C++0x features. To use this capability you //will need to make sure you have boost installed on your system. - #include - #define polyvox_shared_ptr boost::shared_ptr - #include #define polyvox_function boost::function @@ -80,8 +77,6 @@ freely, subject to the following restrictions: #else //We have a decent compiler - use real C++0x features #include - #include - #define polyvox_shared_ptr std::shared_ptr #define polyvox_function std::function #define polyvox_bind std::bind #define polyvox_placeholder_1 std::placeholders::_1 @@ -115,4 +110,12 @@ freely, subject to the following restrictions: using boost::uint32_t; #endif +#if defined(HAS_CXX11_SHARED_PTR) + #include + #define polyvox_shared_ptr std::shared_ptr +#else + #include + #define polyvox_shared_ptr boost::shared_ptr +#endif + #endif From a8bc3081fb12ee36d83fbae08166cab4d2b1dce3 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Wed, 12 Dec 2012 14:48:10 +0000 Subject: [PATCH 09/47] Disable checks for a few C++11 features We don't use a lot of these features so don't bother checking for them just yet. --- cmake/Modules/CheckCXX11Features.cmake | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cmake/Modules/CheckCXX11Features.cmake b/cmake/Modules/CheckCXX11Features.cmake index 5373ba6a..b3158f4c 100644 --- a/cmake/Modules/CheckCXX11Features.cmake +++ b/cmake/Modules/CheckCXX11Features.cmake @@ -114,20 +114,20 @@ function(cxx11_check_feature FEATURE_NAME RESULT_VAR) endif (NOT DEFINED ${RESULT_VAR}) endfunction(cxx11_check_feature) -cxx11_check_feature("__func__" HAS_CXX11_FUNC) -cxx11_check_feature("auto" HAS_CXX11_AUTO) -cxx11_check_feature("auto_ret_type" HAS_CXX11_AUTO_RET_TYPE) -cxx11_check_feature("class_override_final" HAS_CXX11_CLASS_OVERRIDE) +#cxx11_check_feature("__func__" HAS_CXX11_FUNC) +#cxx11_check_feature("auto" HAS_CXX11_AUTO) +#cxx11_check_feature("auto_ret_type" HAS_CXX11_AUTO_RET_TYPE) +#cxx11_check_feature("class_override_final" HAS_CXX11_CLASS_OVERRIDE) cxx11_check_feature("constexpr" HAS_CXX11_CONSTEXPR) cxx11_check_feature("cstdint" HAS_CXX11_CSTDINT_H) -cxx11_check_feature("decltype" HAS_CXX11_DECLTYPE) -cxx11_check_feature("initializer_list" HAS_CXX11_INITIALIZER_LIST) -cxx11_check_feature("lambda" HAS_CXX11_LAMBDA) -cxx11_check_feature("long_long" HAS_CXX11_LONG_LONG) -cxx11_check_feature("nullptr" HAS_CXX11_NULLPTR) -cxx11_check_feature("regex" HAS_CXX11_LIB_REGEX) -cxx11_check_feature("rvalue-references" HAS_CXX11_RVALUE_REFERENCES) -cxx11_check_feature("sizeof_member" HAS_CXX11_SIZEOF_MEMBER) +#cxx11_check_feature("decltype" HAS_CXX11_DECLTYPE) +#cxx11_check_feature("initializer_list" HAS_CXX11_INITIALIZER_LIST) +#cxx11_check_feature("lambda" HAS_CXX11_LAMBDA) +#cxx11_check_feature("long_long" HAS_CXX11_LONG_LONG) +#cxx11_check_feature("nullptr" HAS_CXX11_NULLPTR) +#cxx11_check_feature("regex" HAS_CXX11_LIB_REGEX) +#cxx11_check_feature("rvalue-references" HAS_CXX11_RVALUE_REFERENCES) +#cxx11_check_feature("sizeof_member" HAS_CXX11_SIZEOF_MEMBER) cxx11_check_feature("static_assert" HAS_CXX11_STATIC_ASSERT) -cxx11_check_feature("variadic_templates" HAS_CXX11_VARIADIC_TEMPLATES) +#cxx11_check_feature("variadic_templates" HAS_CXX11_VARIADIC_TEMPLATES) cxx11_check_feature("shared_ptr" HAS_CXX11_SHARED_PTR) From 2a12bcd6d67e92ca235727531ecb746acf69f435 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Tue, 18 Dec 2012 14:34:36 +0100 Subject: [PATCH 10/47] Fixed behavior of SimpleVolumeSampler.inl --- .../PolyVoxCore/SimpleVolumeSampler.inl | 66 +++++++++++-------- tests/testvolume.cpp | 4 +- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl index 7920fc6b..d324b966 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl @@ -26,6 +26,13 @@ freely, subject to the following restrictions: //#define BORDER_LOW(x) (( x % this->mVolume->m_uBlockSideLength) != 0) //#define BORDER_HIGH(x) (( x % this->mVolume->m_uBlockSideLength) != this->mVolume->m_uBlockSideLength - 1) +#define CAN_GO_NEG_X(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getX()) && ((( val >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != val)) +#define CAN_GO_POS_X(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getX()) && ((( (val+1) >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != (val+1))) +#define CAN_GO_NEG_Y(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getY()) && ((( val >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != val)) +#define CAN_GO_POS_Y(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getY()) && ((( (val+1) >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != (val+1))) +#define CAN_GO_NEG_Z(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getZ()) && ((( val >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != val)) +#define CAN_GO_POS_Z(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getZ()) && ((( (val+1) >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != (val+1))) + namespace PolyVox { /** @@ -299,7 +306,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1nx1ny1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -309,7 +316,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1nx1ny0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength); } @@ -319,7 +326,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1nx1ny1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -329,7 +336,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1nx0py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -339,7 +346,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1nx0py0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) ) { return *(mCurrentVoxel - 1); } @@ -349,7 +356,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1nx0py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -359,7 +366,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1nx1py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -369,7 +376,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1nx1py0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength); } @@ -379,7 +386,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1nx1py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -391,7 +398,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel0px1ny1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -401,7 +408,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel0px1ny0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength); } @@ -411,7 +418,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel0px1ny1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -421,7 +428,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel0px0py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -441,7 +448,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel0px0py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -451,7 +458,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel0px1py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -461,7 +468,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel0px1py0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength); } @@ -471,7 +478,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel0px1py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -483,7 +490,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1px1ny1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -493,7 +500,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1px1ny0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength); } @@ -503,7 +510,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1px1ny1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -513,7 +520,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1px0py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -523,7 +530,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1px0py0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) ) { return *(mCurrentVoxel + 1); } @@ -533,7 +540,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1px0py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -543,7 +550,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1px1py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -553,7 +560,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1px1py0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength); } @@ -563,7 +570,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1px1py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -571,5 +578,12 @@ namespace PolyVox } } +#undef CAN_GO_NEG_X +#undef CAN_GO_POS_X +#undef CAN_GO_NEG_Y +#undef CAN_GO_POS_Y +#undef CAN_GO_NEG_Z +#undef CAN_GO_POS_Z + #undef BORDER_LOW #undef BORDER_HIGH diff --git a/tests/testvolume.cpp b/tests/testvolume.cpp index 088670b2..8913d915 100644 --- a/tests/testvolume.cpp +++ b/tests/testvolume.cpp @@ -321,12 +321,12 @@ void TestVolume::testSimpleVolumeDirectAccess() void TestVolume::testSimpleVolumeSamplers() { - /*int32_t result = 0; + int32_t result = 0; QBENCHMARK { result = testSamplersWithWrapping(m_pSimpleVolume); } - QCOMPARE(result, static_cast(-601818385)); //FXME - Wrong value?!*/ + QCOMPARE(result, static_cast(-928601007)); } void TestVolume::testLargeVolumeDirectAccess() From 1c61329e6756c15b50fe3fca755c96e2b41fdec5 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Tue, 18 Dec 2012 15:13:41 +0000 Subject: [PATCH 11/47] Fix compilation in Linux --- library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index 1fafad5a..8a0a2e34 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -31,7 +31,7 @@ namespace PolyVox RawVolume::RawVolume(const Region& regValid) :BaseVolume(regValid) { - setBorderValue(VoxelType()); + this->setBorderValue(VoxelType()); //Create a volume of the right size. initialise(regValid); From 8b018be2dc67a65b4fea84c8b62a6170d7028239 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Tue, 18 Dec 2012 16:25:31 +0100 Subject: [PATCH 12/47] Fix for LargeVolumeSampler. --- .../PolyVoxCore/LargeVolumeSampler.inl | 70 ++++++++++--------- .../PolyVoxCore/SimpleVolumeSampler.inl | 20 ++---- tests/testvolume.cpp | 8 +-- 3 files changed, 48 insertions(+), 50 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl index 530fafc0..b6f3fc4f 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl @@ -21,10 +21,12 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#define BORDER_LOW(x) ((( x >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != x) -#define BORDER_HIGH(x) ((( (x+1) >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != (x+1)) -//#define BORDER_LOW(x) (( x % mVolume->m_uBlockSideLength) != 0) -//#define BORDER_HIGH(x) (( x % mVolume->m_uBlockSideLength) != mVolume->m_uBlockSideLength - 1) +#define CAN_GO_NEG_X(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getX()) && (val % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_POS_X(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getX()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_NEG_Y(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getY()) && (val % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_POS_Y(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getY()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_NEG_Z(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getZ()) && (val % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_POS_Z(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getZ()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) namespace PolyVox { @@ -280,7 +282,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1nx1ny1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -290,7 +292,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1nx1ny0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength); } @@ -300,7 +302,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1nx1ny1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -310,7 +312,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1nx0py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -320,7 +322,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1nx0py0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) ) { return *(mCurrentVoxel - 1); } @@ -330,7 +332,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1nx0py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -340,7 +342,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1nx1py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -350,7 +352,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1nx1py0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength); } @@ -360,7 +362,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1nx1py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -372,7 +374,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel0px1ny1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -382,7 +384,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel0px1ny0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength); } @@ -392,7 +394,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel0px1ny1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -402,7 +404,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel0px0py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -422,7 +424,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel0px0py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -432,7 +434,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel0px1py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -442,7 +444,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel0px1py0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength); } @@ -452,7 +454,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel0px1py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -464,7 +466,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1px1ny1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -474,7 +476,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1px1ny0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength); } @@ -484,7 +486,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1px1ny1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -494,7 +496,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1px0py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -504,7 +506,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1px0py0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) ) { return *(mCurrentVoxel + 1); } @@ -514,7 +516,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1px0py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -524,7 +526,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1px1py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -534,7 +536,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1px1py0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength); } @@ -544,7 +546,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1px1py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -552,5 +554,9 @@ namespace PolyVox } } -#undef BORDER_LOW -#undef BORDER_HIGH +#undef CAN_GO_NEG_X +#undef CAN_GO_POS_X +#undef CAN_GO_NEG_Y +#undef CAN_GO_POS_Y +#undef CAN_GO_NEG_Z +#undef CAN_GO_POS_Z diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl index d324b966..8e8deddf 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl @@ -21,17 +21,12 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#define BORDER_LOW(x) ((( x >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != x) -#define BORDER_HIGH(x) ((( (x+1) >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != (x+1)) -//#define BORDER_LOW(x) (( x % this->mVolume->m_uBlockSideLength) != 0) -//#define BORDER_HIGH(x) (( x % this->mVolume->m_uBlockSideLength) != this->mVolume->m_uBlockSideLength - 1) - -#define CAN_GO_NEG_X(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getX()) && ((( val >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != val)) -#define CAN_GO_POS_X(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getX()) && ((( (val+1) >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != (val+1))) -#define CAN_GO_NEG_Y(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getY()) && ((( val >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != val)) -#define CAN_GO_POS_Y(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getY()) && ((( (val+1) >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != (val+1))) -#define CAN_GO_NEG_Z(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getZ()) && ((( val >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != val)) -#define CAN_GO_POS_Z(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getZ()) && ((( (val+1) >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != (val+1))) +#define CAN_GO_NEG_X(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getX()) && (val % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_POS_X(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getX()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_NEG_Y(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getY()) && (val % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_POS_Y(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getY()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_NEG_Z(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getZ()) && (val % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_POS_Z(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getZ()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) namespace PolyVox { @@ -584,6 +579,3 @@ namespace PolyVox #undef CAN_GO_POS_Y #undef CAN_GO_NEG_Z #undef CAN_GO_POS_Z - -#undef BORDER_LOW -#undef BORDER_HIGH diff --git a/tests/testvolume.cpp b/tests/testvolume.cpp index 8913d915..47130f95 100644 --- a/tests/testvolume.cpp +++ b/tests/testvolume.cpp @@ -331,23 +331,23 @@ void TestVolume::testSimpleVolumeSamplers() void TestVolume::testLargeVolumeDirectAccess() { - /*int32_t result = 0; + int32_t result = 0; QBENCHMARK { result = testDirectAccessWithWrapping(m_pLargeVolume); } - QCOMPARE(result, static_cast(-601818385)); //FXME - Wrong value?!*/ + QCOMPARE(result, static_cast(-928601007)); } void TestVolume::testLargeVolumeSamplers() { int32_t result = 0; - /*QBENCHMARK + QBENCHMARK { result = testSamplersWithWrapping(m_pLargeVolume); } - QCOMPARE(result, static_cast(-601818385)); //FXME - Wrong value?!*/ + QCOMPARE(result, static_cast(-928601007)); } QTEST_MAIN(TestVolume) From 4396c609bbab4c8580a9e620401cc609245d020b Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Tue, 18 Dec 2012 16:46:57 +0100 Subject: [PATCH 13/47] Added wrap mode support to CubicSurfaceExtractor. --- .../include/PolyVoxCore/CubicSurfaceExtractor.h | 7 ++++++- .../include/PolyVoxCore/CubicSurfaceExtractor.inl | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h index 76f53f89..524132b6 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h @@ -29,6 +29,7 @@ freely, subject to the following restrictions: #include "PolyVoxForwardDeclarations.h" #include "PolyVoxCore/Array.h" +#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these? #include "PolyVoxCore/DefaultIsQuadNeeded.h" #include "PolyVoxCore/SurfaceMesh.h" @@ -109,7 +110,7 @@ namespace PolyVox }; public: - CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); + CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(0), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); void execute(); @@ -145,6 +146,10 @@ namespace PolyVox //This constant defines the maximum number of quads which can share a //vertex in a cubic style mesh. See the initialisation for more details. static const uint32_t MaxVerticesPerPosition; + + //The wrap mode + WrapMode m_eWrapMode; + typename VolumeType::VoxelType m_tBorderValue; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl index 211498c9..c9b793f5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl @@ -35,11 +35,13 @@ namespace PolyVox const uint32_t CubicSurfaceExtractor::MaxVerticesPerPosition = 6; template - CubicSurfaceExtractor::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, bool bMergeQuads, IsQuadNeeded isQuadNeeded) + CubicSurfaceExtractor::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded) :m_volData(volData) ,m_regSizeInVoxels(region) ,m_meshCurrent(result) ,m_bMergeQuads(bMergeQuads) + ,m_eWrapMode(eWrapMode) + ,m_tBorderValue(tBorderValue) { m_funcIsQuadNeededCallback = isQuadNeeded; } @@ -68,6 +70,7 @@ namespace PolyVox m_vecQuads[PositiveZ].resize(m_regSizeInVoxels.getUpperCorner().getZ() - m_regSizeInVoxels.getLowerCorner().getZ() + 2); typename VolumeType::Sampler volumeSampler(m_volData); + volumeSampler.setWrapMode(m_eWrapMode, m_tBorderValue); for(int32_t z = m_regSizeInVoxels.getLowerCorner().getZ(); z <= m_regSizeInVoxels.getUpperCorner().getZ(); z++) { From 933c211d47ef32f70fba25cd41c4fefeb88b4fc4 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Wed, 19 Dec 2012 11:23:55 +0100 Subject: [PATCH 14/47] Added wrap mode support to CubicSurfaceExtractorWithNormals. --- .../CubicSurfaceExtractorWithNormals.h | 7 ++++++- .../CubicSurfaceExtractorWithNormals.inl | 16 +++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h index cf5bd70e..0d9f61bb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h @@ -27,6 +27,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/DefaultIsQuadNeeded.h" #include "PolyVoxCore/Array.h" +#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these? #include "PolyVoxCore/SurfaceMesh.h" namespace PolyVox @@ -35,7 +36,7 @@ namespace PolyVox class CubicSurfaceExtractorWithNormals { public: - CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh* result, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); + CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(0), IsQuadNeeded isQuadNeeded = IsQuadNeeded()); void execute(); @@ -51,6 +52,10 @@ namespace PolyVox //Information about the region we are currently processing Region m_regSizeInVoxels; + + //The wrap mode + WrapMode m_eWrapMode; + typename VolumeType::VoxelType m_tBorderValue; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl index e3c5ca34..5e16d3b8 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl @@ -24,11 +24,13 @@ freely, subject to the following restrictions: namespace PolyVox { template - CubicSurfaceExtractorWithNormals::CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh* result, IsQuadNeeded isQuadNeeded) + CubicSurfaceExtractorWithNormals::CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, IsQuadNeeded isQuadNeeded) :m_volData(volData) ,m_sampVolume(volData) ,m_meshCurrent(result) ,m_regSizeInVoxels(region) + ,m_eWrapMode(eWrapMode) + ,m_tBorderValue(tBorderValue) { m_funcIsQuadNeededCallback = isQuadNeeded; } @@ -51,7 +53,7 @@ namespace PolyVox uint32_t material = 0; - if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z), m_volData->getVoxelAt(x+1,y,z), material)) + if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x+1,y,z,m_eWrapMode,m_tBorderValue), material)) { uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ - 0.5f), Vector3DFloat(1.0f, 0.0f, 0.0f), static_cast(material))); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(1.0f, 0.0f, 0.0f), static_cast(material))); @@ -61,7 +63,7 @@ namespace PolyVox m_meshCurrent->addTriangleCubic(v0,v2,v1); m_meshCurrent->addTriangleCubic(v1,v2,v3); } - if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x+1,y,z), m_volData->getVoxelAt(x,y,z), material)) + if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x+1,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), material)) { uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ - 0.5f), Vector3DFloat(-1.0f, 0.0f, 0.0f), static_cast(material))); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(-1.0f, 0.0f, 0.0f), static_cast(material))); @@ -72,7 +74,7 @@ namespace PolyVox m_meshCurrent->addTriangleCubic(v1,v3,v2); } - if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z), m_volData->getVoxelAt(x,y+1,z), material)) + if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y+1,z,m_eWrapMode,m_tBorderValue), material)) { uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(0.0f, 1.0f, 0.0f), static_cast(material))); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 1.0f, 0.0f), static_cast(material))); @@ -82,7 +84,7 @@ namespace PolyVox m_meshCurrent->addTriangleCubic(v0,v1,v2); m_meshCurrent->addTriangleCubic(v1,v3,v2); } - if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y+1,z), m_volData->getVoxelAt(x,y,z), material)) + if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y+1,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), material)) { uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(0.0f, -1.0f, 0.0f), static_cast(material))); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, -1.0f, 0.0f), static_cast(material))); @@ -93,7 +95,7 @@ namespace PolyVox m_meshCurrent->addTriangleCubic(v1,v2,v3); } - if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z), m_volData->getVoxelAt(x,y,z+1), material)) + if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y,z+1,m_eWrapMode,m_tBorderValue), material)) { uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, 1.0f), static_cast(material))); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, 1.0f), static_cast(material))); @@ -103,7 +105,7 @@ namespace PolyVox m_meshCurrent->addTriangleCubic(v0,v2,v1); m_meshCurrent->addTriangleCubic(v1,v2,v3); } - if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z+1), m_volData->getVoxelAt(x,y,z), material)) + if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y,z+1,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), material)) { uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, -1.0f), static_cast(material))); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, -1.0f), static_cast(material))); From 44dcb0ba898cef8c10c1a97616efeddf55d776d6 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Wed, 19 Dec 2012 11:32:45 +0100 Subject: [PATCH 15/47] Different method of controlling the war mode of the MarchingCubesSurfaceExtractor. --- .../include/PolyVoxCore/MarchingCubesSurfaceExtractor.h | 3 ++- .../include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl | 4 ++-- tests/TestSurfaceExtractor.cpp | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h index b0d7c694..6473a3d4 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h @@ -28,6 +28,7 @@ freely, subject to the following restrictions: #include "Impl/TypeDef.h" #include "PolyVoxCore/Array.h" +#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these? #include "PolyVoxCore/SurfaceMesh.h" #include "PolyVoxCore/DefaultMarchingCubesController.h" @@ -37,7 +38,7 @@ namespace PolyVox class MarchingCubesSurfaceExtractor { public: - MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, Controller controller = Controller()); + MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(0), Controller controller = Controller()); void execute(); diff --git a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl index 23617603..1ca352eb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl @@ -24,7 +24,7 @@ freely, subject to the following restrictions: namespace PolyVox { template - MarchingCubesSurfaceExtractor::MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, Controller controller) + MarchingCubesSurfaceExtractor::MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, Controller controller) :m_volData(volData) ,m_sampVolume(volData) ,m_meshCurrent(result) @@ -36,7 +36,7 @@ namespace PolyVox m_regSizeInCells = m_regSizeInVoxels; m_regSizeInCells.setUpperCorner(m_regSizeInCells.getUpperCorner() - Vector3DInt32(1,1,1)); - m_sampVolume.setWrapMode(m_controller.getWrapMode(), m_controller.getBorderValue()); + m_sampVolume.setWrapMode(eWrapMode, tBorderValue); } template diff --git a/tests/TestSurfaceExtractor.cpp b/tests/TestSurfaceExtractor.cpp index 4bc7fc15..6114935d 100644 --- a/tests/TestSurfaceExtractor.cpp +++ b/tests/TestSurfaceExtractor.cpp @@ -132,7 +132,7 @@ void testForType(SurfaceMesh& result) DefaultMarchingCubesController controller; controller.setThreshold(50); - MarchingCubesSurfaceExtractor< SimpleVolume > extractor(&volData, volData.getEnclosingRegion(), &result, controller); + MarchingCubesSurfaceExtractor< SimpleVolume > extractor(&volData, volData.getEnclosingRegion(), &result, WrapModes::Border, 0, controller); extractor.execute(); } @@ -156,7 +156,7 @@ void testCustomController(SurfaceMesh& result) } CustomMarchingCubesController controller; - MarchingCubesSurfaceExtractor< SimpleVolume, CustomMarchingCubesController > extractor(&volData, volData.getEnclosingRegion(), &result, controller); + MarchingCubesSurfaceExtractor< SimpleVolume, CustomMarchingCubesController > extractor(&volData, volData.getEnclosingRegion(), &result, WrapModes::Border, 0, controller); extractor.execute(); } From 898aa241264aa29324a0dcf68b8534431f581fd0 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Wed, 19 Dec 2012 11:46:44 +0100 Subject: [PATCH 16/47] Removed code which is redundant after previous commit. --- .../DefaultMarchingCubesController.h | 20 ------------------- .../PolyVoxCore/include/PolyVoxCore/Density.h | 19 ------------------ .../include/PolyVoxCore/MaterialDensityPair.h | 14 ------------- tests/TestSurfaceExtractor.cpp | 10 ---------- 4 files changed, 63 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/DefaultMarchingCubesController.h b/library/PolyVoxCore/include/PolyVoxCore/DefaultMarchingCubesController.h index 8d5359e9..7be8dc9e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/DefaultMarchingCubesController.h +++ b/library/PolyVoxCore/include/PolyVoxCore/DefaultMarchingCubesController.h @@ -78,8 +78,6 @@ namespace PolyVox */ DefaultMarchingCubesController(void) :m_tThreshold(((std::numeric_limits::min)() + (std::numeric_limits::max)()) / 2) - ,m_eWrapMode(WrapModes::Border) - ,m_tBorder(VoxelType(0)) { } @@ -105,11 +103,6 @@ namespace PolyVox return 1; } - VoxelType getBorderValue(void) - { - return m_tBorder; - } - /** * Returns the density value which was passed to the constructor. * @@ -122,26 +115,13 @@ namespace PolyVox return m_tThreshold; } - WrapMode getWrapMode(void) - { - return m_eWrapMode; - } - void setThreshold(DensityType tThreshold) { m_tThreshold = tThreshold; } - void setWrapMode(WrapMode eWrapMode, VoxelType tBorder = VoxelType(0)) - { - m_eWrapMode = eWrapMode; - m_tBorder = tBorder; - } - private: DensityType m_tThreshold; - WrapMode m_eWrapMode; - VoxelType m_tBorder; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Density.h b/library/PolyVoxCore/include/PolyVoxCore/Density.h index a92d23b9..4d60ad53 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Density.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Density.h @@ -155,13 +155,11 @@ namespace PolyVox { // Default to a threshold value halfway between the min and max possible values. m_tThreshold = (Density::getMinDensity() + Density::getMaxDensity()) / 2; - m_eWrapMode = WrapModes::Border; } DefaultMarchingCubesController(DensityType tThreshold) { m_tThreshold = tThreshold; - m_eWrapMode = WrapModes::Border; } DensityType convertToDensity(Density voxel) @@ -174,35 +172,18 @@ namespace PolyVox return 1; } - Density getBorderValue(void) - { - return m_tBorder; - } - DensityType getThreshold(void) { return m_tThreshold; } - WrapMode getWrapMode(void) - { - return m_eWrapMode; - } - void setThreshold(DensityType tThreshold) { m_tThreshold = tThreshold; } - void setWrapMode(WrapMode eWrapMode) - { - m_eWrapMode = eWrapMode; - } - private: DensityType m_tThreshold; - WrapMode m_eWrapMode; - Density m_tBorder; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h index d3df49b8..ec8fb874 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h @@ -119,13 +119,11 @@ namespace PolyVox { // Default to a threshold value halfway between the min and max possible values. m_tThreshold = (MaterialDensityPair::getMinDensity() + MaterialDensityPair::getMaxDensity()) / 2; - m_eWrapMode = WrapModes::Border; } DefaultMarchingCubesController(DensityType tThreshold) { m_tThreshold = tThreshold; - m_eWrapMode = WrapModes::Border; } DensityType convertToDensity(MaterialDensityPair voxel) @@ -148,25 +146,13 @@ namespace PolyVox return m_tThreshold; } - WrapMode getWrapMode(void) - { - return m_eWrapMode; - } - void setThreshold(DensityType tThreshold) { m_tThreshold = tThreshold; } - void setWrapMode(WrapMode eWrapMode) - { - m_eWrapMode = eWrapMode; - } - private: DensityType m_tThreshold; - WrapMode m_eWrapMode; - MaterialDensityPair m_tBorder; }; typedef MaterialDensityPair MaterialDensityPair44; diff --git a/tests/TestSurfaceExtractor.cpp b/tests/TestSurfaceExtractor.cpp index 6114935d..80416eb4 100644 --- a/tests/TestSurfaceExtractor.cpp +++ b/tests/TestSurfaceExtractor.cpp @@ -59,16 +59,6 @@ public: { return 50.0f; } - - WrapMode getWrapMode(void) - { - return WrapModes::Border; - } - - float getBorderValue(void) - { - return 0.0f; - } }; // These 'writeDensityValueToVoxel' functions provide a unified interface for writting densities to primative and class voxel types. From b71b4dd032f47fd88b904290cc6ddc6d08ca1b69 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Wed, 19 Dec 2012 16:14:31 +0000 Subject: [PATCH 17/47] Undefine POLYVOX_DEPRECATED when compiling with SWIG We want to wrap the deprecated functions but we don't want to be told off for it. See issue #19 --- library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h index 1bbfa07b..96173233 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h @@ -44,6 +44,13 @@ freely, subject to the following restrictions: #endif #endif +#if defined SWIG + //Do nothing in this case +#else + #undef POLYVOX_DEPRECATED + #define POLYVOX_DEPRECATED //Define it to nothing to avoid warnings +#endif + // Now we use the generic helper definitions above to define POLYVOX_API and POLYVOX_LOCAL. // POLYVOX_API is used for the public API symbols. It either imports or exports (or does nothing for static build) // POLYVOX_LOCAL is used for non-api symbols. From 2ae111a67f8ec903175a4ea2214225ed205baf04 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Sun, 23 Dec 2012 12:29:45 +0000 Subject: [PATCH 18/47] Fix compile error --- library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h | 2 +- .../include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h | 2 +- .../include/PolyVoxCore/MarchingCubesSurfaceExtractor.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h index 524132b6..1928c2ab 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h @@ -110,7 +110,7 @@ namespace PolyVox }; public: - CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(0), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); + CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(0), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); void execute(); diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h index 0d9f61bb..6b74f5ee 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h @@ -36,7 +36,7 @@ namespace PolyVox class CubicSurfaceExtractorWithNormals { public: - CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(0), IsQuadNeeded isQuadNeeded = IsQuadNeeded()); + CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(0), IsQuadNeeded isQuadNeeded = IsQuadNeeded()); void execute(); diff --git a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h index 6473a3d4..4eacd253 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h @@ -38,7 +38,7 @@ namespace PolyVox class MarchingCubesSurfaceExtractor { public: - MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(0), Controller controller = Controller()); + MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(0), Controller controller = Controller()); void execute(); From f22410ed9ad20e9f546d45173ff28ec56e653571 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 23 Dec 2012 13:53:00 +0100 Subject: [PATCH 19/47] Linux compile fix. --- .../PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h index ec8fb874..9ae3bca0 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h @@ -136,11 +136,6 @@ namespace PolyVox return voxel.getMaterial(); } - MaterialDensityPair getBorderValue(void) - { - return m_tBorder; - } - DensityType getThreshold(void) { return m_tThreshold; From fc74ec5f0f6dd5b7b9d9dd537099c36b7f70adbc Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Mon, 24 Dec 2012 15:51:40 +0000 Subject: [PATCH 20/47] The static_assert() methods are now not bound in SWIG The ReducedStorageType here is to work around a bug in SWIG. --- .../include/PolyVoxCore/Vector.inl | 26 +++++-------------- library/bindings/Vector.i | 25 ++++++++++++------ 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Vector.inl b/library/PolyVoxCore/include/PolyVoxCore/Vector.inl index 09501f18..22d3009e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Vector.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Vector.inl @@ -53,9 +53,7 @@ namespace PolyVox template Vector::Vector(StorageType x, StorageType y) { -#ifndef SWIGPYTHON // SWIG instantiates all constructors, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it? static_assert(Size == 2, "This constructor should only be used for vectors with two elements."); -#endif m_tElements[0] = x; m_tElements[1] = y; @@ -70,9 +68,7 @@ namespace PolyVox template Vector::Vector(StorageType x, StorageType y, StorageType z) { -#ifndef SWIGPYTHON // SWIG instantiates all constructors, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it? static_assert(Size == 3, "This constructor should only be used for vectors with three elements."); -#endif m_tElements[0] = x; m_tElements[1] = y; @@ -90,9 +86,7 @@ namespace PolyVox template Vector::Vector(StorageType x, StorageType y, StorageType z, StorageType w) { -#ifndef SWIGPYTHON // SWIG instantiates all constructors, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it? static_assert(Size == 4, "This constructor should only be used for vectors with four elements."); -#endif m_tElements[0] = x; m_tElements[1] = y; @@ -448,9 +442,7 @@ namespace PolyVox template inline StorageType Vector::getZ(void) const { -#ifndef SWIGPYTHON // SWIG instantiates all getters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it? static_assert(Size >= 3, "You can only get the 'z' component from a vector with at least three elements."); -#endif return m_tElements[2]; } @@ -461,9 +453,7 @@ namespace PolyVox template inline StorageType Vector::getW(void) const { -#ifndef SWIGPYTHON // SWIG instantiates all getters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it? static_assert(Size >= 4, "You can only get the 'w' component from a vector with at least four elements."); -#endif return m_tElements[3]; } @@ -501,9 +491,8 @@ namespace PolyVox template inline void Vector::setElements(StorageType x, StorageType y, StorageType z) { -#ifndef SWIGPYTHON // SWIG instantiates all setters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it? static_assert(Size >= 3, "You can only use this version of setElements() on a vector with at least three elements."); -#endif + m_tElements[0] = x; m_tElements[1] = y; m_tElements[2] = z; @@ -519,9 +508,8 @@ namespace PolyVox template inline void Vector::setElements(StorageType x, StorageType y, StorageType z, StorageType w) { -#ifndef SWIGPYTHON // SWIG instantiates all setters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it? static_assert(Size >= 4, "You can only use this version of setElements() on a vector with at least four elements."); -#endif + m_tElements[0] = x; m_tElements[1] = y; m_tElements[2] = z; @@ -552,10 +540,9 @@ namespace PolyVox template inline void Vector::setZ(StorageType tZ) { -#ifndef SWIGPYTHON // SWIG instantiates all setters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it? static_assert(Size >= 3, "You can only set the 'w' component from a vector with at least three elements."); -#endif - m_tElements[2] = tZ; + + m_tElements[2] = tZ; } /** @@ -564,10 +551,9 @@ namespace PolyVox template inline void Vector::setW(StorageType tW) { -#ifndef SWIGPYTHON // SWIG instantiates all setters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it? static_assert(Size >= 4, "You can only set the 'w' component from a vector with at least four elements."); -#endif - m_tElements[3] = tW; + + m_tElements[3] = tW; } /** diff --git a/library/bindings/Vector.i b/library/bindings/Vector.i index 15830de6..555b7d15 100644 --- a/library/bindings/Vector.i +++ b/library/bindings/Vector.i @@ -34,13 +34,22 @@ PROPERTY(PolyVox::Vector, z, getZ, setZ) STR() }; -%template(Vector3DFloat) PolyVox::Vector<3,float,float>; -%template(Vector3DDouble) PolyVox::Vector<3,double,double>; -%template(Vector3DInt8) PolyVox::Vector<3,int8_t,int32_t>; -%template(Vector3DUint8) PolyVox::Vector<3,uint8_t,int32_t>; -%template(Vector3DInt16) PolyVox::Vector<3,int16_t,int32_t>; -%template(Vector3DUint16) PolyVox::Vector<3,uint16_t,int32_t>; -%template(Vector3DInt32) PolyVox::Vector<3,int32_t,int32_t>; -%template(Vector3DUint32) PolyVox::Vector<3,uint32_t,int32_t>; +%define VECTOR3(StorageType,OperationType,ReducedStorageType) +%ignore PolyVox::Vector<3,StorageType,OperationType>::Vector(ReducedStorageType,ReducedStorageType,ReducedStorageType,ReducedStorageType); +%ignore PolyVox::Vector<3,StorageType,OperationType>::Vector(ReducedStorageType,ReducedStorageType); +%ignore PolyVox::Vector<3,StorageType,OperationType>::getW() const; +%ignore PolyVox::Vector<3,StorageType,OperationType>::setW(ReducedStorageType); +%ignore PolyVox::Vector<3,StorageType,OperationType>::setElements(ReducedStorageType,ReducedStorageType,ReducedStorageType,ReducedStorageType); +%template(Vector3D ## StorageType) PolyVox::Vector<3,StorageType,OperationType>; +%enddef + +VECTOR3(float,float,float) +VECTOR3(double,double,double) +VECTOR3(int8_t,int32_t,signed char) +VECTOR3(uint8_t,int32_t,unsigned char) +VECTOR3(int16_t,int32_t,signed short) +VECTOR3(uint16_t,int32_t,unsigned short) +VECTOR3(int32_t,int32_t,signed int) +VECTOR3(uint32_t,int32_t,unsigned int) //%rename(assign) Vector3DFloat::operator=; From eb380b84c7814ce90dafeb9b7d6e0fc74e5d9061 Mon Sep 17 00:00:00 2001 From: David Williams Date: Mon, 24 Dec 2012 21:54:49 +0000 Subject: [PATCH 21/47] Compile fix for windows. --- .../PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h | 6 ++++++ .../include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h | 6 ++++++ .../include/PolyVoxCore/MarchingCubesSurfaceExtractor.h | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h index 1928c2ab..d3e0a2f1 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h @@ -110,7 +110,13 @@ namespace PolyVox }; public: + // This is a bit ugly - it seems that the C++03 syntax is different from the C++11 syntax? See this thread: http://stackoverflow.com/questions/6076015/typename-outside-of-template + // Long term we should probably come back to this and if the #ifdef is still needed then maybe it should check for C++11 mode instead of MSVC? +#if defined(_MSC_VER) + CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(0), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); +#else CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(0), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); +#endif void execute(); diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h index 6b74f5ee..138887cb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h @@ -36,7 +36,13 @@ namespace PolyVox class CubicSurfaceExtractorWithNormals { public: + // This is a bit ugly - it seems that the C++03 syntax is different from the C++11 syntax? See this thread: http://stackoverflow.com/questions/6076015/typename-outside-of-template + // Long term we should probably come back to this and if the #ifdef is still needed then maybe it should check for C++11 mode instead of MSVC? +#if defined(_MSC_VER) + CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(0), IsQuadNeeded isQuadNeeded = IsQuadNeeded()); +#else CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(0), IsQuadNeeded isQuadNeeded = IsQuadNeeded()); +#endif void execute(); diff --git a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h index 4eacd253..094ed4c5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h @@ -38,7 +38,13 @@ namespace PolyVox class MarchingCubesSurfaceExtractor { public: + // This is a bit ugly - it seems that the C++03 syntax is different from the C++11 syntax? See this thread: http://stackoverflow.com/questions/6076015/typename-outside-of-template + // Long term we should probably come back to this and if the #ifdef is still needed then maybe it should check for C++11 mode instead of MSVC? +#if defined(_MSC_VER) + MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(0), Controller controller = Controller()); +#else MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(0), Controller controller = Controller()); +#endif void execute(); From 831689bd17581913a1b34b7610e751b400cec2b2 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Wed, 26 Dec 2012 00:31:10 +0000 Subject: [PATCH 22/47] Fix tests The names of some of the bound classes have changed and this fixes the tests to match it. --- tests/TestRaycast.py | 8 ++++---- tests/TestSurfaceExtractor.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/TestRaycast.py b/tests/TestRaycast.py index 829654b1..76045ba0 100644 --- a/tests/TestRaycast.py +++ b/tests/TestRaycast.py @@ -13,16 +13,16 @@ class TestSurfaceExtractor(unittest.TestCase): def setUp(self): #Create a small volume - r = PolyVoxCore.Region(PolyVoxCore.Vector3DInt32(0,0,0), PolyVoxCore.Vector3DInt32(31,31,31)) + r = PolyVoxCore.Region(PolyVoxCore.Vector3Dint32_t(0,0,0), PolyVoxCore.Vector3Dint32_t(31,31,31)) self.vol = PolyVoxCore.SimpleVolumeuint8(r) #Set one single voxel to have a reasonably high density - self.vol.setVoxelAt(PolyVoxCore.Vector3DInt32(5, 5, 5), 200) + self.vol.setVoxelAt(PolyVoxCore.Vector3Dint32_t(5, 5, 5), 200) def test_hit_voxel(self): - self.assertEqual(PolyVoxCore.raycastWithEndpointsSimpleVolumeuint8(self.vol, PolyVoxCore.Vector3DFloat(0,0,0), PolyVoxCore.Vector3DFloat(31,31,31), test_functor), 1) + self.assertEqual(PolyVoxCore.raycastWithEndpointsSimpleVolumeuint8(self.vol, PolyVoxCore.Vector3Dfloat(0,0,0), PolyVoxCore.Vector3Dfloat(31,31,31), test_functor), 1) def test_miss_voxel(self): - self.assertEqual(PolyVoxCore.raycastWithEndpointsSimpleVolumeuint8(self.vol, PolyVoxCore.Vector3DFloat(0,0,0), PolyVoxCore.Vector3DFloat(0,31,31), test_functor), 0) + self.assertEqual(PolyVoxCore.raycastWithEndpointsSimpleVolumeuint8(self.vol, PolyVoxCore.Vector3Dfloat(0,0,0), PolyVoxCore.Vector3Dfloat(0,31,31), test_functor), 0) if __name__ == '__main__': unittest.main() diff --git a/tests/TestSurfaceExtractor.py b/tests/TestSurfaceExtractor.py index 9ba40815..34cedaf9 100644 --- a/tests/TestSurfaceExtractor.py +++ b/tests/TestSurfaceExtractor.py @@ -10,10 +10,10 @@ class TestSurfaceExtractor(unittest.TestCase): import PolyVoxCore #Create a small volume - r = PolyVoxCore.Region(PolyVoxCore.Vector3DInt32(0,0,0), PolyVoxCore.Vector3DInt32(31,31,31)) + r = PolyVoxCore.Region(PolyVoxCore.Vector3Dint32_t(0,0,0), PolyVoxCore.Vector3Dint32_t(31,31,31)) vol = PolyVoxCore.SimpleVolumeuint8(r) #Set one single voxel to have a reasonably high density - vol.setVoxelAt(PolyVoxCore.Vector3DInt32(5, 5, 5), 200) + vol.setVoxelAt(PolyVoxCore.Vector3Dint32_t(5, 5, 5), 200) self.mesh = PolyVoxCore.SurfaceMeshPositionMaterialNormal() extractor = PolyVoxCore.MarchingCubesSurfaceExtractorSimpleVolumeuint8(vol, r, self.mesh) extractor.execute() From c78a8595fbb4c94855ca0a2c5ed93b1c25bf5cce Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 26 Dec 2012 01:33:05 +0000 Subject: [PATCH 23/47] Initial work on new assert macro. --- library/PolyVoxCore/CMakeLists.txt | 2 + .../include/PolyVoxCore/Impl/ErrorHandling.h | 77 +++++++++++++++++++ .../polyvoxcore/source/Impl/ErrorHandling.cpp | 70 +++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h create mode 100644 library/polyvoxcore/source/Impl/ErrorHandling.cpp diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index 614e05d7..201d8ab5 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -94,6 +94,7 @@ SET(CORE_INC_FILES ) SET(IMPL_SRC_FILES + source/Impl/ErrorHandling.cpp source/Impl/MarchingCubesTables.cpp source/Impl/RandomUnitVectors.cpp source/Impl/RandomVectors.cpp @@ -106,6 +107,7 @@ SET(IMPL_INC_FILES include/PolyVoxCore/Impl/AStarPathfinderImpl.h include/PolyVoxCore/Impl/Block.h include/PolyVoxCore/Impl/Block.inl + include/PolyVoxCore/Impl/ErrorHandling.h include/PolyVoxCore/Impl/MarchingCubesTables.h include/PolyVoxCore/Impl/RandomUnitVectors.h include/PolyVoxCore/Impl/RandomVectors.h diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h new file mode 100644 index 00000000..c3f832a3 --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h @@ -0,0 +1,77 @@ +/******************************************************************************* +Copyright (c) 2005-2009 David Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +#ifndef __PolyVox_ErrorHandling_H__ +#define __PolyVox_ErrorHandling_H__ + +#define POLYVOX_ASSERTS_ENABLED + +namespace PolyVox +{ + namespace Assert + { + enum FailBehavior + { + Halt, + Continue, + }; + + typedef FailBehavior (*Handler)(const char* condition, const char* msg, const char* file, int line); + + Handler GetHandler(); + void SetHandler(Handler newHandler); + + FailBehavior ReportFailure(const char* condition, + const char* file, + int line, + const char* msg, ...); + } +} + +#define POLYVOX_HALT() __debugbreak() +#define POLYVOX_UNUSED(x) do { (void)sizeof(x); } while(0) + +#ifdef POLYVOX_ASSERTS_ENABLED + + #define POLYVOX_ASSERT(cond, msg, ...) \ + do \ + { \ + if (!(cond)) \ + { \ + if (PolyVox::Assert::ReportFailure(#cond, __FILE__, __LINE__, (msg), __VA_ARGS__) == \ + PolyVox::Assert::Halt) \ + POLYVOX_HALT(); \ + } \ + } while(0) + +#else + + #define POLYVOX_ASSERT(condition, msg, ...) \ + do { POLYVOX_UNUSED(condition); POLYVOX_UNUSED(msg); } while(0) + +#endif + +#define POLYVOX_STATIC_ASSERT(x) \ + typedef char polyvoxStaticAssert[(x) ? 1 : -1]; + +#endif //__PolyVox_ErrorHandling_H__ diff --git a/library/polyvoxcore/source/Impl/ErrorHandling.cpp b/library/polyvoxcore/source/Impl/ErrorHandling.cpp new file mode 100644 index 00000000..40225a44 --- /dev/null +++ b/library/polyvoxcore/source/Impl/ErrorHandling.cpp @@ -0,0 +1,70 @@ +#include "PolyVoxCore/Impl/ErrorHandling.h" + +#include +#include + +namespace PolyVox +{ + +namespace +{ + +Assert::FailBehavior DefaultHandler(const char* condition, + const char* msg, + const char* file, + const int line) +{ + std::printf("%s(%d): Assert Failure: ", file, line); + + if (condition != NULL) + std::printf("'%s' ", condition); + + if (msg != NULL) + std::printf("%s", msg); + + std::printf("\n"); + + return Assert::Halt; +} + +Assert::Handler& GetAssertHandlerInstance() +{ + static Assert::Handler s_handler = &DefaultHandler; + return s_handler; +} + +} + +Assert::Handler Assert::GetHandler() +{ + return GetAssertHandlerInstance(); +} + +void Assert::SetHandler(Assert::Handler newHandler) +{ + GetAssertHandlerInstance() = newHandler; +} + +Assert::FailBehavior Assert::ReportFailure(const char* condition, + const char* file, + const int line, + const char* msg, ...) +{ + const char* message = NULL; + if (msg != NULL) + { + char messageBuffer[1024]; + { + va_list args; + va_start(args, msg); + vsnprintf(messageBuffer, 1024, msg, args); + va_end(args); + } + + message = messageBuffer; + } + + return GetAssertHandlerInstance()(condition, message, file, line); +} + +} \ No newline at end of file From c74c1a2b4456c30e2d4ea9187114522e99f13770 Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 26 Dec 2012 02:03:32 +0000 Subject: [PATCH 24/47] Work on new assert macro. --- .../include/PolyVoxCore/Impl/ErrorHandling.h | 12 +- .../polyvoxcore/source/Impl/ErrorHandling.cpp | 114 +++++++++--------- 2 files changed, 66 insertions(+), 60 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h index c3f832a3..f83975e1 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h @@ -26,6 +26,13 @@ freely, subject to the following restrictions: #define POLYVOX_ASSERTS_ENABLED +/* + * Assertions + * ---------- + * The code below implements a custom assert function called POLYVOX_ASSERT which has a number of advantages compared to + * the standard C/C++ assert(). It is based on http://cnicholson.net/2009/02/stupid-c-tricks-adventures-in-assert/ which + * provides code under the MIT license. + */ namespace PolyVox { namespace Assert @@ -41,10 +48,7 @@ namespace PolyVox Handler GetHandler(); void SetHandler(Handler newHandler); - FailBehavior ReportFailure(const char* condition, - const char* file, - int line, - const char* msg, ...); + FailBehavior ReportFailure(const char* condition, const char* file, int line, const char* msg, ...); } } diff --git a/library/polyvoxcore/source/Impl/ErrorHandling.cpp b/library/polyvoxcore/source/Impl/ErrorHandling.cpp index 40225a44..8e62e9b9 100644 --- a/library/polyvoxcore/source/Impl/ErrorHandling.cpp +++ b/library/polyvoxcore/source/Impl/ErrorHandling.cpp @@ -3,68 +3,70 @@ #include #include +/* + * Assertions + * ---------- + * The code below implements a custom assert function called POLYVOX_ASSERT which has a number of advantages compared to + * the standard C/C++ assert(). It is based on http://cnicholson.net/2009/02/stupid-c-tricks-adventures-in-assert/ which + * provides code under the MIT license. + */ namespace PolyVox { - -namespace -{ - -Assert::FailBehavior DefaultHandler(const char* condition, - const char* msg, - const char* file, - const int line) -{ - std::printf("%s(%d): Assert Failure: ", file, line); - - if (condition != NULL) - std::printf("'%s' ", condition); - - if (msg != NULL) - std::printf("%s", msg); - - std::printf("\n"); - - return Assert::Halt; -} - -Assert::Handler& GetAssertHandlerInstance() -{ - static Assert::Handler s_handler = &DefaultHandler; - return s_handler; -} - -} - -Assert::Handler Assert::GetHandler() -{ - return GetAssertHandlerInstance(); -} - -void Assert::SetHandler(Assert::Handler newHandler) -{ - GetAssertHandlerInstance() = newHandler; -} - -Assert::FailBehavior Assert::ReportFailure(const char* condition, - const char* file, - const int line, - const char* msg, ...) -{ - const char* message = NULL; - if (msg != NULL) + namespace { - char messageBuffer[1024]; + Assert::FailBehavior DefaultHandler(const char* condition, const char* msg, const char* file, const int line) { - va_list args; - va_start(args, msg); - vsnprintf(messageBuffer, 1024, msg, args); - va_end(args); + std::printf("%s(%d): Assert Failure: ", file, line); + + if (condition != NULL) + std::printf("'%s' ", condition); + + if (msg != NULL) + std::printf("%s", msg); + + std::printf("\n"); + + return Assert::Halt; + } + + Assert::Handler& GetAssertHandlerInstance() + { + static Assert::Handler s_handler = &DefaultHandler; + return s_handler; } - message = messageBuffer; } - return GetAssertHandlerInstance()(condition, message, file, line); -} + Assert::Handler Assert::GetHandler() + { + return GetAssertHandlerInstance(); + } -} \ No newline at end of file + void Assert::SetHandler(Assert::Handler newHandler) + { + GetAssertHandlerInstance() = newHandler; + } + + Assert::FailBehavior Assert::ReportFailure(const char* condition, const char* file, const int line, const char* msg, ...) + { + const char* message = NULL; + if (msg != NULL) + { + char messageBuffer[1024]; + { + va_list args; + va_start(args, msg); +#if defined (_MSC_VER) + vsnprintf_s(messageBuffer, 1024, msg, args); +#else + vsnprintf(messageBuffer, 1024, msg, args); +#endif + va_end(args); + } + + message = messageBuffer; + } + + return GetAssertHandlerInstance()(condition, message, file, line); + } +} From e17271a2c72427d1c936dd4823f2572d9bdc41f4 Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 26 Dec 2012 10:34:09 +0000 Subject: [PATCH 25/47] Work on new asserts. --- library/PolyVoxCore/CMakeLists.txt | 1 - .../include/PolyVoxCore/Impl/ErrorHandling.h | 57 ++++++--------- .../polyvoxcore/source/Impl/ErrorHandling.cpp | 72 ------------------- 3 files changed, 21 insertions(+), 109 deletions(-) delete mode 100644 library/polyvoxcore/source/Impl/ErrorHandling.cpp diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index 201d8ab5..db97c3f3 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -94,7 +94,6 @@ SET(CORE_INC_FILES ) SET(IMPL_SRC_FILES - source/Impl/ErrorHandling.cpp source/Impl/MarchingCubesTables.cpp source/Impl/RandomUnitVectors.cpp source/Impl/RandomVectors.cpp diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h index f83975e1..b99f0278 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h @@ -24,58 +24,43 @@ freely, subject to the following restrictions: #ifndef __PolyVox_ErrorHandling_H__ #define __PolyVox_ErrorHandling_H__ +#include + #define POLYVOX_ASSERTS_ENABLED -/* - * Assertions - * ---------- - * The code below implements a custom assert function called POLYVOX_ASSERT which has a number of advantages compared to - * the standard C/C++ assert(). It is based on http://cnicholson.net/2009/02/stupid-c-tricks-adventures-in-assert/ which - * provides code under the MIT license. - */ -namespace PolyVox -{ - namespace Assert - { - enum FailBehavior - { - Halt, - Continue, - }; - - typedef FailBehavior (*Handler)(const char* condition, const char* msg, const char* file, int line); - - Handler GetHandler(); - void SetHandler(Handler newHandler); - - FailBehavior ReportFailure(const char* condition, const char* file, int line, const char* msg, ...); - } -} - #define POLYVOX_HALT() __debugbreak() #define POLYVOX_UNUSED(x) do { (void)sizeof(x); } while(0) +/* + * Assertions + * ---------- + * The code below implements a custom assert function called POLYVOX_ASSERT which has a number of advantages compared + * to the standard C/C++ assert(). It is inspired by http://cnicholson.net/2009/02/stupid-c-tricks-adventures-in-assert/ + * which provides code under the MIT license. + */ + #ifdef POLYVOX_ASSERTS_ENABLED - #define POLYVOX_ASSERT(cond, msg, ...) \ + #define POLYVOX_ASSERT(condition, message) \ do \ { \ - if (!(cond)) \ + if (!(condition)) \ { \ - if (PolyVox::Assert::ReportFailure(#cond, __FILE__, __LINE__, (msg), __VA_ARGS__) == \ - PolyVox::Assert::Halt) \ - POLYVOX_HALT(); \ + std::cerr << std::endl << std::endl; \ + std::cerr << " PolyVox Assertion Failed!" << std::endl; \ + std::cerr << " -------------------------" << std::endl; \ + std::cerr << " Condition: " << #condition << std::endl; \ + std::cerr << " Message: " << (message) << std::endl; \ + std::cerr << " Location: " << "Line " << __LINE__ << " of " << __FILE__ << std::endl << std::endl; \ + POLYVOX_HALT(); \ } \ } while(0) #else - #define POLYVOX_ASSERT(condition, msg, ...) \ - do { POLYVOX_UNUSED(condition); POLYVOX_UNUSED(msg); } while(0) + #define POLYVOX_ASSERT(condition, message) \ + do { POLYVOX_UNUSED(condition); POLYVOX_UNUSED(message); } while(0) #endif -#define POLYVOX_STATIC_ASSERT(x) \ - typedef char polyvoxStaticAssert[(x) ? 1 : -1]; - #endif //__PolyVox_ErrorHandling_H__ diff --git a/library/polyvoxcore/source/Impl/ErrorHandling.cpp b/library/polyvoxcore/source/Impl/ErrorHandling.cpp deleted file mode 100644 index 8e62e9b9..00000000 --- a/library/polyvoxcore/source/Impl/ErrorHandling.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include "PolyVoxCore/Impl/ErrorHandling.h" - -#include -#include - -/* - * Assertions - * ---------- - * The code below implements a custom assert function called POLYVOX_ASSERT which has a number of advantages compared to - * the standard C/C++ assert(). It is based on http://cnicholson.net/2009/02/stupid-c-tricks-adventures-in-assert/ which - * provides code under the MIT license. - */ -namespace PolyVox -{ - namespace - { - Assert::FailBehavior DefaultHandler(const char* condition, const char* msg, const char* file, const int line) - { - std::printf("%s(%d): Assert Failure: ", file, line); - - if (condition != NULL) - std::printf("'%s' ", condition); - - if (msg != NULL) - std::printf("%s", msg); - - std::printf("\n"); - - return Assert::Halt; - } - - Assert::Handler& GetAssertHandlerInstance() - { - static Assert::Handler s_handler = &DefaultHandler; - return s_handler; - } - - } - - Assert::Handler Assert::GetHandler() - { - return GetAssertHandlerInstance(); - } - - void Assert::SetHandler(Assert::Handler newHandler) - { - GetAssertHandlerInstance() = newHandler; - } - - Assert::FailBehavior Assert::ReportFailure(const char* condition, const char* file, const int line, const char* msg, ...) - { - const char* message = NULL; - if (msg != NULL) - { - char messageBuffer[1024]; - { - va_list args; - va_start(args, msg); -#if defined (_MSC_VER) - vsnprintf_s(messageBuffer, 1024, msg, args); -#else - vsnprintf(messageBuffer, 1024, msg, args); -#endif - va_end(args); - } - - message = messageBuffer; - } - - return GetAssertHandlerInstance()(condition, message, file, line); - } -} From f5ea8878c230905b72e797744e122c6a92159ef0 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Wed, 26 Dec 2012 12:54:52 +0000 Subject: [PATCH 26/47] Add a default CompilerCapabilities.h This file assumes that the compiler doesn't support anything. If building without CMake, it will be used and if you want to enable things, the file can be edited. When using CMake, a proper CompilerCapabilites.h will be generated and CMake will set the include path order correctly in order to source the correct file. --- examples/Basic/CMakeLists.txt | 4 ++-- examples/OpenGL/CMakeLists.txt | 4 ++-- examples/Paging/CMakeLists.txt | 4 ++-- examples/SmoothLOD/CMakeLists.txt | 4 ++-- library/PolyVoxCore/CMakeLists.txt | 2 +- .../include/PolyVoxCore/Impl/CompilerCapabilities.h | 12 ++++++++++++ library/PolyVoxUtil/CMakeLists.txt | 2 +- library/bindings/CMakeLists.txt | 2 +- tests/CMakeLists.txt | 2 +- 9 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h diff --git a/examples/Basic/CMakeLists.txt b/examples/Basic/CMakeLists.txt index d9ce3fe3..02e203d2 100644 --- a/examples/Basic/CMakeLists.txt +++ b/examples/Basic/CMakeLists.txt @@ -43,8 +43,8 @@ SOURCE_GROUP("Headers" FILES ${INC_FILES}) FIND_PACKAGE(OpenGL REQUIRED) -#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location) -INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include ${PolyVoxCore_BINARY_DIR}/include ${GLEW_SOURCE_DIR}) +#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location) +INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${GLEW_SOURCE_DIR}) LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}) #Build diff --git a/examples/OpenGL/CMakeLists.txt b/examples/OpenGL/CMakeLists.txt index e1ed404a..5cd1ed55 100644 --- a/examples/OpenGL/CMakeLists.txt +++ b/examples/OpenGL/CMakeLists.txt @@ -51,8 +51,8 @@ SOURCE_GROUP("Headers" FILES ${INC_FILES}) FIND_PACKAGE(OpenGL REQUIRED) -#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location) -INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include ${PolyVoxCore_BINARY_DIR}/include ${GLEW_SOURCE_DIR}) +#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location) +INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${GLEW_SOURCE_DIR}) LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}) #Build diff --git a/examples/Paging/CMakeLists.txt b/examples/Paging/CMakeLists.txt index 094f5e82..e8020b2d 100644 --- a/examples/Paging/CMakeLists.txt +++ b/examples/Paging/CMakeLists.txt @@ -45,8 +45,8 @@ SOURCE_GROUP("Headers" FILES ${INC_FILES}) FIND_PACKAGE(OpenGL REQUIRED) -#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location) -INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include ${PolyVoxCore_BINARY_DIR}/include ${GLEW_SOURCE_DIR}) +#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location) +INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${GLEW_SOURCE_DIR}) LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}) #Build diff --git a/examples/SmoothLOD/CMakeLists.txt b/examples/SmoothLOD/CMakeLists.txt index a476ae82..570cda55 100644 --- a/examples/SmoothLOD/CMakeLists.txt +++ b/examples/SmoothLOD/CMakeLists.txt @@ -43,8 +43,8 @@ SOURCE_GROUP("Headers" FILES ${INC_FILES}) FIND_PACKAGE(OpenGL REQUIRED) -#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location) -INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include ${PolyVoxCore_BINARY_DIR}/include ${GLEW_SOURCE_DIR}) +#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location) +INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${GLEW_SOURCE_DIR}) LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}) #Build diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index 614e05d7..48bae99e 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -126,7 +126,7 @@ SOURCE_GROUP("Sources\\Impl" FILES ${IMPL_SRC_FILES}) SOURCE_GROUP("Headers\\Impl" FILES ${IMPL_INC_FILES}) #Tell CMake the paths -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include) #Core #Build diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h new file mode 100644 index 00000000..d7cebe0c --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h @@ -0,0 +1,12 @@ +#ifndef __PolyVox_CompilerCapabilities_H__ +#define __PolyVox_CompilerCapabilities_H__ + +//#undef HAS_CXX11_CONSTEXPR + +//#undef HAS_CXX11_STATIC_ASSERT + +//#undef HAS_CXX11_CSTDINT_H + +//#undef HAS_CXX11_SHARED_PTR + +#endif diff --git a/library/PolyVoxUtil/CMakeLists.txt b/library/PolyVoxUtil/CMakeLists.txt index bdb091e5..a52006c9 100644 --- a/library/PolyVoxUtil/CMakeLists.txt +++ b/library/PolyVoxUtil/CMakeLists.txt @@ -42,7 +42,7 @@ SOURCE_GROUP("Sources" FILES ${UTIL_SRC_FILES}) SOURCE_GROUP("Headers" FILES ${UTIL_INC_FILES}) #Tell CMake the paths -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${PolyVoxCore_BINARY_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include ${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include) #There has to be a better way! LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/debug ${PolyVoxCore_BINARY_DIR}/release ${PolyVoxCore_BINARY_DIR}) diff --git a/library/bindings/CMakeLists.txt b/library/bindings/CMakeLists.txt index 33172fdb..d807a118 100644 --- a/library/bindings/CMakeLists.txt +++ b/library/bindings/CMakeLists.txt @@ -36,7 +36,7 @@ if(ENABLE_BINDINGS) include(${SWIG_USE_FILE}) include_directories(${PYTHON_INCLUDE_PATH}) - include_directories(${PolyVoxCore_SOURCE_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include/PolyVoxCore ${PolyVoxCore_BINARY_DIR}/include) + include_directories(${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include/PolyVoxCore) link_directories(${PolyVoxCore_BINARY_DIR}) set(CMAKE_SWIG_FLAGS "") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index af46e69f..d76c8167 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -39,7 +39,7 @@ MACRO(CREATE_TEST headerfile sourcefile executablename) SET_PROPERTY(TARGET ${executablename} PROPERTY FOLDER "Tests") ENDMACRO(CREATE_TEST) -INCLUDE_DIRECTORIES(${PolyVox_SOURCE_DIR}/PolyVoxCore/include ${PolyVoxCore_BINARY_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}) +INCLUDE_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/include ${PolyVox_SOURCE_DIR}/PolyVoxCore/include ${CMAKE_CURRENT_BINARY_DIR}) REMOVE_DEFINITIONS(-DQT_GUI_LIB) #Make sure the tests don't link to the QtGui # Test Template. Copy and paste this template for consistant naming. From a3cb8f7a766dc637c71cf5316a9d6fa3082396ce Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 26 Dec 2012 15:02:03 +0000 Subject: [PATCH 27/47] Now using new assert in Vector. --- library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.inl | 2 ++ library/PolyVoxCore/include/PolyVoxCore/Vector.h | 2 +- library/PolyVoxCore/include/PolyVoxCore/Vector.inl | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.inl b/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.inl index 45d24ada..1b9f2bd0 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.inl @@ -21,6 +21,8 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ +#include + namespace PolyVox { template diff --git a/library/PolyVoxCore/include/PolyVoxCore/Vector.h b/library/PolyVoxCore/include/PolyVoxCore/Vector.h index 12c3c201..db3da0f8 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Vector.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Vector.h @@ -24,11 +24,11 @@ freely, subject to the following restrictions: #ifndef __PolyVox_Vector_H__ #define __PolyVox_Vector_H__ +#include "Impl/ErrorHandling.h" #include "Impl/TypeDef.h" #include "PolyVoxForwardDeclarations.h" -#include #include #include #include diff --git a/library/PolyVoxCore/include/PolyVoxCore/Vector.inl b/library/PolyVoxCore/include/PolyVoxCore/Vector.inl index 22d3009e..65b5eba7 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Vector.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Vector.inl @@ -414,7 +414,7 @@ namespace PolyVox template inline StorageType Vector::getElement(uint32_t index) const { - assert(index < Size); + POLYVOX_ASSERT(index < Size, "Attempted to access invalid vector element."); return m_tElements[index]; } @@ -465,7 +465,7 @@ namespace PolyVox template inline void Vector::setElement(uint32_t index, StorageType tValue) { - assert(index < Size); + POLYVOX_ASSERT(index < Size, "Attempted to access invalid vector element."); m_tElements[index] = tValue; } @@ -649,7 +649,7 @@ namespace PolyVox { // Standard float rules apply for divide-by-zero m_tElements[ct] /= fLength; - assert(m_tElements[ct] == m_tElements[ct]); //Will assert if NAN + POLYVOX_ASSERT(m_tElements[ct] == m_tElements[ct], "Obtained NAN during vector normalisation. Perhaps the input vector was too short?"); } } }//namespace PolyVox From a419c4f4e65ef0e3878e806e2b1d041480efac95 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Wed, 26 Dec 2012 15:07:15 +0000 Subject: [PATCH 28/47] Mark Vector::operator< as deprecated in the Python bindings --- library/bindings/Vector.i | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/bindings/Vector.i b/library/bindings/Vector.i index 555b7d15..37d0b3ab 100644 --- a/library/bindings/Vector.i +++ b/library/bindings/Vector.i @@ -34,6 +34,13 @@ PROPERTY(PolyVox::Vector, z, getZ, setZ) STR() }; +%feature("pythonprepend") PolyVox::Vector::operator< %{ + import warnings + warnings.warn("deprecated", DeprecationWarning) +%} + +//%csattributes PolyVox::Vector::operator< "[System.Obsolete(\"deprecated\")]" + %define VECTOR3(StorageType,OperationType,ReducedStorageType) %ignore PolyVox::Vector<3,StorageType,OperationType>::Vector(ReducedStorageType,ReducedStorageType,ReducedStorageType,ReducedStorageType); %ignore PolyVox::Vector<3,StorageType,OperationType>::Vector(ReducedStorageType,ReducedStorageType); From bc8240fe63324ec80a81475c420c209bdf43aaad Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Wed, 26 Dec 2012 15:09:54 +0000 Subject: [PATCH 29/47] These checks are no longer needed since it's checked in the top level file --- library/PolyVoxCore/CMakeLists.txt | 2 -- library/PolyVoxUtil/CMakeLists.txt | 2 -- 2 files changed, 4 deletions(-) diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index 48bae99e..f6f9753f 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -20,8 +20,6 @@ # 3. This notice may not be removed or altered from any source # distribution. -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) - PROJECT(PolyVoxCore) #Set up the C++11 feature header file based on the CheckCXX11Features script diff --git a/library/PolyVoxUtil/CMakeLists.txt b/library/PolyVoxUtil/CMakeLists.txt index a52006c9..7fbdb43e 100644 --- a/library/PolyVoxUtil/CMakeLists.txt +++ b/library/PolyVoxUtil/CMakeLists.txt @@ -20,8 +20,6 @@ # 3. This notice may not be removed or altered from any source # distribution. -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) - PROJECT(PolyVoxUtil) #Projects source files From 03de39b8dd26f6142bc288292cd39dd3de1cf6bf Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Wed, 26 Dec 2012 15:37:16 +0000 Subject: [PATCH 30/47] Add some documentation to the CompilerCapabilities.h files --- .../include/PolyVoxCore/Impl/CompilerCapabilities.h | 8 ++++++++ .../include/PolyVoxCore/Impl/CompilerCapabilities.h.in | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h index d7cebe0c..325b5ed1 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h @@ -1,3 +1,11 @@ +/* + * This file provides the default compiler capabilities for for Visual Studio. + * On other compilers CMake will detect which features are available and create + * a file like this. + * + * To Enable these features in Visual Studio, define the variables in this file. +*/ + #ifndef __PolyVox_CompilerCapabilities_H__ #define __PolyVox_CompilerCapabilities_H__ diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h.in b/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h.in index 5518dfb2..31f1ba80 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h.in +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h.in @@ -1,3 +1,8 @@ +/* + * This file is an input file for the CMake build system. It is processed and + * placed in the build directory by CMake. +*/ + #ifndef __PolyVox_CompilerCapabilities_H__ #define __PolyVox_CompilerCapabilities_H__ From 9e7bb756871b0a3ddeeec1971e88c46319847aae Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Wed, 26 Dec 2012 15:40:59 +0000 Subject: [PATCH 31/47] Disable the C++11 feature detection on Visual Studio There seems to be a bug in the interaction between CMake and Visual Studio which floods the 'recent projects' list with the TRY_COMPILE projects. If in the future this is fixed then it can re-enabled. --- CMakeLists.txt | 4 +++- library/PolyVoxCore/CMakeLists.txt | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2fd957d9..1f42f886 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,7 +69,9 @@ if(CMAKE_CXX_COMPILER MATCHES "clang") ADD_DEFINITIONS(-std=c++0x) #Enable C++0x mode endif() -INCLUDE(cmake/Modules/CheckCXX11Features.cmake) +if(NOT MSVC) #This is causing problems in Visual Studio so disable it for now + INCLUDE(cmake/Modules/CheckCXX11Features.cmake) +endif() ADD_SUBDIRECTORY(library) diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index f6f9753f..69c66052 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -22,8 +22,10 @@ PROJECT(PolyVoxCore) -#Set up the C++11 feature header file based on the CheckCXX11Features script -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/PolyVoxCore/Impl/CompilerCapabilities.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/PolyVoxCore/Impl/CompilerCapabilities.h) +if(NOT MSVC) + #Set up the C++11 feature header file based on the CheckCXX11Features script + CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/PolyVoxCore/Impl/CompilerCapabilities.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/PolyVoxCore/Impl/CompilerCapabilities.h) +endif() #Projects source files SET(CORE_SRC_FILES From 3653528ae517d4b8f875226fe2cc6bda155e66b1 Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 26 Dec 2012 16:44:34 +0100 Subject: [PATCH 32/47] POLYVOX_HALT() implementation for Linux. --- .../include/PolyVoxCore/Impl/ErrorHandling.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h index b99f0278..15570bb9 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h @@ -24,11 +24,17 @@ freely, subject to the following restrictions: #ifndef __PolyVox_ErrorHandling_H__ #define __PolyVox_ErrorHandling_H__ -#include +#include //For std::exit +#include //For std::cerr #define POLYVOX_ASSERTS_ENABLED -#define POLYVOX_HALT() __debugbreak() +#if defined(_MSC_VER) + #define POLYVOX_HALT() __debugbreak() +#else + #define POLYVOX_HALT() std::exit(EXIT_FAILURE) +#endif + #define POLYVOX_UNUSED(x) do { (void)sizeof(x); } while(0) /* From 59d415e305c31b45b02125c479a81f27f1ebc0ca Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Wed, 26 Dec 2012 17:11:08 +0000 Subject: [PATCH 33/47] Pave way for C# bindings This callback implementation is Python-specific and so should be disabled --- library/bindings/Raycast.i | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/library/bindings/Raycast.i b/library/bindings/Raycast.i index ed1869ca..8ae2c297 100644 --- a/library/bindings/Raycast.i +++ b/library/bindings/Raycast.i @@ -2,6 +2,8 @@ %{ #include "Raycast.h" +#ifdef SWIGPYTHON + template class PyCallback { @@ -43,11 +45,17 @@ PolyVox::RaycastResult raycastWithEndpointsPython(VolumeType* volData, const Pol return PolyVox::raycastWithEndpoints(volData, v3dStart, v3dEnd, newCallback); } +#endif + %} %include "Raycast.h" +#ifdef SWIGPYTHON + template PolyVox::RaycastResult raycastWithEndpointsPython(VolumeType* volData, const PolyVox::Vector3DFloat& v3dStart, const PolyVox::Vector3DFloat& v3dEnd, PyObject *callback); %template(raycastWithEndpointsSimpleVolumeuint8) raycastWithEndpointsPython, PyCallback > >; + +#endif From 64cd6e31b067476a13e66fa1a3d08acf0b8beb21 Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 26 Dec 2012 18:16:43 +0000 Subject: [PATCH 34/47] The non-C++11 implemention of POLYVOX_STATIC_ASSERT is no longer dependent on Boost. --- .../include/PolyVoxCore/Impl/ErrorHandling.h | 23 +++++++++++++++++++ .../include/PolyVoxCore/Impl/TypeDef.h | 7 ------ .../include/PolyVoxCore/Vector.inl | 22 +++++++++--------- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h index 15570bb9..569802c2 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h @@ -69,4 +69,27 @@ freely, subject to the following restrictions: #endif +namespace PolyVox +{ +#if defined(HAS_CXX11_STATIC_ASSERT) + //In this case we can just use static_assert +#define POLYVOX_STATIC_ASSERT static_assert +#else + // empty default template + template + struct StaticAssert {}; + + // template specialized on true + template <> + struct StaticAssert + { + // If the static assertion is failing then this function won't exist. It will then + // appear in the error message which gives a clue to the user about what is wrong. + static void ERROR_The_static_assertion_has_failed() {} + }; + + #define POLYVOX_STATIC_ASSERT(condition, message) StaticAssert<(condition)>::ERROR_The_static_assertion_has_failed(); +#endif +} + #endif //__PolyVox_ErrorHandling_H__ diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h index da1fedd5..3724efe4 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h @@ -98,13 +98,6 @@ freely, subject to the following restrictions: #define polyvox_constexpr #endif -#if defined(HAS_CXX11_STATIC_ASSERT) - //In this case we can just use static_assert -#else - #include - #define static_assert(condition, message) BOOST_STATIC_ASSERT(condition) -#endif - #if defined(HAS_CXX11_CSTDINT_H) #include #else diff --git a/library/PolyVoxCore/include/PolyVoxCore/Vector.inl b/library/PolyVoxCore/include/PolyVoxCore/Vector.inl index 65b5eba7..57b3e2f0 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Vector.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Vector.inl @@ -53,7 +53,7 @@ namespace PolyVox template Vector::Vector(StorageType x, StorageType y) { - static_assert(Size == 2, "This constructor should only be used for vectors with two elements."); + POLYVOX_STATIC_ASSERT(Size == 2, "This constructor should only be used for vectors with two elements."); m_tElements[0] = x; m_tElements[1] = y; @@ -68,7 +68,7 @@ namespace PolyVox template Vector::Vector(StorageType x, StorageType y, StorageType z) { - static_assert(Size == 3, "This constructor should only be used for vectors with three elements."); + POLYVOX_STATIC_ASSERT(Size == 3, "This constructor should only be used for vectors with three elements."); m_tElements[0] = x; m_tElements[1] = y; @@ -86,7 +86,7 @@ namespace PolyVox template Vector::Vector(StorageType x, StorageType y, StorageType z, StorageType w) { - static_assert(Size == 4, "This constructor should only be used for vectors with four elements."); + POLYVOX_STATIC_ASSERT(Size == 4, "This constructor should only be used for vectors with four elements."); m_tElements[0] = x; m_tElements[1] = y; @@ -129,14 +129,14 @@ namespace PolyVox template Vector::~Vector(void) { - // We put the static_asserts in the destructor because there is one one of these, + // We put the static asserts in the destructor because there is one one of these, // where as there are multiple constructors. // Force a vector to have a length greater than one. There is no need for a // vector with one element, and supporting this would cause confusion over the // behaviour of the constructor taking a single value, as this fills all elements // to that value rather than just the first one. - static_assert(Size > 1, "Vector must have a length greater than one."); + POLYVOX_STATIC_ASSERT(Size > 1, "Vector must have a length greater than one."); } /** @@ -442,7 +442,7 @@ namespace PolyVox template inline StorageType Vector::getZ(void) const { - static_assert(Size >= 3, "You can only get the 'z' component from a vector with at least three elements."); + POLYVOX_STATIC_ASSERT(Size >= 3, "You can only get the 'z' component from a vector with at least three elements."); return m_tElements[2]; } @@ -453,7 +453,7 @@ namespace PolyVox template inline StorageType Vector::getW(void) const { - static_assert(Size >= 4, "You can only get the 'w' component from a vector with at least four elements."); + POLYVOX_STATIC_ASSERT(Size >= 4, "You can only get the 'w' component from a vector with at least four elements."); return m_tElements[3]; } @@ -491,7 +491,7 @@ namespace PolyVox template inline void Vector::setElements(StorageType x, StorageType y, StorageType z) { - static_assert(Size >= 3, "You can only use this version of setElements() on a vector with at least three elements."); + POLYVOX_STATIC_ASSERT(Size >= 3, "You can only use this version of setElements() on a vector with at least three elements."); m_tElements[0] = x; m_tElements[1] = y; @@ -508,7 +508,7 @@ namespace PolyVox template inline void Vector::setElements(StorageType x, StorageType y, StorageType z, StorageType w) { - static_assert(Size >= 4, "You can only use this version of setElements() on a vector with at least four elements."); + POLYVOX_STATIC_ASSERT(Size >= 4, "You can only use this version of setElements() on a vector with at least four elements."); m_tElements[0] = x; m_tElements[1] = y; @@ -540,7 +540,7 @@ namespace PolyVox template inline void Vector::setZ(StorageType tZ) { - static_assert(Size >= 3, "You can only set the 'w' component from a vector with at least three elements."); + POLYVOX_STATIC_ASSERT(Size >= 3, "You can only set the 'w' component from a vector with at least three elements."); m_tElements[2] = tZ; } @@ -551,7 +551,7 @@ namespace PolyVox template inline void Vector::setW(StorageType tW) { - static_assert(Size >= 4, "You can only set the 'w' component from a vector with at least four elements."); + POLYVOX_STATIC_ASSERT(Size >= 4, "You can only set the 'w' component from a vector with at least four elements."); m_tElements[3] = tW; } From ecad915001c3d9731aaa868d72a39535fa98a009 Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 26 Dec 2012 20:18:46 +0000 Subject: [PATCH 35/47] Tidied up some code. --- .../include/PolyVoxCore/Impl/ErrorHandling.h | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h index 569802c2..b4efd2f9 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h @@ -69,27 +69,27 @@ freely, subject to the following restrictions: #endif -namespace PolyVox -{ #if defined(HAS_CXX11_STATIC_ASSERT) //In this case we can just use static_assert -#define POLYVOX_STATIC_ASSERT static_assert + #define POLYVOX_STATIC_ASSERT static_assert #else - // empty default template - template - struct StaticAssert {}; - - // template specialized on true - template <> - struct StaticAssert + namespace PolyVox { - // If the static assertion is failing then this function won't exist. It will then - // appear in the error message which gives a clue to the user about what is wrong. - static void ERROR_The_static_assertion_has_failed() {} - }; + // empty default template + template + struct StaticAssert {}; + + // template specialized on true + template <> + struct StaticAssert + { + // If the static assertion is failing then this function won't exist. It will then + // appear in the error message which gives a clue to the user about what is wrong. + static void ERROR_The_static_assertion_has_failed() {} + }; + } #define POLYVOX_STATIC_ASSERT(condition, message) StaticAssert<(condition)>::ERROR_The_static_assertion_has_failed(); #endif -} #endif //__PolyVox_ErrorHandling_H__ From 9ca84dc0e15f3109069b3d9e488e4af3846d020d Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 26 Dec 2012 20:24:55 +0000 Subject: [PATCH 36/47] Updated CHANGELOG.txt --- CHANGELOG.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 5cceff72..b96f18ad 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -2,6 +2,10 @@ Changes for PolyVox version 0.3 =============================== This release has focused on... (some introduction here). +Error Handling +-------------- +PolyVox now has it's own POLYVOX_ASSERT() macro rather than using the standard assert(). This has some advantages such as allowing a message to be printed and providing file/line information, and it is also possible to enable/disable it independantly of whether you are making a debug or release build + Volume wrap modes ----------------- This release has seen a overhaul of the way PolyVox handles voxel positions which are outside of the volume. It used to be the case that you could specify a border value which would be returned whenever an out-of-volume access was performed, but this was not flexible enough for all use cases. You can now choose between different wrapping modes (border, clamp, etc) and apply them to both the volume itself or to samplers. If you have multiple samplers pointing at the same volume then you can choose to have different wrap modes for each of them. From 25a4ff1c8ed3ca7dfb73e1136bf84ece849ed4bf Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 26 Dec 2012 20:27:29 +0000 Subject: [PATCH 37/47] Added comment. --- .../PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h index b4efd2f9..88415f74 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h @@ -69,6 +69,12 @@ freely, subject to the following restrictions: #endif +/* + * Static Assertions + * ----------------- + * These map to C+11 static_assert if available or our own implentation otherwise. + */ + #if defined(HAS_CXX11_STATIC_ASSERT) //In this case we can just use static_assert #define POLYVOX_STATIC_ASSERT static_assert From 81a4294a7dd63f8d9ba60c98f206ad3618658a47 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Wed, 26 Dec 2012 20:53:44 +0000 Subject: [PATCH 38/47] Enable SWIG generation of C# bindings --- library/bindings/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/bindings/CMakeLists.txt b/library/bindings/CMakeLists.txt index d807a118..040d0afe 100644 --- a/library/bindings/CMakeLists.txt +++ b/library/bindings/CMakeLists.txt @@ -48,6 +48,11 @@ if(ENABLE_BINDINGS) set_target_properties(${SWIG_MODULE_PolyVoxCorePython_REAL_NAME} PROPERTIES OUTPUT_NAME _PolyVoxCore) #set_target_properties(${SWIG_MODULE_PolyVoxCore_REAL_NAME} PROPERTIES SUFFIX ".pyd") SET_PROPERTY(TARGET ${SWIG_MODULE_PolyVoxCorePython_REAL_NAME} PROPERTY FOLDER "Bindings") + + swig_add_module(PolyVoxCoreCSharp csharp PolyVoxCore.i) + set(SWIG_MODULE_PolyVoxCoreCSharp_EXTRA_FLAGS "-dllimport;PolyVoxCoreCSharp") #This _should_ be inside UseSWIG.cmake - http://www.cmake.org/Bug/view.php?id=13814 + swig_link_libraries(PolyVoxCoreCSharp PolyVoxCore) + SET_PROPERTY(TARGET ${SWIG_MODULE_PolyVoxCoreCSharp_REAL_NAME} PROPERTY FOLDER "Bindings") else() set(BUILD_BINDINGS OFF CACHE BOOL "Will the bindings be built" FORCE) endif() From f87b19bd58208cc741c141dab7a1951a1e78660b Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 2 Dec 2012 14:15:34 +0100 Subject: [PATCH 39/47] Fixed build error on VS2008 --- library/PolyVoxCore/include/PolyVoxCore/DefaultIsQuadNeeded.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/DefaultIsQuadNeeded.h b/library/PolyVoxCore/include/PolyVoxCore/DefaultIsQuadNeeded.h index 5775c4ba..81ddb9e5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/DefaultIsQuadNeeded.h +++ b/library/PolyVoxCore/include/PolyVoxCore/DefaultIsQuadNeeded.h @@ -24,7 +24,7 @@ freely, subject to the following restrictions: #ifndef __PolyVox_DefaultIsQuadNeeded_H__ #define __PolyVox_DefaultIsQuadNeeded_H__ -#include +#include "PolyVoxCore/Impl/TypeDef.h" namespace PolyVox { From 9a30fa54a532bfdc34291a1dfcad61c484ff0156 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 2 Dec 2012 14:17:41 +0100 Subject: [PATCH 40/47] Fixed bug with peek function checking in wrong direction. --- library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl index 758e578d..39f51f3e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl @@ -238,7 +238,7 @@ namespace PolyVox template VoxelType RawVolume::Sampler::peekVoxel0px1ny1nz(void) const { - if( BORDER_LOWX(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) ) + if( BORDER_LOWY(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) ) { return *(mCurrentVoxel - this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight()); } From 3b46aaa5d3431c185eefc78dec912f9e19ebb63d Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Thu, 22 Nov 2012 22:23:07 +0000 Subject: [PATCH 41/47] Fix LowPassFilter test The implicit default kernel size for the non-SAT version was 3 but the SAT version was using an explicit kernel of 5 which caused a discrepancy. Now just use a kernel of 3. --- tests/TestLowPassFilter.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/TestLowPassFilter.cpp b/tests/TestLowPassFilter.cpp index 4ace36eb..902c26d6 100644 --- a/tests/TestLowPassFilter.cpp +++ b/tests/TestLowPassFilter.cpp @@ -58,7 +58,7 @@ void TestLowPassFilter::testExecute() RawVolume resultVolume(reg); - LowPassFilter< RawVolume, RawVolume, Density16 > lowPassfilter(&volData, reg, &resultVolume, reg, 5); + LowPassFilter< RawVolume, RawVolume, Density16 > lowPassfilter(&volData, reg, &resultVolume, reg, 3); //Test the normal implementation QBENCHMARK { @@ -74,16 +74,17 @@ void TestLowPassFilter::testExecute() QCOMPARE(resultVolume.getVoxelAt(7,7,7), Density8(4)); //Test the SAT implmentation - //FIXME - Shouldn't the results be the same as the normal case? - lowPassfilter.executeSAT(); + QBENCHMARK { + lowPassfilter.executeSAT(); + } QCOMPARE(resultVolume.getVoxelAt(0,0,0), Density8(4)); - QCOMPARE(resultVolume.getVoxelAt(1,1,1), Density8(8)); - QCOMPARE(resultVolume.getVoxelAt(2,2,2), Density8(19)); - QCOMPARE(resultVolume.getVoxelAt(3,3,3), Density8(12)); - QCOMPARE(resultVolume.getVoxelAt(4,4,4), Density8(19)); - QCOMPARE(resultVolume.getVoxelAt(5,5,5), Density8(12)); - QCOMPARE(resultVolume.getVoxelAt(6,6,6), Density8(8)); - QCOMPARE(resultVolume.getVoxelAt(7,7,7), Density8(2)); + QCOMPARE(resultVolume.getVoxelAt(1,1,1), Density8(21)); + QCOMPARE(resultVolume.getVoxelAt(2,2,2), Density8(10)); + QCOMPARE(resultVolume.getVoxelAt(3,3,3), Density8(21)); + QCOMPARE(resultVolume.getVoxelAt(4,4,4), Density8(10)); + QCOMPARE(resultVolume.getVoxelAt(5,5,5), Density8(21)); + QCOMPARE(resultVolume.getVoxelAt(6,6,6), Density8(10)); + QCOMPARE(resultVolume.getVoxelAt(7,7,7), Density8(4)); } QTEST_MAIN(TestLowPassFilter) From da77fa8432f7a3b1e18e4dd396216b4541877ba2 Mon Sep 17 00:00:00 2001 From: David Williams Date: Tue, 4 Dec 2012 21:57:54 +0100 Subject: [PATCH 42/47] Updated readme with some real information for BitBucket. --- README.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 9081fcb5..6c88db24 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,5 @@ PolyVox - The voxel management and manipulation library ======================================================= +PolyVox is the core technology which lies behind our games. It is a fast, lightweight C++ library for the storage and processing of volumetric (voxel-based) environments. It has applications in both games and medical/scientific visualisation, and is released under the terms of the `zlib license `_. -For installation instructions, please see INSTALL.txt +PolyVox is a relatively low-level library, and you will need experience in C++ and computer graphics/shaders to use it effectively. It is designed to be easily integrated into existing applications and is independent of your chosen graphics API. For more details please see 'this page '_ on our website. \ No newline at end of file From 7f4be2929e773021d8e6db8de12683bc3d5865b9 Mon Sep 17 00:00:00 2001 From: David Williams Date: Tue, 4 Dec 2012 22:26:39 +0100 Subject: [PATCH 43/47] Changed type of single quotes used for link. I'm not sure if this makes a difference but it's for consistency. --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 6c88db24..9bf85940 100644 --- a/README.rst +++ b/README.rst @@ -2,4 +2,4 @@ PolyVox - The voxel management and manipulation library ======================================================= PolyVox is the core technology which lies behind our games. It is a fast, lightweight C++ library for the storage and processing of volumetric (voxel-based) environments. It has applications in both games and medical/scientific visualisation, and is released under the terms of the `zlib license `_. -PolyVox is a relatively low-level library, and you will need experience in C++ and computer graphics/shaders to use it effectively. It is designed to be easily integrated into existing applications and is independent of your chosen graphics API. For more details please see 'this page '_ on our website. \ No newline at end of file +PolyVox is a relatively low-level library, and you will need experience in C++ and computer graphics/shaders to use it effectively. It is designed to be easily integrated into existing applications and is independent of your chosen graphics API. For more details please see `this page `_ on our website. \ No newline at end of file From c10e992bf2b408863483408e9be373c47d13c688 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Wed, 26 Dec 2012 23:24:09 +0000 Subject: [PATCH 44/47] Fixed bug with SimpleVolume and negative positions. See commit 3f87fc780f6b60f6bf574833921bfca6 --- .../include/PolyVoxCore/SimpleVolume.inl | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index 12cee40f..f811f456 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -197,18 +197,28 @@ namespace PolyVox throw std::invalid_argument("Block side length must be a power of two."); } - m_uBlockSideLength = uBlockSideLength; - m_uNoOfVoxelsPerBlock = m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength; + //m_uBlockSideLength = uBlockSideLength; + //m_uNoOfVoxelsPerBlock = m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength; m_pUncompressedBorderData = 0; this->m_regValidRegion = regValidRegion; - m_regValidRegionInBlocks.setLowerCorner(this->m_regValidRegion.getLowerCorner() / static_cast(uBlockSideLength)); - m_regValidRegionInBlocks.setUpperCorner(this->m_regValidRegion.getUpperCorner() / static_cast(uBlockSideLength)); + //m_regValidRegionInBlocks.setLowerCorner(this->m_regValidRegion.getLowerCorner() / static_cast(uBlockSideLength)); + //m_regValidRegionInBlocks.setUpperCorner(this->m_regValidRegion.getUpperCorner() / static_cast(uBlockSideLength)); //Compute the block side length m_uBlockSideLength = uBlockSideLength; m_uBlockSideLengthPower = logBase2(m_uBlockSideLength); + m_uNoOfVoxelsPerBlock = m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength; + + //m_regValidRegionInBlocks.setLowerX(this->m_regValidRegion.getLowerX() >> m_uBlockSideLengthPower); + //m_regValidRegionInBlocks.setLowerY(this->m_regValidRegion.getLowerY() >> m_uBlockSideLengthPower); + //m_regValidRegionInBlocks.setLowerZ(this->m_regValidRegion.getLowerZ() >> m_uBlockSideLengthPower); + m_regValidRegionInBlocks.setLowerCorner(Vector3DInt32(this->m_regValidRegion.getLowerCorner().getX() >> m_uBlockSideLengthPower, this->m_regValidRegion.getLowerCorner().getY() >> m_uBlockSideLengthPower, this->m_regValidRegion.getLowerCorner().getZ() >> m_uBlockSideLengthPower)); + //m_regValidRegionInBlocks.setUpperX(this->m_regValidRegion.getUpperX() >> m_uBlockSideLengthPower); + //m_regValidRegionInBlocks.setUpperY(this->m_regValidRegion.getUpperY() >> m_uBlockSideLengthPower); + //m_regValidRegionInBlocks.setUpperZ(this->m_regValidRegion.getUpperZ() >> m_uBlockSideLengthPower); + m_regValidRegionInBlocks.setUpperCorner(Vector3DInt32(this->m_regValidRegion.getUpperCorner().getX() >> m_uBlockSideLengthPower, this->m_regValidRegion.getUpperCorner().getY() >> m_uBlockSideLengthPower, this->m_regValidRegion.getUpperCorner().getZ() >> m_uBlockSideLengthPower)); //Compute the size of the volume in blocks (and note +1 at the end) m_uWidthInBlocks = m_regValidRegionInBlocks.getUpperCorner().getX() - m_regValidRegionInBlocks.getLowerCorner().getX() + 1; From f0e2924c42ea5260fd453eed93e25423cf0ef98b Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Wed, 26 Dec 2012 23:39:06 +0000 Subject: [PATCH 45/47] Fixed potential bug with negative voxel positions in large volume. See commit 1f9264a --- .../include/PolyVoxCore/LargeVolume.inl | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 4e679477..8a6634f7 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -422,18 +422,25 @@ namespace PolyVox this->m_regValidRegion = regValidRegion; - m_regValidRegionInBlocks.setLowerCorner(this->m_regValidRegion.getLowerCorner() / static_cast(uBlockSideLength)); - m_regValidRegionInBlocks.setUpperCorner(this->m_regValidRegion.getUpperCorner() / static_cast(uBlockSideLength)); + //m_regValidRegionInBlocks.setLowerCorner(this->m_regValidRegion.getLowerCorner() / static_cast(uBlockSideLength)); + //m_regValidRegionInBlocks.setUpperCorner(this->m_regValidRegion.getUpperCorner() / static_cast(uBlockSideLength)); + //Compute the block side length + m_uBlockSideLength = uBlockSideLength; + m_uBlockSideLengthPower = logBase2(m_uBlockSideLength); + //m_regValidRegionInBlocks.setLowerX(this->m_regValidRegion.getLowerX() >> m_uBlockSideLengthPower); + //m_regValidRegionInBlocks.setLowerY(this->m_regValidRegion.getLowerY() >> m_uBlockSideLengthPower); + //m_regValidRegionInBlocks.setLowerZ(this->m_regValidRegion.getLowerZ() >> m_uBlockSideLengthPower); + m_regValidRegionInBlocks.setLowerCorner(Vector3DInt32(this->m_regValidRegion.getLowerCorner().getX() >> m_uBlockSideLengthPower, this->m_regValidRegion.getLowerCorner().getY() >> m_uBlockSideLengthPower, this->m_regValidRegion.getLowerCorner().getZ() >> m_uBlockSideLengthPower)); + //m_regValidRegionInBlocks.setUpperX(this->m_regValidRegion.getUpperX() >> m_uBlockSideLengthPower); + //m_regValidRegionInBlocks.setUpperY(this->m_regValidRegion.getUpperY() >> m_uBlockSideLengthPower); + //m_regValidRegionInBlocks.setUpperZ(this->m_regValidRegion.getUpperZ() >> m_uBlockSideLengthPower); + m_regValidRegionInBlocks.setUpperCorner(Vector3DInt32(this->m_regValidRegion.getUpperCorner().getX() >> m_uBlockSideLengthPower, this->m_regValidRegion.getUpperCorner().getY() >> m_uBlockSideLengthPower, this->m_regValidRegion.getUpperCorner().getZ() >> m_uBlockSideLengthPower)); setMaxNumberOfUncompressedBlocks(m_uMaxNumberOfUncompressedBlocks); //Clear the previous data m_pBlocks.clear(); - //Compute the block side length - m_uBlockSideLength = uBlockSideLength; - m_uBlockSideLengthPower = logBase2(m_uBlockSideLength); - //Clear the previous data m_pBlocks.clear(); From 8747c05be9694ee27898d753de1453edd27d2695 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Thu, 27 Dec 2012 00:04:40 +0000 Subject: [PATCH 46/47] Bump version number to 0.2.1 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e8bbf35..1b587ab0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ PROJECT(PolyVox) SET(POLYVOX_VERSION_MAJOR "0") SET(POLYVOX_VERSION_MINOR "2") -SET(POLYVOX_VERSION_PATCH "0") +SET(POLYVOX_VERSION_PATCH "1") SET(POLYVOX_VERSION "${POLYVOX_VERSION_MAJOR}.${POLYVOX_VERSION_MINOR}.${POLYVOX_VERSION_PATCH}" CACHE STRING "PolyVox version") MARK_AS_ADVANCED(FORCE POLYVOX_VERSION) From 4f7a6256a9fbbc17aadc5b28c3a30961f6a42b77 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 29 Dec 2012 00:11:23 +0000 Subject: [PATCH 47/47] The throwing of exceptions can now be disabled, and in this case a handler function is called instead. --- library/PolyVoxCore/CMakeLists.txt | 1 + .../include/PolyVoxCore/Impl/ErrorHandling.h | 25 ++++++++++++++++++- library/PolyVoxCore/source/Impl/Utility.cpp | 12 ++++----- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index 34deabef..f964a8d5 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -94,6 +94,7 @@ SET(CORE_INC_FILES ) SET(IMPL_SRC_FILES + source/Impl/ErrorHandling.cpp source/Impl/MarchingCubesTables.cpp source/Impl/RandomUnitVectors.cpp source/Impl/RandomVectors.cpp diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h index 88415f74..d3ef8b49 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h @@ -26,8 +26,10 @@ freely, subject to the following restrictions: #include //For std::exit #include //For std::cerr +#include #define POLYVOX_ASSERTS_ENABLED +//#define POLYVOX_THROW_ENABLED #if defined(_MSC_VER) #define POLYVOX_HALT() __debugbreak() @@ -54,7 +56,7 @@ freely, subject to the following restrictions: { \ std::cerr << std::endl << std::endl; \ std::cerr << " PolyVox Assertion Failed!" << std::endl; \ - std::cerr << " -------------------------" << std::endl; \ + std::cerr << " =========================" << std::endl; \ std::cerr << " Condition: " << #condition << std::endl; \ std::cerr << " Message: " << (message) << std::endl; \ std::cerr << " Location: " << "Line " << __LINE__ << " of " << __FILE__ << std::endl << std::endl; \ @@ -98,4 +100,25 @@ freely, subject to the following restrictions: #define POLYVOX_STATIC_ASSERT(condition, message) StaticAssert<(condition)>::ERROR_The_static_assertion_has_failed(); #endif +/* + * Exceptions + * ---------- + * ... + */ +#ifdef POLYVOX_THROW_ENABLED + #define POLYVOX_THROW(type, message) throw type((message)) +#else + namespace PolyVox + { + typedef void (*ThrowHandler)(std::exception& e, const char* file, int line); + + ThrowHandler getThrowHandler(); + void setThrowHandler(ThrowHandler newHandler); + } + + #define POLYVOX_THROW(type, message) \ + type except = (type)((message)); \ + getThrowHandler()((except), __FILE__, __LINE__) +#endif + #endif //__PolyVox_ErrorHandling_H__ diff --git a/library/PolyVoxCore/source/Impl/Utility.cpp b/library/PolyVoxCore/source/Impl/Utility.cpp index 6e907ab9..c82c9630 100644 --- a/library/PolyVoxCore/source/Impl/Utility.cpp +++ b/library/PolyVoxCore/source/Impl/Utility.cpp @@ -21,11 +21,9 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ +#include "PolyVoxCore/Impl/ErrorHandling.h" #include "PolyVoxCore/Impl/Utility.h" -#include -#include - namespace PolyVox { //Note: this function only works for inputs which are a power of two and not zero @@ -33,17 +31,17 @@ namespace PolyVox uint8_t logBase2(uint32_t uInput) { //Debug mode validation - assert(uInput != 0); - assert(isPowerOf2(uInput)); + POLYVOX_ASSERT(uInput != 0, "Cannot compute the log of zero."); + POLYVOX_ASSERT(isPowerOf2(uInput), "Input must be a power of two in order to compute the log."); //Release mode validation if(uInput == 0) { - throw std::invalid_argument("Cannot compute the log of zero."); + POLYVOX_THROW(std::invalid_argument, "Cannot compute the log of zero."); } if(!isPowerOf2(uInput)) { - throw std::invalid_argument("Input must be a power of two in order to compute the log."); + POLYVOX_THROW(std::invalid_argument, "Input must be a power of two in order to compute the log."); } uint32_t uResult = 0;