diff options
author | Damien Lespiau <damien.lespiau@intel.com> | 2010-01-25 11:21:05 +0000 |
---|---|---|
committer | Damien Lespiau <damien.lespiau@intel.com> | 2010-02-08 17:14:49 +0000 |
commit | dbef77cd8bfad02a5f2cf4b9c7343e42e584de6a (patch) | |
tree | 810428b680067497e088e62911bfbdd5fe1694ad | |
parent | 0adc2c458d5fadbff99d6341093043b5863219a1 (diff) | |
download | cogl-dbef77cd8bfad02a5f2cf4b9c7343e42e584de6a.tar.gz |
cogl: new textures sould have GL_TEXTURE_MIN_FILTER set to GL_LINEAR
The only way the user has to set the mipmap filters is through the
material/layer API. This API defaults to GL_LINEAR/GL_LINEAR for the max
and min filters. With the main use case of cogl being 2D interfaces, it
makes sense do default to GL_LINEAR for the min filter.
When creating new textures, we did not set any filter on them, using
OpenGL defaults': GL_NEAREST_MIPMAP_LINEAR for the min filter and
GL_LINEAR for the max filter. This will make the driver allocate memory
for the mipmap tree, memory that will not be used in the nominal case
(as the material API defaults to GL_LINEAR).
This patch tries to ensure that the min filter is set to GL_LINEAR
before any glTexImage*() call is done on the texture by setting the
filter when generating new OpenGL handles.
-rw-r--r-- | cogl/cogl-texture-2d-sliced.c | 9 | ||||
-rw-r--r-- | cogl/cogl-texture-2d.c | 9 | ||||
-rw-r--r-- | cogl/cogl-texture-driver.h | 9 | ||||
-rw-r--r-- | cogl/driver/gl/cogl-texture-driver.c | 27 | ||||
-rw-r--r-- | cogl/driver/gles/cogl-texture-driver.c | 27 |
5 files changed, 72 insertions, 9 deletions
diff --git a/cogl/cogl-texture-2d-sliced.c b/cogl/cogl-texture-2d-sliced.c index 0cfef1f5..b7a7bd7a 100644 --- a/cogl/cogl-texture-2d-sliced.c +++ b/cogl/cogl-texture-2d-sliced.c @@ -829,8 +829,7 @@ _cogl_texture_2d_sliced_slices_create (CoglTexture2DSliced *tex_2ds, * re-binding between textures inside a set) */ gl_handles = (GLuint*) tex_2ds->slice_gl_handles->data; - GE( glGenTextures (n_slices, gl_handles) ); - + _cogl_texture_driver_gen (GL_TEXTURE_2D, n_slices, gl_handles); /* Init each GL texture object */ for (y = 0; y < n_y_slices; ++y) @@ -917,9 +916,9 @@ _cogl_texture_2d_sliced_upload_from_data tex_2ds->slice_y_spans = NULL; tex_2ds->slice_gl_handles = NULL; - /* Unknown filter */ - tex_2ds->min_filter = GL_FALSE; - tex_2ds->mag_filter = GL_FALSE; + /* We default to GL_LINEAR for both filters */ + tex_2ds->min_filter = GL_LINEAR; + tex_2ds->mag_filter = GL_LINEAR; if (bmp->data) { diff --git a/cogl/cogl-texture-2d.c b/cogl/cogl-texture-2d.c index 8d32e310..b700eb19 100644 --- a/cogl/cogl-texture-2d.c +++ b/cogl/cogl-texture-2d.c @@ -225,9 +225,9 @@ _cogl_texture_2d_create_base (unsigned int width, tex_2d->mipmaps_dirty = TRUE; tex_2d->auto_mipmap = (flags & COGL_TEXTURE_NO_AUTO_MIPMAP) == 0; - /* Unknown filter */ - tex_2d->min_filter = GL_FALSE; - tex_2d->mag_filter = GL_FALSE; + /* We default to GL_LINEAR for both filters */ + tex_2d->min_filter = GL_LINEAR; + tex_2d->mag_filter = GL_LINEAR; /* Wrap mode not yet set */ tex_2d->wrap_mode = GL_FALSE; @@ -263,6 +263,7 @@ _cogl_texture_2d_new_with_size (unsigned int width, tex_2d = _cogl_texture_2d_create_base (width, height, flags, internal_format); GE( glGenTextures (1, &tex_2d->gl_texture) ); + GE( glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) ); GE( glBindTexture (GL_TEXTURE_2D, tex_2d->gl_texture) ); GE( glTexImage2D (GL_TEXTURE_2D, 0, gl_intformat, width, height, 0, gl_format, gl_type, NULL) ); @@ -300,7 +301,7 @@ _cogl_texture_2d_new_from_bitmap (CoglHandle bmp_handle, flags, internal_format); - GE( glGenTextures (1, &tex_2d->gl_texture) ); + _cogl_texture_driver_gen (GL_TEXTURE_2D, 1, &tex_2d->gl_texture); _cogl_texture_driver_upload_to_gl (GL_TEXTURE_2D, tex_2d->gl_texture, &dst_bmp, diff --git a/cogl/cogl-texture-driver.h b/cogl/cogl-texture-driver.h index 6961659d..5f08cfba 100644 --- a/cogl/cogl-texture-driver.h +++ b/cogl/cogl-texture-driver.h @@ -25,6 +25,15 @@ #define __COGL_TEXTURE_DRIVER_H /* + * A very small wrapper around glGenTextures() that ensures we default to + * non-mipmap filters when creating textures. This is to save some memory as + * the driver will not allocate room for the mipmap tree. + */ +void +_cogl_texture_driver_gen (GLenum gl_target, + GLsizei n, + GLuint *textures); +/* * Basically just a wrapper around glBindTexture, but the GLES2 backend * for example also wants to know about the internal format so it can * identify when alpha only textures are bound. diff --git a/cogl/driver/gl/cogl-texture-driver.c b/cogl/driver/gl/cogl-texture-driver.c index f1fe59a2..5d7c9f86 100644 --- a/cogl/driver/gl/cogl-texture-driver.c +++ b/cogl/driver/gl/cogl-texture-driver.c @@ -48,6 +48,33 @@ #define glGenerateMipmap ctx->drv.pf_glGenerateMipmap void +_cogl_texture_driver_gen (GLenum gl_target, + GLsizei n, + GLuint *textures) +{ + guint i; + + GE (glGenTextures (n, textures)); + + for (i = 0; i < n; i++) + { + GE (glBindTexture (gl_target, textures[i])); + + switch (gl_target) + { + case GL_TEXTURE_2D: + /* GL_TEXTURE_MAG_FILTER defaults to GL_LINEAR, no need to set it */ + GE( glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) ); + break; + + default: + g_assert_not_reached(); + } + + } +} + +void _cogl_texture_driver_bind (GLenum gl_target, GLuint gl_handle, GLenum gl_intformat) diff --git a/cogl/driver/gles/cogl-texture-driver.c b/cogl/driver/gles/cogl-texture-driver.c index 62324f58..41cc9a82 100644 --- a/cogl/driver/gles/cogl-texture-driver.c +++ b/cogl/driver/gles/cogl-texture-driver.c @@ -47,6 +47,33 @@ #include "cogl-gles2-wrapper.h" +void +_cogl_texture_driver_gen (GLenum gl_target, + GLsizei n, + GLuint *textures) +{ + guint i; + + GE (glGenTextures (n, textures)); + + for (i = 0; i < n; i++) + { + GE (glBindTexture (gl_target, textures[i])); + + switch (gl_target) + { + case GL_TEXTURE_2D: + /* GL_TEXTURE_MAG_FILTER defaults to GL_LINEAR, no need to set it */ + GE( glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) ); + break; + + default: + g_assert_not_reached(); + } + + } +} + void _cogl_texture_driver_bind (GLenum gl_target, |