Gamedev Framework (gf)  0.11.0
A C++14 framework for 2D games
RenderTarget.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2018 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 "Image.h"
30 #include "Matrix.h"
31 #include "Portability.h"
32 #include "PrimitiveType.h"
33 #include "Range.h"
34 #include "Region.h"
35 #include "RenderStates.h"
36 #include "Shader.h"
37 #include "View.h"
38 
39 namespace gf {
40 #ifndef DOXYGEN_SHOULD_SKIP_THIS
41 inline namespace v1 {
42 #endif
43 
44  class Drawable;
45  class VertexBuffer;
46  struct Vertex;
47 
66  class GF_API RenderTarget {
67  public:
68 
72  RenderTarget() = default;
73 
77  virtual ~RenderTarget();
78 
82  RenderTarget(const RenderTarget&) = delete;
83 
87  RenderTarget& operator=(const RenderTarget&) = delete;
88 
94  virtual Vector2u getSize() const = 0;
95 
106  Region getCanonicalScissorBox();
107 
113  void setCanonicalScissorBox(const Region& box);
114 
120  RectI getScissorBox();
121 
127  void setScissorBox(const RectI& box);
128 
137  void clear(const Color4f& color);
138 
148  void clear();
149 
156  RangeF getAliasedLineWidthRange() const;
157 
164  float getLineWidth() const;
165 
174  void draw(const Vertex *vertices, std::size_t count, PrimitiveType type, const RenderStates& states = RenderStates());
175 
185  void draw(const Vertex *vertices, const uint16_t *indices, std::size_t count, PrimitiveType type, const RenderStates& states = RenderStates());
186 
193  void draw(const VertexBuffer& buffer, const RenderStates& states = RenderStates());
194 
201  void draw(Drawable& drawable, const RenderStates& states = RenderStates());
202 
228  void setView(const View& view);
229 
237  const View& getView() const {
238  return m_view;
239  }
240 
253  Region getCanonicalViewport(const View& view) const;
254 
267  RectI getViewport(const View& view) const;
268 
298  Vector2f mapPixelToCoords(Vector2i point, const View& view) const;
299 
319  Vector2f mapPixelToCoords(Vector2i point) const;
320 
346  Vector2i mapCoordsToPixel(Vector2f point, const View& view) const;
347 
367  Vector2i mapCoordsToPixel(Vector2f point) const;
368 
371  protected:
378  void initialize();
379 
380 
386  Image captureFramebuffer(unsigned name) const;
387 
388  private:
389  void initializeViews();
390  void initializeShader();
391  void initializeTexture();
392 
393  struct Locations {
394  int positionLoc;
395  int colorLoc;
396  int texCoordsLoc;
397  };
398 
399  void drawStart(const RenderStates& states, Locations& locations);
400  void drawFinish(const Locations& locations);
401 
402  private:
403  View m_view;
404  Shader m_defaultShader;
405  Shader m_defaultAlphaShader;
406  Texture m_defaultTexture;
407  };
408 
409 #ifndef DOXYGEN_SHOULD_SKIP_THIS
410 }
411 #endif
412 }
413 
414 #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:42
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:66
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:70
Abstract base class for objects that can be drawn to a render window.
Definition: Drawable.h:79
An OpenGL vertex and/or fragment shader.
Definition: Shader.h:120
A texture for colored images.
Definition: Texture.h:339
Class for loading, manipulating and saving images.
Definition: Image.h:92
The namespace for gf classes.
Definition: Action.h:35
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:237