An open API service indexing awesome lists of open source software.

https://github.com/jpbruyere/shaderc.net

shaderc net binding
https://github.com/jpbruyere/shaderc.net

binding csharp net opengl shader shaderc vulkan

Last synced: 11 months ago
JSON representation

shaderc net binding

Awesome Lists containing this project

README

          









# shaderc.net

Net bindings for [google shaderc](https://github.com/google/shaderc).

#### spirv compilation
This sample use [vk.net](https://github.com/jpbruyere/vk.net) to create the shader module.
On success, `Result` object will hold a native pointer on the generated spirv code suitable for the `ShaderModuleCreateInfo` pCode field. This pointer will stay valid until the `Result` disposal.

```csharp
using (Compiler comp = new Compiler ()) {
using (Result res = comp.Compile ("test.vert", ShaderKind.VertexShader)) {
if (res.Status == Status.Success) {
VkShaderModuleCreateInfo ci = VkShaderModuleCreateInfo.New ();
ci.codeSize = res.codeSize;
ci.pCode = res.code;
vkCreateShaderModule (VkDev, ref moduleCreateInfo, IntPtr.Zero, out VkShaderModule shaderModule));
```

#### Resolving includes
**shaderc** library provide the ability to add `#include` statements as in **c/c++**. This functionality is enabled or not in the `Options` class constructor, the default is enabled.
```csharp
Options opt = new Options(false);
```
A default `Options` instance is created by the `Compiler` constructor which enable the include resolution. You may provide a custom Options instance to the compiler constructor.
```csharp
Compiler comp = new Compiler (opt);
comp.Options.InvertY = true;
```
As in **c/c++**, you may have local or global include (enclosed in "" or <>). Local includes enclosed in "" will be searched from the current parsed source file. Global includes enclosed in '<>' will be searched in directories listed in ```Options.IncludeDirectories```. The pathes may be relative to the executable directory, or absolute.
```csharp
comp.Options.IncludeDirectories.AddRange ("shaders", @"c:\test");
```
If you want to override the default include resolution, to search for embedded ressources for example, derive the `Options` class and override the `TryFindInclude` method.
```csharp
class OptionsWithCustomIncResolve : Options {
protected override bool TryFindInclude (string sourcePath, string includePath, IncludeType incType, out string incFile, out string incContent) {
...
```