17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-19 01:29:21 +02:00
Files
maszyna/betterRenderer/renderer/source/nvtexture.h
maj00r 26501b0fd7 hoist standard includes above everything else
Ordering them before the imports in the same file was not enough: a
project header on line 1 can import a module several levels down whose
global module fragment already pulled in the same standard header, and
that include guard does not cross the module boundary. Putting them
first means the guard is set before anything can import.

Skips vendored single-header libraries and anything inside an #if.
2026-09-10 01:02:17 +02:00

111 lines
3.5 KiB
C++

#pragma once
#include <bitset>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include <nvrhi/nvrhi.h>
#include "global_include/interfaces/ITexture_macros.h"
#include "nvrenderer/nvrenderer_enums.h"
import eu07.global_include.interfaces.itexture;
import eu07.glm;
enum MaTextureTraits {
MaTextureTraits_Sharpen,
MaTextureTraits_ClampS,
MaTextureTraits_ClampT,
MaTextureTraits_NoMipBias,
MaTextureTraits_NoAnisotropy,
MaTextureTraits_NoFilter,
MaTextureTraits_Num
};
using TextureTraitFlags = std::bitset<MaTextureTraits_Num>;
struct opengl_texture;
struct NvTexture : public ITexture {
virtual bool create(bool Static = false) override {
return CreateRhiTexture();
}
virtual int get_width() const override { return m_width; }
virtual int get_height() const override { return m_height; }
virtual size_t get_id() const override {
return reinterpret_cast<size_t>(m_rhi_texture.Get());
}
virtual void release() override {}
virtual void make_stub() override {}
virtual std::string_view get_traits() const override { return ""; }
virtual std::string_view get_name() const override {
return m_sz_texture->get_name();
}
virtual std::string_view get_type() const override {
return m_sz_texture->get_type();
}
virtual bool is_stub() const override { return false; }
virtual bool get_has_alpha() const override { return m_has_alpha; }
virtual bool get_is_ready() const override { return m_rhi_texture; }
virtual void set_components_hint(int format_hint) override;
virtual void make_from_memory(size_t width, size_t height,
const uint8_t* data) override;
virtual void update_from_memory(size_t width, size_t height,
const uint8_t* data) override;
void Load(int size_bias);
bool LoadDDS(std::string& data, int size_bias);
bool IsLoaded() const;
std::shared_ptr<ITexture> m_sz_texture;
nvrhi::TextureHandle m_rhi_texture;
std::vector<std::pair<int, std::string>> m_data;
TextureTraitFlags GetTraits() const { return 0; }
int m_width;
int m_height;
int m_mipcount;
int m_slicecount;
bool m_srgb;
bool m_bc;
bool m_has_alpha;
nvrhi::Format m_format;
size_t m_gc_slot;
bool CreateRhiTexture();
uint64_t m_last_change;
static uint64_t s_change_counter;
uint64_t m_own_handle;
};
class NvTextureManager {
public:
struct TextureGCSlot {
size_t m_index;
glm::dvec3 m_last_position_requested;
};
NvTextureManager(class NvRenderer* renderer);
size_t FetchTexture(std::string path, int format_hint, int size_bias,
bool unload_on_location);
size_t RegisterExternalTexture(std::string const& path, nvrhi::ITexture *texture);
void UpdateLastUse(size_t handle, const glm::dvec3& location);
bool IsValidHandle(size_t handle);
NvTexture* GetTexture(size_t handle);
nvrhi::ITexture* GetRhiTexture(size_t handle,
nvrhi::ICommandList* command_list = nullptr);
TextureTraitFlags GetTraits(size_t handle);
nvrhi::SamplerHandle GetSamplerForTraits(TextureTraitFlags traits,
RendererEnums::RenderPassType pass);
std::vector<TextureGCSlot> m_unloadable_textures;
void Cleanup(const glm::dvec3& location);
private:
std::unordered_map<TextureTraitFlags, nvrhi::SamplerHandle> m_samplers;
class NvRendererBackend* m_backend;
std::unordered_map<std::string, size_t> m_texture_map;
std::vector<std::shared_ptr<NvTexture>> m_texture_cache;
};