diff --git a/cogl/cogl/cogl-atlas-texture.c b/cogl/cogl/cogl-atlas-texture.c index 9ec19b755..b4b1889a2 100644 --- a/cogl/cogl/cogl-atlas-texture.c +++ b/cogl/cogl/cogl-atlas-texture.c @@ -693,9 +693,10 @@ cogl_atlas_texture_new_with_size (CoglContext *ctx, g_return_val_if_fail (width > 0 && height > 0, NULL); loader = _cogl_texture_create_loader (); - loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZED; + loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZE; loader->src.sized.width = width; loader->src.sized.height = height; + loader->src.sized.format = COGL_PIXEL_FORMAT_ANY; return _cogl_atlas_texture_create_base (ctx, width, height, COGL_PIXEL_FORMAT_RGBA_8888_PRE, @@ -782,7 +783,11 @@ allocate_with_size (CoglAtlasTexture *atlas_tex, GError **error) { CoglTexture *tex = COGL_TEXTURE (atlas_tex); - CoglPixelFormat internal_format = + CoglPixelFormat internal_format; + + g_warn_if_fail (loader->src.sized.format == COGL_PIXEL_FORMAT_ANY); + + internal_format = _cogl_texture_determine_internal_format (tex, COGL_PIXEL_FORMAT_ANY); if (allocate_space (atlas_tex, @@ -873,7 +878,7 @@ _cogl_atlas_texture_allocate (CoglTexture *tex, switch (loader->src_type) { - case COGL_TEXTURE_SOURCE_TYPE_SIZED: + case COGL_TEXTURE_SOURCE_TYPE_SIZE: return allocate_with_size (atlas_tex, loader, error); case COGL_TEXTURE_SOURCE_TYPE_BITMAP: return allocate_from_bitmap (atlas_tex, loader, error); diff --git a/cogl/cogl/cogl-texture-2d-sliced.c b/cogl/cogl/cogl-texture-2d-sliced.c index 8e7f91f70..7a49a4343 100644 --- a/cogl/cogl/cogl-texture-2d-sliced.c +++ b/cogl/cogl/cogl-texture-2d-sliced.c @@ -872,9 +872,10 @@ cogl_texture_2d_sliced_new_with_size (CoglContext *ctx, int max_waste) { CoglTextureLoader *loader = _cogl_texture_create_loader (); - loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZED; + loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZE; loader->src.sized.width = width; loader->src.sized.height = height; + loader->src.sized.format = COGL_PIXEL_FORMAT_ANY; return _cogl_texture_2d_sliced_create_base (ctx, width, @@ -987,7 +988,11 @@ allocate_with_size (CoglTexture2DSliced *tex_2ds, GError **error) { CoglTexture *tex = COGL_TEXTURE (tex_2ds); - CoglPixelFormat internal_format = + CoglPixelFormat internal_format; + + g_warn_if_fail (loader->src.sized.format == COGL_PIXEL_FORMAT_ANY); + + internal_format = _cogl_texture_determine_internal_format (tex, COGL_PIXEL_FORMAT_ANY); if (allocate_slices (tex_2ds, @@ -1071,7 +1076,7 @@ _cogl_texture_2d_sliced_allocate (CoglTexture *tex, switch (loader->src_type) { - case COGL_TEXTURE_SOURCE_TYPE_SIZED: + case COGL_TEXTURE_SOURCE_TYPE_SIZE: return allocate_with_size (tex_2ds, loader, error); case COGL_TEXTURE_SOURCE_TYPE_BITMAP: return allocate_from_bitmap (tex_2ds, loader, error); diff --git a/cogl/cogl/cogl-texture-2d.c b/cogl/cogl/cogl-texture-2d.c index 88978abb3..ffd0ceaf5 100644 --- a/cogl/cogl/cogl-texture-2d.c +++ b/cogl/cogl/cogl-texture-2d.c @@ -110,6 +110,26 @@ _cogl_texture_2d_create_base (CoglContext *ctx, return _cogl_texture_2d_object_new (tex_2d); } +CoglTexture2D * +cogl_texture_2d_new_with_format (CoglContext *ctx, + int width, + int height, + CoglPixelFormat format) +{ + CoglTextureLoader *loader; + + g_return_val_if_fail (width >= 1, NULL); + g_return_val_if_fail (height >= 1, NULL); + + loader = _cogl_texture_create_loader (); + loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZE; + loader->src.sized.width = width; + loader->src.sized.height = height; + loader->src.sized.format = format; + + return _cogl_texture_2d_create_base (ctx, width, height, format, loader); +} + CoglTexture2D * cogl_texture_2d_new_with_size (CoglContext *ctx, int width, @@ -121,9 +141,10 @@ cogl_texture_2d_new_with_size (CoglContext *ctx, g_return_val_if_fail (height >= 1, NULL); loader = _cogl_texture_create_loader (); - loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZED; + loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZE; loader->src.sized.width = width; loader->src.sized.height = height; + loader->src.sized.format = COGL_PIXEL_FORMAT_ANY; return _cogl_texture_2d_create_base (ctx, width, height, COGL_PIXEL_FORMAT_RGBA_8888_PRE, loader); diff --git a/cogl/cogl/cogl-texture-2d.h b/cogl/cogl/cogl-texture-2d.h index bf22c5d6b..3726f3dc3 100644 --- a/cogl/cogl/cogl-texture-2d.h +++ b/cogl/cogl/cogl-texture-2d.h @@ -87,6 +87,37 @@ GType cogl_texture_2d_get_gtype (void); COGL_EXPORT gboolean cogl_is_texture_2d (void *object); +/** + * cogl_texture_2d_new_with_format: (skip) + * @ctx: A #CoglContext + * @width: Width of the texture to allocate + * @height: Height of the texture to allocate + * @format: format of the texture to allocate + * + * Creates a low-level #CoglTexture2D texture with a given @width and + * @height that your GPU can texture from directly. + * + * The storage for the texture is not allocated before this function + * returns. You can call cogl_texture_allocate() to explicitly + * allocate the underlying storage or preferably let Cogl + * automatically allocate storage lazily when it may know more about + * how the texture is being used and can optimize how it is allocated. + * + * The texture is still configurable until it has been allocated so + * for example you can influence the internal format of the texture + * using cogl_texture_set_components() and + * cogl_texture_set_premultiplied(). + * + * Returns: (transfer full): A new #CoglTexture2D object with no storage yet allocated. + * + * Since: 2.0 + */ +COGL_EXPORT CoglTexture2D * +cogl_texture_2d_new_with_format (CoglContext *ctx, + int width, + int height, + CoglPixelFormat format); + /** * cogl_texture_2d_new_with_size: (skip) * @ctx: A #CoglContext diff --git a/cogl/cogl/cogl-texture-private.h b/cogl/cogl/cogl-texture-private.h index d20de6bce..dba7764cd 100644 --- a/cogl/cogl/cogl-texture-private.h +++ b/cogl/cogl/cogl-texture-private.h @@ -151,7 +151,7 @@ struct _CoglTextureVtable }; typedef enum _CoglTextureSoureType { - COGL_TEXTURE_SOURCE_TYPE_SIZED = 1, + COGL_TEXTURE_SOURCE_TYPE_SIZE = 1, COGL_TEXTURE_SOURCE_TYPE_BITMAP, COGL_TEXTURE_SOURCE_TYPE_EGL_IMAGE, COGL_TEXTURE_SOURCE_TYPE_EGL_IMAGE_EXTERNAL @@ -165,6 +165,7 @@ typedef struct _CoglTextureLoader int width; int height; int depth; /* for 3d textures */ + CoglPixelFormat format; } sized; struct { CoglBitmap *bitmap; diff --git a/cogl/cogl/cogl-texture.c b/cogl/cogl/cogl-texture.c index 880454f68..33dbacda0 100644 --- a/cogl/cogl/cogl-texture.c +++ b/cogl/cogl/cogl-texture.c @@ -147,7 +147,7 @@ _cogl_texture_free_loader (CoglTexture *texture) CoglTextureLoader *loader = texture->loader; switch (loader->src_type) { - case COGL_TEXTURE_SOURCE_TYPE_SIZED: + case COGL_TEXTURE_SOURCE_TYPE_SIZE: case COGL_TEXTURE_SOURCE_TYPE_EGL_IMAGE: case COGL_TEXTURE_SOURCE_TYPE_EGL_IMAGE_EXTERNAL: break; diff --git a/cogl/cogl/driver/gl/cogl-texture-2d-gl.c b/cogl/cogl/driver/gl/cogl-texture-2d-gl.c index 61ccd75cf..7a3a1a33a 100644 --- a/cogl/cogl/driver/gl/cogl-texture-2d-gl.c +++ b/cogl/cogl/driver/gl/cogl-texture-2d-gl.c @@ -137,7 +137,7 @@ allocate_with_size (CoglTexture2D *tex_2d, GLenum gl_texture; internal_format = - _cogl_texture_determine_internal_format (tex, COGL_PIXEL_FORMAT_ANY); + _cogl_texture_determine_internal_format (tex, loader->src.sized.format); if (!_cogl_texture_2d_gl_can_create (ctx, width, @@ -428,7 +428,7 @@ _cogl_texture_2d_gl_allocate (CoglTexture *tex, switch (loader->src_type) { - case COGL_TEXTURE_SOURCE_TYPE_SIZED: + case COGL_TEXTURE_SOURCE_TYPE_SIZE: return allocate_with_size (tex_2d, loader, error); case COGL_TEXTURE_SOURCE_TYPE_BITMAP: return allocate_from_bitmap (tex_2d, loader, error);