Merge branch 'master' into cogl-float

This commit is contained in:
Robert Bragg 2009-01-08 11:48:00 +00:00
commit 755f3935f3
8 changed files with 759 additions and 570 deletions

View File

@ -148,7 +148,7 @@ gboolean cogl_is_texture (CoglHandle handle);
/** /**
* cogl_texture_get_width: * cogl_texture_get_width:
* @handle: a #CoglHandle for a texture. * @handle: a #CoglHandle for a texture.
* *
* Query the width of a cogl texture. * Query the width of a cogl texture.
* *
* Returns: the width of the GPU side texture in pixels: * Returns: the width of the GPU side texture in pixels:
@ -158,7 +158,7 @@ guint cogl_texture_get_width (CoglHandle handle);
/** /**
* cogl_texture_get_height: * cogl_texture_get_height:
* @handle: a #CoglHandle for a texture. * @handle: a #CoglHandle for a texture.
* *
* Query the height of a cogl texture. * Query the height of a cogl texture.
* *
* Returns: the height of the GPU side texture in pixels: * Returns: the height of the GPU side texture in pixels:
@ -168,7 +168,7 @@ guint cogl_texture_get_height (CoglHandle handle);
/** /**
* cogl_texture_get_format: * cogl_texture_get_format:
* @handle: a #CoglHandle for a texture. * @handle: a #CoglHandle for a texture.
* *
* Query the #CoglPixelFormat of a cogl texture. * Query the #CoglPixelFormat of a cogl texture.
* *
* Returns: the #CoglPixelFormat of the GPU side texture. * Returns: the #CoglPixelFormat of the GPU side texture.
@ -179,7 +179,7 @@ CoglPixelFormat cogl_texture_get_format (CoglHandle handle);
/** /**
* cogl_texture_get_rowstride: * cogl_texture_get_rowstride:
* @handle: a #CoglHandle for a texture. * @handle: a #CoglHandle for a texture.
* *
* Query the rowstride of a cogl texture. * Query the rowstride of a cogl texture.
* *
* Returns: the offset in bytes between each consequetive row of pixels. * Returns: the offset in bytes between each consequetive row of pixels.
@ -189,7 +189,7 @@ guint cogl_texture_get_rowstride (CoglHandle handle);
/** /**
* cogl_texture_get_max_waste: * cogl_texture_get_max_waste:
* @handle: a #CoglHandle for a texture. * @handle: a #CoglHandle for a texture.
* *
* Query the maximum wasted (unused) pixels in one dimension of a GPU side * Query the maximum wasted (unused) pixels in one dimension of a GPU side
* texture. * texture.
* *
@ -200,7 +200,7 @@ gint cogl_texture_get_max_waste (CoglHandle handle);
/** /**
* cogl_texture_get_min_filter: * cogl_texture_get_min_filter:
* @handle: a #CoglHandle for a texture. * @handle: a #CoglHandle for a texture.
* *
* Query the currently set downscaling filter for a cogl texture. * Query the currently set downscaling filter for a cogl texture.
* *
* Returns: the current downscaling filter for a cogl texture. * Returns: the current downscaling filter for a cogl texture.
@ -210,7 +210,7 @@ COGLenum cogl_texture_get_min_filter (CoglHandle handle);
/** /**
* cogl_texture_get_mag_filter: * cogl_texture_get_mag_filter:
* @handle: a #CoglHandle for a texture. * @handle: a #CoglHandle for a texture.
* *
* Query the currently set downscaling filter for a cogl texture. * Query the currently set downscaling filter for a cogl texture.
* *
* Returns: the current downscaling filter for a cogl texture. * Returns: the current downscaling filter for a cogl texture.
@ -220,7 +220,7 @@ COGLenum cogl_texture_get_mag_filter (CoglHandle handle);
/** /**
* cogl_texture_is_sliced: * cogl_texture_is_sliced:
* @handle: a #CoglHandle for a texture. * @handle: a #CoglHandle for a texture.
* *
* Query if a texture is sliced (stored as multiple GPU side tecture * Query if a texture is sliced (stored as multiple GPU side tecture
* objects). * objects).
* *
@ -235,7 +235,7 @@ gboolean cogl_texture_is_sliced (CoglHandle handle);
* @out_gl_handle: pointer to return location for the textures GL handle, or * @out_gl_handle: pointer to return location for the textures GL handle, or
* NULL. * NULL.
* @out_gl_target: pointer to return location for the GL target type, or NULL. * @out_gl_target: pointer to return location for the GL target type, or NULL.
* *
* Query the GL handles for a GPU side texture through it's #CoglHandle, * Query the GL handles for a GPU side texture through it's #CoglHandle,
* if the texture is spliced the data for the first sub texture will be * if the texture is spliced the data for the first sub texture will be
* queried. * queried.
@ -255,7 +255,7 @@ gboolean cogl_texture_get_gl_texture (CoglHandle handle,
* specified. * specified.
* @data: memory location to write contents of buffer, or %NULL if we're * @data: memory location to write contents of buffer, or %NULL if we're
* only querying the data size through the return value. * only querying the data size through the return value.
* *
* Copy the pixel data from a cogl texture to system memory. * Copy the pixel data from a cogl texture to system memory.
* *
* Returns: the size of the texture data in bytes (or 0 if the texture * Returns: the size of the texture data in bytes (or 0 if the texture
@ -271,7 +271,7 @@ gint cogl_texture_get_data (CoglHandle handle,
* @handle: a #CoglHandle. * @handle: a #CoglHandle.
* @min_filter: the filter used when scaling the texture down. * @min_filter: the filter used when scaling the texture down.
* @mag_filter: the filter used when magnifying the texture. * @mag_filter: the filter used when magnifying the texture.
* *
* Changes the decimation and interpolation filters used when the texture is * Changes the decimation and interpolation filters used when the texture is
* drawn at other scales than 100%. * drawn at other scales than 100%.
*/ */
@ -297,7 +297,7 @@ void cogl_texture_set_filters (CoglHandle handle,
* @data: the actual pixel data. * @data: the actual pixel data.
* *
* Sets the pixels in a rectangular subregion of @handle from an in-memory * Sets the pixels in a rectangular subregion of @handle from an in-memory
* buffer containing pixel data. * buffer containing pixel data.
* *
* Returns: %TRUE if the subregion upload was successful, otherwise %FALSE. * Returns: %TRUE if the subregion upload was successful, otherwise %FALSE.
*/ */
@ -385,6 +385,29 @@ void cogl_texture_polygon (CoglHandle handle,
CoglTextureVertex *vertices, CoglTextureVertex *vertices,
gboolean use_color); gboolean use_color);
/**
* cogl_texture_multiple_rectangles:
* @handle: a @CoglHandle.
* @verts: an array of vertices
* @n_rects: number of rectangles to draw
*
* Draws a series of rectangles in the same way that
* cogl_texture_rectangle() does. In some situations it can give a
* significant performance boost to use this function rather than
* calling cogl_texture_rectangle() separately for each rectangle.
*
* @verts should point to an array of #CoglFixed<!-- -->s with
* @n_rects * 8 elements. Each group of 8 values corresponds to the
* parameters x1, y1, x2, y2, tx1, ty1, tx2 and ty2 and have the same
* meaning as in cogl_texture_rectangle().
*
* Since: 1.0
*/
void cogl_texture_multiple_rectangles
(CoglHandle handle,
const CoglFixed *verts,
guint n_rects);
G_END_DECLS G_END_DECLS
#endif /* __COGL_TEXTURE_H__ */ #endif /* __COGL_TEXTURE_H__ */

