Pārlūkot izejas kodu

premunger for dx

David Rose 18 gadi atpakaļ
vecāks
revīzija
6b913ae195

+ 83 - 0
panda/src/dxgsg8/dxGeomMunger8.cxx

@@ -174,6 +174,89 @@ munge_format_impl(const GeomVertexFormat *orig,
   return GeomVertexFormat::register_format(new_format);
   return GeomVertexFormat::register_format(new_format);
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: DXGeomMunger8::premunge_format_impl
+//       Access: Protected, Virtual
+//  Description: Given a source GeomVertexFormat, converts it if
+//               necessary to the appropriate format for rendering.
+////////////////////////////////////////////////////////////////////
+CPT(GeomVertexFormat) DXGeomMunger8::
+premunge_format_impl(const GeomVertexFormat *orig) {
+  // We have to build a completely new format that includes only the
+  // appropriate components, in the appropriate order, in just one
+  // array.
+  PT(GeomVertexFormat) new_format = new GeomVertexFormat(*orig);
+  PT(GeomVertexArrayFormat) new_array_format = new GeomVertexArrayFormat;
+
+  const GeomVertexColumn *vertex_type = orig->get_vertex_column();
+  const GeomVertexColumn *normal_type = orig->get_normal_column(); 
+  const GeomVertexColumn *color_type = orig->get_color_column();
+
+  if (vertex_type != (const GeomVertexColumn *)NULL) {
+    new_array_format->add_column
+      (InternalName::get_vertex(), 3, NT_float32,
+       vertex_type->get_contents());
+    new_format->remove_column(vertex_type->get_name());
+
+  } else {
+    // If we don't have a vertex type, not much we can do.
+    return orig;
+  }
+
+  if (normal_type != (const GeomVertexColumn *)NULL) {
+    new_array_format->add_column
+      (InternalName::get_normal(), 3, NT_float32, C_vector);
+    new_format->remove_column(normal_type->get_name());
+  }
+
+  if (color_type != (const GeomVertexColumn *)NULL) {
+    new_array_format->add_column
+      (InternalName::get_color(), 1, NT_packed_dabc, C_color);
+    new_format->remove_column(color_type->get_name());
+  }
+
+  // To support multitexture, we will need to add all of the relevant
+  // texcoord types, and in the correct order.
+
+  // Now set up each of the active texture coordinate stages--or at
+  // least those for which we're not generating texture coordinates
+  // automatically.
+
+  // Now copy all of the texture coordinates in, in order by stage
+  // index.  But we have to reuse previous columns.
+  if (_filtered_texture != (TextureAttrib *)NULL) {
+    typedef pset<const InternalName *> UsedStages;
+    UsedStages used_stages;
+
+    int num_stages = _filtered_texture->get_num_on_stages();
+    for (int i = 0; i < num_stages; ++i) {
+      TextureStage *stage = _filtered_texture->get_on_stage(i);
+
+      InternalName *name = stage->get_texcoord_name();
+      if (used_stages.insert(name).second) {
+        // This is the first time we've encountered this texcoord name.
+        const GeomVertexColumn *texcoord_type = orig->get_column(name);
+        
+        if (texcoord_type != (const GeomVertexColumn *)NULL) {
+          new_array_format->add_column
+            (name, texcoord_type->get_num_values(), NT_float32, C_texcoord);
+        } else {
+          // We have to add something as a placeholder, even if the
+          // texture coordinates aren't defined.
+          new_array_format->add_column(name, 2, NT_float32, C_texcoord);
+        }
+        new_format->remove_column(name);
+      }
+    }
+  }
+
+  // Make sure the FVF-style array we just built up is first in the
+  // list.
+  new_format->insert_array(0, new_array_format);
+
+  return GeomVertexFormat::register_format(new_format);
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGeomMunger8::compare_to_impl
 //     Function: DXGeomMunger8::compare_to_impl
 //       Access: Protected, Virtual
 //       Access: Protected, Virtual

+ 2 - 1
panda/src/dxgsg8/dxGeomMunger8.h

@@ -43,7 +43,8 @@ public:
 
 
 protected:
 protected:
   virtual CPT(GeomVertexFormat) munge_format_impl(const GeomVertexFormat *orig,
   virtual CPT(GeomVertexFormat) munge_format_impl(const GeomVertexFormat *orig,
-                                                    const GeomVertexAnimationSpec &animation);
+                                                  const GeomVertexAnimationSpec &animation);
+  virtual CPT(GeomVertexFormat) premunge_format_impl(const GeomVertexFormat *orig);
 
 
   virtual int compare_to_impl(const GeomMunger *other) const;
   virtual int compare_to_impl(const GeomMunger *other) const;
   virtual int geom_compare_to_impl(const GeomMunger *other) const;
   virtual int geom_compare_to_impl(const GeomMunger *other) const;

+ 83 - 0
panda/src/dxgsg9/dxGeomMunger9.cxx

@@ -174,6 +174,89 @@ munge_format_impl(const GeomVertexFormat *orig,
   return GeomVertexFormat::register_format(new_format);
   return GeomVertexFormat::register_format(new_format);
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: DXGeomMunger9::premunge_format_impl
+//       Access: Protected, Virtual
+//  Description: Given a source GeomVertexFormat, converts it if
+//               necessary to the appropriate format for rendering.
+////////////////////////////////////////////////////////////////////
+CPT(GeomVertexFormat) DXGeomMunger9::
+premunge_format_impl(const GeomVertexFormat *orig) {
+  // We have to build a completely new format that includes only the
+  // appropriate components, in the appropriate order, in just one
+  // array.
+  PT(GeomVertexFormat) new_format = new GeomVertexFormat(*orig);
+  PT(GeomVertexArrayFormat) new_array_format = new GeomVertexArrayFormat;
+
+  const GeomVertexColumn *vertex_type = orig->get_vertex_column();
+  const GeomVertexColumn *normal_type = orig->get_normal_column();
+  const GeomVertexColumn *color_type = orig->get_color_column();
+
+  if (vertex_type != (const GeomVertexColumn *)NULL) {
+    new_array_format->add_column
+      (InternalName::get_vertex(), 3, NT_float32,
+       vertex_type->get_contents());
+    new_format->remove_column(vertex_type->get_name());
+
+  } else {
+    // If we don't have a vertex type, not much we can do.
+    return orig;
+  }
+
+  if (normal_type != (const GeomVertexColumn *)NULL) {
+    new_array_format->add_column
+      (InternalName::get_normal(), 3, NT_float32, C_vector);
+    new_format->remove_column(normal_type->get_name());
+  }
+
+  if (color_type != (const GeomVertexColumn *)NULL) {
+    new_array_format->add_column
+      (InternalName::get_color(), 1, NT_packed_dabc, C_color);
+    new_format->remove_column(color_type->get_name());
+  }
+
+  // To support multitexture, we will need to add all of the relevant
+  // texcoord types, and in the correct order.
+
+  // Now set up each of the active texture coordinate stages--or at
+  // least those for which we're not generating texture coordinates
+  // automatically.
+
+  // Now copy all of the texture coordinates in, in order by stage
+  // index.  But we have to reuse previous columns.
+  if (_filtered_texture != (TextureAttrib *)NULL) {
+    typedef pset<const InternalName *> UsedStages;
+    UsedStages used_stages;
+
+    int num_stages = _filtered_texture->get_num_on_stages();
+    for (int i = 0; i < num_stages; ++i) {
+      TextureStage *stage = _filtered_texture->get_on_stage(i);
+
+      InternalName *name = stage->get_texcoord_name();
+      if (used_stages.insert(name).second) {
+        // This is the first time we've encountered this texcoord name.
+        const GeomVertexColumn *texcoord_type = orig->get_column(name);
+
+        if (texcoord_type != (const GeomVertexColumn *)NULL) {
+          new_array_format->add_column
+            (name, texcoord_type->get_num_values(), NT_float32, C_texcoord);
+        } else {
+          // We have to add something as a placeholder, even if the
+          // texture coordinates aren't defined.
+          new_array_format->add_column(name, 2, NT_float32, C_texcoord);
+        }
+        new_format->remove_column(name);
+      }
+    }
+  }
+
+  // Make sure the FVF-style array we just built up is first in the
+  // list.
+  new_format->insert_array(0, new_array_format);
+
+  return GeomVertexFormat::register_format(new_format);
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGeomMunger9::compare_to_impl
 //     Function: DXGeomMunger9::compare_to_impl
 //       Access: Protected, Virtual
 //       Access: Protected, Virtual

+ 2 - 1
panda/src/dxgsg9/dxGeomMunger9.h

@@ -43,7 +43,8 @@ public:
 
 
 protected:
 protected:
   virtual CPT(GeomVertexFormat) munge_format_impl(const GeomVertexFormat *orig,
   virtual CPT(GeomVertexFormat) munge_format_impl(const GeomVertexFormat *orig,
-                                                    const GeomVertexAnimationSpec &animation);
+                                                  const GeomVertexAnimationSpec &animation);
+  virtual CPT(GeomVertexFormat) premunge_format_impl(const GeomVertexFormat *orig);
 
 
   virtual int compare_to_impl(const GeomMunger *other) const;
   virtual int compare_to_impl(const GeomMunger *other) const;
   virtual int geom_compare_to_impl(const GeomMunger *other) const;
   virtual int geom_compare_to_impl(const GeomMunger *other) const;

+ 1 - 1
panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx

@@ -5185,7 +5185,7 @@ check_dx_allocation (HRESULT result, int allocation_size, int attempts)
           }
           }
         }
         }
         break;
         break;
-        
+
       default:
       default:
         break;
         break;
     }
     }

+ 4 - 1
panda/src/dxgsg9/dxTextureContext9.cxx

@@ -1408,7 +1408,10 @@ fill_d3d_texture_pixels(bool supports_automatic_mipmap_generation) {
     // The texture doesn't have an image to load.  That's ok; it
     // The texture doesn't have an image to load.  That's ok; it
     // might be a texture we've rendered to by frame buffer
     // might be a texture we've rendered to by frame buffer
     // operations or something.
     // operations or something.
-    return S_OK;
+    if (get_texture()->get_render_to_texture()) {
+      return S_OK;
+    }
+    return E_FAIL;
   }
   }
   nassertr(IS_VALID_PTR((BYTE*)image.p()), E_FAIL);
   nassertr(IS_VALID_PTR((BYTE*)image.p()), E_FAIL);
   nassertr(IS_VALID_PTR(_d3d_texture), E_FAIL);
   nassertr(IS_VALID_PTR(_d3d_texture), E_FAIL);