From e8eb9793e66cd78162626f65e02922b63a0f9b26 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Thu, 8 Nov 2012 23:00:49 +0000 Subject: [PATCH] moves some gl texture code too cogl-texture-gl.c 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. Reviewed-by: Neil Roberts (cherry picked from commit 2c9e81de70cc02d72b1ce9013c49e39300a05b6a) --- cogl/Makefile.am | 2 + cogl/cogl-atlas-texture.c | 1 + cogl/cogl-sub-texture.c | 1 + cogl/cogl-texture-2d-sliced.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 +- .../driver/gl/gles/cogl-texture-driver-gles.c | 6 +- cogl/winsys/cogl-texture-pixmap-x11.c | 1 + 14 files changed, 160 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 223249934..ee39f766f 100644 --- a/cogl/Makefile.am +++ b/cogl/Makefile.am @@ -163,6 +163,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 99ca74653..20cb6e20e 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 diff --git a/cogl/cogl-sub-texture.c b/cogl/cogl-sub-texture.c index ccb8b2d60..1f56f483f 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 #include diff --git a/cogl/cogl-texture-2d-sliced.c b/cogl/cogl-texture-2d-sliced.c index e79f07bcc..0bd29cb88 100644 --- a/cogl/cogl-texture-2d-sliced.c +++ b/cogl/cogl-texture-2d-sliced.c @@ -39,6 +39,7 @@ #include "cogl-texture-2d-gl.h" #include "cogl-texture-2d-private.h" #include "cogl-texture-2d-sliced-private.h" +#include "cogl-texture-gl-private.h" #include "cogl-texture-driver.h" #include "cogl-context-private.h" #include "cogl-object-private.h" diff --git a/cogl/cogl-texture-private.h b/cogl/cogl-texture-private.h index c862ecd1f..05c16d4f8 100644 --- a/cogl/cogl-texture-private.h +++ b/cogl/cogl-texture-private.h @@ -209,17 +209,6 @@ _cogl_texture_transform_quad_coords_to_gl (CoglTexture *texture, 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); @@ -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 385f7c228..14eb5f89f 100644 --- a/cogl/cogl-texture.c +++ b/cogl/cogl-texture.c @@ -269,49 +269,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) { @@ -1376,24 +1333,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 5db670257..54ea71600 100644 --- a/cogl/cogl.symbols +++ b/cogl/cogl.symbols @@ -920,7 +920,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 43874f69f..23cf1a74f 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 diff --git a/cogl/driver/gl/cogl-pipeline-opengl.c b/cogl/driver/gl/cogl-pipeline-opengl.c index 4108d4d4d..b354944a4 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 000000000..b44861c99 --- /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 . + * + */ + +#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 000000000..a9f0d32bc --- /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 . + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#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 76900cafe..c3ea683a2 100644 --- a/cogl/driver/gl/gl/cogl-texture-driver-gl.c +++ b/cogl/driver/gl/gl/cogl-texture-driver-gl.c @@ -42,6 +42,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 #include @@ -117,7 +118,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 @@ -147,7 +148,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 576de99b9..1490e2c1a 100644 --- a/cogl/driver/gl/gles/cogl-texture-driver-gles.c +++ b/cogl/driver/gl/gles/cogl-texture-driver-gles.c @@ -42,6 +42,7 @@ #include "cogl-primitives.h" #include "cogl-util-gl-private.h" #include "cogl-error-private.h" +#include "cogl-texture-gl-private.h" #include #include @@ -115,7 +116,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 @@ -135,7 +136,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 d2d8f4cfd..cf5de196a 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 #include