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,