Exemple #1
0
        protected GraphicsResource(DirectXDevice device, string name)
            : base(name)
        {
            Contract.Requires <ArgumentNullException>(device != null, "device");

            Device = device;
        }
        public override void Render()
        {
            DirectXDevice device = DeviceService.DirectXDevice;

            foreach (Shader shader in Technique)
            {
                shader.Apply(Technique.Name, UpdateType.SceneFrame);
            }

            foreach (IEntity entity in Entities)
            {
                if (!entity.IsEnabled)
                {
                    continue;
                }

                foreach (Shader shader in Technique)
                {
                    shader.Apply(Technique.Name, entity.Id, UpdateType.InstanceStatic);
                    shader.Apply(Technique.Name, entity.Id, UpdateType.InstanceFrame);
                }

                foreach (ModelMesh mesh in Model.Meshes)
                {
                    mesh.Draw(device);
                }
            }
        }
Exemple #3
0
 public Designer(IServiceRegistry services)
 {
     this.services   = services;
     device          = services.GetService <IGraphicsDeviceService>().DirectXDevice;
     shapes          = new List <ShapeMeshDescription>();
     ModelOperations = ModelOperation.None;
 }
Exemple #4
0
 /// <summary>
 /// Creates a new Typed buffer <see cref="ResourceUsage.Default" /> usage.
 /// </summary>
 /// <param name="device">The <see cref="DirectXDevice"/>.</param>
 /// <param name="value">The value to initialize the Typed buffer.</param>
 /// <param name="viewFormat">The view format of the buffer.</param>
 /// <param name="isUnorderedAccess">if set to <c>true</c> this buffer supports unordered access (RW in HLSL).</param>
 /// <param name="usage">The usage of this resource.</param>
 /// <returns>A Typed buffer</returns>
 public static Buffer New(DirectXDevice device, DataPointer value, PixelFormat viewFormat,
                          bool isUnorderedAccess = false, ResourceUsage usage = ResourceUsage.Default)
 {
     return(Buffer.New(device, value, 0,
                       BufferFlags.ShaderResource | (isUnorderedAccess ? BufferFlags.UnorderedAccess : BufferFlags.None),
                       viewFormat, usage));
 }
Exemple #5
0
 /// <summary>
 /// <p>Create a sampler-state object that encapsulates sampling information for a texture.</p>
 /// </summary>
 /// <param name="device">The <see cref="DirectXDevice"/>.</param>
 /// <param name="name">Name of this sampler state.</param>
 /// <param name="description">A sampler state description</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(DirectXDevice device, string name, SamplerStateDescription description)
 {
     return(new SamplerState(device, description)
     {
         Name = name
     });
 }
Exemple #6
0
 /// <summary>
 /// Creates a new Typed buffer <see cref="ResourceUsage.Default" /> usage.
 /// </summary>
 /// <typeparam name="T">Type of the Typed buffer to get the sizeof from</typeparam>
 /// <param name="device">The <see cref="DirectXDevice"/>.</param>
 /// <param name="value">The value to initialize the Typed buffer.</param>
 /// <param name="viewFormat">The view format of the buffer.</param>
 /// <param name="isUnorderedAccess">if set to <c>true</c> this buffer supports unordered access (RW in HLSL).</param>
 /// <param name="usage">The usage of this resource.</param>
 /// <returns>A Typed buffer</returns>
 public static Buffer <T> New <T>(DirectXDevice device, T[] value, PixelFormat viewFormat,
                                  bool isUnorderedAccess = false, ResourceUsage usage = ResourceUsage.Default) where T : struct
 {
     return(Buffer.New(device, value,
                       BufferFlags.ShaderResource | (isUnorderedAccess ? BufferFlags.UnorderedAccess : BufferFlags.None),
                       viewFormat, usage));
 }
