1
0
Fork 0

texture-3d: remove _EXP defines + CoglHandle and pass context

We are in the process of removing all _EXP suffix mangling for
experimental APIs (Ref: c6528c4b6c) 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.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
This commit is contained in:
Robert Bragg 2012-02-18 02:11:34 +00:00
parent 80ccf06b84
commit 47868e1f3e
5 changed files with 114 additions and 123 deletions

View file

@ -399,10 +399,10 @@ cogl_context_new (CoglDisplay *display,
/* If 3D or rectangle textures aren't supported then these should /* If 3D or rectangle textures aren't supported then these should
just silently return NULL */ just silently return NULL */
context->default_gl_texture_3d_tex = 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, /* height */
1, /* depth */ 1, /* depth */
COGL_TEXTURE_NONE,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
NULL); NULL);
context->default_gl_texture_rect_tex = context->default_gl_texture_rect_tex =

View file

@ -28,10 +28,7 @@
#include "cogl-handle.h" #include "cogl-handle.h"
#include "cogl-pipeline-private.h" #include "cogl-pipeline-private.h"
#include "cogl-texture-private.h" #include "cogl-texture-private.h"
#include "cogl-texture-3d.h"
#define COGL_TEXTURE_3D(tex) ((CoglTexture3D *) tex)
typedef struct _CoglTexture3D CoglTexture3D;
struct _CoglTexture3D struct _CoglTexture3D
{ {
@ -60,10 +57,9 @@ struct _CoglTexture3D
/* /*
* cogl_texture_3d_new_from_bitmap: * 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. * @height: height of the texture in pixels.
* @depth: depth 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 * @internal_format: the #CoglPixelFormat that will be used for storing
* the buffer on the GPU. If COGL_PIXEL_FORMAT_ANY is given then a * 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 * premultiplied format similar to the format of the source data will
@ -81,14 +77,14 @@ struct _CoglTexture3D
* actual height of the bitmap can be larger than @height × @depth. In * actual height of the bitmap can be larger than @height × @depth. In
* this case it assumes there is padding between the images. * 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. * there was an error.
*/ */
CoglHandle CoglTexture3D *
_cogl_texture_3d_new_from_bitmap (CoglBitmap *bmp, _cogl_texture_3d_new_from_bitmap (CoglContext *context,
CoglBitmap *bmp,
unsigned int height, unsigned int height,
unsigned int depth, unsigned int depth,
CoglTextureFlags flags,
CoglPixelFormat internal_format, CoglPixelFormat internal_format,
GError **error); GError **error);

View file

@ -100,10 +100,10 @@ _cogl_texture_3d_free (CoglTexture3D *tex_3d)
} }
static CoglTexture3D * static CoglTexture3D *
_cogl_texture_3d_create_base (unsigned int width, _cogl_texture_3d_create_base (CoglContext *ctx,
unsigned int height, int width,
unsigned int depth, int height,
CoglTextureFlags flags, int depth,
CoglPixelFormat internal_format) CoglPixelFormat internal_format)
{ {
CoglTexture3D *tex_3d = g_new (CoglTexture3D, 1); CoglTexture3D *tex_3d = g_new (CoglTexture3D, 1);
@ -115,7 +115,7 @@ _cogl_texture_3d_create_base (unsigned int width,
tex_3d->height = height; tex_3d->height = height;
tex_3d->depth = depth; tex_3d->depth = depth;
tex_3d->mipmaps_dirty = TRUE; 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 */ /* We default to GL_LINEAR for both filters */
tex_3d->min_filter = GL_LINEAR; tex_3d->min_filter = GL_LINEAR;
@ -132,18 +132,16 @@ _cogl_texture_3d_create_base (unsigned int width,
} }
static gboolean static gboolean
_cogl_texture_3d_can_create (unsigned int width, _cogl_texture_3d_can_create (CoglContext *ctx,
unsigned int height, int width,
unsigned int depth, int height,
CoglTextureFlags flags, int depth,
CoglPixelFormat internal_format, CoglPixelFormat internal_format,
GError **error) GError **error)
{ {
GLenum gl_intformat; GLenum gl_intformat;
GLenum gl_type; GLenum gl_type;
_COGL_GET_CONTEXT (ctx, FALSE);
/* This should only happen on GLES */ /* This should only happen on GLES */
if (!cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_3D)) if (!cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_3D))
{ {
@ -192,11 +190,11 @@ _cogl_texture_3d_can_create (unsigned int width,
return TRUE; return TRUE;
} }
CoglHandle CoglTexture3D *
cogl_texture_3d_new_with_size (unsigned int width, cogl_texture_3d_new_with_size (CoglContext *ctx,
unsigned int height, int width,
unsigned int depth, int height,
CoglTextureFlags flags, int depth,
CoglPixelFormat internal_format, CoglPixelFormat internal_format,
GError **error) GError **error)
{ {
@ -205,24 +203,24 @@ cogl_texture_3d_new_with_size (unsigned int width,
GLenum gl_format; GLenum gl_format;
GLenum gl_type; GLenum gl_type;
_COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
/* Since no data, we need some internal format */ /* Since no data, we need some internal format */
if (internal_format == COGL_PIXEL_FORMAT_ANY) if (internal_format == COGL_PIXEL_FORMAT_ANY)
internal_format = COGL_PIXEL_FORMAT_RGBA_8888_PRE; internal_format = COGL_PIXEL_FORMAT_RGBA_8888_PRE;
if (!_cogl_texture_3d_can_create (width, height, depth, if (!_cogl_texture_3d_can_create (ctx,
flags, internal_format, width, height, depth,
internal_format,
error)) error))
return COGL_INVALID_HANDLE; return NULL;
internal_format = ctx->texture_driver->pixel_format_to_gl (internal_format, internal_format = ctx->texture_driver->pixel_format_to_gl (internal_format,
&gl_intformat, &gl_intformat,
&gl_format, &gl_format,
&gl_type); &gl_type);
tex_3d = _cogl_texture_3d_create_base (width, height, depth, tex_3d = _cogl_texture_3d_create_base (ctx,
flags, internal_format); width, height, depth,
internal_format);
ctx->texture_driver->gen (GL_TEXTURE_3D, 1, &tex_3d->gl_texture); ctx->texture_driver->gen (GL_TEXTURE_3D, 1, &tex_3d->gl_texture);
_cogl_bind_gl_texture_transient (GL_TEXTURE_3D, _cogl_bind_gl_texture_transient (GL_TEXTURE_3D,
@ -234,11 +232,11 @@ cogl_texture_3d_new_with_size (unsigned int width,
return _cogl_texture_3d_handle_new (tex_3d); return _cogl_texture_3d_handle_new (tex_3d);
} }
CoglHandle CoglTexture3D *
_cogl_texture_3d_new_from_bitmap (CoglBitmap *bmp, _cogl_texture_3d_new_from_bitmap (CoglContext *ctx,
CoglBitmap *bmp,
unsigned int height, unsigned int height,
unsigned int depth, unsigned int depth,
CoglTextureFlags flags,
CoglPixelFormat internal_format, CoglPixelFormat internal_format,
GError **error) GError **error)
{ {
@ -251,18 +249,17 @@ _cogl_texture_3d_new_from_bitmap (CoglBitmap *bmp,
GLenum gl_type; GLenum gl_type;
guint8 *data; guint8 *data;
_COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
bmp_width = _cogl_bitmap_get_width (bmp); bmp_width = _cogl_bitmap_get_width (bmp);
bmp_format = _cogl_bitmap_get_format (bmp); bmp_format = _cogl_bitmap_get_format (bmp);
internal_format = _cogl_texture_determine_internal_format (bmp_format, internal_format = _cogl_texture_determine_internal_format (bmp_format,
internal_format); internal_format);
if (!_cogl_texture_3d_can_create (bmp_width, height, depth, if (!_cogl_texture_3d_can_create (ctx,
flags, internal_format, bmp_width, height, depth,
internal_format,
error)) error))
return COGL_INVALID_HANDLE; return NULL;
dst_bmp = _cogl_texture_prepare_for_upload (bmp, dst_bmp = _cogl_texture_prepare_for_upload (bmp,
internal_format, 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, g_set_error (error, COGL_BITMAP_ERROR, COGL_BITMAP_ERROR_FAILED,
"Bitmap conversion failed"); "Bitmap conversion failed");
return COGL_INVALID_HANDLE; return NULL;
} }
tex_3d = _cogl_texture_3d_create_base (bmp_width, height, depth, tex_3d = _cogl_texture_3d_create_base (ctx,
flags, internal_format); bmp_width, height, depth,
internal_format);
/* Keep a copy of the first pixel so that if glGenerateMipmap isn't /* Keep a copy of the first pixel so that if glGenerateMipmap isn't
supported we can fallback to using GL_GENERATE_MIPMAP */ 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); return _cogl_texture_3d_handle_new (tex_3d);
} }
CoglHandle CoglTexture3D *
cogl_texture_3d_new_from_data (unsigned int width, cogl_texture_3d_new_from_data (CoglContext *context,
unsigned int height, int width,
unsigned int depth, int height,
CoglTextureFlags flags, int depth,
CoglPixelFormat format, CoglPixelFormat format,
CoglPixelFormat internal_format, CoglPixelFormat internal_format,
unsigned int rowstride, int rowstride,
unsigned int image_stride, int image_stride,
const guint8 *data, const guint8 *data,
GError **error) GError **error)
{ {
CoglBitmap *bitmap; CoglBitmap *bitmap;
CoglHandle ret; CoglTexture3D *ret;
/* These are considered a programmer errors so we won't set a /* 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 GError. It would be nice if this was a _COGL_RETURN_IF_FAIL but the
rest of Cogl isn't using that */ rest of Cogl isn't using that */
if (format == COGL_PIXEL_FORMAT_ANY) if (format == COGL_PIXEL_FORMAT_ANY)
return COGL_INVALID_HANDLE; return NULL;
if (data == NULL) if (data == NULL)
return COGL_INVALID_HANDLE; return NULL;
/* Rowstride from width if not given */ /* Rowstride from width if not given */
if (rowstride == 0) if (rowstride == 0)
@ -347,7 +345,7 @@ cogl_texture_3d_new_from_data (unsigned int width,
image_stride = height * rowstride; image_stride = height * rowstride;
if (image_stride < rowstride * height) if (image_stride < rowstride * height)
return COGL_INVALID_HANDLE; return NULL;
/* GL doesn't support uploading when the image_stride isn't a /* GL doesn't support uploading when the image_stride isn't a
multiple of the rowstride. If this happens we'll just pack the 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 */
NULL /* destroy_fn_data */); NULL /* destroy_fn_data */);
ret = _cogl_texture_3d_new_from_bitmap (bitmap, ret = _cogl_texture_3d_new_from_bitmap (context,
bitmap,
height, height,
depth, depth,
flags,
internal_format, internal_format,
error); error);

View file

@ -45,21 +45,16 @@ G_BEGIN_DECLS
* account the 'r' texture coordinate to select one of the images. * account the 'r' texture coordinate to select one of the images.
*/ */
/* All of the cogl-texture-3d API is currently experimental so we typedef struct _CoglTexture3D CoglTexture3D;
* 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 #define COGL_TEXTURE_3D(X) ((CoglTexture3D *)X)
* 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
/** /**
* cogl_texture_3d_new_with_size: * cogl_texture_3d_new_with_size:
* @context: a #CoglContext
* @width: width of the texture in pixels. * @width: width of the texture in pixels.
* @height: height of the texture in pixels. * @height: height of the texture in pixels.
* @depth: depth 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 * @internal_format: the #CoglPixelFormat to use for the GPU
* storage of the texture. * storage of the texture.
* @error: A GError return location. * @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 * %COGL_FEATURE_TEXTURE_3D is not advertised. It can also fail if the
* requested dimensions are not supported by the GPU. * requested dimensions are not supported by the GPU.
* *
* Return value: a new handle to a CoglTexture3D object or * Return value: a new #CoglTexture3D object or
* %COGL_INVALID_HANDLE on failure. * %NULL on failure and an exception will be returned
* Since: 1.4 * in @error.
* Since: 1.10
* Stability: Unstable * Stability: Unstable
*/ */
CoglHandle CoglTexture3D *
cogl_texture_3d_new_with_size (unsigned int width, cogl_texture_3d_new_with_size (CoglContext *context,
unsigned int height, int width,
unsigned int depth, int height,
CoglTextureFlags flags, int depth,
CoglPixelFormat internal_format, CoglPixelFormat internal_format,
GError **error); GError **error);
/** /**
* cogl_texture_3d_new_from_data: * cogl_texture_3d_new_from_data:
* @context: a #CoglContext
* @width: width of the texture in pixels. * @width: width of the texture in pixels.
* @height: height of the texture in pixels. * @height: height of the texture in pixels.
* @depth: depth 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 * @format: the #CoglPixelFormat the buffer is stored in in RAM
* @internal_format: the #CoglPixelFormat that will be used for storing * @internal_format: the #CoglPixelFormat that will be used for storing
* the buffer on the GPU. If COGL_PIXEL_FORMAT_ANY is given then a * 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 * %COGL_FEATURE_TEXTURE_3D is not advertised. It can also fail if the
* requested dimensions are not supported by the GPU. * requested dimensions are not supported by the GPU.
* *
* Return value: the newly created texture or %COGL_INVALID_HANDLE if * Return value: the newly created #CoglTexture3D or %NULL if
* there was an error. * there was an error an an exception will be returned
* Since: 1.4 * through @error.
* Since: 1.10
* Stability: Unstable * Stability: Unstable
*/ */
CoglHandle CoglTexture3D *
cogl_texture_3d_new_from_data (unsigned int width, cogl_texture_3d_new_from_data (CoglContext *context,
unsigned int height, int width,
unsigned int depth, int height,
CoglTextureFlags flags, int depth,
CoglPixelFormat format, CoglPixelFormat format,
CoglPixelFormat internal_format, CoglPixelFormat internal_format,
unsigned int rowstride, int rowstride,
unsigned int image_stride, int image_stride,
const guint8 *data, const guint8 *data,
GError **error); GError **error);
/** /**
* cogl_is_texture_3d: * 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 * and %FALSE otherwise
* *
* Since: 1.4 * Since: 1.4
* Stability: Unstable * Stability: Unstable
*/ */
gboolean gboolean
cogl_is_texture_3d (CoglHandle handle); cogl_is_texture_3d (void *object);
G_END_DECLS G_END_DECLS

View file

@ -19,13 +19,13 @@ typedef struct _TestState
CoglFramebuffer *fb; CoglFramebuffer *fb;
} TestState; } TestState;
static CoglTexture * static CoglTexture3D *
create_texture_3d (void) create_texture_3d (CoglContext *context)
{ {
int x, y, z; int x, y, z;
guint8 *data = g_malloc (TEX_IMAGE_STRIDE * TEX_DEPTH); guint8 *data = g_malloc (TEX_IMAGE_STRIDE * TEX_DEPTH);
guint8 *p = data; guint8 *p = data;
CoglHandle tex; CoglTexture3D *tex;
GError *error = NULL; GError *error = NULL;
for (z = 0; z < TEX_DEPTH; z++) for (z = 0; z < TEX_DEPTH; z++)
@ -51,8 +51,8 @@ create_texture_3d (void)
p += TEX_IMAGE_STRIDE - (TEX_HEIGHT * TEX_ROWSTRIDE); p += TEX_IMAGE_STRIDE - (TEX_HEIGHT * TEX_ROWSTRIDE);
} }
tex = cogl_texture_3d_new_from_data (TEX_WIDTH, TEX_HEIGHT, TEX_DEPTH, tex = cogl_texture_3d_new_from_data (context,
COGL_TEXTURE_NO_AUTO_MIPMAP, TEX_WIDTH, TEX_HEIGHT, TEX_DEPTH,
COGL_PIXEL_FORMAT_RGBA_8888, COGL_PIXEL_FORMAT_RGBA_8888,
COGL_PIXEL_FORMAT_ANY, COGL_PIXEL_FORMAT_ANY,
TEX_ROWSTRIDE, TEX_ROWSTRIDE,
@ -60,7 +60,7 @@ create_texture_3d (void)
data, data,
&error); &error);
if (tex == COGL_INVALID_HANDLE) if (tex == NULL)
{ {
g_assert (error != NULL); g_assert (error != NULL);
g_warning ("Failed to create 3D texture: %s", error->message); g_warning ("Failed to create 3D texture: %s", error->message);
@ -75,7 +75,7 @@ create_texture_3d (void)
static void static void
draw_frame (TestState *state) draw_frame (TestState *state)
{ {
CoglTexture *tex = create_texture_3d (); CoglTexture *tex = COGL_TEXTURE (create_texture_3d (state->context));
CoglPipeline *pipeline = cogl_pipeline_new (); CoglPipeline *pipeline = cogl_pipeline_new ();
typedef struct { float x, y, s, t, r; } Vert; typedef struct { float x, y, s, t, r; } Vert;
CoglPrimitive *primitive; CoglPrimitive *primitive;
@ -200,7 +200,7 @@ static void
test_multi_texture (TestState *state) test_multi_texture (TestState *state)
{ {
CoglPipeline *pipeline; CoglPipeline *pipeline;
CoglHandle tex_3d; CoglTexture3D *tex_3d;
CoglTexture2D *tex_2d; CoglTexture2D *tex_2d;
guint8 tex_data[4]; guint8 tex_data[4];
@ -230,8 +230,8 @@ test_multi_texture (TestState *state)
tex_data[1] = 0xff; tex_data[1] = 0xff;
tex_data[2] = 0x00; tex_data[2] = 0x00;
tex_data[3] = 0xff; tex_data[3] = 0xff;
tex_3d = cogl_texture_3d_new_from_data (1, 1, 1, /* width/height/depth */ tex_3d = cogl_texture_3d_new_from_data (state->context,
COGL_TEXTURE_NONE, 1, 1, 1, /* width/height/depth */
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
4, /* rowstride */ 4, /* rowstride */