mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-21 19:29:19 +02:00
geometry shaders, map poi icons
This commit is contained in:
@@ -16,8 +16,11 @@ ui::map_panel::map_panel() : ui_panel(LOC_STR(ui_map), false)
|
||||
|
||||
gl::shader vert("map.vert");
|
||||
gl::shader frag("map.frag");
|
||||
gl::program *prog = new gl::program({vert, frag});
|
||||
m_shader = std::unique_ptr<gl::program>(prog);
|
||||
gl::shader poi_frag("map_poi.frag");
|
||||
gl::shader poi_geom("map_poi.geom");
|
||||
m_track_shader = std::unique_ptr<gl::program>(new gl::program({vert, frag}));
|
||||
m_poi_shader = std::unique_ptr<gl::program>(new gl::program({vert, poi_frag, poi_geom}));
|
||||
m_icon_atlas = GfxRenderer.Fetch_Texture("map_icons");
|
||||
|
||||
m_tex = std::make_unique<opengl_texture>();
|
||||
m_tex->alloc_rendertarget(GL_RGB8, GL_RGB, fb_size, fb_size);
|
||||
@@ -100,7 +103,7 @@ void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_si
|
||||
m_fb->bind();
|
||||
}
|
||||
|
||||
m_shader->bind();
|
||||
m_track_shader->bind();
|
||||
glLineWidth(1.5f);
|
||||
glViewport(0, 0, surface_size.x, surface_size.y);
|
||||
|
||||
@@ -117,7 +120,10 @@ void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_si
|
||||
scene_ubo->update(scene_ubs);
|
||||
GfxRenderer.Draw_Geometry(m_switch_handles.begin(), m_switch_handles.end());
|
||||
|
||||
glPointSize(5.0f);
|
||||
GfxRenderer.Bind_Texture(0, m_icon_atlas);
|
||||
m_poi_shader->bind();
|
||||
scene_ubs.scene_extra = glm::vec3(1.0f / (surface_size / 200.0f), 1.0f);
|
||||
|
||||
scene_ubs.time = 1.0f;
|
||||
scene_ubo->update(scene_ubs);
|
||||
GfxRenderer.Draw_Geometry(simulation::Region->get_map_poi_geometry());
|
||||
@@ -126,7 +132,7 @@ void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_si
|
||||
m_fb->blit_from(m_msaa_fb.get(), surface_size.x, surface_size.y, GL_COLOR_BUFFER_BIT, GL_COLOR_ATTACHMENT0);
|
||||
|
||||
gl::framebuffer::unbind();
|
||||
m_shader->unbind();
|
||||
gl::program::unbind();
|
||||
}
|
||||
|
||||
void ui::map_panel::render_labels(glm::mat4 transform, ImVec2 origin, glm::vec2 surface_size)
|
||||
@@ -285,9 +291,9 @@ void ui::handle_map_object_click(ui_panel &parent, std::shared_ptr<map::map_obje
|
||||
{
|
||||
parent.register_popup(std::make_unique<semaphore_window>(parent, std::move(sem)));
|
||||
}
|
||||
else if (auto track = std::dynamic_pointer_cast<map::track_switch>(obj))
|
||||
else if (auto track = std::dynamic_pointer_cast<map::launcher>(obj))
|
||||
{
|
||||
parent.register_popup(std::make_unique<switch_window>(parent, std::move(track)));
|
||||
parent.register_popup(std::make_unique<launcher_window>(parent, std::move(track)));
|
||||
}
|
||||
else if (auto obstacle = std::dynamic_pointer_cast<map::obstacle>(obj))
|
||||
{
|
||||
@@ -411,21 +417,29 @@ void ui::semaphore_window::render_content()
|
||||
}
|
||||
}
|
||||
|
||||
ui::switch_window::switch_window(ui_panel &panel, std::shared_ptr<map::track_switch> &&sw) : popup(panel), m_switch(sw) {}
|
||||
ui::launcher_window::launcher_window(ui_panel &panel, std::shared_ptr<map::launcher> &&sw) : popup(panel), m_switch(sw) {}
|
||||
|
||||
void ui::switch_window::render_content()
|
||||
void ui::launcher_window::render_content()
|
||||
{
|
||||
ImGui::TextUnformatted(m_switch->name.c_str());
|
||||
|
||||
if (ImGui::Button(LOC_STR(map_straight)))
|
||||
const std::string &open_label = locale::strings[
|
||||
m_switch->type == map::launcher::track_switch
|
||||
? locale::string::map_straight : locale::string::map_open];
|
||||
|
||||
const std::string &close_label = locale::strings[
|
||||
m_switch->type == map::launcher::track_switch
|
||||
? locale::string::map_divert : locale::string::map_close];
|
||||
|
||||
if (ImGui::Button(open_label.c_str()))
|
||||
{
|
||||
m_relay.post(user_command::queueevent, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &m_switch->straight_event->name());
|
||||
m_relay.post(user_command::queueevent, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &m_switch->first_event->name());
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
|
||||
if (ImGui::Button(LOC_STR(map_divert)))
|
||||
if (ImGui::Button(close_label.c_str()))
|
||||
{
|
||||
m_relay.post(user_command::queueevent, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &m_switch->divert_event->name());
|
||||
m_relay.post(user_command::queueevent, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &m_switch->second_event->name());
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
}
|
||||
@@ -473,12 +487,13 @@ void ui::obstacle_insert_window::render_content()
|
||||
obstacle->name = entry.first;
|
||||
obstacle->location = m_position;
|
||||
obstacle->model_name = name;
|
||||
map::Objects.entries.push_back(std::move(obstacle));
|
||||
|
||||
std::vector<gfx::basic_vertex> vertices;
|
||||
vertices.emplace_back((glm::vec3)m_position, glm::vec3(), glm::vec3());
|
||||
vertices.emplace_back(std::move(obstacle->vertex()));
|
||||
GfxRenderer.Append(vertices, simulation::Region->get_map_poi_geometry(), GL_POINTS);
|
||||
|
||||
map::Objects.entries.push_back(std::move(obstacle));
|
||||
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,13 +31,13 @@ class semaphore_window : public popup
|
||||
virtual void render_content() override;
|
||||
};
|
||||
|
||||
class switch_window : public popup
|
||||
class launcher_window : public popup
|
||||
{
|
||||
std::shared_ptr<map::track_switch> m_switch;
|
||||
std::shared_ptr<map::launcher> m_switch;
|
||||
command_relay m_relay;
|
||||
|
||||
public:
|
||||
switch_window(ui_panel &panel, std::shared_ptr<map::track_switch> &&sw);
|
||||
launcher_window(ui_panel &panel, std::shared_ptr<map::launcher> &&sw);
|
||||
|
||||
virtual void render_content() override;
|
||||
};
|
||||
@@ -67,9 +67,11 @@ class obstacle_remove_window : public popup
|
||||
|
||||
class map_panel : public ui_panel
|
||||
{
|
||||
std::unique_ptr<gl::program> m_shader;
|
||||
std::unique_ptr<gl::program> m_track_shader;
|
||||
std::unique_ptr<gl::program> m_poi_shader;
|
||||
std::unique_ptr<gl::framebuffer> m_msaa_fb;
|
||||
std::unique_ptr<gl::renderbuffer> m_msaa_rb;
|
||||
texture_handle m_icon_atlas;
|
||||
|
||||
std::unique_ptr<gl::framebuffer> m_fb;
|
||||
std::unique_ptr<opengl_texture> m_tex;
|
||||
|
||||
@@ -13,6 +13,9 @@ struct map_object
|
||||
glm::vec3 location;
|
||||
|
||||
virtual ~map_object() = default;
|
||||
virtual gfx::basic_vertex vertex() {
|
||||
return gfx::basic_vertex(location, glm::vec3(), glm::vec2(0.0f, 0.25f));
|
||||
}
|
||||
};
|
||||
|
||||
using object_list = std::vector<std::shared_ptr<map::map_object>>;
|
||||
@@ -22,21 +25,38 @@ using sorted_object_list = std::map<float, std::shared_ptr<map::map_object>>;
|
||||
struct semaphore : public map_object
|
||||
{
|
||||
std::vector<TAnimModel *> models;
|
||||
|
||||
std::vector<basic_event *> events;
|
||||
|
||||
virtual gfx::basic_vertex vertex() override {
|
||||
return gfx::basic_vertex(location, glm::vec3(), glm::vec2(0.0f, 0.25f));
|
||||
}
|
||||
};
|
||||
|
||||
// switch description (only for minimap purposes)
|
||||
struct track_switch : public map_object
|
||||
// event launcher description (only for minimap purposes)
|
||||
struct launcher : public map_object
|
||||
{
|
||||
basic_event *straight_event = nullptr;
|
||||
basic_event *divert_event = nullptr;
|
||||
basic_event *first_event = nullptr;
|
||||
basic_event *second_event = nullptr;
|
||||
|
||||
enum type_e {
|
||||
track_switch,
|
||||
level_crossing
|
||||
} type;
|
||||
|
||||
virtual gfx::basic_vertex vertex() {
|
||||
return gfx::basic_vertex(location, glm::vec3(),
|
||||
type == track_switch ? glm::vec2(0.25f, 0.5f) : glm::vec2(0.5f, 0.75f));
|
||||
}
|
||||
};
|
||||
|
||||
// training obstacle description
|
||||
struct obstacle : public map_object
|
||||
{
|
||||
std::string model_name;
|
||||
|
||||
virtual gfx::basic_vertex vertex() {
|
||||
return gfx::basic_vertex(location, glm::vec3(), glm::vec2(0.75f, 1.0f));
|
||||
}
|
||||
};
|
||||
|
||||
struct objects
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "Train.h"
|
||||
|
||||
ui::vehicleparams_panel::vehicleparams_panel(const std::string &vehicle)
|
||||
: ui_panel(std::string(LOC_STR(vehicleparams_window)) + ": " + vehicle, false), m_vehicle_name(vehicle)
|
||||
: ui_panel(std::string(locale::strings[locale::string::vehicleparams_window]) + ": " + vehicle, false), m_vehicle_name(vehicle)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user