[gtk+] vulkan: Get vertex description from pipeline subclass



commit 5dfb74c70cafc2e7fad980646a97dc13a27220aa
Author: Benjamin Otte <otte redhat com>
Date:   Sun Dec 18 05:33:16 2016 +0100

    vulkan: Get vertex description from pipeline subclass

 gsk/gskvulkanblendpipeline.c   |   39 +++++++++++++++++++++++++++++++++++++++
 gsk/gskvulkancolorpipeline.c   |   39 +++++++++++++++++++++++++++++++++++++++
 gsk/gskvulkanpipeline.c        |   27 +--------------------------
 gsk/gskvulkanpipelineprivate.h |    3 +++
 4 files changed, 82 insertions(+), 26 deletions(-)
---
diff --git a/gsk/gskvulkanblendpipeline.c b/gsk/gskvulkanblendpipeline.c
index eaaed67..59dd971 100644
--- a/gsk/gskvulkanblendpipeline.c
+++ b/gsk/gskvulkanblendpipeline.c
@@ -19,6 +19,41 @@ struct _GskVulkanVertex
 
 G_DEFINE_TYPE (GskVulkanBlendPipeline, gsk_vulkan_blend_pipeline, GSK_TYPE_VULKAN_PIPELINE)
 
+static const VkPipelineVertexInputStateCreateInfo *
+gsk_vulkan_blend_pipeline_get_input_state_create_info (GskVulkanPipeline *self)
+{
+  static const VkVertexInputBindingDescription vertexBindingDescriptions[] = {
+      {
+          .binding = 0,
+          .stride = 4 * sizeof (float),
+          .inputRate = VK_VERTEX_INPUT_RATE_VERTEX
+      }
+  };
+  static const VkVertexInputAttributeDescription vertexInputAttributeDescription[] = {
+      {
+          .location = 0,
+          .binding = 0,
+          .format = VK_FORMAT_R32G32_SFLOAT,
+          .offset = 0,
+      },
+      {
+          .location = 1,
+          .binding = 0,
+          .format = VK_FORMAT_R32G32_SFLOAT,
+          .offset = 2 * sizeof (float),
+      }
+  };
+  static const VkPipelineVertexInputStateCreateInfo info = {
+      .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
+      .vertexBindingDescriptionCount = G_N_ELEMENTS (vertexBindingDescriptions),
+      .pVertexBindingDescriptions = vertexBindingDescriptions,
+      .vertexAttributeDescriptionCount = G_N_ELEMENTS (vertexInputAttributeDescription),
+      .pVertexAttributeDescriptions = vertexInputAttributeDescription
+  };
+
+  return &info;
+}
+
 static void
 gsk_vulkan_blend_pipeline_finalize (GObject *gobject)
 {
@@ -30,7 +65,11 @@ gsk_vulkan_blend_pipeline_finalize (GObject *gobject)
 static void
 gsk_vulkan_blend_pipeline_class_init (GskVulkanBlendPipelineClass *klass)
 {
+  GskVulkanPipelineClass *pipeline_class = GSK_VULKAN_PIPELINE_CLASS (klass);
+
   G_OBJECT_CLASS (klass)->finalize = gsk_vulkan_blend_pipeline_finalize;
+
+  pipeline_class->get_input_state_create_info = gsk_vulkan_blend_pipeline_get_input_state_create_info;
 }
 
 static void
diff --git a/gsk/gskvulkancolorpipeline.c b/gsk/gskvulkancolorpipeline.c
index 42a2c39..b7dc8f4 100644
--- a/gsk/gskvulkancolorpipeline.c
+++ b/gsk/gskvulkancolorpipeline.c
@@ -19,6 +19,41 @@ struct _GskVulkanVertex
 
 G_DEFINE_TYPE (GskVulkanColorPipeline, gsk_vulkan_color_pipeline, GSK_TYPE_VULKAN_PIPELINE)
 
+static const VkPipelineVertexInputStateCreateInfo *
+gsk_vulkan_color_pipeline_get_input_state_create_info (GskVulkanPipeline *self)
+{
+  static const VkVertexInputBindingDescription vertexBindingDescriptions[] = {
+      {
+          .binding = 0,
+          .stride = 4 * sizeof (float),
+          .inputRate = VK_VERTEX_INPUT_RATE_VERTEX
+      }
+  };
+  static const VkVertexInputAttributeDescription vertexInputAttributeDescription[] = {
+      {
+          .location = 0,
+          .binding = 0,
+          .format = VK_FORMAT_R32G32_SFLOAT,
+          .offset = 0,
+      },
+      {
+          .location = 1,
+          .binding = 0,
+          .format = VK_FORMAT_R32G32_SFLOAT,
+          .offset = 2 * sizeof (float),
+      }
+  };
+  static const VkPipelineVertexInputStateCreateInfo info = {
+      .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
+      .vertexBindingDescriptionCount = G_N_ELEMENTS (vertexBindingDescriptions),
+      .pVertexBindingDescriptions = vertexBindingDescriptions,
+      .vertexAttributeDescriptionCount = G_N_ELEMENTS (vertexInputAttributeDescription),
+      .pVertexAttributeDescriptions = vertexInputAttributeDescription
+  };
+
+  return &info;
+}
+
 static void
 gsk_vulkan_color_pipeline_finalize (GObject *gobject)
 {
@@ -30,7 +65,11 @@ gsk_vulkan_color_pipeline_finalize (GObject *gobject)
 static void
 gsk_vulkan_color_pipeline_class_init (GskVulkanColorPipelineClass *klass)
 {
+  GskVulkanPipelineClass *pipeline_class = GSK_VULKAN_PIPELINE_CLASS (klass);
+
   G_OBJECT_CLASS (klass)->finalize = gsk_vulkan_color_pipeline_finalize;
+
+  pipeline_class->get_input_state_create_info = gsk_vulkan_color_pipeline_get_input_state_create_info;
 }
 
 static void
diff --git a/gsk/gskvulkanpipeline.c b/gsk/gskvulkanpipeline.c
index 1138078..7fff1d2 100644
--- a/gsk/gskvulkanpipeline.c
+++ b/gsk/gskvulkanpipeline.c
@@ -99,32 +99,7 @@ gsk_vulkan_pipeline_new (GType                    pipeline_type,
                                                    GST_VULKAN_SHADER_STAGE_CREATE_INFO (priv->vertex_shader),
                                                    GST_VULKAN_SHADER_STAGE_CREATE_INFO 
(priv->fragment_shader)
                                                },
-                                               .pVertexInputState = &(VkPipelineVertexInputStateCreateInfo) {
-                                                   .sType = 
VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
-                                                   .vertexBindingDescriptionCount = 1,
-                                                   .pVertexBindingDescriptions = 
(VkVertexInputBindingDescription[]) {
-                                                       {
-                                                           .binding = 0,
-                                                           .stride = 4 * sizeof (float),
-                                                           .inputRate = VK_VERTEX_INPUT_RATE_VERTEX
-                                                       }
-                                                   },
-                                                   .vertexAttributeDescriptionCount = 2,
-                                                   .pVertexAttributeDescriptions = 
(VkVertexInputAttributeDescription[]) {
-                                                       {
-                                                           .location = 0,
-                                                           .binding = 0,
-                                                           .format = VK_FORMAT_R32G32_SFLOAT,
-                                                           .offset = 0,
-                                                       },
-                                                       {
-                                                           .location = 1,
-                                                           .binding = 0,
-                                                           .format = VK_FORMAT_R32G32_SFLOAT,
-                                                           .offset = 2 * sizeof (float),
-                                                       }
-                                                   }
-                                               },
+                                               .pVertexInputState = GSK_VULKAN_PIPELINE_GET_CLASS 
(self)->get_input_state_create_info (self),
                                                .pInputAssemblyState = 
&(VkPipelineInputAssemblyStateCreateInfo) {
                                                    .sType = 
VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
                                                    .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
diff --git a/gsk/gskvulkanpipelineprivate.h b/gsk/gskvulkanpipelineprivate.h
index 1f1ad1a..91ffee8 100644
--- a/gsk/gskvulkanpipelineprivate.h
+++ b/gsk/gskvulkanpipelineprivate.h
@@ -16,6 +16,9 @@ G_DECLARE_DERIVABLE_TYPE (GskVulkanPipeline, gsk_vulkan_pipeline, GSK, VULKAN_PI
 struct _GskVulkanPipelineClass
 {
   GObjectClass parent_class;
+
+  const VkPipelineVertexInputStateCreateInfo *
+                                (* get_input_state_create_info)         (GskVulkanPipeline              
*self);
 };
 
 static inline VkResult


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]