Ejemplo n.º 1
0
        private void SetupRenderElement(MyRenderVoxelBatch batch, MyRender.MyRenderElement renderElement)
        {
            renderElement.RenderObject = this;

            renderElement.VertexDeclaration = MyVertexFormatVoxelSingleMaterial.VertexDeclaration;
            renderElement.VertexStride      = MyVertexFormatVoxelSingleMaterial.Stride;
            renderElement.VertexCount       = batch.VertexCount;
            renderElement.VertexBuffer      = batch.VertexBuffer;

            renderElement.InstanceBuffer = null;

            renderElement.IndexBuffer = batch.IndexBuffer;
            renderElement.IndexStart  = 0;
            if (renderElement.IndexBuffer != null)
            {
                renderElement.TriCount = batch.IndexCount / 3;
            }

            {
                var matrix = m_worldMatrix;
                matrix.Right    = (Vector3D)m_offset;
                matrix.Up       = (Vector3D)m_scale;
                matrix.Backward = MyRenderCamera.Position - m_worldMatrix.Translation;
                Vector2 lodBounds;
                MyClipmap.ComputeLodViewBounds(m_scaleGroup, m_coord.Lod, out lodBounds.X, out lodBounds.Y);
                matrix.M14 = lodBounds.X;
                matrix.M24 = lodBounds.Y;
                matrix.M34 = MathHelper.Clamp(MyClipmap.DebugClipmapMostDetailedLod - m_coord.Lod, 0f, 1f);
                renderElement.WorldMatrix = matrix;
            }
            renderElement.VoxelBatch = batch;
        }
Ejemplo n.º 2
0
        private unsafe void AddBatch(MyClipmapCellBatch batch)
        {
            //  This will just preload textures used by this material - so they are ready in memory when first time drawn
            MyRenderVoxelMaterials.Get((byte)batch.Material0).GetTextures();

            MyRenderVoxelBatch newBatch  = new MyRenderVoxelBatch();
            string             debugName = "VoxelBatchSingle";

            newBatch.Type      = MyRenderVoxelBatchType.SINGLE_MATERIAL;
            newBatch.Lod       = m_metadata.Cell.Lod;
            newBatch.Material0 = (byte)batch.Material0;
            newBatch.Material1 = batch.Material1 == -1 ? (byte?)null : (byte)batch.Material1;
            newBatch.Material2 = batch.Material2 == -1 ? (byte?)null : (byte)batch.Material2;
            if (newBatch.Material1 != null || newBatch.Material2 != null)
            {
                newBatch.Type = MyRenderVoxelBatchType.MULTI_MATERIAL;
                debugName     = "VoxelBatchMulti";
            }


            //  Vertex buffer
            int vbSize = sizeof(MyVertexFormatVoxelSingleData) * batch.Vertices.Length;

            newBatch.VertexCount = batch.Vertices.Length;

            // When Usage.Dynamic was not there, it crashed on nVidia cards
            newBatch.VertexBuffer = new VertexBuffer(MyRender.GraphicsDevice, vbSize, Usage.WriteOnly | Usage.Dynamic, VertexFormat.None, Pool.Default);
            newBatch.VertexBuffer.SetData(batch.Vertices, LockFlags.Discard);
            newBatch.VertexBuffer.Tag       = newBatch;
            newBatch.VertexBuffer.DebugName = debugName;
            MyPerformanceCounter.PerAppLifetime.VoxelVertexBuffersSize += vbSize;

            //  Index buffer
            int ibSize = sizeof(short) * batch.Indices.Length;

            newBatch.IndexCount = batch.Indices.Length;

            // When Usage.Dynamic was not there, it crashed on nVidia cards
            newBatch.IndexBuffer = new IndexBuffer(MyRender.GraphicsDevice, ibSize, Usage.WriteOnly | Usage.Dynamic, Pool.Default, true);
            newBatch.IndexBuffer.SetData(batch.Indices, LockFlags.Discard);
            newBatch.IndexBuffer.DebugName = debugName;
            MyPerformanceCounter.PerAppLifetime.VoxelIndexBuffersSize += ibSize;


            newBatch.UpdateSortOrder();

            m_batches.Add(newBatch);
        }
Ejemplo n.º 3
0
        private void SetupRenderElement(MyRenderVoxelBatch batch, MyRender.MyRenderElement renderElement)
        {
            renderElement.RenderObject = this;

            renderElement.VertexDeclaration = MyVertexFormatVoxelSingleMaterial.VertexDeclaration;
            renderElement.VertexStride      = MyVertexFormatVoxelSingleMaterial.Stride;
            renderElement.VertexCount       = batch.VertexCount;
            renderElement.VertexBuffer      = batch.VertexBuffer;

            renderElement.InstanceBuffer = null;

            renderElement.IndexBuffer = batch.IndexBuffer;
            renderElement.IndexStart  = 0;
            if (renderElement.IndexBuffer != null)
            {
                renderElement.TriCount = batch.IndexCount / 3;
            }
            renderElement.WorldMatrix              = m_worldMatrix;
            renderElement.WorldMatrix.Translation += m_metadata.PositionOffset;
            renderElement.VoxelBatch = batch;
        }
