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 "base/rect.h"
6
7// #include "tred/types.h"
8#include "base/vec2.h"
9#include "base/vec3.h"
10#include "base/vec4.h"
11
12#include "render/shader.h"
13#include "render/texture.h"
14
15#include "base/colors.h"
16
17
18namespace eu::render
19{
20
21struct SpriteBatch;
22struct OpenglStates;
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;
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
101
110
112{
114};
115
116
123
130
131
133{
135};
136
138{
142
143 // todo(Gustav): add clear to color function
144 void clear(const Rgb& color, const LayoutData& ld) const;
145 void clear(const Rgb& color, const LerpData& ld) const;
146};
147
148
150// Functions
151
152
153// todo(Gustav): pass camera to with_ functions
154// todo(Gustav): move to member functions
155
159
163
164}
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
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)
std::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
A (inclusive) range between two values.
Definition range.h:19
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:119
LayoutData rhs
Definition canvas.h:127
LayoutData lhs
Definition canvas.h:126
A "cache" for the current open gl state.
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
CompiledShaderVertexAttributes quad_layout
Definition canvas.h:85
Uniform view_projection_uniform
Definition canvas.h:87
ShaderProgram quad_shader
Definition canvas.h:86
ShaderVertexAttributes quad_description
Definition canvas.h:84
Uniform texture_uniform
Definition canvas.h:89
Render2(OpenglStates *states)
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
OpenglStates * states
Definition canvas.h:139
SpriteBatch * batch
Definition canvas.h:104
RenderLayer2(const Layer &l, SpriteBatch *batch)
RenderLayer3(const Layer &l)
RAII representation of a open gl shader program.
Definition shader.h:25
OpenglStates * states
Definition canvas.h:57
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(OpenglStates *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 2d image texture.
Definition texture.h:89
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