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
|
// 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 "primitive.h"
#define TRACK_INDEX_RANGE 1
typedef enum {
INDEX_U8 = GL_UNSIGNED_BYTE, // GL has this, Vulkan does not
INDEX_U16 = GL_UNSIGNED_SHORT,
INDEX_U32 = GL_UNSIGNED_INT
} IndexType;
typedef struct {
unsigned index_ct;
#if TRACK_INDEX_RANGE
IndexType 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
} ElementList;
void ElementList_use(ElementList*);
unsigned ElementList_size(const ElementList*);
typedef struct {
unsigned max_allowed_index;
unsigned max_index_ct;
unsigned index_ct;
PrimitiveType prim_type;
unsigned* data;
} ElementListBuilder;
// supported primitives:
// PRIM_POINTS
// PRIM_LINES
// PRIM_TRIANGLES
void ElementListBuilder_init(ElementListBuilder*, PrimitiveType, unsigned prim_ct, unsigned vertex_ct);
//void ElementListBuilder_init_custom(ElementListBuilder*, PrimitiveType, unsigned index_ct, unsigned vertex_ct);
void add_generic_vertex(ElementListBuilder*, unsigned v);
void add_point_vertex(ElementListBuilder*, unsigned v);
void add_line_vertices(ElementListBuilder*, unsigned v1, unsigned v2);
void add_triangle_vertices(ElementListBuilder*, unsigned v1, unsigned v2, unsigned v3);
ElementList* ElementList_build(ElementListBuilder*);
void ElementList_build_in_place(ElementListBuilder*, ElementList*);
void ElementList_discard(ElementList*);
|