cogl-vertex-buffer: Default to GL_CLAMP_TO_EDGE for point sprites
authorNeil Roberts <neil@linux.intel.com>
Wed, 7 Apr 2010 10:06:20 +0000 (11:06 +0100)
committerRobert Bragg <robert@linux.intel.com>
Thu, 8 Jul 2010 15:34:31 +0000 (16:34 +0100)
For point sprites you are usually drawing the whole texture so you
most often want GL_CLAMP_TO_EDGE. This patch removes the override for
COGL_MATERIAL_WRAP_MODE_AUTOMATIC when point sprites are enabled for a
layer so that it will clamp to edge.

clutter/cogl/cogl/cogl-material.h
clutter/cogl/cogl/cogl-vertex-buffer.c

index 7c9de1a..c9c9763 100644 (file)
@@ -96,8 +96,10 @@ typedef enum {
  *   decide which of the above two to use. For cogl_rectangle(), it
  *   will use repeat mode if any of the texture coordinates are
  *   outside the range 0→1, otherwise it will use clamp to edge. For
- *   cogl_polygon() and cogl_vertex_buffer_draw() it will always use
- *   repeat mode. This is the default value.
+ *   cogl_polygon() it will always use repeat mode. For
+ *   cogl_vertex_buffer_draw() it will use repeat mode except for
+ *   layers that have point sprite coordinate generation enabled. This
+ *   is the default value.
  *
  * The wrap mode specifies what happens when texture coordinates
  * outside the range 0→1 are used. Note that if the filter mode is
index 57a353e..9664adc 100644 (file)
@@ -1659,6 +1659,37 @@ enable_state_for_drawing_buffer (CoglVertexBuffer *buffer)
       if (tex_handle == COGL_INVALID_HANDLE)
         continue;
 
+      if (!cogl_material_get_layer_point_sprite_coords_enabled (source, i))
+        {
+          /* By default COGL_MATERIAL_WRAP_MODE_AUTOMATIC becomes
+             GL_CLAMP_TO_EDGE but we want GL_REPEAT to maintain
+             compatibility with older versions of Cogl so we'll
+             override it. We don't want to do this for point sprites
+             because in that case the whole texture is drawn so you
+             would usually want clamp-to-edge. */
+          if (cogl_material_layer_get_wrap_mode_s (layer) ==
+              COGL_MATERIAL_WRAP_MODE_AUTOMATIC)
+            {
+              options.wrap_mode_overrides.values[i].s =
+                COGL_MATERIAL_WRAP_MODE_OVERRIDE_REPEAT;
+              options.flags |= COGL_MATERIAL_FLUSH_WRAP_MODE_OVERRIDES;
+            }
+          if (cogl_material_layer_get_wrap_mode_t (layer) ==
+              COGL_MATERIAL_WRAP_MODE_AUTOMATIC)
+            {
+              options.wrap_mode_overrides.values[i].t =
+                COGL_MATERIAL_WRAP_MODE_OVERRIDE_REPEAT;
+              options.flags |= COGL_MATERIAL_FLUSH_WRAP_MODE_OVERRIDES;
+            }
+          if (_cogl_material_layer_get_wrap_mode_r (layer) ==
+              COGL_MATERIAL_WRAP_MODE_AUTOMATIC)
+            {
+              options.wrap_mode_overrides.values[i].r =
+                COGL_MATERIAL_WRAP_MODE_OVERRIDE_REPEAT;
+              options.flags |= COGL_MATERIAL_FLUSH_WRAP_MODE_OVERRIDES;
+            }
+        }
+
       /* Give the texture a chance to know that we're rendering
          non-quad shaped primitives. If the texture is in an atlas it
          will be migrated */
@@ -1691,32 +1722,6 @@ enable_state_for_drawing_buffer (CoglVertexBuffer *buffer)
            */
           fallback_layers |= (1 << i);
         }
-
-      /* By default COGL_MATERIAL_WRAP_MODE_AUTOMATIC becomes
-         GL_CLAMP_TO_EDGE but we want GL_REPEAT to maintain
-         compatibility with older versions of Cogl so we'll override
-         it */
-      if (cogl_material_layer_get_wrap_mode_s (layer) ==
-          COGL_MATERIAL_WRAP_MODE_AUTOMATIC)
-        {
-          options.wrap_mode_overrides.values[i].s =
-            COGL_MATERIAL_WRAP_MODE_OVERRIDE_REPEAT;
-          options.flags |= COGL_MATERIAL_FLUSH_WRAP_MODE_OVERRIDES;
-        }
-      if (cogl_material_layer_get_wrap_mode_t (layer) ==
-          COGL_MATERIAL_WRAP_MODE_AUTOMATIC)
-        {
-          options.wrap_mode_overrides.values[i].t =
-            COGL_MATERIAL_WRAP_MODE_OVERRIDE_REPEAT;
-          options.flags |= COGL_MATERIAL_FLUSH_WRAP_MODE_OVERRIDES;
-        }
-      if (_cogl_material_layer_get_wrap_mode_r (layer) ==
-          COGL_MATERIAL_WRAP_MODE_AUTOMATIC)
-        {
-          options.wrap_mode_overrides.values[i].r =
-            COGL_MATERIAL_WRAP_MODE_OVERRIDE_REPEAT;
-          options.flags |= COGL_MATERIAL_FLUSH_WRAP_MODE_OVERRIDES;
-        }
     }
 
   /* Disable any tex coord arrays that we didn't use */