51 static const PN_stdfloat dual_opaque_level = 252.0 / 256.0;
52 static const double bin_color_flash_rate = 1.0;
61 _draw_region_pcollector(draw_region_pcollector)
63 #ifdef DO_MEMORY_USAGE 68 _show_transparency = show_transparency.
get_value();
80 new_result->_bins.reserve(_bins.size());
84 for (
size_t i = 0; i < _bins.size(); ++i) {
86 if (old_bin ==
nullptr ||
87 old_bin->get_bin_type() != bin_manager->
get_bin_type(i)) {
88 new_result->_bins.push_back(
nullptr);
90 new_result->_bins.push_back(old_bin->make_next());
103 static const LColor flash_alpha_color(0.92, 0.96, 0.10, 1.0f);
104 static const LColor flash_binary_color(0.21f, 0.67f, 0.24, 1.0f);
105 static const LColor flash_multisample_color(0.78f, 0.05f, 0.81f, 1.0f);
106 static const LColor flash_dual_color(0.92, 0.01f, 0.01f, 1.0f);
108 nassertv(object->_draw_callback !=
nullptr || object->_geom !=
nullptr);
116 object->_state->get_attrib_def(rescale);
117 if (rescale->
get_mode() == RescaleNormalAttrib::M_auto) {
118 RescaleNormalAttrib::Mode mode;
120 if (object->_internal_transform->has_identity_scale()) {
121 mode = RescaleNormalAttrib::M_none;
122 }
else if (object->_internal_transform->has_uniform_scale()) {
123 mode = RescaleNormalAttrib::M_rescale;
125 mode = RescaleNormalAttrib::M_normalize;
128 object->_state =
object->_state->compose(get_rescale_normal_state(mode));
133 if (object->_state->get_attrib(rmode)) {
134 if (rmode->
get_mode() == RenderModeAttrib::M_filled_wireframe) {
136 wireframe_part->_state = get_wireframe_overlay_state(rmode);
139 (_gsg, _gsg->get_geom_munger(wireframe_part->_state, current_thread),
141 int wireframe_bin_index = bin_manager->
find_bin(
"fixed");
143 nassertv(bin !=
nullptr);
144 check_flash_bin(wireframe_part->_state, bin_manager, wireframe_bin_index);
145 bin->add_object(wireframe_part, current_thread);
147 delete wireframe_part;
150 object->_state =
object->_state->compose(get_wireframe_filled_state());
156 if (object->_state->get_attrib(trans)) {
158 case TransparencyAttrib::M_alpha:
159 case TransparencyAttrib::M_premultiplied_alpha:
162 object->_state =
object->_state->compose(get_alpha_state());
163 check_flash_transparency(object->_state, flash_alpha_color);
166 case TransparencyAttrib::M_binary:
168 object->_state =
object->_state->compose(get_binary_state());
169 check_flash_transparency(object->_state, flash_binary_color);
172 case TransparencyAttrib::M_multisample:
173 case TransparencyAttrib::M_multisample_mask:
176 if (!_gsg->get_supports_multisample()) {
177 object->_state =
object->_state->compose(get_binary_state());
179 check_flash_transparency(object->_state, flash_multisample_color);
182 case TransparencyAttrib::M_dual:
184 check_flash_transparency(object->_state, flash_dual_color);
198 if (!object->_state->get_attrib(bin_attrib) ||
203 if (m_dual_transparent)
207 CPT(
RenderState) transparent_state = get_dual_transparent_state();
208 transparent_part->_state =
object->_state->compose(transparent_state);
210 (_gsg, _gsg->get_geom_munger(transparent_part->_state, current_thread),
212 int transparent_bin_index = transparent_part->_state->get_bin_index();
214 nassertv(bin !=
nullptr);
215 check_flash_bin(transparent_part->_state, bin_manager, transparent_bin_index);
216 bin->add_object(transparent_part, current_thread);
218 delete transparent_part;
224 object->_state =
object->_state->compose(get_dual_opaque_state());
226 if (!m_dual_opaque) {
242 int bin_index =
object->_state->get_bin_index();
244 nassertv(bin !=
nullptr);
245 check_flash_bin(object->_state, bin_manager, bin_index);
249 if (object->
munge_geom(_gsg, _gsg->get_geom_munger(object->_state, current_thread), traverser, force)) {
253 bin->add_object(
object, current_thread);
268 for (
size_t i = 0; i < _bins.size(); ++i) {
276 if (bin !=
nullptr) {
277 bin->finish_cull(scene_setup, current_thread);
288 bool force = !_gsg->get_effective_incomplete_render();
293 for (
int i = 0; i < num_bins; i++) {
294 int bin_index = bin_manager->
get_bin(i);
295 nassertv(bin_index >= 0);
297 if (bin_index < (
int)_bins.size() && _bins[bin_index] !=
nullptr) {
299 _gsg->push_group_marker(_bins[bin_index]->get_name());
300 _bins[bin_index]->draw(force, current_thread);
301 _gsg->pop_group_marker();
317 make_result_graph() {
323 for (
int i = 0; i < num_bins; i++) {
324 int bin_index = bin_manager->
get_bin(i);
325 nassertr(bin_index >= 0,
nullptr);
327 if (bin_index < (
int)_bins.size() && _bins[bin_index] !=
nullptr) {
328 root_node->add_child(_bins[bin_index]->make_result_graph());
351 make_new_bin(
int bin_index) {
353 PT(
CullBin) bin = bin_manager->make_new_bin(bin_index, _gsg,
354 _draw_region_pcollector);
357 if (bin_ptr !=
nullptr) {
359 while (bin_index >= (
int)_bins.size()) {
360 _bins.push_back(
nullptr);
362 nassertr(bin_index >= 0 && bin_index < (
int)_bins.size(),
nullptr);
365 std::swap(_bins[bin_index], bin);
375 get_rescale_normal_state(RescaleNormalAttrib::Mode mode) {
376 static CPT(
RenderState) states[RescaleNormalAttrib::M_auto + 1];
377 if (states[mode].is_null()) {
378 states[mode] = RenderState::make(RescaleNormalAttrib::make(mode),
379 RenderState::get_max_priority());
381 return states[mode].p();
391 if (state ==
nullptr) {
394 state = RenderState::make(AlphaTestAttrib::make(AlphaTestAttrib::M_greater, 0.0f));
405 if (state ==
nullptr) {
406 state = RenderState::make(AlphaTestAttrib::make(AlphaTestAttrib::M_greater_equal, 0.5f),
407 TransparencyAttrib::make(TransparencyAttrib::M_none),
408 RenderState::get_max_priority());
418 apply_flash_color(
CPT(
RenderState) &state,
const LColor &flash_color) {
420 if ((cycle & 1) == 0) {
421 state = state->remove_attrib(TextureAttrib::get_class_slot());
422 state = state->remove_attrib(LightAttrib::get_class_slot());
423 state = state->remove_attrib(ColorScaleAttrib::get_class_slot());
424 state = state->remove_attrib(FogAttrib::get_class_slot());
425 state = state->add_attrib(ColorAttrib::make_flat(flash_color),
426 RenderState::get_max_priority());
436 get_dual_transparent_state() {
438 if (state ==
nullptr) {
444 state = RenderState::make(AlphaTestAttrib::make(AlphaTestAttrib::M_greater, 0.0f),
445 TransparencyAttrib::make(TransparencyAttrib::M_alpha),
446 DepthWriteAttrib::make(DepthWriteAttrib::M_off),
447 RenderState::get_max_priority());
453 if ((cycle & 1) == 0) {
455 if (flash_state ==
nullptr) {
456 flash_state = state->add_attrib(ColorAttrib::make_flat(LColor(0.8f, 0.2, 0.2, 1.0f)),
457 RenderState::get_max_priority());
459 flash_state = flash_state->add_attrib(ColorScaleAttrib::make(LVecBase4(1.0f, 1.0f, 1.0f, 1.0f)),
460 RenderState::get_max_priority());
462 flash_state = flash_state->add_attrib(AlphaTestAttrib::make(AlphaTestAttrib::M_less, 1.0f),
463 RenderState::get_max_priority());
465 return flash_state.p();
478 get_dual_opaque_state() {
480 if (state ==
nullptr) {
481 state = RenderState::make(AlphaTestAttrib::make(AlphaTestAttrib::M_greater_equal, dual_opaque_level),
482 TransparencyAttrib::make(TransparencyAttrib::M_none),
483 RenderState::get_max_priority());
489 if ((cycle & 1) == 0) {
491 if (flash_state ==
nullptr) {
492 flash_state = state->add_attrib(ColorAttrib::make_flat(LColor(0.2, 0.2, 0.8f, 1.0f)),
493 RenderState::get_max_priority());
494 flash_state = flash_state->add_attrib(ColorScaleAttrib::make(LVecBase4(1.0f, 1.0f, 1.0f, 1.0f)),
495 RenderState::get_max_priority());
498 return flash_state.p();
511 get_wireframe_filled_state() {
513 RenderModeAttrib::make(RenderModeAttrib::M_filled),
514 RenderState::get_max_priority());
524 return RenderState::make(
525 DepthOffsetAttrib::make(1, 0, 0.99999f),
527 ColorBlendAttrib::make(ColorBlendAttrib::M_add,
528 ColorBlendAttrib::O_incoming_alpha,
529 ColorBlendAttrib::O_one_minus_incoming_alpha),
530 RenderModeAttrib::make(RenderModeAttrib::M_wireframe,
CPT(RenderState) CullResult
Returns a RenderState that renders only the wireframe part of an M_filled_wireframe model.
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
PT(CullResult) CullResult
Returns a newly-allocated CullResult object that contains a copy of just the subset of the data from ...
A basic node of the scene graph or data graph.
get_mode
Returns the transparency mode.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A collection of Geoms and their associated state, for a particular scene.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Thread * get_current_thread() const
Returns the currently-executing thread object, as passed to the CullTraverser constructor.
This controls the enabling of transparency.
get_mode
Returns the render mode.
get_bin_name
Returns the name of the bin this attribute specifies.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_value
Returns the variable's value.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
static CullBinManager * get_global_ptr()
Returns the pointer to the global CullBinManager object.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int find_bin(const std::string &name) const
Returns the bin_index associated with the bin of the given name, or -1 if no bin has that name.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool get_effective_incomplete_render() const
Returns true if the cull traversal is effectively in incomplete_render state, considering both the GS...
A lightweight class that represents a single element that may be timed and/or counted via stats.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The smallest atom of cull.
get_frame_time
Returns the time in seconds as of the last time tick() was called (typically, this will be as of the ...
CullBin * get_bin(int bin_index)
Returns the CullBin associated with the indicated bin_index, or NULL if the bin_index is invalid.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool munge_geom(GraphicsStateGuardianBase *gsg, GeomMunger *munger, const CullTraverser *traverser, bool force)
Uses the indicated GeomMunger to transform the geom and/or its vertices.
static void bin_removed(int bin_index)
Intended to be called by CullBinManager::remove_bin(), this informs all the CullResults in the world ...
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
static void update_type(ReferenceCount *ptr, TypeHandle type)
Associates the indicated type with the given pointer.
Assigns geometry to a particular bin by name.
bool get_bin_active(int bin_index) const
Returns the active flag of the bin with the indicated bin_index (where bin_index was retrieved by get...
get_num_bins
Returns the number of bins in the world.
This stores the result of a BinCullHandler traversal: an ordered collection of CullBins,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_bin
Returns the bin_index of the nth bin in the set, where n is a number between 0 and get_num_bins().
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
get_mode
Returns the render mode.
A thread; that is, a lightweight process.
get_wireframe_color
Returns the color that is used in M_filled_wireframe mode to distinguish the wireframe from the rest ...
Specifies how polygons are to be drawn.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_thickness
Returns the line width or point thickness.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_perspective
Returns the perspective flag.
Specifies how polygons are to be drawn.
void draw(Thread *current_thread)
Asks all the bins to draw themselves in the correct order.
TypeHandle is the identifier used to differentiate C++ class types.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This object holds the camera position, etc., and other general setup information for rendering a part...
This is a global object that maintains the collection of named CullBins in the world.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
BinType get_bin_type(int bin_index) const
Returns the type of the bin with the indicated bin_index (where bin_index was retrieved by get_bin() ...