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

gwn_vertex_format.h « gawain « gawain « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 503c2d03c42cf65a157ecd4b73f82b951234f066 (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
76
77
78

// Gawain vertex format
//
// 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_common.h"

#define GWN_VERT_ATTR_MAX_LEN 16
#define GWN_VERT_ATTR_MAX_NAMES 3
#define GWN_VERT_ATTR_NAME_AVERAGE_LEN 11
#define GWN_VERT_ATTR_NAMES_BUF_LEN ((GWN_VERT_ATTR_NAME_AVERAGE_LEN + 1) * GWN_VERT_ATTR_MAX_LEN)

typedef enum {
	GWN_COMP_I8,
	GWN_COMP_U8,
	GWN_COMP_I16,
	GWN_COMP_U16,
	GWN_COMP_I32,
	GWN_COMP_U32,

	GWN_COMP_F32,

	GWN_COMP_I10
} Gwn_VertCompType;

typedef enum {
	GWN_FETCH_FLOAT,
	GWN_FETCH_INT,
	GWN_FETCH_INT_TO_FLOAT_UNIT, // 127 (ubyte) -> 0.5 (and so on for other int types)
	GWN_FETCH_INT_TO_FLOAT // 127 (any int type) -> 127.0
} Gwn_VertFetchMode;

typedef struct Gwn_VertAttr {
	Gwn_VertFetchMode fetch_mode;
	Gwn_VertCompType comp_type;
	unsigned gl_comp_type;
	unsigned comp_ct; // 1 to 4 or 8 or 12 or 16
	unsigned sz; // size in bytes, 1 to 64
	unsigned offset; // from beginning of vertex, in bytes
	unsigned name_ct; // up to GWN_VERT_ATTR_MAX_NAMES
	const char* name[GWN_VERT_ATTR_MAX_NAMES];
} Gwn_VertAttr;

typedef struct Gwn_VertFormat {
	unsigned attrib_ct; // 0 to 16 (GWN_VERT_ATTR_MAX_LEN)
	unsigned name_ct; // total count of active vertex attrib
	unsigned stride; // stride in bytes, 1 to 256
	unsigned name_offset;
	bool packed;
	char names[GWN_VERT_ATTR_NAMES_BUF_LEN];
	Gwn_VertAttr attribs[GWN_VERT_ATTR_MAX_LEN]; // TODO: variable-size attribs array
} Gwn_VertFormat;

void GWN_vertformat_clear(Gwn_VertFormat*);
void GWN_vertformat_copy(Gwn_VertFormat* dest, const Gwn_VertFormat* src);

unsigned GWN_vertformat_attr_add(Gwn_VertFormat*, const char* name, Gwn_VertCompType, unsigned comp_ct, Gwn_VertFetchMode);
void GWN_vertformat_alias_add(Gwn_VertFormat*, const char* alias);

// format conversion

typedef struct Gwn_PackedNormal {
	int x : 10;
	int y : 10;
	int z : 10;
	int w : 2;	// 0 by default, can manually set to { -2, -1, 0, 1 }
} Gwn_PackedNormal;

Gwn_PackedNormal GWN_normal_convert_i10_v3(const float data[3]);
Gwn_PackedNormal GWN_normal_convert_i10_s3(const short data[3]);