mirror of
https://github.com/brl/mutter.git
synced 2024-11-13 01:36:10 -05:00
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.
This commit is contained in:
parent
c0f65212ba
commit
de8a6314f1
@ -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)
|
||||
{
|
||||
|
@ -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,
|
||||
|
@ -24,6 +24,15 @@
|
||||
#ifndef __COGL_TEXTURE_DRIVER_H
|
||||
#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
|
||||
|
@ -47,6 +47,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,
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user