[Cogl] [PATCH] moves some gl texture code too cogl-texture-gl.c

Robert Bragg robert at sixbynine.org
Mon Nov 19 08:52:25 PST 2012


From: Robert Bragg <robert at linux.intel.com>

This adds a driver/gl/cogl-texture-gl.c file and moves some gl specific
bits from cogl-texture.c into it. The moved symbols were also given a
_gl_ infix and the calling code was updated accordingly.
---
 cogl/Makefile.am                               |    2 +
 cogl/cogl-atlas-texture.c                      |    1 +
 cogl/cogl-sub-texture.c                        |    1 +
 cogl/cogl-texture-private.h                    |   19 -----
 cogl/cogl-texture.c                            |   64 ----------------
 cogl/cogl.symbols                              |    2 +-
 cogl/driver/gl/cogl-framebuffer-gl.c           |    1 +
 cogl/driver/gl/cogl-pipeline-opengl.c          |    1 +
 cogl/driver/gl/cogl-texture-gl-private.h       |   49 ++++++++++++
 cogl/driver/gl/cogl-texture-gl.c               |   94 ++++++++++++++++++++++++
 cogl/driver/gl/gl/cogl-texture-driver-gl.c     |    6 +-
 cogl/driver/gl/gles/cogl-texture-driver-gles.c |    6 +-
 cogl/winsys/cogl-texture-pixmap-x11.c          |    1 +
 13 files changed, 159 insertions(+), 88 deletions(-)
 create mode 100644 cogl/driver/gl/cogl-texture-gl-private.h
 create mode 100644 cogl/driver/gl/cogl-texture-gl.c

diff --git a/cogl/Makefile.am b/cogl/Makefile.am
index 937a64b..a026e91 100644
--- a/cogl/Makefile.am
+++ b/cogl/Makefile.am
@@ -144,6 +144,8 @@ cogl_driver_sources += \
 	$(srcdir)/driver/gl/cogl-util-gl.c \
 	$(srcdir)/driver/gl/cogl-framebuffer-gl-private.h \
 	$(srcdir)/driver/gl/cogl-framebuffer-gl.c \
+	$(srcdir)/driver/gl/cogl-texture-gl-private.h \
+	$(srcdir)/driver/gl/cogl-texture-gl.c \
 	$(srcdir)/driver/gl/cogl-texture-2d-gl-private.h \
 	$(srcdir)/driver/gl/cogl-texture-2d-gl.c \
 	$(srcdir)/driver/gl/cogl-attribute-gl-private.h \
diff --git a/cogl/cogl-atlas-texture.c b/cogl/cogl-atlas-texture.c
index 1ea2260..77e52f9 100644
--- a/cogl/cogl-atlas-texture.c
+++ b/cogl/cogl-atlas-texture.c
@@ -45,6 +45,7 @@
 #include "cogl1-context.h"
 #include "cogl-sub-texture.h"
 #include "cogl-error-private.h"
+#include "cogl-texture-gl-private.h"
 
 #include <stdlib.h>
 
diff --git a/cogl/cogl-sub-texture.c b/cogl/cogl-sub-texture.c
index eb8f097..fb2cf8e 100644
--- a/cogl/cogl-sub-texture.c
+++ b/cogl/cogl-sub-texture.c
@@ -38,6 +38,7 @@
 #include "cogl-texture-driver.h"
 #include "cogl-texture-rectangle-private.h"
 #include "cogl-texture-2d.h"
+#include "cogl-texture-gl-private.h"
 
 #include <string.h>
 #include <math.h>
diff --git a/cogl/cogl-texture-private.h b/cogl/cogl-texture-private.h
index e907242..1619277 100644
--- a/cogl/cogl-texture-private.h
+++ b/cogl/cogl-texture-private.h
@@ -210,17 +210,6 @@ GLenum
 _cogl_texture_get_gl_format (CoglTexture *texture);
 
 void
-_cogl_texture_gl_flush_legacy_texobj_wrap_modes (CoglTexture *texture,
-                                                 GLenum wrap_mode_s,
-                                                 GLenum wrap_mode_t,
-                                                 GLenum wrap_mode_p);
-
-void
-_cogl_texture_gl_flush_legacy_texobj_filters (CoglTexture *texture,
-                                              GLenum min_filter,
-                                              GLenum mag_filter);
-
-void
 _cogl_texture_pre_paint (CoglTexture *texture, CoglTexturePrePaintFlags flags);
 
 void
