mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
support dynamic geoms properly with display lists
This commit is contained in:
parent
0f5c46313c
commit
ad9a03da5c
@ -17,6 +17,30 @@
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: CLP(GraphicsStateGuardian)::draw_display_list
|
||||||
|
// Access: Public
|
||||||
|
// Description: If the GeomContext is non-NULL and contains a valid
|
||||||
|
// display list, uses it to draw the geometry if
|
||||||
|
// appropriate, and returns true. If the display list
|
||||||
|
// is absent or cannot be used for some reason, does
|
||||||
|
// nothing and returns false.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE bool CLP(GraphicsStateGuardian)::
|
||||||
|
draw_display_list(GeomContext *gc) {
|
||||||
|
if (gc != (GeomContext *)NULL && _vertex_colors_enabled) {
|
||||||
|
_draw_primitive_pcollector.start();
|
||||||
|
CLP(GeomContext) *ggc = DCAST(CLP(GeomContext), gc);
|
||||||
|
GLP(CallList)(ggc->_index);
|
||||||
|
#ifdef DO_PSTATS
|
||||||
|
_vertices_display_list_pcollector.add_level(ggc->_num_verts);
|
||||||
|
#endif
|
||||||
|
_draw_primitive_pcollector.stop();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: CLP(GraphicsStateGuardian)::report_errors
|
// Function: CLP(GraphicsStateGuardian)::report_errors
|
||||||
// Access: Public, Static
|
// Access: Public, Static
|
||||||
|
@ -652,14 +652,7 @@ draw_point(GeomPoint *geom, GeomContext *gc) {
|
|||||||
GLCAT.spam() << "draw_point()" << endl;
|
GLCAT.spam() << "draw_point()" << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (gc != (GeomContext *)NULL) {
|
if (draw_display_list(gc)) {
|
||||||
_draw_primitive_pcollector.start();
|
|
||||||
CLP(GeomContext) *ggc = DCAST(CLP(GeomContext), gc);
|
|
||||||
GLP(CallList)(ggc->_index);
|
|
||||||
#ifdef DO_PSTATS
|
|
||||||
_vertices_display_list_pcollector.add_level(ggc->_num_verts);
|
|
||||||
#endif
|
|
||||||
_draw_primitive_pcollector.stop();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -725,14 +718,7 @@ draw_line(GeomLine *geom, GeomContext *gc) {
|
|||||||
GLCAT.spam() << "draw_line()" << endl;
|
GLCAT.spam() << "draw_line()" << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (gc != (GeomContext *)NULL) {
|
if (draw_display_list(gc)) {
|
||||||
_draw_primitive_pcollector.start();
|
|
||||||
CLP(GeomContext) *ggc = DCAST(CLP(GeomContext), gc);
|
|
||||||
GLP(CallList)(ggc->_index);
|
|
||||||
#ifdef DO_PSTATS
|
|
||||||
_vertices_display_list_pcollector.add_level(ggc->_num_verts);
|
|
||||||
#endif
|
|
||||||
_draw_primitive_pcollector.stop();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -808,14 +794,7 @@ draw_linestrip(GeomLinestrip *geom, GeomContext *gc) {
|
|||||||
GLCAT.spam() << "draw_linestrip()" << endl;
|
GLCAT.spam() << "draw_linestrip()" << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (gc != (GeomContext *)NULL) {
|
if (draw_display_list(gc)) {
|
||||||
_draw_primitive_pcollector.start();
|
|
||||||
CLP(GeomContext) *ggc = DCAST(CLP(GeomContext), gc);
|
|
||||||
GLP(CallList)(ggc->_index);
|
|
||||||
#ifdef DO_PSTATS
|
|
||||||
_vertices_display_list_pcollector.add_level(ggc->_num_verts);
|
|
||||||
#endif
|
|
||||||
_draw_primitive_pcollector.stop();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1190,14 +1169,7 @@ draw_polygon(GeomPolygon *geom, GeomContext *gc) {
|
|||||||
GLCAT.spam() << "draw_polygon()" << endl;
|
GLCAT.spam() << "draw_polygon()" << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (gc != (GeomContext *)NULL) {
|
if (draw_display_list(gc)) {
|
||||||
_draw_primitive_pcollector.start();
|
|
||||||
CLP(GeomContext) *ggc = DCAST(CLP(GeomContext), gc);
|
|
||||||
GLP(CallList)(ggc->_index);
|
|
||||||
#ifdef DO_PSTATS
|
|
||||||
_vertices_display_list_pcollector.add_level(ggc->_num_verts);
|
|
||||||
#endif
|
|
||||||
_draw_primitive_pcollector.stop();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1280,14 +1252,7 @@ draw_tri(GeomTri *geom, GeomContext *gc) {
|
|||||||
GLCAT.spam() << "draw_tri()" << endl;
|
GLCAT.spam() << "draw_tri()" << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (gc != (GeomContext *)NULL) {
|
if (draw_display_list(gc)) {
|
||||||
_draw_primitive_pcollector.start();
|
|
||||||
CLP(GeomContext) *ggc = DCAST(CLP(GeomContext), gc);
|
|
||||||
GLP(CallList)(ggc->_index);
|
|
||||||
#ifdef DO_PSTATS
|
|
||||||
_vertices_display_list_pcollector.add_level(ggc->_num_verts);
|
|
||||||
#endif
|
|
||||||
_draw_primitive_pcollector.stop();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1367,14 +1332,7 @@ draw_quad(GeomQuad *geom, GeomContext *gc) {
|
|||||||
GLCAT.spam() << "draw_quad()" << endl;
|
GLCAT.spam() << "draw_quad()" << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (gc != (GeomContext *)NULL) {
|
if (draw_display_list(gc)) {
|
||||||
_draw_primitive_pcollector.start();
|
|
||||||
CLP(GeomContext) *ggc = DCAST(CLP(GeomContext), gc);
|
|
||||||
GLP(CallList)(ggc->_index);
|
|
||||||
#ifdef DO_PSTATS
|
|
||||||
_vertices_display_list_pcollector.add_level(ggc->_num_verts);
|
|
||||||
#endif
|
|
||||||
_draw_primitive_pcollector.stop();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1452,14 +1410,7 @@ draw_tristrip(GeomTristrip *geom, GeomContext *gc) {
|
|||||||
GLCAT.spam() << "draw_tristrip()" << endl;
|
GLCAT.spam() << "draw_tristrip()" << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (gc != (GeomContext *)NULL) {
|
if (draw_display_list(gc)) {
|
||||||
_draw_primitive_pcollector.start();
|
|
||||||
CLP(GeomContext) *ggc = DCAST(CLP(GeomContext), gc);
|
|
||||||
GLP(CallList)(ggc->_index);
|
|
||||||
#ifdef DO_PSTATS
|
|
||||||
_vertices_display_list_pcollector.add_level(ggc->_num_verts);
|
|
||||||
#endif
|
|
||||||
_draw_primitive_pcollector.stop();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1560,14 +1511,7 @@ draw_trifan(GeomTrifan *geom, GeomContext *gc) {
|
|||||||
GLCAT.spam() << "draw_trifan()" << endl;
|
GLCAT.spam() << "draw_trifan()" << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (gc != (GeomContext *)NULL) {
|
if (draw_display_list(gc)) {
|
||||||
_draw_primitive_pcollector.start();
|
|
||||||
CLP(GeomContext) *ggc = DCAST(CLP(GeomContext), gc);
|
|
||||||
GLP(CallList)(ggc->_index);
|
|
||||||
#ifdef DO_PSTATS
|
|
||||||
_vertices_display_list_pcollector.add_level(ggc->_num_verts);
|
|
||||||
#endif
|
|
||||||
_draw_primitive_pcollector.stop();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1668,14 +1612,7 @@ draw_sphere(GeomSphere *geom, GeomContext *gc) {
|
|||||||
GLCAT.spam() << "draw_sphere()" << endl;
|
GLCAT.spam() << "draw_sphere()" << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (gc != (GeomContext *)NULL) {
|
if (draw_display_list(gc)) {
|
||||||
_draw_primitive_pcollector.start();
|
|
||||||
CLP(GeomContext) *ggc = DCAST(CLP(GeomContext), gc);
|
|
||||||
GLP(CallList)(ggc->_index);
|
|
||||||
#ifdef DO_PSTATS
|
|
||||||
_vertices_display_list_pcollector.add_level(ggc->_num_verts);
|
|
||||||
#endif
|
|
||||||
_draw_primitive_pcollector.stop();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1841,6 +1778,20 @@ release_texture(TextureContext *tc) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
GeomContext *CLP(GraphicsStateGuardian)::
|
GeomContext *CLP(GraphicsStateGuardian)::
|
||||||
prepare_geom(Geom *geom) {
|
prepare_geom(Geom *geom) {
|
||||||
|
if (!_vertex_colors_enabled) {
|
||||||
|
// We can't build a display list (or play back a display list) if
|
||||||
|
// its color is overridden with a scene graph color. Maybe if we
|
||||||
|
// take advantage of the OpenGL color matrix we can do this, but
|
||||||
|
// for now we'll just ignore it.
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (geom->is_dynamic()) {
|
||||||
|
// If the Geom is dynamic in some way, we shouldn't try to
|
||||||
|
// display-list it.
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
CLP(GeomContext) *ggc = new CLP(GeomContext)(geom);
|
CLP(GeomContext) *ggc = new CLP(GeomContext)(geom);
|
||||||
ggc->_index = GLP(GenLists)(1);
|
ggc->_index = GLP(GenLists)(1);
|
||||||
if (GLCAT.is_debug()) {
|
if (GLCAT.is_debug()) {
|
||||||
@ -1854,16 +1805,12 @@ prepare_geom(Geom *geom) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// We need to temporarily force normals and UV's on, so the display
|
// We need to temporarily force normals and UV's on, so the display
|
||||||
// list will have them built in.
|
// list will have them built in.
|
||||||
bool old_normals_enabled = _normals_enabled;
|
bool old_normals_enabled = _normals_enabled;
|
||||||
bool old_texturing_enabled = _texturing_enabled;
|
bool old_texturing_enabled = _texturing_enabled;
|
||||||
bool old_vertex_colors_enabled = _vertex_colors_enabled;
|
|
||||||
_normals_enabled = true;
|
_normals_enabled = true;
|
||||||
_texturing_enabled = true;
|
_texturing_enabled = true;
|
||||||
_vertex_colors_enabled = true;
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef DO_PSTATS
|
#ifdef DO_PSTATS
|
||||||
// Count up the number of vertices we're about to render, by
|
// Count up the number of vertices we're about to render, by
|
||||||
@ -1891,11 +1838,8 @@ prepare_geom(Geom *geom) {
|
|||||||
ggc->_num_verts = (int)(num_verts + 0.5);
|
ggc->_num_verts = (int)(num_verts + 0.5);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
_normals_enabled = old_normals_enabled;
|
_normals_enabled = old_normals_enabled;
|
||||||
_texturing_enabled = old_texturing_enabled;
|
_texturing_enabled = old_texturing_enabled;
|
||||||
_vertex_colors_enabled = old_vertex_colors_enabled;
|
|
||||||
*/
|
|
||||||
|
|
||||||
report_my_gl_errors();
|
report_my_gl_errors();
|
||||||
return ggc;
|
return ggc;
|
||||||
|
@ -66,6 +66,8 @@ public:
|
|||||||
virtual void draw_trifan(GeomTrifan *geom, GeomContext *gc);
|
virtual void draw_trifan(GeomTrifan *geom, GeomContext *gc);
|
||||||
virtual void draw_sphere(GeomSphere *geom, GeomContext *gc);
|
virtual void draw_sphere(GeomSphere *geom, GeomContext *gc);
|
||||||
|
|
||||||
|
INLINE bool draw_display_list(GeomContext *gc);
|
||||||
|
|
||||||
virtual TextureContext *prepare_texture(Texture *tex);
|
virtual TextureContext *prepare_texture(Texture *tex);
|
||||||
virtual void apply_texture(TextureContext *tc);
|
virtual void apply_texture(TextureContext *tc);
|
||||||
virtual void release_texture(TextureContext *tc);
|
virtual void release_texture(TextureContext *tc);
|
||||||
|
@ -82,6 +82,21 @@ draw_immediate(GraphicsStateGuardianBase *gsg, GeomContext *gc) {
|
|||||||
gsg->draw_sprite(this, gc);
|
gsg->draw_sprite(this, gc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: GeomSprite::is_dynamic
|
||||||
|
// Access: Public, Virtual
|
||||||
|
// Description: Returns true if the Geom has any dynamic properties
|
||||||
|
// that are expected to change from one frame to the
|
||||||
|
// next, or false if the Geom is largely static. For
|
||||||
|
// now, this is the same thing as asking whether its
|
||||||
|
// vertices are indexed.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
bool GeomSprite::
|
||||||
|
is_dynamic() const {
|
||||||
|
// Sprites are always dynamic.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GeomSprite::write_datagram
|
// Function: GeomSprite::write_datagram
|
||||||
// Access: Public
|
// Access: Public
|
||||||
|
@ -43,6 +43,8 @@ public:
|
|||||||
virtual Geom *explode() const {
|
virtual Geom *explode() const {
|
||||||
return new GeomSprite(*this); }
|
return new GeomSprite(*this); }
|
||||||
|
|
||||||
|
virtual bool is_dynamic() const;
|
||||||
|
|
||||||
static float get_frustum_top() { return 1.0f; }
|
static float get_frustum_top() { return 1.0f; }
|
||||||
static float get_frustum_bottom() { return -1.0f; }
|
static float get_frustum_bottom() { return -1.0f; }
|
||||||
static float get_frustum_left() { return -1.0f; }
|
static float get_frustum_left() { return -1.0f; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user