2010-07-01 17:04:59 -04:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2010-07-01 17:04:59 -04:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Intel Corporation.
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2010-07-01 17:04:59 -04:00
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
2010-07-01 17:04:59 -04:00
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2010-07-01 17:04:59 -04:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Neil Roberts <neil@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-02-13 18:02:04 -05:00
|
|
|
#include "cogl-private.h"
|
2010-07-01 17:04:59 -04:00
|
|
|
#include "cogl-util.h"
|
|
|
|
#include "cogl-texture-private.h"
|
|
|
|
#include "cogl-texture-3d-private.h"
|
2012-02-17 20:19:17 -05:00
|
|
|
#include "cogl-texture-3d.h"
|
2012-11-09 12:55:54 -05:00
|
|
|
#include "cogl-texture-gl-private.h"
|
2010-07-01 17:04:59 -04:00
|
|
|
#include "cogl-texture-driver.h"
|
2010-11-04 18:25:52 -04:00
|
|
|
#include "cogl-context-private.h"
|
2012-04-16 09:14:10 -04:00
|
|
|
#include "cogl-object-private.h"
|
2010-07-01 17:04:59 -04:00
|
|
|
#include "cogl-journal-private.h"
|
2010-10-27 13:54:57 -04:00
|
|
|
#include "cogl-pipeline-private.h"
|
|
|
|
#include "cogl-pipeline-opengl-private.h"
|
2012-08-31 14:28:27 -04:00
|
|
|
#include "cogl-error-private.h"
|
2012-10-25 12:09:09 -04:00
|
|
|
#include "cogl-util-gl-private.h"
|
2013-09-02 11:02:42 -04:00
|
|
|
#include "cogl-gtype-private.h"
|
2010-07-01 17:04:59 -04:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
/* These might not be defined on GLES */
|
|
|
|
#ifndef GL_TEXTURE_3D
|
|
|
|
#define GL_TEXTURE_3D 0x806F
|
|
|
|
#endif
|
|
|
|
#ifndef GL_TEXTURE_WRAP_R
|
|
|
|
#define GL_TEXTURE_WRAP_R 0x8072
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void _cogl_texture_3d_free (CoglTexture3D *tex_3d);
|
|
|
|
|
|
|
|
COGL_TEXTURE_DEFINE (Texture3D, texture_3d);
|
2013-09-02 11:02:42 -04:00
|
|
|
COGL_GTYPE_DEFINE_CLASS (Texture3D, texture_3d,
|
|
|
|
COGL_GTYPE_IMPLEMENT_INTERFACE (texture));
|
2010-07-01 17:04:59 -04:00
|
|
|
|
|
|
|
static const CoglTextureVtable cogl_texture_3d_vtable;
|
|
|
|
|
|
|
|
static void
|
2012-09-10 15:35:39 -04:00
|
|
|
_cogl_texture_3d_gl_flush_legacy_texobj_wrap_modes (CoglTexture *tex,
|
|
|
|
GLenum wrap_mode_s,
|
|
|
|
GLenum wrap_mode_t,
|
|
|
|
GLenum wrap_mode_p)
|
2010-07-01 17:04:59 -04:00
|
|
|
{
|
|
|
|
CoglTexture3D *tex_3d = COGL_TEXTURE_3D (tex);
|
2012-09-07 10:26:34 -04:00
|
|
|
CoglContext *ctx = tex->context;
|
2011-07-06 16:51:00 -04:00
|
|
|
|
2010-07-01 17:04:59 -04:00
|
|
|
/* Only set the wrap mode if it's different from the current value
|
|
|
|
to avoid too many GL calls. */
|
2012-09-10 15:35:39 -04:00
|
|
|
if (tex_3d->gl_legacy_texobj_wrap_mode_s != wrap_mode_s ||
|
|
|
|
tex_3d->gl_legacy_texobj_wrap_mode_t != wrap_mode_t ||
|
|
|
|
tex_3d->gl_legacy_texobj_wrap_mode_p != wrap_mode_p)
|
2010-07-01 17:04:59 -04:00
|
|
|
{
|
|
|
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_3D,
|
|
|
|
tex_3d->gl_texture,
|
|
|
|
FALSE);
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glTexParameteri (GL_TEXTURE_3D,
|
|
|
|
GL_TEXTURE_WRAP_S,
|
|
|
|
wrap_mode_s) );
|
|
|
|
GE( ctx, glTexParameteri (GL_TEXTURE_3D,
|
|
|
|
GL_TEXTURE_WRAP_T,
|
|
|
|
wrap_mode_t) );
|
|
|
|
GE( ctx, glTexParameteri (GL_TEXTURE_3D,
|
|
|
|
GL_TEXTURE_WRAP_R,
|
|
|
|
wrap_mode_p) );
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2012-09-10 15:35:39 -04:00
|
|
|
tex_3d->gl_legacy_texobj_wrap_mode_s = wrap_mode_s;
|
|
|
|
tex_3d->gl_legacy_texobj_wrap_mode_t = wrap_mode_t;
|
|
|
|
tex_3d->gl_legacy_texobj_wrap_mode_p = wrap_mode_p;
|
2010-07-01 17:04:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_texture_3d_free (CoglTexture3D *tex_3d)
|
|
|
|
{
|
2012-11-22 18:01:08 -05:00
|
|
|
if (tex_3d->gl_texture)
|
|
|
|
_cogl_delete_gl_texture (tex_3d->gl_texture);
|
2010-07-01 17:04:59 -04:00
|
|
|
|
|
|
|
/* Chain up */
|
|
|
|
_cogl_texture_free (COGL_TEXTURE (tex_3d));
|
|
|
|
}
|
|
|
|
|
2012-04-04 10:09:43 -04:00
|
|
|
static void
|
|
|
|
_cogl_texture_3d_set_auto_mipmap (CoglTexture *tex,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
CoglBool value)
|
2012-04-04 10:09:43 -04:00
|
|
|
{
|
|
|
|
CoglTexture3D *tex_3d = COGL_TEXTURE_3D (tex);
|
|
|
|
|
|
|
|
tex_3d->auto_mipmap = value;
|
|
|
|
}
|
|
|
|
|
2010-07-01 17:04:59 -04:00
|
|
|
static CoglTexture3D *
|
2012-02-17 21:11:34 -05:00
|
|
|
_cogl_texture_3d_create_base (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int depth,
|
2013-06-23 11:18:18 -04:00
|
|
|
CoglPixelFormat internal_format,
|
|
|
|
CoglTextureLoader *loader)
|
2010-07-01 17:04:59 -04:00
|
|
|
{
|
|
|
|
CoglTexture3D *tex_3d = g_new (CoglTexture3D, 1);
|
|
|
|
CoglTexture *tex = COGL_TEXTURE (tex_3d);
|
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
_cogl_texture_init (tex, ctx, width, height,
|
|
|
|
internal_format, loader, &cogl_texture_3d_vtable);
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
tex_3d->gl_texture = 0;
|
|
|
|
|
2010-07-01 17:04:59 -04:00
|
|
|
tex_3d->depth = depth;
|
|
|
|
tex_3d->mipmaps_dirty = TRUE;
|
2012-02-17 21:11:34 -05:00
|
|
|
tex_3d->auto_mipmap = TRUE;
|
2010-07-01 17:04:59 -04:00
|
|
|
|
|
|
|
/* We default to GL_LINEAR for both filters */
|
2012-09-10 15:35:39 -04:00
|
|
|
tex_3d->gl_legacy_texobj_min_filter = GL_LINEAR;
|
|
|
|
tex_3d->gl_legacy_texobj_mag_filter = GL_LINEAR;
|
2010-07-01 17:04:59 -04:00
|
|
|
|
|
|
|
/* Wrap mode not yet set */
|
2012-09-10 15:35:39 -04:00
|
|
|
tex_3d->gl_legacy_texobj_wrap_mode_s = GL_FALSE;
|
|
|
|
tex_3d->gl_legacy_texobj_wrap_mode_t = GL_FALSE;
|
|
|
|
tex_3d->gl_legacy_texobj_wrap_mode_p = GL_FALSE;
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2012-10-25 12:09:09 -04:00
|
|
|
return _cogl_texture_3d_object_new (tex_3d);
|
2010-07-01 17:04:59 -04:00
|
|
|
}
|
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
CoglTexture3D *
|
|
|
|
cogl_texture_3d_new_with_size (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
2013-07-01 20:48:54 -04:00
|
|
|
int depth)
|
2013-06-23 11:18:18 -04:00
|
|
|
{
|
2013-07-01 20:48:54 -04:00
|
|
|
CoglTextureLoader *loader = _cogl_texture_create_loader ();
|
2013-06-23 11:18:18 -04:00
|
|
|
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZED;
|
|
|
|
loader->src.sized.width = width;
|
|
|
|
loader->src.sized.height = height;
|
|
|
|
loader->src.sized.depth = depth;
|
|
|
|
|
|
|
|
return _cogl_texture_3d_create_base (ctx, width, height, depth,
|
2013-07-01 20:48:54 -04:00
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
|
|
|
loader);
|
2013-06-23 11:18:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglTexture3D *
|
|
|
|
cogl_texture_3d_new_from_bitmap (CoglBitmap *bmp,
|
|
|
|
int height,
|
2013-07-01 20:48:54 -04:00
|
|
|
int depth)
|
2013-06-23 11:18:18 -04:00
|
|
|
{
|
|
|
|
CoglTextureLoader *loader;
|
|
|
|
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (bmp, NULL);
|
|
|
|
|
|
|
|
loader = _cogl_texture_create_loader ();
|
|
|
|
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_BITMAP;
|
|
|
|
loader->src.bitmap.bitmap = cogl_object_ref (bmp);
|
|
|
|
loader->src.bitmap.height = height;
|
|
|
|
loader->src.bitmap.depth = depth;
|
|
|
|
loader->src.bitmap.can_convert_in_place = FALSE; /* TODO add api for this */
|
|
|
|
|
|
|
|
return _cogl_texture_3d_create_base (_cogl_bitmap_get_context (bmp),
|
|
|
|
cogl_bitmap_get_width (bmp),
|
|
|
|
height,
|
|
|
|
depth,
|
2013-07-01 20:48:54 -04:00
|
|
|
cogl_bitmap_get_format (bmp),
|
2013-06-23 11:18:18 -04:00
|
|
|
loader);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglTexture3D *
|
|
|
|
cogl_texture_3d_new_from_data (CoglContext *context,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int depth,
|
|
|
|
CoglPixelFormat format,
|
|
|
|
int rowstride,
|
|
|
|
int image_stride,
|
|
|
|
const uint8_t *data,
|
|
|
|
CoglError **error)
|
|
|
|
{
|
|
|
|
CoglBitmap *bitmap;
|
|
|
|
CoglTexture3D *ret;
|
|
|
|
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (data, NULL);
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (format != COGL_PIXEL_FORMAT_ANY, NULL);
|
|
|
|
|
|
|
|
/* Rowstride from width if not given */
|
|
|
|
if (rowstride == 0)
|
|
|
|
rowstride = width * _cogl_pixel_format_get_bytes_per_pixel (format);
|
|
|
|
/* Image stride from height and rowstride if not given */
|
|
|
|
if (image_stride == 0)
|
|
|
|
image_stride = height * rowstride;
|
|
|
|
|
|
|
|
if (image_stride < rowstride * height)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* GL doesn't support uploading when the image_stride isn't a
|
|
|
|
multiple of the rowstride. If this happens we'll just pack the
|
|
|
|
image into a new bitmap. The documentation for this function
|
|
|
|
recommends avoiding this situation. */
|
|
|
|
if (image_stride % rowstride != 0)
|
|
|
|
{
|
|
|
|
uint8_t *bmp_data;
|
|
|
|
int bmp_rowstride;
|
|
|
|
int z, y;
|
|
|
|
|
|
|
|
bitmap = _cogl_bitmap_new_with_malloc_buffer (context,
|
|
|
|
width,
|
|
|
|
depth * height,
|
|
|
|
format,
|
|
|
|
error);
|
|
|
|
if (!bitmap)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
bmp_data = _cogl_bitmap_map (bitmap,
|
|
|
|
COGL_BUFFER_ACCESS_WRITE,
|
|
|
|
COGL_BUFFER_MAP_HINT_DISCARD,
|
|
|
|
error);
|
|
|
|
|
|
|
|
if (bmp_data == NULL)
|
|
|
|
{
|
|
|
|
cogl_object_unref (bitmap);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bmp_rowstride = cogl_bitmap_get_rowstride (bitmap);
|
|
|
|
|
|
|
|
/* Copy all of the images in */
|
|
|
|
for (z = 0; z < depth; z++)
|
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
memcpy (bmp_data + (z * bmp_rowstride * height +
|
|
|
|
bmp_rowstride * y),
|
|
|
|
data + z * image_stride + rowstride * y,
|
|
|
|
bmp_rowstride);
|
|
|
|
|
|
|
|
_cogl_bitmap_unmap (bitmap);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bitmap = cogl_bitmap_new_for_data (context,
|
|
|
|
width,
|
|
|
|
image_stride / rowstride * depth,
|
|
|
|
format,
|
|
|
|
rowstride,
|
|
|
|
(uint8_t *) data);
|
|
|
|
|
|
|
|
ret = cogl_texture_3d_new_from_bitmap (bitmap,
|
|
|
|
height,
|
2013-07-01 20:48:54 -04:00
|
|
|
depth);
|
2013-06-23 11:18:18 -04:00
|
|
|
|
|
|
|
cogl_object_unref (bitmap);
|
|
|
|
|
|
|
|
if (ret &&
|
|
|
|
!cogl_texture_allocate (COGL_TEXTURE (ret), error))
|
|
|
|
{
|
|
|
|
cogl_object_unref (ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2012-02-17 21:11:34 -05:00
|
|
|
_cogl_texture_3d_can_create (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int depth,
|
|
|
|
CoglPixelFormat internal_format,
|
2012-08-31 14:28:27 -04:00
|
|
|
CoglError **error)
|
2010-07-01 17:04:59 -04:00
|
|
|
{
|
|
|
|
GLenum gl_intformat;
|
|
|
|
GLenum gl_type;
|
|
|
|
|
|
|
|
/* This should only happen on GLES */
|
2011-10-12 17:31:12 -04:00
|
|
|
if (!cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_3D))
|
2010-07-01 17:04:59 -04:00
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_SYSTEM_ERROR,
|
|
|
|
COGL_SYSTEM_ERROR_UNSUPPORTED,
|
|
|
|
"3D textures are not supported by the GPU");
|
2010-07-01 17:04:59 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If NPOT textures aren't supported then the size must be a power
|
|
|
|
of two */
|
2011-10-12 17:31:12 -04:00
|
|
|
if (!cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT) &&
|
2010-07-01 17:04:59 -04:00
|
|
|
(!_cogl_util_is_pot (width) ||
|
|
|
|
!_cogl_util_is_pot (height) ||
|
|
|
|
!_cogl_util_is_pot (depth)))
|
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_SYSTEM_ERROR,
|
|
|
|
COGL_SYSTEM_ERROR_UNSUPPORTED,
|
|
|
|
"A non-power-of-two size was requested but this is not "
|
|
|
|
"supported by the GPU");
|
2010-07-01 17:04:59 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-03-22 12:32:56 -04:00
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
internal_format,
|
|
|
|
&gl_intformat,
|
|
|
|
NULL,
|
|
|
|
&gl_type);
|
2010-07-01 17:04:59 -04:00
|
|
|
|
|
|
|
/* Check that the driver can create a texture with that size */
|
2012-03-22 13:04:47 -04:00
|
|
|
if (!ctx->texture_driver->size_supported_3d (ctx,
|
|
|
|
GL_TEXTURE_3D,
|
2010-07-01 17:04:59 -04:00
|
|
|
gl_intformat,
|
|
|
|
gl_type,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
depth))
|
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_SYSTEM_ERROR,
|
|
|
|
COGL_SYSTEM_ERROR_UNSUPPORTED,
|
|
|
|
"The requested dimensions are not supported by the GPU");
|
2010-07-01 17:04:59 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
static CoglBool
|
2013-06-23 11:18:18 -04:00
|
|
|
allocate_with_size (CoglTexture3D *tex_3d,
|
|
|
|
CoglTextureLoader *loader,
|
|
|
|
CoglError **error)
|
2012-11-22 18:01:08 -05:00
|
|
|
{
|
2013-06-23 11:18:18 -04:00
|
|
|
CoglTexture *tex = COGL_TEXTURE (tex_3d);
|
2012-11-22 18:01:08 -05:00
|
|
|
CoglContext *ctx = tex->context;
|
2013-06-23 11:18:18 -04:00
|
|
|
CoglPixelFormat internal_format;
|
|
|
|
int width = loader->src.sized.width;
|
|
|
|
int height = loader->src.sized.height;
|
|
|
|
int depth = loader->src.sized.depth;
|
2012-10-25 12:09:09 -04:00
|
|
|
GLenum gl_intformat;
|
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
|
|
|
GLenum gl_error;
|
2012-11-22 18:01:08 -05:00
|
|
|
GLenum gl_texture;
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
internal_format =
|
|
|
|
_cogl_texture_determine_internal_format (tex, COGL_PIXEL_FORMAT_ANY);
|
|
|
|
|
2012-02-17 21:11:34 -05:00
|
|
|
if (!_cogl_texture_3d_can_create (ctx,
|
2013-06-23 11:18:18 -04:00
|
|
|
width,
|
|
|
|
height,
|
|
|
|
depth,
|
|
|
|
internal_format,
|
2010-07-01 17:04:59 -04:00
|
|
|
error))
|
2012-11-22 18:01:08 -05:00
|
|
|
return FALSE;
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
2013-06-23 11:18:18 -04:00
|
|
|
internal_format,
|
2012-11-22 18:01:08 -05:00
|
|
|
&gl_intformat,
|
|
|
|
&gl_format,
|
|
|
|
&gl_type);
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
gl_texture =
|
2013-06-23 11:18:18 -04:00
|
|
|
ctx->texture_driver->gen (ctx, GL_TEXTURE_3D, internal_format);
|
2010-07-01 17:04:59 -04:00
|
|
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_3D,
|
2012-11-22 18:01:08 -05:00
|
|
|
gl_texture,
|
2010-07-01 17:04:59 -04:00
|
|
|
FALSE);
|
2012-10-25 12:09:09 -04:00
|
|
|
/* Clear any GL errors */
|
|
|
|
while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
|
|
|
|
;
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2012-10-25 12:09:09 -04:00
|
|
|
ctx->glTexImage3D (GL_TEXTURE_3D, 0, gl_intformat,
|
2013-06-23 11:18:18 -04:00
|
|
|
width, height, depth,
|
2012-11-22 18:01:08 -05:00
|
|
|
0, gl_format, gl_type, NULL);
|
2012-10-25 12:09:09 -04:00
|
|
|
|
|
|
|
if (_cogl_gl_util_catch_out_of_memory (ctx, error))
|
|
|
|
{
|
2012-11-22 18:01:08 -05:00
|
|
|
GE( ctx, glDeleteTextures (1, &gl_texture) );
|
|
|
|
return FALSE;
|
2012-10-25 12:09:09 -04:00
|
|
|
}
|
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
tex_3d->gl_texture = gl_texture;
|
|
|
|
tex_3d->gl_format = gl_intformat;
|
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
tex_3d->depth = depth;
|
|
|
|
|
|
|
|
tex_3d->internal_format = internal_format;
|
|
|
|
|
|
|
|
_cogl_texture_set_allocated (tex, internal_format, width, height);
|
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
return TRUE;
|
2010-07-01 17:04:59 -04:00
|
|
|
}
|
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
static CoglBool
|
|
|
|
allocate_from_bitmap (CoglTexture3D *tex_3d,
|
|
|
|
CoglTextureLoader *loader,
|
|
|
|
CoglError **error)
|
2010-07-01 17:04:59 -04:00
|
|
|
{
|
2013-06-23 11:18:18 -04:00
|
|
|
CoglTexture *tex = COGL_TEXTURE (tex_3d);
|
|
|
|
CoglContext *ctx = tex->context;
|
|
|
|
CoglPixelFormat internal_format;
|
|
|
|
CoglBitmap *bmp = loader->src.bitmap.bitmap;
|
|
|
|
int bmp_width = cogl_bitmap_get_width (bmp);
|
|
|
|
int height = loader->src.bitmap.height;
|
|
|
|
int depth = loader->src.bitmap.depth;
|
|
|
|
CoglPixelFormat bmp_format = cogl_bitmap_get_format (bmp);
|
|
|
|
CoglBool can_convert_in_place = loader->src.bitmap.can_convert_in_place;
|
2013-06-07 19:28:14 -04:00
|
|
|
CoglBitmap *upload_bmp;
|
|
|
|
CoglPixelFormat upload_format;
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
GLenum gl_intformat;
|
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
2012-04-04 08:57:42 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
internal_format = _cogl_texture_determine_internal_format (tex, bmp_format);
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2012-02-17 21:11:34 -05:00
|
|
|
if (!_cogl_texture_3d_can_create (ctx,
|
|
|
|
bmp_width, height, depth,
|
|
|
|
internal_format,
|
2010-07-01 17:04:59 -04:00
|
|
|
error))
|
2013-06-23 11:18:18 -04:00
|
|
|
return FALSE;
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
upload_bmp = _cogl_bitmap_convert_for_upload (bmp,
|
|
|
|
internal_format,
|
|
|
|
can_convert_in_place,
|
|
|
|
error);
|
2013-06-07 19:28:14 -04:00
|
|
|
if (upload_bmp == NULL)
|
2013-06-23 11:18:18 -04:00
|
|
|
return FALSE;
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2013-06-07 19:28:14 -04:00
|
|
|
upload_format = cogl_bitmap_get_format (upload_bmp);
|
|
|
|
|
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
upload_format,
|
|
|
|
NULL, /* internal format */
|
|
|
|
&gl_format,
|
|
|
|
&gl_type);
|
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
internal_format,
|
|
|
|
&gl_intformat,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
2010-07-13 13:41:01 -04:00
|
|
|
/* Keep a copy of the first pixel so that if glGenerateMipmap isn't
|
|
|
|
supported we can fallback to using GL_GENERATE_MIPMAP */
|
2012-11-08 12:54:10 -05:00
|
|
|
if (!cogl_has_feature (ctx, COGL_FEATURE_ID_OFFSCREEN))
|
2010-07-07 13:44:16 -04:00
|
|
|
{
|
2012-11-08 12:54:10 -05:00
|
|
|
CoglError *ignore = NULL;
|
2013-06-07 19:28:14 -04:00
|
|
|
uint8_t *data = _cogl_bitmap_map (upload_bmp,
|
2012-11-08 12:54:10 -05:00
|
|
|
COGL_BUFFER_ACCESS_READ, 0,
|
|
|
|
&ignore);
|
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
tex_3d->first_pixel.gl_format = gl_format;
|
|
|
|
tex_3d->first_pixel.gl_type = gl_type;
|
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
memcpy (tex_3d->first_pixel.data, data,
|
2013-06-07 19:28:14 -04:00
|
|
|
_cogl_pixel_format_get_bytes_per_pixel (upload_format));
|
|
|
|
_cogl_bitmap_unmap (upload_bmp);
|
2012-11-08 12:54:10 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning ("Failed to read first pixel of bitmap for "
|
|
|
|
"glGenerateMipmap fallback");
|
|
|
|
cogl_error_free (ignore);
|
|
|
|
memset (tex_3d->first_pixel.data, 0,
|
2013-06-07 19:28:14 -04:00
|
|
|
_cogl_pixel_format_get_bytes_per_pixel (upload_format));
|
2012-11-08 12:54:10 -05:00
|
|
|
}
|
2010-07-07 13:44:16 -04:00
|
|
|
}
|
2010-07-13 13:41:01 -04:00
|
|
|
|
2012-11-19 12:28:52 -05:00
|
|
|
tex_3d->gl_texture =
|
|
|
|
ctx->texture_driver->gen (ctx, GL_TEXTURE_3D, internal_format);
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
if (!ctx->texture_driver->upload_to_gl_3d (ctx,
|
|
|
|
GL_TEXTURE_3D,
|
|
|
|
tex_3d->gl_texture,
|
|
|
|
FALSE, /* is_foreign */
|
|
|
|
height,
|
|
|
|
depth,
|
2013-06-07 19:28:14 -04:00
|
|
|
upload_bmp,
|
2012-11-08 12:54:10 -05:00
|
|
|
gl_intformat,
|
|
|
|
gl_format,
|
|
|
|
gl_type,
|
|
|
|
error))
|
|
|
|
{
|
2013-06-07 19:28:14 -04:00
|
|
|
cogl_object_unref (upload_bmp);
|
2013-06-23 11:18:18 -04:00
|
|
|
return FALSE;
|
2012-11-08 12:54:10 -05:00
|
|
|
}
|
2010-07-01 17:04:59 -04:00
|
|
|
|
|
|
|
tex_3d->gl_format = gl_intformat;
|
|
|
|
|
2013-06-07 19:28:14 -04:00
|
|
|
cogl_object_unref (upload_bmp);
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
tex_3d->depth = loader->src.bitmap.depth;
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
tex_3d->internal_format = internal_format;
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
_cogl_texture_set_allocated (tex, internal_format,
|
|
|
|
bmp_width, loader->src.bitmap.height);
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
static CoglBool
|
|
|
|
_cogl_texture_3d_allocate (CoglTexture *tex,
|
|
|
|
CoglError **error)
|
|
|
|
{
|
|
|
|
CoglTexture3D *tex_3d = COGL_TEXTURE_3D (tex);
|
|
|
|
CoglTextureLoader *loader = tex->loader;
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (loader, FALSE);
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
switch (loader->src_type)
|
2010-07-01 17:04:59 -04:00
|
|
|
{
|
2013-06-23 11:18:18 -04:00
|
|
|
case COGL_TEXTURE_SOURCE_TYPE_SIZED:
|
|
|
|
return allocate_with_size (tex_3d, loader, error);
|
|
|
|
case COGL_TEXTURE_SOURCE_TYPE_BITMAP:
|
|
|
|
return allocate_from_bitmap (tex_3d, loader, error);
|
|
|
|
default:
|
|
|
|
break;
|
2010-07-01 17:04:59 -04:00
|
|
|
}
|
2010-07-07 13:44:16 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
g_return_val_if_reached (FALSE);
|
2010-07-01 17:04:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_cogl_texture_3d_get_max_waste (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2010-07-01 17:04:59 -04:00
|
|
|
_cogl_texture_3d_is_sliced (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2010-07-01 17:04:59 -04:00
|
|
|
_cogl_texture_3d_can_hardware_repeat (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_texture_3d_transform_coords_to_gl (CoglTexture *tex,
|
|
|
|
float *s,
|
|
|
|
float *t)
|
|
|
|
{
|
|
|
|
/* The texture coordinates map directly so we don't need to do
|
|
|
|
anything */
|
|
|
|
}
|
|
|
|
|
|
|
|
static CoglTransformResult
|
|
|
|
_cogl_texture_3d_transform_quad_coords_to_gl (CoglTexture *tex,
|
|
|
|
float *coords)
|
|
|
|
{
|
|
|
|
/* The texture coordinates map directly so we don't need to do
|
|
|
|
anything other than check for repeats */
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
CoglBool need_repeat = FALSE;
|
2010-07-01 17:04:59 -04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
if (coords[i] < 0.0f || coords[i] > 1.0f)
|
|
|
|
need_repeat = TRUE;
|
|
|
|
|
|
|
|
return (need_repeat ? COGL_TRANSFORM_HARDWARE_REPEAT
|
|
|
|
: COGL_TRANSFORM_NO_REPEAT);
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2010-07-01 17:04:59 -04:00
|
|
|
_cogl_texture_3d_get_gl_texture (CoglTexture *tex,
|
|
|
|
GLuint *out_gl_handle,
|
|
|
|
GLenum *out_gl_target)
|
|
|
|
{
|
|
|
|
CoglTexture3D *tex_3d = COGL_TEXTURE_3D (tex);
|
|
|
|
|
|
|
|
if (out_gl_handle)
|
|
|
|
*out_gl_handle = tex_3d->gl_texture;
|
|
|
|
|
|
|
|
if (out_gl_target)
|
|
|
|
*out_gl_target = GL_TEXTURE_3D;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-09-10 15:35:39 -04:00
|
|
|
_cogl_texture_3d_gl_flush_legacy_texobj_filters (CoglTexture *tex,
|
|
|
|
GLenum min_filter,
|
|
|
|
GLenum mag_filter)
|
2010-07-01 17:04:59 -04:00
|
|
|
{
|
|
|
|
CoglTexture3D *tex_3d = COGL_TEXTURE_3D (tex);
|
2012-09-07 10:26:34 -04:00
|
|
|
CoglContext *ctx = tex->context;
|
2011-07-06 16:51:00 -04:00
|
|
|
|
2012-09-10 15:35:39 -04:00
|
|
|
if (min_filter == tex_3d->gl_legacy_texobj_min_filter
|
|
|
|
&& mag_filter == tex_3d->gl_legacy_texobj_mag_filter)
|
2010-07-01 17:04:59 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Store new values */
|
2012-09-10 15:35:39 -04:00
|
|
|
tex_3d->gl_legacy_texobj_min_filter = min_filter;
|
|
|
|
tex_3d->gl_legacy_texobj_mag_filter = mag_filter;
|
2010-07-01 17:04:59 -04:00
|
|
|
|
|
|
|
/* Apply new filters to the texture */
|
|
|
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_3D,
|
|
|
|
tex_3d->gl_texture,
|
|
|
|
FALSE);
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glTexParameteri (GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, mag_filter) );
|
|
|
|
GE( ctx, glTexParameteri (GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, min_filter) );
|
2010-07-01 17:04:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_texture_3d_pre_paint (CoglTexture *tex, CoglTexturePrePaintFlags flags)
|
|
|
|
{
|
|
|
|
CoglTexture3D *tex_3d = COGL_TEXTURE_3D (tex);
|
2012-09-07 10:26:34 -04:00
|
|
|
CoglContext *ctx = tex->context;
|
2010-07-01 17:04:59 -04:00
|
|
|
|
|
|
|
/* Only update if the mipmaps are dirty */
|
|
|
|
if ((flags & COGL_TEXTURE_NEEDS_MIPMAP) &&
|
|
|
|
tex_3d->auto_mipmap && tex_3d->mipmaps_dirty)
|
|
|
|
{
|
2010-07-13 13:41:01 -04:00
|
|
|
/* glGenerateMipmap is defined in the FBO extension. If it's not
|
|
|
|
available we'll fallback to temporarily enabling
|
|
|
|
GL_GENERATE_MIPMAP and reuploading the first pixel */
|
2011-10-12 17:31:12 -04:00
|
|
|
if (cogl_has_feature (ctx, COGL_FEATURE_ID_OFFSCREEN))
|
2012-11-09 12:55:54 -05:00
|
|
|
_cogl_texture_gl_generate_mipmaps (tex);
|
2011-07-07 15:44:56 -04:00
|
|
|
#if defined (HAVE_COGL_GL) || defined (HAVE_COGL_GLES)
|
2013-11-25 11:11:36 -05:00
|
|
|
else if (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_GL_FIXED))
|
2010-07-13 13:41:01 -04:00
|
|
|
{
|
2012-11-09 12:55:54 -05:00
|
|
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_3D,
|
|
|
|
tex_3d->gl_texture,
|
|
|
|
FALSE);
|
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glTexParameteri (GL_TEXTURE_3D,
|
|
|
|
GL_GENERATE_MIPMAP,
|
|
|
|
GL_TRUE) );
|
|
|
|
GE( ctx, glTexSubImage3D (GL_TEXTURE_3D,
|
|
|
|
0, /* level */
|
|
|
|
0, /* xoffset */
|
|
|
|
0, /* yoffset */
|
|
|
|
0, /* zoffset */
|
|
|
|
1, /* width */
|
|
|
|
1, /* height */
|
|
|
|
1, /* depth */
|
|
|
|
tex_3d->first_pixel.gl_format,
|
|
|
|
tex_3d->first_pixel.gl_type,
|
|
|
|
tex_3d->first_pixel.data) );
|
|
|
|
GE( ctx, glTexParameteri (GL_TEXTURE_3D,
|
|
|
|
GL_GENERATE_MIPMAP,
|
|
|
|
GL_FALSE) );
|
2010-07-13 13:41:01 -04:00
|
|
|
}
|
2010-12-05 13:02:05 -05:00
|
|
|
#endif
|
2010-07-01 17:04:59 -04:00
|
|
|
|
|
|
|
tex_3d->mipmaps_dirty = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_texture_3d_ensure_non_quad_rendering (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
/* Nothing needs to be done */
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2012-11-08 12:54:10 -05:00
|
|
|
_cogl_texture_3d_set_region (CoglTexture *tex,
|
|
|
|
int src_x,
|
|
|
|
int src_y,
|
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
|
|
|
int dst_width,
|
|
|
|
int dst_height,
|
2012-11-09 12:55:54 -05:00
|
|
|
int level,
|
2012-11-08 12:54:10 -05:00
|
|
|
CoglBitmap *bmp,
|
|
|
|
CoglError **error)
|
2010-07-01 17:04:59 -04:00
|
|
|
{
|
|
|
|
/* This function doesn't really make sense for 3D textures because
|
|
|
|
it can't specify which image to upload to */
|
2012-11-08 12:54:10 -05:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_SYSTEM_ERROR,
|
|
|
|
COGL_SYSTEM_ERROR_UNSUPPORTED,
|
|
|
|
"Setting a 2D region on a 3D texture isn't "
|
|
|
|
"currently supported");
|
|
|
|
|
2010-07-01 17:04:59 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
_cogl_texture_3d_get_data (CoglTexture *tex,
|
|
|
|
CoglPixelFormat format,
|
2012-09-26 12:05:01 -04:00
|
|
|
int rowstride,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
uint8_t *data)
|
2010-07-01 17:04:59 -04:00
|
|
|
{
|
|
|
|
/* FIXME: we could probably implement this by assuming the data is
|
|
|
|
big enough to hold all of the images and that there is no stride
|
|
|
|
between the images. However it would be better to have an API
|
|
|
|
that can provide an image stride and this function probably isn't
|
|
|
|
particularly useful anyway so for now it just reports failure */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CoglPixelFormat
|
|
|
|
_cogl_texture_3d_get_format (CoglTexture *tex)
|
|
|
|
{
|
2012-11-22 18:01:08 -05:00
|
|
|
return COGL_TEXTURE_3D (tex)->internal_format;
|
2010-07-01 17:04:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static GLenum
|
|
|
|
_cogl_texture_3d_get_gl_format (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return COGL_TEXTURE_3D (tex)->gl_format;
|
|
|
|
}
|
|
|
|
|
2012-02-09 06:19:04 -05:00
|
|
|
static CoglTextureType
|
|
|
|
_cogl_texture_3d_get_type (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return COGL_TEXTURE_TYPE_3D;
|
|
|
|
}
|
|
|
|
|
2010-07-01 17:04:59 -04:00
|
|
|
static const CoglTextureVtable
|
|
|
|
cogl_texture_3d_vtable =
|
|
|
|
{
|
2012-04-04 10:09:43 -04:00
|
|
|
TRUE, /* primitive */
|
2012-11-22 18:01:08 -05:00
|
|
|
_cogl_texture_3d_allocate,
|
2010-07-01 17:04:59 -04:00
|
|
|
_cogl_texture_3d_set_region,
|
|
|
|
_cogl_texture_3d_get_data,
|
2011-10-08 09:13:03 -04:00
|
|
|
NULL, /* foreach_sub_texture_in_region */
|
2010-07-01 17:04:59 -04:00
|
|
|
_cogl_texture_3d_get_max_waste,
|
|
|
|
_cogl_texture_3d_is_sliced,
|
|
|
|
_cogl_texture_3d_can_hardware_repeat,
|
|
|
|
_cogl_texture_3d_transform_coords_to_gl,
|
|
|
|
_cogl_texture_3d_transform_quad_coords_to_gl,
|
|
|
|
_cogl_texture_3d_get_gl_texture,
|
2012-09-10 15:35:39 -04:00
|
|
|
_cogl_texture_3d_gl_flush_legacy_texobj_filters,
|
2010-07-01 17:04:59 -04:00
|
|
|
_cogl_texture_3d_pre_paint,
|
|
|
|
_cogl_texture_3d_ensure_non_quad_rendering,
|
2012-09-10 15:35:39 -04:00
|
|
|
_cogl_texture_3d_gl_flush_legacy_texobj_wrap_modes,
|
2010-07-01 17:04:59 -04:00
|
|
|
_cogl_texture_3d_get_format,
|
|
|
|
_cogl_texture_3d_get_gl_format,
|
2012-02-09 06:19:04 -05:00
|
|
|
_cogl_texture_3d_get_type,
|
2012-04-04 10:09:43 -04:00
|
|
|
NULL, /* is_foreign */
|
|
|
|
_cogl_texture_3d_set_auto_mipmap
|
2010-07-01 17:04:59 -04:00
|
|
|
};
|