Merge remote branch 'master' into texture-debugging

Conflicts:
	clutter/cogl/cogl/cogl-context.h
This commit is contained in:
Neil Roberts 2010-02-01 13:37:19 +00:00
commit efcbd20320
9 changed files with 118 additions and 39 deletions

View File

@ -115,6 +115,12 @@ typedef struct
CoglAtlas *atlas; CoglAtlas *atlas;
CoglHandle atlas_texture; CoglHandle atlas_texture;
/* This debugging variable is used to pick a colour for visually
displaying the quad batches. It needs to be global so that it can
be reset by cogl_clear. It needs to be reset to increase the
chances of getting the same colour during an animation */
guint8 journal_rectangles_color;
CoglContextDriver drv; CoglContextDriver drv;
} CoglContext; } CoglContext;

View File

@ -101,6 +101,8 @@ CoglTextureUnit *
_cogl_get_texture_unit (int index_); _cogl_get_texture_unit (int index_);
void void
_cogl_destroy_texture_units (void); _cogl_destroy_texture_units (void);
guint
_cogl_get_max_texture_image_units (void);
void void
_cogl_flush_face_winding (void); _cogl_flush_face_winding (void);

View File

@ -225,30 +225,51 @@ _cogl_journal_flush_modelview_and_entries (CoglJournalEntry *batch_start,
} }
#endif #endif
/* DEBUGGING CODE XXX: /* DEBUGGING CODE XXX: This path will cause all rectangles to be
* This path will cause all rectangles to be drawn with a red, green * drawn with a coloured outline. Each batch will be rendered with
* or blue outline with no blending. This may e.g. help with debugging * the same color. This may e.g. help with debugging texture slicing
* texture slicing issues or blending issues, plus it looks quite cool. * issues, visually seeing what is batched and debugging blending
* issues, plus it looks quite cool.
*/ */
if (cogl_debug_flags & COGL_DEBUG_RECTANGLES) if (cogl_debug_flags & COGL_DEBUG_RECTANGLES)
{ {
static CoglHandle outline = COGL_INVALID_HANDLE; static CoglHandle outline = COGL_INVALID_HANDLE;
static int color = 0; guint8 color_intensity;
int i; int i;
_COGL_GET_CONTEXT (ctxt, NO_RETVAL);
if (outline == COGL_INVALID_HANDLE) if (outline == COGL_INVALID_HANDLE)
outline = cogl_material_new (); outline = cogl_material_new ();
/* The least significant three bits represent the three
components so that the order of colours goes red, green,
yellow, blue, magenta, cyan. Black and white are skipped. The
next two bits give four scales of intensity for those colours
in the order 0xff, 0xcc, 0x99, and 0x66. This gives a total
of 24 colours. If there are more than 24 batches on the stage
then it will wrap around */
color_intensity = 0xff - 0x33 * (ctxt->journal_rectangles_color >> 3);
cogl_material_set_color4ub (outline,
(ctxt->journal_rectangles_color & 1) ?
color_intensity : 0,
(ctxt->journal_rectangles_color & 2) ?
color_intensity : 0,
(ctxt->journal_rectangles_color & 4) ?
color_intensity : 0,
0xff);
_cogl_material_flush_gl_state (outline, NULL);
cogl_enable (COGL_ENABLE_VERTEX_ARRAY); cogl_enable (COGL_ENABLE_VERTEX_ARRAY);
for (i = 0; i < batch_len; i++, color = (color + 1) % 3) for (i = 0; i < batch_len; i++)
{ GE( glDrawArrays (GL_LINE_LOOP, 4 * i + state->vertex_offset, 4) );
cogl_material_set_color4ub (outline,
color == 0 ? 0xff : 0x00, /* Go to the next color */
color == 1 ? 0xff : 0x00, do
color == 2 ? 0xff : 0x00, ctxt->journal_rectangles_color = ((ctxt->journal_rectangles_color + 1) &
0xff); ((1 << 5) - 1));
_cogl_material_flush_gl_state (outline, NULL); /* We don't want to use black or white */
GE( glDrawArrays (GL_LINE_LOOP, 4 * i, 4) ); while ((ctxt->journal_rectangles_color & 0x07) == 0
} || (ctxt->journal_rectangles_color & 0x07) == 0x07);
} }
state->vertex_offset += (4 * batch_len); state->vertex_offset += (4 * batch_len);
@ -779,8 +800,7 @@ _cogl_journal_log_quad (float x_1,
if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DISABLE_SOFTWARE_TRANSFORM)) if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DISABLE_SOFTWARE_TRANSFORM))
cogl_get_modelview_matrix (&entry->model_view); cogl_get_modelview_matrix (&entry->model_view);
if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DISABLE_BATCHING if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DISABLE_BATCHING))
|| cogl_debug_flags & COGL_DEBUG_RECTANGLES))
_cogl_journal_flush (); _cogl_journal_flush ();
COGL_TIMER_STOP (_cogl_uprof_context, log_timer); COGL_TIMER_STOP (_cogl_uprof_context, log_timer);

