internal static void Push() { if (spritesDrawn == 0) { return; } else if (spritesDrawn == -1) { spritesDrawn = 0; return; } Display.context.PixelShader.SetShaderResource(0, lastTexture.ressource); //Display.context.Rasterizer.SetScissorRectangles(lastRectangle); while (vertices.Seek()) { int newVar = verticesLastPosition + vertices.GetItemsCount(); if (newVar >= vertexBufferSize) { DataStream stream; Display.context.MapSubresource(vertexBuffer, MapMode.WriteDiscard, MapFlags.None, out stream); stream.WriteRange(vertices.Get()); Display.context.UnmapSubresource(vertexBuffer, 0); Display.context.DrawIndexed(spritesDrawn * 6, 0, 0); verticesLastCount = spritesDrawn; verticesLastPosition = vertices.GetItemsCount(); } else { DataStream stream; Display.context.MapSubresource(vertexBuffer, MapMode.WriteNoOverwrite, MapFlags.None, out stream); stream.Position = verticesLastPosition * Vertex2D.SizeInBytes; stream.WriteRange(vertices.Get(), 0, vertices.GetItemsCount()); Display.context.UnmapSubresource(vertexBuffer, 0); Display.context.DrawIndexed(spritesDrawn * 6, 0, verticesLastPosition); verticesLastCount += spritesDrawn; verticesLastPosition += vertices.GetItemsCount(); } } vertices.Clear(); spritesDrawn = 0; }
public void Render() { if (vertices.Count > 0) { ShaderManager.Apply("VS_Debug"); ShaderManager.Apply("PS_Debug"); GraphicsManager.SetBlendState(DeviceStates.blendStateTrans); GraphicsManager.SetDepthState(DeviceStates.depthWriteOff); GraphicsManager.SetPrimitiveTopology(SharpDX.Direct3D.PrimitiveTopology.TriangleList); Display.context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, VertexColor.SizeInBytes, 0)); while (vertices.Seek()) { DataStream stream; Display.context.MapSubresource(vertexBuffer, MapMode.WriteDiscard, MapFlags.None, out stream); stream.WriteRange(vertices.Get()); Display.context.UnmapSubresource(vertexBuffer, 0); Display.context.Draw(vertices.GetItemsCount(), 0); } vertices.Clear(); } }