[gegl] gegl-cl-texture improvements



commit 4dcc7c7f45cdce6fcc294f967f278cc12abac1e9
Author: Victor Oliveira <victormatheus gmail com>
Date:   Mon Jan 2 16:33:58 2012 -0200

    gegl-cl-texture improvements

 gegl/opencl/gegl-cl-texture.c |   35 +++++++++++++++++++++++++----------
 gegl/opencl/gegl-cl-texture.h |   24 ++++++++++--------------
 gegl/opencl/gegl-cl-types.h   |   10 ++++++++++
 3 files changed, 45 insertions(+), 24 deletions(-)
---
diff --git a/gegl/opencl/gegl-cl-texture.c b/gegl/opencl/gegl-cl-texture.c
index 58281d0..67e7ebc 100644
--- a/gegl/opencl/gegl-cl-texture.c
+++ b/gegl/opencl/gegl-cl-texture.c
@@ -4,15 +4,14 @@
 #include "gegl-cl-texture.h"
 
 GeglClTexture *
-gegl_cl_texture_new (const gint width, const gint height)
+gegl_cl_texture_new (gint width, gint height, cl_image_format format)
 {
   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->format = format;
   texture->data  = gegl_clCreateImage2D (gegl_cl_get_context(),
                                          CL_MEM_READ_WRITE,
                                          &texture->format,
@@ -29,36 +28,51 @@ gegl_cl_texture_new (const gint width, const gint height)
   return texture;
 }
 
+GeglClTexture *
+gegl_cl_texture_new_from_mem (cl_mem mem, gint width, gint height, cl_image_format format)
+{
+  cl_int errcode;
+
+  GeglClTexture *texture = g_new (GeglClTexture, 1);
+  texture->width = width;
+  texture->height = height;
+  texture->format = format;
+  texture->data  = mem;
+  return texture;
+}
+
 void
 gegl_cl_texture_free (GeglClTexture *texture)
 {
   gegl_clReleaseMemObject (texture->data);
+  texture->data = NULL;
+
   g_free (texture);
 }
 
 void
-gegl_cl_texture_get (const GeglClTexture *texture,
-                     gpointer             dst)
+gegl_cl_texture_read (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,
+                          texture->data, CL_FALSE, origin, region, 0, 0, dst,
                           0, NULL, NULL);
 }
 
 void
-gegl_cl_texture_set (GeglClTexture  *texture,
-                     const gpointer  src)
+gegl_cl_texture_write (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,
+                          texture->data, CL_FALSE, origin, region, 0, 0, src,
                           0, NULL, NULL);
 }
 
@@ -71,7 +85,8 @@ gegl_cl_texture_dup (const GeglClTexture *texture)
                             1};
 
   GeglClTexture *new_texture = gegl_cl_texture_new (texture->width,
-                                                    texture->height);
+                                                    texture->height,
+                                                    texture->format);
 
   gegl_clEnqueueCopyImage(gegl_cl_get_command_queue(),
                           texture->data, new_texture->data,
diff --git a/gegl/opencl/gegl-cl-texture.h b/gegl/opencl/gegl-cl-texture.h
index ff411af..8ed0a9b 100644
--- a/gegl/opencl/gegl-cl-texture.h
+++ b/gegl/opencl/gegl-cl-texture.h
@@ -9,27 +9,23 @@
 
 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);
+GeglClTexture  *gegl_cl_texture_new      (gint            width,
+                                          gint            height,
+                                          cl_image_format format);
+GeglClTexture  *gegl_cl_texture_new_from_mem
+                                         (cl_mem          mem,
+                                          gint            width,
+                                          gint            height,
+                                          cl_image_format format);
 
 void            gegl_cl_texture_free     (GeglClTexture       *texture);
 
-void            gegl_cl_texture_get      (const GeglClTexture *texture,
+void            gegl_cl_texture_read     (const GeglClTexture *texture,
                                           gpointer             dest);
 
-void            gegl_cl_texture_set      (GeglClTexture       *texture,
+void            gegl_cl_texture_write    (GeglClTexture       *texture,
                                           const gpointer       src);
 
 GeglClTexture  *gegl_cl_texture_dup      (const GeglClTexture *texture);
diff --git a/gegl/opencl/gegl-cl-types.h b/gegl/opencl/gegl-cl-types.h
index b1028bc..4e94b76 100644
--- a/gegl/opencl/gegl-cl-types.h
+++ b/gegl/opencl/gegl-cl-types.h
@@ -8,6 +8,16 @@
 #include "cl_gl_ext.h"
 #include "cl_ext.h"
 
+struct _GeglClTexture
+{
+  cl_mem data;
+  cl_image_format format;
+  gint width;
+  gint height;
+};
+
+typedef struct _GeglClTexture GeglClTexture;
+
 #if defined(_WIN32)
 #define CL_API_ENTRY
 #define CL_API_CALL __stdcall



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]