Преглед изворни кода

Support rendering without any vertex arrays bound better

rdb пре 9 година
родитељ
комит
6225755230

+ 4 - 1
panda/src/display/graphicsStateGuardian.cxx

@@ -2196,7 +2196,10 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader,
                       bool force) {
   _munger = munger;
   _data_reader = data_reader;
-  return _data_reader->has_vertex();
+
+  // Always draw if we have a shader, since the shader might use a different
+  // mechanism for fetching vertex data.
+  return _data_reader->has_vertex() || (_target_shader && _target_shader->has_shader());
 }
 
 /**

+ 2 - 1
panda/src/gobj/geomPrimitive.cxx

@@ -2231,7 +2231,8 @@ get_num_primitives() const {
  */
 bool GeomPrimitivePipelineReader::
 check_valid(const GeomVertexDataPipelineReader *data_reader) const {
-  if (get_num_vertices() != 0  &&
+  if (get_num_vertices() != 0 &&
+      data_reader->get_num_arrays() > 0 &&
       get_max_vertex() >= data_reader->get_num_rows()) {
 
 #ifndef NDEBUG

+ 9 - 0
panda/src/gobj/geomVertexFormat.I

@@ -235,6 +235,15 @@ get_morph_delta(size_t n) const {
   return _morphs[n]._delta;
 }
 
+/**
+ * Returns a standard vertex format containing no arrays at all, useful for
+ * pull-style vertex rendering.
+ */
+INLINE const GeomVertexFormat *GeomVertexFormat::
+get_empty() {
+  return get_registry()->_empty;
+}
+
 /**
  * Returns a standard vertex format with just a 3-component vertex position.
  */

+ 2 - 4
panda/src/gobj/geomVertexFormat.cxx

@@ -890,6 +890,8 @@ Registry() {
  */
 void GeomVertexFormat::Registry::
 make_standard_formats() {
+  _empty = register_format(new GeomVertexFormat);
+
   _v3 = register_format(new GeomVertexArrayFormat
                         (InternalName::get_vertex(), 3,
                          NT_stdfloat, C_point));
@@ -1011,10 +1013,6 @@ register_format(GeomVertexFormat *format) {
     new_format = (*fi);
     if (!new_format->is_registered()) {
       new_format->do_register();
-      if (new_format->get_num_arrays() == 0) {
-        gobj_cat.warning()
-          << "Empty GeomVertexFormat registered.\n";
-      }
     }
   }
 

+ 4 - 0
panda/src/gobj/geomVertexFormat.h

@@ -125,6 +125,8 @@ PUBLISHED:
   void write_with_data(ostream &out, int indent_level,
                        const GeomVertexData *data) const;
 
+  INLINE static const GeomVertexFormat *get_empty();
+
   // Some standard vertex formats.  No particular requirement to use one of
   // these, but the DirectX renderers can use these formats directly, whereas
   // any other format will have to be converted first.
@@ -227,6 +229,8 @@ private:
     Formats _formats;
     LightReMutex _lock;
 
+    CPT(GeomVertexFormat) _empty;
+
     CPT(GeomVertexFormat) _v3;
     CPT(GeomVertexFormat) _v3n3;
     CPT(GeomVertexFormat) _v3t2;