Пример #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);
         }
     }
 }
Пример #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="indexCount"></param>
 /// <param name="firstIndex"></param>
 /// <param name="baseVertexOffset"></param>
 public void DrawInstancedIndexed(int indexCountPerInstance, int instanceCount, int startIndexLocation, int baseVertexLocation, int startInstanceLocation)
 {
     lock (deviceContext) {
         ApplyGpuState();
         deviceContext.DrawIndexedInstanced(indexCountPerInstance, instanceCount, startIndexLocation, baseVertexLocation, startInstanceLocation);
     }
 }
Пример #3
0
 public void DrawInstanced(DeviceContext context, int instcount)
 {
     context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
     context.InputAssembler.SetVertexBuffers(0, vbbinding);
     context.InputAssembler.SetIndexBuffer(IndexBuffer, Format.R32_UInt, 0);
     context.DrawIndexedInstanced(IndexCount, instcount, 0, 0, 0);
 }
Пример #4
0
        public void DrawInstanced(DeviceContext dc, int subsetId, Buffer instanceBuffer, int numInstances, int instanceStride)
        {
            const int offset = 0;

            dc.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_vb, _vertexStride, offset), new VertexBufferBinding(instanceBuffer, instanceStride, 0));
            dc.InputAssembler.SetIndexBuffer(_ib, Format.R32_UInt, 0);
            dc.DrawIndexedInstanced(_subsetTable[subsetId].FaceCount * 3, numInstances, _subsetTable[subsetId].FaceStart * 3, 0, 0);
        }
 private void RenderShader(DeviceContext deviceContext, int vertexCount, int instanceCount)
 {
     deviceContext.InputAssembler.InputLayout = Layout;
     deviceContext.VertexShader.Set(VertexShader);
     deviceContext.GeometryShader.Set(null);
     deviceContext.PixelShader.Set(PixelShader);
     deviceContext.PixelShader.SetSampler(0, SamplerState);
     deviceContext.DrawIndexedInstanced(vertexCount, instanceCount, 0, 0, 0);
 }
Пример #6
0
        protected override void DrawIndexedCore(uint indexCount, uint instanceCount, uint indexStart, int vertexOffset, uint instanceStart)
        {
            PreDrawCommand();

            Debug.Assert(_ib != null);
            if (instanceCount == 1)
            {
                _context.DrawIndexed((int)indexCount, (int)indexStart, vertexOffset);
            }
            else
            {
                _context.DrawIndexedInstanced((int)indexCount, (int)instanceCount, (int)indexStart, vertexOffset, (int)instanceStart);
            }
        }
Пример #7
0
        public override void Draw(uint indexCount, uint instanceCount, uint indexStart, int vertexOffset, uint instanceStart)
        {
            FlushViewports();
            FlushScissorRects();
            FlushVertexBindings();

            if (instanceCount == 1)
            {
                _context.DrawIndexed((int)indexCount, (int)indexStart, vertexOffset);
            }
            else
            {
                _context.DrawIndexedInstanced((int)indexCount, (int)instanceCount, (int)indexStart, vertexOffset, (int)instanceStart);
            }
        }
Пример #8
0
        internal override void Draw(ref DeviceContext context, ref Camera camera)
        {
            if (!Visible || Adornee == null)
            {
                return;
            }

            if (_rbo == null)
            {
                _rbo           = Game.Workspace.RenderObjectProvider[Shape.Cube];
                _indexCount    = _rbo.Geometry.IndexCount;
                _indexBuffer   = _rbo.Geometry.IndexBuffer;
                _bufferBinding = _rbo.Bindings[0];
            }

            TransformLines();

            lock (Renderer.Locker)
            {
                Renderer.AALinePass.Use(ref context);

                context.VertexShader.SetConstantBuffer(2, _lineConstantBuffer);

                if (_bufferDirty)
                {
                    DataStream stream;
                    context.MapSubresource(_instanceBuffer, MapMode.WriteDiscard, MapFlags.None, out stream);
                    for (int i = 0; i < 12; i++)
                    {
                        var line = _handles[i];
                        stream.Write(new InstanceRenderData
                        {
                            Size         = line.Size,
                            Colour       = Colour,
                            ModelMatrix  = line.Matrix,
                            Transparency = Transparency,
                            ShadingModel = ShadingModel.Unlit
                        });
                    }
                    context.UnmapSubresource(_instanceBuffer, 0);
                    _bufferDirty = false;
                }

                context.InputAssembler.SetVertexBuffers(0, _bufferBinding, _instanceBufferBinding);
                context.InputAssembler.SetIndexBuffer(_indexBuffer, Format.R32_UInt, 0);
                context.DrawIndexedInstanced(_indexCount, 12, 0, 0, 0);
            }
        }
