Haiku: gl context locking

This commit is contained in:
Kostadin Damyanov 2015-07-02 18:41:32 +03:00
parent e0e54ea7d4
commit 77e78cdb20
4 changed files with 62 additions and 18 deletions

View file

@ -15,20 +15,17 @@ ContextGL_Haiku::~ContextGL_Haiku() {
Error ContextGL_Haiku::initialize() {
window->AddChild(view);
view->LockGL();
window->SetHaikuGLView(view);
return OK;
}
void ContextGL_Haiku::release_current() {
//ERR_PRINT("release_current() NOT IMPLEMENTED");
view->UnlockGL();
}
void ContextGL_Haiku::make_current() {
view->LockGL();
//ERR_PRINT("make_current() NOT IMPLEMENTED");
}
void ContextGL_Haiku::swap_buffers() {

View file

@ -23,7 +23,7 @@ void HaikuDirectWindow::SetHaikuGLView(HaikuGLView* p_view) {
void HaikuDirectWindow::StartMessageRunner() {
update_runner = new BMessageRunner(BMessenger(this),
new BMessage(REDRAW_MSG), 1000000/60 /* 60 fps */);
new BMessage(REDRAW_MSG), 1000000/30 /* 30 fps */);
}
void HaikuDirectWindow::StopMessageRunner() {
@ -68,15 +68,31 @@ void HaikuDirectWindow::DispatchMessage(BMessage* message, BHandler* handler) {
switch (message->what) {
case B_MOUSE_DOWN:
case B_MOUSE_UP:
DispatchMouseButton(message);
HandleMouseButton(message);
break;
case B_MOUSE_MOVED:
DispatchMouseMoved(message);
HandleMouseMoved(message);
break;
case B_MOUSE_WHEEL_CHANGED:
DispatchMouseWheelChanged(message);
HandleMouseWheelChanged(message);
break;
case B_WINDOW_RESIZED:
HandleWindowResized(message);
//view->UnlockGL();
//BDirectWindow::DispatchMessage(message, handler);
//view->LockGL();
break;
case LOCKGL_MSG:
ERR_PRINT("LOCKGL");
view->LockGL();
break;
case UNLOCKGL_MSG:
view->UnlockGL();
break;
default:
@ -84,7 +100,7 @@ void HaikuDirectWindow::DispatchMessage(BMessage* message, BHandler* handler) {
}
}
void HaikuDirectWindow::DispatchMouseButton(BMessage* message) {
void HaikuDirectWindow::HandleMouseButton(BMessage* message) {
message->PrintToStream();
BPoint where;
@ -143,7 +159,7 @@ void HaikuDirectWindow::DispatchMouseButton(BMessage* message) {
input->parse_input_event(mouse_event);
}
void HaikuDirectWindow::DispatchMouseMoved(BMessage* message) {
void HaikuDirectWindow::HandleMouseMoved(BMessage* message) {
BPoint where;
if (message->FindPoint("where", &where) != B_OK) {
return;
@ -183,7 +199,7 @@ void HaikuDirectWindow::DispatchMouseMoved(BMessage* message) {
input->parse_input_event(motion_event);
}
void HaikuDirectWindow::DispatchMouseWheelChanged(BMessage* message) {
void HaikuDirectWindow::HandleMouseWheelChanged(BMessage* message) {
float wheel_delta_y = 0;
if (message->FindFloat("be:wheel_delta_y", &wheel_delta_y) != B_OK) {
return;
@ -210,6 +226,18 @@ void HaikuDirectWindow::DispatchMouseWheelChanged(BMessage* message) {
input->parse_input_event(mouse_event);
}
void HaikuDirectWindow::HandleWindowResized(BMessage* message) {
int32 width = 0;
int32 height = 0;
if ((message->FindInt32("width", &width) != B_OK) || (message->FindInt32("height", &height) != B_OK)) {
return;
}
current_video_mode->width = width;
current_video_mode->height = height;
}
inline InputModifierState HaikuDirectWindow::GetKeyModifierState(uint32 p_state) {
last_key_modifier_state = p_state;
InputModifierState state;

View file

@ -5,9 +5,12 @@
#include <DirectWindow.h>
#include "os/input.h"
#include "core/os/os.h"
#include "haiku_gl_view.h"
#define REDRAW_MSG 'rdrw'
#define LOCKGL_MSG 'glck'
#define UNLOCKGL_MSG 'ulck'
class HaikuDirectWindow : public BDirectWindow
{
@ -18,15 +21,17 @@ private:
uint32 last_buttons_state;
uint32 last_key_modifier_state;
int last_button_mask;
OS::VideoMode* current_video_mode;
MainLoop* main_loop;
InputDefault* input;
HaikuGLView* view;
BMessageRunner* update_runner;
void DispatchMouseButton(BMessage* message);
void DispatchMouseMoved(BMessage* message);
void DispatchMouseWheelChanged(BMessage* message);
void HandleMouseButton(BMessage* message);
void HandleMouseMoved(BMessage* message);
void HandleMouseWheelChanged(BMessage* message);
void HandleWindowResized(BMessage* message);
inline InputModifierState GetKeyModifierState(uint32 p_state);
inline int GetMouseButtonState(uint32 p_state);
@ -39,6 +44,7 @@ public:
void StopMessageRunner();
void SetInput(InputDefault* p_input);
void SetMainLoop(MainLoop* p_main_loop);
inline void SetVideoMode(OS::VideoMode* video_mode) { current_video_mode = video_mode; };
virtual bool QuitRequested();
virtual void DirectConnected(direct_buffer_info* info);
virtual void MessageReceived(BMessage* message);

View file

@ -20,11 +20,21 @@ void OS_Haiku::run() {
}
main_loop->init();
context_gl->release_current();
// TODO: clean up
BMessenger* bms = new BMessenger(window);
BMessage* msg = new BMessage();
bms->SendMessage(LOCKGL_MSG, msg);
window->StartMessageRunner();
app->Run();
window->StopMessageRunner();
delete app;
delete bms;
delete msg;
main_loop->finish();
}
@ -54,6 +64,7 @@ void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_
frame.Set(50, 50, 50 + current_video_mode.width - 1, 50 + current_video_mode.height - 1);
window = new HaikuDirectWindow(frame);
window->SetVideoMode(&current_video_mode);
if (current_video_mode.fullscreen) {
window->SetFullScreen(true);
@ -68,6 +79,7 @@ void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_
#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
context_gl = memnew(ContextGL_Haiku(window));
context_gl->initialize();
context_gl->make_current();
rasterizer = memnew(RasterizerGLES2);
#endif
@ -81,6 +93,10 @@ void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_
// visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD));
//}
input = memnew(InputDefault);
window->SetInput(input);
window->Show();
visual_server->init();
physics_server = memnew(PhysicsServerSW);
@ -104,10 +120,6 @@ void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_
spatial_sound_server->init();
spatial_sound_2d_server = memnew(SpatialSound2DServerSW);
spatial_sound_2d_server->init();
input = memnew(InputDefault);
window->SetInput(input);
window->Show();
}
void OS_Haiku::finalize() {
@ -266,10 +278,11 @@ void OS_Haiku::set_window_resizable(bool p_enabled) {
}
window->SetFlags(flags);
current_video_mode.resizable = p_enabled;
}
bool OS_Haiku::is_window_resizable() const {
return !(window->Flags() & B_NOT_RESIZABLE);
return current_video_mode.resizable;
}
void OS_Haiku::set_window_minimized(bool p_enabled) {