Berserk
ResTexture.hpp
Go to the documentation of this file.
1 /**********************************************************************************/
2 /* This file is part of Berserk Engine project */
3 /* https://github.com/EgorOrachyov/Berserk */
4 /**********************************************************************************/
5 /* MIT License */
6 /* */
7 /* Copyright (c) 2018 - 2021 Egor Orachyov */
8 /* */
9 /* Permission is hereby granted, free of charge, to any person obtaining a copy */
10 /* of this software and associated documentation files (the "Software"), to deal */
11 /* in the Software without restriction, including without limitation the rights */
12 /* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
13 /* copies of the Software, and to permit persons to whom the Software is */
14 /* furnished to do so, subject to the following conditions: */
15 /* */
16 /* The above copyright notice and this permission notice shall be included in all */
17 /* copies or substantial portions of the Software. */
18 /* */
19 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
20 /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
21 /* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
22 /* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
23 /* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
24 /* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
25 /* SOFTWARE. */
26 /**********************************************************************************/
27 
28 #ifndef BERSERK_RESTEXTURE_HPP
29 #define BERSERK_RESTEXTURE_HPP
30 
31 #include <core/image/Image.hpp>
32 #include <resource/Resource.hpp>
34 
35 #include <rhi/RHISampler.hpp>
36 #include <rhi/RHITexture.hpp>
37 
39 
50 public:
52  BRK_API ~ResTextureImportOptions() override = default;
53 
54  int width = -1;
55  int height = -1;
56  bool mipmaps = false;
57  bool cacheCPU = false;
59 };
60 
65 class ResTexture final : public Resource {
66 public:
67  BRK_API ResTexture() = default;
68  BRK_API ~ResTexture() override = default;
69 
70  BRK_API const StringName &GetResourceType() const override;
72 
73  BRK_API void CreateFromImage(const Image &image, bool mipmaps, bool cache);
74  BRK_API void SetSampler(Ref<RHISampler> sampler);
75 
76  BRK_API uint32 GetWidth() const { return mWidth; }
77  BRK_API uint32 GetHeight() const { return mHeight; }
78  BRK_API Image::Format GetFormat() const { return mFormat; }
79  BRK_API bool MipMaps() const { return mMipmaps; }
80 
81  BRK_API const Image &GetImage() const { return mImage; }
82  BRK_API const Ref<RHITexture> &GetRHITexture() const { return mRHITexture; };
83  BRK_API const Ref<RHISampler> &GetRHISampler() const { return mRHISampler; };
84 
85 private:
86  Ref<RHITexture> mRHITexture;
87  Ref<RHISampler> mRHISampler;
89  Image mImage;
92  uint32 mWidth = 0;
93  uint32 mHeight = 0;
94  bool mMipmaps = false;
95 };
96 
102 
103 #endif//BERSERK_RESTEXTURE_HPP
#define BRK_NS_END
Definition: Config.hpp:48
#define BRK_API
Definition: Config.hpp:32
std::uint32_t uint32
Definition: Typedefs.hpp:44
Hardware-independent image representation.
Definition: Image.hpp:52
Texture import options.
Definition: ResTexture.hpp:49
bool cacheCPU
Definition: ResTexture.hpp:57
int width
Definition: ResTexture.hpp:54
uint32 channels
Definition: ResTexture.hpp:58
BRK_API ~ResTextureImportOptions() override=default
BRK_API ResTextureImportOptions()=default
bool mipmaps
Definition: ResTexture.hpp:56
int height
Definition: ResTexture.hpp:55
2d texture resource for rendering
Definition: ResTexture.hpp:65
BRK_API bool MipMaps() const
Definition: ResTexture.hpp:79
BRK_API ~ResTexture() override=default
BRK_API Image::Format GetFormat() const
Definition: ResTexture.hpp:78
BRK_API const Ref< RHITexture > & GetRHITexture() const
Definition: ResTexture.hpp:82
BRK_API void CreateFromImage(const Image &image, bool mipmaps, bool cache)
Definition: ResTexture.cpp:44
BRK_API uint32 GetHeight() const
Definition: ResTexture.hpp:77
BRK_API ResTexture()=default
BRK_API const Image & GetImage() const
Definition: ResTexture.hpp:81
static BRK_API const StringName & GetResourceTypeStatic()
Definition: ResTexture.cpp:39
BRK_API const StringName & GetResourceType() const override
Definition: ResTexture.cpp:35
BRK_API const Ref< RHISampler > & GetRHISampler() const
Definition: ResTexture.hpp:83
BRK_API void SetSampler(Ref< RHISampler > sampler)
Definition: ResTexture.cpp:80
BRK_API uint32 GetWidth() const
Definition: ResTexture.hpp:76
Base class for import options to import specific resource.
Definition: ResourceImporter.hpp:48
Base class for any engine resource object.
Definition: Resource.hpp:48
Cached shared utf-8 string id.
Definition: StringName.hpp:61
RHITextureFormat
Definition: RHIDefs.hpp:135
Definition: GLDevice.cpp:46