Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gwn_element.h « gawain « gawain « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3081305769ff40a76dd4d2309cc1a8f9b37c7c17 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75

// Gawain element list (AKA index buffer)
//
// This code is part of the Gawain library, with modifications
// specific to integration with Blender.
//
// Copyright 2016 Mike Erwin
//
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of
// the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

#pragma once

#include "gwn_primitive.h"

#define GWN_TRACK_INDEX_RANGE 1

typedef enum {
	GWN_INDEX_U8, // GL has this, Vulkan does not
	GWN_INDEX_U16,
	GWN_INDEX_U32
} Gwn_IndexBufType;

typedef struct Gwn_IndexBuf {
	unsigned index_ct;
#if GWN_TRACK_INDEX_RANGE
	Gwn_IndexBufType index_type;
	GLenum gl_index_type;
	unsigned min_index;
	unsigned max_index;
	unsigned base_index;
#endif
	void* data; // NULL indicates data in VRAM (unmapped) or not yet allocated
	GLuint vbo_id; // 0 indicates not yet sent to VRAM
} Gwn_IndexBuf;

void GWN_indexbuf_use(Gwn_IndexBuf*);
unsigned GWN_indexbuf_size_get(const Gwn_IndexBuf*);

typedef struct Gwn_IndexBufBuilder {
	unsigned max_allowed_index;
	unsigned max_index_ct;
	unsigned index_ct;
	Gwn_PrimType prim_type;
	unsigned* data;
} Gwn_IndexBufBuilder;

// supported primitives:
//  GWN_PRIM_POINTS
//  GWN_PRIM_LINES
//  GWN_PRIM_TRIS

void GWN_indexbuf_init(Gwn_IndexBufBuilder*, Gwn_PrimType, unsigned prim_ct, unsigned vertex_ct);
//void GWN_indexbuf_init_custom(Gwn_IndexBufBuilder*, Gwn_PrimType, unsigned index_ct, unsigned vertex_ct);

void GWN_indexbuf_add_generic_vert(Gwn_IndexBufBuilder*, unsigned v);

void GWN_indexbuf_add_point_vert(Gwn_IndexBufBuilder*, unsigned v);
void GWN_indexbuf_add_line_verts(Gwn_IndexBufBuilder*, unsigned v1, unsigned v2);
void GWN_indexbuf_add_tri_verts(Gwn_IndexBufBuilder*, unsigned v1, unsigned v2, unsigned v3);

Gwn_IndexBuf* GWN_indexbuf_build(Gwn_IndexBufBuilder*);
void GWN_indexbuf_build_in_place(Gwn_IndexBufBuilder*, Gwn_IndexBuf*);

void GWN_indexbuf_discard(Gwn_IndexBuf*);


/* Macros */

#define GWN_INDEXBUF_DISCARD_SAFE(elem) do { \
	if (elem != NULL) { \
		GWN_indexbuf_discard(elem); \
		elem = NULL; \
	} \
} while (0)