/// <summary> /// Deserializes the object and populates it from the input. /// </summary> /// <param name="input">Savable input</param> /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying implementation fails or the render /// system is not set.</exception> public void Read(ISavableReader input) { IRenderSystemProvider renderSystem = input.RenderSystem; if (renderSystem == null) { Dispose(); throw new TeslaException("Render system provider not set, cannot create graphics resource implementation."); } base.RenderSystem = renderSystem; String name = input.ReadString(); int indexCount = input.ReadInt(); IndexFormat format = input.ReadEnum <IndexFormat>(); ResourceUsage usage = input.ReadEnum <ResourceUsage>(); byte[] byteBuffer = input.ReadByteArray(); try { _impl = renderSystem.CreateIndexBufferImplementation(format, indexCount, usage); _impl.Name = name; SetData <byte>(byteBuffer); } catch (Exception e) { Dispose(); throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e); } }
/// <summary> /// Creates a new instance of <see cref="IndexBuffer"/>. /// </summary> /// <param name="renderSystem">Render system used to create the underlying implementation.</param> /// <param name="data">The index data.</param> /// <param name="usage">The resource usage specifying the type of memory the buffer should use.</param> /// <exception cref="System.ArgumentNullException">Thrown if the render system is null.</exception> /// <exception cref="Tesla.Core.TeslaException">Thrown if creating underlying buffer fails.</exception> public IndexBuffer(IRenderSystemProvider renderSystem, DataBuffer <short> data, ResourceUsage usage) { if (renderSystem == null) { Dispose(); throw new ArgumentNullException("renderSystem", "Render system cannot be null."); } base.RenderSystem = renderSystem; try { _impl = renderSystem.CreateIndexBufferImplementation(data, usage); } catch (Exception e) { Dispose(); throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e); } }
/// <summary> /// Creates a new instance of <see cref="IndexBuffer"/>. /// </summary> /// <param name="data">The index data.</param> /// <param name="usage">The resource usage specifying the type of memory the buffer should use.</param> /// <exception cref="Tesla.Core.TeslaException">Thrown if creating underlying buffer fails or the render system /// was not initialized.</exception> public IndexBuffer(DataBuffer <short> data, ResourceUsage usage) { IRenderSystemProvider renderSystem = Engine.Services.GetService <IRenderSystemProvider>(); if (renderSystem == null) { Dispose(); throw new TeslaException("Render system provider not set, cannot create graphics resource implementation."); } base.RenderSystem = renderSystem; try { _impl = renderSystem.CreateIndexBufferImplementation(data, usage); } catch (Exception e) { Dispose(); throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e); } }