public void Add(MyLodTypeEnum lod, MyRender.MyRenderElement renderElement)
 {
     if (renderElement.DrawTechnique == MyMeshDrawTechnique.VOXEL_MAP)
     {
         AddVoxel(lod, renderElement);
     }
     else
     {
         AddModel(lod, renderElement);
     }
 }
        public void AddVoxel(MyLodTypeEnum lod, MyRender.MyRenderElement renderElement)
        {
            var matDict = Voxels[GetVoxelIndex(lod, renderElement.VoxelBatch.Type)];
            List <MyRender.MyRenderElement> elements;

            if (!matDict.Voxels.TryGetValue(renderElement.VoxelBatch.MaterialId, out elements))
            {
                elements = new List <MyRender.MyRenderElement>(20);
                matDict.Voxels[renderElement.VoxelBatch.MaterialId] = elements;
            }
            matDict.RenderElementCount++;
            elements.Add(renderElement);
        }
        private static void DrawShadowsForElements(MyEffectShadowMap effect, bool relativeCamera, List <MyRender.MyRenderElement> elements, bool voxelShadows, int perfCounterIndex)
        {
            effect.Begin();

            long lastVertexBuffer = 0;

            for (int i = 0; i < elements.Count; i++)
            {
                MyRender.MyRenderElement renderElement = elements[i];

                if ((renderElement.Entity is MyVoxelMap) != voxelShadows ||
                    renderElement.VertexBuffer.IsDisposed ||
                    renderElement.IndexBuffer.IsDisposed)
                {
                    continue;
                }

                long currentVertexBuffer = renderElement.VertexBuffer.GetHashCode();
                if (lastVertexBuffer != currentVertexBuffer)
                {
                    lastVertexBuffer = currentVertexBuffer;

                    MyMinerGame.Static.GraphicsDevice.SetStreamSource(0, renderElement.VertexBuffer, 0, renderElement.VertexStride);
                    MyMinerGame.Static.GraphicsDevice.VertexDeclaration = renderElement.VertexDeclaration;
                    MyMinerGame.Static.GraphicsDevice.Indices           = renderElement.IndexBuffer;

                    System.Diagnostics.Debug.Assert(renderElement.IndexBuffer != null);
                }

                effect.SetWorldMatrix(relativeCamera ? renderElement.WorldMatrixForDraw : renderElement.WorldMatrix);

                MyPerformanceCounter.PerCameraDraw.ShadowDrawCalls[perfCounterIndex]++;

                effect.D3DEffect.CommitChanges();
                MyMinerGame.Static.GraphicsDevice.DrawIndexedPrimitive(SharpDX.Direct3D9.PrimitiveType.TriangleList, 0, 0, renderElement.VertexCount, renderElement.IndexStart, renderElement.TriCount);

                MyPerformanceCounter.PerCameraDraw.TotalDrawCalls++;
            }

            effect.End();
        }
        public void AddModel(MyLodTypeEnum lod, MyRender.MyRenderElement renderElement)
        {
            var matDict = Models[GetModelIndex(lod, renderElement.DrawTechnique)];
            ModelMaterialSet vbDict;

            if (!matDict.Models.TryGetValue(renderElement.Material, out vbDict))
            {
                vbDict = new ModelMaterialSet();
                matDict.Models[renderElement.Material] = vbDict;
            }

            List <MyRender.MyRenderElement> elements;

            if (!vbDict.Models.TryGetValue(renderElement.VertexBuffer, out elements))
            {
                elements = new List <MyRender.MyRenderElement>(20);
                vbDict.Models[renderElement.VertexBuffer] = elements;
            }

            matDict.RenderElementCount++;
            vbDict.RenderElementCount++;

            elements.Add(renderElement);
        }