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-2024 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
31
34
36
38
39#include <filesystem>
40
41#include <cstddef>
42#include <cstdint>
43
44
45namespace sf
46{
47class InputStream;
48class Window;
49class Image;
50
56{
57public:
67
73
80 Texture(const Texture& copy);
81
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
714private:
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
765SFML_GRAPHICS_API void swap(Texture& left, Texture& right) noexcept;
766
767} // namespace sf
768
769
#define SFML_GRAPHICS_API
Base class for classes that require an OpenGL context.
Class for loading, manipulating and saving images.
Definition Image.hpp:55
Abstract class for custom file input streams.
Base class for all render targets (window, texture, ...)
Target for off-screen 2D rendering into a texture.
Graphical text that can be drawn to a render target.
Definition Text.hpp:57
Image living on the graphics card that can be used for drawing.
Definition Texture.hpp:56
void update(const Image &image)
Update the texture from an image.
static unsigned int getMaximumSize()
Get the maximum texture size allowed.
void setSmooth(bool smooth)
Enable or disable the smooth filter.
static void bind(const Texture *texture, CoordinateType coordinateType=CoordinateType::Normalized)
Bind a texture for rendering.
Texture()
Default constructor.
bool isSmooth() const
Tell whether the smooth filter is enabled or not.
void update(const std::uint8_t *pixels, Vector2u size, Vector2u dest)
Update a part of the texture from an array of pixels.
void update(const Texture &texture, Vector2u dest)
Update a part of this texture from another texture.
Texture(const Texture &copy)
Copy constructor.
Texture & operator=(const Texture &)
Copy assignment operator.
unsigned int getNativeHandle() const
Get the underlying OpenGL handle of the texture.
bool loadFromStream(InputStream &stream, bool sRgb=false, const IntRect &area={})
Load the texture from a custom stream.
bool generateMipmap()
Generate a mipmap using the current texture data.
Image copyToImage() const
Copy the texture pixels to an image.
Texture(Texture &&) noexcept
Move constructor.
~Texture()
Destructor.
bool isSrgb() const
Tell whether the texture source is converted from sRGB or not.
Vector2u getSize() const
Return the size of the texture.
void swap(Texture &right) noexcept
Swap the contents of this texture with those of another.
bool loadFromMemory(const void *data, std::size_t size, bool sRgb=false, const IntRect &area={})
Load the texture from a file in memory.
void setRepeated(bool repeated)
Enable or disable repeating.
void update(const Window &window, Vector2u dest)
Update a part of the texture from the contents of a window.
void update(const Image &image, Vector2u dest)
Update a part of the texture from an image.
void update(const Window &window)
Update the texture from the contents of a window.
void update(const std::uint8_t *pixels)
Update the whole texture from an array of pixels.
bool loadFromImage(const Image &image, bool sRgb=false, const IntRect &area={})
Load the texture from an image.
bool isRepeated() const
Tell whether the texture is repeated or not.
void update(const Texture &texture)
Update a part of this texture from another texture.
Window that serves as a target for OpenGL rendering.
CoordinateType
Types of texture coordinates that can be used for rendering.
void swap(Texture &left, Texture &right) noexcept
Swap the contents of one texture with those of another.