예제 #1
0
        public override void BlitToMemory(Media.BasicBox srcBox, Media.PixelBox dst)
        {
            if (!this.Buffer.Contains(srcBox))
            {
                throw new ArgumentOutOfRangeException("srcBox", "source box out of range.");
            }

            if (srcBox.Left == 0 && srcBox.Right == width && srcBox.Top == 0 && srcBox.Bottom == height && srcBox.Front == 0 && srcBox.Back == depth && dst.Width == width && dst.Height == height && dst.Depth == depth && GLES2PixelUtil.GetGLOriginFormat(dst.Format) != 0)
            {
                //The direct case: the user wants the entire texture in a format supported by GL
                //so we don't need an intermediate buffer
                this.Download(dst);
            }
            else
            {
                //Use buffer for intermediate copy
                this.AllocateBuffer();
                //Download entire buffer
                this.Download(this.Buffer);
                if (srcBox.Width != dst.Width || srcBox.Height != dst.Height || srcBox.Depth != dst.Depth)
                {
                    //We need scaling
                    Image.Scale(this.Buffer.GetSubVolume(srcBox), dst, ImageFilter.Bilinear);
                }
                else
                {
                    //Just copy the bit that we need
                    PixelConverter.BulkPixelConversion(this.Buffer.GetSubVolume(srcBox), dst);
                }

                this.FreeBuffer();
            }
        }
예제 #2
0
 protected override Media.PixelBox LockImpl(Media.BasicBox lockBox, BufferLocking options)
 {
     this.AllocateBuffer();
     if (options != BufferLocking.Discard && (usage & BufferUsage.WriteOnly) == 0)
     {
         //Downoad the old contents of the texture
         this.Download(this.Buffer);
     }
     this.CurrentLockOptions = options;
     lockedBox = lockBox;
     return(this.Buffer.GetSubVolume(lockBox));
 }
예제 #3
0
        /// <summary>
        /// </summary>
        /// <param name="src"> </param>
        /// <param name="dstBox"> </param>
        public override void BlitFromMemory(PixelBox src, Media.BasicBox dstBox)
        {
            if (!this._buffer.Contains(dstBox))
            {
                throw new ArgumentOutOfRangeException("Destination box out of range, GLESHardwarePixelBuffer.BlitToMemory");
            }

            PixelBox scaled;

            if (src.Width != dstBox.Width || src.Height != dstBox.Height || src.Depth != dstBox.Depth)
            {
                LogManager.Instance.Write("[GLESHardwarePixelBuffer] Scale to destination size.");
                // Scale to destination size. Use DevIL and not iluScale because ILU screws up for
                // floating point textures and cannot cope with 3D images.
                // This also does pixel format conversion if needed
                AllocateBuffer();
                scaled = this._buffer.GetSubVolume(dstBox);
                Image.Scale(src, scaled, ImageFilter.Bilinear);
            }
            else if ((src.Format != Format) || ((GLESPixelUtil.GetGLOriginFormat(src.Format) == 0) && (src.Format != PixelFormat.R8G8B8)))
            {
                LogManager.Instance.Write("[GLESHardwarePixelBuffer] Extents match, but format is not accepted as valid source format for GL.");
                LogManager.Instance.Write("[GLESHardwarePixelBuffer] Source.Format = {0}, Format = {1}, GLOriginFormat = {2}", src.Format, Format, GLESPixelUtil.GetGLOriginFormat(src.Format));
                // Extents match, but format is not accepted as valid source format for GL
                // do conversion in temporary buffer
                AllocateBuffer();
                scaled = this._buffer.GetSubVolume(dstBox);

                PixelConverter.BulkPixelConversion(src, scaled);
            }
            else
            {
                LogManager.Instance.Write("[GLESHardwarePixelBuffer] No scaling or conversion needed.");
                scaled = src;
                if (src.Format == PixelFormat.R8G8B8)
                {
                    scaled.Format = PixelFormat.R8G8B8;
                    PixelConverter.BulkPixelConversion(src, scaled);
                }
                // No scaling or conversion needed
                // Set extents for upload
                scaled.Left   = dstBox.Left;
                scaled.Right  = dstBox.Right;
                scaled.Top    = dstBox.Top;
                scaled.Bottom = dstBox.Bottom;
                scaled.Front  = dstBox.Front;
                scaled.Back   = dstBox.Back;
            }

            Upload(scaled, dstBox);
            FreeBuffer();
        }
예제 #4
0
        public override void BlitFromMemory(Media.PixelBox src, Media.BasicBox dstBox)
        {
            if (this.Buffer.Contains(dstBox) == false)
            {
                throw new ArgumentOutOfRangeException("dstBox", "Destination box out of range");
            }

            PixelBox scaled;

            if (src.Width != dstBox.Width || src.Height != dstBox.Height || src.Depth != dstBox.Depth)
            {
                //Scale to destination size
                //This also does pixel format conversion if needed
                this.AllocateBuffer();
                scaled = this.Buffer.GetSubVolume(dstBox);
                Image.Scale(src, scaled, ImageFilter.Bilinear);
            }
            else if ((src.Format != format) || ((GLES2PixelUtil.GetGLOriginFormat(src.Format) == 0) && (src.Format != PixelFormat.R8G8B8)))
            {
                //Extents match, but format is not accepted as valid source format for GL
                //do conversion in temporary buffer
                this.AllocateBuffer();
                scaled = this.Buffer.GetSubVolume(dstBox);
                PixelConverter.BulkPixelConversion(src, scaled);
                if (src.Format == PixelFormat.A4R4G4B4)
                {
                    // ARGB->BGRA
                    GLES2PixelUtil.ConvertToGLFormat(ref scaled, ref scaled);
                }
            }
            else
            {
                this.AllocateBuffer();
                scaled = src.Clone();

                if (src.Format == PixelFormat.R8G8B8)
                {
                    scaled.Format = PixelFormat.B8G8R8;
                    PixelConverter.BulkPixelConversion(src, scaled);
                }
            }

            this.Upload(scaled, dstBox);
            this.FreeBuffer();
        }