Exemple #7
0
 /// <summary>
 /// Creates a new Typed buffer <see cref="ResourceUsage.Default" /> usage.
 /// </summary>
 /// <param name="device">The <see cref="DirectXDevice"/>.</param>
 /// <param name="count">The number of data with the following viewFormat.</param>
 /// <param name="viewFormat">The view format of the buffer.</param>
 /// <param name="isUnorderedAccess">if set to <c>true</c> this buffer supports unordered access (RW in HLSL).</param>
 /// <param name="usage">The usage.</param>
 /// <returns>A Typed buffer</returns>
 public static Buffer New(DirectXDevice device, int count, PixelFormat viewFormat,
                          bool isUnorderedAccess = false, ResourceUsage usage = ResourceUsage.Default)
 {
     return(Buffer.New(device, count * viewFormat.SizeInBytes,
                       BufferFlags.ShaderResource | (isUnorderedAccess ? BufferFlags.UnorderedAccess : BufferFlags.None),
                       viewFormat, usage));
 }
Exemple #8
0
        public override void Render()
        {
            DirectXDevice device = DeviceService.DirectXDevice;

            foreach (Shader shader in Technique)
            {
                shader.Apply(Technique.Name, UpdateType.SceneFrame);
            }

            foreach (Shader shader in Technique)
            {
                shader.Apply(Technique.Name, entity.Id, UpdateType.InstanceStatic);
                shader.Apply(Technique.Name, entity.Id, UpdateType.InstanceFrame);
            }

            quad.Draw(device);

            device.SetPixelShaderSampler(0, null);

            var inputs = Inputs.ToArray();

            for (int i = 0; i < inputs.Length; i++)
            {
                device.SetPixelShaderShaderResourceView(i, null);
            }
        }
 /// <summary>
 /// <p>Create a rasterizer state object that tells the rasterizer stage how to behave.</p>
 /// </summary>
 /// <param name="device">The <see cref="DirectXDevice"/>.</param>
 /// <param name="name">Name of this depth stencil state.</param>
 /// <param name="description">A rasterizer state description</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(DirectXDevice device, string name, RasterizerStateDescription description)
 {
     return(new RasterizerState(device, description)
     {
         Name = name
     });
 }
Exemple #10
0
 /// <summary>
 /// <p>Create a blend-state object that encapsulates blend state for the output-merger stage.</p>
 /// </summary>
 /// <param name="device">The  <see cref="DirectXDevice"/>.</param>
 /// <param name="name">Name of this blend state.</param>
 /// <param name="description"><dd>  <p>Pointer to a blend-state description (see <strong><see cref="SharpDX.Direct3D11.BlendStateDescription" /></strong>).</p> </dd></param>
 /// <param name="mask">The mask.</param>
 /// <returns>A new <see cref="BlendState"/> instance.</returns>
 /// <msdn-id>ff476500</msdn-id>
 ///   <unmanaged>HRESULT ID3D11Device::CreateBlendState([In] const D3D11_BLEND_DESC* pBlendStateDesc,[Out, Fast] ID3D11BlendState** ppBlendState)</unmanaged>
 ///   <unmanaged-short>ID3D11Device::CreateBlendState</unmanaged-short>
 /// <remarks><p>An application can create up to 4096 unique blend-state objects. For each object created, the runtime checks to see if a previous object  has the same state. If such a previous object exists, the runtime will return a reference to previous instance instead of creating a duplicate object.</p></remarks>
 public static BlendState New(DirectXDevice device, string name, BlendStateDescription description, int mask = -1)
 {
     return(new BlendState(device, description, Color.White, mask)
     {
         Name = name
     });
 }
Exemple #11
0
        public void DrawIndexedInstanced(DirectXDevice device, int instanceCount)
        {
            SetBuffers(device);

            // Draw this mesh
            device.DrawIndexedInstanced(PrimitiveType, IndexBuffer.Count, instanceCount);
        }