View File

@ -120,6 +120,7 @@ cogl_texture_set_region
cogl_texture_ref cogl_texture_ref
cogl_texture_unref cogl_texture_unref
cogl_texture_rectangle cogl_texture_rectangle
cogl_texture_multiple_rectangles
cogl_texture_polygon cogl_texture_polygon
</SECTION> </SECTION>

View File

@ -41,27 +41,29 @@ cogl_create_context ()
{ {
if (_context != NULL) if (_context != NULL)
return FALSE; return FALSE;
/* Allocate context memory */ /* Allocate context memory */
_context = (CoglContext*) g_malloc (sizeof (CoglContext)); _context = (CoglContext*) g_malloc (sizeof (CoglContext));
/* Init default values */ /* Init default values */
_context->feature_flags = 0; _context->feature_flags = 0;
_context->features_cached = FALSE; _context->features_cached = FALSE;
_context->enable_flags = 0; _context->enable_flags = 0;
_context->color_alpha = 255; _context->color_alpha = 255;
_context->path_nodes = g_array_new (FALSE, FALSE, sizeof (CoglPathNode)); _context->path_nodes = g_array_new (FALSE, FALSE, sizeof (CoglPathNode));
_context->last_path = 0; _context->last_path = 0;
_context->texture_handles = NULL; _context->texture_handles = NULL;
_context->texture_vertices_size = 0; _context->texture_vertices = g_array_new (FALSE, FALSE,
_context->texture_vertices = NULL; sizeof (CoglTextureGLVertex));
_context->texture_indices = g_array_new (FALSE, FALSE,
sizeof (GLushort));
_context->fbo_handles = NULL; _context->fbo_handles = NULL;
_context->draw_buffer = COGL_WINDOW_BUFFER; _context->draw_buffer = COGL_WINDOW_BUFFER;
_context->blend_src_factor = CGL_SRC_ALPHA; _context->blend_src_factor = CGL_SRC_ALPHA;
_context->blend_dst_factor = CGL_ONE_MINUS_SRC_ALPHA; _context->blend_dst_factor = CGL_ONE_MINUS_SRC_ALPHA;
@ -70,7 +72,7 @@ cogl_create_context ()
_context->program_handles = NULL; _context->program_handles = NULL;
_context->mesh_handles = NULL; _context->mesh_handles = NULL;
_context->pf_glGenRenderbuffersEXT = NULL; _context->pf_glGenRenderbuffersEXT = NULL;
_context->pf_glBindRenderbufferEXT = NULL; _context->pf_glBindRenderbufferEXT = NULL;
_context->pf_glRenderbufferStorageEXT = NULL; _context->pf_glRenderbufferStorageEXT = NULL;
@ -82,7 +84,7 @@ cogl_create_context ()
_context->pf_glDeleteFramebuffersEXT = NULL; _context->pf_glDeleteFramebuffersEXT = NULL;
_context->pf_glBlitFramebufferEXT = NULL; _context->pf_glBlitFramebufferEXT = NULL;
_context->pf_glRenderbufferStorageMultisampleEXT = NULL; _context->pf_glRenderbufferStorageMultisampleEXT = NULL;
_context->pf_glCreateProgramObjectARB = NULL; _context->pf_glCreateProgramObjectARB = NULL;
_context->pf_glCreateShaderObjectARB = NULL; _context->pf_glCreateShaderObjectARB = NULL;
_context->pf_glShaderSourceARB = NULL; _context->pf_glShaderSourceARB = NULL;
@ -115,7 +117,7 @@ cogl_create_context ()
_context->pf_glUniformMatrix4fvARB = NULL; _context->pf_glUniformMatrix4fvARB = NULL;
_context->pf_glDrawRangeElements = NULL; _context->pf_glDrawRangeElements = NULL;
/* Init OpenGL state */ /* Init OpenGL state */
GE( glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) ); GE( glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) );
GE( glColorMask (TRUE, TRUE, TRUE, FALSE) ); GE( glColorMask (TRUE, TRUE, TRUE, FALSE) );
@ -124,7 +126,7 @@ cogl_create_context ()
/* Initialise the clip stack */ /* Initialise the clip stack */
_cogl_clip_stack_state_init (); _cogl_clip_stack_state_init ();
return TRUE; return TRUE;
} }
@ -147,7 +149,12 @@ cogl_destroy_context ()
g_array_free (_context->shader_handles, TRUE); g_array_free (_context->shader_handles, TRUE);
if (_context->program_handles) if (_context->program_handles)
g_array_free (_context->program_handles, TRUE); g_array_free (_context->program_handles, TRUE);
if (_context->texture_vertices)
g_array_free (_context->texture_vertices, TRUE);
if (_context->texture_indices)
g_array_free (_context->texture_indices, TRUE);
g_free (_context); g_free (_context);
} }
@ -157,6 +164,6 @@ _cogl_context_get_default ()
/* Create if doesn't exist yet */ /* Create if doesn't exist yet */
if (_context == NULL) if (_context == NULL)
cogl_create_context (); cogl_create_context ();
return _context; return _context;
} }

