17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-03 10:50:22 +01:00

feat(vulkan): vulkan 1.4 core with the user interface and the launcher, shaders split into ogl46/vk14 with SPIR-V binaries loaded first

This commit is contained in:
2026-10-24 05:47:11 +02:00
parent 68fa5dc2da
commit bd589f272d
235 changed files with 9397 additions and 3975 deletions

View File

@@ -95,19 +95,19 @@ bool opengl46_grass::init()
return false;
}
m_vao = std::make_unique<gl::vao>();
auto const location = [&](char const *Name) { return ::glGetUniformLocation(*m_program, Name); };
m_uniforms.tile = location("grass_tile");
m_uniforms.part = location("grass_part");
m_uniforms.chunk = location("grass_chunk");
m_uniforms.camera = location("grass_camera");
m_uniforms.lod = location("grass_lod");
m_uniforms.wind = location("grass_wind");
m_uniforms.base = location("grass_base");
m_uniforms.tip = location("grass_tip");
m_uniforms.shape = location("grass_shape");
m_uniforms.share = location("grass_share");
m_uniforms.dry = location("grass_dry");
m_uniforms.season = location("grass_season");
// the locations grass.vert gives its uniforms (a program loaded from SPIR-V doesn't know their names)
m_uniforms.tile = 0;
m_uniforms.part = 1;
m_uniforms.chunk = 2;
m_uniforms.camera = 3;
m_uniforms.lod = 4;
m_uniforms.wind = 5;
m_uniforms.base = 6;
m_uniforms.tip = 10;
m_uniforms.shape = 14;
m_uniforms.share = 18;
m_uniforms.dry = 19;
m_uniforms.season = 23;
m_state = 1;
return true;
}

View File

@@ -200,8 +200,8 @@ bool opengl46_renderer::Init(GLFWwindow *Window)
return false;
}
scene_ubo = std::make_unique<gl::ubo>(sizeof(gl::scene_ubs), 0);
model_ubo = std::make_unique<gl::stream_ubo>(sizeof(gl::model_ubs), 1, Global.gfx_bufferstreaming);
scene_ubo = std::make_unique<gl::ubo>(sizeof(gl::scene_ubs), gl::SCENE_UBO_BINDING);
model_ubo = std::make_unique<gl::stream_ubo>(sizeof(gl::model_ubs), gl::MODEL_UBO_BINDING, Global.gfx_bufferstreaming);
light_ssbo = std::make_unique<gl::ssbo>(sizeof(gl::light_data), gl::LIGHT_SSBO_BINDING);
light_ssbo->bind_base();
{
@@ -673,6 +673,8 @@ std::unique_ptr<gl::program> opengl46_renderer::make_shader(std::string v, std::
bool opengl46_renderer::Render()
{
// the texture names bound before may have been given to other textures since the last frame
opengl_texture::reset_unit_cache();
Timer::subsystem.gfx_total.start();
std::optional<int64_t> result = m_timequery->result();
@@ -3270,7 +3272,7 @@ bool opengl46_renderer::Blendable_Material(material_handle const Material)
return m_materials.blendable(Material);
}
std::string opengl46_renderer::Shader_Name(std::shared_ptr<gl::program> const &Program) const
std::string opengl46_renderer::Shader_Name(std::shared_ptr<gfx::shader_program> const &Program) const
{
for (auto const &shader : m_shaders)
if (shader.second == Program)
@@ -3278,7 +3280,7 @@ std::string opengl46_renderer::Shader_Name(std::shared_ptr<gl::program> const &P
return {};
}
std::shared_ptr<gl::program> opengl46_renderer::Fetch_Shader(const std::string &name)
std::shared_ptr<gfx::shader_program> opengl46_renderer::Fetch_Shader(const std::string &name)
{
auto it = m_shaders.find(name);
if (it == m_shaders.end())
@@ -3472,7 +3474,7 @@ void opengl46_renderer::Bind_Material( material_handle const Material, TSubModel
if (lastdiff)
glBindTextures(0, lastdiff, &opengl_texture::units[0]);
auto *program{material.shader.get()};
auto *program{static_cast<gl::program *>(material.shader.get())};
if (m_bindmultidraw)
{
// the replay of the instances drawn from the gpu culling with multi draws (Render_Instances_Indirect_Colour())
@@ -4887,7 +4889,7 @@ int opengl46_renderer::Prepass_Class( material_handle const Material )
if( Material == null_handle ) { return 0; }
auto const &material { m_materials.material( Material ) };
if( ( false == material.is_good ) || ( material.shader == nullptr ) ) { return 0; }
auto const lookup { m_prepassclasses.find( material.shader.get() ) };
auto const lookup { m_prepassclasses.find( static_cast<gl::program const *>( material.shader.get() ) ) };
if( lookup != m_prepassclasses.end() ) { return lookup->second; }
// names the programs are fetched by: mat_<name>.frag
@@ -4904,7 +4906,7 @@ int opengl46_renderer::Prepass_Class( material_handle const Material )
prepassclass = ( alphatested.count( shader.first ) > 0 ? 2 : solid.count( shader.first ) > 0 ? 1 : 0 );
break;
}
m_prepassclasses.emplace( material.shader.get(), prepassclass );
m_prepassclasses.emplace( static_cast<gl::program const *>( material.shader.get() ), prepassclass );
return prepassclass;
}
@@ -5678,7 +5680,7 @@ gl::program const *opengl46_renderer::Indirect_Program( material_handle Material
material = &m_materials.material( m_invalid_material );
if( false == material->is_good ) { return nullptr; }
}
return material->shader.get();
return static_cast<gl::program const *>( material->shader.get() );
}
gl::program *opengl46_renderer::Multidraw_Program( gl::program const *Program )
@@ -8867,7 +8869,11 @@ std::string const &opengl46_renderer::info_stats() const
void opengl46_renderer::MakeScreenshot()
{
screenshot_manager::make_screenshot();
// rows are tightly packed RGB: the renderer sets GL_PACK_ALIGNMENT to 1
auto img = new char[Global.fb_size.x * Global.fb_size.y * 3];
glReadPixels(0, 0, Global.fb_size.x, Global.fb_size.y, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)img);
//m7t: use pbo
screenshot_manager::save(img, Global.fb_size.x, Global.fb_size.y);
}
// model previews
@@ -10239,9 +10245,14 @@ void opengl46_renderer::opengl46_imgui_renderer::Render()
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}
std::uint64_t opengl46_renderer::opengl46_imgui_renderer::Create_Image(std::uint8_t const *Rgba, int const Width, int const Height)
std::uint64_t opengl46_renderer::opengl46_imgui_renderer::Create_Image(std::uint8_t const *Rgba, int const Width, int const Height, image_options const &Options)
{
// the ui colours are made linear in its shaders, the image is too, by sampling it as srgb. the bindings the renderer
return Update_Image(0, Rgba, Width, Height, Options);
}
std::uint64_t opengl46_renderer::opengl46_imgui_renderer::Update_Image(std::uint64_t const Image, std::uint8_t const *Rgba, int const Width, int const Height, image_options const &Options)
{
// the ui colours are made linear in its shaders, an srgb image is too, by sampling it as srgb. the bindings the renderer
// keeps track of are put back as they were
GLint texture{0}, unpack{0}, alignment{4};
glGetIntegerv(GL_TEXTURE_BINDING_2D, &texture);
@@ -10249,14 +10260,18 @@ std::uint64_t opengl46_renderer::opengl46_imgui_renderer::Create_Image(std::uint
glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
GLuint image{0};
glGenTextures(1, &image);
auto image{static_cast<GLuint>(Image)};
if (image == 0)
glGenTextures(1, &image);
glBindTexture(GL_TEXTURE_2D, image);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
auto const filter{Options.nearest ? GL_NEAREST : GL_LINEAR};
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Options.mipmaps ? (Options.nearest ? GL_NEAREST_MIPMAP_NEAREST : GL_LINEAR_MIPMAP_LINEAR) : filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, Rgba);
glTexImage2D(GL_TEXTURE_2D, 0, Options.srgb ? GL_SRGB8_ALPHA8 : GL_RGBA8, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, Rgba);
if (Options.mipmaps)
glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(texture));
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, static_cast<GLuint>(unpack));
glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);

