Example #1
0
 /// <summary>
 /// Draw call
 /// </summary>
 /// <param name="context"></param>
 /// <param name="instanceModel"></param>
 protected virtual void OnDraw(DeviceContext context, IElementsBufferModel instanceModel)
 {
     if (GeometryBuffer.IndexBuffer != null)
     {
         if (instanceModel == null || !instanceModel.HasElements)
         {
             context.DrawIndexed(GeometryBuffer.IndexBuffer.ElementCount, GeometryBuffer.IndexBuffer.Offset, 0);
         }
         else
         {
             context.DrawIndexedInstanced(GeometryBuffer.IndexBuffer.ElementCount, instanceModel.Buffer.ElementCount, GeometryBuffer.IndexBuffer.Offset, 0, instanceModel.Buffer.Offset);
         }
     }
     else if (GeometryBuffer.VertexBuffer.Length > 0)
     {
         if (instanceModel == null || !instanceModel.HasElements)
         {
             context.Draw(GeometryBuffer.VertexBuffer[0].ElementCount, 0);
         }
         else
         {
             context.DrawInstanced(GeometryBuffer.VertexBuffer[0].ElementCount, instanceModel.Buffer.ElementCount,
                                   0, instanceModel.Buffer.Offset);
         }
     }
 }
Example #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="primitive"></param>
 /// <param name="vertexCountPerInstance"></param>
 /// <param name="instanceCount"></param>
 /// <param name="startVertexLocation"></param>
 /// <param name="startInstanceLocation"></param>
 public void DrawInstanced(int vertexCountPerInstance, int instanceCount, int startVertexLocation, int startInstanceLocation)
 {
     lock (deviceContext) {
         ApplyGpuState();
         //deviceContext.InputAssembler.PrimitiveTopology	=	Converter.Convert( primitive );
         deviceContext.DrawInstanced(vertexCountPerInstance, instanceCount, startVertexLocation, startInstanceLocation);
     }
 }
Example #3
0
        private void RenderShader(DeviceContext deviceContext, int vertexCount, int instanceCount)
        {
            deviceContext.InputAssembler.InputLayout = Layout;

            deviceContext.VertexShader.Set(VertexShader);
            deviceContext.PixelShader.Set(PixelShader);

            deviceContext.PixelShader.SetSampler(0, SampleState);

            deviceContext.DrawInstanced(vertexCount, instanceCount, 0, 0);
        }
Example #4
0
        protected override void DrawCore(uint vertexCount, uint instanceCount, uint vertexStart, uint instanceStart)
        {
            PreDrawCommand();

            if (instanceCount == 1)
            {
                _context.Draw((int)vertexCount, (int)vertexStart);
            }
            else
            {
                _context.DrawInstanced((int)vertexCount, (int)instanceCount, (int)vertexStart, (int)instanceStart);
            }
        }
Example #5
0
        protected override void OnDraw(DeviceContext context, IElementsBufferModel instanceModel)
        {
            var billboardGeometry = GeometryBuffer.Geometry as IBillboardText;
            var vertexCount       = billboardGeometry.BillboardVertices.Count;

            if (instanceModel == null || !instanceModel.HasElements)
            {
                context.Draw(vertexCount, 0);
            }
            else
            {
                context.DrawInstanced(vertexCount, instanceModel.Buffer.ElementCount, 0, 0);
            }
        }
        private void RenderShader(DeviceContext deviceContext, int vertexCount, int instanceCount)
        {
            // Set the vertex input layout.
            deviceContext.InputAssembler.InputLayout = Layout;

            // Set the vertex and pixel shaders that will be used to render this triangle.
            deviceContext.VertexShader.Set(VertexShader);
            deviceContext.PixelShader.Set(PixelShader);

            // Set the sampler state in the pixel shader.
            deviceContext.PixelShader.SetSampler(0, SamplerState);

            // Render the triangle.
            deviceContext.DrawInstanced(vertexCount, instanceCount, 0, 0);
        }
