Back to home page

EIC code displayed by LXR

 
 

    


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

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_RENDERTEXTURE_HPP
0026 #define SFML_RENDERTEXTURE_HPP
0027 
0028 ////////////////////////////////////////////////////////////
0029 // Headers
0030 ////////////////////////////////////////////////////////////
0031 #include <SFML/Graphics/Export.hpp>
0032 #include <SFML/Graphics/Texture.hpp>
0033 #include <SFML/Graphics/RenderTarget.hpp>
0034 #include <SFML/Window/ContextSettings.hpp>
0035 
0036 
0037 namespace sf
0038 {
0039 namespace priv
0040 {
0041     class RenderTextureImpl;
0042 }
0043 
0044 ////////////////////////////////////////////////////////////
0045 /// \brief Target for off-screen 2D rendering into a texture
0046 ///
0047 ////////////////////////////////////////////////////////////
0048 class SFML_GRAPHICS_API RenderTexture : public RenderTarget
0049 {
0050 public:
0051 
0052     ////////////////////////////////////////////////////////////
0053     /// \brief Default constructor
0054     ///
0055     /// Constructs an empty, invalid render-texture. You must
0056     /// call create to have a valid render-texture.
0057     ///
0058     /// \see create
0059     ///
0060     ////////////////////////////////////////////////////////////
0061     RenderTexture();
0062 
0063     ////////////////////////////////////////////////////////////
0064     /// \brief Destructor
0065     ///
0066     ////////////////////////////////////////////////////////////
0067     virtual ~RenderTexture();
0068 
0069     ////////////////////////////////////////////////////////////
0070     /// \brief Create the render-texture
0071     ///
0072     /// Before calling this function, the render-texture is in
0073     /// an invalid state, thus it is mandatory to call it before
0074     /// doing anything with the render-texture.
0075     ///
0076     /// The last parameter, \a depthBuffer, is useful if you want
0077     /// to use the render-texture for 3D OpenGL rendering that requires
0078     /// a depth buffer. Otherwise it is unnecessary, and you should
0079     /// leave this parameter to false (which is its default value).
0080     ///
0081     /// After creation, the contents of the render-texture are undefined.
0082     /// Call `RenderTexture::clear` first to ensure a single color fill.
0083     ///
0084     /// \param width       Width of the render-texture
0085     /// \param height      Height of the render-texture
0086     /// \param depthBuffer Do you want this render-texture to have a depth buffer?
0087     ///
0088     /// \return True if creation has been successful
0089     ///
0090     /// \deprecated Use create(unsigned int, unsigned int, const ContextSettings&) instead.
0091     ///
0092     ////////////////////////////////////////////////////////////
0093     SFML_DEPRECATED bool create(unsigned int width, unsigned int height, bool depthBuffer);
0094 
0095     ////////////////////////////////////////////////////////////
0096     /// \brief Create the render-texture
0097     ///
0098     /// Before calling this function, the render-texture is in
0099     /// an invalid state, thus it is mandatory to call it before
0100     /// doing anything with the render-texture.
0101     ///
0102     /// The last parameter, \a settings, is useful if you want to enable
0103     /// multi-sampling or use the render-texture for OpenGL rendering that
0104     /// requires a depth or stencil buffer. Otherwise it is unnecessary, and
0105     /// you should leave this parameter at its default value.
0106     ///
0107     /// After creation, the contents of the render-texture are undefined.
0108     /// Call `RenderTexture::clear` first to ensure a single color fill.
0109     ///
0110     /// \param width    Width of the render-texture
0111     /// \param height   Height of the render-texture
0112     /// \param settings Additional settings for the underlying OpenGL texture and context
0113     ///
0114     /// \return True if creation has been successful
0115     ///
0116     ////////////////////////////////////////////////////////////
0117     bool create(unsigned int width, unsigned int height, const ContextSettings& settings = ContextSettings());
0118 
0119     ////////////////////////////////////////////////////////////
0120     /// \brief Get the maximum anti-aliasing level supported by the system
0121     ///
0122     /// \return The maximum anti-aliasing level supported by the system
0123     ///
0124     ////////////////////////////////////////////////////////////
0125     static unsigned int getMaximumAntialiasingLevel();
0126 
0127     ////////////////////////////////////////////////////////////
0128     /// \brief Enable or disable texture smoothing
0129     ///
0130     /// This function is similar to Texture::setSmooth.
0131     /// This parameter is disabled by default.
0132     ///
0133     /// \param smooth True to enable smoothing, false to disable it
0134     ///
0135     /// \see isSmooth
0136     ///
0137     ////////////////////////////////////////////////////////////
0138     void setSmooth(bool smooth);
0139 
0140     ////////////////////////////////////////////////////////////
0141     /// \brief Tell whether the smooth filtering is enabled or not
0142     ///
0143     /// \return True if texture smoothing is enabled
0144     ///
0145     /// \see setSmooth
0146     ///
0147     ////////////////////////////////////////////////////////////
0148     bool isSmooth() const;
0149 
0150     ////////////////////////////////////////////////////////////
0151     /// \brief Enable or disable texture repeating
0152     ///
0153     /// This function is similar to Texture::setRepeated.
0154     /// This parameter is disabled by default.
0155     ///
0156     /// \param repeated True to enable repeating, false to disable it
0157     ///
0158     /// \see isRepeated
0159     ///
0160     ////////////////////////////////////////////////////////////
0161     void setRepeated(bool repeated);
0162 
0163     ////////////////////////////////////////////////////////////
0164     /// \brief Tell whether the texture is repeated or not
0165     ///
0166     /// \return True if texture is repeated
0167     ///
0168     /// \see setRepeated
0169     ///
0170     ////////////////////////////////////////////////////////////
0171     bool isRepeated() const;
0172 
0173     ////////////////////////////////////////////////////////////
0174     /// \brief Generate a mipmap using the current texture data
0175     ///
0176     /// This function is similar to Texture::generateMipmap and operates
0177     /// on the texture used as the target for drawing.
0178     /// Be aware that any draw operation may modify the base level image data.
0179     /// For this reason, calling this function only makes sense after all
0180     /// drawing is completed and display has been called. Not calling display
0181     /// after subsequent drawing will lead to undefined behavior if a mipmap
0182     /// had been previously generated.
0183     ///
0184     /// \return True if mipmap generation was successful, false if unsuccessful
0185     ///
0186     ////////////////////////////////////////////////////////////
0187     bool generateMipmap();
0188 
0189     ////////////////////////////////////////////////////////////
0190     /// \brief Activate or deactivate the render-texture for rendering
0191     ///
0192     /// This function makes the render-texture's context current for
0193     /// future OpenGL rendering operations (so you shouldn't care
0194     /// about it if you're not doing direct OpenGL stuff).
0195     /// Only one context can be current in a thread, so if you
0196     /// want to draw OpenGL geometry to another render target
0197     /// (like a RenderWindow) don't forget to activate it again.
0198     ///
0199     /// \param active True to activate, false to deactivate
0200     ///
0201     /// \return True if operation was successful, false otherwise
0202     ///
0203     ////////////////////////////////////////////////////////////
0204     bool setActive(bool active = true);
0205 
0206     ////////////////////////////////////////////////////////////
0207     /// \brief Update the contents of the target texture
0208     ///
0209     /// This function updates the target texture with what
0210     /// has been drawn so far. Like for windows, calling this
0211     /// function is mandatory at the end of rendering. Not calling
0212     /// it may leave the texture in an undefined state.
0213     ///
0214     ////////////////////////////////////////////////////////////
0215     void display();
0216 
0217     ////////////////////////////////////////////////////////////
0218     /// \brief Return the size of the rendering region of the texture
0219     ///
0220     /// The returned value is the size that you passed to
0221     /// the create function.
0222     ///
0223     /// \return Size in pixels
0224     ///
0225     ////////////////////////////////////////////////////////////
0226     virtual Vector2u getSize() const;
0227 
0228 
0229     ////////////////////////////////////////////////////////////
0230     /// \brief Tell if the render-texture will use sRGB encoding when drawing on it
0231     ///
0232     /// You can request sRGB encoding for a render-texture
0233     /// by having the sRgbCapable flag set for the context parameter of create() method
0234     ///
0235     /// \return True if the render-texture use sRGB encoding, false otherwise
0236     ///
0237     ////////////////////////////////////////////////////////////
0238     virtual bool isSrgb() const;
0239 
0240     ////////////////////////////////////////////////////////////
0241     /// \brief Get a read-only reference to the target texture
0242     ///
0243     /// After drawing to the render-texture and calling Display,
0244     /// you can retrieve the updated texture using this function,
0245     /// and draw it using a sprite (for example).
0246     /// The internal sf::Texture of a render-texture is always the
0247     /// same instance, so that it is possible to call this function
0248     /// once and keep a reference to the texture even after it is
0249     /// modified.
0250     ///
0251     /// \return Const reference to the texture
0252     ///
0253     ////////////////////////////////////////////////////////////
0254     const Texture& getTexture() const;
0255 
0256 private:
0257 
0258     ////////////////////////////////////////////////////////////
0259     // Member data
0260     ////////////////////////////////////////////////////////////
0261     priv::RenderTextureImpl* m_impl;    //!< Platform/hardware specific implementation
0262     Texture                  m_texture; //!< Target texture to draw on
0263 };
0264 
0265 } // namespace sf
0266 
0267 
0268 #endif // SFML_RENDERTEXTURE_HPP
0269 
0270 
0271 ////////////////////////////////////////////////////////////
0272 /// \class sf::RenderTexture
0273 /// \ingroup graphics
0274 ///
0275 /// sf::RenderTexture is the little brother of sf::RenderWindow.
0276 /// It implements the same 2D drawing and OpenGL-related functions
0277 /// (see their base class sf::RenderTarget for more details),
0278 /// the difference is that the result is stored in an off-screen
0279 /// texture rather than being show in a window.
0280 ///
0281 /// Rendering to a texture can be useful in a variety of situations:
0282 /// \li precomputing a complex static texture (like a level's background from multiple tiles)
0283 /// \li applying post-effects to the whole scene with shaders
0284 /// \li creating a sprite from a 3D object rendered with OpenGL
0285 /// \li etc.
0286 ///
0287 /// Usage example:
0288 ///
0289 /// \code
0290 /// // Create a new render-window
0291 /// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
0292 ///
0293 /// // Create a new render-texture
0294 /// sf::RenderTexture texture;
0295 /// if (!texture.create(500, 500))
0296 ///     return -1;
0297 ///
0298 /// // The main loop
0299 /// while (window.isOpen())
0300 /// {
0301 ///    // Event processing
0302 ///    // ...
0303 ///
0304 ///    // Clear the whole texture with red color
0305 ///    texture.clear(sf::Color::Red);
0306 ///
0307 ///    // Draw stuff to the texture
0308 ///    texture.draw(sprite);  // sprite is a sf::Sprite
0309 ///    texture.draw(shape);   // shape is a sf::Shape
0310 ///    texture.draw(text);    // text is a sf::Text
0311 ///
0312 ///    // We're done drawing to the texture
0313 ///    texture.display();
0314 ///
0315 ///    // Now we start rendering to the window, clear it first
0316 ///    window.clear();
0317 ///
0318 ///    // Draw the texture
0319 ///    sf::Sprite sprite(texture.getTexture());
0320 ///    window.draw(sprite);
0321 ///
0322 ///    // End the current frame and display its contents on screen
0323 ///    window.display();
0324 /// }
0325 /// \endcode
0326 ///
0327 /// Like sf::RenderWindow, sf::RenderTexture is still able to render direct
0328 /// OpenGL stuff. It is even possible to mix together OpenGL calls
0329 /// and regular SFML drawing commands. If you need a depth buffer for
0330 /// 3D rendering, don't forget to request it when calling RenderTexture::create.
0331 ///
0332 /// \see sf::RenderTarget, sf::RenderWindow, sf::View, sf::Texture
0333 ///
0334 ////////////////////////////////////////////////////////////