Spinning Topp Logo BlackTopp Studios
inc
combinemodifier.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine 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  The Mezzanine Engine 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 The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 /*
41  -----------------------------------------------------------------------------
42  This source file is part of ogre-procedural
43 
44  For the latest info, see http://code.google.com/p/ogre-procedural/
45 
46  Copyright (c) 2010-2013 Michael Broutin
47 
48  Permission is hereby granted, free of charge, to any person obtaining a copy
49  of this software and associated documentation files (the "Software"), to deal
50  in the Software without restriction, including without limitation the rights
51  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
52  copies of the Software, and to permit persons to whom the Software is
53  furnished to do so, subject to the following conditions:
54 
55  The above copyright notice and this permission notice shall be included in
56  all copies or substantial portions of the Software.
57 
58  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
61  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
62  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
63  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
64  THE SOFTWARE.
65  -----------------------------------------------------------------------------
66  */
67 #ifndef _graphicsproceduralcombinemodifier_h
68 #define _graphicsproceduralcombinemodifier_h
69 
70 #include "Graphics/Procedural/Texture/texturemodifier.h"
71 
72 namespace Mezzanine
73 {
74  namespace Graphics
75  {
76  namespace Procedural
77  {
78  ///////////////////////////////////////////////////////////////////////////////
79  /// @brief Convenience class used by the CombineModifier class to describe what action to take with a specific texture to be combined.
80  /// @details
81  ///////////////////////////////////////
82  struct CombineLayer
83  {
84  /// @brief A pointer to the texture that will be combined with the target texture in the modifier.
86  /// @brief The mode that will be used to combine the specified texture with the target texture being processed by the modifier.
88  };//CombineLayer
89 
90  ///////////////////////////////////////////////////////////////////////////////
91  /// @brief A modifier that will attempt to combine the content of multiple textures.
92  /// @details To use this modifier, textures should be added in sequence based on the order in which you want to apply the textures to the target texture. Added textures are
93  /// not combined directly, rather the first texture is applied to the target texture and the second texture is applied to the result of that operation and so forth, from the
94  /// first texture specified to the last.
95  ///////////////////////////////////////
97  {
98  public:
99  /// @brief An enum used to describe how a texture is to be combined with the other textures in the queue.
100  /// @details Unless explicitly stated, modes in this enum do not operate on the Alpha Channel.
102  {
103  CM_Add_Clamp = 1, ///< Simple addition of colours. This will generally make the result image brighter. Overflowing colour channels will be clamped to the maximum value.
104  CM_Add_Wrap = 2, ///< Simple addition of colours. This can make the image brighter or darker, because overflowing colour channels will wrap back to 0 and increment from there.
105  CM_Sub_Clamp = 3, ///< Simple subtraction of colours. This will generally make the result image darker. Underflowing colour channels will be clamped to the minimum value.
106  CM_Sub_Wrap = 4, ///< Simple subtraction of colours. This can make the image brighter or darker, because underflowing colour channels will wrap back to the maximum value and decrement from there.
107  CM_Multiply = 5, ///< Multiplication of colours. Results are then divided by 256. This can make the image brighter or darker. Overflowing colour channels will be clamped to the maximum value.
108  CM_Multiply_Double = 6, ///< Multiplication of colours. Results are then divided by 128, causing the result to be double what you would get with CM_Multiply. This will generally make the result image
109  ///< brighter than CM_Multiply, but can also make it darker with low colour values. Overflowing colour channels will be clamped to the maximum value.
110  CM_Blend = 7, ///< For each colour channel, add them together and divide by two. Produces the average of both textures.
111  CM_Alpha = 8, ///< As CM_Blend, but only performs the operation on the Alpha channel. Leaves other channels unmodified.
112  CM_Layer = 9 ///< Uses the Alpha Channel from the current operating texture to fade the colours in the target texture. The inverse of the Alpha Channel is applied to the colours of the current
113  ///< operating texture. The results are then added together.
114  };
115 
116  /// @brief Basic container type for @ref CombineLayer storage by this class.
117  typedef std::vector<CombineLayer> CombineLayerContainer;
118  /// @brief Iterator type for @ref CombineLayer instances stored by this class.
119  typedef CombineLayerContainer::iterator CombineLayerIterator;
120  /// @brief Const Iterator type for @ref CombineLayer instances stored by this class.
121  typedef CombineLayerContainer::const_iterator ConstCombineLayerIterator;
122  protected:
123  /// @internal
124  /// @brief The amount of colour from each layer that is to be used when combining textures.
126  /// @internal
127  /// @brief A container of all the layers to be applied to the target texture in sequence.
128  CombineLayerContainer CombineLayers;
129 
130  /// @internal
131  /// @brief Processes a single layer to combine it with the target image.
132  /// @param Layer The texture being combined with the result image.
133  /// @param Buffer The buffer being drawn to/combined with.
134  void ProcessLayer(const CombineLayer& Layer, TextureBuffer& Buffer);
135  public:
136  /// @brief Blank constructor.
137  CombineModifier();
138  /// @brief Class destructor.
139  virtual ~CombineModifier();
140 
141  ///////////////////////////////////////////////////////////////////////////////
142  // Utility
143 
144  /// @copydoc TextureModifier::Modify(TextureBuffer&)
145  virtual void Modify(TextureBuffer& Buffer);
146  /// @copydoc TextureModifier::GetName() const
147  virtual String GetName() const;
148 
149  ///////////////////////////////////////////////////////////////////////////////
150  // Configuration
151 
152  /// @brief Adds a texture to the end of the sequence to be processed.
153  /// @param Layer A pointer to the texture being added.
154  /// @param Mode The combine operation to be performed between the specified texture in the first argument and the target texture being processed by the modifier.
155  /// @return Returns a reference to this.
156  CombineModifier& AddTexture(TextureBuffer* Layer, const CombineMode Mode);
157  /// @brief Removes all textures from all layers.
158  /// @return Returns a reference to this.
159  CombineModifier& RemoveAllTextures();
160  /// @brief Sets which colour channels to filter (and by how much) from each layer texture.
161  /// @param Colour The amount of colour from the layer texture to keep when combining. Initial Value: (1.0,1.0,1.0,1.0).
162  /// @return Returns a reference to this.
163  CombineModifier& SetFilterColour(const ColourValue& Colour);
164  /// @brief Sets which colour channels to filter (and by how much) from each layer texture.
165  /// @param Red The amount of red colour from the layer texture to keep when combining. Initial Value: 1.0.
166  /// @param Green The amount of green colour from the layer texture to keep when combining. Initial Value: 1.0.
167  /// @param Blue The amount of blue colour from the layer texture to keep when combining. Initial Value: 1.0.
168  /// @param Alpha The amount of alpha colour from the layer texture to keep when combining. Initial Value: 1.0.
169  /// @return Returns a reference to this.
170  CombineModifier& SetFilterColour(const Real Red, const Real Green, const Real Blue, const Real Alpha);
171  };//CombineModifier
172  }//Procedural
173  }//Graphics
174 }//Mezzanine
175 
176 #endif
CombineLayerContainer::const_iterator ConstCombineLayerIterator
Const Iterator type for CombineLayer instances stored by this class.
This is a simple class for holding 4 reals representing the colour any give object or lightsource can...
Definition: colourvalue.h:64
TextureBuffer * TextureLayer
A pointer to the texture that will be combined with the target texture in the modifier.
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
CombineLayerContainer CombineLayers
A container of all the layers to be applied to the target texture in sequence.
A modifier that will attempt to combine the content of multiple textures.
CombineMode
An enum used to describe how a texture is to be combined with the other textures in the queue...
ColourValue CombineFilterColour
The amount of colour from each layer that is to be used when combining textures.
Whole Mode
The mode that will be used to combine the specified texture with the target texture being processed b...
CombineLayerContainer::iterator CombineLayerIterator
Iterator type for CombineLayer instances stored by this class.
A convenience buffer that stores pixel colour values of a texture to be generated.
Definition: texturebuffer.h:86
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
Convenience class used by the CombineModifier class to describe what action to take with a specific t...
A base class for modifying the contents of an already populated texture buffer.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
std::vector< CombineLayer > CombineLayerContainer
Basic container type for CombineLayer storage by this class.