[gegl/gsoc2011-opencl-2: 6/22] OpenCL Texture Class
- From: Victor Matheus de Araujo Oliveira <vmaolive src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/gsoc2011-opencl-2: 6/22] OpenCL Texture Class
- Date: Mon, 5 Dec 2011 22:16:21 +0000 (UTC)
commit be1c137ca5582502c538275214565c4b70896b50
Author: Victor Oliveira <victormatheus gmail com>
Date: Wed Jun 1 14:25:16 2011 -0300
OpenCL Texture Class
gegl/opencl/Makefile.am | 4 +-
gegl/opencl/gegl-cl-texture.c | 98 +++++++++++++++++++++++++++++++++++++++++
gegl/opencl/gegl-cl-texture.h | 49 ++++++++++++++++++++
3 files changed, 150 insertions(+), 1 deletions(-)
---
diff --git a/gegl/opencl/Makefile.am b/gegl/opencl/Makefile.am
index fc122dc..90df443 100644
--- a/gegl/opencl/Makefile.am
+++ b/gegl/opencl/Makefile.am
@@ -19,8 +19,10 @@ noinst_LTLIBRARIES = libcl.la
#libcl_public_HEADERS = gegl-cl-init.h
libcl_la_SOURCES = \
+ gegl-cl-types.h \
gegl-cl-init.c \
gegl-cl-init.h \
- gegl-cl-types.h
+ gegl-cl-texture.c \
+ gegl-cl-texture.h
#libcl_la_SOURCES = $(libcl_sources) $(libcl_public_HEADERS)
diff --git a/gegl/opencl/gegl-cl-texture.c b/gegl/opencl/gegl-cl-texture.c
new file mode 100644
index 0000000..58281d0
--- /dev/null
+++ b/gegl/opencl/gegl-cl-texture.c
@@ -0,0 +1,98 @@
+#include "gegl.h"
+#include "gegl-cl-types.h"
+#include "gegl-cl-init.h"
+#include "gegl-cl-texture.h"
+
+GeglClTexture *
+gegl_cl_texture_new (const gint width, const gint height)
+{
+ cl_int errcode;
+
+ GeglClTexture *texture = g_new (GeglClTexture, 1);
+ texture->width = width;
+ texture->height = height;
+ texture->format.image_channel_order = CL_RGBA;
+ texture->format.image_channel_data_type = CL_FLOAT;
+ texture->data = gegl_clCreateImage2D (gegl_cl_get_context(),
+ CL_MEM_READ_WRITE,
+ &texture->format,
+ texture->width,
+ texture->height,
+ 0, NULL, &errcode);
+ if (errcode != CL_SUCCESS)
+ {
+ g_warning("OpenCL Alloc Error: %s", gegl_cl_errstring(errcode));
+ g_free(texture);
+ return NULL;
+ }
+
+ return texture;
+}
+
+void
+gegl_cl_texture_free (GeglClTexture *texture)
+{
+ gegl_clReleaseMemObject (texture->data);
+ g_free (texture);
+}
+
+void
+gegl_cl_texture_get (const GeglClTexture *texture,
+ gpointer dst)
+{
+ const size_t origin[3] = {0,0,0};
+ const size_t region[3] = {texture->width,
+ texture->height,
+ 1};
+ gegl_clEnqueueReadImage(gegl_cl_get_command_queue(),
+ texture->data, CL_TRUE, origin, region, 0, 0, dst,
+ 0, NULL, NULL);
+}
+
+void
+gegl_cl_texture_set (GeglClTexture *texture,
+ const gpointer src)
+{
+ const size_t origin[3] = {0,0,0};
+ const size_t region[3] = {texture->width,
+ texture->height,
+ 1};
+ gegl_clEnqueueWriteImage(gegl_cl_get_command_queue(),
+ texture->data, CL_TRUE, origin, region, 0, 0, src,
+ 0, NULL, NULL);
+}
+
+GeglClTexture *
+gegl_cl_texture_dup (const GeglClTexture *texture)
+{
+ const size_t origin[3] = {0,0,0};
+ const size_t region[3] = {texture->width,
+ texture->height,
+ 1};
+
+ GeglClTexture *new_texture = gegl_cl_texture_new (texture->width,
+ texture->height);
+
+ gegl_clEnqueueCopyImage(gegl_cl_get_command_queue(),
+ texture->data, new_texture->data,
+ origin, origin, region,
+ 0, NULL, NULL);
+ return new_texture;
+}
+
+void
+gegl_cl_texture_copy (const GeglClTexture *src,
+ GeglRectangle *src_rect,
+ GeglClTexture *dst,
+ gint dst_x,
+ gint dst_y)
+{
+ const size_t src_origin[3] = {src_rect->x, src_rect->y, 0};
+ const size_t dst_origin[3] = {dst_x, dst_y, 0};
+ const size_t region[3] = {src_rect->width, src_rect->height, 1};
+
+ gegl_clEnqueueCopyImage (gegl_cl_get_command_queue(),
+ src->data, dst->data,
+ src_origin, dst_origin, region,
+ 0, NULL, NULL);
+}
diff --git a/gegl/opencl/gegl-cl-texture.h b/gegl/opencl/gegl-cl-texture.h
new file mode 100644
index 0000000..ff411af
--- /dev/null
+++ b/gegl/opencl/gegl-cl-texture.h
@@ -0,0 +1,49 @@
+#ifndef __GEGL_CL_TEXTURE_H__
+#define __GEGL_CL_TEXTURE_H__
+
+#include <glib-object.h>
+
+#include "gegl.h"
+#include "gegl-cl-types.h"
+#include "gegl-cl-init.h"
+
+G_BEGIN_DECLS
+
+struct _GeglClTexture
+{
+ cl_mem data;
+ cl_image_format format;
+ gint width;
+ gint height;
+};
+
+typedef struct _GeglClTexture GeglClTexture;
+
+GType gegl_cl_texture_get_type (void) G_GNUC_CONST;
+
+GeglClTexture *gegl_cl_texture_new (const gint width,
+ const gint height);
+
+void gegl_cl_texture_free (GeglClTexture *texture);
+
+void gegl_cl_texture_get (const GeglClTexture *texture,
+ gpointer dest);
+
+void gegl_cl_texture_set (GeglClTexture *texture,
+ const gpointer src);
+
+GeglClTexture *gegl_cl_texture_dup (const GeglClTexture *texture);
+
+void gegl_cl_texture_copy (const GeglClTexture *src,
+ GeglRectangle *src_rect,
+ GeglClTexture *dst,
+ gint dst_x,
+ gint dst_y);
+
+#define GEGL_TYPE_CL_TEXTURE (gegl_cl_texture_get_type())
+
+#define gegl_cl_texture_get_data(texture) (texture->data)
+
+G_END_DECLS
+
+#endif /* __GEGL_CL_TEXTURE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]