| 1 | //////////////////////////////////////////////////////////// |
| 2 | // |
| 3 | // SFML - Simple and Fast Multimedia Library |
| 4 | // Copyright (C) 2007-2020 Laurent Gomila (laurent@sfml-dev.org) |
| 5 | // |
| 6 | // This software is provided 'as-is', without any express or implied warranty. |
| 7 | // In no event will the authors be held liable for any damages arising from the use of this software. |
| 8 | // |
| 9 | // Permission is granted to anyone to use this software for any purpose, |
| 10 | // including commercial applications, and to alter it and redistribute it freely, |
| 11 | // subject to the following restrictions: |
| 12 | // |
| 13 | // 1. The origin of this software must not be misrepresented; |
| 14 | // you must not claim that you wrote the original software. |
| 15 | // If you use this software in a product, an acknowledgment |
| 16 | // in the product documentation would be appreciated but is not required. |
| 17 | // |
| 18 | // 2. Altered source versions must be plainly marked as such, |
| 19 | // and must not be misrepresented as being the original software. |
| 20 | // |
| 21 | // 3. This notice may not be removed or altered from any source distribution. |
| 22 | // |
| 23 | //////////////////////////////////////////////////////////// |
| 24 | |
| 25 | #ifndef SFML_RENDERSTATES_HPP |
| 26 | #define SFML_RENDERSTATES_HPP |
| 27 | |
| 28 | //////////////////////////////////////////////////////////// |
| 29 | // Headers |
| 30 | //////////////////////////////////////////////////////////// |
| 31 | #include <SFML/Graphics/Export.hpp> |
| 32 | #include <SFML/Graphics/BlendMode.hpp> |
| 33 | #include <SFML/Graphics/Transform.hpp> |
| 34 | |
| 35 | |
| 36 | namespace sf |
| 37 | { |
| 38 | class Shader; |
| 39 | class Texture; |
| 40 | |
| 41 | //////////////////////////////////////////////////////////// |
| 42 | /// \brief Define the states used for drawing to a RenderTarget |
| 43 | /// |
| 44 | //////////////////////////////////////////////////////////// |
| 45 | class SFML_GRAPHICS_API RenderStates |
| 46 | { |
| 47 | public: |
| 48 | |
| 49 | //////////////////////////////////////////////////////////// |
| 50 | /// \brief Default constructor |
| 51 | /// |
| 52 | /// Constructing a default set of render states is equivalent |
| 53 | /// to using sf::RenderStates::Default. |
| 54 | /// The default set defines: |
| 55 | /// \li the BlendAlpha blend mode |
| 56 | /// \li the identity transform |
| 57 | /// \li a null texture |
| 58 | /// \li a null shader |
| 59 | /// |
| 60 | //////////////////////////////////////////////////////////// |
| 61 | RenderStates(); |
| 62 | |
| 63 | //////////////////////////////////////////////////////////// |
| 64 | /// \brief Construct a default set of render states with a custom blend mode |
| 65 | /// |
| 66 | /// \param theBlendMode Blend mode to use |
| 67 | /// |
| 68 | //////////////////////////////////////////////////////////// |
| 69 | RenderStates(const BlendMode& theBlendMode); |
| 70 | |
| 71 | //////////////////////////////////////////////////////////// |
| 72 | /// \brief Construct a default set of render states with a custom transform |
| 73 | /// |
| 74 | /// \param theTransform Transform to use |
| 75 | /// |
| 76 | //////////////////////////////////////////////////////////// |
| 77 | RenderStates(const Transform& theTransform); |
| 78 | |
| 79 | //////////////////////////////////////////////////////////// |
| 80 | /// \brief Construct a default set of render states with a custom texture |
| 81 | /// |
| 82 | /// \param theTexture Texture to use |
| 83 | /// |
| 84 | //////////////////////////////////////////////////////////// |
| 85 | RenderStates(const Texture* theTexture); |
| 86 | |
| 87 | //////////////////////////////////////////////////////////// |
| 88 | /// \brief Construct a default set of render states with a custom shader |
| 89 | /// |
| 90 | /// \param theShader Shader to use |
| 91 | /// |
| 92 | //////////////////////////////////////////////////////////// |
| 93 | RenderStates(const Shader* theShader); |
| 94 | |
| 95 | //////////////////////////////////////////////////////////// |
| 96 | /// \brief Construct a set of render states with all its attributes |
| 97 | /// |
| 98 | /// \param theBlendMode Blend mode to use |
| 99 | /// \param theTransform Transform to use |
| 100 | /// \param theTexture Texture to use |
| 101 | /// \param theShader Shader to use |
| 102 | /// |
| 103 | //////////////////////////////////////////////////////////// |
| 104 | RenderStates(const BlendMode& theBlendMode, const Transform& theTransform, |
| 105 | const Texture* theTexture, const Shader* theShader); |
| 106 | |
| 107 | //////////////////////////////////////////////////////////// |
| 108 | // Static member data |
| 109 | //////////////////////////////////////////////////////////// |
| 110 | static const RenderStates Default; //!< Special instance holding the default render states |
| 111 | |
| 112 | //////////////////////////////////////////////////////////// |
| 113 | // Member data |
| 114 | //////////////////////////////////////////////////////////// |
| 115 | BlendMode blendMode; //!< Blending mode |
| 116 | Transform transform; //!< Transform |
| 117 | const Texture* texture; //!< Texture |
| 118 | const Shader* shader; //!< Shader |
| 119 | }; |
| 120 | |
| 121 | } // namespace sf |
| 122 | |
| 123 | |
| 124 | #endif // SFML_RENDERSTATES_HPP |
| 125 | |
| 126 | |
| 127 | //////////////////////////////////////////////////////////// |
| 128 | /// \class sf::RenderStates |
| 129 | /// \ingroup graphics |
| 130 | /// |
| 131 | /// There are four global states that can be applied to |
| 132 | /// the drawn objects: |
| 133 | /// \li the blend mode: how pixels of the object are blended with the background |
| 134 | /// \li the transform: how the object is positioned/rotated/scaled |
| 135 | /// \li the texture: what image is mapped to the object |
| 136 | /// \li the shader: what custom effect is applied to the object |
| 137 | /// |
| 138 | /// High-level objects such as sprites or text force some of |
| 139 | /// these states when they are drawn. For example, a sprite |
| 140 | /// will set its own texture, so that you don't have to care |
| 141 | /// about it when drawing the sprite. |
| 142 | /// |
| 143 | /// The transform is a special case: sprites, texts and shapes |
| 144 | /// (and it's a good idea to do it with your own drawable classes |
| 145 | /// too) combine their transform with the one that is passed in the |
| 146 | /// RenderStates structure. So that you can use a "global" transform |
| 147 | /// on top of each object's transform. |
| 148 | /// |
| 149 | /// Most objects, especially high-level drawables, can be drawn |
| 150 | /// directly without defining render states explicitly -- the |
| 151 | /// default set of states is ok in most cases. |
| 152 | /// \code |
| 153 | /// window.draw(sprite); |
| 154 | /// \endcode |
| 155 | /// |
| 156 | /// If you want to use a single specific render state, |
| 157 | /// for example a shader, you can pass it directly to the Draw |
| 158 | /// function: sf::RenderStates has an implicit one-argument |
| 159 | /// constructor for each state. |
| 160 | /// \code |
| 161 | /// window.draw(sprite, shader); |
| 162 | /// \endcode |
| 163 | /// |
| 164 | /// When you're inside the Draw function of a drawable |
| 165 | /// object (inherited from sf::Drawable), you can |
| 166 | /// either pass the render states unmodified, or change |
| 167 | /// some of them. |
| 168 | /// For example, a transformable object will combine the |
| 169 | /// current transform with its own transform. A sprite will |
| 170 | /// set its texture. Etc. |
| 171 | /// |
| 172 | /// \see sf::RenderTarget, sf::Drawable |
| 173 | /// |
| 174 | //////////////////////////////////////////////////////////// |
| 175 | |