/* This file is auto-generated; changes will not be preserved */

#include "config.h"

#include "gskgpuconicgradientopprivate.h"

#include "gskgpurenderpassprivate.h"
#include "gskgpushaderopprivate.h"
#include "gskrectprivate.h"
#include <graphene.h>


typedef struct _GskGpuConicGradientInstance GskGpuConicGradientInstance;

struct _GskGpuConicGradientInstance {
  float bounds[4];
  float center_angle[4];
  float color0[4];
  float color1[4];
  float color2[4];
  float color3[4];
  float color4[4];
  float color5[4];
  float color6[4];
  float offsets0[4];
  float offsets1[4];
  float hints0[4];
  float hints1[4];
};

static void
gsk_gpu_conic_gradient_op_print_instance (GskGpuShaderOp *shader,
                                          gpointer        instance_,
                                          GString        *string)
{

GskGpuConicGradientInstance *instance = instance_;

  gsk_gpu_print_rect (string, instance->bounds);

  /* FIXME: Implement */
}

static inline void
gsk_gpu_conic_gradient_setup_vao (gsize offset)
{
  glEnableVertexAttribArray (0);
  glVertexAttribDivisor (0, 1);
  glVertexAttribPointer (0,
                         4,
                         GL_FLOAT,
                         GL_FALSE,
                         208,
                         GSIZE_TO_POINTER (offset + 0));
  glEnableVertexAttribArray (1);
  glVertexAttribDivisor (1, 1);
  glVertexAttribPointer (1,
                         3,
                         GL_FLOAT,
                         GL_FALSE,
                         208,
                         GSIZE_TO_POINTER (offset + 16));
  glEnableVertexAttribArray (2);
  glVertexAttribDivisor (2, 1);
  glVertexAttribPointer (2,
                         4,
                         GL_FLOAT,
                         GL_FALSE,
                         208,
                         GSIZE_TO_POINTER (offset + 32));
  glEnableVertexAttribArray (3);
  glVertexAttribDivisor (3, 1);
  glVertexAttribPointer (3,
                         4,
                         GL_FLOAT,
                         GL_FALSE,
                         208,
                         GSIZE_TO_POINTER (offset + 48));
  glEnableVertexAttribArray (4);
  glVertexAttribDivisor (4, 1);
  glVertexAttribPointer (4,
                         4,
                         GL_FLOAT,
                         GL_FALSE,
                         208,
                         GSIZE_TO_POINTER (offset + 64));
  glEnableVertexAttribArray (5);
  glVertexAttribDivisor (5, 1);
  glVertexAttribPointer (5,
                         4,
                         GL_FLOAT,
                         GL_FALSE,
                         208,
                         GSIZE_TO_POINTER (offset + 80));
  glEnableVertexAttribArray (6);
  glVertexAttribDivisor (6, 1);
  glVertexAttribPointer (6,
                         4,
                         GL_FLOAT,
                         GL_FALSE,
                         208,
                         GSIZE_TO_POINTER (offset + 96));
  glEnableVertexAttribArray (7);
  glVertexAttribDivisor (7, 1);
  glVertexAttribPointer (7,
                         4,
                         GL_FLOAT,
                         GL_FALSE,
                         208,
                         GSIZE_TO_POINTER (offset + 112));
  glEnableVertexAttribArray (8);
  glVertexAttribDivisor (8, 1);
  glVertexAttribPointer (8,
                         4,
                         GL_FLOAT,
                         GL_FALSE,
                         208,
                         GSIZE_TO_POINTER (offset + 128));
  glEnableVertexAttribArray (9);
  glVertexAttribDivisor (9, 1);
  glVertexAttribPointer (9,
                         4,
                         GL_FLOAT,
                         GL_FALSE,
                         208,
                         GSIZE_TO_POINTER (offset + 144));
  glEnableVertexAttribArray (10);
  glVertexAttribDivisor (10, 1);
  glVertexAttribPointer (10,
                         4,
                         GL_FLOAT,
                         GL_FALSE,
                         208,
                         GSIZE_TO_POINTER (offset + 160));
  glEnableVertexAttribArray (11);
  glVertexAttribDivisor (11, 1);
  glVertexAttribPointer (11,
                         4,
                         GL_FLOAT,
                         GL_FALSE,
                         208,
                         GSIZE_TO_POINTER (offset + 176));
  glEnableVertexAttribArray (12);
  glVertexAttribDivisor (12, 1);
  glVertexAttribPointer (12,
                         4,
                         GL_FLOAT,
                         GL_FALSE,
                         208,
                         GSIZE_TO_POINTER (offset + 192));
}

static inline void
gsk_gpu_conic_gradient_setup_attrib_locations (GLuint program)
{
  glBindAttribLocation (program, 0, "in_bounds");
  glBindAttribLocation (program, 1, "in_center_angle");
  glBindAttribLocation (program, 2, "in_color0");
  glBindAttribLocation (program, 3, "in_color1");
  glBindAttribLocation (program, 4, "in_color2");
  glBindAttribLocation (program, 5, "in_color3");
  glBindAttribLocation (program, 6, "in_color4");
  glBindAttribLocation (program, 7, "in_color5");
  glBindAttribLocation (program, 8, "in_color6");
  glBindAttribLocation (program, 9, "in_offsets0");
  glBindAttribLocation (program, 10, "in_offsets1");
  glBindAttribLocation (program, 11, "in_hints0");
  glBindAttribLocation (program, 12, "in_hints1");
}

