2012-06-30 23:37:30 +00:00
|
|
|
// * This file is part of the COLOBOT source code
|
|
|
|
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
|
|
|
|
// *
|
|
|
|
// * This program is free software: you can redistribute it and/or modify
|
|
|
|
// * it under the terms of the GNU General Public License as published by
|
|
|
|
// * the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// * (at your option) any later version.
|
|
|
|
// *
|
|
|
|
// * This program is distributed in the hope that it will be useful,
|
|
|
|
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// * GNU General Public License for more details.
|
|
|
|
// *
|
|
|
|
// * You should have received a copy of the GNU General Public License
|
|
|
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
|
|
|
|
2012-08-11 16:39:16 +00:00
|
|
|
/**
|
|
|
|
* \file graphics/core/texture.h
|
|
|
|
* \brief Texture struct and related enums
|
|
|
|
*/
|
2012-06-30 23:37:30 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2012-09-19 21:50:28 +00:00
|
|
|
|
2012-09-29 20:44:05 +00:00
|
|
|
#include "graphics/core/color.h"
|
|
|
|
|
2012-08-11 15:17:04 +00:00
|
|
|
#include "math/intpoint.h"
|
2012-07-29 13:09:53 +00:00
|
|
|
|
|
|
|
|
2012-09-19 21:50:28 +00:00
|
|
|
// Graphics module namespace
|
2012-06-30 23:37:30 +00:00
|
|
|
namespace Gfx {
|
|
|
|
|
2012-09-29 08:40:11 +00:00
|
|
|
|
2012-07-16 17:17:26 +00:00
|
|
|
/**
|
2012-09-19 21:50:28 +00:00
|
|
|
* \enum TexImgFormat
|
|
|
|
* \brief Format of image data
|
|
|
|
*/
|
2012-07-16 17:17:26 +00:00
|
|
|
enum TexImgFormat
|
|
|
|
{
|
2012-07-24 22:27:01 +00:00
|
|
|
//! Try to determine automatically (may not work)
|
|
|
|
TEX_IMG_AUTO,
|
|
|
|
//! RGB triplet, 3 bytes
|
2012-07-16 17:17:26 +00:00
|
|
|
TEX_IMG_RGB,
|
2012-07-24 22:27:01 +00:00
|
|
|
//! BGR triplet, 3 bytes
|
2012-07-16 17:17:26 +00:00
|
|
|
TEX_IMG_BGR,
|
2012-07-24 22:27:01 +00:00
|
|
|
//! RGBA triplet, 4 bytes
|
2012-07-16 17:17:26 +00:00
|
|
|
TEX_IMG_RGBA,
|
2012-07-24 22:27:01 +00:00
|
|
|
//! BGRA triplet, 4 bytes
|
2012-07-16 17:17:26 +00:00
|
|
|
TEX_IMG_BGRA
|
|
|
|
};
|
|
|
|
|
2012-07-06 17:00:22 +00:00
|
|
|
/**
|
2012-09-19 21:50:28 +00:00
|
|
|
* \enum TexMinFilter
|
|
|
|
* \brief Texture minification filter
|
|
|
|
*
|
|
|
|
* Corresponds to OpenGL modes but should translate to DirectX too.
|
|
|
|
*/
|
2012-07-06 17:00:22 +00:00
|
|
|
enum TexMinFilter
|
|
|
|
{
|
|
|
|
TEX_MIN_FILTER_NEAREST,
|
|
|
|
TEX_MIN_FILTER_LINEAR,
|
|
|
|
TEX_MIN_FILTER_NEAREST_MIPMAP_NEAREST,
|
|
|
|
TEX_MIN_FILTER_LINEAR_MIPMAP_NEAREST,
|
|
|
|
TEX_MIN_FILTER_NEAREST_MIPMAP_LINEAR,
|
|
|
|
TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-09-19 21:50:28 +00:00
|
|
|
* \enum TexMagFilter
|
|
|
|
* \brief Texture magnification filter
|
|
|
|
*/
|
2012-07-06 17:00:22 +00:00
|
|
|
enum TexMagFilter
|
|
|
|
{
|
|
|
|
TEX_MAG_FILTER_NEAREST,
|
|
|
|
TEX_MAG_FILTER_LINEAR
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-09-19 21:50:28 +00:00
|
|
|
* \enum TexWrapMode
|
|
|
|
* \brief Wrapping mode for texture coords
|
|
|
|
*/
|
2012-07-06 17:00:22 +00:00
|
|
|
enum TexWrapMode
|
|
|
|
{
|
|
|
|
TEX_WRAP_CLAMP,
|
|
|
|
TEX_WRAP_REPEAT
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-09-19 21:50:28 +00:00
|
|
|
* \enum TexMixOperation
|
|
|
|
* \brief Multitexture mixing operation
|
|
|
|
*/
|
2012-07-06 17:00:22 +00:00
|
|
|
enum TexMixOperation
|
|
|
|
{
|
2012-07-24 22:27:01 +00:00
|
|
|
//! Default operation on default params (modulate on computed & texture)
|
|
|
|
TEX_MIX_OPER_DEFAULT,
|
|
|
|
//! = Arg1
|
|
|
|
TEX_MIX_OPER_REPLACE,
|
|
|
|
//! = Arg1 * Arg2
|
2012-07-06 17:00:22 +00:00
|
|
|
TEX_MIX_OPER_MODULATE,
|
2012-07-24 22:27:01 +00:00
|
|
|
//! = Arg1 + Arg2
|
|
|
|
TEX_MIX_OPER_ADD,
|
|
|
|
//! = Arg1 - Arg2
|
|
|
|
TEX_MIX_OPER_SUBTRACT
|
2012-07-06 17:00:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-09-19 21:50:28 +00:00
|
|
|
* \enum TexMixArgument
|
|
|
|
* \brief Multitexture mixing argument
|
|
|
|
*/
|
2012-07-06 17:00:22 +00:00
|
|
|
enum TexMixArgument
|
|
|
|
{
|
2012-07-24 22:27:01 +00:00
|
|
|
//! Color from current texture
|
2012-07-06 17:00:22 +00:00
|
|
|
TEX_MIX_ARG_TEXTURE,
|
2012-07-24 22:27:01 +00:00
|
|
|
//! Color computed by previous texture unit (current in DirectX; previous in OpenGL)
|
|
|
|
TEX_MIX_ARG_COMPUTED_COLOR,
|
|
|
|
//! (Source) color of textured fragment (diffuse in DirectX; primary color in OpenGL)
|
|
|
|
TEX_MIX_ARG_SRC_COLOR,
|
|
|
|
//! Constant color (texture factor in DirectX; texture env color in OpenGL)
|
2012-07-06 17:00:22 +00:00
|
|
|
TEX_MIX_ARG_FACTOR
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-09-29 08:40:11 +00:00
|
|
|
* \struct TextureCreateParams
|
|
|
|
* \brief Parameters for texture creation
|
|
|
|
*
|
|
|
|
* These params define how particular texture is created and later displayed.
|
|
|
|
* They must be specified at texture creation time and cannot be changed later.
|
|
|
|
*/
|
2012-07-06 17:00:22 +00:00
|
|
|
struct TextureCreateParams
|
|
|
|
{
|
|
|
|
//! Whether to generate mipmaps
|
|
|
|
bool mipmap;
|
2012-07-16 17:17:26 +00:00
|
|
|
//! Format of source image data
|
2012-09-19 21:50:28 +00:00
|
|
|
TexImgFormat format;
|
2012-07-06 17:00:22 +00:00
|
|
|
//! Minification filter
|
2012-09-19 21:50:28 +00:00
|
|
|
TexMinFilter minFilter;
|
2012-07-06 17:00:22 +00:00
|
|
|
//! Magnification filter
|
2012-09-19 21:50:28 +00:00
|
|
|
TexMagFilter magFilter;
|
2013-05-11 21:05:20 +00:00
|
|
|
//! Pad the image to nearest power of 2 dimensions
|
|
|
|
bool padToNearestPowerOfTwo;
|
2012-07-06 17:00:22 +00:00
|
|
|
|
|
|
|
//! Constructor; calls LoadDefault()
|
|
|
|
TextureCreateParams()
|
|
|
|
{ LoadDefault(); }
|
|
|
|
|
|
|
|
//! Loads the default values
|
2012-07-16 17:17:26 +00:00
|
|
|
inline void LoadDefault()
|
|
|
|
{
|
2012-09-19 21:50:28 +00:00
|
|
|
format = TEX_IMG_RGB;
|
2012-07-16 17:17:26 +00:00
|
|
|
mipmap = false;
|
2013-05-11 21:05:20 +00:00
|
|
|
padToNearestPowerOfTwo = false;
|
2012-07-16 17:17:26 +00:00
|
|
|
|
2012-09-19 21:50:28 +00:00
|
|
|
minFilter = TEX_MIN_FILTER_NEAREST;
|
|
|
|
magFilter = TEX_MAG_FILTER_NEAREST;
|
2012-07-16 17:17:26 +00:00
|
|
|
}
|
2012-07-06 17:00:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-09-29 08:40:11 +00:00
|
|
|
* \struct TextureStageParams
|
|
|
|
* \brief Parameters for a texture unit
|
|
|
|
*
|
|
|
|
* These params define the behavior of texturing units (stages).
|
|
|
|
* They can be changed freely and are features of graphics engine, not any particular texture.
|
|
|
|
*/
|
2012-07-24 22:27:01 +00:00
|
|
|
struct TextureStageParams
|
2012-07-06 17:00:22 +00:00
|
|
|
{
|
|
|
|
//! Mixing operation done on color values
|
2012-09-19 21:50:28 +00:00
|
|
|
TexMixOperation colorOperation;
|
2012-07-06 17:00:22 +00:00
|
|
|
//! 1st argument of color operations
|
2012-09-19 21:50:28 +00:00
|
|
|
TexMixArgument colorArg1;
|
2012-07-06 17:00:22 +00:00
|
|
|
//! 2nd argument of color operations
|
2012-09-19 21:50:28 +00:00
|
|
|
TexMixArgument colorArg2;
|
2012-07-06 17:00:22 +00:00
|
|
|
//! Mixing operation done on alpha values
|
2012-09-19 21:50:28 +00:00
|
|
|
TexMixOperation alphaOperation;
|
2012-07-06 17:00:22 +00:00
|
|
|
//! 1st argument of alpha operations
|
2012-09-19 21:50:28 +00:00
|
|
|
TexMixArgument alphaArg1;
|
2012-07-06 17:00:22 +00:00
|
|
|
//! 2nd argument of alpha operations
|
2012-09-19 21:50:28 +00:00
|
|
|
TexMixArgument alphaArg2;
|
2012-07-24 22:27:01 +00:00
|
|
|
//! Wrap mode for 1st tex coord
|
2012-09-19 21:50:28 +00:00
|
|
|
TexWrapMode wrapS;
|
2012-07-24 22:27:01 +00:00
|
|
|
//! Wrap mode for 2nd tex coord
|
2012-09-19 21:50:28 +00:00
|
|
|
TexWrapMode wrapT;
|
2012-09-29 20:44:05 +00:00
|
|
|
//! Constant color factor (for TEX_MIX_ARG_FACTOR)
|
|
|
|
Color factor;
|
2012-07-06 17:00:22 +00:00
|
|
|
|
|
|
|
//! Constructor; calls LoadDefault()
|
2012-07-24 22:27:01 +00:00
|
|
|
TextureStageParams()
|
2012-07-06 17:00:22 +00:00
|
|
|
{ LoadDefault(); }
|
|
|
|
|
|
|
|
//! Loads the default values
|
2012-07-16 17:17:26 +00:00
|
|
|
inline void LoadDefault()
|
|
|
|
{
|
2012-09-19 21:50:28 +00:00
|
|
|
colorOperation = TEX_MIX_OPER_DEFAULT;
|
|
|
|
colorArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
|
|
|
|
colorArg2 = TEX_MIX_ARG_TEXTURE;
|
2012-07-16 17:17:26 +00:00
|
|
|
|
2012-09-19 21:50:28 +00:00
|
|
|
alphaOperation = TEX_MIX_OPER_DEFAULT;
|
|
|
|
alphaArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
|
|
|
|
alphaArg2 = TEX_MIX_ARG_TEXTURE;
|
2012-07-24 22:27:01 +00:00
|
|
|
|
2012-09-19 21:50:28 +00:00
|
|
|
wrapS = wrapT = TEX_WRAP_REPEAT;
|
2012-07-16 17:17:26 +00:00
|
|
|
}
|
2012-07-06 17:00:22 +00:00
|
|
|
};
|
|
|
|
|
2012-07-24 22:27:01 +00:00
|
|
|
/**
|
2012-09-29 08:40:11 +00:00
|
|
|
* \struct Texture
|
|
|
|
* \brief Info about a texture
|
|
|
|
*
|
|
|
|
* Identifies (through id) a texture created in graphics engine.
|
|
|
|
* Also contains some additional data.
|
|
|
|
*/
|
2012-06-30 23:37:30 +00:00
|
|
|
struct Texture
|
|
|
|
{
|
2012-08-12 17:28:22 +00:00
|
|
|
//! ID of the texture in graphics engine; 0 = invalid texture
|
2012-07-03 22:04:53 +00:00
|
|
|
unsigned int id;
|
2012-07-29 13:09:53 +00:00
|
|
|
//! Size of texture
|
2012-08-11 15:17:04 +00:00
|
|
|
Math::IntPoint size;
|
2013-05-11 21:05:20 +00:00
|
|
|
//! Original size of texture (as loaded from image)
|
|
|
|
Math::IntPoint originalSize;
|
2012-07-22 20:05:12 +00:00
|
|
|
//! Whether the texture has alpha channel
|
|
|
|
bool alpha;
|
2012-07-03 22:04:53 +00:00
|
|
|
|
|
|
|
Texture()
|
2012-07-22 20:05:12 +00:00
|
|
|
{
|
|
|
|
id = 0;
|
|
|
|
alpha = false;
|
|
|
|
}
|
|
|
|
|
2012-08-12 17:28:22 +00:00
|
|
|
//! Returns whether the texture is valid (ID != 0)
|
|
|
|
bool Valid() const
|
|
|
|
{
|
|
|
|
return id != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets the ID to invalid value (0)
|
|
|
|
void SetInvalid()
|
|
|
|
{
|
|
|
|
id = 0;
|
|
|
|
}
|
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
//! Comparator for use in texture maps and sets
|
2012-09-19 21:50:28 +00:00
|
|
|
inline bool operator<(const Texture &other) const
|
2012-07-22 20:05:12 +00:00
|
|
|
{
|
|
|
|
// Invalid textures are always "less than" every other texture
|
|
|
|
|
2012-08-12 17:28:22 +00:00
|
|
|
if ( (! Valid()) && (! other.Valid()) )
|
2012-07-22 20:05:12 +00:00
|
|
|
return false;
|
|
|
|
|
2012-08-12 17:28:22 +00:00
|
|
|
if (! Valid())
|
2012-07-22 20:05:12 +00:00
|
|
|
return true;
|
|
|
|
|
2012-08-12 17:28:22 +00:00
|
|
|
if (! other.Valid())
|
2012-07-22 20:05:12 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return id < other.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Comparator
|
2012-09-19 21:50:28 +00:00
|
|
|
inline bool operator==(const Texture &other) const
|
2012-07-22 20:05:12 +00:00
|
|
|
{
|
2012-08-12 17:28:22 +00:00
|
|
|
if (Valid() != other.Valid())
|
2012-07-22 20:05:12 +00:00
|
|
|
return false;
|
2012-08-12 17:28:22 +00:00
|
|
|
if ( (! Valid()) && (! other.Valid()) )
|
2012-07-22 20:05:12 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return id == other.id;
|
|
|
|
}
|
2012-06-30 23:37:30 +00:00
|
|
|
};
|
|
|
|
|
2012-09-19 21:50:28 +00:00
|
|
|
|
|
|
|
} // namespace Gfx
|
2013-05-26 15:47:54 +00:00
|
|
|
|