// drawRenderablePrimitives -- Draws the primitives public void drawRenderablePrimitives() { RenderablePrimitiveNode current = _headNode; while (current != null) { _graphicsDevice.Textures[0] = current.renderablePrimitive.texture; _primitivesEffect.Parameters["world"].SetValue(current.renderablePrimitive.worldMatrix); _primitivesEffect.CurrentTechnique.Passes["textured_primitives"].Apply(); _graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, current.renderablePrimitive.vertices, 0, current.renderablePrimitive.primitiveCount, VertexPositionColorTexture.VertexDeclaration); //_graphicsDevice.DrawUserPrimitives<CustomVertexFormat>(PrimitiveType.TriangleList, current.renderablePrimitive.vertices, 0, current.renderablePrimitive.primitiveCount); current = current.next; } _headNode = null; }
// Add a renderable primitive to the draw list // TODO: This creates a lot of garbage... should consider refactoring. public void addRenderablePrimitive(IRenderablePrimitive renderablePrimitive) { RenderablePrimitiveNode node = new RenderablePrimitiveNode(renderablePrimitive); if (_headNode == null) { // This is the first node, so make it the head _headNode = node; } else if (_headNode.renderablePrimitive.layerDepth < node.renderablePrimitive.layerDepth) { // The head node has a layer depth lower than the node being added, so move it down the list node.next = _headNode; _headNode = node; } else { RenderablePrimitiveNode current = _headNode; while (current != null) { if (current.next == null) { current.next = node; return; } else if (current.next.renderablePrimitive.layerDepth <= node.renderablePrimitive.layerDepth) { node.next = current.next; current.next = node; return; } current = current.next; } } }