コード例 #1
0
 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);
     }
 }
コード例 #2
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;
     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);
     }
 }
コード例 #6
0
 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);
     }
 }
コード例 #7
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();
     }
 }
コード例 #10
0
 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);
     }
 }
コード例 #11
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();
     }
 }
コード例 #14
0
 /// <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;
                }
            }
        }
コード例 #16
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)
        {
            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)
 {
 }
コード例 #21
0
 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);
     }
 }
コード例 #24
0
 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);
     }
 }
コード例 #26
0
 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)
 {
 }
コード例 #28
0
 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);
 }