<commit_before>import Color from "../Core/Color.js";
import DrawCommand from "../Renderer/DrawCommand.js";
import ShaderSource from "../Renderer/ShaderSource.js";
import ShaderProgram from "../Renderer/ShaderProgram.js";
import defined from "../Core/defined.js";

/**
 * @private
 */
function DebugInspector() {
  this._cachedShowFrustumsShaders = {};
}

function getAttributeLocations(shaderProgram) {
  var attributeLocations = {};
  var attributes = shaderProgram.vertexAttributes;
  for (var a in attributes) {
    if (attributes.hasOwnProperty(a)) {
      attributeLocations[a] = attributes[a].index;
    }
  }

  return attributeLocations;
}

function createDebugShowFrustumsShaderProgram(scene, shaderProgram) {
  var context = scene.context;
  var sp = shaderProgram;
  var fs = sp.fragmentShaderSource.clone();

  var targets = [];
  fs.sources = fs.sources.map(function (source) {
    source = ShaderSource.replaceMain(source, "czm_Debug_main");
    var re = /gl_FragData\[(\d+)\]/g;
    var match;
    while ((match = re.exec(source)) !== null) {
      if (targets.indexOf(match[1]) === -1) {
        targets.push(match[1]);
      }
    }
    return source;
  });
  var length = targets.length;

  var newMain = "";
  newMain += "uniform vec3 debugShowCommandsColor;\n";
  newMain += "uniform vec3 debugShowFrustumsColor;\n";
  newMain += "void main() \n" + "{ \n" + "    czm_Debug_main(); \n";

  // set debugShowCommandsColor to Color(1.0, 1.0, 1.0, 1.0) to stop rendering scene.debugShowCommands
  // set debugShowFrustumsColor to Color(1.0, 1.0, 1.0, 1.0) to stop rendering scene.debugShowFrustums
  var i;
  if (length > 0) {
    for (i = 0; i < length; ++i) {
      newMain +=
        "    gl_FragData[" + targets[i] + "].rgb *= debugShowCommandsColor;\n";
      newMain +=
        "    gl_FragData[" + targets[i] + "].rgb *= debugShowFrustumsColor;\n";
    }
  } else {
    newMain += "    gl_FragColor.rgb *= debugShowCommandsColor;\n";
    newMain += "    gl_FragColor.rgb *= debugShowFrustumsColor;\n";
  }
  newMain += "}";

  fs.sources.push(newMain);

  var attributeLocations = getAttributeLocations(sp);

  return ShaderProgram.fromCache({
    context: context,
    vertexShaderSource: sp.vertexShaderSource,
    fragmentShaderSource: fs,
    attributeLocations: attributeLocations,
  });
}