@@ -248,14 +237,6 @@ _cogl_texture_prepare_for_upload (CoglBitmap *src_bmp,
                                   GLenum *out_gltype,
                                   CoglError **error);
 
-void
-_cogl_texture_prep_gl_alignment_for_pixels_upload (int pixels_rowstride);
-
-void
-_cogl_texture_prep_gl_alignment_for_pixels_download (int bpp,
-                                                     int width,
-                                                     int rowstride);
-
 CoglBool
 _cogl_texture_is_foreign (CoglTexture *texture);
 
diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c
index e771a4e..cf69304 100644
--- a/cogl/cogl-texture.c
+++ b/cogl/cogl-texture.c
@@ -231,49 +231,6 @@ _cogl_texture_prepare_for_upload (CoglBitmap *src_bmp,
   return dst_bmp;
 }
 
-static inline int
-calculate_alignment (int rowstride)
-{
-  int alignment = 1 << (_cogl_util_ffs (rowstride) - 1);
-
-  return MIN (alignment, 8);
-}
-
-void
-_cogl_texture_prep_gl_alignment_for_pixels_upload (int pixels_rowstride)
-{
-  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
-
-  GE( ctx, glPixelStorei (GL_UNPACK_ALIGNMENT,
-                          calculate_alignment (pixels_rowstride)) );
-}
-
-void
-_cogl_texture_prep_gl_alignment_for_pixels_download (int bpp,
-                                                     int width,
-                                                     int rowstride)
-{
-  int alignment;
-
-  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
-
-  /* If no padding is needed then we can always use an alignment of 1.
-   * We want to do this even though it is equivalent to the alignment
-   * of the rowstride because the Intel driver in Mesa currently has
-   * an optimisation when reading data into a PBO that only works if
-   * the alignment is exactly 1.
-   *
-   * https://bugs.freedesktop.org/show_bug.cgi?id=46632
-   */
-
-  if (rowstride == bpp * width)
-    alignment = 1;
-  else
-    alignment = calculate_alignment (rowstride);
-
-  GE( ctx, glPixelStorei (GL_PACK_ALIGNMENT, alignment) );
-}
-
 CoglBool
 _cogl_texture_is_foreign (CoglTexture *texture)
 {
@@ -1211,24 +1168,3 @@ _cogl_texture_spans_foreach_in_region (CoglSpan *x_spans,
 	}
     }
 }
-
-void
-_cogl_texture_gl_flush_legacy_texobj_wrap_modes (CoglTexture *texture,
-                                                 GLenum wrap_mode_s,
-                                                 GLenum wrap_mode_t,
-                                                 GLenum wrap_mode_p)
-{
-  texture->vtable->gl_flush_legacy_texobj_wrap_modes (texture,
-                                                      wrap_mode_s,
-                                                      wrap_mode_t,
-                                                      wrap_mode_p);
-}
-
-void
-_cogl_texture_gl_flush_legacy_texobj_filters (CoglTexture *texture,
-                                              GLenum min_filter,
-                                              GLenum mag_filter)
-{
-  texture->vtable->gl_flush_legacy_texobj_filters (texture,
-                                                   min_filter, mag_filter);
-}
diff --git a/cogl/cogl.symbols b/cogl/cogl.symbols
index 9c773dc..99d8a05 100644
--- a/cogl/cogl.symbols
+++ b/cogl/cogl.symbols
@@ -673,7 +673,7 @@ _cogl_texture_get_gl_format
 _cogl_texture_init
 _cogl_texture_is_foreign
 _cogl_texture_prepare_for_upload
-_cogl_texture_prep_gl_alignment_for_pixels_upload
+_cogl_texture_gl_prep_alignment_for_pixels_upload
 _cogl_texture_pre_paint
 _cogl_texture_register_texture_type
 _cogl_texture_gl_flush_legacy_texobj_filters
diff --git a/cogl/driver/gl/cogl-framebuffer-gl.c b/cogl/driver/gl/cogl-framebuffer-gl.c
index 43874f6..23cf1a7 100644
--- a/cogl/driver/gl/cogl-framebuffer-gl.c
+++ b/cogl/driver/gl/cogl-framebuffer-gl.c
@@ -31,6 +31,7 @@
 #include "cogl-framebuffer-gl-private.h"
 #include "cogl-buffer-gl-private.h"
 #include "cogl-error-private.h"
