18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-19 06:26:01 +01:00

Merge branch 'master' into feat/renderers-cleanup

This commit is contained in:
2026-11-10 17:09:09 +01:00
140 changed files with 13065 additions and 622 deletions

View File

@@ -1,9 +1,58 @@
#include "stdafx.h"
#include "rendering/nullrenderer.h"
#include "application/application.h"
#include "utilities/Logs.h"
namespace
{
// the null renderer draws nothing, but parts of the ui make textures with gl calls of their own. the window has no hints,
// so any context will do for them: a machine without a graphics driver (a test runner) has only the basic one of the system
bool null_after_window(GLFWwindow *Window)
{
glfwMakeContextCurrent(Window);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
ErrorLog("Bad init: failed to initialize glad");
return false;
}
return true;
}
gfx_backend_desc null_backend_desc()
{
gfx_backend_desc desc;
desc.name = "null";
desc.create = &null_renderer::create_func;
desc.after_window = &null_after_window;
desc.gl_context = true;
return desc;
}
} // namespace
void null_imgui_renderer::BeginFrame()
{
auto &io { ImGui::GetIO() };
if( false == io.Fonts->IsBuilt() ) {
unsigned char *pixels { nullptr };
int width { 0 };
int height { 0 };
io.Fonts->GetTexDataAsAlpha8( &pixels, &width, &height );
}
}
bool null_renderer::Render()
{
// the ui frame begun by the application has to be ended, or imgui won't start the next one
Application.render_ui();
return true;
}
std::unique_ptr<gfx_renderer> null_renderer::create_func()
{
return std::make_unique<null_renderer>();
}
bool null_renderer::renderer_register = gfx_renderer_factory::get_instance()->register_backend("null", null_renderer::create_func);
bool null_renderer::renderer_register = gfx_renderer_factory::get_instance()->register_backend("null", null_backend_desc());

View File

@@ -35,7 +35,18 @@ private:
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:
@@ -49,7 +60,7 @@ public:
Init( GLFWwindow *Window ) override { return true; }
// main draw call. returns false on error
bool
Render() override { return true; }
Render() override;
void
SwapBuffers() override { /* null implementation, nothing to do */ }
inline
@@ -105,20 +116,22 @@ public:
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 m_materials.at(Material - 1).get(); }
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 { throw std::runtime_error("not impl"); }
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 */ }
opengl_texture &
Texture( texture_handle const Texture ) override { throw std::runtime_error("not impl"); }
opengl_texture const &
Texture( texture_handle const Texture ) const override { throw std::runtime_error("not impl"); }
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 */ }
@@ -152,11 +165,12 @@ public:
imgui_renderer *GetImguiRenderer() override
{
return nullptr;
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;
};

View File

@@ -24,6 +24,11 @@ namespace gfx
class shader_program;
}
namespace script_screens
{
class post_processor;
}
namespace gfx
{
// material painted over the heightmap terrain, and the size (metres) its textures are repeated at; 0: the size given by the material, or 8 m
@@ -193,6 +198,9 @@ public:
// seen in perspective from the front, side and above and filling the image less Margin pixels at each edge.
// Image receives rgb rows, top row first. returns false if the backend can't make previews or there's nothing to draw
virtual auto Render_Preview( TAnimModel *Instance, int const Size, int const Margin, bool const Shadows, std::vector<std::uint8_t> &Image ) -> bool { return false; }
// runs the post-processing of the script screens (image:led_post, image:resize) on the gpu. nullptr when the backend
// can't; the screens then do it on the cpu
virtual auto Screen_post_processor() -> script_screens::post_processor * { return nullptr; }
};
// what the application has to know about a backend before its renderer exists: whether it can run here at all, and how its