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_TEXTURE_HPP
0026 #define SFML_TEXTURE_HPP
0027 
0028 ////////////////////////////////////////////////////////////
0029 // Headers
0030 ////////////////////////////////////////////////////////////
0031 #include <SFML/Graphics/Export.hpp>
0032 #include <SFML/Graphics/Image.hpp>
0033 #include <SFML/Window/GlResource.hpp>
0034 
0035 
0036 namespace sf
0037 {
0038 class InputStream;
0039 class RenderTarget;
0040 class RenderTexture;
0041 class Text;
0042 class Window;
0043 
0044 ////////////////////////////////////////////////////////////
0045 /// \brief Image living on the graphics card that can be used for drawing
0046 ///
0047 ////////////////////////////////////////////////////////////
0048 class SFML_GRAPHICS_API Texture : GlResource
0049 {
0050 public:
0051 
0052     ////////////////////////////////////////////////////////////
0053     /// \brief Types of texture coordinates that can be used for rendering
0054     ///
0055     ////////////////////////////////////////////////////////////
0056     enum CoordinateType
0057     {
0058         Normalized, //!< Texture coordinates in range [0 .. 1]
0059         Pixels      //!< Texture coordinates in range [0 .. size]
0060     };
0061 
0062 public:
0063 
0064     ////////////////////////////////////////////////////////////
0065     /// \brief Default constructor
0066     ///
0067     /// Creates an empty texture.
0068     ///
0069     ////////////////////////////////////////////////////////////
0070     Texture();
0071 
0072     ////////////////////////////////////////////////////////////
0073     /// \brief Copy constructor
0074     ///
0075     /// \param copy instance to copy
0076     ///
0077     ////////////////////////////////////////////////////////////
0078     Texture(const Texture& copy);
0079 
0080     ////////////////////////////////////////////////////////////
0081     /// \brief Destructor
0082     ///
0083     ////////////////////////////////////////////////////////////
0084     ~Texture();
0085 
0086     ////////////////////////////////////////////////////////////
0087     /// \brief Create the texture
0088     ///
0089     /// If this function fails, the texture is left unchanged.
0090     ///
0091     /// \param width  Width of the texture
0092     /// \param height Height of the texture
0093     ///
0094     /// \return True if creation was successful
0095     ///
0096     ////////////////////////////////////////////////////////////
0097     bool create(unsigned int width, unsigned int height);
0098 
0099     ////////////////////////////////////////////////////////////
0100     /// \brief Load the texture from a file on disk
0101     ///
0102     /// This function is a shortcut for the following code:
0103     /// \code
0104     /// sf::Image image;
0105     /// image.loadFromFile(filename);
0106     /// texture.loadFromImage(image, area);
0107     /// \endcode
0108     ///
0109     /// The \a area argument can be used to load only a sub-rectangle
0110     /// of the whole image. If you want the entire image then leave
0111     /// the default value (which is an empty IntRect).
0112     /// If the \a area rectangle crosses the bounds of the image, it
0113     /// is adjusted to fit the image size.
0114     ///
0115     /// The maximum size for a texture depends on the graphics
0116     /// driver and can be retrieved with the getMaximumSize function.
0117     ///
0118     /// If this function fails, the texture is left unchanged.
0119     ///
0120     /// \param filename Path of the image file to load
0121     /// \param area     Area of the image to load
0122     ///
0123     /// \return True if loading was successful
0124     ///
0125     /// \see loadFromMemory, loadFromStream, loadFromImage
0126     ///
0127     ////////////////////////////////////////////////////////////
0128     bool loadFromFile(const std::string& filename, const IntRect& area = IntRect());
0129 
0130     ////////////////////////////////////////////////////////////
0131     /// \brief Load the texture from a file in memory
0132     ///
0133     /// This function is a shortcut for the following code:
0134     /// \code
0135     /// sf::Image image;
0136     /// image.loadFromMemory(data, size);
0137     /// texture.loadFromImage(image, area);
0138     /// \endcode
0139     ///
0140     /// The \a area argument can be used to load only a sub-rectangle
0141     /// of the whole image. If you want the entire image then leave
0142     /// the default value (which is an empty IntRect).
0143     /// If the \a area rectangle crosses the bounds of the image, it
0144     /// is adjusted to fit the image size.
0145     ///
0146     /// The maximum size for a texture depends on the graphics
0147     /// driver and can be retrieved with the getMaximumSize function.
0148     ///
0149     /// If this function fails, the texture is left unchanged.
0150     ///
0151     /// \param data Pointer to the file data in memory
0152     /// \param size Size of the data to load, in bytes
0153     /// \param area Area of the image to load
0154     ///
0155     /// \return True if loading was successful
0156     ///
0157     /// \see loadFromFile, loadFromStream, loadFromImage
0158     ///
0159     ////////////////////////////////////////////////////////////
0160     bool loadFromMemory(const void* data, std::size_t size, const IntRect& area = IntRect());
0161 
0162     ////////////////////////////////////////////////////////////
0163     /// \brief Load the texture from a custom stream
0164     ///
0165     /// This function is a shortcut for the following code:
0166     /// \code
0167     /// sf::Image image;
0168     /// image.loadFromStream(stream);
0169     /// texture.loadFromImage(image, area);
0170     /// \endcode
0171     ///
0172     /// The \a area argument can be used to load only a sub-rectangle
0173     /// of the whole image. If you want the entire image then leave
0174     /// the default value (which is an empty IntRect).
0175     /// If the \a area rectangle crosses the bounds of the image, it
0176     /// is adjusted to fit the image size.
0177     ///
0178     /// The maximum size for a texture depends on the graphics
0179     /// driver and can be retrieved with the getMaximumSize function.
0180     ///
0181     /// If this function fails, the texture is left unchanged.
0182     ///
0183     /// \param stream Source stream to read from
0184     /// \param area   Area of the image to load
0185     ///
0186     /// \return True if loading was successful
0187     ///
0188     /// \see loadFromFile, loadFromMemory, loadFromImage
0189     ///
0190     ////////////////////////////////////////////////////////////
0191     bool loadFromStream(InputStream& stream, const IntRect& area = IntRect());
0192 
0193     ////////////////////////////////////////////////////////////
0194     /// \brief Load the texture from an image
0195     ///
0196     /// The \a area argument can be used to load only a sub-rectangle
0197     /// of the whole image. If you want the entire image then leave
0198     /// the default value (which is an empty IntRect).
0199     /// If the \a area rectangle crosses the bounds of the image, it
0200     /// is adjusted to fit the image size.
0201     ///
0202     /// The maximum size for a texture depends on the graphics
0203     /// driver and can be retrieved with the getMaximumSize function.
0204     ///
0205     /// If this function fails, the texture is left unchanged.
0206     ///
0207     /// \param image Image to load into the texture
0208     /// \param area  Area of the image to load
0209     ///
0210     /// \return True if loading was successful
0211     ///
0212     /// \see loadFromFile, loadFromMemory
0213     ///
0214     ////////////////////////////////////////////////////////////
0215     bool loadFromImage(const Image& image, const IntRect& area = IntRect());
0216 
0217     ////////////////////////////////////////////////////////////
0218     /// \brief Return the size of the texture
0219     ///
0220     /// \return Size in pixels
0221     ///
0222     ////////////////////////////////////////////////////////////
0223     Vector2u getSize() const;
0224 
0225     ////////////////////////////////////////////////////////////
0226     /// \brief Copy the texture pixels to an image
0227     ///
0228     /// This function performs a slow operation that downloads
0229     /// the texture's pixels from the graphics card and copies
0230     /// them to a new image, potentially applying transformations
0231     /// to pixels if necessary (texture may be padded or flipped).
0232     ///
0233     /// \return Image containing the texture's pixels
0234     ///
0235     /// \see loadFromImage
0236     ///
0237     ////////////////////////////////////////////////////////////
0238     Image copyToImage() const;
0239 
0240     ////////////////////////////////////////////////////////////
0241     /// \brief Update the whole texture from an array of pixels
0242     ///
0243     /// The \a pixel array is assumed to have the same size as
0244     /// the \a area rectangle, and to contain 32-bits RGBA pixels.
0245     ///
0246     /// No additional check is performed on the size of the pixel
0247     /// array, passing invalid arguments will lead to an undefined
0248     /// behavior.
0249     ///
0250     /// This function does nothing if \a pixels is null or if the
0251     /// texture was not previously created.
0252     ///
0253     /// \param pixels Array of pixels to copy to the texture
0254     ///
0255     ////////////////////////////////////////////////////////////
0256     void update(const Uint8* pixels);
0257 
0258     ////////////////////////////////////////////////////////////
0259     /// \brief Update a part of the texture from an array of pixels
0260     ///
0261     /// The size of the \a pixel array must match the \a width and
0262     /// \a height arguments, and it must contain 32-bits RGBA pixels.
0263     ///
0264     /// No additional check is performed on the size of the pixel
0265     /// array or the bounds of the area to update, passing invalid
0266     /// arguments will lead to an undefined behavior.
0267     ///
0268     /// This function does nothing if \a pixels is null or if the
0269     /// texture was not previously created.
0270     ///
0271     /// \param pixels Array of pixels to copy to the texture
0272     /// \param width  Width of the pixel region contained in \a pixels
0273     /// \param height Height of the pixel region contained in \a pixels
0274     /// \param x      X offset in the texture where to copy the source pixels
0275     /// \param y      Y offset in the texture where to copy the source pixels
0276     ///
0277     ////////////////////////////////////////////////////////////
0278     void update(const Uint8* pixels, unsigned int width, unsigned int height, unsigned int x, unsigned int y);
0279 
0280     ////////////////////////////////////////////////////////////
0281     /// \brief Update a part of this texture from another texture
0282     ///
0283     /// Although the source texture can be smaller than this texture,
0284     /// this function is usually used for updating the whole texture.
0285     /// The other overload, which has (x, y) additional arguments,
0286     /// is more convenient for updating a sub-area of this texture.
0287     ///
0288     /// No additional check is performed on the size of the passed
0289     /// texture, passing a texture bigger than this texture
0290     /// will lead to an undefined behavior.
0291     ///
0292     /// This function does nothing if either texture was not
0293     /// previously created.
0294     ///
0295     /// \param texture Source texture to copy to this texture
0296     ///
0297     ////////////////////////////////////////////////////////////
0298     void update(const Texture& texture);
0299 
0300     ////////////////////////////////////////////////////////////
0301     /// \brief Update a part of this texture from another texture
0302     ///
0303     /// No additional check is performed on the size of the texture,
0304     /// passing an invalid combination of texture size and offset
0305     /// will lead to an undefined behavior.
0306     ///
0307     /// This function does nothing if either texture was not
0308     /// previously created.
0309     ///
0310     /// \param texture Source texture to copy to this texture
0311     /// \param x       X offset in this texture where to copy the source texture
0312     /// \param y       Y offset in this texture where to copy the source texture
0313     ///
0314     ////////////////////////////////////////////////////////////
0315     void update(const Texture& texture, unsigned int x, unsigned int y);
0316 
0317     ////////////////////////////////////////////////////////////
0318     /// \brief Update the texture from an image
0319     ///
0320     /// Although the source image can be smaller than the texture,
0321     /// this function is usually used for updating the whole texture.
0322     /// The other overload, which has (x, y) additional arguments,
0323     /// is more convenient for updating a sub-area of the texture.
0324     ///
0325     /// No additional check is performed on the size of the image,
0326     /// passing an image bigger than the texture will lead to an
0327     /// undefined behavior.
0328     ///
0329     /// This function does nothing if the texture was not
0330     /// previously created.
0331     ///
0332     /// \param image Image to copy to the texture
0333     ///
0334     ////////////////////////////////////////////////////////////
0335     void update(const Image& image);
0336 
0337     ////////////////////////////////////////////////////////////
0338     /// \brief Update a part of the texture from an image
0339     ///
0340     /// No additional check is performed on the size of the image,
0341     /// passing an invalid combination of image size and offset
0342     /// will lead to an undefined behavior.
0343     ///
0344     /// This function does nothing if the texture was not
0345     /// previously created.
0346     ///
0347     /// \param image Image to copy to the texture
0348     /// \param x     X offset in the texture where to copy the source image
0349     /// \param y     Y offset in the texture where to copy the source image
0350     ///
0351     ////////////////////////////////////////////////////////////
0352     void update(const Image& image, unsigned int x, unsigned int y);
0353 
0354     ////////////////////////////////////////////////////////////
0355     /// \brief Update the texture from the contents of a window
0356     ///
0357     /// Although the source window can be smaller than the texture,
0358     /// this function is usually used for updating the whole texture.
0359     /// The other overload, which has (x, y) additional arguments,
0360     /// is more convenient for updating a sub-area of the texture.
0361     ///
0362     /// No additional check is performed on the size of the window,
0363     /// passing a window bigger than the texture will lead to an
0364     /// undefined behavior.
0365     ///
0366     /// This function does nothing if either the texture or the window
0367     /// was not previously created.
0368     ///
0369     /// \param window Window to copy to the texture
0370     ///
0371     ////////////////////////////////////////////////////////////
0372     void update(const Window& window);
0373 
0374     ////////////////////////////////////////////////////////////
0375     /// \brief Update a part of the texture from the contents of a window
0376     ///
0377     /// No additional check is performed on the size of the window,
0378     /// passing an invalid combination of window size and offset
0379     /// will lead to an undefined behavior.
0380     ///
0381     /// This function does nothing if either the texture or the window
0382     /// was not previously created.
0383     ///
0384     /// \param window Window to copy to the texture
0385     /// \param x      X offset in the texture where to copy the source window
0386     /// \param y      Y offset in the texture where to copy the source window
0387     ///
0388     ////////////////////////////////////////////////////////////
0389     void update(const Window& window, unsigned int x, unsigned int y);
0390 
0391     ////////////////////////////////////////////////////////////
0392     /// \brief Enable or disable the smooth filter
0393     ///
0394     /// When the filter is activated, the texture appears smoother
0395     /// so that pixels are less noticeable. However if you want
0396     /// the texture to look exactly the same as its source file,
0397     /// you should leave it disabled.
0398     /// The smooth filter is disabled by default.
0399     ///
0400     /// \param smooth True to enable smoothing, false to disable it
0401     ///
0402     /// \see isSmooth
0403     ///
0404     ////////////////////////////////////////////////////////////
0405     void setSmooth(bool smooth);
0406 
0407     ////////////////////////////////////////////////////////////
0408     /// \brief Tell whether the smooth filter is enabled or not
0409     ///
0410     /// \return True if smoothing is enabled, false if it is disabled
0411     ///
0412     /// \see setSmooth
0413     ///
0414     ////////////////////////////////////////////////////////////
0415     bool isSmooth() const;
0416 
0417     ////////////////////////////////////////////////////////////
0418     /// \brief Enable or disable conversion from sRGB
0419     ///
0420     /// When providing texture data from an image file or memory, it can
0421     /// either be stored in a linear color space or an sRGB color space.
0422     /// Most digital images account for gamma correction already, so they
0423     /// would need to be "uncorrected" back to linear color space before
0424     /// being processed by the hardware. The hardware can automatically
0425     /// convert it from the sRGB color space to a linear color space when
0426     /// it gets sampled. When the rendered image gets output to the final
0427     /// framebuffer, it gets converted back to sRGB.
0428     ///
0429     /// After enabling or disabling sRGB conversion, make sure to reload
0430     /// the texture data in order for the setting to take effect.
0431     ///
0432     /// This option is only useful in conjunction with an sRGB capable
0433     /// framebuffer. This can be requested during window creation.
0434     ///
0435     /// \param sRgb True to enable sRGB conversion, false to disable it
0436     ///
0437     /// \see isSrgb
0438     ///
0439     ////////////////////////////////////////////////////////////
0440     void setSrgb(bool sRgb);
0441 
0442     ////////////////////////////////////////////////////////////
0443     /// \brief Tell whether the texture source is converted from sRGB or not
0444     ///
0445     /// \return True if the texture source is converted from sRGB, false if not
0446     ///
0447     /// \see setSrgb
0448     ///
0449     ////////////////////////////////////////////////////////////
0450     bool isSrgb() const;
0451 
0452     ////////////////////////////////////////////////////////////
0453     /// \brief Enable or disable repeating
0454     ///
0455     /// Repeating is involved when using texture coordinates
0456     /// outside the texture rectangle [0, 0, width, height].
0457     /// In this case, if repeat mode is enabled, the whole texture
0458     /// will be repeated as many times as needed to reach the
0459     /// coordinate (for example, if the X texture coordinate is
0460     /// 3 * width, the texture will be repeated 3 times).
0461     /// If repeat mode is disabled, the "extra space" will instead
0462     /// be filled with border pixels.
0463     /// Warning: on very old graphics cards, white pixels may appear
0464     /// when the texture is repeated. With such cards, repeat mode
0465     /// can be used reliably only if the texture has power-of-two
0466     /// dimensions (such as 256x128).
0467     /// Repeating is disabled by default.
0468     ///
0469     /// \param repeated True to repeat the texture, false to disable repeating
0470     ///
0471     /// \see isRepeated
0472     ///
0473     ////////////////////////////////////////////////////////////
0474     void setRepeated(bool repeated);
0475 
0476     ////////////////////////////////////////////////////////////
0477     /// \brief Tell whether the texture is repeated or not
0478     ///
0479     /// \return True if repeat mode is enabled, false if it is disabled
0480     ///
0481     /// \see setRepeated
0482     ///
0483     ////////////////////////////////////////////////////////////
0484     bool isRepeated() const;
0485 
0486     ////////////////////////////////////////////////////////////
0487     /// \brief Generate a mipmap using the current texture data
0488     ///
0489     /// Mipmaps are pre-computed chains of optimized textures. Each
0490     /// level of texture in a mipmap is generated by halving each of
0491     /// the previous level's dimensions. This is done until the final
0492     /// level has the size of 1x1. The textures generated in this process may
0493     /// make use of more advanced filters which might improve the visual quality
0494     /// of textures when they are applied to objects much smaller than they are.
0495     /// This is known as minification. Because fewer texels (texture elements)
0496     /// have to be sampled from when heavily minified, usage of mipmaps
0497     /// can also improve rendering performance in certain scenarios.
0498     ///
0499     /// Mipmap generation relies on the necessary OpenGL extension being
0500     /// available. If it is unavailable or generation fails due to another
0501     /// reason, this function will return false. Mipmap data is only valid from
0502     /// the time it is generated until the next time the base level image is
0503     /// modified, at which point this function will have to be called again to
0504     /// regenerate it.
0505     ///
0506     /// \return True if mipmap generation was successful, false if unsuccessful
0507     ///
0508     ////////////////////////////////////////////////////////////
0509     bool generateMipmap();
0510 
0511     ////////////////////////////////////////////////////////////
0512     /// \brief Overload of assignment operator
0513     ///
0514     /// \param right Instance to assign
0515     ///
0516     /// \return Reference to self
0517     ///
0518     ////////////////////////////////////////////////////////////
0519     Texture& operator =(const Texture& right);
0520 
0521     ////////////////////////////////////////////////////////////
0522     /// \brief Swap the contents of this texture with those of another
0523     ///
0524     /// \param right Instance to swap with
0525     ///
0526     ////////////////////////////////////////////////////////////
0527     void swap(Texture& right);
0528 
0529     ////////////////////////////////////////////////////////////
0530     /// \brief Get the underlying OpenGL handle of the texture.
0531     ///
0532     /// You shouldn't need to use this function, unless you have
0533     /// very specific stuff to implement that SFML doesn't support,
0534     /// or implement a temporary workaround until a bug is fixed.
0535     ///
0536     /// \return OpenGL handle of the texture or 0 if not yet created
0537     ///
0538     ////////////////////////////////////////////////////////////
0539     unsigned int getNativeHandle() const;
0540 
0541     ////////////////////////////////////////////////////////////
0542     /// \brief Bind a texture for rendering
0543     ///
0544     /// This function is not part of the graphics API, it mustn't be
0545     /// used when drawing SFML entities. It must be used only if you
0546     /// mix sf::Texture with OpenGL code.
0547     ///
0548     /// \code
0549     /// sf::Texture t1, t2;
0550     /// ...
0551     /// sf::Texture::bind(&t1);
0552     /// // draw OpenGL stuff that use t1...
0553     /// sf::Texture::bind(&t2);
0554     /// // draw OpenGL stuff that use t2...
0555     /// sf::Texture::bind(NULL);
0556     /// // draw OpenGL stuff that use no texture...
0557     /// \endcode
0558     ///
0559     /// The \a coordinateType argument controls how texture
0560     /// coordinates will be interpreted. If Normalized (the default), they
0561     /// must be in range [0 .. 1], which is the default way of handling
0562     /// texture coordinates with OpenGL. If Pixels, they must be given
0563     /// in pixels (range [0 .. size]). This mode is used internally by
0564     /// the graphics classes of SFML, it makes the definition of texture
0565     /// coordinates more intuitive for the high-level API, users don't need
0566     /// to compute normalized values.
0567     ///
0568     /// \param texture Pointer to the texture to bind, can be null to use no texture
0569     /// \param coordinateType Type of texture coordinates to use
0570     ///
0571     ////////////////////////////////////////////////////////////
0572     static void bind(const Texture* texture, CoordinateType coordinateType = Normalized);
0573 
0574     ////////////////////////////////////////////////////////////
0575     /// \brief Get the maximum texture size allowed
0576     ///
0577     /// This maximum size is defined by the graphics driver.
0578     /// You can expect a value of 512 pixels for low-end graphics
0579     /// card, and up to 8192 pixels or more for newer hardware.
0580     ///
0581     /// \return Maximum size allowed for textures, in pixels
0582     ///
0583     ////////////////////////////////////////////////////////////
0584     static unsigned int getMaximumSize();
0585 
0586 private:
0587 
0588     friend class Text;
0589     friend class RenderTexture;
0590     friend class RenderTarget;
0591 
0592     ////////////////////////////////////////////////////////////
0593     /// \brief Get a valid image size according to hardware support
0594     ///
0595     /// This function checks whether the graphics driver supports
0596     /// non power of two sizes or not, and adjusts the size
0597     /// accordingly.
0598     /// The returned size is greater than or equal to the original size.
0599     ///
0600     /// \param size size to convert
0601     ///
0602     /// \return Valid nearest size (greater than or equal to specified size)
0603     ///
0604     ////////////////////////////////////////////////////////////
0605     static unsigned int getValidSize(unsigned int size);
0606 
0607     ////////////////////////////////////////////////////////////
0608     /// \brief Invalidate the mipmap if one exists
0609     ///
0610     /// This also resets the texture's minifying function.
0611     /// This function is mainly for internal use by RenderTexture.
0612     ///
0613     ////////////////////////////////////////////////////////////
0614     void invalidateMipmap();
0615 
0616     ////////////////////////////////////////////////////////////
0617     // Member data
0618     ////////////////////////////////////////////////////////////
0619     Vector2u     m_size;          //!< Public texture size
0620     Vector2u     m_actualSize;    //!< Actual texture size (can be greater than public size because of padding)
0621     unsigned int m_texture;       //!< Internal texture identifier
0622     bool         m_isSmooth;      //!< Status of the smooth filter
0623     bool         m_sRgb;          //!< Should the texture source be converted from sRGB?
0624     bool         m_isRepeated;    //!< Is the texture in repeat mode?
0625     mutable bool m_pixelsFlipped; //!< To work around the inconsistency in Y orientation
0626     bool         m_fboAttachment; //!< Is this texture owned by a framebuffer object?
0627     bool         m_hasMipmap;     //!< Has the mipmap been generated?
0628     Uint64       m_cacheId;       //!< Unique number that identifies the texture to the render target's cache
0629 };
0630 
0631 } // namespace sf
0632 
0633 
0634 #endif // SFML_TEXTURE_HPP
0635 
0636 ////////////////////////////////////////////////////////////
0637 /// \class sf::Texture
0638 /// \ingroup graphics
0639 ///
0640 /// sf::Texture stores pixels that can be drawn, with a sprite
0641 /// for example. A texture lives in the graphics card memory,
0642 /// therefore it is very fast to draw a texture to a render target,
0643 /// or copy a render target to a texture (the graphics card can
0644 /// access both directly).
0645 ///
0646 /// Being stored in the graphics card memory has some drawbacks.
0647 /// A texture cannot be manipulated as freely as a sf::Image,
0648 /// you need to prepare the pixels first and then upload them
0649 /// to the texture in a single operation (see Texture::update).
0650 ///
0651 /// sf::Texture makes it easy to convert from/to sf::Image, but
0652 /// keep in mind that these calls require transfers between
0653 /// the graphics card and the central memory, therefore they are
0654 /// slow operations.
0655 ///
0656 /// A texture can be loaded from an image, but also directly
0657 /// from a file/memory/stream. The necessary shortcuts are defined
0658 /// so that you don't need an image first for the most common cases.
0659 /// However, if you want to perform some modifications on the pixels
0660 /// before creating the final texture, you can load your file to a
0661 /// sf::Image, do whatever you need with the pixels, and then call
0662 /// Texture::loadFromImage.
0663 ///
0664 /// Since they live in the graphics card memory, the pixels of a texture
0665 /// cannot be accessed without a slow copy first. And they cannot be
0666 /// accessed individually. Therefore, if you need to read the texture's
0667 /// pixels (like for pixel-perfect collisions), it is recommended to
0668 /// store the collision information separately, for example in an array
0669 /// of booleans.
0670 ///
0671 /// Like sf::Image, sf::Texture can handle a unique internal
0672 /// representation of pixels, which is RGBA 32 bits. This means
0673 /// that a pixel must be composed of 8 bits red, green, blue and
0674 /// alpha channels -- just like a sf::Color.
0675 ///
0676 /// Usage example:
0677 /// \code
0678 /// // This example shows the most common use of sf::Texture:
0679 /// // drawing a sprite
0680 ///
0681 /// // Load a texture from a file
0682 /// sf::Texture texture;
0683 /// if (!texture.loadFromFile("texture.png"))
0684 ///     return -1;
0685 ///
0686 /// // Assign it to a sprite
0687 /// sf::Sprite sprite;
0688 /// sprite.setTexture(texture);
0689 ///
0690 /// // Draw the textured sprite
0691 /// window.draw(sprite);
0692 /// \endcode
0693 ///
0694 /// \code
0695 /// // This example shows another common use of sf::Texture:
0696 /// // streaming real-time data, like video frames
0697 ///
0698 /// // Create an empty texture
0699 /// sf::Texture texture;
0700 /// if (!texture.create(640, 480))
0701 ///     return -1;
0702 ///
0703 /// // Create a sprite that will display the texture
0704 /// sf::Sprite sprite(texture);
0705 ///
0706 /// while (...) // the main loop
0707 /// {
0708 ///     ...
0709 ///
0710 ///     // update the texture
0711 ///     sf::Uint8* pixels = ...; // get a fresh chunk of pixels (the next frame of a movie, for example)
0712 ///     texture.update(pixels);
0713 ///
0714 ///     // draw it
0715 ///     window.draw(sprite);
0716 ///
0717 ///     ...
0718 /// }
0719 ///
0720 /// \endcode
0721 ///
0722 /// Like sf::Shader that can be used as a raw OpenGL shader,
0723 /// sf::Texture can also be used directly as a raw texture for
0724 /// custom OpenGL geometry.
0725 /// \code
0726 /// sf::Texture::bind(&texture);
0727 /// ... render OpenGL geometry ...
0728 /// sf::Texture::bind(NULL);
0729 /// \endcode
0730 ///
0731 /// \see sf::Sprite, sf::Image, sf::RenderTexture
0732 ///
0733 ////////////////////////////////////////////////////////////