Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
BufferedGeometry.h
1/*
2 * Gamedev Framework (gf)
3 * Copyright (C) 2016-2022 Julien Bernard
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#ifndef GF_BUFFERED_GEOMETRY_H
22#define GF_BUFFERED_GEOMETRY_H
23
24#include "GraphicsApi.h"
25#include "Rect.h"
26#include "Texture.h"
27#include "Transformable.h"
28
29namespace gf {
30#ifndef DOXYGEN_SHOULD_SKIP_THIS
31inline namespace v1 {
32#endif
33
34 struct RenderStates;
35 class RenderTarget;
36 class VertexBuffer;
37
55 class GF_GRAPHICS_API BufferedGeometry : public Transformable {
56 public:
61
68
76 BufferedGeometry(const VertexBuffer& buffer, const VertexBuffer& outlineBuffer);
77
84 void setBuffer(const VertexBuffer& buffer) {
85 m_buffer = &buffer;
86 }
87
94 void setOutlineBuffer(const VertexBuffer& outlineBuffer) {
95 m_outlineBuffer = &outlineBuffer;
96 }
97
111 void setTexture(const BareTexture& texture) {
112 m_texture = &texture;
113 }
114
125 const BareTexture& getTexture() const {
126 return *m_texture;
127 }
128
136 bool hasTexture() const {
137 return m_texture != nullptr;
138 }
139
148 m_texture = nullptr;
149 }
150
160 void setLocalBounds(const RectF& bounds) {
161 m_bounds = bounds;
162 }
163
176 return m_bounds;
177 }
178
189 void setAnchor(Anchor anchor);
190
191 virtual void draw(RenderTarget& target, const RenderStates& states) override;
192
193 private:
194 const VertexBuffer *m_buffer;
195 const VertexBuffer *m_outlineBuffer;
196 const BareTexture *m_texture;
197 RectF m_bounds;
198 };
199
200
201#ifndef DOXYGEN_SHOULD_SKIP_THIS
202}
203#endif
204}
205
206#endif // GF_BUFFERED_GEOMETRY_H
An image that lives in the graphic memory that can be used for drawing.
Definition: Texture.h:79
A drawable for buffers.
Definition: BufferedGeometry.h:55
void setOutlineBuffer(const VertexBuffer &outlineBuffer)
Set the outline buffer, if any.
Definition: BufferedGeometry.h:94
BufferedGeometry(const VertexBuffer &buffer)
Constructor with a buffer.
void setBuffer(const VertexBuffer &buffer)
Set the vertex buffer.
Definition: BufferedGeometry.h:84
void setTexture(const BareTexture &texture)
Change the source texture of the geometry.
Definition: BufferedGeometry.h:111
virtual void draw(RenderTarget &target, const RenderStates &states) override
Draw the object to a render target.
BufferedGeometry(const VertexBuffer &buffer, const VertexBuffer &outlineBuffer)
Constructor with a buffer and an outline buffer.
bool hasTexture() const
Check if a texture is set.
Definition: BufferedGeometry.h:136
BufferedGeometry()
Default constructor.
void unsetTexture()
Unset the source texture of the geometry.
Definition: BufferedGeometry.h:147
const BareTexture & getTexture() const
Get the source texture of the geometry.
Definition: BufferedGeometry.h:125
void setLocalBounds(const RectF &bounds)
Set the local bounds of the geometry.
Definition: BufferedGeometry.h:160
void setAnchor(Anchor anchor)
Set the anchor origin of the entity.
RectF getLocalBounds() const
Get the local bounding rectangle of the entity.
Definition: BufferedGeometry.h:175
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:102
Decomposed transform defined by a position, a rotation and a scale.
Definition: Transformable.h:95
Data in the graphics memory.
Definition: VertexBuffer.h:81
Anchor
An anchor of a box.
Definition: Anchor.h:38
The namespace for gf classes.
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.h:82