1 /** @file texturevariantspec.h  Texture resource, variant specification.
2  *
3  * @authors Copyright © 2011-2013 Daniel Swanson <danij@dengine.net>
4  *
5  * @par License
6  * GPL: http://www.gnu.org/licenses/gpl.html
7  *
8  * <small>This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by the
10  * Free Software Foundation; either version 2 of the License, or (at your
11  * option) any later version. This program is distributed in the hope that it
12  * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14  * Public License for more details. You should have received a copy of the GNU
15  * General Public License along with this program; if not, write to the Free
16  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17  * 02110-1301 USA</small>
18  */
19 
20 #ifndef DENG_RESOURCE_TEXTUREVARIANTSPEC_H
21 #define DENG_RESOURCE_TEXTUREVARIANTSPEC_H
22 
23 #ifndef __CLIENT__
24 #  error "resource/texturevariantspec.h only exists in the Client"
25 #endif
26 
27 #include "dd_types.h"
28 //#include "gl/sys_opengl.h"
29 #include <de/String>
30 
31 typedef enum {
32     TC_UNKNOWN = -1,
33     TEXTUREVARIANTUSAGECONTEXT_FIRST = 0,
34     TC_UI = TEXTUREVARIANTUSAGECONTEXT_FIRST,
35     TC_MAPSURFACE_DIFFUSE,
36     TC_MAPSURFACE_REFLECTION,
37     TC_MAPSURFACE_REFLECTIONMASK,
38     TC_MAPSURFACE_LIGHTMAP,
39     TC_SPRITE_DIFFUSE,
40     TC_MODELSKIN_DIFFUSE,
41     TC_MODELSKIN_REFLECTION,
42     TC_HALO_LUMINANCE,
43     TC_PSPRITE_DIFFUSE,
44     TC_SKYSPHERE_DIFFUSE,
45     TEXTUREVARIANTUSAGECONTEXT_LAST = TC_SKYSPHERE_DIFFUSE
46 } texturevariantusagecontext_t;
47 
48 #define TEXTUREVARIANTUSAGECONTEXT_COUNT (\
49     TEXTUREVARIANTUSAGECONTEXT_LAST + 1 - TEXTUREVARIANTUSAGECONTEXT_FIRST )
50 
51 #define VALID_TEXTUREVARIANTUSAGECONTEXT(tc) (\
52     (tc) >= TEXTUREVARIANTUSAGECONTEXT_FIRST && (tc) <= TEXTUREVARIANTUSAGECONTEXT_LAST)
53 
54 /**
55  * @defgroup textureVariantSpecificationFlags  Texture Variant Specification Flags
56  * @ingroup flags
57  */
58 /*@{*/
59 #define TSF_ZEROMASK                0x1 // Set pixel alpha to fully opaque.
60 #define TSF_NO_COMPRESSION          0x2
61 #define TSF_UPSCALE_AND_SHARPEN     0x4
62 #define TSF_MONOCHROME              0x8
63 
64 #define TSF_INTERNAL_MASK           0xff000000
65 #define TSF_HAS_COLORPALETTE_XLAT   0x80000000
66 /*@}*/
67 
68 struct variantspecification_t
69 {
70     texturevariantusagecontext_t context;
71     int flags; /// @ref textureVariantSpecificationFlags
72     byte border; /// In pixels, added to all four edges of the texture.
73     int wrapS, wrapT;
74     dd_bool mipmapped, gammaCorrection, noStretch, toAlpha;
75 
76     /**
77      * Minification filter modes. Specified using either a logical
78      * texture class id (actual mode used is then determined by the
79      * user's preference for that class) or a constant value.
80      *
81      * Texture class:
82      * -1: No class
83      *
84      * Constant:
85      * 0: Nearest or Nearest-Mipmap-Nearest (if mipmapping)
86      * 1: Linear  or Linear-Mipmap-Nearest (if mipmapping)
87      * 2: Nearest-Mipmap-Linear (mipmapping only)
88      * 3: Linear-Mipmap-Linear (mipmapping only)
89      */
90     int minFilter;
91 
92     /**
93      * Magnification filter modes. Specified using either a logical
94      * texture class id (actual mode used is then determined by the
95      * user's preference for that class) or a constant value.
96      *
97      * Texture class:
98      * -3: UI class
99      * -2: Sprite class
100      * -1: No class
101      *
102      * Constant:
103      * 0: Nearest (in Manhattan distance)
104      * 1: Linear (weighted average)
105      */
106     int magFilter;
107 
108     /// -1: User preference else a logical DGL anisotropic filter level.
109     int anisoFilter;
110 
111     /// Color palette translation.
112     int tClass, tMap;
113 
114     int glMinFilter() const;
115     int glMagFilter() const;
116     int logicalAnisoLevel() const;
117 
118     variantspecification_t();
119     variantspecification_t(variantspecification_t const &other);
120 
121     /**
122      * Magnification, Anisotropic filter level and GL texture wrap modes are
123      * handled through dynamic changes to GL's texture environment state.
124      * Consequently, they are ignored during spec equality comparison.
125      */
126     bool operator == (variantspecification_t const &other) const;
127 
128     inline bool operator != (variantspecification_t const &other) const {
129         return !(*this == other);
130     }
131 };
132 
133 /**
134  * Detail textures are faded to gray depending on the contrast factor.
135  * The texture is also progressively faded towards gray in each mipmap
136  * level uploaded.
137  *
138  * Contrast is quantized in order to reduce the number of variants to
139  * a more sensible/manageable number per texture.
140  */
141 #define DETAILTEXTURE_CONTRAST_QUANTIZATION_FACTOR  (10)
142 
143 struct detailvariantspecification_t
144 {
145     uint8_t contrast;
146 
147     bool operator == (detailvariantspecification_t const &other) const;
148 
149     inline bool operator != (detailvariantspecification_t const &other) const {
150         return !(*this == other);
151     }
152 };
153 
154 enum texturevariantspecificationtype_t
155 {
156     TST_GENERAL,
157     TST_DETAIL
158 };
159 
160 class TextureVariantSpec
161 {
162 public:
163     texturevariantspecificationtype_t type;
164     variantspecification_t variant;
165     detailvariantspecification_t detailVariant;
166 
167 public:
168     TextureVariantSpec(texturevariantspecificationtype_t type = TST_GENERAL);
169     TextureVariantSpec(TextureVariantSpec const &other);
170 
171     bool operator == (TextureVariantSpec const &other) const;
172 
173     inline bool operator != (TextureVariantSpec const &other) const {
174         return !(*this == other);
175     }
176 
177     /**
178      * Returns a textual, human-readable representation of the specification.
179      */
180     de::String asText() const;
181 };
182 
183 #endif // DENG_RESOURCE_TEXTUREVARIANTSPEC_H
184