View File

@ -48,12 +48,6 @@
#include "../gles/cogl-gles2-wrapper.h" #include "../gles/cogl-gles2-wrapper.h"
#endif #endif
#ifdef HAVE_COGL_GLES
#define COGL_MATERIAL_MAX_TEXTURE_UNITS GL_MAX_TEXTURE_UNITS
#else
#define COGL_MATERIAL_MAX_TEXTURE_UNITS GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS
#endif
#ifdef HAVE_COGL_GL #ifdef HAVE_COGL_GL
#define glActiveTexture ctx->drv.pf_glActiveTexture #define glActiveTexture ctx->drv.pf_glActiveTexture
#define glClientActiveTexture ctx->drv.pf_glClientActiveTexture #define glClientActiveTexture ctx->drv.pf_glClientActiveTexture
@ -828,7 +822,7 @@ cogl_material_set_layer (CoglHandle material_handle,
_cogl_material_pre_change_notify (material, FALSE, NULL); _cogl_material_pre_change_notify (material, FALSE, NULL);
material->n_layers = g_list_length (material->layers); material->n_layers = g_list_length (material->layers);
if (material->n_layers >= COGL_MATERIAL_MAX_TEXTURE_UNITS) if (material->n_layers >= _cogl_get_max_texture_image_units ())
{ {
if (!(material->flags & COGL_MATERIAL_FLAG_SHOWN_SAMPLER_WARNING)) if (!(material->flags & COGL_MATERIAL_FLAG_SHOWN_SAMPLER_WARNING))
{ {
@ -1551,7 +1545,7 @@ _cogl_material_flush_layers_gl_state (CoglMaterial *material,
layer->flags &= ~COGL_MATERIAL_LAYER_FLAG_DIRTY; layer->flags &= ~COGL_MATERIAL_LAYER_FLAG_DIRTY;
if ((i+1) >= COGL_MATERIAL_MAX_TEXTURE_UNITS) if ((i+1) >= _cogl_get_max_texture_image_units ())
break; break;
} }

View File

@ -120,8 +120,8 @@ typedef struct _CoglTextureVertex CoglTextureVertex;
* @COGL_PIXEL_FORMAT_RGB_565: RGB, 16 bits * @COGL_PIXEL_FORMAT_RGB_565: RGB, 16 bits
* @COGL_PIXEL_FORMAT_RGBA_4444: RGBA, 16 bits * @COGL_PIXEL_FORMAT_RGBA_4444: RGBA, 16 bits
* @COGL_PIXEL_FORMAT_RGBA_5551: RGBA, 16 bits * @COGL_PIXEL_FORMAT_RGBA_5551: RGBA, 16 bits
* @COGL_PIXEL_FORMAT_YUV: FIXME * @COGL_PIXEL_FORMAT_YUV: Not currently supported
* @COGL_PIXEL_FORMAT_G_8: FIXME * @COGL_PIXEL_FORMAT_G_8: Single luminance component
* @COGL_PIXEL_FORMAT_RGB_888: RGB, 24 bits * @COGL_PIXEL_FORMAT_RGB_888: RGB, 24 bits
* @COGL_PIXEL_FORMAT_BGR_888: BGR, 24 bits * @COGL_PIXEL_FORMAT_BGR_888: BGR, 24 bits
* @COGL_PIXEL_FORMAT_RGBA_8888: RGBA, 32 bits * @COGL_PIXEL_FORMAT_RGBA_8888: RGBA, 32 bits
@ -135,7 +135,23 @@ typedef struct _CoglTextureVertex CoglTextureVertex;
* @COGL_PIXEL_FORMAT_RGBA_4444_PRE: Premultiplied RGBA, 16 bits * @COGL_PIXEL_FORMAT_RGBA_4444_PRE: Premultiplied RGBA, 16 bits
* @COGL_PIXEL_FORMAT_RGBA_5551_PRE: Premultiplied RGBA, 16 bits * @COGL_PIXEL_FORMAT_RGBA_5551_PRE: Premultiplied RGBA, 16 bits
* *
* Pixel formats used by COGL. * Pixel formats used by COGL. For the formats with a byte per
* component, the order of the components specify the order in
* increasing memory addresses. So for example
* %COGL_PIXEL_FORMAT_RGB_888 would have the red component in the
* lowest address, green in the next address and blue after that
* regardless of the endinanness of the system.
*
* For the 16-bit formats the component order specifies the order
* within a 16-bit number from most significant bit to least
* significant. So for %COGL_PIXEL_FORMAT_RGB_565, the red component
* would be in bits 11-15, the green component would be in 6-11 and
* the blue component would be in 1-5. Therefore the order in memory
* depends on the endianness of the system.
*
* When uploading a texture %COGL_PIXEL_FORMAT_ANY can be used as the
* internal format. Cogl will try to pick the best format to use
* internally and convert the texture data if necessary.
* *
* Since: 0.8 * Since: 0.8
*/ */

View File

@ -51,9 +51,9 @@
int int
cogl_util_next_p2 (int a) cogl_util_next_p2 (int a)
{ {
int rval=1; int rval = 1;
while(rval < a) while (rval < a)
rval <<= 1; rval <<= 1;
return rval; return rval;
@ -237,8 +237,8 @@ cogl_fixed_get_type (void)
g_value_register_transform_func (_cogl_fixed_type, G_TYPE_FLOAT, g_value_register_transform_func (_cogl_fixed_type, G_TYPE_FLOAT,
cogl_value_transform_fixed_float); cogl_value_transform_fixed_float);
g_value_register_transform_func (G_TYPE_FLOAT, _cogl_fixed_type, g_value_register_transform_func (G_TYPE_FLOAT, _cogl_fixed_type,
cogl_value_transform_float_fixed); cogl_value_transform_float_fixed);
g_value_register_transform_func (_cogl_fixed_type, G_TYPE_DOUBLE, g_value_register_transform_func (_cogl_fixed_type, G_TYPE_DOUBLE,
cogl_value_transform_fixed_double); cogl_value_transform_fixed_double);
g_value_register_transform_func (G_TYPE_DOUBLE, _cogl_fixed_type, g_value_register_transform_func (G_TYPE_DOUBLE, _cogl_fixed_type,

View File

@ -1512,7 +1512,7 @@ enable_state_for_drawing_buffer (CoglVertexBuffer *buffer)
GLuint generic_index = 0; GLuint generic_index = 0;
#endif #endif
gulong enable_flags = 0; gulong enable_flags = 0;
guint max_texcoord_attrib_unit = 0; guint max_texcoord_attrib_unit = -1;
const GList *layers; const GList *layers;
guint32 fallback_layers = 0; guint32 fallback_layers = 0;
guint32 disable_layers = ~0; guint32 disable_layers = ~0;

View File

@ -40,6 +40,7 @@
#include "cogl-winsys.h" #include "cogl-winsys.h"
#include "cogl-framebuffer-private.h" #include "cogl-framebuffer-private.h"
#include "cogl-matrix-private.h" #include "cogl-matrix-private.h"
#include "cogl-journal-private.h"
#if defined (HAVE_COGL_GLES2) || defined (HAVE_COGL_GLES) #if defined (HAVE_COGL_GLES2) || defined (HAVE_COGL_GLES)
#include "cogl-gles2-wrapper.h" #include "cogl-gles2-wrapper.h"
@ -155,6 +156,16 @@ cogl_clear (const CoglColor *color, gulong buffers)
glClear (gl_buffers); glClear (gl_buffers);
/* This is a debugging variable used to visually display the quad
batches from the journal. It is reset here to increase the
chances of getting the same colours for each frame during an
animation */
if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_RECTANGLES))
{
_COGL_GET_CONTEXT (ctxt, NO_RETVAL);
ctxt->journal_rectangles_color = 1;
}
COGL_NOTE (DRAW, "Clear end"); COGL_NOTE (DRAW, "Clear end");
} }
@ -729,10 +740,11 @@ cogl_end_gl (void)
} }
static CoglTextureUnit * static CoglTextureUnit *
_cogl_texture_unit_new (void) _cogl_texture_unit_new (int index_)
{ {
CoglTextureUnit *unit = g_new0 (CoglTextureUnit, 1); CoglTextureUnit *unit = g_new0 (CoglTextureUnit, 1);
unit->matrix_stack = _cogl_matrix_stack_new (); unit->matrix_stack = _cogl_matrix_stack_new ();
unit->index = index_;
return unit; return unit;
} }
@ -766,7 +778,7 @@ _cogl_get_texture_unit (int index_)
/* NB: if we now insert a new layer before l, that will maintain order. /* NB: if we now insert a new layer before l, that will maintain order.
*/ */
unit = _cogl_texture_unit_new (); unit = _cogl_texture_unit_new (index_);
/* Note: see comment after for() loop above */ /* Note: see comment after for() loop above */
ctx->texture_units = ctx->texture_units =
@ -787,6 +799,36 @@ _cogl_destroy_texture_units (void)
g_list_free (ctx->texture_units); g_list_free (ctx->texture_units);
} }
/*
* This is more complicated than that, another pass needs to be done when
* cogl have a neat way of saying if we are using the fixed function pipeline
* or not (for the GL case):
* MAX_TEXTURE_UNITS: fixed function pipeline, a texture unit has both a
* sampler and a set of texture coordinates
* MAX_TEXTURE_IMAGE_UNITS: number of samplers one can use from a fragment
* program/shader (ARBfp1.0 asm/GLSL)
* MAX_VERTEX_TEXTURE_UNITS: number of samplers one can use from a vertex
* program/shader (can be 0)
* MAX_COMBINED_TEXTURE_IMAGE_UNITS: Maximum samplers one can use, counting both
* the vertex and fragment shaders
*
* If both the vertex shader and the fragment processing stage access the same
* texture image unit, then that counts as using two texture image units
* against the latter limit: http://www.opengl.org/sdk/docs/man/xhtml/glGet.xml
*
* Note that, for now, we use GL_MAX_TEXTURE_UNITS as we are exposing the
* fixed function pipeline.
*/
guint
_cogl_get_max_texture_image_units (void)
{
GLint nb_texture_image_units;
GE( glGetIntegerv(GL_MAX_TEXTURE_UNITS, &nb_texture_image_units) );
return nb_texture_image_units;
}
void void
cogl_push_matrix (void) cogl_push_matrix (void)
{ {

View File

@ -59,14 +59,13 @@ to this OpenGL code:
<programlisting> <programlisting>
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE); glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS); glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE); glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS); glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS);
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_COLOR);
glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE); glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_TEXTURE);
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_COLOR);
</programlisting> </programlisting>
</section> </section>