protected override void OnCreateVertexBuffer(DeviceContextProxy context, IElementsBufferProxy buffer, int bufferIndex, Geometry3D geometry, IDeviceResources deviceResources)
 {
     if (bufferIndex == 0 && geometry != null && geometry.Positions != null && geometry.Positions.Count > 0)
     {
         buffer.UploadDataToBuffer(context, geometry.Positions, geometry.Positions.Count);
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GeometryBufferModel"/> class.
 /// </summary>
 /// <param name="topology">The topology.</param>
 /// <param name="vertexBuffer">The vertex buffer.</param>
 /// <param name="indexBuffer">The index buffer.</param>
 protected GeometryBufferModel(PrimitiveTopology topology, IElementsBufferProxy vertexBuffer, IElementsBufferProxy indexBuffer)
 {
     Topology           = topology;
     this.vertexBuffers = vertexBuffer != null ? new IElementsBufferProxy[] { vertexBuffer } : emptyBuffers;
     VertexChanged      = 1u;
     this.indexBuffer   = indexBuffer;
 }
示例#3
0
 /// <summary>
 /// Called when [create vertex buffer].
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="buffer">The buffer.</param>
 /// <param name="geometry">The geometry.</param>
 /// <param name="deviceResources">The device resources.</param>
 /// <param name="bufferIndex"></param>
 protected override void OnCreateVertexBuffer(DeviceContextProxy context, IElementsBufferProxy buffer, int bufferIndex, Geometry3D geometry, IDeviceResources deviceResources)
 {
     if (geometry is IBillboardText billboardGeometry)
     {
         billboardGeometry.DrawTexture(deviceResources);
         if (billboardGeometry.BillboardVertices != null && billboardGeometry.BillboardVertices.Count > 0)
         {
             Type = billboardGeometry.Type;
             buffer.UploadDataToBuffer(context, billboardGeometry.BillboardVertices, billboardGeometry.BillboardVertices.Count, 0, geometry.PreDefinedVertexCount);
             if (textureStream != billboardGeometry.Texture)
             {
                 RemoveAndDispose(ref textureView);
                 textureStream = billboardGeometry.Texture;
                 if (textureStream != null)
                 {
                     textureView = Collect(deviceResources.MaterialTextureManager.Register(textureStream));
                 }
             }
         }
         else
         {
             RemoveAndDispose(ref textureView);
             textureStream = null;
             buffer.UploadDataToBuffer(context, emptyVerts, 0);
         }
     }
 }
示例#4
0
 public StaticGeometryBatchingBufferBase(PrimitiveTopology topology, IElementsBufferProxy vertexBuffer, IElementsBufferProxy indexBuffer)
 {
     Topology     = topology;
     VertexBuffer = new IElementsBufferProxy[] { Collect(vertexBuffer) };
     if (indexBuffer != null)
     {
         IndexBuffer = Collect(indexBuffer);
     }
 }
示例#5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GeometryBufferModel"/> class.
 /// </summary>
 /// <param name="topology">The topology.</param>
 /// <param name="vertexBuffer">The vertex buffer.</param>
 /// <param name="indexBuffer">The index buffer.</param>
 protected GeometryBufferModel(PrimitiveTopology topology, IElementsBufferProxy vertexBuffer, IElementsBufferProxy indexBuffer)
 {
     Topology      = topology;
     VertexBuffer  = new IElementsBufferProxy[] { Collect(vertexBuffer) };
     VertexChanged = 1u;
     if (indexBuffer != null)
     {
         IndexBuffer = Collect(indexBuffer);
     }
 }
 public static void DrawIndexed(DeviceContextProxy context, IElementsBufferProxy indexBuffer, IElementsBufferModel instanceModel)
 {
     if (instanceModel == null || !instanceModel.HasElements)
     {
         context.DrawIndexed(indexBuffer.ElementCount, 0, 0);
     }
     else
     {
         context.DrawIndexedInstanced(indexBuffer.ElementCount, instanceModel.Buffer.ElementCount, 0, 0, 0);
     }
 }
 /// <summary>
 /// Called when [create index buffer].
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="buffer">The buffer.</param>
 /// <param name="geometry">The geometry.</param>
 /// <param name="deviceResources">The device resources.</param>
 protected override void OnCreateIndexBuffer(DeviceContextProxy context, IElementsBufferProxy buffer, Geometry3D geometry, IDeviceResources deviceResources)
 {
     if (geometry != null && geometry.Indices != null && geometry.Indices.Count > 0)
     {
         buffer.UploadDataToBuffer(context, geometry.Indices, geometry.Indices.Count, 0, geometry.PreDefinedIndexCount);
     }
     else
     {
         buffer.UploadDataToBuffer(context, emptyIndices, 0);
     }
 }
示例#8
0
 public static void DrawPoints(DeviceContextProxy context, IElementsBufferProxy vertexBuffer, IElementsBufferModel instanceModel)
 {
     if (!instanceModel.HasElements)
     {
         context.Draw(vertexBuffer.ElementCount, 0);
     }
     else
     {
         context.DrawInstanced(vertexBuffer.ElementCount, instanceModel.Buffer.ElementCount, 0, 0);
     }
 }
示例#9
0
 /// <summary>
 /// Called when [create index buffer].
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="buffer">The buffer.</param>
 /// <param name="geometry">The geometry.</param>
 /// <param name="deviceResources">The device resources.</param>
 protected override void OnCreateIndexBuffer(DeviceContextProxy context, IElementsBufferProxy buffer, Geometry3D geometry, IDeviceResources deviceResources)
 {
     if (geometry != null && geometry.Indices != null && geometry.Indices.Count > 0)
     {
         buffer.UploadDataToBuffer(context, geometry.Indices, geometry.Indices.Count);
     }
     else
     {
         buffer.DisposeAndClear();
     }
 }
 protected override void OnCreateVertexBuffer(DeviceContextProxy context, IElementsBufferProxy buffer, int bufferIndex, Geometry3D geometry, IDeviceResources deviceResources)
 {
     // -- set geometry if given
     if (geometry != null && geometry.Positions != null && geometry.Positions.Count > 0)
     {
         buffer.UploadDataToBuffer(context, geometry.Positions, geometry.Positions.Count);
     }
     else
     {
         buffer.UploadDataToBuffer(context, emptyVerts, 0);
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GeometryBufferModel"/> class.
 /// </summary>
 /// <param name="topology">The topology.</param>
 /// <param name="vertexBuffer">The vertex buffer.</param>
 /// <param name="indexBuffer">The index buffer.</param>
 protected GeometryBufferModel(PrimitiveTopology topology, IElementsBufferProxy[] vertexBuffer, IElementsBufferProxy indexBuffer)
 {
     Topology = topology;
     if (vertexBuffer != null)
     {
         for (var i = 0; i < vertexBuffer.Length; ++i)
         {
             VertexChanged |= 1u << i;
         }
         this.vertexBuffers = vertexBuffer;
     }
     this.indexBuffer = indexBuffer;
 }
示例#12
0
 /// <summary>
 /// Called when [create vertex buffer].
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="buffer">The buffer.</param>
 /// <param name="geometry">The geometry.</param>
 /// <param name="deviceResources">The device resources.</param>
 /// <param name="bufferIndex"></param>
 protected override void OnCreateVertexBuffer(DeviceContextProxy context, IElementsBufferProxy buffer, int bufferIndex, Geometry3D geometry, IDeviceResources deviceResources)
 {
     // -- set geometry if given
     if (geometry != null && geometry.Positions != null && geometry.Positions.Count > 0)
     {
         // --- get geometry
         var data = OnBuildVertexArray(geometry);
         buffer.UploadDataToBuffer(context, data, geometry.Positions.Count, 0, geometry.PreDefinedVertexCount);
     }
     else
     {
         buffer.UploadDataToBuffer(context, emptyVerts, 0);
     }
 }
示例#13
0
 /// <summary>
 /// Called when [create vertex buffer].
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="buffer">The buffer.</param>
 /// <param name="geometry">The geometry.</param>
 /// <param name="deviceResources">The device resources.</param>
 /// <param name="bufferIndex"></param>
 protected override void OnCreateVertexBuffer(DeviceContextProxy context, IElementsBufferProxy buffer, int bufferIndex, Geometry3D geometry, IDeviceResources deviceResources)
 {
     // -- set geometry if given
     if (geometry != null && geometry.Positions != null && geometry.Positions.Count > 0)
     {
         // --- get geometry
         var mesh = geometry as LineGeometry3D;
         var data = OnBuildVertexArray(mesh);
         buffer.UploadDataToBuffer(context, data, geometry.Positions.Count);
     }
     else
     {
         buffer.DisposeAndClear();
     }
 }
 /// <summary>
 /// Releases unmanaged and - optionally - managed resources.
 /// </summary>
 /// <param name="disposeManagedResources"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
 protected override void OnDispose(bool disposeManagedResources)
 {
     if (geometry != null)
     {
         geometry.PropertyChanged -= Geometry_PropertyChanged;
     }
     geometry = null;
     for (var i = 0; i < vertexBuffers.Length; ++i)
     {
         RemoveAndDispose(vertexBuffers[i]);
     }
     vertexBuffers = emptyBuffers;
     RemoveAndDispose(indexBuffer);
     indexBuffer          = null;
     VertexBufferBindings = emptyBinding;
     base.OnDispose(disposeManagedResources);
 }
示例#15
0
        /// <summary>
        /// Called when [create vertex buffer].
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="buffer">The buffer.</param>
        /// <param name="bufferIndex">Index of the buffer.</param>
        /// <param name="geometry">The geometry.</param>
        /// <param name="deviceResources">The device resources.</param>
        protected override void OnCreateVertexBuffer(DeviceContextProxy context, IElementsBufferProxy buffer, int bufferIndex, Geometry3D geometry, IDeviceResources deviceResources)
        {
            if (geometry is MeshGeometry3D mesh)
            {
                switch (bufferIndex)
                {
                case 0:
                    // -- set geometry if given
                    if (geometry.Positions != null && geometry.Positions.Count > 0)
                    {
                        // --- get geometry
                        var data = BuildVertexArray(mesh);
                        buffer.UploadDataToBuffer(context, data, geometry.Positions.Count, 0, geometry.PreDefinedVertexCount);
                    }
                    else
                    {
                        //buffer.DisposeAndClear();
                        buffer.UploadDataToBuffer(context, emptyVerts, 0);
                    }
                    break;

                case 1:
                    if (mesh.TextureCoordinates != null && mesh.TextureCoordinates.Count > 0)
                    {
                        buffer.UploadDataToBuffer(context, mesh.TextureCoordinates, mesh.TextureCoordinates.Count, 0, geometry.PreDefinedVertexCount);
                    }
                    else
                    {
                        buffer.UploadDataToBuffer(context, emptyTextureArray, 0);
                    }
                    break;

                case 2:
                    if (geometry.Colors != null && geometry.Colors.Count > 0)
                    {
                        buffer.UploadDataToBuffer(context, geometry.Colors, geometry.Colors.Count, 0, geometry.PreDefinedVertexCount);
                    }
                    else
                    {
                        buffer.UploadDataToBuffer(context, emptyColorArray, 0);
                    }
                    break;
                }
            }
        }
        /// <summary>
        /// Called when [create vertex buffer].
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="buffer">The buffer.</param>
        /// <param name="geometry">The geometry.</param>
        /// <param name="deviceResources">The device resources.</param>
        /// <param name="bufferIndex"></param>
        protected override void OnCreateVertexBuffer(DeviceContextProxy context, IElementsBufferProxy buffer, int bufferIndex, Geometry3D geometry, IDeviceResources deviceResources)
        {
            var billboardGeometry = geometry as IBillboardText;

            billboardGeometry.DrawTexture(deviceResources);
            if (billboardGeometry != null && billboardGeometry.BillboardVertices != null && billboardGeometry.BillboardVertices.Count > 0)
            {
                Type = billboardGeometry.Type;
                var data = OnBuildVertexArray(billboardGeometry, deviceResources);
                buffer.UploadDataToBuffer(context, data, billboardGeometry.BillboardVertices.Count);
                RemoveAndDispose(ref textureView);
                if (billboardGeometry.Texture != null)
                {
                    textureView = Collect(deviceResources.MaterialTextureManager.Register(billboardGeometry.Texture));
                }
            }
            else
            {
                textureView = null;
                buffer.DisposeAndClear();
            }
        }
示例#17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LineGeometryBufferModel{VertexStruct}"/> class.
 /// </summary>
 /// <param name="vertexBuffer"></param>
 /// <param name="dynamic">Create dynamic buffer or immutable buffer</param>
 public LineGeometryBufferModel(IElementsBufferProxy vertexBuffer, bool dynamic = false)
     : base(PrimitiveTopology.LineList,
            vertexBuffer,
            dynamic ? new DynamicBufferProxy(sizeof(int), BindFlags.IndexBuffer) : new ImmutableBufferProxy(sizeof(int), BindFlags.IndexBuffer) as IElementsBufferProxy)
 {
 }
示例#18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LineGeometryBufferModel{VertexStruct}"/> class.
 /// </summary>
 /// <param name="vertexBuffer"></param>
 public LineGeometryBufferModel(IElementsBufferProxy vertexBuffer) : base(PrimitiveTopology.LineList,
                                                                          vertexBuffer, new ImmutableBufferProxy(sizeof(int), BindFlags.IndexBuffer))
 {
 }
示例#19
0
 /// <summary>
 /// Called when [create index buffer].
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="buffer">The buffer.</param>
 /// <param name="geometry">The geometry.</param>
 /// <param name="deviceResources">The device resources.</param>
 protected override void OnCreateIndexBuffer(DeviceContext context, IElementsBufferProxy buffer, Geometry3D geometry, IDeviceResources deviceResources)
 {
 }
示例#20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PointGeometryBufferModel{VertexStruct}"/> class.
 /// </summary>
 /// <param name="vertexBuffer"></param>
 public PointGeometryBufferModel(IElementsBufferProxy vertexBuffer) : base(PrimitiveTopology.PointList,
                                                                           vertexBuffer, null)
 {
 }
 public BoneSkinnedMeshBufferModel()
 {
     boneIdBuffer = new ImmutableBufferProxy(BoneIds.SizeInBytes, BindFlags.VertexBuffer, ResourceOptionFlags.None);
 }
示例#22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LineGeometryBufferModel{VertexStruct}"/> class.
 /// </summary>
 /// <param name="vertexBuffer"></param>
 /// <param name="indexBuffer"></param>
 public LineGeometryBufferModel(IElementsBufferProxy[] vertexBuffer, IElementsBufferProxy indexBuffer)
     : base(PrimitiveTopology.LineList,
            vertexBuffer, indexBuffer)
 {
 }
示例#23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GeometryBufferModel"/> class.
 /// </summary>
 /// <param name="topology">The topology.</param>
 /// <param name="vertexBuffer">The vertex buffer.</param>
 /// <param name="indexBuffer">The index buffer.</param>
 protected GeometryBufferModel(PrimitiveTopology topology, IElementsBufferProxy[] vertexBuffer, IElementsBufferProxy indexBuffer)
 {
     Topology = topology;
     foreach (var buffer in vertexBuffer)
     {
         Collect(buffer);
     }
     VertexChanged = Enumerable.Repeat <bool>(true, vertexBuffer.Length).ToArray();
     VertexBuffer  = vertexBuffer;
     if (indexBuffer != null)
     {
         IndexBuffer = Collect(indexBuffer);
     }
 }
 public StaticGeometryBatchingBufferBase(PrimitiveTopology topology, IElementsBufferProxy vertexBuffer, IElementsBufferProxy indexBuffer)
 {
     Topology         = topology;
     vertexBuffers    = new IElementsBufferProxy[] { vertexBuffer };
     this.indexBuffer = indexBuffer;
 }
示例#25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GeometryBufferModel"/> class.
 /// </summary>
 /// <param name="topology">The topology.</param>
 /// <param name="vertexBuffer">The vertex buffer.</param>
 /// <param name="indexBuffer">The index buffer.</param>
 protected GeometryBufferModel(PrimitiveTopology topology, IElementsBufferProxy[] vertexBuffer, IElementsBufferProxy indexBuffer)
 {
     Topology = topology;
     for (int i = 0; i < vertexBuffer.Length; ++i)
     {
         Collect(vertexBuffer[i]);
         VertexChanged |= 1u << i;
     }
     VertexBuffer = vertexBuffer;
     if (indexBuffer != null)
     {
         IndexBuffer = Collect(indexBuffer);
     }
 }
 public DefaultStaticMeshBatchingBuffer(PrimitiveTopology topology, IElementsBufferProxy vertexBuffer, IElementsBufferProxy indexBuffer)
     : base(topology, vertexBuffer, indexBuffer)
 {
 }
示例#27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MeshGeometryBufferModel{VertexStruct}"/> class.
 /// </summary>
 /// <param name="topology">The topology.</param>
 /// <param name="vertexBuffer">The vertex buffer.</param>
 /// <param name="indexBuffer">The index buffer.</param>
 protected MeshGeometryBufferModel(PrimitiveTopology topology, IElementsBufferProxy[] vertexBuffer, IElementsBufferProxy indexBuffer)
     : base(topology, vertexBuffer, indexBuffer)
 {
 }
 public void Initialize()
 {
     elementBuffer   = Collect(new DynamicBufferProxy(StructSize, BindFlags.VertexBuffer));
     Initialized     = true;
     instanceChanged = true;
 }
示例#29
0
 /// <summary>
 /// Called when [create index buffer].
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="buffer">The buffer.</param>
 /// <param name="geometry">The geometry.</param>
 /// <param name="deviceResources">The device resources.</param>
 protected abstract void OnCreateIndexBuffer(DeviceContextProxy context, IElementsBufferProxy buffer, Geometry3D geometry, IDeviceResources deviceResources);
示例#30
0
 public Sprite2DBufferModel()
 {
     vertextBuffer   = new DynamicBufferProxy(SpriteStruct.SizeInBytes, BindFlags.VertexBuffer);
     VertexBuffer[0] = vertextBuffer;
     indexBuffer     = new DynamicBufferProxy(sizeof(int), BindFlags.IndexBuffer);
 }