#include "enums.glsl"

layout(set = 3, binding = 0, std140) uniform GskGlobals {
    mat4 mvp;
    vec2 scale;
    vec2 color_volume1;
    vec2 color_volume2;
    vec2 color_volume3;
    vec4 clip_mask_rect;
    mat3x4 clip;
} gsk_globals;

layout(constant_id=0) const uint GSK_FLAGS = 0;
layout(constant_id=1) const uint GSK_COLOR_STATES = 0;
layout(constant_id=2) const uint GSK_VARIATION = 0;

#define GSK_GLOBAL_MVP gsk_globals.mvp
#define GSK_GLOBAL_CLIP gsk_globals.clip
#define GSK_GLOBAL_CLIP_RECT gsk_globals.clip[0]
#define GSK_GLOBAL_SCALE gsk_globals.scale

#define GSK_VERTEX_INDEX gl_VertexIndex

#ifdef GSK_VERTEX_SHADER
#define IN(_loc) layout(location = _loc) in
#define PASS(_loc) layout(location = _loc) out
#define PASS_FLAT(_loc) layout(location = _loc) flat out
#endif


#ifdef GSK_FRAGMENT_SHADER
#define PASS(_loc) layout(location = _loc) in
#define PASS_FLAT(_loc) layout(location = _loc) flat in

layout(set = 0, binding = 0) uniform sampler2D GSK_TEXTURE0_ARRAY[3];
#define GSK_TEXTURE0 GSK_TEXTURE0_ARRAY[0]
#define GSK_TEXTURE0_1 GSK_TEXTURE0_ARRAY[1]
#define GSK_TEXTURE0_2 GSK_TEXTURE0_ARRAY[2]
layout(set = 1, binding = 0) uniform sampler2D GSK_TEXTURE1_ARRAY[3];
#define GSK_TEXTURE1 GSK_TEXTURE1_ARRAY[0]
#define GSK_TEXTURE1_1 GSK_TEXTURE1_ARRAY[1]
#define GSK_TEXTURE1_2 GSK_TEXTURE1_ARRAY[2]
layout(location = 0) out vec4 out_color;
#ifdef GSK_DUAL_BLEND
layout(location = 0, index = 1) out vec4 out_mask;
#endif

#ifdef GSK_VULKAN_HAS_CLIP_MASK
layout(set = 2, binding = 0) uniform sampler2D GSK_TEXTURE_MASK;
#endif

#include "rect.glsl"

float
gsk_clip_mask_coverage (void)
{
#ifdef GSK_VULKAN_HAS_CLIP_MASK
  vec2 coord = rect_get_coord (rect_new_size (gsk_globals.clip_mask_rect), gl_FragCoord.xy);
  return texture (GSK_TEXTURE_MASK, coord).a;
#else
  return 1.0;
#endif
}

void
gsk_set_output_color (vec4 color)
{
  out_color = color;
}

#ifdef GSK_DUAL_BLEND
void
gsk_set_output_mask (vec4 mask)
{
  out_mask = mask;
}
#endif

#endif
