/// <inheritdoc/> public override void SetData <T>(T[] data, SetDataOrigin origin = SetDataOrigin.TopLeft) { if (willNotBeSampled) { throw new NotSupportedException(OpenGLStrings.RenderBufferWillNotBeSampled); } texture.SetData <T>(data, origin); }
/// <summary> /// Sets the texture's data. /// </summary> /// <param name="level">The mipmap level for which to set data.</param> /// <param name="rect">A rectangle describing the position and size of the data to set.</param> /// <param name="data">A pointer to the data to set.</param> /// <param name="offset">The index of the first element to set.</param> /// <param name="count">The number of elements to set.</param> /// <param name="stride">The number of elements in one row of data.</param> /// <param name="format">The format of the data being set.</param> /// <param name="origin">A <see cref="SetDataOrigin"/> value specifying the origin of the texture data in <paramref name="data"/>.</param> private unsafe void SetDataInternal(Int32 level, Rectangle?rect, IntPtr data, Int32 offset, Int32 count, Int32 stride, TextureDataFormat format, SetDataOrigin origin) { var region = rect ?? new Rectangle(0, 0, width, height); if (region.Width * region.Height != count) { throw new InvalidOperationException(UltravioletStrings.BufferIsWrongSize); } const Int32 SizeOfTextureElementInBytes = 4; var flipHorizontally = (origin == SetDataOrigin.TopRight || origin == SetDataOrigin.BottomRight); var flipVertically = (origin == SetDataOrigin.TopLeft || origin == SetDataOrigin.TopRight); TextureUtil.ReorientTextureData(data.ToPointer(), region.Width, region.Height, SizeOfTextureElementInBytes, flipHorizontally, flipVertically); if (flipHorizontally) { region = new Rectangle((width - region.Width) - region.X, region.Y, region.Width, region.Height); } if (flipVertically) { region = new Rectangle(region.X, (height - region.Height) - region.Y, region.Width, region.Height); } using (OpenGLState.ScopedBindTexture2D(texture)) { var rowLengthSupported = (!gl.IsGLES2 || gl.IsExtensionSupported("GL_EXT_unpack_subimage")); var rowLengthFallbackRequired = (stride != 0 && !rowLengthSupported); if (rowLengthFallbackRequired) { var ptr = (Byte *)data.ToPointer(); for (int i = 0; i < height; i++) { gl.TextureSubImage2D(texture, gl.GL_TEXTURE_2D, level, region.X, region.Y + i, region.Width, 1, GetOpenGLTextureFormat(format), gl.GL_UNSIGNED_BYTE, ptr); ptr += stride * 4; } } else { if (rowLengthSupported) { gl.PixelStorei(gl.GL_UNPACK_ROW_LENGTH, stride); gl.ThrowIfError(); } gl.PixelStorei(gl.GL_UNPACK_ALIGNMENT, 1); gl.ThrowIfError(); gl.TextureSubImage2D(texture, gl.GL_TEXTURE_2D, level, region.X, region.Y, region.Width, region.Height, GetOpenGLTextureFormat(format), gl.GL_UNSIGNED_BYTE, data.ToPointer()); gl.ThrowIfError(); if (rowLengthSupported) { gl.PixelStorei(gl.GL_UNPACK_ROW_LENGTH, 0); gl.ThrowIfError(); } } } }
/// <inheritdoc/> public override void SetData(Int32 level, Rectangle?rect, IntPtr data, Int32 offset, Int32 count, Int32 stride, TextureDataFormat format, SetDataOrigin origin = SetDataOrigin.TopLeft) { if (willNotBeSampled) { throw new NotSupportedException(OpenGLStrings.RenderBufferWillNotBeSampled); } texture.SetData(level, rect, data, offset, count, stride, format, origin); }
/// <inheritdoc/> public override void SetData <T>(Int32 level, Rectangle?rect, T[] data, Int32 offset, Int32 count, Int32 stride, SetDataOrigin origin = SetDataOrigin.TopLeft) { Contract.EnsureNotDisposed(this, Disposed); var handle = default(GCHandle); try { handle = GCHandle.Alloc(data, GCHandleType.Pinned); SetDataInternal(level, rect, handle.AddrOfPinnedObject(), offset, count, stride, TextureDataFormat.RGBA, origin); } finally { if (handle.IsAllocated) { handle.Free(); } } }
/// <inheritdoc/> public override void SetData(Int32 level, Rectangle?rect, IntPtr data, Int32 offset, Int32 count, Int32 stride, TextureDataFormat format, SetDataOrigin origin = SetDataOrigin.TopLeft) { Contract.EnsureNotDisposed(this, Disposed); SetDataInternal(level, rect, data, offset, count, stride, format, origin); }
/// <inheritdoc/> public override void SetData <T>(T[] data, SetDataOrigin origin = SetDataOrigin.TopLeft) { SetData(0, null, data, 0, (data == null) ? 0 : data.Length); }
/// <inheritdoc/> public override void SetData <T>(T[] data, Int32 offset, Int32 count, SetDataOrigin origin = SetDataOrigin.TopLeft) { SetData(0, null, data, offset, count); }
/// <summary> /// Sets the texture's data. /// </summary> /// <param name="level">The mipmap level for which to set data.</param> /// <param name="rect">A rectangle describing the position and size of the data to set.</param> /// <param name="data">A pointer to the data to set.</param> /// <param name="offset">The index of the first element to set.</param> /// <param name="count">The number of elements to set.</param> /// <param name="stride">The number of elements in one row of data.</param> /// <param name="format">The format of the data being set.</param> /// <param name="origin">A <see cref="SetDataOrigin"/> value specifying the origin of the texture data in <paramref name="data"/>.</param> private unsafe void SetDataInternal(Int32 level, Rectangle?rect, IntPtr data, Int32 offset, Int32 count, Int32 stride, TextureDataFormat format, SetDataOrigin origin) { var region = rect ?? new Rectangle(0, 0, width, height); if (region.Width * region.Height != count) { throw new InvalidOperationException(UltravioletStrings.BufferIsWrongSize); } const Int32 SizeOfTextureElementInBytes = 4; var flipHorizontally = (origin == SetDataOrigin.TopRight || origin == SetDataOrigin.BottomRight); var flipVertically = (origin == SetDataOrigin.TopLeft || origin == SetDataOrigin.TopRight); TextureUtil.ReorientTextureData(data.ToPointer(), region.Width, region.Height, SizeOfTextureElementInBytes, flipHorizontally, flipVertically); if (flipHorizontally) { region = new Rectangle((width - region.Width) - region.X, region.Y, region.Width, region.Height); } if (flipVertically) { region = new Rectangle(region.X, (height - region.Height) - region.Y, region.Width, region.Height); } using (OpenGLState.ScopedBindTexture2D(texture)) { gl.PixelStorei(gl.GL_UNPACK_ROW_LENGTH, stride); gl.ThrowIfError(); gl.PixelStorei(gl.GL_UNPACK_ALIGNMENT, 1); gl.ThrowIfError(); gl.TextureSubImage2D(texture, gl.GL_TEXTURE_2D, level, region.X, region.Y, region.Width, region.Height, GetOpenGLTextureFormat(format), gl.GL_UNSIGNED_BYTE, data.ToPointer()); gl.ThrowIfError(); gl.PixelStorei(gl.GL_UNPACK_ROW_LENGTH, 0); gl.ThrowIfError(); } }
/// <summary> /// Sets the texture's data. /// </summary> /// <typeparam name="T">The type of the elements in the array being set as the texture's data.</typeparam> /// <param name="data">An array containing the data to set.</param> /// <param name="offset">The index of the first element to set.</param> /// <param name="count">The number of elements to set.</param> /// <param name="origin">A <see cref="SetDataOrigin"/> value specifying the origin of the texture data in <paramref name="data"/>.</param> public abstract void SetData <T>(T[] data, Int32 offset, Int32 count, SetDataOrigin origin = SetDataOrigin.TopLeft) where T : struct;
/// <summary> /// Sets the texture's data. /// </summary> /// <typeparam name="T">The type of the elements in the array being set as the texture's data.</typeparam> /// <param name="data">An array containing the data to set.</param> /// <param name="origin">A <see cref="SetDataOrigin"/> value specifying the origin of the texture data in <paramref name="data"/>.</param> public abstract void SetData <T>(T[] data, SetDataOrigin origin = SetDataOrigin.TopLeft) where T : struct;
/// <summary> /// Sets the texture's data. /// </summary> /// <param name="level">The mipmap level for which to set data.</param> /// <param name="rect">A rectangle describing the position and size of the data to set, or <see langword="null"/> to set the entire texture.</param> /// <param name="data">A pointer to the data to set.</param> /// <param name="offset">The index of the first element to set.</param> /// <param name="count">The number of elements to set.</param> /// <param name="stride">The number of elements in one row of data, or zero to use the width of <paramref name="rect"/>.</param> /// <param name="format">The format of the data being set.</param> /// <param name="origin">A <see cref="SetDataOrigin"/> value specifying the origin of the texture data in <paramref name="data"/>.</param> public abstract void SetData(Int32 level, Rectangle?rect, IntPtr data, Int32 offset, Int32 count, Int32 stride, TextureDataFormat format, SetDataOrigin origin = SetDataOrigin.TopLeft);
/// <summary> /// Sets the texture's data. /// </summary> /// <typeparam name="T">The type of the elements of the array to set as the texture's data.</typeparam> /// <param name="level">The mipmap level for which to set data.</param> /// <param name="rect">A rectangle describing the position and size of the data to set, or <see langword="null"/> to set the entire texture.</param> /// <param name="data">An array containing the data to set.</param> /// <param name="offset">The index of the first element to set.</param> /// <param name="count">The number of elements to set.</param> /// <param name="stride">The number of elements in one row of data, or zero to use the width of <paramref name="rect"/>.</param> /// <param name="origin">A <see cref="SetDataOrigin"/> value specifying the origin of the texture data in <paramref name="data"/>.</param> public abstract void SetData <T>(Int32 level, Rectangle?rect, T[] data, Int32 offset, Int32 count, Int32 stride, SetDataOrigin origin = SetDataOrigin.TopLeft) where T : struct;