immediate-mode refinements

This commit is contained in:
David Rose 2005-08-16 17:27:40 +00:00
parent 854b66d0bb
commit d13afc82cf
8 changed files with 108 additions and 63 deletions

View File

@ -306,6 +306,14 @@
// only in a development build. // only in a development build.
#defer SIMULATE_NETWORK_DELAY $[<= $[OPTIMIZE], 3] #defer SIMULATE_NETWORK_DELAY $[<= $[OPTIMIZE], 3]
// This option compiles in support for immediate-mode OpenGL
// rendering. Since this is normally useful only for researching
// buggy drivers, and since there is a tiny bit of per-primitive
// overhead to have this option available even if it is unused, it is
// by default enabled only in a development build. This has no effect
// on DirectX rendering.
#define SUPPORT_IMMEDIATE_MODE $[<= $[OPTIMIZE], 3]
// Do you want to compile in support for pipelining? This enables // Do you want to compile in support for pipelining? This enables
// setting and accessing multiple different copies of frame-specific // setting and accessing multiple different copies of frame-specific
// data stored in nodes, etc. At the moment, Panda cannot actually // data stored in nodes, etc. At the moment, Panda cannot actually

View File

@ -226,6 +226,9 @@ $[cdefine DO_MEMORY_USAGE]
/* Define if we want to enable min-lag and max-lag. */ /* Define if we want to enable min-lag and max-lag. */
$[cdefine SIMULATE_NETWORK_DELAY] $[cdefine SIMULATE_NETWORK_DELAY]
/* Define if we want to allow immediate mode OpenGL rendering. */
$[cdefine SUPPORT_IMMEDIATE_MODE]
/* Define if we want to compile in support for pipelining. */ /* Define if we want to compile in support for pipelining. */
$[cdefine DO_PIPELINING] $[cdefine DO_PIPELINING]

View File

