diff --git a/cogl/cogl/cogl-context.c b/cogl/cogl/cogl-context.c index dc99f3508..c05123580 100644 --- a/cogl/cogl/cogl-context.c +++ b/cogl/cogl/cogl-context.c @@ -30,6 +30,7 @@ #include "cogl-config.h" +#include "cogl-mutter.h" #include "cogl-object.h" #include "cogl-private.h" #include "cogl-profile.h" @@ -464,3 +465,10 @@ cogl_context_is_hardware_accelerated (CoglContext *context) { return context->driver_vtable->is_hardware_accelerated (context); } + +gboolean +cogl_context_format_supports_upload (CoglContext *ctx, + CoglPixelFormat format) +{ + return ctx->texture_driver->format_supports_upload (ctx, format); +} diff --git a/cogl/cogl/cogl-mutter.h b/cogl/cogl/cogl-mutter.h index 2d48ce040..28b7ae043 100644 --- a/cogl/cogl/cogl-mutter.h +++ b/cogl/cogl/cogl-mutter.h @@ -48,4 +48,8 @@ void cogl_renderer_set_custom_winsys (CoglRenderer *renderer, CoglCustomWinsysVtableGetter winsys_vtable_getter, void *user_data); +COGL_EXPORT +gboolean cogl_context_format_supports_upload (CoglContext *ctx, + CoglPixelFormat format); + #endif /* __COGL_MUTTER_H___ */ diff --git a/cogl/cogl/cogl-texture-driver.h b/cogl/cogl/cogl-texture-driver.h index 240635f49..8fa0d86a1 100644 --- a/cogl/cogl/cogl-texture-driver.h +++ b/cogl/cogl/cogl-texture-driver.h @@ -128,6 +128,11 @@ struct _CoglTextureDriver int width, int height); + + gboolean + (* format_supports_upload) (CoglContext *ctx, + CoglPixelFormat format); + /* * The driver may impose constraints on what formats can be used to store * texture data read from textures. For example GLES currently only supports diff --git a/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c b/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c index 35c10c2d6..f254de711 100644 --- a/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c +++ b/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c @@ -396,6 +396,64 @@ _cogl_texture_driver_size_supported (CoglContext *ctx, return new_width != 0; } +static gboolean +_cogl_texture_driver_upload_supported (CoglContext *ctx, + CoglPixelFormat format) +{ + switch (format) + { + case COGL_PIXEL_FORMAT_A_8: + case COGL_PIXEL_FORMAT_G_8: + case COGL_PIXEL_FORMAT_RG_88: + case COGL_PIXEL_FORMAT_BGRA_8888: + case COGL_PIXEL_FORMAT_BGRA_8888_PRE: + case COGL_PIXEL_FORMAT_RGB_888: + case COGL_PIXEL_FORMAT_BGR_888: + case COGL_PIXEL_FORMAT_RGBA_1010102: + case COGL_PIXEL_FORMAT_RGBA_1010102_PRE: + case COGL_PIXEL_FORMAT_BGRA_1010102: + case COGL_PIXEL_FORMAT_BGRA_1010102_PRE: + case COGL_PIXEL_FORMAT_ABGR_2101010: + case COGL_PIXEL_FORMAT_ABGR_2101010_PRE: + case COGL_PIXEL_FORMAT_ARGB_2101010: + case COGL_PIXEL_FORMAT_ARGB_2101010_PRE: + case COGL_PIXEL_FORMAT_RGBA_8888: + case COGL_PIXEL_FORMAT_RGBA_8888_PRE: + case COGL_PIXEL_FORMAT_ARGB_8888: + case COGL_PIXEL_FORMAT_ARGB_8888_PRE: + case COGL_PIXEL_FORMAT_ABGR_8888: + case COGL_PIXEL_FORMAT_ABGR_8888_PRE: + case COGL_PIXEL_FORMAT_RGB_565: + case COGL_PIXEL_FORMAT_RGBA_4444: + case COGL_PIXEL_FORMAT_RGBA_4444_PRE: + case COGL_PIXEL_FORMAT_RGBA_5551: + case COGL_PIXEL_FORMAT_RGBA_5551_PRE: + return TRUE; + case COGL_PIXEL_FORMAT_BGRA_FP_16161616: + case COGL_PIXEL_FORMAT_ARGB_FP_16161616: + case COGL_PIXEL_FORMAT_ABGR_FP_16161616: + case COGL_PIXEL_FORMAT_BGRA_FP_16161616_PRE: + case COGL_PIXEL_FORMAT_ARGB_FP_16161616_PRE: + case COGL_PIXEL_FORMAT_ABGR_FP_16161616_PRE: + case COGL_PIXEL_FORMAT_RGBA_FP_16161616: + case COGL_PIXEL_FORMAT_RGBA_FP_16161616_PRE: + if (_cogl_has_private_feature + (ctx, COGL_PRIVATE_FEATURE_TEXTURE_FORMAT_HALF_FLOAT)) + return TRUE; + else + return FALSE; + case COGL_PIXEL_FORMAT_DEPTH_16: + case COGL_PIXEL_FORMAT_DEPTH_32: + case COGL_PIXEL_FORMAT_DEPTH_24_STENCIL_8: + case COGL_PIXEL_FORMAT_ANY: + case COGL_PIXEL_FORMAT_YUV: + return TRUE; + } + + g_assert_not_reached (); + return FALSE; +} + static CoglPixelFormat _cogl_texture_driver_find_best_gl_get_data_format (CoglContext *context, @@ -419,5 +477,6 @@ _cogl_texture_driver_gl = _cogl_texture_driver_prep_gl_for_pixels_download, _cogl_texture_driver_gl_get_tex_image, _cogl_texture_driver_size_supported, + _cogl_texture_driver_upload_supported, _cogl_texture_driver_find_best_gl_get_data_format }; diff --git a/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c b/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c index f3cf3831e..c9d652cf5 100644 --- a/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c +++ b/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c @@ -439,6 +439,75 @@ _cogl_texture_driver_size_supported (CoglContext *ctx, return width <= max_size && height <= max_size; } +static gboolean +_cogl_texture_driver_upload_supported (CoglContext *ctx, + CoglPixelFormat format) +{ + switch (format) + { + case COGL_PIXEL_FORMAT_A_8: + case COGL_PIXEL_FORMAT_G_8: + case COGL_PIXEL_FORMAT_RG_88: + case COGL_PIXEL_FORMAT_BGRA_8888: + case COGL_PIXEL_FORMAT_BGRA_8888_PRE: + case COGL_PIXEL_FORMAT_RGB_888: + case COGL_PIXEL_FORMAT_BGR_888: + return TRUE; + case COGL_PIXEL_FORMAT_RGBA_1010102: + case COGL_PIXEL_FORMAT_RGBA_1010102_PRE: + case COGL_PIXEL_FORMAT_BGRA_1010102: + case COGL_PIXEL_FORMAT_BGRA_1010102_PRE: + case COGL_PIXEL_FORMAT_ABGR_2101010: + case COGL_PIXEL_FORMAT_ABGR_2101010_PRE: + case COGL_PIXEL_FORMAT_ARGB_2101010: + case COGL_PIXEL_FORMAT_ARGB_2101010_PRE: +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + if (_cogl_has_private_feature + (ctx, COGL_PRIVATE_FEATURE_TEXTURE_FORMAT_RGBA1010102)) + return TRUE; + else + return FALSE; +#else + return FALSE; +#endif + case COGL_PIXEL_FORMAT_RGBA_8888: + case COGL_PIXEL_FORMAT_RGBA_8888_PRE: + case COGL_PIXEL_FORMAT_ARGB_8888: + case COGL_PIXEL_FORMAT_ARGB_8888_PRE: + case COGL_PIXEL_FORMAT_ABGR_8888: + case COGL_PIXEL_FORMAT_ABGR_8888_PRE: + case COGL_PIXEL_FORMAT_RGB_565: + case COGL_PIXEL_FORMAT_RGBA_4444: + case COGL_PIXEL_FORMAT_RGBA_4444_PRE: + case COGL_PIXEL_FORMAT_RGBA_5551: + case COGL_PIXEL_FORMAT_RGBA_5551_PRE: + return TRUE; + case COGL_PIXEL_FORMAT_BGRA_FP_16161616: + case COGL_PIXEL_FORMAT_ARGB_FP_16161616: + case COGL_PIXEL_FORMAT_ABGR_FP_16161616: + case COGL_PIXEL_FORMAT_BGRA_FP_16161616_PRE: + case COGL_PIXEL_FORMAT_ARGB_FP_16161616_PRE: + case COGL_PIXEL_FORMAT_ABGR_FP_16161616_PRE: + return FALSE; + case COGL_PIXEL_FORMAT_RGBA_FP_16161616: + case COGL_PIXEL_FORMAT_RGBA_FP_16161616_PRE: + if (_cogl_has_private_feature + (ctx, COGL_PRIVATE_FEATURE_TEXTURE_FORMAT_HALF_FLOAT)) + return TRUE; + else + return FALSE; + case COGL_PIXEL_FORMAT_DEPTH_16: + case COGL_PIXEL_FORMAT_DEPTH_32: + case COGL_PIXEL_FORMAT_DEPTH_24_STENCIL_8: + case COGL_PIXEL_FORMAT_ANY: + case COGL_PIXEL_FORMAT_YUV: + return TRUE; + } + + g_assert_not_reached (); + return FALSE; +} + static CoglPixelFormat _cogl_texture_driver_find_best_gl_get_data_format (CoglContext *context, @@ -463,5 +532,6 @@ _cogl_texture_driver_gles = _cogl_texture_driver_prep_gl_for_pixels_download, _cogl_texture_driver_gl_get_tex_image, _cogl_texture_driver_size_supported, + _cogl_texture_driver_upload_supported, _cogl_texture_driver_find_best_gl_get_data_format };