<commit_before>// Filename: stencilRenderStates.cxx
// Created by:  aignacio (17May06)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2006, Disney Enterprises, Inc.  All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license.  You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// <EMAIL> .
//
////////////////////////////////////////////////////////////////////

#include "graphicsStateGuardian.h"
#include "stencilRenderStates.h"

StencilRenderStates::
StencilRenderStates (GraphicsStateGuardian *gsg) {

  int index;

  // clear all
  for (index = 0; index < SRS_total; index++) {
    _stencil_render_state_array [index] = 0;
    _stencil_function_array [index] = 0;
  }

  // set default render states
  set_stencil_render_state (false, SRS_clear_value, 0);

  set_stencil_render_state (false, SRS_reference, 0);

  set_stencil_render_state (false, SRS_read_mask, ~0);
  set_stencil_render_state (false, SRS_write_mask, ~0);

  set_stencil_render_state (false, SRS_front_enable, 0);
  set_stencil_render_state (false, SRS_front_comparison_function, SCF_always);
  set_stencil_render_state (false, SRS_front_stencil_fail_operation, SO_keep);
  set_stencil_render_state (false, SRS_front_stencil_pass_z_fail_operation, SO_keep);
  set_stencil_render_state (false, SRS_front_stencil_pass_z_pass_operation, SO_keep);

  set_stencil_render_state (false, SRS_back_enable, 0);
  set_stencil_render_state (false, SRS_back_comparison_function, SCF_always);
  set_stencil_render_state (false, SRS_back_stencil_fail_operation, SO_keep);
  set_stencil_render_state (false, SRS_back_stencil_pass_z_fail_operation, SO_keep);
  set_stencil_render_state (false, SRS_back_stencil_pass_z_pass_operation, SO_keep);

  _gsg = gsg;
}

StencilRenderStates::
~StencilRenderStates (void) {

}

void StencilRenderStates::
set_stencil_render_state (bool execute_function, StencilRenderStates::StencilRenderState stencil_render_state, StencilType value) {

  _stencil_render_state_array [stencil_render_state] = value;

  if (execute_function) {
    StencilFunction stencil_function;

    stencil_function = _stencil_function_array [stencil_render_state];
    if (stencil_function) {
      stencil_function (stencil_render_state, this);
    }
  }
}

StencilType StencilRenderStates::
get_stencil_render_state (StencilRenderStates::StencilRenderState stencil_render_state) {
  return _stencil_render_state_array [stencil_render_state];
}

void StencilRenderStates::
set_stencil_function (StencilRenderStates::StencilRenderState stencil_render_state, StencilFunction stencil_function) {
  _stencil_function_array [stencil_render_state] = stencil_function;
}

<commit_msg>Add comments, debug.<commit_after>// Filename: stencilRenderStates.cxx
// Created by:  aignacio (17May06)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2006, Disney Enterprises, Inc.  All rights
// reserved.
//
// All use of this software is subject to the terms of the Panda 3d
// Software license.  You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// <EMAIL> .
//
////////////////////////////////////////////////////////////////////

#include "graphicsStateGuardian.h"
#include "stencilRenderStates.h"

////////////////////////////////////////////////////////////////////
//     Function: StencilRenderStates::Constructor
//  Description: Constructor.  All data is set to the default.
////////////////////////////////////////////////////////////////////
StencilRenderStates::
StencilRenderStates (GraphicsStateGuardian *gsg) {

  int index;

  // clear all
  for (index = 0; index < SRS_total; index++) {
    _stencil_render_state_array [index] = 0;
    _stencil_function_array [index] = 0;
  }

  // set default render states
  set_stencil_render_state (false, SRS_reference, 0);

  set_stencil_render_state (false, SRS_read_mask, ~0);
  set_stencil_render_state (false, SRS_write_mask, ~0);

  set_stencil_render_state (false, SRS_front_enable, 0);
  set_stencil_render_state (false, SRS_front_comparison_function, SCF_always);
  set_stencil_render_state (false, SRS_front_stencil_fail_operation, SO_keep);
  set_stencil_render_state (false, SRS_front_stencil_pass_z_fail_operation, SO_keep);
  set_stencil_render_state (false, SRS_front_stencil_pass_z_pass_operation, SO_keep);

  set_stencil_render_state (false, SRS_back_enable, 0);
  set_stencil_render_state (false, SRS_back_comparison_function, SCF_always);
  set_stencil_render_state (false, SRS_back_stencil_fail_operation, SO_keep);
  set_stencil_render_state (false, SRS_back_stencil_pass_z_fail_operation, SO_keep);
  set_stencil_render_state (false, SRS_back_stencil_pass_z_pass_operation, SO_keep);

  _gsg = gsg;
}

////////////////////////////////////////////////////////////////////
//     Function: StencilRenderStates::Destructor
//  Description:
////////////////////////////////////////////////////////////////////
StencilRenderStates::
~StencilRenderStates (void) {

}

////////////////////////////////////////////////////////////////////
//     Function: StencilRenderStates::set_stencil_render_state
//  Description: Sets the current render state for the specified
//               stencil render state. The execute_function
//               parameter can be used to defer the actual setting
//               of the render state at the API level.  This is
//               useful for the OpenGL API where certain render
//               states are not independent/atomic (i.e.
//               glStencilFunc and glStencilOp).
////////////////////////////////////////////////////////////////////
void StencilRenderStates::
set_stencil_render_state (bool execute_function, StencilRenderStates::StencilRenderState stencil_render_state, StencilType value) {

  // DEBUG
  if (false) {
    printf ("SRS %d %d %d \n", execute_function, stencil_render_state, value);
  }

  _stencil_render_state_array [stencil_render_state] = value;

  if (execute_function) {
    StencilFunction stencil_function;

    stencil_function = _stencil_function_array [stencil_render_state];
    if (stencil_function) {
      stencil_function (stencil_render_state, this);
    }
  }
}

////////////////////////////////////////////////////////////////////
//     Function: StencilRenderStates::get_stencil_render_state
//  Description: Gets the current render state for the specified
//               stencil render state.
////////////////////////////////////////////////////////////////////
StencilType StencilRenderStates::
get_stencil_render_state (StencilRenderStates::StencilRenderState stencil_render_state) {
  return _stencil_render_state_array [stencil_render_state];
}

////////////////////////////////////////////////////////////////////
//     Function: StencilRenderStates::set_stencil_function
//  Description: Registers an API specific callback for setting a
//               specified stencil render state.
////////////////////////////////////////////////////////////////////
void StencilRenderStates::
set_stencil_function (StencilRenderStates::StencilRenderState stencil_render_state, StencilFunction stencil_function) {
  _stencil_function_array [stencil_render_state] = stencil_function;
}

{'fraction_non_alphanumeric': 0.19598644774563462, 'fraction_numerical': 0.006124576492051082, 'mean_word_length': 2.6757662835249043, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4320402', 'n_tokens_mistral': 2259, 'n_tokens_neox': 2189, 'n_words': 510}