summaryrefslogtreecommitdiffstats
path: root/o3d/converter_edge
diff options
context:
space:
mode:
authoryux@google.com <yux@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-14 21:49:59 +0000
committeryux@google.com <yux@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-14 21:49:59 +0000
commit857cb0f878e570f81e6a09695ee392ec78e0e164 (patch)
treec7fdd40a0b348d2eeab1374705a1138f9319783e /o3d/converter_edge
parent0f51d4a28303ed8f44e62b879e8c9d26a64439ce (diff)
downloadchromium_src-857cb0f878e570f81e6a09695ee392ec78e0e164.zip
chromium_src-857cb0f878e570f81e6a09695ee392ec78e0e164.tar.gz
chromium_src-857cb0f878e570f81e6a09695ee392ec78e0e164.tar.bz2
Duplicate converter with add extra edge feature.
Review URL: http://codereview.chromium.org/164488 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23466 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/converter_edge')
-rw-r--r--o3d/converter_edge/README.converter_edge59
-rw-r--r--o3d/converter_edge/build.scons152
-rw-r--r--o3d/converter_edge/cross/buffer_stub.cc87
-rw-r--r--o3d/converter_edge/cross/buffer_stub.h112
-rw-r--r--o3d/converter_edge/cross/converter.cc639
-rw-r--r--o3d/converter_edge/cross/converter.h139
-rw-r--r--o3d/converter_edge/cross/converter_main.cc180
-rw-r--r--o3d/converter_edge/cross/draw_element_stub.h58
-rw-r--r--o3d/converter_edge/cross/effect_stub.h73
-rw-r--r--o3d/converter_edge/cross/param_cache_stub.h69
-rw-r--r--o3d/converter_edge/cross/primitive_stub.h71
-rw-r--r--o3d/converter_edge/cross/render_surface_stub.h75
-rw-r--r--o3d/converter_edge/cross/renderer_stub.cc204
-rw-r--r--o3d/converter_edge/cross/renderer_stub.h123
-rw-r--r--o3d/converter_edge/cross/sampler_stub.h53
-rw-r--r--o3d/converter_edge/cross/stream_bank_stub.h51
-rw-r--r--o3d/converter_edge/cross/texture_stub.cc51
-rw-r--r--o3d/converter_edge/cross/texture_stub.h174
-rw-r--r--o3d/converter_edge/cross/verifier_main.cc106
-rw-r--r--o3d/converter_edge/mac/converter_main.mm49
20 files changed, 2525 insertions, 0 deletions
diff --git a/o3d/converter_edge/README.converter_edge b/o3d/converter_edge/README.converter_edge
new file mode 100644
index 0000000..17edbf4
--- /dev/null
+++ b/o3d/converter_edge/README.converter_edge
@@ -0,0 +1,59 @@
+The converter is a command line utility that will convert from COLLADA
+to the form that the sample JavaScript scene loader (in
+samples/o3djs/serialization.js) can read.
+
+It is able to read COLLADA files as either DAE text files (and
+associated asset files in subdirectories), or as part of a ZIP archive
+(or KMZ file). It outputs a gzip-compressed tar archive (.tgz) which
+contains a JSON file and any associated assets (textures, shaders,
+etc.) from the source COLLADA model. By default we don't use the .tgz
+extension, as it can cause problems with some webservers; we put .o3dtgz on
+instead.
+
+In order to run the converter on Windows, you need the DirectX SDK installed.
+Installing it requires administrator privileges. You can get it here:
+http://msdn.microsoft.com/en-us/library/bb219737(VS.85).aspx.
+
+The command line arguments are as follows:
+
+Usage: o3dConverter.exe [--base-path=<path>]
+ [--up-axis=x,y,z]
+ [--no-condition]
+ [--pretty-print]
+ [--sharp-edge-threshold=<threshold>]
+ [--sharp-edge-color=r,g,b]
+ <infile.dae> [ <outfile> ]
+
+--base-path=<path>: This specifies the path elements to remove from
+ the beginning of the filenames placed into the
+ .o3dtgz file (to avoid including sensitive paths in
+ the .o3dtgz file).
+
+--up-axis=x,y,z: This specifies the up-axis for the resulting model,
+ if you wish it to be different from the axis in the
+ COLLADA file.
+
+--pretty-print: This simply formats the JSON file in the resulting
+ .o3dtgz file to be human readable, instead of compacted
+ into one line.
+
+--no-condition: This will prevent conditioning of the shaders from
+ COLLADA form to the form expected by O3D. [This is
+ useful only for pre-release data conditioned before
+ the converter existed.]
+
+--sharp-edge-threshold=<threshold>: Adds edges with normal angle
+ larger than <threshold>.
+
+--sharp-edge-color=r,g,b: Specify color of the additional edges,
+ (value 0 to 1).Default value is 1,0,0.
+
+<infile.dae|infile.zip|infile.kmz>: This is the input file in one of
+ ZIP, KMZ, or DAE formats. The
+ DAE format expects to find assets
+ relative to the .dae file.
+
+<outfile>: An optional argument giving the name of the
+ gzip-compressed tar archive output file. By default
+ this has the same basename as the input file, and has the extension
+ .o3dtgz.
diff --git a/o3d/converter_edge/build.scons b/o3d/converter_edge/build.scons
new file mode 100644
index 0000000..283502b
--- /dev/null
+++ b/o3d/converter_edge/build.scons
@@ -0,0 +1,152 @@
+# 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.
+
+
+Import('env')
+
+env.Append(
+ LIBPATH = [
+ '$NACL_LIB_DIR',
+ '$ANTLRLIBC_DIR/lib',
+ '$OBJ_ROOT/compiler/technique',
+ '$OBJ_ROOT/compiler/antlr',
+ '$CG_DIR/lib',
+ ],
+ LIBS = [
+ 'o3dConvertEdge',
+ 'o3dCore',
+ 'o3dArchive',
+ 'o3dImport',
+ 'o3dImportConditioner',
+ 'o3dCorePlatform',
+ 'o3dSerializer',
+ 'o3dSerializationObjects',
+ 'o3dUtils',
+ 'o3d_base',
+ 'FColladaU',
+ 'technique',
+ 'antlr3c',
+ 'google_nacl_imc',
+ 'skia',
+ ] + env['ICU_LIBS'],
+)
+
+# add renderer specific libraries and includes to the linker environment
+env.Append(CPPPATH = env['RENDERER_INCLUDE_PATH'],
+ LIBPATH = env['RENDERER_LIB_PATH'],
+ LIBS = env['RENDERER_LIBS'])
+
+if env.Bit('windows'):
+ env.Append(
+ CCFLAGS=['/Wp64', '/D_CRT_SECURE_NO_WARNINGS'],
+ LINKFLAGS=['/SUBSYSTEM:CONSOLE'],
+ LIBS = [
+ 'cg',
+ 'cgGL',
+ 'd3dx9',
+ 'ole32',
+ ],
+ )
+
+if env.Bit('mac'):
+ env.Append(
+ LINKFLAGS = ['-F$CG_DIR'],
+ FRAMEWORKS = [
+ 'ApplicationServices',
+ 'Cg',
+ 'Foundation',
+ 'OpenGL',
+ ],
+ )
+
+inputs = [
+ 'cross/converter.cc',
+ 'cross/renderer_stub.cc',
+ 'cross/buffer_stub.cc',
+ 'cross/texture_stub.cc',
+ ]
+
+# Create converter library.
+lib = env.ComponentLibrary('o3dConvertEdge', inputs)
+
+# Create a target executable program called 'o3dConverterEdge'
+if env.Bit('mac'):
+ exe = env.ComponentProgram('o3dConverterEdge',
+ ['mac/converter_main.mm',
+ 'cross/converter_main.cc',
+ ])
+ # Fix executable to look for Cg.framework in the appropriate place.
+ exe_fix = env.Command('$ARTIFACTS_DIR/converter/fixed_exe.stamp',
+ [exe], [
+ '/usr/bin/install_name_tool'
+ ' -change '
+ '@executable_path/../Library/Frameworks/Cg.framework/Cg '
+ '@executable_path/Frameworks/Cg.framework/Cg '
+ "$SOURCE",
+ 'touch $TARGET',
+ ])
+ # Copy the resulting executable to the Artifacts directory.
+ exe_install = env.Replicate('$ARTIFACTS_DIR/converter', [exe])
+ env.Depends(exe_install, exe_fix)
+else:
+ exe = env.ComponentProgram('o3dConverterEdge', ['cross/converter_main.cc'])
+ # Copy the resulting executable to the Artifacts directory.
+ exe_install = env.Replicate('$ARTIFACTS_DIR', [exe])
+
+# Put the Cg DLL's, cgc and the d3dx9 DLL there as well.
+if env.Bit('windows'):
+ env.Requires(exe_install, env.Replicate(
+ '$ARTIFACTS_DIR', [
+ '$CG_DIR/bin/cgc.exe',
+ '$CG_DIR/bin/cg.dll',
+ '$CG_DIR/bin/cgGL.dll',
+ ]))
+
+if env.Bit('mac'):
+ env.Requires(
+ exe_install,
+ env.Command(env.Dir('$ARTIFACTS_DIR/converter/Frameworks'),
+ env.Dir("$CG_DIR/Cg.framework"),
+ [ # Copy in a Cg framework for the converter to use.
+ 'ditto --arch i386 "$CG_DIR/Cg.framework" '
+ '"$ARTIFACTS_DIR/converter/Frameworks/Cg.framework"',
+ ]))
+ env.Requires(exe_install, env.Replicate(
+ '$ARTIFACTS_DIR/converter', [
+ '$CG_DIR/bin/cgc',
+ ]))
+
+if env.Bit('linux'):
+ env.Requires(exe_install, env.Replicate(
+ '$ARTIFACTS_DIR', [
+ '$CG_DIR/bin/cgc',
+ '$CG_DIR/lib/libCg.so',
+ '$CG_DIR/lib/libCgGL.so',
+ '$GLEW_DIR/lib/libGLEW.so.1.5',
+ ]))
diff --git a/o3d/converter_edge/cross/buffer_stub.cc b/o3d/converter_edge/cross/buffer_stub.cc
new file mode 100644
index 0000000..1549939
--- /dev/null
+++ b/o3d/converter_edge/cross/buffer_stub.cc
@@ -0,0 +1,87 @@
+/*
+ * 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 contains the definition of the VertexBufferStub and
+// IndexBufferStub classes.
+
+#include "converter_edge/cross/buffer_stub.h"
+
+namespace o3d {
+
+bool VertexBufferStub::ConcreteAllocate(size_t size_in_bytes) {
+ buffer_.reset(new int8[size_in_bytes]);
+ return true;
+}
+
+void VertexBufferStub::ConcreteFree() {
+ buffer_.reset();
+}
+
+bool VertexBufferStub::ConcreteLock(AccessMode access_mode,
+ void** buffer_data) {
+ *buffer_data = buffer_.get();
+ DCHECK(locked_ == false);
+ locked_ = true;
+ return (buffer_.get() != NULL);
+}
+
+bool VertexBufferStub::ConcreteUnlock() {
+ bool status = locked_;
+ DCHECK(locked_ == true);
+ locked_ = false;
+ return status;
+}
+
+bool IndexBufferStub::ConcreteAllocate(size_t size_in_bytes) {
+ buffer_.reset(new int8[size_in_bytes]);
+ return true;
+}
+
+void IndexBufferStub::ConcreteFree() {
+ buffer_.reset();
+}
+
+bool IndexBufferStub::ConcreteLock(AccessMode access_mode, void** buffer_data) {
+ *buffer_data = buffer_.get();
+ DCHECK(locked_ == false);
+ locked_ = true;
+ return (buffer_.get() != NULL);
+}
+
+bool IndexBufferStub::ConcreteUnlock() {
+ bool status = locked_;
+ DCHECK(locked_ == true);
+ locked_ = false;
+ return status;
+}
+
+} // end namespace o3d
diff --git a/o3d/converter_edge/cross/buffer_stub.h b/o3d/converter_edge/cross/buffer_stub.h
new file mode 100644
index 0000000..d1da197
--- /dev/null
+++ b/o3d/converter_edge/cross/buffer_stub.h
@@ -0,0 +1,112 @@
+/*
+ * 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 contains the declaration of the platform specific
+// VertexBufferStub and IndexBufferStub objects used by O3D
+
+#ifndef O3D_CONVERTER_EDGE_CROSS_BUFFER_STUB_H_
+#define O3D_CONVERTER_EDGE_CROSS_BUFFER_STUB_H_
+
+#include "base/basictypes.h"
+#include "base/scoped_ptr.h"
+#include "core/cross/buffer.h"
+
+namespace o3d {
+
+// VertexBufferStub is a wrapper around an Stub Vertex Buffer Object (VBO).
+// The buffer starts out empty. Calling Allocate() will reserve video memory
+// for the buffer. Buffer contents are are updated by calling Lock() to get a
+// pointer to the memory allocated for the buffer, updating that data in place
+// and calling Unlock() to notify Stub that the edits are done.
+
+class VertexBufferStub : public VertexBuffer {
+ public:
+ explicit VertexBufferStub(ServiceLocator* service_locator)
+ : VertexBuffer(service_locator), locked_(false) {}
+ ~VertexBufferStub() {}
+
+ protected:
+ // Creates a Stub vertex buffer object of the specified size.
+ virtual bool ConcreteAllocate(size_t size_in_bytes);
+
+ // Frees the buffer.
+ virtual void ConcreteFree();
+
+ // Returns a pointer to the current contents of the buffer. A matching
+ // call to Unlock is necessary to update the contents of the buffer.
+ virtual bool ConcreteLock(AccessMode access_mode, void** buffer_data);
+
+ // Notifies Stub that the buffer data has been updated. Unlock is only
+ // valid if it follows a Lock operation.
+ virtual bool ConcreteUnlock();
+ private:
+ scoped_array<int8> buffer_;
+ bool locked_;
+
+ DISALLOW_COPY_AND_ASSIGN(VertexBufferStub);
+};
+
+// IndexBufferStub is a wrapper around a Stub Index Buffer Object.
+// The buffer starts out empty. A call to Allocate() will create a stub
+// index buffer of the requested size. Updates the to the contents of the
+// buffer are done via the Lock/Unlock calls.
+class IndexBufferStub : public IndexBuffer {
+ public:
+ explicit IndexBufferStub(ServiceLocator* service_locator)
+ : IndexBuffer(service_locator), locked_(false) {}
+ ~IndexBufferStub() {}
+
+ protected:
+ // Creates a OpenGL index buffer of the specified size.
+ virtual bool ConcreteAllocate(size_t size_in_bytes);
+
+ // Frees the buffer.
+ virtual void ConcreteFree();
+
+ // Returns a pointer to the current contents of the buffer. After calling
+ // Lock, the contents of the buffer can be updated in place.
+ virtual bool ConcreteLock(AccessMode access_mode, void** buffer_data);
+
+ // Notifies OpenGL that the buffer data has been updated. Unlock is only
+ // valid if it follows a Lock operation.
+ virtual bool ConcreteUnlock();
+ private:
+ scoped_array<int8> buffer_;
+ bool locked_;
+
+ DISALLOW_COPY_AND_ASSIGN(IndexBufferStub);
+};
+
+} // namespace o3d
+
+
+#endif // O3D_CONVERTER_EDGE_CROSS_BUFFER_STUB_H_
diff --git a/o3d/converter_edge/cross/converter.cc b/o3d/converter_edge/cross/converter.cc
new file mode 100644
index 0000000..8936213
--- /dev/null
+++ b/o3d/converter_edge/cross/converter.cc
@@ -0,0 +1,639 @@
+/*
+ * 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 contains the logic for converting the scene graph to a
+// JSON-encoded file that is stored in a zip archive.
+#include "converter_edge/cross/converter.h"
+
+#include <cmath>
+#include <map>
+#include <utility>
+
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/scoped_ptr.h"
+#include "core/cross/class_manager.h"
+#include "core/cross/client.h"
+#include "core/cross/client_info.h"
+#include "core/cross/effect.h"
+#include "core/cross/error.h"
+#include "core/cross/features.h"
+#include "core/cross/object_manager.h"
+#include "core/cross/pack.h"
+#include "core/cross/renderer.h"
+#include "core/cross/service_locator.h"
+#include "core/cross/transform.h"
+#include "core/cross/tree_traversal.h"
+#include "core/cross/types.h"
+#include "core/cross/primitive.cc"
+#include "import/cross/collada.h"
+#include "import/cross/collada_conditioner.h"
+#include "import/cross/file_output_stream_processor.h"
+#include "import/cross/targz_generator.h"
+#include "import/cross/archive_request.h"
+#include "serializer/cross/serializer.h"
+#include "utils/cross/file_path_utils.h"
+#include "utils/cross/json_writer.h"
+#include "utils/cross/string_writer.h"
+#include "utils/cross/temporary_file.h"
+
+namespace o3d {
+
+namespace {
+static const float kPi = 3.14159265358979f;
+static const float kEpsilon = 0.0001f;
+
+void AddBinaryElements(const Collada& collada,
+ TarGzGenerator* archive_generator) {
+ const ColladaDataMap& data_map(collada.original_data_map());
+ std::vector<FilePath> paths = data_map.GetOriginalDataFilenames();
+ for (std::vector<FilePath>::const_iterator iter = paths.begin();
+ iter != paths.end();
+ ++iter) {
+ const std::string& data = data_map.GetOriginalData(*iter);
+
+ archive_generator->AddFile(FilePathToUTF8(*iter), data.size());
+ archive_generator->AddFileBytes(
+ reinterpret_cast<const uint8*>(data.c_str()),
+ data.length());
+ }
+}
+} // end anonymous namespace
+
+namespace converter {
+// Constructor, make sure points order is unique.
+// If x-coordinates are the same, compare y-coordinate.
+// If y values are also the same, compare z.
+Edge::Edge(Point3 p1, Point3 p2) {
+ bool isRightOrder = false;
+ if (fabs(p1.getX() - p2.getX()) < kEpsilon) {
+ if (fabs(p1.getY() - p2.getY()) < kEpsilon) {
+ if (p1.getZ() < p2.getZ())
+ isRightOrder = true;
+ } else {
+ if (p1.getY() < p2.getY())
+ isRightOrder = true;
+ }
+ } else {
+ if (p1.getX() < p2.getX())
+ isRightOrder = true;
+ }
+ if (isRightOrder) {
+ pts.push_back(p1);
+ pts.push_back(p2);
+ } else {
+ pts.push_back(p2);
+ pts.push_back(p1);
+ }
+}
+
+// less than operator overload, necessary function for edge-triangle map.
+bool operator<(const Edge& left, const Edge& right) {
+ // compare two edges by their actually coordinates, not indices.
+ // Beceause two different indices may point to one actually coordinates.
+ if (dist(left.pts[0], right.pts[0]) < kEpsilon) {
+ if (fabs(left.pts[1].getX() - right.pts[1].getX()) < kEpsilon) {
+ if (fabs(left.pts[1].getY() - right.pts[1].getY()) < kEpsilon) {
+ return left.pts[1].getZ() < right.pts[1].getZ();
+ }
+ return left.pts[1].getY() < right.pts[1].getY();
+ }
+ return left.pts[1].getX() < right.pts[1].getX();
+ } else {
+ if (fabs(left.pts[0].getX() - right.pts[0].getX()) < kEpsilon) {
+ if (fabs(left.pts[0].getY() - right.pts[0].getY()) < kEpsilon) {
+ return left.pts[0].getZ() < right.pts[0].getZ();
+ }
+ return left.pts[0].getY() < right.pts[0].getY();
+ }
+ return left.pts[0].getX() < right.pts[0].getX();
+ }
+}
+
+void CheckSharpEdge(const Edge& shared_edge,
+ const std::vector<Triangle>& triangle_list,
+ std::vector<Edge>* sharp_edges, float threshold) {
+ for (size_t i = 0; i < triangle_list.size(); i++)
+ for (size_t j = i + 1; j < triangle_list.size(); j++) {
+ Triangle t1 = triangle_list[i];
+ Triangle t2 = triangle_list[j];
+ int same_vertices_count = 0;
+ // Same triangle might be stored twice to represent inner and outer faces.
+ // Check the order of indices of vertices to not mix inner and outer faces
+ // togeter.
+ std::vector<int> same_vertices_pos;
+ for (int k = 0; k < 3; k++)
+ for (int l = 0; l < 3; l++) {
+ if (dist(t1.pts[k], t2.pts[l]) < kEpsilon) {
+ same_vertices_count++;
+ same_vertices_pos.push_back(k);
+ same_vertices_pos.push_back(l);
+ }
+ }
+ if (same_vertices_count != 2)
+ continue;
+ // check the order of positions to make sure triangles are on
+ // the same face.
+ int i1 = same_vertices_pos[2] - same_vertices_pos[0];
+ int i2 = same_vertices_pos[3] - same_vertices_pos[1];
+ // if triangles are on different faces.
+ if (!(i1 * i2 == -1 || i1 * i2 == 2 || i1 * i2 == -4))
+ continue;
+
+ Vector3 v12 = t1.pts[1] - t1.pts[0];
+ Vector3 v13 = t1.pts[2] - t1.pts[0];
+ Vector3 n1 = cross(v12, v13);
+ Vector3 v22 = t2.pts[1] - t2.pts[0];
+ Vector3 v23 = t2.pts[2] - t2.pts[0];
+ Vector3 n2 = cross(v22, v23);
+ float iAngle = acos(dot(n1, n2) / (length(n1) * length(n2)));
+ iAngle = iAngle * 180 / kPi;
+ if (iAngle >= threshold) {
+ sharp_edges->push_back(shared_edge);
+ return;
+ }
+ }
+}
+
+// create a single color material and effect and attach it to
+// sharp edge primitive.
+Material* GetSingleColorMaterial(Pack::Ref pack, const Vector3& edge_color) {
+ Material* singleColorMaterial = pack->Create<Material>();
+ singleColorMaterial->set_name("singleColorMaterial");
+ ParamString* lighting_param = singleColorMaterial->CreateParam<ParamString>(
+ Collada::kLightingTypeParamName);
+ lighting_param->set_value(Collada::kLightingTypeConstant);
+ ParamFloat4* emissive_param = singleColorMaterial->CreateParam<ParamFloat4>(
+ Collada::kMaterialParamNameEmissive);
+ emissive_param->set_value(Float4(edge_color.getX(), edge_color.getY(),
+ edge_color.getZ(), 1));
+
+ return singleColorMaterial;
+}
+
+// insert edge-triangle pair to edge triangle map.
+void InsertEdgeTrianglePair(const Edge& edge, const Triangle& triangle,
+ std::map<Edge, std::vector<Triangle>>* et_map) {
+ std::map<Edge, std::vector<Triangle>>::iterator iter1 =
+ et_map->find(edge);
+ if (iter1 == et_map->end()) {
+ std::vector<Triangle> same_edge_triangle_list;
+ same_edge_triangle_list.push_back(triangle);
+ et_map->insert(make_pair(edge, same_edge_triangle_list));
+ } else {
+ iter1->second.push_back(triangle);
+ }
+}
+
+// Loads the Collada input file and writes it to the zipped JSON output file.
+bool Convert(const FilePath& in_filename,
+ const FilePath& out_filename,
+ const Options& options,
+ String *error_messages) {
+ // Create a service locator and renderer.
+ ServiceLocator service_locator;
+ EvaluationCounter evaluation_counter(&service_locator);
+ ClassManager class_manager(&service_locator);
+ ClientInfoManager client_info_manager(&service_locator);
+ ObjectManager object_manager(&service_locator);
+ Profiler profiler(&service_locator);
+ ErrorStatus error_status(&service_locator);
+ Features features(&service_locator);
+
+ Collada::Init(&service_locator);
+ features.Init("MaxCapabilities");
+
+ // Collect error messages.
+ ErrorCollector error_collector(&service_locator);
+
+ scoped_ptr<Renderer> renderer(
+ Renderer::CreateDefaultRenderer(&service_locator));
+ renderer->InitCommon();
+
+ Pack::Ref pack(object_manager.CreatePack());
+ Transform* root = pack->Create<Transform>();
+ root->set_name(String(Serializer::ROOT_PREFIX) + String("root"));
+
+ // Setup a ParamFloat to be the source to all animations in this file.
+ ParamObject* param_object = pack->Create<ParamObject>();
+ // This is some arbitrary name
+ param_object->set_name(O3D_STRING_CONSTANT("animSourceOwner"));
+ ParamFloat* param_float = param_object->CreateParam<ParamFloat>("animSource");
+
+ Collada::Options collada_options;
+ collada_options.condition_document = options.condition;
+ collada_options.keep_original_data = true;
+ collada_options.base_path = options.base_path;
+ collada_options.file_paths = options.file_paths;
+ collada_options.up_axis = options.up_axis;
+ Collada collada(pack.Get(), collada_options);
+ bool result = collada.ImportFile(in_filename, root, param_float);
+ if (!result || !error_collector.errors().empty()) {
+ if (error_messages) {
+ *error_messages += error_collector.errors();
+ }
+ return false;
+ }
+
+ // Remove the animation param_object (and indirectly the param_float)
+ // if there is no animation.
+ if (param_float->output_connections().empty()) {
+ pack->RemoveObject(param_object);
+ }
+
+ // Add edges whose normals angle is larger than predefined threshold.
+ if (options.enable_add_sharp_edge) {
+ std::vector<Shape*> shapes = pack->GetByClass<Shape>();
+ for (unsigned s = 0; s < shapes.size(); ++s) {
+ Shape* shape = shapes[s];
+ const ElementRefArray& elements = shape->GetElementRefs();
+ for (unsigned e = 0; e < elements.size(); ++e) {
+ if (elements[e]->IsA(Primitive::GetApparentClass())) {
+ Primitive* primitive = down_cast<Primitive*>(elements[e].Get());
+ // Get vertices and indices of this primitive.
+ if (primitive->primitive_type() != Primitive::TRIANGLELIST)
+ continue;
+ FieldReadAccessor<Point3> vertices;
+ FieldReadAccessorUnsignedInt indices;
+ if (!GetVerticesAccessor(primitive, 0, &vertices))
+ return false;
+
+ unsigned int index_count;
+ if (primitive->indexed()) {
+ if (!Primitive::GetIndexCount(Primitive::TRIANGLELIST,
+ primitive->number_primitives(),
+ &index_count))
+ continue;
+
+ if (!GetIndicesAccessor(primitive, &indices,
+ primitive->start_index(), index_count))
+ continue;
+ index_count = std::min(index_count, indices.max_index());
+ } else {
+ index_count = primitive->number_vertices();
+ indices.InitializeJustCount(primitive->start_index(), index_count);
+ }
+ // If there are no vertices then exit early.
+ if (vertices.max_index() == 0) {
+ continue;
+ }
+ // generate triangle list.
+ int prim = 0;
+ std::vector<Triangle> triangle_list;
+ std::vector<Point3> point_list;
+ for (size_t i = 0; i < 48; i++) {
+ point_list.push_back(vertices[i]);
+ }
+ for (unsigned int prim_base = 0; prim_base + 2 < index_count;
+ prim_base += 3) {
+ Triangle triangle(vertices[indices[prim_base + 0]],
+ vertices[indices[prim_base + 1]],
+ vertices[indices[prim_base + 2]]);
+ triangle_list.push_back(triangle);
+ }
+ // build edge and triangle map.
+ std::map<Edge, std::vector<Triangle>> edge_triangle_map;
+ for (size_t i = 0; i < triangle_list.size(); i++) {
+ Triangle triangle = triangle_list[i];
+ Edge e1(triangle.pts[0], triangle.pts[1]);
+ Edge e2(triangle.pts[1], triangle.pts[2]);
+ Edge e3(triangle.pts[0], triangle.pts[2]);
+ InsertEdgeTrianglePair(e1, triangle, &edge_triangle_map);
+ InsertEdgeTrianglePair(e2, triangle, &edge_triangle_map);
+ InsertEdgeTrianglePair(e3, triangle, &edge_triangle_map);
+ }
+ // go through the edge-triangle map.
+ std::map<Edge, std::vector<Triangle>>::iterator iter;
+ std::vector<Edge> sharp_edges;
+ for (iter = edge_triangle_map.begin();
+ iter != edge_triangle_map.end(); iter++) {
+ if (iter->second.size() < 2)
+ continue;
+ CheckSharpEdge(iter->first, iter->second, &sharp_edges,
+ options.sharp_edge_threshold);
+ }
+
+ if (sharp_edges.size() > 0) {
+ Primitive* sharp_edge_primitive = pack->Create<Primitive>();
+ sharp_edge_primitive->SetOwner(shape);
+ sharp_edge_primitive->set_name("sharp_edge_primitive");
+ StreamBank* stream_bank = pack->Create<StreamBank>();
+
+ VertexBuffer* vertex_buffer = pack->Create<VertexBuffer>();
+ vertex_buffer->set_name("sharp_edges_vertex_buffer");
+ size_t num_vertices = sharp_edges.size() * 2;
+
+ Field* field = vertex_buffer->CreateField(
+ FloatField::GetApparentClass(), 3);
+ if (!vertex_buffer->AllocateElements(static_cast<unsigned int>(
+ sharp_edges.size() * 2))) {
+ O3D_ERROR(&service_locator) << "Failed to allocate vertex buffer";
+ return NULL;
+ }
+ scoped_array<float> values(new float[num_vertices * 3]);
+ for (unsigned int i = 0; i < num_vertices; i++) {
+ Point3 currentPoint;
+ if (i % 2 == 0)
+ currentPoint = sharp_edges[i / 2].pts[0];
+ else
+ currentPoint = sharp_edges[i / 2].pts[1];
+ values[i * 3 + 0] = currentPoint.getX();
+ values[i * 3 + 1] = currentPoint.getY();
+ values[i * 3 + 2] = currentPoint.getZ();
+ }
+ field->SetFromFloats(&values[0], 3, 0,
+ static_cast<unsigned int>(num_vertices));
+ stream_bank->SetVertexStream(Stream::POSITION, 0, field, 0);
+ stream_bank->set_name("sharp_edges_stream_bank");
+
+ Material* material =
+ GetSingleColorMaterial(pack, options.sharp_edge_color);
+ sharp_edge_primitive->set_material(material);
+ sharp_edge_primitive->set_primitive_type(Primitive::LINELIST);
+ sharp_edge_primitive->set_number_vertices(static_cast<int>(
+ sharp_edges.size() * 2));
+ sharp_edge_primitive->set_number_primitives(static_cast<int>(
+ sharp_edges.size()));
+ sharp_edge_primitive->set_stream_bank(stream_bank);
+ }
+ }
+ }
+ }
+ }
+ // Mark all Samplers to use tri-linear filtering
+ if (!options.keep_filters) {
+ std::vector<Sampler*> samplers = pack->GetByClass<Sampler>();
+ for (unsigned ii = 0; ii < samplers.size(); ++ii) {
+ Sampler* sampler = samplers[ii];
+ sampler->set_mag_filter(Sampler::LINEAR);
+ sampler->set_min_filter(Sampler::LINEAR);
+ sampler->set_mip_filter(Sampler::LINEAR);
+ }
+ }
+
+ // Mark all Materials that are on Primitives that have no normals as constant.
+ if (!options.keep_materials) {
+ std::vector<Primitive*> primitives = pack->GetByClass<Primitive>();
+ for (unsigned ii = 0; ii < primitives.size(); ++ii) {
+ Primitive* primitive = primitives[ii];
+ StreamBank* stream_bank = primitive->stream_bank();
+ if (stream_bank && !stream_bank->GetVertexStream(Stream::NORMAL, 0)) {
+ Material* material = primitive->material();
+ if (material) {
+ ParamString* lighting_param = material->GetParam<ParamString>(
+ Collada::kLightingTypeParamName);
+ if (lighting_param) {
+ // If the lighting type is lambert, blinn, or phong
+ // copy the diffuse color to the emissive since that's most likely
+ // what the user wants to see.
+ if (lighting_param->value().compare(
+ Collada::kLightingTypeLambert) == 0 ||
+ lighting_param->value().compare(
+ Collada::kLightingTypeBlinn) == 0 ||
+ lighting_param->value().compare(
+ Collada::kLightingTypePhong) == 0) {
+ // There's 4 cases: (to bad they are not the same names)
+ // 1) Diffuse -> Emissive
+ // 2) DiffuseSampler -> Emissive
+ // 3) Diffuse -> EmissiveSampler
+ // 4) DiffuseSampler -> EmissiveSampler
+ ParamFloat4* diffuse_param = material->GetParam<ParamFloat4>(
+ Collada::kMaterialParamNameDiffuse);
+ ParamFloat4* emissive_param = material->GetParam<ParamFloat4>(
+ Collada::kMaterialParamNameEmissive);
+ ParamSampler* diffuse_sampler_param =
+ material->GetParam<ParamSampler>(
+ Collada::kMaterialParamNameDiffuseSampler);
+ ParamSampler* emissive_sampler_param =
+ material->GetParam<ParamSampler>(
+ Collada::kMaterialParamNameEmissive);
+ Param* source_param = diffuse_param ?
+ static_cast<Param*>(diffuse_param) :
+ static_cast<Param*>(diffuse_sampler_param);
+ Param* destination_param = emissive_param ?
+ static_cast<Param*>(emissive_param) :
+ static_cast<Param*>(emissive_sampler_param);
+ if (!source_param->IsA(destination_param->GetClass())) {
+ // The params do not match type so we need to make the emissive
+ // Param the same as the diffuse Param.
+ material->RemoveParam(destination_param);
+ destination_param = material->CreateParamByClass(
+ diffuse_param ? Collada::kMaterialParamNameEmissive :
+ Collada::kMaterialParamNameEmissiveSampler,
+ source_param->GetClass());
+ DCHECK(destination_param);
+ }
+ destination_param->CopyDataFromParam(source_param);
+ }
+ lighting_param->set_value(Collada::kLightingTypeConstant);
+ }
+ }
+ }
+ }
+ }
+
+ // Attempt to open the output file.
+ FILE* out_file = file_util::OpenFile(out_filename, "wb");
+ if (out_file == NULL) {
+ O3D_ERROR(&service_locator) << "Could not open output file \""
+ << FilePathToUTF8(out_filename).c_str()
+ << "\"";
+ if (error_messages) {
+ *error_messages += error_collector.errors();
+ }
+ return false;
+ }
+
+ // Create an archive file and serialize the JSON scene graph and assets to it.
+ FileOutputStreamProcessor stream_processor(out_file);
+ TarGzGenerator archive_generator(&stream_processor);
+
+ archive_generator.AddFile(ArchiveRequest::O3D_MARKER,
+ ArchiveRequest::O3D_MARKER_CONTENT_LENGTH);
+ archive_generator.AddFileBytes(
+ reinterpret_cast<const uint8*>(ArchiveRequest::O3D_MARKER_CONTENT),
+ ArchiveRequest::O3D_MARKER_CONTENT_LENGTH);
+
+ // Serialize the created O3D scene graph to JSON.
+ StringWriter out_writer(StringWriter::LF);
+ JsonWriter json_writer(&out_writer, 2);
+ if (!options.pretty_print) {
+ json_writer.BeginCompacting();
+ }
+ Serializer serializer(&service_locator, &json_writer, &archive_generator);
+ serializer.SerializePack(pack.Get());
+ json_writer.Close();
+ out_writer.Close();
+ if (!options.pretty_print) {
+ json_writer.EndCompacting();
+ }
+
+ String json = out_writer.ToString();
+
+ archive_generator.AddFile("scene.json", json.length());
+ archive_generator.AddFileBytes(reinterpret_cast<const uint8*>(json.c_str()),
+ json.length());
+
+ // Now add original data (e.g. compressed textures) collected during
+ // the loading process.
+ AddBinaryElements(collada, &archive_generator);
+
+ archive_generator.Close(true);
+
+ pack->Destroy();
+ if (error_messages) {
+ *error_messages = error_collector.errors();
+ }
+ return true;
+}
+
+// Loads the input shader file and validates it.
+bool Verify(const FilePath& in_filename,
+ const FilePath& out_filename,
+ const Options& options,
+ String* error_messages) {
+ FilePath source_filename(in_filename);
+ // Create a service locator and renderer.
+ ServiceLocator service_locator;
+ EvaluationCounter evaluation_counter(&service_locator);
+ ClassManager class_manager(&service_locator);
+ ObjectManager object_manager(&service_locator);
+ Profiler profiler(&service_locator);
+ ErrorStatus error_status(&service_locator);
+
+ // Collect error messages.
+ ErrorCollector error_collector(&service_locator);
+
+ scoped_ptr<Renderer> renderer(
+ Renderer::CreateDefaultRenderer(&service_locator));
+ renderer->InitCommon();
+
+ Pack::Ref pack(object_manager.CreatePack());
+ Transform* root = pack->Create<Transform>();
+ root->set_name(O3D_STRING_CONSTANT("root"));
+
+ Collada::Options collada_options;
+ collada_options.condition_document = options.condition;
+ collada_options.keep_original_data = false;
+ Collada collada(pack.Get(), collada_options);
+
+ ColladaConditioner conditioner(&service_locator);
+ String vertex_shader_entry_point;
+ String fragment_shader_entry_point;
+ TemporaryFile temp_file;
+ if (options.condition) {
+ if (!TemporaryFile::Create(&temp_file)) {
+ O3D_ERROR(&service_locator) << "Could not create temporary file";
+ if (error_messages) {
+ *error_messages = error_collector.errors();
+ }
+ return false;
+ }
+ SamplerStateList state_list;
+ if (!conditioner.RewriteShaderFile(NULL,
+ in_filename,
+ temp_file.path(),
+ &state_list,
+ &vertex_shader_entry_point,
+ &fragment_shader_entry_point)) {
+ O3D_ERROR(&service_locator) << "Could not rewrite shader file";
+ if (error_messages) {
+ *error_messages = error_collector.errors();
+ }
+ return false;
+ }
+ source_filename = temp_file.path();
+ } else {
+ source_filename = in_filename;
+ }
+
+ std::string shader_source_in;
+ // Load file into memory
+ if (!file_util::ReadFileToString(source_filename, &shader_source_in)) {
+ O3D_ERROR(&service_locator) << "Could not read shader file "
+ << FilePathToUTF8(source_filename).c_str();
+ if (error_messages) {
+ *error_messages = error_collector.errors();
+ }
+ return false;
+ }
+
+ Effect::MatrixLoadOrder matrix_load_order;
+ scoped_ptr<Effect> effect(pack->Create<Effect>());
+ if (!effect->ValidateFX(shader_source_in,
+ &vertex_shader_entry_point,
+ &fragment_shader_entry_point,
+ &matrix_load_order)) {
+ O3D_ERROR(&service_locator) << "Could not validate shader file";
+ if (error_messages) {
+ *error_messages = error_collector.errors();
+ }
+ return false;
+ }
+
+ if (!conditioner.CompileHLSL(shader_source_in,
+ vertex_shader_entry_point,
+ fragment_shader_entry_point)) {
+ O3D_ERROR(&service_locator) << "Could not HLSL compile shader file";
+ if (error_messages) {
+ *error_messages = error_collector.errors();
+ }
+ return false;
+ }
+
+ if (!conditioner.CompileCg(in_filename,
+ shader_source_in,
+ vertex_shader_entry_point,
+ fragment_shader_entry_point)) {
+ O3D_ERROR(&service_locator) << "Could not Cg compile shader file";
+ if (error_messages) {
+ *error_messages = error_collector.errors();
+ }
+ return false;
+ }
+
+ // If we've validated the file, then we write out the conditioned
+ // shader to the given output file, if there is one.
+ if (options.condition && !out_filename.empty()) {
+ if (file_util::WriteFile(out_filename, shader_source_in.c_str(),
+ static_cast<int>(shader_source_in.size())) == -1) {
+ O3D_ERROR(&service_locator) << "Warning: Could not write to output file '"
+ << FilePathToUTF8(in_filename).c_str() << "'";
+ }
+ }
+ if (error_messages) {
+ *error_messages = error_collector.errors();
+ }
+ return true;
+}
+} // end namespace converter
+} // end namespace o3d
diff --git a/o3d/converter_edge/cross/converter.h b/o3d/converter_edge/cross/converter.h
new file mode 100644
index 0000000..af360e5
--- /dev/null
+++ b/o3d/converter_edge/cross/converter.h
@@ -0,0 +1,139 @@
+/*
+ * 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 contains the declarations for the functions in the
+// O3D converter namespace. These functions do most of the actual
+// work of conditioning and packagaging a JSON file for use in
+// O3D.
+
+#ifndef O3D_CONVERTER_EDGE_CROSS_CONVERTER_H_
+#define O3D_CONVERTER_EDGE_CROSS_CONVERTER_H_
+
+#include <vector>
+#include <cmath>
+#include "base/file_path.h"
+#include "core/cross/types.h"
+#include "utils/cross/file_path_utils.h"
+
+namespace o3d {
+namespace converter {
+
+// Options struct for passing to the converter.
+struct Options {
+ Options()
+ : base_path(FilePath::kCurrentDirectory),
+ condition(true),
+ up_axis(0, 0, 0),
+ pretty_print(false),
+ keep_filters(false),
+ keep_materials(false),
+ enable_add_sharp_edge(false),
+ sharp_edge_threshold(0),
+ sharp_edge_color(1, 0, 0) {
+ }
+
+ // A list of paths to search for assets..
+ std::vector<FilePath> file_paths;
+
+ // The path to the "base" of the model path, from which all paths
+ // are made relative. Defaults to the current directory.
+ FilePath base_path;
+
+ // Indicates if the converter should condition the input shaders or
+ // not.
+ bool condition;
+
+ // The up axis of the output. The input will be converted to a new coordinate
+ // system if it indicates a different up axis. Zero means no conversion.
+ Vector3 up_axis;
+
+ // This indicates whether or not the serialized JSON code should be
+ // pretty-printed (formatted with spaces and newlines) or just
+ // emitted as one huge one-line string. Defaults to false.
+ bool pretty_print;
+
+ // Tells the converter not to set all filters to tri-linear.
+ bool keep_filters;
+
+ // Tells the converter not to change materials to constant if they are used by
+ // a mesh that has no normals.
+ bool keep_materials;
+
+ // Add edges with normal angle larger than soften_edge_threshold.
+ bool enable_add_sharp_edge;
+
+ // The threshold of normal angle of edge, if angle of certain edge is larger
+ // than this threshold, it will be added into the output file.
+ float sharp_edge_threshold;
+
+ // The color of edges been added.
+ Vector3 sharp_edge_color;
+};
+
+// Edge class is used in sharp edge detect process.
+// It stores two points in a specific order,
+// and it serves as key class in edge-triangle map.
+struct Edge {
+ Edge(Point3 p1, Point3 p2);
+ std::vector<Point3> pts;
+};
+
+// Triangle class is used in detect sharp edge process.
+struct Triangle {
+ Triangle(Point3 p1, Point3 p2, Point3 p3) {
+ pts.push_back(p1);
+ pts.push_back(p2);
+ pts.push_back(p3);
+ }
+ std::vector<Point3> pts;
+};
+
+// Converts the given file for use in O3D. This is done by
+// loading the input file, traversing the scene graph and serializing
+// what is found there.
+bool Convert(const FilePath& in_filename,
+ const FilePath& out_filename,
+ const Options& options,
+ String* error_messages);
+
+// Verifies the given shader file as "valid". Returns true if input
+// shader file contains valid code (code that can be compiled
+// successfully).
+bool Verify(const FilePath& in_filename,
+ const FilePath& out_filename,
+ const Options& options,
+ String* error_messages);
+
+} // namespace converter
+} // namespace o3d
+
+#endif // O3D_CONVERTER_EDGE_CROSS_CONVERTER_H_
diff --git a/o3d/converter_edge/cross/converter_main.cc b/o3d/converter_edge/cross/converter_main.cc
new file mode 100644
index 0000000..ee40311
--- /dev/null
+++ b/o3d/converter_edge/cross/converter_main.cc
@@ -0,0 +1,180 @@
+/*
+ * 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 contains the main routine for the converter that writes
+// out a scene graph as a JSON file.
+
+#include <string>
+#include <iostream>
+#include <vector>
+
+#include "base/at_exit.h"
+#include "base/command_line.h"
+#include "base/file_path.h"
+#include "base/string_util.h"
+#include "converter_edge/cross/converter.h"
+#include "utils/cross/file_path_utils.h"
+
+using std::string;
+using std::wstring;
+
+#if defined(OS_WIN)
+int wmain(int argc, wchar_t **argv) {
+ // On Windows, CommandLine::Init ignores its arguments and uses
+ // GetCommandLineW.
+ CommandLine::Init(0, NULL);
+#endif
+#if defined(OS_LINUX)
+int main(int argc, char **argv) {
+ CommandLine::Init(argc, argv);
+#endif
+#if defined(OS_MACOSX)
+// The "real" main on Mac is in mac/converter_main.mm, so we can get
+// memory pool initialization for Cocoa.
+int CrossMain(int argc, char**argv) {
+ CommandLine::Init(argc, argv);
+#endif
+ // Create an at_exit_manager so that base singletons will get
+ // deleted properly.
+ base::AtExitManager at_exit_manager;
+ const CommandLine* command_line = CommandLine::ForCurrentProcess();
+
+ FilePath in_filename, out_filename;
+
+ std::vector<std::wstring> values = command_line->GetLooseValues();
+ if (values.size() == 1) {
+ // If we're only given one argument, then construct the output
+ // filename by substituting the extension on the filename (if any)
+ // with .o3dtgz.
+ in_filename = o3d::WideToFilePath(values[0]);
+ out_filename = in_filename.ReplaceExtension(FILE_PATH_LITERAL(".o3dtgz"));
+ } else if (values.size()== 2) {
+ in_filename = o3d::WideToFilePath(values[0]);
+ out_filename = o3d::WideToFilePath(values[1]);
+ } else {
+ std::cerr << "Usage: " << argv[0]
+ << " [ options ] <infile.dae> [ <outfile> ]\n";
+ std::cerr
+ << "--no-condition\n"
+ << " Stops the converter from conditioning shaders.\n"
+ << "--base-path=<path>\n"
+ << " Sets the path to remove from URIs of external files\n"
+ << "--asset-paths=<comma separted list of paths>\n"
+ << " Sets the paths for finding textures and other external\n"
+ << " files.\n"
+ << "--up-axis=x,y,z\n"
+ << " Converts the file to have this up axis.\n"
+ << "--pretty-print\n"
+ << " Makes the exported JSON easier to read.\n"
+ << "--keep-filters\n"
+ << " Stops the converter from forcing all texture samplers to use\n"
+ << " tri-linear filtering.\n"
+ << "--keep-materials\n"
+ << " Stops the converter from changing materials to <constant> if\n"
+ << " they are used by a mesh that has no normals.\n"
+ << "--sharp-edge-threshold=<threshold>\n"
+ << " Adds edges with normal angle larger than <threshold>.\n"
+ << "--sharp-edge-color=r,g,b\n"
+ << " Specify color of the additional edges, (value 0 to 1).\n"
+ << " Default value is 1,0,0.\n";
+ return EXIT_FAILURE;
+ }
+
+ o3d::converter::Options options;
+ options.condition = !command_line->HasSwitch(L"no-condition");
+ options.pretty_print = command_line->HasSwitch(L"pretty-print");
+ if (command_line->HasSwitch(L"base-path")) {
+ options.base_path = o3d::WideToFilePath(
+ command_line->GetSwitchValue(L"base-path"));
+ }
+ if (command_line->HasSwitch(L"asset-paths")) {
+ std::vector<std::wstring> paths;
+ SplitString(command_line->GetSwitchValue(L"asset-paths"), ',', &paths);
+ for (size_t ii = 0; ii < paths.size(); ++ii) {
+ options.file_paths.push_back(o3d::WideToFilePath(paths[ii]));
+ }
+ }
+ if (command_line->HasSwitch(L"up-axis")) {
+ wstring up_axis_string = command_line->GetSwitchValue(L"up-axis");
+ int x, y, z;
+ if (swscanf(up_axis_string.c_str(), L"%d,%d,%d", &x, &y, &z) != 3) {
+ std::cerr << "Invalid --up-axis value. Should be --up-axis=x,y,z\n";
+ return EXIT_FAILURE;
+ }
+ options.up_axis = o3d::Vector3(static_cast<float>(x),
+ static_cast<float>(y),
+ static_cast<float>(z));
+ }
+ if (command_line->HasSwitch(L"sharp-edge-threshold")) {
+ wstring soften_edge_string =
+ command_line->GetSwitchValue(L"sharp-edge-threshold");
+ float soft_threshold;
+ if (swscanf(soften_edge_string.c_str(), L"%f", &soft_threshold) != 1) {
+ std::cerr << "Invalid --sharp-edges-threshold value.\n";
+ return EXIT_FAILURE;
+ }
+ options.enable_add_sharp_edge = true;
+ options.sharp_edge_threshold = soft_threshold;
+ }
+ if (command_line->HasSwitch(L"sharp-edge-color")) {
+ wstring edge_color_str =
+ command_line->GetSwitchValue(L"sharp-edge-color");
+ int r, g, b;
+ if (swscanf(edge_color_str.c_str(), L"%d,%d,%d", &r, &g, &b) != 3) {
+ std::cerr << "Invalid --sharp-edge-color value. Should be "
+ << "--sharp-edge-color=r,g,b\n";
+ return EXIT_FAILURE;
+ }
+ options.sharp_edge_color = o3d::Vector3(static_cast<float>(r),
+ static_cast<float>(g),
+ static_cast<float>(b));
+ }
+
+ o3d::String error_messages;
+ bool result = o3d::converter::Convert(in_filename,
+ out_filename,
+ options,
+ &error_messages);
+ if (result) {
+ std::cerr << "Converted '" << o3d::FilePathToUTF8(in_filename).c_str()
+ << "' to '" << o3d::FilePathToUTF8(out_filename).c_str()
+ << "'." << std::endl;
+ return EXIT_SUCCESS;
+ } else {
+ std::cerr << error_messages.c_str() << std::endl;
+ std::cerr << "FAILED to convert '"
+ << o3d::FilePathToUTF8(in_filename).c_str()
+ << "' to '" << o3d::FilePathToUTF8(out_filename).c_str()
+ << "'." << std::endl;
+ return EXIT_FAILURE;
+ }
+}
diff --git a/o3d/converter_edge/cross/draw_element_stub.h b/o3d/converter_edge/cross/draw_element_stub.h
new file mode 100644
index 0000000..8ed3de6
--- /dev/null
+++ b/o3d/converter_edge/cross/draw_element_stub.h
@@ -0,0 +1,58 @@
+/*
+ * 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 contains the declaration of the DrawElementGL class.
+
+#ifndef O3D_CONVERTER_EDGE_CROSS_DRAW_ELEMENT_STUB_H_
+#define O3D_CONVERTER_EDGE_CROSS_DRAW_ELEMENT_STUB_H_
+
+#include "core/cross/draw_element.h"
+
+namespace o3d {
+
+class ServiceLocator;
+
+// DrawElementStub is the Stub implementation of the DrawElement. It
+// provides a place for the renderer to store platform specific cache
+// information.
+class DrawElementStub : public DrawElement {
+ public:
+ explicit DrawElementStub(ServiceLocator* service_locator)
+ : DrawElement(service_locator) {}
+ ~DrawElementStub() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DrawElementStub);
+};
+} // o3d
+
+#endif // O3D_CONVERTER_EDGE_CROSS_DRAW_ELEMENT_STUB_H_
diff --git a/o3d/converter_edge/cross/effect_stub.h b/o3d/converter_edge/cross/effect_stub.h
new file mode 100644
index 0000000..dfe9a84
--- /dev/null
+++ b/o3d/converter_edge/cross/effect_stub.h
@@ -0,0 +1,73 @@
+/*
+ * 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 contains the declaration of the EffectGL class.
+
+#ifndef O3D_CONVERTER_EDGE_CROSS_EFFECT_STUB_H_
+#define O3D_CONVERTER_EDGE_CROSS_EFFECT_STUB_H_
+
+#include "core/cross/effect.h"
+
+namespace o3d {
+
+class ServiceLocator;
+
+// EffectStub is an implementation of the Effect object for the
+// converter. It provides the API for setting the vertex and fragment
+// shaders for the Effect using the Cg Runtime.
+class EffectStub : public Effect {
+ public:
+ explicit EffectStub(ServiceLocator* service_locator)
+ : Effect(service_locator) {}
+ virtual ~EffectStub() {}
+
+ // Reads the vertex and fragment shaders from string in the FX format.
+ // It returns true if the shaders were successfully compiled.
+ virtual bool LoadFromFXString(const String& effect) { return true; }
+
+ // Gets info about the parameters this effect needs.
+ // Overriden from Effect.
+ virtual void GetParameterInfo(EffectParameterInfoArray* info_array) {}
+
+ // Gets info about the varying parameters this effects vertex shader needs.
+ // Parameters:
+ // info_array: EffectParameterInfoArray to receive info.
+ virtual void GetStreamInfo(
+ EffectStreamInfoArray* info_array) {
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(EffectStub);
+};
+} // namespace o3d
+
+#endif // O3D_CONVERTER_EDGE_CROSS_EFFECT_STUB_H_
diff --git a/o3d/converter_edge/cross/param_cache_stub.h b/o3d/converter_edge/cross/param_cache_stub.h
new file mode 100644
index 0000000..38efe6e
--- /dev/null
+++ b/o3d/converter_edge/cross/param_cache_stub.h
@@ -0,0 +1,69 @@
+/*
+ * 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 contains the declaration of the ParamCacheStub class.
+
+#ifndef O3D_CONVERTER_EDGE_CROSS_PARAM_CACHE_STUB_H_
+#define O3D_CONVERTER_EDGE_CROSS_PARAM_CACHE_STUB_H_
+
+#include "core/cross/param_cache.h"
+
+namespace o3d {
+
+class Effect;
+class DrawElement;
+class Element;
+class Material;
+class ParamObject;
+
+class ParamCacheStub : public ParamCache {
+ public:
+ ParamCacheStub() : ParamCache() {}
+
+ // Overridden from ParamCache.
+ virtual void UpdateCache(Effect* effect,
+ DrawElement* draw_element,
+ Element* element,
+ Material* material,
+ ParamObject* override) {}
+
+ protected:
+ // Overridden from ParamCache
+ // Validates platform specific information about the effect.
+ virtual bool ValidateEffect(Effect* effect) { return true; }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ParamCacheStub);
+};
+} // o3d
+
+#endif // O3D_CONVERTER_EDGE_CROSS_PARAM_CACHE_STUB_H_
diff --git a/o3d/converter_edge/cross/primitive_stub.h b/o3d/converter_edge/cross/primitive_stub.h
new file mode 100644
index 0000000..5dd43ac
--- /dev/null
+++ b/o3d/converter_edge/cross/primitive_stub.h
@@ -0,0 +1,71 @@
+/*
+ * 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 contains the declaration of the PrimitiveStub class.
+
+#ifndef O3D_CONVERTER_EDGE_CROSS_PRIMITIVE_STUB_H_
+#define O3D_CONVERTER_EDGE_CROSS_PRIMITIVE_STUB_H_
+
+#include "core/cross/primitive.h"
+
+namespace o3d {
+
+class DrawElement;
+class Material;
+class ParamCache;
+class ParamObject;
+class Renderer;
+class ServiceLocator;
+
+// PrimitiveStub is the Stub implementation of the Primitive. It provides the
+// necessary interfaces for setting the geometry streams on the Primitive.
+class PrimitiveStub : public Primitive {
+ public:
+ explicit PrimitiveStub(ServiceLocator* service_locator)
+ : Primitive(service_locator) {}
+ virtual ~PrimitiveStub() {}
+
+ // Overridden from Element
+ // Renders this Element using the parameters from override first, followed by
+ // the draw_element, followed by params on this Primitive and material.
+ virtual void Render(Renderer* renderer,
+ DrawElement* draw_element,
+ Material* material,
+ ParamObject* override,
+ ParamCache* param_cache) {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PrimitiveStub);
+};
+} // o3d
+
+#endif // O3D_CONVERTER_EDGE_CROSS_PRIMITIVE_STUB_H_
diff --git a/o3d/converter_edge/cross/render_surface_stub.h b/o3d/converter_edge/cross/render_surface_stub.h
new file mode 100644
index 0000000..8b018b4
--- /dev/null
+++ b/o3d/converter_edge/cross/render_surface_stub.h
@@ -0,0 +1,75 @@
+/*
+ * 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 contains the declarations for RenderSurfaceGL and
+// RenderDepthStencilSurfaceGL.
+
+#ifndef O3D_CONVERTER_EDGE_CROSS_RENDER_SURFACE_STUB_H_
+#define O3D_CONVERTER_EDGE_CROSS_RENDER_SURFACE_STUB_H_
+
+#include "core/cross/render_surface.h"
+#include "core/cross/texture.h"
+
+namespace o3d {
+
+class RenderSurfaceStub : public RenderSurface {
+ public:
+ typedef SmartPointer<RenderSurfaceStub> Ref;
+
+ // Constructs a RenderSurfaceStub instance.
+ // Parameters:
+ // service_locator: Service locator for the instance.
+ RenderSurfaceStub(ServiceLocator *service_locator,
+ int width,
+ int height)
+ : RenderSurface(service_locator, width, height, NULL) {}
+ virtual ~RenderSurfaceStub() {}
+ private:
+ DISALLOW_COPY_AND_ASSIGN(RenderSurfaceStub);
+};
+
+class RenderDepthStencilSurfaceStub : public RenderDepthStencilSurface {
+ public:
+ typedef SmartPointer<RenderDepthStencilSurfaceStub> Ref;
+
+ RenderDepthStencilSurfaceStub(ServiceLocator *service_locator,
+ int width,
+ int height)
+ : RenderDepthStencilSurface(service_locator, width, height) {}
+ virtual ~RenderDepthStencilSurfaceStub() {}
+ private:
+ DISALLOW_COPY_AND_ASSIGN(RenderDepthStencilSurfaceStub);
+};
+
+} // namespace o3d
+
+#endif // O3D_CONVERTER_EDGE_CROSS_RENDER_SURFACE_STUB_H_
diff --git a/o3d/converter_edge/cross/renderer_stub.cc b/o3d/converter_edge/cross/renderer_stub.cc
new file mode 100644
index 0000000..1ede3d4
--- /dev/null
+++ b/o3d/converter_edge/cross/renderer_stub.cc
@@ -0,0 +1,204 @@
+/*
+ * 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 contains the definition of abstract functions in the
+// cross platform API so that we can use it for serialization of the
+// scene graph on all systems without needing graphics.
+
+#include "converter/cross/renderer_stub.h"
+#include "core/cross/object_manager.h"
+#include "core/cross/service_locator.h"
+#include "converter_edge/cross/buffer_stub.h"
+#include "converter_edge/cross/draw_element_stub.h"
+#include "converter_edge/cross/effect_stub.h"
+#include "converter_edge/cross/param_cache_stub.h"
+#include "converter_edge/cross/primitive_stub.h"
+#include "converter_edge/cross/render_surface_stub.h"
+#include "converter_edge/cross/sampler_stub.h"
+#include "converter_edge/cross/stream_bank_stub.h"
+#include "converter_edge/cross/texture_stub.h"
+
+namespace o3d {
+
+Renderer* RendererStub::CreateDefault(ServiceLocator* service_locator) {
+ return new RendererStub(service_locator);
+}
+
+RendererStub::RendererStub(ServiceLocator* service_locator)
+ : Renderer(service_locator) {
+}
+
+Renderer::InitStatus RendererStub::InitPlatformSpecific(
+ const DisplayWindow&, bool) {
+ DCHECK(false);
+ return SUCCESS;
+}
+
+void RendererStub::InitCommon() {
+}
+
+void RendererStub::UninitCommon() {
+}
+
+void RendererStub::Destroy(void) {
+ DCHECK(false);
+}
+
+bool RendererStub::BeginDraw(void) {
+ DCHECK(false);
+ return true;
+}
+
+void RendererStub::EndDraw(void) {
+ DCHECK(false);
+}
+
+bool RendererStub::StartRendering(void) {
+ DCHECK(false);
+ return true;
+}
+
+void RendererStub::FinishRendering(void) {
+ DCHECK(false);
+}
+
+void RendererStub::Resize(int, int) {
+ DCHECK(false);
+}
+
+void RendererStub::Clear(const Float4 &, bool, float, bool, int, bool) {
+ DCHECK(false);
+}
+
+void RendererStub::RenderElement(Element *,
+ DrawElement *,
+ Material *,
+ ParamObject *,
+ ParamCache *) {
+ DCHECK(false);
+}
+
+void RendererStub::SetRenderSurfacesPlatformSpecific(
+ RenderSurface* surface,
+ RenderDepthStencilSurface* surface_depth) {
+ DCHECK(false);
+}
+
+void RendererStub::SetBackBufferPlatformSpecific() {
+ DCHECK(false);
+}
+
+Primitive::Ref RendererStub::CreatePrimitive(void) {
+ return Primitive::Ref(new PrimitiveStub(service_locator()));
+}
+
+DrawElement::Ref RendererStub::CreateDrawElement(void) {
+ return DrawElement::Ref(new DrawElementStub(service_locator()));
+}
+
+VertexBuffer::Ref RendererStub::CreateVertexBuffer(void) {
+ return VertexBuffer::Ref(new VertexBufferStub(service_locator()));
+}
+
+IndexBuffer::Ref RendererStub::CreateIndexBuffer(void) {
+ return IndexBuffer::Ref(new IndexBufferStub(service_locator()));
+}
+
+Effect::Ref RendererStub::CreateEffect(void) {
+ return Effect::Ref(new EffectStub(service_locator()));
+}
+
+Sampler::Ref RendererStub::CreateSampler(void) {
+ return Sampler::Ref(new SamplerStub(service_locator()));
+}
+
+Texture2D::Ref RendererStub::CreatePlatformSpecificTexture2D(
+ int width,
+ int height,
+ Texture::Format format,
+ int levels,
+ bool enable_render_surfaces) {
+ return Texture2D::Ref(new Texture2DStub(service_locator(),
+ width,
+ height,
+ format,
+ levels,
+ enable_render_surfaces));
+}
+
+TextureCUBE::Ref RendererStub::CreatePlatformSpecificTextureCUBE(
+ int edge_length,
+ Texture::Format format,
+ int levels,
+ bool enable_render_surfaces) {
+ return TextureCUBE::Ref(new TextureCUBEStub(service_locator(),
+ edge_length,
+ format,
+ levels,
+ enable_render_surfaces));
+}
+
+RenderDepthStencilSurface::Ref RendererStub::CreateDepthStencilSurface(
+ int width,
+ int height) {
+ return RenderDepthStencilSurface::Ref(
+ new RenderDepthStencilSurfaceStub(service_locator(), width, height));
+}
+
+StreamBank::Ref RendererStub::CreateStreamBank() {
+ return StreamBank::Ref(new StreamBankStub(service_locator()));
+}
+
+Bitmap::Ref RendererStub::TakeScreenshot() {
+ return Bitmap::Ref();
+}
+
+ParamCache *RendererStub::CreatePlatformSpecificParamCache(void) {
+ return new ParamCacheStub;
+}
+
+void RendererStub::SetViewportInPixels(int, int, int, int, float, float) {
+ DCHECK(false);
+}
+
+const int* RendererStub::GetRGBAUByteNSwizzleTable() {
+ static int swizzle_table[] = { 0, 1, 2, 3, };
+ return swizzle_table;
+}
+
+// This is a factory function for creating Renderer objects. Since
+// we're implementing a stub renderer, we only ever return a stub renderer.
+Renderer* Renderer::CreateDefaultRenderer(ServiceLocator* service_locator) {
+ return RendererStub::CreateDefault(service_locator);
+}
+
+} // namespace o3d
diff --git a/o3d/converter_edge/cross/renderer_stub.h b/o3d/converter_edge/cross/renderer_stub.h
new file mode 100644
index 0000000..e924cf1
--- /dev/null
+++ b/o3d/converter_edge/cross/renderer_stub.h
@@ -0,0 +1,123 @@
+/*
+ * 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 contains the declaration of functions needed to
+// instantiate a renderer from the core cross-platform API so that we
+// can use it for serialization of the scene graph on all systems
+// without needing graphics.
+
+#ifndef O3D_CONVERTER_EDGE_CROSS_RENDERER_STUB_H_
+#define O3D_CONVERTER_EDGE_CROSS_RENDERER_STUB_H_
+
+#include "core/cross/renderer.h"
+
+namespace o3d {
+
+// Please see core/cross/renderer.h for documentation of these
+// functions. With the exception of the "Create..." methods, these
+// are mostly just stubbed out here, and don't do anything.
+
+class RendererStub : public Renderer {
+ public:
+ static Renderer* CreateDefault(ServiceLocator* service_locator);
+ virtual InitStatus InitPlatformSpecific(const DisplayWindow& display,
+ bool off_screen);
+ virtual void InitCommon();
+ virtual void UninitCommon();
+ virtual void Destroy();
+ virtual bool BeginDraw();
+ virtual void EndDraw();
+ virtual bool StartRendering();
+ virtual void FinishRendering();
+ virtual void Resize(int width, int height);
+ virtual void Clear(const Float4 &color,
+ bool color_flag,
+ float depth,
+ bool depth_flag,
+ int stencil,
+ bool stencil_flag);
+ virtual void RenderElement(Element* element,
+ DrawElement* draw_element,
+ Material* material,
+ ParamObject* override,
+ ParamCache* param_cache);
+ virtual Primitive::Ref CreatePrimitive();
+ virtual DrawElement::Ref CreateDrawElement();
+ virtual VertexBuffer::Ref CreateVertexBuffer();
+ virtual IndexBuffer::Ref CreateIndexBuffer();
+ virtual Effect::Ref CreateEffect();
+ virtual Sampler::Ref CreateSampler();
+ virtual RenderDepthStencilSurface::Ref CreateDepthStencilSurface(int width,
+ int height);
+ virtual StreamBank::Ref CreateStreamBank();
+ virtual Bitmap::Ref TakeScreenshot();
+ ParamCache *CreatePlatformSpecificParamCache();
+ virtual void SetViewportInPixels(int left,
+ int top,
+ int width,
+ int height,
+ float min_z,
+ float max_z);
+
+ // Overridden from Renderer.
+ virtual const int* GetRGBAUByteNSwizzleTable();
+
+ protected:
+ explicit RendererStub(ServiceLocator* service_locator);
+
+ // Overridden from Renderer.
+ virtual void SetBackBufferPlatformSpecific();
+
+ // Overridden from Renderer.
+ virtual void SetRenderSurfacesPlatformSpecific(
+ RenderSurface* surface,
+ RenderDepthStencilSurface* depth_surface);
+
+ // Overridden from Renderer.
+ virtual Texture2D::Ref CreatePlatformSpecificTexture2D(
+ int width,
+ int height,
+ Texture::Format format,
+ int levels,
+ bool enable_render_surfaces);
+
+ // Overridden from Renderer.
+ virtual TextureCUBE::Ref CreatePlatformSpecificTextureCUBE(
+ int edge_length,
+ Texture::Format format,
+ int levels,
+ bool enable_render_surfaces);
+};
+
+} // namespace o3d
+
+#endif // O3D_CONVERTER_EDGE_CROSS_RENDERER_STUB_H_
diff --git a/o3d/converter_edge/cross/sampler_stub.h b/o3d/converter_edge/cross/sampler_stub.h
new file mode 100644
index 0000000..1eb3fcc
--- /dev/null
+++ b/o3d/converter_edge/cross/sampler_stub.h
@@ -0,0 +1,53 @@
+/*
+ * 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 contains the class declaration for SamplerStub.
+
+#ifndef O3D_CONVERTER_EDGE_CROSS_SAMPLER_STUB_H_
+#define O3D_CONVERTER_EDGE_CROSS_SAMPLER_STUB_H_
+
+#include "core/cross/sampler.h"
+
+namespace o3d {
+
+// SamplerStub is an implementation of the Sampler object for the converter.
+class SamplerStub : public Sampler {
+ public:
+ explicit SamplerStub(ServiceLocator* service_locator)
+ : Sampler(service_locator) {}
+ virtual ~SamplerStub() {}
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SamplerStub);
+};
+} // namespace o3d
+
+#endif // O3D_CONVERTER_EDGE_CROSS_SAMPLER_STUB_H_
diff --git a/o3d/converter_edge/cross/stream_bank_stub.h b/o3d/converter_edge/cross/stream_bank_stub.h
new file mode 100644
index 0000000..3ee9dc5
--- /dev/null
+++ b/o3d/converter_edge/cross/stream_bank_stub.h
@@ -0,0 +1,51 @@
+/*
+ * 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 contains the declaration of the StreamBankGL class.
+
+#ifndef O3D_CONVERTER_EDGE_CROSS_STREAM_BANK_STUB_H_
+#define O3D_CONVERTER_EDGE_CROSS_STREAM_BANK_STUB_H_
+
+#include "core/cross/stream_bank.h"
+
+namespace o3d {
+
+// StreamBankStub is the Stub implementation of the StreamBank.
+class StreamBankStub : public StreamBank {
+ public:
+ explicit StreamBankStub(ServiceLocator* service_locator)
+ : StreamBank(service_locator) {}
+ virtual ~StreamBankStub() {}
+};
+} // o3d
+
+#endif // O3D_CONVERTER_EDGE_CROSS_STREAM_BANK_STUB_H_
diff --git a/o3d/converter_edge/cross/texture_stub.cc b/o3d/converter_edge/cross/texture_stub.cc
new file mode 100644
index 0000000..c287b58
--- /dev/null
+++ b/o3d/converter_edge/cross/texture_stub.cc
@@ -0,0 +1,51 @@
+/*
+ * 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 "converter_edge/cross/texture_stub.h"
+
+namespace o3d {
+
+namespace {
+
+Texture::RGBASwizzleIndices g_stub_abgr32f_swizzle_indices = {0, 1, 2, 3};
+
+} // anonymous namespace.
+
+const Texture::RGBASwizzleIndices& Texture2DStub::GetABGR32FSwizzleIndices() {
+ return g_stub_abgr32f_swizzle_indices;
+}
+
+const Texture::RGBASwizzleIndices& TextureCUBEStub::GetABGR32FSwizzleIndices() {
+ return g_stub_abgr32f_swizzle_indices;
+}
+
+} // namespace o3d
diff --git a/o3d/converter_edge/cross/texture_stub.h b/o3d/converter_edge/cross/texture_stub.h
new file mode 100644
index 0000000..7b31a17
--- /dev/null
+++ b/o3d/converter_edge/cross/texture_stub.h
@@ -0,0 +1,174 @@
+/*
+ * 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 contains the declarations for Texture2DStub and TextureCUBEStub.
+
+#ifndef O3D_CONVERTER_EDGE_CROSS_TEXTURE_STUB_H_
+#define O3D_CONVERTER_EDGE_CROSS_TEXTURE_STUB_H_
+
+#include "core/cross/bitmap.h"
+#include "core/cross/texture.h"
+#include "core/cross/types.h"
+
+namespace o3d {
+
+// Texture2DStub implements the stub Texture2D interface for the converter.
+class Texture2DStub : public Texture2D {
+ public:
+ typedef SmartPointer<Texture2DStub> Ref;
+
+ Texture2DStub(ServiceLocator* service_locator,
+ int width,
+ int height,
+ Texture::Format format,
+ int levels,
+ bool enable_render_surfaces)
+ : Texture2D(service_locator,
+ width,
+ height,
+ format,
+ levels,
+ enable_render_surfaces) {}
+ virtual ~Texture2DStub() {}
+
+ // Overridden from Texture2D
+ virtual void SetRect(int level,
+ unsigned left,
+ unsigned top,
+ unsigned width,
+ unsigned height,
+ const void* src_data,
+ int src_pitch) {
+ }
+
+ // Returns a RenderSurface object associated with a mip_level of a texture.
+ // Parameters:
+ // mip_level: [in] The mip-level of the surface to be returned.
+ // pack: [in] The pack in which the surface will reside.
+ // Returns:
+ // Reference to the RenderSurface object.
+ virtual RenderSurface::Ref GetRenderSurface(int mip_level, Pack *pack) {
+ return RenderSurface::Ref(NULL);
+ }
+
+ // Returns the implementation-specific texture handle for this texture.
+ void* GetTextureHandle() const {
+ return NULL;
+ }
+
+ // Gets a RGBASwizzleIndices that contains a mapping from
+ // RGBA to the internal format used by the rendering API.
+ virtual const RGBASwizzleIndices& GetABGR32FSwizzleIndices();
+
+ protected:
+ // Locks the image buffer of a given mipmap level for writing from main
+ // memory.
+ virtual bool Lock(int level, void** texture_data, int* pitch) {
+ return false;
+ }
+
+ // Unlocks this texture and returns it to Stub control.
+ virtual bool Unlock(int level) { return true; }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Texture2DStub);
+};
+
+
+// TextureCUBEStub implements the TextureCUBE interface for the converter stub.
+class TextureCUBEStub : public TextureCUBE {
+ public:
+ typedef SmartPointer<TextureCUBEStub> Ref;
+ TextureCUBEStub(ServiceLocator* service_locator,
+ int edge_length,
+ Texture::Format format,
+ int levels,
+ bool enable_render_surfaces)
+ : TextureCUBE(service_locator,
+ edge_length,
+ format,
+ levels,
+ enable_render_surfaces) {}
+ virtual ~TextureCUBEStub() {}
+
+ // Overridden from TextureCUBE
+ virtual void SetRect(CubeFace face,
+ int level,
+ unsigned dst_left,
+ unsigned dst_top,
+ unsigned width,
+ unsigned height,
+ const void* src_data,
+ int src_pitch) {
+ };
+
+ // Returns a RenderSurface object associated with a given cube face and
+ // mip_level of a texture.
+ // Parameters:
+ // face: [in] The cube face from which to extract the surface.
+ // mip_level: [in] The mip-level of the surface to be returned.
+ // pack: [in] The pack in which the surface will reside.
+ // Returns:
+ // Reference to the RenderSurface object.
+ virtual RenderSurface::Ref GetRenderSurface(CubeFace face,
+ int level,
+ Pack* pack) {
+ return RenderSurface::Ref(NULL);
+ }
+
+ // Returns the implementation-specific texture handle for this texture.
+ void* GetTextureHandle() const {
+ return NULL;
+ }
+
+ // Gets a RGBASwizzleIndices that contains a mapping from
+ // RGBA to the internal format used by the rendering API.
+ virtual const RGBASwizzleIndices& GetABGR32FSwizzleIndices();
+
+ protected:
+ // Locks the image buffer of a given face and mipmap level for loading
+ // from main memory.
+ virtual bool Lock(
+ CubeFace face, int level, void** texture_data, int* pitch) {
+ return false;
+ }
+
+ // Unlocks the image buffer of a given face and mipmap level.
+ virtual bool Unlock(CubeFace face, int level) { return true; }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TextureCUBEStub);
+};
+
+} // namespace o3d
+
+#endif // O3D_CONVERTER_EDGE_CROSS_TEXTURE_STUB_H_
diff --git a/o3d/converter_edge/cross/verifier_main.cc b/o3d/converter_edge/cross/verifier_main.cc
new file mode 100644
index 0000000..bc0e8a9
--- /dev/null
+++ b/o3d/converter_edge/cross/verifier_main.cc
@@ -0,0 +1,106 @@
+/*
+ * 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 contains the main routine for the converter that writes
+// out a scene graph as a JSON file.
+
+#include <string>
+#include <iostream>
+#include <vector>
+
+#include "base/at_exit.h"
+#include "base/file_path.h"
+#include "base/command_line.h"
+#include "converter_edge/cross/converter.h"
+#include "utils/cross/file_path_utils.h"
+
+using std::string;
+using std::wstring;
+
+#if defined(OS_WIN)
+int wmain(int argc, wchar_t **argv) {
+ // On Windows, CommandLine::Init ignores its arguments and uses
+ // GetCommandLineW.
+ CommandLine::Init(0, NULL);
+#endif
+#if defined(OS_LINUX)
+int main(int argc, char **argv) {
+ CommandLine::Init(argc, argv);
+#endif
+#if defined(OS_MACOSX)
+// The "real" main on Mac is in mac/converter_main.mm, so we can get
+// memory pool initialization for Cocoa.
+int CrossMain(int argc, char**argv) {
+ CommandLine::Init(argc, argv);
+#endif
+ // Create an at_exit_manager so that base singletons will get
+ // deleted properly.
+ base::AtExitManager at_exit_manager;
+ const CommandLine* command_line = CommandLine::ForCurrentProcess();
+
+ FilePath in_filename, out_filename;
+
+ std::vector<std::wstring> values = command_line->GetLooseValues();
+ if (values.size() == 1) {
+ in_filename = o3d::WideToFilePath(values[0]);
+ } else if (values.size()== 2) {
+ in_filename = o3d::WideToFilePath(values[0]);
+ out_filename = o3d::WideToFilePath(values[1]);
+ } else {
+ std::cerr << "Usage: " << FilePath(argv[0]).BaseName().value()
+ << " [--no-condition] <infile.fx> [<outfile.fx>]\n";
+ return EXIT_FAILURE;
+ }
+
+ o3d::converter::Options options;
+ options.condition = !command_line->HasSwitch(L"no-condition");
+
+ if (!options.condition && !out_filename.empty()) {
+ std::cerr << "Warning: Ignoring output filename because conditioning "
+ << "has been turned off.\n";
+ out_filename = FilePath();
+ }
+
+ o3d::String errors;
+ bool result = o3d::converter::Verify(in_filename, out_filename, options,
+ &errors);
+ if (result) {
+ std::cerr << "Shader in '" << o3d::FilePathToUTF8(in_filename).c_str()
+ << "' has been validated." << std::endl;
+ return EXIT_SUCCESS;
+ } else {
+ std::cerr << errors.c_str() << std::endl;
+ std::cerr << "Shader in '" << o3d::FilePathToUTF8(in_filename).c_str()
+ << "' FAILED to be validated." << std::endl;
+ return EXIT_FAILURE;
+ }
+}
diff --git a/o3d/converter_edge/mac/converter_main.mm b/o3d/converter_edge/mac/converter_main.mm
new file mode 100644
index 0000000..4e9a4af
--- /dev/null
+++ b/o3d/converter_edge/mac/converter_main.mm
@@ -0,0 +1,49 @@
+/*
+ * 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 contains the main routine for the converter that writes
+// out a scene graph as a JSON file. Really, just a shell for the
+// common main routine in cross so we can get memory pool
+// initialization for Cocoa.
+
+#import <Cocoa/Cocoa.h>
+
+// Defined in converter/cross/converter_main.cc
+extern int CrossMain(int argc, char** argv);
+
+int main(int argc, char** argv) {
+ // Make a pool to use for any Cocoa objects in the app.
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ int result = CrossMain(argc, argv);
+ [pool release];
+ return result;
+}