Example #7
0
        public void OnRender(DeviceContext context, EffectPass pass)
        {
            context.InputAssembler.InputLayout = vertexLayout;
            context.InputAssembler.PrimitiveTopology
                = PrimitiveTopology.TriangleList;

            VertexBufferBinding[] binds = new VertexBufferBinding[]
            {
                new VertexBufferBinding(vertexBuffer, Marshal.SizeOf(typeof(VertexDefinition)), 0),
                new VertexBufferBinding(inputBuffer, Marshal.SizeOf(typeof(Matrix)), 0),
            };

            context.InputAssembler.SetVertexBuffers(0, binds);

            pass.Apply(context);
            context.DrawInstanced(faces.Length, statusArray.Count, 0, 0);
        }
Example #8
0
        public void OnRender(DeviceContext context)
        {
            context.InputAssembler.InputLayout = vertexLayout;
            context.InputAssembler.PrimitiveTopology
                = PrimitiveTopology.TriangleList;

            context.InputAssembler.SetVertexBuffers(
                0,
                new VertexBufferBinding(
                    vertexBuffer,
                    VertexDefinition.SizeInBytes,
                    0
                    )
                );



            try
            {
                ComputeShader cs = engine.Load(csPath);
                context.ComputeShader.Set(cs);

                context.ComputeShader.SetUnorderedAccessView(statusUAV, 2);

                context.Dispatch(100, 1, 1);

                //context.CopyResource(bufferUA, bufferSR);

                context.ComputeShader.SetUnorderedAccessView(null, 2);// Slot2 をリセット


                effectPass.Apply(context);
                context.PixelShader.SetSampler(sampler, 0);
                context.PixelShader.SetShaderResource(textureView, 0);
                context.VertexShader.SetShaderResource(statusSRV, 1);
            }
            catch (Exception e)
            {
                return;
            }


            context.DrawInstanced(faces.Length, statusArray.Count, 0, 0);

            //context.VertexShader.SetShaderResource(null, 1);
        }
Example #9
0
        private void Render(DeviceContext context, VertexColumnChart[] dataPerInstance)
        {
            if (dataPerInstance.Length == 0)
            {
                return;
            }

            RenderStatesRepo.ApplyStates(_engine.ImmediateContext, _rasterStateId, _blendStateId, _depthStateId);

            _effect.Begin(context);
            _effect.CBPerDraw.Values.ViewportSize = new Vector2(_engine.ViewPort.Width, _engine.ViewPort.Height);
            _effect.CBPerDraw.IsDirty             = true;
            _effect.Apply(context);

            _vBufferInstanced.SetInstancedData(context, dataPerInstance);
            _vBufferInstanced.SetToDevice(context, 0);

            context.DrawInstanced(2, dataPerInstance.Length, 0, 0);
        }
 public override void Draw(DeviceContext ctx)
 {
     ctx.DrawInstanced(this.geom.VerticesCount, this.InstanceCount, 0, this.StartInstanceLocation);
 }
Example #11
0
 public override void Draw(DeviceContext ctx)
 {
     ctx.DrawInstanced(this.geom.VerticesCount, this.InstanceCount, 0, this.StartInstanceLocation);
 }