+#include "cogl-texture-gl-private.h"
 
 #include <glib.h>
 
diff --git a/cogl/driver/gl/cogl-pipeline-opengl.c b/cogl/driver/gl/cogl-pipeline-opengl.c
index a65caf9..1ece0a7 100644
--- a/cogl/driver/gl/cogl-pipeline-opengl.c
+++ b/cogl/driver/gl/cogl-pipeline-opengl.c
@@ -36,6 +36,7 @@
 #include "cogl-texture-private.h"
 #include "cogl-framebuffer-private.h"
 #include "cogl-offscreen.h"
+#include "cogl-texture-gl-private.h"
 
 #include "cogl-pipeline-progend-glsl-private.h"
 
diff --git a/cogl/driver/gl/cogl-texture-gl-private.h b/cogl/driver/gl/cogl-texture-gl-private.h
new file mode 100644
index 0000000..b44861c
--- /dev/null
+++ b/cogl/driver/gl/cogl-texture-gl-private.h
@@ -0,0 +1,49 @@
+/*
+ * Cogl
+ *
+ * An object oriented GL/GLES Abstraction/Utility Layer
+ *
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef _COGL_TEXTURE_GL_PRIVATE_H_
+#define _COGL_TEXTURE_GL_PRIVATE_H_
+
+#include "cogl-context.h"
+
+void
+_cogl_texture_gl_prep_alignment_for_pixels_upload (CoglContext *ctx,
+                                                   int pixels_rowstride);
+
+void
+_cogl_texture_gl_prep_alignment_for_pixels_download (CoglContext *ctx,
+                                                     int bpp,
+                                                     int width,
+                                                     int rowstride);
+
+void
+_cogl_texture_gl_flush_legacy_texobj_wrap_modes (CoglTexture *texture,
+                                                 unsigned int wrap_mode_s,
+                                                 unsigned int wrap_mode_t,
+                                                 unsigned int wrap_mode_p);
+
+void
+_cogl_texture_gl_flush_legacy_texobj_filters (CoglTexture *texture,
+                                              unsigned int min_filter,
+                                              unsigned int mag_filter);
+
+#endif /* _COGL_TEXTURE_GL_PRIVATE_H_ */
diff --git a/cogl/driver/gl/cogl-texture-gl.c b/cogl/driver/gl/cogl-texture-gl.c
new file mode 100644
index 0000000..a9f0d32
--- /dev/null
+++ b/cogl/driver/gl/cogl-texture-gl.c
@@ -0,0 +1,94 @@
+/*
+ * Cogl
+ *
+ * An object oriented GL/GLES Abstraction/Utility Layer
+ *
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <strings.h>
+
+#include "cogl-internal.h"
+#include "cogl-context-private.h"
+#include "cogl-texture-gl-private.h"
+#include "cogl-util.h"
+
+static inline int
+calculate_alignment (int rowstride)
+{
+  int alignment = 1 << (_cogl_util_ffs (rowstride) - 1);
+
+  return MIN (alignment, 8);
+}
+
+void
+_cogl_texture_gl_prep_alignment_for_pixels_upload (CoglContext *ctx,
+                                                   int pixels_rowstride)
+{
+  GE( ctx, glPixelStorei (GL_UNPACK_ALIGNMENT,
+                          calculate_alignment (pixels_rowstride)) );
+}
+
+void
+_cogl_texture_gl_prep_alignment_for_pixels_download (CoglContext *ctx,
+                                                     int bpp,
+                                                     int width,
+                                                     int rowstride)
+{
+  int alignment;
+
+  /* If no padding is needed then we can always use an alignment of 1.
+   * We want to do this even though it is equivalent to the alignment
+   * of the rowstride because the Intel driver in Mesa currently has
+   * an optimisation when reading data into a PBO that only works if
+   * the alignment is exactly 1.
+   *
+   * https://bugs.freedesktop.org/show_bug.cgi?id=46632
+   */
+
+  if (rowstride == bpp * width)
+    alignment = 1;
+  else
+    alignment = calculate_alignment (rowstride);
+
+  GE( ctx, glPixelStorei (GL_PACK_ALIGNMENT, alignment) );
+}
+
+void
+_cogl_texture_gl_flush_legacy_texobj_wrap_modes (CoglTexture *texture,
+                                                 unsigned int wrap_mode_s,
+                                                 unsigned int wrap_mode_t,
+                                                 unsigned int wrap_mode_p)
+{
+  texture->vtable->gl_flush_legacy_texobj_wrap_modes (texture,
+                                                      wrap_mode_s,
+                                                      wrap_mode_t,
+                                                      wrap_mode_p);
+}
+
+void
+_cogl_texture_gl_flush_legacy_texobj_filters (CoglTexture *texture,
+                                              unsigned int min_filter,
+                                              unsigned int mag_filter)
+{
+  texture->vtable->gl_flush_legacy_texobj_filters (texture,
+                                                   min_filter, mag_filter);
+}
diff --git a/cogl/driver/gl/gl/cogl-texture-driver-gl.c b/cogl/driver/gl/gl/cogl-texture-driver-gl.c
index b6b4d3f..6855915 100644
--- a/cogl/driver/gl/gl/cogl-texture-driver-gl.c
+++ b/cogl/driver/gl/gl/cogl-texture-driver-gl.c
@@ -41,6 +41,7 @@
 #include "cogl-pipeline-opengl-private.h"
 #include "cogl-util-gl-private.h"
 #include "cogl-error-private.h"
