aboutsummaryrefslogtreecommitdiffstats
path: root/texture-share-vk.lua
diff options
context:
space:
mode:
Diffstat (limited to 'texture-share-vk.lua')
-rw-r--r--texture-share-vk.lua82
1 files changed, 80 insertions, 2 deletions
diff --git a/texture-share-vk.lua b/texture-share-vk.lua
index b8e2523..f8f9c4c 100644
--- a/texture-share-vk.lua
+++ b/texture-share-vk.lua
@@ -18,6 +18,19 @@ typedef enum ImgFormat {
Undefined,
} ImgFormat;
+typedef uint8_t ImgName[1024];
+
+typedef struct ShmemDataInternal {
+ ImgName name;
+ uint32_t handle_id;
+ uint32_t width;
+ uint32_t height;
+ enum ImgFormat format;
+ uint64_t allocation_size;
+ uint64_t gpu_device_uuid_0;
+ uint64_t gpu_device_uuid_1;
+} ShmemDataInternal;
+
// texture_share_gl_client/texture_share_gl_client.h
typedef enum ImageLookupResult {
Error = -1,
@@ -59,6 +72,18 @@ enum ImageLookupResult gl_client_init_image(struct GlClient *gl_client,
ImgFormat format,
bool overwrite_existing);
+enum ImageLookupResult gl_client_find_image(struct GlClient *gl_client,
+ const char *image_name,
+ bool force_update);
+
+struct ClientImageDataGuard *gl_client_find_image_data(struct GlClient *gl_client,
+ const char *image_name,
+ bool force_update);
+
+const ShmemDataInternal *gl_client_image_data_guard_read(const struct ClientImageDataGuard *image_data_guard);
+
+void gl_client_image_data_guard_destroy(struct ClientImageDataGuard *image_data_guard);
+
int gl_client_send_image(struct GlClient *gl_client,
const char *image_name,
GLuint src_texture_id,
@@ -66,6 +91,14 @@ int gl_client_send_image(struct GlClient *gl_client,
bool invert,
GLuint prev_fbo,
const struct GlImageExtent *extents);
+
+int gl_client_recv_image(struct GlClient *gl_client,
+ const char *image_name,
+ GLuint src_texture_id,
+ GLenum src_texture_target,
+ bool invert,
+ GLuint prev_fbo,
+ const struct GlImageExtent *extents);
]]
-- from texture_share_vk/config.h
@@ -83,6 +116,8 @@ local GL_TEXTURE_2D = 0x0DE1
local IMAGE_FORMATS = {
rgba8 = ffi.C.R8G8B8A8,
rgb8 = ffi.C.R8G8B8,
+ [ffi.C.R8G8B8A8] = "rgba8",
+ [ffi.C.R8G8B8] = "rgb8",
}
local tvs = ffi.load("texture_share_gl_client")
@@ -135,7 +170,38 @@ function Client:newSharedCanvas(name, ...)
name = name,
canvas = canvas,
client = self,
- texture_id = name_ptr[0]
+ texture_id = name_ptr[0],
+ }, Canvas)
+end
+
+function Client:loadSharedCanvas(name)
+ local guard = assert(
+ tvs.gl_client_find_image_data(self.client, name, false),
+ "failed to load image"
+ )
+
+ local data = tvs.gl_client_image_data_guard_read(guard)
+ local format = assert(IMAGE_FORMATS[tonumber(data.format)], "unsupported Texture format")
+ local canvas = love.graphics.newCanvas(data.width, data.height, { format = format })
+ tvs.gl_client_image_data_guard_destroy(guard)
+
+ local last_canvas = love.graphics.getCanvas()
+ love.graphics.setCanvas(canvas)
+
+ local name_ptr = ffi.typeof('GLint[1]')()
+ gl.glGetFramebufferAttachmentParameteriv(
+ GL_FRAMEBUFFER,
+ GL_COLOR_ATTACHMENT0,
+ GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME,
+ name_ptr
+ )
+ love.graphics.setCanvas(last_canvas)
+
+ return setmetatable({
+ name = name,
+ canvas = canvas,
+ client = self,
+ texture_id = name_ptr[0],
}, Canvas)
end
@@ -144,7 +210,19 @@ function Client:__gc()
end
function Canvas:send()
- tvs.gl_client_send_image(
+ return tvs.gl_client_send_image(
+ self.client.client,
+ self.name,
+ self.texture_id,
+ GL_TEXTURE_2D,
+ false,
+ 0,
+ nil
+ )
+end
+
+function Canvas:recv()
+ return tvs.gl_client_recv_image(
self.client.client,
self.name,
self.texture_id,