SFML 2.6.1

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

- File List
- File Members

Loading...
Searching...
No Matches
RenderTarget.hpp
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2023 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
31#include <SFML/Graphics/Export.hpp>
32#include <SFML/Graphics/Color.hpp>
33#include <SFML/Graphics/Rect.hpp>
34#include <SFML/Graphics/View.hpp>
35#include <SFML/Graphics/Transform.hpp>
36#include <SFML/Graphics/BlendMode.hpp>
37#include <SFML/Graphics/RenderStates.hpp>
38#include <SFML/Graphics/PrimitiveType.hpp>
39#include <SFML/Graphics/Vertex.hpp>
40#include <SFML/System/NonCopyable.hpp>
41
42
43 namespace sf
44{
45 class Drawable;
46 class VertexBuffer;
47
52 class SFML_GRAPHICS_API RenderTarget : NonCopyable
53{
54 public:
55
60 virtual ~RenderTarget();
61
71 void clear(const Color& color = Color(0, 0, 0, 255));
72
92 void setView(const View& view);
93
102 const View& getView() const;
103
115 const View& getDefaultView() const;
116
130 IntRect getViewport(const View& view) const;
131
150 Vector2f mapPixelToCoords(const Vector2i& point) const;
151
181 Vector2f mapPixelToCoords(const Vector2i& point, const View& view) const;
182
201 Vector2i mapCoordsToPixel(const Vector2f& point) const;
202
228 Vector2i mapCoordsToPixel(const Vector2f& point, const View& view) const;
229
237 void draw(const Drawable& drawable, const RenderStates& states = RenderStates::Default);
238
248 void draw(const Vertex* vertices, std::size_t vertexCount,
249 PrimitiveType type, const RenderStates& states = RenderStates::Default);
250
258 void draw(const VertexBuffer& vertexBuffer, const RenderStates& states = RenderStates::Default);
259
269 void draw(const VertexBuffer& vertexBuffer, std::size_t firstVertex, std::size_t vertexCount, const RenderStates& states = RenderStates::Default);
270
277 virtual Vector2u getSize() const = 0;
278
285 virtual bool isSrgb() const;
286
307 virtual bool setActive(bool active = true);
308
341 void pushGLStates();
342
352 void popGLStates();
353
375 void resetGLStates();
376
377 protected:
378
383 RenderTarget();
384
392 void initialize();
393
394 private:
395
400 void applyCurrentView();
401
408 void applyBlendMode(const BlendMode& mode);
409
416 void applyTransform(const Transform& transform);
417
424 void applyTexture(const Texture* texture);
425
432 void applyShader(const Shader* shader);
433
441 void setupDraw(bool useVertexCache, const RenderStates& states);
442
451 void drawPrimitives(PrimitiveType type, std::size_t firstVertex, std::size_t vertexCount);
452
459 void cleanupDraw(const RenderStates& states);
460
465 struct StatesCache
466 {
467 enum {VertexCacheSize = 4};
468
469 bool enable;
470 bool glStatesSet;
471 bool viewChanged;
472 BlendMode lastBlendMode;
473 Uint64 lastTextureId;
474 bool texCoordsArrayEnabled;
475 bool useVertexCache;
476 Vertex vertexCache[VertexCacheSize];
477 };
478
480 // Member data
482 View m_defaultView;
483 View m_view;
484 StatesCache m_cache;
485 Uint64 m_id;
486};
487
488} // namespace sf
489
490
491#endif // SFML_RENDERTARGET_HPP
492
493
sf::Color
Utility class for manipulating RGBA colors.
Definition Color.hpp:41
sf::Drawable
Abstract base class for objects that can be drawn to a render target.
Definition Drawable.hpp:45
sf::NonCopyable
Utility class that makes any derived class non-copyable.
Definition NonCopyable.hpp:42
sf::Rect< int >
sf::RenderStates
Define the states used for drawing to a RenderTarget.
Definition RenderStates.hpp:46
sf::RenderTarget
Base class for all render targets (window, texture, ...)
Definition RenderTarget.hpp:53
sf::RenderTarget::mapPixelToCoords
Vector2f mapPixelToCoords(const Vector2i &point) const
Convert a point from target coordinates to world coordinates, using the current view.
sf::RenderTarget::setView
void setView(const View &view)
Change the current active view.
sf::RenderTarget::draw
void draw(const VertexBuffer &vertexBuffer, std::size_t firstVertex, std::size_t vertexCount, const RenderStates &states=RenderStates::Default)
Draw primitives defined by a vertex buffer.
sf::RenderTarget::draw
void draw(const Drawable &drawable, const RenderStates &states=RenderStates::Default)
Draw a drawable object to the render target.
sf::RenderTarget::RenderTarget
RenderTarget()
Default constructor.
sf::RenderTarget::mapPixelToCoords
Vector2f mapPixelToCoords(const Vector2i &point, const View &view) const
Convert a point from target coordinates to world coordinates.
sf::RenderTarget::getSize
virtual Vector2u getSize() const =0
Return the size of the rendering region of the target.
sf::RenderTarget::draw
void draw(const VertexBuffer &vertexBuffer, const RenderStates &states=RenderStates::Default)
Draw primitives defined by a vertex buffer.
sf::RenderTarget::clear
void clear(const Color &color=Color(0, 0, 0, 255))
Clear the entire target with a single color.
sf::RenderTarget::getDefaultView
const View & getDefaultView() const
Get the default view of the render target.
sf::RenderTarget::mapCoordsToPixel
Vector2i mapCoordsToPixel(const Vector2f &point, const View &view) const
Convert a point from world coordinates to target coordinates.
sf::RenderTarget::getViewport
IntRect getViewport(const View &view) const
Get the viewport of a view, applied to this render target.
sf::RenderTarget::pushGLStates
void pushGLStates()
Save the current OpenGL render states and matrices.
sf::RenderTarget::draw
void draw(const Vertex *vertices, std::size_t vertexCount, PrimitiveType type, const RenderStates &states=RenderStates::Default)
Draw primitives defined by an array of vertices.
sf::RenderTarget::~RenderTarget
virtual ~RenderTarget()
Destructor.
sf::RenderTarget::resetGLStates
void resetGLStates()
Reset the internal OpenGL states so that the target is ready for drawing.
sf::RenderTarget::popGLStates
void popGLStates()
Restore the previously saved OpenGL render states and matrices.
sf::RenderTarget::mapCoordsToPixel
Vector2i mapCoordsToPixel(const Vector2f &point) const
Convert a point from world coordinates to target coordinates, using the current view.
sf::RenderTarget::getView
const View & getView() const
Get the view currently in use in the render target.
sf::RenderTarget::setActive
virtual bool setActive(bool active=true)
Activate or deactivate the render target for rendering.
sf::RenderTarget::isSrgb
virtual bool isSrgb() const
Tell if the render target will use sRGB encoding when drawing on it.
sf::RenderTarget::initialize
void initialize()
Performs the common initialization step after creation.
sf::Shader
Shader class (vertex, geometry and fragment)
Definition Shader.hpp:53
sf::Texture
Image living on the graphics card that can be used for drawing.
Definition Texture.hpp:49
sf::Transform
Define a 3x3 transform matrix.
Definition Transform.hpp:43
sf::Vector2< float >
sf::VertexBuffer
Vertex buffer storage for one or more 2D primitives.
Definition VertexBuffer.hpp:47
sf::Vertex
Define a point with color and texture coordinates.
Definition Vertex.hpp:43
sf::View
2D camera that defines what region is shown on screen
Definition View.hpp:44
sf::PrimitiveType
PrimitiveType
Types of primitives that a sf::VertexArray can render.
Definition PrimitiveType.hpp:40
sf::BlendMode
Blending modes for drawing.
Definition BlendMode.hpp:42