Ejemplo n.º 1
0
 public static D3D.LockFlags ConvertEnum(BufferLocking locking, BufferUsage usage)
 {
     D3D.LockFlags d3dLockFlags = 0;
     if (locking == BufferLocking.Discard)
     {
         // D3D doesn't like discard or no_overwrite on non-dynamic buffers
         if ((usage & BufferUsage.Dynamic) != 0)
         {
             d3dLockFlags |= D3D.LockFlags.Discard;
         }
     }
     else 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)
         {
             d3dLockFlags |= D3D.LockFlags.ReadOnly;
         }
     }
     else if (locking == BufferLocking.NoOverwrite)
     {
         // D3D doesn't like discard or no_overwrite on non-dynamic buffers
         if ((usage & BufferUsage.Dynamic) != 0)
         {
             d3dLockFlags |= D3D.LockFlags.NoOverwrite;
         }
     }
     return(d3dLockFlags);
 }
Ejemplo n.º 2
0
        public Array Lock(bool read)
        {
            D3d.LockFlags d3dLockFlags = D3d.LockFlags.None;
            if (!read)
            {
                d3dLockFlags |= D3d.LockFlags.Discard;
            }

            Array lockedArray = d3dIndexBuffer.Lock(0, d3dLockFlags);

            d3dLock = true;
            return(lockedArray);
        }
Ejemplo n.º 3
0
        public static D3D.LockFlags ConvertEnum(BufferLocking locking, BufferUsage usage)
        {
            D3D.LockFlags ret = 0;
            if (locking == BufferLocking.Discard)
            {
#if !NO_OGRE_D3D_MANAGE_BUFFERS
                // Only add the discard flag for dynamic usgae and default pool
                if ((usage & BufferUsage.Dynamic) != 0 &&
                    (usage & BufferUsage.Discardable) != 0)
                {
                    ret |= D3D.LockFlags.Discard;
                }
#else
                // D3D doesn't like discard or no_overwrite on non-dynamic buffers
                if ((usage & BufferUsage.Dynamic) != 0)
                {
                    ret |= D3D.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 |= D3D.LockFlags.ReadOnly;
                }
            }
            if (locking == BufferLocking.NoOverwrite)
            {
#if !NO_OGRE_D3D_MANAGE_BUFFERS
                // Only add the nooverwrite flag for dynamic usgae and default pool
                if ((usage & BufferUsage.Dynamic) != 0 &&
                    (usage & BufferUsage.Discardable) != 0)
                {
                    ret |= D3D.LockFlags.NoOverwrite;
                }
#else
                // D3D doesn't like discard or no_overwrite on non-dynamic buffers
                if ((usage & BufferUsage.Dynamic) != 0)
                {
                    ret |= D3D.LockFlags.NoOverwrite;
                }
#endif
            }

            return(ret);
        }
Ejemplo n.º 4
0
        public static D3D.LockFlags ConvertEnum(BufferLocking locking)
        {
            D3D.LockFlags d3dLockFlags = 0;

            if (locking == BufferLocking.Discard)
            {
                d3dLockFlags |= D3D.LockFlags.Discard;
            }
            if (locking == BufferLocking.ReadOnly)
            {
                d3dLockFlags |= D3D.LockFlags.ReadOnly;
            }
            if (locking == BufferLocking.NoOverwrite)
            {
                d3dLockFlags |= D3D.LockFlags.NoOverwrite;
            }

            return(d3dLockFlags);
        }
Ejemplo n.º 5
0
        ///<summary>
        ///    Lock a box
        ///</summary>
        public override PixelBox LockImpl(BasicBox lockBox, BufferLocking options)
        {
            // Check for misuse
            if (((int)usage & (int)TextureUsage.RenderTarget) != 0)
            {
                throw new Exception("DirectX does not allow locking of or directly writing to RenderTargets. Use BlitFromMemory if you need the contents; " +
                                    "in D3D9HardwarePixelBuffer.LockImpl");
            }
            // Set extents and format
            PixelBox rval = new PixelBox(lockBox, format);

            // Set locking flags according to options
            D3D.LockFlags flags = D3D.LockFlags.None;
            switch (options)
            {
            case BufferLocking.Discard:
                // D3D only likes D3D.LockFlags.Discard if you created the texture with D3DUSAGE_DYNAMIC
                // debug runtime flags this up, could cause problems on some drivers
                if ((usage & BufferUsage.Dynamic) != 0)
                {
                    flags |= D3D.LockFlags.Discard;
                }
                break;

            case BufferLocking.ReadOnly:
                flags |= D3D.LockFlags.ReadOnly;
                break;

            default:
                break;
            }

            if (surface != null)
            {
                // Surface
                GraphicsStream data = null;
                int            pitch;
                if (lockBox.Left == 0 && lockBox.Top == 0 &&
                    lockBox.Right == width && lockBox.Bottom == height)
                {
                    // Lock whole surface
                    data = surface.LockRectangle(flags, out pitch);
                }
                else
                {
                    Rectangle prect = ToD3DRectangle(lockBox);             // specify range to lock
                    data = surface.LockRectangle(prect, flags, out pitch);
                }
                if (data == null)
                {
                    throw new Exception("Surface locking failed; in D3D9HardwarePixelBuffer.LockImpl");
                }
                FromD3DLock(rval, pitch, data);
            }
            else
            {
                // Volume
                D3D.Box       pbox = ToD3DBox(lockBox); // specify range to lock
                D3D.LockedBox lbox;                     // Filled in by D3D

                GraphicsStream data = volume.LockBox(pbox, flags, out lbox);
                FromD3DLock(rval, lbox, data);
            }
            return(rval);
        }
Ejemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <param name="length"></param>
 /// <param name="locking"></param>
 /// <returns></returns>
 protected override IntPtr LockImpl(int offset, int length, BufferLocking locking)
 {
     D3D.LockFlags d3dLocking           = D3DHelper.ConvertEnum(locking, usage);
     Microsoft.DirectX.GraphicsStream s = d3dBuffer.Lock(offset, length, d3dLocking);
     return(s.InternalData);
 }