Compare commits
5
Commits
b9e8144519
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de7d435ccb | ||
|
|
97aed4e5ca | ||
|
|
416446206f | ||
|
|
c6ab0327c1 | ||
|
|
e6a5c9e805 |
+5
-3
@@ -1,9 +1,11 @@
|
|||||||
build/
|
build/
|
||||||
.vscode/
|
.*
|
||||||
|
!.gitignore
|
||||||
|
!.clangd
|
||||||
CMakeFiles/
|
CMakeFiles/
|
||||||
|
CMakeKits.json
|
||||||
CMakeCache.txt
|
CMakeCache.txt
|
||||||
docs/*
|
docs/*
|
||||||
!docs/CMake*
|
!docs/CMake*
|
||||||
!docs/Doxyfile.in
|
!docs/Doxyfile.in
|
||||||
!.clangd
|
|
||||||
.glsld
|
|
||||||
|
|||||||
+18
-31
@@ -28,56 +28,43 @@ function(toAbsolutePath SETVAR PATHS)
|
|||||||
set(${SETVAR} ${RET_VAL} PARENT_SCOPE)
|
set(${SETVAR} ${RET_VAL} PARENT_SCOPE)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
if (NOT CMAKE_BUILD_TYPE)
|
||||||
|
set(CMAKE_BUILD_TYPE "Debug")
|
||||||
|
endif()
|
||||||
|
|
||||||
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||||
message(STATUS "Targeting Release build")
|
add_compile_definitions(_NB_BUILD_RELEASE)
|
||||||
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
message(STATUS "Targeting Debug build")
|
|
||||||
set(NB_DEBUG_BUILD ON)
|
set(NB_DEBUG_BUILD ON)
|
||||||
add_compile_definitions(_NB_BUILD_DEBUG)
|
add_compile_definitions(_NB_BUILD_DEBUG)
|
||||||
endif()
|
endif()
|
||||||
|
message(STATUS "Targeting ${CMAKE_BUILD_TYPE} build")
|
||||||
|
|
||||||
|
if (NB_DEBUG_BUILD)
|
||||||
|
set(NB_LOGGING ON)
|
||||||
|
set(NB_BUILD_TESTS ON)
|
||||||
|
set(NB_BUILD_DOCS ON)
|
||||||
|
set(NB_MONITOR_OPENGL_CALLS ON)
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
|
||||||
|
endif()
|
||||||
|
|
||||||
cmake_dependent_option(NB_LOGGING
|
|
||||||
"Creates a default logger and automatically logs with code locations."
|
|
||||||
ON
|
|
||||||
NB_DEBUG_BUILD
|
|
||||||
OFF
|
|
||||||
)
|
|
||||||
cmake_dependent_option(NB_BUILD_TESTS
|
|
||||||
"Build unit tests"
|
|
||||||
ON
|
|
||||||
NB_DEBUG_BUILD
|
|
||||||
OFF
|
|
||||||
)
|
|
||||||
cmake_dependent_option(NB_BUILD_DOCS
|
|
||||||
"Build documentation"
|
|
||||||
ON
|
|
||||||
NB_DEBUG_BUILD
|
|
||||||
OFF
|
|
||||||
)
|
|
||||||
cmake_dependent_option(NBENGINE_INSTALL
|
cmake_dependent_option(NBENGINE_INSTALL
|
||||||
"Install NBEngine"
|
"Install NBEngine"
|
||||||
ON
|
ON
|
||||||
NB_DEBUG_BUILD
|
NB_DEBUG_BUILD
|
||||||
OFF
|
OFF
|
||||||
)
|
)
|
||||||
cmake_dependent_option(NB_MONITOR_OPENGL_CALLS
|
|
||||||
"Monitors every OpenGL call for errors"
|
|
||||||
ON
|
|
||||||
NB_DEBUG_BUILD
|
|
||||||
OFF
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||||
message(STATUS "Building for Windows")
|
message(STATUS "Targeting Windows")
|
||||||
set(NB_TARGET_WINDOWS ON)
|
set(NB_TARGET_WINDOWS ON)
|
||||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||||
message(STATUS "Building for Linux")
|
message(STATUS "Targeting Linux")
|
||||||
set(NB_TARGET_LINUX ON)
|
set(NB_TARGET_LINUX ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NB_BUILD_TESTS)
|
if(NB_BUILD_TESTS)
|
||||||
message(STATUS "Building tests")
|
message(STATUS "Targeting tests")
|
||||||
enable_testing()
|
enable_testing()
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
@@ -106,7 +93,7 @@ endif()
|
|||||||
|
|
||||||
get_filename_component(NBENGINE_ROOT ${CMAKE_CURRENT_LIST_DIR} ABSOLUTE)
|
get_filename_component(NBENGINE_ROOT ${CMAKE_CURRENT_LIST_DIR} ABSOLUTE)
|
||||||
|
|
||||||
add_subdirectory(./engine ${PROJECT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
|
add_subdirectory(./engine)
|
||||||
|
|
||||||
# Toggle
|
# Toggle
|
||||||
set(NB_REBUILD_DOCS)
|
set(NB_REBUILD_DOCS)
|
||||||
|
|||||||
+15
-28
@@ -1,30 +1,17 @@
|
|||||||
add_subdirectory(./NBCore)
|
set(NBENGINE_MODULES
|
||||||
|
NBCore
|
||||||
|
NBGraphics
|
||||||
|
NBData
|
||||||
|
)
|
||||||
|
|
||||||
get_target_property(NBCORE_INTERFACE_INCLUDES NBCore INTERFACE_INCLUDE_DIRECTORIES)
|
set(NB_INCLUDE_FILES "")
|
||||||
include_directories(${NBCORE_INTERFACE_INCLUDES})
|
set(NB_SOURCE_FILES "")
|
||||||
|
foreach(module ${NBENGINE_MODULES})
|
||||||
|
add_subdirectory("./${module}")
|
||||||
|
get_target_property(MODULE_INCLUDES ${module} INTERFACE_INCLUDE_DIRECTORIES)
|
||||||
|
list(APPEND NB_INCLUDE_FILES ${MODULE_INCLUDES})
|
||||||
|
list(APPEND NB_SOURCE_FILES ${MODULE_INCLUDES})
|
||||||
|
endforeach()
|
||||||
|
set(NB_INCLUDE_FILES ${NB_INCLUDE_FILES} PARENT_SCOPE)
|
||||||
|
set(NB_SOURCE_FILES ${NB_SOURCE_FILES} PARENT_SCOPE)
|
||||||
|
|
||||||
#add_subdirectory(./NBEvents)
|
|
||||||
add_subdirectory(./NBGraphics)
|
|
||||||
add_subdirectory(./NBData)
|
|
||||||
|
|
||||||
if (NB_CORE_SOURCE OR NB_EVENTS_SOURCE OR NB_GRAPHICS_SOURCE OR NB_DATA_SOURCE)
|
|
||||||
set(NB_SOURCE_FILES "")
|
|
||||||
list(APPEND NB_SOURCE_FILES
|
|
||||||
${NB_CORE_SOURCE}
|
|
||||||
${NB_GRAPHICS_SOURCE}
|
|
||||||
${NB_EVENTS_SOURCE}
|
|
||||||
${NB_DATA_SOURCE}
|
|
||||||
)
|
|
||||||
set(NB_SOURCE_FILES ${NB_SOURCE_FILES} PARENT_SCOPE)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (NB_CORE_INCLUDE OR NB_EVENTS_INCLUDE OR NB_GRAPHICS_INCLUDE OR NB_DATA_INCLUDE)
|
|
||||||
set(NB_INCLUDE_FILES "")
|
|
||||||
list(APPEND NB_INCLUDE_FILES
|
|
||||||
${NB_CORE_INCLUDE}
|
|
||||||
${NB_GRAPHICS_INCLUDE}
|
|
||||||
${NB_EVENTS_INCLUDE}
|
|
||||||
${NB_DATA_INCLUDE}
|
|
||||||
)
|
|
||||||
set(NB_INCLUDE_FILES ${NB_INCLUDE_FILES} PARENT_SCOPE)
|
|
||||||
endif()
|
|
||||||
|
|||||||
@@ -8,15 +8,9 @@ set(CMAKE_CXX_EXTENSIONS OFF)
|
|||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
include(CMakePackageConfigHelpers)
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
toAbsolutePath(NB_CORE_SOURCE
|
|
||||||
./src/ErrorsImpl.cpp
|
|
||||||
./src/Logger.cpp
|
|
||||||
./src/Processes.cpp
|
|
||||||
./src/StringUtils.cpp
|
|
||||||
./src/TypeTraits.cpp
|
|
||||||
./src/Utils.cpp
|
|
||||||
)
|
|
||||||
toAbsolutePath(NB_CORE_INCLUDE
|
toAbsolutePath(NB_CORE_INCLUDE
|
||||||
|
./include/NBCore/Arrays.hpp
|
||||||
|
./include/NBCore/CoreTypes.hpp
|
||||||
./include/NBCore/DataSink.hpp
|
./include/NBCore/DataSink.hpp
|
||||||
./include/NBCore/Errors.hpp
|
./include/NBCore/Errors.hpp
|
||||||
./include/NBCore/ErrorsImpl.hpp
|
./include/NBCore/ErrorsImpl.hpp
|
||||||
@@ -30,10 +24,14 @@ toAbsolutePath(NB_CORE_INCLUDE
|
|||||||
./include/NBCore/Utils.hpp
|
./include/NBCore/Utils.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(NB_CORE_SOURCE ${NB_CORE_SOURCE} PARENT_SCOPE)
|
add_library(NBCore
|
||||||
set(NB_CORE_INCLUDE ${NB_CORE_INCLUDE} PARENT_SCOPE)
|
./src/ErrorsImpl.cpp
|
||||||
|
./src/Logger.cpp
|
||||||
add_library(NBCore ${NB_CORE_SOURCE})
|
./src/Processes.cpp
|
||||||
|
./src/StringUtils.cpp
|
||||||
|
./src/TypeTraits.cpp
|
||||||
|
./src/Utils.cpp
|
||||||
|
)
|
||||||
add_library(NBEngine::Core ALIAS NBCore)
|
add_library(NBEngine::Core ALIAS NBCore)
|
||||||
target_include_directories(NBCore
|
target_include_directories(NBCore
|
||||||
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
|
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
|
||||||
|
|||||||
@@ -0,0 +1,135 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifndef _NB_DATA_TYPES
|
||||||
|
#define _NB_DATA_TYPES
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include <NBCore/Errors.hpp>
|
||||||
|
|
||||||
|
namespace nb {
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief A multidimensional array template class
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
template<typename T, unsigned int N>
|
||||||
|
class NDArray {
|
||||||
|
public:
|
||||||
|
using Coordinate = std::array<unsigned int, N>;
|
||||||
|
|
||||||
|
private:
|
||||||
|
template<unsigned int M>
|
||||||
|
static Coordinate ProjectDimensions(const std::array<unsigned int, M>& dims) {
|
||||||
|
Coordinate p;
|
||||||
|
unsigned int i=0;
|
||||||
|
if constexpr (M > N) {
|
||||||
|
std::for_each(dims.begin(), dims.end(), [&](unsigned int x){
|
||||||
|
if (i < N) {
|
||||||
|
p[i] = x;
|
||||||
|
} else {
|
||||||
|
if (x != 1) {
|
||||||
|
THROW(Error(Error<>::VALUE_ERROR,
|
||||||
|
"Higher dimensions must have a size of 1"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
});
|
||||||
|
} else if constexpr (M < N) {
|
||||||
|
p.fill(1);
|
||||||
|
std::for_each(dims.begin(), dims.end(), [&](unsigned int x) {p[i] = x; i++;});
|
||||||
|
} else { p = dims; }
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
T* _data;
|
||||||
|
static unsigned int CalculateTotalSize(const std::array<unsigned int, N>& dims) {
|
||||||
|
unsigned int ret = 1;
|
||||||
|
std::for_each(dims.begin(), dims.end(), [&](unsigned int n){
|
||||||
|
ret *= n;
|
||||||
|
});
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
template<typename U, unsigned int M>
|
||||||
|
friend class NDArray;
|
||||||
|
|
||||||
|
static NDArray&& MemoryToNDArray(const Coordinate& dimensions_, T* data_) {
|
||||||
|
auto ret = NDArray(dimensions_);
|
||||||
|
ret._data = data_;
|
||||||
|
return std::move(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
const Coordinate dimensions;
|
||||||
|
const unsigned int totalSize;
|
||||||
|
NDArray(const Coordinate& dimensions_, T* data_=nullptr) :
|
||||||
|
dimensions(dimensions_),
|
||||||
|
totalSize(CalculateTotalSize(dimensions_))
|
||||||
|
{
|
||||||
|
if (data_) { data(data_); }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NDArray(NDArray&& arr) :
|
||||||
|
dimensions(arr.dimensions),
|
||||||
|
totalSize(arr.totalSize),
|
||||||
|
_data(std::move(arr._data)) {}
|
||||||
|
|
||||||
|
NDArray(const NDArray& arr)=delete;
|
||||||
|
|
||||||
|
template<unsigned int M>
|
||||||
|
NDArray(NDArray<T, M>&& arr) :
|
||||||
|
dimensions(ProjectDimensions<M>(arr.dimensions)),
|
||||||
|
totalSize(arr.totalSize),
|
||||||
|
_data(std::move(arr._data)){}
|
||||||
|
|
||||||
|
NDArray& operator=(const NDArray& arr) = delete;
|
||||||
|
NDArray& operator=(NDArray&& arr) = delete;
|
||||||
|
~NDArray() {
|
||||||
|
if (_data) { delete[] _data; }
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned int coordinateToIndex(const Coordinate& coord) const {
|
||||||
|
unsigned int blockSize = 1;
|
||||||
|
unsigned int ret = 0;
|
||||||
|
for (auto i = 0; i < dimensions.size(); ++i) {
|
||||||
|
ret += coord[i] * blockSize;
|
||||||
|
blockSize *= dimensions[i];
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline NDArray& copy() const {
|
||||||
|
return NDArray(dimensions, _data);
|
||||||
|
}
|
||||||
|
inline const T& at(const Coordinate& coord) const {
|
||||||
|
return operator[](coord);
|
||||||
|
}
|
||||||
|
inline const T* data() const { return _data; }
|
||||||
|
inline const T& operator[](const Coordinate& coord) const {
|
||||||
|
return _data[coordinateToIndex(coord)];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline T& at(const Coordinate& coord) {
|
||||||
|
return _data[coordinateToIndex(coord)];
|
||||||
|
}
|
||||||
|
inline T* data(const T* data_) {
|
||||||
|
if (!_data) { _data = new T[totalSize]; }
|
||||||
|
std::memcpy(_data, data_, totalSize * sizeof(T));
|
||||||
|
return _data;
|
||||||
|
}
|
||||||
|
inline T& operator[](const Coordinate& coord) {
|
||||||
|
return _data[coordinateToIndex(coord)];
|
||||||
|
}
|
||||||
|
|
||||||
|
}; // class NDArray<type, int>
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace nb
|
||||||
|
#endif // _NB_DATA_TYPES
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifndef _NB_CORE_TYPES
|
||||||
|
#define _NB_CORE_TYPES
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace nb {
|
||||||
|
template<typename T>
|
||||||
|
using SharedVector = std::vector<std::shared_ptr<T>>;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
using RValueVector = std::vector<T&&>;
|
||||||
|
|
||||||
|
using ByteVector = std::vector<uint8_t>;
|
||||||
|
|
||||||
|
template<typename A, typename B>
|
||||||
|
class ConstantMap : public std::unordered_map<A, B> {
|
||||||
|
using Base = std::unordered_map<A, B>;
|
||||||
|
|
||||||
|
public:
|
||||||
|
using Base::Base;
|
||||||
|
using Base::at;
|
||||||
|
const B& operator[](const A& key) const {
|
||||||
|
return at(key);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
enum TypeCodes {
|
||||||
|
UINT8, UINT16, UINT32, UINT64, INT8, INT16, INT32, INT64,
|
||||||
|
FLOAT16, FLOAT32, DOUBLE64, BOOL, NONE
|
||||||
|
};
|
||||||
|
|
||||||
|
}; // namespace nb
|
||||||
|
|
||||||
|
#endif // _NB_NB_CORE_TYPES
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include <NBCore/StringUtils.hpp>
|
#include <NBCore/StringUtils.hpp>
|
||||||
#include <NBCore/Utils.hpp>
|
#include <NBCore/CoreTypes.hpp>
|
||||||
|
|
||||||
namespace nb {
|
namespace nb {
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
#define _NB_TYPE_TRAITS
|
#define _NB_TYPE_TRAITS
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include <NBCore/CoreTypes.hpp>
|
||||||
|
|
||||||
namespace nb {
|
namespace nb {
|
||||||
|
|
||||||
@@ -29,10 +32,8 @@ namespace detail {
|
|||||||
};
|
};
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
enum TypeCodes {
|
template<typename K, typename V>
|
||||||
UINT8, UINT16, UINT32, UINT64, INT8, INT16, INT32, INT64,
|
std::pair<K, V> KeyVal(K key, V val) { return std::pair(key, val); }
|
||||||
FLOAT16, FLOAT32, DOUBLE64, BOOL, NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static constexpr TypeCodes GetTypeEnum = NONE;
|
static constexpr TypeCodes GetTypeEnum = NONE;
|
||||||
|
|||||||
@@ -1,35 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifndef _NB_CORE_TYPES
|
#ifndef _NB_UTILTIES
|
||||||
#define _NB_CORE_TYPES
|
#define _NB_UTILTIES
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// #include <NBCore/Errors.hpp>
|
#include <NBCore/CoreTypes.hpp>
|
||||||
|
#include <NBCore/Errors.hpp>
|
||||||
|
|
||||||
namespace nb {
|
namespace nb {
|
||||||
|
|
||||||
template<typename A, typename B>
|
|
||||||
class ConstantMap : public std::unordered_map<A, B> {
|
|
||||||
using Base = std::unordered_map<A, B>;
|
|
||||||
|
|
||||||
public:
|
|
||||||
using Base::Base;
|
|
||||||
using Base::at;
|
|
||||||
const B& operator[](const A& key) const {
|
|
||||||
return at(key);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
using SharedVector = std::vector<std::shared_ptr<T>>;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
using RValueVector = std::vector<T&&>;
|
|
||||||
|
|
||||||
using ByteVector = std::vector<uint8_t>;
|
|
||||||
|
|
||||||
/* class ObjectManagerError : public Error<ObjectManagerError> {
|
/* class ObjectManagerError : public Error<ObjectManagerError> {
|
||||||
using Base = Error<ObjectManagerError>;
|
using Base = Error<ObjectManagerError>;
|
||||||
|
|
||||||
@@ -67,10 +46,9 @@ ByteVector concatVectorBytes(const std::vector<T>& vec1, const std::vector<S>& v
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
std::vector<T> bytesToVector(const ByteVector& vec) {
|
std::vector<T> bytesToVector(const ByteVector& vec) {
|
||||||
if (vec.size() % sizeof(T) != 0) {
|
if (vec.size() % sizeof(T) != 0) {
|
||||||
/* THROW(Error<NoneType>(
|
THROW(Error(
|
||||||
std::runtime_error("Data size does not align to std::vector<" + std::string(typeid(T).name()) + ">.")
|
std::runtime_error("Data size does not align to std::vector<" + std::string(typeid(T).name()) + ">.")
|
||||||
)); */
|
));
|
||||||
throw "byyyyeeee";
|
|
||||||
}
|
}
|
||||||
unsigned int num_elmts = vec.size() / sizeof(T);
|
unsigned int num_elmts = vec.size() / sizeof(T);
|
||||||
std::vector<T> ret(num_elmts);
|
std::vector<T> ret(num_elmts);
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
cmake_minimum_required(VERSION 3.26.0)
|
cmake_minimum_required(VERSION 3.26.0)
|
||||||
|
|
||||||
if (NB_BUILD_TESTS)
|
enable_testing()
|
||||||
enable_testing()
|
include(GoogleTest)
|
||||||
include(GoogleTest)
|
add_executable(TestCore
|
||||||
add_executable(TestCore
|
./testArrays.cpp
|
||||||
./testErrors.cpp
|
./testErrors.cpp
|
||||||
#./testProcesses.cpp
|
#./testProcesses.cpp
|
||||||
./testUtils.cpp
|
./testUtils.cpp
|
||||||
)
|
)
|
||||||
target_link_libraries(TestCore
|
target_link_libraries(TestCore
|
||||||
NBCore
|
NBCore
|
||||||
GTest::gtest_main
|
GTest::gtest_main
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(LoggerTest
|
add_executable(LoggerTest
|
||||||
./testLogger.cpp
|
./testLogger.cpp
|
||||||
)
|
)
|
||||||
target_link_libraries(LoggerTest
|
target_link_libraries(LoggerTest
|
||||||
NBCore
|
NBCore
|
||||||
)
|
)
|
||||||
|
|
||||||
|
gtest_discover_tests(TestCore)
|
||||||
|
|
||||||
gtest_discover_tests(TestCore)
|
|
||||||
endif()
|
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
#define CODE_ERROR_LOCATIONS
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <NBCore/Arrays.hpp>
|
||||||
|
|
||||||
|
template<unsigned int N>
|
||||||
|
using Coord = typename nb::NDArray<uint8_t, N>::Coordinate;
|
||||||
|
|
||||||
|
template<typename A, typename B>
|
||||||
|
void ASSERT_ARRAY_EQ(A a, B b) {
|
||||||
|
unsigned int n = a.size();
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
|
ASSERT_EQ(a[i], b[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(TestNDArray, TestBasic) {
|
||||||
|
float* data_f = new float[9] {0,1,2,3,4,5,6,7,8};
|
||||||
|
nb::NDArray<float, 2> arr({3, 3}, data_f);
|
||||||
|
Coord<2> x{1,1};
|
||||||
|
ASSERT_ARRAY_EQ(arr.dimensions, Coord<2>{3,3});
|
||||||
|
ASSERT_FLOAT_EQ(data_f[4], arr.at(x));
|
||||||
|
arr.at(x) = 0.5;
|
||||||
|
ASSERT_FLOAT_EQ(0.5, arr.at(x));
|
||||||
|
delete[] data_f;
|
||||||
|
|
||||||
|
Coord<3> y{1,0,1};
|
||||||
|
unsigned int* data_ui = new unsigned int[8] {0,1,2,3,4,5,6,7};
|
||||||
|
nb::NDArray<unsigned int, 3> arr3d({2,2,2}, data_ui);
|
||||||
|
ASSERT_ARRAY_EQ(arr3d.dimensions, Coord<3>{2,2,2});
|
||||||
|
ASSERT_EQ(data_ui[5], arr3d.at(y));
|
||||||
|
arr3d[{0,1,1}] = 23;
|
||||||
|
ASSERT_EQ(23, arr3d.at({0,1,1}));
|
||||||
|
delete[] data_ui;
|
||||||
|
|
||||||
|
nb::NDArray<uint8_t, 4> arr4d({4,4,4,4});
|
||||||
|
arr4d[{0,1,2,3}] = 57;
|
||||||
|
ASSERT_ARRAY_EQ(arr4d.dimensions, Coord<4>{4,4,4,4});
|
||||||
|
ASSERT_EQ(57, arr4d.at({0,1,2,3}));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(TestNDArray, TestMove) {
|
||||||
|
unsigned int data_ui[8] = {0,1,2,3,4,5,6,7};
|
||||||
|
nb::NDArray<unsigned int, 2> arr_1({4, 2}, data_ui);
|
||||||
|
nb::NDArray<unsigned int, 2> arr_2(std::move(arr_1));
|
||||||
|
Coord<2> x{2, 1};
|
||||||
|
ASSERT_EQ(arr_1.data(), nullptr);
|
||||||
|
ASSERT_ARRAY_EQ(arr_1.dimensions, arr_2.dimensions);
|
||||||
|
ASSERT_EQ(arr_2.at(x), 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(TestNDArray, TestConversion) {
|
||||||
|
nb::NDArray<unsigned int, 2> arr1({3,3});
|
||||||
|
nb::NDArray<unsigned int, 3> arr2(std::move(arr1));
|
||||||
|
ASSERT_EQ(arr1.data(), nullptr);
|
||||||
|
ASSERT_ARRAY_EQ(arr2.dimensions, Coord<3>{3,3,1});
|
||||||
|
nb::NDArray<unsigned int, 2> arr3(std::move(arr2));
|
||||||
|
ASSERT_EQ(arr2.data(), nullptr);
|
||||||
|
ASSERT_ARRAY_EQ(arr3.dimensions, Coord<2>{3,3});
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(TestNDArray, TestFromMemory) {
|
||||||
|
auto data = new float[9]{1,2,3,4,5,6,7,8,9};
|
||||||
|
auto arr1 = nb::NDArray<float, 2>::MemoryToNDArray({3,3}, data);
|
||||||
|
ASSERT_EQ(arr1.data(), data);
|
||||||
|
ASSERT_FLOAT_EQ(arr1.at({1,2}), data[5]);
|
||||||
|
auto data2 = new float[9]{9,8,7,6,5,4,3,2,1};
|
||||||
|
arr1.data(data2);
|
||||||
|
ASSERT_EQ(arr1.data(), data);
|
||||||
|
ASSERT_FLOAT_EQ(arr1.at({3,0}), data2[6]);
|
||||||
|
delete[] data2;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -3,8 +3,9 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <NBCore/TypeTraits.hpp>
|
|
||||||
#include <NBCore/StringUtils.hpp>
|
#include <NBCore/StringUtils.hpp>
|
||||||
|
#include <NBCore/TypeTraits.hpp>
|
||||||
|
#include <NBCore/Utils.hpp>
|
||||||
|
|
||||||
namespace nb {
|
namespace nb {
|
||||||
|
|
||||||
@@ -46,7 +47,6 @@ TEST(UtilsTest, TestFindAndReplaceWstr) {
|
|||||||
find_and_replace<wchar_t>(L"Jeff", L"e", L"efe").c_str(),
|
find_and_replace<wchar_t>(L"Jeff", L"e", L"efe").c_str(),
|
||||||
L"Jefeff"
|
L"Jefeff"
|
||||||
);
|
);
|
||||||
|
|
||||||
std::wstring tmp = find_and_replace<wchar_t>(L"Naif", L"a", L"afa");
|
std::wstring tmp = find_and_replace<wchar_t>(L"Naif", L"a", L"afa");
|
||||||
ASSERT_STREQ(
|
ASSERT_STREQ(
|
||||||
find_and_replace<wchar_t>(tmp, L"i", L"ifi").c_str(),
|
find_and_replace<wchar_t>(tmp, L"i", L"ifi").c_str(),
|
||||||
@@ -74,44 +74,6 @@ TEST(UtilsTest, TestFindAndReplaceWstr) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TEST(UtilsTest, TestWstrToStr) {
|
|
||||||
ASSERT_STREQ(
|
|
||||||
nb::wstr_to_str(L"Hi!").c_str(),
|
|
||||||
"Hi!"
|
|
||||||
);
|
|
||||||
ASSERT_STREQ(
|
|
||||||
nb::wstr_to_str(L"Naif").c_str(),
|
|
||||||
"Naif"
|
|
||||||
);
|
|
||||||
ASSERT_STREQ(
|
|
||||||
nb::wstr_to_str(L"\r\r\r\n").c_str(),
|
|
||||||
"\r\r\r\n"
|
|
||||||
);
|
|
||||||
ASSERT_STREQ(
|
|
||||||
nb::wstr_to_str(L"Naif\ttalks\r\ra\t\nlot").c_str(),
|
|
||||||
"Naif\ttalks\r\ra\t\nlot"
|
|
||||||
);
|
|
||||||
} */
|
|
||||||
|
|
||||||
/* TEST(UtilsTest, TestStrToWstr) {
|
|
||||||
ASSERT_STREQ(
|
|
||||||
nb::str_to_wstr("Hi!").c_str(),
|
|
||||||
L"Hi!"
|
|
||||||
);
|
|
||||||
ASSERT_STREQ(
|
|
||||||
nb::str_to_wstr("Naif").c_str(),
|
|
||||||
L"Naif"
|
|
||||||
);
|
|
||||||
ASSERT_STREQ(
|
|
||||||
nb::str_to_wstr("\r\r\r\n").c_str(),
|
|
||||||
L"\r\r\r\n"
|
|
||||||
);
|
|
||||||
ASSERT_STREQ(
|
|
||||||
nb::str_to_wstr("Naif\ttalks\r\ra\t\nlot").c_str(),
|
|
||||||
L"Naif\ttalks\r\ra\t\nlot"
|
|
||||||
);
|
|
||||||
} */
|
|
||||||
|
|
||||||
struct A { bool x(); };
|
struct A { bool x(); };
|
||||||
struct B { bool y(); };
|
struct B { bool y(); };
|
||||||
struct C { bool x(); bool y; };
|
struct C { bool x(); bool y; };
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <NBCore/Errors.hpp>
|
#include <NBCore/Errors.hpp>
|
||||||
@@ -31,6 +33,86 @@ class GLFWError : public Error<GLFWError> {
|
|||||||
static const ErrorCodeMap ErrorMessages;
|
static const ErrorCodeMap ErrorMessages;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class OGLWindow;
|
||||||
|
|
||||||
|
enum WindowCallbacks {
|
||||||
|
KEY, CHAR, CHAR_MODS, MOUSE_BUTTON, CURSOR_POS, CURSOR_ENTER,
|
||||||
|
SCROLL, DROP, WINDOW_POS, WINDOW_SIZE, WINDOW_CLOSE, WINDOW_REFRESH,
|
||||||
|
WINDOW_FOCUS, WINDOW_ICONIFY, WINDOW_MAX, FRAMEBUFFER_SIZE, WINDOW_SCALE,
|
||||||
|
};
|
||||||
|
|
||||||
|
template<WindowCallbacks>
|
||||||
|
struct OGLWindowCallbacks;
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct OGLWindowCallbacks<WindowCallbacks::KEY> {
|
||||||
|
using type = typename std::function<void(OGLWindow*, int, int, int, int)>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct OGLWindowCallbacks<WindowCallbacks::CHAR> {
|
||||||
|
using type = typename std::function<void(OGLWindow*, unsigned int)>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct OGLWindowCallbacks<WindowCallbacks::CHAR_MODS> {
|
||||||
|
using type = typename std::function<void(OGLWindow*, unsigned int, int)>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct OGLWindowCallbacks<WindowCallbacks::CURSOR_ENTER> {
|
||||||
|
using type = typename std::function<void(OGLWindow*, int)>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct OGLWindowCallbacks<WindowCallbacks::CURSOR_POS> {
|
||||||
|
using type = typename std::function<void(OGLWindow*, double, double)>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct OGLWindowCallbacks<WindowCallbacks::MOUSE_BUTTON> {
|
||||||
|
using type = typename std::function<void(OGLWindow*, int, int, int)>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct OGLWindowCallbacks<WindowCallbacks::SCROLL> {
|
||||||
|
using type = typename std::function<void(OGLWindow*, double, double)>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct OGLWindowCallbacks<WindowCallbacks::DROP> {
|
||||||
|
using type = typename std::function<void(OGLWindow*, int, const char**)>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct OGLWindowCallbacks<WindowCallbacks::WINDOW_POS> {
|
||||||
|
using type = typename std::function<void(OGLWindow*, int, int)>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct OGLWindowCallbacks<WindowCallbacks::WINDOW_SIZE> {
|
||||||
|
using type = typename std::function<void(OGLWindow*, int, int)>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct OGLWindowCallbacks<WindowCallbacks::WINDOW_CLOSE> {
|
||||||
|
using type = typename std::function<void(OGLWindow*)>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct OGLWindowCallbacks<WindowCallbacks::WINDOW_REFRESH> {
|
||||||
|
using type = typename std::function<void(OGLWindow*)>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct OGLWindowCallbacks<WindowCallbacks::WINDOW_FOCUS> {
|
||||||
|
using type = typename std::function<void(OGLWindow*, int)>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct OGLWindowCallbacks<WindowCallbacks::WINDOW_ICONIFY> {
|
||||||
|
using type = typename std::function<void(OGLWindow*, int)>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct OGLWindowCallbacks<WindowCallbacks::WINDOW_MAX> {
|
||||||
|
using type = typename std::function<void(OGLWindow*, int)>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct OGLWindowCallbacks<WindowCallbacks::FRAMEBUFFER_SIZE> {
|
||||||
|
using type = typename std::function<void(OGLWindow*, int, int)>;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct OGLWindowCallbacks<WindowCallbacks::WINDOW_SCALE> {
|
||||||
|
using type = typename std::function<void(OGLWindow*, int)>;
|
||||||
|
};
|
||||||
|
|
||||||
class OGLWindow {
|
class OGLWindow {
|
||||||
using GLFWHint = std::array<int, 2>;
|
using GLFWHint = std::array<int, 2>;
|
||||||
private:
|
private:
|
||||||
@@ -39,12 +121,6 @@ class OGLWindow {
|
|||||||
THROW(GLFWError(GLFWError::Codes::NOT_MAIN));
|
THROW(GLFWError(GLFWError::Codes::NOT_MAIN));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template<typename... Args>
|
|
||||||
using CallbackFuncType = void (*)(GLFWwindow*, Args...);
|
|
||||||
template<typename... Args>
|
|
||||||
struct CallbackSetterFuncType {
|
|
||||||
typedef CallbackFuncType<Args...> (*type)(GLFWwindow*, CallbackFuncType<Args...>);
|
|
||||||
};
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static std::atomic<unsigned int> _count;
|
static std::atomic<unsigned int> _count;
|
||||||
@@ -52,32 +128,30 @@ class OGLWindow {
|
|||||||
static thread_local GLFWwindow* _currWindow;
|
static thread_local GLFWwindow* _currWindow;
|
||||||
static thread_local const GLFWwindow* _currArena;
|
static thread_local const GLFWwindow* _currArena;
|
||||||
|
|
||||||
static void SetHintInteger(const std::array<int, 2>&);
|
template<typename T>
|
||||||
static void SetHintString(const std::tuple<int, std::string>&);
|
static void SetHint(std::pair<int, T> hint) {
|
||||||
|
if constexpr ( std::is_same_v<T, std::string> ) {
|
||||||
|
glfwWindowHintString(std::get<0>(hint), std::get<1>(hint).c_str());
|
||||||
|
} else if constexpr ( std::is_same_v<T, int> ) {
|
||||||
|
glfwWindowHint(std::get<0>(hint), std::get<1>(hint));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string _title;
|
std::string _title;
|
||||||
GLFWwindow* _window_ptr;
|
GLFWwindow* _window_ptr;
|
||||||
const GLFWwindow* _arena;
|
const GLFWwindow* _arena;
|
||||||
|
|
||||||
OGLWindow(
|
OGLWindow(
|
||||||
unsigned int,
|
unsigned int x,
|
||||||
unsigned int,
|
unsigned int y,
|
||||||
const std::string&,
|
const std::string&,
|
||||||
const std::vector<std::array<int, 2>>&,
|
|
||||||
const std::vector<std::tuple<int, std::string>>&,
|
|
||||||
GLFWwindow* sharingContext = NULL
|
GLFWwindow* sharingContext = NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
GLFWwindow* makeCurrent() const;
|
GLFWwindow* makeCurrent() const;
|
||||||
void detachWindow();
|
void detachWindow();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Callbacks {
|
|
||||||
KEY, CHAR, CHAR_MODS, MOUSE_BUTTON, CURSOR_POS, CURSOR_ENTER,
|
|
||||||
SCROLL, DROP, WINDOW_POS, WINDOW_SIZE, WINDOW_CLOSE, WINDOW_REFRESH,
|
|
||||||
WINDOW_FOCUS, WINDOW_ICONIFY, WINDOW_MAX, FRAMEBUFFER_SIZE, WINDOW_SCALE,
|
|
||||||
};
|
|
||||||
template<typename... T>
|
|
||||||
using CallbackFunc = void(*)(OGLWindow*, T...);
|
|
||||||
|
|
||||||
static inline bool IsGLFWInitialized() { return _glfwInitialized; }
|
static inline bool IsGLFWInitialized() { return _glfwInitialized; }
|
||||||
static bool InitGLFW(const std::vector<GLFWHint>& hints={});
|
static bool InitGLFW(const std::vector<GLFWHint>& hints={});
|
||||||
@@ -87,21 +161,37 @@ class OGLWindow {
|
|||||||
static GLFWwindow* MakeCurrent(const std::shared_ptr<OGLWindow>&);
|
static GLFWwindow* MakeCurrent(const std::shared_ptr<OGLWindow>&);
|
||||||
static inline GLFWwindow* DropCurrent() { return MakeCurrent(nullptr); }
|
static inline GLFWwindow* DropCurrent() { return MakeCurrent(nullptr); }
|
||||||
static void DestroyWindow(std::shared_ptr<OGLWindow>&);
|
static void DestroyWindow(std::shared_ptr<OGLWindow>&);
|
||||||
|
template <typename... T>
|
||||||
static std::shared_ptr<OGLWindow> CreateWindow(
|
static std::shared_ptr<OGLWindow> CreateWindow(
|
||||||
unsigned int x,
|
unsigned int x,
|
||||||
unsigned int y,
|
unsigned int y,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::vector<std::array<int, 2>>& integerHints={},
|
const std::pair<int, T>&... windowHints
|
||||||
const std::vector<std::tuple<int, std::string>>& stringHints={}
|
) {
|
||||||
);
|
(SetHint(std::pair(windowHints)),... );
|
||||||
|
return std::shared_ptr<OGLWindow>(new OGLWindow(
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
title,
|
||||||
|
nullptr
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
template<typename... T>
|
||||||
static std::shared_ptr<OGLWindow> CreateSharedWindow(
|
static std::shared_ptr<OGLWindow> CreateSharedWindow(
|
||||||
unsigned int x,
|
unsigned int x,
|
||||||
unsigned int y,
|
unsigned int y,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
std::shared_ptr<OGLWindow> sharingWindow,
|
std::shared_ptr<OGLWindow> sharingWindow = NULL,
|
||||||
const std::vector<std::array<int, 2>>& integerHints={},
|
const std::pair<int, T>&... windowHints
|
||||||
const std::vector<std::tuple<int, std::string>>& stringHints={}
|
) {
|
||||||
);
|
(SetHint(std::pair(windowHints)),... );
|
||||||
|
return std::shared_ptr<OGLWindow>(new OGLWindow(
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
title,
|
||||||
|
sharingWindow->_window_ptr
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
|
||||||
OGLWindow(OGLWindow&&) = delete;
|
OGLWindow(OGLWindow&&) = delete;
|
||||||
OGLWindow(const OGLWindow&) = delete;
|
OGLWindow(const OGLWindow&) = delete;
|
||||||
@@ -121,8 +211,84 @@ class OGLWindow {
|
|||||||
void setTitle(const std::string&);
|
void setTitle(const std::string&);
|
||||||
void shouldClose(bool);
|
void shouldClose(bool);
|
||||||
|
|
||||||
template<enum Callbacks, typename Func>
|
template<WindowCallbacks CallbackType, typename CallbackFunc>
|
||||||
void setCallback(std::function<Func> callback);
|
void setCallback(CallbackFunc callback) {
|
||||||
|
CheckForMainThread();
|
||||||
|
auto tmp = makeCurrent();
|
||||||
|
static auto this_ptr = this;
|
||||||
|
static typename OGLWindowCallbacks<CallbackType>::type tmp_callback = callback;
|
||||||
|
if constexpr (CallbackType == KEY) {
|
||||||
|
glfwSetKeyCallback(_window_ptr, [](GLFWwindow*, int a, int b, int c, int d){
|
||||||
|
tmp_callback(this_ptr, a,b,c,d);
|
||||||
|
});
|
||||||
|
} else if constexpr (CallbackType == CHAR) {
|
||||||
|
glfwSetCharCallback(_window_ptr, [](GLFWwindow*, int a) {
|
||||||
|
tmp_callback(this_ptr, a);
|
||||||
|
});
|
||||||
|
} else if constexpr (CallbackType == CHAR_MODS) {
|
||||||
|
glfwSetCharModsCallback(_window_ptr, [](GLFWwindow*, unsigned int a, int b) {
|
||||||
|
tmp_callback(this_ptr, a, b);
|
||||||
|
});
|
||||||
|
} else if constexpr (CallbackType == CURSOR_ENTER) {
|
||||||
|
glfwSetCursorEnterCallback(_window_ptr, [](GLFWwindow*, int a) {
|
||||||
|
tmp_callback(this_ptr, a);
|
||||||
|
});
|
||||||
|
} else if constexpr (CallbackType == CURSOR_POS) {
|
||||||
|
glfwSetCursorPosCallback(_window_ptr, [](GLFWwindow*, double a, double b){
|
||||||
|
tmp_callback(this_ptr, a,b);
|
||||||
|
});
|
||||||
|
} else if constexpr (CallbackType == MOUSE_BUTTON) {
|
||||||
|
glfwSetMouseButtonCallback(_window_ptr, [](GLFWwindow*, int a, int b, int c){
|
||||||
|
tmp_callback(this_ptr, a,b,c);
|
||||||
|
});
|
||||||
|
} else if constexpr (CallbackType == SCROLL) {
|
||||||
|
glfwSetScrollCallback(_window_ptr, [](GLFWwindow*, double a, double b) {
|
||||||
|
tmp_callback(this_ptr, a,b);
|
||||||
|
});
|
||||||
|
} else if constexpr (CallbackType == DROP) {
|
||||||
|
glfwSetDropCallback(_window_ptr, [](GLFWwindow*, int a, const char** b) {
|
||||||
|
tmp_callback(this_ptr, a, b);
|
||||||
|
});
|
||||||
|
} else if constexpr (CallbackType == WINDOW_POS) {
|
||||||
|
glfwSetWindowPosCallback(_window_ptr, [](GLFWwindow*, int a, int b){
|
||||||
|
tmp_callback(this_ptr, a,b);
|
||||||
|
});
|
||||||
|
} else if constexpr (CallbackType == WINDOW_SIZE) {
|
||||||
|
glfwSetWindowSizeCallback(_window_ptr, [](GLFWwindow*, int a, int b){
|
||||||
|
tmp_callback(this_ptr, a,b);
|
||||||
|
});
|
||||||
|
} else if constexpr (CallbackType == WINDOW_CLOSE) {
|
||||||
|
glfwSetWindowCloseCallback(_window_ptr, [](GLFWwindow*){
|
||||||
|
tmp_callback(this_ptr);
|
||||||
|
});
|
||||||
|
} else if constexpr (CallbackType == WINDOW_REFRESH) {
|
||||||
|
glfwSetWindowRefreshCallback(_window_ptr, [](GLFWwindow*){
|
||||||
|
tmp_callback(this_ptr);
|
||||||
|
});
|
||||||
|
} else if constexpr (CallbackType == WINDOW_FOCUS) {
|
||||||
|
glfwSetWindowFocusCallback(_window_ptr, [](GLFWwindow*, int a) {
|
||||||
|
tmp_callback(this_ptr, a);
|
||||||
|
});
|
||||||
|
} else if constexpr (CallbackType == WINDOW_ICONIFY) {
|
||||||
|
glfwSetWindowIconifyCallback(_window_ptr, [](GLFWwindow*, int a) {
|
||||||
|
tmp_callback(this_ptr, a);
|
||||||
|
});
|
||||||
|
} else if constexpr (CallbackType == WINDOW_MAX) {
|
||||||
|
glfwSetWindowMaximizeCallback(_window_ptr, [](GLFWwindow*, int a) {
|
||||||
|
tmp_callback(this_ptr, a);
|
||||||
|
});
|
||||||
|
} else if constexpr (CallbackType == FRAMEBUFFER_SIZE) {
|
||||||
|
glfwSetFramebufferSizeCallback(_window_ptr, [](GLFWwindow*, int a, int b) {
|
||||||
|
tmp_callback(this_ptr, a, b);
|
||||||
|
});
|
||||||
|
} else if constexpr (CallbackType == WINDOW_SCALE) {
|
||||||
|
glfwSetWindowContentScaleCallback(_window_ptr, [](GLFWwindow*, int a, int b) {
|
||||||
|
tmp_callback(this_ptr, a, b);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
static_assert(false, "No matching callback.");
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#include <NBGraphics/Window.hpp>
|
#include <NBGraphics/Window.hpp>
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
namespace nb {
|
namespace nb {
|
||||||
|
|
||||||
using GLFWCodes = GLFWError::Codes;
|
using GLFWCodes = GLFWError::Codes;
|
||||||
@@ -50,16 +48,6 @@ bool OGLWindow::TerminateGLFW() {
|
|||||||
return !IsGLFWInitialized();
|
return !IsGLFWInitialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OGLWindow::SetHintInteger(const std::array<int, 2>& hint) {
|
|
||||||
CheckForMainThread();
|
|
||||||
glfwWindowHint(hint[0], hint[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OGLWindow::SetHintString(const std::tuple<int, std::string>& hint) {
|
|
||||||
CheckForMainThread();
|
|
||||||
glfwWindowHintString(std::get<0>(hint), std::get<1>(hint).c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
GLFWwindow* OGLWindow::MakeCurrent(const std::shared_ptr<OGLWindow>& window) {
|
GLFWwindow* OGLWindow::MakeCurrent(const std::shared_ptr<OGLWindow>& window) {
|
||||||
auto tmp = _currWindow;
|
auto tmp = _currWindow;
|
||||||
if (window) {
|
if (window) {
|
||||||
@@ -73,56 +61,14 @@ GLFWwindow* OGLWindow::MakeCurrent(const std::shared_ptr<OGLWindow>& window) {
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<OGLWindow> OGLWindow::CreateWindow(
|
|
||||||
unsigned int x,
|
|
||||||
unsigned int y,
|
|
||||||
const std::string& title,
|
|
||||||
const std::vector<std::array<int, 2>>& integerHints,
|
|
||||||
const std::vector<std::tuple<int, std::string>>& stringHints
|
|
||||||
) {
|
|
||||||
return std::shared_ptr<OGLWindow>( new OGLWindow(
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
title,
|
|
||||||
integerHints,
|
|
||||||
stringHints
|
|
||||||
) );
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<OGLWindow> OGLWindow::CreateSharedWindow(
|
|
||||||
unsigned int x,
|
|
||||||
unsigned int y,
|
|
||||||
const std::string& title,
|
|
||||||
std::shared_ptr<OGLWindow> sharingWindow,
|
|
||||||
const std::vector<std::array<int, 2>>& integerHints,
|
|
||||||
const std::vector<std::tuple<int, std::string>>& stringHints
|
|
||||||
) {
|
|
||||||
return std::shared_ptr<OGLWindow>( new OGLWindow(
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
title,
|
|
||||||
integerHints,
|
|
||||||
stringHints,
|
|
||||||
sharingWindow->getWindowPtr()
|
|
||||||
) );
|
|
||||||
}
|
|
||||||
|
|
||||||
OGLWindow::OGLWindow(
|
OGLWindow::OGLWindow(
|
||||||
unsigned int x,
|
unsigned int x,
|
||||||
unsigned int y,
|
unsigned int y,
|
||||||
const std::string& title,
|
const std::string&,
|
||||||
const std::vector<std::array<int, 2>>& integerHints,
|
|
||||||
const std::vector<std::tuple<int, std::string>>& stringHints,
|
|
||||||
GLFWwindow* sharingContext
|
GLFWwindow* sharingContext
|
||||||
) : _title(title) {
|
) {
|
||||||
CheckForMainThread();
|
CheckForMainThread();
|
||||||
InitGLFW();
|
InitGLFW();
|
||||||
for (const auto& hint : integerHints) {
|
|
||||||
SetHintInteger(hint);
|
|
||||||
}
|
|
||||||
for (const auto& hint : stringHints) {
|
|
||||||
SetHintString(hint);
|
|
||||||
}
|
|
||||||
_window_ptr = glfwCreateWindow(
|
_window_ptr = glfwCreateWindow(
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
@@ -202,37 +148,4 @@ void OGLWindow::setTitle(const std::string& name) {
|
|||||||
glfwSetWindowTitle(_window_ptr, _title.c_str());
|
glfwSetWindowTitle(_window_ptr, _title.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
|
||||||
void OGLWindow::setCallback<OGLWindow::KEY>(std::function<void(OGLWindow*, int, int, int, int)> callback) {
|
|
||||||
CheckForMainThread();
|
|
||||||
auto tmp = makeCurrent();
|
|
||||||
static auto this_ptr = this;
|
|
||||||
static auto tmp_callback = callback;
|
|
||||||
glfwSetKeyCallback(_window_ptr, [](GLFWwindow*, int a, int b, int c, int d){
|
|
||||||
tmp_callback(this_ptr, a, b, c, d);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
void OGLWindow::setCallback<OGLWindow::MOUSE_BUTTON>(std::function<void(OGLWindow*, int, int, int)> callback) {
|
|
||||||
CheckForMainThread();
|
|
||||||
auto tmp = makeCurrent();
|
|
||||||
static auto this_ptr = this;
|
|
||||||
static auto tmp_callback = callback;
|
|
||||||
glfwSetMouseButtonCallback(_window_ptr, [](GLFWwindow*, int a, int b, int c){
|
|
||||||
tmp_callback(this_ptr, a, b, c);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
void OGLWindow::setCallback<OGLWindow::CURSOR_POS>(std::function<void(OGLWindow*, double, double)> callback) {
|
|
||||||
CheckForMainThread();
|
|
||||||
auto tmp = makeCurrent();
|
|
||||||
static auto this_ptr = this;
|
|
||||||
static auto tmp_callback = callback;
|
|
||||||
glfwSetCursorPosCallback(_window_ptr, [](GLFWwindow*, double a, double b){
|
|
||||||
tmp_callback(this_ptr, a, b);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "stb_image.h"
|
#include "stb_image.h"
|
||||||
|
|
||||||
#include <NBCore/Errors.hpp>
|
#include <NBCore/Errors.hpp>
|
||||||
|
#include <NBCore/TypeTraits.hpp>
|
||||||
#include <NBGraphics/Image.hpp>
|
#include <NBGraphics/Image.hpp>
|
||||||
#include <NBGraphics/Mesh.hpp>
|
#include <NBGraphics/Mesh.hpp>
|
||||||
#include <NBGraphics/ProgramPipeline.hpp>
|
#include <NBGraphics/ProgramPipeline.hpp>
|
||||||
@@ -17,8 +18,8 @@ int main() {
|
|||||||
400,
|
400,
|
||||||
400,
|
400,
|
||||||
"Howdy!",
|
"Howdy!",
|
||||||
{{GLFW_CONTEXT_VERSION_MAJOR, 3},
|
nb::KeyVal(GLFW_CONTEXT_VERSION_MAJOR, 3),
|
||||||
{GLFW_CONTEXT_VERSION_MINOR, 3}}
|
nb::KeyVal(GLFW_CONTEXT_VERSION_MINOR, 3)
|
||||||
);
|
);
|
||||||
nb::OGLWindow::MakeCurrent(window);
|
nb::OGLWindow::MakeCurrent(window);
|
||||||
|
|
||||||
@@ -69,16 +70,19 @@ int main() {
|
|||||||
}}, indxs);
|
}}, indxs);
|
||||||
LOG(prog.log());
|
LOG(prog.log());
|
||||||
|
|
||||||
window->setCallback<nb::OGLWindow::KEY>(
|
using nb::WindowCallbacks;
|
||||||
(std::function<void(nb::OGLWindow*, int, int, int, int)>)[](nb::OGLWindow* w, int key, int x, int actiom, int mods)->void{
|
|
||||||
|
window->setCallback<nb::KEY>(
|
||||||
|
[](nb::OGLWindow* w, int key, int, int, int)->void{
|
||||||
if (key == GLFW_KEY_Q) {
|
if (key == GLFW_KEY_Q) {
|
||||||
w->shouldClose(true);
|
w->shouldClose(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
window->setCallback<nb::OGLWindow::CURSOR_POS>(
|
window->setCallback<nb::CURSOR_POS>(
|
||||||
(std::function<void(nb::OGLWindow*, double, double)>)[](nb::OGLWindow* w, double x, double y)->void{
|
[](nb::OGLWindow* w, double x, double y)->void{
|
||||||
nb::logger.msg("Pos in x is " + std::to_string(x));
|
nb::logger.msg("Pos in x is " + std::to_string(x));
|
||||||
});
|
}
|
||||||
|
);
|
||||||
while(!window->shouldClose()) {
|
while(!window->shouldClose()) {
|
||||||
OPENGL_CALL(glClearColor(0.2f, 0.3f, 0.3f, 1.0f));
|
OPENGL_CALL(glClearColor(0.2f, 0.3f, 0.3f, 1.0f));
|
||||||
OPENGL_CALL(glClear(GL_COLOR_BUFFER_BIT));
|
OPENGL_CALL(glClear(GL_COLOR_BUFFER_BIT));
|
||||||
|
|||||||
Reference in New Issue
Block a user