Exemplo n.º 1
0
        internal static unsafe void ClearTexture(Texture texture, Colour colour)
        {
            using (HardwarePixelBufferSharedPtr hbuf = texture.GetBuffer())
            {
                hbuf.Lock(HardwareBuffer.LockOptions.HBL_NORMAL);
                PixelBox pb = hbuf.CurrentLock;

                byte *destData          = (byte *)pb.data;
                uint  destPixelSize     = PixelUtil.GetNumElemBytes(pb.format);
                uint  destRowPitchBytes = pb.rowPitch * destPixelSize;

                ColourValue cv = new ColourValue(colour.Red / 255f, colour.Green / 255f, colour.Blue / 255f, colour.Alpha / 255f);
                for (uint i = 0; i < texture.Height; i++)
                {
                    for (uint j = 0; j < texture.Width; j++)
                    {
                        uint offset = (i * destRowPitchBytes) + (j * destPixelSize);
                        PixelUtil.PackColour(cv, pb.format, &destData[offset]);
                    }
                }

                hbuf.Unlock();
            }
        }