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

#include "config.h"

#include "gskgpuarithmeticopprivate.h"

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


typedef struct _GskGpuArithmeticInstance GskGpuArithmeticInstance;

struct _GskGpuArithmeticInstance {
  float rect[4];
  float first_rect[4];
  float second_rect[4];
  float k1_k2_k3_k4[4];
  float opacity[4];
};

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

  /* FIXME: Implement */
}

static inline void
gsk_gpu_arithmetic_setup_vao (gsize offset)
{
  glEnableVertexAttribArray (0);
  glVertexAttribDivisor (0, 1);
  glVertexAttribPointer (0,
                         4,
                         GL_FLOAT,
                         GL_FALSE,
                         80,
                         GSIZE_TO_POINTER (offset + 0));
  glEnableVertexAttribArray (1);
  glVertexAttribDivisor (1, 1);
  glVertexAttribPointer (1,
                         4,
                         GL_FLOAT,
                         GL_FALSE,
                         80,
                         GSIZE_TO_POINTER (offset + 16));
  glEnableVertexAttribArray (2);
  glVertexAttribDivisor (2, 1);
  glVertexAttribPointer (2,
                         4,
                         GL_FLOAT,
                         GL_FALSE,
                         80,
                         GSIZE_TO_POINTER (offset + 32));
  glEnableVertexAttribArray (3);
  glVertexAttribDivisor (3, 1);
  glVertexAttribPointer (3,
                         4,
                         GL_FLOAT,
                         GL_FALSE,
                         80,
                         GSIZE_TO_POINTER (offset + 48));
  glEnableVertexAttribArray (4);
  glVertexAttribDivisor (4, 1);
  glVertexAttribPointer (4,
                         1,
                         GL_FLOAT,
                         GL_FALSE,
                         80,
                         GSIZE_TO_POINTER (offset + 64));
}

static inline void
gsk_gpu_arithmetic_setup_attrib_locations (GLuint program)
{
  glBindAttribLocation (program, 0, "in_rect");
  glBindAttribLocation (program, 1, "in_first_rect");
  glBindAttribLocation (program, 2, "in_second_rect");
  glBindAttribLocation (program, 3, "in_k1_k2_k3_k4");
  glBindAttribLocation (program, 4, "in_opacity");
}

#ifdef GDK_RENDERING_VULKAN

static const VkPipelineVertexInputStateCreateInfo gsk_gpu_arithmetic_info = {
  .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
  .vertexBindingDescriptionCount = 1,
  .pVertexBindingDescriptions = (VkVertexInputBindingDescription[1]) {
      {
        .binding = 0,
        .stride = 80,
        .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE
      }
  },
  .vertexAttributeDescriptionCount = 5,
  .pVertexAttributeDescriptions = (VkVertexInputAttributeDescription[5]) {
      {
        .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_R32_SFLOAT,
        .offset = 64,
      },
  },
};

#endif /* GDK_RENDERING_VULKAN */

static const GskGpuShaderOpClass GSK_GPU_ARITHMETIC_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
  },
  "gskgpuarithmetic",
  2,
  6,
  sizeof (GskGpuArithmeticInstance),
#ifdef GDK_RENDERING_VULKAN
  &gsk_gpu_arithmetic_info,
#endif
  gsk_gpu_arithmetic_op_print_instance,
  gsk_gpu_arithmetic_setup_attrib_locations,
  gsk_gpu_arithmetic_setup_vao
};

void
gsk_gpu_arithmetic_op (GskGpuFrame            *frame,
                       GskGpuShaderClip        clip,
                       GdkColorState          *ccs,
                       GdkColorState          *acs,
                       float                   opacity,
                       const graphene_point_t *offset,
                       GskGpuImage            *image1,
                       GskGpuSampler           sampler1,
                       GskGpuImage            *image2,
                       GskGpuSampler           sampler2,
                       const graphene_rect_t  *rect,
                       const graphene_rect_t  *first_rect,
                       const graphene_rect_t  *second_rect,
                       float                   k1,
                       float                   k2,
                       float                   k3,
                       float                   k4)
{
  GskGpuArithmeticInstance *instance;

  gsk_gpu_shader_op_alloc (frame,
                           &GSK_GPU_ARITHMETIC_OP_CLASS,
                           ccs ? gsk_gpu_color_states_create (ccs, TRUE, acs, TRUE)
                               : gsk_gpu_color_states_create_equal (TRUE, TRUE),
                           0,
                           clip,
                           (GskGpuImage *[2]) { image1, image2 },
                           (GskGpuSampler[2]) { sampler1, sampler2 },
                           &instance);
  gsk_gpu_rect_to_float (rect, offset, instance->rect);
  gsk_gpu_rect_to_float (first_rect, offset, instance->first_rect);
  gsk_gpu_rect_to_float (second_rect, offset, instance->second_rect);
  instance->k1_k2_k3_k4[0] = k1;
  instance->k1_k2_k3_k4[1] = k2;
  instance->k1_k2_k3_k4[2] = k3;
  instance->k1_k2_k3_k4[3] = k4;
  instance->opacity[0] = opacity;
}

