cangine
Loading...
Searching...
No Matches
quad_renderer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <iostream>
4#include <vector>
5#include <optional>
6#include <cstdint>
7
8#include "../../engine/components/transform_component.hpp"
9
10#include "../../shapes/shapes.hpp"
11
12#include "../../types/types.hpp"
13
14#include "../../util/color.hpp"
15#include "../../util/position.hpp"
16
17#include "../vao.hpp"
18#include "../vbo.hpp"
19#include "../ebo.hpp"
20#include "../shader.hpp"
21#include "../texture.hpp"
22
23
24namespace cangine {
25
34 private:
35 bool currentMono = false;
36
39 static constexpr uint32_t MAX_QUADS = 10000;
40 static constexpr uint32_t MAX_VERTICES = MAX_QUADS * 4;
41 static constexpr uint32_t MAX_INDICES = MAX_QUADS * 6;
42
43 std::vector<Vertex> vertices;
44 uint32_t quadCount = 0;
45
50
51 public:
57
59 void beginFrame();
66 void draw(const Transform& transform, const Rectangle& r, bool normalize = true);
72 void draw(const Rectangle& r, bool normalize = true);
74 void flush();
80 void setTexture(Texture* t, bool mono = false);
85 void setShader(Shader* shader);
86 };
87
88}
Wraps an OpenGL Element Buffer Object (index buffer).
Definition ebo.hpp:12
Batched renderer for textured quads (rectangles).
Definition quad_renderer.hpp:33
static QuadRenderer * instance
Singleton instance.
Definition quad_renderer.hpp:37
void setTexture(Texture *t, bool mono=false)
Binds a texture for subsequent quads, flushing if it changes.
Definition quad_renderer.cpp:191
VBO vbo
Vertex buffer holding the batched data.
Definition quad_renderer.hpp:47
void draw(const Transform &transform, const Rectangle &r, bool normalize=true)
Adds a transformed rectangle to the current batch.
Definition quad_renderer.cpp:85
Shader * shader
Shader used to draw the quads.
Definition quad_renderer.hpp:49
EBO ebo
Index buffer for the quads.
Definition quad_renderer.hpp:48
VAO vao
Vertex array describing the layout.
Definition quad_renderer.hpp:46
Texture * currentTexture
Currently bound texture, if any.
Definition quad_renderer.hpp:38
std::vector< Vertex > vertices
Accumulated vertices for the current batch.
Definition quad_renderer.hpp:43
static constexpr uint32_t MAX_VERTICES
Vertex capacity (4 per quad).
Definition quad_renderer.hpp:40
static constexpr uint32_t MAX_QUADS
Maximum quads per batch.
Definition quad_renderer.hpp:39
void flush()
Submits the accumulated batch to the GPU.
Definition quad_renderer.cpp:154
uint32_t quadCount
Number of quads in the current batch.
Definition quad_renderer.hpp:44
void beginFrame()
Resets the batch at the start of a frame.
Definition quad_renderer.cpp:80
void setShader(Shader *shader)
Replaces the shader used for drawing.
Definition quad_renderer.cpp:205
static constexpr uint32_t MAX_INDICES
Index capacity (6 per quad).
Definition quad_renderer.hpp:41
bool currentMono
Whether the bound texture is single-channel.
Definition quad_renderer.hpp:35
Wraps a compiled and linked OpenGL shader program.
Definition shader.hpp:61
Wraps an OpenGL texture object.
Definition texture.hpp:12
Component holding an object's position, rotation and scale.
Definition transform_component.hpp:17
Wraps an OpenGL Vertex Array Object.
Definition vao.hpp:12
Wraps an OpenGL Vertex Buffer Object.
Definition vbo.hpp:11
Definition audiomanager.cpp:4
An axis-aligned rectangle with a position, size and color.
Definition rectangle.hpp:21