[cogl/wip/rib/master-next: 18/29] texture-3d: remove _EXP defines + CoglHandle and pass context



commit 4f525d175b1cbfdddb570db2f2ba86ed9b8f0caf
Author: Robert Bragg <robert linux intel com>
Date:   Sat Feb 18 02:11:34 2012 +0000

    texture-3d: remove _EXP defines + CoglHandle and pass context
    
    We are in the process of removing all _EXP suffix mangling for
    experimental APIs (Ref: c6528c4b6c3c34) and adding missing gtk-doc
    comments so that we can instead rely on the "Stability: unstable"
    markers in the gtk-doc comments. This patch tackles the cogl-texture-3d
    api symbols.
    
    This patch also replaces use of CoglHandle with a CoglTexture3D type
    instead.
    
    Finally this patch also ensures the CoglTexture3D constructors take an
    explicit CoglContext pointer but not a CoglTextureFlags argument,
    consistent with other CoglTexture constructors.

 cogl/cogl-context.c             |    4 +-
 cogl/cogl-texture-3d-private.h  |   24 +++-----
 cogl/cogl-texture-3d.c          |  118 +++++++++++++++++++--------------------
 cogl/cogl-texture-3d.h          |   71 +++++++++++------------
 tests/conform/test-texture-3d.c |   20 +++---
 5 files changed, 114 insertions(+), 123 deletions(-)
