Create window on Haiku
This commit is contained in:
parent
c73b363a7f
commit
d25b6de1b5
@ -101,6 +101,12 @@ if(SERENITYOS)
|
||||
add_definitions("-D__serenityos__")
|
||||
endif()
|
||||
option(WINDOW_SERENITYOS "Enable SerenityOS window creation" ${WINDOW_SERENITYOS_DEFAULT})
|
||||
if(HAIKU)
|
||||
set(WINDOW_HAIKU_DEFAULT ON)
|
||||
else()
|
||||
set(WINDOW_HAIKU_DEFAULT OFF)
|
||||
endif()
|
||||
option(WINDOW_HAIKU "Enable Haiku window creation" ${WINDOW_HAIKU_DEFAULT})
|
||||
|
||||
option(ENABLE_BACKTRACE_PRINTING "Enable backtrace printing" OFF)
|
||||
if(ENABLE_BACKTRACE_PRINTING)
|
||||
@ -235,6 +241,16 @@ if(BUILD_CLIENT)
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
if(WINDOW_HAIKU)
|
||||
list(APPEND CLIENT_SOURCES
|
||||
src/game/window/haiku_window.cpp
|
||||
)
|
||||
if(RENDERER_GL OR RENDERER_LEGACY_GL)
|
||||
list(APPEND CLIENT_SOURCES
|
||||
src/game/renderer/gl/haiku_gl_context.cpp
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
if(BUILD_SERVER)
|
||||
file(GLOB_RECURSE SERVER_SOURCES "src/server/**.cpp")
|
||||
@ -348,6 +364,10 @@ if(BUILD_CLIENT)
|
||||
target_link_libraries(${PROJECT_NAME} ${XKBCommon_LIBRARY})
|
||||
endif()
|
||||
|
||||
if(WINDOW_HAIKU)
|
||||
target_link_libraries(${PROJECT_NAME} "be" "game")
|
||||
endif()
|
||||
|
||||
if(NOT GLM_INCLUDE_DIRS)
|
||||
find_package(GLM REQUIRED)
|
||||
endif()
|
||||
|
@ -32,6 +32,7 @@ SOFTWARE.
|
||||
#cmakedefine WINDOW_X11
|
||||
#cmakedefine WINDOW_WAYLAND
|
||||
#cmakedefine WINDOW_SERENITYOS
|
||||
#cmakedefine WINDOW_HAIKU
|
||||
|
||||
#cmakedefine ENABLE_BACKTRACE_PRINTING
|
||||
|
||||
|
@ -71,8 +71,8 @@ GLContext* GLContext::create_context(window::Window* window) {
|
||||
break;
|
||||
#endif
|
||||
case window::WindowType::WINDOW_TYPE_WAYLAND:
|
||||
return nullptr;
|
||||
case window::WindowType::WINDOW_TYPE_SERENITYOS:
|
||||
case window::WindowType::WINDOW_TYPE_HAIKU:
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
|
40
src/game/renderer/gl/haiku_gl_context.cpp
Normal file
40
src/game/renderer/gl/haiku_gl_context.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "game/renderer/gl/haiku_gl_context.hpp"
|
||||
|
||||
#include "game/window/haiku_window.hpp"
|
||||
|
||||
using namespace polygun::renderer;
|
||||
|
||||
HaikuGLContext::HaikuGLContext(window::HaikuWindow* window) :
|
||||
GLContext(),
|
||||
BGLView(window->Bounds(), "glView", B_FOLLOW_ALL_SIDES, 0, BGL_RGB|BGL_DEPTH|BGL_DOUBLE)
|
||||
{
|
||||
LockGL();
|
||||
}
|
||||
|
||||
void* HaikuGLContext::get_proc_address(const std::string& name) {
|
||||
return nullptr;
|
||||
}
|
46
src/game/renderer/gl/haiku_gl_context.hpp
Normal file
46
src/game/renderer/gl/haiku_gl_context.hpp
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef POLYGUN_RENDERER_HAIKU_GL_CONTEXT_HPP
|
||||
#define POLYGUN_RENDERER_HAIKU_GL_CONTEXT_HPP
|
||||
|
||||
#include "game/renderer/gl/gl_context.hpp"
|
||||
#include <GLView.h>
|
||||
|
||||
namespace polygun::window {
|
||||
class HaikuWindow;
|
||||
}
|
||||
|
||||
namespace polygun::renderer {
|
||||
class HaikuGLContext final : public GLContext, public BGLView {
|
||||
public:
|
||||
HaikuGLContext(window::HaikuWindow* window);
|
||||
|
||||
#if defined(RENDERER_GL)
|
||||
virtual void* get_proc_address(const std::string& name) override;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
#endif // POLYGUN_RENDERER_HAIKU_GL_CONTEXT_HPP
|
@ -38,7 +38,8 @@ using namespace polygun::renderer;
|
||||
|
||||
LegacyGLMasterRenderer::LegacyGLMasterRenderer(window::Window* window) :
|
||||
MasterRenderer(),
|
||||
m_context(nullptr)
|
||||
m_context(nullptr),
|
||||
m_should_delete_gl_context(!window->window_creates_gl_context())
|
||||
{
|
||||
if(window->window_creates_gl_context())
|
||||
m_context = window->get_window_gl_context();
|
||||
@ -52,6 +53,7 @@ LegacyGLMasterRenderer::LegacyGLMasterRenderer(window::Window* window) :
|
||||
}
|
||||
|
||||
LegacyGLMasterRenderer::~LegacyGLMasterRenderer() {
|
||||
if(m_should_delete_gl_context)
|
||||
delete m_context;
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,7 @@ namespace polygun::renderer {
|
||||
|
||||
private:
|
||||
GLContext* m_context;
|
||||
bool m_should_delete_gl_context;
|
||||
};
|
||||
}
|
||||
|
||||
|
93
src/game/window/haiku_window.cpp
Normal file
93
src/game/window/haiku_window.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "game/window/haiku_window.hpp"
|
||||
|
||||
#include <Application.h>
|
||||
|
||||
#include "common/logger.hpp"
|
||||
|
||||
using namespace polygun::window;
|
||||
|
||||
static BApplication* g_app = nullptr;
|
||||
|
||||
HaikuWindow::HaikuWindow(const std::string& title, unsigned width, unsigned height, renderer::RendererType renderer_type) :
|
||||
BDirectWindow(BRect(10, 10, width, height), title.c_str(), B_TITLED_WINDOW, 0),
|
||||
Window()
|
||||
{
|
||||
m_type = WindowType::WINDOW_TYPE_HAIKU;
|
||||
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::HaikuGLContext(this);
|
||||
AddChild(m_gl_context);
|
||||
#else
|
||||
LOG_FATAL("Request to setup HaikuGLContext while OpenGL renderer is not compiled in");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
Show();
|
||||
}
|
||||
|
||||
HaikuWindow::~HaikuWindow() {
|
||||
#if defined(RENDERER_GL) || defined(RENDERER_LEGACY_GL)
|
||||
if(m_gl_context) {
|
||||
m_gl_context->UnlockGL();
|
||||
//delete m_gl_context;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void HaikuWindow::finish_frame() {
|
||||
#if defined(RENDERER_GL) || defined(RENDERER_LEGACY_GL)
|
||||
if(m_gl_context)
|
||||
m_gl_context->SwapBuffers();
|
||||
#endif
|
||||
}
|
||||
|
||||
void HaikuWindow::grab_mouse(bool grab) {
|
||||
|
||||
}
|
||||
|
||||
bool HaikuWindow::QuitRequested() {
|
||||
Event new_event;
|
||||
new_event.m_type = EventType::EVENT_TYPE_WINDOW_CLOSE;
|
||||
push_event(new_event);
|
||||
return true;
|
||||
}
|
||||
|
||||
void HaikuWindow::MessageReceived(BMessage* msg) {
|
||||
msg->PrintToStream();
|
||||
switch(msg->what) {
|
||||
case B_KYD:
|
||||
LOG_VERBOSE("Key down!");
|
||||
default:
|
||||
BDirectWindow::MessageReceived(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void HaikuWindow::init_application() {
|
||||
g_app = new BApplication("application/x-vnd.PolyGun-PolyGun");
|
||||
}
|
61
src/game/window/haiku_window.hpp
Normal file
61
src/game/window/haiku_window.hpp
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef POLYGUN_WINDOW_HAIKU_WINDOW_HPP
|
||||
#define POLYGUN_WINDOW_HAIKU_WINDOW_HPP
|
||||
|
||||
#include "game/window/window.hpp"
|
||||
#include <DirectWindow.h>
|
||||
|
||||
#if defined(RENDERER_GL) || defined(RENDERER_LEGACY_GL)
|
||||
#include "game/renderer/gl/haiku_gl_context.hpp"
|
||||
#endif
|
||||
|
||||
namespace polygun::window {
|
||||
class HaikuWindow final : public BDirectWindow, public Window {
|
||||
public:
|
||||
HaikuWindow(const std::string& title, unsigned width, unsigned height, renderer::RendererType renderer_type);
|
||||
virtual ~HaikuWindow() override;
|
||||
|
||||
virtual void finish_frame() override;
|
||||
virtual void grab_mouse(bool grab) override;
|
||||
#if defined(RENDERER_GL) || defined(RENDERER_LEGACY_GL)
|
||||
virtual bool window_creates_gl_context() const override { return true; }
|
||||
virtual renderer::GLContext* get_window_gl_context() override { return m_gl_context; }
|
||||
#endif
|
||||
// BDirectWindow methods
|
||||
virtual bool QuitRequested() override;
|
||||
virtual void MessageReceived(BMessage* msg) override;
|
||||
|
||||
static void init_application();
|
||||
|
||||
private:
|
||||
#if defined(RENDERER_GL) || defined(RENDERER_LEGACY_GL)
|
||||
renderer::HaikuGLContext* m_gl_context;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // POLYGUN_WINDOW_HAIKU_WINDOW_HPP
|
@ -37,6 +37,9 @@ SOFTWARE.
|
||||
#if defined(WINDOW_SERENITYOS)
|
||||
#include "game/window/serenityos_window.hpp"
|
||||
#endif
|
||||
#if defined(WINDOW_HAIKU)
|
||||
#include "game/window/haiku_window.hpp"
|
||||
#endif
|
||||
#include "common/logger.hpp"
|
||||
|
||||
using namespace polygun;
|
||||
@ -122,6 +125,13 @@ window::Window* window::Window::create_window(const std::string& title, unsigned
|
||||
LOG_FATAL("Failed to create X11 window: not compiled in");
|
||||
#endif
|
||||
}
|
||||
#elif defined(__HAIKU__)
|
||||
#if defined(WINDOW_HAIKU)
|
||||
HaikuWindow::init_application();
|
||||
return new HaikuWindow(title, width, height, renderer_type);
|
||||
#else
|
||||
LOG_FATAL("Failed to create Haiku window: not compiled in");
|
||||
#endif
|
||||
#endif
|
||||
LOG_FATAL("Failed to determine which window type should be created. You may have to set it manually");
|
||||
return nullptr;
|
||||
|
@ -46,7 +46,8 @@ namespace polygun::window {
|
||||
WINDOW_TYPE_WIN32,
|
||||
WINDOW_TYPE_X11,
|
||||
WINDOW_TYPE_WAYLAND,
|
||||
WINDOW_TYPE_SERENITYOS
|
||||
WINDOW_TYPE_SERENITYOS,
|
||||
WINDOW_TYPE_HAIKU
|
||||
};
|
||||
|
||||
class Window : public utils::ThreadSafe{
|
||||
|
Loading…
x
Reference in New Issue
Block a user