58 lines
1.9 KiB
C++
58 lines
1.9 KiB
C++
//
|
|
// Created by Vicente Ferrari Smith on 27.02.26.
|
|
//
|
|
|
|
#pragma once
|
|
#include <simd/simd.h>
|
|
|
|
using namespace simd;
|
|
|
|
struct vertex_p2_s2_uv2_c4_a1 {
|
|
float2 pos;
|
|
float2 scale;
|
|
float2 uv;
|
|
float4 color;
|
|
float alpha;
|
|
|
|
static MTL::VertexDescriptor* vertexDescriptor() {
|
|
MTL::VertexDescriptor* vd = MTL::VertexDescriptor::alloc()->init();
|
|
|
|
// ATTRIBUTE 0 — float2 pos
|
|
vd->attributes()->object(0)->setFormat(MTL::VertexFormatFloat2);
|
|
vd->attributes()->object(0)->setOffset(offsetof(vertex_p2_s2_uv2_c4_a1, pos));
|
|
vd->attributes()->object(0)->setBufferIndex(0);
|
|
|
|
// ATTRIBUTE 1 — float2 scale
|
|
vd->attributes()->object(1)->setFormat(MTL::VertexFormatFloat2);
|
|
vd->attributes()->object(1)->setOffset(offsetof(vertex_p2_s2_uv2_c4_a1, scale));
|
|
vd->attributes()->object(1)->setBufferIndex(0);
|
|
|
|
// ATTRIBUTE 2 — float2 uv
|
|
vd->attributes()->object(2)->setFormat(MTL::VertexFormatFloat2);
|
|
vd->attributes()->object(2)->setOffset(offsetof(vertex_p2_s2_uv2_c4_a1, uv));
|
|
vd->attributes()->object(2)->setBufferIndex(0);
|
|
|
|
// ATTRIBUTE 3 — float4 color
|
|
vd->attributes()->object(3)->setFormat(MTL::VertexFormatFloat4);
|
|
vd->attributes()->object(3)->setOffset(offsetof(vertex_p2_s2_uv2_c4_a1, color));
|
|
vd->attributes()->object(3)->setBufferIndex(0);
|
|
|
|
// ATTRIBUTE 4 — float alpha
|
|
vd->attributes()->object(4)->setFormat(MTL::VertexFormatFloat);
|
|
vd->attributes()->object(4)->setOffset(offsetof(vertex_p2_s2_uv2_c4_a1, alpha));
|
|
vd->attributes()->object(4)->setBufferIndex(0);
|
|
|
|
// Layout for buffer 0
|
|
vd->layouts()->object(0)->setStride(sizeof(vertex_p2_s2_uv2_c4_a1));
|
|
vd->layouts()->object(0)->setStepFunction(MTL::VertexStepFunctionPerVertex);
|
|
|
|
return vd;
|
|
}
|
|
};
|
|
|
|
struct TransformationData {
|
|
float4x4 model_matrix;
|
|
float4x4 view_matrix;
|
|
float4x4 perspective_matrix;
|
|
};
|