Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
TextureDescriptor.inl
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_DESCRIPTOR_INL_
34#define DVD_TEXTURE_DESCRIPTOR_INL_
35
36namespace Divide {
37
38inline bool Is1DTexture( const TextureType texType ) noexcept
39{
40 return texType == TextureType::TEXTURE_1D ||
42}
43
44inline bool Is2DTexture( const TextureType texType ) noexcept
45{
46 return texType == TextureType::TEXTURE_2D ||
48}
49
50inline bool Is3DTexture( const TextureType texType ) noexcept
51{
52 return texType == TextureType::TEXTURE_3D;
53}
54
55
56inline bool IsCubeTexture(const TextureType texType) noexcept
57{
58 return texType == TextureType::TEXTURE_CUBE_MAP ||
60}
61
62inline bool IsArrayTexture(const TextureType texType) noexcept
63{
64 return texType == TextureType::TEXTURE_1D_ARRAY ||
67}
68
69inline bool IsDepthTexture(const GFXImagePacking packing) noexcept
70{
71 return packing == GFXImagePacking::DEPTH ||
73}
74
75inline bool IsNormalizedTexture( GFXImagePacking packing ) noexcept
76{
77 return packing != GFXImagePacking::UNNORMALIZED;
78}
79
80inline bool SupportsZOffsetTexture( const TextureType texType ) noexcept
81{
82 return IsCubeTexture( texType ) || Is3DTexture( texType ) || IsArrayTexture( texType );
83}
84
85inline U8 NumChannels(const GFXImageFormat format) noexcept
86{
87 switch (format)
88 {
91 case GFXImageFormat::BC4u: return 1u;
92
95 case GFXImageFormat::BC5u: return 2u;
96
101 case GFXImageFormat::BC6u: return 3u;
102
109 case GFXImageFormat::BC7: return 4u;
110
112 }
113
114 return 0u;
115}
116
117inline bool IsBGRTexture( GFXImageFormat format ) noexcept
118{
119 return format == GFXImageFormat::BGR ||
120 format == GFXImageFormat::BGRA;
121}
122
124{
125 descriptor._usageMask |= (1u << to_base( usage ));
126}
127
129{
130 descriptor._usageMask &= ~(1u << to_base( usage ));
131}
132
133FORCE_INLINE bool HasUsageFlagSet( const PropertyDescriptor<Texture>& descriptor, const ImageUsage usage ) noexcept
134{
135 return descriptor._usageMask & (1u << to_base( usage ));
136}
137
138template<>
139inline size_t GetHash( const PropertyDescriptor<Texture>& descriptor ) noexcept
140{
141 size_t hash = 1337;
142
143 Util::Hash_combine( hash,
144 descriptor._layerCount,
145 descriptor._mipBaseLevel,
146 to_base( descriptor._mipMappingState ),
147 descriptor._msaaSamples,
148 to_U32( descriptor._dataType ),
149 to_U32( descriptor._baseFormat ),
150 to_U32( descriptor._packing ),
151 to_U32( descriptor._texType ),
152 descriptor._usageMask,
153 descriptor._textureOptions._alphaChannelTransparency,
154 descriptor._textureOptions._fastCompression,
155 descriptor._textureOptions._isNormalMap,
156 descriptor._textureOptions._mipFilter,
157 descriptor._textureOptions._skipMipMaps,
158 descriptor._textureOptions._outputFormat,
159 descriptor._textureOptions._outputSRGB,
160 descriptor._textureOptions._useDDSCache
161 );
162
163 return hash;
164}
165} //namespace Divide
166
167#endif //DVD_TEXTURE_DESCRIPTOR_INL_
#define DIVIDE_UNEXPECTED_CALL()
#define FORCE_INLINE
void Hash_combine(size_t &seed, const T &v, const Rest &... rest) noexcept
a la Boost
Definition: MathHelper.inl:799
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
bool Is1DTexture(TextureType texType) noexcept
constexpr U32 to_U32(const T value)
bool IsNormalizedTexture(GFXImagePacking packing) noexcept
uint8_t U8
bool IsCubeTexture(TextureType texType) noexcept
bool IsArrayTexture(TextureType texType) noexcept
bool Is3DTexture(TextureType texType) noexcept
size_t GetHash(const PropertyDescriptor< T > &descriptor) noexcept
Definition: Resource.inl:40
void AddImageUsageFlag(PropertyDescriptor< Texture > &descriptor, const ImageUsage usage) noexcept
bool Is2DTexture(TextureType texType) noexcept
bool IsDepthTexture(GFXImagePacking packing) noexcept
void RemoveImageUsageFlag(PropertyDescriptor< Texture > &descriptor, const ImageUsage usage) noexcept
U8 NumChannels(GFXImageFormat format) noexcept
bool HasUsageFlagSet(const PropertyDescriptor< Texture > &descriptor, const ImageUsage usage) noexcept
bool SupportsZOffsetTexture(TextureType texType) noexcept
bool IsBGRTexture(GFXImageFormat format) noexcept
constexpr auto to_base(const Type value) -> Type