mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-07 11:20:09 +00:00
2aba50efa0
This is a massive refactoring because it collects all the renderops of all renderpasses into one long array in the Render object. Lots of code in there is still flaky and needs cleanup. That will follow in further commits. Other than that it does work fine though.
138 lines
4.9 KiB
C
138 lines
4.9 KiB
C
#include "config.h"
|
|
|
|
#include "gskvulkanblendmodeopprivate.h"
|
|
|
|
#include "gskvulkanprivate.h"
|
|
|
|
#include "vulkan/resources/blend-mode.vert.h"
|
|
|
|
typedef struct _GskVulkanBlendModeOp GskVulkanBlendModeOp;
|
|
|
|
struct _GskVulkanBlendModeOp
|
|
{
|
|
GskVulkanOp op;
|
|
|
|
graphene_rect_t bounds;
|
|
GskBlendMode blend_mode;
|
|
|
|
struct {
|
|
GskVulkanImage *image;
|
|
graphene_rect_t rect;
|
|
graphene_rect_t tex_rect;
|
|
guint32 image_descriptor;
|
|
} top, bottom;
|
|
};
|
|
|
|
static void
|
|
gsk_vulkan_blend_mode_op_finish (GskVulkanOp *op)
|
|
{
|
|
GskVulkanBlendModeOp *self = (GskVulkanBlendModeOp *) op;
|
|
|
|
g_object_unref (self->top.image);
|
|
g_object_unref (self->bottom.image);
|
|
}
|
|
|
|
static void
|
|
gsk_vulkan_blend_mode_op_print (GskVulkanOp *op,
|
|
GString *string,
|
|
guint indent)
|
|
{
|
|
GskVulkanBlendModeOp *self = (GskVulkanBlendModeOp *) op;
|
|
|
|
print_indent (string, indent);
|
|
print_rect (string, &self->bounds);
|
|
g_string_append_printf (string, "blend-mode %d%% ", self->blend_mode);
|
|
print_newline (string);
|
|
}
|
|
|
|
static void
|
|
gsk_vulkan_blend_mode_op_collect_vertex_data (GskVulkanOp *op,
|
|
guchar *data)
|
|
{
|
|
GskVulkanBlendModeOp *self = (GskVulkanBlendModeOp *) op;
|
|
GskVulkanBlendModeInstance *instance = (GskVulkanBlendModeInstance *) (data + op->vertex_offset);
|
|
|
|
gsk_vulkan_rect_to_float (&self->bounds, instance->rect);
|
|
gsk_vulkan_rect_to_float (&self->top.rect, instance->top_rect);
|
|
gsk_vulkan_rect_to_float (&self->bottom.rect, instance->bottom_rect);
|
|
gsk_vulkan_rect_to_float (&self->top.tex_rect, instance->top_tex_rect);
|
|
gsk_vulkan_rect_to_float (&self->bottom.tex_rect, instance->bottom_tex_rect);
|
|
|
|
instance->top_tex_id = self->top.image_descriptor;
|
|
instance->bottom_tex_id = self->bottom.image_descriptor;
|
|
instance->blend_mode = self->blend_mode;
|
|
}
|
|
|
|
static void
|
|
gsk_vulkan_blend_mode_op_reserve_descriptor_sets (GskVulkanOp *op,
|
|
GskVulkanRender *render)
|
|
{
|
|
GskVulkanBlendModeOp *self = (GskVulkanBlendModeOp *) op;
|
|
|
|
self->top.image_descriptor = gsk_vulkan_render_get_image_descriptor (render,
|
|
self->top.image,
|
|
GSK_VULKAN_SAMPLER_DEFAULT);
|
|
self->bottom.image_descriptor = gsk_vulkan_render_get_image_descriptor (render,
|
|
self->bottom.image,
|
|
GSK_VULKAN_SAMPLER_DEFAULT);
|
|
}
|
|
|
|
static GskVulkanOp *
|
|
gsk_vulkan_blend_mode_op_command (GskVulkanOp *op,
|
|
GskVulkanRender *render,
|
|
VkPipelineLayout pipeline_layout,
|
|
VkCommandBuffer command_buffer)
|
|
{
|
|
GskVulkanBlendModeOp *self = (GskVulkanBlendModeOp *) op;
|
|
|
|
vkCmdDraw (command_buffer,
|
|
6, 1,
|
|
0, self->vertex_offset / gsk_vulkan_blend_mode_info.pVertexBindingDescriptions[0].stride);
|
|
|
|
return op->next;
|
|
}
|
|
|
|
static const GskVulkanShaderOpClass GSK_VULKAN_BLEND_MODE_OP_CLASS = {
|
|
GSK_VULKAN_OP_SIZE (GskVulkanBlendModeOp),
|
|
GSK_VULKAN_STAGE_COMMAND,
|
|
"blend-mode",
|
|
&gsk_vulkan_blend_mode_info,
|
|
gsk_vulkan_blend_mode_op_finish,
|
|
gsk_vulkan_blend_mode_op_print,
|
|
gsk_vulkan_op_draw_upload,
|
|
gsk_vulkan_op_draw_count_vertex_data,
|
|
gsk_vulkan_blend_mode_op_collect_vertex_data,
|
|
gsk_vulkan_blend_mode_op_reserve_descriptor_sets,
|
|
gsk_vulkan_op_draw_command
|
|
};
|
|
|
|
void
|
|
gsk_vulkan_blend_mode_op (GskVulkanRender *render,
|
|
const char *clip_type,
|
|
const graphene_rect_t *bounds,
|
|
const graphene_point_t *offset,
|
|
GskBlendMode blend_mode,
|
|
GskVulkanImage *top_image,
|
|
const graphene_rect_t *top_rect,
|
|
const graphene_rect_t *top_tex_rect,
|
|
GskVulkanImage *bottom_image,
|
|
const graphene_rect_t *bottom_rect,
|
|
const graphene_rect_t *bottom_tex_rect)
|
|
{
|
|
GskVulkanBlendModeOp *self;
|
|
|
|
self = (GskVulkanBlendModeOp *) gsk_vulkan_op_alloc (render, &GSK_VULKAN_BLEND_MODE_OP_CLASS);
|
|
|
|
((GskVulkanOp *) self)->clip_type = g_intern_string (clip_type);
|
|
graphene_rect_offset_r (bounds, offset->x, offset->y, &self->bounds);
|
|
self->blend_mode = blend_mode;
|
|
|
|
self->top.image = g_object_ref (top_image);
|
|
graphene_rect_offset_r (top_rect, offset->x, offset->y, &self->top.rect);
|
|
gsk_vulkan_normalize_tex_coords (&self->top.tex_rect, bounds, top_tex_rect);
|
|
|
|
self->bottom.image = g_object_ref (bottom_image);
|
|
graphene_rect_offset_r (bottom_rect, offset->x, offset->y, &self->bottom.rect);
|
|
gsk_vulkan_normalize_tex_coords (&self->bottom.tex_rect, bounds, bottom_tex_rect);
|
|
}
|