summaryrefslogtreecommitdiff
path: root/src/core/vert.c
blob: 0e62087d4f535b193d8ed8e10c1bdd206c8d8111 (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
#include "vert.h"

Vert* vert_new(uint comp) {
	Vert* vert = ssrM_new(Vert);
	vert->comp = comp;
	vert->position = ssrM_new(Vec3);
	vert->normal = ssrM_new(Vec3);
	vert->tangent = ssrM_new(Vec3);
	vert->uv = ssrM_new(Vec2);
	return vert;
}

void vert_init(Vert* v, uint comp) {
	ssr_assert(v);
	v->comp = comp;
	v->index = 0;
	if ((comp & VERTMASK_POSITION) && !v->position)
		v->position = ssrM_new(Vec3);
	else if (!(comp & VERTMASK_POSITION) && v->position)
		ssrM_free(v->position);
	if ((comp & VERTMASK_NORMAL) && !v->normal)
		v->normal = ssrM_new(Vec3);
	else if (!(comp & VERTMASK_NORMAL) && v->normal)
		ssrM_free(v->normal);
	if ((comp & VERTMASK_TANGENT) && !v->tangent)
		v->tangent = ssrM_new(Vec3);
	else if (!(comp & VERTMASK_TANGENT) && v->tangent)
		ssrM_free(v->tangent);
	if ((comp & VERTMASK_UV) && !v->uv)
		v->uv = ssrM_new(Vec2);
	else if (!(comp & VERTMASK_UV) && v->uv)
		ssrM_free(v->uv);
}

void vert_free(Vert* v) {
	ssr_assert(v);
	if (v->position) ssrM_free(v->position);
	if (v->normal) ssrM_free(v->normal);
	if (v->tangent) ssrM_free(v->tangent);
	if (v->uv) ssrM_free(v->uv);
	ssrM_free(v);
}