Exemple #12
0
 public void DrawIndexedInstanced(DirectXDevice device, int instanceCount)
 {
     foreach (ModelMeshPart part in MeshParts)
     {
         part.DrawIndexedInstanced(device, instanceCount);
     }
 }
        private void DirectXDevice_Disposing(object sender, EventArgs e)
        {
            // Clears the Device
            directXDevice = null;

            OnDeviceDisposing(sender, e);
        }
Exemple #14
0
 public void DrawIndexed(DirectXDevice device)
 {
     foreach (ModelMeshPart part in MeshParts)
     {
         part.DrawIndexed(device);
     }
 }
Exemple #15
0
 /// <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="DirectXDevice"/>.</param>
 /// <param name="name">Name of this depth stencil state.</param>
 /// <param name="description">A depth-stencil state description</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(DirectXDevice device, string name, DepthStencilStateDescription description)
 {
     return(new DepthStencilState(device, description)
     {
         Name = name
     });
 }
Exemple #16
0
 internal RenderTarget2D(DirectXDevice device, SharpDX.Direct3D11.Texture2D texture, RenderTargetView renderTargetView = null, bool pureRenderTarget = false)
     : base(device, texture)
 {
     this.pureRenderTarget  = pureRenderTarget;
     customRenderTargetView = renderTargetView;
     Initialize(Resource);
 }
        public Model ToModel(DirectXDevice device)
        {
            Buffer indexBuffer = null;

            if (Indices != null)
            {
                if (Indices.Length < 0xFFFF)
                {
                    ushort[] indicesShort = new ushort[Indices.Length];
                    for (int i = 0; i < Indices.Length; i++)
                    {
                        indicesShort[i] = (ushort)Indices[i];
                    }
                    indexBuffer = Buffer.Index.New(device, indicesShort);
                }
                else
                {
                    if (device.Features.Level <= FeatureLevel.Level_9_3)
                    {
                        throw new InvalidOperationException(
                                  "Cannot generate more than 65535 indices on feature level HW <= 9.3");
                    }

                    indexBuffer = Buffer.Index.New(device, Indices);
                }
                indexBuffer.DebugName = "IB_" + Name;
            }
            Buffer vertexBuffer = Buffer.Vertex.New(device, Vertices);

            vertexBuffer.DebugName = "VB_" + Name;

            return(new Model(Name, PrimitiveType, vertexBuffer, InputLayout, indexBuffer));
        }
Exemple #18
0
        /// <summary>
        /// Draws this <see cref="ModelMeshPart"/>. See remarks for difference with XNA.
        /// </summary>
        /// <param name="device">The graphics device.</param>
        /// <remarks>
        /// Unlike XNA, a <see cref="ModelMeshPart"/> is not bound to a specific Effect. The effect must have been setup prior calling this method.
        /// This method is only responsible to setup the VertexBuffer, IndexBuffer and call the appropriate <see cref="DirectxDevice.DrawIndexed"/> method on the <see cref="GraphicsDevice"/>.
        /// </remarks>
        public void DrawUnindexed(DirectXDevice device)
        {
            SetBuffers(device);

            // Finally Draw this mesh
            device.Draw(PrimitiveType, VertexBuffer.Count);
        }
Exemple #19
0
        public Technique(DirectXDevice device, string techniqueName, TechniqueMapping mapping)
        {
            Contract.Requires <ArgumentNullException>(device != null, "device");
            Contract.Requires <ArgumentNullException>(mapping != null, "mapping");
            Name         = techniqueName;
            this.mapping = mapping;

            ShaderDescription vsDesc;
            ShaderDescription psDesc;

            techniqueMapping = mapping;

            shaders = new Dictionary <ShaderType, Shader>();

            if (mapping.TryGetValue(ShaderType.Vertex, out vsDesc))
            {
                VertexShader vertexShader      = device.TechniquePool.RegisterShader <VertexShader>(vsDesc.Name, vsDesc.ByteCode);
                var          vertexInputLayout = mapping.GenerateVertexInputLayout();
                inputLayout = ToDispose(new InputLayout(device, vsDesc.ByteCode, vertexInputLayout.InputElements));
                shaders.Add(ShaderType.Vertex, vertexShader);
            }
            if (mapping.TryGetValue(ShaderType.Pixel, out psDesc))
            {
                PixelShader pixelShader = device.TechniquePool.RegisterShader <PixelShader>(psDesc.Name, psDesc.ByteCode);
                shaders.Add(ShaderType.Pixel, pixelShader);
            }
        }
