Commit e43ee53f authored by Lubosz Sarnecki's avatar Lubosz Sarnecki

scene-window: Implement y-axis texture flipping.

parent 2aeb7bab
......@@ -310,6 +310,9 @@ _init_windows (Example *self)
xrd_window_set_reset_transformation (window, NULL, 0);
if ((col + row) % 2 == 0)
xrd_window_set_flip_y (window, true);
if (col == 0 && row == 0)
_init_child_window (self, window);
}
......
......@@ -13,6 +13,7 @@ layout (location = 0) in vec2 uv;
layout (binding = 1) uniform sampler2D image;
layout (binding = 2) uniform Shading {
vec4 color;
bool flip_y;
} ubo;
......@@ -20,6 +21,7 @@ layout (location = 0) out vec4 out_color;
void main ()
{
out_color = texture (image, uv) * ubo.color;
vec2 uv_b = ubo.flip_y ? vec2(uv.x, 1.0f - uv.y) : uv;
out_color = texture (image, uv_b) * ubo.color;
}
......@@ -26,6 +26,11 @@ enum
static void
xrd_scene_window_window_interface_init (XrdWindowInterface *iface);
typedef struct {
float color[4];
bool flip_y;
} XrdWindowUniformBuffer;
typedef struct _XrdSceneWindowPrivate
{
XrdSceneObject parent;
......@@ -38,6 +43,7 @@ typedef struct _XrdSceneWindowPrivate
graphene_vec3_t color;
GulkanUniformBuffer *shading_buffer;
XrdWindowUniformBuffer shading_buffer_data;
XrdWindowData window_data;
} XrdSceneWindowPrivate;
......@@ -156,6 +162,7 @@ xrd_scene_window_init (XrdSceneWindow *self)
priv->aspect_ratio = 1.0;
priv->window_data.texture = NULL;
priv->shading_buffer = gulkan_uniform_buffer_new ();
priv->shading_buffer_data.flip_y = false;
priv->window_data.title = NULL;
priv->window_data.child_window = NULL;
......@@ -300,7 +307,7 @@ xrd_scene_window_initialize (XrdSceneWindow *self)
return FALSE;
if (!gulkan_uniform_buffer_allocate_and_map (priv->shading_buffer,
device, sizeof (float) * 4))
device, sizeof (XrdWindowUniformBuffer)))
return FALSE;
graphene_vec3_t white;
......@@ -345,7 +352,11 @@ xrd_scene_window_set_color (XrdSceneWindow *self,
graphene_vec4_t color_vec4;
graphene_vec4_init_from_vec3 (&color_vec4, color, 1.0f);
gulkan_uniform_buffer_update_vec4 (priv->shading_buffer, &color_vec4);
graphene_vec4_to_float (&color_vec4, priv->shading_buffer_data.color);
gulkan_uniform_buffer_update_struct (priv->shading_buffer,
(gpointer) &priv->shading_buffer_data);
}
void
......@@ -539,6 +550,10 @@ _set_flip_y (XrdWindow *window,
XrdSceneWindow *self = XRD_SCENE_WINDOW (window);
XrdSceneWindowPrivate *priv = xrd_scene_window_get_instance_private (self);
priv->flip_y = flip_y;
priv->shading_buffer_data.flip_y = flip_y;
gulkan_uniform_buffer_update_struct (priv->shading_buffer,
(gpointer) &priv->shading_buffer_data);
}
void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment