18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 15:17:08 +01:00
Files
maszyna/rendering/nullrenderer.h
T
lcddisplay 328149b721 Merge MaSzyna-EU07/maszyna master into feat/vat-people
master as of 9fecba82: the test mode (--test, null renderer), the AI braking
and passenger stops, the ESt3 brake, the SOD lamp, the 401Da oil pump lamp,
smoke of vehicles taken off the tracks, text displays with national
characters, the scenario picker drag and drop, the log written to the end of
the closing, unit and scenario tests, and the small fixes.

How the conflicts went:
- the OpenGL 3.3 and legacy renderers stay removed; what master changed in
  them is carried over where this branch has a counterpart: the opaque
  characters of text displays in scene_walk::Render_text(). The instancing
  range of master is covered by the instance records of this branch, the
  sizes of the sun and the moon are its own.
- test mode: the null backend picked in select_gfx_backend(), the window
  hidden, no crash gui; settings of the removed renderers left out.
- materials: the matte and tinted copies of this branch (the tint in the
  slot of the weathering), made again on a change of the season or the
  weather (update_variants), before the track blends.
- tracks: this branch's Segment, Track and TrackUneven, with master's
  replaced_shake(), uneven_underway(), rail_joints_moved(),
  switch_followers() and the editor's add_followers(); tributary and unknown
  track types stay as this branch loads them.
- the log service stops by StopLogService(), the exit paths of EU07.cpp too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GXgG7F4L42c2F9sDSAJbT2
2026-11-08 21:17:00 +01:00

