Gamedev Framework (gf)  0.14.0
A C++14 framework for 2D games
RenderTarget.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2019 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  * Part of this file comes from SFML, with the same license:
22  * Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
23  */
24 #ifndef GF_RENDER_TARGET_H
25 #define GF_RENDER_TARGET_H
26 
27 #include <cstdint>
28 
29 #include "GraphicsHandle.h"
30 #include "Image.h"
31 #include "Matrix.h"
32 #include "Portability.h"
33 #include "PrimitiveType.h"
34 #include "Range.h"
35 #include "Region.h"
36 #include "RenderStates.h"
37 #include "Shader.h"
38 #include "View.h"
39 
40 namespace gf {
41 #ifndef DOXYGEN_SHOULD_SKIP_THIS
42 inline namespace v1 {
43 #endif
44 
45  class Drawable;
46  class VertexBuffer;
47  struct Vertex;
48 
49  template<>
51  static void gen(int n, unsigned* resources);
52  static void del(int n, const unsigned* resources);
53  };
54 
73  class GF_API RenderTarget {
74  public:
75 
81  RenderTarget(Vector2i size);
82 
86  virtual ~RenderTarget();
87 
91  RenderTarget(const RenderTarget&) = delete;
92 
96  RenderTarget& operator=(const RenderTarget&) = delete;
97 
103  virtual Vector2i getSize() const = 0;
104 
115  Region getCanonicalScissorBox();
116 
122  void setCanonicalScissorBox(const Region& box);
123 
129  RectI getScissorBox();
130 
136  void setScissorBox(const RectI& box);
137 
146  void clear(const Color4f& color);
147 
157  void clear();
158 
165  RangeF getAliasedLineWidthRange() const;
166 
173  float getLineWidth() const;
174 
183  void draw(const Vertex *vertices, std::size_t count, PrimitiveType type, const RenderStates& states = RenderStates());
184 
194  void draw(const Vertex *vertices, const uint16_t *indices, std::size_t count, PrimitiveType type, const RenderStates& states = RenderStates());
195 
202  void draw(const VertexBuffer& buffer, const RenderStates& states = RenderStates());
203 
210  void draw(Drawable& drawable, const RenderStates& states = RenderStates());
211 
237  void setView(const View& view);
238 
246  const View& getView() const {
247  return m_view;
248  }
249 
262  Region getCanonicalViewport(const View& view) const;
263 
276  RectI getViewport(const View& view) const;
277 
307  Vector2f mapPixelToCoords(Vector2i point, const View& view) const;
308 
328  Vector2f mapPixelToCoords(Vector2i point) const;
329 
355  Vector2i mapCoordsToPixel(Vector2f point, const View& view) const;
356 
376  Vector2i mapCoordsToPixel(Vector2f point) const;
377 
380  protected:
386  Image captureFramebuffer(unsigned name) const;
387 
388  private:
389  struct Locations {
390  int data[3];
391  };
392 
393  void drawStart(const RenderStates& states, Locations& locations);
394  void drawFinish(const Locations& locations);
395 
396  private:
397  View m_view;
398  Shader m_defaultShader;
399  Shader m_defaultAlphaShader;
400  Texture m_defaultTexture;
401  };
402 
403 #ifndef DOXYGEN_SHOULD_SKIP_THIS
404 }
405 #endif
406 }
407 
408 #endif // GF_RENDER_TARGET_H
2D camera that defines what region is shown on screen
Definition: View.h:94
A half-open range of values.
Definition: Range.h:43
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:73
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.h:82
A point associated with a color and a texture coordinate.
Definition: Vertex.h:75
PrimitiveType
Kind of primitives to render.
Definition: PrimitiveType.h:43
Data in the graphics memory.
Definition: VertexBuffer.h:77
Definition: GraphicsHandle.h:41
Abstract base class for objects that can be drawn to a render window.
Definition: Drawable.h:57
An OpenGL vertex and/or fragment shader.
Definition: Shader.h:120
A texture for colored images.
Definition: Texture.h:301
GraphicsTag
Definition: GraphicsHandle.h:34
Class for loading, manipulating and saving images.
Definition: Image.h:80
The namespace for gf classes.
Definition: Action.h:35
A 4D vector.
Definition: Vector.h:838
A region of a window.
Definition: Region.h:40
const View & getView() const
Get the view currently in use in the render target.
Definition: RenderTarget.h:246