View File

@ -41,7 +41,7 @@ typedef struct
/* Features cache */ /* Features cache */
CoglFeatureFlags feature_flags; CoglFeatureFlags feature_flags;
gboolean features_cached; gboolean features_cached;
/* Enable cache */ /* Enable cache */
gulong enable_flags; gulong enable_flags;
guint8 color_alpha; guint8 color_alpha;
@ -49,7 +49,7 @@ typedef struct
COGLenum blend_dst_factor; COGLenum blend_dst_factor;
gboolean enable_backface_culling; gboolean enable_backface_culling;
/* Primitives */ /* Primitives */
CoglFixedVec2 path_start; CoglFixedVec2 path_start;
CoglFixedVec2 path_pen; CoglFixedVec2 path_pen;
@ -60,12 +60,18 @@ typedef struct
/* Cache of inverse projection matrix */ /* Cache of inverse projection matrix */
GLfloat inverse_projection[16]; GLfloat inverse_projection[16];
/* Textures */ /* Textures */
GArray *texture_handles; GArray *texture_handles;
CoglTextureGLVertex *texture_vertices; GArray *texture_vertices;
gulong texture_vertices_size; GArray *texture_indices;
/* The gl texture number that the above vertices apply to. This to
detect when a different slice is encountered so that the vertices
can be flushed */
GLuint texture_current;
GLenum texture_target;
GLenum texture_wrap_mode;
/* Framebuffer objects */ /* Framebuffer objects */
GArray *fbo_handles; GArray *fbo_handles;
CoglBufferTarget draw_buffer; CoglBufferTarget draw_buffer;
@ -78,10 +84,10 @@ typedef struct
/* Clip stack */ /* Clip stack */
CoglClipStackState clip; CoglClipStackState clip;
/* Mesh */ /* Mesh */
GArray *mesh_handles; GArray *mesh_handles;
/* Relying on glext.h to define these */ /* Relying on glext.h to define these */
COGL_PFNGLGENRENDERBUFFERSEXTPROC pf_glGenRenderbuffersEXT; COGL_PFNGLGENRENDERBUFFERSEXTPROC pf_glGenRenderbuffersEXT;
COGL_PFNGLDELETERENDERBUFFERSEXTPROC pf_glDeleteRenderbuffersEXT; COGL_PFNGLDELETERENDERBUFFERSEXTPROC pf_glDeleteRenderbuffersEXT;
@ -95,7 +101,7 @@ typedef struct
COGL_PFNGLDELETEFRAMEBUFFERSEXTPROC pf_glDeleteFramebuffersEXT; COGL_PFNGLDELETEFRAMEBUFFERSEXTPROC pf_glDeleteFramebuffersEXT;
COGL_PFNGLBLITFRAMEBUFFEREXTPROC pf_glBlitFramebufferEXT; COGL_PFNGLBLITFRAMEBUFFEREXTPROC pf_glBlitFramebufferEXT;
COGL_PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC pf_glRenderbufferStorageMultisampleEXT; COGL_PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC pf_glRenderbufferStorageMultisampleEXT;
COGL_PFNGLCREATEPROGRAMOBJECTARBPROC pf_glCreateProgramObjectARB; COGL_PFNGLCREATEPROGRAMOBJECTARBPROC pf_glCreateProgramObjectARB;
COGL_PFNGLCREATESHADEROBJECTARBPROC pf_glCreateShaderObjectARB; COGL_PFNGLCREATESHADEROBJECTARBPROC pf_glCreateShaderObjectARB;
COGL_PFNGLSHADERSOURCEARBPROC pf_glShaderSourceARB; COGL_PFNGLSHADERSOURCEARBPROC pf_glShaderSourceARB;
@ -151,6 +157,6 @@ _cogl_context_get_default ();
CoglContext *ctxvar = _cogl_context_get_default (); \ CoglContext *ctxvar = _cogl_context_get_default (); \
if (ctxvar == NULL) return retval; if (ctxvar == NULL) return retval;
#define NO_RETVAL #define NO_RETVAL
#endif /* __COGL_CONTEXT_H */ #endif /* __COGL_CONTEXT_H */

