From 7c81952179f0ff08cfdd8f571eb1c0f06e224070 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 11 Dec 2012 14:39:32 +0000 Subject: [PATCH] Cycles: trick to make building with OSL trunk work as well, it has a different name for LoadMemoryShader so we make it call the right name depending on which is available. --- intern/cycles/render/osl.cpp | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/intern/cycles/render/osl.cpp b/intern/cycles/render/osl.cpp index e4ee40d881e..b3b838be25b 100644 --- a/intern/cycles/render/osl.cpp +++ b/intern/cycles/render/osl.cpp @@ -268,9 +268,43 @@ const char *OSLShaderManager::shader_load_filepath(string filepath) return shader_load_bytecode(bytecode_hash, bytecode); } +/* don't try this at home .. this is a template trick to use either + * LoadMemoryShader or LoadMemoryCompiledShader which are the function + * names in our custom branch and the official repository. */ + +template struct enable_if { typedef T type; }; +template struct enable_if { }; + +template +struct has_LoadMemoryCompiledShader { + typedef int yes; + typedef char no; + + template struct type_check; + template static yes &chk(type_check*); + template static no &chk(...); + static bool const value = sizeof(chk(0)) == sizeof(yes); +}; + +template +typename enable_if::value, bool>::type +load_memory_shader(T *ss, const char *name, const char *buffer) +{ + return ss->LoadMemoryCompiledShader(name, buffer); +} + +template +typename enable_if::value, bool>::type +load_memory_shader(T *ss, const char *name, const char *buffer) +{ + return ss->LoadMemoryShader(name, buffer); +} + const char *OSLShaderManager::shader_load_bytecode(const string& hash, const string& bytecode) { - ss->LoadMemoryShader(hash.c_str(), bytecode.c_str()); + load_memory_shader(ss, hash.c_str(), bytecode.c_str()); return loaded_shaders.insert(hash).first->c_str(); }