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-2016 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
34
35
36namespace sf
37{
38class Window;
39class RenderTarget;
40class RenderTexture;
41class InputStream;
42
48{
49public:
50
60
61public:
62
70
77 Texture(const Texture& copy);
78
84
96 bool create(unsigned int width, unsigned int height);
97
127 bool loadFromFile(const std::string& filename, const IntRect& area = IntRect());
128
159 bool loadFromMemory(const void* data, std::size_t size, const IntRect& area = IntRect());
160
190 bool loadFromStream(InputStream& stream, const IntRect& area = IntRect());
191
214 bool loadFromImage(const Image& image, const IntRect& area = IntRect());
215
223
238
255 void update(const Uint8* pixels);
256
277 void update(const Uint8* pixels, unsigned int width, unsigned int height, unsigned int x, unsigned int y);
278
297 void update(const Image& image);
298
314 void update(const Image& image, unsigned int x, unsigned int y);
315
334 void update(const Window& window);
335
351 void update(const Window& window, unsigned int x, unsigned int y);
352
367 void setSmooth(bool smooth);
368
377 bool isSmooth() const;
378
402 void setSrgb(bool sRgb);
403
412 bool isSrgb() const;
413
436 void setRepeated(bool repeated);
437
446 bool isRepeated() const;
447
472
481 Texture& operator =(const Texture& right);
482
493 unsigned int getNativeHandle() const;
494
526 static void bind(const Texture* texture, CoordinateType coordinateType = Normalized);
527
538 static unsigned int getMaximumSize();
539
540private:
541
542 friend class RenderTexture;
543 friend class RenderTarget;
544
558 static unsigned int getValidSize(unsigned int size);
559
567 void invalidateMipmap();
568
570 // Member data
572 Vector2u m_size;
573 Vector2u m_actualSize;
574 unsigned int m_texture;
575 bool m_isSmooth;
576 bool m_sRgb;
577 bool m_isRepeated;
578 mutable bool m_pixelsFlipped;
579 bool m_fboAttachment;
580 bool m_hasMipmap;
581 Uint64 m_cacheId;
582};
583
584} // namespace sf
585
586
587#endif // SFML_TEXTURE_HPP
588
#define SFML_GRAPHICS_API
GlResource()
Default constructor.
Class for loading, manipulating and saving images.
Definition Image.hpp:47
Abstract class for custom file input streams.
Base class for all render targets (window, texture, ...).
Target for off-screen 2D rendering into a texture.
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.
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.
void update(const Window &window, unsigned int x, unsigned int y)
Update a part of the texture from the contents of a window.
friend class RenderTexture
Definition Texture.hpp:542
bool loadFromMemory(const void *data, std::size_t size, const IntRect &area=IntRect())
Load the texture from a file in memory.
Texture()
Default constructor.
bool isSmooth() const
Tell whether the smooth filter is enabled or not.
Texture(const Texture &copy)
Copy constructor.
unsigned int getNativeHandle() const
Get the underlying OpenGL handle of the texture.
bool generateMipmap()
Generate a mipmap using the current texture data.
Image copyToImage() const
Copy the texture pixels to an image.
bool loadFromStream(InputStream &stream, const IntRect &area=IntRect())
Load the texture from a custom stream.
void update(const Image &image, unsigned int x, unsigned int y)
Update a part of the texture from an image.
bool create(unsigned int width, unsigned int height)
Create the texture.
bool loadFromFile(const std::string &filename, const IntRect &area=IntRect())
Load the texture from a file on disk.
~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.
friend class RenderTarget
Definition Texture.hpp:543
CoordinateType
Types of texture coordinates that can be used for rendering.
Definition Texture.hpp:56
@ Pixels
Texture coordinates in range [0 .. size].
Definition Texture.hpp:58
@ Normalized
Texture coordinates in range [0 .. 1].
Definition Texture.hpp:57
void setRepeated(bool repeated)
Enable or disable repeating.
bool loadFromImage(const Image &image, const IntRect &area=IntRect())
Load the texture from an image.
void update(const Window &window)
Update the texture from the contents of a window.
void update(const Uint8 *pixels)
Update the whole texture from an array of pixels.
static void bind(const Texture *texture, CoordinateType coordinateType=Normalized)
Bind a texture for rendering.
bool isRepeated() const
Tell whether the texture is repeated or not.
void setSrgb(bool sRgb)
Enable or disable conversion from sRGB.
Window that serves as a target for OpenGL rendering.
unsigned char Uint8
Definition Config.hpp:209
Vector2< unsigned int > Vector2u
Definition Vector2.hpp:254
Rect< int > IntRect
Definition Rect.hpp:196
unsigned long long Uint64
Definition Config.hpp:225