protected override PixelBox LockImpl(BasicBox lockBox, BufferLocking options)
        {
            //Entering critical section
            LockDeviceAccess();

            // Check for misuse
            if (((int)usage & (int)TextureUsage.RenderTarget) != 0)
            {
                throw new AxiomException(
                          "DirectX does not allow locking of or directly writing to RenderTargets. Use BlitFromMemory if you need the contents.");
            }

            // Set locking flags according to options
            var flags = D3D9Helper.ConvertEnum(options, usage);

            if (this.mapDeviceToBufferResources.Count == 0)
            {
                throw new AxiomException("There are no resources attached to this pixel buffer !!");
            }

            lockedBox      = lockBox;
            this.lockFlags = flags;

            var bufferResources = this.mapDeviceToBufferResources.First().Value;

            // Lock the source buffer.
            var lockedBuf = LockBuffer(bufferResources, lockBox, flags);

            //Leaving critical section
            UnlockDeviceAccess();

            return(lockedBuf);
        }
Beispiel #2
0
        public static D3D9.LockFlags ConvertEnum(BufferLocking locking, BufferUsage usage)
        {
            D3D9.LockFlags ret = 0;
            if (locking == BufferLocking.Discard)
            {
#if AXIOM_D3D_MANAGE_BUFFERS
                // Only add the discard flag for dynamic usgae and default pool
                if ((usage & BufferUsage.Dynamic) != 0 && (usage & BufferUsage.Discardable) != 0)
                {
                    ret |= D3D9.LockFlags.Discard;
                }
#else
                // D3D doesn't like discard or no_overwrite on non-dynamic buffers
                if ((usage & BufferUsage.Dynamic) != 0)
                {
                    ret |= D3D9.LockFlags.Discard;
                }
#endif
            }
            if (locking == BufferLocking.ReadOnly)
            {
                // D3D debug runtime doesn't like you locking managed buffers readonly
                // when they were created with write-only (even though you CAN read
                // from the software backed version)
                if ((usage & BufferUsage.WriteOnly) == 0)
                {
                    ret |= D3D9.LockFlags.ReadOnly;
                }
            }
            if (locking == BufferLocking.NoOverwrite)
            {
#if AXIOM_D3D_MANAGE_BUFFERS
                // Only add the nooverwrite flag for dynamic usgae and default pool
                if ((usage & BufferUsage.Dynamic) != 0 && (usage & BufferUsage.Discardable) != 0)
                {
                    ret |= D3D9.LockFlags.NoOverwrite;
                }
#else
                // D3D doesn't like discard or no_overwrite on non-dynamic buffers
                if ((usage & BufferUsage.Dynamic) != 0)
                {
                    ret |= D3D9.LockFlags.NoOverwrite;
                }
#endif
            }

            return(ret);
        }
		protected override PixelBox LockImpl( BasicBox lockBox, BufferLocking options )
		{
			//Entering critical section
			LockDeviceAccess();

			// Check for misuse
			if ( ( (int)usage & (int)TextureUsage.RenderTarget ) != 0 )
			{
				throw new AxiomException(
					"DirectX does not allow locking of or directly writing to RenderTargets. Use BlitFromMemory if you need the contents." );
			}

			// Set locking flags according to options
			var flags = D3D9Helper.ConvertEnum( options, usage );

			if ( this.mapDeviceToBufferResources.Count == 0 )
			{
				throw new AxiomException( "There are no resources attached to this pixel buffer !!" );
			}

			lockedBox = lockBox;
			this.lockFlags = flags;

			var bufferResources = this.mapDeviceToBufferResources.First().Value;

			// Lock the source buffer.
			var lockedBuf = LockBuffer( bufferResources, lockBox, flags );

			//Leaving critical section
			UnlockDeviceAccess();

			return lockedBuf;
		}
        protected PixelBox LockBuffer(BufferResources bufferResources, BasicBox lockBox, D3D9.LockFlags flags)
        {
            // Set extents and format
            // Note that we do not carry over the left/top/front here, since the returned
            // PixelBox will be re-based from the locking point onwards
            var rval = new PixelBox(lockBox.Width, lockBox.Height, lockBox.Depth, Format);

            if (bufferResources.Surface != null)
            {
                //Surface
                DX.DataRectangle lrect;                 // Filled in by D3D

                if (lockBox.Left == 0 && lockBox.Top == 0 && lockBox.Right == Width && lockBox.Bottom == Height)
                {
                    // Lock whole surface
                    lrect = bufferResources.Surface.LockRectangle(flags);
                }
                else
                {
                    var prect = ToD3DRectangle(lockBox);
                    lrect = bufferResources.Surface.LockRectangle(prect, flags);
                }

                FromD3DLock(rval, lrect);
            }
            else if (bufferResources.Volume != null)
            {
                // Volume
                var pbox = ToD3DBox(lockBox);                   // specify range to lock
                var lbox = bufferResources.Volume.LockBox(pbox, flags);
                FromD3DLock(rval, lbox);
            }

            return(rval);
        }