Panda3D
cullBinStateSorted.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file cullBinStateSorted.I
10  * @author drose
11  * @date 2005-03-22
12  */
13 
14 /**
15  *
16  */
17 INLINE CullBinStateSorted::
18 CullBinStateSorted(const std::string &name, GraphicsStateGuardianBase *gsg,
19  const PStatCollector &draw_region_pcollector) :
20  CullBin(name, BT_state_sorted, gsg, draw_region_pcollector),
21  _objects(get_class_type())
22 {
23 }
24 
25 /**
26  *
27  */
28 INLINE CullBinStateSorted::ObjectData::
29 ObjectData(CullableObject *object) :
30  _object(object)
31 {
32  if (object->_munged_data == nullptr) {
33  _format = nullptr;
34  } else {
35  _format = object->_munged_data->get_format();
36  }
37 }
38 
39 /**
40  * Specifies the correct sort ordering for these objects.
41  */
42 INLINE bool CullBinStateSorted::ObjectData::
43 operator < (const ObjectData &other) const {
44  // Group by state changes, in approximate order from heaviest change to
45  // lightest change.
46  const RenderState *sa = _object->_state;
47  const RenderState *sb = other._object->_state;
48  int compare = sa->compare_sort(*sb);
49  if (compare != 0) {
50  return compare < 0;
51  }
52 
53  // Vertex format changes are also fairly slow.
54  if (_format != other._format) {
55  return _format < other._format;
56  }
57 
58  // Prevent unnecessary vertex buffer rebinds.
59  if (_object->_munged_data != other._object->_munged_data) {
60  return _object->_munged_data < other._object->_munged_data;
61  }
62 
63  // Uniform updates are actually pretty fast.
64  if (_object->_internal_transform != other._object->_internal_transform) {
65  return _object->_internal_transform < other._object->_internal_transform;
66  }
67 
68  return 0;
69 }
A collection of Geoms and their associated state, for a particular scene.
Definition: cullBin.h:40
A lightweight class that represents a single element that may be timed and/or counted via stats.
The smallest atom of cull.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:47
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
int compare_sort(const RenderState &other) const
Returns -1, 0, or 1 according to the relative sorting of these two RenderStates, with regards to rend...