Win32Window: Adapt to changes introduced in d097e34
This commit is contained in:
parent
8467fcc584
commit
cfdc59d5bd
@ -26,6 +26,13 @@ SOFTWARE.
|
|||||||
|
|
||||||
#if defined(RENDERER_GL)
|
#if defined(RENDERER_GL)
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#include "game/renderer/gl/msvc_glext.hpp"
|
||||||
|
#else
|
||||||
|
#include <GL/glext.h>
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace polygun::renderer;
|
using namespace polygun::renderer;
|
||||||
|
@ -36,9 +36,6 @@ namespace polygun::renderer {
|
|||||||
virtual Shader* create_shader() const override;
|
virtual Shader* create_shader() const override;
|
||||||
virtual Mesh* create_mesh(MeshUsageHint hint = MeshUsageHint::MESH_USAGE_HINT_STATIC) const override;
|
virtual Mesh* create_mesh(MeshUsageHint hint = MeshUsageHint::MESH_USAGE_HINT_STATIC) const override;
|
||||||
virtual Texture* create_texture() const override;
|
virtual Texture* create_texture() const override;
|
||||||
|
|
||||||
private:
|
|
||||||
bool m_window_manages_gl_context;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,17 +24,16 @@ SOFTWARE.
|
|||||||
|
|
||||||
#include "game/renderer/gl/win32_gl_context.hpp"
|
#include "game/renderer/gl/win32_gl_context.hpp"
|
||||||
|
|
||||||
|
#include "common/logger.hpp"
|
||||||
#include "game/window/win32_window.hpp"
|
#include "game/window/win32_window.hpp"
|
||||||
#include "game/renderer/gl/opengl.hpp"
|
#include "game/renderer/gl/opengl.hpp"
|
||||||
#include "common/logger.hpp"
|
|
||||||
|
|
||||||
using namespace polygun::renderer;
|
using namespace polygun::renderer;
|
||||||
|
|
||||||
Win32GLContext::Win32GLContext(window::Window* window):
|
Win32GLContext::Win32GLContext(window::Win32Window* window):
|
||||||
m_context()
|
m_context()
|
||||||
{
|
{
|
||||||
window::Win32Window* wnd = static_cast<window::Win32Window*>(window);
|
initialize(window->get_ctx());
|
||||||
initialize(wnd->get_ctx());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Win32GLContext::~Win32GLContext() {
|
Win32GLContext::~Win32GLContext() {
|
||||||
|
@ -33,10 +33,14 @@ SOFTWARE.
|
|||||||
#undef UNICODE
|
#undef UNICODE
|
||||||
//#include <GL/gl.h>
|
//#include <GL/gl.h>
|
||||||
|
|
||||||
|
namespace polygun::window {
|
||||||
|
class Win32Window;
|
||||||
|
}
|
||||||
|
|
||||||
namespace polygun::renderer {
|
namespace polygun::renderer {
|
||||||
class Win32GLContext final : public GLContext {
|
class Win32GLContext final : public GLContext {
|
||||||
public:
|
public:
|
||||||
Win32GLContext(window::Window* window);
|
Win32GLContext(window::Win32Window* window);
|
||||||
~Win32GLContext() override;
|
~Win32GLContext() override;
|
||||||
|
|
||||||
#if defined(RENDERER_GL)
|
#if defined(RENDERER_GL)
|
||||||
|
@ -270,11 +270,14 @@ static LRESULT CALLBACK window_proc(HWND window_handle, UINT message, WPARAM par
|
|||||||
return g_current_window.load()->window_proc(window_handle, message, param1, param2);
|
return g_current_window.load()->window_proc(window_handle, message, param1, param2);
|
||||||
}
|
}
|
||||||
|
|
||||||
Win32Window::Win32Window(const std::string& title, unsigned width, unsigned height) :
|
Win32Window::Win32Window(const std::string& title, unsigned width, unsigned height, renderer::RendererType renderer_type) :
|
||||||
Window(),
|
Window(),
|
||||||
m_window_handle(),
|
m_window_handle(),
|
||||||
m_ctx(),
|
m_ctx(),
|
||||||
m_window_thread(),
|
m_window_thread(),
|
||||||
|
#if defined(RENDERER_GL) || defined(RENDERER_LEGACY_GL)
|
||||||
|
m_gl_context(nullptr),
|
||||||
|
#endif
|
||||||
m_window_created(false),
|
m_window_created(false),
|
||||||
m_switch_mouse_grab(false)
|
m_switch_mouse_grab(false)
|
||||||
{
|
{
|
||||||
@ -284,9 +287,24 @@ Win32Window::Win32Window(const std::string& title, unsigned width, unsigned heig
|
|||||||
// Wait until window thread creates window
|
// Wait until window thread creates window
|
||||||
LOG_VERBOSE("Waiting until window thread creates window");
|
LOG_VERBOSE("Waiting until window thread creates window");
|
||||||
while(!m_window_created);
|
while(!m_window_created);
|
||||||
|
|
||||||
|
switch(renderer_type) {
|
||||||
|
case renderer::RendererType::RENDERER_TYPE_GL:
|
||||||
|
case renderer::RendererType::RENDERER_TYPE_LEGACY_GL:
|
||||||
|
#if defined(RENDERER_GL) || defined(RENDERER_LEGACY_GL)
|
||||||
|
m_gl_context = new renderer::Win32GLContext(this);
|
||||||
|
#else
|
||||||
|
throw std::runtime_error("Request to setup OpenGL context while OpenGL renderer is not compiled in");
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Win32Window::~Win32Window() {
|
Win32Window::~Win32Window() {
|
||||||
|
#if defined(RENDERER_GL) || defined(RENDERER_LEGACY_GL)
|
||||||
|
if(m_gl_context)
|
||||||
|
delete m_gl_context;
|
||||||
|
#endif
|
||||||
if(m_window_thread->joinable())
|
if(m_window_thread->joinable())
|
||||||
m_window_thread->join();
|
m_window_thread->join();
|
||||||
ReleaseDC(m_window_handle, m_ctx);
|
ReleaseDC(m_window_handle, m_ctx);
|
||||||
|
@ -33,10 +33,20 @@ SOFTWARE.
|
|||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#if defined(RENDERER_GL) || defined(RENDERER_LEGACY_GL)
|
||||||
|
#include "game/renderer/gl/win32_gl_context.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(RENDERER_GL) || defined(RENDERER_LEGACY_GL)
|
||||||
|
namespace polygun::renderer {
|
||||||
|
class Win32GLContext;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace polygun::window {
|
namespace polygun::window {
|
||||||
class Win32Window final : public Window {
|
class Win32Window final : public Window {
|
||||||
public:
|
public:
|
||||||
Win32Window(const std::string& title, unsigned width, unsigned height);
|
Win32Window(const std::string& title, unsigned width, unsigned height, renderer::RendererType renderer_type);
|
||||||
virtual ~Win32Window() override;
|
virtual ~Win32Window() override;
|
||||||
|
|
||||||
LRESULT window_proc(HWND window_handle, UINT message, WPARAM param1, LPARAM param2);
|
LRESULT window_proc(HWND window_handle, UINT message, WPARAM param1, LPARAM param2);
|
||||||
@ -46,11 +56,17 @@ namespace polygun::window {
|
|||||||
|
|
||||||
virtual void finish_frame() override;
|
virtual void finish_frame() override;
|
||||||
virtual void grab_mouse(bool grab) override;
|
virtual void grab_mouse(bool grab) override;
|
||||||
|
#if defined(RENDERER_GL) || defined(RENDERER_LEGACY_GL)
|
||||||
|
virtual renderer::GLContext* get_window_gl_context() override { return m_gl_context; }
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HWND m_window_handle;
|
HWND m_window_handle;
|
||||||
HDC m_ctx;
|
HDC m_ctx;
|
||||||
std::unique_ptr<std::thread> m_window_thread;
|
std::unique_ptr<std::thread> m_window_thread;
|
||||||
|
#if defined(RENDERER_GL) || defined(RENDERER_LEGACY_GL)
|
||||||
|
renderer::Win32GLContext* m_gl_context;
|
||||||
|
#endif
|
||||||
// State semaphores
|
// State semaphores
|
||||||
std::atomic_bool m_window_created;
|
std::atomic_bool m_window_created;
|
||||||
std::atomic_bool m_switch_mouse_grab;
|
std::atomic_bool m_switch_mouse_grab;
|
||||||
|
@ -78,7 +78,7 @@ size_t window::Window::poll_events(Event& event) {
|
|||||||
window::Window* window::Window::create_window(const std::string& title, unsigned width, unsigned height, renderer::RendererType renderer_type) {
|
window::Window* window::Window::create_window(const std::string& title, unsigned width, unsigned height, renderer::RendererType renderer_type) {
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#if defined(WINDOW_WIN32)
|
#if defined(WINDOW_WIN32)
|
||||||
return new window::Win32Window(title, width, height);
|
return new window::Win32Window(title, width, height, renderer_type);
|
||||||
#else
|
#else
|
||||||
LOG_FATAL("Win32Window creation is not compiled in");
|
LOG_FATAL("Win32Window creation is not compiled in");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user