private static void init(ShaderI shader, Loader.LoadedCallbackMethod loadedCallback) { try { CameraConstant = shader.Variable("Camera"); PositionConstant = shader.Variable("Position"); SizeConstant = shader.Variable("Size"); ColorConstant = shader.Variable("Color"); var elements = new List <BufferLayoutElement>(); elements.Add(new BufferLayoutElement(BufferLayoutElementTypes.Vector2, BufferLayoutElementUsages.Position, 0, 0, 0)); BufferLayoutDesc = BufferLayoutDescAPI.New(elements); BufferLayout = BufferLayoutAPI.New(shader, shader, BufferLayoutDesc); } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) { loadedCallback(null, false); } return; } Loaded = true; if (loadedCallback != null) { loadedCallback(null, true); } }
private static void init(ShaderI shader, Loader.LoadedCallbackMethod loadedCallback) { try { CameraConstant = shader.Variable("Camera"); BillboardTransformConstant = shader.Variable("BillboardTransform"); DiffuseConstant = shader.Resource("Diffuse"); ColorPalletConstant = shader.Variable("ColorPallet"); ScalePalletConstant = shader.Variable("ScalePallet"); TransformsConstant = shader.Variable("Transforms"); var elements = new List <BufferLayoutElement>(); elements.Add(new BufferLayoutElement(BufferLayoutElementTypes.Vector3, BufferLayoutElementUsages.Position, 0, 0, 0)); elements.Add(new BufferLayoutElement(BufferLayoutElementTypes.Vector2, BufferLayoutElementUsages.UV, 0, 0, 3)); BufferLayoutDesc = BufferLayoutDescAPI.New(elements); BufferLayout = BufferLayoutAPI.New(shader, shader, BufferLayoutDesc); } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) { loadedCallback(null, false); } return; } Loaded = true; if (loadedCallback != null) { loadedCallback(null, true); } }
private void init(ShaderI shader, Texture2DI 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, }; indexBuffer = IndexBufferAPI.New(this, BufferUsages.Default, Indices); vertexBuffer = VertexBufferAPI.New(this, layoutDesc, BufferUsages.Default, VertexBufferTopologys.Triangle, Vertices); } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) { loadedCallback(this, false); } } Loaded = true; if (loadedCallback != null) { loadedCallback(this, true); } }