<commit_before>/*
 * Cogl
 *
 * An object oriented GL/GLES Abstraction/Utility Layer
 *
 * Copyright (C) 2007,2008,2009,2010 Intel Corporation.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 *
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "cogl.h"
#include "cogl-object.h"
#include "cogl-internal.h"
#include "cogl-context.h"
#include "cogl-journal-private.h"
#include "cogl-material-private.h"
#include "cogl-framebuffer-private.h"
#include "cogl-path-private.h"

#include <string.h>
#include <math.h>

#define _COGL_MAX_BEZ_RECURSE_DEPTH 16

#ifdef HAVE_COGL_GL
#define glClientActiveTexture ctx->drv.pf_glClientActiveTexture
#endif

static void _cogl_path_free (CoglPath *path);

COGL_OBJECT_DEFINE (Path, path);

static void
_cogl_path_data_unref (CoglPathData *data)
{
  if (--data->ref_count <= 0)
    {
      g_array_free (data->path_nodes, TRUE);

      g_slice_free (CoglPathData, data);
    }
}

static void
_cogl_path_modify (CoglPath *path)
{
  /* This needs to be called whenever the path is about to be modified
     to implement copy-on-write semantics */

  /* If there is more than one path using the data then we need to
     copy the data instead */
  if (path->data->ref_count != 1)
    {
      CoglPathData *old_data = path->data;

      path->data = g_slice_dup (CoglPathData, old_data);
      path->data->path_nodes = g_array_new (FALSE, FALSE,
                                            sizeof (CoglPathNode));
      g_array_append_vals (path->data->path_nodes,
                           old_data->path_nodes->data,
                           old_data->path_nodes->len);

      path->data->ref_count = 1;

      _cogl_path_data_unref (old_data);
    }
}

static void
_cogl_path_add_node (gboolean new_sub_path,
		     float x,
		     float y)
{
  CoglPathNode new_node;
  CoglPath *path;
  CoglPathData *data;

  _COGL_GET_CONTEXT (ctx, NO_RETVAL);

  path = COGL_PATH (ctx->current_path);

  _cogl_path_modify (path);

  data = path->data;

  new_node.x = x;
  new_node.y = y;
  new_node.path_size = 0;

  if (new_sub_path || data->path_nodes->len == 0)
    data->last_path = data->path_nodes->len;

  g_array_append_val (data->path_nodes, new_node);

  g_array_index (data->path_nodes, CoglPathNode, data->last_path).path_size++;

  if (data->path_nodes->len == 1)
    {
      data->path_nodes_min.x = data->path_nodes_max.x = x;
      data->path_nodes_min.y = data->path_nodes_max.y = y;
    }
  else
    {
      if (x < data->path_nodes_min.x) data->path_nodes_min.x = x;
      if (x > data->path_nodes_max.x) data->path_nodes_max.x = x;
      if (y < data->path_nodes_min.y) data->path_nodes_min.y = y;
      if (y > data->path_nodes_max.y) data->path_nodes_max.y = y;
    }
}

static void
_cogl_path_stroke_nodes (void)
{
  unsigned int   path_start = 0;
  unsigned long  enable_flags = COGL_ENABLE_VERTEX_ARRAY;
  CoglPathData  *data;
  CoglHandle     source;

  _COGL_GET_CONTEXT (ctx, NO_RETVAL);

  data = COGL_PATH (ctx->current_path)->data;

  _cogl_journal_flush ();

  /* NB: _cogl_framebuffer_flush_state may disrupt various state (such
   * as the material state) when flushing the clip stack, so should
   * always be done first when preparing to draw. */
  _cogl_framebuffer_flush_state (_cogl_get_framebuffer (), 0);

  _cogl_enable (enable_flags);

  if (G_UNLIKELY (ctx->legacy_state_set))
    {
      source = cogl_material_copy (ctx->source_material);
      _cogl_material_apply_legacy_state (source);
    }
  else
    source = ctx->source_material;

  if (cogl_material_get_n_layers (source) != 0)
    {
      CoglMaterialFlushOptions options;
      options.flags = COGL_MATERIAL_FLUSH_DISABLE_MASK;
      /* disable all texture layers */
      options.disable_layers = (guint32)~0;

      /* If we haven't already created a derived material... */
      if (source == ctx->source_material)
        source = cogl_material_copy (ctx->source_material);
      _cogl_material_apply_overrides (source, &options);
    }

  _cogl_material_flush_gl_state (source, FALSE);

  while (path_start < data->path_nodes->len)
    {
      CoglPathNode *node = &g_array_index (data->path_nodes, CoglPathNode,
                                           path_start);

      GE( glVertexPointer (2, GL_FLOAT, sizeof (CoglPathNode), &node->x) );
      GE( glDrawArrays (GL_LINE_STRIP, 0, node->path_size) );

      path_start += node->path_size;
    }

  if (G_UNLIKELY (source != ctx->source_material))
    cogl_handle_unref (source);
}
<commit_msg>cogl-path: Disable texture coord arrays before drawing<commit_after>/*
 * Cogl
 *
 * An object oriented GL/GLES Abstraction/Utility Layer
 *
 * Copyright (C) 2007,2008,2009,2010 Intel Corporation.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 *
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "cogl.h"
#include "cogl-object.h"
#include "cogl-internal.h"
#include "cogl-context.h"
#include "cogl-journal-private.h"
#include "cogl-material-private.h"
#include "cogl-framebuffer-private.h"
#include "cogl-path-private.h"

#include <string.h>
#include <math.h>

#define _COGL_MAX_BEZ_RECURSE_DEPTH 16

#ifdef HAVE_COGL_GL
#define glClientActiveTexture ctx->drv.pf_glClientActiveTexture
#endif

static void _cogl_path_free (CoglPath *path);

COGL_OBJECT_DEFINE (Path, path);

static void
_cogl_path_data_unref (CoglPathData *data)
{
  if (--data->ref_count <= 0)
    {
      g_array_free (data->path_nodes, TRUE);

      g_slice_free (CoglPathData, data);
    }
}

static void
_cogl_path_modify (CoglPath *path)
{
  /* This needs to be called whenever the path is about to be modified
     to implement copy-on-write semantics */

  /* If there is more than one path using the data then we need to
     copy the data instead */
  if (path->data->ref_count != 1)
    {
      CoglPathData *old_data = path->data;

      path->data = g_slice_dup (CoglPathData, old_data);
      path->data->path_nodes = g_array_new (FALSE, FALSE,
                                            sizeof (CoglPathNode));
      g_array_append_vals (path->data->path_nodes,
                           old_data->path_nodes->data,
                           old_data->path_nodes->len);

      path->data->ref_count = 1;

      _cogl_path_data_unref (old_data);
    }
}

