/// <summary>
        /// Test <see cref="ArrayBufferObject.Create(GraphicsContext, Array)"/>.
        /// </summary>
        private void CreateCtxArray_Core()
        {
            ArrayBufferObjectBase arrayBufferRef = null;

            using (ArrayBufferObjectBase arrayBuffer = CreateInstance()) {
                ConstructionDefaulValues(arrayBuffer);

                // Create GPU memory
                Assert.IsFalse(arrayBuffer.Exists(_Context));
                arrayBuffer.Create(_Context, new float[16]);

                // Now exists
                Assert.IsTrue(arrayBuffer.Exists(_Context));
                // ItemCount reflect the GPU buffer size
                Assert.AreEqual(16, arrayBuffer.ItemCount);

                // We should be able to issue a new buffer
                arrayBuffer.Create(_Context, new float[32]);
                Assert.IsTrue(arrayBuffer.Exists(_Context));
                // ItemCount reflect the GPU buffer size
                Assert.AreEqual(32, arrayBuffer.ItemCount);
                // ItemCount reflect the GPU buffer size
                Assert.AreEqual(32 * arrayBuffer.ItemSize, arrayBuffer.BufferSize);

                // Test after disposition
                arrayBufferRef = arrayBuffer;
            }

            if (arrayBufferRef != null)
            {
                DispositionDefaulValues(arrayBufferRef);
            }
        }
        /// <summary>
        /// Test <see cref="ArrayBufferObject.Create(uint)"/>.
        /// </summary>
        private void CreateArray_Core()
        {
            Array testArray = CreateTestArray();

            ArrayBufferObjectBase arrayBufferRef = null;

            using (ArrayBufferObjectBase arrayBuffer = CreateInstance()) {
                ConstructionDefaulValues(arrayBuffer);

                // Create client memory
                Assert.IsFalse(arrayBuffer.Exists(_Context));
                arrayBuffer.Create(testArray);

                // Still not existing
                Assert.IsFalse(arrayBuffer.Exists(_Context));
                // ItemCount reflect client buffer size
                Assert.AreEqual((uint)testArray.Length, arrayBuffer.ItemCount);

                // Actually define GPU buffer
                arrayBuffer.Create(_Context);

                // Now exists
                Assert.IsTrue(arrayBuffer.Exists(_Context));
                // ItemCount reflect the GPU buffer size
                Assert.AreEqual((uint)testArray.Length, arrayBuffer.ItemCount);

                // Test after disposition
                arrayBufferRef = arrayBuffer;
            }

            if (arrayBufferRef != null)
            {
                DispositionDefaulValues(arrayBufferRef);
            }
        }
Example #3
0
 /// <summary>
 /// Allocate resources used by this vertex array.
 /// </summary>
 /// <param name="ctx">
 /// The <see cref="GraphicsContext"/> used for rendering.
 /// </param>
 public void Create(GraphicsContext ctx)
 {
     if (ArrayBuffer.Exists(ctx) == false)
     {
         ArrayBuffer.Create(ctx);
     }
 }
        public void CreateCtxArray_Exception2()
        {
            _Context.MakeCurrent(false);

            using (ArrayBufferObjectBase arrayBuffer = CreateInstance()) {
                arrayBuffer.Create(_Context, 0);
            }
        }
