2023-06-24 22:56:13 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gskvulkantextureopprivate.h"
|
|
|
|
|
2023-07-03 13:57:30 +00:00
|
|
|
#include "gskvulkanprivate.h"
|
|
|
|
|
2023-06-29 04:36:17 +00:00
|
|
|
#include "vulkan/resources/texture.vert.h"
|
2023-06-24 22:56:13 +00:00
|
|
|
|
|
|
|
typedef struct _GskVulkanTextureOp GskVulkanTextureOp;
|
|
|
|
|
|
|
|
struct _GskVulkanTextureOp
|
|
|
|
{
|
|
|
|
GskVulkanOp op;
|
|
|
|
|
|
|
|
GskVulkanImage *image;
|
|
|
|
GskVulkanRenderSampler sampler;
|
|
|
|
graphene_rect_t rect;
|
|
|
|
graphene_rect_t tex_rect;
|
|
|
|
|
|
|
|
guint32 image_descriptor;
|
|
|
|
gsize vertex_offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_texture_op_finish (GskVulkanOp *op)
|
|
|
|
{
|
|
|
|
GskVulkanTextureOp *self = (GskVulkanTextureOp *) op;
|
|
|
|
|
|
|
|
g_object_unref (self->image);
|
|
|
|
}
|
|
|
|
|
2023-07-05 04:32:52 +00:00
|
|
|
static void
|
|
|
|
gsk_vulkan_texture_op_print (GskVulkanOp *op,
|
|
|
|
GString *string,
|
|
|
|
guint indent)
|
|
|
|
{
|
|
|
|
GskVulkanTextureOp *self = (GskVulkanTextureOp *) op;
|
|
|
|
|
|
|
|
print_indent (string, indent);
|
|
|
|
print_rect (string, &self->rect);
|
|
|
|
g_string_append (string, "texture ");
|
|
|
|
print_image (string, self->image);
|
|
|
|
print_newline (string);
|
|
|
|
}
|
|
|
|
|
2023-06-24 22:56:13 +00:00
|
|
|
static void
|
|
|
|
gsk_vulkan_texture_op_upload (GskVulkanOp *op,
|
|
|
|
GskVulkanRenderPass *pass,
|
|
|
|
GskVulkanRender *render,
|
2023-07-03 01:23:17 +00:00
|
|
|
GskVulkanUploader *uploader)
|
2023-06-24 22:56:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline gsize
|
|
|
|
round_up (gsize number, gsize divisor)
|
|
|
|
{
|
|
|
|
return (number + divisor - 1) / divisor * divisor;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gsize
|
|
|
|
gsk_vulkan_texture_op_count_vertex_data (GskVulkanOp *op,
|
|
|
|
gsize n_bytes)
|
|
|
|
{
|
|
|
|
GskVulkanTextureOp *self = (GskVulkanTextureOp *) op;
|
|
|
|
gsize vertex_stride;
|
|
|
|
|
2023-06-29 04:36:17 +00:00
|
|
|
vertex_stride = gsk_vulkan_texture_info.pVertexBindingDescriptions[0].stride;
|
2023-06-24 22:56:13 +00:00
|
|
|
n_bytes = round_up (n_bytes, vertex_stride);
|
|
|
|
self->vertex_offset = n_bytes;
|
|
|
|
n_bytes += vertex_stride;
|
|
|
|
return n_bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_texture_op_collect_vertex_data (GskVulkanOp *op,
|
|
|
|
GskVulkanRenderPass *pass,
|
|
|
|
GskVulkanRender *render,
|
|
|
|
guchar *data)
|
|
|
|
{
|
|
|
|
GskVulkanTextureOp *self = (GskVulkanTextureOp *) op;
|
2023-06-29 04:36:17 +00:00
|
|
|
GskVulkanTextureInstance *instance = (GskVulkanTextureInstance *) (data + self->vertex_offset);
|
|
|
|
|
|
|
|
instance->rect[0] = self->rect.origin.x;
|
|
|
|
instance->rect[1] = self->rect.origin.y;
|
|
|
|
instance->rect[2] = self->rect.size.width;
|
|
|
|
instance->rect[3] = self->rect.size.height;
|
|
|
|
instance->tex_rect[0] = self->tex_rect.origin.x;
|
|
|
|
instance->tex_rect[1] = self->tex_rect.origin.y;
|
|
|
|
instance->tex_rect[2] = self->tex_rect.size.width;
|
|
|
|
instance->tex_rect[3] = self->tex_rect.size.height;
|
|
|
|
instance->tex_id = self->image_descriptor;
|
2023-06-24 22:56:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_texture_op_reserve_descriptor_sets (GskVulkanOp *op,
|
|
|
|
GskVulkanRender *render)
|
|
|
|
{
|
|
|
|
GskVulkanTextureOp *self = (GskVulkanTextureOp *) op;
|
|
|
|
|
2023-06-28 18:50:43 +00:00
|
|
|
self->image_descriptor = gsk_vulkan_render_get_image_descriptor (render, self->image, self->sampler);
|
2023-06-24 22:56:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_texture_op_command (GskVulkanOp *op,
|
2023-06-25 20:16:37 +00:00
|
|
|
GskVulkanRender *render,
|
2023-06-24 22:56:13 +00:00
|
|
|
VkPipelineLayout pipeline_layout,
|
|
|
|
VkCommandBuffer command_buffer)
|
|
|
|
{
|
|
|
|
GskVulkanTextureOp *self = (GskVulkanTextureOp *) op;
|
|
|
|
|
2023-06-29 04:36:17 +00:00
|
|
|
vkCmdDraw (command_buffer,
|
|
|
|
6, 1,
|
|
|
|
0, self->vertex_offset / gsk_vulkan_texture_info.pVertexBindingDescriptions[0].stride);
|
2023-06-24 22:56:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const GskVulkanOpClass GSK_VULKAN_TEXTURE_OP_CLASS = {
|
|
|
|
GSK_VULKAN_OP_SIZE (GskVulkanTextureOp),
|
2023-06-29 04:36:17 +00:00
|
|
|
"texture",
|
|
|
|
&gsk_vulkan_texture_info,
|
2023-06-24 22:56:13 +00:00
|
|
|
gsk_vulkan_texture_op_finish,
|
2023-07-05 04:32:52 +00:00
|
|
|
gsk_vulkan_texture_op_print,
|
2023-06-24 22:56:13 +00:00
|
|
|
gsk_vulkan_texture_op_upload,
|
|
|
|
gsk_vulkan_texture_op_count_vertex_data,
|
|
|
|
gsk_vulkan_texture_op_collect_vertex_data,
|
|
|
|
gsk_vulkan_texture_op_reserve_descriptor_sets,
|
|
|
|
gsk_vulkan_texture_op_command
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2023-06-28 02:30:35 +00:00
|
|
|
gsk_vulkan_texture_op (GskVulkanRenderPass *render_pass,
|
2023-06-29 04:36:17 +00:00
|
|
|
const char *clip_type,
|
2023-06-28 02:30:35 +00:00
|
|
|
GskVulkanImage *image,
|
|
|
|
GskVulkanRenderSampler sampler,
|
|
|
|
const graphene_rect_t *rect,
|
|
|
|
const graphene_point_t *offset,
|
|
|
|
const graphene_rect_t *tex_rect)
|
2023-06-24 22:56:13 +00:00
|
|
|
{
|
2023-06-28 02:30:35 +00:00
|
|
|
GskVulkanTextureOp *self;
|
2023-06-24 22:56:13 +00:00
|
|
|
|
2023-06-28 02:30:35 +00:00
|
|
|
self = (GskVulkanTextureOp *) gsk_vulkan_op_alloc (render_pass, &GSK_VULKAN_TEXTURE_OP_CLASS);
|
2023-06-24 22:56:13 +00:00
|
|
|
|
2023-06-29 04:36:17 +00:00
|
|
|
((GskVulkanOp *) self)->clip_type = g_intern_string (clip_type);
|
2023-06-24 22:56:13 +00:00
|
|
|
self->image = g_object_ref (image);
|
|
|
|
self->sampler = sampler;
|
|
|
|
graphene_rect_offset_r (rect, offset->x, offset->y, &self->rect);
|
2023-06-25 23:39:32 +00:00
|
|
|
gsk_vulkan_normalize_tex_coords (&self->tex_rect, rect, tex_rect);
|
2023-06-24 22:56:13 +00:00
|
|
|
}
|