DO_DCAST, is_qpgeom()

This commit is contained in:
David Rose 2005-04-27 16:33:59 +00:00
parent 988792a85d
commit 212fbc6c6b
22 changed files with 71 additions and 28 deletions

View File

@ -377,7 +377,7 @@ r_copy_char(PandaNode *dest, const PandaNode *source,
////////////////////////////////////////////////////////////////////
PT(Geom) Character::
copy_geom(const Geom *source, const Character *from) {
if (source->is_of_type(qpGeom::get_class_type())) {
if (source->is_qpgeom()) {
CPT(qpGeom) qpsource = DCAST(qpGeom, source);
CPT(qpGeomVertexFormat) format = qpsource->get_vertex_data()->get_format();
if (format->get_animation().get_animation_type() == qpGeom::AT_none) {

View File

@ -741,7 +741,7 @@ compare_collider_to_geom(CollisionEntry &entry, const Geom *geom,
ci = _colliders.find(entry.get_from_node_path());
nassertv(ci != _colliders.end());
if (geom->is_of_type(qpGeom::get_class_type())) {
if (geom->is_qpgeom()) {
const qpGeom *qpgeom = DCAST(qpGeom, geom);
if (qpgeom->get_primitive_type() == qpGeom::PT_polygons) {
const qpGeomVertexData *data =qpgeom->get_vertex_data();

View File

@ -601,7 +601,7 @@ recompute_geom(Geom *geom, const LMatrix4f &rel_mat) {
const LMatrix3f &to_uv = _invert_uvs ? lens_to_uv_inverted : lens_to_uv;
if (geom->is_of_type(qpGeom::get_class_type())) {
if (geom->is_qpgeom()) {
qpGeom *qpgeom = DCAST(qpGeom, geom);
// Iterate through all the vertices in the Geom.
@ -812,7 +812,7 @@ make_mesh_geom_node(const WorkingNodePath &np, const NodePath &camera,
////////////////////////////////////////////////////////////////////
PT(Geom) ProjectionScreen::
make_mesh_geom(const Geom *geom, Lens *lens, LMatrix4f &rel_mat) {
if (geom->is_of_type(qpGeom::get_class_type())) {
if (geom->is_qpgeom()) {
PT(qpGeom) new_geom = new qpGeom(*DCAST(qpGeom, geom));
qpGeomVertexRewriter vertex(new_geom->modify_vertex_data(),

View File

@ -62,6 +62,14 @@ ConfigVariableDouble egg_flatten_radius
"the user to specify what should be considered \"small\". Set "
"it to 0.0 to disable this feature."));
ConfigVariableBool egg_unify
("egg-unify", true,
PRC_DESC("When this is true, then in addition to flattening the scene graph "
"nodes, the egg loader will also as many Geoms as possible within "
"a given node into a single Geom. This has theoretical performance "
"benefits, especially on higher-end graphics cards, but it also "
"slightly slows down egg loading."));
ConfigVariableBool egg_combine_geoms
("egg-combine-geoms", false,
PRC_DESC("Set this true to combine sibling GeomNodes into a single GeomNode, "

View File

@ -41,6 +41,7 @@ extern EXPCL_PANDAEGG ConfigVariableBool egg_ignore_filters;
extern EXPCL_PANDAEGG ConfigVariableBool egg_ignore_clamp;
extern EXPCL_PANDAEGG ConfigVariableBool egg_ignore_decals;
extern EXPCL_PANDAEGG ConfigVariableBool egg_flatten;
extern EXPCL_PANDAEGG ConfigVariableBool egg_unify;
extern EXPCL_PANDAEGG ConfigVariableDouble egg_flatten_radius;
extern EXPCL_PANDAEGG ConfigVariableBool egg_combine_geoms;
extern EXPCL_PANDAEGG ConfigVariableBool egg_show_collision_solids;

View File

@ -48,9 +48,14 @@ load_from_loader(EggLoader &loader) {
}
int num_reduced = gr.flatten(loader._root, combine_siblings_bits);
// gr.collect_vertex_data(loader._root);
// gr.unify(loader._root);
egg2pg_cat.info() << "Flattened " << num_reduced << " nodes.\n";
if (egg_unify) {
gr.collect_vertex_data(loader._root);
gr.unify(loader._root);
if (egg2pg_cat.is_debug()) {
egg2pg_cat.debug() << "Unified.\n";
}
}
}
return loader._root;

View File

@ -54,7 +54,7 @@ _dcast_get_typehandle(WantType *) {
template<class WantType>
INLINE WantType *
_dcast(WantType *, TypedObject *ptr) {
#ifndef NDEBUG
#ifdef DO_DCAST
TypeHandle want_handle = _dcast_get_typehandle((WantType *)0);
if (!_dcast_verify(want_handle, sizeof(WantType), ptr)) {
return (WantType *)NULL;
@ -75,7 +75,7 @@ _dcast(WantType *, TypedObject *ptr) {
template<class WantType>
INLINE const WantType *
_dcast(WantType *, const TypedObject *ptr) {
#ifndef NDEBUG
#ifdef DO_DCAST
TypeHandle want_handle = _dcast_get_typehandle((WantType *)0);
if (!_dcast_verify(want_handle, sizeof(WantType), ptr)) {
return (const WantType *)NULL;

View File

@ -24,7 +24,7 @@
#endif
#ifndef NDEBUG
#ifdef DO_DCAST
////////////////////////////////////////////////////////////////////
// Function: _dcast_verify
// Description: This function performs the actual check that the
@ -67,5 +67,6 @@ _dcast_verify(TypeHandle want_handle, size_t want_size,
return true;
}
#endif // NDEBUG
#endif // DO_DCAST

View File

@ -68,12 +68,12 @@ INLINE WantType *_dcast_ref(WantType *&, TypedObject *ptr);
template<class WantType>
INLINE const WantType *_dcast_ref(WantType *&, const TypedObject *ptr);
#ifndef NDEBUG
#ifdef DO_DCAST
// _dcast_verify performs the actual verification.
EXPCL_PANDAEXPRESS bool
_dcast_verify(TypeHandle want_handle, size_t want_size,
const TypedObject *ptr);
#endif // NDEBUG
#endif // DO_DCAST
#define DCAST_INTO_V(to_pointer, from_pointer) \
{ \

View File

@ -2846,7 +2846,7 @@ GeomContext *CLP(GraphicsStateGuardian)::
prepare_geom(Geom *geom) {
// Temporary test until the experimental Geom rewrite becomes the
// actual Geom implementation.
if (geom->is_of_type(qpGeom::get_class_type())) {
if (geom->is_qpgeom()) {
CLP(GeomContext) *ggc = new CLP(GeomContext)(geom);
return ggc;

View File

@ -567,6 +567,18 @@ is_dynamic() const {
return (_vindex != (ushort*)0L);
}
////////////////////////////////////////////////////////////////////
// Function: Geom::is_qpgeom
// Access: Published, Virtual
// Description: Returns true if this is a new-style qpGeom class,
// false otherwise. Temporary until the experimental
// Geom rewrite becomes the actual Geom implementation.
////////////////////////////////////////////////////////////////////
bool Geom::
is_qpgeom() const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: Geom::prepare
// Access: Published

View File

@ -171,6 +171,9 @@ public:
PUBLISHED:
virtual bool is_dynamic() const;
// Temporary.
virtual bool is_qpgeom() const;
INLINE GeomBindType get_binding(int attr) const;
INLINE bool has_any_texcoords() const;
INLINE bool has_texcoords(const InternalName *name) const;

View File

@ -105,6 +105,18 @@ make_copy() const {
return new qpGeom(*this);
}
////////////////////////////////////////////////////////////////////
// Function: qpGeom::is_qpgeom
// Access: Published, Virtual
// Description: Returns true if this is a new-style qpGeom class,
// false otherwise. Temporary until the experimental
// Geom rewrite becomes the actual Geom implementation.
////////////////////////////////////////////////////////////////////
bool qpGeom::
is_qpgeom() const {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: qpGeom::set_usage_hint
// Access: Published

View File

@ -66,6 +66,7 @@ PUBLISHED:
// Temporary.
virtual Geom *make_copy() const;
virtual bool is_qpgeom() const;
INLINE PrimitiveType get_primitive_type() const;
INLINE ShadeModel get_shade_model() const;

View File

@ -809,7 +809,7 @@ transfer_geom(GeomNode *geom_node, const InternalName *texcoord_name,
const GeomInfo &geom_info = (*gi);
const Geom *orig_geom = geom_info._geom_node->get_geom(geom_info._index);
if (orig_geom->is_of_type(qpGeom::get_class_type())) {
if (orig_geom->is_qpgeom()) {
PT(qpGeom) geom = new qpGeom(*DCAST(qpGeom, orig_geom));
PT(qpGeomVertexData) vdata = geom->modify_vertex_data();
vdata->set_usage_hint(qpGeom::UH_stream);

View File

@ -147,7 +147,7 @@ set_from_node(const NodePath &node_path, bool size_from_texels) {
TexCoordf min_uv, max_uv;
Vertexf min_xyz, max_xyz;
if (geom->is_of_type(qpGeom::get_class_type())) {
if (geom->is_qpgeom()) {
const qpGeom *qpgeom = DCAST(qpGeom, geom);
qpGeomVertexReader texcoord(qpgeom->get_vertex_data());
qpGeomVertexReader vertex(qpgeom->get_vertex_data());

View File

@ -46,7 +46,7 @@ munge_geom(GraphicsStateGuardianBase *gsg,
if (_geom != (Geom *)NULL) {
// Temporary test and dcast until the experimental Geom rewrite
// becomes the actual Geom rewrite.
if (_geom->is_of_type(qpGeom::get_class_type())) {
if (_geom->is_qpgeom()) {
_munger = munger;
CPT(qpGeom) qpgeom = DCAST(qpGeom, _geom);
_munged_data = qpgeom->get_vertex_data();

View File

@ -354,7 +354,7 @@ calc_tight_bounds(LPoint3f &min_point, LPoint3f &max_point, bool &found_any,
const Geom *geom = get_geom(i);
// Temporary test until the experimental Geom rewrite is final.
if (geom->is_of_type(qpGeom::get_class_type())) {
if (geom->is_qpgeom()) {
const qpGeom *qpgeom = DCAST(qpGeom, geom);
qpgeom->calc_tight_bounds(min_point, max_point, found_any,
qpgeom->get_vertex_data()->animate_vertices(),
@ -481,11 +481,11 @@ unify() {
const GeomEntry &entry = (*gi);
bool unified = false;
if (entry._geom->is_of_type(qpGeom::get_class_type())) {
if (entry._geom->is_qpgeom()) {
Geoms::iterator gj;
for (gj = new_geoms.begin(); gj != new_geoms.end() && !unified; ++gj) {
GeomEntry &new_entry = (*gj);
if (new_entry._geom->is_of_type(qpGeom::get_class_type())) {
if (new_entry._geom->is_qpgeom()) {
if (entry._state == new_entry._state) {
// Both states match, so try to combine the primitives.
if (DCAST(qpGeom, new_entry._geom)->copy_primitives_from
@ -512,7 +512,7 @@ unify() {
// Finally, go back through and unify the resulting geom(s).
for (gi = cdata->_geoms.begin(); gi != cdata->_geoms.end(); ++gi) {
const GeomEntry &entry = (*gi);
if (entry._geom->is_of_type(qpGeom::get_class_type())) {
if (entry._geom->is_qpgeom()) {
DCAST(qpGeom, entry._geom)->unify_in_place();
}
}

View File

@ -71,7 +71,7 @@ transform_vertices(Geom *geom, const LMatrix4f &mat) {
nassertr(geom != (Geom *)NULL, false);
if (geom->is_of_type(qpGeom::get_class_type())) {
if (geom->is_qpgeom()) {
qpGeom *qpgeom = DCAST(qpGeom, geom);
qpSourceVertices sv;
@ -212,7 +212,7 @@ transform_texcoords(Geom *geom, const InternalName *from_name,
bool transformed = false;
nassertr(geom != (Geom *)NULL, false);
if (geom->is_of_type(qpGeom::get_class_type())) {
if (geom->is_qpgeom()) {
qpGeom *qpgeom = DCAST(qpGeom, geom);
qpSourceTexCoords st;
@ -331,7 +331,7 @@ bool GeomTransformer::
set_color(Geom *geom, const Colorf &color) {
bool transformed = false;
if (geom->is_of_type(qpGeom::get_class_type())) {
if (geom->is_qpgeom()) {
qpGeom *qpgeom = DCAST(qpGeom, geom);
qpSourceColors sc;
@ -411,7 +411,7 @@ transform_colors(Geom *geom, const LVecBase4f &scale) {
nassertr(geom != (Geom *)NULL, false);
if (geom->is_of_type(qpGeom::get_class_type())) {
if (geom->is_qpgeom()) {
qpGeom *qpgeom = DCAST(qpGeom, geom);
qpSourceColors sc;
@ -763,7 +763,7 @@ collect_vertex_data(GeomNode *node, int collect_bits) {
GeomNode::Geoms::iterator gi;
for (gi = cdata->_geoms.begin(); gi != cdata->_geoms.end(); ++gi) {
GeomNode::GeomEntry &entry = (*gi);
if (entry._geom->is_of_type(qpGeom::get_class_type())) {
if (entry._geom->is_qpgeom()) {
PT(qpGeom) new_geom = DCAST(qpGeom, entry._geom->make_copy());
entry._geom = new_geom;

View File

@ -684,7 +684,7 @@ r_make_nonindexed(PandaNode *node, int nonindexed_bits) {
GeomNode *geom_node = DCAST(GeomNode, node);
int num_geoms = geom_node->get_num_geoms();
for (int i = 0; i < num_geoms; ++i) {
if (geom_node->get_geom(i)->is_of_type(qpGeom::get_class_type())) {
if (geom_node->get_geom(i)->is_qpgeom()) {
const qpGeom *geom = DCAST(qpGeom, geom_node->get_geom(i));
// Check whether the geom is animated or dynamic, and skip it

View File

@ -196,7 +196,7 @@ find_character_gsets(PandaNode *root, CPT(Geom) &ch,
for (int i = 0; i < geode->get_num_geoms(); i++) {
const Geom *geom = geode->get_geom(i);
if (geom->is_of_type(qpGeom::get_class_type())) {
if (geom->is_qpgeom()) {
CPT(qpGeom) qpgeom = DCAST(qpGeom, geom);
bool found_points = false;

View File

@ -83,7 +83,7 @@ get_geom(qpGeom::UsageHint usage_hint) const {
// it is also critical for the DynamicTextGlyph, which depends on
// this behavior to properly count references to this glyph.
PT(Geom) new_geom = _geom->make_copy();
if (new_geom->is_of_type(qpGeom::get_class_type())) {
if (new_geom->is_qpgeom()) {
qpGeom *qpgeom = DCAST(qpGeom, new_geom);
qpgeom->set_usage_hint(usage_hint);
if (qpgeom->get_vertex_data()->get_usage_hint() != usage_hint) {