Example #5
0
        /// <summary>
        /// Test <see cref="ArrayBufferObject.Create(GraphicsContext, uint)"/>.
        /// </summary>
        private void CreateCtxCount_Core()
        {
            const uint TestItemCount = 16;

            ArrayBufferObjectBase arrayBufferRef = null;

            using (ArrayBufferObjectBase arrayBuffer = CreateInstance())
            {
                ConstructionDefaulValues(arrayBuffer);

                // Create GPU memory
                Assert.IsFalse(arrayBuffer.Exists(_Context));
                arrayBuffer.Create(_Context, TestItemCount);

                // Now exists
                Assert.IsTrue(arrayBuffer.Exists(_Context));
                // ItemCount reflect the GPU buffer size
                Assert.AreEqual(TestItemCount, arrayBuffer.ItemCount);
                // ClientItemCount can be 0 (client buffer disposed) or ItemCount
                Assert.IsTrue(arrayBuffer.ClientItemCount == 0 || arrayBuffer.ClientItemCount == arrayBuffer.ItemCount);

                // We should be able to issue a new buffer
                arrayBuffer.Create(_Context, TestItemCount * 2);
                Assert.IsTrue(arrayBuffer.Exists(_Context));
                // ItemCount reflect the GPU buffer size
                Assert.AreEqual(TestItemCount * 2, arrayBuffer.ItemCount);
                // ClientItemCount can be 0 (client buffer disposed) or ItemCount
                Assert.IsTrue(arrayBuffer.ClientItemCount == 0 || arrayBuffer.ClientItemCount == arrayBuffer.ItemCount);

                // Test after disposition
                arrayBufferRef = arrayBuffer;
            }

            if (arrayBufferRef != null)
            {
                Assert.AreEqual(0, arrayBufferRef.ItemCount);
                Assert.AreEqual(0, arrayBufferRef.ClientItemCount);
            }
        }
 public void CreateCtxArray_Exception3()
 {
     using (ArrayBufferObjectBase arrayBuffer = CreateInstance()) {
         arrayBuffer.Create(_Context, 0);
     }
 }
 public void CreateCtxArray_Exception1()
 {
     using (ArrayBufferObjectBase arrayBuffer = CreateInstance()) {
         arrayBuffer.Create((GraphicsContext)null, 0);
     }
 }
 public void CreateCount_Exception1()
 {
     using (ArrayBufferObjectBase arrayBuffer = CreateInstance()) {
         arrayBuffer.Create(0);
     }
 }
        /// <summary>
        /// Test <see cref="ArrayBufferObject.Create(uint)"/>.
        /// </summary>
        private void CreateCount_Core()
        {
            const uint TestItemCount = 16;

            ArrayBufferObjectBase arrayBufferRef = null;

            using (ArrayBufferObjectBase arrayBuffer = CreateInstance()) {
                ConstructionDefaulValues(arrayBuffer);

                // Create client buffer
                Assert.IsFalse(arrayBuffer.Exists(_Context));
                arrayBuffer.Create(TestItemCount);

                // Still not existing
                Assert.IsFalse(arrayBuffer.Exists(_Context));
                // ItemCount reflect client buffer size
                Assert.AreEqual(TestItemCount, arrayBuffer.ItemCount);
                Assert.AreEqual(TestItemCount, arrayBuffer.ClientItemCount);

                // Actually define GPU buffer
                arrayBuffer.Create(_Context);

                // Now exists
                Assert.IsTrue(arrayBuffer.Exists(_Context));
                // ItemCount reflect the GPU buffer size
                Assert.AreEqual(TestItemCount, arrayBuffer.ItemCount);
                // ClientItemCount can be 0 (client buffer disposed) or ItemCount
                Assert.IsTrue(arrayBuffer.ClientItemCount == 0 || arrayBuffer.ClientItemCount == arrayBuffer.ItemCount);

                // Define a new client buffer, different from previous
                arrayBuffer.Create(TestItemCount * 2);

                // Still exists
                Assert.IsTrue(arrayBuffer.Exists(_Context));
                // GPU buffer item count hasn't changed
                Assert.AreEqual(TestItemCount, arrayBuffer.ItemCount);
                // Client buffer item count respect the last request
                Assert.AreEqual(TestItemCount * 2, arrayBuffer.ClientItemCount);

                // Actually update GPU buffer
                uint prevObjectName = arrayBuffer.ObjectName;

                arrayBuffer.Create(_Context);
                // Still exists
                Assert.IsTrue(arrayBuffer.Exists(_Context));
                // No new object has been created
                Assert.AreEqual(prevObjectName, arrayBuffer.ObjectName);
                // GPU buffer item count has been updated
                Assert.AreEqual(TestItemCount * 2, arrayBuffer.ItemCount);
                // ClientItemCount can be 0 (client buffer disposed) or ItemCount
                Assert.IsTrue(arrayBuffer.ClientItemCount == 0 || arrayBuffer.ClientItemCount == arrayBuffer.ItemCount);

                // Test after disposition
                arrayBufferRef = arrayBuffer;
            }

            if (arrayBufferRef != null)
            {
                DispositionDefaulValues(arrayBufferRef);
            }
        }