#include <metal_stdlib>
using namespace metal;

template<typename T, size_t N>
struct tint_array {
  const constant T& operator[](size_t i) const constant { return elements[i]; }
  device T& operator[](size_t i) device { return elements[i]; }
  const device T& operator[](size_t i) const device { return elements[i]; }
  thread T& operator[](size_t i) thread { return elements[i]; }
  const thread T& operator[](size_t i) const thread { return elements[i]; }
  threadgroup T& operator[](size_t i) threadgroup { return elements[i]; }
  const threadgroup T& operator[](size_t i) const threadgroup { return elements[i]; }
  T elements[N];
};

struct vtx_main_outputs {
  float4 tint_symbol [[position]];
};

struct frag_main_outputs {
  float4 tint_symbol_1 [[color(0)]];
};

float4 vtx_main_inner(uint VertexIndex) {
  return float4(tint_array<float2, 3>{float2(0.0f, 0.5f), float2(-0.5f), float2(0.5f, -0.5f)}[VertexIndex], 0.0f, 1.0f);
}

float4 frag_main_inner() {
  return float4(1.0f, 0.0f, 0.0f, 1.0f);
}

vertex vtx_main_outputs vtx_main(uint VertexIndex [[vertex_id]]) {
  return vtx_main_outputs{.tint_symbol=vtx_main_inner(VertexIndex)};
}

fragment frag_main_outputs frag_main() {
  return frag_main_outputs{.tint_symbol_1=frag_main_inner()};
}
