Commit 34f464fb authored by gman@google.com's avatar gman@google.com

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
parent e8b80d81
...@@ -94,6 +94,7 @@ bool Convert(const FilePath& in_filename, ...@@ -94,6 +94,7 @@ bool Convert(const FilePath& in_filename,
ErrorStatus error_status(&service_locator); ErrorStatus error_status(&service_locator);
Features features(&service_locator); Features features(&service_locator);
Collada::Init(&service_locator);
features.Init("MaxCapabilities"); features.Init("MaxCapabilities");
// Collect error messages. // Collect error messages.
...@@ -119,7 +120,8 @@ bool Convert(const FilePath& in_filename, ...@@ -119,7 +120,8 @@ bool Convert(const FilePath& in_filename,
collada_options.base_path = options.base_path; collada_options.base_path = options.base_path;
collada_options.up_axis = options.up_axis; collada_options.up_axis = options.up_axis;
Collada collada(pack.Get(), collada_options); Collada collada(pack.Get(), collada_options);
if (!collada.ImportFile(in_filename, root, param_float)) { bool result = collada.ImportFile(in_filename, root, param_float);
if (!result || !error_collector.errors().empty()) {
if (error_messages) { if (error_messages) {
*error_messages += error_collector.errors(); *error_messages += error_collector.errors();
} }
......
...@@ -44,6 +44,16 @@ ObjectBase::Class ObjectBase::class_ = { ...@@ -44,6 +44,16 @@ ObjectBase::Class ObjectBase::class_ = {
O3D_STRING_CONSTANT("ObjectBase"), NULL O3D_STRING_CONSTANT("ObjectBase"), NULL
}; };
const char* ObjectBase::Class::unqualified_name() const {
if (strncmp(
name_,
O3D_NAMESPACE O3D_NAMESPACE_SEPARATOR,
sizeof(O3D_NAMESPACE) + sizeof(O3D_NAMESPACE_SEPARATOR) - 2) == 0) {
return name_ + sizeof(O3D_NAMESPACE) + sizeof(O3D_NAMESPACE_SEPARATOR) - 2;
}
return name_;
}
ObjectBase::ObjectBase(ServiceLocator *service_locator) ObjectBase::ObjectBase(ServiceLocator *service_locator)
: id_(IdManager::CreateId()), : id_(IdManager::CreateId()),
service_locator_(service_locator) { service_locator_(service_locator) {
......
...@@ -50,11 +50,12 @@ ...@@ -50,11 +50,12 @@
#define O3D_STRING_CONSTANT(value) \ #define O3D_STRING_CONSTANT(value) \
(O3D_NAMESPACE O3D_NAMESPACE_SEPARATOR value) (O3D_NAMESPACE O3D_NAMESPACE_SEPARATOR value)
// This macro declares the necessary functions for the type mechanism to work. // This macro declares the necessary functions for the type mechanism to work.
// It needs to be used in each of the definition of any class that derives from // It needs to be used in each of the definition of any class that derives from
// ObjectBase. // ObjectBase.
// CLASS is the class being defined, BASE is its base class. // CLASS is the class being defined, BASE is its base class.
#define O3D_DECL_CLASS(CLASS, BASE) \ #define O3D_OBJECT_BASE_DECL_CLASS(CLASS, BASE) \
public: \ public: \
static const ObjectBase::Class *GetApparentClass() { return &class_; } \ static const ObjectBase::Class *GetApparentClass() { return &class_; } \
static const String GetApparentClassName() { \ static const String GetApparentClassName() { \
...@@ -72,10 +73,24 @@ ...@@ -72,10 +73,24 @@
// This macro defines the class descriptor for the type mechanism. It needs to // This macro defines the class descriptor for the type mechanism. It needs to
// be used once in the definition file of any class that derives from // be used once in the definition file of any class that derives from
// ObjectBase. // ObjectBase.
// CLASSNAME is the name to use to identify the class.
// CLASS is the class being defined.
// BASE is its base class.
#define O3D_OBJECT_BASE_DEFN_CLASS(CLASSNAME, CLASS, BASE) \
ObjectBase::Class CLASS::class_ = { CLASSNAME, BASE::GetApparentClass() };
// This macro declares the necessary functions for the type mechanism to work.
// It needs to be used in each of the definition of any class that derives from
// ObjectBase.
// CLASS is the class being defined, BASE is its base class. // CLASS is the class being defined, BASE is its base class.
#define O3D_DEFN_CLASS(CLASS, BASE) \ #define O3D_DECL_CLASS(CLASS, BASE) O3D_OBJECT_BASE_DECL_CLASS(CLASS, BASE)
ObjectBase::Class CLASS::class_ = \
{ O3D_STRING_CONSTANT(#CLASS), BASE::GetApparentClass() }; // This macro defines the class descriptor for the type mechanism. It needs to
// be used once in the definition file of any class that derives from
// ObjectBase.
// CLASS is the class being defined, BASE is its base class.
#define O3D_DEFN_CLASS(CLASS, BASE) \
O3D_OBJECT_BASE_DEFN_CLASS(O3D_STRING_CONSTANT(#CLASS), CLASS, BASE)
namespace o3d { namespace o3d {
...@@ -142,10 +157,7 @@ class ObjectBase : public RefCounted { ...@@ -142,10 +157,7 @@ class ObjectBase : public RefCounted {
return name_; return name_;
} }
const char* unqualified_name() const { const char* unqualified_name() const;
return name_ + sizeof(O3D_NAMESPACE) +
sizeof(O3D_NAMESPACE_SEPARATOR) - 2;
}
public: public:
// The name of the class. // The name of the class.
......
...@@ -89,6 +89,9 @@ bool StreamBank::SetVertexStream(Stream::Semantic stream_semantic, ...@@ -89,6 +89,9 @@ bool StreamBank::SetVertexStream(Stream::Semantic stream_semantic,
O3D_ERROR(service_locator()) << "No buffer on field"; O3D_ERROR(service_locator()) << "No buffer on field";
return false; return false;
} }
// Check that this buffer is renderable. StreamBanks are used to submit
// data to GPU so we can only allow GPU accessible buffers through here.
if (!buffer->IsA(VertexBuffer::GetApparentClass())) { if (!buffer->IsA(VertexBuffer::GetApparentClass())) {
O3D_ERROR(service_locator()) << "Buffer is not a VertexBuffer"; O3D_ERROR(service_locator()) << "Buffer is not a VertexBuffer";
return false; return false;
......
...@@ -64,6 +64,7 @@ else: ...@@ -64,6 +64,7 @@ else:
collada_inputs = [ collada_inputs = [
'cross/collada.cc', 'cross/collada.cc',
'cross/collada_zip_archive.cc', 'cross/collada_zip_archive.cc',
'cross/destination_buffer.cc',
'cross/zip_archive.cc', 'cross/zip_archive.cc',
'cross/gz_compressor.cc', 'cross/gz_compressor.cc',
'cross/file_output_stream_processor.cc', 'cross/file_output_stream_processor.cc',
......
This diff is collapsed.
...@@ -66,6 +66,7 @@ class FilePath; ...@@ -66,6 +66,7 @@ class FilePath;
namespace o3d { namespace o3d {
class ClassManager;
class ColladaZipArchive; class ColladaZipArchive;
class Effect; class Effect;
class IErrorStatus; class IErrorStatus;
...@@ -221,6 +222,9 @@ class Collada { ...@@ -221,6 +222,9 @@ class Collada {
std::vector<FilePath> GetOriginalDataFilenames() const; std::vector<FilePath> GetOriginalDataFilenames() const;
const std::string& GetOriginalData(const FilePath& filename) const; const std::string& GetOriginalData(const FilePath& filename) const;
// Init the Collada Importer.
static void Init(ServiceLocator* service_locator);
private: private:
// Imports the given ZIP file into the given pack. // Imports the given ZIP file into the given pack.
bool ImportZIP(const FilePath& filename, Transform* parent, bool ImportZIP(const FilePath& filename, Transform* parent,
...@@ -244,7 +248,7 @@ class Collada { ...@@ -244,7 +248,7 @@ class Collada {
// Recursively imports a tree of nodes from FCollada, rooted at the // Recursively imports a tree of nodes from FCollada, rooted at the
// given node, into the O3D scene. // given node, into the O3D scene.
void ImportTree(NodeInstance *instance, bool ImportTree(NodeInstance *instance,
Transform* parent, Transform* parent,
ParamFloat* animation_input); ParamFloat* animation_input);
...@@ -252,7 +256,7 @@ class Collada { ...@@ -252,7 +256,7 @@ class Collada {
// rooted at the given node, into the O3D scene. This is a separate step // rooted at the given node, into the O3D scene. This is a separate step
// from ImportTree because various kinds of instances can reference other // from ImportTree because various kinds of instances can reference other
// parts of the tree. // parts of the tree.
void ImportTreeInstances(FCDocument* doc, bool ImportTreeInstances(FCDocument* doc,
NodeInstance* instance); NodeInstance* instance);
bool BuildFloatAnimation(ParamFloat* result, bool BuildFloatAnimation(ParamFloat* result,
......
/*
* Copyright 2009, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "import/cross/destination_buffer.h"
namespace o3d {
O3D_OBJECT_BASE_DEFN_CLASS(
"o3djs.DestinationBuffer", DestinationBuffer, VertexBuffer);
DestinationBuffer::DestinationBuffer(ServiceLocator* service_locator)
: VertexBuffer(service_locator),
buffer_() {
}
DestinationBuffer::~DestinationBuffer() {
ConcreteFree();
}
void DestinationBuffer::ConcreteFree() {
buffer_.reset();
}
bool DestinationBuffer::ConcreteAllocate(size_t size_in_bytes) {
ConcreteFree();
buffer_.reset(new char[size_in_bytes]);
return true;
}
bool DestinationBuffer::ConcreteLock(AccessMode access_mode,
void **buffer_data) {
if (!buffer_.get()) {
return false;
}
*buffer_data = reinterpret_cast<void*>(buffer_.get());
return true;
}
bool DestinationBuffer::ConcreteUnlock() {
return buffer_.get() != NULL;
}
ObjectBase::Ref DestinationBuffer::Create(ServiceLocator* service_locator) {
return ObjectBase::Ref(new DestinationBuffer(service_locator));
}
} // namespace o3d
/*
* Copyright 2009, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// This file declares the DestinationBuffer class.
#ifndef O3D_IMPORT_CROSS_DESTINATION_BUFFER_H_
#define O3D_IMPORT_CROSS_DESTINATION_BUFFER_H_
#include "core/cross/buffer.h"
namespace o3d {
// DestinationBuffer is a used for serialization only and is not part of the
// normal O3D plugin. It is used for Skinning to distinguish between a normal
// VertexBuffer that needs to have its contents serialized and a
// DestinationBuffer that only needs to know its structure but not its
// contents.
class DestinationBuffer : public VertexBuffer {
public:
typedef SmartPointer<DestinationBuffer> Ref;
~DestinationBuffer();
protected:
// Overridden from Buffer.
virtual bool ConcreteAllocate(size_t size_in_bytes);
// Overridden from Buffer.
virtual bool ConcreteLock(AccessMode access_mode, void **buffer_data);
// Overridden from Buffer.
virtual bool ConcreteUnlock();
explicit DestinationBuffer(ServiceLocator* service_locator);
protected:
// Frees the buffer if it exists.
void ConcreteFree();
private:
friend class IClassManager;
static ObjectBase::Ref Create(ServiceLocator* service_locator);
scoped_array<char> buffer_; // The actual data for this buffer.
O3D_OBJECT_BASE_DECL_CLASS(DestinationBuffer, VertexBuffer);
DISALLOW_COPY_AND_ASSIGN(DestinationBuffer);
};
} // namespace o3d
#endif // O3D_IMPORT_CROSS_DESTINATION_BUFFER_H_
/*
* Copyright 2009, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "tests/common/win/testing_common.h"
#include "import/cross/destination_buffer.h"
#include "core/cross/class_manager.h"
#include "core/cross/object_manager.h"
#include "core/cross/pack.h"
#include "core/cross/service_dependency.h"
namespace o3d {
class DestinationBufferTest : public testing::Test {
protected:
DestinationBufferTest()
: class_manager_(g_service_locator),
object_manager_(g_service_locator) {
class_manager_->AddTypedClass<DestinationBuffer>();
}
virtual void SetUp();
virtual void TearDown();
Pack* pack() { return pack_; }
private:
ServiceDependency<ClassManager> class_manager_;
ServiceDependency<ObjectManager> object_manager_;
Pack* pack_;
};
void DestinationBufferTest::SetUp() {
pack_ = object_manager_->CreatePack();
}
void DestinationBufferTest::TearDown() {
object_manager_->DestroyPack(pack_);
}
// Creates a Destination buffer, tests basic properties, and checks that writing
// then reading data works.
TEST_F(DestinationBufferTest, TestDestinationBuffer) {
Buffer *buffer = pack()->Create<DestinationBuffer>();
EXPECT_TRUE(buffer->IsA(DestinationBuffer::GetApparentClass()));
EXPECT_TRUE(buffer->IsA(VertexBuffer::GetApparentClass()));
EXPECT_TRUE(buffer->IsA(Buffer::GetApparentClass()));
const size_t kSize = 100;
Field* field = buffer->CreateField(UInt32Field::GetApparentClass(), 1);
ASSERT_TRUE(field != NULL);
ASSERT_TRUE(buffer->AllocateElements(kSize));
EXPECT_EQ(kSize * sizeof(uint32), buffer->GetSizeInBytes()); // NOLINT
// Put some data into the buffer.
uint32 *data = NULL;
ASSERT_TRUE(buffer->LockAs(Buffer::WRITE_ONLY, &data));
ASSERT_TRUE(data != NULL);
for (uint32 i = 0; i < kSize; ++i) {
data[i] = i;
}
ASSERT_TRUE(buffer->Unlock());
data = NULL;
// Read the data from the buffer, checks that it's the expected values.
ASSERT_TRUE(buffer->LockAs(Buffer::READ_ONLY, &data));
ASSERT_TRUE(data != NULL);
for (uint32 i = 0; i < kSize; ++i) {
EXPECT_EQ(i, data[i]);
}
ASSERT_TRUE(buffer->Unlock());
}
} // namespace o3d
...@@ -96,6 +96,20 @@ o3djs.serialization.Deserializer = function(pack, json) { ...@@ -96,6 +96,20 @@ o3djs.serialization.Deserializer = function(pack, json) {
* @type {!Object} * @type {!Object}
*/ */
this.createCallbacks = { this.createCallbacks = {
'o3djs.DestinationBuffer': function(deserializer, json) {
var object = deserializer.pack.createObject('o3d.VertexBuffer');
if ('custom' in json) {
for (var i = 0; i < json.custom.fields.length; ++i) {
var fieldInfo = json.custom.fields[i]
var field = object.createField(fieldInfo.type,
fieldInfo.numComponents);
deserializer.addObject(fieldInfo.id, field);
}
object.allocateElements(json.custom.numElements);
}
return object;
},
'o3d.VertexBuffer': function(deserializer, json) { 'o3d.VertexBuffer': function(deserializer, json) {
var object = deserializer.pack.createObject('o3d.VertexBuffer'); var object = deserializer.pack.createObject('o3d.VertexBuffer');
if ('custom' in json) { if ('custom' in json) {
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include "core/cross/skin.h" #include "core/cross/skin.h"
#include "core/cross/texture.h" #include "core/cross/texture.h"
#include "core/cross/transform.h" #include "core/cross/transform.h"
#include "import/cross/destination_buffer.h"
#include "import/cross/iarchive_generator.h" #include "import/cross/iarchive_generator.h"
#include "import/cross/memory_buffer.h" #include "import/cross/memory_buffer.h"
#include "import/cross/memory_stream.h" #include "import/cross/memory_stream.h"
...@@ -345,6 +346,7 @@ class CustomVisitor : public VisitorBase<CustomVisitor> { ...@@ -345,6 +346,7 @@ class CustomVisitor : public VisitorBase<CustomVisitor> {
BinaryArchiveManager* binary_archive_manager) BinaryArchiveManager* binary_archive_manager)
: writer_(writer), : writer_(writer),
binary_archive_manager_(binary_archive_manager) { binary_archive_manager_(binary_archive_manager) {
Enable<DestinationBuffer>(&CustomVisitor::Visit);
Enable<Buffer>(&CustomVisitor::Visit); Enable<Buffer>(&CustomVisitor::Visit);
Enable<Curve>(&CustomVisitor::Visit); Enable<Curve>(&CustomVisitor::Visit);
Enable<Primitive>(&CustomVisitor::Visit); Enable<Primitive>(&CustomVisitor::Visit);
...@@ -356,6 +358,31 @@ class CustomVisitor : public VisitorBase<CustomVisitor> { ...@@ -356,6 +358,31 @@ class CustomVisitor : public VisitorBase<CustomVisitor> {
} }
private: 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) { void Visit(Buffer* buffer) {
Visit(static_cast<NamedObject*>(buffer)); Visit(static_cast<NamedObject*>(buffer));
...@@ -585,6 +612,7 @@ class BinaryVisitor : public VisitorBase<BinaryVisitor> { ...@@ -585,6 +612,7 @@ class BinaryVisitor : public VisitorBase<BinaryVisitor> {
: binary_archive_manager_(binary_archive_manager) { : binary_archive_manager_(binary_archive_manager) {
Enable<Curve>(&BinaryVisitor::Visit); Enable<Curve>(&BinaryVisitor::Visit);
Enable<IndexBuffer>(&BinaryVisitor::Visit); Enable<IndexBuffer>(&BinaryVisitor::Visit);
Enable<DestinationBuffer>(&BinaryVisitor::Visit);
Enable<VertexBufferBase>(&BinaryVisitor::Visit); Enable<VertexBufferBase>(&BinaryVisitor::Visit);
Enable<Skin>(&BinaryVisitor::Visit); Enable<Skin>(&BinaryVisitor::Visit);
} }
...@@ -608,6 +636,11 @@ class BinaryVisitor : public VisitorBase<BinaryVisitor> { ...@@ -608,6 +636,11 @@ class BinaryVisitor : public VisitorBase<BinaryVisitor> {
serialized_data.GetLength()); serialized_data.GetLength());
} }
void Visit(DestinationBuffer* buffer) {
// Destination buffers should NOT have their contents serialized.
Visit(static_cast<Buffer*>(buffer));
}
void Visit(IndexBuffer* buffer) { void Visit(IndexBuffer* buffer) {
Visit(static_cast<Buffer*>(buffer)); Visit(static_cast<Buffer*>(buffer));
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
#define O3D_SERIALIZER_CROSS_VERSION_H_ #define O3D_SERIALIZER_CROSS_VERSION_H_
namespace o3d { namespace o3d {
const int kSerializerVersion = 5; const int kSerializerVersion = 6;
} }
#endif // O3D_SERIALIZER_CROSS_VERSION_H_ #endif // O3D_SERIALIZER_CROSS_VERSION_H_
...@@ -217,6 +217,7 @@ tests = [ ...@@ -217,6 +217,7 @@ tests = [
'core/cross/vertex_source_test.cc', 'core/cross/vertex_source_test.cc',
'core/cross/visitor_base_test.cc', 'core/cross/visitor_base_test.cc',
'core/cross/weak_ptr_test.cc', 'core/cross/weak_ptr_test.cc',
'import/cross/destination_buffer_test.cc',
'import/cross/gz_compressor_test.cc', 'import/cross/gz_compressor_test.cc',
'import/cross/gz_decompressor_test.cc', 'import/cross/gz_decompressor_test.cc',
'import/cross/memory_buffer_test.cc', 'import/cross/memory_buffer_test.cc',
...@@ -458,10 +459,10 @@ if ARGUMENTS.get('SYSTEM_TESTS_ENABLED', False): ...@@ -458,10 +459,10 @@ if ARGUMENTS.get('SYSTEM_TESTS_ENABLED', False):
# Also require gl related libraries based on variant. # Also require gl related libraries based on variant.
system_tests_req += gl_requirements system_tests_req += gl_requirements
# Require SwiftShader (only if it is available). # Require SwiftShader (only if it is available).
system_tests_req += swiftshader_install system_tests_req += swiftshader_install
# Add requirements for system_tests. # Add requirements for system_tests.
env.Requires(system_tests_install, system_tests_req) env.Requires(system_tests_install, system_tests_req)
...@@ -542,7 +543,7 @@ selenium_good_to_go = True ...@@ -542,7 +543,7 @@ selenium_good_to_go = True
if run_env.Bit('mac'): if run_env.Bit('mac'):
plugin_path = '$ARTIFACTS_DIR/O3D.plugin' plugin_path = '$ARTIFACTS_DIR/O3D.plugin'
if run_env['MAC_HERMETIC_FIREFOX_DIR']: if run_env['MAC_HERMETIC_FIREFOX_DIR']:
# if we have a hermetic version of Firefox, then run it # if we have a hermetic version of Firefox, then run it
if os.path.exists(run_env.subst('$MAC_HERMETIC_FIREFOX_DIR')): if os.path.exists(run_env.subst('$MAC_HERMETIC_FIREFOX_DIR')):
...@@ -579,7 +580,7 @@ if run_env.Bit('mac'): ...@@ -579,7 +580,7 @@ if run_env.Bit('mac'):
cleanup_steps = [ cleanup_steps = [
'rm -rf "$MAC_FIREFOX_DIR"', 'rm -rf "$MAC_FIREFOX_DIR"',
] ]
def DeferSelenium(env): def DeferSelenium(env):
if not selenium_good_to_go: if not selenium_good_to_go:
...@@ -604,7 +605,7 @@ def DeferSelenium(env): ...@@ -604,7 +605,7 @@ def DeferSelenium(env):
'--screenshotsdir=$ARTIFACTS_DIR/selenium/screenshots_firefox'])] + '--screenshotsdir=$ARTIFACTS_DIR/selenium/screenshots_firefox'])] +
cleanup_steps, cleanup_steps,
) )
# Require SwiftShader (only if it is available). # Require SwiftShader (only if it is available).
run_env.Requires(run_selenium_firefox, swiftshader_install) run_env.Requires(run_selenium_firefox, swiftshader_install)
......
...@@ -929,6 +929,44 @@ g_suite.testShouldSetVertexBufferData = function() { ...@@ -929,6 +929,44 @@ g_suite.testShouldSetVertexBufferData = function() {
g_test.assertEquals(12, field.size); g_test.assertEquals(12, field.size);
}; };
g_suite.testShouldSetDestinationBufferData = function() {
var json = {
version: o3djs.serialization.supportedVersion,
objects: {
'o3djs.DestinationBuffer': [
{
'custom':{
'numElements':1398,
'fields':[
{
'id':197809,
'type':'o3d.FloatField',
'numComponents':3},
{
'id':197813,
'type':'o3d.FloatField',
'numComponents':3}]
}
}
]
}
};
var pack = g_client.createPack();
var deserializer = o3djs.serialization.createDeserializer(pack, json);
deserializer.archiveInfo = g_archiveInfo;
deserializer.run();
g_test.assertEquals(1, pack.objects.length);
var buffer = pack.objects[0];
g_test.assertEquals(1398, buffer.numElements);
g_test.assertEquals(2, buffer.fields.length);
var field = buffer.fields[0];
g_test.assertEquals('o3d.FloatField', field.className);
g_test.assertEquals(3, field.numComponents);
g_test.assertEquals(12, field.size);
};
g_suite.testShouldSetSourceBufferData = function() { g_suite.testShouldSetSourceBufferData = function() {
var json = { var json = {
version: o3djs.serialization.supportedVersion, version: o3djs.serialization.supportedVersion,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment