GameKit  0.0.1a
C++ gamedev tools
RenderTarget.hpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: RenderTarget.hpp
5  *
6  * Description:
7  *
8  * Created: 14/06/2018 19:54:56
9  *
10  * Author: Quentin Bazin, <quent42340@gmail.com>
11  *
12  * =====================================================================================
13  */
14 #ifndef GK_RENDERTARGET_HPP_
15 #define GK_RENDERTARGET_HPP_
16 
17 #include "gk/core/Rect.hpp"
18 #include "gk/gl/OpenGL.hpp"
19 #include "gk/gl/RenderStates.hpp"
20 #include "gk/gl/View.hpp"
21 
22 namespace gk {
23 
24 class IDrawable;
25 class VertexBuffer;
26 
27 class RenderTarget {
28  public:
29  void draw(const IDrawable &drawable, const RenderStates &states = RenderStates::Default);
30  void draw(const VertexBuffer &vertexBuffer, GLenum mode, std::size_t firstVertex, std::size_t vertexCount, const RenderStates &states = RenderStates::Default);
31  void drawElements(const VertexBuffer &vertexBuffer, GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, const RenderStates &states = RenderStates::Default);
32 
33  virtual Vector2u getSize() const = 0;
34 
35  virtual const View &getDefaultView() const = 0;
36 
37  const View *getView() const { return m_view; }
38  void setView(const View &view) { m_view = &view; m_viewChanged = true; }
39  void disableView() { m_view = nullptr; }
40 
41  private:
42  void beginDrawing(const RenderStates &states);
43  void endDrawing(const RenderStates &states);
44 
45  IntRect getViewport(const View &view) const;
46 
47  void applyCurrentView(const RenderStates &states);
48 
49  bool m_viewChanged = false;
50  const View *m_view = nullptr;
51 
53 };
54 
55 } // namespace gk
56 
57 #endif // GK_RENDERTARGET_HPP_
void beginDrawing(const RenderStates &states)
2D view that defines what is shown on screen
Definition: View.hpp:29
void applyCurrentView(const RenderStates &states)
IntRect getViewport(const View &view) const
void endDrawing(const RenderStates &states)
virtual Vector2u getSize() const =0
void setView(const View &view)
void draw(const IDrawable &drawable, const RenderStates &states=RenderStates::Default)
const View * m_view
static const RenderStates Default
IntRect m_previousViewport
Abstract base class for objects that can be drawn to a render target.
Definition: IDrawable.hpp:25
virtual const View & getDefaultView() const =0
void drawElements(const VertexBuffer &vertexBuffer, GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, const RenderStates &states=RenderStates::Default)
const View * getView() const