SFML 2.5.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

Texture.hpp
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2018 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#ifndef SFML_TEXTURE_HPP
26#define SFML_TEXTURE_HPP
27
29// Headers
31#include <SFML/Graphics/Export.hpp>
32#include <SFML/Graphics/Image.hpp>
33#include <SFML/Window/GlResource.hpp>
34
35
36namespace sf
37{
38class InputStream;
39class RenderTarget;
40class RenderTexture;
41class Text;
42class Window;
43
48 class SFML_GRAPHICS_API Texture : GlResource
49{
50public:
51
56 enum CoordinateType
57 {
58 Normalized,
59 Pixels
60 };
61
62public:
63
70 Texture();
71
78 Texture(const Texture& copy);
79
84 ~Texture();
85
97 bool create(unsigned int width, unsigned int height);
98
128 bool loadFromFile(const std::string& filename, const IntRect& area = IntRect());
129
160 bool loadFromMemory(const void* data, std::size_t size, const IntRect& area = IntRect());
161
191 bool loadFromStream(InputStream& stream, const IntRect& area = IntRect());
192
215 bool loadFromImage(const Image& image, const IntRect& area = IntRect());
216
223 Vector2u getSize() const;
224
238 Image copyToImage() const;
239
256 void update(const Uint8* pixels);
257
278 void update(const Uint8* pixels, unsigned int width, unsigned int height, unsigned int x, unsigned int y);
279
298 void update(const Texture& texture);
299
315 void update(const Texture& texture, unsigned int x, unsigned int y);
316
335 void update(const Image& image);
336
352 void update(const Image& image, unsigned int x, unsigned int y);
353
372 void update(const Window& window);
373
389 void update(const Window& window, unsigned int x, unsigned int y);
390
405 void setSmooth(bool smooth);
406
415 bool isSmooth() const;
416
440 void setSrgb(bool sRgb);
441
450 bool isSrgb() const;
451
474 void setRepeated(bool repeated);
475
484 bool isRepeated() const;
485
509 bool generateMipmap();
510
519 Texture& operator =(const Texture& right);
520
527 void swap(Texture& right);
528
539 unsigned int getNativeHandle() const;
540
572 static void bind(const Texture* texture, CoordinateType coordinateType = Normalized);
573
584 static unsigned int getMaximumSize();
585
586private:
587
588 friend class Text;
589 friend class RenderTexture;
590 friend class RenderTarget;
591
605 static unsigned int getValidSize(unsigned int size);
606
614 void invalidateMipmap();
615
617 // Member data
619 Vector2u m_size;
620 Vector2u m_actualSize;
621 unsigned int m_texture;
622 bool m_isSmooth;
623 bool m_sRgb;
624 bool m_isRepeated;
625 mutable bool m_pixelsFlipped;
626 bool m_fboAttachment;
627 bool m_hasMipmap;
628 Uint64 m_cacheId;
629};
630
631} // namespace sf
632
633
634#endif // SFML_TEXTURE_HPP
635
sf::GlResource
Base class for classes that require an OpenGL context.
Definition: GlResource.hpp:47
sf::Image
Class for loading, manipulating and saving images.
Definition: Image.hpp:47
sf::InputStream
Abstract class for custom file input streams.
Definition: InputStream.hpp:42
sf::Rect< int >
sf::RenderTarget
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.hpp:53
sf::RenderTexture
Target for off-screen 2D rendering into a texture.
Definition: RenderTexture.hpp:49
sf::Text
Graphical text that can be drawn to a render target.
Definition: Text.hpp:49
sf::Texture
Image living on the graphics card that can be used for drawing.
Definition: Texture.hpp:49
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::update
void update(const Uint8 *pixels, unsigned int width, unsigned int height, unsigned int x, unsigned int y)
Update a part of the texture from an array of pixels.
sf::Texture::update
void update(const Window &window, unsigned int x, unsigned int y)
Update a part of the texture from the contents of a window.
sf::Texture::loadFromMemory
bool loadFromMemory(const void *data, std::size_t size, const IntRect &area=IntRect())
Load the texture from a file in memory.
sf::Texture::Texture
Texture()
Default constructor.
sf::Texture::isSmooth
bool isSmooth() const
Tell whether the smooth filter is enabled or not.
sf::Texture::Texture
Texture(const Texture &copy)
Copy constructor.
sf::Texture::getNativeHandle
unsigned int getNativeHandle() const
Get the underlying OpenGL handle of the texture.
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::loadFromStream
bool loadFromStream(InputStream &stream, const IntRect &area=IntRect())
Load the texture from a custom stream.
sf::Texture::update
void update(const Image &image, unsigned int x, unsigned int y)
Update a part of the texture from an image.
sf::Texture::create
bool create(unsigned int width, unsigned int height)
Create the texture.
sf::Texture::update
void update(const Texture &texture, unsigned int x, unsigned int y)
Update a part of this texture from another texture.
sf::Texture::loadFromFile
bool loadFromFile(const std::string &filename, const IntRect &area=IntRect())
Load the texture from a file on disk.
sf::Texture::swap
void swap(Texture &right)
Swap the contents of this texture with those of another.
sf::Texture::~Texture
~Texture()
Destructor.
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::CoordinateType
CoordinateType
Types of texture coordinates that can be used for rendering.
Definition: Texture.hpp:57
sf::Texture::Normalized
@ Normalized
Texture coordinates in range [0 .. 1].
Definition: Texture.hpp:58
sf::Texture::setRepeated
void setRepeated(bool repeated)
Enable or disable repeating.
sf::Texture::loadFromImage
bool loadFromImage(const Image &image, const IntRect &area=IntRect())
Load 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 Uint8 *pixels)
Update the whole texture from an array of pixels.
sf::Texture::bind
static void bind(const Texture *texture, CoordinateType coordinateType=Normalized)
Bind a texture for rendering.
sf::Texture::isRepeated
bool isRepeated() const
Tell whether the texture is repeated or not.
sf::Texture::setSrgb
void setSrgb(bool sRgb)
Enable or disable conversion from sRGB.
sf::Texture::update
void update(const Texture &texture)
Update a part of this texture from another texture.
sf::Vector2< unsigned int >
sf::Window
Window that serves as a target for OpenGL rendering.
Definition: Window/Window.hpp:59