Example #1
0
 internal RenderTarget2D(GraphicsDevice device, Direct3D11.Texture2D texture, RenderTargetView renderTargetView = null, bool pureRenderTarget = false)
     : base(device.MainDevice, texture)
 {
     this.pureRenderTarget = pureRenderTarget;
     this.customRenderTargetView = renderTargetView;
     Initialize(Resource);
 }
Example #2
0
        internal GraphicsDeviceFeatures(Direct3D11.Device device)
        {
            mapFeaturesPerFormat = new FeaturesPerFormat[256];

            // Check global features
            Level = device.FeatureLevel;
            HasComputeShaders = device.CheckFeatureSupport(Feature.ComputeShaders);
            HasDoublePrecision = device.CheckFeatureSupport(Feature.ShaderDoubles);
            device.CheckThreadingSupport(out HasMultiThreadingConcurrentResources, out this.HasDriverCommandLists);

            // Check features for each DXGI.Format
            foreach (var format in Enum.GetValues(typeof(DXGI.Format)))
            {
                var dxgiFormat = (DXGI.Format) format;
                var maximumMSAA = MSAALevel.None;
                var computeShaderFormatSupport = ComputeShaderFormatSupport.None;
                var formatSupport = FormatSupport.None;

                if (!ObsoleteFormatToExcludes.Contains(dxgiFormat))
                {
                    maximumMSAA = GetMaximumMSAASampleCount(device, dxgiFormat);
                    if (HasComputeShaders)
                        computeShaderFormatSupport = device.CheckComputeShaderFormatSupport(dxgiFormat);

                    formatSupport = device.CheckFormatSupport(dxgiFormat);
                }

                mapFeaturesPerFormat[(int)dxgiFormat] = new FeaturesPerFormat(dxgiFormat, maximumMSAA, computeShaderFormatSupport, formatSupport);
            }
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BlendState" /> class.
 /// </summary>
 /// <param name="device">The device local.</param>
 /// <param name="nativeState">State of the native.</param>
 /// <param name="blendFactor">The blend factor.</param>
 /// <param name="mask">The mask.</param>
 private BlendState(GraphicsDevice device, Direct3D11.BlendState nativeState, Color4 blendFactor, int mask) : base(device)
 {
     Description = nativeState.Description;
     BlendFactor = blendFactor;
     MultiSampleMask = mask;
     Initialize(nativeState);
 }
Example #4
0
 internal DepthStencilBuffer(GraphicsDevice device, Direct3D11.Texture2D texture, DepthFormat depthFormat)
     : base(device, texture)
 {
     DepthFormat = depthFormat;
     DefaultViewFormat = ComputeViewFormat(DepthFormat, out HasStencil);
     Initialize(Resource);
     HasReadOnlyView = InitializeViewsDelayed(out ReadOnlyView);
 }
Example #5
0
 private Direct3D11Device()
 {
     try
     {
         m_device = Direct3D11.Create();
     }
     catch (Exception)
     {
     }
 }
Example #6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="cFlags"></param>
 /// <param name="minLevel"></param>
 /// <returns></returns>
 public static SharpDX.Direct3D11.Device Create11(
     Direct3D11.DeviceCreationFlags cFlags = Direct3D11.DeviceCreationFlags.None,
     Direct3D.FeatureLevel minLevel = Direct3D.FeatureLevel.Level_9_1)
 {
     using (var dg = new DisposeGroup())
     {
         var ada = GetBestAdapter(dg);
         if (ada == null)
             return null;
         var level = Direct3D11.Device.GetSupportedFeatureLevel(ada);
         if (level < minLevel)
             return null;
         return new Direct3D11.Device(ada, cFlags, level);
     }
 }
Example #7
0
        /// <summary>
        /// Creates new instance of <see cref="D3D11Image"/> Associates an D3D11 render target with the current instance.
        /// </summary>
        /// <param name="device">A valid D3D9 DeviceEx.</param>
        /// <param name="renderTarget">A valid D3D11 render target. It must be created with the "Shared" flag.</param>
        public D3D11Image(DeviceEx device, Direct3D11.Texture2D renderTarget)
        {
            using (var resource = renderTarget.QueryInterface<DXGI.Resource>())
            {
                var handle = resource.SharedHandle;
                texture = new Texture(device,
                                      renderTarget.Description.Width,
                                      renderTarget.Description.Height,
                                      1,
                                      Usage.RenderTarget,
                                      Format.A8R8G8B8,
                                      Pool.Default,
                                      ref handle);
            }

            using (var surface = texture.GetSurfaceLevel(0))
            {
                textureSurfaceHandle = surface.NativePointer;
                TrySetBackbufferPointer(textureSurfaceHandle);
            }

            this.IsFrontBufferAvailableChanged += HandleIsFrontBufferAvailableChanged;
        }
Example #8
0
 internal RenderTargetCube(GraphicsDevice device, Direct3D11.Texture2D texture)
     : base(device, texture)
 {
     Initialize(Resource);
 }
Example #9
0
 /// <summary>	
 /// <p>Create a sampler-state object that encapsulates sampling information for a texture.</p>	
 /// </summary>	
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="samplerState">An existing <see cref="Direct3D11.SamplerState"/> instance.</param>	
 /// <returns>A new <see cref="SamplerState"/> instance</returns>	
 /// <remarks>	
 /// <p>4096 unique sampler state objects can be created on a device at a time.</p><p>If an application attempts to create a sampler-state interface with the same state as an existing interface, the same interface will be returned and the total number of unique sampler state objects will stay the same.</p>	
 /// </remarks>	
 /// <msdn-id>ff476518</msdn-id>	
 /// <unmanaged>HRESULT ID3D11Device::CreateSamplerState([In] const D3D11_SAMPLER_DESC* pSamplerDesc,[Out, Fast] ID3D11SamplerState** ppSamplerState)</unmanaged>	
 /// <unmanaged-short>ID3D11Device::CreateSamplerState</unmanaged-short>	
 public static SamplerState New(GraphicsDevice device, Direct3D11.SamplerState samplerState)
 {
     return new SamplerState(device, samplerState);
 }
Example #10
0
 /// <summary>
 /// Creates a new <see cref="RenderTargetCube"/> from a <see cref="Direct3D11.Texture2D"/>.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="texture">The native texture <see cref="Direct3D11.Texture2D"/>.</param>
 /// <returns>
 /// A new instance of <see cref="RenderTargetCube"/> class.
 /// </returns>
 /// <msdn-id>ff476521</msdn-id>	
 /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged>	
 /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short>	
 public static RenderTargetCube New(GraphicsDevice device, Direct3D11.Texture2D texture)
 {
     return new RenderTargetCube(device, texture);
 }
Example #11
0
 /// <summary>	
 /// <p>Create a rasterizer state object that tells the rasterizer stage how to behave.</p>	
 /// </summary>	
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="rasterizerState">An existing <see cref="Direct3D11.RasterizerState"/> instance.</param>	
 /// <remarks>	
 /// <p>4096 unique rasterizer state objects can be created on a device at a time.</p><p>If an application attempts to create a rasterizer-state interface with the same state as an existing interface, the same interface will be returned and the total number of unique rasterizer state objects will stay the same.</p>	
 /// </remarks>	
 /// <msdn-id>ff476516</msdn-id>	
 /// <unmanaged>HRESULT ID3D11Device::CreateRasterizerState([In] const D3D11_RASTERIZER_DESC* pRasterizerDesc,[Out, Fast] ID3D11RasterizerState** ppRasterizerState)</unmanaged>	
 /// <unmanaged-short>ID3D11Device::CreateRasterizerState</unmanaged-short>	
 public static RasterizerState New(GraphicsDevice device, Direct3D11.RasterizerState rasterizerState)
 {
     return new RasterizerState(device, rasterizerState);
 }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SamplerState" /> class.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="nativeState">State of the native.</param>
 private SamplerState(GraphicsDevice device, Direct3D11.SamplerState nativeState) : base(device.MainDevice)
 {
     Description = nativeState.Description;
     Initialize(nativeState);
 }
Example #13
0
        /// <summary>
        /// Associates an D3D11 render target with the current instance.
        /// </summary>
        /// <param name="renderTarget">An valid D3D11 render target. It must be created with the "Shared" flag.</param>
        internal void SetBackbuffer(Direct3D11.Texture2D renderTarget)
        {
            DisposedGuard();

            DisposeD3D9Backbuffer();

            using (var resource = renderTarget.QueryInterface<DXGI.Resource>())
            {
                var handle = resource.SharedHandle;
                texture = new Texture(device9,
                                      renderTarget.Description.Width,
                                      renderTarget.Description.Height,
                                      1,
                                      Usage.RenderTarget,
                                      Format.A8R8G8B8,
                                      Pool.Default,
                                      ref handle);
            }

            using (var surface = texture.GetSurfaceLevel(0))
                TrySetBackbufferPointer(surface.NativePointer);
        }
Example #14
0
 /// <summary>
 /// Gets the maximum MSAA sample count for a particular <see cref="PixelFormat" />.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="pixelFormat">The pixelFormat.</param>
 /// <returns>The maximum multisample count for this pixel pixelFormat</returns>
 /// <msdn-id>ff476499</msdn-id>
 ///   <unmanaged>HRESULT ID3D11Device::CheckMultisampleQualityLevels([In] DXGI_FORMAT Format,[In] unsigned int SampleCount,[Out] unsigned int* pNumQualityLevels)</unmanaged>
 ///   <unmanaged-short>ID3D11Device::CheckMultisampleQualityLevels</unmanaged-short>
 private static MSAALevel GetMaximumMSAASampleCount(Direct3D11.Device device, PixelFormat pixelFormat)
 {
     int maxCount = 1;
     for (int i = 1; i <= 8; i *= 2)
     {
         if (device.CheckMultisampleQualityLevels(pixelFormat, i) != 0)
             maxCount = i;
     }
     return (MSAALevel)maxCount;
 }
Example #15
0
 /// <summary>
 /// Specialised constructor for use only by derived classes.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="texture">The texture.</param>
 /// <msdn-id>ff476521</msdn-id>	
 /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged>	
 /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short>	
 protected internal Texture2DBase(GraphicsDevice device, Direct3D11.Texture2D texture)
     : base(device, texture.Description)
 {
     Resource = texture;
 }
Example #16
0
 /// <summary>
 /// Specialised constructor for use only by derived classes.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="texture">The texture.</param>
 /// <msdn-id>ff476520</msdn-id>	
 /// <unmanaged>HRESULT ID3D11Device::CreateTexture1D([In] const D3D11_TEXTURE1D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture1D** ppTexture1D)</unmanaged>	
 /// <unmanaged-short>ID3D11Device::CreateTexture1D</unmanaged-short>	
 protected internal Texture1DBase(GraphicsDevice device, Direct3D11.Texture1D texture)
     : base(device, texture.Description)
 {
     Resource = texture;
     Initialize(Resource);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DepthStencilState" /> class.
 /// </summary>
 /// <param name="device">The device local.</param>
 /// <param name="nativeState">State of the native.</param>
 private DepthStencilState(GraphicsDevice device, Direct3D11.DepthStencilState nativeState) : base(device.MainDevice)
 {
     Description = nativeState.Description;
     Initialize(nativeState);
 }
 /// <summary>	
 /// Create a depth-stencil state object that encapsulates depth-stencil test information for the output-merger stage.
 /// </summary>	
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="depthStencilState">An existing <see cref="Direct3D11.DepthStencilState"/> instance.</param>	
 /// <returns>A new instance of <see cref="DepthStencilState"/></returns>	
 /// <remarks>	
 /// <p>4096 unique depth-stencil state objects can be created on a device at a time.</p><p>If an application attempts to create a depth-stencil-state interface with the same state as an existing interface, the same interface will be returned and the total number of unique depth-stencil state objects will stay the same.</p>	
 /// </remarks>	
 /// <msdn-id>ff476506</msdn-id>	
 /// <unmanaged>HRESULT ID3D11Device::CreateDepthStencilState([In] const D3D11_DEPTH_STENCIL_DESC* pDepthStencilDesc,[Out, Fast] ID3D11DepthStencilState** ppDepthStencilState)</unmanaged>	
 /// <unmanaged-short>ID3D11Device::CreateDepthStencilState</unmanaged-short>	
 public static DepthStencilState New(GraphicsDevice device, Direct3D11.DepthStencilState depthStencilState)
 {
     return new DepthStencilState(device, depthStencilState);
 }
Example #19
0
 /// <summary>
 /// Creates a new <see cref="DepthStencilBuffer"/> from a <see cref="Direct3D11.Texture2D"/>.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="texture">The native texture <see cref="Direct3D11.Texture2D"/>.</param>
 /// <returns>
 /// A new instance of <see cref="DepthStencilBuffer"/> class.
 /// </returns>
 /// <msdn-id>ff476521</msdn-id>	
 /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged>	
 /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short>	
 public static DepthStencilBuffer New(GraphicsDevice device, Direct3D11.Texture2D texture)
 {
     return new DepthStencilBuffer(device, texture, ComputeViewFormat(texture.Description.Format));
 }
Example #20
0
 internal RenderTarget3D(GraphicsDevice device, Direct3D11.Texture3D texture)
     : base(device, texture)
 {
 }
Example #21
0
 /// <summary>
 /// Creates a new <see cref="RenderTarget1D"/> from a <see cref="Direct3D11.Texture1D"/>.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="texture">The native texture <see cref="Direct3D11.Texture1D"/>.</param>
 /// <returns>
 /// A new instance of <see cref="RenderTarget1D"/> class.
 /// </returns>
 /// <msdn-id>ff476520</msdn-id>	
 /// <unmanaged>HRESULT ID3D11Device::CreateTexture1D([In] const D3D11_TEXTURE1D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture1D** ppTexture1D)</unmanaged>	
 /// <unmanaged-short>ID3D11Device::CreateTexture1D</unmanaged-short>	
 public static RenderTarget1D New(GraphicsDevice device, Direct3D11.Texture1D texture)
 {
     return new RenderTarget1D(device, texture);
 }