Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/*
   Copyright (c) 2017 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software
   and associated documentation files (the "Software"), to deal in the Software
   without restriction,
   including without limitation the rights to use, copy, modify, merge, publish,
   distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so,
   subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED,
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
   PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
   DAMAGES OR OTHER LIABILITY,
   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
   IN CONNECTION WITH THE SOFTWARE
   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */

#ifndef _TEXTURE_DESCRIPTOR_H_
#define _TEXTURE_DESCRIPTOR_H_

#include "Core/Resources/Headers/ResourceDescriptor.h"
#include "Platform/Video/Headers/RenderAPIEnums.h"
#include "Utility/Headers/Colours.h"

namespace Divide {
/// This class is used to define all of the sampler settings needed to use a texture
/// We do not define copy constructors as we must define descriptors only with POD
class SamplerDescriptor : public Hashable {
   public:
    /// The constructor specifies the type so it can be used later for
    /// down-casting if needed
    SamplerDescriptor()
    {
        setDefaultValues();
    }

    virtual ~SamplerDescriptor()
    {

    }

    /// All of these are default values that should be safe for any kind of
    /// texture usage
    inline void setDefaultValues() {
        setWrapMode();
        setFilters(TextureFilter::LINEAR_MIPMAP_LINEAR, TextureFilter::LINEAR);
        setAnisotropy(16);
        setLOD();
        // Everything we load should be SRGB. Everything we create at runtime shouldn't
        toggleSRGBColourSpace(false);
        // The following 2 are mainly used by depthmaps for hardware comparisons
        _cmpFunc = ComparisonFunction::LEQUAL;
        _useRefCompare = false;
        _borderColour.set(DefaultColours::BLACK);
    }

    SamplerDescriptor* clone() const {
        return MemoryManager_NEW SamplerDescriptor(*this);
    }

    /*
    *  Sampler states (LOD, wrap modes, anisotropy levels, etc
    */
    inline void setAnisotropy(U8 value = 0) { _anisotropyLevel = value; }

    inline void setLOD(F32 minLOD = -1000.f, F32 maxLOD = 1000.f,
                       F32 biasLOD = 0.f) {
        _minLOD = minLOD;
        _maxLOD = maxLOD;
        _biasLOD = biasLOD;
    }

    inline void setBorderColour(const FColour& colour) {
        _borderColour.set(colour);
    }

    inline void setWrapMode(TextureWrap wrapUVW = TextureWrap::REPEAT) {
        setWrapModeU(wrapUVW);
        setWrapModeV(wrapUVW);
        setWrapModeW(wrapUVW);
    }

    inline void setWrapMode(TextureWrap wrapU, TextureWrap wrapV,
                            TextureWrap wrapW = TextureWrap::REPEAT) {
        setWrapModeU(wrapU);
        setWrapModeV(wrapV);
        setWrapModeW(wrapW);
    }

    inline void setWrapMode(I32 wrapU, I32 wrapV, I32 wrapW) {
        setWrapMode(static_cast<TextureWrap>(wrapU),
                    static_cast<TextureWrap>(wrapV),
                    static_cast<TextureWrap>(wrapW));
    }

    inline void setWrapModeU(TextureWrap wrapU) { _wrapU = wrapU; }
    inline void setWrapModeV(TextureWrap wrapV) { _wrapV = wrapV; }
    inline void setWrapModeW(TextureWrap wrapW) { _wrapW = wrapW; }

    inline void setFilters(TextureFilter filters) {
        setMinFilter(filters);
        switch (filters) {
            case TextureFilter::LINEAR_MIPMAP_LINEAR:
            case TextureFilter::LINEAR_MIPMAP_NEAREST:
                setMagFilter(TextureFilter::LINEAR);
                break;
            case TextureFilter::NEAREST_MIPMAP_LINEAR:
            case TextureFilter::NEAREST_MIPMAP_NEAREST:
                setMagFilter(TextureFilter::NEAREST);
                break;
            default:
                setMagFilter(filters);
                break;
        }
    }

    inline void setFilters(TextureFilter minFilter, TextureFilter magFilter) {
        setMinFilter(minFilter);
        setMagFilter(magFilter);
    }

