libSDL2pp
C++ bindings/wrapper for SDL2
Loading...
Searching...
No Matches
Texture.hh
1/*
2 libSDL2pp - C++ bindings/wrapper for SDL2
3 Copyright (C) 2013-2016 Dmitry Marakasov <amdmi3@amdmi3.ru>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 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
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22#ifndef SDL2PP_TEXTURE_HH
23#define SDL2PP_TEXTURE_HH
24
25#include <string>
26
27#include <SDL_stdinc.h>
28#include <SDL_blendmode.h>
29
30#include <SDL2pp/Optional.hh>
31#include <SDL2pp/Rect.hh>
32#include <SDL2pp/Config.hh>
33#include <SDL2pp/Export.hh>
34#include <SDL2pp/Color.hh>
35
36struct SDL_Texture;
37
38namespace SDL2pp {
39
40class Renderer;
41class RWops;
42class Surface;
43
53class SDL2PP_EXPORT Texture {
54private:
55 SDL_Texture* texture_;
56
57public:
96 class LockHandle {
97 friend class Texture;
98 private:
99 Texture* texture_;
100 void* pixels_;
101 int pitch_;
102
103 private:
114 LockHandle(Texture* texture, const Optional<Rect>& rect);
115
116 public:
124 LockHandle();
125
134 ~LockHandle();
135
142 LockHandle(LockHandle&& other) noexcept;
143
152 LockHandle& operator=(LockHandle&& other) noexcept;
153
160 LockHandle(const LockHandle& other) = delete;
161
168 LockHandle& operator=(const LockHandle& other) = delete;
169
176 void* GetPixels() const;
177
185 int GetPitch() const;
186 };
187
188public:
195 explicit Texture(SDL_Texture* texture);
196
211 Texture(Renderer& renderer, Uint32 format, int access, int w, int h);
212
213#ifdef SDL2PP_WITH_IMAGE
223 Texture(Renderer& renderer, RWops& rwops);
224
234 Texture(Renderer& renderer, const std::string& filename);
235#endif
236
248 Texture(Renderer& renderer, const Surface& surface);
249
256 virtual ~Texture();
257
264 Texture(Texture&& other) noexcept;
265
274 Texture& operator=(Texture&& other) noexcept;
275
282 Texture(const Texture& other) = delete;
283
290 Texture& operator=(const Texture& other) = delete;
291
298 SDL_Texture* Get() const;
299
316 Texture& Update(const Optional<Rect>& rect, const void* pixels, int pitch);
317
337 Texture& Update(const Optional<Rect>& rect, Surface& surface);
338
358 Texture& Update(const Optional<Rect>& rect, Surface&& surface);
359
379 Texture& UpdateYUV(const Optional<Rect>& rect, const Uint8* yplane, int ypitch, const Uint8* uplane, int upitch, const Uint8* vplane, int vpitch);
380
393 Texture& SetBlendMode(SDL_BlendMode blendMode = SDL_BLENDMODE_NONE);
394
407 Texture& SetAlphaMod(Uint8 alpha = 255);
408
423 Texture& SetColorMod(Uint8 r = 255, Uint8 g = 255, Uint8 b = 255);
424
438 Texture& SetColorAndAlphaMod(const Color& color = Color{255, 255, 255, SDL_ALPHA_OPAQUE});
439
453 LockHandle Lock(const Optional<Rect>& rect = NullOpt);
454
467 Uint32 GetFormat() const;
468
480 int GetAccess() const;
481
492 int GetWidth() const;
493
504 int GetHeight() const;
505
516 Point GetSize() const;
517
528 Uint8 GetAlphaMod() const;
529
540 SDL_BlendMode GetBlendMode() const;
541
554 void GetColorMod(Uint8& r, Uint8& g, Uint8 &b) const;
555
567 Color GetColorAndAlphaMod() const;
568};
569
570}
571
572#endif
RGB color with Alpha.
Definition: Color.hh:48
2D point
Definition: Point.hh:51
I/O abstraction.
Definition: RWops.hh:156
2D rendering context
Definition: Renderer.hh:52
Image stored in system memory with direct access to pixel data.
Definition: Surface.hh:53
SDL2pp::Texture lock.
Definition: Texture.hh:96
LockHandle & operator=(const LockHandle &other)=delete
Deleted assignment operator.
LockHandle(const LockHandle &other)=delete
Deleted copy constructor.
Image stored in the graphics card memory that can be used for fast drawing.
Definition: Texture.hh:53
Texture(const Texture &other)=delete
Deleted copy constructor.
Texture & operator=(const Texture &other)=delete
Deleted assignment operator.