public static IBufferLayout New(VideoTypes videoType, IDisposableResource parent, IShader shader, IBufferLayoutDesc desc) { IBufferLayout api = null; #if WIN32 if (videoType == VideoTypes.D3D9) { api = new D3D9.BufferLayout(parent, shader, desc); } #endif #if WIN32 || WINRT || WP8 if (videoType == VideoTypes.D3D11) { api = new D3D11.BufferLayout(parent, shader, desc); } #endif #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl if (videoType == VideoTypes.OpenGL) { api = new OpenGL.BufferLayout(parent, shader, desc); } #endif #if XNA if (videoType == VideoTypes.XNA) { api = new XNA.BufferLayout(parent, shader, desc); } #endif #if VITA if (videoType == VideoTypes.Vita) { api = new Vita.BufferLayout(parent, shader, desc); } #endif if (api == null) { Debug.ThrowError("BufferLayoutAPI", "Unsuported InputType: " + videoType); } return(api); }
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); } }
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); }