    inline void setMinFilter(TextureFilter minFilter) {
        _minFilter = minFilter;
    }

    inline void setMagFilter(TextureFilter magFilter) {
        assert(magFilter == TextureFilter::LINEAR ||
               magFilter == TextureFilter::NEAREST);
        _magFilter = magFilter;
    }

    inline void toggleSRGBColourSpace(const bool state) { _srgb = state; }

    inline size_t getHash() const override {
        _hash = 0;
        Util::Hash_combine(_hash, to_U32(_cmpFunc));
        Util::Hash_combine(_hash, _useRefCompare);
        Util::Hash_combine(_hash, _srgb);
        Util::Hash_combine(_hash, to_U32(_wrapU));
        Util::Hash_combine(_hash, to_U32(_wrapV));
        Util::Hash_combine(_hash, to_U32(_wrapW));
        Util::Hash_combine(_hash, to_U32(_minFilter));
        Util::Hash_combine(_hash, to_U32(_magFilter));
        Util::Hash_combine(_hash, _minLOD);
        Util::Hash_combine(_hash, _maxLOD);
        Util::Hash_combine(_hash, _biasLOD);
        Util::Hash_combine(_hash, _anisotropyLevel);
        Util::Hash_combine(_hash, _borderColour.r);
        Util::Hash_combine(_hash, _borderColour.g);
        Util::Hash_combine(_hash, _borderColour.b);
        Util::Hash_combine(_hash, _borderColour.a);
        Util::Hash_combine(_hash, _msaaSamples);
        return _hash;
    }
    /*
    *  "Internal" data
    */

    // HW comparison settings
    ComparisonFunction _cmpFunc;  ///<Used by RefCompare
    bool _useRefCompare;  ///<use red channel as comparison (e.g. for shadows)

    inline TextureWrap wrapU() const { return _wrapU; }
    inline TextureWrap wrapV() const { return _wrapV; }
    inline TextureWrap wrapW() const { return _wrapW; }
    inline TextureFilter minFilter() const { return _minFilter; }
    inline TextureFilter magFilter() const { return _magFilter; }
    inline F32 minLOD() const { return _minLOD; }
    inline F32 maxLOD() const { return _maxLOD; }
    inline F32 biasLOD() const { return _biasLOD; }
    inline bool srgb() const { return _srgb; }
    inline U8 anisotropyLevel() const { return _anisotropyLevel; }
    inline bool generateMipMaps() const { 
        return _minFilter != TextureFilter::LINEAR &&
               _minFilter != TextureFilter::NEAREST &&
               _minFilter != TextureFilter::COUNT;
    }

    inline const FColour& borderColour() const { return _borderColour; }

   protected:
    // Sampler states
    /// Texture filtering mode
    TextureFilter _minFilter, _magFilter;
    /// Texture wrap mode (Or S-R-T)
    TextureWrap _wrapU, _wrapV, _wrapW;
    /// Use SRGB colour space
    bool _srgb;
    /// The value must be in the range [0...255] and is automatically clamped by
    /// the max HW supported level
    U8 _anisotropyLevel;
    /// OpenGL eg: used by TEXTURE_MIN_LOD and TEXTURE_MAX_LOD
    F32 _minLOD, _maxLOD;
    /// OpenGL eg: used by TEXTURE_LOD_BIAS
    F32 _biasLOD;
    /// Used with CLAMP_TO_BORDER as the background colour outside of the texture border
    FColour _borderColour;
    /// number of MSAA samples: -1 (default) - max supported by implementation/settings, 0 - disabled
    I32 _msaaSamples;
};

/// Use to define a texture with details such as type, image formats, etc
/// We do not define copy constructors as we must define descriptors only with
/// POD
class TextureDescriptor : public PropertyDescriptor {
   public:
    TextureDescriptor()
        : TextureDescriptor(TextureType::COUNT,
                            GFXImageFormat::COUNT,
                            GFXDataFormat::COUNT)
    {
    }

    TextureDescriptor(TextureType type)
         : TextureDescriptor(type,
                             GFXImageFormat::COUNT)
    {
    }

