summaryrefslogtreecommitdiffstats
path: root/o3d/import
diff options
context:
space:
mode:
authoramarinichev@chromium.org <amarinichev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-23 23:17:56 +0000
committeramarinichev@chromium.org <amarinichev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-23 23:17:56 +0000
commitbc3ef7faa993606415465cc3a036b5f3af9de660 (patch)
tree69c51db29737194ed207c84c6235a18779a3e91c /o3d/import
parent1eb71d721dee36e8f386bdc0900f915a0813981a (diff)
downloadchromium_src-bc3ef7faa993606415465cc3a036b5f3af9de660.zip
chromium_src-bc3ef7faa993606415465cc3a036b5f3af9de660.tar.gz
chromium_src-bc3ef7faa993606415465cc3a036b5f3af9de660.tar.bz2
Adds --convert-cg-to-glsl to the Collada converter tool.
Review URL: http://codereview.chromium.org/1750008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45514 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/import')
-rw-r--r--o3d/import/cross/collada.cc27
-rw-r--r--o3d/import/cross/collada.h10
2 files changed, 36 insertions, 1 deletions
diff --git a/o3d/import/cross/collada.cc b/o3d/import/cross/collada.cc
index cfc64b3..cb6dcac 100644
--- a/o3d/import/cross/collada.cc
+++ b/o3d/import/cross/collada.cc
@@ -35,6 +35,7 @@
#include "base/file_path.h"
#include "base/file_util.h"
+#include "base/process_util.h"
#include "base/string_util.h"
#include "core/cross/class_manager.h"
#include "core/cross/curve.h"
@@ -509,6 +510,26 @@ void BindParams(Param* input_param,
bool ok = input_param->Bind(output_param);
DCHECK_EQ(ok, true);
}
+
+// Runs effect_string through the filter, replacing it in place.
+bool ConvertCgToGlsl(const FilePath& converter, String* effect_string) {
+ FilePath temporary_file_name;
+ FILE* temporary_file = file_util::CreateAndOpenTemporaryFile(
+ &temporary_file_name);
+ if (!temporary_file)
+ return false;
+
+ fwrite(effect_string->c_str(), 1, effect_string->length(), temporary_file);
+ file_util::CloseFile(temporary_file);
+
+ CommandLine cmd_line(converter);
+ cmd_line.AppendLooseValue(L"-i");
+ cmd_line.AppendLooseValue(o3d::FilePathToWide(temporary_file_name));
+ bool rc = ::base::GetAppOutput(cmd_line, effect_string);
+
+ file_util::Delete(temporary_file_name, false);
+ return rc;
+}
} // namespace anonymous
bool Collada::BuildFloatAnimation(ParamFloat* result,
@@ -2178,6 +2199,12 @@ Effect* Collada::BuildEffect(FCDocument* doc, FCDEffect* collada_effect) {
<< "'";
return NULL;
}
+
+ if (options_.convert_cg_to_glsl) {
+ if (!ConvertCgToGlsl(options_.converter_tool, &effect_string))
+ O3D_ERROR(service_locator_) << "Shader conversion failed.";
+ }
+
if (options_.keep_original_data) {
// Cache the original data by URI so we can recover it later.
original_data_map_.AddData(file_path, effect_string, service_locator_);
diff --git a/o3d/import/cross/collada.h b/o3d/import/cross/collada.h
index e0c1a02..18b5937 100644
--- a/o3d/import/cross/collada.h
+++ b/o3d/import/cross/collada.h
@@ -162,7 +162,9 @@ class Collada {
condition_document(false),
up_axis(0.0f, 0.0f, 0.0f),
base_path(FilePath::kCurrentDirectory),
- convert_dds_to_png(false) {}
+ convert_dds_to_png(false),
+ convert_cg_to_glsl(false),
+ converter_tool() {}
// Whether or not to generate mip-maps on the textures we load.
bool generate_mipmaps;
@@ -187,6 +189,12 @@ class Collada {
// True means convert DDS files to PNGs. For cube map textures, this
// implies writing six separate PNGs.
bool convert_dds_to_png;
+
+ // If true, run converter tool on shaders.
+ bool convert_cg_to_glsl;
+
+ // Path to the shader converter tool.
+ FilePath converter_tool;
};
// Collada Param Names.