[Cogl] [PATCH 1/3] Use the internal format to check if the texture size is supported

Damien Lespiau damien.lespiau at gmail.com
Wed May 23 10:23:45 PDT 2012


From: Damien Lespiau <damien.lespiau at intel.com>

Until now, we hardcoded the internal format to GL_RGBA and used the
internal format returned by pixel_format_to_gl() as the format for
checking the texture size and format we're asked to create.

Let's use the proper internal format/format from now on.

This is needed as a later patch introduces DEPTH and DEPTH_STENCIL
textures.
---
 cogl/cogl-atlas.c                           |    8 ++++++--
 cogl/cogl-texture-2d-sliced.c               |    5 ++++-
 cogl/cogl-texture-2d.c                      |    4 +++-
 cogl/cogl-texture-driver.h                  |    1 +
 cogl/cogl-texture-rectangle.c               |    4 +++-
 cogl/driver/gl/cogl-texture-driver-gl.c     |    3 ++-
 cogl/driver/gles/cogl-texture-driver-gles.c |    1 +
 7 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/cogl/cogl-atlas.c b/cogl/cogl-atlas.c
index bfa76dc..a546489 100644
--- a/cogl/cogl-atlas.c
+++ b/cogl/cogl-atlas.c
@@ -173,13 +173,14 @@ _cogl_atlas_get_initial_size (CoglPixelFormat format,
 {
   unsigned int size;
   GLenum gl_intformat;
+  GLenum gl_format;
   GLenum gl_type;
 
   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
 
   ctx->texture_driver->pixel_format_to_gl (format,
                                            &gl_intformat,
-                                           NULL, /* gl_format */
+                                           &gl_format,
                                            &gl_type);
 
   /* At least on Intel hardware, the texture size will be rounded up
@@ -197,6 +198,7 @@ _cogl_atlas_get_initial_size (CoglPixelFormat format,
   while (size > 1 &&
          !ctx->texture_driver->size_supported (GL_TEXTURE_2D,
                                                gl_intformat,
+                                               gl_format,
                                                gl_type,
                                                size, size))
     size >>= 1;
@@ -213,19 +215,21 @@ _cogl_atlas_create_map (CoglPixelFormat          format,
                         CoglAtlasRepositionData *textures)
 {
   GLenum gl_intformat;
+  GLenum gl_format;
   GLenum gl_type;
 
   _COGL_GET_CONTEXT (ctx, NULL);
 
   ctx->texture_driver->pixel_format_to_gl (format,
                                            &gl_intformat,
-                                           NULL, /* gl_format */
+                                           &gl_format,
                                            &gl_type);
 
   /* Keep trying increasingly larger atlases until we can fit all of
      the textures */
   while (ctx->texture_driver->size_supported (GL_TEXTURE_2D,
                                               gl_intformat,
+                                              gl_format,
                                               gl_type,
                                               map_width, map_height))
     {
diff --git a/cogl/cogl-texture-2d-sliced.c b/cogl/cogl-texture-2d-sliced.c
index 836caaf..542e0fa 100644
--- a/cogl/cogl-texture-2d-sliced.c
+++ b/cogl/cogl-texture-2d-sliced.c
@@ -621,6 +621,7 @@ _cogl_texture_2d_sliced_slices_create (CoglContext *ctx,
   CoglSpan *x_span;
   CoglSpan *y_span;
   GLenum gl_intformat;
+  GLenum gl_format;
   GLenum gl_type;
 
   int   (*slices_for_size) (int, int, int, GArray*);
@@ -641,7 +642,7 @@ _cogl_texture_2d_sliced_slices_create (CoglContext *ctx,
 
   ctx->texture_driver->pixel_format_to_gl (format,
                                            &gl_intformat,
-                                           NULL,
+                                           &gl_format,
                                            &gl_type);
 
   /* Negative number means no slicing forced by the user */
@@ -652,6 +653,7 @@ _cogl_texture_2d_sliced_slices_create (CoglContext *ctx,
       /* Check if size supported else bail out */
       if (!ctx->texture_driver->size_supported (GL_TEXTURE_2D,
                                                 gl_intformat,
+                                                gl_format,
                                                 gl_type,
                                                 max_width,
                                                 max_height))
@@ -686,6 +688,7 @@ _cogl_texture_2d_sliced_slices_create (CoglContext *ctx,
       /* Decrease the size of largest slice until supported by GL */
       while (!ctx->texture_driver->size_supported (GL_TEXTURE_2D,
                                                    gl_intformat,
+                                                   gl_format,
                                                    gl_type,
                                                    max_width,
                                                    max_height))
diff --git a/cogl/cogl-texture-2d.c b/cogl/cogl-texture-2d.c
index dad1eac..cc7217c 100644
--- a/cogl/cogl-texture-2d.c
+++ b/cogl/cogl-texture-2d.c
@@ -109,6 +109,7 @@ _cogl_texture_2d_can_create (unsigned int width,
                              CoglPixelFormat internal_format)
 {
   GLenum gl_intformat;
+  GLenum gl_format;
   GLenum gl_type;
 
   _COGL_GET_CONTEXT (ctx, FALSE);
@@ -122,12 +123,13 @@ _cogl_texture_2d_can_create (unsigned int width,
 
   ctx->texture_driver->pixel_format_to_gl (internal_format,
                                            &gl_intformat,
-                                           NULL,
+                                           &gl_format,
                                            &gl_type);
 
   /* Check that the driver can create a texture with that size */
   if (!ctx->texture_driver->size_supported (GL_TEXTURE_2D,
                                             gl_intformat,
+                                            gl_format,
                                             gl_type,
                                             width,
                                             height))
diff --git a/cogl/cogl-texture-driver.h b/cogl/cogl-texture-driver.h
index 6cbc3af..b5287bb 100644
--- a/cogl/cogl-texture-driver.h
+++ b/cogl/cogl-texture-driver.h
@@ -138,6 +138,7 @@ struct _CoglTextureDriver
    */
   gboolean
   (* size_supported) (GLenum gl_target,
+                      GLenum gl_intformat,
                       GLenum gl_format,
                       GLenum gl_type,
                       int    width,
diff --git a/cogl/cogl-texture-rectangle.c b/cogl/cogl-texture-rectangle.c
index b906f58..e48e1b1 100644
--- a/cogl/cogl-texture-rectangle.c
+++ b/cogl/cogl-texture-rectangle.c
@@ -115,6 +115,7 @@ _cogl_texture_rectangle_can_create (unsigned int width,
                                     GError **error)
 {
   GLenum gl_intformat;
+  GLenum gl_format;
   GLenum gl_type;
 
   _COGL_GET_CONTEXT (ctx, FALSE);
@@ -130,12 +131,13 @@ _cogl_texture_rectangle_can_create (unsigned int width,
 
   ctx->texture_driver->pixel_format_to_gl (internal_format,
                                            &gl_intformat,
-                                           NULL,
+                                           &gl_format,
                                            &gl_type);
 
   /* Check that the driver can create a texture with that size */
   if (!ctx->texture_driver->size_supported (GL_TEXTURE_RECTANGLE_ARB,
                                             gl_intformat,
+                                            gl_format,
                                             gl_type,
                                             width,
                                             height))
diff --git a/cogl/driver/gl/cogl-texture-driver-gl.c b/cogl/driver/gl/cogl-texture-driver-gl.c
index 83d47ae..3d46ccb 100644
--- a/cogl/driver/gl/cogl-texture-driver-gl.c
+++ b/cogl/driver/gl/cogl-texture-driver-gl.c
@@ -307,6 +307,7 @@ _cogl_texture_driver_size_supported_3d (GLenum gl_target,
 
 static gboolean
 _cogl_texture_driver_size_supported (GLenum gl_target,
+                                     GLenum gl_intformat,
                                      GLenum gl_format,
                                      GLenum gl_type,
                                      int    width,
@@ -328,7 +329,7 @@ _cogl_texture_driver_size_supported (GLenum gl_target,
     return FALSE;
 
   /* Proxy texture allows for a quick check for supported size */
-  GE( ctx, glTexImage2D (proxy_target, 0, GL_RGBA,
+  GE( ctx, glTexImage2D (proxy_target, 0, gl_intformat,
                          width, height, 0 /* border */,
                          gl_format, gl_type, NULL) );
 
diff --git a/cogl/driver/gles/cogl-texture-driver-gles.c b/cogl/driver/gles/cogl-texture-driver-gles.c
index 2bc596b..21cfb61 100644
--- a/cogl/driver/gles/cogl-texture-driver-gles.c
+++ b/cogl/driver/gles/cogl-texture-driver-gles.c
@@ -365,6 +365,7 @@ _cogl_texture_driver_size_supported_3d (GLenum gl_target,
 
 static gboolean
 _cogl_texture_driver_size_supported (GLenum gl_target,
+                                     GLenum gl_intformat,
                                      GLenum gl_format,
                                      GLenum gl_type,
                                      int    width,
-- 
1.7.7.5



More information about the Cogl mailing list