public Texture2DGL3x(Texture2DDescription description, TextureTarget textureTarget) { if (description.Width <= 0) { throw new ArgumentOutOfRangeException("description.Width", "description.Width must be greater than zero."); } if (description.Height <= 0) { throw new ArgumentOutOfRangeException("description.Height", "description.Height must be greater than zero."); } if (description.GenerateMipmaps) { if (textureTarget == TextureTarget.TextureRectangle) { throw new ArgumentException("description.GenerateMipmaps cannot be true for texture rectangles.", "description"); } if (!TextureUtility.IsPowerOfTwo(Convert.ToUInt32(description.Width))) { throw new ArgumentException("When description.GenerateMipmaps is true, the width must be a power of two.", "description"); } if (!TextureUtility.IsPowerOfTwo(Convert.ToUInt32(description.Height))) { throw new ArgumentException("When description.GenerateMipmaps is true, the height must be a power of two.", "description"); } } _name = new TextureNameGL3x(); _target = textureTarget; _description = description; _lastTextureUnit = OpenTKTextureUnit.Texture0 + (Device.NumberOfTextureUnits - 1); // // TexImage2D is just used to allocate the texture so a PBO can't be bound. // WritePixelBufferGL3x.UnBind(); BindToLastTextureUnit(); GL.TexImage2D(_target, 0, TypeConverterGL3x.To(description.TextureFormat), description.Width, description.Height, 0, TypeConverterGL3x.TextureToPixelFormat(description.TextureFormat), TypeConverterGL3x.TextureToPixelType(description.TextureFormat), new IntPtr()); // // Default sampler, compatiable when attaching a non-mimapped // texture to a frame buffer object. // ApplySampler(Device.TextureSamplers.LinearClamp); GC.AddMemoryPressure(description.ApproximateSizeInBytes); }
public override void CopyFromBuffer( WritePixelBuffer pixelBuffer, int xOffset, int yOffset, int width, int height, ImageFormat format, ImageDatatype dataType, int rowAlignment) { if (pixelBuffer.SizeInBytes < TextureUtility.RequiredSizeInBytes( width, height, format, dataType, rowAlignment)) { throw new ArgumentException("Pixel buffer is not big enough for provided width, height, format, and datatype."); } if (xOffset < 0) { throw new ArgumentOutOfRangeException("xOffset", "xOffset must be greater than or equal to zero."); } if (yOffset < 0) { throw new ArgumentOutOfRangeException("yOffset", "yOffset must be greater than or equal to zero."); } if (xOffset + width > _description.Width) { throw new ArgumentOutOfRangeException("xOffset + width must be less than or equal to Description.Width"); } if (yOffset + height > _description.Height) { throw new ArgumentOutOfRangeException("yOffset + height must be less than or equal to Description.Height"); } VerifyRowAlignment(rowAlignment); WritePixelBufferGL3x bufferObjectGL = (WritePixelBufferGL3x)pixelBuffer; bufferObjectGL.Bind(); BindToLastTextureUnit(); GL.PixelStore(PixelStoreParameter.UnpackAlignment, rowAlignment); GL.TexSubImage2D(_target, 0, xOffset, yOffset, width, height, TypeConverterGL3x.To(format), TypeConverterGL3x.To(dataType), new IntPtr()); GenerateMipmaps(); }