---
diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c
index a6f0965..5ee75aa 100644
--- a/cogl/cogl-context.c
+++ b/cogl/cogl-context.c
@@ -399,10 +399,10 @@ cogl_context_new (CoglDisplay *display,
   /* If 3D or rectangle textures aren't supported then these should
      just silently return NULL */
   context->default_gl_texture_3d_tex =
-    _cogl_texture_3d_new_from_bitmap (default_texture_bitmap,
+    _cogl_texture_3d_new_from_bitmap (context,
+                                      default_texture_bitmap,
                                       1, /* height */
                                       1, /* depth */
-                                      COGL_TEXTURE_NONE,
                                       COGL_PIXEL_FORMAT_RGBA_8888_PRE,
                                       NULL);
   context->default_gl_texture_rect_tex =
diff --git a/cogl/cogl-texture-3d-private.h b/cogl/cogl-texture-3d-private.h
index b6c9923..b1cc7d8 100644
--- a/cogl/cogl-texture-3d-private.h
+++ b/cogl/cogl-texture-3d-private.h
@@ -28,10 +28,7 @@
 #include "cogl-handle.h"
 #include "cogl-pipeline-private.h"
 #include "cogl-texture-private.h"
-
-#define COGL_TEXTURE_3D(tex) ((CoglTexture3D *) tex)
-
-typedef struct _CoglTexture3D CoglTexture3D;
+#include "cogl-texture-3d.h"
 
 struct _CoglTexture3D
 {
@@ -60,10 +57,9 @@ struct _CoglTexture3D
 
 /*
  * cogl_texture_3d_new_from_bitmap:
- * @bmp_handle: A #CoglHandle to a bitmap.
+ * @bmp_handle: A #CoglBitmap object.
  * @height: height of the texture in pixels.
  * @depth: depth of the texture in pixels.
- * @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE
  * @internal_format: the #CoglPixelFormat that will be used for storing
  *    the buffer on the GPU. If COGL_PIXEL_FORMAT_ANY is given then a
  *    premultiplied format similar to the format of the source data will
@@ -81,15 +77,15 @@ struct _CoglTexture3D
  * actual height of the bitmap can be larger than @height à @depth. In
  * this case it assumes there is padding between the images.
  *
- * Return value: the newly created texture or %COGL_INVALID_HANDLE if
+ * Return value: the newly created texture or %NULL if
  *   there was an error.
  */
-CoglHandle
-_cogl_texture_3d_new_from_bitmap (CoglBitmap      *bmp,
-                                  unsigned int     height,
-                                  unsigned int     depth,
-                                  CoglTextureFlags flags,
-                                  CoglPixelFormat  internal_format,
-                                  GError         **error);
+CoglTexture3D *
+_cogl_texture_3d_new_from_bitmap (CoglContext *context,
+                                  CoglBitmap *bmp,
+                                  unsigned int height,
+                                  unsigned int depth,
+                                  CoglPixelFormat internal_format,
+                                  GError **error);
 
 #endif /* __COGL_TEXTURE_3D_PRIVATE_H */
diff --git a/cogl/cogl-texture-3d.c b/cogl/cogl-texture-3d.c
index f4478fb..ee80d62 100644
--- a/cogl/cogl-texture-3d.c
+++ b/cogl/cogl-texture-3d.c
@@ -100,11 +100,11 @@ _cogl_texture_3d_free (CoglTexture3D *tex_3d)
 }
 
 static CoglTexture3D *
-_cogl_texture_3d_create_base (unsigned int     width,
-                              unsigned int     height,
-                              unsigned int     depth,
-                              CoglTextureFlags flags,
-                              CoglPixelFormat  internal_format)
+_cogl_texture_3d_create_base (CoglContext *ctx,
+                              int width,
+                              int height,
+                              int depth,
+                              CoglPixelFormat internal_format)
 {
   CoglTexture3D *tex_3d = g_new (CoglTexture3D, 1);
   CoglTexture *tex = COGL_TEXTURE (tex_3d);
@@ -115,7 +115,7 @@ _cogl_texture_3d_create_base (unsigned int     width,
   tex_3d->height = height;
   tex_3d->depth = depth;
   tex_3d->mipmaps_dirty = TRUE;
-  tex_3d->auto_mipmap = (flags & COGL_TEXTURE_NO_AUTO_MIPMAP) == 0;
+  tex_3d->auto_mipmap = TRUE;
 
   /* We default to GL_LINEAR for both filters */
   tex_3d->min_filter = GL_LINEAR;
@@ -132,18 +132,16 @@ _cogl_texture_3d_create_base (unsigned int     width,
 }
 
 static gboolean
-_cogl_texture_3d_can_create (unsigned int     width,
-                            unsigned int     height,
-                            unsigned int     depth,
-                            CoglTextureFlags flags,
-                            CoglPixelFormat  internal_format,
-                            GError         **error)
+_cogl_texture_3d_can_create (CoglContext *ctx,
+                             int width,
+                             int height,
+                             int depth,
+                             CoglPixelFormat internal_format,
+                             GError **error)
 {
   GLenum gl_intformat;
   GLenum gl_type;
 
-  _COGL_GET_CONTEXT (ctx, FALSE);
-
   /* This should only happen on GLES */
   if (!cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_3D))
     {
@@ -192,37 +190,37 @@ _cogl_texture_3d_can_create (unsigned int     width,
   return TRUE;
 }
 
-CoglHandle
-cogl_texture_3d_new_with_size (unsigned int     width,
-                               unsigned int     height,
-                               unsigned int     depth,
-                               CoglTextureFlags flags,
-                               CoglPixelFormat  internal_format,
-                               GError         **error)
+CoglTexture3D *
+cogl_texture_3d_new_with_size (CoglContext *ctx,
+                               int width,
+                               int height,
+                               int depth,
+                               CoglPixelFormat internal_format,
+                               GError **error)
 {
   CoglTexture3D         *tex_3d;
   GLenum                 gl_intformat;
   GLenum                 gl_format;
   GLenum                 gl_type;
 
-  _COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
-
   /* Since no data, we need some internal format */
   if (internal_format == COGL_PIXEL_FORMAT_ANY)
     internal_format = COGL_PIXEL_FORMAT_RGBA_8888_PRE;
 
-  if (!_cogl_texture_3d_can_create (width, height, depth,
-                                    flags, internal_format,
+  if (!_cogl_texture_3d_can_create (ctx,
+                                    width, height, depth,
+                                    internal_format,
                                     error))
-    return COGL_INVALID_HANDLE;
+    return NULL;
 
   internal_format = ctx->texture_driver->pixel_format_to_gl (internal_format,
                                                              &gl_intformat,
                                                              &gl_format,
                                                              &gl_type);
 
-  tex_3d = _cogl_texture_3d_create_base (width, height, depth,
-                                         flags, internal_format);
+  tex_3d = _cogl_texture_3d_create_base (ctx,
+                                         width, height, depth,
+                                         internal_format);
 
   ctx->texture_driver->gen (GL_TEXTURE_3D, 1, &tex_3d->gl_texture);
   _cogl_bind_gl_texture_transient (GL_TEXTURE_3D,
@@ -234,13 +232,13 @@ cogl_texture_3d_new_with_size (unsigned int     width,
   return _cogl_texture_3d_handle_new (tex_3d);
 }
 
-CoglHandle
-_cogl_texture_3d_new_from_bitmap (CoglBitmap      *bmp,
-                                  unsigned int     height,
-                                  unsigned int     depth,
-                                  CoglTextureFlags flags,
-                                  CoglPixelFormat  internal_format,
-                                  GError         **error)
+CoglTexture3D *
+_cogl_texture_3d_new_from_bitmap (CoglContext *ctx,
+                                  CoglBitmap *bmp,
+                                  unsigned int height,
+                                  unsigned int depth,
+                                  CoglPixelFormat internal_format,
+                                  GError **error)
 {
   CoglTexture3D   *tex_3d;
   CoglBitmap      *dst_bmp;
@@ -251,18 +249,17 @@ _cogl_texture_3d_new_from_bitmap (CoglBitmap      *bmp,
   GLenum           gl_type;
   guint8          *data;
 
-  _COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
-
   bmp_width = _cogl_bitmap_get_width (bmp);
   bmp_format = _cogl_bitmap_get_format (bmp);
 
   internal_format = _cogl_texture_determine_internal_format (bmp_format,
                                                              internal_format);
 
-  if (!_cogl_texture_3d_can_create (bmp_width, height, depth,
-                                    flags, internal_format,
+  if (!_cogl_texture_3d_can_create (ctx,
+                                    bmp_width, height, depth,
+                                    internal_format,
                                     error))
-    return COGL_INVALID_HANDLE;
+    return NULL;
 
   dst_bmp = _cogl_texture_prepare_for_upload (bmp,
                                               internal_format,
@@ -275,11 +272,12 @@ _cogl_texture_3d_new_from_bitmap (CoglBitmap      *bmp,
     {
       g_set_error (error, COGL_BITMAP_ERROR, COGL_BITMAP_ERROR_FAILED,
                    "Bitmap conversion failed");
-      return COGL_INVALID_HANDLE;
+      return NULL;
     }
 
-  tex_3d = _cogl_texture_3d_create_base (bmp_width, height, depth,
-                                         flags, internal_format);
+  tex_3d = _cogl_texture_3d_create_base (ctx,
+                                         bmp_width, height, depth,
+                                         internal_format);
 
   /* Keep a copy of the first pixel so that if glGenerateMipmap isn't
      supported we can fallback to using GL_GENERATE_MIPMAP */
@@ -315,29 +313,29 @@ _cogl_texture_3d_new_from_bitmap (CoglBitmap      *bmp,
   return _cogl_texture_3d_handle_new (tex_3d);
 }
 
-CoglHandle
-cogl_texture_3d_new_from_data (unsigned int      width,
-                               unsigned int      height,
-                               unsigned int      depth,
-                               CoglTextureFlags  flags,
-                               CoglPixelFormat   format,
-                               CoglPixelFormat   internal_format,
-                               unsigned int      rowstride,
-                               unsigned int      image_stride,
-                               const guint8     *data,
-                               GError          **error)
+CoglTexture3D *
+cogl_texture_3d_new_from_data (CoglContext *context,
+                               int width,
+                               int height,
+                               int depth,
+                               CoglPixelFormat format,
+                               CoglPixelFormat internal_format,
+                               int rowstride,
+                               int image_stride,
+                               const guint8 *data,
+                               GError **error)
 {
   CoglBitmap *bitmap;
-  CoglHandle ret;
+  CoglTexture3D *ret;
 
   /* These are considered a programmer errors so we won't set a
      GError. It would be nice if this was a _COGL_RETURN_IF_FAIL but the
      rest of Cogl isn't using that */
   if (format == COGL_PIXEL_FORMAT_ANY)
-    return COGL_INVALID_HANDLE;
+    return NULL;
 
   if (data == NULL)
-    return COGL_INVALID_HANDLE;
+    return NULL;
 
   /* Rowstride from width if not given */
   if (rowstride == 0)
@@ -347,7 +345,7 @@ cogl_texture_3d_new_from_data (unsigned int      width,
     image_stride = height * rowstride;
 
   if (image_stride < rowstride * height)
-    return COGL_INVALID_HANDLE;
+    return NULL;
 
   /* GL doesn't support uploading when the image_stride isn't a
      multiple of the rowstride. If this happens we'll just pack the
@@ -385,10 +383,10 @@ cogl_texture_3d_new_from_data (unsigned int      width,
                                          NULL, /* destroy_fn */
                                          NULL /* destroy_fn_data */);
 
-  ret = _cogl_texture_3d_new_from_bitmap (bitmap,
+  ret = _cogl_texture_3d_new_from_bitmap (context,
+                                          bitmap,
                                           height,
                                           depth,
-                                          flags,
                                           internal_format,
                                           error);
 
diff --git a/cogl/cogl-texture-3d.h b/cogl/cogl-texture-3d.h
index 7f14c5e..6c14912 100644
--- a/cogl/cogl-texture-3d.h
+++ b/cogl/cogl-texture-3d.h
@@ -45,21 +45,16 @@ G_BEGIN_DECLS
  * account the 'r' texture coordinate to select one of the images.
  */
 
-/* All of the cogl-texture-3d API is currently experimental so we
- * suffix the actual symbols with _EXP so if somone is monitoring for
- * ABI changes it will hopefully be clearer to them what's going on if
- * any of the symbols dissapear at a later date.
- */
-#define cogl_texture_3d_new_with_size cogl_texture_3d_new_with_size_EXP
-#define cogl_texture_3d_new_from_data cogl_texture_3d_new_from_data_EXP
-#define cogl_is_texture_3d cogl_is_texture_3d_EXP
+typedef struct _CoglTexture3D CoglTexture3D;
+
+#define COGL_TEXTURE_3D(X) ((CoglTexture3D *)X)
 
 /**
  * cogl_texture_3d_new_with_size:
+ * @context: a #CoglContext
  * @width: width of the texture in pixels.
  * @height: height of the texture in pixels.
  * @depth: depth of the texture in pixels.
- * @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE
  * @internal_format: the #CoglPixelFormat to use for the GPU
  *    storage of the texture.
  * @error: A GError return location.
@@ -71,25 +66,26 @@ G_BEGIN_DECLS
  * %COGL_FEATURE_TEXTURE_3D is not advertised. It can also fail if the
  * requested dimensions are not supported by the GPU.
  *
- * Return value: a new handle to a CoglTexture3D object or
- *   %COGL_INVALID_HANDLE on failure.
- * Since: 1.4
+ * Return value: a new #CoglTexture3D object or
+ *               %NULL on failure and an exception will be returned
+ *               in @error.
+ * Since: 1.10
  * Stability: Unstable
  */
-CoglHandle
-cogl_texture_3d_new_with_size (unsigned int     width,
-                               unsigned int     height,
-                               unsigned int     depth,
-                               CoglTextureFlags flags,
+CoglTexture3D *
+cogl_texture_3d_new_with_size (CoglContext *context,
+                               int width,
+                               int height,
+                               int depth,
                                CoglPixelFormat  internal_format,
-                               GError         **error);
+                               GError **error);
 
 /**
  * cogl_texture_3d_new_from_data:
+ * @context: a #CoglContext
  * @width: width of the texture in pixels.
  * @height: height of the texture in pixels.
  * @depth: depth of the texture in pixels.
- * @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE
  * @format: the #CoglPixelFormat the buffer is stored in in RAM
  * @internal_format: the #CoglPixelFormat that will be used for storing
  *    the buffer on the GPU. If COGL_PIXEL_FORMAT_ANY is given then a
@@ -117,37 +113,38 @@ cogl_texture_3d_new_with_size (unsigned int     width,
  * %COGL_FEATURE_TEXTURE_3D is not advertised. It can also fail if the
  * requested dimensions are not supported by the GPU.
  *
- * Return value: the newly created texture or %COGL_INVALID_HANDLE if
- *   there was an error.
- * Since: 1.4
+ * Return value: the newly created #CoglTexture3D or %NULL if
+ *               there was an error an an exception will be returned
+ *               through @error.
+ * Since: 1.10
  * Stability: Unstable
  */
-CoglHandle
-cogl_texture_3d_new_from_data (unsigned int      width,
-                               unsigned int      height,
-                               unsigned int      depth,
-                               CoglTextureFlags  flags,
-                               CoglPixelFormat   format,
-                               CoglPixelFormat   internal_format,
-                               unsigned int      rowstride,
-                               unsigned int      image_stride,
-                               const guint8     *data,
-                               GError          **error);
+CoglTexture3D *
+cogl_texture_3d_new_from_data (CoglContext *context,
+                               int width,
+                               int height,
+                               int depth,
+                               CoglPixelFormat format,
+                               CoglPixelFormat internal_format,
+                               int rowstride,
+                               int image_stride,
+                               const guint8 *data,
+                               GError **error);
 
 /**
  * cogl_is_texture_3d:
- * @handle: a #CoglHandle
+ * @object: a #CoglObject
  *
- * Checks whether @handle is a #CoglHandle for a 3D texture.
+ * Checks whether the given object references a #CoglTexture3D
  *
- * Return value: %TRUE if the passed handle represents a 3D texture
+ * Return value: %TRUE if the passed object represents a 3D texture
  *   and %FALSE otherwise
  *
  * Since: 1.4
  * Stability: Unstable
  */
 gboolean
-cogl_is_texture_3d (CoglHandle handle);
+cogl_is_texture_3d (void *object);
 
 G_END_DECLS
 
diff --git a/tests/conform/test-texture-3d.c b/tests/conform/test-texture-3d.c
index e347ad5..fcd511c 100644
--- a/tests/conform/test-texture-3d.c
+++ b/tests/conform/test-texture-3d.c
@@ -19,13 +19,13 @@ typedef struct _TestState
   CoglFramebuffer *fb;
 } TestState;
 
-static CoglTexture *
-create_texture_3d (void)
+static CoglTexture3D *
+create_texture_3d (CoglContext *context)
 {
   int x, y, z;
   guint8 *data = g_malloc (TEX_IMAGE_STRIDE * TEX_DEPTH);
   guint8 *p = data;
-  CoglHandle tex;
+  CoglTexture3D *tex;
   GError *error = NULL;
 
   for (z = 0; z < TEX_DEPTH; z++)
@@ -51,8 +51,8 @@ create_texture_3d (void)
       p += TEX_IMAGE_STRIDE - (TEX_HEIGHT * TEX_ROWSTRIDE);
     }
 
-  tex = cogl_texture_3d_new_from_data (TEX_WIDTH, TEX_HEIGHT, TEX_DEPTH,
-                                       COGL_TEXTURE_NO_AUTO_MIPMAP,
+  tex = cogl_texture_3d_new_from_data (context,
+                                       TEX_WIDTH, TEX_HEIGHT, TEX_DEPTH,
                                        COGL_PIXEL_FORMAT_RGBA_8888,
                                        COGL_PIXEL_FORMAT_ANY,
                                        TEX_ROWSTRIDE,
@@ -60,7 +60,7 @@ create_texture_3d (void)
                                        data,
                                        &error);
 
-  if (tex == COGL_INVALID_HANDLE)
+  if (tex == NULL)
     {
       g_assert (error != NULL);
       g_warning ("Failed to create 3D texture: %s", error->message);
@@ -75,7 +75,7 @@ create_texture_3d (void)
 static void
 draw_frame (TestState *state)
 {
-  CoglTexture *tex = create_texture_3d ();
+  CoglTexture *tex = COGL_TEXTURE (create_texture_3d (state->context));
   CoglPipeline *pipeline = cogl_pipeline_new ();
   typedef struct { float x, y, s, t, r; } Vert;
   CoglPrimitive *primitive;
@@ -200,7 +200,7 @@ static void
 test_multi_texture (TestState *state)
 {
   CoglPipeline *pipeline;
-  CoglHandle tex_3d;
+  CoglTexture3D *tex_3d;
   CoglTexture2D *tex_2d;
   guint8 tex_data[4];
 
@@ -230,8 +230,8 @@ test_multi_texture (TestState *state)
   tex_data[1] = 0xff;
   tex_data[2] = 0x00;
   tex_data[3] = 0xff;
-  tex_3d = cogl_texture_3d_new_from_data (1, 1, 1, /* width/height/depth */
-                                          COGL_TEXTURE_NONE,
+  tex_3d = cogl_texture_3d_new_from_data (state->context,
+                                          1, 1, 1, /* width/height/depth */
                                           COGL_PIXEL_FORMAT_RGBA_8888_PRE,
                                           COGL_PIXEL_FORMAT_RGBA_8888_PRE,
                                           4, /* rowstride */



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