Heavy buffer update, window update, object tracking
This commit is contained in:
@@ -16,8 +16,8 @@ const ErrorCodeMap GLFWError::ErrorMessages = {
|
||||
// class OGLWindow
|
||||
|
||||
std::atomic<bool> OGLWindow::_glfwInitialized = false;
|
||||
thread_local std::shared_ptr<OGLWindow> OGLWindow::_currWindow = nullptr;
|
||||
thread_local GLFWwindow* OGLWindow::_currArena = nullptr;
|
||||
thread_local GLFWwindow* OGLWindow::_currWindow = nullptr;
|
||||
thread_local const GLFWwindow* OGLWindow::_currArena = nullptr;
|
||||
std::atomic<unsigned int> OGLWindow::_count = 0;
|
||||
|
||||
bool OGLWindow::InitGLFW(const std::vector<GLFWHint>& hints) {
|
||||
@@ -58,11 +58,11 @@ void OGLWindow::SetHintString(const std::tuple<int, std::string>& hint) {
|
||||
glfwWindowHintString(std::get<0>(hint), std::get<1>(hint).c_str());
|
||||
}
|
||||
|
||||
std::shared_ptr<OGLWindow> OGLWindow::MakeCurrent(const std::shared_ptr<OGLWindow>& window) {
|
||||
GLFWwindow* OGLWindow::MakeCurrent(const std::shared_ptr<OGLWindow>& window) {
|
||||
auto tmp = _currWindow;
|
||||
_currWindow = window;
|
||||
_currWindow = window->getWindowPtr();
|
||||
if (window) {
|
||||
glfwMakeContextCurrent(_currWindow->_window_ptr);
|
||||
glfwMakeContextCurrent(_currWindow);
|
||||
_currArena = window->_arena;
|
||||
} else {
|
||||
glfwMakeContextCurrent(nullptr);
|
||||
@@ -71,41 +71,6 @@ std::shared_ptr<OGLWindow> OGLWindow::MakeCurrent(const std::shared_ptr<OGLWindo
|
||||
return tmp;
|
||||
}
|
||||
|
||||
OGLWindow::OGLWindow(
|
||||
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
|
||||
) : _title(title) {
|
||||
CheckForMainThread();
|
||||
InitGLFW();
|
||||
for (const auto& hint : integerHints) {
|
||||
SetHintInteger(hint);
|
||||
}
|
||||
for (const auto& hint : stringHints) {
|
||||
SetHintString(hint);
|
||||
}
|
||||
_window_ptr = glfwCreateWindow(
|
||||
x,
|
||||
y,
|
||||
_title.c_str(),
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
if (_window_ptr == NULL) {
|
||||
THROW(GLFWError(GLFWError::Codes::WINDOW_FAILED));
|
||||
}
|
||||
_arena = _window_ptr;
|
||||
auto tmp = glfwGetCurrentContext();
|
||||
glfwMakeContextCurrent(_window_ptr);
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||
THROW(GLFWError(GLFWError::Codes::GLAD_FAILED));
|
||||
}
|
||||
glfwMakeContextCurrent(tmp);
|
||||
OGLWindow::_count.fetch_add(1);
|
||||
}
|
||||
|
||||
std::shared_ptr<OGLWindow> OGLWindow::CreateWindow(
|
||||
unsigned int x,
|
||||
unsigned int y,
|
||||
@@ -122,10 +87,63 @@ std::shared_ptr<OGLWindow> OGLWindow::CreateWindow(
|
||||
) );
|
||||
}
|
||||
|
||||
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(
|
||||
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,
|
||||
GLFWwindow* sharingContext
|
||||
) : _title(title) {
|
||||
CheckForMainThread();
|
||||
InitGLFW();
|
||||
for (const auto& hint : integerHints) {
|
||||
SetHintInteger(hint);
|
||||
}
|
||||
for (const auto& hint : stringHints) {
|
||||
SetHintString(hint);
|
||||
}
|
||||
_window_ptr = glfwCreateWindow(
|
||||
x,
|
||||
y,
|
||||
_title.c_str(),
|
||||
NULL,
|
||||
sharingContext
|
||||
);
|
||||
if (_window_ptr == NULL) {
|
||||
THROW(GLFWError(GLFWError::Codes::WINDOW_FAILED));
|
||||
}
|
||||
_arena = _window_ptr;
|
||||
auto tmp = makeCurrent();
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||
THROW(GLFWError(GLFWError::Codes::GLAD_FAILED));
|
||||
}
|
||||
glfwMakeContextCurrent(tmp);
|
||||
OGLWindow::_count.fetch_add(1);
|
||||
}
|
||||
|
||||
OGLWindow::~OGLWindow() {
|
||||
CheckForMainThread();
|
||||
if (_window_ptr) {
|
||||
if (_window_ptr == _currWindow->_window_ptr) {
|
||||
if (_window_ptr == _currWindow) {
|
||||
_currWindow = nullptr;
|
||||
_currArena = nullptr;
|
||||
}
|
||||
@@ -137,6 +155,12 @@ OGLWindow::~OGLWindow() {
|
||||
}
|
||||
}
|
||||
|
||||
void OGLWindow::detachWindow() {
|
||||
_title = "";
|
||||
_window_ptr = nullptr;
|
||||
_arena = nullptr;
|
||||
}
|
||||
|
||||
int OGLWindow::getWindowAttribute(int attr) const {
|
||||
CheckForMainThread();
|
||||
return glfwGetWindowAttrib(_window_ptr, attr);
|
||||
@@ -149,6 +173,22 @@ std::array<int, 2> OGLWindow::getSize() const {
|
||||
return {x, y};
|
||||
}
|
||||
|
||||
bool OGLWindow::shouldClose() const {
|
||||
CheckForMainThread();
|
||||
return glfwWindowShouldClose(_window_ptr);
|
||||
}
|
||||
|
||||
void OGLWindow::shouldClose(bool val) {
|
||||
CheckForMainThread();
|
||||
glfwSetWindowShouldClose(_window_ptr, val);
|
||||
}
|
||||
|
||||
GLFWwindow* OGLWindow::makeCurrent() const {
|
||||
auto tmp = glfwGetCurrentContext();
|
||||
glfwMakeContextCurrent(_window_ptr);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void OGLWindow::setSize(unsigned int x, unsigned int y) {
|
||||
CheckForMainThread();
|
||||
glfwSetWindowSize(_window_ptr, x, y);
|
||||
@@ -160,4 +200,14 @@ void OGLWindow::setTitle(const std::string& name) {
|
||||
glfwSetWindowTitle(_window_ptr, _title.c_str());
|
||||
}
|
||||
|
||||
/* template<> void OGLWindow::setCallBack<OGLWindow::KEY>( CallbackFunc<int,int,int,int> func) {
|
||||
CheckForMainThread();
|
||||
auto tmp = makeCurrent();
|
||||
auto tmp_func =
|
||||
[=](GLFWwindow* window, int a, int b, int c, int d){
|
||||
func(this, a, b, c, d);
|
||||
};
|
||||
glfwSetKeyCallback(_window_ptr, tmp_func);
|
||||
} */
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user