Пример #9
0
        public override void DrawIndexed(uint indexCount, uint instanceCount, uint indexStart, int vertexOffset, uint instanceStart)
        {
            PreDrawCommand();

            ShaderResourceView[] srvs = _context.PixelShader.GetShaderResources(0, 10);

            Debug.Assert(_ib != null);
            if (instanceCount == 1)
            {
                _context.DrawIndexed((int)indexCount, (int)indexStart, vertexOffset);
            }
            else
            {
                _context.DrawIndexedInstanced((int)indexCount, (int)instanceCount, (int)indexStart, vertexOffset, (int)instanceStart);
            }
        }
Пример #10
0
        public void Draw(DeviceContext deviceContext, PrimitivePerInstanceData[] instanceData, int count)
        {
            deviceContext.MapSubresource(m_instanceBuffer, MapMode.WriteDiscard, MapFlags.None, out DataStream dataStream);
            dataStream.WriteRange(instanceData, 0, count);
            deviceContext.UnmapSubresource(m_instanceBuffer, 0);

            VertexBufferBinding[] vertexBufferBindings = new VertexBufferBinding[]
            {
                new VertexBufferBinding(m_vertexBuffer, Utilities.SizeOf <DebugVertexType>(), 0),
                new VertexBufferBinding(m_instanceBuffer, Utilities.SizeOf <PrimitivePerInstanceData>(), 0)
            };

            deviceContext.InputAssembler.SetVertexBuffers(0, vertexBufferBindings);
            deviceContext.InputAssembler.SetIndexBuffer(m_indexBuffer, Format.R16_UInt, 0);

            deviceContext.DrawIndexedInstanced(m_indexCount, count, 0, 0, 0);
        }
Пример #11
0
        public void DrawInstanced(DeviceContext context, int count)
        {
            context.InputAssembler.InputLayout = InputLayout;

            if (islines)
            {
                context.InputAssembler.PrimitiveTopology = PrimitiveTopology.LineList;
            }
            else
            {
                context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            }
            context.InputAssembler.SetVertexBuffers(0, vbbinding);
            context.InputAssembler.SetIndexBuffer(IndexBuffer, SharpDX.DXGI.Format.R32_UInt, 0);

            context.DrawIndexedInstanced(indexcount, count, 0, 0, 0);
        }
        private void RenderShader(DeviceContext deviceContext, SC_grid.DLightBuffer[] _DLightBuffer_, SC_grid _cuber)
        {
            deviceContext.MapSubresource(_cuber.InstanceBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);
            mappedResource.WriteRange(_cuber.instances, 0, _cuber.instances.Length);
            deviceContext.UnmapSubresource(_cuber.InstanceBuffer, 0);
            mappedResource.Dispose();

            deviceContext.MapSubresource(_cuber.InstanceRotationBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);
            mappedResource.WriteRange(_cuber.instancesDataForward, 0, _cuber.instancesDataForward.Length);
            deviceContext.UnmapSubresource(_cuber.InstanceRotationBuffer, 0);
            mappedResource.Dispose();

            deviceContext.MapSubresource(_cuber.InstanceRotationBufferRIGHT, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);
            mappedResource.WriteRange(_cuber.instancesDataRIGHT, 0, _cuber.instancesDataRIGHT.Length);
            deviceContext.UnmapSubresource(_cuber.InstanceRotationBufferRIGHT, 0);
            mappedResource.Dispose();

            deviceContext.MapSubresource(_cuber.InstanceRotationBufferUP, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);
            mappedResource.WriteRange(_cuber.instancesDataUP, 0, _cuber.instancesDataUP.Length);
            deviceContext.UnmapSubresource(_cuber.InstanceRotationBufferUP, 0);
            mappedResource.Dispose();

            if (_switchOnce == 0)
            {
                try
                {
                    deviceContext.MapSubresource(_constantLightBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);
                    mappedResource.WriteRange(_DLightBuffer_, 0, _DLightBuffer_.Length);
                    deviceContext.UnmapSubresource(_constantLightBuffer, 0);
                    mappedResource.Dispose();
                }
                catch (Exception ex)
                {
                    MainWindow.MessageBox((IntPtr)0, ex.ToString() + "", "Oculus Error", 0);
                }
                //_switchOnce = 1;
            }

            deviceContext.InputAssembler.InputLayout = Layout;
            deviceContext.VertexShader.Set(VertexShader);
            deviceContext.PixelShader.Set(PixelShader);
            deviceContext.PixelShader.SetConstantBuffer(0, _constantLightBuffer);
            deviceContext.GeometryShader.Set(null);
            deviceContext.PixelShader.SetSampler(0, SamplerState);
            deviceContext.DrawIndexedInstanced(_cuber.IndexCount, _cuber.InstanceCount, 0, 0, 0);
        }
