/// <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 mipCount = input.ReadInt(); try { _impl = renderSystem.CreateTexture1DImplementation(width, mipCount > 1, format, null); for (int i = 0; i < mipCount; i++) { byte[] byteBuffer = input.ReadByteArray(); _impl.SetData <byte>(byteBuffer, i, 0, width >> i, 0, byteBuffer.Length); } } 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="Texture1D"/>. This creates an empty texture. /// </summary> /// <param name="renderSystem">Render system used to create the underlying implementation.</param> /// <param name="width">The width of the texture in pixels.</param> /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying texture fails or the render /// system was not initialized.</exception> public Texture1D(IRenderSystemProvider renderSystem, int width) { if (renderSystem == null) { Dispose(); throw new TeslaException("Render system provider not set, cannot create graphics resource implementation."); } base.RenderSystem = renderSystem; try { _impl = renderSystem.CreateTexture1DImplementation(width, false, SurfaceFormat.Color, null); } 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="Texture1D"/>. This creates an empty texture. /// </summary> /// <param name="renderSystem">Render system used to create the underlying implementation.</param> /// <param name="width">The width of the texture in pixels.</param> /// <param name="genMipMap">Whether or not mip maps should be generated. If so, the levels are created.</param> /// <param name="format">The surface format.</param> /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying texture fails or the render /// system was not initialized.</exception> /// <exception cref="System.InvalidOperationException">Thrown if the texture does not support the format.</exception> public Texture1D(IRenderSystemProvider renderSystem, int width, bool genMipMap, SurfaceFormat format) { if (renderSystem == null) { Dispose(); throw new TeslaException("Render system provider not set, cannot create graphics resource implementation."); } if (!renderSystem.Renderer.Adapter.QueryTextureFormat(format, TextureDimensions.One)) { throw new InvalidOperationException(String.Format("Texture1D does not support {0} format", format)); } base.RenderSystem = renderSystem; try { _impl = renderSystem.CreateTexture1DImplementation(width, genMipMap, format, null); } catch (Exception e) { Dispose(); throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e); } }