/// <summary> /// Sets the data from the texture. /// </summary> /// <typeparam name="T">Type of data in the array</typeparam> /// <param name="data">The array of data</param> /// <exception cref="System.ArgumentNullException">Thrown if data is null.</exception> /// <exception cref="Tesla.Core.TeslaException">Thrown if there is an error writing to the texture /// or arguments are invalid, check the inner exception for additional details.</exception> /// <remarks>See implementors for details on other exceptions that can be thrown.</remarks> public void SetData <T>(T[] data) where T : struct { if (data == null || data.Length == 0) { throw new ArgumentNullException("Data cannot be null."); } try { _impl.SetData <T>(data, 0, 0, _impl.Width, 0, _impl.Height, 0, _impl.Depth, 0, data.Length); } catch (Exception e) { throw new TeslaException("Error writing to texture: \n" + e.Message, e); } }
/// <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 override 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(); SurfaceFormat format = input.ReadEnum <SurfaceFormat>(); int width = input.ReadInt(); int height = input.ReadInt(); int depth = input.ReadInt(); int mipCount = input.ReadInt(); try { _impl = renderSystem.CreateTexture3DImplementation(width, height, depth, mipCount > 1, format, null); for (int i = 0; i < mipCount; i++) { byte[] byteBuffer = input.ReadByteArray(); _impl.SetData <byte>(byteBuffer, i, 0, width, 0, height, 0, depth, 0, byteBuffer.Length); width = System.Math.Max(width >> 1, 1); height = System.Math.Max(height >> 1, 1); depth = System.Math.Max(depth >> 1, 1); } } catch (Exception e) { Dispose(); throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e); } }