2023-04-07 01:10:11 +02:00
|
|
|
#include "panel.h"
|
2023-04-13 21:45:21 +02:00
|
|
|
#include "app.h"
|
|
|
|
#include "overlay.h"
|
2023-04-07 01:10:11 +02:00
|
|
|
|
2023-04-07 20:32:52 +02:00
|
|
|
Panel::Panel(App *app, vr::HmdMatrix34_t start_pose, int index, int x, int y, int width, int height)
|
2023-04-07 01:10:11 +02:00
|
|
|
: _app(app),
|
|
|
|
_index(index),
|
|
|
|
_x(x),
|
|
|
|
_y(y),
|
|
|
|
_width(width),
|
2023-04-11 19:26:26 +02:00
|
|
|
_height(height),
|
2023-04-13 21:45:21 +02:00
|
|
|
_overlay(app, "screen_view_" + std::to_string(index))
|
2023-04-07 01:10:11 +02:00
|
|
|
{
|
|
|
|
glGenTextures(1, &_gl_texture);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, _gl_texture);
|
2023-04-07 19:13:52 +02:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glTexImage2D(
|
|
|
|
GL_TEXTURE_2D, 0, GL_RGB,
|
|
|
|
_width, _height, 0,
|
|
|
|
GL_BGRA, GL_UNSIGNED_BYTE, 0);
|
2023-04-07 01:10:11 +02:00
|
|
|
|
2023-04-07 13:26:42 +02:00
|
|
|
_texture.eColorSpace = vr::ColorSpace_Auto;
|
|
|
|
_texture.eType = vr::TextureType_OpenGL;
|
2023-04-07 01:10:11 +02:00
|
|
|
_texture.handle = (void *)(uintptr_t)_gl_texture;
|
|
|
|
|
2023-04-13 21:45:21 +02:00
|
|
|
_overlay.SetTransformWorld(&start_pose);
|
2023-04-07 01:10:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::Update()
|
|
|
|
{
|
|
|
|
Render();
|
|
|
|
UpdateCursor();
|
|
|
|
|
2023-04-13 21:45:21 +02:00
|
|
|
_overlay.Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
Overlay *Panel::GetOverlay()
|
|
|
|
{
|
|
|
|
return &_overlay;
|
2023-04-07 01:10:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::Render()
|
|
|
|
{
|
2023-04-07 19:13:52 +02:00
|
|
|
glCopyImageSubData(
|
|
|
|
_app->_gl_frame, GL_TEXTURE_2D, 0,
|
|
|
|
_x, _y, 0,
|
|
|
|
_gl_texture, GL_TEXTURE_2D, 0,
|
|
|
|
0, 0, 0,
|
|
|
|
_width, _height, 1);
|
2023-04-07 01:10:11 +02:00
|
|
|
|
2023-04-13 21:45:21 +02:00
|
|
|
_overlay.SetTexture(&_texture);
|
2023-04-07 01:10:11 +02:00
|
|
|
}
|
|
|
|
|
2023-04-11 18:03:03 +02:00
|
|
|
void Panel::SetHidden(bool state)
|
|
|
|
{
|
2023-04-13 21:45:21 +02:00
|
|
|
_overlay.SetHidden(state);
|
2023-04-11 18:03:03 +02:00
|
|
|
}
|
|
|
|
|
2023-04-07 01:10:11 +02:00
|
|
|
void Panel::UpdateCursor()
|
|
|
|
{
|
2023-04-07 19:27:35 +02:00
|
|
|
auto global_pos = _app->GetCursorPosition();
|
|
|
|
if (global_pos.x < _x || global_pos.x >= _x + _width || global_pos.y < _y || global_pos.y >= _y + _height)
|
|
|
|
{
|
2023-04-13 21:45:21 +02:00
|
|
|
_app->vr_overlay->ClearOverlayCursorPositionOverride(_overlay.Id());
|
2023-04-07 19:27:35 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
int local_x = global_pos.x - _x;
|
|
|
|
int local_y = global_pos.y - _y;
|
|
|
|
|
2023-04-07 01:10:11 +02:00
|
|
|
// TODO: make this work when aspect ratio is >1 (root window is taller than it is wide)
|
|
|
|
float ratio = (float)_height / (float)_width;
|
|
|
|
float top_edge = 0.5f - ratio / 2.0f;
|
2023-04-07 19:27:35 +02:00
|
|
|
float x = local_x / (float)_width;
|
|
|
|
float y = 1.0f - (local_y / (float)_width + top_edge);
|
2023-04-07 01:10:11 +02:00
|
|
|
auto pos = vr::HmdVector2_t{x, y};
|
2023-04-13 21:45:21 +02:00
|
|
|
_app->vr_overlay->SetOverlayCursorPositionOverride(_overlay.Id(), &pos);
|
2023-04-07 01:10:11 +02:00
|
|
|
}
|