Exemple #20
0
 protected Shader(DirectXDevice device, ShaderType type, string name)
     : base(device, name)
 {
     this.type = type;
     textures  = new List <TextureMapping>();
     buffers   = new IndexedCollection <long, ConstantBuffer>();
 }
Exemple #21
0
 /// <summary>
 /// Creates a new <see cref="RenderTarget2D"/> from a <see cref="RenderTargetView"/>.
 /// </summary>
 /// <param name="device">The <see cref="DirectXDevice"/>.</param>
 /// <param name="renderTargetView">The native texture <see cref="RenderTargetView"/>.</param>
 /// <returns>
 /// A new instance of <see cref="RenderTarget2D"/> 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 RenderTarget2D New(DirectXDevice device, RenderTargetView renderTargetView, bool pureRenderTarget = false)
 {
     using (var resource = renderTargetView.Resource)
     {
         return(new RenderTarget2D(device, resource.QueryInterface <SharpDX.Direct3D11.Texture2D>(), renderTargetView, pureRenderTarget));
     }
 }
Exemple #22
0
 public StateViewer(IServiceRegistry services, IEnumerable <Command> list)
 {
     Contract.Requires <ArgumentNullException>(list != null, "List cannot be null.");
     this.services  = services;
     device         = services.GetService <IGraphicsDeviceService>().DirectXDevice;
     resultCommands = new LinkedList <Command>();
     sourceCommands = new LinkedList <Command>(list);
 }
        public static Model New <TVertex>(DirectXDevice device, string name, TVertex[] vertices, int[] indices,
                                          PrimitiveTopology primitiveTopology = PrimitiveTopology.TriangleList, ModelOperation modelOperations = ModelOperation.None)
            where TVertex : struct
        {
            bool toLeftHanded = modelOperations.HasFlag(ModelOperation.ReverseIndices);

            return(new GeometricPrimitive <TVertex>(name, vertices, indices, primitiveTopology, toLeftHanded).ToModel(device));
        }
Exemple #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BlendState" /> class.
 /// </summary>
 /// <param name="device">The device local.</param>
 /// <param name="description">The description.</param>
 /// <param name="blendFactor">The blend factor.</param>
 /// <param name="mask">The mask.</param>
 private BlendState(DirectXDevice device, BlendStateDescription description, Color4 blendFactor, int mask)
     : base(device)
 {
     this.description = description;
     BlendFactor      = blendFactor;
     MultiSampleMask  = mask;
     Resource         = new SharpDX.Direct3D11.BlendState(device, description);
 }
