Panda3D
Loading...
Searching...
No Matches
cullBinStateSorted.cxx
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.cxx
10 * @author drose
11 * @date 2005-03-22
12 */
13
14#include "cullBinStateSorted.h"
16#include "cullableObject.h"
17#include "cullHandler.h"
18#include "pStatTimer.h"
19
20#include <algorithm>
21
22
23TypeHandle CullBinStateSorted::_type_handle;
24
25/**
26 *
27 */
28CullBinStateSorted::
29~CullBinStateSorted() {
30 Objects::iterator oi;
31 for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
32 CullableObject *object = (*oi)._object;
33 delete object;
34 }
35}
36
37/**
38 * Factory constructor for passing to the CullBinManager.
39 */
41make_bin(const std::string &name, GraphicsStateGuardianBase *gsg,
42 const PStatCollector &draw_region_pcollector) {
43 return new CullBinStateSorted(name, gsg, draw_region_pcollector);
44}
45
46/**
47 * Adds a geom, along with its associated state, to the bin for rendering.
48 */
50add_object(CullableObject *object, Thread *current_thread) {
51 _objects.push_back(ObjectData(object));
52}
53
54/**
55 * Called after all the geoms have been added, this indicates that the cull
56 * process is finished for this frame and gives the bins a chance to do any
57 * post-processing (like sorting) before moving on to draw.
58 */
60finish_cull(SceneSetup *, Thread *current_thread) {
61 PStatTimer timer(_cull_this_pcollector, current_thread);
62 sort(_objects.begin(), _objects.end());
63}
64
65
66/**
67 * Draws all the geoms in the bin, in the appropriate order.
68 */
70draw(bool force, Thread *current_thread) {
71 PStatTimer timer(_draw_this_pcollector, current_thread);
72
73 Objects::const_iterator oi;
74 for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
75 CullableObject *object = (*oi)._object;
76
77 if (object->_draw_callback == nullptr) {
78 nassertd(object->_geom != nullptr) continue;
79
80 _gsg->set_state_and_transform(object->_state, object->_internal_transform);
81
82 GeomPipelineReader geom_reader(object->_geom, current_thread);
83 GeomVertexDataPipelineReader data_reader(object->_munged_data, current_thread);
84 data_reader.check_array_readers();
85 geom_reader.draw(_gsg, &data_reader, force);
86 } else {
87 // It has a callback associated.
88 object->draw_callback(_gsg, force, current_thread);
89 // Now the callback has taken care of drawing.
90 }
91 }
92}
93
94/**
95 * Called by CullBin::make_result_graph() to add all the geoms to the special
96 * cull result scene graph.
97 */
98void CullBinStateSorted::
99fill_result_graph(CullBin::ResultGraphBuilder &builder) {
100 Objects::const_iterator oi;
101 for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
102 CullableObject *object = (*oi)._object;
103 builder.add_object(object);
104 }
105}
A specific kind of CullBin that sorts geometry to collect items of the same state together,...
static CullBin * make_bin(const std::string &name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector)
Factory constructor for passing to the CullBinManager.
virtual void add_object(CullableObject *object, Thread *current_thread)
Adds a geom, along with its associated state, to the bin for rendering.
virtual void finish_cull(SceneSetup *scene_setup, Thread *current_thread)
Called after all the geoms have been added, this indicates that the cull process is finished for this...
virtual void draw(bool force, Thread *current_thread)
Draws all the geoms in the bin, in the appropriate order.
A collection of Geoms and their associated state, for a particular scene.
Definition cullBin.h:40
The smallest atom of cull.
Encapsulates the data from a Geom, pre-fetched for one stage of the pipeline.
Definition geom.h:405
bool draw(GraphicsStateGuardianBase *gsg, const GeomVertexDataPipelineReader *data_reader, bool force) const
The implementation of Geom::draw().
Definition geom.cxx:1881
Encapsulates the data from a GeomVertexData, pre-fetched for one stage of the pipeline.
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
A lightweight class that represents a single element that may be timed and/or counted via stats.
A lightweight class that can be used to automatically start and stop a PStatCollector around a sectio...
Definition pStatTimer.h:30
This object holds the camera position, etc., and other general setup information for rendering a part...
Definition sceneSetup.h:32
A thread; that is, a lightweight process.
Definition thread.h:46
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.