@@ -88,13 +88,13 @@ class ShaderCompiler final : public system::IApplicationFramework
88
88
}
89
89
#endif
90
90
91
- const ICPUShader* shader = open_shader_file (file_to_compile);
91
+ auto shader = open_shader_file (file_to_compile);
92
92
if (shader->getContentType () != IShader::E_CONTENT_TYPE::ECT_HLSL)
93
93
{
94
94
m_logger->log (" Error. Loaded shader file content is not HLSL." , ILogger::ELL_ERROR);
95
95
return false ;
96
96
}
97
- auto compilation_result = compile_shader (shader, file_to_compile);
97
+ auto compilation_result = compile_shader (shader. get () , file_to_compile);
98
98
99
99
// writie compiled shader to file as bytes
100
100
if (compilation_result && !output_filepath.empty ()) {
@@ -132,7 +132,7 @@ class ShaderCompiler final : public system::IApplicationFramework
132
132
}
133
133
134
134
135
- const ICPUShader* open_shader_file (std::string& filepath) {
135
+ core::smart_refctd_ptr< const ICPUShader> open_shader_file (std::string filepath) {
136
136
137
137
m_assetMgr = make_smart_refctd_ptr<asset::IAssetManager>(smart_refctd_ptr (m_system));
138
138
@@ -146,9 +146,19 @@ class ShaderCompiler final : public system::IApplicationFramework
146
146
return nullptr ;
147
147
}
148
148
assert (assets.size () == 1 );
149
+
150
+ // could happen when the file is missing an extension and we can't deduce its a shader
151
+ if (assets[0 ]->getAssetType ()==IAsset::ET_BUFFER)
152
+ {
153
+ auto buf = IAsset::castDown<ICPUBuffer>(assets[0 ]);
154
+ std::string source; source.resize (buf->getSize ()+1 );
155
+ memcpy (source.data (),buf->getPointer (),buf->getSize ());
156
+ return core::make_smart_refctd_ptr<ICPUShader>(source.data (), IShader::ESS_UNKNOWN, IShader::E_CONTENT_TYPE::ECT_HLSL, std::move (filepath));
157
+ }
158
+
149
159
smart_refctd_ptr<ICPUSpecializedShader> source = IAsset::castDown<ICPUSpecializedShader>(assets[0 ]);
150
160
151
- return source->getUnspecialized ();
161
+ return core::smart_refctd_ptr< const ICPUShader>( source->getUnspecialized () );
152
162
}
153
163
154
164
0 commit comments