1
0
Fork 0

Add a CoglPrimitiveTexture interface

This interface represents any textures that are backed by a single
texture in GL and that can be used directly with the
cogl_framebuffer_draw_attributes family of functions. This currently
equates to CoglTexture2D, CoglTexture3D and CoglTextureRectangle.

The interface currently has only one method called
cogl_primitive_set_auto_mipmap. This replaces the
COGL_TEXTURE_NO_AUTO_MIPMAP flag from the CoglTextureFlags parameter
in the constructors. None of the other flags in CoglTextureFlags make
sense for primitive textures so it doesn't seem like a good idea to
need them for primitive constructors.

There is a boolean in the vtable to mark whether a texture type is
primitive which the new cogl_is_primitive function uses. There is also
a new texture virtual called set_auto_mipmap which is only required to
be implemented for primitive textures.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
This commit is contained in:
Neil Roberts 2012-04-04 15:09:43 +01:00
parent e7df2dbf79
commit e7f1582630
14 changed files with 231 additions and 16 deletions

View file

@ -108,6 +108,7 @@ cogl_experimental_h = \
$(srcdir)/cogl-texture-2d-sliced.h \
$(srcdir)/cogl-sub-texture.h \
$(srcdir)/cogl-meta-texture.h \
$(srcdir)/cogl-primitive-texture.h \
$(srcdir)/cogl-depth-state.h \
$(srcdir)/cogl-buffer.h \
$(srcdir)/cogl-pixel-buffer.h \
@ -310,6 +311,7 @@ cogl_sources_c = \
$(srcdir)/cogl-atlas-texture-private.h \
$(srcdir)/cogl-atlas-texture.c \
$(srcdir)/cogl-meta-texture.c \
$(srcdir)/cogl-primitive-texture.c \
$(srcdir)/cogl-blit.h \
$(srcdir)/cogl-blit.c \
$(srcdir)/cogl-spans.h \

View file

@ -817,6 +817,7 @@ _cogl_atlas_texture_get_type (CoglTexture *tex)
static const CoglTextureVtable
cogl_atlas_texture_vtable =
{
FALSE, /* not primitive */
_cogl_atlas_texture_set_region,
NULL, /* get_data */
_cogl_atlas_texture_foreach_sub_texture_in_region,
@ -835,5 +836,6 @@ cogl_atlas_texture_vtable =
_cogl_atlas_texture_get_width,
_cogl_atlas_texture_get_height,
_cogl_atlas_texture_get_type,
NULL /* is_foreign */
NULL, /* is_foreign */
NULL /* set_auto_mipmap */
};

View file