File diff suppressed because it is too large Load Diff

View File

@ -59,9 +59,11 @@ cogl_create_context ()
_context->last_path = 0; _context->last_path = 0;
_context->texture_handles = NULL; _context->texture_handles = NULL;
_context->texture_vertices_size = 0; _context->texture_vertices = g_array_new (FALSE, FALSE,
_context->texture_vertices = NULL; sizeof (CoglTextureGLVertex));
_context->texture_indices = g_array_new (FALSE, FALSE,
sizeof (GLushort));
_context->fbo_handles = NULL; _context->fbo_handles = NULL;
_context->program_handles = NULL; _context->program_handles = NULL;
_context->shader_handles = NULL; _context->shader_handles = NULL;
@ -104,8 +106,10 @@ cogl_destroy_context ()
#endif #endif
if (_context->texture_vertices) if (_context->texture_vertices)
g_free (_context->texture_vertices); g_array_free (_context->texture_vertices, TRUE);
if (_context->texture_indices)
g_array_free (_context->texture_indices, TRUE);
if (_context->texture_handles) if (_context->texture_handles)
g_array_free (_context->texture_handles, TRUE); g_array_free (_context->texture_handles, TRUE);
if (_context->fbo_handles) if (_context->fbo_handles)

View File

@ -65,9 +65,14 @@ typedef struct
/* Textures */ /* Textures */
GArray *texture_handles; GArray *texture_handles;
CoglTextureGLVertex *texture_vertices; GArray *texture_vertices;
gulong texture_vertices_size; GArray *texture_indices;
/* The gl texture number that the above vertices apply to. This to
detect when a different slice is encountered so that the vertices
can be flushed */
GLuint texture_current;
GLenum texture_target;
/* Framebuffer objects */ /* Framebuffer objects */
GArray *fbo_handles; GArray *fbo_handles;
CoglBufferTarget draw_buffer; CoglBufferTarget draw_buffer;

View File

