summaryrefslogtreecommitdiff
path: root/shared_cpp/Renderer2d.h
blob: bada0eabab7e5bdfaf9ce335f4c1e8621c960fa8 (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
#pragma once

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

struct WebglContext;

struct Renderer2d {
	Mat4x4 projection;
	uint32 shader;
	WebglContext* context;

	struct {
		int32 position;
		int32 color;
	} attributes;

	struct {
		int32 projection;
		int32 model;
	} uniforms;

	void load(WebglContext* context);
	void render();
	void unload();
};

struct Vertex2d {
	Vector4 position;
	Vector4 color;
};

enum MeshMode {
	Vertex = 0,
	Index = 1
};

struct Mesh2d {
	MeshMode mode = MeshMode::Vertex;
	uint32 vao;
	uint32 vbo;
	uint32 ebo;
	uint32 numVertices = 0;
	uint32 numIndices = 0;
	Mat4x4 model;
	bool isDynamic = false;

	void load(Vertex2d* vertices, uint32 numVertices, Renderer2d* renderer, GLenum loadType = GL_STATIC_DRAW);
	void load(Vertex2d* vertices, uint32 numVertices, GLuint* indices, uint32 numIndices, Renderer2d* renderer, GLenum loadType = GL_STATIC_DRAW);
	void render(Renderer2d* renderer, GLenum drawType = GL_TRIANGLES);
	void unload();

	void updateVertices(Vertex2d* vertices);
};