Ejemplo n.º 4
0
        private unsafe void AddBatch(MyClipmapCellBatch batch)
        {
            //  This will just preload textures used by this material - so they are ready in memory when first time drawn
            MyRenderVoxelMaterials.Get((byte)batch.Material0).GetTextures();

            MyRenderVoxelBatch newBatch = new MyRenderVoxelBatch();
            string debugName = "VoxelBatchSingle";

            newBatch.Type = MyRenderVoxelBatchType.SINGLE_MATERIAL;
            newBatch.Lod = m_coord.Lod;
            newBatch.Material0 = (byte)batch.Material0;
            newBatch.Material1 = batch.Material1 == -1 ? (byte?)null : (byte)batch.Material1;
            newBatch.Material2 = batch.Material2 == -1 ? (byte?)null : (byte)batch.Material2;
            if (newBatch.Material1 != null || newBatch.Material2 != null)
            {
                newBatch.Type = MyRenderVoxelBatchType.MULTI_MATERIAL;
                debugName = "VoxelBatchMulti";
            }


            //  Vertex buffer
            int vbSize = sizeof(MyVertexFormatVoxelSingleData) * batch.Vertices.Length;
            newBatch.VertexCount = batch.Vertices.Length;

            // When Usage.Dynamic was not there, it crashed on nVidia cards
            newBatch.VertexBuffer = new VertexBuffer(MyRender.GraphicsDevice, vbSize, Usage.WriteOnly | Usage.Dynamic, VertexFormat.None, Pool.Default);
            newBatch.VertexBuffer.SetData(batch.Vertices, LockFlags.Discard);
            newBatch.VertexBuffer.Tag = newBatch;
            newBatch.VertexBuffer.DebugName = debugName;
            MyPerformanceCounter.PerAppLifetime.VoxelVertexBuffersSize += vbSize;

            //  Index buffer
            int ibSize = sizeof(short) * batch.Indices.Length;
            newBatch.IndexCount = batch.Indices.Length;

            // When Usage.Dynamic was not there, it crashed on nVidia cards
            newBatch.IndexBuffer = new IndexBuffer(MyRender.GraphicsDevice, ibSize, Usage.WriteOnly | Usage.Dynamic, Pool.Default, true);
            newBatch.IndexBuffer.SetData(batch.Indices, LockFlags.Discard);
            newBatch.IndexBuffer.DebugName = debugName;
            MyPerformanceCounter.PerAppLifetime.VoxelIndexBuffersSize += ibSize;


            newBatch.UpdateSortOrder();

            m_batches.Add(newBatch);
        }
Ejemplo n.º 5
0
        private void SetupRenderElement(MyRenderVoxelBatch batch, MyRender.MyRenderElement renderElement)
        {
            renderElement.RenderObject = this;

            renderElement.VertexDeclaration = MyVertexFormatVoxelSingleMaterial.VertexDeclaration;
            renderElement.VertexStride = MyVertexFormatVoxelSingleMaterial.Stride;
            renderElement.VertexCount = batch.VertexCount;
            renderElement.VertexBuffer = batch.VertexBuffer;

            renderElement.InstanceBuffer = null;

            renderElement.IndexBuffer = batch.IndexBuffer;
            renderElement.IndexStart = 0;
            if (renderElement.IndexBuffer != null)
            {
                renderElement.TriCount = batch.IndexCount / 3;
            }
            renderElement.WorldMatrix = m_worldMatrix;
            renderElement.WorldMatrix.Translation += m_cellOffset;
            renderElement.VoxelBatch = batch;
        }
Ejemplo n.º 6
0
        //  For sorting batches by type and material
        //  We want first multi-clear, then single-material and multi-material as last
        public int CompareTo(object compareToObject)
        {
            MyRenderVoxelBatch compareToBatch = (MyRenderVoxelBatch)compareToObject;

            return(this.SortOrder.CompareTo(compareToBatch.SortOrder));
        }
        private void SetupRenderElement(MyRenderVoxelBatch batch, MyRender.MyRenderElement renderElement)
        {
            renderElement.RenderObject = this;

            renderElement.VertexDeclaration = MyVertexFormatVoxelSingleMaterial.VertexDeclaration;
            renderElement.VertexStride = MyVertexFormatVoxelSingleMaterial.Stride;
            renderElement.VertexCount = batch.VertexCount;
            renderElement.VertexBuffer = batch.VertexBuffer;

            renderElement.InstanceBuffer = null;

            renderElement.IndexBuffer = batch.IndexBuffer;
            renderElement.IndexStart = 0;
            if (renderElement.IndexBuffer != null)
            {
                renderElement.TriCount = batch.IndexCount / 3;
            }

            {
                var matrix = m_worldMatrix;
                matrix.Right = (Vector3D)m_offset;
                matrix.Up = (Vector3D)m_scale;
                matrix.Backward = MyRenderCamera.Position - m_worldMatrix.Translation;
                Vector2 lodBounds;
                MyClipmap.ComputeLodViewBounds(m_scaleGroup, m_coord.Lod, out lodBounds.X, out lodBounds.Y);
                matrix.M14 = lodBounds.X;
                matrix.M24 = lodBounds.Y;
                matrix.M34 = MathHelper.Clamp(MyClipmap.DebugClipmapMostDetailedLod - m_coord.Lod, 0f, 1f);
                renderElement.WorldMatrix = matrix;
            }
            renderElement.VoxelBatch = batch;
        }