summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNaveen Kumar <naveen1.kumar@intel.com>2022-06-06 13:19:11 +0000
committerMarge Bot <marge-bot@gnome.org>2022-12-17 23:12:34 +0000
commit86b7b5bc0606e4973e949b0dea2b522cb51f944f (patch)
tree739dbd363957ee3f31a4e0388b9a4603960579cb
parentd8612720f6b14e971fddd244f68c6174b52222c0 (diff)
downloadmutter-86b7b5bc0606e4973e949b0dea2b522cb51f944f.tar.gz
cogl/texture: Add support for sized textures with explicit format
Add API that introduce a method to allocate 2d textures given a passed pixel format (e.g. xrgb210101010). Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2461>
-rw-r--r--cogl/cogl/cogl-atlas-texture.c11
-rw-r--r--cogl/cogl/cogl-texture-2d-sliced.c11
-rw-r--r--cogl/cogl/cogl-texture-2d.c23
-rw-r--r--cogl/cogl/cogl-texture-2d.h31
-rw-r--r--cogl/cogl/cogl-texture-private.h3
-rw-r--r--cogl/cogl/cogl-texture.c2
-rw-r--r--cogl/cogl/driver/gl/cogl-texture-2d-gl.c4
7 files changed, 74 insertions, 11 deletions
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
@@ -111,6 +111,26 @@ _cogl_texture_2d_create_base (CoglContext *ctx,
}
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,
int height)
@@ -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
@@ -88,6 +88,37 @@ 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
* @width: Width of the texture to allocate
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);