Blender V4.3
GPU_vertex_format.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2016 by Mike Erwin. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11#pragma once
12
13#include "BLI_assert.h"
14#include "BLI_compiler_compat.h"
15#include "BLI_math_geom.h"
16#include "GPU_common.hh"
17
18struct GPUShader;
19
20#define GPU_VERT_ATTR_MAX_LEN 16
21#define GPU_VERT_ATTR_MAX_NAMES 6
22#define GPU_VERT_ATTR_NAMES_BUF_LEN 256
23#define GPU_VERT_FORMAT_MAX_NAMES 63 /* More than enough, actual max is ~30. */
24/* Computed as GPU_VERT_ATTR_NAMES_BUF_LEN / 30 (actual max format name). */
25#define GPU_MAX_SAFE_ATTR_NAME 12
26
42
46 GPU_FETCH_INT_TO_FLOAT_UNIT, /* 127 (ubyte) -> 0.5 (and so on for other int types) */
47 GPU_FETCH_INT_TO_FLOAT, /* 127 (any int type) -> 127.0 */
48 /* Warning! adjust GPUVertAttr if changing. */
49};
50
52 /* GPUVertFetchMode */
54 /* GPUVertCompType */
56 /* 1 to 4 or 8 or 12 or 16 */
58 /* size in bytes, 1 to 64 */
60 /* from beginning of vertex, in bytes */
62 /* up to GPU_VERT_ATTR_MAX_NAMES */
65};
66
68 "We use uchar as index inside the name buffer "
69 "so GPU_VERT_ATTR_NAMES_BUF_LEN needs to be "
70 "smaller than GPUVertFormat->name_offset and "
71 "GPUVertAttr->names maximum value");
72
90
92void GPU_vertformat_copy(GPUVertFormat *dest, const GPUVertFormat &src);
94
96 GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode);
97void GPU_vertformat_alias_add(GPUVertFormat *, const char *alias);
98
111
127
128int GPU_vertformat_attr_id_get(const GPUVertFormat *, const char *name);
129
131 const GPUVertAttr *attr,
132 uint n_idx)
133{
134 return format->names + attr->names[n_idx];
135}
136
141void GPU_vertformat_attr_rename(GPUVertFormat *format, int attr, const char *new_name);
142
147void GPU_vertformat_safe_attr_name(const char *attr_name, char *r_safe_name, uint max_len);
148
149/* format conversion */
150
152 int x : 10;
153 int y : 10;
154 int z : 10;
155 int w : 2; /* 0 by default, can manually set to { -2, -1, 0, 1 } */
156};
157
158struct GPUNormal {
159 union {
161 short high[4];
162 };
163};
164
165/* OpenGL ES packs in a different order as desktop GL but component conversion is the same.
166 * Of the code here, only GPUPackedNormal needs to change. */
167
168#define SIGNED_INT_10_MAX 511
169#define SIGNED_INT_10_MIN -512
170
171BLI_INLINE int clampi(int x, int min_allowed, int max_allowed)
172{
173#if TRUST_NO_ONE
174 assert(min_allowed <= max_allowed);
175#endif
176 if (x < min_allowed) {
177 return min_allowed;
178 }
179 else if (x > max_allowed) {
180 return max_allowed;
181 }
182 else {
183 return x;
184 }
185}
186
188{
189 int qx = x * 511.0f;
191}
192
194{
195 /* 16-bit signed --> 10-bit signed */
196 /* TODO: round? */
197 return x >> 6;
198}
199
209
211{
212 GPUPackedNormal n = {
213 gpu_convert_i16_to_i10(data[0]),
214 gpu_convert_i16_to_i10(data[1]),
215 gpu_convert_i16_to_i10(data[2]),
216 };
217 return n;
218}
219
221 const float data[3],
222 const bool do_hq_normals)
223{
224 if (do_hq_normals) {
225 normal_float_to_short_v3(gpu_normal->high, data);
226 }
227 else {
228 gpu_normal->low = GPU_normal_convert_i10_v3(data);
229 }
230}
#define BLI_STATIC_ASSERT(a, msg)
Definition BLI_assert.h:87
#define BLI_INLINE
MINLINE void normal_float_to_short_v3(short out[3], const float in[3])
unsigned char uchar
unsigned int uint
#define GPU_VERT_ATTR_MAX_NAMES
void GPU_vertformat_attr_rename(GPUVertFormat *format, int attr, const char *new_name)
void GPU_vertformat_safe_attr_name(const char *attr_name, char *r_safe_name, uint max_len)
BLI_INLINE const char * GPU_vertformat_attr_name_get(const GPUVertFormat *format, const GPUVertAttr *attr, uint n_idx)
GPUVertFetchMode
@ GPU_FETCH_FLOAT
@ GPU_FETCH_INT_TO_FLOAT_UNIT
@ GPU_FETCH_INT
@ GPU_FETCH_INT_TO_FLOAT
BLI_INLINE GPUPackedNormal GPU_normal_convert_i10_s3(const short data[3])
BLI_INLINE int gpu_convert_normalized_f32_to_i10(float x)
#define SIGNED_INT_10_MIN
#define GPU_VERT_ATTR_NAMES_BUF_LEN
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
BLI_INLINE int gpu_convert_i16_to_i10(short x)
BLI_INLINE void GPU_normal_convert_v3(GPUNormal *gpu_normal, const float data[3], const bool do_hq_normals)
void GPU_vertformat_multiload_enable(GPUVertFormat *format, int load_count)
BLI_INLINE int clampi(int x, int min_allowed, int max_allowed)
void GPU_vertformat_clear(GPUVertFormat *)
#define SIGNED_INT_10_MAX
void GPU_vertformat_copy(GPUVertFormat *dest, const GPUVertFormat &src)
#define GPU_VERT_ATTR_MAX_LEN
BLI_INLINE GPUPackedNormal GPU_normal_convert_i10_v3(const float data[3])
void GPU_vertformat_alias_add(GPUVertFormat *, const char *alias)
int GPU_vertformat_attr_id_get(const GPUVertFormat *, const char *name)
void GPU_vertformat_deinterleave(GPUVertFormat *format)
void GPU_vertformat_from_shader(GPUVertFormat *format, const GPUShader *shader)
GPUVertCompType
@ GPU_COMP_U16
@ GPU_COMP_MAX
@ GPU_COMP_I10
@ GPU_COMP_F32
@ GPU_COMP_I32
@ GPU_COMP_I8
@ GPU_COMP_U32
@ GPU_COMP_I16
@ GPU_COMP_U8
struct GPUShader GPUShader
format
GPUPackedNormal low
uchar names[GPU_VERT_ATTR_MAX_NAMES]
GPUVertAttr attrs[GPU_VERT_ATTR_MAX_LEN]
char names[GPU_VERT_ATTR_NAMES_BUF_LEN]