From ae9d219d770a3168fb2e293a74d82df06038dc8b Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 3 Jun 2005 22:43:46 +0000 Subject: [PATCH] fix particles some more --- .../glstuff/glGraphicsStateGuardian_src.cxx | 82 +++++++++++++++---- panda/src/particlesystem/particleSystem.I | 11 ++- .../particlesystem/spriteParticleRenderer.cxx | 80 ++++++++++++------ panda/src/testbed/pview.cxx | 4 +- 4 files changed, 128 insertions(+), 49 deletions(-) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 6e24062ba0..f12ea97fb2 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -2194,6 +2194,12 @@ draw_sphere(GeomSphere *geom, GeomContext *gc) { bool CLP(GraphicsStateGuardian):: begin_draw_primitives(const qpGeom *geom, const qpGeomMunger *munger, const qpGeomVertexData *vertex_data) { +#ifndef NDEBUG + if (GLCAT.is_spam()) { + GLCAT.spam() << "begin_draw_primitives: " << *vertex_data << "\n"; + } +#endif // NDEBUG + if (!GraphicsStateGuardian::begin_draw_primitives(geom, munger, vertex_data)) { return false; } @@ -2514,6 +2520,12 @@ begin_draw_primitives(const qpGeom *geom, const qpGeomMunger *munger, //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: draw_triangles(const qpGeomTriangles *primitive) { +#ifndef NDEBUG + if (GLCAT.is_spam()) { + GLCAT.spam() << "draw_triangles: " << *primitive << "\n"; + } +#endif // NDEBUG + _vertices_tri_pcollector.add_level(primitive->get_num_vertices()); _primitive_batches_tri_pcollector.add_level(1); @@ -2542,6 +2554,12 @@ draw_triangles(const qpGeomTriangles *primitive) { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: draw_tristrips(const qpGeomTristrips *primitive) { +#ifndef NDEBUG + if (GLCAT.is_spam()) { + GLCAT.spam() << "draw_tristrips: " << *primitive << "\n"; + } +#endif // NDEBUG + if (connect_triangle_strips && _render_mode != RenderModeAttrib::M_wireframe) { // One long triangle strip, connected by the degenerate vertices // that have already been set up within the primitive. @@ -2607,6 +2625,12 @@ draw_tristrips(const qpGeomTristrips *primitive) { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: draw_trifans(const qpGeomTrifans *primitive) { +#ifndef NDEBUG + if (GLCAT.is_spam()) { + GLCAT.spam() << "draw_trifans: " << *primitive << "\n"; + } +#endif // NDEBUG + // Send the individual triangle fans. There's no connecting fans // with degenerate vertices, so no worries about that. CPTA_int ends = primitive->get_ends(); @@ -2650,6 +2674,12 @@ draw_trifans(const qpGeomTrifans *primitive) { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: draw_lines(const qpGeomLines *primitive) { +#ifndef NDEBUG + if (GLCAT.is_spam()) { + GLCAT.spam() << "draw_lines: " << *primitive << "\n"; + } +#endif // NDEBUG + _vertices_other_pcollector.add_level(primitive->get_num_vertices()); _primitive_batches_other_pcollector.add_level(1); @@ -2677,6 +2707,12 @@ draw_lines(const qpGeomLines *primitive) { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: draw_linestrips(const qpGeomLinestrips *primitive) { +#ifndef NDEBUG + if (GLCAT.is_spam()) { + GLCAT.spam() << "draw_linestrips: " << *primitive << "\n"; + } +#endif // NDEBUG + } //////////////////////////////////////////////////////////////////// @@ -2686,6 +2722,12 @@ draw_linestrips(const qpGeomLinestrips *primitive) { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: draw_points(const qpGeomPoints *primitive) { +#ifndef NDEBUG + if (GLCAT.is_spam()) { + GLCAT.spam() << "draw_points: " << *primitive << "\n"; + } +#endif // NDEBUG + _vertices_other_pcollector.add_level(primitive->get_num_vertices()); _primitive_batches_other_pcollector.add_level(1); @@ -2976,16 +3018,18 @@ apply_vertex_buffer(VertexBufferContext *vbc) { << "copying " << num_bytes << " bytes into vertex buffer " << gvbc->_index << "\n"; } - if (gvbc->changed_size() || gvbc->changed_usage_hint()) { - _glBufferData(GL_ARRAY_BUFFER, num_bytes, - gvbc->get_data()->get_data(), - get_usage(gvbc->get_data()->get_usage_hint())); - - } else { - _glBufferSubData(GL_ARRAY_BUFFER, 0, num_bytes, - gvbc->get_data()->get_data()); + if (num_bytes != 0) { + if (gvbc->changed_size() || gvbc->changed_usage_hint()) { + _glBufferData(GL_ARRAY_BUFFER, num_bytes, + gvbc->get_data()->get_data(), + get_usage(gvbc->get_data()->get_usage_hint())); + + } else { + _glBufferSubData(GL_ARRAY_BUFFER, 0, num_bytes, + gvbc->get_data()->get_data()); + } + _data_transferred_pcollector.add_level(num_bytes); } - _data_transferred_pcollector.add_level(num_bytes); add_to_total_buffer_record(gvbc); gvbc->mark_loaded(); } @@ -3119,16 +3163,18 @@ apply_index_buffer(IndexBufferContext *ibc) { << "copying " << num_bytes << " bytes into index buffer " << gibc->_index << "\n"; } - if (gibc->changed_size() || gibc->changed_usage_hint()) { - _glBufferData(GL_ELEMENT_ARRAY_BUFFER, num_bytes, - gibc->get_data()->get_data(), - get_usage(gibc->get_data()->get_usage_hint())); - - } else { - _glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, num_bytes, - gibc->get_data()->get_data()); + if (num_bytes != 0) { + if (gibc->changed_size() || gibc->changed_usage_hint()) { + _glBufferData(GL_ELEMENT_ARRAY_BUFFER, num_bytes, + gibc->get_data()->get_data(), + get_usage(gibc->get_data()->get_usage_hint())); + + } else { + _glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, num_bytes, + gibc->get_data()->get_data()); + } + _data_transferred_pcollector.add_level(num_bytes); } - _data_transferred_pcollector.add_level(num_bytes); add_to_total_buffer_record(gibc); gibc->mark_loaded(); } diff --git a/panda/src/particlesystem/particleSystem.I b/panda/src/particlesystem/particleSystem.I index 5db069090f..8f40950b26 100644 --- a/panda/src/particlesystem/particleSystem.I +++ b/panda/src/particlesystem/particleSystem.I @@ -51,19 +51,18 @@ induce_labor() { INLINE void ParticleSystem:: clear_to_initial() { BaseParticle *bp; - int index; int i; //int particle_pool_size = _particle_pool_size; //resize_pool(0); //resize_pool(particle_pool_size); - for(i = 0; i < _physics_objects.size(); i++) - { - bp = (BaseParticle *)_physics_objects[i].p(); - if(bp->get_alive()) - kill_particle(i); + for(i = 0; i < (int)_physics_objects.size(); i++) { + bp = (BaseParticle *)_physics_objects[i].p(); + if(bp->get_alive()) { + kill_particle(i); } + } } //// /////////////////////////////////////////////////////// diff --git a/panda/src/particlesystem/spriteParticleRenderer.cxx b/panda/src/particlesystem/spriteParticleRenderer.cxx index 4aba06fd74..cae0d29603 100644 --- a/panda/src/particlesystem/spriteParticleRenderer.cxx +++ b/panda/src/particlesystem/spriteParticleRenderer.cxx @@ -41,11 +41,15 @@ SpriteParticleRenderer(Texture *tex) : _color(Colorf(1.0f, 1.0f, 1.0f, 1.0f)), _ll_uv(0.0f, 0.0f), _ur_uv(1.0f, 1.0f), + _height(1.0f), + _width(1.0f), _initial_x_scale(0.02f), _final_x_scale(0.02f), _initial_y_scale(0.02f), _final_y_scale(0.02f), _theta(0.0f), + _base_y_scale(1.0f), + _aspect_ratio(1.0f), _animate_x_ratio(false), _animate_y_ratio(false), _animate_theta(false), @@ -144,36 +148,57 @@ set_from_node(const NodePath &node_path, bool size_from_texels) { nassertv(gnode->get_num_geoms() > 0); const Geom *geom = gnode->get_geom(0); - TexCoordf min_uv, max_uv; - Vertexf min_xyz, max_xyz; + bool got_texcoord = false; + TexCoordf min_uv(0.0f, 0.0f); + TexCoordf max_uv(0.0f, 0.0f); + + bool got_vertex = false; + Vertexf min_xyz(0.0f, 0.0f, 0.0f); + Vertexf max_xyz(0.0f, 0.0f, 0.0f); if (geom->is_qpgeom()) { const qpGeom *qpgeom = DCAST(qpGeom, geom); - qpGeomVertexReader texcoord(qpgeom->get_vertex_data()); - qpGeomVertexReader vertex(qpgeom->get_vertex_data()); - - if (texcoord.has_column() && vertex.has_column()) { - bool found_any = false; + qpGeomVertexReader texcoord(qpgeom->get_vertex_data(), + InternalName::get_texcoord()); + if (texcoord.has_column()) { for (int pi = 0; pi < qpgeom->get_num_primitives(); ++pi) { const qpGeomPrimitive *primitive = qpgeom->get_primitive(pi); for (int vi = 0; vi < primitive->get_num_vertices(); ++vi) { int vert = primitive->get_vertex(vi); texcoord.set_row(vert); - vertex.set_row(vert); - if (!found_any) { + if (!got_texcoord) { min_uv = max_uv = texcoord.get_data2f(); - min_xyz = max_xyz = vertex.get_data3f(); + got_texcoord = true; } else { const LVecBase2f &uv = texcoord.get_data2f(); - const LVecBase3f &xyz = vertex.get_data3f(); min_uv[0] = min(min_uv[0], uv[0]); max_uv[0] = max(max_uv[0], uv[0]); min_uv[1] = min(min_uv[1], uv[1]); max_uv[1] = max(max_uv[1], uv[1]); + } + } + } + } + + qpGeomVertexReader vertex(qpgeom->get_vertex_data(), + InternalName::get_vertex()); + if (vertex.has_column()) { + for (int pi = 0; pi < qpgeom->get_num_primitives(); ++pi) { + const qpGeomPrimitive *primitive = qpgeom->get_primitive(pi); + for (int vi = 0; vi < primitive->get_num_vertices(); ++vi) { + int vert = primitive->get_vertex(vi); + vertex.set_row(vert); + + if (!got_vertex) { + min_xyz = max_xyz = vertex.get_data3f(); + got_vertex = true; + } else { + const LVecBase3f &xyz = vertex.get_data3f(); + min_xyz[0] = min(min_xyz[0], xyz[0]); max_xyz[0] = max(max_xyz[0], xyz[0]); min_xyz[1] = min(min_xyz[1], xyz[1]); @@ -202,6 +227,9 @@ set_from_node(const NodePath &node_path, bool size_from_texels) { << geom_node_path << " has no vertices in its first Geom.\n"; return; } + + got_texcoord = true; + got_vertex = true; Geom::TexCoordIterator ti = geom->make_texcoord_iterator(); Geom::VertexIterator vi = geom->make_vertex_iterator(); @@ -238,20 +266,26 @@ set_from_node(const NodePath &node_path, bool size_from_texels) { set_ll_uv(min_uv); set_ur_uv(max_uv); - float width = max_xyz[0] - min_xyz[0]; - float height = max(max_xyz[1] - min_xyz[1], - max_xyz[2] - min_xyz[2]); - - if (size_from_texels) { - // If size_from_texels is true, we get the particle size from the - // number of texels in the source image. - float y_texels = _texture->get_y_size() * fabs(_ur_uv[1] - _ll_uv[1]); - set_size(y_texels * width / height, y_texels); + if (got_vertex) { + float width = max_xyz[0] - min_xyz[0]; + float height = max(max_xyz[1] - min_xyz[1], + max_xyz[2] - min_xyz[2]); + + if (size_from_texels && got_texcoord) { + // If size_from_texels is true, we get the particle size from the + // number of texels in the source image. + float y_texels = _texture->get_y_size() * fabs(_ur_uv[1] - _ll_uv[1]); + set_size(y_texels * width / height, y_texels); + + } else { + // If size_from_texels is false, we get the particle size from + // the size of the polygon. + set_size(width, height); + } } else { - // If size_from_texels is false, we get the particle size from - // the size of the polygon. - set_size(width, height); + // With no vertices, just punt. + set_size(1.0f, 1.0f); } _source_type = ST_from_node; diff --git a/panda/src/testbed/pview.cxx b/panda/src/testbed/pview.cxx index 42ace008fc..a7e0135085 100644 --- a/panda/src/testbed/pview.cxx +++ b/panda/src/testbed/pview.cxx @@ -138,12 +138,13 @@ void event_0(CPT_Event event, void *) { // 0: run hacky test. + /* SceneGraphReducer gr; gr.collect_vertex_data(framework.get_models().node()); gr.unify(framework.get_models().node()); gr.make_nonindexed(framework.get_models().node()); + */ - /* static int count = 0; static PT(TextureStage) ts; @@ -189,7 +190,6 @@ event_0(CPT_Event event, void *) { } } count++; - */ } void