177 lines
8.4 KiB
C++

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#pragma once
#include "model/Texture.h"
#include "rendering/geometrybank.h"
#include "model/material.h"
#include "rendering/renderer.h"
#include "stdafx.h"
#include <glm/fwd.hpp>
#include <stdexcept>
class null_geometrybank : public gfx::geometry_bank {
public:
// constructors:
null_geometrybank() = default;
// destructor
~null_geometrybank() = default;
private:
// methods:
// create() subclass details
void
create_( gfx::geometry_handle const &Geometry ) override { /* null implementation, nothing to do */ }
// replace() subclass details
void
replace_( gfx::geometry_handle const &Geometry ) override { /* null implementation, nothing to do */ }
// draw() subclass details
auto
draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) -> std::size_t override { return 0; }
// release() subclass details
void
release_() override { /* null implementation, nothing to do */ }
};
// user interface backend which draws nothing: imgui still builds its frames, so the ui code runs as usual
class null_imgui_renderer final : public imgui_renderer {
public:
bool Init() override { return true; }
void Shutdown() override { /* null implementation, nothing to do */ }
// imgui wants its font atlas built before a frame starts; that's done on the cpu, no texture is made of it
void BeginFrame() override;
void Render() override { /* null implementation, nothing to do */ }
};
// bare-bones render controller, in lack of anything better yet
// it's the renderer of the test mode (--test): models are loaded for the physics, textures aren't
class null_renderer : public gfx_renderer {
public:
// types
// constructors
null_renderer() = default;
// destructor
~null_renderer() = default;
// methods
bool
Init( GLFWwindow *Window ) override { return true; }
// main draw call. returns false on error
bool
Render() override;
void
SwapBuffers() override { /* null implementation, nothing to do */ }
inline
float
Framerate() override { return 10.0f; }
bool AddViewport(const global_settings::extraviewport_config &conf) override { return false; }
bool Debug_Ui_State(std::optional<bool>) override { return false; }
void Shutdown() override { /* null implementation, nothing to do */ }
// geometry methods
// NOTE: hands-on geometry management is exposed as a temporary measure; ultimately all visualization data should be generated/handled automatically by the renderer itself
// creates a new geometry bank. returns: handle to the bank or NULL
gfx::geometrybank_handle
Create_Bank() override { return m_geometry.register_bank(std::make_unique<null_geometrybank>()); }
// creates a new indexed geometry chunk of specified type from supplied data, in specified bank. returns: handle to the chunk or NULL
gfx::geometry_handle Insert(gfx::index_array &Indices, gfx::vertex_array &Vertices, gfx::userdata_array &Userdata, gfx::geometrybank_handle const &Geometry, int const Type) override {
return m_geometry.create_chunk( Indices, Vertices, Userdata, Geometry, Type ); }
// creates a new geometry chunk of specified type from supplied data, in specified bank. returns: handle to the chunk or NULL
gfx::geometry_handle Insert(gfx::vertex_array &Vertices, gfx::userdata_array &Userdata, gfx::geometrybank_handle const &Geometry, int const Type) override {
gfx::calculate_tangents(Vertices, gfx::index_array(), Type);
return m_geometry.create_chunk(Vertices, Userdata, Geometry, Type);
}
// replaces data of specified chunk with the supplied vertex data, starting from specified offset
bool Replace(gfx::vertex_array &Vertices, gfx::userdata_array &Userdata, gfx::geometry_handle const &Geometry, int const Type, const std::size_t Offset = 0) override {
gfx::calculate_tangents(Vertices, gfx::index_array(), Type);
return m_geometry.replace(Vertices, Userdata, Geometry, Offset);
}
// adds supplied vertex data at the end of specified chunk
bool Append(gfx::vertex_array &Vertices, gfx::userdata_array &Userdata, gfx::geometry_handle const &Geometry, int const Type) override {
gfx::calculate_tangents(Vertices, gfx::index_array(), Type);
return m_geometry.append(Vertices, Userdata, Geometry);
}
// provides direct access to index data of specfied chunk
gfx::index_array const &
Indices( gfx::geometry_handle const &Geometry ) const override { return m_geometry.indices(Geometry); }
// provides direct access to vertex data of specfied chunk
gfx::vertex_array const &
Vertices( gfx::geometry_handle const &Geometry ) const override { return m_geometry.vertices(Geometry); }
// provides direct access to vertex data of specfied chunk
gfx::userdata_array const &
UserData( gfx::geometry_handle const &Geometry ) const override { return m_geometry.userdata(Geometry); }
// material methods
material_handle
Fetch_Material( std::string const &Filename, bool const Loadnow = true ) override {
m_materials.push_back(std::make_shared<opengl_material>());
m_materials.back()->name = Filename;
return static_cast<material_handle>(m_materials.size());
}
void
Bind_Material( material_handle const Material, TSubModel const *sm = nullptr, lighting_data const *lighting = nullptr ) override { /* null implementation, nothing to do */ }
IMaterial const *
Material( material_handle const Material ) const override {
return ( Material > 0 && static_cast<std::size_t>( Material ) <= m_materials.size() ? m_materials[ Material - 1 ].get() : IMaterial::null_material() ); }
// shader methods
auto Fetch_Shader( std::string const &name ) -> std::shared_ptr<gfx::shader_program> override { throw std::runtime_error("not impl"); }
// texture methods
// no textures are loaded; whoever asks gets the null texture
texture_handle
Fetch_Texture( std::string const &Filename, bool const Loadnow = true, GLint format_hint = GL_SRGB_ALPHA ) override { return null_handle; }
void
Bind_Texture( texture_handle const Texture ) override { /* null implementation, nothing to do */ }
void
Bind_Texture( std::size_t const Unit, texture_handle const Texture ) override { /* null implementation, nothing to do */ }
ITexture &
Texture( texture_handle const Texture ) override { return *ITexture::null_texture(); }
ITexture const &
Texture( texture_handle const Texture ) const override { return *ITexture::null_texture(); }
// utility methods
void
Pick_Control_Callback( std::function<void( TSubModel const *, const glm::vec2 )> Callback ) override { /* null implementation, nothing to do */ }
void
Pick_Node_Callback( std::function<void( scene::basic_node * )> Callback ) override { /* null implementation, nothing to do */ }
TSubModel const *
Pick_Control() const override { return nullptr; }
scene::basic_node const *
Pick_Node() const override { return nullptr; }
glm::dvec3
Mouse_Position() const override { return glm::dvec3(); }
// maintenance methods
void
Update( double const Deltatime ) override { /* null implementation, nothing to do */ }
void
Update_Pick_Control() override { /* null implementation, nothing to do */ }
void
Update_Pick_Node() override { /* null implementation, nothing to do */ }
glm::dvec3
Update_Mouse_Position() override { return glm::dvec3(); }
// debug methods
std::string const &
info_times() const override { return empty_str; }
std::string const &
info_stats() const override { return empty_str; }
void MakeScreenshot() override { /* null implementation, nothing to do */ }
static std::unique_ptr<gfx_renderer> create_func();
static bool renderer_register;
imgui_renderer *GetImguiRenderer() override
{
return &m_imgui;
}
private:
std::string empty_str;
null_imgui_renderer m_imgui;
gfx::geometrybank_manager m_geometry;
std::vector<std::shared_ptr<opengl_material>> m_materials;
};