RavEngine
Loading...
Searching...
No Matches
Texture.hpp
1#if !RVE_SERVER
2#pragma once
3#include "Ref.hpp"
4#include "Manager.hpp"
5#include "Filesystem.hpp"
6#include <RGL/Types.hpp>
7#include <RGL/TextureFormat.hpp>
8#include <RGL/Texture.hpp>
9#include "RenderTargetCollection.hpp"
10#include <span>
11#include <cstddef>
12
13namespace RavEngine{
14
15struct IStream;
16
17struct Texture {
18 struct Config {
19 uint8_t mipLevels = 1;
20 int numLayers = 1;
21 bool enableRenderTarget = false;
22 RGL::TextureUploadData initialData;
23 RGL::TextureFormat format = RGL::TextureFormat::RGBA8_Unorm;
24 std::string_view debugName;
25 };
26
31 Texture(const std::string& filename);
32 Texture(const char* filename) : Texture(std::string(filename)) {}
33
34 Texture(const std::string& filename, uint16_t width, uint16_t height);
35
36 Texture(const Filesystem::Path& pathOnDisk);
37 Texture(RGLTexturePtr tx) : texture(tx){}
38
48 Texture(int width, int height, const Config& config) : Texture() {
49 CreateTexture(width, height, config);
50 }
51
52 virtual ~Texture();
53
57 struct Manager : public GenericWeakReadThroughCache<std::string, RavEngine::Texture>{
58 static Ref<RavEngine::Texture> defaultTexture, defaultNormalTexture, zeroTexture;
59 };
60
61 auto GetRHITexturePointer() const {
62 return texture;
63 }
64
69
70protected:
71
72 RGLTexturePtr texture;
73
74 Texture(){}
75
76 void CreateTexture(int width, int height, const Config& config);
77
78 void InitFromDDS(IStream&);
79 void InitFromEXR(IStream&);
80};
81
82
84
85 RenderTexture(int width, int height);
86
87 Ref<Texture> GetTexture();
88 const auto& GetCollection() const{
89 return collection;
90 }
91private:
92 RenderTargetCollection collection;
93 Ref<Texture> finalFB;
94};
95
97 struct Config {
98 std::string_view debugName;
99 RGL::TextureFormat format = RGL::TextureFormat::RGBA8_Unorm;
100 uint32_t numMips = 1;
101 bool enableRenderTarget = false;
102#if !_MSC_VER
103 Config(): enableRenderTarget(false), format(RGL::TextureFormat::RGBA8_Unorm),numMips(1){} // workaround for clang/gcc bug
104#endif
105 };
106
107 CubemapTexture(int size, const Config& config = {});
108
109 RGL::TextureView GetView() const;
110
111 RGL::Dimension GetTextureSize() const;
112
113 auto GetRHITexturePointer() const {
114 return cubemap;
115 }
116
117private:
118 RGLTexturePtr cubemap;
119};
120
121}
122#endif
Definition concurrentqueue.h:747
Definition Animation.hpp:6
Definition Texture.hpp:25
Definition Texture.hpp:162
Definition Texture.hpp:43
Definition Texture.hpp:97
Definition Texture.hpp:96
Definition RenderTargetCollection.hpp:19
Definition Texture.hpp:83
Definition Texture.hpp:18
Definition Texture.hpp:57
Definition Texture.hpp:17
Texture(int width, int height, const Config &config)
Definition Texture.hpp:48
RGL::Dimension GetTextureSize() const
Definition Texture.cpp:209