Euphoria
canvas.h
Go to the documentation of this file.
1#pragma once
2
3// todo(Gustav): figure out a beter name than canvas
4
5#include "eu/base/rect.h"
6
7// #include "tred/types.h"
8#include "eu/base/vec2.h"
9#include "eu/base/vec3.h"
10#include "eu/base/vec4.h"
11
12#include "eu/render/shader.h"
13#include "eu/render/texture.h"
14
15#include "eu/base/colors.h"
16
17
18namespace eu::render
19{
20
21struct SpriteBatch;
22struct State;
23struct ShaderProgram;
24struct Render2;
25
26
28
29
36
38{
41};
42
43struct Quad
44{
45 std::optional<const Texture2d*> texture = std::nullopt;
46 std::optional<Rect> texturecoord = std::nullopt;
48 std::optional<RotateQuad> rotation = std::nullopt;
49
50 void draw(SpriteBatch* batch, const Rect& screen);
51};
52
54{
55 static constexpr int max_quads = 100;
56
58 std::vector<float> data;
59 int quads = 0;
60 const Texture2d* current_texture = nullptr;
61 u32 va = 0;
62 u32 vb = 0;
63 u32 ib = 0;
66
69
70 SpriteBatch(const SpriteBatch&) = delete;
71 void operator=(const SpriteBatch&) = delete;
73 void operator=(SpriteBatch&&) = delete;
74
75 void quad(std::optional<const Texture2d*> texture, const Vertex2& v0, const Vertex2& v1, const Vertex2& v2, const Vertex2& v3);
76
77 void submit();
78};
79
93
94struct Layer
95{
98
99 [[nodiscard]] v2 mouse_to_world(const v2& p) const;
100};
101
103{
105
108
110 RenderLayer2(const RenderLayer2&) = delete;
111 void operator=(RenderLayer2&&) = delete;
112 void operator=(const RenderLayer2&) = delete;
113};
114
116{
118};
119
120
127
134
135
137{
139};
140
142{
146
147 // todo(Gustav): add clear to color function
148 void clear(const Rgb& color, const LayoutData& ld) const;
149 void clear(const Rgb& color, const LerpData& ld) const;
150};
151
152
154// Functions
155
156
157// todo(Gustav): pass camera to with_ functions
158// todo(Gustav): move to member functions
159
163
166Layer with_layer(const InputCommand& rc, const LerpData& ld);
167
168}
std::vector< VertexElementDescription > ShaderVertexAttributes
Describes all vertex inputs a shader requires like [vec3 position, vec3 normal, vec2 uv].
constexpr auto white
Definition colors.h:156
Definition ui.h:4
RenderLayer2 with_layer2(const RenderCommand &rc, const LayoutData &ld)
ViewportStyle
Definition canvas.h:27
Layer with_layer(const InputCommand &rc, const LayoutData &ld)
RenderLayer3 with_layer3(const RenderCommand &rc, const LayoutData &ld)
uint32_t u32
Definition ints.h:14
An angle in both degrees and radians.
Definition angle.h:13
Represents a color with an alpha component. The color is stored in gamma (non-linear) space (aka sRGB...
Definition colors.h:75
Represents color in gamma (non-linear) space (aka sRGB).
Definition colors.h:14
a size
Definition size.h:11
A list of CompiledVertexElement (for shader).
Rect viewport_aabb_in_worldspace
Definition canvas.h:96
v2 mouse_to_world(const v2 &p) const
ViewportStyle style
Definition canvas.h:123
LayoutData rhs
Definition canvas.h:131
LayoutData lhs
Definition canvas.h:130
std::optional< const Texture2d * > texture
Definition canvas.h:45
std::optional< Rect > texturecoord
Definition canvas.h:46
void draw(SpriteBatch *batch, const Rect &screen)
std::optional< RotateQuad > rotation
Definition canvas.h:48
Render2(State *states)
Uniform view_projection_uniform
Definition canvas.h:87
core::CompiledShaderVertexAttributes quad_layout
Definition canvas.h:85
ShaderProgram quad_shader
Definition canvas.h:86
Uniform texture_uniform
Definition canvas.h:89
core::ShaderVertexAttributes quad_description
Definition canvas.h:84
Uniform transform_uniform
Definition canvas.h:88
SpriteBatch batch
Definition canvas.h:91
void clear(const Rgb &color, const LayoutData &ld) const
void clear(const Rgb &color, const LerpData &ld) const
SpriteBatch * batch
Definition canvas.h:104
RenderLayer2(const RenderLayer2 &)=delete
RenderLayer2(RenderLayer2 &&)=delete
void operator=(RenderLayer2 &&)=delete
void operator=(const RenderLayer2 &)=delete
RenderLayer2(const Layer &l, SpriteBatch *batch)
RenderLayer3(const Layer &l)
RAII representation of a open gl shader program.
Definition shader.h:28
void operator=(const SpriteBatch &)=delete
std::vector< float > data
Definition canvas.h:58
SpriteBatch(const SpriteBatch &)=delete
Texture2d white_texture
Definition canvas.h:65
SpriteBatch(State *states, ShaderProgram *shader, Render2 *r)
void quad(std::optional< const Texture2d * > texture, const Vertex2 &v0, const Vertex2 &v1, const Vertex2 &v2, const Vertex2 &v3)
const Texture2d * current_texture
Definition canvas.h:60
SpriteBatch(SpriteBatch &&)=delete
void operator=(SpriteBatch &&)=delete
static constexpr int max_quads
Definition canvas.h:55
A "cache" for the current open gl state.
Definition state.h:119
A 2d image texture.
Definition texture.h:74
Represents a found shader uniform and created via ShaderProgram::GetUniform().
Definition uniform.h:9
a 2d vector
Definition vec2.h:17
a 3d vector
Definition vec3.h:27