mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 00:49:19 +02:00
map
This commit is contained in:
@@ -84,6 +84,7 @@ set(SOURCES
|
||||
"simulationtime.cpp"
|
||||
"sceneeditor.cpp"
|
||||
"screenshot.cpp"
|
||||
"map.cpp"
|
||||
|
||||
"gl/shader.cpp"
|
||||
"gl/vao.cpp"
|
||||
|
||||
@@ -679,6 +679,11 @@ global_settings::ConfigParse(cParser &Parser) {
|
||||
Parser.getTokens(1);
|
||||
Parser >> gfx_postfx_motionblur_shutter;
|
||||
}
|
||||
else if (token == "map.enabled")
|
||||
{
|
||||
Parser.getTokens(1);
|
||||
Parser >> map_enabled;
|
||||
}
|
||||
} while ((token != "") && (token != "endconfig")); //(!Parser->EndOfFile)
|
||||
// na koniec trochę zależności
|
||||
if (!bLoadTraction) // wczytywanie drutów i słupów
|
||||
|
||||
@@ -108,7 +108,6 @@ struct global_settings {
|
||||
float BaseDrawRange{ 2500.f };
|
||||
int DynamicLightCount{ 8 };
|
||||
bool ScaleSpecularValues{ true };
|
||||
bool gfx_shadowmap_enabled{ true };
|
||||
struct shadowtune_t {
|
||||
unsigned int map_size{ 2048 };
|
||||
float width{ 250.f }; // no longer used
|
||||
@@ -176,10 +175,13 @@ struct global_settings {
|
||||
bool dds_upper_origin = false;
|
||||
bool captureonstart = true;
|
||||
|
||||
bool gfx_shadowmap_enabled = true;
|
||||
bool gfx_envmap_enabled = true;
|
||||
bool gfx_postfx_motionblur_enabled = true;
|
||||
float gfx_postfx_motionblur_shutter = 0.01f;
|
||||
|
||||
bool map_enabled = true;
|
||||
|
||||
// methods
|
||||
void LoadIniFile( std::string asFileName );
|
||||
void ConfigParse( cParser &parser );
|
||||
|
||||
@@ -1126,6 +1126,15 @@ void TTrack::RaAssign( TAnimModel *am, TEvent *done, TEvent *joined )
|
||||
}
|
||||
};
|
||||
|
||||
void TTrack::create_map_geometry(std::vector<gfx::basic_vertex> &Bank)
|
||||
{
|
||||
if (iCategoryFlag != 1)
|
||||
return; // only tracks for now
|
||||
|
||||
for (auto &v : endpoints())
|
||||
Bank.push_back(gfx::basic_vertex(glm::vec3(v), glm::vec3(0.0f), glm::vec2(0.0f)));
|
||||
}
|
||||
|
||||
// wypełnianie tablic VBO
|
||||
void TTrack::create_geometry( gfx::geometrybank_handle const &Bank ) {
|
||||
// Ra: trzeba rozdzielić szyny od podsypki, aby móc grupować wg tekstur
|
||||
|
||||
1
Track.h
1
Track.h
@@ -251,6 +251,7 @@ public:
|
||||
endpoints() const;
|
||||
|
||||
void create_geometry( gfx::geometrybank_handle const &Bank ); // wypełnianie VBO
|
||||
void create_map_geometry(std::vector<gfx::basic_vertex> &Bank);
|
||||
void RenderDynSounds(); // odtwarzanie dźwięków pojazdów jest niezależne od ich wyświetlania
|
||||
|
||||
void RaOwnerSet( scene::basic_cell *o ) {
|
||||
|
||||
1
World.h
1
World.h
@@ -76,6 +76,7 @@ TWorld();
|
||||
void compute_season( int const Yearday ) const;
|
||||
// calculates current weather
|
||||
void compute_weather() const;
|
||||
TCamera& get_camera() { return Camera; }
|
||||
|
||||
// members
|
||||
|
||||
|
||||
10
gl/ubo.cpp
10
gl/ubo.cpp
@@ -1,11 +1,17 @@
|
||||
#include "stdafx.h"
|
||||
#include "ubo.h"
|
||||
|
||||
gl::ubo::ubo(int size, int index)
|
||||
gl::ubo::ubo(int size, int idx, GLenum hint)
|
||||
{
|
||||
glGenBuffers(1, *this);
|
||||
bind();
|
||||
glBufferData(GL_UNIFORM_BUFFER, size, nullptr, GL_STREAM_DRAW);
|
||||
glBufferData(GL_UNIFORM_BUFFER, size, nullptr, hint);
|
||||
index = idx;
|
||||
bind_uniform();
|
||||
}
|
||||
|
||||
void gl::ubo::bind_uniform()
|
||||
{
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, index, *this);
|
||||
}
|
||||
|
||||
|
||||
5
gl/ubo.h
5
gl/ubo.h
@@ -11,10 +11,13 @@ namespace gl
|
||||
|
||||
class ubo : public object, public bindable<ubo>
|
||||
{
|
||||
int index;
|
||||
|
||||
public:
|
||||
ubo(int size, int index);
|
||||
ubo(int size, int index, GLenum hint = GL_DYNAMIC_DRAW);
|
||||
~ubo();
|
||||
|
||||
void bind_uniform();
|
||||
using bindable::bind;
|
||||
static void bind(GLuint i);
|
||||
|
||||
|
||||
177
map.cpp
Normal file
177
map.cpp
Normal file
@@ -0,0 +1,177 @@
|
||||
#include "stdafx.h"
|
||||
#include "map.h"
|
||||
#include "imgui/imgui.h"
|
||||
#include "Logs.h"
|
||||
#include "World.h"
|
||||
#include "Train.h"
|
||||
#include "Camera.h"
|
||||
|
||||
void map::init()
|
||||
{
|
||||
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);
|
||||
|
||||
m_tex = std::make_unique<opengl_texture>();
|
||||
m_tex->alloc_rendertarget(GL_RGB4, GL_RGB, GL_FLOAT, fb_size, fb_size);
|
||||
|
||||
m_fb = std::make_unique<gl::framebuffer>();
|
||||
m_fb->attach(*m_tex, GL_COLOR_ATTACHMENT0);
|
||||
|
||||
m_fb->setup_drawing(1);
|
||||
|
||||
if (!m_fb->is_complete())
|
||||
throw std::runtime_error("map framebuffer incomplete");
|
||||
|
||||
if (Global.iMultisampling)
|
||||
{
|
||||
m_msaa_rb = std::make_unique<gl::renderbuffer>();
|
||||
m_msaa_rb->alloc(GL_RGB4, fb_size, fb_size, 1 << Global.iMultisampling);
|
||||
|
||||
m_msaa_fb = std::make_unique<gl::framebuffer>();
|
||||
m_msaa_fb->attach(*m_msaa_rb, GL_COLOR_ATTACHMENT0);
|
||||
|
||||
m_msaa_fb->setup_drawing(1);
|
||||
|
||||
if (!m_msaa_fb->is_complete())
|
||||
throw std::runtime_error("map multisampling framebuffer incomplete");
|
||||
}
|
||||
|
||||
scene_ubo = std::make_unique<gl::ubo>(sizeof(gl::scene_ubs), 0);
|
||||
}
|
||||
|
||||
float map::get_vehicle_rotation()
|
||||
{
|
||||
const TDynamicObject *vehicle = World.train()->Dynamic();
|
||||
glm::vec3 front = glm::dvec3(vehicle->VectorFront()) * (vehicle->DirectionGet() > 0 ? 1.0 : -1.0);
|
||||
glm::vec2 f2(front.x, front.z);
|
||||
glm::vec2 north_ptr(0.0f, 1.0f);
|
||||
return glm::atan(f2.y, f2.x) - glm::atan(north_ptr.y, north_ptr.x);
|
||||
}
|
||||
|
||||
void map::render(scene::basic_region *Region)
|
||||
{
|
||||
if (!map_opened)
|
||||
return;
|
||||
|
||||
if (!m_shader)
|
||||
init();
|
||||
|
||||
ImGui::SetNextWindowSizeConstraints(ImVec2(200, 200), ImVec2(fb_size, fb_size));
|
||||
if (ImGui::Begin("Map", &map_opened, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse))
|
||||
{
|
||||
float prevzoom = zoom;
|
||||
|
||||
if (ImGui::Button("-"))
|
||||
zoom /= 2;
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("+"))
|
||||
zoom *= 2;
|
||||
ImGui::SameLine();
|
||||
|
||||
float x = zoom / prevzoom;
|
||||
translate *= x;
|
||||
|
||||
glm::mat4 transform;
|
||||
transform[0][0] = -1.0f;
|
||||
|
||||
static int mode = 0;
|
||||
ImGui::RadioButton("manual", &mode, 0); ImGui::SameLine();
|
||||
ImGui::RadioButton("cam", &mode, 1); ImGui::SameLine();
|
||||
ImGui::RadioButton("vehicle", &mode, 2);
|
||||
|
||||
if (mode == 2 && World.train() && World.train()->Dynamic())
|
||||
{
|
||||
float rot = get_vehicle_rotation();
|
||||
|
||||
transform = glm::rotate(transform, rot, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
|
||||
glm::dvec3 vpos = World.train()->Dynamic()->GetPosition();
|
||||
translate = glm::vec2(vpos.x, vpos.z) * -zoom;
|
||||
}
|
||||
else if (mode == 1)
|
||||
{
|
||||
float rot;
|
||||
if (FreeFlyModeFlag)
|
||||
rot = glm::pi<float>() - World.get_camera().Yaw;
|
||||
else
|
||||
rot = get_vehicle_rotation() - World.get_camera().Yaw;
|
||||
|
||||
transform = glm::rotate(transform, rot, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
|
||||
glm::dvec3 vpos = World.get_camera().Pos;
|
||||
translate = glm::vec2(vpos.x, vpos.z) * -zoom;
|
||||
}
|
||||
|
||||
ImVec2 size = ImGui::GetContentRegionAvail();
|
||||
|
||||
transform = glm::translate(transform, glm::vec3(translate.x, 0.0f, translate.y));
|
||||
transform = glm::scale(transform, glm::vec3(zoom));
|
||||
|
||||
frustum.calculate(transform, glm::mat4());
|
||||
|
||||
m_section_handles.clear();
|
||||
|
||||
for (int row = 0; row < scene::EU07_REGIONSIDESECTIONCOUNT; row++)
|
||||
{
|
||||
for (int column = 0; column < scene::EU07_REGIONSIDESECTIONCOUNT; column++)
|
||||
{
|
||||
scene::basic_section *s = Region->get_section(row * scene::EU07_REGIONSIDESECTIONCOUNT + column);
|
||||
if (s && frustum.sphere_inside(s->area().center, s->area().radius) > 0.f)
|
||||
{
|
||||
const gfx::geometrybank_handle handle = s->get_map_geometry();
|
||||
if (handle != null_handle)
|
||||
m_section_handles.push_back(handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scene_ubs.projection = transform;
|
||||
scene_ubo->update(scene_ubs);
|
||||
scene_ubo->bind_uniform();
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
if (Global.iMultisampling)
|
||||
{
|
||||
m_msaa_fb->clear(GL_COLOR_BUFFER_BIT);
|
||||
m_msaa_fb->bind();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_fb->clear(GL_COLOR_BUFFER_BIT);
|
||||
m_fb->bind();
|
||||
}
|
||||
|
||||
m_shader->bind();
|
||||
glLineWidth(1.5f);
|
||||
glViewport(0, 0, size.x, size.y);
|
||||
|
||||
GfxRenderer.Draw_Geometry(m_section_handles.begin(), m_section_handles.end());
|
||||
|
||||
if (Global.iMultisampling)
|
||||
m_fb->blit_from(*m_msaa_fb, size.x, size.y, GL_COLOR_BUFFER_BIT, GL_COLOR_ATTACHMENT0);
|
||||
|
||||
m_fb->unbind();
|
||||
|
||||
ImGui::ImageButton(reinterpret_cast<void*>(m_tex->id), size, ImVec2(0, size.y / fb_size), ImVec2(size.x / fb_size, 0), 0);
|
||||
|
||||
if (mode == 0 && ImGui::IsItemHovered() && ImGui::IsMouseDragging())
|
||||
{
|
||||
ImVec2 ivdelta = ImGui::GetMouseDragDelta();
|
||||
ImGui::ResetMouseDragDelta();
|
||||
|
||||
glm::vec2 delta(ivdelta.x, ivdelta.y);
|
||||
delta.x /= size.x;
|
||||
delta.y /= size.y;
|
||||
|
||||
translate -= delta * 2.0f;
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void map::toggle_window()
|
||||
{
|
||||
map_opened = !map_opened;
|
||||
}
|
||||
34
map.h
Normal file
34
map.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "gl/shader.h"
|
||||
#include "renderer.h"
|
||||
#include "Texture.h"
|
||||
|
||||
class map
|
||||
{
|
||||
std::unique_ptr<gl::program> m_shader;
|
||||
std::unique_ptr<gl::framebuffer> m_msaa_fb;
|
||||
std::unique_ptr<gl::renderbuffer> m_msaa_rb;
|
||||
|
||||
std::unique_ptr<gl::framebuffer> m_fb;
|
||||
std::unique_ptr<opengl_texture> m_tex;
|
||||
|
||||
std::unique_ptr<gl::ubo> scene_ubo;
|
||||
gl::scene_ubs scene_ubs;
|
||||
|
||||
std::vector<gfx::geometrybank_handle> m_section_handles;
|
||||
|
||||
const int fb_size = 1024;
|
||||
|
||||
glm::vec2 translate;
|
||||
float zoom = 1.0f / 1000.0f;
|
||||
float get_vehicle_rotation();
|
||||
|
||||
void init();
|
||||
|
||||
cFrustum frustum;
|
||||
public:
|
||||
bool map_opened = false;
|
||||
void render(scene::basic_region *Region);
|
||||
void toggle_window();
|
||||
};
|
||||
@@ -241,10 +241,8 @@ opengl_vbogeometrybank::replace_( gfx::geometry_handle const &Geometry ) {
|
||||
}
|
||||
}
|
||||
|
||||
// draw() subclass details
|
||||
void
|
||||
opengl_vbogeometrybank::draw_( gfx::geometry_handle const &Geometry) {
|
||||
|
||||
void opengl_vbogeometrybank::setup_buffer()
|
||||
{
|
||||
if( m_buffer == 0 ) {
|
||||
// if there's no buffer, we'll have to make one
|
||||
// NOTE: this isn't exactly optimal in terms of ensuring the gfx card doesn't stall waiting for the data
|
||||
@@ -300,6 +298,13 @@ opengl_vbogeometrybank::draw_( gfx::geometry_handle const &Geometry) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
m_vao->unbind();
|
||||
}
|
||||
}
|
||||
|
||||
// draw() subclass details
|
||||
void
|
||||
opengl_vbogeometrybank::draw_( gfx::geometry_handle const &Geometry)
|
||||
{
|
||||
setup_buffer();
|
||||
|
||||
// actual draw procedure starts here
|
||||
auto &chunkrecord = m_chunkrecords.at(Geometry.chunk - 1);
|
||||
@@ -321,6 +326,60 @@ opengl_vbogeometrybank::draw_( gfx::geometry_handle const &Geometry) {
|
||||
::glDrawArrays( chunk.type, chunkrecord.offset, chunkrecord.size );
|
||||
}
|
||||
|
||||
void opengl_vbogeometrybank::draw_(const std::vector<gfx::geometry_handle>::iterator begin, const std::vector<gfx::geometry_handle>::iterator end)
|
||||
{
|
||||
if (begin == end)
|
||||
return;
|
||||
|
||||
setup_buffer();
|
||||
|
||||
m_offsets.clear();
|
||||
m_counts.clear();
|
||||
GLenum type = 0;
|
||||
bool coalesce = false;
|
||||
|
||||
for (auto it = begin; it != end; it++)
|
||||
{
|
||||
gfx::geometry_handle Geometry = *it;
|
||||
auto &chunkrecord = m_chunkrecords.at(Geometry.chunk - 1);
|
||||
auto const &chunk = gfx::geometry_bank::chunk( Geometry );
|
||||
if( false == chunkrecord.is_good ) {
|
||||
glBindBuffer( GL_ARRAY_BUFFER, m_buffer );
|
||||
// we may potentially need to upload new buffer data before we can draw it
|
||||
::glBufferSubData(
|
||||
GL_ARRAY_BUFFER,
|
||||
chunkrecord.offset * sizeof( gfx::basic_vertex ),
|
||||
chunkrecord.size * sizeof( gfx::basic_vertex ),
|
||||
chunk.vertices.data() );
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
chunkrecord.is_good = true;
|
||||
}
|
||||
|
||||
if (!type)
|
||||
{
|
||||
type = chunk.type;
|
||||
if (type == GL_POINTS || type == GL_LINES || type == GL_TRIANGLES)
|
||||
coalesce = true;
|
||||
}
|
||||
else if (type != chunk.type)
|
||||
throw std::logic_error("inconsistent draw types");
|
||||
|
||||
if (coalesce && m_offsets.size() && chunkrecord.offset == m_offsets.back() + m_counts.back())
|
||||
m_counts.back() += chunkrecord.size;
|
||||
else
|
||||
{
|
||||
m_offsets.push_back(chunkrecord.offset);
|
||||
m_counts.push_back(chunkrecord.size);
|
||||
}
|
||||
}
|
||||
|
||||
m_vao->bind();
|
||||
if (m_offsets.size() == 1)
|
||||
glDrawArrays(type, m_offsets.front(), m_counts.front());
|
||||
else
|
||||
glMultiDrawArrays(type, m_offsets.data(), m_counts.data(), m_offsets.size());
|
||||
}
|
||||
|
||||
// release () subclass details
|
||||
void
|
||||
opengl_vbogeometrybank::release_() {
|
||||
@@ -394,6 +453,29 @@ geometrybank_manager::draw( gfx::geometry_handle const &Geometry ) {
|
||||
bankrecord.first->draw( Geometry );
|
||||
}
|
||||
|
||||
void geometrybank_manager::draw(const std::vector<gfx::geometry_handle>::iterator begin, const std::vector<gfx::geometry_handle>::iterator end)
|
||||
{
|
||||
if (begin == end)
|
||||
return;
|
||||
|
||||
auto &run_bank = bank(*begin);
|
||||
std::vector<gfx::geometry_handle>::iterator run_begin = begin;
|
||||
|
||||
std::vector<gfx::geometry_handle>::iterator it;
|
||||
for (it = begin; it != end; it++)
|
||||
{
|
||||
if (bank(*it) != run_bank)
|
||||
{
|
||||
run_bank.first->draw(run_begin, it);
|
||||
run_bank = bank(*it);
|
||||
run_begin = it;
|
||||
}
|
||||
}
|
||||
|
||||
if (run_begin != it)
|
||||
run_bank.first->draw(run_begin, it);
|
||||
}
|
||||
|
||||
// provides direct access to vertex data of specfied chunk
|
||||
gfx::vertex_array const &
|
||||
geometrybank_manager::vertices( gfx::geometry_handle const &Geometry ) const {
|
||||
|
||||
@@ -94,9 +94,10 @@ public:
|
||||
void
|
||||
draw( gfx::geometry_handle const &Geometry );
|
||||
// draws geometry stored in supplied list of chunks
|
||||
template <typename Iterator_>
|
||||
void
|
||||
draw( Iterator_ First, Iterator_ Last ) { while( First != Last ) { draw( *First ); ++First; } }
|
||||
void draw(std::vector<gfx::geometry_handle>::iterator begin, std::vector<gfx::geometry_handle>::iterator end)
|
||||
{
|
||||
draw_(begin, end);
|
||||
}
|
||||
// frees subclass-specific resources associated with the bank, typically called when the bank wasn't in use for a period of time
|
||||
void
|
||||
release();
|
||||
@@ -139,6 +140,7 @@ private:
|
||||
virtual void replace_( gfx::geometry_handle const &Geometry ) = 0;
|
||||
// draw() subclass details
|
||||
virtual void draw_( gfx::geometry_handle const &Geometry ) = 0;
|
||||
virtual void draw_(const std::vector<gfx::geometry_handle>::iterator begin, const std::vector<gfx::geometry_handle>::iterator end) = 0;
|
||||
// resource release subclass details
|
||||
virtual void release_() = 0;
|
||||
};
|
||||
@@ -167,6 +169,12 @@ private:
|
||||
};
|
||||
|
||||
typedef std::vector<chunk_record> chunkrecord_sequence;
|
||||
void setup_buffer();
|
||||
|
||||
// vectors for glMultiDrawArrays in class scope
|
||||
// to don't waste time on reallocating
|
||||
std::vector<GLint> m_offsets;
|
||||
std::vector<GLsizei> m_counts;
|
||||
|
||||
// methods:
|
||||
// create() subclass details
|
||||
@@ -178,6 +186,7 @@ private:
|
||||
// draw() subclass details
|
||||
void
|
||||
draw_( gfx::geometry_handle const &Geometry );
|
||||
void draw_(const std::vector<gfx::geometry_handle>::iterator begin, const std::vector<gfx::geometry_handle>::iterator end);
|
||||
// release() subclass details
|
||||
void
|
||||
release_();
|
||||
@@ -217,12 +226,7 @@ public:
|
||||
// draws geometry stored in specified chunk
|
||||
void
|
||||
draw( gfx::geometry_handle const &Geometry);
|
||||
template <typename Iterator_>
|
||||
void
|
||||
draw( Iterator_ First, Iterator_ Last ) {
|
||||
while( First != Last ) {
|
||||
draw( *First );
|
||||
++First; } }
|
||||
void draw(const std::vector<gfx::geometry_handle>::iterator begin, const std::vector<gfx::geometry_handle>::iterator end);
|
||||
// provides direct access to vertex data of specfied chunk
|
||||
gfx::vertex_array const &
|
||||
vertices( gfx::geometry_handle const &Geometry ) const;
|
||||
|
||||
25
renderer.cpp
25
renderer.cpp
@@ -158,9 +158,9 @@ bool opengl_renderer::Init(GLFWwindow *Window)
|
||||
return false;
|
||||
}
|
||||
|
||||
scene_ubo = std::make_unique<gl::ubo>(sizeof(gl::scene_ubs), 0);
|
||||
model_ubo = std::make_unique<gl::ubo>(sizeof(gl::model_ubs), 1);
|
||||
light_ubo = std::make_unique<gl::ubo>(sizeof(gl::light_ubs), 2);
|
||||
scene_ubo = std::make_unique<gl::ubo>(sizeof(gl::scene_ubs), 0);
|
||||
model_ubo = std::make_unique<gl::ubo>(sizeof(gl::model_ubs), 1, GL_STREAM_DRAW);
|
||||
light_ubo = std::make_unique<gl::ubo>(sizeof(gl::light_ubs), 2);
|
||||
|
||||
// better initialize with 0 to not crash driver/whole system
|
||||
// when we forget
|
||||
@@ -384,6 +384,7 @@ void opengl_renderer::Render_pass(rendermode const Mode)
|
||||
scene_ubs.time = Timer::GetTime();
|
||||
scene_ubs.projection = OpenGLMatrices.data(GL_PROJECTION);
|
||||
scene_ubo->update(scene_ubs);
|
||||
scene_ubo->bind_uniform();
|
||||
|
||||
m_colorpass = m_renderpass;
|
||||
|
||||
@@ -493,6 +494,8 @@ void opengl_renderer::Render_pass(rendermode const Mode)
|
||||
setup_shadow_map(nullptr, m_renderpass);
|
||||
setup_env_map(nullptr);
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
if (Global.gfx_postfx_motionblur_enabled)
|
||||
{
|
||||
m_main_fb->clear(GL_COLOR_BUFFER_BIT);
|
||||
@@ -509,9 +512,8 @@ void opengl_renderer::Render_pass(rendermode const Mode)
|
||||
m_msaa_fb->blit_to(*m_main2_fb.get(), Global.render_width, Global.render_height, GL_COLOR_BUFFER_BIT, GL_COLOR_ATTACHMENT0);
|
||||
}
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
glEnable(GL_FRAMEBUFFER_SRGB);
|
||||
glViewport(0, 0, Global.iWindowWidth, Global.iWindowHeight);
|
||||
glViewport(0, 0, Global.iWindowWidth, Global.iWindowHeight);
|
||||
m_pfx_tonemapping->apply(*m_main2_tex, nullptr);
|
||||
opengl_texture::reset_unit_cache();
|
||||
glDisable(GL_FRAMEBUFFER_SRGB);
|
||||
@@ -1484,7 +1486,7 @@ void opengl_renderer::Render(section_sequence::iterator First, section_sequence:
|
||||
if (false == section->m_shapes.empty())
|
||||
{
|
||||
// since all shapes of the section share center point we can optimize out a few calls here
|
||||
::glPushMatrix();
|
||||
::glPushMatrix();
|
||||
auto const originoffset{section->m_area.center - m_renderpass.camera.position()};
|
||||
::glTranslated(originoffset.x, originoffset.y, originoffset.z);
|
||||
// render
|
||||
@@ -1681,6 +1683,11 @@ void opengl_renderer::Render(cell_sequence::iterator First, cell_sequence::itera
|
||||
}
|
||||
}
|
||||
|
||||
void opengl_renderer::Draw_Geometry(std::vector<gfx::geometrybank_handle>::iterator begin, std::vector<gfx::geometrybank_handle>::iterator end)
|
||||
{
|
||||
m_geometry.draw(begin, end);
|
||||
}
|
||||
|
||||
void opengl_renderer::draw(const gfx::geometry_handle &handle)
|
||||
{
|
||||
model_ubs.set_modelview(OpenGLMatrices.data(GL_MODELVIEW));
|
||||
@@ -1694,11 +1701,7 @@ void opengl_renderer::draw(std::vector<gfx::geometrybank_handle>::iterator it, s
|
||||
model_ubs.set_modelview(OpenGLMatrices.data(GL_MODELVIEW));
|
||||
model_ubo->update(model_ubs);
|
||||
|
||||
while (it != end)
|
||||
{
|
||||
m_geometry.draw(*it);
|
||||
it++;
|
||||
}
|
||||
Draw_Geometry(it, end);
|
||||
}
|
||||
|
||||
void opengl_renderer::Render(scene::shape_node const &Shape, bool const Ignorerange)
|
||||
|
||||
@@ -146,6 +146,8 @@ class opengl_renderer
|
||||
bool Replace(gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry, int const Type, std::size_t const Offset = 0);
|
||||
// adds supplied vertex data at the end of specified chunk
|
||||
bool Append(gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry, int const Type);
|
||||
// draws supplied geometry handles
|
||||
void Draw_Geometry(std::vector<gfx::geometrybank_handle>::iterator begin, std::vector<gfx::geometrybank_handle>::iterator end);
|
||||
// provides direct access to vertex data of specfied chunk
|
||||
gfx::vertex_array const &Vertices(gfx::geometry_handle const &Geometry) const;
|
||||
// material methods
|
||||
|
||||
31
scene.cpp
31
scene.cpp
@@ -599,6 +599,15 @@ basic_cell::create_geometry( gfx::geometrybank_handle const &Bank ) {
|
||||
m_geometrycreated = true; // helper for legacy animation code, get rid of it after refactoring
|
||||
}
|
||||
|
||||
void basic_cell::create_map_geometry(std::vector<gfx::basic_vertex> &Bank)
|
||||
{
|
||||
if (!m_active)
|
||||
return;
|
||||
|
||||
for (auto *path : m_paths)
|
||||
path->create_map_geometry(Bank);
|
||||
}
|
||||
|
||||
// executes event assigned to specified launcher
|
||||
void
|
||||
basic_cell::launch_event( TEventLauncher *Launcher ) {
|
||||
@@ -902,6 +911,15 @@ basic_section::create_geometry() {
|
||||
}
|
||||
}
|
||||
|
||||
void basic_section::create_map_geometry(const gfx::geometrybank_handle handle)
|
||||
{
|
||||
std::vector<gfx::basic_vertex> lines;
|
||||
for (auto &cell : m_cells)
|
||||
cell.create_map_geometry(lines);
|
||||
|
||||
m_map_geometryhandle = GfxRenderer.Insert(lines, handle, GL_LINES);
|
||||
}
|
||||
|
||||
// provides access to section enclosing specified point
|
||||
basic_cell &
|
||||
basic_section::cell( glm::dvec3 const &Location ) {
|
||||
@@ -1557,6 +1575,19 @@ basic_region::section( glm::dvec3 const &Location ) {
|
||||
return *section;
|
||||
}
|
||||
|
||||
void basic_region::create_map_geometry()
|
||||
{
|
||||
m_map_geometrybank = GfxRenderer.Create_Bank();
|
||||
|
||||
for (int row = 0; row < EU07_REGIONSIDESECTIONCOUNT; row++)
|
||||
for (int column = 0; column < EU07_REGIONSIDESECTIONCOUNT; column++)
|
||||
{
|
||||
basic_section *s = m_sections[row * EU07_REGIONSIDESECTIONCOUNT + column];
|
||||
if (s)
|
||||
s->create_map_geometry(m_map_geometrybank);
|
||||
}
|
||||
}
|
||||
|
||||
} // scene
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
16
scene.h
16
scene.h
@@ -151,6 +151,7 @@ public:
|
||||
// generates renderable version of held non-instanced geometry in specified geometry bank
|
||||
void
|
||||
create_geometry( gfx::geometrybank_handle const &Bank );
|
||||
void create_map_geometry(std::vector<gfx::basic_vertex> &Bank);
|
||||
// provides access to bounding area data
|
||||
bounding_area const &
|
||||
area() const {
|
||||
@@ -274,10 +275,15 @@ public:
|
||||
// generates renderable version of held non-instanced geometry
|
||||
void
|
||||
create_geometry();
|
||||
void create_map_geometry(const gfx::geometrybank_handle handle);
|
||||
// provides access to bounding area data
|
||||
bounding_area const &
|
||||
area() const {
|
||||
return m_area; }
|
||||
const gfx::geometrybank_handle get_map_geometry()
|
||||
{
|
||||
return m_map_geometryhandle;
|
||||
}
|
||||
|
||||
private:
|
||||
// types
|
||||
@@ -289,6 +295,7 @@ private:
|
||||
cell( glm::dvec3 const &Location );
|
||||
// members
|
||||
// placement and visibility
|
||||
|
||||
scene::bounding_area m_area { glm::dvec3(), static_cast<float>( 0.5 * M_SQRT2 * EU07_SECTIONSIZE ) };
|
||||
// content
|
||||
cell_array m_cells; // partitioning scheme
|
||||
@@ -297,6 +304,8 @@ private:
|
||||
// gfx renderer data
|
||||
gfx::geometrybank_handle m_geometrybank;
|
||||
bool m_geometrycreated { false };
|
||||
|
||||
gfx::geometrybank_handle m_map_geometryhandle;
|
||||
};
|
||||
|
||||
// top-level of scene spatial structure, holds collection of sections
|
||||
@@ -383,6 +392,11 @@ public:
|
||||
// finds sections inside specified sphere. returns: list of sections
|
||||
std::vector<basic_section *> const &
|
||||
sections( glm::dvec3 const &Point, float const Radius );
|
||||
void create_map_geometry();
|
||||
basic_section* get_section(size_t section)
|
||||
{
|
||||
return m_sections[section];
|
||||
}
|
||||
|
||||
private:
|
||||
// types
|
||||
@@ -393,6 +407,8 @@ private:
|
||||
std::vector<basic_section *> sections;
|
||||
};
|
||||
|
||||
gfx::geometrybank_handle m_map_geometrybank;
|
||||
|
||||
// methods
|
||||
// checks whether specified point is within boundaries of the region
|
||||
bool
|
||||
|
||||
8
shaders/map.frag
Normal file
8
shaders/map.frag
Normal file
@@ -0,0 +1,8 @@
|
||||
#version 330
|
||||
|
||||
#include <common>
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragData[0] = vec4(1.0f);
|
||||
}
|
||||
12
shaders/map.vert
Normal file
12
shaders/map.vert
Normal file
@@ -0,0 +1,12 @@
|
||||
#version 330
|
||||
|
||||
layout(location = 0) in vec3 v_vert;
|
||||
|
||||
#include <common>
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 clip_pos = projection * vec4(v_vert, 1.0f);
|
||||
|
||||
gl_Position = vec4(clip_pos.xz, 0.5, 1.0);
|
||||
}
|
||||
@@ -74,7 +74,7 @@ void main()
|
||||
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
|
||||
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
|
||||
|
||||
gl_FragData[1] = vec4(a - b, 0.0f, tex_color.a < 0.9f ? 0.0f : 1.0f);
|
||||
gl_FragData[1] = vec4(a - b, 0.0f, tex_color.a);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -163,6 +163,9 @@ state_serializer::deserialize( cParser &Input, scene::scratch_data &Scratchpad )
|
||||
// manually perform scenario initialization
|
||||
deserialize_firstinit( Input, Scratchpad );
|
||||
}
|
||||
|
||||
if (Global.map_enabled)
|
||||
Region->create_map_geometry();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
1159
uilayer.cpp
1159
uilayer.cpp
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <string>
|
||||
#include "Texture.h"
|
||||
#include "map.h"
|
||||
|
||||
// GuiLayer -- basic user interface class. draws requested information on top of openGL screen
|
||||
|
||||
@@ -75,6 +76,8 @@ private:
|
||||
|
||||
ImGuiIO *imgui_io;
|
||||
|
||||
std::unique_ptr<map> m_map;
|
||||
|
||||
// progress bar config. TODO: put these together into an object
|
||||
float m_progress { 0.0f }; // percentage of filled progres bar, to indicate lengthy operations.
|
||||
float m_subtaskprogress{ 0.0f }; // percentage of filled progres bar, to indicate lengthy operations.
|
||||
|
||||
Reference in New Issue
Block a user