public Shader(ShaderStages stage, string entryPoint, IShaderResource glslShader, IShaderResource metalShader, IShaderResource hlslShader, IShaderResource spirvShader) { Stage = stage; EntryPoint = entryPoint; GlslShader = glslShader; MetalShader = metalShader; HlslShader = hlslShader; SpirvShader = spirvShader; }
private void init(IShader shader, ITexture2D texture, Stream stream, string metricsFileName, Loader.LoadedCallbackMethod loadedCallback) { try { // load characters var metrics = new FontMetrics(); metrics.Load(stream); Characters = new Character[metrics.Characters.Length]; for (int i = 0; i != metrics.Characters.Length; ++i) { var character = metrics.Characters[i]; Characters[i] = new Character(character.Key, new Vector2(character.X, character.Y), new Vector2(character.Width, character.Height)); } // get shader variables this.texture = texture; this.shader = shader; shaderCamera = shader.Variable("Camera"); shaderPosition = shader.Variable("Position"); shaderSize = shader.Variable("Size"); shaderPositionUV = shader.Variable("PositionUV"); shaderSizeUV = shader.Variable("SizeUV"); texelOffset = shader.Variable("TexelOffset"); shaderColor = shader.Variable("Color"); shaderTexture = shader.Resource("DiffuseTexture"); // create buffers var layoutDesc = BufferLayoutDescAPI.New(BufferLayoutTypes.Position2); layout = BufferLayoutAPI.New(this, shader, layoutDesc); var Indices = new int[6] { 0, 1, 2, 0, 2, 3 }; var Vertices = new float[8] { 0, 0, 0, 1, 1, 1, 1, 0, }; vertexBuffer = VertexBufferAPI.New(this, layoutDesc, BufferUsages.Default, VertexBufferTopologys.Triangle, Vertices, Indices); } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) { loadedCallback(this, false); } } Loaded = true; if (loadedCallback != null) { loadedCallback(this, true); } }
public void SetResource(int index, IShaderResource resource) { OnSetResource(index, resource); _resources[index] = resource; }
private void init(IShader shader, ITexture2D texture, Stream stream, string metricsFileName, Loader.LoadedCallbackMethod loadedCallback) { try { // load characters var metrics = new FontMetrics(); metrics.Load(stream); Characters = new Character[metrics.Characters.Length]; for (int i = 0; i != metrics.Characters.Length; ++i) { var character = metrics.Characters[i]; Characters[i] = new Character(character.Key, new Vector2(character.X, character.Y), new Vector2(character.Width, character.Height)); } // get shader variables this.texture = texture; this.shader = shader; shaderCamera = shader.Variable("Camera"); shaderPosition = shader.Variable("Position"); shaderSize = shader.Variable("Size"); shaderPositionUV = shader.Variable("PositionUV"); shaderSizeUV = shader.Variable("SizeUV"); texelOffset = shader.Variable("TexelOffset"); shaderColor = shader.Variable("Color"); shaderTexture = shader.Resource("DiffuseTexture"); // create buffers var layoutDesc = BufferLayoutDescAPI.New(BufferLayoutTypes.Position2); layout = BufferLayoutAPI.New(this, shader, layoutDesc); var Indices = new int[6] { 0, 1, 2, 0, 2, 3 }; var Vertices = new float[8] { 0, 0, 0, 1, 1, 1, 1, 0, }; vertexBuffer = VertexBufferAPI.New(this, layoutDesc, BufferUsages.Default, VertexBufferTopologys.Triangle, Vertices, Indices); } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) loadedCallback(this, false); } Loaded = true; if (loadedCallback != null) loadedCallback(this, true); }
protected abstract void OnSetResource(int index, IShaderResource resource);