    TextureDescriptor(TextureType type,
                      GFXImageFormat internalFormat)
        : TextureDescriptor(type,
                            internalFormat,
                            GFXDataFormat::COUNT)
    {
    }

    TextureDescriptor(TextureType type,
                      GFXImageFormat internalFmt,
                      GFXDataFormat dataType)
        : PropertyDescriptor(DescriptorType::DESCRIPTOR_TEXTURE),
          _layerCount(1),
          _baseFormat(GFXImageFormat::COUNT),
          _dataType(dataType),
          _type(type),
          _compressed(false),
          _automaticMipMaps(true),
          _mipLevels(0u, 1u),
          _msaaSamples(-1)
    {
        internalFormat(internalFmt);
    }

    virtual ~TextureDescriptor()
    {
    }

    TextureDescriptor* clone() const {
        return MemoryManager_NEW TextureDescriptor(*this);
    }

    /// Pixel alignment and miplevels are set to match what the HW sets by
    /// default
    inline void setDefaultValues() {
        setLayerCount(1);
        setSampler(SamplerDescriptor());
        _internalFormat = GFXImageFormat::RGBA8;
        _baseFormat = baseFromInternalFormat(_internalFormat);
        _dataType = GFXDataFormat::UNSIGNED_BYTE;
        _type = TextureType::TEXTURE_2D;
        _automaticMipMaps = true;
        _mipLevels.set(0u, 1u);
        _msaaSamples = -1;
    }

    inline void setLayerCount(U32 layerCount) { 
        _layerCount = layerCount;
    }

    inline bool isCubeTexture() const {
        return (_type == TextureType::TEXTURE_CUBE_MAP ||
                _type == TextureType::TEXTURE_CUBE_ARRAY);
    }

    inline bool isArrayTexture() const {
        return _type == TextureType::TEXTURE_2D_ARRAY;
    }

    inline bool isMultisampledTexture() const {
        return _type == TextureType::TEXTURE_2D_MS ||
               _type == TextureType::TEXTURE_2D_ARRAY_MS;
    }
    /// A TextureDescriptor will always have a sampler, even if it is the
    /// default one
    inline void setSampler(const SamplerDescriptor& descriptor) {
        _samplerDescriptor = descriptor;
    }

    inline GFXImageFormat internalFormat() const {
        return _internalFormat;
    }

    inline void internalFormat(GFXImageFormat internalFormat) {
        _internalFormat = internalFormat;
        _baseFormat = baseFromInternalFormat(internalFormat);
        _dataType = dataTypeForInternalFormat(internalFormat);
    }

    inline const SamplerDescriptor& getSampler() const {
        return _samplerDescriptor;
    }

    inline GFXDataFormat dataType() const {
        assert(_dataType != GFXDataFormat::COUNT);
        return _dataType;
    }

    inline GFXImageFormat baseFormat() const {
        assert(_baseFormat != GFXImageFormat::COUNT);

        return _baseFormat;
    }

    inline bool automaticMipMapGeneration() const {
        return _automaticMipMaps;
    }

    inline void toggleAutomaticMipMapGeneration(const bool state) {
        _automaticMipMaps = state;
    }

    inline void type(TextureType type) { _type = type; }

    inline TextureType type() const { return _type; }

    inline I16 msaaSamples() const { return _msaaSamples; }

    inline void msaaSamples(I16 sampleCount) { _msaaSamples = sampleCount; }

    inline size_t getHash() const override {
        size_t hash = 0;
        Util::Hash_combine(hash, _layerCount);
        Util::Hash_combine(hash, to_U32(_internalFormat));
        Util::Hash_combine(hash, to_U32(_type));
        Util::Hash_combine(hash, _compressed);
        Util::Hash_combine(hash, _automaticMipMaps);
        Util::Hash_combine(hash, _baseFormat); 
        Util::Hash_combine(hash, _dataType);
        Util::Hash_combine(hash, _mipLevels.min);
        Util::Hash_combine(hash, _mipLevels.max);
        Util::Hash_combine(hash, _msaaSamples);
        Util::Hash_combine(hash, _samplerDescriptor.getHash());
        Util::Hash_combine(hash, PropertyDescriptor::getHash());

        return hash;
    }

