From 32043605153543bd72eb012ff310367299ad4e8f Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 6 Jul 2012 19:00:22 +0200 Subject: Refactoring in math & texture modules - moved texture-related structs to texture.h & code to texture.cpp - cleaned up texture test code - added Math:: namespace qualifiers to math modules for clarity --- src/graphics/common/device.cpp | 23 --------- src/graphics/common/device.h | 109 ---------------------------------------- src/graphics/common/texture.cpp | 43 ++++++++++++++++ src/graphics/common/texture.h | 109 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 152 insertions(+), 132 deletions(-) create mode 100644 src/graphics/common/texture.cpp (limited to 'src/graphics/common') diff --git a/src/graphics/common/device.cpp b/src/graphics/common/device.cpp index 79102b2..fcd4318 100644 --- a/src/graphics/common/device.cpp +++ b/src/graphics/common/device.cpp @@ -31,26 +31,3 @@ void Gfx::DeviceConfig::LoadDefault() doubleBuf = true; noFrame = false; } - -void Gfx::TextureCreateParams::LoadDefault() -{ - alpha = false; - mipmap = false; - - minFilter = Gfx::TEX_MIN_FILTER_NEAREST; - magFilter = Gfx::TEX_MAG_FILTER_NEAREST; - - wrapS = Gfx::TEX_WRAP_REPEAT; - wrapT = Gfx::TEX_WRAP_REPEAT; -} - -void Gfx::TextureParams::LoadDefault() -{ - colorOperation = Gfx::TEX_MIX_OPER_MODULATE; - colorArg1 = Gfx::TEX_MIX_ARG_CURRENT; - colorArg2 = Gfx::TEX_MIX_ARG_TEXTURE; - - alphaOperation = Gfx::TEX_MIX_OPER_MODULATE; - alphaArg1 = Gfx::TEX_MIX_ARG_CURRENT; - alphaArg2 = Gfx::TEX_MIX_ARG_TEXTURE; -} diff --git a/src/graphics/common/device.h b/src/graphics/common/device.h index 41181aa..6a71a8a 100644 --- a/src/graphics/common/device.h +++ b/src/graphics/common/device.h @@ -181,115 +181,6 @@ enum PrimitiveType PRIMITIVE_TRIANGLE_STRIP }; -/** - \enum TexMinFilter - \brief Minification texture filter - - Corresponds to OpenGL modes but should translate to DirectX too. */ -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 -}; - -/** - \enum TexMagFilter - \brief Magnification texture filter */ -enum TexMagFilter -{ - TEX_MAG_FILTER_NEAREST, - TEX_MAG_FILTER_LINEAR -}; - -/** - \enum TexWrapMode - \brief Wrapping mode for texture coords */ -enum TexWrapMode -{ - TEX_WRAP_CLAMP, - TEX_WRAP_REPEAT -}; - -/** - \enum TexMixOperation - \brief Multitexture mixing operation - */ -enum TexMixOperation -{ - TEX_MIX_OPER_MODULATE, - TEX_MIX_OPER_ADD -}; - -/** - \enum TexMixArgument - \brief Multitexture mixing argument - */ -enum TexMixArgument -{ - TEX_MIX_ARG_CURRENT, - TEX_MIX_ARG_TEXTURE, - TEX_MIX_ARG_DIFFUSE, - TEX_MIX_ARG_FACTOR -}; - -/** - \struct TextureCreateParams - \brief Parameters for texture creation - */ -struct TextureCreateParams -{ - //! Whether the texture image contains alpha - bool alpha; - //! Whether to generate mipmaps - bool mipmap; - //! Minification filter - Gfx::TexMinFilter minFilter; - //! Magnification filter - Gfx::TexMagFilter magFilter; - //! Wrap S coord mode - Gfx::TexWrapMode wrapS; - //! Wrap T coord mode - Gfx::TexWrapMode wrapT; - - //! Constructor; calls LoadDefault() - TextureCreateParams() - { LoadDefault(); } - - //! Loads the default values - void LoadDefault(); -}; - -/** - \struct TextureParams - \brief Parameters for texture creation - */ -struct TextureParams -{ - //! Mixing operation done on color values - Gfx::TexMixOperation colorOperation; - //! 1st argument of color operations - Gfx::TexMixArgument colorArg1; - //! 2nd argument of color operations - Gfx::TexMixArgument colorArg2; - //! Mixing operation done on alpha values - Gfx::TexMixOperation alphaOperation; - //! 1st argument of alpha operations - Gfx::TexMixArgument alphaArg1; - //! 2nd argument of alpha operations - Gfx::TexMixArgument alphaArg2; - - //! Constructor; calls LoadDefault() - TextureParams() - { LoadDefault(); } - - //! Loads the default values - void LoadDefault(); -}; - /* Notes for rewriting DirectX code: diff --git a/src/graphics/common/texture.cpp b/src/graphics/common/texture.cpp new file mode 100644 index 0000000..50e71cd --- /dev/null +++ b/src/graphics/common/texture.cpp @@ -0,0 +1,43 @@ +// * 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/. + +// texture.cpp + +#include "graphics/common/texture.h" + + +void Gfx::TextureCreateParams::LoadDefault() +{ + alpha = false; + mipmap = false; + + minFilter = Gfx::TEX_MIN_FILTER_NEAREST; + magFilter = Gfx::TEX_MAG_FILTER_NEAREST; + + wrapS = Gfx::TEX_WRAP_REPEAT; + wrapT = Gfx::TEX_WRAP_REPEAT; +} + +void Gfx::TextureParams::LoadDefault() +{ + colorOperation = Gfx::TEX_MIX_OPER_MODULATE; + colorArg1 = Gfx::TEX_MIX_ARG_CURRENT; + colorArg2 = Gfx::TEX_MIX_ARG_TEXTURE; + + alphaOperation = Gfx::TEX_MIX_OPER_MODULATE; + alphaArg1 = Gfx::TEX_MIX_ARG_CURRENT; + alphaArg2 = Gfx::TEX_MIX_ARG_TEXTURE; +} diff --git a/src/graphics/common/texture.h b/src/graphics/common/texture.h index 55d5c70..55b2fc2 100644 --- a/src/graphics/common/texture.h +++ b/src/graphics/common/texture.h @@ -20,6 +20,115 @@ namespace Gfx { +/** + \enum TexMinFilter + \brief Minification texture filter + + Corresponds to OpenGL modes but should translate to DirectX too. */ +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 +}; + +/** + \enum TexMagFilter + \brief Magnification texture filter */ +enum TexMagFilter +{ + TEX_MAG_FILTER_NEAREST, + TEX_MAG_FILTER_LINEAR +}; + +/** + \enum TexWrapMode + \brief Wrapping mode for texture coords */ +enum TexWrapMode +{ + TEX_WRAP_CLAMP, + TEX_WRAP_REPEAT +}; + +/** + \enum TexMixOperation + \brief Multitexture mixing operation + */ +enum TexMixOperation +{ + TEX_MIX_OPER_MODULATE, + TEX_MIX_OPER_ADD +}; + +/** + \enum TexMixArgument + \brief Multitexture mixing argument + */ +enum TexMixArgument +{ + TEX_MIX_ARG_CURRENT, + TEX_MIX_ARG_TEXTURE, + TEX_MIX_ARG_DIFFUSE, + TEX_MIX_ARG_FACTOR +}; + +/** + \struct TextureCreateParams + \brief Parameters for texture creation + */ +struct TextureCreateParams +{ + //! Whether the texture image contains alpha + bool alpha; + //! Whether to generate mipmaps + bool mipmap; + //! Minification filter + Gfx::TexMinFilter minFilter; + //! Magnification filter + Gfx::TexMagFilter magFilter; + //! Wrap S coord mode + Gfx::TexWrapMode wrapS; + //! Wrap T coord mode + Gfx::TexWrapMode wrapT; + + //! Constructor; calls LoadDefault() + TextureCreateParams() + { LoadDefault(); } + + //! Loads the default values + void LoadDefault(); +}; + +/** + \struct TextureParams + \brief Parameters for texture creation + */ +struct TextureParams +{ + //! Mixing operation done on color values + Gfx::TexMixOperation colorOperation; + //! 1st argument of color operations + Gfx::TexMixArgument colorArg1; + //! 2nd argument of color operations + Gfx::TexMixArgument colorArg2; + //! Mixing operation done on alpha values + Gfx::TexMixOperation alphaOperation; + //! 1st argument of alpha operations + Gfx::TexMixArgument alphaArg1; + //! 2nd argument of alpha operations + Gfx::TexMixArgument alphaArg2; + + //! Constructor; calls LoadDefault() + TextureParams() + { LoadDefault(); } + + //! Loads the default values + void LoadDefault(); +}; + /** \struct Texture*/ struct Texture { -- cgit v1.2.3-1-g7c22