From 3069ad640926e8f70e3a406acce518282b58b345 Mon Sep 17 00:00:00 2001 From: Damien Lespiau Date: Sun, 15 Nov 2009 19:54:17 +0000 Subject: [PATCH 1/7] cogl: Create CoglTextureUnit with its associated unit number The index field of CoglTextureUnit was never set, leading to the creation of units with index set to 0. When trying to retrieve a texture unit by its index (!= 0) with _cogl_get_texture_unit(), a new one was created as it could not find it back in the list of textures units: ctx->texture_units. http://bugzilla.openedhand.com/show_bug.cgi?id=1958 --- cogl/cogl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cogl/cogl.c b/cogl/cogl.c index aa61fd590..ca76641f5 100644 --- a/cogl/cogl.c +++ b/cogl/cogl.c @@ -729,10 +729,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 +767,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 = From 84a438be55b13c6411f0f854987356235d7db91e Mon Sep 17 00:00:00 2001 From: Damien Lespiau Date: Sun, 15 Nov 2009 20:17:47 +0000 Subject: [PATCH 2/7] cogl: Fix gl equivalent of blend string An example of what could be the equivalent of "RBG = REPLACE(TEXTURE) A = MODULATE(PREVIOUS,TEXTURE)" using the ARB_texture_env_combine extension was given, but it seems that a few typo were left: * remove a spurius GL_COMBINE_ALPHA * use the _ALPHA variant of SRCN and OPERANDN when setting up the alpha combiner --- doc/reference/cogl/blend-strings.xml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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); From 9d45e9641c57a890474fa76178d3eba316aa445a Mon Sep 17 00:00:00 2001 From: Damien Lespiau Date: Tue, 26 Jan 2010 18:47:25 +0000 Subject: [PATCH 3/7] cogl: Fix checks of the number of available texture units We were checking the number of texture units against the GL enum that is used in glGetInteger() to query that number. Let's abstract this in a little function. Took the opportunity to dig a bit on the usage of GL limits for the number of texture (image) units and document our use of them. We'll need something finer grained if we want to fully exploit texture image units with a programmable pipeline. --- cogl/cogl-internal.h | 2 ++ cogl/cogl-material.c | 10 ++-------- cogl/cogl.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) 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-material.c b/cogl/cogl-material.c index 00c376fb5..65b7258d0 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)) { @@ -1537,7 +1531,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.c b/cogl/cogl.c index ca76641f5..387eac417 100644 --- a/cogl/cogl.c +++ b/cogl/cogl.c @@ -788,6 +788,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) { From 548ed1cdf241ac0d324e2b289964f371f859b408 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Wed, 27 Jan 2010 12:06:22 +0000 Subject: [PATCH 4/7] docs: Add some notes about the CoglPixelFormat enums The pixel format enums didn't explain what order in memory the components should be so it was difficult to use them. --- cogl/cogl-types.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/cogl/cogl-types.h b/cogl/cogl-types.h index 30c73d4f7..826b26055 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 */ From 1718b1d42ef167779e7cefa18e01023b64e57cf9 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Tue, 26 Jan 2010 13:46:27 +0000 Subject: [PATCH 5/7] cogl-vertex-buffer: Fix disabling the texture arrays from previous prim MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When setting up the state for the vertex buffer, enable_state_for_drawing_buffer tries to keep track of the highest numbered texture unit in use. It then disables any texture arrays for units that were previously enabled if they are greater than that number. However if there is no texturing in the VBO then the max used unit would be left at 0 which it would later think meant unit 0 is still in use so it wouldn't disable it. To fix this it now initialises the max used unit to -1 which it should interpret as ‘no units are in use’ so it will later disable the arrays for all units. Thanks to Jon Mayo for reporting the bug. http://bugzilla.openedhand.com/show_bug.cgi?id=1957 --- cogl/cogl-vertex-buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogl/cogl-vertex-buffer.c b/cogl/cogl-vertex-buffer.c index 26d09ce01..5ced90abe 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; From 47df6724b2893936033777fd2eec1cd0b8c7499c Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Fri, 22 Jan 2010 18:14:57 +0000 Subject: [PATCH 6/7] cogl: Use the colours of COGL_DEBUG=rectangles to debug batching Instead of assigning a new colour to each quad of a batch, the rectangle debugging code now assigns a new colour to each batch so that it can be used to visually see what is being batched. The colour is stored in a global variable that is reset during cogl_clear. This improves the chances that the same colour will be used for a batch in the next frames to avoid flickering. --- cogl/cogl-context.h | 6 +++++ cogl/cogl-journal.c | 54 +++++++++++++++++++++++++++++++-------------- cogl/cogl.c | 11 +++++++++ 3 files changed, 54 insertions(+), 17 deletions(-) diff --git a/cogl/cogl-context.h b/cogl/cogl-context.h index 717f3534e..53c233c4b 100644 --- a/cogl/cogl-context.h +++ b/cogl/cogl-context.h @@ -111,6 +111,12 @@ typedef struct CoglHandle texture_download_material; + /* 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-journal.c b/cogl/cogl-journal.c index 601d53d9a..96fe3e5c7 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.c b/cogl/cogl.c index 387eac417..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"); } From 4fcbbfeedcb1641d283743acb712b567a757efce Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 27 Jan 2010 21:26:26 +0000 Subject: [PATCH 7/7] Whitespace fixes in cogl-util --- cogl/cogl-util.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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,