public override void Render(ID3D11Device device, ID3D11DeviceContext deviceContext, Camera camera)
        {
            if (!DoRender)
            {
                return;
            }

            //if (!camera.CheckBBoxFrustum(Transform.TranslationVector, BoundingBox))
            //     return;

            VertexBufferView VertexBufferView = new VertexBufferView(vertexBuffer, Unsafe.SizeOf <VertexLayouts.NormalLayout.Vertex>(), 0);

            deviceContext.IASetVertexBuffers(0, VertexBufferView);
            deviceContext.IASetIndexBuffer(indexBuffer, Vortice.DXGI.Format.R32_UInt, 0);
            deviceContext.IASetPrimitiveTopology(PrimitiveTopology.TriangleList);
            deviceContext.PSSetShaderResource(2, AOTexture);

            for (int i = 0; i != LODs[0].ModelParts.Length; i++)
            {
                ModelPart Segment = LODs[0].ModelParts[i];
                Segment.Shader.SetShaderParameters(device, deviceContext, new MaterialParameters(Segment.Material, SelectionColour.Normalize()));
                Segment.Shader.SetSceneVariables(deviceContext, Transform, camera);
                Segment.Shader.Render(deviceContext, PrimitiveTopology.TriangleList, (int)(Segment.NumFaces * 3), Segment.StartIndex);
            }
        }
Exemple #2
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);
        }