Example #12
0
        public void Replay()
        {
            foreach (var @event in _frame.Events)
            {
                var args = @event.Arguments;
                switch (@event.OperationType)
                {
                // Device operations.
                case OperationType.DeviceCreateBlendState:
                    _device.CreateBlendState(args.Get <BlendStateDescription>(0));
                    break;

                case OperationType.DeviceCreateBuffer:
                    _device.CreateBuffer(args.Get <BufferDescription>(0), args.Get <byte[]>(1));
                    break;

                case OperationType.DeviceCreateDepthStencilState:
                    _device.CreateDepthStencilState(args.Get <DepthStencilStateDescription>(0));
                    break;

                case OperationType.DeviceCreateDepthStencilView:
                    _device.CreateDepthStencilView(_device.GetDeviceChild <Resource>(args.Get <int>(0)),
                                                   args.Get <DepthStencilViewDescription?>(1));
                    break;

                case OperationType.DeviceCreateGeometryShader:
                    _device.CreateGeometryShader(args.Get <byte[]>(0));
                    break;

                case OperationType.DeviceCreateInputLayout:
                    _device.CreateInputLayout(args.Get <InputElement[]>(0), args.Get <byte[]>(1));
                    break;

                case OperationType.DeviceCreatePixelShader:
                    _device.CreatePixelShader(args.Get <byte[]>(0));
                    break;

                case OperationType.DeviceCreateRasterizerState:
                    _device.CreateRasterizerState(args.Get <RasterizerStateDescription>(0));
                    break;

                case OperationType.DeviceCreateRenderTargetView:
                    _device.CreateRenderTargetView(args.Get <Texture2D>(_device, 0),
                                                   args.Get <RenderTargetViewDescription?>(1));
                    break;

                case OperationType.DeviceCreateSamplerState:
                    _device.CreateSamplerState(args.Get <SamplerStateDescription>(0));
                    break;

                case OperationType.DeviceCreateShaderResourceView:
                    _device.CreateShaderResourceView(args.Get <Resource>(_device, 0),
                                                     args.Get <ShaderResourceViewDescription?>(1));
                    break;

                case OperationType.DeviceCreateSwapChain:
                    _device.CreateSwapChain(
                        args.Get <SwapChainDescription>(0),
                        _swapChainPresenter);
                    break;

                case OperationType.DeviceCreateTexture1D:
                    _device.CreateTexture1D(args.Get <Texture1DDescription>(0));
                    break;

                case OperationType.DeviceCreateTexture2D:
                    _device.CreateTexture2D(args.Get <Texture2DDescription>(0));
                    break;

                case OperationType.DeviceCreateTexture3D:
                    _device.CreateTexture3D(args.Get <Texture3DDescription>(0));
                    break;

                case OperationType.DeviceCreateVertexShader:
                    _device.CreateVertexShader(args.Get <byte[]>(0));
                    break;

                // Device context operations.
                case OperationType.DeviceContextClearDepthStencilView:
                    _deviceContext.ClearDepthStencilView(
                        args.Get <DepthStencilView>(_device, 0),
                        args.Get <DepthStencilClearFlags>(1),
                        args.Get <float>(2),
                        args.Get <byte>(3));
                    break;

                case OperationType.DeviceContextClearRenderTargetView:
                    _deviceContext.ClearRenderTargetView(
                        _device.GetDeviceChild <RenderTargetView>(args.Get <int>(0)),
                        args.Get <Color4>(1));
                    break;

                case OperationType.DeviceContextDraw:
                    _deviceContext.Draw(args.Get <int>(0), args.Get <int>(1));
                    break;

                case OperationType.DeviceContextDrawIndexed:
                    _deviceContext.DrawIndexed(
                        args.Get <int>(0), args.Get <int>(1),
                        args.Get <int>(2));
                    break;

                case OperationType.DeviceContextDrawInstanced:
                    _deviceContext.DrawInstanced(
                        args.Get <int>(0), args.Get <int>(1),
                        args.Get <int>(2), args.Get <int>(3));
                    break;

                case OperationType.DeviceContextGenerateMips:
                    _deviceContext.GenerateMips(args.Get <TextureBase>(_device, 0));
                    break;

                case OperationType.DeviceContextPresent:
                    _deviceContext.Present(args.Get <SwapChain>(_device, 0));
                    break;

                case OperationType.DeviceContextSetBufferData:
                    _deviceContext.SetBufferData(args.Get <Buffer>(_device, 0),
                                                 args.Get <byte[]>(1), args.Get <int>(2));
                    break;

                case OperationType.DeviceContextSetTextureData:
                    _deviceContext.SetTextureData(args.Get <TextureBase>(_device, 0),
                                                  args.Get <int>(1), args.Get <Color4[]>(2));
                    break;

                // Input assembler stage operations.
                case OperationType.InputAssemblerStageSetInputLayout:
                    _deviceContext.InputAssembler.InputLayout = args.Get <InputLayout>(_device, 0);
                    break;

                case OperationType.InputAssemblerStageSetPrimitiveTopology:
                    _deviceContext.InputAssembler.PrimitiveTopology = args.Get <PrimitiveTopology>(0);
                    break;

                case OperationType.InputAssemblerStageSetVertexBuffers:
                    _deviceContext.InputAssembler.SetVertexBuffers(args.Get <int>(0),
                                                                   args.Get <SerializedVertexBufferBinding[]>(1)
                                                                   .Select(x => new VertexBufferBinding
                    {
                        Buffer = _device.GetDeviceChild <Buffer>(x.Buffer),
                        Offset = x.Offset,
                        Stride = x.Stride
                    }).ToArray());
                    break;

                case OperationType.InputAssemblerStageSetIndexBuffer:
                    _deviceContext.InputAssembler.SetIndexBuffer(args.Get <Buffer>(_device, 0),
                                                                 args.Get <Format>(1), args.Get <int>(2));
                    break;

                // Vertex shader stage operations.
                case OperationType.VertexShaderStageSetShader:
                    _deviceContext.VertexShader.Shader = args.Get <VertexShader>(_device, 0);
                    break;

                case OperationType.VertexShaderStageSetConstantBuffers:
                    _deviceContext.VertexShader.SetConstantBuffers(args.Get <int>(0),
                                                                   args.GetArray <Buffer>(_device, 1));
                    break;

                case OperationType.VertexShaderStageSetSamplers:
                    _deviceContext.VertexShader.SetSamplers(args.Get <int>(0),
                                                            args.GetArray <SamplerState>(_device, 1));
                    break;

                case OperationType.VertexShaderStageSetShaderResources:
                    _deviceContext.VertexShader.SetShaderResources(args.Get <int>(0),
                                                                   args.GetArray <ShaderResourceView>(_device, 1));
                    break;

                // Geometry shader stage operations.
                case OperationType.GeometryShaderStageSetShader:
                    _deviceContext.GeometryShader.Shader = args.Get <GeometryShader>(_device, 0);
                    break;

                case OperationType.GeometryShaderStageSetConstantBuffers:
                    _deviceContext.GeometryShader.SetConstantBuffers(args.Get <int>(0),
                                                                     args.GetArray <Buffer>(_device, 1));
                    break;

                case OperationType.GeometryShaderStageSetSamplers:
                    _deviceContext.GeometryShader.SetSamplers(args.Get <int>(0),
                                                              args.GetArray <SamplerState>(_device, 1));
                    break;

                case OperationType.GeometryShaderStageSetShaderResources:
                    _deviceContext.GeometryShader.SetShaderResources(args.Get <int>(0),
                                                                     args.GetArray <ShaderResourceView>(_device, 1));
                    break;

                // Rasterizer stage operations.
                case OperationType.RasterizerStageSetState:
                    _deviceContext.Rasterizer.State = args.Get <RasterizerState>(_device, 0);
                    break;

                case OperationType.RasterizerStageSetViewports:
                    _deviceContext.Rasterizer.SetViewports(args.Get <Viewport[]>(0));
                    break;

                // Pixel shader stage operations.
                case OperationType.PixelShaderStageSetShader:
                    _deviceContext.PixelShader.Shader = args.Get <PixelShader>(_device, 0);
                    break;

                case OperationType.PixelShaderStageSetConstantBuffers:
                    _deviceContext.PixelShader.SetConstantBuffers(args.Get <int>(0),
                                                                  args.GetArray <Buffer>(_device, 1));
                    break;

                case OperationType.PixelShaderStageSetSamplers:
                    _deviceContext.PixelShader.SetSamplers(args.Get <int>(0),
                                                           args.GetArray <SamplerState>(_device, 1));
                    break;

                case OperationType.PixelShaderStageSetShaderResources:
                    _deviceContext.PixelShader.SetShaderResources(args.Get <int>(0),
                                                                  args.GetArray <ShaderResourceView>(_device, 1));
                    break;

                // Output merger stage operations.
                case OperationType.OutputMergerStageSetDepthStencilState:
                    _deviceContext.OutputMerger.DepthStencilState = args.Get <DepthStencilState>(_device, 0);
                    break;

                case OperationType.OutputMergerStageSetDepthStencilReference:
                    _deviceContext.OutputMerger.DepthStencilReference = args.Get <int>(0);
                    break;

                case OperationType.OutputMergerStageSetBlendState:
                    _deviceContext.OutputMerger.BlendState = args.Get <BlendState>(_device, 0);
                    break;

                case OperationType.OutputMergerStageSetBlendFactor:
                    _deviceContext.OutputMerger.BlendFactor = args.Get <Color4>(0);
                    break;

                case OperationType.OutputMergerStageSetBlendSampleMask:
                    _deviceContext.OutputMerger.BlendSampleMask = args.Get <int>(0);
                    break;

                case OperationType.OutputMergerStageSetTargets:
                    _deviceContext.OutputMerger.SetTargets(
                        args.Get <DepthStencilView>(_device, 0),
                        args.GetArray <RenderTargetView>(_device, 1));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (@event == _lastEvent)
                {
                    break;
                }
            }
        }