View File

@@ -117,8 +117,8 @@ class opengl46_renderer : public gfx_renderer {
void
Terrain_Grass( std::vector<gfx::grass_kind> const &Kinds, std::vector<gfx::grass_chunk> const &Chunks ) override;
// shader methods
auto Fetch_Shader( std::string const &name ) -> std::shared_ptr<gl::program> override;
auto Shader_Name( std::shared_ptr<gl::program> const &Program ) const -> std::string override;
auto Fetch_Shader( std::string const &name ) -> std::shared_ptr<gfx::shader_program> override;
auto Shader_Name( std::shared_ptr<gfx::shader_program> const &Program ) const -> std::string override;
// texture methods
texture_handle
Fetch_Texture( std::string const &Filename, bool const Loadnow = true, GLint format_hint = GL_SRGB_ALPHA ) override;
@@ -1178,7 +1178,9 @@ class opengl46_renderer : public gfx_renderer {
virtual void Shutdown() override;
virtual void BeginFrame() override;
virtual void Render() override;
virtual std::uint64_t Create_Image(std::uint8_t const *Rgba, int const Width, int const Height) override;
using imgui_renderer::Create_Image;
virtual std::uint64_t Create_Image(std::uint8_t const *Rgba, int const Width, int const Height, image_options const &Options) override;
virtual std::uint64_t Update_Image(std::uint64_t const Image, std::uint8_t const *Rgba, int const Width, int const Height, image_options const &Options) override;
virtual void Release_Image(std::uint64_t const Image) override;
} m_imgui_renderer;

View File

@@ -92,8 +92,8 @@ class opengl46_terrain_materials
std::vector<slot> m_slots;
std::vector<std::size_t> m_free;
std::unordered_map<material_handle, std::size_t> m_slotof;
std::shared_ptr<gl::program> m_program; // of the chunks, mat_terrain
std::shared_ptr<gl::program> m_holesprogram; // of the chunks with holes, mat_terrain_holes
std::shared_ptr<gfx::shader_program> m_program; // of the chunks, mat_terrain
std::shared_ptr<gfx::shader_program> m_holesprogram; // of the chunks with holes, mat_terrain_holes
std::unique_ptr<gl::postfx> m_copy;
std::unique_ptr<gl::framebuffer> m_framebuffer;
};