15 #include "cullResult.h"
16 #include "cullBinManager.h"
17 #include "cullBinAttrib.h"
18 #include "textureAttrib.h"
19 #include "lightAttrib.h"
20 #include "colorAttrib.h"
21 #include "alphaTestAttrib.h"
22 #include "depthWriteAttrib.h"
23 #include "colorScaleAttrib.h"
24 #include "fogAttrib.h"
25 #include "transparencyAttrib.h"
26 #include "renderState.h"
27 #include "clockObject.h"
28 #include "config_pgraph.h"
29 #include "depthOffsetAttrib.h"
30 #include "colorBlendAttrib.h"
56 static const PN_stdfloat dual_opaque_level = 252.0 / 256.0;
57 static const double bin_color_flash_rate = 1.0;
68 _draw_region_pcollector(draw_region_pcollector)
70 #ifdef DO_MEMORY_USAGE
71 MemoryUsage::update_type(
this, get_class_type());
75 _show_transparency = show_transparency.
get_value();
90 new_result->_bins.reserve(_bins.size());
94 for (
size_t i = 0; i < _bins.size(); ++i) {
96 if (old_bin == (
CullBin *)NULL ||
97 old_bin->get_bin_type() != bin_manager->
get_bin_type(i)) {
98 new_result->_bins.push_back((
CullBin *)NULL);
100 new_result->_bins.push_back(old_bin->make_next());
116 static const LColor flash_alpha_color(0.92, 0.96, 0.10, 1.0f);
117 static const LColor flash_binary_color(0.21f, 0.67f, 0.24, 1.0f);
118 static const LColor flash_multisample_color(0.78f, 0.05f, 0.81f, 1.0f);
119 static const LColor flash_dual_color(0.92, 0.01f, 0.01f, 1.0f);
130 state->
get_attrib(TransparencyAttrib::get_class_slot());
134 case TransparencyAttrib::M_alpha:
137 object->_state = state->compose(get_alpha_state());
138 check_flash_transparency(object->_state, flash_alpha_color);
141 case TransparencyAttrib::M_binary:
143 object->_state = state->compose(get_binary_state());
144 check_flash_transparency(object->_state, flash_binary_color);
147 case TransparencyAttrib::M_multisample:
148 case TransparencyAttrib::M_multisample_mask:
151 if (!_gsg->get_supports_multisample()) {
152 object->_state = state->compose(get_binary_state());
154 check_flash_transparency(object->_state, flash_multisample_color);
157 case TransparencyAttrib::M_dual:
159 check_flash_transparency(object->_state, flash_dual_color);
160 state =
object->_state;
175 state->
get_attrib(CullBinAttrib::get_class_slot());
182 if (m_dual_transparent)
186 CPT(
RenderState) transparent_state = get_dual_transparent_state();
187 transparent_part->_state = state->compose(transparent_state);
189 (_gsg, _gsg->get_geom_munger(transparent_part->_state, current_thread),
191 int transparent_bin_index = transparent_part->_state->get_bin_index();
193 nassertv(bin != (
CullBin *)NULL);
194 check_flash_bin(transparent_part->_state, bin_manager, transparent_bin_index);
195 bin->add_object(transparent_part, current_thread);
197 delete transparent_part;
203 object->_state = state->compose(get_dual_opaque_state());
205 if (!m_dual_opaque) {
224 object->_state->get_attrib(RenderModeAttrib::get_class_slot());
226 if (rmode->
get_mode() == RenderModeAttrib::M_filled_wireframe) {
228 wireframe_part->_state = get_wireframe_overlay_state(rmode);
231 (_gsg, _gsg->get_geom_munger(wireframe_part->_state, current_thread),
233 int wireframe_bin_index = bin_manager->
find_bin(
"fixed");
235 nassertv(bin != (
CullBin *)NULL);
236 check_flash_bin(wireframe_part->_state, bin_manager, wireframe_bin_index);
237 bin->add_object(wireframe_part, current_thread);
239 delete wireframe_part;
242 object->_state =
object->_state->set_attrib(RenderModeAttrib::make(RenderModeAttrib::M_filled));
246 int bin_index =
object->_state->get_bin_index();
248 nassertv(bin != (
CullBin *)NULL);
249 check_flash_bin(object->_state, bin_manager, bin_index);
253 if (object->
munge_geom(_gsg, _gsg->get_geom_munger(object->_state, current_thread), traverser, force)) {
258 bin->add_object(
object, current_thread);
277 for (
size_t i = 0; i < _bins.size(); ++i) {
286 bin->finish_cull(scene_setup, current_thread);
300 bool force = !_gsg->get_effective_incomplete_render();
305 for (
int i = 0; i < num_bins; i++) {
306 int bin_index = bin_manager->
get_bin(i);
307 nassertv(bin_index >= 0);
309 if (bin_index < (
int)_bins.size() && _bins[bin_index] != (
CullBin *)NULL) {
310 _bins[bin_index]->draw(force, current_thread);
332 make_result_graph() {
337 int num_bins = bin_manager->get_num_bins();
338 for (
int i = 0; i < num_bins; i++) {
339 int bin_index = bin_manager->
get_bin(i);
340 nassertr(bin_index >= 0, NULL);
342 if (bin_index < (
int)_bins.size() && _bins[bin_index] != (
CullBin *)NULL) {
343 root_node->add_child(_bins[bin_index]->make_result_graph());
371 make_new_bin(
int bin_index) {
373 PT(
CullBin) bin = bin_manager->make_new_bin(bin_index, _gsg,
374 _draw_region_pcollector);
377 if (bin_ptr != (
CullBin *)NULL) {
379 while (bin_index >= (
int)_bins.size()) {
380 _bins.push_back((
CullBin *)NULL);
382 nassertr(bin_index >= 0 && bin_index < (
int)_bins.size(), NULL);
385 swap(_bins[bin_index], bin);
403 state = RenderState::make(AlphaTestAttrib::make(AlphaTestAttrib::M_greater, 0.0f));
418 state = RenderState::make(AlphaTestAttrib::make(AlphaTestAttrib::M_greater_equal, 0.5f),
419 TransparencyAttrib::make(TransparencyAttrib::M_none),
435 if ((cycle & 1) == 0) {
436 state = state->remove_attrib(TextureAttrib::get_class_slot());
437 state = state->remove_attrib(LightAttrib::get_class_slot());
438 state = state->remove_attrib(ColorScaleAttrib::get_class_slot());
439 state = state->remove_attrib(FogAttrib::get_class_slot());
440 state = state->add_attrib(ColorAttrib::make_flat(flash_color),
453 get_dual_transparent_state() {
461 state = RenderState::make(AlphaTestAttrib::make(AlphaTestAttrib::M_greater, 0.0f),
462 TransparencyAttrib::make(TransparencyAttrib::M_alpha),
463 DepthWriteAttrib::make(DepthWriteAttrib::M_off),
470 if ((cycle & 1) == 0) {
473 flash_state = state->add_attrib(ColorAttrib::make_flat(
LColor(0.8f, 0.2, 0.2, 1.0f)),
476 flash_state = flash_state->add_attrib(ColorScaleAttrib::make(
LVecBase4(1.0f, 1.0f, 1.0f, 1.0f)),
479 flash_state = flash_state->add_attrib(AlphaTestAttrib::make(AlphaTestAttrib::M_less, 1.0f),
497 get_dual_opaque_state() {
500 state = RenderState::make(AlphaTestAttrib::make(AlphaTestAttrib::M_greater_equal, dual_opaque_level),
501 TransparencyAttrib::make(TransparencyAttrib::M_none),
508 if ((cycle & 1) == 0) {
511 flash_state = state->add_attrib(ColorAttrib::make_flat(
LColor(0.2, 0.2, 0.8f, 1.0f)),
513 flash_state = flash_state->add_attrib(ColorScaleAttrib::make(
LVecBase4(1.0f, 1.0f, 1.0f, 1.0f)),
533 return RenderState::make(
534 DepthOffsetAttrib::make(1, 0, 0.99999f),
535 ColorAttrib::make_flat(rmode->get_wireframe_color()),
536 ColorBlendAttrib::make(ColorBlendAttrib::M_add,
537 ColorBlendAttrib::O_incoming_alpha,
538 ColorBlendAttrib::O_one_minus_incoming_alpha),
539 RenderModeAttrib::make(RenderModeAttrib::M_wireframe,
540 rmode->get_thickness(),
541 rmode->get_perspective()));
int get_num_bins() const
Returns the number of bins in the world.
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
bool get_value() const
Returns the variable's value.
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...
A basic node of the scene graph or data graph.
void add_object(CullableObject *object, const CullTraverser *traverser)
Adds the indicated CullableObject to the appropriate bin.
A collection of Geoms and their associated state, for a particular scene.
static int get_max_priority()
Returns the maximum priority number (sometimes called override) that may be set on any node...
This controls the enabling of transparency.
const string & get_bin_name() const
Returns the name of the bin this attribute specifies.
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() ...
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...
int find_bin(const string &name) const
Returns the bin_index associated with the bin of the given name, or -1 if no bin has that name...
static CullBinManager * get_global_ptr()
Returns the pointer to the global CullBinManager object.
A lightweight class that represents a single element that may be timed and/or counted via stats...
The smallest atom of cull.
CullBin * get_bin(int bin_index)
Returns the CullBin associated with the indicated bin_index, or NULL if the bin_index is invalid...
double get_frame_time(Thread *current_thread=Thread::get_current_thread()) const
Returns the time in seconds as of the last time tick() was called (typically, this will be as of the ...
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 ...
const RenderAttrib * get_attrib(TypeHandle type) const
Looks for a RenderAttrib of the indicated type in the state, and returns it if it is found...
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Mode get_mode() const
Returns the render mode.
Thread * get_current_thread() const
Returns the currently-executing thread object, as passed to the CullTraverser constructor.
Assigns geometry to a particular bin by name.
This is the base class for all three-component vectors and points.
This stores the result of a BinCullHandler traversal: an ordered collection of CullBins, each of which holds a number of Geoms and RenderStates to be rendered in some defined order.
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
Mode get_mode() const
Returns the transparency mode.
bool get_effective_incomplete_render() const
Returns true if the cull traversal is effectively in incomplete_render state, considering both the GS...
A thread; that is, a lightweight process.
int get_bin(int n) const
Returns the bin_index of the nth bin in the set, where n is a number between 0 and get_num_bins()...
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.
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.
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...