summaryrefslogtreecommitdiff
path: root/themes/src/Renderer2d.h
blob: 74328947b5c0afe7001461ae7ba1be8da4a285ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma once

#include "WebglContext.h"
#include "types.h"
#include "Shader.h"
#include "mathlib.h"

struct WebglContext;

/// Responsible for rendering Mesh2Ds
struct Renderer2d {
	WebglContext* context = NULL;
	Mat4x4 projection;
	u32 shader;
    Vector4 clearColor;

	struct {
		i32 position;
		i32 color;

        // TODO: vMatrix is not standard and does not belong here
		i32 vMatrix;
	} attributes;

	struct {
		i32 projection;
		i32 model;
	} uniforms;

    /// Load with the provided context and shader programs. If the shaders are NULL, the default
    /// shader is used
	void load(WebglContext* context, const char* vertexShader = NULL, const char* fragmentShader = NULL);
	void render();
	void unload();
    f32 get_width();
    f32 get_height();
};

struct Vertex2D {
	Vector2 position;
	Vector4 color;
	Mat4x4 vMatrix;
};

struct Mesh2D {
	u32 vao;
	u32 vbo;
	u32 ebo = 0;
	u32 numVertices = 0;
	u32 numIndices = 0;
	Mat4x4 model;

	void load(Vertex2D* vertices, u32 numVertices, Renderer2d* renderer);
	void load(Vertex2D* vertices,
			  u32 numVertices,
			  u32* indices,
			  u32 numIndices,
			  Renderer2d* renderer);
	void render(Renderer2d* renderer, GLenum drawType = GL_TRIANGLES);
	void unload();
};