private void createVertexBuffer(Device device, PositionColorSize[] points) { if (renderStrategy == RenderStrategy.GeometryShader) { vertexBuffer = new GenVertexBuffer<PositionColorSize>(device, points); } else if (renderStrategy == RenderStrategy.Instanced) { vertexBuffer = new GenVertexBuffer<PositionColorSize>(device, points); } else { const int verticesPerPoint = 4; var expandedPoints = new CompatibilityPointSpriteShader.Vertex[points.Length * verticesPerPoint]; var index = 0; foreach (var p in points) { CompatibilityPointSpriteShader.Vertex xp; xp.X = p.X; xp.Y = p.Y; xp.Z = p.Z; xp.color = p.color; xp.size = p.size; xp.corner = 0; expandedPoints[index + 0] = xp; expandedPoints[index + 0].corner = 0x00000000; expandedPoints[index + 1] = xp; expandedPoints[index + 1].corner = 0xff00ff00; expandedPoints[index + 2] = xp; expandedPoints[index + 2].corner = 0xffffffff; expandedPoints[index + 3] = xp; expandedPoints[index + 3].corner = 0x00ff00ff; index += verticesPerPoint; } fallbackVertexBuffer = new GenVertexBuffer<CompatibilityPointSpriteShader.Vertex>(device, expandedPoints); } }
public void updateVertexBuffer(PositionColorSize[] points) { if (points == null || points.Length == 0 || points.Length > Count) { return; } if (renderStrategy == RenderStrategy.GeometryShader || renderStrategy == RenderStrategy.Instanced) { var vb = (GenVertexBuffer<PositionColorSize>) vertexBuffer; vb.Update(points); } else { var vb = (GenVertexBuffer<CompatibilityPointSpriteShader.Vertex>)fallbackVertexBuffer; var vertexData = vb.Lock(0, 0); if (vertexData != null) { const int verticesPerPoint = 4; var index = 0; foreach (var p in points) { CompatibilityPointSpriteShader.Vertex xp; xp.X = p.X; xp.Y = p.Y; xp.Z = p.Z; xp.color = p.color; xp.size = p.size; xp.corner = 0; vertexData[index + 0] = xp; vertexData[index + 0].corner = 0x00000000; vertexData[index + 1] = xp; vertexData[index + 1].corner = 0xff00ff00; vertexData[index + 2] = xp; vertexData[index + 2].corner = 0xffffffff; vertexData[index + 3] = xp; vertexData[index + 3].corner = 0x00ff00ff; index += verticesPerPoint; } } vb.Unlock(); } }
public static void DrawPointPlanet(RenderContext11 renderContext, Vector3d location, float size, Color color, bool zOrder, float opacity) { var vertices = new PositionColorSize[1]; vertices[0].Position = location.Vector311; vertices[0].size = size * 200; vertices[0].Color = color; if (planetsPointSet == null) { planetsPointSet = new PointSpriteSet(renderContext.Device, vertices); planetsPointSet.PointScaleFactors = new Vector3(1.0f, 0.0f, 0.0f); } else { planetsPointSet.updateVertexBuffer(vertices); } renderContext.BlendMode = BlendMode.Additive; renderContext.DepthStencilMode = zOrder ? DepthStencilMode.ZReadOnly : DepthStencilMode.Off; renderContext.setRasterizerState(TriangleCullMode.Off); planetsPointSet.Draw(renderContext, 1, Grids.StarProfile, opacity); renderContext.DepthStencilMode = DepthStencilMode.ZReadWrite; renderContext.BlendMode = BlendMode.Alpha; }
public PointSpriteSet(Device device, PositionColorSize[] points) : base(device, points) { createVertexBuffer(device, points); }
public PointSpriteSet(SharpDX.Direct3D11.Device device, PositionColorSize[] points) : base(device, points) { createVertexBuffer(device, points); }