Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Texture.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef DVD_TEXTURE_H_
34#define DVD_TEXTURE_H_
35
39
42
44
45namespace Divide
46{
47
48class Kernel;
49class ResourceCache;
50
51namespace Attorney
52{
53 class TextureKernel;
54};
55
56namespace TypeUtil
57{
58 [[nodiscard]] const char* WrapModeToString( TextureWrap wrapMode ) noexcept;
59 [[nodiscard]] TextureWrap StringToWrapMode( const string& wrapMode );
60
61 [[nodiscard]] const char* TextureFilterToString( TextureFilter filter ) noexcept;
62 [[nodiscard]] TextureFilter StringToTextureFilter( const string& filter );
63
64 [[nodiscard]] const char* TextureMipSamplingToString( TextureMipSampling sampling ) noexcept;
65 [[nodiscard]] TextureMipSampling StringToTextureMipSampling( const string& sampling );
66};
67
68class Texture;
69
71{
75};
76
77using TextureLayoutChanges = eastl::fixed_vector<TextureLayoutChange, 6, true>;
78
79[[nodiscard]] bool IsEmpty( const TextureLayoutChanges& changes ) noexcept;
80
83{
84 friend class ResourceCache;
85 friend struct ResourceLoader;
86 template <typename T>
87 friend class ImplResourceLoader;
89
90 public:
91 explicit Texture( PlatformContext& context, const ResourceDescriptor<Texture>& descriptor );
92
93 virtual ~Texture() override;
94
95 static void OnStartup( GFXDevice& gfx );
96 static void OnShutdown() noexcept;
97 [[nodiscard]] static bool UseTextureDDSCache() noexcept;
98 [[nodiscard]] static Handle<Texture> DefaultTexture2D() noexcept;
99 [[nodiscard]] static Handle<Texture> DefaultTexture2DArray() noexcept;
100 [[nodiscard]] static const SamplerDescriptor DefaultSampler() noexcept;
101 [[nodiscard]] static U8 GetBytesPerPixel( GFXDataFormat format, GFXImageFormat baseFormat, GFXImagePacking packing ) noexcept;
102
104 void createWithData( const ImageTools::ImageData& imageData, const PixelAlignment& pixelUnpackAlignment );
105 void createWithData( const Byte* data, size_t dataSize, const vec2<U16>& dimensions, const PixelAlignment& pixelUnpackAlignment );
106 void createWithData( const Byte* data, size_t dataSize, const vec3<U16>& dimensions, const PixelAlignment& pixelUnpackAlignment );
107
108 void replaceData(const Byte* data, size_t dataSize, const vec3<U16>& offset, const vec3<U16>& range, const PixelAlignment& pixelUnpackAlignment );
109
111 void setSampleCount( U8 newSampleCount );
112
113 [[nodiscard]] ImageView getView() const noexcept;
114 [[nodiscard]] ImageView getView( TextureType targetType ) const noexcept;
115 [[nodiscard]] ImageView getView( SubRange mipRange ) const noexcept;
116 [[nodiscard]] ImageView getView( SubRange mipRange, SubRange layerRange ) const noexcept;
117 [[nodiscard]] ImageView getView( TextureType targetType, SubRange mipRange ) const noexcept;
118 [[nodiscard]] ImageView getView( TextureType targetType, SubRange mipRange, SubRange layerRange/*offset, count*/ ) const noexcept;
119
120 [[nodiscard]] virtual ImageReadbackData readData( U8 mipLevel, const PixelAlignment& pixelPackAlignment) const = 0;
121
124 PROPERTY_R( U16, mipCount, 1u );
126 PROPERTY_R( U16, width, 0u );
128 PROPERTY_R( U16, height, 0u );
130 PROPERTY_R( U16, depth, 1u );
132 PROPERTY_R( bool, hasTranslucency, false );
134 PROPERTY_R( bool, hasTransparency, false );
135 PROPERTY_R( bool, loadedFromFile, false );
136 [[nodiscard]] U8 numChannels() const noexcept;
137
138 bool load( PlatformContext& context ) override;
139 bool postLoad() override;
140 protected:
142 bool loadFile( const ResourcePath& path, std::string_view name, ImageTools::ImageData& fileData );
143 bool checkTransparency( const ResourcePath& path, std::string_view name, ImageTools::ImageData& fileData );
145 bool loadInternal();
146
147 void validateDescriptor();
148
149 virtual void loadDataInternal( const ImageTools::ImageData& imageData, const vec3<U16>& offset, const PixelAlignment& pixelUnpackAlignment ) = 0;
150 virtual void loadDataInternal( const Byte* data, size_t size, U8 targetMip, const vec3<U16>& offset, const vec3<U16>& dimensions, const PixelAlignment& pixelUnpackAlignment ) = 0;
151 virtual void prepareTextureData( U16 width, U16 height, U16 depth, bool emptyAllocation );
152 virtual void submitTextureData();
153
154 protected:
155 static bool s_useDDSCache;
156 static SamplerDescriptor s_defaultSampler;
157 static Handle<Texture> s_defaultTexture2D;
158 static Handle<Texture> s_defaultTexture2DArray;
159 static Str<64> s_missingTextureFileName;
160};
161
162namespace Attorney
163{
165 {
166 protected:
167 static void UseTextureDDSCache( const bool state ) noexcept
168 {
169 Texture::s_useDDSCache = state;
170 }
171
172 friend class Divide::Kernel;
173 };
174}
175
176}; // namespace Divide
177#endif // DVD_TEXTURE_H_
#define PROPERTY_R(...)
Convenience method to add a class member with public read access but protected write access.
#define NOINITVTABLE
static void UseTextureDDSCache(const bool state) noexcept
Definition: Texture.h:167
Rough around the edges Adapter pattern abstracting the actual rendering API and access to the GPU.
Definition: GFXDevice.h:215
The kernel is the main system that connects all of our various systems: windows, gfx,...
Definition: Kernel.h:81
An API-independent representation of a texture.
Definition: Texture.h:83
const char * TextureFilterToString(TextureFilter filter) noexcept
const char * WrapModeToString(TextureWrap wrapMode) noexcept
TextureMipSampling StringToTextureMipSampling(const string &sampling)
const char * TextureMipSamplingToString(TextureMipSampling sampling) noexcept
TextureWrap StringToWrapMode(const string &wrapMode)
TextureFilter StringToTextureFilter(const string &filter)
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
std::byte Byte
uint8_t U8
eastl::fixed_vector< TextureLayoutChange, 6, true > TextureLayoutChanges
Definition: Texture.h:77
uint16_t U16
bool IsEmpty(const BufferLocks &locks) noexcept
Definition: BufferLocks.cpp:8
ImageUsage _targetLayout
Definition: Texture.h:74
ImageUsage _sourceLayout
Definition: Texture.h:73