<commit_before>/**
 * PANDA 3D SOFTWARE
 * Copyright (c) Carnegie Mellon University.  All rights reserved.
 *
 * All use of this software is subject to the terms of the revised BSD
 * license.  You should have received a copy of this license along
 * with this source code in a file named "LICENSE."
 *
 * @file cullableObject.cxx
 * @author drose
 * @date 2002-03-04
 */

#include "cullableObject.h"
#include "lightAttrib.h"
#include "nodePath.h"
#include "colorAttrib.h"
#include "texGenAttrib.h"
#include "textureAttrib.h"
#include "shaderAttrib.h"
#include "renderState.h"
#include "clockObject.h"
#include "cullTraverser.h"
#include "sceneSetup.h"
#include "lens.h"
#include "stateMunger.h"
#include "pStatTimer.h"
#include "geomVertexWriter.h"
#include "geomVertexReader.h"
#include "geomTriangles.h"
#include "light.h"
#include "lightMutexHolder.h"

CullableObject::FormatMap CullableObject::_format_map;
LightMutex CullableObject::_format_lock;

PStatCollector CullableObject::_munge_pcollector("*:Munge");
PStatCollector CullableObject::_munge_geom_pcollector("*:Munge:Geom");
PStatCollector CullableObject::_munge_sprites_pcollector("*:Munge:Sprites");
PStatCollector CullableObject::_munge_sprites_verts_pcollector("*:Munge:Sprites:Verts");
PStatCollector CullableObject::_munge_sprites_prims_pcollector("*:Munge:Sprites:Prims");
PStatCollector CullableObject::_sw_sprites_pcollector("SW Sprites");

TypeHandle CullableObject::_type_handle;

/**
 * Uses the indicated GeomMunger to transform the geom and/or its vertices.
 *
 * If force is false, this may do nothing and return false if the vertex data
 * is nonresident.  If force is true, this will always return true, but it may
 * have to block while the vertex data is paged in.
 */