+#include "cogl-texture-gl-private.h"
 
 #include <string.h>
 #include <stdlib.h>
@@ -102,7 +103,7 @@ prep_gl_for_pixels_upload_full (CoglContext *ctx,
   if (cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_3D))
     GE( ctx, glPixelStorei (GL_UNPACK_IMAGE_HEIGHT, image_height) );
 
-  _cogl_texture_prep_gl_alignment_for_pixels_upload (pixels_rowstride);
+  _cogl_texture_gl_prep_alignment_for_pixels_upload (ctx, pixels_rowstride);
 }
 
 static void
@@ -132,7 +133,8 @@ prep_gl_for_pixels_download_full (CoglContext *ctx,
   if (cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_3D))
     GE( ctx, glPixelStorei (GL_PACK_IMAGE_HEIGHT, image_height) );
 
-  _cogl_texture_prep_gl_alignment_for_pixels_download (pixels_bpp,
+  _cogl_texture_gl_prep_alignment_for_pixels_download (ctx,
+                                                       pixels_bpp,
                                                        image_width,
                                                        pixels_rowstride);
 }
diff --git a/cogl/driver/gl/gles/cogl-texture-driver-gles.c b/cogl/driver/gl/gles/cogl-texture-driver-gles.c
index d8363d6..4ea9ef0 100644
--- a/cogl/driver/gl/gles/cogl-texture-driver-gles.c
+++ b/cogl/driver/gl/gles/cogl-texture-driver-gles.c
@@ -41,6 +41,7 @@
 #include "cogl-object-private.h"
 #include "cogl-util-gl-private.h"
 #include "cogl-error-private.h"
+#include "cogl-texture-gl-private.h"
 
 #include <string.h>
 #include <stdlib.h>
@@ -116,7 +117,7 @@ prep_gl_for_pixels_upload_full (CoglContext *ctx,
       g_assert (pixels_src_y == 0);
     }
 
-  _cogl_texture_prep_gl_alignment_for_pixels_upload (pixels_rowstride);
+  _cogl_texture_gl_prep_alignment_for_pixels_upload (ctx, pixels_rowstride);
 }
 
 static void
@@ -136,7 +137,8 @@ _cogl_texture_driver_prep_gl_for_pixels_download (CoglContext *ctx,
                                                   int image_width,
                                                   int pixels_bpp)
 {
-  _cogl_texture_prep_gl_alignment_for_pixels_download (pixels_bpp,
+  _cogl_texture_gl_prep_alignment_for_pixels_download (ctx,
+                                                       pixels_bpp,
                                                        image_width,
                                                        pixels_rowstride);
 }
diff --git a/cogl/winsys/cogl-texture-pixmap-x11.c b/cogl/winsys/cogl-texture-pixmap-x11.c
index 31492f9..4f64237 100644
--- a/cogl/winsys/cogl-texture-pixmap-x11.c
+++ b/cogl/winsys/cogl-texture-pixmap-x11.c
@@ -48,6 +48,7 @@
 #include "cogl-pipeline-opengl-private.h"
 #include "cogl-xlib.h"
 #include "cogl-error-private.h"
+#include "cogl-texture-gl-private.h"
 
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
-- 
1.7.7.6



More information about the Cogl mailing list