forked from google/shaderc
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make basic functionality work as a JS library
- Loading branch information
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "include/shaderc/shaderc.hpp" | ||
#include <emscripten/bind.h> | ||
|
||
using namespace emscripten; | ||
using namespace shaderc; | ||
|
||
EMSCRIPTEN_BINDINGS(shaderc) { | ||
class_<SpvCompilationResult>("SpvCompilationResult") | ||
.function("GetErrorMessage", &SpvCompilationResult::GetErrorMessage) | ||
.function("GetBinary", | ||
optional_override([](SpvCompilationResult& self) { | ||
size_t length = self.end() - self.begin(); | ||
return val(typed_memory_view(length, self.begin())); | ||
})) | ||
; | ||
|
||
class_<CompileOptions>("CompileOptions") | ||
.constructor<>() | ||
; | ||
|
||
class_<Compiler>("Compiler") | ||
.constructor<>() | ||
.function("IsValid", &Compiler::IsValid) | ||
//.function("CompileGlslToSpv", &Compiler::CompileGlslToSpv) | ||
.function("CompileGlslToSpv", | ||
optional_override([](Compiler& self, | ||
const std::string& source_text, | ||
shaderc_shader_kind shader_kind, | ||
const std::string& input_file_name, | ||
const std::string& entry_point_name, | ||
const CompileOptions& options) { | ||
return self.CompileGlslToSpv( | ||
source_text.c_str(), | ||
source_text.length(), | ||
shader_kind, | ||
input_file_name.c_str(), | ||
entry_point_name.c_str(), | ||
options); | ||
})) | ||
; | ||
|
||
enum_<shaderc_shader_kind>("shader_kind") | ||
.value("vertex", shaderc_vertex_shader) | ||
.value("fragment", shaderc_fragment_shader) | ||
; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<script src="shaderc.js"></script> | ||
<script> | ||
var source = "#version 450\nvoid main() {}"; | ||
console.log(source); | ||
|
||
var compiler, opts, result, binary; | ||
setTimeout(() => { | ||
|
||
let S = Module; | ||
compiler = new S.Compiler(); | ||
console.log("compiler =", compiler); | ||
opts = new S.CompileOptions(); | ||
console.log("opts =", opts); | ||
|
||
var result = compiler.CompileGlslToSpv(source, S.shader_kind.vertex, "", "main", opts); | ||
console.log("result =", result); | ||
|
||
console.log(result.GetErrorMessage()); | ||
let binary = result.GetBinary(); | ||
console.log("binary =", binary.length, binary); | ||
}, 200); | ||
</script> |