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
/*
   Copyright (c) 2014 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.h"
#include "Core/Resources/Headers/ResourceDescriptor.h"
#include "Hardware/Video/Headers/RenderAPIEnums.h"
#include <boost/functional/hash.hpp>

///This class is used to define all of the sampler settings needed to use a texture
///Apply a sampler descriptor to either a texture's ResourceDescriptor or to a TextureDescriptor to use it
///We do not definy copy constructors as we must define descriptors only with POD
class SamplerDescriptor : public PropertyDescriptor {
public:
    ///The constructer specifies the type so it can be used later for downcasting if needed
    SamplerDescriptor() : PropertyDescriptor(DESCRIPTOR_SAMPLER)
    {
        setDefaultValues();
    }

    ///All of these are default values that should be safe for any kind of texture usage
    inline void setDefaultValues() {
        setWrapMode();
        setFilters();
        setAnisotropy(16);
        setLOD();
        toggleMipMaps(true);
        //The following 2 are mainly used by depthmaps for hardware comparisons
        _cmpFunc = CMP_FUNC_LEQUAL;
        _useRefCompare  = false;
        _borderColor.set(DefaultColors::BLACK());
    }

    SamplerDescriptor* clone() const {return 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 setBorderColor(const vec4<F32>& color) {
        _borderColor.set(color);
    }

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

    inline void setWrapMode(TextureWrap wrapU, TextureWrap wrapV, TextureWrap wrapW = TEXTURE_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 minFilter = TEXTURE_FILTER_LINEAR, TextureFilter magFilter = TEXTURE_FILTER_LINEAR){
        setMinFilter(minFilter);
        setMagFilter(magFilter);
    }

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

    inline void toggleMipMaps(bool state) {
        _generateMipMaps = state;
        if(state){
            if(_minFilter == TEXTURE_FILTER_LINEAR)
                _minFilter = TEXTURE_FILTER_LINEAR_MIPMAP_LINEAR;
        }else{
            if(_minFilter == TEXTURE_FILTER_LINEAR_MIPMAP_LINEAR)
                _minFilter = TEXTURE_FILTER_LINEAR;
        }
    }

    inline size_t getHash() const {
        size_t hash = 0;
        boost::hash_combine(hash, _cmpFunc);
        boost::hash_combine(hash, _useRefCompare);
        boost::hash_combine(hash, _wrapU);
        boost::hash_combine(hash, _wrapV);
        boost::hash_combine(hash, _wrapW);
        boost::hash_combine(hash, _minFilter);
        boost::hash_combine(hash, _magFilter);
        boost::hash_combine(hash, _minLOD);
        boost::hash_combine(hash, _maxLOD);
        boost::hash_combine(hash, _biasLOD);
        boost::hash_combine(hash, _anisotropyLevel);
        boost::hash_combine(hash, _generateMipMaps);
        boost::hash_combine(hash, _borderColor.r);
        boost::hash_combine(hash, _borderColor.g);
        boost::hash_combine(hash, _borderColor.b);
        boost::hash_combine(hash, _borderColor.a);
        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 U8            anisotropyLevel()  const {return _anisotropyLevel;}
    inline bool          generateMipMaps()  const {return _generateMipMaps;}
    inline vec4<F32>     borderColor()      const {return _borderColor;}

protected:
    //Sampler states
    TextureFilter  _minFilter, _magFilter; ///Texture filtering mode
    TextureWrap    _wrapU, _wrapV, _wrapW; ///<Or S-R-T
    bool           _generateMipMaps;       ///<If it's set to true we create automatic MipMaps
    U8             _anisotropyLevel;       ///<The value must be in the range [0...255] and is automatically clamped by the max HW supported level
    F32            _minLOD,_maxLOD;        ///<OpenGL eg: used by TEXTURE_MIN_LOD and TEXTURE_MAX_LOD
    F32            _biasLOD;               ///<OpenGL eg: used by TEXTURE_LOD_BIAS
    vec4<F32>      _borderColor;           ///<Used with CLAMP_TO_BORDER as the background color outside of the texture border
};

///Use to define a texture with details such as type, image formats, etc
///We do not definy copy constructors as we must define descriptors only with POD
class TextureDescriptor : public PropertyDescriptor {
public:
    ///This enum is used when creating Frame Buffers to define the channel that the texture will attach to
    enum AttachmentType{
        Color0 = 0,
        Color1,
        Color2,
        Color3,
        Depth
    };

    TextureDescriptor() : TextureDescriptor(TextureType_PLACEHOLDER, GFXImageFormat_PLACEHOLDER, GDF_PLACEHOLDER)
    {
    }

    TextureDescriptor(TextureType type,
                      GFXImageFormat internalFormat,
                      GFXDataFormat dataType) : PropertyDescriptor(DESCRIPTOR_TEXTURE),
                                                _type(type),
                                                _internalFormat(internalFormat),
                                                _dataType(dataType)
    {
        setDefaultValues();
    }

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

    ///Pixel alignment and miplevels are set to match what the HW sets by default
    inline void setDefaultValues(){
        setAlignment();
        setMipLevels();
        _layerCount = 1;
    }

    inline void setAlignment(U8 packAlignment = 1, U8 unpackAlignment = 1) {
        _packAlignment = packAlignment; _unpackAlignment = unpackAlignment;
    }

    inline void setMipLevels(U16 mipMinLevel = 0, U16 mipMaxLevel = 0) {
        _mipMinLevel = mipMinLevel; _mipMaxLevel = mipMaxLevel;
    }
    
    inline void setLayerCount(U8 layerCount){
        _layerCount = layerCount;
    }
    
    inline bool isCubeTexture() const {
        return (_type == TEXTURE_CUBE_MAP || _type == TEXTURE_CUBE_ARRAY);
    }

    ///A TextureDescriptor will always have a sampler, even if it is the default one
    inline       void               setSampler(const SamplerDescriptor& descriptor) {_samplerDescriptor = descriptor;}
    inline const SamplerDescriptor& getSampler()                              const {return _samplerDescriptor;}

    U8  _layerCount;
    U8  _packAlignment, _unpackAlignment; ///<Pixel store information
    U16 _mipMinLevel, _mipMaxLevel;       ///<MipMap interval selection

    ///Texture data information
    GFXImageFormat    _internalFormat;
    GFXDataFormat     _dataType;
    TextureType       _type;
    ///The sampler used to initialize this texture with
    SamplerDescriptor _samplerDescriptor;
};

#endif

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

Diff revisions: vs.
Revision Author Commited Message
286 Diff Diff IonutCava picture IonutCava Fri 18 Jul, 2014 16:32:03 +0000

[Ionut] [[BR]]

    • very buggy commit ** [[BR]]

- New rendering pipeline: [[BR]]
— Bumped OpenGL version to 4.4 [[BR]]
— Command based rendering. GFXDevice dispatches rendering commands to their respective buffers [[BR]]
— State changing is exclusively controlled by the GFXDevice class [[BR]]
— Material properties and transform matrices are stored in shader storage buffers that are updated after culling and uploaded once per RenderPass. Objects use drawIDs to index data in shaders [[BR]]
— Removed all custom matrices and other, per shader, bind data [[BR]]
— Removed per node light data. Light culling and shader buffers will replace the old light management system [[BR]]
— Framebuffers now use the Texture class for attachments [[BR]]
— Sampler objects now work like RenderStateBlocks. GL_API handles them and stores them in a hash indexed map [[BR]]
— Removed “prepareMaterial” calls. Pre-draw material setup is now only limited to texture binding [[BR]]
— Moved immediate mode emulation and primitive rendering from API level to GFXDevice level [[BR]]
— Framebuffer rendering must be completed with a call to end() to ensure proper MSAA resolve (asserts, otherwise) [[BR]]
- Fixed hash code generation for RenderStateBlock (and now, glSamplerObject) using boost::hash_combine [[BR]]
- Temporarily disabled XML caching for materials [[BR]]

269 Diff Diff IonutCava picture IonutCava Wed 04 Jun, 2014 12:56:45 +0000

[Ionut] [[BR]]
- All texture objects now properly allocate storage using glTextureStorage*D(w-w/o Multisampled) [[BR]]
- Removed useless “format” element from TextureDescriptor. Format is deduced from the internal format specified (RGBA8 uses RGBA. RG32F uses RG) [[BR]]
- Use GLM only with radians [[BR]]

263 Diff Diff k1ngp1n picture k1ngp1n Fri 09 May, 2014 16:43:53 +0000

[Ionut] [[BR]]
- Fullscreen quads are now rendered via Geometry Shaders [[BR]]
- Implemented shader subroutines [[BR]]
- Improved CVSM’s quality [[BR]]
- Separated shadow only light properties from general light properties in separate UBOs to improve update performance [[BR]]
- Removed shader mask and instead try to load all available shaders from a given file [[BR]]
- Added a method (hackish) of changing projection properties at runtime (e.g. z planes) [[BR]]
- Fixed a comparison bug in RenderStateBlock class (forgot to clean it at last commit) [[BR]]
- Fixed clipping plane upload to shader programs [[BR]]

260 Diff Diff k1ngp1n picture k1ngp1n Sat 03 May, 2014 19:33:41 +0000

[Ionut] [[BR]]
- More work on CSM. Reverted back to VSM to allow easier blurring and filtering [[BR]]
- Rewrote FrameBuffer classes to fix MSAA and memory leaks that occurred on resize (double creation of textures) [[BR]]
— Removed FBType. FrameBuffer types depend only on attachment types and if it’s MSAA enabled or not [[BR]]
- Rewrote RenderState classes to be API agnostic [[BR]]
- Bug fixes in math classes [[BR]]
- Changed “resolution change” logic [[BR]]
- Simplified some options in config.xml [[BR]]
- Improved per-light shadow options [[BR]]

259 Diff Diff k1ngp1n picture k1ngp1n Sun 27 Apr, 2014 18:24:52 +0000

[Ionut][[BR]]
- Implemented Exponential Stable Cascaded Shadow Maps for directional lights (still buggy, but basically working) [[BR]]
— CSM settings (resolution, number of splits, etc) are part of the scene render state [[BR]]
- SGN can skip rendering for the current frame if they are not ready (e.g. OnDraw can now return false or materials can fail to bind) [[BR]]
- Frustum class is now using the Plane class [[BR]]
- Removed Math SIMD implementation as the compiler generated code will always be faster and safer [[BR]]
- Added a “STUBBED” macro for outputing to the error stream of important messages (instead of using #pragma message) [[BR]]
- Added “freeze time” logic to pause/resume updates with or without freezing the GUI too [[BR]]
- Added “processGUI” method the every Scene class to separate time-sensitive GUI updates from game logic loop [[BR]]
- GLSL <-> Vertex Buffer bind locations are automatically set for every vertex shader [[BR]]
- Added basic support for compute shaders [[BR]]
- Removed most OS define checks to make porting to a new platform easier [[BR]]
- Texture transparency check per-pixel is now using OpenMP [[BR]]
- Texture samplers can now set a border color for CLAMP_TO_BORDER wrap mode [[BR]]
- Removed “Object” suffix from GFX Classes (pixel buffer, vertex buffer, frame buffer, etc) [[BR]]
- Stop processing scene input when application looses focus [[BR]]
- SceneGraphNode class is now responsible for updating SGNComponents on draw and calling its _node’s OnDraw method [[BR]]
- UBOs can now list all of the active uniforms inside a block with info such as type and offset [[BR]]
- Removed deprecated ‘GLCheck’ macro [[BR]]
- A lot of bug fixes and performance improvements in various places [[BR]]

223 Diff Diff k1ngp1n picture k1ngp1n Thu 09 Jan, 2014 15:55:04 +0000

[Ionut] [[BR]]
- Fixed most compatibility bugs on nVidia [[BR]]
— Removed the use of gl_Color in shaders [[BR]]
— Removed the use of GL_QUADS for VBOs [[BR]]
— Added VAO support to GLIM [[BR]]
— Hacked extension checking with GLEW (used glGetStringi for anisotropy and s3tc) [[BR]]
- Changed grass rendering to triangle strips (but disabled for now) [[BR]]
- Improved Transform class for more robustness [[BR]]
- Fixed transform related crash in SceneGraphNode when deleting a parentTransform [[BR]]
- Removed grandParent support in SceneGraphNode class as it was useless (getParent()->getParent() works just as well) [[BR]]

221 Diff Diff k1ngp1n picture k1ngp1n Wed 08 Jan, 2014 18:50:02 +0000

[Ionut] [[BR]]
- Merged branch “Shadows And Animations” back into trunk [[BR]]
- Added DoxygenGUI project file [[BR]]

  • Buggy *
171 Diff Diff k1ngp1n picture k1ngp1n Sun 03 Nov, 2013 18:15:06 +0000

-Replaced all tabs with spaces [[BR]]

168 Diff Diff k1ngp1n picture k1ngp1n Sat 26 Oct, 2013 19:03:21 +0000

- Reworked the Camera class[[BR]]
— Now fully quaternion based [[BR]]
— Basic camera types added but not used yet (third person, first person, orbit) [[BR]]
- Cleaned up Material and Texture handling [[BR]]
- Added clipping plane support [[BR]]
— Similar to OpenGL fixed-function clip planes but fully shader driven [[BR]]
— Added a new class, “Plane”, that helps define clip planes [[BR]]
- Optimized the Singleton class to allow faster “getInstance” calls without performance penalties [[BR]]
-- “createInstance” must be called for each singleton class before usage. Or “gerOrCreateInstance” can be used, which is basically the former “getInstance” implementation [[BR]]
- Improved console logging by changing some heap allocations to stack and removing dependencies on the std::string class [[BR]]
- Added a lot of performance optimizations related to coding standards and redundant calculations [[BR]]
— e.g. Frustum AABB check didn’t need to recompute the AABB points as they were calculated already [[BR]]
— e.g. A vector did not need to be set to 0 on initialization as that is already it’s default state on creation [[BR]]
— e.g. Faster Framerate and Timing calculations by using less member variables that are not needed outsied of calling functions [[BR]]
- The SceneState now contains the SceneRenderState and is passed on to the SceneGraph’s update calls [[BR]]
- Better material export/import to/from XML format [[BR]]
- More bug fixes and cleanups [[BR]]

160 k1ngp1n picture k1ngp1n Wed 10 Jul, 2013 17:07:04 +0000

[Ionut] [[BR]]
- Changed licensing from LGPL to the MIT license [[BR]]
— Code can now be used in non-commercial or commercial closed or open source projects [[BR]]