vertex_format_add_custom

此函数为特定顶点格式属性添加自定义数据类型,作为创建的新顶点格式的一部分。

要使用的可用值由您选择的数据类型常量定义,如下所示:

顶点数据类型常量
常量描述
vertex_type_float1A single floating point value
vertex_type_float2Two floating point values
vertex_type_float3Three floating point values
vertex_type_float4Four floating point values
vertex_type_colourFour component values (r, g, b, a)
vertex_type_ubyte4Four component unsigned byte values (from 0 to 255)


还需要定义这些常量的用途,以便可以在所创建的着色器中正确 " 绑定 " 这些值。这是必要的,因为 DirectX 和 OpenGL 有不同的要求,因此如果您没有正确绑定它们,它们将无法在着色器中正确通过。下面列出了您可以选择的可用使用常量,您使用的常量取决于所创建的着色器的具体情况:

顶点使用类型常量
常量描述
vertex_usage_positionposition values (x, y, z)
vertex_usage_colourcolour values (r, g, b, a)
vertex_usage_normalvertex normal values (nx, ny, nz)
vertex_usage_textcoordUV coordinates (u, v)
vertex_usage_blendweightthe blendweight of the input matrix (for skeletal animation, for example)
vertex_usage_blendindicesthe indices of the matrices to use (for skeletal animation, for example)
vertex_usage_depthvertex depth buffer value
vertex_usage_tangenttangent values
vertex_usage_binormalbinormal values
vertex_usage_fogfog values
vertex_usage_samplesampler 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 中。