Subversion Repository Public Repository

Divide-Framework

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

Diff Revisions 167 vs 168 for /trunk/Source Code/Hardware/Video/Textures/Headers/TextureDescriptor.h

Diff revisions: vs.
  @@ -24,49 +24,120 @@
24 24 #define _TEXTURE_DESCRIPTOR_H_
25 25
26 26 #include "core.h"
27 + #include "Core/Resources/Headers/ResourceDescriptor.h"
28 + #include "Hardware/Video/Headers/RenderAPIEnums.h"
27 29
28 - struct SamplerDescriptor {
29 - SamplerDescriptor()
30 + ///This class is used to define all of the sampler settings needed to use a texture
31 + ///Apply a sampler descriptor to either a texture's ResourceDescriptor or to a TextureDescriptor to use it
32 + ///We do not definy copy constructors as we must define descriptors only with POD
33 + class SamplerDescriptor : public PropertyDescriptor {
34 + public:
35 + ///The constructer specifies the type so it can be used later for downcasting if needed
36 + SamplerDescriptor() : PropertyDescriptor(DESCRIPTOR_SAMPLER)
30 37 {
38 + setDefaultValues();
31 39 }
32 40
33 - inline void setWrapMode(TextureWrap wrapU = TEXTURE_CLAMP, TextureWrap wrapV = TEXTURE_CLAMP, TextureWrap wrapW = TEXTURE_CLAMP){
34 - _wrapU = wrapU; _wrapV = wrapV; _wrapW = wrapW;
41 + ///All of these are default values that should be safe for any kind of texture usage
42 + inline void setDefaultValues() {
43 + setWrapMode();
44 + setFilters();
45 + setAnisotrophy(16);
46 + setLOD();
47 + toggleMipMaps(true);
48 + //The following 3 are mainly used by depthmaps for hardware comparisons
49 + _cmpFunc = CMP_FUNC_LEQUAL;
50 + _depthCompareMode = LUMINANCE;
51 + _useRefCompare = false;
52 +
35 53 }
36 54
37 - inline void setFilters(TextureFilter minFilter = TEXTURE_FILTER_LINEAR, TextureFilter magFilter = TEXTURE_FILTER_LINEAR){
38 - _minFilter = minFilter; _magFilter = magFilter;
55 + SamplerDescriptor* clone() const {return New SamplerDescriptor(*this);}
56 +
57 + /*
58 + * Sampler states (LOD, wrap modes, anisotrophy levels, etc
59 + */
60 + inline void setAnisotrophy(U8 value = 0) {_anisotrophyLevel = value;}
61 +
62 + inline void setLOD(F32 minLOD = -1000.f, F32 maxLOD = 1000.f, F32 biasLOD = 0.f){
63 + _minLOD = minLOD; _maxLOD = maxLOD; _biasLOD = biasLOD;
39 64 }
40 65
41 - inline void setAlignment(U8 packAlignment = 1, U8 unpackAlignment = 1) {
42 - _packAlignment = packAlignment; _unpackAlignment = unpackAlignment;
66 + inline void setWrapMode(TextureWrap wrapUVW = TEXTURE_REPEAT){
67 + setWrapModeU(wrapUVW);
68 + setWrapModeV(wrapUVW);
69 + setWrapModeW(wrapUVW);
43 70 }
44 71
45 - inline void setMipLevels(U16 mipMinLevel = 0, U16 mipMaxLevel = 1000) {
46 - _mipMinLevel = mipMinLevel; _mipMaxLevel = mipMaxLevel;
72 + inline void setWrapMode(TextureWrap wrapU, TextureWrap wrapV, TextureWrap wrapW = TEXTURE_REPEAT){
73 + setWrapModeU(wrapU);
74 + setWrapModeV(wrapV);
75 + setWrapModeW(wrapW);
76 + }
77 +
78 + inline void setWrapMode(I32 wrapU, I32 wrapV, I32 wrapW){
79 + setWrapMode(static_cast<TextureWrap>(wrapU), static_cast<TextureWrap>(wrapV), static_cast<TextureWrap>(wrapW));
80 + }
81 +
82 + inline void setWrapModeU(TextureWrap wrapU) { _wrapU = wrapU; }
83 + inline void setWrapModeV(TextureWrap wrapV) { _wrapV = wrapV; }
84 + inline void setWrapModeW(TextureWrap wrapW) { _wrapW = wrapW; }
85 +
86 +
87 + inline void setFilters(TextureFilter minFilter = TEXTURE_FILTER_LINEAR, TextureFilter magFilter = TEXTURE_FILTER_LINEAR){
88 + setMinFilter(minFilter);
89 + setMagFilter(magFilter);
47 90 }
48 91
49 - inline void toggleMipMaps(bool state) {_generateMipMaps = state;}
50 - inline void setAnisotrophy(U8 value) {_anisotrophyLevel = value;}
92 + inline void setMinFilter(TextureFilter minFilter) {_minFilter = minFilter;}
93 + inline void setMagFilter(TextureFilter magFilter) {_magFilter = magFilter;}
51 94
52 - TextureFilter _minFilter;
53 - TextureFilter _magFilter;
54 - TextureWrap _wrapU;
55 - TextureWrap _wrapV;
56 - TextureWrap _wrapW;
57 - bool _generateMipMaps; ///<create automatic MipMaps
58 - bool _useRefCompare; ///<use red channel as comparison (e.g. for shadows)
59 - U8 _anisotrophyLevel;
60 - U8 _packAlignment;
61 - U8 _unpackAlignment;
62 - U16 _mipMinLevel;
63 - U16 _mipMaxLevel;
95 + inline void toggleMipMaps(bool state) {
96 + _generateMipMaps = state;
97 + if(state){
98 + if(_minFilter == TEXTURE_FILTER_LINEAR)
99 + _minFilter = TEXTURE_FILTER_LINEAR_MIPMAP_LINEAR;
100 + }else{
101 + if(_minFilter == TEXTURE_FILTER_LINEAR_MIPMAP_LINEAR)
102 + _minFilter = TEXTURE_FILTER_LINEAR;
103 + }
104 + }
105 +
106 + /*
107 + * "Internal" data
108 + */
109 +
110 + //HW comparison settings
111 + GFXImageFormat _depthCompareMode; ///<Used as the basis for DEPTH_TEXTURE_MODE
112 + ComparisonFunction _cmpFunc; ///<Used by RefCompare
113 + bool _useRefCompare; ///<use red channel as comparison (e.g. for shadows)
114 +
115 + inline TextureWrap wrapU() const {return _wrapU;}
116 + inline TextureWrap wrapV() const {return _wrapV;}
117 + inline TextureWrap wrapW() const {return _wrapW;}
118 + inline TextureFilter minFilter() const {return _minFilter;}
119 + inline TextureFilter magFilter() const {return _magFilter;}
120 + inline F32 minLOD() const {return _minLOD;}
121 + inline F32 maxLOD() const {return _maxLOD;}
122 + inline F32 biasLOD() const {return _biasLOD;}
123 + inline U8 anisotrophyLevel() const {return _anisotrophyLevel;}
124 + inline bool generateMipMaps() const {return _generateMipMaps;}
125 + protected:
126 + //Sampler states
127 + TextureFilter _minFilter, _magFilter; ///Texture filtering mode
128 + TextureWrap _wrapU, _wrapV, _wrapW; ///<Or S-R-T
129 + bool _generateMipMaps; ///<If it's set to true we create automatic MipMaps
130 + U8 _anisotrophyLevel; ///<The value must be in the range [0...255] and is automatically clamped by the max HW supported level
131 + F32 _minLOD,_maxLOD; ///<OpenGL eg: used by TEXTURE_MIN_LOD and TEXTURE_MAX_LOD
132 + F32 _biasLOD; ///<OpenGL eg: used by TEXTURE_LOD_BIAS
64 133
65 - ComparisonFunction _cmpFunc; ///<Used by RefCompare
66 134 };
67 135
68 136 ///Use to define a texture with details such as type, image formats, etc
69 - struct TextureDescriptor {
137 + ///We do not definy copy constructors as we must define descriptors only with POD
138 + class TextureDescriptor : public PropertyDescriptor {
139 + public:
140 + ///This enum is used when creating Frame Buffers to define the channel that the texture will attach to
70 141 enum AttachmentType{
71 142 Color0 = 0,
72 143 Color1,
  @@ -74,14 +145,12 @@
74 145 Color3,
75 146 Depth
76 147 };
77 -
78 - TextureDescriptor() : _type(TextureType_PLACEHOLDER),
148 +
149 + TextureDescriptor() : PropertyDescriptor(DESCRIPTOR_TEXTURE),
150 + _type(TextureType_PLACEHOLDER),
79 151 _format(IMAGE_FORMAT_PLACEHOLDER),
80 152 _internalFormat(IMAGE_FORMAT_PLACEHOLDER),
81 - _dataType(GDF_PLACEHOLDER),
82 - _generateMipMaps(true),
83 - _useRefCompare(false),
84 - _anisotrophyLevel(0)
153 + _dataType(GDF_PLACEHOLDER)
85 154 {
86 155 setDefaultValues();
87 156 }
  @@ -89,63 +158,45 @@
89 158 TextureDescriptor(TextureType type,
90 159 GFXImageFormat format,
91 160 GFXImageFormat internalFormat,
92 - GFXDataFormat dataType) : _type(type),
93 - _format(format),
161 + GFXDataFormat dataType) : PropertyDescriptor(DESCRIPTOR_TEXTURE),
162 + _type(type),
163 + _format(format),
94 164 _internalFormat(internalFormat),
95 - _dataType(dataType),
96 - _generateMipMaps(true),
97 - _useRefCompare(false),
98 - _anisotrophyLevel(0)
165 + _dataType(dataType)
99 166 {
100 167 setDefaultValues();
101 168 }
102 169
170 + TextureDescriptor* clone() const {return New TextureDescriptor(*this);}
171 +
172 + ///Pixel alignment and miplevels are set to match what the HW sets by default
103 173 inline void setDefaultValues(){
104 - setWrapMode();
105 - setFilters();
106 174 setAlignment();
107 175 setMipLevels();
108 - _cmpFunc = CMP_FUNC_LEQUAL;
109 - }
110 -
111 - inline void setWrapMode(TextureWrap wrapU = TEXTURE_CLAMP, TextureWrap wrapV = TEXTURE_CLAMP, TextureWrap wrapW = TEXTURE_CLAMP){
112 - _wrapU = wrapU; _wrapV = wrapV; _wrapW = wrapW;
113 - }
114 -
115 - inline void setFilters(TextureFilter minFilter = TEXTURE_FILTER_LINEAR, TextureFilter magFilter = TEXTURE_FILTER_LINEAR){
116 - _minFilter = minFilter; _magFilter = magFilter;
117 176 }
118 177
119 178 inline void setAlignment(U8 packAlignment = 1, U8 unpackAlignment = 1) {
120 179 _packAlignment = packAlignment; _unpackAlignment = unpackAlignment;
121 180 }
122 -
181 +
123 182 inline void setMipLevels(U16 mipMinLevel = 0, U16 mipMaxLevel = 1000) {
124 183 _mipMinLevel = mipMinLevel; _mipMaxLevel = mipMaxLevel;
125 184 }
185 + ///A TextureDescriptor will always have a sampler, even if it is the default one
186 + inline void setSampler(const SamplerDescriptor& descriptor) {_samplerDescriptor = descriptor;}
187 + inline const SamplerDescriptor& getSampler() const {return _samplerDescriptor;}
126 188
127 - inline void toggleMipMaps(bool state) {_generateMipMaps = state;}
128 - inline void setAnisotrophy(U8 value) {_anisotrophyLevel = value;}
129 -
130 - GFXImageFormat _format;
131 - GFXImageFormat _internalFormat;
132 - GFXImageFormat _depthCompareMode;
133 - GFXDataFormat _dataType;
134 - TextureType _type;
135 - TextureFilter _minFilter;
136 - TextureFilter _magFilter;
137 - TextureWrap _wrapU;
138 - TextureWrap _wrapV;
139 - TextureWrap _wrapW;
140 - bool _generateMipMaps; ///<create automatic MipMaps
141 - bool _useRefCompare; ///<use red channel as comparison (e.g. for shadows)
142 - U8 _anisotrophyLevel;
143 - U8 _packAlignment;
144 - U8 _unpackAlignment;
145 - U16 _mipMinLevel;
146 - U16 _mipMaxLevel;
147 189
148 - ComparisonFunction _cmpFunc; ///<Used by RefCompare
190 + U8 _packAlignment, _unpackAlignment; ///<Pixel stor information
191 + U16 _mipMinLevel, _mipMaxLevel; ///<MipMap interval selection
192 +
193 + ///Texture data information
194 + GFXImageFormat _format;
195 + GFXImageFormat _internalFormat;
196 + GFXDataFormat _dataType;
197 + TextureType _type;
198 + ///The sampler used to initialize this texture with
199 + SamplerDescriptor _samplerDescriptor;
149 200 };
150 201
151 202 #endif