Made window hinting/param system easier
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#define _NB_TYPE_TRAITS
|
#define _NB_TYPE_TRAITS
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace nb {
|
namespace nb {
|
||||||
|
|
||||||
@@ -29,6 +30,9 @@ namespace detail {
|
|||||||
};
|
};
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
|
template<typename K, typename V>
|
||||||
|
std::pair<K, V> KeyVal(K key, V val) { return std::pair(key, val); }
|
||||||
|
|
||||||
enum TypeCodes {
|
enum TypeCodes {
|
||||||
UINT8, UINT16, UINT32, UINT64, INT8, INT16, INT32, INT64,
|
UINT8, UINT16, UINT32, UINT64, INT8, INT16, INT32, INT64,
|
||||||
FLOAT16, FLOAT32, DOUBLE64, BOOL, NONE
|
FLOAT16, FLOAT32, DOUBLE64, BOOL, NONE
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -126,21 +128,26 @@ 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>>& integerWindowHints,
|
|
||||||
const std::vector<std::tuple<int, std::string>>& stringWindowHints={},
|
|
||||||
GLFWwindow* sharingContext = NULL
|
GLFWwindow* sharingContext = NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
GLFWwindow* makeCurrent() const;
|
GLFWwindow* makeCurrent() const;
|
||||||
void detachWindow();
|
void detachWindow();
|
||||||
|
|
||||||
@@ -154,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;
|
||||||
|
|||||||
@@ -48,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) {
|
||||||
@@ -71,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,
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user