JNGL
framebuffer.hpp
Go to the documentation of this file.
1 // Copyright 2012-2020 Jan Niklas Hasse <[email protected]>
2 // For conditions of distribution and use, see copyright notice in LICENSE.txt
5 #pragma once
6 
7 #include "Color.hpp"
8 #include "Finally.hpp"
9 #include "Vec2.hpp"
10 #include "Vertex.hpp"
11 
12 #include <memory>
13 #include <vector>
14 
15 namespace jngl {
16 
17 class ShaderProgram;
18 
20 class FrameBuffer {
21 public:
23  FrameBuffer(int width, int height);
24 
25  FrameBuffer(const FrameBuffer&) = delete;
26  FrameBuffer& operator=(const FrameBuffer&) = delete;
27  FrameBuffer(FrameBuffer&&) = default;
28  FrameBuffer& operator=(FrameBuffer&&) = default;
29  ~FrameBuffer();
30 
32  struct Context {
33  explicit Context(std::function<void()> resetCallback);
34  Context(const Context&) = delete;
35  Context& operator=(const Context&) = delete;
36  Context(Context&&) noexcept;
37  Context& operator=(Context&&) noexcept;
38  ~Context();
39 
41  void clear();
42 
44  void clear(Color color);
45 
46  private:
47  std::function<void()> resetCallback;
48  };
49 
50 #if __cplusplus >= 201703L
51  [[nodiscard]]
52 #endif
53  Context use() const;
54 
56  void draw(Vec2 position, const ShaderProgram* = nullptr) const;
57  void draw(double x, double y) const;
58 
60  void drawMesh(const std::vector<Vertex>& vertexes, const ShaderProgram* = nullptr) const;
61 
64  [[deprecated("use jngl::FrameBuffer::Context::clear(Color) instead")]]
65  static void clear();
66 
68  Vec2 getSize() const;
69 
75  uint32_t getTextureID() const;
76 
77 private:
78  struct Impl;
80 };
81 
82 } // namespace jngl
jngl::FrameBuffer::getTextureID
uint32_t getTextureID() const
Returns the OpenGL texture ID of the associated image buffer.
Finally.hpp
vector
Vertex.hpp
std::function
jngl::FrameBuffer::Context
Lifetime object when the FrameBuffer is in use.
Definition: framebuffer.hpp:32
jngl::FrameBuffer
Image framebuffer object which can be rendered on.
Definition: framebuffer.hpp:20
jngl
JNGL's main namespace.
Definition: App.hpp:9
Vec2.hpp
jngl::FrameBuffer::getSize
Vec2 getSize() const
Returns the size in screen pixels.
jngl::FrameBuffer::FrameBuffer
FrameBuffer(int width, int height)
Creates a framebuffer object with width times height pixels.
jngl::FrameBuffer::drawMesh
void drawMesh(const std::vector< Vertex > &vertexes, const ShaderProgram *=nullptr) const
Draws a list of triangles with the framebuffer's texture on it.
jngl::FrameBuffer::Context::clear
void clear(Color color)
Clear the framebuffer with color.
memory
jngl::FrameBuffer::draw
void draw(Vec2 position, const ShaderProgram *=nullptr) const
Draws the framebuffer image to the screen.
jngl::Color
Object representing a RGB color.
Definition: Color.hpp:24
Color.hpp
jngl::Vec2
Two-dimensional vector.
Definition: Vec2.hpp:14
jngl::FrameBuffer::Context::clear
void clear()
Clear the framebuffer with a transparent background.
std::unique_ptr< Impl >
jngl::FrameBuffer::clear
static void clear()
Clear the framebuffer with the color set by jngl::setBackgroundColor.
jngl::ShaderProgram
Linked vertex and fragment shaders.
Definition: ShaderProgram.hpp:17