From e01cb59d068d2489cf51d94ba5eb5b4a6d7982e2 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 22 Mar 2002 18:16:13 +0000 Subject: [PATCH] move sprites into pgraph land --- panda/src/display/graphicsStateGuardian.cxx | 1 + panda/src/glgsg/glGraphicsStateGuardian.cxx | 57 +++++++------------ .../particlesystem/lineParticleRenderer.cxx | 3 +- .../particlesystem/pointParticleRenderer.cxx | 3 +- .../sparkleParticleRenderer.cxx | 3 +- .../particlesystem/spriteParticleRenderer.cxx | 3 +- panda/src/pgraph/renderState.I | 19 +++++++ panda/src/pgraph/renderState.cxx | 17 ++++++ panda/src/pgraph/renderState.h | 5 ++ 9 files changed, 71 insertions(+), 40 deletions(-) diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 86cab71a97..e2b2556689 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -126,6 +126,7 @@ reset() { _state.clear(); _qpstate = RenderState::make_empty(); + _transform = TransformState::make_identity(); _buffer_mask = 0; _color_clear_value.set(gsg_clear_r, gsg_clear_g, gsg_clear_b, 0.0); diff --git a/panda/src/glgsg/glGraphicsStateGuardian.cxx b/panda/src/glgsg/glGraphicsStateGuardian.cxx index b2928d7862..ae682648f0 100644 --- a/panda/src/glgsg/glGraphicsStateGuardian.cxx +++ b/panda/src/glgsg/glGraphicsStateGuardian.cxx @@ -982,7 +982,6 @@ draw_sprite(GeomSprite *geom, GeomContext *) { // will certainly look close enough. Then, we transform to camera-space // by hand and apply the inverse frustum to the transformed point. // For some cracked out reason, this actually works. - #ifdef GSG_VERBOSE glgsg_cat.debug() << "draw_sprite()" << endl; #endif @@ -1009,31 +1008,16 @@ draw_sprite(GeomSprite *geom, GeomContext *) { Texture *tex = geom->get_texture(); if(tex != NULL) { - // set up the texture-rendering state - NodeTransitions state; - - TextureTransition *ta = new TextureTransition; - ta->set_on(tex); - state.set_transition(ta); - - TextureApplyTransition *taa = new TextureApplyTransition; - taa->set_mode(TextureApplyProperty::M_modulate); - state.set_transition(taa); - - modify_state(state); - - tex_xsize = tex->_pbuffer->get_xsize(); - tex_ysize = tex->_pbuffer->get_ysize(); + // set up the texture-rendering state + modify_state(RenderState::make + (TextureAttrib::make(tex), + TextureApplyAttrib::make(TextureApplyAttrib::M_modulate))); + tex_xsize = tex->_pbuffer->get_xsize(); + tex_ysize = tex->_pbuffer->get_ysize(); } // save the modelview matrix - LMatrix4f modelview_mat; - - const TransformTransition *ctatt; - if (!get_attribute_into(ctatt, this)) - modelview_mat = LMatrix4f::ident_mat(); - else - modelview_mat = ctatt->get_matrix(); + const LMatrix4f &modelview_mat = _transform->get_mat(); // get the camera information @@ -1064,11 +1048,12 @@ draw_sprite(GeomSprite *geom, GeomContext *) { // the user can override alpha sorting if they want bool alpha = false; - if (geom->get_alpha_disable() == false) { + if (!geom->get_alpha_disable()) { // figure out if alpha's enabled (if not, no reason to sort) - const TransparencyTransition *ctratt; - if (get_attribute_into(ctratt, this)) - alpha = (ctratt->get_mode() != TransparencyProperty::M_none); + const TransparencyAttrib *trans = _qpstate->get_transparency(); + if (trans != (const TransparencyAttrib *)NULL) { + alpha = (trans->get_mode() != TransparencyAttrib::M_none); + } } // sort container and iterator @@ -1094,7 +1079,7 @@ draw_sprite(GeomSprite *geom, GeomContext *) { bool theta_on = !(geom->get_theta_bind_type() == G_OFF); // x direction - if (x_overall == true) + if (x_overall) scaled_width = geom->_x_texel_ratio[0] * half_width; else { nassertv(((int)geom->_x_texel_ratio.size() >= geom->get_num_prims())); @@ -1102,7 +1087,7 @@ draw_sprite(GeomSprite *geom, GeomContext *) { } // y direction - if (y_overall == true) + if (y_overall) scaled_height = geom->_y_texel_ratio[0] * half_height * aspect_ratio; else { nassertv(((int)geom->_y_texel_ratio.size() >= geom->get_num_prims())); @@ -1111,7 +1096,7 @@ draw_sprite(GeomSprite *geom, GeomContext *) { // theta if (theta_on) { - if (theta_overall == true) + if (theta_overall) theta = geom->_theta[0]; else { nassertv(((int)geom->_theta.size() >= geom->get_num_prims())); @@ -1138,14 +1123,14 @@ draw_sprite(GeomSprite *geom, GeomContext *) { // build the final object that will go into the vector. ws._v.set(cameraspace_vert[0],cameraspace_vert[1],cameraspace_vert[2]); - if (color_overall == false) + if (!color_overall) ws._c = geom->get_next_color(ci); - if (x_overall == false) + if (!x_overall) ws._x_ratio = *x_walk++; - if (y_overall == false) + if (!y_overall) ws._y_ratio = *y_walk++; if (theta_on) { - if (theta_overall == false) + if (!theta_overall) ws._theta = *theta_walk++; } @@ -1160,13 +1145,13 @@ draw_sprite(GeomSprite *geom, GeomContext *) { sort(cameraspace_vector.begin(), cameraspace_vector.end(), draw_sprite_vertex_less()); - if(_dithering_enabled) + if (_dithering_enabled) glDisable(GL_DITHER); } Vertexf ul, ur, ll, lr; - if (color_overall == true) + if (color_overall) glColor4fv(geom->get_next_color(ci).get_data()); //////////////////////////////////////////////////////////////////////////// diff --git a/panda/src/particlesystem/lineParticleRenderer.cxx b/panda/src/particlesystem/lineParticleRenderer.cxx index 1e1fb9dfd0..a4e0834544 100644 --- a/panda/src/particlesystem/lineParticleRenderer.cxx +++ b/panda/src/particlesystem/lineParticleRenderer.cxx @@ -238,5 +238,6 @@ render(pvector< PT(PhysicsObject) >& po_vector, int ttl_particles) { LPoint3f aabb_center = (_aabb_min + _aabb_max) * 0.5f; float radius = (aabb_center - _aabb_min).length(); - get_render_node()->set_bound(BoundingSphere(aabb_center, radius)); + _line_primitive->set_bound(BoundingSphere(aabb_center, radius)); + get_render_node()->mark_bound_stale(); } diff --git a/panda/src/particlesystem/pointParticleRenderer.cxx b/panda/src/particlesystem/pointParticleRenderer.cxx index 40dfca2069..be56e9bb4b 100644 --- a/panda/src/particlesystem/pointParticleRenderer.cxx +++ b/panda/src/particlesystem/pointParticleRenderer.cxx @@ -278,5 +278,6 @@ render(pvector< PT(PhysicsObject) >& po_vector, int ttl_particles) { LPoint3f aabb_center = _aabb_min + ((_aabb_max - _aabb_min) * 0.5f); float radius = (aabb_center - _aabb_min).length(); - get_render_node()->set_bound(BoundingSphere(aabb_center, radius)); + _point_primitive->set_bound(BoundingSphere(aabb_center, radius)); + get_render_node()->mark_bound_stale(); } diff --git a/panda/src/particlesystem/sparkleParticleRenderer.cxx b/panda/src/particlesystem/sparkleParticleRenderer.cxx index 8e391d4bae..aae2ad7903 100644 --- a/panda/src/particlesystem/sparkleParticleRenderer.cxx +++ b/panda/src/particlesystem/sparkleParticleRenderer.cxx @@ -268,5 +268,6 @@ render(pvector< PT(PhysicsObject) >& po_vector, int ttl_particles) { LPoint3f aabb_center = _aabb_min + ((_aabb_max - _aabb_min) * 0.5f); float radius = (aabb_center - _aabb_min).length(); - get_render_node()->set_bound(BoundingSphere(aabb_center, radius)); + _line_primitive->set_bound(BoundingSphere(aabb_center, radius)); + get_render_node()->mark_bound_stale(); } diff --git a/panda/src/particlesystem/spriteParticleRenderer.cxx b/panda/src/particlesystem/spriteParticleRenderer.cxx index a4a0d67a01..931ee68326 100644 --- a/panda/src/particlesystem/spriteParticleRenderer.cxx +++ b/panda/src/particlesystem/spriteParticleRenderer.cxx @@ -374,5 +374,6 @@ render(pvector< PT(PhysicsObject) >& po_vector, int ttl_particles) { LPoint3f aabb_center = _aabb_min + ((_aabb_max - _aabb_min) * 0.5f); float radius = (aabb_center - _aabb_min).length(); - get_render_node()->set_bound(BoundingSphere(aabb_center, radius)); + _sprite_primitive->set_bound(BoundingSphere(aabb_center, radius)); + get_render_node()->mark_bound_stale(); } diff --git a/panda/src/pgraph/renderState.I b/panda/src/pgraph/renderState.I index 39f486820f..57edd14e49 100644 --- a/panda/src/pgraph/renderState.I +++ b/panda/src/pgraph/renderState.I @@ -216,3 +216,22 @@ get_fog() const { } return _fog; } + +//////////////////////////////////////////////////////////////////// +// Function: RenderState::get_transparency +// Access: Public +// Description: This function is provided as an optimization, to +// speed up the render-time checking for the existance +// of a TransparencyAttrib on this state. It returns a +// pointer to the TransparencyAttrib, if there is one, +// or NULL if there is not. +//////////////////////////////////////////////////////////////////// +INLINE const TransparencyAttrib *RenderState:: +get_transparency() const { + if ((_flags & F_checked_transparency) == 0) { + // We pretend this function is const, even though it transparently + // modifies the internal transparency cache. + ((RenderState *)this)->determine_transparency(); + } + return _transparency; +} diff --git a/panda/src/pgraph/renderState.cxx b/panda/src/pgraph/renderState.cxx index acf70f633d..d226ff069d 100644 --- a/panda/src/pgraph/renderState.cxx +++ b/panda/src/pgraph/renderState.cxx @@ -21,6 +21,7 @@ #include "cullBinAttrib.h" #include "cullBinManager.h" #include "fogAttrib.h" +#include "transparencyAttrib.h" #include "config_pgraph.h" #include "bamReader.h" #include "bamWriter.h" @@ -943,6 +944,22 @@ determine_fog() { _flags |= F_checked_fog; } +//////////////////////////////////////////////////////////////////// +// Function: RenderState::determine_transparency +// Access: Private +// Description: This is the private implementation of get_transparency(). +//////////////////////////////////////////////////////////////////// +void RenderState:: +determine_transparency() { + const RenderAttrib *attrib = + get_attrib(TransparencyAttrib::get_class_type()); + _transparency = (const TransparencyAttrib *)NULL; + if (attrib != (const RenderAttrib *)NULL) { + _transparency = DCAST(TransparencyAttrib, attrib); + } + _flags |= F_checked_transparency; +} + //////////////////////////////////////////////////////////////////// // Function: RenderState::register_with_read_factory // Access: Public, Static diff --git a/panda/src/pgraph/renderState.h b/panda/src/pgraph/renderState.h index 9a9f0f59ac..5609e27ba2 100644 --- a/panda/src/pgraph/renderState.h +++ b/panda/src/pgraph/renderState.h @@ -29,6 +29,7 @@ class GraphicsStateGuardianBase; class FogAttrib; +class TransparencyAttrib; //////////////////////////////////////////////////////////////////// // Class : RenderState @@ -92,6 +93,7 @@ public: INLINE int get_bin_index() const; INLINE int get_draw_order() const; INLINE const FogAttrib *get_fog() const; + INLINE const TransparencyAttrib *get_transparency() const; CPT(RenderState) issue_delta_modify(const RenderState *other, GraphicsStateGuardianBase *gsg) const; @@ -106,6 +108,7 @@ private: CPT(RenderState) do_invert_compose(const RenderState *other) const; void determine_bin_index(); void determine_fog(); + void determine_transparency(); private: typedef pset > States; @@ -167,10 +170,12 @@ private: // We also cache the pointer to some critical attribs stored in the // state, if they exist. const FogAttrib *_fog; + const TransparencyAttrib *_transparency; enum Flags { F_checked_bin_index = 0x0001, F_checked_fog = 0x0002, + F_checked_transparency = 0x0004, }; short _flags;