diff --git a/gl/buffer.h b/gl/buffer.h index c8ff232e..ee5d91e5 100644 --- a/gl/buffer.h +++ b/gl/buffer.h @@ -18,7 +18,7 @@ namespace gl COPY_WRITE_BUFFER, DISPATCH_INDIRECT_BUFFER, DRAW_INDIRECT_BUFFER, - ELEMENT_ARRAY_BUFFER, + ELEMENT_ARRAY_BUFFER, // ELEMENT_ARRAY_BUFFER is part of VAO and therefore shouldn't be managed by global tracker! PIXEL_PACK_BUFFER, PIXEL_UNPACK_BUFFER, SHADER_STORAGE_BUFFER, diff --git a/gl/vao.cpp b/gl/vao.cpp index fd582ae3..019a2e93 100644 --- a/gl/vao.cpp +++ b/gl/vao.cpp @@ -38,6 +38,8 @@ void gl::vao::setup_ebo(buffer &e) { if (use_vao) { bind(); + // ELEMENT_ARRAY_BUFFER is part of VAO and therefore shouldn't be managed by gl::buffer global tracker! + // but it is needed by it for buffer data management, so eh e.bind(buffer::ELEMENT_ARRAY_BUFFER); } else { diff --git a/opengl33renderer.cpp b/opengl33renderer.cpp index ad0481ef..5e72e9a5 100644 --- a/opengl33renderer.cpp +++ b/opengl33renderer.cpp @@ -199,6 +199,9 @@ bool opengl33_renderer::Init(GLFWwindow *Window) if (!init_viewport(default_viewport)) return false; glfwMakeContextCurrent(m_window); + + // after potential context switch, reset vao and buffer because we can have invalid bindings cache + gl::vao::unbind(); gl::buffer::unbind(); if (Global.gfx_shadowmap_enabled) @@ -351,6 +354,9 @@ bool opengl33_renderer::AddViewport(const global_settings::extraviewport_config bool ret = init_viewport(*vp); glfwMakeContextCurrent(m_window); + + // after potential context switch, reset vao and buffer because we can have invalid bindings cache + gl::vao::unbind(); gl::buffer::unbind(); return ret; @@ -518,7 +524,11 @@ bool opengl33_renderer::Render() } glfwMakeContextCurrent(m_window); + + // after potential context switch, reset vao and buffer because we can have invalid bindings cache + gl::vao::unbind(); gl::buffer::unbind(); + m_current_viewport = &(*m_viewports.front()); /* m_debugtimestext += "cpu: " + to_string(Timer::subsystem.gfx_color.average(), 2) + " ms (" + std::to_string(m_cellqueue.size()) + " sectors)\n" += @@ -635,7 +645,11 @@ void opengl33_renderer::Render_pass(viewport_config &vp, rendermode const Mode) glDebug("context switch"); glfwMakeContextCurrent(vp.window); + + // after potential context switch, reset vao and buffer because we can have invalid bindings cache + gl::vao::unbind(); gl::buffer::unbind(); + m_current_viewport = &vp; if ((!simulation::is_ready) || (Global.gfx_skiprendering)) @@ -4095,9 +4109,6 @@ bool opengl33_renderer::Debug_Ui_State(std::optional param) // utility methods void opengl33_renderer::Update_Pick_Control() { - // context-switch workaround - gl::buffer::unbind(); - if (!m_picking_pbo->is_busy()) { unsigned char pickreadout[4]; @@ -4284,6 +4295,11 @@ glm::dvec3 opengl33_renderer::Update_Mouse_Position() void opengl33_renderer::Update(double const Deltatime) { + // workaround: we might be after context switch + // reset vao and buffer because we can have invalid bindings cache + gl::vao::unbind(); + gl::buffer::unbind(); + Update_Pick_Control(); Update_Pick_Node(); diff --git a/widgets/map.cpp b/widgets/map.cpp index d1beb80d..cf0e2072 100644 --- a/widgets/map.cpp +++ b/widgets/map.cpp @@ -640,11 +640,6 @@ ui::vehicle_click_window::vehicle_click_window(ui_panel &panel, std::shared_ptr< void ui::vehicle_click_window::render_content() { - if (!m_vehicle->dynobj->MoverParameters->Battery) { - std::string name_enable = m_vehicle->name + "%Prepare_engine"; - m_relay.post(user_command::sendaicommand, 1.0, 1.0, GLFW_PRESS, 0, glm::vec3(), &name_enable); - } - ImGui::TextUnformatted(STR_C("Light signal:")); if (ImGui::Button(STR_C("none"))) {