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-2024 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#pragma once
26
28// Headers
31
41
43
44#include <array>
45
46#include <cstddef>
47#include <cstdint>
48
49
50namespace sf
51{
52class Drawable;
53class Shader;
54class Texture;
55class Transform;
56class VertexBuffer;
57
63{
64public:
69 virtual ~RenderTarget() = default;
70
75 RenderTarget(const RenderTarget&) = delete;
76
82
87 RenderTarget(RenderTarget&&) noexcept = default;
88
93 RenderTarget& operator=(RenderTarget&&) noexcept = default;
94
104 void clear(Color color = Color::Black);
105
115 void clearStencil(StencilValue stencilValue);
116
127 void clear(Color color, StencilValue stencilValue);
128
148 void setView(const View& view);
149
158 [[nodiscard]] const View& getView() const;
159
171 [[nodiscard]] const View& getDefaultView() const;
172
186 [[nodiscard]] IntRect getViewport(const View& view) const;
187
201 [[nodiscard]] IntRect getScissor(const View& view) const;
202
221 [[nodiscard]] Vector2f mapPixelToCoords(Vector2i point) const;
222
252 [[nodiscard]] Vector2f mapPixelToCoords(Vector2i point, const View& view) const;
253
272 [[nodiscard]] Vector2i mapCoordsToPixel(Vector2f point) const;
273
299 [[nodiscard]] Vector2i mapCoordsToPixel(Vector2f point, const View& view) const;
300
308 void draw(const Drawable& drawable, const RenderStates& states = RenderStates::Default);
309
319 void draw(const Vertex* vertices,
320 std::size_t vertexCount,
321 PrimitiveType type,
322 const RenderStates& states = RenderStates::Default);
323
331 void draw(const VertexBuffer& vertexBuffer, const RenderStates& states = RenderStates::Default);
332
342 void draw(const VertexBuffer& vertexBuffer,
343 std::size_t firstVertex,
344 std::size_t vertexCount,
345 const RenderStates& states = RenderStates::Default);
346
353 [[nodiscard]] virtual Vector2u getSize() const = 0;
354
361 [[nodiscard]] virtual bool isSrgb() const;
362
383 [[nodiscard]] virtual bool setActive(bool active = true);
384
417 void pushGLStates();
418
428 void popGLStates();
429
451 void resetGLStates();
452
453protected:
458 RenderTarget() = default;
459
467 void initialize();
468
469private:
474 void applyCurrentView();
475
482 void applyBlendMode(const BlendMode& mode);
483
490 void applyStencilMode(const StencilMode& mode);
491
498 void applyTransform(const Transform& transform);
499
507 void applyTexture(const Texture* texture, CoordinateType coordinateType = CoordinateType::Pixels);
508
515 void applyShader(const Shader* shader);
516
524 void setupDraw(bool useVertexCache, const RenderStates& states);
525
534 void drawPrimitives(PrimitiveType type, std::size_t firstVertex, std::size_t vertexCount);
535
542 void cleanupDraw(const RenderStates& states);
543
548 struct StatesCache
549 {
550 bool enable{};
551 bool glStatesSet{};
552 bool viewChanged{};
553 bool scissorEnabled{};
554 bool stencilEnabled{};
555 BlendMode lastBlendMode;
556 StencilMode lastStencilMode;
557 std::uint64_t lastTextureId{};
558 CoordinateType lastCoordinateType{};
559 bool texCoordsArrayEnabled{};
560 bool useVertexCache{};
561 std::array<Vertex, 4> vertexCache{};
562 };
563
565 // Member data
567 View m_defaultView;
568 View m_view;
569 StatesCache m_cache{};
570 std::uint64_t m_id{};
571};
572
573} // namespace sf
574
575
#define SFML_GRAPHICS_API
Utility class for manipulating RGBA colors.
Definition Color.hpp:40
Abstract base class for objects that can be drawn to a render target.
Definition Drawable.hpp:44
Base class for all render targets (window, texture, ...)
RenderTarget(RenderTarget &&) noexcept=default
Move constructor.
RenderTarget & operator=(const RenderTarget &)=delete
Deleted copy assignment.
virtual ~RenderTarget()=default
Destructor.
RenderTarget(const RenderTarget &)=delete
Deleted copy constructor.
Shader class (vertex, geometry and fragment)
Definition Shader.hpp:54
Image living on the graphics card that can be used for drawing.
Definition Texture.hpp:56
3x3 transform matrix
Definition Transform.hpp:48
Vertex buffer storage for one or more 2D primitives.
2D camera that defines what region is shown on screen
Definition View.hpp:46
CoordinateType
Types of texture coordinates that can be used for rendering.
PrimitiveType
Types of primitives that a sf::VertexArray can render.
Blending modes for drawing.
Definition BlendMode.hpp:41
Define the states used for drawing to a RenderTarget
Stencil modes for drawing.
Stencil value type (also used as a mask)
Point with color and texture coordinates.
Definition Vertex.hpp:44