Gamedev Framework (gf)  0.5.0
A C++11 framework for 2D games
RenderTarget.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2017 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 
197  void draw(const Vertex *vertices, int *first, const std::size_t *count, std::size_t primcount, PrimitiveType type, const RenderStates& states = RenderStates());
198 
209  void draw(const Vertex *vertices, const uint16_t **indices, const std::size_t *count, std::size_t primcount, PrimitiveType type, const RenderStates& states = RenderStates());
210 
217  void draw(const VertexBuffer& buffer, const RenderStates& states = RenderStates());
218 
225  void draw(Drawable& drawable, const RenderStates& states = RenderStates());
226 
252  void setView(const View& view);
253 
261  const View& getView() const {
262  return m_view;
263  }
264 
277  Region getCanonicalViewport(const View& view) const;
278 
291  RectI getViewport(const View& view) const;
292 
322  Vector2f mapPixelToCoords(Vector2i point, const View& view) const;
323 
343  Vector2f mapPixelToCoords(Vector2i point) const;
344 
370  Vector2i mapCoordsToPixel(Vector2f point, const View& view) const;
371 
391  Vector2i mapCoordsToPixel(Vector2f point) const;
392 
395  protected:
402  void initialize();
403 
404 
410  Image captureFramebuffer(unsigned name) const;
411 
412  private:
413  void initializeViews();
414  void initializeShader();
415  void initializeTexture();
416 
417  struct Locations {
418  int positionLoc;
419  int colorLoc;
420  int texCoordsLoc;
421  };
422 
423  void drawStart(const Vertex *vertices, const RenderStates& states, Locations& locations);
424  void drawFinish(const Locations& locations);
425 
426  private:
427  View m_view;
428  Shader m_defaultShader;
429  Shader m_defaultAlphaShader;
430  Texture m_defaultTexture;
431  };
432 
433 #ifndef DOXYGEN_SHOULD_SKIP_THIS
434 }
435 #endif
436 }
437 
438 #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
Utility class for manipulating 2D axis aligned rectangles.
Definition: Rect.h:88
Class for loading, manipulating and saving images.
Definition: Image.h:92
The namespace for gf classes.
Definition: Action.h:34
A region of a window.
Definition: Region.h:43
const View & getView() const
Get the view currently in use in the render target.
Definition: RenderTarget.h:261