Exemple #25
0
 /// <summary>
 /// <p>Create a blend-state object that encapsulates blend state for the output-merger stage.</p>
 /// </summary>
 /// <param name="device">The  <see cref="DirectXDevice"/>.</param>
 /// <param name="sourceBlend">The source blend.</param>
 /// <param name="destinationBlend">The destination blend.</param>
 /// <param name="blendOperation">The blend operation.</param>
 /// <param name="sourceAlphaBlend">The source alpha blend.</param>
 /// <param name="destinationAlphaBlend">The destination alpha blend.</param>
 /// <param name="alphaBlendOperation">The alpha blend operation.</param>
 /// <param name="renderTargetWriteMask">The render target write mask.</param>
 /// <param name="mask">The mask.</param>
 /// <returns>A new <see cref="BlendState" /> instance.</returns>
 /// <msdn-id>ff476500</msdn-id>
 ///   <unmanaged>HRESULT ID3D11Device::CreateBlendState([In] const D3D11_BLEND_DESC* pBlendStateDesc,[Out, Fast] ID3D11BlendState** ppBlendState)</unmanaged>
 ///   <unmanaged-short>ID3D11Device::CreateBlendState</unmanaged-short>
 /// <remarks><p>An application can create up to 4096 unique blend-state objects. For each object created, the runtime checks to see if a previous object  has the same state. If such a previous object exists, the runtime will return a reference to previous instance instead of creating a duplicate object.</p></remarks>
 public static BlendState New(DirectXDevice device, BlendOption sourceBlend, BlendOption destinationBlend,
                              BlendOperation blendOperation, BlendOption sourceAlphaBlend, BlendOption destinationAlphaBlend,
                              BlendOperation alphaBlendOperation, ColorWriteMaskFlags renderTargetWriteMask = ColorWriteMaskFlags.All,
                              int mask = -1)
 {
     return(New(device, sourceBlend, destinationBlend, blendOperation, sourceAlphaBlend, destinationAlphaBlend,
                alphaBlendOperation, renderTargetWriteMask, Color.White, mask));
 }
 public override void Initialize(DirectXDevice device, Entity source, InitializerParameters parameters)
 {
     base.Initialize(device, source, parameters);
     if (!parameters.Technique.UsesProceduralTextures)
     {
         InitializeTextures(source, parameters);
     }
 }
Exemple #27
0
 public ConstantBuffer(DirectXDevice device, ConstantBufferDescription description, string technique)
 {
     Name             = description.Name;
     this.description = description;
     this.device      = device;
     this.technique   = technique;
     parameters       = new List <IParameter>();
 }
Exemple #28
0
 internal DepthStencilBuffer(DirectXDevice device, Texture2DDescription description2D, DepthFormat depthFormat)
     : base(device, description2D)
 {
     DepthFormat       = depthFormat;
     DefaultViewFormat = ComputeViewFormat(DepthFormat, out HasStencil);
     Initialize(Resource);
     HasReadOnlyView  = InitializeViewsDelayed();
     DepthStencilView = new DepthStencilViewSelector(this);
 }
Exemple #29
0
        /// <summary>
        /// <p>Create a blend-state object that encapsulates blend state for the output-merger stage.</p>
        /// </summary>
        /// <param name="device">The <see cref="DirectXDevice"/>.</param>
        /// <param name="renderTargetBlend0">The render target blend description for the first render target.</param>
        /// <param name="blendFactor">The blend factor.</param>
        /// <param name="mask">The mask.</param>
        /// <returns>A new <see cref="BlendState" /> instance.</returns>
        /// <msdn-id>ff476500</msdn-id>
        ///   <unmanaged>HRESULT ID3D11Device::CreateBlendState([In] const D3D11_BLEND_DESC* pBlendStateDesc,[Out, Fast] ID3D11BlendState** ppBlendState)</unmanaged>
        ///   <unmanaged-short>ID3D11Device::CreateBlendState</unmanaged-short>
        /// <remarks><p>An application can create up to 4096 unique blend-state objects. For each object created, the runtime checks to see if a previous object  has the same state. If such a previous object exists, the runtime will return a reference to previous instance instead of creating a duplicate object.</p></remarks>
        public static BlendState New(DirectXDevice device, RenderTargetBlendDescription renderTargetBlend0,
                                     Color4 blendFactor, int mask = -1)
        {
            var description = BlendStateDescription.Default();

            description.RenderTarget[0] = renderTargetBlend0;

            return(new BlendState(device, description, blendFactor, mask));
        }
Exemple #30
0
 internal DepthStencilBuffer(DirectXDevice device, SharpDX.Direct3D11.Texture2D texture, DepthFormat depthFormat)
     : base(device, texture)
 {
     DepthFormat       = depthFormat;
     DefaultViewFormat = ComputeViewFormat(DepthFormat, out HasStencil);
     Initialize(Resource);
     HasReadOnlyView  = InitializeViewsDelayed();
     DepthStencilView = new DepthStencilViewSelector(this);
 }