Exemplo n.º 1
0
        void SetupRenderState(ImDrawDataPtr drawData, ID3D11DeviceContext ctx)
        {
            var viewport = new Viewport
            {
                Width    = drawData.DisplaySize.X,
                Height   = drawData.DisplaySize.Y,
                MinDepth = 0.0f,
                MaxDepth = 1.0f,
            };

            ctx.RSSetViewports(viewport);

            int stride = sizeof(ImDrawVert);
            int offset = 0;

            ctx.IASetInputLayout(inputLayout);
            ctx.IASetVertexBuffers(0, 1, new[] { vertexBuffer }, new[] { stride }, new[] { offset });
            ctx.IASetIndexBuffer(indexBuffer, sizeof(ImDrawIdx) == 2 ? Format.R16_UInt : Format.R32_UInt, 0);
            ctx.IASetPrimitiveTopology(PrimitiveTopology.TriangleList);
            ctx.VSSetShader(vertexShader);
            ctx.VSSetConstantBuffers(0, constantBuffer);
            ctx.PSSetShader(pixelShader);
            ctx.PSSetSamplers(0, fontSampler);
            ctx.GSSetShader(null);
            ctx.HSSetShader(null);
            ctx.DSSetShader(null);
            ctx.CSSetShader(null);

            ctx.OMSetBlendState(blendState);
            ctx.OMSetDepthStencilState(depthStencilState);
            ctx.RSSetState(rasterizerState);
        }
Exemplo n.º 2
0
        public virtual void Render(ID3D11DeviceContext context, PrimitiveTopology type, int size, uint offset)
        {
            context.IASetInputLayout(Layout);

            // set shaders only if available
            if (OurVertexShader != null)
            {
                context.VSSetShader(OurVertexShader);
            }

            if (OurVertexShader != null)
            {
                context.PSSetShader(OurPixelShader);
                context.PSSetSampler(0, SamplerState);
            }

            if (OurVertexShader != null)
            {
                context.GSSetShader(OurGeometryShader);
            }

            context.DrawIndexed(size, (int)offset, 0);

            Profiler.NumDrawCallsThisFrame++;
        }
Exemplo n.º 3
0
        protected override void SetPipelineStateImpl(PipelineState pipelineState)
        {
            var pipelineStateD3D11 = (PipelineStateD3D11)pipelineState;

            if (pipelineState.IsCompute)
            {
                var computeShader = pipelineStateD3D11.ComputeShader;
                D3D11Context.CSSetShader(computeShader);
            }
            else
            {
                var blendState = pipelineStateD3D11.BlendState;
                if (_boundBlendState != blendState)
                {
                    _boundBlendState = blendState;
                    D3D11Context.OMSetBlendState(blendState, _boundBlendColor);
                }

                var depthStencilState = pipelineStateD3D11.DepthStencilState;
                if (_boundDepthStencilState != depthStencilState)
                {
                    _boundDepthStencilState = depthStencilState;
                    D3D11Context.OMSetDepthStencilState(depthStencilState, _boundStencilReference);
                }

                var rasterizerState = pipelineStateD3D11.RasterizerState;
                if (_boundRasterizerState != rasterizerState)
                {
                    _boundRasterizerState = rasterizerState;
                    D3D11Context.RSSetState(rasterizerState);
                }

                var primitiveTopology = pipelineStateD3D11.PrimitiveTopology;
                if (_boundPrimitiveTopology != primitiveTopology)
                {
                    _boundPrimitiveTopology = primitiveTopology;
                    D3D11Context.IASetPrimitiveTopology(primitiveTopology);
                }

                var inputLayout = pipelineStateD3D11.InputLayout;
                if (_boundInputLayout != inputLayout)
                {
                    _boundInputLayout = inputLayout;
                    D3D11Context.IASetInputLayout(_boundInputLayout);
                }

                var vertexShader = pipelineStateD3D11.VertexShader;
                if (_boundVertexShader != vertexShader)
                {
                    _boundVertexShader = vertexShader;
                    D3D11Context.VSSetShader(vertexShader);
                }

                var geometryShader = pipelineStateD3D11.GeometryShader;
                if (_boundGeometryShader != geometryShader)
                {
                    _boundGeometryShader = geometryShader;
                    D3D11Context.GSSetShader(geometryShader);
                }

                var hullShader = pipelineStateD3D11.HullShader;
                if (_boundHullShader != hullShader)
                {
                    _boundHullShader = hullShader;
                    D3D11Context.HSSetShader(hullShader);
                }

                var domainShader = pipelineStateD3D11.DomainShader;
                if (_boundDomainShader != domainShader)
                {
                    _boundDomainShader = domainShader;
                    D3D11Context.DSSetShader(domainShader);
                }

                var pixelShader = pipelineStateD3D11.PixelShader;
                if (_boundPixelShader != pixelShader)
                {
                    _boundPixelShader = pixelShader;
                    D3D11Context.PSSetShader(pixelShader);
                }
            }
        }