public ShapeData() { Instances = new List<InstanceData>(); InstanceArray = new InstanceData[0]; PrimitiveTopology = PrimitiveTopology.TriangleList; BufferBindings = new VertexBufferBinding[2]; }
public static void Draw(RenderContext11 renderContext, PositionColoredTextured[] points, int count, Texture11 texture, PrimitiveTopology primitiveType) { if (VertexBuffer == null) { VertexBuffer = new Buffer(renderContext.Device, Marshal.SizeOf(points[0]) * 2500, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, Marshal.SizeOf(points[0])); VertexBufferBinding = new VertexBufferBinding(VertexBuffer, Marshal.SizeOf((points[0])), 0); } renderContext.devContext.InputAssembler.PrimitiveTopology = primitiveType; renderContext.BlendMode = BlendMode.Alpha; renderContext.setRasterizerState(TriangleCullMode.Off); var mat = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11; mat.Transpose(); WarpOutputShader.MatWVP = mat; WarpOutputShader.Use(renderContext.devContext, texture != null); renderContext.SetVertexBuffer(VertexBufferBinding); var box = renderContext.devContext.MapSubresource(VertexBuffer, 0, MapMode.WriteDiscard, MapFlags.None); Utilities.Write(box.DataPointer, points, 0, count); renderContext.devContext.UnmapSubresource(VertexBuffer, 0); if (texture != null) { renderContext.devContext.PixelShader.SetShaderResource(0, texture.ResourceView); } else { renderContext.devContext.PixelShader.SetShaderResource(0, null); } renderContext.devContext.Draw(count, 0); }
internal void Clear() { m_deviceContext.ClearState(); m_inputLayout = null; m_primitiveTopology = PrimitiveTopology.Undefined; m_indexBufferRef = null; m_indexBufferFormat = 0; m_indexBufferOffset = 0; for (int i = 0; i < m_vertexBuffers.Length; i++) m_vertexBuffers[i] = null; for (int i = 0; i < m_vertexBuffersStrides.Length; i++) m_vertexBuffersStrides[i] = 0; m_blendState = null; m_stencilRef = 0; m_depthStencilState = null; m_rtvsCount = 0; for (int i = 0; i < m_rtvs.Length; i++) m_rtvs[i] = null; m_dsv = null; m_rasterizerState = null; m_scissorLeftTop = new Vector2I(-1, -1); m_scissorRightBottom = new Vector2I(-1, -1); m_viewport = default(RawViewportF); m_targetBuffer = null; m_targetOffsets = 0; m_statistics.ClearStates++; }
public static PrimitiveRasterizer CreateRasterizer( PrimitiveTopology primitiveTopology, RasterizerStateDescription rasterizerState, int multiSampleCount, ShaderOutputInputBindings outputInputBindings, ref Viewport viewport, Func<int, int, bool> fragmentQuadFilter) { switch (primitiveTopology) { case PrimitiveTopology.PointList: throw new NotImplementedException(); case PrimitiveTopology.LineList: case PrimitiveTopology.LineStrip: throw new NotImplementedException(); case PrimitiveTopology.TriangleList: case PrimitiveTopology.TriangleStrip: return new TriangleRasterizer( rasterizerState, multiSampleCount, outputInputBindings, ref viewport, fragmentQuadFilter); default: throw new ArgumentOutOfRangeException("primitiveTopology"); } }
public Shape(VertexBufferBinding vertexBinding, PrimitiveTopology topology, ShaderResourceView textureView, Style style, int vertexCount) { this.vertexBinding = vertexBinding; this.topology = topology; this.textureView = textureView; this.style = style; this.vertexCount = vertexCount; }
public Shape CreateShape(float[] floatArray, PrimitiveTopology topology, String textureName, Style style) { var vertices = program.ToDispose(Buffer.Create(program.pipeline.device, BindFlags.VertexBuffer, floatArray)); var vertexBufferBinding = new VertexBufferBinding(vertices, Utilities.SizeOf<float>() * style.floatsPerVertex, 0); return new Shape { vertexBinding = vertexBufferBinding, topology = topology, textureView = GetTexture(textureName), style = style, vertexCount = floatArray.Length / style.floatsPerVertex, }; }
public VanillaEffect Init() { // vertex stuff VertexShader = _demo.ShaderManager["vanillaPlane.vs.cso"]; InputLayout = _disposer.Add(new VanillaInputLayout(VertexShader)); PrimitiveTopology = PrimitiveTopology.TriangleList; // pixel stuff // todo: perhaps add pixelshader PixelShader = null; // return this; }
public static void BeginMode(PrimitiveTopology bTopology, out BeginMode mode, out int patchVertexCount) { switch (bTopology) { case PrimitiveTopology.PointList: mode = OpenTK.Graphics.OpenGL.BeginMode.Points; patchVertexCount = 0; return; case PrimitiveTopology.LineList: mode = OpenTK.Graphics.OpenGL.BeginMode.Lines; patchVertexCount = 0; return; case PrimitiveTopology.LineStrip: mode = OpenTK.Graphics.OpenGL.BeginMode.LineStrip; patchVertexCount = 0; return; case PrimitiveTopology.TriangleList: mode = OpenTK.Graphics.OpenGL.BeginMode.Triangles; patchVertexCount = 0; return; case PrimitiveTopology.TriangleStrip: mode = OpenTK.Graphics.OpenGL.BeginMode.TriangleStrip; patchVertexCount = 0; return; case PrimitiveTopology.LineListWithAdjacency: mode = OpenTK.Graphics.OpenGL.BeginMode.LinesAdjacency; patchVertexCount = 0; return; case PrimitiveTopology.LineStripWithAdjacency: mode = OpenTK.Graphics.OpenGL.BeginMode.LineStripAdjacency; patchVertexCount = 0; return; case PrimitiveTopology.TriangleListWithAdjacency: mode = OpenTK.Graphics.OpenGL.BeginMode.TrianglesAdjacency; patchVertexCount = 0; return; case PrimitiveTopology.TriangleStripWithAdjacency: mode = OpenTK.Graphics.OpenGL.BeginMode.TriangleStripAdjacency; patchVertexCount = 0; return; case PrimitiveTopology.PatchList1: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 1; return; case PrimitiveTopology.PatchList2: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 2; return; case PrimitiveTopology.PatchList3: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 3; return; case PrimitiveTopology.PatchList4: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 4; return; case PrimitiveTopology.PatchList5: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 5; return; case PrimitiveTopology.PatchList6: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 6; return; case PrimitiveTopology.PatchList7: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 7; return; case PrimitiveTopology.PatchList8: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 8; return; case PrimitiveTopology.PatchList9: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 9; return; case PrimitiveTopology.PatchList10: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 10; return; case PrimitiveTopology.PatchList11: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 11; return; case PrimitiveTopology.PatchList12: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 12; return; case PrimitiveTopology.PatchList13: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 13; return; case PrimitiveTopology.PatchList14: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 14; return; case PrimitiveTopology.PatchList15: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 15; return; case PrimitiveTopology.PatchList16: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 16; return; case PrimitiveTopology.PatchList17: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 17; return; case PrimitiveTopology.PatchList18: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 18; return; case PrimitiveTopology.PatchList19: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 19; return; case PrimitiveTopology.PatchList20: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 20; return; case PrimitiveTopology.PatchList21: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 21; return; case PrimitiveTopology.PatchList22: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 22; return; case PrimitiveTopology.PatchList23: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 23; return; case PrimitiveTopology.PatchList24: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 24; return; case PrimitiveTopology.PatchList25: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 25; return; case PrimitiveTopology.PatchList26: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 26; return; case PrimitiveTopology.PatchList27: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 27; return; case PrimitiveTopology.PatchList28: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 28; return; case PrimitiveTopology.PatchList29: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 29; return; case PrimitiveTopology.PatchList30: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 30; return; case PrimitiveTopology.PatchList31: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 31; return; case PrimitiveTopology.PatchList32: mode = OpenTK.Graphics.OpenGL.BeginMode.Patches; patchVertexCount = 32; return; default: throw new ArgumentOutOfRangeException("bTopology"); } }
internal IEnumerable<FragmentQuad> Execute( IEnumerable<InputAssemblerPrimitiveOutput> inputs, PrimitiveTopology primitiveTopology, OutputSignatureChunk previousStageOutputSignature, BytecodeContainer pixelShader, int multiSampleCount) { // TODO: Allow selection of different viewport. var viewport = _viewports[0]; var outputInputBindings = ShaderOutputInputBindings.FromShaderSignatures( previousStageOutputSignature, pixelShader); var rasterizer = PrimitiveRasterizerFactory.CreateRasterizer( primitiveTopology, State.Description, multiSampleCount, outputInputBindings, ref viewport, FragmentFilter); foreach (var primitive in inputs) { // Frustum culling. if (ViewportCuller.ShouldCullTriangle(primitive.Vertices)) continue; // TODO: Clipping. // http://simonstechblog.blogspot.tw/2012/04/software-rasterizer-part-2.html#softwareRasterizerDemo // Perspective divide. for (int i = 0; i < primitive.Vertices.Length; i++) PerspectiveDivide(ref primitive.Vertices[i].Position); // Backface culling. if (State.Description.CullMode != CullMode.None && rasterizer.ShouldCull(primitive.Vertices)) continue; // Transform from clip space to screen space. for (int i = 0; i < primitive.Vertices.Length; i++) viewport.MapClipSpaceToScreenSpace(ref primitive.Vertices[i].Position); // Rasterize. foreach (var fragmentQuad in rasterizer.Rasterize(primitive)) yield return fragmentQuad; } }
public virtual Effect Init(EffectDescription description) { // vertex stuff VertexShader = _demo.ShaderManager[description.VertexShaderName ?? "vanillaPlane.vs.cso"]; InputLayout = _disposer.Add(new VanillaInputLayout(VertexShader)); PrimitiveTopology = PrimitiveTopology.TriangleList; // pixel stuff var addressMode = GetTextureAddressMode(); PixelShader = _demo.ShaderManager[description.PixelShaderName]; _textures = (description.TextureNames ?? new string[0]) .Select(textureName => string.IsNullOrEmpty(textureName) ? null : _demo.TextureManager[textureName]) .ToArray(); _resourceViews = _textures .Select(texture => (texture == null) ? null : _disposer.Add(new ShaderResourceView(_demo.Device, texture.Texture))) .ToArray(); _samplers = _textures .Select(texture => (texture == null) ? null : _disposer.Add(new SamplerState(_demo.Device, new SamplerStateDescription() { Filter = Filter.Anisotropic, AddressU = addressMode, AddressV = addressMode, AddressW = addressMode, BorderColor = Color.Black, ComparisonFunction = Comparison.Never, MaximumAnisotropy = 1, // 16 MipLodBias = 0, MinimumLod = 0, MaximumLod = 1, // 16 }))) .ToArray(); // return this; }
public static void SetPrimitiveTopology(PrimitiveTopology topology) { ImmediateContext.InputAssembler.PrimitiveTopology = topology; }
public void DrawIndexedPrimitives(int count, int startingIndex, PrimitiveTopology primitiveTopology) { PlatformSetPrimitiveTopology(primitiveTopology); DrawIndexedPrimitives(count, startingIndex); PlatformSetPrimitiveTopology(PrimitiveTopology.TriangleList); }
public void SetPrimitiveTopology(PrimitiveTopology topology) { primitiveTopology = topology; }
private static extern UInt32 Topology_VertexOffset(PrimitiveTopology topology, UInt32 prim);
public void Save(DeviceContext context) { this.topology = context.InputAssembler.PrimitiveTopology; this.layout = context.InputAssembler.InputLayout; this.viewports = context.Rasterizer.GetViewports(); this.scissorRectangles = context.Rasterizer.GetScissorRectangles(); this.rasterizerState = context.Rasterizer.State; this.blendState = context.OutputMerger.GetBlendState(out this.blendFactor, out this.sampleMaskRef); this.depthState = context.OutputMerger.GetDepthStencilState(out this.stencilRefRef); this.renderTargetView = context.OutputMerger.GetRenderTargets(1, out this.depthStencilView); this.ps = context.PixelShader.Get(); this.psConstantBuffers = context.PixelShader.GetConstantBuffers(0, 4); this.psSamplers = context.PixelShader.GetSamplers(0, 4); this.psResources = context.PixelShader.GetShaderResources(0, 4); this.vs = context.VertexShader.Get(); this.vsConstantBuffers = context.VertexShader.GetConstantBuffers(0, 4); this.vsSamplers = context.VertexShader.GetSamplers(0, 4); this.vsResources = context.VertexShader.GetShaderResources(0, 4); context.InputAssembler.GetIndexBuffer(out this.ib, out this.ibFormat, out this.ibOffset); context.InputAssembler.GetVertexBuffers(0, 1, this.vb, this.vbStride, this.vbOffset); }
protected abstract void PlatformSetPrimitiveTopology(PrimitiveTopology primitiveTopology);
public void Set(PrimitiveTopology topology) { _topology = topology; }
public static void Draw(PrimitiveTopology topology, int startVertex, int vertexCount) { PreDraw(topology); Context.Draw(startVertex, vertexCount); DrawCount++; }
public static void DrawIndexed(PrimitiveTopology topology, int startIndex, int indexCount, int baseVertex = 0) { PreDraw(topology); Context.DrawIndexed(startIndex, indexCount, baseVertex); DrawCount++; }
/// <summary> /// Initializes a new instance of the <see cref="MeshGeometryBufferModel{VertexStruct}"/> class. /// </summary> /// <param name="topology">The topology.</param> /// <param name="vertexBuffers"></param> /// <param name="dynamic">Create dynamic buffer or immutable buffer</param> public MeshGeometryBufferModel(PrimitiveTopology topology, IElementsBufferProxy[] vertexBuffers, bool dynamic = false) : base(topology, vertexBuffers, dynamic ? new DynamicBufferProxy(sizeof(int), BindFlags.IndexBuffer) : new ImmutableBufferProxy(sizeof(int), BindFlags.IndexBuffer) as IElementsBufferProxy) { }
/// <summary> /// Initializes a new instance of the <see cref="MeshGeometryBufferModel{VertexStruct}"/> class. /// </summary> /// <param name="topology">The topology.</param> /// <param name="vertexBuffer">The vertex buffer.</param> /// <param name="indexBuffer">The index buffer.</param> protected MeshGeometryBufferModel(PrimitiveTopology topology, IElementsBufferProxy[] vertexBuffer, IElementsBufferProxy indexBuffer) : base(topology, vertexBuffer, indexBuffer) { }
internal static PrimitiveType New(PrimitiveTopology primitiveTopology) { return(new PrimitiveType(primitiveTopology)); }
/// <summary> /// Internal constructor. /// </summary> /// <param name="type"></param> private PrimitiveType(PrimitiveTopology type) { Value = type; }
/// <summary> /// Constructor. /// </summary> public Primitive(PrimitiveBehaviour primitiveBehaviour, PrimitiveTopology primitiveTopology, Vertex[] vertices, Color color) : base(primitiveBehaviour, new Material(color), primitiveTopology, vertices) { }
/// <summary> /// Flushes the batch. /// </summary> protected void FlushBatch() { // Early out if there is nothing to flush. if (currentTopology == PrimitiveTopology.Undefined) { return; } ((DeviceContext)graphicsDevice).UnmapSubresource(vertexBuffer, 0); if (currentlyIndexed) { // Draw indexed geometry. ((DeviceContext)graphicsDevice).UnmapSubresource(indexBuffer, 0); graphicsDevice.DrawIndexed(currentTopology, currentIndex - baseIndex, baseIndex, baseVertex); } else { // Draw non-indexed geometry. graphicsDevice.Draw(currentTopology, currentVertex - baseVertex, baseVertex); } currentTopology = PrimitiveTopology.Undefined; }
protected override void PlatformSetPrimitiveTopology(PrimitiveTopology primitiveTopology) { _primitiveType = OpenGLESFormats.ConvertPrimitiveTopology(primitiveTopology); }
public void BeginTransformFeedback(PrimitiveTopology topology) { _renderer.New <BeginTransformFeedbackCommand>().Set(topology); _renderer.QueueCommand(); }
public static void DrawArrays(PrimitiveTopology topology, int first, int count) { Gl.DrawArrays((uint)topology, first, count); GlHelper.GetError(); }
public NullGeometry() { this.VertexCount = 1; this.InstanceCount = 1; this.Topology = PrimitiveTopology.PointList; }
public static void DrawElements(PrimitiveTopology topology, int count, DataType type, IntPtr indices, int basevertex) { unsafe { Gl.DrawElementsBaseVertex((uint)topology, count, (uint)type, indices.ToPointer(), basevertex); GlHelper.GetError(); } }
public static void Draw(SharpDXInfo info, PrimitiveTopology primitiveType) { info.Device.ImmediateContext.InputAssembler.PrimitiveTopology = primitiveType; info.Device.ImmediateContext.DrawIndexed(info.rawIndices.Length, 0, 0); }
public static IEnumerable<InputAssemblerPrimitiveOutput> GetPrimitiveStream( IEnumerable<VertexShaderOutput> shadedVertices, PrimitiveTopology primitiveTopology) { var enumerator = shadedVertices.GetEnumerator(); var primitiveID = 0; switch (primitiveTopology) { case PrimitiveTopology.PointList: { while (enumerator.MoveNext()) yield return new InputAssemblerPrimitiveOutput { PrimitiveID = primitiveID++, Vertices = new[] { enumerator.Current }, }; break; } case PrimitiveTopology.LineList: { while (enumerator.MoveNext()) { var vertex0 = enumerator.Current; enumerator.MoveNext(); var vertex1 = enumerator.Current; yield return new InputAssemblerPrimitiveOutput { PrimitiveID = primitiveID++, Vertices = new[] { vertex0, vertex1 } }; } break; } case PrimitiveTopology.LineStrip: { enumerator.MoveNext(); var vertex0 = enumerator.Current; while (enumerator.MoveNext()) { var vertex1 = enumerator.Current; if (vertex1.IsStripCut) { if (enumerator.MoveNext()) vertex0 = enumerator.Current; } else { yield return new InputAssemblerPrimitiveOutput { PrimitiveID = primitiveID++, Vertices = new[] { vertex0, vertex1 } }; vertex0 = vertex1; } } break; } case PrimitiveTopology.TriangleList: { while (enumerator.MoveNext()) { var vertex0 = enumerator.Current; enumerator.MoveNext(); var vertex1 = enumerator.Current; enumerator.MoveNext(); var vertex2 = enumerator.Current; yield return new InputAssemblerPrimitiveOutput { PrimitiveID = primitiveID++, Vertices = new[] { vertex0, vertex1, vertex2 } }; } break; } case PrimitiveTopology.TriangleStrip: { enumerator.MoveNext(); var vertex0 = enumerator.Current; enumerator.MoveNext(); var vertex1 = enumerator.Current; while (enumerator.MoveNext()) { var vertex2 = enumerator.Current; if (vertex2.IsStripCut) { if (enumerator.MoveNext()) vertex0 = enumerator.Current; if (enumerator.MoveNext()) vertex1 = enumerator.Current; } else { yield return new InputAssemblerPrimitiveOutput { PrimitiveID = primitiveID++, Vertices = new[] { vertex0, vertex1, vertex2 } }; vertex1 = vertex2; vertex0 = vertex1; } } break; } case PrimitiveTopology.LineListWithAdjacency: break; case PrimitiveTopology.LineStripWithAdjacency: break; case PrimitiveTopology.TriangleListWithAdjacency: break; case PrimitiveTopology.TriangleStripWithAdjacency: break; default: throw new ArgumentOutOfRangeException("primitiveTopology"); } }
public static UInt32 GetVertexOffset(this PrimitiveTopology topology, UInt32 primitiveIndex) { return(Topology_VertexOffset(topology, primitiveIndex)); }
/// <summary> /// Draws instanced primitives. /// </summary> /// <param name="indexCount">The number of indices to draw, per-instance.</param> /// <param name="instanceCount">The number of instances to draw.</param> /// <param name="primitiveTopology">The <see cref="PrimitiveTopology"/> to render with.</param> public void DrawInstancedPrimitives(int indexCount, int instanceCount, PrimitiveTopology primitiveTopology) { PlatformSetPrimitiveTopology(primitiveTopology); DrawInstancedPrimitives(indexCount, instanceCount); PlatformSetPrimitiveTopology(PrimitiveTopology.TriangleList); }
public void SetPrimitiveTopology(PrimitiveTopology topology) { _renderer.New <SetPrimitiveTopologyCommand>().Set(topology); _renderer.QueueCommand(); }
private void StartDrawing(string name, FXBase effect, int technique, PrimitiveTopology mode) { Camera.Instance.World = Matrix.Identity; activeTexture = resources.GetResource(name); ActiveEffect = effect; ActiveEffect.TechniqueIndex = technique; this.mode = mode; Reset(); }
/// <inheritdoc /> public void Render(TVertex[] vertices, PrimitiveTopology primitiveTopology) { StageVertexShader(vertices, primitiveTopology); }
public static void ResetVertexStateTracker() { LastPrimitiveTopology = PrimitiveTopology.Undefined; }
public static SharpDX.Direct3D9.PrimitiveType PrimitiveType(PrimitiveTopology primitiveTopology) { switch (primitiveTopology) { case PrimitiveTopology.PointList: return SharpDX.Direct3D9.PrimitiveType.PointList; case PrimitiveTopology.LineList: return SharpDX.Direct3D9.PrimitiveType.LineList; case PrimitiveTopology.LineStrip: return SharpDX.Direct3D9.PrimitiveType.LineStrip; case PrimitiveTopology.TriangleList: return SharpDX.Direct3D9.PrimitiveType.TriangleList; case PrimitiveTopology.TriangleStrip: return SharpDX.Direct3D9.PrimitiveType.TriangleStrip; default: throw new NotSupportedException(string.Format( "Primitive topology '{0}' is not supported by the SharpDX9 implementation of Beholder.", primitiveTopology.ToString())); } }
public void Setup(Fragment fragment, VertexBufferBinding vb, SharpDX.Direct3D11.Buffer ib, PrimitiveTopology topology = PrimitiveTopology.TriangleList) { var context = RenderDevice.ImmediateContext; // Prepare All the stages context.InputAssembler.InputLayout = fragment.Layout; context.InputAssembler.PrimitiveTopology = topology; context.InputAssembler.SetVertexBuffers(0, vb); context.InputAssembler.SetIndexBuffer(ib, Format.R32_UInt, 0); context.VertexShader.Set(fragment.VS); context.PixelShader.Set(fragment.PS); context.Rasterizer.SetViewport(new Viewport(0, 0, RenderCanvas.ClientSize.Width, RenderCanvas.ClientSize.Height, 0.0f, 1.0f)); context.OutputMerger.SetTargets(RTView); context.UpdateSubresource(new WorldProjection[] { WP }, WPConstantBuffer); context.VertexShader.SetConstantBuffer(0, WPConstantBuffer); context.PixelShader.SetConstantBuffer(0, WPConstantBuffer); }
public static void DrawElements(PrimitiveTopology topology, int count, DataType type, int offset, int basevertex) { unsafe { Gl.DrawElementsBaseVertex((uint)topology, count, (uint)type, (void*)offset, basevertex); GlHelper.GetError(); } }
/// <summary> /// Draws the specified topology. /// </summary> /// <param name="topology">The topology.</param> /// <param name="isIndexed">if set to <c>true</c> [is indexed].</param> /// <param name="indices">The indices.</param> /// <param name="indexCount">The index count.</param> /// <param name="vertexCount">The vertex count.</param> /// <returns>IntPtr.</returns> /// <exception cref="System.ArgumentNullException">Indices cannot be null</exception> /// <exception cref="System.ArgumentException">Too many indices;indexCount</exception> /// <exception cref="System.InvalidOperationException">Begin must be called before Draw</exception> protected unsafe IntPtr Draw(PrimitiveTopology topology, bool isIndexed, IntPtr indices, int indexCount, int vertexCount) { if (isIndexed && indices == IntPtr.Zero) { throw new ArgumentNullException("Indices cannot be null"); } if (indexCount >= maxIndices) { throw new ArgumentException("Too many indices", "indexCount"); } if (vertexCount >= maxVertices) { throw new ArgumentException("Too many vertices"); } if (!inBeginEndPair) { throw new InvalidOperationException("Begin must be called before Draw"); } // Can we merge this primitive in with an existing batch, or must we flush first? bool wrapIndexBuffer = currentIndex + indexCount > maxIndices; bool wrapVertexBuffer = currentVertex + vertexCount > maxVertices; if ((topology != currentTopology) || (isIndexed != currentlyIndexed) || !CanBatchPrimitives(topology) || wrapIndexBuffer || wrapVertexBuffer) { FlushBatch(); } if (wrapIndexBuffer) { currentIndex = 0; } if (wrapVertexBuffer) { currentVertex = 0; } // If we are not already in a batch, lock the buffers. if (currentTopology == PrimitiveType.Undefined) { if (isIndexed) { mappedIndices = LockBuffer(indexBuffer, currentIndex); baseIndex = currentIndex; } mappedVertices = LockBuffer(vertexBuffer, currentVertex); baseVertex = currentVertex; currentTopology = topology; currentlyIndexed = isIndexed; } // Copy over the index data. if (isIndexed) { short *outputIndices = (short *)mappedIndices.DataPointer + currentIndex; for (int i = 0; i < indexCount; i++) { outputIndices[i] = (short)(((short *)indices)[i] + currentVertex - baseVertex); } currentIndex += indexCount; } // Return the output vertex data location. var result = (IntPtr)((byte *)mappedVertices.DataPointer + (currentVertex * VertexSize)); currentVertex += vertexCount; return(result); }
private static extern UInt32 Topology_VertexOffset(PrimitiveTopology topology, UInt32 prim);
internal static SharpDX.Direct3D.PrimitiveTopology VdToD3D11PrimitiveTopology(PrimitiveTopology primitiveTopology) { switch (primitiveTopology) { case PrimitiveTopology.TriangleList: return(SharpDX.Direct3D.PrimitiveTopology.TriangleList); case PrimitiveTopology.TriangleStrip: return(SharpDX.Direct3D.PrimitiveTopology.TriangleStrip); case PrimitiveTopology.LineList: return(SharpDX.Direct3D.PrimitiveTopology.LineList); case PrimitiveTopology.LineStrip: return(SharpDX.Direct3D.PrimitiveTopology.LineStrip); case PrimitiveTopology.PointList: return(SharpDX.Direct3D.PrimitiveTopology.PointList); default: throw Illegal.Value <PrimitiveTopology>(); } }
private void DrawVertices(VertexPositionColor[] vertices, PrimitiveTopology top) { PopulatePrimitivesBuffer(vertices); this.GraphicsDevice.InputAssembler.SetPrimitiveTopology(top); this.GraphicsDevice.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_userPrimitivesBuffer, VertexPositionColor.SizeInBytes, 0)); this.GraphicsDevice.Draw(vertices.Length, 0); }
public static Model New(DirectXDevice device, float tileX = 1.0f, float tileY = 1.0f, float tileZ = 1.0f, PrimitiveTopology primitiveTopology = PrimitiveTopology.TriangleList, ModelOperation modelOperations = ModelOperation.None) { VertexPositionNormalTextureCube[] vertices; int[] indices; var skybox = new SkyboxMesh(tileX, tileY, tileZ); skybox.GenerateMesh(out vertices, out indices); return(GeometricPrimitive <VertexPositionNormalTextureCube> .New(device, "SkyBoxMesh", vertices, indices, primitiveTopology, modelOperations)); }
public IPipeline CreatePipeline(Shader vertexShader, Shader pixelShader, IInputLayout inputLayout, IBlendState blendState, IDepthStencilState depthStencilState, IRasterizerState rasterizerState, Viewport viewport, PrimitiveTopology primitiveTopology) { throw new System.NotImplementedException(); }
internal unsafe PipelineState(GraphicsDevice graphicsDevice, PipelineStateDescription pipelineStateDescription) : base(graphicsDevice) { if (pipelineStateDescription.RootSignature != null) { var effectReflection = pipelineStateDescription.EffectBytecode.Reflection; var rootSignatureParameters = new List<RootParameter>(); var immutableSamplers = new List<StaticSamplerDescription>(); SrvBindCounts = new int[pipelineStateDescription.RootSignature.EffectDescriptorSetReflection.Layouts.Count]; SamplerBindCounts = new int[pipelineStateDescription.RootSignature.EffectDescriptorSetReflection.Layouts.Count]; for (int layoutIndex = 0; layoutIndex < pipelineStateDescription.RootSignature.EffectDescriptorSetReflection.Layouts.Count; layoutIndex++) { var layout = pipelineStateDescription.RootSignature.EffectDescriptorSetReflection.Layouts[layoutIndex]; if (layout.Layout == null) continue; // TODO D3D12 for now, we don't control register so we simply generate one resource table per shader stage and per descriptor set layout // we should switch to a model where we make sure VS/PS don't overlap for common descriptors so that they can be shared var srvDescriptorRangesVS = new List<DescriptorRange>(); var srvDescriptorRangesPS = new List<DescriptorRange>(); var samplerDescriptorRangesVS = new List<DescriptorRange>(); var samplerDescriptorRangesPS = new List<DescriptorRange>(); int descriptorSrvOffset = 0; int descriptorSamplerOffset = 0; foreach (var item in layout.Layout.Entries) { var isSampler = item.Class == EffectParameterClass.Sampler; // Find matching resource bindings foreach (var binding in effectReflection.ResourceBindings) { if (binding.Stage == ShaderStage.None || binding.KeyInfo.Key != item.Key) continue; List<DescriptorRange> descriptorRanges; switch (binding.Stage) { case ShaderStage.Vertex: descriptorRanges = isSampler ? samplerDescriptorRangesVS : srvDescriptorRangesVS; break; case ShaderStage.Pixel: descriptorRanges = isSampler ? samplerDescriptorRangesPS : srvDescriptorRangesPS; break; default: throw new NotImplementedException(); } if (isSampler) { if (item.ImmutableSampler != null) { immutableSamplers.Add(new StaticSamplerDescription((ShaderVisibility)binding.Stage, binding.SlotStart, 0) { // TODO D3D12 ImmutableSampler should only be a state description instead of a GPU object? Filter = (Filter)item.ImmutableSampler.Description.Filter, ComparisonFunc = (Comparison)item.ImmutableSampler.Description.CompareFunction, BorderColor = ColorHelper.ConvertStatic(item.ImmutableSampler.Description.BorderColor), AddressU = (SharpDX.Direct3D12.TextureAddressMode)item.ImmutableSampler.Description.AddressU, AddressV = (SharpDX.Direct3D12.TextureAddressMode)item.ImmutableSampler.Description.AddressV, AddressW = (SharpDX.Direct3D12.TextureAddressMode)item.ImmutableSampler.Description.AddressW, MinLOD = item.ImmutableSampler.Description.MinMipLevel, MaxLOD = item.ImmutableSampler.Description.MaxMipLevel, MipLODBias = item.ImmutableSampler.Description.MipMapLevelOfDetailBias, MaxAnisotropy = item.ImmutableSampler.Description.MaxAnisotropy, }); } else { // Add descriptor range descriptorRanges.Add(new DescriptorRange(DescriptorRangeType.Sampler, item.ArraySize, binding.SlotStart, 0, descriptorSamplerOffset)); } } else { DescriptorRangeType descriptorRangeType; switch (binding.Class) { case EffectParameterClass.ConstantBuffer: descriptorRangeType = DescriptorRangeType.ConstantBufferView; break; case EffectParameterClass.ShaderResourceView: descriptorRangeType = DescriptorRangeType.ShaderResourceView; break; case EffectParameterClass.UnorderedAccessView: descriptorRangeType = DescriptorRangeType.UnorderedAccessView; break; default: throw new NotImplementedException(); } // Add descriptor range descriptorRanges.Add(new DescriptorRange(descriptorRangeType, item.ArraySize, binding.SlotStart, 0, descriptorSrvOffset)); } } // Move to next element (mirror what is done in DescriptorSetLayout) if (isSampler) { if (item.ImmutableSampler == null) descriptorSamplerOffset += item.ArraySize; } else { descriptorSrvOffset += item.ArraySize; } } if (srvDescriptorRangesVS.Count > 0) { rootSignatureParameters.Add(new RootParameter(ShaderVisibility.Vertex, srvDescriptorRangesVS.ToArray())); SrvBindCounts[layoutIndex]++; } if (srvDescriptorRangesPS.Count > 0) { rootSignatureParameters.Add(new RootParameter(ShaderVisibility.Pixel, srvDescriptorRangesPS.ToArray())); SrvBindCounts[layoutIndex]++; } if (samplerDescriptorRangesVS.Count > 0) { rootSignatureParameters.Add(new RootParameter(ShaderVisibility.Vertex, samplerDescriptorRangesVS.ToArray())); SamplerBindCounts[layoutIndex]++; } if (samplerDescriptorRangesPS.Count > 0) { rootSignatureParameters.Add(new RootParameter(ShaderVisibility.Pixel, samplerDescriptorRangesPS.ToArray())); SamplerBindCounts[layoutIndex]++; } } var rootSignatureDesc = new RootSignatureDescription(RootSignatureFlags.AllowInputAssemblerInputLayout, rootSignatureParameters.ToArray(), immutableSamplers.ToArray()); var rootSignature = NativeDevice.CreateRootSignature(0, rootSignatureDesc.Serialize()); var inputElements = new InputElement[pipelineStateDescription.InputElements.Length]; for (int i = 0; i < inputElements.Length; ++i) { var inputElement = pipelineStateDescription.InputElements[i]; inputElements[i] = new InputElement { Format = (SharpDX.DXGI.Format)inputElement.Format, AlignedByteOffset = inputElement.AlignedByteOffset, SemanticName = inputElement.SemanticName, SemanticIndex = inputElement.SemanticIndex, Slot = inputElement.InputSlot, Classification = (SharpDX.Direct3D12.InputClassification)inputElement.InputSlotClass, InstanceDataStepRate = inputElement.InstanceDataStepRate, }; } PrimitiveTopologyType primitiveTopologyType; switch (pipelineStateDescription.PrimitiveType) { case PrimitiveType.Undefined: throw new ArgumentOutOfRangeException(); case PrimitiveType.PointList: primitiveTopologyType = PrimitiveTopologyType.Point; break; case PrimitiveType.LineList: case PrimitiveType.LineStrip: case PrimitiveType.LineListWithAdjacency: case PrimitiveType.LineStripWithAdjacency: primitiveTopologyType = PrimitiveTopologyType.Line; break; case PrimitiveType.TriangleList: case PrimitiveType.TriangleStrip: case PrimitiveType.TriangleListWithAdjacency: case PrimitiveType.TriangleStripWithAdjacency: primitiveTopologyType = PrimitiveTopologyType.Triangle; break; default: if (pipelineStateDescription.PrimitiveType >= PrimitiveType.PatchList && pipelineStateDescription.PrimitiveType < PrimitiveType.PatchList + 32) primitiveTopologyType = PrimitiveTopologyType.Patch; else throw new ArgumentOutOfRangeException("pipelineStateDescription.PrimitiveType"); break; } var nativePipelineStateDescription = new GraphicsPipelineStateDescription { InputLayout = new InputLayoutDescription(inputElements), RootSignature = rootSignature, RasterizerState = CreateRasterizerState(pipelineStateDescription.RasterizerState), BlendState = CreateBlendState(pipelineStateDescription.BlendState), SampleMask = (int)pipelineStateDescription.SampleMask, DepthStencilFormat = (SharpDX.DXGI.Format)pipelineStateDescription.Output.DepthStencilFormat, DepthStencilState = CreateDepthStencilState(pipelineStateDescription.DepthStencilState), RenderTargetCount = pipelineStateDescription.Output.RenderTargetCount, // TODO D3D12 hardcoded StreamOutput = new StreamOutputDescription(), PrimitiveTopologyType = primitiveTopologyType, // TODO D3D12 hardcoded SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), }; fixed (PixelFormat* renderTargetFormats = &pipelineStateDescription.Output.RenderTargetFormat0) { for (int i = 0; i < pipelineStateDescription.Output.RenderTargetCount; ++i) nativePipelineStateDescription.RenderTargetFormats[i] = (SharpDX.DXGI.Format)renderTargetFormats[i]; } foreach (var stage in pipelineStateDescription.EffectBytecode.Stages) { switch (stage.Stage) { case ShaderStage.Vertex: nativePipelineStateDescription.VertexShader = stage.Data; break; case ShaderStage.Hull: nativePipelineStateDescription.HullShader = stage.Data; break; case ShaderStage.Domain: nativePipelineStateDescription.DomainShader = stage.Data; break; case ShaderStage.Geometry: nativePipelineStateDescription.GeometryShader = stage.Data; break; case ShaderStage.Pixel: nativePipelineStateDescription.PixelShader = stage.Data; break; default: throw new ArgumentOutOfRangeException(); } } CompiledState = NativeDevice.CreateGraphicsPipelineState(nativePipelineStateDescription); RootSignature = rootSignature; PrimitiveTopology = (PrimitiveTopology)pipelineStateDescription.PrimitiveType; } }
internal void SetPrimitiveTopology(PrimitiveTopology pt) { if (pt == m_primitiveTopology) return; m_primitiveTopology = pt; m_deviceContext.InputAssembler.PrimitiveTopology = pt; m_statistics.SetPrimitiveTopologies++; }
/// <summary> /// Sets the input layout and primitive topology, then starts a new 3D drawing pass using the default state settings (<see cref="OpenMLTD.MilliSim.Graphics.Rendering.FrequentlyUsedStates.AlphaBlend"/>, <see cref="OpenMLTD.MilliSim.Graphics.Rendering.FrequentlyUsedStates.LessEqual"/>, <see cref="OpenMLTD.MilliSim.Graphics.Rendering.FrequentlyUsedStates.NoCull"/>). /// </summary> /// <param name="inputLayout">The input layout indicating how vertices are stored.</param> /// <param name="topology">The primitive topology indicating how indices are stored.</param> public void Begin3D(InputLayout inputLayout, PrimitiveTopology topology) { var states = FrequentlyUsedStates; Begin3D(inputLayout, topology, states.AlphaBlend, states.LessEqual, states.NoCull); }
/// <summary> /// Draws the specified topology. /// </summary> /// <param name="topology">The topology.</param> /// <param name="isIndexed">if set to <c>true</c> [is indexed].</param> /// <param name="indices">The indices.</param> /// <param name="indexCount">The index count.</param> /// <param name="vertexCount">The vertex count.</param> /// <returns>IntPtr.</returns> /// <exception cref="System.ArgumentNullException">Indices cannot be null</exception> /// <exception cref="System.ArgumentException">Too many indices;indexCount</exception> /// <exception cref="System.InvalidOperationException">Begin must be called before Draw</exception> protected unsafe IntPtr Draw(PrimitiveTopology topology, bool isIndexed, IntPtr indices, int indexCount, int vertexCount) { if (isIndexed && indices == IntPtr.Zero) { throw new ArgumentNullException("Indices cannot be null"); } if (indexCount >= maxIndices) { throw new ArgumentException("Too many indices", "indexCount"); } if (vertexCount >= maxVertices) { throw new ArgumentException("Too many vertices"); } if (!inBeginEndPair) { throw new InvalidOperationException("Begin must be called before Draw"); } // Can we merge this primitive in with an existing batch, or must we flush first? bool wrapIndexBuffer = currentIndex + indexCount > maxIndices; bool wrapVertexBuffer = currentVertex + vertexCount > maxVertices; if ((topology != currentTopology) || (isIndexed != currentlyIndexed) || !CanBatchPrimitives(topology) || wrapIndexBuffer || wrapVertexBuffer) { FlushBatch(); } if (wrapIndexBuffer) { currentIndex = 0; } if (wrapVertexBuffer) { currentVertex = 0; } // If we are not already in a batch, lock the buffers. if (currentTopology == PrimitiveType.Undefined) { if (isIndexed) { mappedIndices = LockBuffer(indexBuffer, currentIndex); baseIndex = currentIndex; } mappedVertices = LockBuffer(vertexBuffer, currentVertex); baseVertex = currentVertex; currentTopology = topology; currentlyIndexed = isIndexed; } // Copy over the index data. if (isIndexed) { short* outputIndices = (short*)mappedIndices.DataPointer + currentIndex; for (int i = 0; i < indexCount; i++) { outputIndices[i] = (short)(((short*)indices)[i] + currentVertex - baseVertex); } currentIndex += indexCount; } // Return the output vertex data location. var result = (IntPtr)((byte*)mappedVertices.DataPointer + (currentVertex * VertexSize)); currentVertex += vertexCount; return result; }
public void SetPrimitiveTopology(PrimitiveTopology topology) { _primitiveType = topology.Convert(); }
private static bool CanBatchPrimitives(PrimitiveTopology topology) { switch (topology) { case PrimitiveTopology.PointList: case PrimitiveTopology.LineList: case PrimitiveTopology.TriangleList: // Lists can easily be merged. return true; } return false; // We could also merge indexed strips by inserting degenerates, // but that's not always a perf win, so let's keep things simple. }
public void BeginTransformFeedback(PrimitiveTopology topology) { GL.BeginTransformFeedback(_tfTopology = topology.ConvertToTfType()); _tfEnabled = true; }
// Set up the pipeline for drawing a shape then draw it. public void Draw(Shape shape) { // Set pipeline components to suit the shape if necessary. if (currVertexBinding.Buffer != shape.vertexBinding.Buffer) { context.InputAssembler.SetVertexBuffers(0, shape.vertexBinding); currVertexBinding = shape.vertexBinding; } if (currLayout != shape.style.layout) { context.InputAssembler.InputLayout = shape.style.layout; currLayout = shape.style.layout; } if (currTopology != shape.topology) { context.InputAssembler.PrimitiveTopology = shape.topology; currTopology = shape.topology; } if (currVertexShader != shape.style.vertexShader) { context.VertexShader.Set(shape.style.vertexShader); currVertexShader = shape.style.vertexShader; } if (currPixelShader != shape.style.pixelShader) { context.PixelShader.Set(shape.style.pixelShader); currPixelShader = shape.style.pixelShader; } if (currTextureView != shape.textureView) { context.PixelShader.SetShaderResource(0, shape.textureView); currTextureView = shape.textureView; } // Calculate the vertex transformation and update the constant buffer. worldViewProj = world * view * proj; worldViewProj.Transpose(); context.UpdateSubresource(ref worldViewProj, constantBuffer); // Draw the shape. context.Draw(shape.vertexCount, 0); }
// Create a shape that's ready to be drawn with the pipeline. public Shape createShape(float[] floatArray, PrimitiveTopology topology, String textureName, Style style) { try { var vertices = Buffer.Create(deviceManager.DeviceDirect3D, BindFlags.VertexBuffer, floatArray); var vertexBufferBinding = new VertexBufferBinding(vertices, Utilities.SizeOf<float>() * style.floatsPerVertex, 0); return new Shape(vertexBufferBinding, topology, GetTexture(textureName), style, floatArray.Length / style.floatsPerVertex); } catch (Exception e) { Debug.WriteLine(e); return null; } }