mirror of
https://github.com/brl/mutter.git
synced 2024-11-25 09:30:45 -05:00
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>
This commit is contained in:
parent
d8612720f6
commit
86b7b5bc06
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user