1
\$\begingroup\$

I am not sure how metal distinguishes uniforms from vertices buffers? As far as I know code for passing uniforms in buffers are the same like for vertices:

[self.commandEncoder setVertexBuffer:positionBuffer offset:0 atIndex:0];
[self.commandEncoder setVertexBuffer:uniformBuffer offset:0 atIndex:1];

In shader code there is no keyword defining some struct as uniforms, so how Metal know it? In Opengl GLSL was uniform keyword which was clear for me but I can't figure how it is solved in metal.

\$\endgroup\$
2
\$\begingroup\$

They are defined in vertex shader signature, eg.

vertex ColorInOut unlit_vertex(device vertex_t* vertex_array [[ buffer(0) ]],
                            constant uniforms_t& uniforms [[ buffer(1) ]],
                            unsigned int vid [[ vertex_id ]])

Earlier I define them like this:

typedef struct
{
    matrix_float4x4 _ModelViewProjectionMatrix;
    float4 tintColor;
    matrix_float4x4 _ShadowProjectionMatrix;
} uniforms_t;

typedef struct
{
    packed_float3 position;
    packed_float2 texcoord;
    packed_float3 normal;
    packed_float4 tangent;
    packed_float4 color;
} vertex_t;
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Thank you for answer I missed that keyword uniform in shader signature. \$\endgroup\$ – user74836 Nov 17 '15 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy