1
0
Fork 0

Another Cogl gl vs gles normalizaion pass

This tries to make a number of files more comparable with the intention of
moving some code into cogl/common/

Files normalized:
 cogl.c
 cogl-context.c
 cogl-context.h
 cogl-texture.c
This commit is contained in:
Robert Bragg 2009-01-28 14:09:51 +00:00
parent b69d49e43c
commit 02127858f3
6 changed files with 233 additions and 134 deletions

View file

@ -49,12 +49,7 @@ typedef struct
gboolean enable_backface_culling; gboolean enable_backface_culling;
/* Cache of inverse projection matrix */ /* Cache of inverse projection matrix */
GLfloat inverse_projection[16]; float inverse_projection[16];
/* Textures */
GArray *texture_handles;
CoglHandle default_gl_texture_2d_tex;
CoglHandle default_gl_texture_rect_tex;
/* Materials */ /* Materials */
GArray *material_handles; GArray *material_handles;
@ -62,6 +57,12 @@ typedef struct
CoglHandle default_material; CoglHandle default_material;
CoglHandle source_material; CoglHandle source_material;
/* Textures */
GArray *texture_handles;
CoglHandle default_gl_texture_2d_tex;
CoglHandle default_gl_texture_rect_tex;
/* Batching geometry... */ /* Batching geometry... */
/* We journal the texture rectangles we want to submit to OpenGL so /* We journal the texture rectangles we want to submit to OpenGL so
* we have an oppertunity to optimise the final order so that we * we have an oppertunity to optimise the final order so that we

View file

@ -52,10 +52,16 @@
} */ } */
#ifdef HAVE_COGL_GL #ifdef HAVE_COGL_GL
#ifdef glDrawRangeElements
#undef glDrawRangeElements
#endif
#define glDrawRangeElements ctx->pf_glDrawRangeElements #define glDrawRangeElements ctx->pf_glDrawRangeElements
#else
/* GLES doesn't have glDrawRangeElements, so we simply pretend it does
* but that it makes no use of the start, end constraints: */
#define glDrawRangeElements(mode, start, end, count, type, indices) \
glDrawElements (mode, count, type, indices)
#endif #endif
static void _cogl_journal_flush (void); static void _cogl_journal_flush (void);
@ -1967,6 +1973,7 @@ _cogl_journal_flush_quad_batch (CoglJournalEntry *batch_start,
int i; int i;
gulong enable_flags = 0; gulong enable_flags = 0;
guint32 disable_mask; guint32 disable_mask;
int prev_n_texcoord_arrays_enabled;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
@ -2027,12 +2034,14 @@ _cogl_journal_flush_quad_batch (CoglJournalEntry *batch_start,
GE (glEnableClientState (GL_TEXTURE_COORD_ARRAY)); GE (glEnableClientState (GL_TEXTURE_COORD_ARRAY));
GE (glTexCoordPointer (2, GL_FLOAT, stride, vertex_pointer + 2 + 2 * i)); GE (glTexCoordPointer (2, GL_FLOAT, stride, vertex_pointer + 2 + 2 * i));
} }
for (; i < ctx->n_texcoord_arrays_enabled; i++) prev_n_texcoord_arrays_enabled =
ctx->n_texcoord_arrays_enabled;
ctx->n_texcoord_arrays_enabled = i + 1;
for (; i < prev_n_texcoord_arrays_enabled; i++)
{ {
GE (glClientActiveTexture (GL_TEXTURE0 + i)); GE (glClientActiveTexture (GL_TEXTURE0 + i));
GE (glDisableClientState (GL_TEXTURE_COORD_ARRAY)); GE (glDisableClientState (GL_TEXTURE_COORD_ARRAY));
} }
ctx->n_texcoord_arrays_enabled = 0;
/* FIXME: This api is a bit yukky, ideally it will be removed if we /* FIXME: This api is a bit yukky, ideally it will be removed if we
* re-work the cogl_enable mechanism */ * re-work the cogl_enable mechanism */
@ -2046,7 +2055,7 @@ _cogl_journal_flush_quad_batch (CoglJournalEntry *batch_start,
GE (glVertexPointer (2, GL_FLOAT, stride, vertex_pointer)); GE (glVertexPointer (2, GL_FLOAT, stride, vertex_pointer));
GE (ctx->pf_glDrawRangeElements (GL_TRIANGLES, GE (glDrawRangeElements (GL_TRIANGLES,
0, ctx->static_indices->len - 1, 0, ctx->static_indices->len - 1,
6 * batch_len, 6 * batch_len,
GL_UNSIGNED_SHORT, GL_UNSIGNED_SHORT,
@ -2995,6 +3004,7 @@ cogl_polygon (CoglTextureVertex *vertices,
guint stride; guint stride;
gsize stride_bytes; gsize stride_bytes;
GLfloat *v; GLfloat *v;
int prev_n_texcoord_arrays_enabled;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
@ -3049,12 +3059,13 @@ cogl_polygon (CoglTextureVertex *vertices,
return; return;
} }
#ifdef HAVE_COGL_GL
/* Temporarily change the wrapping mode on all of the slices to use /* Temporarily change the wrapping mode on all of the slices to use
* a transparent border * a transparent border
* XXX: it's doesn't look like we save/restore this, like the comment * XXX: it's doesn't look like we save/restore this, like the comment
* implies? */ * implies? */
_cogl_texture_set_wrap_mode_parameter (tex, GL_CLAMP_TO_BORDER); _cogl_texture_set_wrap_mode_parameter (tex, GL_CLAMP_TO_BORDER);
#endif
break; break;
} }
@ -3110,6 +3121,14 @@ cogl_polygon (CoglTextureVertex *vertices,
/* NB: [X,Y,Z,TX,TY...,R,G,B,A,...] */ /* NB: [X,Y,Z,TX,TY...,R,G,B,A,...] */
v + 3 + 2 * i)); v + 3 + 2 * i));
} }
prev_n_texcoord_arrays_enabled =
ctx->n_texcoord_arrays_enabled;
ctx->n_texcoord_arrays_enabled = i + 1;
for (; i < prev_n_texcoord_arrays_enabled; i++)
{
GE (glClientActiveTexture (GL_TEXTURE0 + i));
GE (glDisableClientState (GL_TEXTURE_COORD_ARRAY));
}
if (use_sliced_polygon_fallback) if (use_sliced_polygon_fallback)
_cogl_texture_sliced_polygon (vertices, _cogl_texture_sliced_polygon (vertices,

View file

@ -45,6 +45,10 @@ typedef CoglFuncPtr (*GLXGetProcAddressProc) (const guint8 *procName);
#include "cogl-util.h" #include "cogl-util.h"
#include "cogl-context.h" #include "cogl-context.h"
#if defined (HAVE_COGL_GLES2) || defined (HAVE_COGL_GLES)
#include "cogl-gles2-wrapper.h"
#endif
/* GL error to string conversion */ /* GL error to string conversion */
#if COGL_DEBUG #if COGL_DEBUG
struct token_string struct token_string
@ -388,7 +392,11 @@ set_clip_plane (GLint plane_num,
const float *vertex_a, const float *vertex_a,
const float *vertex_b) const float *vertex_b)
{ {
#if defined (HAVE_COGL_GLES2) || defined (HAVE_COGL_GLES)
GLfloat plane[4];
#else
GLdouble plane[4]; GLdouble plane[4];
#endif
GLfloat angle; GLfloat angle;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
@ -414,7 +422,11 @@ set_clip_plane (GLint plane_num,
plane[1] = -1.0; plane[1] = -1.0;
plane[2] = 0; plane[2] = 0;
plane[3] = vertex_a[1]; plane[3] = vertex_a[1];
#if defined (HAVE_COGL_GLES2) || defined (HAVE_COGL_GLES)
GE( glClipPlanef (plane_num, plane) );
#else
GE( glClipPlane (plane_num, plane) ); GE( glClipPlane (plane_num, plane) );
#endif
GE( glPopMatrix () ); GE( glPopMatrix () );
} }
@ -473,6 +485,8 @@ _cogl_add_stencil_clip (float x_offset,
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
cogl_material_flush_gl_state (ctx->stencil_material);
if (first) if (first)
{ {
GE( glEnable (GL_STENCIL_TEST) ); GE( glEnable (GL_STENCIL_TEST) );
@ -484,10 +498,9 @@ _cogl_add_stencil_clip (float x_offset,
/* Punch out a hole to allow the rectangle */ /* Punch out a hole to allow the rectangle */
GE( glStencilFunc (GL_NEVER, 0x1, 0x1) ); GE( glStencilFunc (GL_NEVER, 0x1, 0x1) );
GE( glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE) ); GE( glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE) );
GE( glRectf ( (x_offset),
(y_offset), cogl_rectangle (x_offset, y_offset,
(x_offset + width), x_offset + width, y_offset + height);
(y_offset + height)) );
} }
else else
{ {
@ -495,10 +508,8 @@ _cogl_add_stencil_clip (float x_offset,
rectangle */ rectangle */
GE( glStencilFunc (GL_NEVER, 0x1, 0x3) ); GE( glStencilFunc (GL_NEVER, 0x1, 0x3) );
GE( glStencilOp (GL_INCR, GL_INCR, GL_INCR) ); GE( glStencilOp (GL_INCR, GL_INCR, GL_INCR) );
GE( glRectf ( (x_offset), cogl_rectangle (x_offset, y_offset,
(y_offset), x_offset + width, y_offset + height);
(x_offset + width),
(y_offset + height)) );
/* Subtract one from all pixels in the stencil buffer so that /* Subtract one from all pixels in the stencil buffer so that
only pixels where both the original stencil buffer and the only pixels where both the original stencil buffer and the
@ -509,7 +520,7 @@ _cogl_add_stencil_clip (float x_offset,
GE( glMatrixMode (GL_PROJECTION) ); GE( glMatrixMode (GL_PROJECTION) );
GE( glPushMatrix () ); GE( glPushMatrix () );
GE( glLoadIdentity () ); GE( glLoadIdentity () );
GE( glRectf (-1, 1, 1, -1) ); cogl_rectangle (-1.0, -1.0, 1.0, 1.0);
GE( glPopMatrix () ); GE( glPopMatrix () );
GE( glMatrixMode (GL_MODELVIEW) ); GE( glMatrixMode (GL_MODELVIEW) );
GE( glPopMatrix () ); GE( glPopMatrix () );
@ -1121,7 +1132,18 @@ cogl_get_projection_matrix (float m[16])
void void
cogl_get_viewport (float v[4]) cogl_get_viewport (float v[4])
{ {
/* FIXME: cogl_get_viewport should return a gint vec */
#if defined (HAVE_COGL_GLES2) || defined (HAVE_COGL_GLES)
GLint viewport[4];
int i;
glGetIntegerv (GL_VIEWPORT, viewport);
for (i = 0; i < 4; i++)
v[i] = (float)(viewport[i]);
#else
glGetFloatv (GL_VIEWPORT, v); glGetFloatv (GL_VIEWPORT, v);
#endif
} }
void void
@ -1167,7 +1189,8 @@ cogl_fog_set (const CoglColor *fog_color,
glFogfv (GL_FOG_COLOR, fogColor); glFogfv (GL_FOG_COLOR, fogColor);
glFogi (GL_FOG_MODE, GL_LINEAR); /* NB: GLES doesn't have glFogi */
glFogf (GL_FOG_MODE, GL_LINEAR);
glHint (GL_FOG_HINT, GL_NICEST); glHint (GL_FOG_HINT, GL_NICEST);
glFogf (GL_FOG_DENSITY, (GLfloat) density); glFogf (GL_FOG_DENSITY, (GLfloat) density);

View file

@ -107,22 +107,22 @@ cogl_create_context ()
cogl_texture_new_from_data (1, /* width */ cogl_texture_new_from_data (1, /* width */
1, /* height */ 1, /* height */
-1, /* max waste */ -1, /* max waste */
FALSE, /* auto mipmap */ COGL_TEXTURE_NONE, /* flags */
COGL_PIXEL_FORMAT_RGBA_8888, /* data format */ COGL_PIXEL_FORMAT_RGBA_8888, /* data format */
/* internal format */ /* internal format */
COGL_PIXEL_FORMAT_RGBA_8888, COGL_PIXEL_FORMAT_RGBA_8888,
0, /* auto calc row stride */ 0, /* auto calc row stride */
&default_texture_data); default_texture_data);
_context->default_gl_texture_rect_tex = _context->default_gl_texture_rect_tex =
cogl_texture_new_from_data (1, /* width */ cogl_texture_new_from_data (1, /* width */
1, /* height */ 1, /* height */
-1, /* max waste */ -1, /* max waste */
FALSE, /* auto mipmap */ COGL_TEXTURE_NONE, /* flags */
COGL_PIXEL_FORMAT_RGBA_8888, /* data format */ COGL_PIXEL_FORMAT_RGBA_8888, /* data format */
/* internal format */ /* internal format */
COGL_PIXEL_FORMAT_RGBA_8888, COGL_PIXEL_FORMAT_RGBA_8888,
0, /* auto calc row stride */ 0, /* auto calc row stride */
&default_texture_data); default_texture_data);
cogl_set_source (_context->default_material); cogl_set_source (_context->default_material);
cogl_material_flush_gl_state (_context->source_material, NULL); cogl_material_flush_gl_state (_context->source_material, NULL);

View file

@ -2086,6 +2086,7 @@ _cogl_journal_flush_quad_batch (CoglJournalEntry *batch_start,
int i; int i;
gulong enable_flags = 0; gulong enable_flags = 0;
guint32 disable_mask; guint32 disable_mask;
int prev_n_texcoord_arrays_enabled;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
@ -2146,14 +2147,14 @@ _cogl_journal_flush_quad_batch (CoglJournalEntry *batch_start,
GE (glEnableClientState (GL_TEXTURE_COORD_ARRAY)); GE (glEnableClientState (GL_TEXTURE_COORD_ARRAY));
GE (glTexCoordPointer (2, GL_FLOAT, stride, vertex_pointer + 2 + 2 * i)); GE (glTexCoordPointer (2, GL_FLOAT, stride, vertex_pointer + 2 + 2 * i));
} }
/* XXX: Without this we get a segfault with the PVR SDK. prev_n_texcoord_arrays_enabled =
* We should probably be doing this for cogl/gl too though. */ ctx->n_texcoord_arrays_enabled;
for (; i < ctx->n_texcoord_arrays_enabled; i++) ctx->n_texcoord_arrays_enabled = i + 1;
for (; i < prev_n_texcoord_arrays_enabled; i++)
{ {
GE (glClientActiveTexture (GL_TEXTURE0 + i)); GE (glClientActiveTexture (GL_TEXTURE0 + i));
GE (glDisableClientState (GL_TEXTURE_COORD_ARRAY)); GE (glDisableClientState (GL_TEXTURE_COORD_ARRAY));
} }
ctx->n_texcoord_arrays_enabled = i + 1;
/* FIXME: This api is a bit yukky, ideally it will be removed if we /* FIXME: This api is a bit yukky, ideally it will be removed if we
* re-work the cogl_enable mechanism */ * re-work the cogl_enable mechanism */
@ -2172,6 +2173,33 @@ _cogl_journal_flush_quad_batch (CoglJournalEntry *batch_start,
6 * batch_len, 6 * batch_len,
GL_UNSIGNED_SHORT, GL_UNSIGNED_SHORT,
ctx->static_indices->data)); ctx->static_indices->data));
/* DEBUGGING CODE XXX:
* Uncommenting this will cause all rectangles to be drawn with a red, green
* or blue outline with no blending. This may e.g. help with debugging
* texture slicing issues or blending issues, plus it looks quite cool.
*/
#if 0
{
static CoglHandle outline = COGL_INVALID_HANDLE;
static int color = 0;
if (outline == COGL_INVALID_HANDLE)
outline = cogl_material_new ();
cogl_enable (COGL_ENABLE_VERTEX_ARRAY);
for (i = 0; i < batch_len; i++, color = (++color) % 3)
{
cogl_material_set_color4ub (outline,
color == 0 ? 0xff : 0x00,
color == 1 ? 0xff : 0x00,
color == 2 ? 0xff : 0x00,
0xff);
cogl_material_flush_gl_state (outline, NULL);
GE( glDrawArrays (GL_LINE_LOOP, 4 * i, 4) );
}
}
#endif
} }
static void static void
@ -2234,8 +2262,6 @@ _cogl_journal_flush (void)
stride = 2 + current_entry->n_layers * 2; stride = 2 + current_entry->n_layers * 2;
current_vertex_pointer += stride; current_vertex_pointer += stride;
#warning "NB: re-enable batching"
#if 1
/* batch rectangles using the same textures */ /* batch rectangles using the same textures */
if (current_entry->material == prev_entry->material && if (current_entry->material == prev_entry->material &&
current_entry->n_layers == prev_entry->n_layers && current_entry->n_layers == prev_entry->n_layers &&
@ -2246,7 +2272,6 @@ _cogl_journal_flush (void)
batch_len++; batch_len++;
continue; continue;
} }
#endif
_cogl_journal_flush_quad_batch (batch_start, _cogl_journal_flush_quad_batch (batch_start,
batch_len, batch_len,
@ -2268,10 +2293,10 @@ _cogl_journal_flush (void)
} }
static void static void
_cogl_journal_log_quad (float x1, _cogl_journal_log_quad (float x_1,
float y1, float y_1,
float x2, float x_2,
float y2, float y_2,
CoglHandle material, CoglHandle material,
gint n_layers, gint n_layers,
guint32 fallback_mask, guint32 fallback_mask,
@ -2308,13 +2333,13 @@ _cogl_journal_log_quad (float x1,
/* XXX: we could defer expanding the vertex data for GL until we come /* XXX: we could defer expanding the vertex data for GL until we come
* to flushing the journal. */ * to flushing the journal. */
v[0] = x1; v[1] = y1; v[0] = x_1; v[1] = y_1;
v += stride; v += stride;
v[0] = x1; v[1] = y2; v[0] = x_1; v[1] = y_2;
v += stride; v += stride;
v[0] = x2; v[1] = y2; v[0] = x_2; v[1] = y_2;
v += stride; v += stride;
v[0] = x2; v[1] = y1; v[0] = x_2; v[1] = y_1;
for (i = 0; i < n_layers; i++) for (i = 0; i < n_layers; i++)
{ {
@ -2343,14 +2368,14 @@ _cogl_journal_log_quad (float x1,
static void static void
_cogl_texture_sliced_quad (CoglTexture *tex, _cogl_texture_sliced_quad (CoglTexture *tex,
CoglHandle material, CoglHandle material,
float x1, float x_1,
float y1, float y_1,
float x2, float x_2,
float y2, float y_2,
float tx1, float tx_1,
float ty1, float ty_1,
float tx2, float tx_2,
float ty2) float ty_2)
{ {
CoglSpanIter iter_x , iter_y; CoglSpanIter iter_x , iter_y;
float tw , th; float tw , th;
@ -2377,52 +2402,52 @@ _cogl_texture_sliced_quad (CoglTexture *tex,
geometry and texture coordinates so that the texture will be geometry and texture coordinates so that the texture will be
flipped but we can still use the same algorithm to iterate the flipped but we can still use the same algorithm to iterate the
slices */ slices */
if (tx2 < tx1) if (tx_2 < tx_1)
{ {
float temp = x1; float temp = x_1;
x1 = x2; x_1 = x_2;
x2 = temp; x_2 = temp;
temp = tx1; temp = tx_1;
tx1 = tx2; tx_1 = tx_2;
tx2 = temp; tx_2 = temp;
} }
if (ty2 < ty1) if (ty_2 < ty_1)
{ {
float temp = y1; float temp = y_1;
y1 = y2; y_1 = y_2;
y2 = temp; y_2 = temp;
temp = ty1; temp = ty_1;
ty1 = ty2; ty_1 = ty_2;
ty2 = temp; ty_2 = temp;
} }
/* Scale ratio from texture to quad widths */ /* Scale ratio from texture to quad widths */
tw = (float)(tex->bitmap.width); tw = (float)(tex->bitmap.width);
th = (float)(tex->bitmap.height); th = (float)(tex->bitmap.height);
tqx = (x2 - x1) / (tw * (tx2 - tx1)); tqx = (x_2 - x_1) / (tw * (tx_2 - tx_1));
tqy = (y2 - y1) / (th * (ty2 - ty1)); tqy = (y_2 - y_1) / (th * (ty_2 - ty_1));
/* Integral texture coordinate for first tile */ /* Integral texture coordinate for first tile */
first_tx = (float)(floorf (tx1)); first_tx = (float)(floorf (tx_1));
first_ty = (float)(floorf (ty1)); first_ty = (float)(floorf (ty_1));
/* Denormalize texture coordinates */ /* Denormalize texture coordinates */
first_tx = (first_tx * tw); first_tx = (first_tx * tw);
first_ty = (first_ty * th); first_ty = (first_ty * th);
tx1 = (tx1 * tw); tx_1 = (tx_1 * tw);
ty1 = (ty1 * th); ty_1 = (ty_1 * th);
tx2 = (tx2 * tw); tx_2 = (tx_2 * tw);
ty2 = (ty2 * th); ty_2 = (ty_2 * th);
/* Quad coordinate of the first tile */ /* Quad coordinate of the first tile */
first_qx = x1 - (tx1 - first_tx) * tqx; first_qx = x_1 - (tx_1 - first_tx) * tqx;
first_qy = y1 - (ty1 - first_ty) * tqy; first_qy = y_1 - (ty_1 - first_ty) * tqy;
/* Iterate until whole quad height covered */ /* Iterate until whole quad height covered */
for (_cogl_span_iter_begin (&iter_y, tex->slice_y_spans, for (_cogl_span_iter_begin (&iter_y, tex->slice_y_spans,
first_ty, ty1, ty2) ; first_ty, ty_1, ty_2) ;
!_cogl_span_iter_end (&iter_y) ; !_cogl_span_iter_end (&iter_y) ;
_cogl_span_iter_next (&iter_y) ) _cogl_span_iter_next (&iter_y) )
{ {
@ -2445,7 +2470,7 @@ _cogl_texture_sliced_quad (CoglTexture *tex,
/* 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, tx_1, tx_2) ;
!_cogl_span_iter_end (&iter_x) ; !_cogl_span_iter_end (&iter_x) ;
_cogl_span_iter_next (&iter_x) ) _cogl_span_iter_next (&iter_x) )
{ {
@ -2502,10 +2527,10 @@ _cogl_texture_sliced_quad (CoglTexture *tex,
} }
static gboolean static gboolean
_cogl_multitexture_unsliced_quad (float x1, _cogl_multitexture_unsliced_quad (float x_1,
float y1, float y_1,
float x2, float x_2,
float y2, float y_2,
CoglHandle material, CoglHandle material,
gint n_layers, gint n_layers,
guint32 fallback_mask, guint32 fallback_mask,
@ -2619,10 +2644,10 @@ _cogl_multitexture_unsliced_quad (float x1,
} }
else else
{ {
out_tex_coords[0] = 0; /* tx1 */ out_tex_coords[0] = 0; /* tx_1 */
out_tex_coords[1] = 0; /* ty1 */ out_tex_coords[1] = 0; /* ty_1 */
out_tex_coords[2] = 1.0; /* tx2 */ out_tex_coords[2] = 1.0; /* tx_2 */
out_tex_coords[3] = 1.0; /* ty2 */ out_tex_coords[3] = 1.0; /* ty_2 */
_cogl_texture_set_wrap_mode_parameter (tex, GL_CLAMP_TO_EDGE); _cogl_texture_set_wrap_mode_parameter (tex, GL_CLAMP_TO_EDGE);
} }
@ -2641,10 +2666,10 @@ _cogl_multitexture_unsliced_quad (float x1,
out_tex_coords[3] * (y_span->size - y_span->waste) / y_span->size; out_tex_coords[3] * (y_span->size - y_span->waste) / y_span->size;
} }
_cogl_journal_log_quad (x1, _cogl_journal_log_quad (x_1,
y1, y_1,
x2, x_2,
y2, y_2,
material, material,
n_layers, n_layers,
fallback_mask, fallback_mask,
@ -2657,10 +2682,10 @@ _cogl_multitexture_unsliced_quad (float x1,
struct _CoglMutiTexturedRect struct _CoglMutiTexturedRect
{ {
float x1; float x_1;
float y1; float y_1;
float x2; float x_2;
float y2; float y_2;
const float *tex_coords; const float *tex_coords;
gint tex_coords_len; gint tex_coords_len;
}; };
@ -2768,27 +2793,25 @@ _cogl_rectangles_with_multitexture_coords (
for (i = 0; i < n_rects; i++) for (i = 0; i < n_rects; i++)
{ {
if (all_use_sliced_quad_fallback if (all_use_sliced_quad_fallback
|| !_cogl_multitexture_unsliced_quad (rects[i].x1, rects[i].y1, || !_cogl_multitexture_unsliced_quad (rects[i].x_1, rects[i].y_1,
rects[i].x2, rects[i].y2, rects[i].x_2, rects[i].y_2,
material, material,
n_layers, n_layers,
fallback_mask, fallback_mask,
rects[i].tex_coords, rects[i].tex_coords,
rects[i].tex_coords_len)) rects[i].tex_coords_len))
{ {
const GList *layers; CoglHandle first_layer, tex_handle;
CoglHandle tex_handle;
CoglTexture *texture; CoglTexture *texture;
layers = cogl_material_get_layers (material); first_layer = layers->data;
tex_handle = tex_handle = cogl_material_layer_get_texture (first_layer);
cogl_material_layer_get_texture ((CoglHandle)layers->data);
texture = _cogl_texture_pointer_from_handle (tex_handle); texture = _cogl_texture_pointer_from_handle (tex_handle);
if (rects[i].tex_coords) if (rects[i].tex_coords)
_cogl_texture_sliced_quad (texture, _cogl_texture_sliced_quad (texture,
material, material,
rects[i].x1, rects[i].y1, rects[i].x_1, rects[i].y_1,
rects[i].x2, rects[i].y2, rects[i].x_2, rects[i].y_2,
rects[i].tex_coords[0], rects[i].tex_coords[0],
rects[i].tex_coords[1], rects[i].tex_coords[1],
rects[i].tex_coords[2], rects[i].tex_coords[2],
@ -2796,8 +2819,8 @@ _cogl_rectangles_with_multitexture_coords (
else else
_cogl_texture_sliced_quad (texture, _cogl_texture_sliced_quad (texture,
material, material,
rects[i].x1, rects[i].y1, rects[i].x_1, rects[i].y_1,
rects[i].x2, rects[i].y2, rects[i].x_2, rects[i].y_2,
0.0f, 0.0f, 1.0f, 1.0f); 0.0f, 0.0f, 1.0f, 1.0f);
} }
} }
@ -2807,17 +2830,17 @@ _cogl_rectangles_with_multitexture_coords (
void void
cogl_rectangles_with_texture_coords (const float *verts, cogl_rectangles_with_texture_coords (const float *verts,
guint n_rects) guint n_rects)
{ {
struct _CoglMutiTexturedRect rects[n_rects]; struct _CoglMutiTexturedRect rects[n_rects];
int i; int i;
for (i = 0; i < n_rects; i++) for (i = 0; i < n_rects; i++)
{ {
rects[i].x1 = verts[i * 8]; rects[i].x_1 = verts[i * 8];
rects[i].y1 = verts[i * 8 + 1]; rects[i].y_1 = verts[i * 8 + 1];
rects[i].x2 = verts[i * 8 + 2]; rects[i].x_2 = verts[i * 8 + 2];
rects[i].y2 = verts[i * 8 + 3]; rects[i].y_2 = verts[i * 8 + 3];
/* FIXME: rect should be defined to have a const float *geom; /* FIXME: rect should be defined to have a const float *geom;
* instead, to avoid this copy * instead, to avoid this copy
* rect[i].geom = &verts[n_rects * 8]; */ * rect[i].geom = &verts[n_rects * 8]; */
@ -2829,43 +2852,43 @@ cogl_rectangles_with_texture_coords (const float *verts,
} }
void void
cogl_rectangle_with_texture_coords (float x1, cogl_rectangle_with_texture_coords (float x_1,
float y1, float y_1,
float x2, float x_2,
float y2, float y_2,
float tx1, float tx_1,
float ty1, float ty_1,
float tx2, float tx_2,
float ty2) float ty_2)
{ {
float verts[8]; float verts[8];
verts[0] = x1; verts[0] = x_1;
verts[1] = y1; verts[1] = y_1;
verts[2] = x2; verts[2] = x_2;
verts[3] = y2; verts[3] = y_2;
verts[4] = tx1; verts[4] = tx_1;
verts[5] = ty1; verts[5] = ty_1;
verts[6] = tx2; verts[6] = tx_2;
verts[7] = ty2; verts[7] = ty_2;
cogl_rectangles_with_texture_coords (verts, 1); cogl_rectangles_with_texture_coords (verts, 1);
} }
void void
cogl_rectangle_with_multitexture_coords (float x1, cogl_rectangle_with_multitexture_coords (float x_1,
float y1, float y_1,
float x2, float x_2,
float y2, float y_2,
const float *user_tex_coords, const float *user_tex_coords,
gint user_tex_coords_len) gint user_tex_coords_len)
{ {
struct _CoglMutiTexturedRect rect; struct _CoglMutiTexturedRect rect;
rect.x1 = x1; rect.x_1 = x_1;
rect.y1 = y1; rect.y_1 = y_1;
rect.x2 = x2; rect.x_2 = x_2;
rect.y2 = y2; rect.y_2 = y_2;
rect.tex_coords = user_tex_coords; rect.tex_coords = user_tex_coords;
rect.tex_coords_len = user_tex_coords_len; rect.tex_coords_len = user_tex_coords_len;
@ -2985,7 +3008,6 @@ _cogl_multitexture_unsliced_polygon (CoglTextureVertex *vertices,
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
v = (GLfloat *)ctx->logged_vertices->data;
material = ctx->source_material; material = ctx->source_material;
layers = cogl_material_get_layers (material); layers = cogl_material_get_layers (material);
@ -3065,6 +3087,7 @@ cogl_polygon (CoglTextureVertex *vertices,
guint stride; guint stride;
gsize stride_bytes; gsize stride_bytes;
GLfloat *v; GLfloat *v;
int prev_n_texcoord_arrays_enabled;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
@ -3175,11 +3198,20 @@ cogl_polygon (CoglTextureVertex *vertices,
for (i = 0; i < n_layers; i++) for (i = 0; i < n_layers; i++)
{ {
GE (glClientActiveTexture (GL_TEXTURE0 + i)); GE (glClientActiveTexture (GL_TEXTURE0 + i));
GE (glEnableClientState (GL_TEXTURE_COORD_ARRAY));
GE (glTexCoordPointer (2, GL_FLOAT, GE (glTexCoordPointer (2, GL_FLOAT,
stride_bytes, stride_bytes,
/* NB: [X,Y,Z,TX,TY...,R,G,B,A,...] */ /* NB: [X,Y,Z,TX,TY...,R,G,B,A,...] */
v + 3 + 2 * i)); v + 3 + 2 * i));
} }
prev_n_texcoord_arrays_enabled =
ctx->n_texcoord_arrays_enabled;
ctx->n_texcoord_arrays_enabled = i + 1;
for (; i < prev_n_texcoord_arrays_enabled; i++)
{
GE (glClientActiveTexture (GL_TEXTURE0 + i));
GE (glDisableClientState (GL_TEXTURE_COORD_ARRAY));
}
if (use_sliced_polygon_fallback) if (use_sliced_polygon_fallback)
_cogl_texture_sliced_polygon (vertices, _cogl_texture_sliced_polygon (vertices,

View file

@ -30,14 +30,24 @@
#include "cogl.h" #include "cogl.h"
#include <string.h> #include <string.h>
#include <gmodule.h>
#include <math.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_CLUTTER_GLX
#include <dlfcn.h>
#include <GL/glx.h>
typedef CoglFuncPtr (*GLXGetProcAddressProc) (const guint8 *procName);
#endif
#include "cogl-internal.h" #include "cogl-internal.h"
#include "cogl-util.h" #include "cogl-util.h"
#include "cogl-context.h" #include "cogl-context.h"
#if defined (HAVE_COGL_GLES2) || defined (HAVE_COGL_GLES)
#include "cogl-gles2-wrapper.h" #include "cogl-gles2-wrapper.h"
#include <math.h> #endif
/* GL error to string conversion */ /* GL error to string conversion */
#if COGL_DEBUG #if COGL_DEBUG
@ -305,7 +315,11 @@ set_clip_plane (GLint plane_num,
const float *vertex_a, const float *vertex_a,
const float *vertex_b) const float *vertex_b)
{ {
#if defined (HAVE_COGL_GLES2) || defined (HAVE_COGL_GLES)
GLfloat plane[4]; GLfloat plane[4];
#else
GLdouble plane[4];
#endif
GLfloat angle; GLfloat angle;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
@ -331,7 +345,11 @@ set_clip_plane (GLint plane_num,
plane[1] = -1.0; plane[1] = -1.0;
plane[2] = 0; plane[2] = 0;
plane[3] = vertex_a[1]; plane[3] = vertex_a[1];
#if defined (HAVE_COGL_GLES2) || defined (HAVE_COGL_GLES)
GE( glClipPlanef (plane_num, plane) ); GE( glClipPlanef (plane_num, plane) );
#else
GE( glClipPlane (plane_num, plane) );
#endif
GE( glPopMatrix () ); GE( glPopMatrix () );
} }
@ -677,6 +695,8 @@ cogl_get_projection_matrix (float m[16])
void void
cogl_get_viewport (float v[4]) cogl_get_viewport (float v[4])
{ {
/* FIXME: cogl_get_viewport should return a gint vec */
#if defined (HAVE_COGL_GLES2) || defined (HAVE_COGL_GLES)
GLint viewport[4]; GLint viewport[4];
int i; int i;
@ -684,6 +704,9 @@ cogl_get_viewport (float v[4])
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
v[i] = (float)(viewport[i]); v[i] = (float)(viewport[i]);
#else
glGetFloatv (GL_VIEWPORT, v);
#endif
} }
void void
@ -729,6 +752,7 @@ cogl_fog_set (const CoglColor *fog_color,
glFogfv (GL_FOG_COLOR, fogColor); glFogfv (GL_FOG_COLOR, fogColor);
/* NB: GLES doesn't have glFogi */
glFogf (GL_FOG_MODE, GL_LINEAR); glFogf (GL_FOG_MODE, GL_LINEAR);
glHint (GL_FOG_HINT, GL_NICEST); glHint (GL_FOG_HINT, GL_NICEST);