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

#include "config.h"

#include "gskgpucomponenttransferopprivate.h"

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


typedef struct _GskGpuComponentTransferInstance GskGpuComponentTransferInstance;

struct _GskGpuComponentTransferInstance {
  float params_r[4];
  float params_g[4];
  float params_b[4];
  float params_a[4];
  float table0[4];
  float table1[4];
  float table2[4];
  float table3[4];
  float table4[4];
  float table5[4];
  float table6[4];
  float table7[4];
  float rect[4];
  float tex_rect[4];
  float opacity[4];
};

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

  /* FIXME: Implement */
}

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

static inline void
gsk_gpu_component_transfer_setup_attrib_locations (GLuint program)
{
  glBindAttribLocation (program, 0, "in_params_r");
  glBindAttribLocation (program, 1, "in_params_g");
  glBindAttribLocation (program, 2, "in_params_b");
  glBindAttribLocation (program, 3, "in_params_a");
  glBindAttribLocation (program, 4, "in_table0");
  glBindAttribLocation (program, 5, "in_table1");
  glBindAttribLocation (program, 6, "in_table2");
  glBindAttribLocation (program, 7, "in_table3");
  glBindAttribLocation (program, 8, "in_table4");
  glBindAttribLocation (program, 9, "in_table5");
  glBindAttribLocation (program, 10, "in_table6");
  glBindAttribLocation (program, 11, "in_table7");
  glBindAttribLocation (program, 12, "in_rect");
  glBindAttribLocation (program, 13, "in_tex_rect");
  glBindAttribLocation (program, 14, "in_opacity");
}

#ifdef GDK_RENDERING_VULKAN

static const VkPipelineVertexInputStateCreateInfo gsk_gpu_component_transfer_info = {
  .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
  .vertexBindingDescriptionCount = 1,
  .pVertexBindingDescriptions = (VkVertexInputBindingDescription[1]) {
      {
        .binding = 0,
        .stride = 240,
        .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE
      }
  },
  .vertexAttributeDescriptionCount = 15,
  .pVertexAttributeDescriptions = (VkVertexInputAttributeDescription[15]) {
      {
        .location = 0,
        .binding = 0,
        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
        .offset = 0,
      },
      {
        .location = 1,
        .binding = 0,
        .format = VK_FORMAT_R32G32B32A32_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,
      },
      {
        .location = 13,
        .binding = 0,
        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
        .offset = 208,
      },
      {
        .location = 14,
        .binding = 0,
        .format = VK_FORMAT_R32_SFLOAT,
        .offset = 224,
      },
  },
};

#endif /* GDK_RENDERING_VULKAN */

static const GskGpuShaderOpClass GSK_GPU_COMPONENT_TRANSFER_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
  },
  "gskgpucomponenttransfer",
  1,
  6,
  sizeof (GskGpuComponentTransferInstance),
#ifdef GDK_RENDERING_VULKAN
  &gsk_gpu_component_transfer_info,
#endif
  gsk_gpu_component_transfer_op_print_instance,
  gsk_gpu_component_transfer_setup_attrib_locations,
  gsk_gpu_component_transfer_setup_vao
};

void
gsk_gpu_component_transfer_op (GskGpuRenderPass      *pass,
                               GdkColorState         *ccs,
                               GdkColorState         *acs,
                               const graphene_rect_t *bounds,
                               GskGpuImage           *image1,
                               GskGpuSampler          sampler1,
                               const graphene_vec4_t *params_r,
                               const graphene_vec4_t *params_g,
                               const graphene_vec4_t *params_b,
                               const graphene_vec4_t *params_a,
                               const graphene_vec4_t *table0,
                               const graphene_vec4_t *table1,
                               const graphene_vec4_t *table2,
                               const graphene_vec4_t *table3,
                               const graphene_vec4_t *table4,
                               const graphene_vec4_t *table5,
                               const graphene_vec4_t *table6,
                               const graphene_vec4_t *table7,
                               const graphene_rect_t *rect,
                               const graphene_rect_t *tex_rect)
{
  GskGpuComponentTransferInstance *instance;

  gsk_gpu_render_pass_prepare_shader (pass);

  gsk_gpu_shader_op_alloc (pass->frame,
                           &GSK_GPU_COMPONENT_TRANSFER_OP_CLASS,
                           ccs ? gsk_gpu_color_states_create (ccs, TRUE, acs, FALSE)
                               : gsk_gpu_color_states_create_equal (TRUE, FALSE),
                           0,
                           gsk_gpu_clip_get_shader_clip (&pass->clip, &pass->offset, bounds),
                           pass->clip_mask,
                           (GskGpuImage *[1]) { image1 },
                           (GskGpuSampler[1]) { sampler1 },
                           &instance);
  graphene_vec4_to_float (params_r, instance->params_r);
  graphene_vec4_to_float (params_g, instance->params_g);
  graphene_vec4_to_float (params_b, instance->params_b);
  graphene_vec4_to_float (params_a, instance->params_a);
  graphene_vec4_to_float (table0, instance->table0);
  graphene_vec4_to_float (table1, instance->table1);
  graphene_vec4_to_float (table2, instance->table2);
  graphene_vec4_to_float (table3, instance->table3);
  graphene_vec4_to_float (table4, instance->table4);
  graphene_vec4_to_float (table5, instance->table5);
  graphene_vec4_to_float (table6, instance->table6);
  graphene_vec4_to_float (table7, instance->table7);
  gsk_gpu_rect_to_float (rect, &pass->offset, instance->rect);
  gsk_gpu_rect_to_float (tex_rect, &pass->offset, instance->tex_rect);
  instance->opacity[0] = pass->opacity;
}

