2023-06-29 19:43:26 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gskvulkancrossfadeopprivate.h"
|
|
|
|
|
2023-07-03 13:57:30 +00:00
|
|
|
#include "gskvulkanprivate.h"
|
|
|
|
|
2023-06-29 19:43:26 +00:00
|
|
|
#include "vulkan/resources/cross-fade.vert.h"
|
|
|
|
|
|
|
|
typedef struct _GskVulkanCrossFadeOp GskVulkanCrossFadeOp;
|
|
|
|
|
|
|
|
struct _GskVulkanCrossFadeOp
|
|
|
|
{
|
|
|
|
GskVulkanOp op;
|
|
|
|
|
|
|
|
graphene_rect_t bounds;
|
|
|
|
float progress;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
GskVulkanImage *image;
|
|
|
|
graphene_rect_t rect;
|
|
|
|
graphene_rect_t tex_rect;
|
|
|
|
guint32 image_descriptor;
|
|
|
|
} start, end;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_cross_fade_op_finish (GskVulkanOp *op)
|
|
|
|
{
|
|
|
|
GskVulkanCrossFadeOp *self = (GskVulkanCrossFadeOp *) op;
|
|
|
|
|
|
|
|
g_object_unref (self->start.image);
|
|
|
|
g_object_unref (self->end.image);
|
|
|
|
}
|
|
|
|
|
2023-07-05 04:32:52 +00:00
|
|
|
static void
|
|
|
|
gsk_vulkan_cross_fade_op_print (GskVulkanOp *op,
|
|
|
|
GString *string,
|
|
|
|
guint indent)
|
|
|
|
{
|
|
|
|
GskVulkanCrossFadeOp *self = (GskVulkanCrossFadeOp *) op;
|
|
|
|
|
|
|
|
print_indent (string, indent);
|
|
|
|
print_rect (string, &self->bounds);
|
|
|
|
g_string_append_printf (string, "cross-fade %d%% ", (int) (self->progress * 100 + 0.5));
|
|
|
|
print_newline (string);
|
|
|
|
}
|
|
|
|
|
2023-06-29 19:43:26 +00:00
|
|
|
static void
|
2023-07-08 19:28:56 +00:00
|
|
|
gsk_vulkan_cross_fade_op_collect_vertex_data (GskVulkanOp *op,
|
|
|
|
guchar *data)
|
2023-06-29 19:43:26 +00:00
|
|
|
{
|
|
|
|
GskVulkanCrossFadeOp *self = (GskVulkanCrossFadeOp *) op;
|
2023-07-09 14:27:02 +00:00
|
|
|
GskVulkanCrossFadeInstance *instance = (GskVulkanCrossFadeInstance *) (data + op->vertex_offset);
|
2023-06-29 19:43:26 +00:00
|
|
|
|
|
|
|
gsk_vulkan_rect_to_float (&self->bounds, instance->rect);
|
|
|
|
gsk_vulkan_rect_to_float (&self->start.rect, instance->start_rect);
|
|
|
|
gsk_vulkan_rect_to_float (&self->end.rect, instance->end_rect);
|
|
|
|
gsk_vulkan_rect_to_float (&self->start.tex_rect, instance->start_tex_rect);
|
|
|
|
gsk_vulkan_rect_to_float (&self->end.tex_rect, instance->end_tex_rect);
|
|
|
|
|
|
|
|
instance->start_tex_id = self->start.image_descriptor;
|
|
|
|
instance->end_tex_id = self->end.image_descriptor;
|
|
|
|
instance->progress = self->progress;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_cross_fade_op_reserve_descriptor_sets (GskVulkanOp *op,
|
|
|
|
GskVulkanRender *render)
|
|
|
|
{
|
|
|
|
GskVulkanCrossFadeOp *self = (GskVulkanCrossFadeOp *) op;
|
|
|
|
|
|
|
|
self->start.image_descriptor = gsk_vulkan_render_get_image_descriptor (render,
|
|
|
|
self->start.image,
|
|
|
|
GSK_VULKAN_SAMPLER_DEFAULT);
|
|
|
|
self->end.image_descriptor = gsk_vulkan_render_get_image_descriptor (render,
|
|
|
|
self->end.image,
|
|
|
|
GSK_VULKAN_SAMPLER_DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const GskVulkanOpClass GSK_VULKAN_CROSS_FADE_OP_CLASS = {
|
|
|
|
GSK_VULKAN_OP_SIZE (GskVulkanCrossFadeOp),
|
2023-07-09 13:40:48 +00:00
|
|
|
GSK_VULKAN_STAGE_COMMAND,
|
2023-06-29 19:43:26 +00:00
|
|
|
"cross-fade",
|
|
|
|
&gsk_vulkan_cross_fade_info,
|
|
|
|
gsk_vulkan_cross_fade_op_finish,
|
2023-07-05 04:32:52 +00:00
|
|
|
gsk_vulkan_cross_fade_op_print,
|
2023-07-09 14:27:02 +00:00
|
|
|
gsk_vulkan_op_draw_count_vertex_data,
|
2023-06-29 19:43:26 +00:00
|
|
|
gsk_vulkan_cross_fade_op_collect_vertex_data,
|
|
|
|
gsk_vulkan_cross_fade_op_reserve_descriptor_sets,
|
2023-07-09 14:27:02 +00:00
|
|
|
gsk_vulkan_op_draw_command
|
2023-06-29 19:43:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2023-07-09 18:28:12 +00:00
|
|
|
gsk_vulkan_cross_fade_op (GskVulkanRender *render,
|
2023-06-29 19:43:26 +00:00
|
|
|
const char *clip_type,
|
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
const graphene_point_t *offset,
|
|
|
|
float progress,
|
|
|
|
GskVulkanImage *start_image,
|
|
|
|
const graphene_rect_t *start_rect,
|
|
|
|
const graphene_rect_t *start_tex_rect,
|
|
|
|
GskVulkanImage *end_image,
|
|
|
|
const graphene_rect_t *end_rect,
|
|
|
|
const graphene_rect_t *end_tex_rect)
|
|
|
|
{
|
|
|
|
GskVulkanCrossFadeOp *self;
|
|
|
|
|
2023-07-09 18:28:12 +00:00
|
|
|
self = (GskVulkanCrossFadeOp *) gsk_vulkan_op_alloc (render, &GSK_VULKAN_CROSS_FADE_OP_CLASS);
|
2023-06-29 19:43:26 +00:00
|
|
|
|
|
|
|
((GskVulkanOp *) self)->clip_type = g_intern_string (clip_type);
|
|
|
|
graphene_rect_offset_r (bounds, offset->x, offset->y, &self->bounds);
|
|
|
|
self->progress = progress;
|
|
|
|
|
|
|
|
self->start.image = g_object_ref (start_image);
|
|
|
|
graphene_rect_offset_r (start_rect, offset->x, offset->y, &self->start.rect);
|
|
|
|
gsk_vulkan_normalize_tex_coords (&self->start.tex_rect, bounds, start_tex_rect);
|
|
|
|
|
|
|
|
self->end.image = g_object_ref (end_image);
|
|
|
|
graphene_rect_offset_r (end_rect, offset->x, offset->y, &self->end.rect);
|
|
|
|
gsk_vulkan_normalize_tex_coords (&self->end.tex_rect, bounds, end_tex_rect);
|
|
|
|
}
|