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;
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
2023-07-08 19:28:56 +00:00
|
|
|
gsk_vulkan_texture_op_collect_vertex_data (GskVulkanOp *op,
|
|
|
|
guchar *data)
|
2023-06-24 22:56:13 +00:00
|
|
|
{
|
|
|
|
GskVulkanTextureOp *self = (GskVulkanTextureOp *) op;
|
2023-07-09 14:27:02 +00:00
|
|
|
GskVulkanTextureInstance *instance = (GskVulkanTextureInstance *) (data + op->vertex_offset);
|
2023-06-29 04:36:17 +00:00
|
|
|
|
|
|
|
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 const GskVulkanOpClass GSK_VULKAN_TEXTURE_OP_CLASS = {
|
|
|
|
GSK_VULKAN_OP_SIZE (GskVulkanTextureOp),
|
2023-07-09 13:40:48 +00:00
|
|
|
GSK_VULKAN_STAGE_COMMAND,
|
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-07-09 14:27:02 +00:00
|
|
|
gsk_vulkan_op_draw_upload,
|
|
|
|
gsk_vulkan_op_draw_count_vertex_data,
|
2023-06-24 22:56:13 +00:00
|
|
|
gsk_vulkan_texture_op_collect_vertex_data,
|
|
|
|
gsk_vulkan_texture_op_reserve_descriptor_sets,
|
2023-07-09 14:27:02 +00:00
|
|
|
gsk_vulkan_op_draw_command
|
2023-06-24 22:56:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
}
|