Пример #13
0
        private void PlatformDrawIndexedInstanced(
            PrimitiveType primitiveType,
            uint indexCount,
            uint instanceCount,
            Buffer <ushort> indexBuffer,
            uint indexBufferOffset)
        {
            _context.InputAssembler.PrimitiveTopology = primitiveType.ToPrimitiveTopology();

            _context.InputAssembler.SetIndexBuffer(
                indexBuffer.DeviceBuffer,
                SharpDX.DXGI.Format.R16_UInt,
                0);

            _context.DrawIndexedInstanced(
                (int)indexCount,
                (int)instanceCount,
                (int)indexBufferOffset,
                0,
                0);
        }
Пример #14
0
        /// <summary>
        /// Draws instances to the current render target.
        /// </summary>
        public void Draw(ref DeviceContext context, ref Camera camera, bool pix = true)
        {
            if (!IsBuilt)
            {
                Build();
            }

            if (_bufferDirty)
            {
                Update(ref context);
            }

            if (InstanceCount == 0)
            {
                return;
            }

            if (pix)
            {
                PixHelper.BeginEvent(Color.Red, Name);
            }

            var newTopology = Geometry.PrimitiveTopology;

            if (newTopology != context.InputAssembler.PrimitiveTopology)
            {
                context.InputAssembler.PrimitiveTopology = Geometry.PrimitiveTopology;
            }

            context.InputAssembler.SetVertexBuffers(0, Bindings);
            context.InputAssembler.SetIndexBuffer(Geometry.IndexBuffer, Format.R32_UInt, 0);

            context.DrawIndexedInstanced(Geometry.IndexCount, InstanceCount, 0, 0, 0);

            if (pix)
            {
                PixHelper.EndEvent();
            }
        }
