Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
texture.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
25 #pragma once
26 
27 
28 #include "graphics/core/color.h"
29 
30 #include "math/intpoint.h"
31 
32 
33 // Graphics module namespace
34 namespace Gfx {
35 
36 
42 {
53 };
54 
62 {
63  TEX_FILTER_NEAREST,
64  TEX_FILTER_BILINEAR,
65  TEX_FILTER_TRILINEAR
66 };
67 
75 {
76  TEX_MIN_FILTER_NEAREST,
77  TEX_MIN_FILTER_LINEAR,
78  TEX_MIN_FILTER_NEAREST_MIPMAP_NEAREST,
79  TEX_MIN_FILTER_LINEAR_MIPMAP_NEAREST,
80  TEX_MIN_FILTER_NEAREST_MIPMAP_LINEAR,
81  TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR
82 };
83 
89 {
90  TEX_MAG_FILTER_NEAREST,
91  TEX_MAG_FILTER_LINEAR
92 };
93 
99 {
100  TEX_WRAP_CLAMP,
101  TEX_WRAP_CLAMP_TO_BORDER,
102  TEX_WRAP_REPEAT
103 };
104 
110 {
121 };
122 
128 {
145 };
146 
155 {
157  bool mipmap;
164 
167  { LoadDefault(); }
168 
170  inline void LoadDefault()
171  {
172  format = TEX_IMG_RGB;
173  mipmap = false;
174  padToNearestPowerOfTwo = false;
175 
176  filter = TEX_FILTER_NEAREST;
177  }
178 };
179 
188 {
207 
210  { LoadDefault(); }
211 
213  inline void LoadDefault()
214  {
215  colorOperation = TEX_MIX_OPER_DEFAULT;
216  colorArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
217  colorArg2 = TEX_MIX_ARG_TEXTURE;
218 
219  alphaOperation = TEX_MIX_OPER_DEFAULT;
220  alphaArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
221  alphaArg2 = TEX_MIX_ARG_TEXTURE;
222 
223  wrapS = wrapT = TEX_WRAP_REPEAT;
224  }
225 };
226 
232 {
245 };
246 
254 {
255  struct
256  {
257  TexGenMode mode;
258  float plane[4];
259  } coords[4];
260 
262  {
263  LoadDefault();
264  }
265 
266  inline void LoadDefault()
267  {
268  for (int i = 0; i < 4; i++)
269  {
270  coords[i].mode = TEX_GEN_NONE;
271  }
272  }
273 };
274 
282 struct Texture
283 {
285  unsigned int id;
291  bool alpha;
292 
293  Texture()
294  {
295  id = 0;
296  alpha = false;
297  }
298 
300  bool Valid() const
301  {
302  return id != 0;
303  }
304 
306  void SetInvalid()
307  {
308  id = 0;
309  }
310 
312  inline bool operator<(const Texture &other) const
313  {
314  // Invalid textures are always "less than" every other texture
315 
316  if ( (! Valid()) && (! other.Valid()) )
317  return false;
318 
319  if (! Valid())
320  return true;
321 
322  if (! other.Valid())
323  return false;
324 
325  return id < other.id;
326  }
327 
329  inline bool operator==(const Texture &other) const
330  {
331  if (Valid() != other.Valid())
332  return false;
333  if ( (! Valid()) && (! other.Valid()) )
334  return true;
335 
336  return id == other.id;
337  }
338 };
339 
340 
341 } // namespace Gfx
342 
Color from texture unit 1.
Definition: texture.h:134
bool Valid() const
Returns whether the texture is valid (ID != 0)
Definition: texture.h:300
Try to determine automatically (may not work)
Definition: texture.h:44
bool mipmap
Whether to generate mipmaps.
Definition: texture.h:157
(Source) color of textured fragment (diffuse in DirectX; primary color in OpenGL) ...
Definition: texture.h:142
TexMixOperation
Multitexture mixing operation.
Definition: texture.h:109
bool operator<(const Texture &other) const
Comparator for use in texture maps and sets.
Definition: texture.h:312
TexMixArgument
Multitexture mixing argument.
Definition: texture.h:127
Texture generation mode.
unsigned int id
ID of the texture in graphics engine; 0 = invalid texture.
Definition: texture.h:285
bool alpha
Whether the texture has alpha channel.
Definition: texture.h:291
Color from current texture.
Definition: texture.h:130
TexWrapMode
Wrapping mode for texture coords.
Definition: texture.h:98
Normal mapping mode.
Definition: texture.h:242
Constant color (texture factor in DirectX; texture env color in OpenGL)
Definition: texture.h:144
TexMixOperation colorOperation
Mixing operation done on color values.
Definition: texture.h:190
Math::IntPoint size
Size of texture.
Definition: texture.h:287
Color from texture unit 2.
Definition: texture.h:136
TexMixArgument alphaArg1
1st argument of alpha operations
Definition: texture.h:198
TextureStageParams()
Constructor; calls LoadDefault()
Definition: texture.h:209
TexMagFilter
Texture magnification filter.
Definition: texture.h:88
Parameters for a texture unit.
Definition: texture.h:187
Color from texture unit 3.
Definition: texture.h:138
bool operator==(const Texture &other) const
Comparator.
Definition: texture.h:329
TexMinFilter
Texture minification filter.
Definition: texture.h:74
Color computed by previous texture unit (current in DirectX; previous in OpenGL)
Definition: texture.h:140
RGBA triplet, 4 bytes.
Definition: texture.h:50
TexImgFormat format
Format of source image data.
Definition: texture.h:159
Parameters for texture coordinate generation.
Definition: texture.h:253
Eye linear mode.
Definition: texture.h:238
TexImgFormat
Format of image data.
Definition: texture.h:41
Spherical mapping mode.
Definition: texture.h:240
Color structs and related functions.
Parameters for texture creation.
Definition: texture.h:154
Color from texture unit 0.
Definition: texture.h:132
void SetInvalid()
Sets the ID to invalid value (0)
Definition: texture.h:306
TexFilter filter
General texture filtering mode.
Definition: texture.h:161
TexMixArgument colorArg2
2nd argument of color operations
Definition: texture.h:194
Color factor
Constant color factor (for TEX_MIX_ARG_FACTOR)
Definition: texture.h:206
= Arg1 * Arg2
Definition: texture.h:116
TexMixArgument colorArg1
1st argument of color operations
Definition: texture.h:192
TexMixArgument alphaArg2
2nd argument of alpha operations
Definition: texture.h:200
BGR triplet, 3 bytes.
Definition: texture.h:48
= Arg1 + Arg2
Definition: texture.h:118
TexWrapMode wrapS
Wrap mode for 1st tex coord.
Definition: texture.h:202
bool padToNearestPowerOfTwo
Pad the image to nearest power of 2 dimensions.
Definition: texture.h:163
Namespace for (new) graphics code.
Definition: app.h:49
No texture generation.
Definition: texture.h:234
= Arg1 - Arg2
Definition: texture.h:120
Info about a texture.
Definition: texture.h:282
TexFilter
General texture filtering mode.
Definition: texture.h:61
void LoadDefault()
Loads the default values.
Definition: texture.h:170
Reflection mapping mode.
Definition: texture.h:244
2D Point with integer coords
Definition: intpoint.h:38
Math::IntPoint originalSize
Original size of texture (as loaded from image)
Definition: texture.h:289
RGBA color.
Definition: color.h:38
void LoadDefault()
Loads the default values.
Definition: texture.h:213
TexWrapMode wrapT
Wrap mode for 2nd tex coord.
Definition: texture.h:204
BGRA triplet, 4 bytes.
Definition: texture.h:52
TextureCreateParams()
Constructor; calls LoadDefault()
Definition: texture.h:166
IntPoint struct.
= Arg1
Definition: texture.h:114
TexMixOperation alphaOperation
Mixing operation done on alpha values.
Definition: texture.h:196
Default operation on default params (modulate on computed & texture)
Definition: texture.h:112
RGB triplet, 3 bytes.
Definition: texture.h:46
Object linear mode.
Definition: texture.h:236