diff --git a/cogl/cogl-context.h b/cogl/cogl-context.h index ce84b01cb..dcbba2c70 100644 --- a/cogl/cogl-context.h +++ b/cogl/cogl-context.h @@ -115,6 +115,12 @@ typedef struct CoglAtlas *atlas; 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; } CoglContext; diff --git a/cogl/cogl-internal.h b/cogl/cogl-internal.h index 585220a1d..f38107ead 100644 --- a/cogl/cogl-internal.h +++ b/cogl/cogl-internal.h @@ -101,6 +101,8 @@ CoglTextureUnit * _cogl_get_texture_unit (int index_); void _cogl_destroy_texture_units (void); +guint +_cogl_get_max_texture_image_units (void); void _cogl_flush_face_winding (void); diff --git a/cogl/cogl-journal.c b/cogl/cogl-journal.c index 2a0e106a5..a27eb8d75 100644 --- a/cogl/cogl-journal.c +++ b/cogl/cogl-journal.c @@ -225,30 +225,51 @@ _cogl_journal_flush_modelview_and_entries (CoglJournalEntry *batch_start, } #endif - /* DEBUGGING CODE XXX: - * This path 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. + /* DEBUGGING CODE XXX: This path will cause all rectangles to be + * drawn with a coloured outline. Each batch will be rendered with + * the same color. This may e.g. help with debugging texture slicing + * issues, visually seeing what is batched and debugging blending + * issues, plus it looks quite cool. */ if (cogl_debug_flags & COGL_DEBUG_RECTANGLES) { static CoglHandle outline = COGL_INVALID_HANDLE; - static int color = 0; + guint8 color_intensity; int i; + + _COGL_GET_CONTEXT (ctxt, NO_RETVAL); + if (outline == COGL_INVALID_HANDLE) 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); - for (i = 0; i < batch_len; i++, color = (color + 1) % 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) ); - } + for (i = 0; i < batch_len; i++) + GE( glDrawArrays (GL_LINE_LOOP, 4 * i + state->vertex_offset, 4) ); + + /* Go to the next color */ + do + ctxt->journal_rectangles_color = ((ctxt->journal_rectangles_color + 1) & + ((1 << 5) - 1)); + /* We don't want to use black or white */ + while ((ctxt->journal_rectangles_color & 0x07) == 0 + || (ctxt->journal_rectangles_color & 0x07) == 0x07); } 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)) cogl_get_modelview_matrix (&entry->model_view); - if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DISABLE_BATCHING - || cogl_debug_flags & COGL_DEBUG_RECTANGLES)) + if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DISABLE_BATCHING)) _cogl_journal_flush (); COGL_TIMER_STOP (_cogl_uprof_context, log_timer); diff --git a/cogl/cogl-material.c b/cogl/cogl-material.c index 589a753db..8f12fc81b 100644 --- a/cogl/cogl-material.c +++ b/cogl/cogl-material.c @@ -48,12 +48,6 @@ #include "../gles/cogl-gles2-wrapper.h" #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 #define glActiveTexture ctx->drv.pf_glActiveTexture #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); 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)) { @@ -1551,7 +1545,7 @@ _cogl_material_flush_layers_gl_state (CoglMaterial *material, 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; } diff --git a/cogl/cogl-types.h b/cogl/cogl-types.h index 3d5e3eb02..4ce1502f3 100644 --- a/cogl/cogl-types.h +++ b/cogl/cogl-types.h @@ -120,8 +120,8 @@ typedef struct _CoglTextureVertex CoglTextureVertex; * @COGL_PIXEL_FORMAT_RGB_565: RGB, 16 bits * @COGL_PIXEL_FORMAT_RGBA_4444: RGBA, 16 bits * @COGL_PIXEL_FORMAT_RGBA_5551: RGBA, 16 bits - * @COGL_PIXEL_FORMAT_YUV: FIXME - * @COGL_PIXEL_FORMAT_G_8: FIXME + * @COGL_PIXEL_FORMAT_YUV: Not currently supported + * @COGL_PIXEL_FORMAT_G_8: Single luminance component * @COGL_PIXEL_FORMAT_RGB_888: RGB, 24 bits * @COGL_PIXEL_FORMAT_BGR_888: BGR, 24 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_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 */ diff --git a/cogl/cogl-util.c b/cogl/cogl-util.c index 6debb5599..96fa4c9d8 100644 --- a/cogl/cogl-util.c +++ b/cogl/cogl-util.c @@ -51,9 +51,9 @@ int cogl_util_next_p2 (int a) { - int rval=1; + int rval = 1; - while(rval < a) + while (rval < a) rval <<= 1; return rval; @@ -237,8 +237,8 @@ cogl_fixed_get_type (void) g_value_register_transform_func (_cogl_fixed_type, G_TYPE_FLOAT, cogl_value_transform_fixed_float); g_value_register_transform_func (G_TYPE_FLOAT, _cogl_fixed_type, - cogl_value_transform_float_fixed); + g_value_register_transform_func (_cogl_fixed_type, G_TYPE_DOUBLE, cogl_value_transform_fixed_double); g_value_register_transform_func (G_TYPE_DOUBLE, _cogl_fixed_type, diff --git a/cogl/cogl-vertex-buffer.c b/cogl/cogl-vertex-buffer.c index 943b77776..67fd43810 100644 --- a/cogl/cogl-vertex-buffer.c +++ b/cogl/cogl-vertex-buffer.c @@ -1512,7 +1512,7 @@ enable_state_for_drawing_buffer (CoglVertexBuffer *buffer) GLuint generic_index = 0; #endif gulong enable_flags = 0; - guint max_texcoord_attrib_unit = 0; + guint max_texcoord_attrib_unit = -1; const GList *layers; guint32 fallback_layers = 0; guint32 disable_layers = ~0; diff --git a/cogl/cogl.c b/cogl/cogl.c index aa61fd590..e66f997ed 100644 --- a/cogl/cogl.c +++ b/cogl/cogl.c @@ -40,6 +40,7 @@ #include "cogl-winsys.h" #include "cogl-framebuffer-private.h" #include "cogl-matrix-private.h" +#include "cogl-journal-private.h" #if defined (HAVE_COGL_GLES2) || defined (HAVE_COGL_GLES) #include "cogl-gles2-wrapper.h" @@ -155,6 +156,16 @@ cogl_clear (const CoglColor *color, gulong 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"); } @@ -729,10 +740,11 @@ cogl_end_gl (void) } static CoglTextureUnit * -_cogl_texture_unit_new (void) +_cogl_texture_unit_new (int index_) { CoglTextureUnit *unit = g_new0 (CoglTextureUnit, 1); unit->matrix_stack = _cogl_matrix_stack_new (); + unit->index = index_; 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. */ - unit = _cogl_texture_unit_new (); + unit = _cogl_texture_unit_new (index_); /* Note: see comment after for() loop above */ ctx->texture_units = @@ -787,6 +799,36 @@ _cogl_destroy_texture_units (void) 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 cogl_push_matrix (void) { diff --git a/doc/reference/cogl/blend-strings.xml b/doc/reference/cogl/blend-strings.xml index 9c3c8d3c9..0b37757c7 100644 --- a/doc/reference/cogl/blend-strings.xml +++ b/doc/reference/cogl/blend-strings.xml @@ -59,14 +59,13 @@ to this OpenGL code: 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_ALPHA, GL_REPLACE); glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS); glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE); - glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS); - glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); - glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE); - glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); + glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS); + glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_COLOR); + glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_TEXTURE); + glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_COLOR);