Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:58:13

0001 ////////////////////////////////////////////////////////////
0002 //
0003 // SFML - Simple and Fast Multimedia Library
0004 // Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org)
0005 //
0006 // This software is provided 'as-is', without any express or implied warranty.
0007 // In no event will the authors be held liable for any damages arising from the use of this software.
0008 //
0009 // Permission is granted to anyone to use this software for any purpose,
0010 // including commercial applications, and to alter it and redistribute it freely,
0011 // subject to the following restrictions:
0012 //
0013 // 1. The origin of this software must not be misrepresented;
0014 //    you must not claim that you wrote the original software.
0015 //    If you use this software in a product, an acknowledgment
0016 //    in the product documentation would be appreciated but is not required.
0017 //
0018 // 2. Altered source versions must be plainly marked as such,
0019 //    and must not be misrepresented as being the original software.
0020 //
0021 // 3. This notice may not be removed or altered from any source distribution.
0022 //
0023 ////////////////////////////////////////////////////////////
0024 
0025 #ifndef SFML_RENDERSTATES_HPP
0026 #define SFML_RENDERSTATES_HPP
0027 
0028 ////////////////////////////////////////////////////////////
0029 // Headers
0030 ////////////////////////////////////////////////////////////
0031 #include <SFML/Graphics/Export.hpp>
0032 #include <SFML/Graphics/BlendMode.hpp>
0033 #include <SFML/Graphics/Transform.hpp>
0034 
0035 
0036 namespace sf
0037 {
0038 class Shader;
0039 class Texture;
0040 
0041 ////////////////////////////////////////////////////////////
0042 /// \brief Define the states used for drawing to a RenderTarget
0043 ///
0044 ////////////////////////////////////////////////////////////
0045 class SFML_GRAPHICS_API RenderStates
0046 {
0047 public:
0048 
0049     ////////////////////////////////////////////////////////////
0050     /// \brief Default constructor
0051     ///
0052     /// Constructing a default set of render states is equivalent
0053     /// to using sf::RenderStates::Default.
0054     /// The default set defines:
0055     /// \li the BlendAlpha blend mode
0056     /// \li the identity transform
0057     /// \li a null texture
0058     /// \li a null shader
0059     ///
0060     ////////////////////////////////////////////////////////////
0061     RenderStates();
0062 
0063     ////////////////////////////////////////////////////////////
0064     /// \brief Construct a default set of render states with a custom blend mode
0065     ///
0066     /// \param theBlendMode Blend mode to use
0067     ///
0068     ////////////////////////////////////////////////////////////
0069     RenderStates(const BlendMode& theBlendMode);
0070 
0071     ////////////////////////////////////////////////////////////
0072     /// \brief Construct a default set of render states with a custom transform
0073     ///
0074     /// \param theTransform Transform to use
0075     ///
0076     ////////////////////////////////////////////////////////////
0077     RenderStates(const Transform& theTransform);
0078 
0079     ////////////////////////////////////////////////////////////
0080     /// \brief Construct a default set of render states with a custom texture
0081     ///
0082     /// \param theTexture Texture to use
0083     ///
0084     ////////////////////////////////////////////////////////////
0085     RenderStates(const Texture* theTexture);
0086 
0087     ////////////////////////////////////////////////////////////
0088     /// \brief Construct a default set of render states with a custom shader
0089     ///
0090     /// \param theShader Shader to use
0091     ///
0092     ////////////////////////////////////////////////////////////
0093     RenderStates(const Shader* theShader);
0094 
0095     ////////////////////////////////////////////////////////////
0096     /// \brief Construct a set of render states with all its attributes
0097     ///
0098     /// \param theBlendMode Blend mode to use
0099     /// \param theTransform Transform to use
0100     /// \param theTexture   Texture to use
0101     /// \param theShader    Shader to use
0102     ///
0103     ////////////////////////////////////////////////////////////
0104     RenderStates(const BlendMode& theBlendMode, const Transform& theTransform,
0105                  const Texture* theTexture, const Shader* theShader);
0106 
0107     ////////////////////////////////////////////////////////////
0108     // Static member data
0109     ////////////////////////////////////////////////////////////
0110     static const RenderStates Default; //!< Special instance holding the default render states
0111 
0112     ////////////////////////////////////////////////////////////
0113     // Member data
0114     ////////////////////////////////////////////////////////////
0115     BlendMode      blendMode; //!< Blending mode
0116     Transform      transform; //!< Transform
0117     const Texture* texture;   //!< Texture
0118     const Shader*  shader;    //!< Shader
0119 };
0120 
0121 } // namespace sf
0122 
0123 
0124 #endif // SFML_RENDERSTATES_HPP
0125 
0126 
0127 ////////////////////////////////////////////////////////////
0128 /// \class sf::RenderStates
0129 /// \ingroup graphics
0130 ///
0131 /// There are four global states that can be applied to
0132 /// the drawn objects:
0133 /// \li the blend mode: how pixels of the object are blended with the background
0134 /// \li the transform: how the object is positioned/rotated/scaled
0135 /// \li the texture: what image is mapped to the object
0136 /// \li the shader: what custom effect is applied to the object
0137 ///
0138 /// High-level objects such as sprites or text force some of
0139 /// these states when they are drawn. For example, a sprite
0140 /// will set its own texture, so that you don't have to care
0141 /// about it when drawing the sprite.
0142 ///
0143 /// The transform is a special case: sprites, texts and shapes
0144 /// (and it's a good idea to do it with your own drawable classes
0145 /// too) combine their transform with the one that is passed in the
0146 /// RenderStates structure. So that you can use a "global" transform
0147 /// on top of each object's transform.
0148 ///
0149 /// Most objects, especially high-level drawables, can be drawn
0150 /// directly without defining render states explicitly -- the
0151 /// default set of states is ok in most cases.
0152 /// \code
0153 /// window.draw(sprite);
0154 /// \endcode
0155 ///
0156 /// If you want to use a single specific render state,
0157 /// for example a shader, you can pass it directly to the Draw
0158 /// function: sf::RenderStates has an implicit one-argument
0159 /// constructor for each state.
0160 /// \code
0161 /// window.draw(sprite, shader);
0162 /// \endcode
0163 ///
0164 /// When you're inside the Draw function of a drawable
0165 /// object (inherited from sf::Drawable), you can
0166 /// either pass the render states unmodified, or change
0167 /// some of them.
0168 /// For example, a transformable object will combine the
0169 /// current transform with its own transform. A sprite will
0170 /// set its texture. Etc.
0171 ///
0172 /// \see sf::RenderTarget, sf::Drawable
0173 ///
0174 ////////////////////////////////////////////////////////////