16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-17 23:39:18 +02:00

handle different window/framebuffer sizes

This commit is contained in:
milek7
2021-01-24 22:00:30 +01:00
parent 34113bf7e7
commit 90a6b7c3b5
15 changed files with 138 additions and 121 deletions

View File

@@ -70,15 +70,13 @@ global_settings::ConfigParse(cParser &Parser) {
} }
else if (token == "width") else if (token == "width")
{ {
Parser.getTokens(1, false); Parser.getTokens(1, false);
Parser >> iWindowWidth; Parser >> window_size.x;
} }
else if (token == "height") else if (token == "height")
{ {
Parser.getTokens(1, false); Parser.getTokens(1, false);
Parser >> iWindowHeight; Parser >> window_size.y;
} }
else if (token == "heightbase") else if (token == "heightbase")
{ {
@@ -1170,8 +1168,8 @@ global_settings::export_as_text( std::ostream &Output ) const {
export_as_text( Output, "sceneryfile", SceneryFile ); export_as_text( Output, "sceneryfile", SceneryFile );
export_as_text( Output, "humanctrlvehicle", local_start_vehicle ); export_as_text( Output, "humanctrlvehicle", local_start_vehicle );
export_as_text( Output, "fieldofview", FieldOfView ); export_as_text( Output, "fieldofview", FieldOfView );
export_as_text( Output, "width", iWindowWidth ); export_as_text( Output, "width", window_size.x );
export_as_text( Output, "height", iWindowHeight ); export_as_text( Output, "height", window_size.y );
export_as_text( Output, "targetfps", targetfps ); export_as_text( Output, "targetfps", targetfps );
export_as_text( Output, "basedrawrange", BaseDrawRange ); export_as_text( Output, "basedrawrange", BaseDrawRange );
export_as_text( Output, "fullscreen", bFullScreen ); export_as_text( Output, "fullscreen", bFullScreen );

View File

@@ -111,8 +111,10 @@ struct global_settings {
float UIBgOpacity{ 0.65f }; // opacity of ui windows float UIBgOpacity{ 0.65f }; // opacity of ui windows
std::string asLang{ "pl" }; // domyślny język - http://tools.ietf.org/html/bcp47 std::string asLang{ "pl" }; // domyślny język - http://tools.ietf.org/html/bcp47
// gfx // gfx
int iWindowWidth{ 800 }; glm::ivec2 window_size; // main window size in platform-specific virtual pixels
int iWindowHeight{ 600 }; glm::ivec2 cursor_pos; // cursor position in platform-specific virtual pixels
glm::ivec2 fb_size; // main window framebuffer size
float fDistanceFactor{ 1.f }; // baza do przeliczania odległości dla LoD float fDistanceFactor{ 1.f }; // baza do przeliczania odległości dla LoD
float targetfps{ 0.0f }; float targetfps{ 0.0f };
bool bFullScreen{ false }; bool bFullScreen{ false };

View File

@@ -66,15 +66,16 @@ void focus_callback( GLFWwindow *window, int focus ) {
Application.on_focus_change(focus != 0); Application.on_focus_change(focus != 0);
} }
void window_resize_callback( GLFWwindow *window, int w, int h ) { void framebuffer_resize_callback( GLFWwindow *, int w, int h ) {
// NOTE: we have two variables which basically do the same thing as we don't have dynamic fullscreen toggle Global.fb_size = glm::ivec2(w, h);
// TBD, TODO: merge them? }
Global.iWindowWidth = w;
Global.iWindowHeight = h; void window_resize_callback( GLFWwindow *, int w, int h ) {
glViewport( 0, 0, w, h ); Global.window_size = glm::ivec2(w, h);
} }
void cursor_pos_callback( GLFWwindow *window, double x, double y ) { void cursor_pos_callback( GLFWwindow *window, double x, double y ) {
Global.cursor_pos = glm::ivec2(x, y);
Application.on_cursor_pos( x, y ); Application.on_cursor_pos( x, y );
} }
@@ -486,22 +487,6 @@ eu07_application::set_cursor_pos( double const Horizontal, double const Vertical
glfwSetCursorPos( m_windows.front(), Horizontal, Vertical ); glfwSetCursorPos( m_windows.front(), Horizontal, Vertical );
} }
glm::dvec2
eu07_application::get_cursor_pos() const {
glm::dvec2 pos;
if( !m_windows.empty() ) {
glfwGetCursorPos( m_windows.front(), &pos.x, &pos.y );
}
return pos;
}
void
eu07_application::get_cursor_pos( double &Horizontal, double &Vertical ) const {
glfwGetCursorPos( m_windows.front(), &Horizontal, &Vertical );
}
/* /*
// provides keyboard mapping associated with specified control item // provides keyboard mapping associated with specified control item
std::string std::string
@@ -579,6 +564,8 @@ eu07_application::window(int const Windowindex, bool visible, int width, int hei
auto const *vmode { glfwGetVideoMode( monitor ? monitor : glfwGetPrimaryMonitor() ) }; auto const *vmode { glfwGetVideoMode( monitor ? monitor : glfwGetPrimaryMonitor() ) };
// match requested video mode to current to allow for
// fullwindow creation when resolution is the same
glfwWindowHint( GLFW_RED_BITS, vmode->redBits ); glfwWindowHint( GLFW_RED_BITS, vmode->redBits );
glfwWindowHint( GLFW_GREEN_BITS, vmode->greenBits ); glfwWindowHint( GLFW_GREEN_BITS, vmode->greenBits );
glfwWindowHint( GLFW_BLUE_BITS, vmode->blueBits ); glfwWindowHint( GLFW_BLUE_BITS, vmode->blueBits );
@@ -738,8 +725,6 @@ eu07_application::init_glfw() {
return -1; return -1;
} }
// match requested video mode to current to allow for
// fullwindow creation when resolution is the same
{ {
int monitor_count; int monitor_count;
GLFWmonitor **monitors = glfwGetMonitors(&monitor_count); GLFWmonitor **monitors = glfwGetMonitors(&monitor_count);
@@ -807,13 +792,13 @@ eu07_application::init_glfw() {
if( Global.fullscreen_windowed ) { if( Global.fullscreen_windowed ) {
auto const mode = glfwGetVideoMode( monitor ); auto const mode = glfwGetVideoMode( monitor );
Global.iWindowWidth = mode->width; Global.window_size.x = mode->width;
Global.iWindowHeight = mode->height; Global.window_size.y = mode->height;
Global.bFullScreen = true; Global.bFullScreen = true;
} }
auto *mainwindow = window( auto *mainwindow = window(
-1, true, Global.iWindowWidth, Global.iWindowHeight, ( Global.bFullScreen ? monitor : nullptr ), true, false ); -1, true, Global.window_size.x, Global.window_size.y, ( Global.bFullScreen ? monitor : nullptr ), true, false );
if( mainwindow == nullptr ) { if( mainwindow == nullptr ) {
ErrorLog( "Bad init: failed to create glfw window" ); ErrorLog( "Bad init: failed to create glfw window" );
@@ -823,6 +808,16 @@ eu07_application::init_glfw() {
glfwMakeContextCurrent( mainwindow ); glfwMakeContextCurrent( mainwindow );
glfwSwapInterval( Global.VSync ? 1 : 0 ); //vsync glfwSwapInterval( Global.VSync ? 1 : 0 ); //vsync
{
int width, height;
glfwGetFramebufferSize( mainwindow, &width, &height );
framebuffer_resize_callback( mainwindow, width, height );
glfwGetWindowSize( mainwindow, &width, &height );
window_resize_callback( mainwindow, width, height );
}
#ifdef _WIN32 #ifdef _WIN32
// setup wrapper for base glfw window proc, to handle copydata messages // setup wrapper for base glfw window proc, to handle copydata messages
Hwnd = glfwGetWin32Window( mainwindow ); Hwnd = glfwGetWin32Window( mainwindow );
@@ -846,18 +841,14 @@ void
eu07_application::init_callbacks() { eu07_application::init_callbacks() {
auto *window { m_windows.front() }; auto *window { m_windows.front() };
glfwSetFramebufferSizeCallback( window, window_resize_callback ); glfwSetWindowSizeCallback( window, window_resize_callback );
glfwSetFramebufferSizeCallback( window, framebuffer_resize_callback );
glfwSetCursorPosCallback( window, cursor_pos_callback ); glfwSetCursorPosCallback( window, cursor_pos_callback );
glfwSetMouseButtonCallback( window, mouse_button_callback ); glfwSetMouseButtonCallback( window, mouse_button_callback );
glfwSetKeyCallback( window, key_callback ); glfwSetKeyCallback( window, key_callback );
glfwSetScrollCallback( window, scroll_callback ); glfwSetScrollCallback( window, scroll_callback );
glfwSetCharCallback(window, char_callback); glfwSetCharCallback(window, char_callback);
glfwSetWindowFocusCallback( window, focus_callback ); glfwSetWindowFocusCallback( window, focus_callback );
{
int width, height;
glfwGetFramebufferSize( window, &width, &height );
window_resize_callback( window, width, height );
}
} }
int int

View File

@@ -63,10 +63,6 @@ public:
set_cursor( int const Mode ); set_cursor( int const Mode );
void void
set_cursor_pos( double const Horizontal, double const Vertical ); set_cursor_pos( double const Horizontal, double const Vertical );
glm::dvec2
get_cursor_pos() const;
void
get_cursor_pos( double &Horizontal, double &Vertical ) const;
void queue_screenshot(); void queue_screenshot();
// input handlers // input handlers
void void

View File

@@ -1123,7 +1123,7 @@ driver_mode::set_picking( bool const Picking ) {
} }
else { else {
// switch off // switch off
Application.get_cursor_pos( m_input.mouse_pickmodepos.x, m_input.mouse_pickmodepos.y ); m_input.mouse_pickmodepos = glm::dvec2(Global.cursor_pos);
Application.set_cursor( GLFW_CURSOR_DISABLED ); Application.set_cursor( GLFW_CURSOR_DISABLED );
Application.set_cursor_pos( 0, 0 ); Application.set_cursor_pos( 0, 0 );
} }

View File

@@ -114,11 +114,11 @@ mouse_slider::bind( user_command const &Command ) {
} }
} }
// hide the cursor and place it in accordance with current slider value // hide the cursor and place it in accordance with current slider value
Application.get_cursor_pos( m_cursorposition.x, m_cursorposition.y ); m_cursorposition = glm::dvec2(Global.cursor_pos);
Application.set_cursor( GLFW_CURSOR_DISABLED ); Application.set_cursor( GLFW_CURSOR_DISABLED );
auto const controlsize { Global.iWindowHeight * EU07_CONTROLLER_MOUSESLIDERSIZE }; auto const controlsize { Global.window_size.y * EU07_CONTROLLER_MOUSESLIDERSIZE };
auto const controledge { Global.iWindowHeight * 0.5 + controlsize * 0.5 }; auto const controledge { Global.window_size.y * 0.5 + controlsize * 0.5 };
auto const stepsize { controlsize / m_valuerange }; auto const stepsize { controlsize / m_valuerange };
if( m_invertrange ) { if( m_invertrange ) {
@@ -126,7 +126,7 @@ mouse_slider::bind( user_command const &Command ) {
} }
Application.set_cursor_pos( Application.set_cursor_pos(
Global.iWindowWidth * 0.5, Global.window_size.y,
( m_analogue ? ( m_analogue ?
controledge - m_value * controlsize : controledge - m_value * controlsize :
controledge - m_value * stepsize - 0.5 * stepsize ) ); controledge - m_value * stepsize - 0.5 * stepsize ) );
@@ -143,8 +143,8 @@ mouse_slider::release() {
void void
mouse_slider::on_move( double const Mousex, double const Mousey ) { mouse_slider::on_move( double const Mousex, double const Mousey ) {
auto const controlsize { Global.iWindowHeight * EU07_CONTROLLER_MOUSESLIDERSIZE }; auto const controlsize { Global.window_size.y * EU07_CONTROLLER_MOUSESLIDERSIZE };
auto const controledge { Global.iWindowHeight * 0.5 + controlsize * 0.5 }; auto const controledge { Global.window_size.y * 0.5 + controlsize * 0.5 };
auto const stepsize { controlsize / m_valuerange }; auto const stepsize { controlsize / m_valuerange };
auto mousey = clamp( Mousey, controledge - controlsize, controledge ); auto mousey = clamp( Mousey, controledge - controlsize, controledge );
@@ -462,7 +462,7 @@ drivermouse_input::poll() {
auto updaterate { m_updaterate }; auto updaterate { m_updaterate };
if( m_varyingpollrate ) { if( m_varyingpollrate ) {
updaterate /= std::max( 0.15, 2.0 * glm::length( m_cursorposition - m_varyingpollrateorigin ) / std::max( 1, Global.iWindowHeight ) ); updaterate /= std::max( 0.15, 2.0 * glm::length( m_cursorposition - m_varyingpollrateorigin ) / std::max( 1, Global.window_size.y ) );
} }
while( m_updateaccumulator > updaterate ) { while( m_updateaccumulator > updaterate ) {

View File

@@ -42,15 +42,15 @@ driver_ui::driver_ui() {
m_scenariopanel.title = STR("Scenario"); m_scenariopanel.title = STR("Scenario");
m_scenariopanel.size_min = { 435, 85 }; m_scenariopanel.size_min = { 435, 85 };
m_scenariopanel.size_max = { Global.iWindowWidth * 0.95, Global.iWindowHeight * 0.95 }; m_scenariopanel.size_max = { Global.fb_size.x * 0.95f, Global.fb_size.y * 0.95 };
m_timetablepanel.title = STR("%-*.*s Time: %d:%02d:%02d"); m_timetablepanel.title = STR("%-*.*s Time: %d:%02d:%02d");
m_timetablepanel.size_min = { 435, 70}; m_timetablepanel.size_min = { 435, 70};
m_timetablepanel.size_max = { 435, Global.iWindowHeight * 0.95 }; m_timetablepanel.size_max = { 435, Global.fb_size.y * 0.95 };
m_transcriptspanel.title = STR("Transcripts"); m_transcriptspanel.title = STR("Transcripts");
m_transcriptspanel.size_min = { 435, 85 }; m_transcriptspanel.size_min = { 435, 85 };
m_transcriptspanel.size_max = { Global.iWindowWidth * 0.95, Global.iWindowHeight * 0.95 }; m_transcriptspanel.size_max = { Global.fb_size.x * 0.95, Global.fb_size.y * 0.95 };
if (Global.gui_defaultwindows) { if (Global.gui_defaultwindows) {
m_aidpanel.is_open = true; m_aidpanel.is_open = true;
@@ -205,7 +205,7 @@ driver_ui::set_cursor( bool const Visible ) {
if( Visible ) { if( Visible ) {
Application.set_cursor( GLFW_CURSOR_NORMAL ); Application.set_cursor( GLFW_CURSOR_NORMAL );
Application.set_cursor_pos( Global.iWindowWidth / 2, Global.iWindowHeight / 2 ); Application.set_cursor_pos( Global.window_size.x / 2, Global.window_size.y / 2 );
} }
else { else {
Application.set_cursor( GLFW_CURSOR_DISABLED ); Application.set_cursor( GLFW_CURSOR_DISABLED );

View File

@@ -730,7 +730,7 @@ void opengl33_renderer::Render_pass(viewport_config &vp, rendermode const Mode)
glm::ivec2 target_size(vp.width, vp.height); glm::ivec2 target_size(vp.width, vp.height);
if (vp.main && !vp.custom_backbuffer) // TODO: update window sizes also for extra viewports if (vp.main && !vp.custom_backbuffer) // TODO: update window sizes also for extra viewports
target_size = glm::ivec2(Global.iWindowWidth, Global.iWindowHeight); target_size = Global.fb_size;
if (!Global.gfx_skippipeline) if (!Global.gfx_skippipeline)
{ {
@@ -920,7 +920,7 @@ void opengl33_renderer::Render_pass(viewport_config &vp, rendermode const Mode)
if (vp.custom_backbuffer && vp.real_window) { if (vp.custom_backbuffer && vp.real_window) {
if (vp.main) if (vp.main)
target_size = glm::ivec2(Global.iWindowWidth, Global.iWindowHeight); target_size = Global.fb_size;
glViewport(0, 0, target_size.x, target_size.y); glViewport(0, 0, target_size.x, target_size.y);
vp.backbuffer_tex->bind(0); vp.backbuffer_tex->bind(0);
@@ -1407,7 +1407,7 @@ void opengl33_renderer::setup_pass(viewport_config &Viewport, renderpass_config
glm::ivec2 target_size(Viewport.width, Viewport.height); glm::ivec2 target_size(Viewport.width, Viewport.height);
if (Viewport.main) // TODO: update window sizes also for extra viewports if (Viewport.main) // TODO: update window sizes also for extra viewports
target_size = glm::ivec2(Global.iWindowWidth, Global.iWindowHeight); target_size = Global.fb_size;
Config.viewport_camera.position() = Global.pCamera.Pos; Config.viewport_camera.position() = Global.pCamera.Pos;
@@ -1420,7 +1420,7 @@ void opengl33_renderer::setup_pass(viewport_config &Viewport, renderpass_config
float const fovy = glm::radians(Global.FieldOfView / Global.ZoomFactor); float const fovy = glm::radians(Global.FieldOfView / Global.ZoomFactor);
// setup virtual screen // setup virtual screen
glm::vec2 screen_h = glm::vec2(Global.iWindowWidth, Global.iWindowHeight) / 2.0f; glm::vec2 screen_h = glm::vec2(Global.window_size) / 2.0f;
float const dist = screen_h.y / glm::tan(fovy / 2.0f); float const dist = screen_h.y / glm::tan(fovy / 2.0f);
Viewport.projection.pa = glm::vec3(-screen_h.x, -screen_h.y, -dist); Viewport.projection.pa = glm::vec3(-screen_h.x, -screen_h.y, -dist);
@@ -4219,11 +4219,11 @@ void opengl33_renderer::Update_Pick_Control()
if (!m_control_pick_requests.empty()) if (!m_control_pick_requests.empty())
{ {
glm::dvec2 mousepos = Application.get_cursor_pos(); glm::vec2 mousepos = Global.cursor_pos;
mousepos.y = Global.iWindowHeight - mousepos.y; // cursor coordinates are flipped compared to opengl mousepos.y = Global.window_size.y - mousepos.y; // cursor coordinates are flipped compared to opengl
glm::ivec2 pickbufferpos; glm::ivec2 pickbufferpos;
pickbufferpos = glm::ivec2{mousepos.x * EU07_PICKBUFFERSIZE / std::max(1, Global.iWindowWidth), mousepos.y * EU07_PICKBUFFERSIZE / std::max(1, Global.iWindowHeight)}; pickbufferpos = glm::ivec2(mousepos * glm::vec2(EU07_PICKBUFFERSIZE) / glm::vec2(Global.window_size));
if (vr) if (vr)
pickbufferpos = glm::ivec2(EU07_PICKBUFFERSIZE / 2 + 1, EU07_PICKBUFFERSIZE / 2 + 1); pickbufferpos = glm::ivec2(EU07_PICKBUFFERSIZE / 2 + 1, EU07_PICKBUFFERSIZE / 2 + 1);
@@ -4261,11 +4261,11 @@ void opengl33_renderer::Update_Pick_Node()
if (!m_node_pick_requests.empty()) if (!m_node_pick_requests.empty())
{ {
// determine point to examine // determine point to examine
glm::dvec2 mousepos = Application.get_cursor_pos(); glm::vec2 mousepos = Global.cursor_pos;
mousepos.y = Global.iWindowHeight - mousepos.y; // cursor coordinates are flipped compared to opengl mousepos.y = Global.window_size.y - mousepos.y; // cursor coordinates are flipped compared to opengl
glm::ivec2 pickbufferpos; glm::ivec2 pickbufferpos;
pickbufferpos = glm::ivec2{mousepos.x * EU07_PICKBUFFERSIZE / std::max(1, Global.iWindowWidth), mousepos.y * EU07_PICKBUFFERSIZE / std::max(1, Global.iWindowHeight)}; pickbufferpos = glm::ivec2(mousepos * glm::vec2(EU07_PICKBUFFERSIZE) / glm::vec2(Global.window_size));
pickbufferpos = glm::clamp(pickbufferpos, glm::ivec2(0, 0), glm::ivec2(EU07_PICKBUFFERSIZE - 1, EU07_PICKBUFFERSIZE - 1)); pickbufferpos = glm::clamp(pickbufferpos, glm::ivec2(0, 0), glm::ivec2(EU07_PICKBUFFERSIZE - 1, EU07_PICKBUFFERSIZE - 1));
Render_pass(*m_viewports.front().get(), rendermode::pickscenery); Render_pass(*m_viewports.front().get(), rendermode::pickscenery);
@@ -4295,11 +4295,11 @@ glm::dvec3 opengl33_renderer::Update_Mouse_Position()
if (!m_depth_pointer_pbo->is_busy()) if (!m_depth_pointer_pbo->is_busy())
{ {
// determine point to examine // determine point to examine
glm::dvec2 mousepos = Application.get_cursor_pos(); glm::vec2 mousepos = Global.cursor_pos;
mousepos.y = Global.iWindowHeight - mousepos.y; // cursor coordinates are flipped compared to opengl mousepos.y = Global.window_size.y - mousepos.y; // cursor coordinates are flipped compared to opengl
glm::ivec2 bufferpos; glm::ivec2 bufferpos;
bufferpos = glm::ivec2{mousepos.x * Global.gfx_framebuffer_width / std::max(1, Global.iWindowWidth), mousepos.y * Global.gfx_framebuffer_height / std::max(1, Global.iWindowHeight)}; bufferpos = glm::ivec2(mousepos * glm::vec2(Global.gfx_framebuffer_width, Global.gfx_framebuffer_height) / glm::vec2(Global.window_size));
bufferpos = glm::clamp(bufferpos, glm::ivec2(0, 0), glm::ivec2(Global.gfx_framebuffer_width - 1, Global.gfx_framebuffer_height - 1)); bufferpos = glm::clamp(bufferpos, glm::ivec2(0, 0), glm::ivec2(Global.gfx_framebuffer_width - 1, Global.gfx_framebuffer_height - 1));
float pointdepth = std::numeric_limits<float>::max(); float pointdepth = std::numeric_limits<float>::max();
@@ -4731,9 +4731,9 @@ bool opengl33_renderer::Init_caps()
} }
if (Global.gfx_framebuffer_width == -1) if (Global.gfx_framebuffer_width == -1)
Global.gfx_framebuffer_width = Global.iWindowWidth; Global.gfx_framebuffer_width = Global.fb_size.x;
if (Global.gfx_framebuffer_height == -1) if (Global.gfx_framebuffer_height == -1)
Global.gfx_framebuffer_height = Global.iWindowHeight; Global.gfx_framebuffer_height = Global.fb_size.y;
WriteLog("main window size: " + std::to_string(Global.gfx_framebuffer_width) + "x" + std::to_string(Global.gfx_framebuffer_height)); WriteLog("main window size: " + std::to_string(Global.gfx_framebuffer_width) + "x" + std::to_string(Global.gfx_framebuffer_height));

View File

@@ -463,7 +463,7 @@ opengl_renderer::Render_pass( rendermode const Mode ) {
} }
} }
::glViewport( 0, 0, Global.iWindowWidth, Global.iWindowHeight ); ::glViewport( 0, 0, Global.fb_size.x, Global.fb_size.y );
auto const skydomecolour = simulation::Environment.m_skydome.GetAverageColor(); auto const skydomecolour = simulation::Environment.m_skydome.GetAverageColor();
::glClearColor( skydomecolour.x, skydomecolour.y, skydomecolour.z, 0.f ); // kolor nieba ::glClearColor( skydomecolour.x, skydomecolour.y, skydomecolour.z, 0.f ); // kolor nieba
@@ -945,7 +945,7 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f
camera.projection() *= camera.projection() *=
glm::perspective( glm::perspective(
glm::radians( Global.FieldOfView / Global.ZoomFactor ), glm::radians( Global.FieldOfView / Global.ZoomFactor ),
std::max( 1.f, (float)Global.iWindowWidth ) / std::max( 1.f, (float)Global.iWindowHeight ), std::max( 1.f, (float)Global.window_size.x ) / std::max( 1.f, (float)Global.window_size.y ),
znear, znear,
zfar ); zfar );
/* /*
@@ -1083,7 +1083,7 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f
camera.projection() *= camera.projection() *=
glm::perspective( glm::perspective(
glm::radians( Global.FieldOfView / Global.ZoomFactor ), glm::radians( Global.FieldOfView / Global.ZoomFactor ),
std::max( 1.f, (float)Global.iWindowWidth ) / std::max( 1.f, (float)Global.iWindowHeight ), std::max( 1.f, (float)Global.window_size.x ) / std::max( 1.f, (float)Global.window_size.y ),
0.1f * Global.ZoomFactor, 0.1f * Global.ZoomFactor,
Config.draw_range * Global.fDistanceFactor ); Config.draw_range * Global.fDistanceFactor );
break; break;
@@ -2887,7 +2887,7 @@ opengl_renderer::Render( TSubModel *Submodel ) {
// we're capping how much effect the distance attenuation can have, otherwise the lights get too tiny at regular distances // we're capping how much effect the distance attenuation can have, otherwise the lights get too tiny at regular distances
float const distancefactor { std::max( 0.5f, ( Submodel->fSquareMaxDist - TSubModel::fSquareDist ) / Submodel->fSquareMaxDist ) }; float const distancefactor { std::max( 0.5f, ( Submodel->fSquareMaxDist - TSubModel::fSquareDist ) / Submodel->fSquareMaxDist ) };
auto const pointsize { std::max( 3.f, 5.f * distancefactor * anglefactor ) }; auto const pointsize { std::max( 3.f, 5.f * distancefactor * anglefactor ) };
auto const resolutionratio { Global.iWindowHeight / 1080.f };
// additionally reduce light strength for farther sources in rain or snow // additionally reduce light strength for farther sources in rain or snow
if( Global.Overcast > 0.75f ) { if( Global.Overcast > 0.75f ) {
float const precipitationfactor{ float const precipitationfactor{
@@ -2931,7 +2931,7 @@ opengl_renderer::Render( TSubModel *Submodel ) {
clamp( Global.fFogEnd / 2000, 0.f, 1.f ) ) clamp( Global.fFogEnd / 2000, 0.f, 1.f ) )
* std::max( 1.f, Global.Overcast ) }; * std::max( 1.f, Global.Overcast ) };
::glPointSize( pointsize * resolutionratio * fogfactor ); ::glPointSize( pointsize * fogfactor );
::glColor4f( ::glColor4f(
lightcolor[ 0 ], lightcolor[ 0 ],
lightcolor[ 1 ], lightcolor[ 1 ],
@@ -2941,7 +2941,7 @@ opengl_renderer::Render( TSubModel *Submodel ) {
m_geometry.draw( Submodel->m_geometry.handle ); m_geometry.draw( Submodel->m_geometry.handle );
::glDepthMask( GL_TRUE ); ::glDepthMask( GL_TRUE );
} }
::glPointSize( pointsize * resolutionratio ); ::glPointSize( pointsize );
::glColor4f( ::glColor4f(
lightcolor[ 0 ], lightcolor[ 0 ],
lightcolor[ 1 ], lightcolor[ 1 ],
@@ -3997,21 +3997,18 @@ opengl_renderer::Update_Pick_Control() {
#endif #endif
Render_pass( rendermode::pickcontrols ); Render_pass( rendermode::pickcontrols );
// determine point to examine // determine point to examine
glm::dvec2 mousepos; glm::vec2 mousepos = Global.cursor_pos;
glfwGetCursorPos( m_window, &mousepos.x, &mousepos.y ); mousepos.y = Global.window_size.y - mousepos.y; // cursor coordinates are flipped compared to opengl
mousepos.y = Global.iWindowHeight - mousepos.y; // cursor coordinates are flipped compared to opengl
#ifdef EU07_USE_PICKING_FRAMEBUFFER #ifdef EU07_USE_PICKING_FRAMEBUFFER
glm::ivec2 pickbufferpos; glm::ivec2 pickbufferpos;
if( true == m_framebuffersupport ) { if( true == m_framebuffersupport ) {
// ::glReadBuffer( GL_COLOR_ATTACHMENT0_EXT ); // ::glReadBuffer( GL_COLOR_ATTACHMENT0_EXT );
pickbufferpos = glm::ivec2{ pickbufferpos = mousepos * glm::vec2(EU07_PICKBUFFERSIZE) / glm::vec2(Global.window_size);
mousepos.x * EU07_PICKBUFFERSIZE / std::max( 1, Global.iWindowWidth ),
mousepos.y * EU07_PICKBUFFERSIZE / std::max( 1, Global.iWindowHeight ) };
} }
else { else {
// ::glReadBuffer( GL_BACK ); // ::glReadBuffer( GL_BACK );
pickbufferpos = glm::ivec2{ mousepos }; pickbufferpos = mousepos * glm::vec2(Global.fb_size) / glm::vec2(Global.window_size);
} }
#else #else
// ::glReadBuffer( GL_BACK ); // ::glReadBuffer( GL_BACK );
@@ -4048,22 +4045,18 @@ opengl_renderer::Update_Pick_Node() {
#endif #endif
Render_pass( rendermode::pickscenery ); Render_pass( rendermode::pickscenery );
// determine point to examine // determine point to examine
glm::dvec2 mousepos; glm::vec2 mousepos = Global.cursor_pos;
glfwGetCursorPos( m_window, &mousepos.x, &mousepos.y ); mousepos.y = Global.window_size.y - mousepos.y; // cursor coordinates are flipped compared to opengl
mousepos.y = Global.iWindowHeight - mousepos.y; // cursor coordinates are flipped compared to opengl
#ifdef EU07_USE_PICKING_FRAMEBUFFER #ifdef EU07_USE_PICKING_FRAMEBUFFER
glm::ivec2 pickbufferpos; glm::ivec2 pickbufferpos;
if( true == m_framebuffersupport ) { if( true == m_framebuffersupport ) {
// ::glReadBuffer( GL_COLOR_ATTACHMENT0_EXT ); // ::glReadBuffer( GL_COLOR_ATTACHMENT0_EXT );
pickbufferpos = glm::ivec2{ pickbufferpos = mousepos * glm::vec2(EU07_PICKBUFFERSIZE) / glm::vec2(Global.window_size);
mousepos.x * EU07_PICKBUFFERSIZE / Global.iWindowWidth,
mousepos.y * EU07_PICKBUFFERSIZE / Global.iWindowHeight
};
} }
else { else {
// ::glReadBuffer( GL_BACK ); // ::glReadBuffer( GL_BACK );
pickbufferpos = glm::ivec2{ mousepos }; pickbufferpos = mousepos * glm::vec2(Global.fb_size) / glm::vec2(Global.window_size);
} }
#else #else
// ::glReadBuffer( GL_BACK ); // ::glReadBuffer( GL_BACK );
@@ -4095,11 +4088,9 @@ opengl_renderer::Update_Pick_Node() {
glm::dvec3 glm::dvec3
opengl_renderer::Update_Mouse_Position() { opengl_renderer::Update_Mouse_Position() {
glm::dvec2 mousepos; glm::ivec2 mousepos = Global.cursor_pos * Global.fb_size / Global.window_size;
Application.get_cursor_pos( mousepos.x, mousepos.y ); mousepos.x = clamp<int>( mousepos.x, 0, Global.fb_size.x - 1 );
// glfwGetCursorPos( m_window, &mousepos.x, &mousepos.y ); mousepos.y = clamp<int>( Global.fb_size.y - mousepos.y, 0, Global.fb_size.y - 1 ) ;
mousepos.x = clamp<int>( mousepos.x, 0, Global.iWindowWidth - 1 );
mousepos.y = clamp<int>( Global.iWindowHeight - clamp<int>( mousepos.y, 0, Global.iWindowHeight ), 0, Global.iWindowHeight - 1 ) ;
GLfloat pointdepth; GLfloat pointdepth;
::glReadPixels( mousepos.x, mousepos.y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &pointdepth ); ::glReadPixels( mousepos.x, mousepos.y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &pointdepth );
@@ -4109,7 +4100,7 @@ opengl_renderer::Update_Mouse_Position() {
glm::vec3{ mousepos, pointdepth }, glm::vec3{ mousepos, pointdepth },
glm::mat4{ glm::mat3{ m_colorpass.camera.modelview() } }, glm::mat4{ glm::mat3{ m_colorpass.camera.modelview() } },
m_colorpass.camera.projection(), m_colorpass.camera.projection(),
glm::vec4{ 0, 0, Global.iWindowWidth, Global.iWindowHeight } ); glm::vec4{ 0, 0, Global.fb_size.x, Global.fb_size.y } );
} }
return m_colorpass.camera.position() + glm::dvec3{ m_worldmousecoordinates }; return m_colorpass.camera.position() + glm::dvec3{ m_worldmousecoordinates };
@@ -4363,8 +4354,9 @@ opengl_renderer::Init_caps() {
} }
#endif #endif
WriteLog( "Supported extensions: \n" char* extensions = (char*)glGetString( GL_EXTENSIONS );
+ std::string((char *)glGetString( GL_EXTENSIONS )) ); if (extensions)
WriteLog( "Supported extensions: \n" + std::string(extensions));
WriteLog( std::string("render path: ") + ( Global.bUseVBO ? "VBO" : "Display lists" ) ); WriteLog( std::string("render path: ") + ( Global.bUseVBO ? "VBO" : "Display lists" ) );
if( GL_EXT_framebuffer_object ) { if( GL_EXT_framebuffer_object ) {
@@ -4420,7 +4412,7 @@ opengl_renderer::Init_caps() {
WriteLog( "using multisampling x" + std::to_string( 1 << Global.iMultisampling ) ); WriteLog( "using multisampling x" + std::to_string( 1 << Global.iMultisampling ) );
} }
WriteLog( "main window size: " + std::to_string( Global.iWindowWidth ) + "x" + std::to_string( Global.iWindowHeight ) ); WriteLog( "main window size: " + std::to_string( Global.fb_size.x ) + "x" + std::to_string( Global.fb_size.y ) );
return true; return true;
} }

View File

@@ -5,10 +5,16 @@
#include "gl/vao.h" #include "gl/vao.h"
#include "Logs.h" #include "Logs.h"
void texture_window_resize(GLFWwindow *win, int w, int h)
{
python_screen_viewer *texwindow = (python_screen_viewer*)glfwGetWindowUserPointer(win);
texwindow->notify_window_size(win, w, h);
}
void texture_window_fb_resize(GLFWwindow *win, int w, int h) void texture_window_fb_resize(GLFWwindow *win, int w, int h)
{ {
python_screen_viewer *texwindow = (python_screen_viewer*)glfwGetWindowUserPointer(win); python_screen_viewer *texwindow = (python_screen_viewer*)glfwGetWindowUserPointer(win);
texwindow->notify_window_size(win, w, h); texwindow->notify_window_fb_size(win, w, h);
} }
void texture_window_mouse_button(GLFWwindow *win, int button, int action, int mods) void texture_window_mouse_button(GLFWwindow *win, int button, int action, int mods)
@@ -31,7 +37,7 @@ python_screen_viewer::python_screen_viewer(std::shared_ptr<python_rt> rt, std::s
for (const auto &viewport : Global.python_viewports) { for (const auto &viewport : Global.python_viewports) {
if (viewport.surface == surfacename) { if (viewport.surface == surfacename) {
auto conf = std::make_unique<window_state>(); auto conf = std::make_unique<window_state>();
conf->size = viewport.size; conf->window_size = viewport.size;
conf->offset = viewport.offset; conf->offset = viewport.offset;
conf->scale = viewport.scale; conf->scale = viewport.scale;
@@ -39,10 +45,17 @@ python_screen_viewer::python_screen_viewer(std::shared_ptr<python_rt> rt, std::s
if (!monitor && viewport.monitor != "window") if (!monitor && viewport.monitor != "window")
continue; continue;
conf->window = Application.window(-1, true, conf->size.x, conf->size.y, conf->window = Application.window(-1, true, conf->window_size.x, conf->window_size.y,
monitor, false, Global.python_sharectx); monitor, false, Global.python_sharectx);
{
int w, h;
glfwGetWindowSize(conf->window, &w, &h);
conf->window_size = glm::ivec2(w, h);
}
glfwSetWindowUserPointer(conf->window, this); glfwSetWindowUserPointer(conf->window, this);
glfwSetWindowSizeCallback(conf->window, texture_window_resize);
glfwSetFramebufferSizeCallback(conf->window, texture_window_fb_resize); glfwSetFramebufferSizeCallback(conf->window, texture_window_fb_resize);
glfwSetMouseButtonCallback(conf->window, texture_window_mouse_button); glfwSetMouseButtonCallback(conf->window, texture_window_mouse_button);
glfwSetCursorPosCallback(conf->window, texture_window_cursor_pos); glfwSetCursorPosCallback(conf->window, texture_window_cursor_pos);
@@ -155,7 +168,7 @@ void python_screen_viewer::threadfunc()
} }
} }
glViewport(0, 0, window->size.x, window->size.y); glViewport(0, 0, window->fb_size.x, window->fb_size.y);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
@@ -170,12 +183,23 @@ void python_screen_viewer::threadfunc()
} }
} }
void python_screen_viewer::notify_window_fb_size(GLFWwindow *window, int w, int h)
{
for (auto &conf : m_windows) {
if (conf->window == window) {
conf->fb_size.x = w;
conf->fb_size.y = h;
return;
}
}
}
void python_screen_viewer::notify_window_size(GLFWwindow *window, int w, int h) void python_screen_viewer::notify_window_size(GLFWwindow *window, int w, int h)
{ {
for (auto &conf : m_windows) { for (auto &conf : m_windows) {
if (conf->window == window) { if (conf->window == window) {
conf->size.x = w; conf->window_size.x = w;
conf->size.y = h; conf->window_size.y = h;
return; return;
} }
} }
@@ -199,7 +223,7 @@ void python_screen_viewer::notify_click(GLFWwindow *window, int button, int acti
for (auto &conf : m_windows) { for (auto &conf : m_windows) {
if (conf->window == window) { if (conf->window == window) {
auto pos = glm::vec2(conf->cursor_pos) / glm::vec2(conf->size); auto pos = glm::vec2(conf->cursor_pos) / glm::vec2(conf->window_size);
pos.y = 1.0f - pos.y; pos.y = 1.0f - pos.y;
pos = (pos + conf->offset) / conf->scale; pos = (pos + conf->offset) / conf->scale;

View File

@@ -7,7 +7,8 @@ class python_screen_viewer
struct window_state { struct window_state {
GLFWwindow *window = nullptr; GLFWwindow *window = nullptr;
glm::ivec2 size; glm::ivec2 window_size;
glm::ivec2 fb_size;
glm::ivec2 cursor_pos; glm::ivec2 cursor_pos;
glm::vec2 offset; glm::vec2 offset;
@@ -38,6 +39,7 @@ public:
~python_screen_viewer(); ~python_screen_viewer();
void notify_window_size(GLFWwindow *window, int w, int h); void notify_window_size(GLFWwindow *window, int w, int h);
void notify_window_fb_size(GLFWwindow *window, int w, int h);
void notify_cursor_pos(GLFWwindow *window, double x, double y); void notify_cursor_pos(GLFWwindow *window, double x, double y);
void notify_click(GLFWwindow *window, int button, int action); void notify_click(GLFWwindow *window, int button, int action);
}; };

View File

@@ -57,11 +57,11 @@ void screenshot_manager::screenshot_save_thread( char *img, int w, int h )
void screenshot_manager::make_screenshot() void screenshot_manager::make_screenshot()
{ {
char *img = new char[Global.iWindowWidth * Global.iWindowHeight * 4]; char *img = new char[Global.fb_size.x * Global.fb_size.y * 4];
glReadPixels(0, 0, Global.iWindowWidth, Global.iWindowHeight, Global.gfx_usegles ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)img); glReadPixels(0, 0, Global.fb_size.x, Global.fb_size.y, Global.gfx_usegles ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)img);
//m7t: use pbo //m7t: use pbo
std::thread t(screenshot_save_thread, img, Global.iWindowWidth, Global.iWindowHeight); std::thread t(screenshot_save_thread, img, Global.fb_size.x, Global.fb_size.y);
t.detach(); t.detach();
} }

View File

@@ -492,7 +492,7 @@ void ui_layer::render_menu_contents()
void ui_layer::render_menu() void ui_layer::render_menu()
{ {
glm::dvec2 mousepos = Application.get_cursor_pos(); glm::dvec2 mousepos = Global.cursor_pos;
if (!((Global.ControlPicking && mousepos.y < 50.0f) || m_imguiio->WantCaptureMouse) || m_progress != 0.0f) if (!((Global.ControlPicking && mousepos.y < 50.0f) || m_imguiio->WantCaptureMouse) || m_progress != 0.0f)
return; return;

View File

@@ -68,6 +68,11 @@ ui::map_panel::map_panel() : ui_panel(STR_C("Map"), false)
} }
} }
glGetError();
glLineWidth(2.0f);
if (!glGetError())
m_widelines_supported = true;
scene_ubo = std::make_unique<gl::ubo>(sizeof(gl::scene_ubs), 0); scene_ubo = std::make_unique<gl::ubo>(sizeof(gl::scene_ubs), 0);
init_done = true; init_done = true;
@@ -131,7 +136,8 @@ void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_si
} }
m_track_shader->bind(); m_track_shader->bind();
glLineWidth(1.5f); if (m_widelines_supported)
glLineWidth(1.5f);
glViewport(0, 0, surface_size.x, surface_size.y); glViewport(0, 0, surface_size.x, surface_size.y);
scene_ubs.projection = transform; scene_ubs.projection = transform;
@@ -144,22 +150,26 @@ void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_si
gl33->Draw_Geometry(m_section_handles.begin(), m_section_handles.end()); gl33->Draw_Geometry(m_section_handles.begin(), m_section_handles.end());
glLineWidth(1.5f); if (m_widelines_supported)
glLineWidth(4.5f);
scene_ubs.cascade_end = glm::vec3(0.7f, 0.7f, 0.0f); scene_ubs.cascade_end = glm::vec3(0.7f, 0.7f, 0.0f);
scene_ubo->update(scene_ubs); scene_ubo->update(scene_ubs);
gl33->Draw_Geometry(m_colored_paths.future.begin(), m_colored_paths.future.end()); gl33->Draw_Geometry(m_colored_paths.future.begin(), m_colored_paths.future.end());
glLineWidth(3.0f); if (m_widelines_supported)
glLineWidth(3.0f);
scene_ubs.cascade_end = glm::vec3(0.0f, 1.0f, 0.0f); scene_ubs.cascade_end = glm::vec3(0.0f, 1.0f, 0.0f);
scene_ubo->update(scene_ubs); scene_ubo->update(scene_ubs);
gl33->Draw_Geometry(m_colored_paths.switches.begin(), m_colored_paths.switches.end()); gl33->Draw_Geometry(m_colored_paths.switches.begin(), m_colored_paths.switches.end());
glLineWidth(1.5f); if (m_widelines_supported)
glLineWidth(1.5f);
scene_ubs.cascade_end = glm::vec3(1.0f, 0.0f, 0.0f); scene_ubs.cascade_end = glm::vec3(1.0f, 0.0f, 0.0f);
scene_ubo->update(scene_ubs); scene_ubo->update(scene_ubs);
gl33->Draw_Geometry(m_colored_paths.occupied.begin(), m_colored_paths.occupied.end()); gl33->Draw_Geometry(m_colored_paths.occupied.begin(), m_colored_paths.occupied.end());
glLineWidth(4.0f); if (m_widelines_supported)
glLineWidth(4.0f);
scene_ubs.cascade_end = glm::vec3(0.3f, 0.3f, 1.0f); scene_ubs.cascade_end = glm::vec3(0.3f, 0.3f, 1.0f);
scene_ubo->update(scene_ubs); scene_ubo->update(scene_ubs);
gl33->Draw_Geometry(m_colored_paths.highlighted.begin(), m_colored_paths.highlighted.end()); gl33->Draw_Geometry(m_colored_paths.highlighted.begin(), m_colored_paths.highlighted.end());

View File

@@ -115,6 +115,8 @@ class map_panel : public ui_panel
std::vector<gfx::geometrybank_handle> m_section_handles; std::vector<gfx::geometrybank_handle> m_section_handles;
map_colored_paths m_colored_paths; map_colored_paths m_colored_paths;
bool m_widelines_supported;
const int fb_size = 1024; const int fb_size = 1024;
glm::vec2 translate; glm::vec2 translate;