summaryrefslogtreecommitdiffstats
path: root/o3d/serializer
diff options
context:
space:
mode:
authorgman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-07 04:24:21 +0000
committergman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-07 04:24:21 +0000
commit34f464fb752432829a22a30767b66eb5c24a2242 (patch)
tree93545e6e6f56e7151ae8bc5100accf0998c262ad /o3d/serializer
parente8b80d819b7d1888e10f5cfef75bfeff0f5d3b03 (diff)
downloadchromium_src-34f464fb752432829a22a30767b66eb5c24a2242.zip
chromium_src-34f464fb752432829a22a30767b66eb5c24a2242.tar.gz
chromium_src-34f464fb752432829a22a30767b66eb5c24a2242.tar.bz2
Add o3djs.DestinationBuffer to converter.
I named it o3djs.DestinationBuffer because it has nothing to do with O3D. It's purely part of our sample serialization example. Review URL: http://codereview.chromium.org/149236 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20013 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/serializer')
-rw-r--r--o3d/serializer/cross/serializer.cc33
-rw-r--r--o3d/serializer/cross/version.h2
2 files changed, 34 insertions, 1 deletions
diff --git a/o3d/serializer/cross/serializer.cc b/o3d/serializer/cross/serializer.cc
index 066ce30..25996c8 100644
--- a/o3d/serializer/cross/serializer.cc
+++ b/o3d/serializer/cross/serializer.cc
@@ -47,6 +47,7 @@
#include "core/cross/skin.h"
#include "core/cross/texture.h"
#include "core/cross/transform.h"
+#include "import/cross/destination_buffer.h"
#include "import/cross/iarchive_generator.h"
#include "import/cross/memory_buffer.h"
#include "import/cross/memory_stream.h"
@@ -345,6 +346,7 @@ class CustomVisitor : public VisitorBase<CustomVisitor> {
BinaryArchiveManager* binary_archive_manager)
: writer_(writer),
binary_archive_manager_(binary_archive_manager) {
+ Enable<DestinationBuffer>(&CustomVisitor::Visit);
Enable<Buffer>(&CustomVisitor::Visit);
Enable<Curve>(&CustomVisitor::Visit);
Enable<Primitive>(&CustomVisitor::Visit);
@@ -356,6 +358,31 @@ class CustomVisitor : public VisitorBase<CustomVisitor> {
}
private:
+ void Visit(DestinationBuffer* buffer) {
+ // NOTE: We don't call Visit<VertexBuffer*> because we don't want to
+ // serialize the contents of the Buffer. We only serialize its structure.
+ Visit(static_cast<NamedObject*>(buffer));
+ writer_->WritePropertyName("numElements");
+ Serialize(writer_, buffer->num_elements());
+ writer_->WritePropertyName("fields");
+ writer_->OpenArray();
+ const FieldRefArray& fields = buffer->fields();
+ for (size_t ii = 0; ii < fields.size(); ++ii) {
+ Field* field = fields[ii].Get();
+ writer_->BeginCompacting();
+ writer_->OpenObject();
+ writer_->WritePropertyName("id");
+ Serialize(writer_, field->id());
+ writer_->WritePropertyName("type");
+ Serialize(writer_, field->GetClassName());
+ writer_->WritePropertyName("numComponents");
+ Serialize(writer_, field->num_components());
+ writer_->CloseObject();
+ writer_->EndCompacting();
+ }
+ writer_->CloseArray();
+ }
+
void Visit(Buffer* buffer) {
Visit(static_cast<NamedObject*>(buffer));
@@ -585,6 +612,7 @@ class BinaryVisitor : public VisitorBase<BinaryVisitor> {
: binary_archive_manager_(binary_archive_manager) {
Enable<Curve>(&BinaryVisitor::Visit);
Enable<IndexBuffer>(&BinaryVisitor::Visit);
+ Enable<DestinationBuffer>(&BinaryVisitor::Visit);
Enable<VertexBufferBase>(&BinaryVisitor::Visit);
Enable<Skin>(&BinaryVisitor::Visit);
}
@@ -608,6 +636,11 @@ class BinaryVisitor : public VisitorBase<BinaryVisitor> {
serialized_data.GetLength());
}
+ void Visit(DestinationBuffer* buffer) {
+ // Destination buffers should NOT have their contents serialized.
+ Visit(static_cast<Buffer*>(buffer));
+ }
+
void Visit(IndexBuffer* buffer) {
Visit(static_cast<Buffer*>(buffer));
diff --git a/o3d/serializer/cross/version.h b/o3d/serializer/cross/version.h
index 6792023..619ad3b 100644
--- a/o3d/serializer/cross/version.h
+++ b/o3d/serializer/cross/version.h
@@ -39,7 +39,7 @@
#define O3D_SERIALIZER_CROSS_VERSION_H_
namespace o3d {
-const int kSerializerVersion = 5;
+const int kSerializerVersion = 6;
}
#endif // O3D_SERIALIZER_CROSS_VERSION_H_