Exemple #3
0
        public void Draw(ID3D11Device device, ID3D11DeviceContext context, Span <D3D11_INPUT_ELEMENT_DESC> _layout)
        {
            if (!m_vertexBuffer)
            {
                using (var pin = PinPtr.Create(m_vertices))
                {
                    var desc = new D3D11_BUFFER_DESC
                    {
                        ByteWidth = (uint)m_vertices.Length,
                        Usage     = D3D11_USAGE._DEFAULT,
                        BindFlags = (uint)D3D11_BIND_FLAG._VERTEX_BUFFER,
                    };
                    var data = new D3D11_SUBRESOURCE_DATA
                    {
                        pSysMem = pin.Ptr
                    };
                    device.CreateBuffer(ref desc, ref data,
                                        out m_vertexBuffer).ThrowIfFailed();
                }
            }
            Span <IntPtr> pBufferTbl = stackalloc IntPtr[] { m_vertexBuffer.Ptr };
            Span <uint>   SizeTbl    = stackalloc uint[] { (uint)m_vertexSize };
            Span <uint>   OffsetTbl  = stackalloc uint[] { 0 };

            context.IASetVertexBuffers(0, 1,
                                       ref MemoryMarshal.GetReference(pBufferTbl),
                                       ref MemoryMarshal.GetReference(SizeTbl),
                                       ref MemoryMarshal.GetReference(OffsetTbl));

            if (!m_indexBuffer)
            {
                using (var pin = PinPtr.Create(m_indices))
                {
                    var desc = new D3D11_BUFFER_DESC
                    {
                        ByteWidth = (uint)m_indices.Length,
                        Usage     = D3D11_USAGE._DEFAULT,
                        BindFlags = (uint)D3D11_BIND_FLAG._INDEX_BUFFER,
                    };
                    var data = new D3D11_SUBRESOURCE_DATA
                    {
                        pSysMem = pin.Ptr
                    };
                    device.CreateBuffer(ref desc, ref data,
                                        out m_indexBuffer).ThrowIfFailed();
                }
            }
            context.IASetIndexBuffer(m_indexBuffer, m_indexFormat, 0);

            context.IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY._TRIANGLELIST);
            context.DrawIndexed((uint)m_indexCount, 0, 0);
        }
    }
}
Exemple #4
0
        private void RenderLines(ID3D11DeviceContext InDeviceContext, Camera InCamera)
        {
            VertexBufferView BufferView = new VertexBufferView(VertexBuffer, Unsafe.SizeOf <VertexLayouts.BasicLayout.Vertex>(), 0);

            InDeviceContext.IASetVertexBuffers(0, BufferView);
            InDeviceContext.IASetIndexBuffer(IndexBuffer, Vortice.DXGI.Format.R16_UInt, 0);
            InDeviceContext.IASetPrimitiveTopology(PrimitiveTopology.LineStrip);

            BaseShader Shader = RenderStorageSingleton.Instance.ShaderManager.shaders[1];

            Shader.SetSceneVariables(InDeviceContext, Matrix4x4.Identity, InCamera);
            Shader.Render(InDeviceContext, PrimitiveTopology.LineList, SizeToRender, 0);
        }
        public static void IASetIndexBuffer(this ID3D11DeviceContext context, ID3D11Buffer indexBuffer, DXGI_FORMAT format = DXGI_FORMAT.DXGI_FORMAT_R32_UINT, int offset = 0)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (indexBuffer == null)
            {
                throw new ArgumentNullException(nameof(indexBuffer));
            }

            context.IASetIndexBuffer(indexBuffer, format, (uint)offset);
        }
        public override void Render(ID3D11Device device, ID3D11DeviceContext deviceContext, Camera camera)
        {
            if (!DoRender)
            {
                return;
            }

            VertexBufferView VertexBufferView = new VertexBufferView(vertexBuffer, Unsafe.SizeOf <VertexLayouts.BasicLayout.Vertex>(), 0);

            deviceContext.IASetVertexBuffers(0, VertexBufferView);
            deviceContext.IASetIndexBuffer(indexBuffer, Vortice.DXGI.Format.R32_UInt, 0);
            deviceContext.IASetPrimitiveTopology(PrimitiveTopology.LineList);

            shader.SetSceneVariables(deviceContext, Transform, camera);
            shader.Render(deviceContext, PrimitiveTopology.LineList, ReadOnlyIndices.Length, 0);
        }
        public override void Render(ID3D11Device device, ID3D11DeviceContext deviceContext, Camera camera)
        {
            if (!DoRender)
            {
                return;
            }

            VertexBufferView VertexBufferView = new VertexBufferView(vertexBuffer, Unsafe.SizeOf <VertexLayouts.CollisionLayout.Vertex>(), 0);

            deviceContext.IASetVertexBuffers(0, VertexBufferView);
            deviceContext.IASetIndexBuffer(indexBuffer, Vortice.DXGI.Format.R32_UInt, 0);
            deviceContext.IASetPrimitiveTopology(PrimitiveTopology.TriangleList);

            Shader.SetSceneVariables(deviceContext, Transform, camera);
            Shader.SetShaderParameters(device, deviceContext, new BaseShader.MaterialParameters(null, SelectionColour.Normalize()));

            Shader.Render(deviceContext, PrimitiveTopology.TriangleList, Indices.Length, 0);
        }
Exemple #8
0
        public void Draw(ID3D11Device device, ID3D11DeviceContext context, Span <VertexAttribute> layout)
        {
            Span <IntPtr> buffers = stackalloc IntPtr[layout.Length];
            Span <uint>   strides = stackalloc uint[layout.Length];
            Span <uint>   offsets = stackalloc uint[layout.Length];

            for (int i = 0; i < layout.Length; ++i)
            {
                var va = layout[i];
                if (m_vertexBufferMap.TryGetValue(va.Semantic, out VertexBuffer vb))
                {
                    buffers[i] = vb.GetPtr(device);
                    strides[i] = (uint)vb.Stride;
                }
            }
            context.IASetVertexBuffers(0, (uint)layout.Length,
                                       ref MemoryMarshal.GetReference(buffers),
                                       ref MemoryMarshal.GetReference(strides),
                                       ref MemoryMarshal.GetReference(offsets));

            context.IASetIndexBuffer(m_indexBuffer.Buffer, m_indexFormat, 0);
            context.IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY._TRIANGLELIST);
            context.DrawIndexed((uint)m_indexCount, 0, 0);
        }