mirror of
https://github.com/brl/mutter.git
synced 2024-12-24 12:02:04 +00:00
texture: expose mipmap level in set region apis
cogl_texture_set_region() and cogl_texture_set_region_from_bitmap() now have a level argument so image data can be uploaded to a specific mipmap level. The prototype for cogl_texture_set_region was also updated to simplify the arguments. The arguments for cogl_texture_set_region_from_bitmap were reordered to be consistent with cogl_texture_set_region with the source related arguments listed first followed by the destination arguments. Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit 3a336a8adcd406b53731a6de0e7d97ba7932c1a8) Note: Public API changes were reverted in cherry-picking this patch
This commit is contained in:
parent
fa5a9c88fe
commit
7011eb5db4
@ -361,14 +361,11 @@ static void
|
|||||||
_cogl_atlas_texture_migrate_out_of_atlas (CoglAtlasTexture *atlas_tex)
|
_cogl_atlas_texture_migrate_out_of_atlas (CoglAtlasTexture *atlas_tex)
|
||||||
{
|
{
|
||||||
CoglTexture *standalone_tex;
|
CoglTexture *standalone_tex;
|
||||||
CoglContext *ctx;
|
|
||||||
|
|
||||||
/* Make sure this texture is not in the atlas */
|
/* Make sure this texture is not in the atlas */
|
||||||
if (!atlas_tex->atlas)
|
if (!atlas_tex->atlas)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ctx = COGL_TEXTURE (atlas_tex)->context;
|
|
||||||
|
|
||||||
COGL_NOTE (ATLAS, "Migrating texture out of the atlas");
|
COGL_NOTE (ATLAS, "Migrating texture out of the atlas");
|
||||||
|
|
||||||
/* We don't know if any journal entries currently depend on
|
/* We don't know if any journal entries currently depend on
|
||||||
@ -457,11 +454,12 @@ _cogl_atlas_texture_set_region_with_border (CoglAtlasTexture *atlas_tex,
|
|||||||
/* Copy the central data */
|
/* Copy the central data */
|
||||||
if (!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
if (!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
||||||
src_x, src_y,
|
src_x, src_y,
|
||||||
dst_x + atlas_tex->rectangle.x + 1,
|
|
||||||
dst_y + atlas_tex->rectangle.y + 1,
|
|
||||||
dst_width,
|
dst_width,
|
||||||
dst_height,
|
dst_height,
|
||||||
bmp,
|
bmp,
|
||||||
|
dst_x + atlas_tex->rectangle.x + 1,
|
||||||
|
dst_y + atlas_tex->rectangle.y + 1,
|
||||||
|
0, /* level 0 */
|
||||||
error))
|
error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
@ -469,42 +467,46 @@ _cogl_atlas_texture_set_region_with_border (CoglAtlasTexture *atlas_tex,
|
|||||||
if (dst_x == 0 &&
|
if (dst_x == 0 &&
|
||||||
!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
||||||
src_x, src_y,
|
src_x, src_y,
|
||||||
atlas_tex->rectangle.x,
|
|
||||||
dst_y + atlas_tex->rectangle.y + 1,
|
|
||||||
1, dst_height,
|
1, dst_height,
|
||||||
bmp,
|
bmp,
|
||||||
|
atlas_tex->rectangle.x,
|
||||||
|
dst_y + atlas_tex->rectangle.y + 1,
|
||||||
|
0, /* level 0 */
|
||||||
error))
|
error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
/* Update the right edge pixels */
|
/* Update the right edge pixels */
|
||||||
if (dst_x + dst_width == atlas_tex->rectangle.width - 2 &&
|
if (dst_x + dst_width == atlas_tex->rectangle.width - 2 &&
|
||||||
!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
||||||
src_x + dst_width - 1, src_y,
|
src_x + dst_width - 1, src_y,
|
||||||
|
1, dst_height,
|
||||||
|
bmp,
|
||||||
atlas_tex->rectangle.x +
|
atlas_tex->rectangle.x +
|
||||||
atlas_tex->rectangle.width - 1,
|
atlas_tex->rectangle.width - 1,
|
||||||
dst_y + atlas_tex->rectangle.y + 1,
|
dst_y + atlas_tex->rectangle.y + 1,
|
||||||
1, dst_height,
|
0, /* level 0 */
|
||||||
bmp,
|
|
||||||
error))
|
error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
/* Update the top edge pixels */
|
/* Update the top edge pixels */
|
||||||
if (dst_y == 0 &&
|
if (dst_y == 0 &&
|
||||||
!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
||||||
src_x, src_y,
|
src_x, src_y,
|
||||||
dst_x + atlas_tex->rectangle.x + 1,
|
|
||||||
atlas_tex->rectangle.y,
|
|
||||||
dst_width, 1,
|
dst_width, 1,
|
||||||
bmp,
|
bmp,
|
||||||
|
dst_x + atlas_tex->rectangle.x + 1,
|
||||||
|
atlas_tex->rectangle.y,
|
||||||
|
0, /* level 0 */
|
||||||
error))
|
error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
/* Update the bottom edge pixels */
|
/* Update the bottom edge pixels */
|
||||||
if (dst_y + dst_height == atlas_tex->rectangle.height - 2 &&
|
if (dst_y + dst_height == atlas_tex->rectangle.height - 2 &&
|
||||||
!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
||||||
src_x, src_y + dst_height - 1,
|
src_x, src_y + dst_height - 1,
|
||||||
|
dst_width, 1,
|
||||||
|
bmp,
|
||||||
dst_x + atlas_tex->rectangle.x + 1,
|
dst_x + atlas_tex->rectangle.x + 1,
|
||||||
atlas_tex->rectangle.y +
|
atlas_tex->rectangle.y +
|
||||||
atlas_tex->rectangle.height - 1,
|
atlas_tex->rectangle.height - 1,
|
||||||
dst_width, 1,
|
0, /* level 0 */
|
||||||
bmp,
|
|
||||||
error))
|
error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
@ -567,11 +569,15 @@ _cogl_atlas_texture_set_region (CoglTexture *tex,
|
|||||||
int dst_y,
|
int dst_y,
|
||||||
int dst_width,
|
int dst_width,
|
||||||
int dst_height,
|
int dst_height,
|
||||||
|
int level,
|
||||||
CoglBitmap *bmp,
|
CoglBitmap *bmp,
|
||||||
CoglError **error)
|
CoglError **error)
|
||||||
{
|
{
|
||||||
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
|
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
|
||||||
|
|
||||||
|
if (level != 0 && atlas_tex->atlas)
|
||||||
|
_cogl_atlas_texture_migrate_out_of_atlas (atlas_tex);
|
||||||
|
|
||||||
/* If the texture is in the atlas then we need to copy the edge
|
/* If the texture is in the atlas then we need to copy the edge
|
||||||
pixels to the border */
|
pixels to the border */
|
||||||
if (atlas_tex->atlas)
|
if (atlas_tex->atlas)
|
||||||
@ -600,9 +606,10 @@ _cogl_atlas_texture_set_region (CoglTexture *tex,
|
|||||||
/* Otherwise we can just forward on to the sub texture */
|
/* Otherwise we can just forward on to the sub texture */
|
||||||
return _cogl_texture_set_region_from_bitmap (atlas_tex->sub_texture,
|
return _cogl_texture_set_region_from_bitmap (atlas_tex->sub_texture,
|
||||||
src_x, src_y,
|
src_x, src_y,
|
||||||
dst_x, dst_y,
|
|
||||||
dst_width, dst_height,
|
dst_width, dst_height,
|
||||||
bmp,
|
bmp,
|
||||||
|
dst_x, dst_y,
|
||||||
|
level,
|
||||||
error);
|
error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,10 +253,11 @@ _cogl_blit_copy_tex_sub_image_blit (CoglBlitData *data,
|
|||||||
int height)
|
int height)
|
||||||
{
|
{
|
||||||
_cogl_texture_2d_copy_from_framebuffer (COGL_TEXTURE_2D (data->dst_tex),
|
_cogl_texture_2d_copy_from_framebuffer (COGL_TEXTURE_2D (data->dst_tex),
|
||||||
|
src_x, src_y,
|
||||||
|
width, height,
|
||||||
data->src_fb,
|
data->src_fb,
|
||||||
dst_x, dst_y,
|
dst_x, dst_y,
|
||||||
src_x, src_y,
|
0); /* level */
|
||||||
width, height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -288,14 +289,18 @@ _cogl_blit_get_tex_data_blit (CoglBlitData *data,
|
|||||||
int width,
|
int width,
|
||||||
int height)
|
int height)
|
||||||
{
|
{
|
||||||
cogl_texture_set_region (data->dst_tex,
|
CoglError *ignore = NULL;
|
||||||
src_x, src_y,
|
int rowstride = data->src_width * data->bpp;
|
||||||
dst_x, dst_y,
|
int offset = rowstride * src_y + src_x * data->bpp;
|
||||||
|
|
||||||
|
_cogl_texture_set_region (data->dst_tex,
|
||||||
width, height,
|
width, height,
|
||||||
data->src_width, data->src_height,
|
|
||||||
data->format,
|
data->format,
|
||||||
data->src_width * data->bpp,
|
rowstride,
|
||||||
data->image_data);
|
data->image_data + offset,
|
||||||
|
dst_x, dst_y,
|
||||||
|
0, /* level */
|
||||||
|
&ignore);
|
||||||
/* TODO: support chaining up errors during the blit */
|
/* TODO: support chaining up errors during the blit */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,13 +168,14 @@ struct _CoglDriverVtable
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
(* texture_2d_copy_from_framebuffer) (CoglTexture2D *tex_2d,
|
(* texture_2d_copy_from_framebuffer) (CoglTexture2D *tex_2d,
|
||||||
CoglFramebuffer *src_fb,
|
|
||||||
int dst_x,
|
|
||||||
int dst_y,
|
|
||||||
int src_x,
|
int src_x,
|
||||||
int src_y,
|
int src_y,
|
||||||
int width,
|
int width,
|
||||||
int height);
|
int height,
|
||||||
|
CoglFramebuffer *src_fb,
|
||||||
|
int dst_x,
|
||||||
|
int dst_y,
|
||||||
|
int level);
|
||||||
|
|
||||||
/* If the given texture has a corresponding OpenGL texture handle
|
/* If the given texture has a corresponding OpenGL texture handle
|
||||||
* then return that.
|
* then return that.
|
||||||
@ -196,13 +197,14 @@ struct _CoglDriverVtable
|
|||||||
*/
|
*/
|
||||||
CoglBool
|
CoglBool
|
||||||
(* texture_2d_copy_from_bitmap) (CoglTexture2D *tex_2d,
|
(* texture_2d_copy_from_bitmap) (CoglTexture2D *tex_2d,
|
||||||
CoglBitmap *bitmap,
|
|
||||||
int dst_x,
|
|
||||||
int dst_y,
|
|
||||||
int src_x,
|
int src_x,
|
||||||
int src_y,
|
int src_y,
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
|
CoglBitmap *bitmap,
|
||||||
|
int dst_x,
|
||||||
|
int dst_y,
|
||||||
|
int level,
|
||||||
CoglError **error);
|
CoglError **error);
|
||||||
|
|
||||||
/* Reads back the full contents of the given texture and write it to
|
/* Reads back the full contents of the given texture and write it to
|
||||||
|
@ -1595,6 +1595,9 @@ cogl_pipeline_set_layer_filters (CoglPipeline *pipeline,
|
|||||||
|
|
||||||
_COGL_RETURN_IF_FAIL (cogl_is_pipeline (pipeline));
|
_COGL_RETURN_IF_FAIL (cogl_is_pipeline (pipeline));
|
||||||
|
|
||||||
|
_COGL_RETURN_IF_FAIL (mag_filter == COGL_PIPELINE_FILTER_NEAREST ||
|
||||||
|
mag_filter == COGL_PIPELINE_FILTER_LINEAR);
|
||||||
|
|
||||||
/* Note: this will ensure that the layer exists, creating one if it
|
/* Note: this will ensure that the layer exists, creating one if it
|
||||||
* doesn't already.
|
* doesn't already.
|
||||||
*
|
*
|
||||||
|
@ -359,6 +359,11 @@ cogl_pipeline_get_n_layers (CoglPipeline *pipeline);
|
|||||||
* Changes the decimation and interpolation filters used when a texture is
|
* Changes the decimation and interpolation filters used when a texture is
|
||||||
* drawn at other scales than 100%.
|
* drawn at other scales than 100%.
|
||||||
*
|
*
|
||||||
|
* <note>It is an error to pass anything other than
|
||||||
|
* %COGL_PIPELINE_FILTER_NEAREST or %COGL_PIPELINE_FILTER_LINEAR as
|
||||||
|
* magnification filters since magnification doesn't ever need to
|
||||||
|
* reference values stored in the mipmap chain.</note>
|
||||||
|
*
|
||||||
* Since: 1.10
|
* Since: 1.10
|
||||||
* Stability: unstable
|
* Stability: unstable
|
||||||
*/
|
*/
|
||||||
|
@ -374,17 +374,32 @@ _cogl_sub_texture_set_region (CoglTexture *tex,
|
|||||||
int dst_y,
|
int dst_y,
|
||||||
int dst_width,
|
int dst_width,
|
||||||
int dst_height,
|
int dst_height,
|
||||||
|
int level,
|
||||||
CoglBitmap *bmp,
|
CoglBitmap *bmp,
|
||||||
CoglError **error)
|
CoglError **error)
|
||||||
{
|
{
|
||||||
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
|
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
|
||||||
|
|
||||||
|
if (level != 0)
|
||||||
|
{
|
||||||
|
int full_width = cogl_texture_get_width (sub_tex->full_texture);
|
||||||
|
int full_height = cogl_texture_get_width (sub_tex->full_texture);
|
||||||
|
|
||||||
|
_COGL_RETURN_VAL_IF_FAIL (sub_tex->sub_x == 0 &&
|
||||||
|
cogl_texture_get_width (tex) == full_width,
|
||||||
|
FALSE);
|
||||||
|
_COGL_RETURN_VAL_IF_FAIL (sub_tex->sub_y == 0 &&
|
||||||
|
cogl_texture_get_height (tex) == full_height,
|
||||||
|
FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
return _cogl_texture_set_region_from_bitmap (sub_tex->full_texture,
|
return _cogl_texture_set_region_from_bitmap (sub_tex->full_texture,
|
||||||
src_x, src_y,
|
src_x, src_y,
|
||||||
dst_x + sub_tex->sub_x,
|
|
||||||
dst_y + sub_tex->sub_y,
|
|
||||||
dst_width, dst_height,
|
dst_width, dst_height,
|
||||||
bmp,
|
bmp,
|
||||||
|
dst_x + sub_tex->sub_x,
|
||||||
|
dst_y + sub_tex->sub_y,
|
||||||
|
level,
|
||||||
error);
|
error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ struct _CoglTexture2D
|
|||||||
* of driver private state. */
|
* of driver private state. */
|
||||||
|
|
||||||
/* The internal format of the GL texture represented as a GL enum */
|
/* The internal format of the GL texture represented as a GL enum */
|
||||||
GLenum gl_format;
|
GLenum gl_internal_format;
|
||||||
/* The texture object number */
|
/* The texture object number */
|
||||||
GLuint gl_texture;
|
GLuint gl_texture;
|
||||||
GLenum gl_legacy_texobj_min_filter;
|
GLenum gl_legacy_texobj_min_filter;
|
||||||
@ -98,25 +98,27 @@ _cogl_texture_2d_externally_modified (CoglTexture *texture);
|
|||||||
/*
|
/*
|
||||||
* _cogl_texture_2d_copy_from_framebuffer:
|
* _cogl_texture_2d_copy_from_framebuffer:
|
||||||
* @texture: A #CoglTexture2D pointer
|
* @texture: A #CoglTexture2D pointer
|
||||||
* @src_fb: A source #CoglFramebuffer to copy from
|
|
||||||
* @dst_x: X-position to store the image within the texture
|
|
||||||
* @dst_y: Y-position to store the image within the texture
|
|
||||||
* @src_x: X-position to within the framebuffer to read from
|
* @src_x: X-position to within the framebuffer to read from
|
||||||
* @src_y: Y-position to within the framebuffer to read from
|
* @src_y: Y-position to within the framebuffer to read from
|
||||||
* @width: width of the rectangle to copy
|
* @width: width of the rectangle to copy
|
||||||
* @height: height of the rectangle to copy
|
* @height: height of the rectangle to copy
|
||||||
|
* @src_fb: A source #CoglFramebuffer to copy from
|
||||||
|
* @dst_x: X-position to store the image within the texture
|
||||||
|
* @dst_y: Y-position to store the image within the texture
|
||||||
|
* @level: The mipmap level of @texture to copy too
|
||||||
*
|
*
|
||||||
* This copies a portion of the given @src_fb into the
|
* This copies a portion of the given @src_fb into the
|
||||||
* texture.
|
* texture.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
_cogl_texture_2d_copy_from_framebuffer (CoglTexture2D *texture,
|
_cogl_texture_2d_copy_from_framebuffer (CoglTexture2D *texture,
|
||||||
CoglFramebuffer *src_fb,
|
|
||||||
int dst_x,
|
|
||||||
int dst_y,
|
|
||||||
int src_x,
|
int src_x,
|
||||||
int src_y,
|
int src_y,
|
||||||
int width,
|
int width,
|
||||||
int height);
|
int height,
|
||||||
|
CoglFramebuffer *src_fb,
|
||||||
|
int dst_x,
|
||||||
|
int dst_y,
|
||||||
|
int level);
|
||||||
|
|
||||||
#endif /* __COGL_TEXTURE_2D_PRIVATE_H */
|
#endif /* __COGL_TEXTURE_2D_PRIVATE_H */
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
#include "cogl-pipeline-opengl-private.h"
|
#include "cogl-pipeline-opengl-private.h"
|
||||||
#include "cogl-primitive-texture.h"
|
#include "cogl-primitive-texture.h"
|
||||||
#include "cogl-error-private.h"
|
#include "cogl-error-private.h"
|
||||||
|
#include "cogl-texture-gl-private.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -238,15 +239,16 @@ _cogl_texture_2d_sliced_set_waste (CoglTexture2DSliced *tex_2ds,
|
|||||||
if (!_cogl_texture_set_region_from_bitmap (COGL_TEXTURE (slice_tex),
|
if (!_cogl_texture_set_region_from_bitmap (COGL_TEXTURE (slice_tex),
|
||||||
0, /* src_x */
|
0, /* src_x */
|
||||||
0, /* src_y */
|
0, /* src_y */
|
||||||
|
x_span->waste, /* width */
|
||||||
|
/* height */
|
||||||
|
y_iter->intersect_end -
|
||||||
|
y_iter->intersect_start,
|
||||||
|
waste_bmp,
|
||||||
/* dst_x */
|
/* dst_x */
|
||||||
x_span->size - x_span->waste,
|
x_span->size - x_span->waste,
|
||||||
y_iter->intersect_start -
|
y_iter->intersect_start -
|
||||||
y_span->start, /* dst_y */
|
y_span->start, /* dst_y */
|
||||||
x_span->waste, /* dst_width */
|
0, /* level */
|
||||||
/* dst_height */
|
|
||||||
y_iter->intersect_end -
|
|
||||||
y_iter->intersect_start,
|
|
||||||
waste_bmp,
|
|
||||||
error))
|
error))
|
||||||
{
|
{
|
||||||
cogl_object_unref (waste_bmp);
|
cogl_object_unref (waste_bmp);
|
||||||
@ -298,14 +300,15 @@ _cogl_texture_2d_sliced_set_waste (CoglTexture2DSliced *tex_2ds,
|
|||||||
if (!_cogl_texture_set_region_from_bitmap (COGL_TEXTURE (slice_tex),
|
if (!_cogl_texture_set_region_from_bitmap (COGL_TEXTURE (slice_tex),
|
||||||
0, /* src_x */
|
0, /* src_x */
|
||||||
0, /* src_y */
|
0, /* src_y */
|
||||||
|
copy_width, /* width */
|
||||||
|
y_span->waste, /* height */
|
||||||
|
waste_bmp,
|
||||||
/* dst_x */
|
/* dst_x */
|
||||||
x_iter->intersect_start -
|
x_iter->intersect_start -
|
||||||
x_iter->pos,
|
x_iter->pos,
|
||||||
/* dst_y */
|
/* dst_y */
|
||||||
y_span->size - y_span->waste,
|
y_span->size - y_span->waste,
|
||||||
copy_width, /* dst_width */
|
0, /* level */
|
||||||
y_span->waste, /* dst_height */
|
|
||||||
waste_bmp,
|
|
||||||
error))
|
error))
|
||||||
{
|
{
|
||||||
cogl_object_unref (waste_bmp);
|
cogl_object_unref (waste_bmp);
|
||||||
@ -359,13 +362,14 @@ _cogl_texture_2d_sliced_upload_to_gl (CoglTexture2DSliced *tex_2ds,
|
|||||||
if (!_cogl_texture_set_region_from_bitmap (COGL_TEXTURE (slice_tex),
|
if (!_cogl_texture_set_region_from_bitmap (COGL_TEXTURE (slice_tex),
|
||||||
x_span->start, /* src x */
|
x_span->start, /* src x */
|
||||||
y_span->start, /* src y */
|
y_span->start, /* src y */
|
||||||
0, /* dst x */
|
|
||||||
0, /* dst y */
|
|
||||||
x_span->size -
|
x_span->size -
|
||||||
x_span->waste, /* width */
|
x_span->waste, /* width */
|
||||||
y_span->size -
|
y_span->size -
|
||||||
y_span->waste, /* height */
|
y_span->waste, /* height */
|
||||||
bmp,
|
bmp,
|
||||||
|
0, /* dst x */
|
||||||
|
0, /* dst y */
|
||||||
|
0, /* level */
|
||||||
error))
|
error))
|
||||||
{
|
{
|
||||||
if (waste_buf)
|
if (waste_buf)
|
||||||
@ -495,11 +499,12 @@ _cogl_texture_2d_sliced_upload_subregion_to_gl (CoglTexture2DSliced *tex_2ds,
|
|||||||
if (!_cogl_texture_set_region_from_bitmap (COGL_TEXTURE (slice_tex),
|
if (!_cogl_texture_set_region_from_bitmap (COGL_TEXTURE (slice_tex),
|
||||||
source_x,
|
source_x,
|
||||||
source_y,
|
source_y,
|
||||||
local_x, /* dst x */
|
|
||||||
local_y, /* dst y */
|
|
||||||
inter_w, /* width */
|
inter_w, /* width */
|
||||||
inter_h, /* height */
|
inter_h, /* height */
|
||||||
source_bmp,
|
source_bmp,
|
||||||
|
local_x, /* dst x */
|
||||||
|
local_y, /* dst y */
|
||||||
|
0, /* level */
|
||||||
error))
|
error))
|
||||||
{
|
{
|
||||||
if (waste_buf)
|
if (waste_buf)
|
||||||
@ -1286,6 +1291,7 @@ _cogl_texture_2d_sliced_set_region (CoglTexture *tex,
|
|||||||
int dst_y,
|
int dst_y,
|
||||||
int dst_width,
|
int dst_width,
|
||||||
int dst_height,
|
int dst_height,
|
||||||
|
int level,
|
||||||
CoglBitmap *bmp,
|
CoglBitmap *bmp,
|
||||||
CoglError **error)
|
CoglError **error)
|
||||||
{
|
{
|
||||||
|
@ -343,24 +343,26 @@ _cogl_texture_2d_externally_modified (CoglTexture *texture)
|
|||||||
|
|
||||||
void
|
void
|
||||||
_cogl_texture_2d_copy_from_framebuffer (CoglTexture2D *tex_2d,
|
_cogl_texture_2d_copy_from_framebuffer (CoglTexture2D *tex_2d,
|
||||||
CoglFramebuffer *src_fb,
|
|
||||||
int dst_x,
|
|
||||||
int dst_y,
|
|
||||||
int src_x,
|
int src_x,
|
||||||
int src_y,
|
int src_y,
|
||||||
int width,
|
int width,
|
||||||
int height)
|
int height,
|
||||||
|
CoglFramebuffer *src_fb,
|
||||||
|
int dst_x,
|
||||||
|
int dst_y,
|
||||||
|
int level)
|
||||||
{
|
{
|
||||||
CoglContext *ctx = COGL_TEXTURE (tex_2d)->context;
|
CoglContext *ctx = COGL_TEXTURE (tex_2d)->context;
|
||||||
|
|
||||||
ctx->driver_vtable->texture_2d_copy_from_framebuffer (tex_2d,
|
ctx->driver_vtable->texture_2d_copy_from_framebuffer (tex_2d,
|
||||||
src_fb,
|
|
||||||
dst_x,
|
|
||||||
dst_y,
|
|
||||||
src_x,
|
src_x,
|
||||||
src_y,
|
src_y,
|
||||||
width,
|
width,
|
||||||
height);
|
height,
|
||||||
|
src_fb,
|
||||||
|
dst_x,
|
||||||
|
dst_y,
|
||||||
|
level);
|
||||||
|
|
||||||
tex_2d->mipmaps_dirty = TRUE;
|
tex_2d->mipmaps_dirty = TRUE;
|
||||||
}
|
}
|
||||||
@ -479,6 +481,7 @@ _cogl_texture_2d_set_region (CoglTexture *tex,
|
|||||||
int dst_y,
|
int dst_y,
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
|
int level,
|
||||||
CoglBitmap *bmp,
|
CoglBitmap *bmp,
|
||||||
CoglError **error)
|
CoglError **error)
|
||||||
{
|
{
|
||||||
@ -486,13 +489,14 @@ _cogl_texture_2d_set_region (CoglTexture *tex,
|
|||||||
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
|
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
|
||||||
|
|
||||||
if (!ctx->driver_vtable->texture_2d_copy_from_bitmap (tex_2d,
|
if (!ctx->driver_vtable->texture_2d_copy_from_bitmap (tex_2d,
|
||||||
bmp,
|
|
||||||
dst_x,
|
|
||||||
dst_y,
|
|
||||||
src_x,
|
src_x,
|
||||||
src_y,
|
src_y,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
|
bmp,
|
||||||
|
dst_x,
|
||||||
|
dst_y,
|
||||||
|
level,
|
||||||
error))
|
error))
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -530,7 +534,7 @@ _cogl_texture_2d_get_format (CoglTexture *tex)
|
|||||||
static GLenum
|
static GLenum
|
||||||
_cogl_texture_2d_get_gl_format (CoglTexture *tex)
|
_cogl_texture_2d_get_gl_format (CoglTexture *tex)
|
||||||
{
|
{
|
||||||
return COGL_TEXTURE_2D (tex)->gl_format;
|
return COGL_TEXTURE_2D (tex)->gl_internal_format;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include "cogl-texture-private.h"
|
#include "cogl-texture-private.h"
|
||||||
#include "cogl-texture-3d-private.h"
|
#include "cogl-texture-3d-private.h"
|
||||||
#include "cogl-texture-3d.h"
|
#include "cogl-texture-3d.h"
|
||||||
|
#include "cogl-texture-gl-private.h"
|
||||||
#include "cogl-texture-driver.h"
|
#include "cogl-texture-driver.h"
|
||||||
#include "cogl-context-private.h"
|
#include "cogl-context-private.h"
|
||||||
#include "cogl-object-private.h"
|
#include "cogl-object-private.h"
|
||||||
@ -547,17 +548,18 @@ _cogl_texture_3d_pre_paint (CoglTexture *tex, CoglTexturePrePaintFlags flags)
|
|||||||
if ((flags & COGL_TEXTURE_NEEDS_MIPMAP) &&
|
if ((flags & COGL_TEXTURE_NEEDS_MIPMAP) &&
|
||||||
tex_3d->auto_mipmap && tex_3d->mipmaps_dirty)
|
tex_3d->auto_mipmap && tex_3d->mipmaps_dirty)
|
||||||
{
|
{
|
||||||
_cogl_bind_gl_texture_transient (GL_TEXTURE_3D,
|
|
||||||
tex_3d->gl_texture,
|
|
||||||
FALSE);
|
|
||||||
/* glGenerateMipmap is defined in the FBO extension. If it's not
|
/* glGenerateMipmap is defined in the FBO extension. If it's not
|
||||||
available we'll fallback to temporarily enabling
|
available we'll fallback to temporarily enabling
|
||||||
GL_GENERATE_MIPMAP and reuploading the first pixel */
|
GL_GENERATE_MIPMAP and reuploading the first pixel */
|
||||||
if (cogl_has_feature (ctx, COGL_FEATURE_ID_OFFSCREEN))
|
if (cogl_has_feature (ctx, COGL_FEATURE_ID_OFFSCREEN))
|
||||||
ctx->texture_driver->gl_generate_mipmaps (ctx, GL_TEXTURE_3D);
|
_cogl_texture_gl_generate_mipmaps (tex);
|
||||||
#if defined (HAVE_COGL_GL) || defined (HAVE_COGL_GLES)
|
#if defined (HAVE_COGL_GL) || defined (HAVE_COGL_GLES)
|
||||||
else if (ctx->driver != COGL_DRIVER_GLES2)
|
else if (ctx->driver != COGL_DRIVER_GLES2)
|
||||||
{
|
{
|
||||||
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_3D,
|
||||||
|
tex_3d->gl_texture,
|
||||||
|
FALSE);
|
||||||
|
|
||||||
GE( ctx, glTexParameteri (GL_TEXTURE_3D,
|
GE( ctx, glTexParameteri (GL_TEXTURE_3D,
|
||||||
GL_GENERATE_MIPMAP,
|
GL_GENERATE_MIPMAP,
|
||||||
GL_TRUE) );
|
GL_TRUE) );
|
||||||
@ -596,6 +598,7 @@ _cogl_texture_3d_set_region (CoglTexture *tex,
|
|||||||
int dst_y,
|
int dst_y,
|
||||||
int dst_width,
|
int dst_width,
|
||||||
int dst_height,
|
int dst_height,
|
||||||
|
int level,
|
||||||
CoglBitmap *bmp,
|
CoglBitmap *bmp,
|
||||||
CoglError **error)
|
CoglError **error)
|
||||||
{
|
{
|
||||||
|
@ -65,8 +65,7 @@ struct _CoglTextureDriver
|
|||||||
*/
|
*/
|
||||||
CoglBool
|
CoglBool
|
||||||
(* upload_subregion_to_gl) (CoglContext *ctx,
|
(* upload_subregion_to_gl) (CoglContext *ctx,
|
||||||
GLenum gl_target,
|
CoglTexture *texture,
|
||||||
GLuint gl_handle,
|
|
||||||
CoglBool is_foreign,
|
CoglBool is_foreign,
|
||||||
int src_x,
|
int src_x,
|
||||||
int src_y,
|
int src_y,
|
||||||
@ -74,6 +73,7 @@ struct _CoglTextureDriver
|
|||||||
int dst_y,
|
int dst_y,
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
|
int level,
|
||||||
CoglBitmap *source_bmp,
|
CoglBitmap *source_bmp,
|
||||||
GLuint source_gl_format,
|
GLuint source_gl_format,
|
||||||
GLuint source_gl_type,
|
GLuint source_gl_type,
|
||||||
@ -182,15 +182,6 @@ struct _CoglTextureDriver
|
|||||||
(* allows_foreign_gl_target) (CoglContext *ctx,
|
(* allows_foreign_gl_target) (CoglContext *ctx,
|
||||||
GLenum gl_target);
|
GLenum gl_target);
|
||||||
|
|
||||||
/*
|
|
||||||
* glGenerateMipmap semantics may need to be emulated for some
|
|
||||||
* drivers. E.g. by enabling auto mipmap generation an re-loading a
|
|
||||||
* number of known texels.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
(* gl_generate_mipmaps) (CoglContext *ctx,
|
|
||||||
GLenum texture_target);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The driver may impose constraints on what formats can be used to store
|
* The driver may impose constraints on what formats can be used to store
|
||||||
* texture data read from textures. For example GLES currently only supports
|
* texture data read from textures. For example GLES currently only supports
|
||||||
|
@ -72,6 +72,7 @@ struct _CoglTextureVtable
|
|||||||
int dst_y,
|
int dst_y,
|
||||||
int dst_width,
|
int dst_width,
|
||||||
int dst_height,
|
int dst_height,
|
||||||
|
int level,
|
||||||
CoglBitmap *bitmap,
|
CoglBitmap *bitmap,
|
||||||
CoglError **error);
|
CoglError **error);
|
||||||
|
|
||||||
@ -142,6 +143,7 @@ struct _CoglTexture
|
|||||||
CoglObject _parent;
|
CoglObject _parent;
|
||||||
CoglContext *context;
|
CoglContext *context;
|
||||||
GList *framebuffers;
|
GList *framebuffers;
|
||||||
|
int max_level;
|
||||||
const CoglTextureVtable *vtable;
|
const CoglTextureVtable *vtable;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -276,6 +278,18 @@ _cogl_texture_spans_foreach_in_region (CoglSpan *x_spans,
|
|||||||
CoglTextureType
|
CoglTextureType
|
||||||
_cogl_texture_get_type (CoglTexture *texture);
|
_cogl_texture_get_type (CoglTexture *texture);
|
||||||
|
|
||||||
|
CoglBool
|
||||||
|
_cogl_texture_set_region (CoglTexture *texture,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
CoglPixelFormat format,
|
||||||
|
int rowstride,
|
||||||
|
const uint8_t *data,
|
||||||
|
int dst_x,
|
||||||
|
int dst_y,
|
||||||
|
int level,
|
||||||
|
CoglError **error);
|
||||||
|
|
||||||
CoglTexture *
|
CoglTexture *
|
||||||
_cogl_texture_new_from_bitmap (CoglBitmap *bitmap,
|
_cogl_texture_new_from_bitmap (CoglBitmap *bitmap,
|
||||||
CoglTextureFlags flags,
|
CoglTextureFlags flags,
|
||||||
@ -286,15 +300,26 @@ CoglBool
|
|||||||
_cogl_texture_set_region_from_bitmap (CoglTexture *texture,
|
_cogl_texture_set_region_from_bitmap (CoglTexture *texture,
|
||||||
int src_x,
|
int src_x,
|
||||||
int src_y,
|
int src_y,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
CoglBitmap *bmp,
|
||||||
int dst_x,
|
int dst_x,
|
||||||
int dst_y,
|
int dst_y,
|
||||||
unsigned int dst_width,
|
int level,
|
||||||
unsigned int dst_height,
|
|
||||||
CoglBitmap *bmp,
|
|
||||||
CoglError **error);
|
CoglError **error);
|
||||||
|
|
||||||
CoglBool
|
CoglBool
|
||||||
_cogl_texture_needs_premult_conversion (CoglPixelFormat src_format,
|
_cogl_texture_needs_premult_conversion (CoglPixelFormat src_format,
|
||||||
CoglPixelFormat dst_format);
|
CoglPixelFormat dst_format);
|
||||||
|
|
||||||
|
int
|
||||||
|
_cogl_texture_get_n_levels (CoglTexture *texture);
|
||||||
|
|
||||||
|
void
|
||||||
|
_cogl_texture_get_level_size (CoglTexture *texture,
|
||||||
|
int level,
|
||||||
|
int *width,
|
||||||
|
int *height,
|
||||||
|
int *depth);
|
||||||
|
|
||||||
#endif /* __COGL_TEXTURE_PRIVATE_H */
|
#endif /* __COGL_TEXTURE_PRIVATE_H */
|
||||||
|
@ -554,10 +554,10 @@ _cogl_texture_rectangle_set_region (CoglTexture *tex,
|
|||||||
int dst_y,
|
int dst_y,
|
||||||
int dst_width,
|
int dst_width,
|
||||||
int dst_height,
|
int dst_height,
|
||||||
|
int level,
|
||||||
CoglBitmap *bmp,
|
CoglBitmap *bmp,
|
||||||
CoglError **error)
|
CoglError **error)
|
||||||
{
|
{
|
||||||
CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
|
|
||||||
GLenum gl_format;
|
GLenum gl_format;
|
||||||
GLenum gl_type;
|
GLenum gl_type;
|
||||||
CoglContext *ctx = tex->context;
|
CoglContext *ctx = tex->context;
|
||||||
@ -576,12 +576,12 @@ _cogl_texture_rectangle_set_region (CoglTexture *tex,
|
|||||||
/* Send data to GL */
|
/* Send data to GL */
|
||||||
status =
|
status =
|
||||||
ctx->texture_driver->upload_subregion_to_gl (ctx,
|
ctx->texture_driver->upload_subregion_to_gl (ctx,
|
||||||
GL_TEXTURE_RECTANGLE_ARB,
|
tex,
|
||||||
tex_rect->gl_texture,
|
|
||||||
FALSE,
|
FALSE,
|
||||||
src_x, src_y,
|
src_x, src_y,
|
||||||
dst_x, dst_y,
|
dst_x, dst_y,
|
||||||
dst_width, dst_height,
|
dst_width, dst_height,
|
||||||
|
level,
|
||||||
bmp,
|
bmp,
|
||||||
gl_format,
|
gl_format,
|
||||||
gl_type,
|
gl_type,
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
#include "cogl-texture-2d-sliced-private.h"
|
#include "cogl-texture-2d-sliced-private.h"
|
||||||
#include "cogl-texture-2d-private.h"
|
#include "cogl-texture-2d-private.h"
|
||||||
#include "cogl-texture-2d-gl.h"
|
#include "cogl-texture-2d-gl.h"
|
||||||
|
#include "cogl-texture-3d-private.h"
|
||||||
#include "cogl-texture-rectangle-private.h"
|
#include "cogl-texture-rectangle-private.h"
|
||||||
#include "cogl-sub-texture-private.h"
|
#include "cogl-sub-texture-private.h"
|
||||||
#include "cogl-atlas-texture-private.h"
|
#include "cogl-atlas-texture-private.h"
|
||||||
@ -134,6 +135,7 @@ _cogl_texture_init (CoglTexture *texture,
|
|||||||
const CoglTextureVtable *vtable)
|
const CoglTextureVtable *vtable)
|
||||||
{
|
{
|
||||||
texture->context = context;
|
texture->context = context;
|
||||||
|
texture->max_level = 0;
|
||||||
texture->vtable = vtable;
|
texture->vtable = vtable;
|
||||||
texture->framebuffers = NULL;
|
texture->framebuffers = NULL;
|
||||||
}
|
}
|
||||||
@ -328,6 +330,61 @@ cogl_texture_get_max_waste (CoglTexture *texture)
|
|||||||
return texture->vtable->get_max_waste (texture);
|
return texture->vtable->get_max_waste (texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
_cogl_texture_get_n_levels (CoglTexture *texture)
|
||||||
|
{
|
||||||
|
int width = cogl_texture_get_width (texture);
|
||||||
|
int height = cogl_texture_get_height (texture);
|
||||||
|
int max_dimension = MAX (width, height);
|
||||||
|
|
||||||
|
if (cogl_is_texture_3d (texture))
|
||||||
|
{
|
||||||
|
CoglTexture3D *tex_3d = COGL_TEXTURE_3D (texture);
|
||||||
|
max_dimension = MAX (max_dimension, tex_3d->depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _cogl_util_fls (max_dimension);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_cogl_texture_get_level_size (CoglTexture *texture,
|
||||||
|
int level,
|
||||||
|
int *width,
|
||||||
|
int *height,
|
||||||
|
int *depth)
|
||||||
|
{
|
||||||
|
int current_width = cogl_texture_get_width (texture);
|
||||||
|
int current_height = cogl_texture_get_height (texture);
|
||||||
|
int current_depth;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (cogl_is_texture_3d (texture))
|
||||||
|
{
|
||||||
|
CoglTexture3D *tex_3d = COGL_TEXTURE_3D (texture);
|
||||||
|
current_depth = tex_3d->depth;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
current_depth = 0;
|
||||||
|
|
||||||
|
/* NB: The OpenGL spec (like D3D) uses a floor() convention to
|
||||||
|
* round down the size of a mipmap level when dividing the size
|
||||||
|
* of the previous level results in a fraction...
|
||||||
|
*/
|
||||||
|
for (i = 0; i < level; i++)
|
||||||
|
{
|
||||||
|
current_width = MAX (1, current_width >> 1);
|
||||||
|
current_height = MAX (1, current_height >> 1);
|
||||||
|
current_depth = MAX (1, current_depth >> 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (width)
|
||||||
|
*width = current_width;
|
||||||
|
if (height)
|
||||||
|
*height = current_height;
|
||||||
|
if (depth)
|
||||||
|
*depth = current_depth;
|
||||||
|
}
|
||||||
|
|
||||||
CoglBool
|
CoglBool
|
||||||
cogl_texture_is_sliced (CoglTexture *texture)
|
cogl_texture_is_sliced (CoglTexture *texture)
|
||||||
{
|
{
|
||||||
@ -399,22 +456,21 @@ CoglBool
|
|||||||
_cogl_texture_set_region_from_bitmap (CoglTexture *texture,
|
_cogl_texture_set_region_from_bitmap (CoglTexture *texture,
|
||||||
int src_x,
|
int src_x,
|
||||||
int src_y,
|
int src_y,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
CoglBitmap *bmp,
|
||||||
int dst_x,
|
int dst_x,
|
||||||
int dst_y,
|
int dst_y,
|
||||||
unsigned int dst_width,
|
int level,
|
||||||
unsigned int dst_height,
|
|
||||||
CoglBitmap *bmp,
|
|
||||||
CoglError **error)
|
CoglError **error)
|
||||||
{
|
{
|
||||||
CoglBool ret;
|
|
||||||
|
|
||||||
_COGL_RETURN_VAL_IF_FAIL ((cogl_bitmap_get_width (bmp) - src_x)
|
_COGL_RETURN_VAL_IF_FAIL ((cogl_bitmap_get_width (bmp) - src_x)
|
||||||
>= dst_width, FALSE);
|
>= width, FALSE);
|
||||||
_COGL_RETURN_VAL_IF_FAIL ((cogl_bitmap_get_height (bmp) - src_y)
|
_COGL_RETURN_VAL_IF_FAIL ((cogl_bitmap_get_height (bmp) - src_y)
|
||||||
>= dst_height, FALSE);
|
>= height, FALSE);
|
||||||
|
|
||||||
/* Shortcut out early if the image is empty */
|
/* Shortcut out early if the image is empty */
|
||||||
if (dst_width == 0 || dst_height == 0)
|
if (width == 0 || height == 0)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
/* Note that we don't prepare the bitmap for upload here because
|
/* Note that we don't prepare the bitmap for upload here because
|
||||||
@ -424,14 +480,13 @@ _cogl_texture_set_region_from_bitmap (CoglTexture *texture,
|
|||||||
always stored in an RGBA texture even if the texture format is
|
always stored in an RGBA texture even if the texture format is
|
||||||
advertised as RGB. */
|
advertised as RGB. */
|
||||||
|
|
||||||
ret = texture->vtable->set_region (texture,
|
return texture->vtable->set_region (texture,
|
||||||
src_x, src_y,
|
src_x, src_y,
|
||||||
dst_x, dst_y,
|
dst_x, dst_y,
|
||||||
dst_width, dst_height,
|
width, height,
|
||||||
|
level,
|
||||||
bmp,
|
bmp,
|
||||||
error);
|
error);
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CoglBool
|
CoglBool
|
||||||
@ -448,9 +503,10 @@ cogl_texture_set_region_from_bitmap (CoglTexture *texture,
|
|||||||
CoglBool status =
|
CoglBool status =
|
||||||
_cogl_texture_set_region_from_bitmap (texture,
|
_cogl_texture_set_region_from_bitmap (texture,
|
||||||
src_x, src_y,
|
src_x, src_y,
|
||||||
dst_x, dst_y,
|
|
||||||
dst_width, dst_height,
|
dst_width, dst_height,
|
||||||
bitmap,
|
bitmap,
|
||||||
|
dst_x, dst_y,
|
||||||
|
0, /* level */
|
||||||
&ignore_error);
|
&ignore_error);
|
||||||
|
|
||||||
if (!status)
|
if (!status)
|
||||||
@ -458,31 +514,23 @@ cogl_texture_set_region_from_bitmap (CoglTexture *texture,
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CoglBool
|
CoglBool
|
||||||
_cogl_texture_set_region (CoglTexture *texture,
|
_cogl_texture_set_region (CoglTexture *texture,
|
||||||
int src_x,
|
|
||||||
int src_y,
|
|
||||||
int dst_x,
|
|
||||||
int dst_y,
|
|
||||||
unsigned int dst_width,
|
|
||||||
unsigned int dst_height,
|
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
CoglPixelFormat format,
|
CoglPixelFormat format,
|
||||||
unsigned int rowstride,
|
int rowstride,
|
||||||
const uint8_t *data,
|
const uint8_t *data,
|
||||||
|
int dst_x,
|
||||||
|
int dst_y,
|
||||||
|
int level,
|
||||||
CoglError **error)
|
CoglError **error)
|
||||||
{
|
{
|
||||||
CoglContext *ctx = texture->context;
|
CoglContext *ctx = texture->context;
|
||||||
CoglBitmap *source_bmp;
|
CoglBitmap *source_bmp;
|
||||||
CoglBool ret;
|
CoglBool ret;
|
||||||
|
|
||||||
_COGL_RETURN_VAL_IF_FAIL ((width - src_x) >= dst_width, FALSE);
|
_COGL_RETURN_VAL_IF_FAIL (format != COGL_PIXEL_FORMAT_ANY, FALSE);
|
||||||
_COGL_RETURN_VAL_IF_FAIL ((height - src_y) >= dst_height, FALSE);
|
|
||||||
|
|
||||||
/* Check for valid format */
|
|
||||||
if (format == COGL_PIXEL_FORMAT_ANY)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
/* Rowstride from width if none specified */
|
/* Rowstride from width if none specified */
|
||||||
if (rowstride == 0)
|
if (rowstride == 0)
|
||||||
@ -496,10 +544,11 @@ _cogl_texture_set_region (CoglTexture *texture,
|
|||||||
(uint8_t *) data);
|
(uint8_t *) data);
|
||||||
|
|
||||||
ret = _cogl_texture_set_region_from_bitmap (texture,
|
ret = _cogl_texture_set_region_from_bitmap (texture,
|
||||||
src_x, src_y,
|
0, 0,
|
||||||
dst_x, dst_y,
|
width, height,
|
||||||
dst_width, dst_height,
|
|
||||||
source_bmp,
|
source_bmp,
|
||||||
|
dst_x, dst_y,
|
||||||
|
level,
|
||||||
error);
|
error);
|
||||||
|
|
||||||
cogl_object_unref (source_bmp);
|
cogl_object_unref (source_bmp);
|
||||||
@ -522,14 +571,25 @@ cogl_texture_set_region (CoglTexture *texture,
|
|||||||
const uint8_t *data)
|
const uint8_t *data)
|
||||||
{
|
{
|
||||||
CoglError *ignore_error = NULL;
|
CoglError *ignore_error = NULL;
|
||||||
CoglBool status = _cogl_texture_set_region (texture,
|
const uint8_t *first_pixel;
|
||||||
src_x, src_y,
|
int bytes_per_pixel = _cogl_pixel_format_get_bytes_per_pixel (format);
|
||||||
dst_x, dst_y,
|
CoglBool status;
|
||||||
dst_width, dst_height,
|
|
||||||
width, height,
|
/* Rowstride from width if none specified */
|
||||||
|
if (rowstride == 0)
|
||||||
|
rowstride = bytes_per_pixel * width;
|
||||||
|
|
||||||
|
first_pixel = data + rowstride * src_y + bytes_per_pixel * src_x;
|
||||||
|
|
||||||
|
status = _cogl_texture_set_region (texture,
|
||||||
|
dst_width,
|
||||||
|
dst_height,
|
||||||
format,
|
format,
|
||||||
rowstride,
|
rowstride,
|
||||||
data,
|
first_pixel,
|
||||||
|
dst_x,
|
||||||
|
dst_y,
|
||||||
|
0,
|
||||||
&ignore_error);
|
&ignore_error);
|
||||||
if (!status)
|
if (!status)
|
||||||
cogl_error_free (ignore_error);
|
cogl_error_free (ignore_error);
|
||||||
|
@ -124,6 +124,7 @@ _cogl_util_one_at_a_time_mix (unsigned int hash);
|
|||||||
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
|
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
|
||||||
#define COGL_UTIL_HAVE_BUILTIN_FFSL
|
#define COGL_UTIL_HAVE_BUILTIN_FFSL
|
||||||
#define COGL_UTIL_HAVE_BUILTIN_POPCOUNTL
|
#define COGL_UTIL_HAVE_BUILTIN_POPCOUNTL
|
||||||
|
#define COGL_UTIL_HAVE_BUILTIN_CLZ
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* The 'ffs' function is part of C99 so it isn't always available */
|
/* The 'ffs' function is part of C99 so it isn't always available */
|
||||||
@ -148,6 +149,24 @@ int
|
|||||||
_cogl_util_ffsl_wrapper (long int num);
|
_cogl_util_ffsl_wrapper (long int num);
|
||||||
#endif /* COGL_UTIL_HAVE_BUILTIN_FFSL */
|
#endif /* COGL_UTIL_HAVE_BUILTIN_FFSL */
|
||||||
|
|
||||||
|
static inline unsigned int
|
||||||
|
_cogl_util_fls (unsigned int n)
|
||||||
|
{
|
||||||
|
#ifdef COGL_UTIL_HAVE_BUILTIN_CLZ
|
||||||
|
return n == 0 ? 0 : sizeof (unsigned int) * 8 - __builtin_clz (n);
|
||||||
|
#else
|
||||||
|
unsigned int v = 1;
|
||||||
|
|
||||||
|
if (n == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
while (n >>= 1)
|
||||||
|
v++;
|
||||||
|
|
||||||
|
return v;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef COGL_UTIL_HAVE_BUILTIN_POPCOUNTL
|
#ifdef COGL_UTIL_HAVE_BUILTIN_POPCOUNTL
|
||||||
#define _cogl_util_popcountl __builtin_popcountl
|
#define _cogl_util_popcountl __builtin_popcountl
|
||||||
#else
|
#else
|
||||||
|
@ -79,13 +79,14 @@ _cogl_texture_2d_gl_flush_legacy_texobj_wrap_modes (CoglTexture *tex,
|
|||||||
|
|
||||||
void
|
void
|
||||||
_cogl_texture_2d_gl_copy_from_framebuffer (CoglTexture2D *tex_2d,
|
_cogl_texture_2d_gl_copy_from_framebuffer (CoglTexture2D *tex_2d,
|
||||||
CoglFramebuffer *src_fb,
|
|
||||||
int dst_x,
|
|
||||||
int dst_y,
|
|
||||||
int src_x,
|
int src_x,
|
||||||
int src_y,
|
int src_y,
|
||||||
int width,
|
int width,
|
||||||
int height);
|
int height,
|
||||||
|
CoglFramebuffer *src_fb,
|
||||||
|
int dst_x,
|
||||||
|
int dst_y,
|
||||||
|
int level);
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
_cogl_texture_2d_gl_get_gl_handle (CoglTexture2D *tex_2d);
|
_cogl_texture_2d_gl_get_gl_handle (CoglTexture2D *tex_2d);
|
||||||
@ -95,13 +96,14 @@ _cogl_texture_2d_gl_generate_mipmap (CoglTexture2D *tex_2d);
|
|||||||
|
|
||||||
CoglBool
|
CoglBool
|
||||||
_cogl_texture_2d_gl_copy_from_bitmap (CoglTexture2D *tex_2d,
|
_cogl_texture_2d_gl_copy_from_bitmap (CoglTexture2D *tex_2d,
|
||||||
CoglBitmap *bitmap,
|
|
||||||
int dst_x,
|
|
||||||
int dst_y,
|
|
||||||
int src_x,
|
int src_x,
|
||||||
int src_y,
|
int src_y,
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
|
CoglBitmap *bitmap,
|
||||||
|
int dst_x,
|
||||||
|
int dst_y,
|
||||||
|
int level,
|
||||||
CoglError **error);
|
CoglError **error);
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include "cogl-texture-2d-gl.h"
|
#include "cogl-texture-2d-gl.h"
|
||||||
#include "cogl-texture-2d-gl-private.h"
|
#include "cogl-texture-2d-gl-private.h"
|
||||||
#include "cogl-texture-2d-private.h"
|
#include "cogl-texture-2d-private.h"
|
||||||
|
#include "cogl-texture-gl-private.h"
|
||||||
#include "cogl-pipeline-opengl-private.h"
|
#include "cogl-pipeline-opengl-private.h"
|
||||||
#include "cogl-error-private.h"
|
#include "cogl-error-private.h"
|
||||||
#include "cogl-util-gl-private.h"
|
#include "cogl-util-gl-private.h"
|
||||||
@ -112,6 +113,9 @@ _cogl_texture_2d_gl_new_with_size (CoglContext *ctx,
|
|||||||
|
|
||||||
tex_2d->gl_texture =
|
tex_2d->gl_texture =
|
||||||
ctx->texture_driver->gen (ctx, GL_TEXTURE_2D, internal_format);
|
ctx->texture_driver->gen (ctx, GL_TEXTURE_2D, internal_format);
|
||||||
|
|
||||||
|
tex_2d->gl_internal_format = gl_intformat;
|
||||||
|
|
||||||
_cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
|
||||||
tex_2d->gl_texture,
|
tex_2d->gl_texture,
|
||||||
tex_2d->is_foreign);
|
tex_2d->is_foreign);
|
||||||
@ -205,7 +209,7 @@ _cogl_texture_2d_gl_new_from_bitmap (CoglBitmap *bmp,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
tex_2d->gl_format = gl_intformat;
|
tex_2d->gl_internal_format = gl_intformat;
|
||||||
|
|
||||||
cogl_object_unref (dst_bmp);
|
cogl_object_unref (dst_bmp);
|
||||||
|
|
||||||
@ -441,7 +445,7 @@ cogl_texture_2d_new_from_foreign (CoglContext *ctx,
|
|||||||
tex_2d->format = format;
|
tex_2d->format = format;
|
||||||
|
|
||||||
tex_2d->gl_texture = gl_handle;
|
tex_2d->gl_texture = gl_handle;
|
||||||
tex_2d->gl_format = gl_int_format;
|
tex_2d->gl_internal_format = gl_int_format;
|
||||||
|
|
||||||
/* Unknown filter */
|
/* Unknown filter */
|
||||||
tex_2d->gl_legacy_texobj_min_filter = GL_FALSE;
|
tex_2d->gl_legacy_texobj_min_filter = GL_FALSE;
|
||||||
@ -452,13 +456,14 @@ cogl_texture_2d_new_from_foreign (CoglContext *ctx,
|
|||||||
|
|
||||||
void
|
void
|
||||||
_cogl_texture_2d_gl_copy_from_framebuffer (CoglTexture2D *tex_2d,
|
_cogl_texture_2d_gl_copy_from_framebuffer (CoglTexture2D *tex_2d,
|
||||||
CoglFramebuffer *src_fb,
|
|
||||||
int dst_x,
|
|
||||||
int dst_y,
|
|
||||||
int src_x,
|
int src_x,
|
||||||
int src_y,
|
int src_y,
|
||||||
int width,
|
int width,
|
||||||
int height)
|
int height,
|
||||||
|
CoglFramebuffer *src_fb,
|
||||||
|
int dst_x,
|
||||||
|
int dst_y,
|
||||||
|
int level)
|
||||||
{
|
{
|
||||||
CoglContext *ctx = COGL_TEXTURE (tex_2d)->context;
|
CoglContext *ctx = COGL_TEXTURE (tex_2d)->context;
|
||||||
|
|
||||||
@ -492,18 +497,18 @@ _cogl_texture_2d_gl_generate_mipmap (CoglTexture2D *tex_2d)
|
|||||||
{
|
{
|
||||||
CoglContext *ctx = COGL_TEXTURE (tex_2d)->context;
|
CoglContext *ctx = COGL_TEXTURE (tex_2d)->context;
|
||||||
|
|
||||||
_cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
|
|
||||||
tex_2d->gl_texture,
|
|
||||||
tex_2d->is_foreign);
|
|
||||||
|
|
||||||
/* glGenerateMipmap is defined in the FBO extension. If it's not
|
/* glGenerateMipmap is defined in the FBO extension. If it's not
|
||||||
available we'll fallback to temporarily enabling
|
available we'll fallback to temporarily enabling
|
||||||
GL_GENERATE_MIPMAP and reuploading the first pixel */
|
GL_GENERATE_MIPMAP and reuploading the first pixel */
|
||||||
if (cogl_has_feature (ctx, COGL_FEATURE_ID_OFFSCREEN))
|
if (cogl_has_feature (ctx, COGL_FEATURE_ID_OFFSCREEN))
|
||||||
ctx->texture_driver->gl_generate_mipmaps (ctx, GL_TEXTURE_2D);
|
_cogl_texture_gl_generate_mipmaps (COGL_TEXTURE (tex_2d));
|
||||||
#if defined(HAVE_COGL_GLES) || defined(HAVE_COGL_GL)
|
#if defined(HAVE_COGL_GLES) || defined(HAVE_COGL_GL)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
|
||||||
|
tex_2d->gl_texture,
|
||||||
|
tex_2d->is_foreign);
|
||||||
|
|
||||||
GE( ctx, glTexParameteri (GL_TEXTURE_2D,
|
GE( ctx, glTexParameteri (GL_TEXTURE_2D,
|
||||||
GL_GENERATE_MIPMAP,
|
GL_GENERATE_MIPMAP,
|
||||||
GL_TRUE) );
|
GL_TRUE) );
|
||||||
@ -520,13 +525,14 @@ _cogl_texture_2d_gl_generate_mipmap (CoglTexture2D *tex_2d)
|
|||||||
|
|
||||||
CoglBool
|
CoglBool
|
||||||
_cogl_texture_2d_gl_copy_from_bitmap (CoglTexture2D *tex_2d,
|
_cogl_texture_2d_gl_copy_from_bitmap (CoglTexture2D *tex_2d,
|
||||||
CoglBitmap *bmp,
|
|
||||||
int dst_x,
|
|
||||||
int dst_y,
|
|
||||||
int src_x,
|
int src_x,
|
||||||
int src_y,
|
int src_y,
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
|
CoglBitmap *bmp,
|
||||||
|
int dst_x,
|
||||||
|
int dst_y,
|
||||||
|
int level,
|
||||||
CoglError **error)
|
CoglError **error)
|
||||||
{
|
{
|
||||||
CoglTexture *tex = COGL_TEXTURE (tex_2d);
|
CoglTexture *tex = COGL_TEXTURE (tex_2d);
|
||||||
@ -574,14 +580,13 @@ _cogl_texture_2d_gl_copy_from_bitmap (CoglTexture2D *tex_2d,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send data to GL */
|
|
||||||
status = ctx->texture_driver->upload_subregion_to_gl (ctx,
|
status = ctx->texture_driver->upload_subregion_to_gl (ctx,
|
||||||
GL_TEXTURE_2D,
|
tex,
|
||||||
tex_2d->gl_texture,
|
|
||||||
FALSE,
|
FALSE,
|
||||||
src_x, src_y,
|
src_x, src_y,
|
||||||
dst_x, dst_y,
|
dst_x, dst_y,
|
||||||
width, height,
|
width, height,
|
||||||
|
level,
|
||||||
bmp,
|
bmp,
|
||||||
gl_format,
|
gl_format,
|
||||||
gl_type,
|
gl_type,
|
||||||
@ -589,6 +594,8 @@ _cogl_texture_2d_gl_copy_from_bitmap (CoglTexture2D *tex_2d,
|
|||||||
|
|
||||||
cogl_object_unref (bmp);
|
cogl_object_unref (bmp);
|
||||||
|
|
||||||
|
_cogl_texture_gl_maybe_update_max_level (tex, level);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,4 +46,11 @@ _cogl_texture_gl_flush_legacy_texobj_filters (CoglTexture *texture,
|
|||||||
unsigned int min_filter,
|
unsigned int min_filter,
|
||||||
unsigned int mag_filter);
|
unsigned int mag_filter);
|
||||||
|
|
||||||
|
void
|
||||||
|
_cogl_texture_gl_maybe_update_max_level (CoglTexture *texture,
|
||||||
|
int max_level);
|
||||||
|
|
||||||
|
void
|
||||||
|
_cogl_texture_gl_generate_mipmaps (CoglTexture *texture);
|
||||||
|
|
||||||
#endif /* _COGL_TEXTURE_GL_PRIVATE_H_ */
|
#endif /* _COGL_TEXTURE_GL_PRIVATE_H_ */
|
||||||
|
@ -29,7 +29,9 @@
|
|||||||
#include "cogl-internal.h"
|
#include "cogl-internal.h"
|
||||||
#include "cogl-context-private.h"
|
#include "cogl-context-private.h"
|
||||||
#include "cogl-texture-gl-private.h"
|
#include "cogl-texture-gl-private.h"
|
||||||
|
#include "cogl-texture-3d-private.h"
|
||||||
#include "cogl-util.h"
|
#include "cogl-util.h"
|
||||||
|
#include "cogl-pipeline-opengl-private.h"
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
calculate_alignment (int rowstride)
|
calculate_alignment (int rowstride)
|
||||||
@ -92,3 +94,44 @@ _cogl_texture_gl_flush_legacy_texobj_filters (CoglTexture *texture,
|
|||||||
texture->vtable->gl_flush_legacy_texobj_filters (texture,
|
texture->vtable->gl_flush_legacy_texobj_filters (texture,
|
||||||
min_filter, mag_filter);
|
min_filter, mag_filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_cogl_texture_gl_maybe_update_max_level (CoglTexture *texture,
|
||||||
|
int max_level)
|
||||||
|
{
|
||||||
|
if (texture->max_level < max_level)
|
||||||
|
{
|
||||||
|
CoglContext *ctx = texture->context;
|
||||||
|
GLuint gl_handle;
|
||||||
|
GLenum gl_target;
|
||||||
|
|
||||||
|
cogl_texture_get_gl_texture (texture, &gl_handle, &gl_target);
|
||||||
|
|
||||||
|
texture->max_level = max_level;
|
||||||
|
|
||||||
|
_cogl_bind_gl_texture_transient (gl_target,
|
||||||
|
gl_handle,
|
||||||
|
_cogl_texture_is_foreign (texture));
|
||||||
|
|
||||||
|
GE( ctx, glTexParameteri (gl_target,
|
||||||
|
GL_TEXTURE_MAX_LEVEL, texture->max_level));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_cogl_texture_gl_generate_mipmaps (CoglTexture *texture)
|
||||||
|
{
|
||||||
|
CoglContext *ctx = texture->context;
|
||||||
|
int n_levels = _cogl_texture_get_n_levels (texture);
|
||||||
|
GLuint gl_handle;
|
||||||
|
GLenum gl_target;
|
||||||
|
|
||||||
|
_cogl_texture_gl_maybe_update_max_level (texture, n_levels - 1);
|
||||||
|
|
||||||
|
cogl_texture_get_gl_texture (texture, &gl_handle, &gl_target);
|
||||||
|
|
||||||
|
_cogl_bind_gl_texture_transient (gl_target,
|
||||||
|
gl_handle,
|
||||||
|
_cogl_texture_is_foreign (texture));
|
||||||
|
GE( ctx, glGenerateMipmap (gl_target) );
|
||||||
|
}
|
||||||
|
@ -67,6 +67,14 @@ _cogl_texture_driver_gen (CoglContext *ctx,
|
|||||||
{
|
{
|
||||||
case GL_TEXTURE_2D:
|
case GL_TEXTURE_2D:
|
||||||
case GL_TEXTURE_3D:
|
case GL_TEXTURE_3D:
|
||||||
|
/* In case automatic mipmap generation gets disabled for this
|
||||||
|
* texture but a minification filter depending on mipmap
|
||||||
|
* interpolation is selected then we initialize the max mipmap
|
||||||
|
* level to 0 so OpenGL will consider the texture storage to be
|
||||||
|
* "complete".
|
||||||
|
*/
|
||||||
|
GE( ctx, glTexParameteri (gl_target, GL_TEXTURE_MAX_LEVEL, 0));
|
||||||
|
|
||||||
/* GL_TEXTURE_MAG_FILTER defaults to GL_LINEAR, no need to set it */
|
/* GL_TEXTURE_MAG_FILTER defaults to GL_LINEAR, no need to set it */
|
||||||
GE( ctx, glTexParameteri (gl_target,
|
GE( ctx, glTexParameteri (gl_target,
|
||||||
GL_TEXTURE_MIN_FILTER,
|
GL_TEXTURE_MIN_FILTER,
|
||||||
@ -170,8 +178,7 @@ _cogl_texture_driver_prep_gl_for_pixels_download (CoglContext *ctx,
|
|||||||
|
|
||||||
static CoglBool
|
static CoglBool
|
||||||
_cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
|
_cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
|
||||||
GLenum gl_target,
|
CoglTexture *texture,
|
||||||
GLuint gl_handle,
|
|
||||||
CoglBool is_foreign,
|
CoglBool is_foreign,
|
||||||
int src_x,
|
int src_x,
|
||||||
int src_y,
|
int src_y,
|
||||||
@ -179,17 +186,24 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
|
|||||||
int dst_y,
|
int dst_y,
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
|
int level,
|
||||||
CoglBitmap *source_bmp,
|
CoglBitmap *source_bmp,
|
||||||
GLuint source_gl_format,
|
GLuint source_gl_format,
|
||||||
GLuint source_gl_type,
|
GLuint source_gl_type,
|
||||||
CoglError **error)
|
CoglError **error)
|
||||||
{
|
{
|
||||||
|
GLenum gl_target;
|
||||||
|
GLuint gl_handle;
|
||||||
uint8_t *data;
|
uint8_t *data;
|
||||||
CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
|
CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
|
||||||
int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
|
int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
|
||||||
GLenum gl_error;
|
GLenum gl_error;
|
||||||
CoglBool status = TRUE;
|
CoglBool status = TRUE;
|
||||||
CoglError *internal_error = NULL;
|
CoglError *internal_error = NULL;
|
||||||
|
int level_width;
|
||||||
|
int level_height;
|
||||||
|
|
||||||
|
cogl_texture_get_gl_texture (texture, &gl_handle, &gl_target);
|
||||||
|
|
||||||
data = _cogl_bitmap_gl_bind (source_bmp, COGL_BUFFER_ACCESS_READ, 0, &internal_error);
|
data = _cogl_bitmap_gl_bind (source_bmp, COGL_BUFFER_ACCESS_READ, 0, &internal_error);
|
||||||
|
|
||||||
@ -216,12 +230,58 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
|
|||||||
while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
|
while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
|
||||||
;
|
;
|
||||||
|
|
||||||
ctx->glTexSubImage2D (gl_target, 0,
|
_cogl_texture_get_level_size (texture,
|
||||||
|
level,
|
||||||
|
&level_width,
|
||||||
|
&level_height,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
if (level_width == width && level_height == height)
|
||||||
|
{
|
||||||
|
/* GL gets upset if you use glTexSubImage2D to initialize the
|
||||||
|
* contents of a mipmap level so we make sure to use
|
||||||
|
* glTexImage2D if we are uploading a full mipmap level.
|
||||||
|
*/
|
||||||
|
ctx->glTexImage2D (gl_target,
|
||||||
|
level,
|
||||||
|
_cogl_texture_get_gl_format (texture),
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
0,
|
||||||
|
source_gl_format,
|
||||||
|
source_gl_type,
|
||||||
|
data);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* GL gets upset if you use glTexSubImage2D to initialize the
|
||||||
|
* contents of a mipmap level so if this is the first time
|
||||||
|
* we've seen a request to upload to this level we call
|
||||||
|
* glTexImage2D first to assert that the storage for this
|
||||||
|
* level exists.
|
||||||
|
*/
|
||||||
|
if (texture->max_level < level)
|
||||||
|
{
|
||||||
|
ctx->glTexImage2D (gl_target,
|
||||||
|
level,
|
||||||
|
_cogl_texture_get_gl_format (texture),
|
||||||
|
level_width,
|
||||||
|
level_height,
|
||||||
|
0,
|
||||||
|
source_gl_format,
|
||||||
|
source_gl_type,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->glTexSubImage2D (gl_target,
|
||||||
|
level,
|
||||||
dst_x, dst_y,
|
dst_x, dst_y,
|
||||||
width, height,
|
width, height,
|
||||||
source_gl_format,
|
source_gl_format,
|
||||||
source_gl_type,
|
source_gl_type,
|
||||||
data);
|
data);
|
||||||
|
}
|
||||||
|
|
||||||
if (_cogl_gl_util_catch_out_of_memory (ctx, error))
|
if (_cogl_gl_util_catch_out_of_memory (ctx, error))
|
||||||
status = FALSE;
|
status = FALSE;
|
||||||
@ -442,13 +502,6 @@ _cogl_texture_driver_allows_foreign_gl_target (CoglContext *ctx,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
_cogl_texture_driver_gl_generate_mipmaps (CoglContext *ctx,
|
|
||||||
GLenum gl_target)
|
|
||||||
{
|
|
||||||
GE( ctx, glGenerateMipmap (gl_target) );
|
|
||||||
}
|
|
||||||
|
|
||||||
static CoglPixelFormat
|
static CoglPixelFormat
|
||||||
_cogl_texture_driver_find_best_gl_get_data_format
|
_cogl_texture_driver_find_best_gl_get_data_format
|
||||||
(CoglContext *context,
|
(CoglContext *context,
|
||||||
@ -477,6 +530,5 @@ _cogl_texture_driver_gl =
|
|||||||
_cogl_texture_driver_size_supported_3d,
|
_cogl_texture_driver_size_supported_3d,
|
||||||
_cogl_texture_driver_try_setting_gl_border_color,
|
_cogl_texture_driver_try_setting_gl_border_color,
|
||||||
_cogl_texture_driver_allows_foreign_gl_target,
|
_cogl_texture_driver_allows_foreign_gl_target,
|
||||||
_cogl_texture_driver_gl_generate_mipmaps,
|
|
||||||
_cogl_texture_driver_find_best_gl_get_data_format
|
_cogl_texture_driver_find_best_gl_get_data_format
|
||||||
};
|
};
|
||||||
|
@ -82,6 +82,14 @@ _cogl_texture_driver_gen (CoglContext *ctx,
|
|||||||
{
|
{
|
||||||
case GL_TEXTURE_2D:
|
case GL_TEXTURE_2D:
|
||||||
case GL_TEXTURE_3D:
|
case GL_TEXTURE_3D:
|
||||||
|
/* In case automatic mipmap generation gets disabled for this
|
||||||
|
* texture but a minification filter depending on mipmap
|
||||||
|
* interpolation is selected then we initialize the max mipmap
|
||||||
|
* level to 0 so OpenGL will consider the texture storage to be
|
||||||
|
* "complete".
|
||||||
|
*/
|
||||||
|
GE( ctx, glTexParameteri (gl_target, GL_TEXTURE_MAX_LEVEL, 0));
|
||||||
|
|
||||||
/* GL_TEXTURE_MAG_FILTER defaults to GL_LINEAR, no need to set it */
|
/* GL_TEXTURE_MAG_FILTER defaults to GL_LINEAR, no need to set it */
|
||||||
GE( ctx, glTexParameteri (gl_target,
|
GE( ctx, glTexParameteri (gl_target,
|
||||||
GL_TEXTURE_MIN_FILTER,
|
GL_TEXTURE_MIN_FILTER,
|
||||||
@ -173,8 +181,7 @@ prepare_bitmap_alignment_for_upload (CoglContext *ctx,
|
|||||||
|
|
||||||
static CoglBool
|
static CoglBool
|
||||||
_cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
|
_cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
|
||||||
GLenum gl_target,
|
CoglTexture *texture,
|
||||||
GLuint gl_handle,
|
|
||||||
CoglBool is_foreign,
|
CoglBool is_foreign,
|
||||||
int src_x,
|
int src_x,
|
||||||
int src_y,
|
int src_y,
|
||||||
@ -182,11 +189,14 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
|
|||||||
int dst_y,
|
int dst_y,
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
|
int level,
|
||||||
CoglBitmap *source_bmp,
|
CoglBitmap *source_bmp,
|
||||||
GLuint source_gl_format,
|
GLuint source_gl_format,
|
||||||
GLuint source_gl_type,
|
GLuint source_gl_type,
|
||||||
CoglError **error)
|
CoglError **error)
|
||||||
{
|
{
|
||||||
|
GLenum gl_target;
|
||||||
|
GLuint gl_handle;
|
||||||
uint8_t *data;
|
uint8_t *data;
|
||||||
CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
|
CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
|
||||||
int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
|
int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
|
||||||
@ -195,6 +205,10 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
|
|||||||
GLenum gl_error;
|
GLenum gl_error;
|
||||||
CoglBool status = TRUE;
|
CoglBool status = TRUE;
|
||||||
CoglError *internal_error = NULL;
|
CoglError *internal_error = NULL;
|
||||||
|
int level_width;
|
||||||
|
int level_height;
|
||||||
|
|
||||||
|
cogl_texture_get_gl_texture (texture, &gl_handle, &gl_target);
|
||||||
|
|
||||||
/* If we have the GL_EXT_unpack_subimage extension then we can
|
/* If we have the GL_EXT_unpack_subimage extension then we can
|
||||||
upload from subregions directly. Otherwise we may need to copy
|
upload from subregions directly. Otherwise we may need to copy
|
||||||
@ -255,12 +269,57 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
|
|||||||
while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
|
while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
|
||||||
;
|
;
|
||||||
|
|
||||||
ctx->glTexSubImage2D (gl_target, 0,
|
_cogl_texture_get_level_size (texture,
|
||||||
|
level,
|
||||||
|
&level_width,
|
||||||
|
&level_height,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
if (level_width == width && level_height == height)
|
||||||
|
{
|
||||||
|
/* GL gets upset if you use glTexSubImage2D to define the
|
||||||
|
* contents of a mipmap level so we make sure to use
|
||||||
|
* glTexImage2D if we are uploading a full mipmap level.
|
||||||
|
*/
|
||||||
|
ctx->glTexImage2D (gl_target,
|
||||||
|
level,
|
||||||
|
_cogl_texture_get_gl_format (texture),
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
0,
|
||||||
|
source_gl_format,
|
||||||
|
source_gl_type,
|
||||||
|
data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* GL gets upset if you use glTexSubImage2D to initialize the
|
||||||
|
* contents of a mipmap level so if this is the first time
|
||||||
|
* we've seen a request to upload to this level we call
|
||||||
|
* glTexImage2D first to assert that the storage for this
|
||||||
|
* level exists.
|
||||||
|
*/
|
||||||
|
if (texture->max_level < level)
|
||||||
|
{
|
||||||
|
ctx->glTexImage2D (gl_target,
|
||||||
|
level,
|
||||||
|
_cogl_texture_get_gl_format (texture),
|
||||||
|
level_width,
|
||||||
|
level_height,
|
||||||
|
0,
|
||||||
|
source_gl_format,
|
||||||
|
source_gl_type,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->glTexSubImage2D (gl_target,
|
||||||
|
level,
|
||||||
dst_x, dst_y,
|
dst_x, dst_y,
|
||||||
width, height,
|
width, height,
|
||||||
source_gl_format,
|
source_gl_format,
|
||||||
source_gl_type,
|
source_gl_type,
|
||||||
data);
|
data);
|
||||||
|
}
|
||||||
|
|
||||||
if (_cogl_gl_util_catch_out_of_memory (ctx, error))
|
if (_cogl_gl_util_catch_out_of_memory (ctx, error))
|
||||||
status = FALSE;
|
status = FALSE;
|
||||||
@ -552,14 +611,6 @@ _cogl_texture_driver_allows_foreign_gl_target (CoglContext *ctx,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
_cogl_texture_driver_gl_generate_mipmaps (CoglContext *ctx,
|
|
||||||
GLenum gl_target)
|
|
||||||
{
|
|
||||||
if (ctx->driver == COGL_DRIVER_GLES2)
|
|
||||||
GE( ctx, glGenerateMipmap (gl_target) );
|
|
||||||
}
|
|
||||||
|
|
||||||
static CoglPixelFormat
|
static CoglPixelFormat
|
||||||
_cogl_texture_driver_find_best_gl_get_data_format
|
_cogl_texture_driver_find_best_gl_get_data_format
|
||||||
(CoglContext *context,
|
(CoglContext *context,
|
||||||
@ -589,6 +640,5 @@ _cogl_texture_driver_gles =
|
|||||||
_cogl_texture_driver_size_supported_3d,
|
_cogl_texture_driver_size_supported_3d,
|
||||||
_cogl_texture_driver_try_setting_gl_border_color,
|
_cogl_texture_driver_try_setting_gl_border_color,
|
||||||
_cogl_texture_driver_allows_foreign_gl_target,
|
_cogl_texture_driver_allows_foreign_gl_target,
|
||||||
_cogl_texture_driver_gl_generate_mipmaps,
|
|
||||||
_cogl_texture_driver_find_best_gl_get_data_format
|
_cogl_texture_driver_find_best_gl_get_data_format
|
||||||
};
|
};
|
||||||
|
@ -79,13 +79,14 @@ _cogl_texture_2d_nop_flush_legacy_texobj_wrap_modes (CoglTexture *tex,
|
|||||||
|
|
||||||
void
|
void
|
||||||
_cogl_texture_2d_nop_copy_from_framebuffer (CoglTexture2D *tex_2d,
|
_cogl_texture_2d_nop_copy_from_framebuffer (CoglTexture2D *tex_2d,
|
||||||
CoglFramebuffer *src_fb,
|
|
||||||
int dst_x,
|
|
||||||
int dst_y,
|
|
||||||
int src_x,
|
int src_x,
|
||||||
int src_y,
|
int src_y,
|
||||||
int width,
|
int width,
|
||||||
int height);
|
int height,
|
||||||
|
CoglFramebuffer *src_fb,
|
||||||
|
int dst_x,
|
||||||
|
int dst_y,
|
||||||
|
int level);
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
_cogl_texture_2d_nop_get_gl_handle (CoglTexture2D *tex_2d);
|
_cogl_texture_2d_nop_get_gl_handle (CoglTexture2D *tex_2d);
|
||||||
@ -95,13 +96,14 @@ _cogl_texture_2d_nop_generate_mipmap (CoglTexture2D *tex_2d);
|
|||||||
|
|
||||||
CoglBool
|
CoglBool
|
||||||
_cogl_texture_2d_nop_copy_from_bitmap (CoglTexture2D *tex_2d,
|
_cogl_texture_2d_nop_copy_from_bitmap (CoglTexture2D *tex_2d,
|
||||||
CoglBitmap *bitmap,
|
|
||||||
int dst_x,
|
|
||||||
int dst_y,
|
|
||||||
int src_x,
|
int src_x,
|
||||||
int src_y,
|
int src_y,
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
|
CoglBitmap *bitmap,
|
||||||
|
int dst_x,
|
||||||
|
int dst_y,
|
||||||
|
int level,
|
||||||
CoglError **error);
|
CoglError **error);
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -114,13 +114,14 @@ _cogl_texture_2d_nop_flush_legacy_texobj_wrap_modes (CoglTexture *tex,
|
|||||||
|
|
||||||
void
|
void
|
||||||
_cogl_texture_2d_nop_copy_from_framebuffer (CoglTexture2D *tex_2d,
|
_cogl_texture_2d_nop_copy_from_framebuffer (CoglTexture2D *tex_2d,
|
||||||
CoglFramebuffer *src_fb,
|
|
||||||
int dst_x,
|
|
||||||
int dst_y,
|
|
||||||
int src_x,
|
int src_x,
|
||||||
int src_y,
|
int src_y,
|
||||||
int width,
|
int width,
|
||||||
int height)
|
int height,
|
||||||
|
CoglFramebuffer *src_fb,
|
||||||
|
int dst_x,
|
||||||
|
int dst_y,
|
||||||
|
int level)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,13 +138,14 @@ _cogl_texture_2d_nop_generate_mipmap (CoglTexture2D *tex_2d)
|
|||||||
|
|
||||||
CoglBool
|
CoglBool
|
||||||
_cogl_texture_2d_nop_copy_from_bitmap (CoglTexture2D *tex_2d,
|
_cogl_texture_2d_nop_copy_from_bitmap (CoglTexture2D *tex_2d,
|
||||||
CoglBitmap *bitmap,
|
|
||||||
int dst_x,
|
|
||||||
int dst_y,
|
|
||||||
int src_x,
|
int src_x,
|
||||||
int src_y,
|
int src_y,
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
|
CoglBitmap *bitmap,
|
||||||
|
int dst_x,
|
||||||
|
int dst_y,
|
||||||
|
int level,
|
||||||
CoglError **error)
|
CoglError **error)
|
||||||
{
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -49,6 +49,7 @@
|
|||||||
#include "cogl-xlib.h"
|
#include "cogl-xlib.h"
|
||||||
#include "cogl-error-private.h"
|
#include "cogl-error-private.h"
|
||||||
#include "cogl-texture-gl-private.h"
|
#include "cogl-texture-gl-private.h"
|
||||||
|
#include "cogl-private.h"
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
@ -481,6 +482,9 @@ _cogl_texture_pixmap_x11_update_image_texture (CoglTexturePixmapX11 *tex_pixmap)
|
|||||||
XImage *image;
|
XImage *image;
|
||||||
int src_x, src_y;
|
int src_x, src_y;
|
||||||
int x, y, width, height;
|
int x, y, width, height;
|
||||||
|
int bpp;
|
||||||
|
int offset;
|
||||||
|
CoglError *ignore = NULL;
|
||||||
|
|
||||||
display = cogl_xlib_get_display ();
|
display = cogl_xlib_get_display ();
|
||||||
visual = tex_pixmap->visual;
|
visual = tex_pixmap->visual;
|
||||||
@ -585,14 +589,18 @@ _cogl_texture_pixmap_x11_update_image_texture (CoglTexturePixmapX11 *tex_pixmap)
|
|||||||
image->bits_per_pixel,
|
image->bits_per_pixel,
|
||||||
image->byte_order == LSBFirst);
|
image->byte_order == LSBFirst);
|
||||||
|
|
||||||
cogl_texture_set_region (tex_pixmap->tex,
|
bpp = _cogl_pixel_format_get_bytes_per_pixel (image_format);
|
||||||
src_x, src_y,
|
offset = image->bytes_per_line * src_y + bpp * src_x;
|
||||||
x, y, width, height,
|
|
||||||
image->width,
|
_cogl_texture_set_region (tex_pixmap->tex,
|
||||||
image->height,
|
width,
|
||||||
|
height,
|
||||||
image_format,
|
image_format,
|
||||||
image->bytes_per_line,
|
image->bytes_per_line,
|
||||||
(const uint8_t *) image->data);
|
((const uint8_t *) image->data) + offset,
|
||||||
|
x, y,
|
||||||
|
0, /* level */
|
||||||
|
&ignore);
|
||||||
|
|
||||||
/* If we have a shared memory segment then the XImage would be a
|
/* If we have a shared memory segment then the XImage would be a
|
||||||
temporary one with no data allocated so we can just XFree it */
|
temporary one with no data allocated so we can just XFree it */
|
||||||
@ -685,6 +693,7 @@ _cogl_texture_pixmap_x11_set_region (CoglTexture *tex,
|
|||||||
int dst_y,
|
int dst_y,
|
||||||
int dst_width,
|
int dst_width,
|
||||||
int dst_height,
|
int dst_height,
|
||||||
|
int level,
|
||||||
CoglBitmap *bmp,
|
CoglBitmap *bmp,
|
||||||
CoglError **error)
|
CoglError **error)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user