@ -0,0 +1,54 @@
/*
* 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/>.
*
*
* Authors:
* Neil Roberts <neil@linux.intel.com>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "cogl-primitive-texture.h"
#include "cogl-texture-private.h"
gboolean
cogl_is_primitive_texture (void *object)
{
return (cogl_is_texture (object) &&
COGL_TEXTURE (object)->vtable->is_primitive);
}
void
cogl_primitive_texture_set_auto_mipmap (CoglPrimitiveTexture *primitive_texture,
gboolean value)
{
CoglTexture *texture;
_COGL_RETURN_IF_FAIL (cogl_is_primitive_texture (primitive_texture));
texture = COGL_TEXTURE (primitive_texture);
g_assert (texture->vtable->set_auto_mipmap != NULL);
texture->vtable->set_auto_mipmap (texture, value);
}

View file

@ -0,0 +1,98 @@
/*
* 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/>.
*
*
*/
#if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
#error "Only <cogl/cogl.h> can be included directly."
#endif
#ifndef __COGL_PRIMITIVE_TEXTURE_H__
#define __COGL_PRIMITIVE_TEXTURE_H__
#include <glib.h>
G_BEGIN_DECLS
/**
* SECTION:cogl-primitive-texture
* @short_description: Interface for low-level textures like
* #CoglTexture2D and #CoglTexture3D.
*
* A #CoglPrimitiveTexture is a texture that is directly represented
* by a single texture on the GPU. For example these could be a
* #CoglTexture2D, #CoglTexture3D or #CoglTextureRectangle. This is
* opposed to high level meta textures which may be composed of
* multiple primitive textures or a sub-region of another texture such
* as #CoglAtlasTexture and #CoglTexture2DSliced.
*
* A texture that implements this interface can be directly used with
* the attributes API such as cogl_framebuffer_draw_attributes().
* Other types of textures need to be first resolved to primitive
* textures using the #CoglMetaTexture interface.
*
* <note>Most developers won't need to use this interface directly but
* still it is worth understanding the distinction between high-level
* and primitive textures because you may find other references in the
* documentation that detail limitations of using
* primitive textures.</note>
*/
typedef struct _CoglPrimitiveTexture CoglPrimitiveTexture;
#define COGL_PRIMITIVE_TEXTURE(X) ((CoglPrimitiveTexture *)X)
/**
* cogl_is_primitive_texture:
* @object: A #CoglObject pointer
*
* Gets whether the given object references a primitive texture object.
*
* Return value: %TRUE if the pointer references a primitive texture, and
* %FALSE otherwise
* Since: 2.0
* Stability: unstable
*/
gboolean
cogl_is_primitive_texture (void *object);
/**
* cogl_primitive_texture_set_auto_mipmap:
* @primitive_texture: A #CoglPrimitiveTexture
* @value: The new value for whether to auto mipmap
*
* Sets whether the texture will automatically update the smaller
* mipmap levels after any part of level 0 is updated. The update will
* only occur whenever the texture is used for drawing with a texture
* filter that requires the lower mipmap levels. An application should
* disable this if it wants to upload its own data for the other
* levels. By default auto mipmapping is enabled.
*
* Since: 2.0
* Stability: unstable
*/
void
cogl_primitive_texture_set_auto_mipmap (CoglPrimitiveTexture *primitive_texture,
gboolean value);
G_END_DECLS
#endif /* __COGL_PRIMITIVE_TEXTURE_H__ */

View file

@ -427,6 +427,7 @@ _cogl_sub_texture_get_type (CoglTexture *tex)
static const CoglTextureVtable
cogl_sub_texture_vtable =
{
FALSE, /* not primitive */
_cogl_sub_texture_set_region,
NULL, /* get_data */
_cogl_sub_texture_foreach_sub_texture_in_region,
@ -445,5 +446,6 @@ cogl_sub_texture_vtable =
_cogl_sub_texture_get_width,
_cogl_sub_texture_get_height,
_cogl_sub_texture_get_type,
NULL /* is_foreign */
NULL, /* is_foreign */
NULL /* set_auto_mipmap */
};

View file

@ -1303,6 +1303,7 @@ _cogl_texture_2d_sliced_get_type (CoglTexture *tex)
static const CoglTextureVtable
cogl_texture_2d_sliced_vtable =
{
FALSE, /* not primitive */
_cogl_texture_2d_sliced_set_region,
NULL, /* get_data */
_cogl_texture_2d_sliced_foreach_sub_texture_in_region,
@ -1321,5 +1322,6 @@ cogl_texture_2d_sliced_vtable =
_cogl_texture_2d_sliced_get_width,
_cogl_texture_2d_sliced_get_height,
_cogl_texture_2d_sliced_get_type,
_cogl_texture_2d_sliced_is_foreign
_cogl_texture_2d_sliced_is_foreign,
NULL /* set_auto_mipmap */
};

View file