    U32 _layerCount;
    TextureType _type;
    bool _compressed;
    /// Automatically compute mipmaps
    bool _automaticMipMaps;
    /// The sampler used to initialize this texture with
    SamplerDescriptor _samplerDescriptor;
    /// Mip levels
    vec2<U16> _mipLevels;
    /// How many MSAA samples to use: -1 (default) = max available, 0 = disabled
    I16 _msaaSamples;

  private:
     GFXImageFormat _baseFormat;
     GFXDataFormat  _dataType;
     /// Texture data information
     GFXImageFormat _internalFormat;
};

};  // namespace Divide
#endif

Commits for Divide-Framework/trunk/Source Code/Platform/Video/Textures/Headers/TextureDescriptor.h

Diff revisions: vs.
Revision Author Commited Message
1004 Diff Diff IonutCava picture IonutCava Wed 20 Dec, 2017 17:16:32 +0000

[Ionut]
- More GUI cleanup (added multiple GUIButton events)
- Typedef vec4<U8> and vec4<F32> to UColour and FColour respectively for easier to read code.

955 Diff Diff IonutCava picture IonutCava Sun 29 Oct, 2017 20:45:04 +0000

[Ionut]
- Modify the CEGUI opengl renderer to interact with the state in GLWrapper better
- Performance optimizations

953 Diff Diff IonutCava picture IonutCava Sat 28 Oct, 2017 21:57:10 +0000

[Ionut]
- Fix blinking issue by caching and hashing pipelines to that we don’t overwrite pipelines used by other elements

947 Diff Diff IonutCava picture IonutCava Sun 08 Oct, 2017 22:36:54 +0000

[Ionut]
- Refactor command buffer pooling
- Remove all static commands in an attempt to fix rendering issues. Profile and rework later.

909 Diff Diff IonutCava picture IonutCava Thu 29 Jun, 2017 23:57:18 +0000

[Ionut]
- Rework RenderTarget class
— RTAttachment now deal with textures directly
— RT size needs to be specified upfront
- Application class is no longer a Singleton but passed around in the PlatformContext

908 Diff Diff IonutCava picture IonutCava Thu 29 Jun, 2017 15:56:53 +0000

[Ionut]
- Texture’s MSAA sample count is now a property of the TextureDescriptor
- Add extra SDL validation as well as fallback for too high MSAA sample count specified

907 Diff Diff IonutCava picture IonutCava Wed 28 Jun, 2017 23:16:40 +0000

[Ionut]
- Rework texture loading, mip map generation, sampler usage, etc
- ResourceDescriptor for textures now ONLY takes a TextureDescriptor as a property descriptor. Sampler must be assigned to the tex descriptor:
— ToDo: Separate samplers completely from textures and assign them from a pool to textures at bind time

899 Diff Diff IonutCava picture IonutCava Fri 23 Jun, 2017 15:37:44 +0000

[IonutCava]
- Move sRGB conversion and fog calculation to post-processing stages (fog in postProcessing using the depth buffer and sRGB in the presentToScreen step)
- Split the bloom.glsl file into multiple shaders: bloom, tonemap and luminanceCalc for ease of use purposes
- Rework RenderBin sorting: sort translucent/transparent nodes by material in depth passes
- Sort order is no longer part of RenderBin for better control

867 Diff Diff IonutCava picture IonutCava Mon 20 Feb, 2017 17:01:12 +0000

[IonutCava]
- Rename to_XNN and to_const_XNN functions to reflect the target data type they are converting to.
- Cleanup Angle namespace and remove all “inDegrees” parameters from rotation functions. Use aliases to differentiate between Degree and Radian parameters.
- Profile guided optimizations.

863 IonutCava picture IonutCava Wed 15 Feb, 2017 16:27:26 +0000

[IonutCava]
- Split Resource class into Resource and CachedResource
— CachedResource is the only resource held in a ResourceCache and loaded from a ResourceDescriptor
— CachedResource is mapped by its creation descriptor’s hash value, instead of the resource name
-— Multiple cached resources can now exist with the same name if the have different properties, for example.