var scratchFrustumColor = new Color();
function createDebugShowFrustumsUniformMap(scene, command) {
  // setup uniform for the shader
  var debugUniformMap;
  if (!defined(command.uniformMap)) {
    debugUniformMap = {};
  } else {
    debugUniformMap = command.uniformMap;
  }

  if (
    defined(debugUniformMap.debugShowFrustumsColor) ||
    defined(debugUniformMap.debugShowFrustumsColor)
  ) {
    return debugUniformMap;
  }

  debugUniformMap.debugShowCommandsColor = function () {
    if (!scene.debugShowCommands) {
      return Color.WHITE;
    }

    if (!defined(command._debugColor)) {
      command._debugColor = Color.fromRandom();
    }

    return command._debugColor;
  };

  debugUniformMap.debugShowFrustumsColor = function () {
    if (!scene.debugShowFrustums) {
      return Color.WHITE;
    }

    // Support up to three frustums.  If a command overlaps all
    // three, it's code is not changed.
    scratchFrustumColor.red =<commit_msg>fix typo in the debug uniformMap condition in DebugInspector<commit_after>import Color from "../Core/Color.js";
import DrawCommand from "../Renderer/DrawCommand.js";
import ShaderSource from "../Renderer/ShaderSource.js";
import ShaderProgram from "../Renderer/ShaderProgram.js";
import defined from "../Core/defined.js";

/**
 * @private
 */
function DebugInspector() {
  this._cachedShowFrustumsShaders = {};
}

function getAttributeLocations(shaderProgram) {
  var attributeLocations = {};
  var attributes = shaderProgram.vertexAttributes;
  for (var a in attributes) {
    if (attributes.hasOwnProperty(a)) {
      attributeLocations[a] = attributes[a].index;
    }
  }

  return attributeLocations;
}

function createDebugShowFrustumsShaderProgram(scene, shaderProgram) {
  var context = scene.context;
  var sp = shaderProgram;
  var fs = sp.fragmentShaderSource.clone();

  var targets = [];
  fs.sources = fs.sources.map(function (source) {
    source = ShaderSource.replaceMain(source, "czm_Debug_main");
    var re = /gl_FragData\[(\d+)\]/g;
    var match;
    while ((match = re.exec(source)) !== null) {
      if (targets.indexOf(match[1]) === -1) {
        targets.push(match[1]);
      }
    }
    return source;
  });
  var length = targets.length;

  var newMain = "";
  newMain += "uniform vec3 debugShowCommandsColor;\n";
  newMain += "uniform vec3 debugShowFrustumsColor;\n";
  newMain += "void main() \n" + "{ \n" + "    czm_Debug_main(); \n";

  // set debugShowCommandsColor to Color(1.0, 1.0, 1.0, 1.0) to stop rendering scene.debugShowCommands
  // set debugShowFrustumsColor to Color(1.0, 1.0, 1.0, 1.0) to stop rendering scene.debugShowFrustums
  var i;
  if (length > 0) {
    for (i = 0; i < length; ++i) {
      newMain +=
        "    gl_FragData[" + targets[i] + "].rgb *= debugShowCommandsColor;\n";
      newMain +=
        "    gl_FragData[" + targets[i] + "].rgb *= debugShowFrustumsColor;\n";
    }
  } else {
    newMain += "    gl_FragColor.rgb *= debugShowCommandsColor;\n";
    newMain += "    gl_FragColor.rgb *= debugShowFrustumsColor;\n";
  }
  newMain += "}";

  fs.sources.push(newMain);

  var attributeLocations = getAttributeLocations(sp);

  return ShaderProgram.fromCache({
    context: context,
    vertexShaderSource: sp.vertexShaderSource,
    fragmentShaderSource: fs,
    attributeLocations: attributeLocations,
  });
}

var scratchFrustumColor = new Color();
function createDebugShowFrustumsUniformMap(scene, command) {
  // setup uniform for the shader
  var debugUniformMap;
  if (!defined(command.uniformMap)) {
    debugUniformMap = {};
  } else {
    debugUniformMap = command.uniformMap;
  }

  if (
    defined(debugUniformMap.debugShowCommandsColor) ||
    defined(debugUniformMap.debugShowFrustumsColor)
  ) {
    return debugUniformMap;
  }

  debugUniformMap.debugShowCommandsColor = function () {
    if (!scene.debugShowCommands) {
      return Color.WHITE;
    }

    if (!defined(command._debugColor)) {
      command._debugColor = Color.fromRandom();
    }

    return command._debugColor;
  };

  debugUniformMap.debugShowFrustumsColor = function () {
    if (!scene.debugShowFrustums) {
      return Color.WHITE;
    }

    // Support up to three frustums.  If a command overlaps all
    // three, it's code is not changed.
    scratchFrustumColor.red =
{'fraction_non_alphanumeric': 0.13254652746255108, 'fraction_numerical': 0.006960205779996974, 'mean_word_length': 3.43326626425218, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6249453', 'n_tokens_mistral': 2129, 'n_tokens_neox': 2093, 'n_words': 452}