@ -1041,6 +1041,7 @@ begin_frame() {
#ifdef DO_PSTATS #ifdef DO_PSTATS
_vertices_display_list_pcollector.clear_level(); _vertices_display_list_pcollector.clear_level();
_vertices_immediate_pcollector.clear_level();
_primitive_batches_display_list_pcollector.clear_level(); _primitive_batches_display_list_pcollector.clear_level();
#endif #endif
@ -1297,10 +1298,11 @@ begin_draw_primitives(const Geom *geom, const GeomMunger *munger,
#endif #endif
} }
if (!vertex_arrays) { #ifdef SUPPORT_IMMEDIATE_MODE
_use_sender = !vertex_arrays;
if (_use_sender) {
// We must use immediate mode to render primitives. // We must use immediate mode to render primitives.
_sender.clear(); _sender.clear();
_use_sender = true;
_sender.add_column(_vertex_data, InternalName::get_normal(), _sender.add_column(_vertex_data, InternalName::get_normal(),
NULL, NULL, GLP(Normal3f), NULL); NULL, NULL, GLP(Normal3f), NULL);
@ -1371,10 +1373,10 @@ begin_draw_primitives(const Geom *geom, const GeomMunger *munger,
_sender.add_column(_vertex_data, InternalName::get_vertex(), _sender.add_column(_vertex_data, InternalName::get_vertex(),
NULL, GLP(Vertex2f), GLP(Vertex3f), GLP(Vertex4f)); NULL, GLP(Vertex2f), GLP(Vertex3f), GLP(Vertex4f));
} else { } else
#endif // SUPPORT_IMMEDIATE_MODE
{
// We may use vertex arrays or buffers to render primitives. // We may use vertex arrays or buffers to render primitives.
_use_sender = false;
const GeomVertexArrayData *array_data; const GeomVertexArrayData *array_data;
int num_values; int num_values;
Geom::NumericType numeric_type; Geom::NumericType numeric_type;
@ -1517,13 +1519,16 @@ draw_triangles(const GeomTriangles *primitive) {
} }
#endif // NDEBUG #endif // NDEBUG
_vertices_tri_pcollector.add_level(primitive->get_num_vertices()); #ifdef SUPPORT_IMMEDIATE_MODE
_primitive_batches_tri_pcollector.add_level(1);
if (_use_sender) { if (_use_sender) {
draw_immediate_simple_primitives(primitive, GL_TRIANGLES); draw_immediate_simple_primitives(primitive, GL_TRIANGLES);
} else { } else
#endif // SUPPORT_IMMEDIATE_MODE
{
_vertices_tri_pcollector.add_level(primitive->get_num_vertices());
_primitive_batches_tri_pcollector.add_level(1);
if (primitive->is_indexed()) { if (primitive->is_indexed()) {
const unsigned char *client_pointer = setup_primitive(primitive); const unsigned char *client_pointer = setup_primitive(primitive);
@ -1556,10 +1561,13 @@ draw_tristrips(const GeomTristrips *primitive) {
} }
#endif // NDEBUG #endif // NDEBUG
#ifdef SUPPORT_IMMEDIATE_MODE
if (_use_sender) { if (_use_sender) {
draw_immediate_composite_primitives(primitive, GL_TRIANGLE_STRIP); draw_immediate_composite_primitives(primitive, GL_TRIANGLE_STRIP);
} else { } else
#endif // SUPPORT_IMMEDIATE_MODE
{
if (connect_triangle_strips && _render_mode != RenderModeAttrib::M_wireframe) { if (connect_triangle_strips && _render_mode != RenderModeAttrib::M_wireframe) {
// One long triangle strip, connected by the degenerate vertices // One long triangle strip, connected by the degenerate vertices
// that have already been set up within the primitive. // that have already been set up within the primitive.
@ -1632,10 +1640,12 @@ draw_trifans(const GeomTrifans *primitive) {
} }
#endif // NDEBUG #endif // NDEBUG
#ifdef SUPPORT_IMMEDIATE_MODE
if (_use_sender) { if (_use_sender) {
draw_immediate_composite_primitives(primitive, GL_TRIANGLE_FAN); draw_immediate_composite_primitives(primitive, GL_TRIANGLE_FAN);
} else
} else { #endif // SUPPORT_IMMEDIATE_MODE
{
// Send the individual triangle fans. There's no connecting fans // Send the individual triangle fans. There's no connecting fans
// with degenerate vertices, so no worries about that. // with degenerate vertices, so no worries about that.
CPTA_int ends = primitive->get_ends(); CPTA_int ends = primitive->get_ends();
@ -1686,10 +1696,12 @@ draw_lines(const GeomLines *primitive) {
} }
#endif // NDEBUG #endif // NDEBUG
#ifdef SUPPORT_IMMEDIATE_MODE
if (_use_sender) { if (_use_sender) {
draw_immediate_simple_primitives(primitive, GL_LINES); draw_immediate_simple_primitives(primitive, GL_LINES);
} else
} else { #endif // SUPPORT_IMMEDIATE_MODE
{
_vertices_other_pcollector.add_level(primitive->get_num_vertices()); _vertices_other_pcollector.add_level(primitive->get_num_vertices());
_primitive_batches_other_pcollector.add_level(1); _primitive_batches_other_pcollector.add_level(1);
@ -1739,10 +1751,12 @@ draw_points(const GeomPoints *primitive) {
} }
#endif // NDEBUG #endif // NDEBUG
#ifdef SUPPORT_IMMEDIATE_MODE
if (_use_sender) { if (_use_sender) {
draw_immediate_simple_primitives(primitive, GL_POINTS); draw_immediate_simple_primitives(primitive, GL_POINTS);
} else
} else { #endif // SUPPORT_IMMEDIATE_MODE
{
_vertices_other_pcollector.add_level(primitive->get_num_vertices()); _vertices_other_pcollector.add_level(primitive->get_num_vertices());
_primitive_batches_other_pcollector.add_level(1); _primitive_batches_other_pcollector.add_level(1);
@ -3082,6 +3096,7 @@ wants_texcoords() const {
return true; return true;
} }
#ifdef SUPPORT_IMMEDIATE_MODE
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: GLGraphicsStateGuardian::draw_immediate_simple_primitives // Function: GLGraphicsStateGuardian::draw_immediate_simple_primitives
// Access: Protected // Access: Protected
@ -3108,7 +3123,9 @@ draw_immediate_simple_primitives(const GeomPrimitive *primitive, GLenum mode) {
GLP(End)(); GLP(End)();
} }
#endif // SUPPORT_IMMEDIATE_MODE
#ifdef SUPPORT_IMMEDIATE_MODE
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: GLGraphicsStateGuardian::draw_immediate_composite_primitives // Function: GLGraphicsStateGuardian::draw_immediate_composite_primitives
// Access: Protected // Access: Protected
@ -3156,6 +3173,7 @@ draw_immediate_composite_primitives(const GeomPrimitive *primitive, GLenum mode)
} }
} }
} }
#endif // SUPPORT_IMMEDIATE_MODE
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: GLGraphicsStateGuardian::report_errors_loop // Function: GLGraphicsStateGuardian::report_errors_loop

View File

@ -157,8 +157,11 @@ public:
void dump_state(void); void dump_state(void);
const float *get_light_color(Light *light) const; const float *get_light_color(Light *light) const;
#ifdef SUPPORT_IMMEDIATE_MODE
void draw_immediate_simple_primitives(const GeomPrimitive *primitive, GLenum mode); void draw_immediate_simple_primitives(const GeomPrimitive *primitive, GLenum mode);
void draw_immediate_composite_primitives(const GeomPrimitive *primitive, GLenum mode); void draw_immediate_composite_primitives(const GeomPrimitive *primitive, GLenum mode);
#endif // SUPPORT_IMMEDIATE_MODE
INLINE static bool report_errors(int line, const char *source_file); INLINE static bool report_errors(int line, const char *source_file);
INLINE void report_my_errors(int line, const char *source_file); INLINE void report_my_errors(int line, const char *source_file);
@ -306,8 +309,11 @@ protected:
bool _vertex_blending_enabled; bool _vertex_blending_enabled;
CPT(DisplayRegion) _actual_display_region; CPT(DisplayRegion) _actual_display_region;
#ifdef SUPPORT_IMMEDIATE_MODE
CLP(ImmediateModeSender) _sender; CLP(ImmediateModeSender) _sender;
bool _use_sender; bool _use_sender;
#endif // SUPPORT_IMMEDIATE_MODE
#ifdef HAVE_CGGL #ifdef HAVE_CGGL
PT(CgShader) _cg_shader; // The current CgShader object PT(CgShader) _cg_shader; // The current CgShader object

View File

@ -16,6 +16,7 @@
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
#ifdef SUPPORT_IMMEDIATE_MODE
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: CLP(ImmediateModeSender)::Destructor // Function: CLP(ImmediateModeSender)::Destructor
@ -616,3 +617,5 @@ issue_vertex() {
(*_func)(4, (const unsigned int *)d); (*_func)(4, (const unsigned int *)d);
} }
#endif // SUPPORT_IMMEDIATE_MODE

View File

@ -19,6 +19,8 @@
#include "pandabase.h" #include "pandabase.h"
#include "geomVertexReader.h" #include "geomVertexReader.h"
#ifdef SUPPORT_IMMEDIATE_MODE
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Class : GLImmediateModeSender // Class : GLImmediateModeSender
// Description : This class collects together a handful of objects // Description : This class collects together a handful of objects
@ -225,3 +227,5 @@ private:
#include "glImmediateModeSender_src.I" #include "glImmediateModeSender_src.I"
#endif // SUPPORT_IMMEDIATE_MODE

View File

@ -92,15 +92,17 @@ ConfigVariableBool vertex_arrays
PRC_DESC("Set this true to allow the use of vertex arrays for rendering " PRC_DESC("Set this true to allow the use of vertex arrays for rendering "
"OpenGL vertex data. This, or vertex buffers, is the normal " "OpenGL vertex data. This, or vertex buffers, is the normal "
"way of issuing vertices ever since OpenGL 1.1, and you " "way of issuing vertices ever since OpenGL 1.1, and you "
"almost always want to have set to true. However, some very " "almost always want to have this set to true. However, some very "
"buggy graphics drivers may have problems handling vertex arrays " "buggy graphics drivers may have problems handling vertex arrays "
"correctly, so if you are experiencing problems you might try " "correctly, so if you are experiencing problems you might try "
"setting this to false. If this is false, Panda will fall back " "setting this to false. If this is false, Panda will fall back "
"to using immediate-mode commands like glVertex3f(), etc., to " "to using immediate-mode commands like glVertex3f(), etc., to "
"issue the vertices, which is potentially much slower than " "issue the vertices, which is potentially much slower than "
"vertex arrays. Setting this false causes vertex_buffers to be " "vertex arrays. Setting this false also disables vertex buffers, "
"ignored (since vertex buffers are a special case of vertex " "effectively ignoring the setting of the vertex-buffers variable "
"arrays in OpenGL). This has no effect on DirectX rendering.")); "(since vertex buffers are a special case of vertex arrays in "
"OpenGL). This variable is normally not enabled in a production "
"build. This has no effect on DirectX rendering."));
ConfigVariableBool display_lists ConfigVariableBool display_lists
("display-lists", false, ("display-lists", false,

View File

@ -189,6 +189,7 @@ static LevelCollectorProperties level_properties[] = {
{ 1, "Vertices:Triangle strips", { 0.2, 0.5, 0.8 } }, { 1, "Vertices:Triangle strips", { 0.2, 0.5, 0.8 } },
{ 1, "Vertices:Indexed triangle strips", { 0.5, 0.2, 0.8 } }, { 1, "Vertices:Indexed triangle strips", { 0.5, 0.2, 0.8 } },
{ 1, "Vertices:Display lists", { 0.8, 0.5, 1.0 } }, { 1, "Vertices:Display lists", { 0.8, 0.5, 1.0 } },
{ 1, "Vertices:Immediate mode", { 1.0, 0.5, 0.0 } },
{ 1, "Nodes", { 0.4, 0.2, 0.8 }, "", 500.0 }, { 1, "Nodes", { 0.4, 0.2, 0.8 }, "", 500.0 },
{ 1, "Nodes:GeomNodes", { 0.8, 0.2, 0.0 } }, { 1, "Nodes:GeomNodes", { 0.8, 0.2, 0.0 } },
{ 1, "Geoms", { 0.4, 0.8, 0.3 }, "", 500.0 }, { 1, "Geoms", { 0.4, 0.8, 0.3 }, "", 500.0 },