@ -138,10 +138,18 @@ _cogl_texture_2d_can_create (unsigned int width,
return TRUE;
}
static void
_cogl_texture_2d_set_auto_mipmap (CoglTexture *tex,
gboolean value)
{
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
tex_2d->auto_mipmap = value;
}
static CoglTexture2D *
_cogl_texture_2d_create_base (unsigned int width,
unsigned int height,
CoglTextureFlags flags,
CoglPixelFormat internal_format)
{
CoglTexture2D *tex_2d = g_new (CoglTexture2D, 1);
@ -152,7 +160,7 @@ _cogl_texture_2d_create_base (unsigned int width,
tex_2d->width = width;
tex_2d->height = height;
tex_2d->mipmaps_dirty = TRUE;
tex_2d->auto_mipmap = (flags & COGL_TEXTURE_NO_AUTO_MIPMAP) == 0;
tex_2d->auto_mipmap = TRUE;
/* We default to GL_LINEAR for both filters */
tex_2d->min_filter = GL_LINEAR;
@ -200,7 +208,7 @@ cogl_texture_2d_new_with_size (CoglContext *ctx,
&gl_format,
&gl_type);
tex_2d = _cogl_texture_2d_create_base (width, height, COGL_TEXTURE_NONE,
tex_2d = _cogl_texture_2d_create_base (width, height,
internal_format);
ctx->texture_driver->gen (ctx, GL_TEXTURE_2D, 1, &tex_2d->gl_texture);
@ -262,7 +270,6 @@ _cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp,
tex_2d = _cogl_texture_2d_create_base (cogl_bitmap_get_width (bmp),
cogl_bitmap_get_height (bmp),
flags,
internal_format);
/* Keep a copy of the first pixel so that if glGenerateMipmap isn't
@ -294,6 +301,9 @@ _cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp,
cogl_object_unref (dst_bmp);
_cogl_texture_2d_set_auto_mipmap (COGL_TEXTURE (tex_2d),
!(flags & COGL_TEXTURE_NO_AUTO_MIPMAP));
return _cogl_texture_2d_handle_new (tex_2d);
}
@ -432,8 +442,8 @@ cogl_texture_2d_new_from_foreign (CoglContext *ctx,
/* Create new texture */
tex_2d = _cogl_texture_2d_create_base (width, height,
COGL_TEXTURE_NO_AUTO_MIPMAP,
format);
_cogl_texture_2d_set_auto_mipmap (COGL_TEXTURE (tex_2d), FALSE);
/* Setup bitmap info */
tex_2d->is_foreign = TRUE;
@ -474,7 +484,7 @@ _cogl_egl_texture_2d_new_from_image (CoglContext *ctx,
COGL_PRIVATE_FEATURE_TEXTURE_2D_FROM_EGL_IMAGE,
NULL);
tex_2d = _cogl_texture_2d_create_base (width, height, COGL_TEXTURE_NONE,
tex_2d = _cogl_texture_2d_create_base (width, height,
format);
ctx->texture_driver->gen (ctx, GL_TEXTURE_2D, 1, &tex_2d->gl_texture);
@ -877,6 +887,7 @@ _cogl_texture_2d_get_type (CoglTexture *tex)
static const CoglTextureVtable
cogl_texture_2d_vtable =
{
TRUE, /* primitive */
_cogl_texture_2d_set_region,
_cogl_texture_2d_get_data,
NULL, /* foreach_sub_texture_in_region */
@ -895,5 +906,6 @@ cogl_texture_2d_vtable =
_cogl_texture_2d_get_width,
_cogl_texture_2d_get_height,
_cogl_texture_2d_get_type,
_cogl_texture_2d_is_foreign
_cogl_texture_2d_is_foreign,
_cogl_texture_2d_set_auto_mipmap
};

View file

@ -99,6 +99,15 @@ _cogl_texture_3d_free (CoglTexture3D *tex_3d)
_cogl_texture_free (COGL_TEXTURE (tex_3d));
}
static void
_cogl_texture_3d_set_auto_mipmap (CoglTexture *tex,
gboolean value)
{
CoglTexture3D *tex_3d = COGL_TEXTURE_3D (tex);
tex_3d->auto_mipmap = value;
}
static CoglTexture3D *
_cogl_texture_3d_create_base (CoglContext *ctx,
int width,
@ -609,6 +618,7 @@ _cogl_texture_3d_get_type (CoglTexture *tex)
static const CoglTextureVtable
cogl_texture_3d_vtable =
{
TRUE, /* primitive */
_cogl_texture_3d_set_region,
_cogl_texture_3d_get_data,
NULL, /* foreach_sub_texture_in_region */
@ -627,5 +637,6 @@ cogl_texture_3d_vtable =
_cogl_texture_3d_get_width,
_cogl_texture_3d_get_height,
_cogl_texture_3d_get_type,
NULL /* is_foreign */
NULL, /* is_foreign */
_cogl_texture_3d_set_auto_mipmap
};

View file

@ -58,6 +58,8 @@ struct _CoglTextureVtable
/* Virtual functions that must be implemented for a texture
backend */
gboolean is_primitive;
/* This should update the specified sub region of the texture with a
sub region of the given bitmap. The bitmap is not converted
before being passed so the implementation is expected to call
@ -126,6 +128,10 @@ struct _CoglTextureVtable
CoglTextureType (* get_type) (CoglTexture *tex);
gboolean (* is_foreign) (CoglTexture *tex);
/* Only needs to be implemented if is_primitive == TRUE */
void (* set_auto_mipmap) (CoglTexture *texture,
gboolean value);
};
struct _CoglTexture

View file

@ -152,6 +152,14 @@ _cogl_texture_rectangle_can_create (unsigned int width,
return TRUE;
}
static void
_cogl_texture_rectangle_set_auto_mipmap (CoglTexture *tex,
gboolean value)
{
/* Rectangle textures currently never support mipmapping so there's
no point in doing anything here */
}
static CoglTextureRectangle *
_cogl_texture_rectangle_create_base (unsigned int width,
unsigned int height,
@ -604,6 +612,7 @@ _cogl_texture_rectangle_get_type (CoglTexture *tex)
static const CoglTextureVtable
cogl_texture_rectangle_vtable =
{
TRUE, /* primitive */
_cogl_texture_rectangle_set_region,
_cogl_texture_rectangle_get_data,
NULL, /* foreach_sub_texture_in_region */
@ -622,5 +631,6 @@ cogl_texture_rectangle_vtable =
_cogl_texture_rectangle_get_width,
_cogl_texture_rectangle_get_height,
_cogl_texture_rectangle_get_type,
_cogl_texture_rectangle_is_foreign
_cogl_texture_rectangle_is_foreign,
_cogl_texture_rectangle_set_auto_mipmap
};

View file

@ -89,6 +89,7 @@
#include <cogl/cogl-texture-2d-sliced.h>
#include <cogl/cogl-sub-texture.h>
#include <cogl/cogl-meta-texture.h>
#include <cogl/cogl-primitive-texture.h>
#include <cogl/cogl-index-buffer.h>
#include <cogl/cogl-attribute-buffer.h>
#include <cogl/cogl-indices.h>

View file

@ -1009,6 +1009,7 @@ _cogl_texture_pixmap_x11_free (CoglTexturePixmapX11 *tex_pixmap)
static const CoglTextureVtable
cogl_texture_pixmap_x11_vtable =
{
FALSE, /* not primitive */
_cogl_texture_pixmap_x11_set_region,
_cogl_texture_pixmap_x11_get_data,
_cogl_texture_pixmap_x11_foreach_sub_texture_in_region,
@ -1027,5 +1028,6 @@ cogl_texture_pixmap_x11_vtable =
_cogl_texture_pixmap_x11_get_width,
_cogl_texture_pixmap_x11_get_height,
_cogl_texture_pixmap_x11_get_type,
NULL /* is_foreign */
NULL, /* is_foreign */
NULL /* set_auto_mipmap */
};

View file

@ -94,9 +94,6 @@
<section id="cogl-textures">
<title>Textures</title>
<xi:include href="xml/cogl-texture.xml"/>
<xi:include href="xml/cogl-texture-2d.xml"/>
<xi:include href="xml/cogl-texture-3d.xml"/>
<xi:include href="xml/cogl-texture-rectangle.xml"/>
</section>
<section id="cogl-meta-textures">
@ -107,6 +104,14 @@
<xi:include href="xml/cogl-texture-pixmap-x11.xml"/>
</section>
<section id="cogl-primitive-textures">
<title>Primitive Textures</title>
<xi:include href="xml/cogl-primitive-texture.xml"/>
<xi:include href="xml/cogl-texture-2d.xml"/>
<xi:include href="xml/cogl-texture-3d.xml"/>
<xi:include href="xml/cogl-texture-rectangle.xml"/>
</section>
<xi:include href="xml/cogl-clipping.xml"/>
<section id="cogl-framebuffer-apis">
<title>Framebuffers</title>

View file

@ -344,6 +344,14 @@ CoglMetaTextureCallback
cogl_meta_texture_foreach_in_region
</SECTION>
<SECTION>
<FILE>cogl-primitive-texture</FILE>
<TITLE>Low-level primitive textures</TITLE>
CoglPrimitiveTexture
cogl_is_primitive_texture
cogl_primitive_texture_set_auto_mipmap
</SECTION>
<SECTION>
<FILE>cogl-sub-texture</FILE>
<TITLE>Sub Textures</TITLE>