summaryrefslogtreecommitdiffstats
path: root/o3d/core/cross/field.cc
diff options
context:
space:
mode:
authorgman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-09 15:52:10 +0000
committergman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-09 15:52:10 +0000
commitc8b58a46e4f97791f81500006e464a94d68c8c12 (patch)
tree8991b7d38e19d9808ef273049a57c7338f4122d2 /o3d/core/cross/field.cc
parent1b91f510fdda3d6e764e0476df5a82c64ae2975e (diff)
downloadchromium_src-c8b58a46e4f97791f81500006e464a94d68c8c12.zip
chromium_src-c8b58a46e4f97791f81500006e464a94d68c8c12.tar.gz
chromium_src-c8b58a46e4f97791f81500006e464a94d68c8c12.tar.bz2
This CL makes the collada importer handle skinned data
better. Specifically, it takes the original VertexBuffer and splits it. One VertexBuffer contains the parts fields that get skinned. (POSITION, NORMAL, etc...) The other VertexBuffer contains the fields that don't get Skinned. (COLOR, TEXCOORD, etc...) That way instancing you can share the non-skinned VertexBuffer. The next step is to not serialize the skinned VertexBuffer's contents. Review URL: http://codereview.chromium.org/118156 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17942 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/core/cross/field.cc')
-rw-r--r--o3d/core/cross/field.cc59
1 files changed, 55 insertions, 4 deletions
diff --git a/o3d/core/cross/field.cc b/o3d/core/cross/field.cc
index c85c9d3..1ccbfde 100644
--- a/o3d/core/cross/field.cc
+++ b/o3d/core/cross/field.cc
@@ -34,6 +34,7 @@
// IndexBuffer.
#include "core/cross/precompile.h"
+#include <vector>
#include "core/cross/field.h"
#include "core/cross/error.h"
#include "core/cross/buffer.h"
@@ -283,6 +284,23 @@ bool Field::RangeValid(unsigned int start_index, unsigned int num_elements) {
return true;
}
+void Field::Copy(const Field& source) {
+ if (!source.IsA(GetClass())) {
+ O3D_ERROR(service_locator())
+ << "source field of type " << source.GetClassName()
+ << " is not compatible with field of type " << GetClassName();
+ return;
+ }
+ if (!source.buffer()) {
+ O3D_ERROR(service_locator()) << "source buffer is null";
+ return;
+ }
+ if (!buffer()) {
+ O3D_ERROR(service_locator()) << "destination buffer is null";
+ return;
+ }
+ ConcreteCopy(source);
+}
// FloatField -------------------
@@ -361,6 +379,16 @@ void FloatField::GetAsFloats(unsigned source_start_index,
num_elements);
}
+void FloatField::ConcreteCopy(const Field& source) {
+ DCHECK(source.IsA(GetClass()));
+ DCHECK(source.buffer());
+ unsigned num_components = source.num_components();
+ unsigned num_elements = source.buffer()->num_elements();
+ scoped_array<float> temp(new float[num_components * num_elements]);
+ source.GetAsFloats(0, temp.get(), num_components, num_elements);
+ SetFromFloats(temp.get(), num_components, 0, num_elements);
+}
+
Field::Ref FloatField::Create(ServiceLocator* service_locator,
Buffer* buffer,
unsigned num_components,
@@ -454,6 +482,17 @@ void UInt32Field::GetAsUInt32s(unsigned source_start_index,
num_elements);
}
+void UInt32Field::ConcreteCopy(const Field& source) {
+ DCHECK(source.IsA(GetClass()));
+ DCHECK(source.buffer());
+ unsigned num_components = source.num_components();
+ unsigned num_elements = source.buffer()->num_elements();
+ scoped_array<uint32> temp(new uint32[num_components * num_elements]);
+ down_cast<const UInt32Field*>(&source)->GetAsUInt32s(
+ 0, temp.get(), num_components, num_elements);
+ SetFromUInt32s(temp.get(), num_components, 0, num_elements);
+}
+
Field::Ref UInt32Field::Create(ServiceLocator* service_locator,
Buffer* buffer,
unsigned num_components,
@@ -543,10 +582,10 @@ void UByteNField::GetAsFloats(unsigned source_start_index,
swizzle_table_);
}
-void UByteNField::GetAsBytes(unsigned source_start_index,
- uint8* destination,
- unsigned destination_stride,
- unsigned num_elements) const {
+void UByteNField::GetAsUByteNs(unsigned source_start_index,
+ uint8* destination,
+ unsigned destination_stride,
+ unsigned num_elements) const {
GetAsWithSwizzle<const uint8, uint8, ConvertUByteNToUByteN>(
this,
source_start_index,
@@ -556,6 +595,18 @@ void UByteNField::GetAsBytes(unsigned source_start_index,
swizzle_table_);
}
+void UByteNField::ConcreteCopy(const Field& source) {
+ DCHECK(source.IsA(GetClass()));
+ DCHECK(source.buffer());
+ unsigned num_components = source.num_components();
+ unsigned num_elements = source.buffer()->num_elements();
+ scoped_array<uint8> temp(new uint8[num_components * num_elements]);
+ down_cast<const UByteNField*>(&source)->GetAsUByteNs(
+ 0, temp.get(), num_components, num_elements);
+ SetFromUByteNs(temp.get(), num_components, 0, num_elements);
+}
+
+
Field::Ref UByteNField::Create(ServiceLocator* service_locator,
Buffer* buffer,
unsigned num_components,