Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
texture.h
Go to the documentation of this file.
1 // * This file is part of the COLOBOT source code
2 // * Copyright (C) 2012, Polish Portal of Colobot (PPC)
3 // *
4 // * This program is free software: you can redistribute it and/or modify
5 // * it under the terms of the GNU General Public License as published by
6 // * the Free Software Foundation, either version 3 of the License, or
7 // * (at your option) any later version.
8 // *
9 // * This program is distributed in the hope that it will be useful,
10 // * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // * GNU General Public License for more details.
13 // *
14 // * You should have received a copy of the GNU General Public License
15 // * along with this program. If not, see http://www.gnu.org/licenses/.
16 
22 #pragma once
23 
24 
25 #include "graphics/core/color.h"
26 
27 #include "math/intpoint.h"
28 
29 
30 // Graphics module namespace
31 namespace Gfx {
32 
33 
39 {
50 };
51 
59 {
60  TEX_MIN_FILTER_NEAREST,
61  TEX_MIN_FILTER_LINEAR,
62  TEX_MIN_FILTER_NEAREST_MIPMAP_NEAREST,
63  TEX_MIN_FILTER_LINEAR_MIPMAP_NEAREST,
64  TEX_MIN_FILTER_NEAREST_MIPMAP_LINEAR,
65  TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR
66 };
67 
73 {
74  TEX_MAG_FILTER_NEAREST,
75  TEX_MAG_FILTER_LINEAR
76 };
77 
83 {
84  TEX_WRAP_CLAMP,
85  TEX_WRAP_REPEAT
86 };
87 
93 {
104 };
105 
111 {
120 };
121 
130 {
132  bool mipmap;
141 
144  { LoadDefault(); }
145 
147  inline void LoadDefault()
148  {
150  mipmap = false;
151  padToNearestPowerOfTwo = false;
152 
153  minFilter = TEX_MIN_FILTER_NEAREST;
154  magFilter = TEX_MAG_FILTER_NEAREST;
155  }
156 };
157 
166 {
185 
188  { LoadDefault(); }
189 
191  inline void LoadDefault()
192  {
196 
200 
201  wrapS = wrapT = TEX_WRAP_REPEAT;
202  }
203 };
204 
212 struct Texture
213 {
215  unsigned int id;
221  bool alpha;
222 
223  Texture()
224  {
225  id = 0;
226  alpha = false;
227  }
228 
230  bool Valid() const
231  {
232  return id != 0;
233  }
234 
236  void SetInvalid()
237  {
238  id = 0;
239  }
240 
242  inline bool operator<(const Texture &other) const
243  {
244  // Invalid textures are always "less than" every other texture
245 
246  if ( (! Valid()) && (! other.Valid()) )
247  return false;
248 
249  if (! Valid())
250  return true;
251 
252  if (! other.Valid())
253  return false;
254 
255  return id < other.id;
256  }
257 
259  inline bool operator==(const Texture &other) const
260  {
261  if (Valid() != other.Valid())
262  return false;
263  if ( (! Valid()) && (! other.Valid()) )
264  return true;
265 
266  return id == other.id;
267  }
268 };
269 
270 
271 } // namespace Gfx
272 
bool Valid() const
Returns whether the texture is valid (ID != 0)
Definition: texture.h:230
Try to determine automatically (may not work)
Definition: texture.h:41
bool mipmap
Whether to generate mipmaps.
Definition: texture.h:132
(Source) color of textured fragment (diffuse in DirectX; primary color in OpenGL) ...
Definition: texture.h:117
TexMixOperation
Multitexture mixing operation.
Definition: texture.h:92
bool operator<(const Texture &other) const
Comparator for use in texture maps and sets.
Definition: texture.h:242
TexMixArgument
Multitexture mixing argument.
Definition: texture.h:110
unsigned int id
ID of the texture in graphics engine; 0 = invalid texture.
Definition: texture.h:215
bool alpha
Whether the texture has alpha channel.
Definition: texture.h:221
Color from current texture.
Definition: texture.h:113
TexWrapMode
Wrapping mode for texture coords.
Definition: texture.h:82
Constant color (texture factor in DirectX; texture env color in OpenGL)
Definition: texture.h:119
TexMixOperation colorOperation
Mixing operation done on color values.
Definition: texture.h:168
Math::IntPoint size
Size of texture.
Definition: texture.h:217
TexMixArgument alphaArg1
1st argument of alpha operations
Definition: texture.h:176
TextureStageParams()
Constructor; calls LoadDefault()
Definition: texture.h:187
TexMagFilter
Texture magnification filter.
Definition: texture.h:72
Parameters for a texture unit.
Definition: texture.h:165
TexMagFilter magFilter
Magnification filter.
Definition: texture.h:138
bool operator==(const Texture &other) const
Comparator.
Definition: texture.h:259
TexMinFilter
Texture minification filter.
Definition: texture.h:58
Color computed by previous texture unit (current in DirectX; previous in OpenGL)
Definition: texture.h:115
RGBA triplet, 4 bytes.
Definition: texture.h:47
TexImgFormat format
Format of source image data.
Definition: texture.h:134
TexImgFormat
Format of image data.
Definition: texture.h:38
Color structs and related functions.
Parameters for texture creation.
Definition: texture.h:129
void SetInvalid()
Sets the ID to invalid value (0)
Definition: texture.h:236
TexMixArgument colorArg2
2nd argument of color operations
Definition: texture.h:172
Color factor
Constant color factor (for TEX_MIX_ARG_FACTOR)
Definition: texture.h:184
= Arg1 * Arg2
Definition: texture.h:99
TexMixArgument colorArg1
1st argument of color operations
Definition: texture.h:170
TexMixArgument alphaArg2
2nd argument of alpha operations
Definition: texture.h:178
BGR triplet, 3 bytes.
Definition: texture.h:45
= Arg1 + Arg2
Definition: texture.h:101
TexWrapMode wrapS
Wrap mode for 1st tex coord.
Definition: texture.h:180
bool padToNearestPowerOfTwo
Pad the image to nearest power of 2 dimensions.
Definition: texture.h:140
= Arg1 - Arg2
Definition: texture.h:103
Info about a texture.
Definition: texture.h:212
void LoadDefault()
Loads the default values.
Definition: texture.h:147
2D Point with integer coords
Definition: intpoint.h:35
Math::IntPoint originalSize
Original size of texture (as loaded from image)
Definition: texture.h:219
RGBA color.
Definition: color.h:35
void LoadDefault()
Loads the default values.
Definition: texture.h:191
TexWrapMode wrapT
Wrap mode for 2nd tex coord.
Definition: texture.h:182
BGRA triplet, 4 bytes.
Definition: texture.h:49
TextureCreateParams()
Constructor; calls LoadDefault()
Definition: texture.h:143
IntPoint struct.
= Arg1
Definition: texture.h:97
TexMinFilter minFilter
Minification filter.
Definition: texture.h:136
TexMixOperation alphaOperation
Mixing operation done on alpha values.
Definition: texture.h:174
Default operation on default params (modulate on computed & texture)
Definition: texture.h:95
RGB triplet, 3 bytes.
Definition: texture.h:43