SFML 3.0.1
Loading...
Searching...
No Matches
Texture.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2025 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//
24
25#pragma once
26
28// Headers
30#include <SFML/Graphics/Export.hpp>
31
32#include <SFML/Graphics/CoordinateType.hpp>
33#include <SFML/Graphics/Rect.hpp>
34
35#include <SFML/Window/GlResource.hpp>
36
37#include <SFML/System/Vector2.hpp>
38
39#include <filesystem>
40
41#include <cstddef>
42#include <cstdint>
43
44
45 namespace sf
46{
47 class InputStream;
48 class Window;
49 class Image;
50
55 class SFML_GRAPHICS_API Texture : GlResource
56{
57 public:
66 Texture();
67
72 ~Texture();
73
80 Texture(const Texture& copy);
81
86 Texture& operator=(const Texture&);
87
92 Texture(Texture&&) noexcept;
93
98 Texture& operator=(Texture&&) noexcept;
99
114 explicit Texture(const std::filesystem::path& filename, bool sRgb = false);
115
137 Texture(const std::filesystem::path& filename, bool sRgb, const IntRect& area);
138
154 Texture(const void* data, std::size_t size, bool sRgb = false);
155
178 Texture(const void* data, std::size_t size, bool sRgb, const IntRect& area);
179
194 explicit Texture(InputStream& stream, bool sRgb = false);
195
217 Texture(InputStream& stream, bool sRgb, const IntRect& area);
218
233 explicit Texture(const Image& image, bool sRgb = false);
234
255 Texture(const Image& image, bool sRgb, const IntRect& area);
256
266 explicit Texture(Vector2u size, bool sRgb = false);
267
279 [[nodiscard]] bool resize(Vector2u size, bool sRgb = false);
280
304 [[nodiscard]] bool loadFromFile(const std::filesystem::path& filename, bool sRgb = false, const IntRect& area = {});
305
330 [[nodiscard]] bool loadFromMemory(const void* data, std::size_t size, bool sRgb = false, const IntRect& area = {});
331
355 [[nodiscard]] bool loadFromStream(InputStream& stream, bool sRgb = false, const IntRect& area = {});
356
380 [[nodiscard]] bool loadFromImage(const Image& image, bool sRgb = false, const IntRect& area = {});
381
388 [[nodiscard]] Vector2u getSize() const;
389
403 [[nodiscard]] Image copyToImage() const;
404
421 void update(const std::uint8_t* pixels);
422
441 void update(const std::uint8_t* pixels, Vector2u size, Vector2u dest);
442
462 void update(const Texture& texture);
463
478 void update(const Texture& texture, Vector2u dest);
479
499 void update(const Image& image);
500
515 void update(const Image& image, Vector2u dest);
516
536 void update(const Window& window);
537
552 void update(const Window& window, Vector2u dest);
553
568 void setSmooth(bool smooth);
569
578 [[nodiscard]] bool isSmooth() const;
579
588 [[nodiscard]] bool isSrgb() const;
589
612 void setRepeated(bool repeated);
613
622 [[nodiscard]] bool isRepeated() const;
623
647 [[nodiscard]] bool generateMipmap();
648
655 void swap(Texture& right) noexcept;
656
667 [[nodiscard]] unsigned int getNativeHandle() const;
668
700 static void bind(const Texture* texture, CoordinateType coordinateType = CoordinateType::Normalized);
701
712 [[nodiscard]] static unsigned int getMaximumSize();
713
714 private:
715 friend class Text;
716 friend class RenderTexture;
717 friend class RenderTarget;
718
732 [[nodiscard]] static unsigned int getValidSize(unsigned int size);
733
741 void invalidateMipmap();
742
744 // Member data
746 Vector2u m_size;
747 Vector2u m_actualSize;
748 unsigned int m_texture{};
749 bool m_isSmooth{};
750 bool m_sRgb{};
751 bool m_isRepeated{};
752 mutable bool m_pixelsFlipped{};
753 bool m_fboAttachment{};
754 bool m_hasMipmap{};
755 std::uint64_t m_cacheId;
756};
757
765 SFML_GRAPHICS_API void swap(Texture& left, Texture& right) noexcept;
766
767} // namespace sf
768
769
CoordinateType.hpp
GlResource.hpp
Export.hpp
SFML_GRAPHICS_API
#define SFML_GRAPHICS_API
Definition Graphics/Export.hpp:42
Rect.hpp
Vector2.hpp
sf::GlResource::GlResource
GlResource()
Default constructor.
sf::Image
Class for loading, manipulating and saving images.
Definition Image.hpp:55
sf::InputStream
Abstract class for custom file input streams.
Definition InputStream.hpp:46
sf::Texture
Image living on the graphics card that can be used for drawing.
Definition Texture.hpp:56
sf::Texture::update
void update(const Image &image)
Update the texture from an image.
sf::Texture::getMaximumSize
static unsigned int getMaximumSize()
Get the maximum texture size allowed.
sf::Texture::setSmooth
void setSmooth(bool smooth)
Enable or disable the smooth filter.
sf::Texture::RenderTexture
friend class RenderTexture
Definition Texture.hpp:716
sf::Texture::bind
static void bind(const Texture *texture, CoordinateType coordinateType=CoordinateType::Normalized)
Bind a texture for rendering.
sf::Texture::Texture
Texture()
Default constructor.
sf::Texture::isSmooth
bool isSmooth() const
Tell whether the smooth filter is enabled or not.
sf::Texture::update
void update(const std::uint8_t *pixels, Vector2u size, Vector2u dest)
Update a part of the texture from an array of pixels.
sf::Texture::update
void update(const Texture &texture, Vector2u dest)
Update a part of this texture from another texture.
sf::Texture::Texture
Texture(const Texture &copy)
Copy constructor.
sf::Texture::operator=
Texture & operator=(const Texture &)
Copy assignment operator.
sf::Texture::getNativeHandle
unsigned int getNativeHandle() const
Get the underlying OpenGL handle of the texture.
sf::Texture::loadFromStream
bool loadFromStream(InputStream &stream, bool sRgb=false, const IntRect &area={})
Load the texture from a custom stream.
sf::Texture::generateMipmap
bool generateMipmap()
Generate a mipmap using the current texture data.
sf::Texture::copyToImage
Image copyToImage() const
Copy the texture pixels to an image.
sf::Texture::Texture
Texture(Texture &&) noexcept
Move constructor.
sf::Texture::~Texture
~Texture()
Destructor.
sf::Texture::loadFromFile
bool loadFromFile(const std::filesystem::path &filename, bool sRgb=false, const IntRect &area={})
Load the texture from a file on disk.
sf::Texture::isSrgb
bool isSrgb() const
Tell whether the texture source is converted from sRGB or not.
sf::Texture::getSize
Vector2u getSize() const
Return the size of the texture.
sf::Texture::swap
void swap(Texture &right) noexcept
Swap the contents of this texture with those of another.
sf::Texture::loadFromMemory
bool loadFromMemory(const void *data, std::size_t size, bool sRgb=false, const IntRect &area={})
Load the texture from a file in memory.
sf::Texture::RenderTarget
friend class RenderTarget
Definition Texture.hpp:717
sf::Texture::setRepeated
void setRepeated(bool repeated)
Enable or disable repeating.
sf::Texture::update
void update(const Window &window, Vector2u dest)
Update a part of the texture from the contents of a window.
sf::Texture::update
void update(const Image &image, Vector2u dest)
Update a part of the texture from an image.
sf::Texture::update
void update(const Window &window)
Update the texture from the contents of a window.
sf::Texture::update
void update(const std::uint8_t *pixels)
Update the whole texture from an array of pixels.
sf::Texture::Text
friend class Text
Definition Texture.hpp:715
sf::Texture::loadFromImage
bool loadFromImage(const Image &image, bool sRgb=false, const IntRect &area={})
Load the texture from an image.
sf::Texture::isRepeated
bool isRepeated() const
Tell whether the texture is repeated or not.
sf::Texture::update
void update(const Texture &texture)
Update a part of this texture from another texture.
sf::Texture::resize
bool resize(Vector2u size, bool sRgb=false)
Resize the texture.
sf::Window
Window that serves as a target for OpenGL rendering.
Definition Window/Window.hpp:56
sf::CoordinateType
CoordinateType
Types of texture coordinates that can be used for rendering.
Definition CoordinateType.hpp:38
sf::CoordinateType::Normalized
@ Normalized
Texture coordinates in range [0 .. 1].
Definition CoordinateType.hpp:39
sf
Definition AudioResource.hpp:36
sf::swap
void swap(Texture &left, Texture &right) noexcept
Swap the contents of one texture with those of another.
sf::Vector2u
Vector2< unsigned int > Vector2u
Definition Vector2.hpp:209
sf::IntRect
Rect< int > IntRect
Definition Rect.hpp:146