Пример #15
0
        public void Draw()
        {
            if (instanceData.Count == 0)
            {
                return;
            }

            DeviceContext context = (DeviceContext)device;

            context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            context.InputAssembler.InputLayout       = layout;

            effect.GetVariableByName("view").AsMatrix().SetMatrix(View);
            effect.GetVariableByName("viewProj").AsMatrix().SetMatrix(ViewProj);
            effect.GetVariableByName("projInv").AsMatrix().SetMatrix(ProjInv);

            effect.GetVariableByName("DiffuseColor").AsVector().Set(Vector3.One);
            effect.GetVariableByName("SpecularColor").AsVector().Set(Vector3.One);
            effect.GetVariableByName("EmissiveColor").AsVector().Set(Vector3.Zero);
            effect.GetVariableByName("SpecularPower").AsScalar().Set(16.0f);

            // Key light.
            effect.GetVariableByName("DirLight0Direction").AsVector().Set(new Vector3(-0.5265408f, -0.5735765f, -0.6275069f));
            effect.GetVariableByName("DirLight0DiffuseColor").AsVector().Set(new Vector3(1, 0.9607844f, 0.8078432f));
            effect.GetVariableByName("DirLight0SpecularColor").AsVector().Set(new Vector3(1, 0.9607844f, 0.8078432f));

            // Fill light.
            effect.GetVariableByName("DirLight1Direction").AsVector().Set(new Vector3(0.7198464f, 0.3420201f, 0.6040227f));
            effect.GetVariableByName("DirLight1DiffuseColor").AsVector().Set(new Vector3(0.9647059f, 0.7607844f, 0.4078432f));
            effect.GetVariableByName("DirLight1SpecularColor").AsVector().Set(Vector3.Zero);

            // Back light.
            effect.GetVariableByName("DirLight2Direction").AsVector().Set(new Vector3(0.4545195f, -0.7660444f, 0.4545195f));
            effect.GetVariableByName("DirLight2DiffuseColor").AsVector().Set(new Vector3(0.3231373f, 0.3607844f, 0.3937255f));
            effect.GetVariableByName("DirLight2SpecularColor").AsVector().Set(new Vector3(0.3231373f, 0.3607844f, 0.3937255f));

            effect.GetVariableByName("FogColor").AsVector().Set(FogColor);
            effect.GetVariableByName("FogStart").AsScalar().Set(FogStart);
            effect.GetVariableByName("FogEnd").AsScalar().Set(FogEnd);

            effect.GetVariableByName("EyePosition").AsVector().Set(Matrix.Invert(View).TranslationVector);

            effect.GetTechniqueByIndex(0).GetPassByIndex(0).Apply(context);

            foreach (var p in instanceData)
            {
                if (toAdd[p.Key].Count > 0 || toRemove[p.Key].Count > 0 || toModify[p.Key].Count > 0)
                {
                    p.Value.InstanceBuffer.SetData(p.Value.Instances.ToArray(), 0, p.Value.InstanceCount);

                    toAdd[p.Key].Clear();
                    toModify[p.Key].Clear();
                    toRemove[p.Key].Clear();
                }

                context.InputAssembler.SetVertexBuffers(0, new SharpDX.Direct3D11.VertexBufferBinding[]
                {
                    new SharpDX.Direct3D11.VertexBufferBinding(p.Key.VertexBuffer, p.Key.VertexBuffer.ElementSize, 0),
                    new SharpDX.Direct3D11.VertexBufferBinding(p.Value.InstanceBuffer, p.Value.InstanceBuffer.ElementSize, 0),
                }
                                                        );
                context.InputAssembler.SetIndexBuffer(p.Key.IndexBuffer, SharpDX.DXGI.Format.R32_UInt, 0);
                context.DrawIndexedInstanced(p.Key.IndexBuffer.ElementCount, p.Value.InstanceCount, 0, 0, 0);
            }
        }
Пример #16
0
 public override void Draw(DeviceContext ctx)
 {
     ctx.DrawIndexedInstanced(this.geom.IndexBuffer.IndicesCount, this.InstanceCount, this.StartIndexLocation, this.BaseVertexLocation, this.StartInstanceLocation);
 }
Пример #17
0
 /// <summary>
 /// Draws our index buffer as an instanced version
 /// </summary>
 /// <param name="context">Device context</param>
 /// <param name="faceCount">Tracked face count</param>
 public void DrawInstanced(DeviceContext context, int faceCount)
 {
     context.DrawIndexedInstanced((int)FaceModel.TriangleCount * 3, faceCount, 0, 0, 0);
 }
Пример #18
0
 /// <summary>
 /// Draws our index buffer as an instanced version
 /// </summary>
 /// <param name="context">Device context</param>
 /// <param name="faceCount">Tracked face count</param>
 public void DrawInstanced(DeviceContext context, int faceCount)
 {
     context.DrawIndexedInstanced((int)FaceModel.TriangleCount * 3, faceCount, 0, 0, 0);
 }
Пример #19
0
 public override void Draw(DeviceContext ctx)
 {
     ctx.DrawIndexedInstanced(this.geom.IndexBuffer.IndicesCount, this.InstanceCount, this.StartIndexLocation, this.BaseVertexLocation, this.StartInstanceLocation);
 }