#ifdef GDK_RENDERING_VULKAN

static const VkPipelineVertexInputStateCreateInfo gsk_gpu_conic_gradient_info = {
  .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
  .vertexBindingDescriptionCount = 1,
  .pVertexBindingDescriptions = (VkVertexInputBindingDescription[1]) {
      {
        .binding = 0,
        .stride = 208,
        .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE
      }
  },
  .vertexAttributeDescriptionCount = 13,
  .pVertexAttributeDescriptions = (VkVertexInputAttributeDescription[13]) {
      {
        .location = 0,
        .binding = 0,
        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
        .offset = 0,
      },
      {
        .location = 1,
        .binding = 0,
        .format = VK_FORMAT_R32G32B32_SFLOAT,
        .offset = 16,
      },
      {
        .location = 2,
        .binding = 0,
        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
        .offset = 32,
      },
      {
        .location = 3,
        .binding = 0,
        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
        .offset = 48,
      },
      {
        .location = 4,
        .binding = 0,
        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
        .offset = 64,
      },
      {
        .location = 5,
        .binding = 0,
        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
        .offset = 80,
      },
      {
        .location = 6,
        .binding = 0,
        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
        .offset = 96,
      },
      {
        .location = 7,
        .binding = 0,
        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
        .offset = 112,
      },
      {
        .location = 8,
        .binding = 0,
        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
        .offset = 128,
      },
      {
        .location = 9,
        .binding = 0,
        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
        .offset = 144,
      },
      {
        .location = 10,
        .binding = 0,
        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
        .offset = 160,
      },
      {
        .location = 11,
        .binding = 0,
        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
        .offset = 176,
      },
      {
        .location = 12,
        .binding = 0,
        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
        .offset = 192,
      },
  },
};

#endif /* GDK_RENDERING_VULKAN */

static const GskGpuShaderOpClass GSK_GPU_CONIC_GRADIENT_OP_CLASS = {
  {
    GSK_GPU_OP_SIZE (GskGpuShaderOp),
    GSK_GPU_STAGE_SHADER,
    gsk_gpu_shader_op_finish,
    gsk_gpu_shader_op_print,
#ifdef GDK_RENDERING_VULKAN
    gsk_gpu_shader_op_vk_command,
#endif
    gsk_gpu_shader_op_gl_command
  },
  "gskgpuconicgradient",
  0,
  6,
  sizeof (GskGpuConicGradientInstance),
#ifdef GDK_RENDERING_VULKAN
  &gsk_gpu_conic_gradient_info,
#endif
  gsk_gpu_conic_gradient_op_print_instance,
  gsk_gpu_conic_gradient_setup_attrib_locations,
  gsk_gpu_conic_gradient_setup_vao
};

void
gsk_gpu_conic_gradient_op (GskGpuRenderPass       *pass,
                           GdkColorState          *ccs,
                           GdkColorState          *acs,
                           const graphene_rect_t  *bounds,
                           gboolean                variation_supersampling,
                           gboolean                variation_premultiplied,
                           const graphene_point_t *center,
                           float                   angle,
                           const GdkColor         *color0,
                           const GdkColor         *color1,
                           const GdkColor         *color2,
                           const GdkColor         *color3,
                           const GdkColor         *color4,
                           const GdkColor         *color5,
                           const GdkColor         *color6,
                           const graphene_vec4_t  *offsets0,
                           const graphene_vec4_t  *offsets1,
                           const graphene_vec4_t  *hints0,
                           const graphene_vec4_t  *hints1)
{
  GskGpuConicGradientInstance *instance;

  gsk_gpu_render_pass_prepare_shader (pass);

  gsk_gpu_shader_op_alloc (pass->frame,
                           &GSK_GPU_CONIC_GRADIENT_OP_CLASS,
                           ccs ? gsk_gpu_color_states_create (ccs, TRUE, acs, TRUE)
                               : gsk_gpu_color_states_create_equal (TRUE, TRUE),
                           ((variation_supersampling & 1) << 0) |
                           ((variation_premultiplied & 1) << 1),
                           gsk_gpu_clip_get_shader_clip (&pass->clip, &pass->offset, bounds),
                           pass->clip_mask,
                           NULL,
                           NULL,
                           &instance);
  gsk_gpu_rect_to_float (bounds, &pass->offset, instance->bounds);
  instance->center_angle[0] = center->x + pass->offset.x;
  instance->center_angle[0 + 1] = center->y + pass->offset.y;
  instance->center_angle[2] = angle;
  gdk_color_to_float (color0, acs, instance->color0);
  instance->color0[3] *= pass->opacity;
  gdk_color_to_float (color1, acs, instance->color1);
  instance->color1[3] *= pass->opacity;
  gdk_color_to_float (color2, acs, instance->color2);
  instance->color2[3] *= pass->opacity;
  gdk_color_to_float (color3, acs, instance->color3);
  instance->color3[3] *= pass->opacity;
  gdk_color_to_float (color4, acs, instance->color4);
  instance->color4[3] *= pass->opacity;
  gdk_color_to_float (color5, acs, instance->color5);
  instance->color5[3] *= pass->opacity;
  gdk_color_to_float (color6, acs, instance->color6);
  instance->color6[3] *= pass->opacity;
  graphene_vec4_to_float (offsets0, instance->offsets0);
  graphene_vec4_to_float (offsets1, instance->offsets1);
  graphene_vec4_to_float (hints0, instance->hints0);
  graphene_vec4_to_float (hints1, instance->hints1);
}

