Loading...
Searching...
No Matches
RenderTarget.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_RENDERTARGET_HPP
26#define SFML_RENDERTARGET_HPP
27
29// Headers
41
42
43namespace sf
44{
45class Drawable;
46
52{
53public:
54
59 virtual ~RenderTarget();
60
70 void clear(const Color& color = Color(0, 0, 0, 255));
71
91 void setView(const View& view);
92
101 const View& getView() const;
102
114 const View& getDefaultView() const;
115
129 IntRect getViewport(const View& view) const;
130
149 Vector2f mapPixelToCoords(const Vector2i& point) const;
150
180 Vector2f mapPixelToCoords(const Vector2i& point, const View& view) const;
181
200 Vector2i mapCoordsToPixel(const Vector2f& point) const;
201
227 Vector2i mapCoordsToPixel(const Vector2f& point, const View& view) const;
228
236 void draw(const Drawable& drawable, const RenderStates& states = RenderStates::Default);
237
247 void draw(const Vertex* vertices, std::size_t vertexCount,
248 PrimitiveType type, const RenderStates& states = RenderStates::Default);
249
256 virtual Vector2u getSize() const = 0;
257
291
302
325
326protected:
327
333
342
343private:
344
349 void applyCurrentView();
350
357 void applyBlendMode(const BlendMode& mode);
358
365 void applyTransform(const Transform& transform);
366
373 void applyTexture(const Texture* texture);
374
381 void applyShader(const Shader* shader);
382
395 virtual bool activate(bool active) = 0;
396
401 struct StatesCache
402 {
403 enum {VertexCacheSize = 4};
404
405 bool glStatesSet;
406 bool viewChanged;
407 BlendMode lastBlendMode;
408 Uint64 lastTextureId;
409 bool useVertexCache;
410 Vertex vertexCache[VertexCacheSize];
411 };
412
414 // Member data
416 View m_defaultView;
417 View m_view;
418 StatesCache m_cache;
419};
420
421} // namespace sf
422
423
424#endif // SFML_RENDERTARGET_HPP
425
426
#define SFML_GRAPHICS_API
Utility class for manipulating RGBA colors.
Definition Color.hpp:41
Abstract base class for objects that can be drawn to a render target.
Definition Drawable.hpp:45
NonCopyable()
Default constructor.
Define the states used for drawing to a RenderTarget.
static const RenderStates Default
Special instance holding the default render states.
Vector2f mapPixelToCoords(const Vector2i &point) const
Convert a point from target coordinates to world coordinates, using the current view.
void setView(const View &view)
Change the current active view.
void draw(const Drawable &drawable, const RenderStates &states=RenderStates::Default)
Draw a drawable object to the render target.
RenderTarget()
Default constructor.
Vector2f mapPixelToCoords(const Vector2i &point, const View &view) const
Convert a point from target coordinates to world coordinates.
virtual Vector2u getSize() const =0
Return the size of the rendering region of the target.
void clear(const Color &color=Color(0, 0, 0, 255))
Clear the entire target with a single color.
const View & getDefaultView() const
Get the default view of the render target.
Vector2i mapCoordsToPixel(const Vector2f &point, const View &view) const
Convert a point from world coordinates to target coordinates.
IntRect getViewport(const View &view) const
Get the viewport of a view, applied to this render target.
void pushGLStates()
Save the current OpenGL render states and matrices.
void draw(const Vertex *vertices, std::size_t vertexCount, PrimitiveType type, const RenderStates &states=RenderStates::Default)
Draw primitives defined by an array of vertices.
virtual ~RenderTarget()
Destructor.
void resetGLStates()
Reset the internal OpenGL states so that the target is ready for drawing.
void popGLStates()
Restore the previously saved OpenGL render states and matrices.
Vector2i mapCoordsToPixel(const Vector2f &point) const
Convert a point from world coordinates to target coordinates, using the current view.
const View & getView() const
Get the view currently in use in the render target.
void initialize()
Performs the common initialization step after creation.
Shader class (vertex, geometry and fragment).
Definition Shader.hpp:53
Image living on the graphics card that can be used for drawing.
Definition Texture.hpp:48
Define a 3x3 transform matrix.
Definition Transform.hpp:43
Define a point with color and texture coordinates.
Definition Vertex.hpp:43
2D camera that defines what region is shown on screen
Definition View.hpp:44
PrimitiveType
Types of primitives that a sf::VertexArray can render.
Vector2< unsigned int > Vector2u
Definition Vector2.hpp:254
Rect< int > IntRect
Definition Rect.hpp:190
Vector2< int > Vector2i
Definition Vector2.hpp:253
Vector2< float > Vector2f
Definition Vector2.hpp:255
unsigned long long Uint64
Definition Config.hpp:225
Blending modes for drawing.
Definition BlendMode.hpp:42