Renderer/Texture: Add static helpers

This commit is contained in:
Jérôme Leclercq
2021-05-25 15:37:55 +02:00
parent 59cfc74ab4
commit 335bb82be1
5 changed files with 106 additions and 127 deletions

View File

@@ -8,14 +8,19 @@
#define NAZARA_TEXTURE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceManager.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Image.hpp>
namespace Nz
{
class RenderDevice;
struct TextureInfo
{
PixelFormat pixelFormat;
@@ -27,6 +32,20 @@ namespace Nz
unsigned int width;
};
struct NAZARA_RENDERER_API TextureParams : ImageParams
{
std::shared_ptr<RenderDevice> renderDevice;
TextureUsageFlags usageFlags = TextureUsage::ShaderSampling | TextureUsage::TransferDestination;
bool IsValid() const;
};
class Texture;
using TextureLibrary = ObjectLibrary<Texture>;
using TextureLoader = ResourceLoader<Texture, TextureParams>;
using TextureManager = ResourceManager<Texture, TextureParams>;
class NAZARA_RENDERER_API Texture : public Resource
{
public:
@@ -44,6 +63,13 @@ namespace Nz
static inline unsigned int GetLevelSize(unsigned int size, unsigned int level);
static std::shared_ptr<Texture> CreateFromImage(const Image& image, const TextureParams& params);
// Load
static std::shared_ptr<Texture> LoadFromFile(const std::filesystem::path& filePath, const TextureParams& params);
static std::shared_ptr<Texture> LoadFromMemory(const void* data, std::size_t size, const TextureParams& params);
static std::shared_ptr<Texture> LoadFromStream(Stream& stream, const TextureParams& params);
Texture& operator=(const Texture&) = delete;
Texture& operator=(Texture&&) = delete;
};