@ -2047,6 +2047,94 @@ cogl_texture_get_data (CoglHandle handle,
return byte_size; return byte_size;
} }
static void
_cogl_texture_flush_vertices (void)
{
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
if (ctx->texture_vertices->len > 0)
{
int needed_indices;
CoglTextureGLVertex *p
= (CoglTextureGLVertex *) ctx->texture_vertices->data;
/* The indices are always the same sequence regardless of the
vertices so we only need to change it if there are more
vertices than ever before */
needed_indices = ctx->texture_vertices->len / 4 * 6;
if (needed_indices > ctx->texture_indices->len)
{
int old_len = ctx->texture_indices->len;
int vert_num = old_len / 6 * 4;
int i;
GLushort *q;
/* Add two triangles for each quad to the list of
indices. That makes six new indices but two of the
vertices in the triangles are shared. */
g_array_set_size (ctx->texture_indices, needed_indices);
q = &g_array_index (ctx->texture_indices, GLushort, old_len);
for (i = old_len;
i < ctx->texture_indices->len;
i += 6, vert_num += 4)
{
*(q++) = vert_num + 0;
*(q++) = vert_num + 1;
*(q++) = vert_num + 3;
*(q++) = vert_num + 1;
*(q++) = vert_num + 2;
*(q++) = vert_num + 3;
}
}
GE( glVertexPointer (2, GL_FLOAT,
sizeof (CoglTextureGLVertex), p->v ) );
GE( glTexCoordPointer (2, GL_FLOAT,
sizeof (CoglTextureGLVertex), p->t ) );
GE( glBindTexture (ctx->texture_target, ctx->texture_current) );
GE( glDrawElements (GL_TRIANGLES,
needed_indices,
GL_UNSIGNED_SHORT,
ctx->texture_indices->data) );
g_array_set_size (ctx->texture_vertices, 0);
}
}
static void
_cogl_texture_add_quad_vertices (GLfloat x1, GLfloat y1,
GLfloat x2, GLfloat y2,
GLfloat tx1, GLfloat ty1,
GLfloat tx2, GLfloat ty2)
{
CoglTextureGLVertex *p;
GLushort first_vert;
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
/* Add the four vertices of the quad to the list of queued
vertices */
first_vert = ctx->texture_vertices->len;
g_array_set_size (ctx->texture_vertices, first_vert + 4);
p = &g_array_index (ctx->texture_vertices, CoglTextureGLVertex, first_vert);
p->v[0] = x1; p->v[1] = y1;
p->t[0] = tx1; p->t[1] = ty1;
p++;
p->v[0] = x1; p->v[1] = y2;
p->t[0] = tx1; p->t[1] = ty2;
p++;
p->v[0] = x2; p->v[1] = y2;
p->t[0] = tx2; p->t[1] = ty2;
p++;
p->v[0] = x2; p->v[1] = y1;
p->t[0] = tx2; p->t[1] = ty1;
p++;
}
static void static void
_cogl_texture_quad_sw (CoglTexture *tex, _cogl_texture_quad_sw (CoglTexture *tex,
CoglFixed x1, CoglFixed x1,
@ -2067,31 +2155,13 @@ _cogl_texture_quad_sw (CoglTexture *tex,
CoglFixed slice_tx2 , slice_ty2; CoglFixed slice_tx2 , slice_ty2;
CoglFixed slice_qx1 , slice_qy1; CoglFixed slice_qx1 , slice_qy1;
CoglFixed slice_qx2 , slice_qy2; CoglFixed slice_qx2 , slice_qy2;
GLfloat tex_coords[8];
GLfloat quad_coords[8];
GLuint gl_handle; GLuint gl_handle;
gulong enable_flags = (COGL_ENABLE_TEXTURE_2D
| COGL_ENABLE_VERTEX_ARRAY
| COGL_ENABLE_TEXCOORD_ARRAY);
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
#if COGL_DEBUG #if COGL_DEBUG
printf("=== Drawing Tex Quad (Software Tiling Mode) ===\n"); printf("=== Drawing Tex Quad (Software Tiling Mode) ===\n");
#endif #endif
/* Prepare GL state */
if (ctx->color_alpha < 255
|| tex->bitmap.format & COGL_A_BIT)
{
enable_flags |= COGL_ENABLE_BLEND;
}
if (ctx->enable_backface_culling)
enable_flags |= COGL_ENABLE_BACKFACE_CULLING;
cogl_enable (enable_flags);
/* If the texture coordinates are backwards then swap both the /* If the texture coordinates are backwards then swap both the
geometry and texture coordinates so that the texture will be geometry and texture coordinates so that the texture will be
@ -2115,10 +2185,7 @@ _cogl_texture_quad_sw (CoglTexture *tex,
ty1 = ty2; ty1 = ty2;
ty2 = temp; ty2 = temp;
} }
GE( glTexCoordPointer (2, GL_FLOAT, 0, tex_coords) );
GE( glVertexPointer (2, GL_FLOAT, 0, quad_coords) );
/* Scale ratio from texture to quad widths */ /* Scale ratio from texture to quad widths */
tw = COGL_FIXED_FROM_INT (tex->bitmap.width); tw = COGL_FIXED_FROM_INT (tex->bitmap.width);
th = COGL_FIXED_FROM_INT (tex->bitmap.height); th = COGL_FIXED_FROM_INT (tex->bitmap.height);
@ -2158,17 +2225,16 @@ _cogl_texture_quad_sw (CoglTexture *tex,
slice_qy2 = first_qy + slice_qy2 = first_qy +
COGL_FIXED_MUL (iter_y.intersect_end - first_ty, tqy); COGL_FIXED_MUL (iter_y.intersect_end - first_ty, tqy);
/* Localize slice texture coordinates */ /* Localize slice texture coordinates */
slice_ty1 = iter_y.intersect_start - iter_y.pos; slice_ty1 = iter_y.intersect_start - iter_y.pos;
slice_ty2 = iter_y.intersect_end - iter_y.pos; slice_ty2 = iter_y.intersect_end - iter_y.pos;
/* Normalize texture coordinates to current slice /* Normalize texture coordinates to current slice
(rectangle texture targets take denormalized) */ (rectangle texture targets take denormalized) */
slice_ty1 /= iter_y.span->size; slice_ty1 /= iter_y.span->size;
slice_ty2 /= iter_y.span->size; slice_ty2 /= iter_y.span->size;
/* Iterate until whole quad width covered */ /* Iterate until whole quad width covered */
for (_cogl_span_iter_begin (&iter_x, tex->slice_x_spans, for (_cogl_span_iter_begin (&iter_x, tex->slice_x_spans,
first_tx, tx1, tx2) ; first_tx, tx1, tx2) ;
@ -2188,12 +2254,12 @@ _cogl_texture_quad_sw (CoglTexture *tex,
/* Localize slice texture coordinates */ /* Localize slice texture coordinates */
slice_tx1 = iter_x.intersect_start - iter_x.pos; slice_tx1 = iter_x.intersect_start - iter_x.pos;
slice_tx2 = iter_x.intersect_end - iter_x.pos; slice_tx2 = iter_x.intersect_end - iter_x.pos;
/* Normalize texture coordinates to current slice /* Normalize texture coordinates to current slice
(rectangle texture targets take denormalized) */ (rectangle texture targets take denormalized) */
slice_tx1 /= iter_x.span->size; slice_tx1 /= iter_x.span->size;
slice_tx2 /= iter_x.span->size; slice_tx2 /= iter_x.span->size;
#if COGL_DEBUG #if COGL_DEBUG
printf("~~~~~ slice (%d,%d)\n", iter_x.index, iter_y.index); printf("~~~~~ slice (%d,%d)\n", iter_x.index, iter_y.index);
printf("qx1: %f\n", COGL_FIXED_TO_FLOAT (slice_qx1)); printf("qx1: %f\n", COGL_FIXED_TO_FLOAT (slice_qx1));
@ -2210,26 +2276,23 @@ _cogl_texture_quad_sw (CoglTexture *tex,
gl_handle = g_array_index (tex->slice_gl_handles, GLuint, gl_handle = g_array_index (tex->slice_gl_handles, GLuint,
iter_y.index * iter_x.array->len + iter_y.index * iter_x.array->len +
iter_x.index); iter_x.index);
GE( cogl_gles2_wrapper_bind_texture (tex->gl_target, gl_handle,
tex->gl_intformat) );
#define CFX_F COGL_FIXED_TO_FLOAT /* If we're using a different texture from the one already queued
then flush the vertices */
/* Draw textured quad */ if (ctx->texture_vertices->len > 0
tex_coords[0] = CFX_F(slice_tx1); tex_coords[1] = CFX_F(slice_ty2); && gl_handle != ctx->texture_current)
tex_coords[2] = CFX_F(slice_tx2); tex_coords[3] = CFX_F(slice_ty2); _cogl_texture_flush_vertices ();
tex_coords[4] = CFX_F(slice_tx1); tex_coords[5] = CFX_F(slice_ty1); ctx->texture_target = tex->gl_target;
tex_coords[6] = CFX_F(slice_tx2); tex_coords[7] = CFX_F(slice_ty1); ctx->texture_current = gl_handle;
quad_coords[0] = CFX_F(slice_qx1); quad_coords[1] = CFX_F(slice_qy2); _cogl_texture_add_quad_vertices (COGL_FIXED_TO_FLOAT (slice_qx1),
quad_coords[2] = CFX_F(slice_qx2); quad_coords[3] = CFX_F(slice_qy2); COGL_FIXED_TO_FLOAT (slice_qy1),
quad_coords[4] = CFX_F(slice_qx1); quad_coords[5] = CFX_F(slice_qy1); COGL_FIXED_TO_FLOAT (slice_qx2),
quad_coords[6] = CFX_F(slice_qx2); quad_coords[7] = CFX_F(slice_qy1); COGL_FIXED_TO_FLOAT (slice_qy2),
COGL_FIXED_TO_FLOAT (slice_tx1),
GE (glDrawArrays (GL_TRIANGLE_STRIP, 0, 4) ); COGL_FIXED_TO_FLOAT (slice_ty1),
COGL_FIXED_TO_FLOAT (slice_tx2),
#undef CFX_F COGL_FIXED_TO_FLOAT (slice_ty2));
} }
} }
} }
@ -2245,41 +2308,27 @@ _cogl_texture_quad_hw (CoglTexture *tex,
CoglFixed tx2, CoglFixed tx2,
CoglFixed ty2) CoglFixed ty2)
{ {
GLfloat tex_coords[8];
GLfloat quad_coords[8];
GLuint gl_handle; GLuint gl_handle;
CoglTexSliceSpan *x_span; CoglTexSliceSpan *x_span;
CoglTexSliceSpan *y_span; CoglTexSliceSpan *y_span;
gulong enable_flags = (COGL_ENABLE_TEXTURE_2D
| COGL_ENABLE_VERTEX_ARRAY
| COGL_ENABLE_TEXCOORD_ARRAY);
#if COGL_DEBUG #if COGL_DEBUG
printf("=== Drawing Tex Quad (Hardware Tiling Mode) ===\n"); printf("=== Drawing Tex Quad (Hardware Tiling Mode) ===\n");
#endif #endif
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
/* Prepare GL state */
if (ctx->color_alpha < 255
|| tex->bitmap.format & COGL_A_BIT)
{
enable_flags |= COGL_ENABLE_BLEND;
}
if (ctx->enable_backface_culling)
enable_flags |= COGL_ENABLE_BACKFACE_CULLING;
cogl_enable (enable_flags); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
GE( glTexCoordPointer (2, GL_FLOAT, 0, tex_coords) );
GE( glVertexPointer (2, GL_FLOAT, 0, quad_coords) );
/* Pick and bind opengl texture object */ /* Pick and bind opengl texture object */
gl_handle = g_array_index (tex->slice_gl_handles, GLuint, 0); gl_handle = g_array_index (tex->slice_gl_handles, GLuint, 0);
GE( cogl_gles2_wrapper_bind_texture (tex->gl_target, gl_handle,
tex->gl_intformat) ); /* If we're using a different texture from the one already queued
then flush the vertices */
if (ctx->texture_vertices->len > 0
&& gl_handle != ctx->texture_current)
_cogl_texture_flush_vertices ();
ctx->texture_target = tex->gl_target;
ctx->texture_current = gl_handle;
/* Don't include the waste in the texture coordinates */ /* Don't include the waste in the texture coordinates */
x_span = &g_array_index (tex->slice_x_spans, CoglTexSliceSpan, 0); x_span = &g_array_index (tex->slice_x_spans, CoglTexSliceSpan, 0);
y_span = &g_array_index (tex->slice_y_spans, CoglTexSliceSpan, 0); y_span = &g_array_index (tex->slice_y_spans, CoglTexSliceSpan, 0);
@ -2290,22 +2339,80 @@ _cogl_texture_quad_hw (CoglTexture *tex,
ty1 = ty1 * (y_span->size - y_span->waste) / y_span->size; ty1 = ty1 * (y_span->size - y_span->waste) / y_span->size;
ty2 = ty2 * (y_span->size - y_span->waste) / y_span->size; ty2 = ty2 * (y_span->size - y_span->waste) / y_span->size;
#define CFX_F(x) COGL_FIXED_TO_FLOAT(x) _cogl_texture_add_quad_vertices (COGL_FIXED_TO_FLOAT (x1),
COGL_FIXED_TO_FLOAT (y1),
COGL_FIXED_TO_FLOAT (x2),
COGL_FIXED_TO_FLOAT (y2),
COGL_FIXED_TO_FLOAT (tx1),
COGL_FIXED_TO_FLOAT (ty1),
COGL_FIXED_TO_FLOAT (tx2),
COGL_FIXED_TO_FLOAT (ty2));
}
void
cogl_texture_multiple_rectangles (CoglHandle handle,
const CoglFixed *verts,
guint n_rects)
{
CoglTexture *tex;
gulong enable_flags = (COGL_ENABLE_VERTEX_ARRAY
| COGL_ENABLE_TEXCOORD_ARRAY
| COGL_ENABLE_TEXTURE_2D);
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
/* Check if valid texture */
if (!cogl_is_texture (handle))
return;
/* Draw textured quad */ cogl_clip_ensure ();
tex_coords[0] = CFX_F(tx1); tex_coords[1] = CFX_F(ty2);
tex_coords[2] = CFX_F(tx2); tex_coords[3] = CFX_F(ty2);
tex_coords[4] = CFX_F(tx1); tex_coords[5] = CFX_F(ty1);
tex_coords[6] = CFX_F(tx2); tex_coords[7] = CFX_F(ty1);
quad_coords[0] = CFX_F(x1); quad_coords[1] = CFX_F(y2); tex = _cogl_texture_pointer_from_handle (handle);
quad_coords[2] = CFX_F(x2); quad_coords[3] = CFX_F(y2);
quad_coords[4] = CFX_F(x1); quad_coords[5] = CFX_F(y1); /* Make sure we got stuff to draw */
quad_coords[6] = CFX_F(x2); quad_coords[7] = CFX_F(y1); if (tex->slice_gl_handles == NULL)
return;
if (tex->slice_gl_handles->len == 0)
return;
GE (glDrawArrays (GL_TRIANGLE_STRIP, 0, 4) ); /* Prepare GL state */
if (ctx->color_alpha < 255
|| tex->bitmap.format & COGL_A_BIT)
enable_flags |= COGL_ENABLE_BLEND;
#undef CFX_F if (ctx->enable_backface_culling)
enable_flags |= COGL_ENABLE_BACKFACE_CULLING;
cogl_enable (enable_flags);
g_array_set_size (ctx->texture_vertices, 0);
while (n_rects-- > 0)
{
if (verts[4] != verts[6] && verts[5] != verts[7])
{
/* If there is only one GL texture and either the texture is
NPOT (no waste) or all of the coordinates are in the
range [0,1] then we can use hardware tiling */
if (tex->slice_gl_handles->len == 1
&& ((cogl_features_available (COGL_FEATURE_TEXTURE_NPOT)
&& tex->gl_target == GL_TEXTURE_2D)
|| (verts[4] >= 0 && verts[4] <= COGL_FIXED_1
&& verts[6] >= 0 && verts[6] <= COGL_FIXED_1
&& verts[5] >= 0 && verts[5] <= COGL_FIXED_1
&& verts[7] >= 0 && verts[7] <= COGL_FIXED_1)))
_cogl_texture_quad_hw (tex, verts[0],verts[1], verts[2],verts[3],
verts[4],verts[5], verts[6],verts[7]);
else
_cogl_texture_quad_sw (tex, verts[0],verts[1], verts[2],verts[3],
verts[4],verts[5], verts[6],verts[7]);
}
verts += 8;
}
_cogl_texture_flush_vertices ();
} }
void void
@ -2319,47 +2426,18 @@ cogl_texture_rectangle (CoglHandle handle,
CoglFixed tx2, CoglFixed tx2,
CoglFixed ty2) CoglFixed ty2)
{ {
CoglTexture *tex; CoglFixed verts[8];
/* Check if valid texture */
if (!cogl_is_texture (handle))
return;
cogl_clip_ensure (); verts[0] = x1;
verts[1] = y1;
tex = _cogl_texture_pointer_from_handle (handle); verts[2] = x2;
verts[3] = y2;
/* Make sure we got stuff to draw */ verts[4] = tx1;
if (tex->slice_gl_handles == NULL) verts[5] = ty1;
return; verts[6] = tx2;
verts[7] = ty2;
if (tex->slice_gl_handles->len == 0)
return; cogl_texture_multiple_rectangles (handle, verts, 1);
if (tx1 == tx2 || ty1 == ty2)
return;
/* Pick tiling mode according to hw support */
if (cogl_features_available (COGL_FEATURE_TEXTURE_NPOT)
&& tex->slice_gl_handles->len == 1)
{
_cogl_texture_quad_hw (tex, x1,y1, x2,y2, tx1,ty1, tx2,ty2);
}
else
{
if (tex->slice_gl_handles->len == 1
&& tx1 >= -COGL_FIXED_1
&& tx2 <= COGL_FIXED_1
&& ty1 >= -COGL_FIXED_1
&& ty2 <= COGL_FIXED_1)
{
_cogl_texture_quad_hw (tex, x1,y1, x2,y2, tx1,ty1, tx2,ty2);
}
else
{
_cogl_texture_quad_sw (tex, x1,y1, x2,y2, tx1,ty1, tx2,ty2);
}
}
} }
void void
@ -2405,23 +2483,9 @@ cogl_texture_polygon (CoglHandle handle,
/* Make sure there is enough space in the global texture vertex /* Make sure there is enough space in the global texture vertex
array. This is used so we can render the polygon with a single array. This is used so we can render the polygon with a single
call to OpenGL but still support any number of vertices */ call to OpenGL but still support any number of vertices */
if (ctx->texture_vertices_size < n_vertices) g_array_set_size (ctx->texture_vertices, n_vertices);
{ p = (CoglTextureGLVertex *) ctx->texture_vertices->data;
guint nsize = ctx->texture_vertices_size;
if (nsize == 0)
nsize = 1;
do
nsize *= 2;
while (nsize < n_vertices);
ctx->texture_vertices_size = nsize;
ctx->texture_vertices = g_realloc (ctx->texture_vertices,
nsize
* sizeof (CoglTextureGLVertex));
}
/* Prepare GL state */ /* Prepare GL state */
enable_flags = (COGL_ENABLE_TEXTURE_2D enable_flags = (COGL_ENABLE_TEXTURE_2D
| COGL_ENABLE_VERTEX_ARRAY | COGL_ENABLE_VERTEX_ARRAY
@ -2447,14 +2511,12 @@ cogl_texture_polygon (CoglHandle handle,
if (use_color) if (use_color)
{ {
enable_flags |= COGL_ENABLE_COLOR_ARRAY; enable_flags |= COGL_ENABLE_COLOR_ARRAY;
GE( glColorPointer (4, GL_UNSIGNED_BYTE, sizeof (CoglTextureGLVertex), GE( glColorPointer (4, GL_UNSIGNED_BYTE,
ctx->texture_vertices[0].c) ); sizeof (CoglTextureGLVertex), p->c) );
} }
GE( glVertexPointer (3, GL_FLOAT, sizeof (CoglTextureGLVertex), GE( glVertexPointer (3, GL_FLOAT, sizeof (CoglTextureGLVertex), p->v ) );
ctx->texture_vertices[0].v) ); GE( glTexCoordPointer (2, GL_FLOAT, sizeof (CoglTextureGLVertex), p->t ) );
GE( glTexCoordPointer (2, GL_FLOAT, sizeof (CoglTextureGLVertex),
ctx->texture_vertices[0].t) );
cogl_enable (enable_flags); cogl_enable (enable_flags);
@ -2464,7 +2526,7 @@ cogl_texture_polygon (CoglHandle handle,
/* Convert the vertices into an array of GLfloats ready to pass to /* Convert the vertices into an array of GLfloats ready to pass to
OpenGL */ OpenGL */
for (i = 0, p = ctx->texture_vertices; i < n_vertices; i++, p++) for (i = 0; i < n_vertices; i++, p++)
{ {
#define CFX_F COGL_FIXED_TO_FLOAT #define CFX_F COGL_FIXED_TO_FLOAT