bool CullableObject::
munge_geom(GraphicsStateGuardianBase *gsg, GeomMunger *munger,
           const CullTraverser *traverser, bool force) {
  nassertr(munger != nullptr, false);

  Thread *current_thread = traverser->get_current_thread();
  PStatTimer timer(_munge_pcollector, current_thread);
  if (_geom != nullptr) {
    GraphicsStateGuardianBase *gsg = traverser->get_gsg();
    int gsg_bits = gsg->get_supported_geom_rendering();
    if (!hardware_point_sprites) {
      // If support for hardware point sprites or perspective-scaled points is
      // disabled, we don't allow the GSG to tell us it supports them.
      gsg_bits &= ~(Geom::GR_point_perspective | Geom::GR_point_sprite);
    }
    if (!hardware_points) {
      // If hardware-points is off, we don't allow any kind of point
      // rendering, except plain old one-pixel points;
      gsg_bits &= ~(Geom::GR_point_bits & ~Geom::GR_point);
    }
    int geom_rendering;
    int unsupported_bits;

    {
      GeomPipelineReader geom_reader(_geom, current_thread);
      _munged_data = geom_reader.get_vertex_data();

#ifdef _DEBUG
      {
        GeomVertexDataPipelineReader data_reader(_munged_data, current_thread);
        data_reader.check_array_readers();
        nassertr(geom_reader.check_valid(&data_reader), false);
      }
#endif  // _DEBUG

      geom_rendering = geom_reader.get_geom_rendering();
      geom_rendering = _state->get_geom_rendering(geom_rendering);
      geom_rendering = _internal_transform->get_geom_rendering(geom_rendering);
      unsupported_bits = geom_rendering & ~gsg_bits;
<commit_msg>cull: don't munge_points_to_quads if shader handles point size<commit_after>/**
 * PANDA 3D SOFTWARE
 * Copyright (c) Carnegie Mellon University.  All rights reserved.
 *
 * All use of this software is subject to the terms of the revised BSD
 * license.  You should have received a copy of this license along
 * with this source code in a file named "LICENSE."
 *
 * @file cullableObject.cxx
 * @author drose
 * @date 2002-03-04
 */

#include "cullableObject.h"
#include "lightAttrib.h"
#include "nodePath.h"
#include "colorAttrib.h"
#include "texGenAttrib.h"
#include "textureAttrib.h"
#include "shaderAttrib.h"
#include "renderState.h"
#include "clockObject.h"
#include "cullTraverser.h"
#include "sceneSetup.h"
#include "lens.h"
#include "stateMunger.h"
#include "pStatTimer.h"
#include "geomVertexWriter.h"
#include "geomVertexReader.h"
#include "geomTriangles.h"
#include "light.h"
#include "lightMutexHolder.h"

CullableObject::FormatMap CullableObject::_format_map;
LightMutex CullableObject::_format_lock;

PStatCollector CullableObject::_munge_pcollector("*:Munge");
PStatCollector CullableObject::_munge_geom_pcollector("*:Munge:Geom");
PStatCollector CullableObject::_munge_sprites_pcollector("*:Munge:Sprites");
PStatCollector CullableObject::_munge_sprites_verts_pcollector("*:Munge:Sprites:Verts");
PStatCollector CullableObject::_munge_sprites_prims_pcollector("*:Munge:Sprites:Prims");
PStatCollector CullableObject::_sw_sprites_pcollector("SW Sprites");

TypeHandle CullableObject::_type_handle;

/**
 * Uses the indicated GeomMunger to transform the geom and/or its vertices.
 *
 * If force is false, this may do nothing and return false if the vertex data
 * is nonresident.  If force is true, this will always return true, but it may
 * have to block while the vertex data is paged in.
 */
bool CullableObject::
munge_geom(GraphicsStateGuardianBase *gsg, GeomMunger *munger,
           const CullTraverser *traverser, bool force) {
  nassertr(munger != nullptr, false);

  Thread *current_thread = traverser->get_current_thread();
  PStatTimer timer(_munge_pcollector, current_thread);
  if (_geom != nullptr) {
    GraphicsStateGuardianBase *gsg = traverser->get_gsg();
    int gsg_bits = gsg->get_supported_geom_rendering();
    if (!hardware_point_sprites) {
      // If support for hardware point sprites or perspective-scaled points is
      // disabled, we don't allow the GSG to tell us it supports them.
      gsg_bits &= ~(Geom::GR_point_perspective | Geom::GR_point_sprite);
    }
    if (!hardware_points) {
      // If hardware-points is off, we don't allow any kind of point
      // rendering, except plain old one-pixel points;
      gsg_bits &= ~(Geom::GR_point_bits & ~Geom::GR_point);
    }
    int geom_rendering;
    int unsupported_bits;

    {
      GeomPipelineReader geom_reader(_geom, current_thread);
      _munged_data = geom_reader.get_vertex_data();

#ifdef _DEBUG
      {
        GeomVertexDataPipelineReader data_reader(_munged_data, current_thread);
        data_reader.check_array_readers();
        nassertr(geom_reader.check_valid(&data_reader), false);
      }
#endif  // _DEBUG

      geom_rendering = geom_reader.get_geom_rendering();
      geom_rendering = _state->get_geom_rendering(geom_rendering);
      geom_rendering = _internal_transform->get_geom_rendering(geom_rendering);
      unsupported_bits = geom_rendering & ~gsg_bits;

      if (unsupported_bits & Geom::GR_per_point_size) {
        // If we have a shader that processes the point size, we can assume it
        // does the right thing.
        const ShaderAttrib *sattr;
        if (_state->get_attrib(sattr) && sattr->get_flag(ShaderAttrib::F_shader_point_size)) {
          unsupported_bits &= ~Geom::GR_per_point_size;
        }
      }

{'fraction_non_alphanumeric': 0.10281293952180028, 'fraction_numerical': 0.002531645569620253, 'mean_word_length': 4.734677419354838, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '955815', 'n_tokens_mistral': 2409, 'n_tokens_neox': 2361, 'n_words': 566}