Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeviceContext10"/> class.
        /// </summary>
        /// <param name="handle">The window handle to associate with the device.</param>
        /// <param name="settings">The settings used to configure the device.</param>
        internal DeviceContext10(IntPtr handle, DeviceSettings10 settings)
        {
            if (handle == IntPtr.Zero)
                throw new ArgumentException("Value must be a valid window handle.", "handle");
            if (settings == null)
                throw new ArgumentNullException("settings");

            this.settings = settings;

            factory = new Factory();
            device = new Direct3D10.Device(factory.GetAdapter(settings.AdapterOrdinal), Direct3D10.DriverType.Hardware, settings.CreationFlags);

            swapChain = new SwapChain(factory, device, new SwapChainDescription
            {
                BufferCount = 1,
                Flags = SwapChainFlags.None,
                IsWindowed = true,
                ModeDescription = new ModeDescription(settings.Width, settings.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                OutputHandle = handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect = SwapEffect.Discard,
                Usage = Usage.RenderTargetOutput
            });

            factory.SetWindowAssociation(handle, WindowAssociationFlags.IgnoreAll | WindowAssociationFlags.IgnoreAltEnter);
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeviceContext10"/> class.
        /// </summary>
        /// <param name="handle">The window handle to associate with the device.</param>
        /// <param name="settings">The settings used to configure the device.</param>
        internal DeviceContext10(IntPtr handle, DeviceSettings10 settings)
        {
            if (handle == IntPtr.Zero)
            {
                throw new ArgumentException("Value must be a valid window handle.", "handle");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            this.settings = settings;

            factory = new Factory();
            device  = new Direct3D10.Device(factory.GetAdapter(settings.AdapterOrdinal), Direct3D10.DriverType.Hardware, settings.CreationFlags);

            swapChain = new SwapChain(factory, device, new SwapChainDescription
            {
                BufferCount       = 1,
                Flags             = SwapChainFlags.None,
                IsWindowed        = true,
                ModeDescription   = new ModeDescription(settings.Width, settings.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                OutputHandle      = handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput
            });

            factory.SetWindowAssociation(handle, WindowAssociationFlags.IgnoreAll | WindowAssociationFlags.IgnoreAltEnter);
        }
Пример #3
0
 /// <summary>
 ///
 /// </summary>
 public ConstantBuffer(Direct3D10.Device device)
     : this(device, new Direct3D10.BufferDescription
 {
     Usage = Direct3D10.ResourceUsage.Default,
     BindFlags = Direct3D10.BindFlags.ConstantBuffer,
     CpuAccessFlags = Direct3D10.CpuAccessFlags.None,
     OptionFlags = Direct3D10.ResourceOptionFlags.None,
 })
 {
 }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="device"></param>
        /// <param name="desc"></param>
        public ConstantBuffer(Direct3D10.Device device, Direct3D10.BufferDescription desc)
        {
            desc.SizeInBytes = Marshal.SizeOf(typeof(T));

            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            this.m_device = device;
            //_device.AddReference();

            m_buffer     = new Direct3D10.Buffer(device, desc);
            m_dataStream = new DataStream(desc.SizeInBytes, true, true);
        }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="disposing"></param>
        private void Dispose(bool disposing)
        {
            if (m_device == null)
            {
                return;
            }

            if (disposing)
            {
                m_dataStream.Dispose();
            }
            // NOTE: SharpDX 1.3 requires explicit Dispose() of all resource
            m_device.Dispose();
            m_buffer.Dispose();
            m_device = null;
            m_buffer = null;
        }
Пример #6
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="device"></param>
        /// <param name="range"></param>
        /// <returns></returns>
        public static Direct3D10.Buffer CreateBuffer <T>(this Direct3D10.Device device, T[] range)
            where T : struct
        {
            int sizeInBytes = Marshal.SizeOf(typeof(T));

            using (var stream = new DataStream(range.Length * sizeInBytes, true, true))
            {
                stream.WriteRange(range);
                return(new Direct3D10.Buffer(device, stream, new Direct3D10.BufferDescription
                {
                    BindFlags = Direct3D10.BindFlags.VertexBuffer,
                    SizeInBytes = (int)stream.Length,
                    CpuAccessFlags = Direct3D10.CpuAccessFlags.None,
                    OptionFlags = Direct3D10.ResourceOptionFlags.None,
                    Usage = Direct3D10.ResourceUsage.Default,
                }));
            }
        }
Пример #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="device"></param>
        /// <param name="w"></param>
        /// <param name="h"></param>
        /// <param name="flags"></param>
        /// <param name="format"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static Direct3D10.Texture2D CreateTexture2D(this Direct3D10.Device device,
                                                           int w, int h,
                                                           Direct3D10.BindFlags flags = Direct3D10.BindFlags.RenderTarget | Direct3D10.BindFlags.ShaderResource,
                                                           Format format = Format.B8G8R8A8_UNorm,
                                                           Direct3D10.ResourceOptionFlags options = Direct3D10.ResourceOptionFlags.Shared)
        {
            var colordesc = new Direct3D10.Texture2DDescription
            {
                BindFlags         = flags,
                Format            = format,
                Width             = w,
                Height            = h,
                MipLevels         = 1,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = Direct3D10.ResourceUsage.Default,
                OptionFlags       = options,
                CpuAccessFlags    = Direct3D10.CpuAccessFlags.None,
                ArraySize         = 1
            };

            return(new Direct3D10.Texture2D(device, colordesc));
        }