此函数为特定顶点格式属性添加自定义数据类型,作为创建的新顶点格式的一部分。
要使用的可用值由您选择的数据类型常量定义,如下所示:
顶点数据类型常量 | |
---|---|
常量 | 描述 |
vertex_type_float1 | A single floating point value |
vertex_type_float2 | Two floating point values |
vertex_type_float3 | Three floating point values |
vertex_type_float4 | Four floating point values |
vertex_type_colour | Four component values (r, g, b, a) |
vertex_type_ubyte4 | Four component unsigned byte values (from 0 to 255) |
还需要定义这些常量的用途,以便可以在所创建的着色器中正确 " 绑定 " 这些值。这是必要的,因为 DirectX 和 OpenGL 有不同的要求,因此如果您没有正确绑定它们,它们将无法在着色器中正确通过。下面列出了您可以选择的可用使用常量,您使用的常量取决于所创建的着色器的具体情况:
顶点使用类型常量 | |
---|---|
常量 | 描述 |
vertex_usage_position | position values (x, y, z) |
vertex_usage_colour | colour values (r, g, b, a) |
vertex_usage_normal | vertex normal values (nx, ny, nz) |
vertex_usage_textcoord | UV coordinates (u, v) |
vertex_usage_blendweight | the blendweight of the input matrix (for skeletal animation, for example) |
vertex_usage_blendindices | the indices of the matrices to use (for skeletal animation, for example) |
vertex_usage_depth | vertex depth buffer value |
vertex_usage_tangent | tangent values |
vertex_usage_binormal | binormal values |
vertex_usage_fog | fog values |
vertex_usage_sample | sampler index |
在使用这些自定义格式时,需要注意一些重要事项:
attribute vec3 in_Position;
attribute vec4 in_BlendIndices;
attribute vec4 in_BlendWeights;
varying vec4 v_vColour;
varying mat4 v_mat;
void main()
{
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * vec4( in_Position.xyz, 1.0);
v_vColour = in_BlendWeights;
ivec4 t = ivec4(in_BlendIndices);
v_mat = gm_Matrices[ t.x ];
}
vertex_format_add_custom(type, usage);
参数 | 类型 | 描述 |
---|---|---|
type | 顶点数据类型常量 | 此自定义顶点数据将保留的数据类型(请参阅上面列出的类型常量)。 |
usage | 顶点使用类型常量 | 数据将获得的用途 (请参阅上面列出的 使用常量 )。 |
N/A
vertex_format_begin();
vertex_format_add_texcoord();
vertex_format_add_custom(vertex_type_float3, vertex_usage_position);
my_format = vertex_format_end();
上面的代码创建了一个新的顶点格式,仅包含纹理和 3 个自定义浮点值的位置。然后,它将格式存储在变量 my_format 中。