static void
_cogl_path_add_node (gboolean new_sub_path,
		     float x,
		     float y)
{
  CoglPathNode new_node;
  CoglPath *path;
  CoglPathData *data;

  _COGL_GET_CONTEXT (ctx, NO_RETVAL);

  path = COGL_PATH (ctx->current_path);

  _cogl_path_modify (path);

  data = path->data;

  new_node.x = x;
  new_node.y = y;
  new_node.path_size = 0;

  if (new_sub_path || data->path_nodes->len == 0)
    data->last_path = data->path_nodes->len;

  g_array_append_val (data->path_nodes, new_node);

  g_array_index (data->path_nodes, CoglPathNode, data->last_path).path_size++;

  if (data->path_nodes->len == 1)
    {
      data->path_nodes_min.x = data->path_nodes_max.x = x;
      data->path_nodes_min.y = data->path_nodes_max.y = y;
    }
  else
    {
      if (x < data->path_nodes_min.x) data->path_nodes_min.x = x;
      if (x > data->path_nodes_max.x) data->path_nodes_max.x = x;
      if (y < data->path_nodes_min.y) data->path_nodes_min.y = y;
      if (y > data->path_nodes_max.y) data->path_nodes_max.y = y;
    }
}

static void
_cogl_path_stroke_nodes (void)
{
  unsigned int   path_start = 0;
  unsigned long  enable_flags = COGL_ENABLE_VERTEX_ARRAY;
  CoglPathData  *data;
  CoglHandle     source;

  _COGL_GET_CONTEXT (ctx, NO_RETVAL);

  data = COGL_PATH (ctx->current_path)->data;

  _cogl_journal_flush ();

  /* NB: _cogl_framebuffer_flush_state may disrupt various state (such
   * as the material state) when flushing the clip stack, so should
   * always be done first when preparing to draw. */
  _cogl_framebuffer_flush_state (_cogl_get_framebuffer (), 0);

  _cogl_enable (enable_flags);

  if (G_UNLIKELY (ctx->legacy_state_set))
    {
      source = cogl_material_copy (ctx->source_material);
      _cogl_material_apply_legacy_state (source);
    }
  else
    source = ctx->source_material;

  if (cogl_material_get_n_layers (source) != 0)
    {
      CoglMaterialFlushOptions options;
      options.flags = COGL_MATERIAL_FLUSH_DISABLE_MASK;
      /* disable all texture layers */
      options.disable_layers = (guint32)~0;

      /* If we haven't already created a derived material... */
      if (source == ctx->source_material)
        source = cogl_material_copy (ctx->source_material);
      _cogl_material_apply_overrides (source, &options);
    }

  _cogl_material_flush_gl_state (source, FALSE);

  /* Disable all client texture coordinate arrays */
  _cogl_bitmask_clear_all (&ctx->temp_bitmask);
  _cogl_disable_other_texcoord_arrays (&ctx->temp_bitmask);

  while (path_start < data->path_nodes->len)
    {
      CoglPathNode *node = &g_array_index (data->path_nodes, CoglPathNode,
                                           path_start);

      GE( glVertexPointer (2, GL_FLOAT, sizeof (CoglPathNode), &node->x) );
      GE( glDrawArrays (GL_LINE_STRIP, 0, node->path_size) );

      path_start += node->path_size;
    }

  if (G_UNLIKELY (source != ctx->source_material))
    cogl_handle_unref (source);
}

{'fraction_non_alphanumeric': 0.10744039069232979, 'fraction_numerical': 0.006320022981901752, 'mean_word_length': 3.2438033319788704, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 125, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3283040', 'n_tokens_mistral': 3770, 'n_tokens_neox': 3538, 'n_words': 890}