Exemplo n.º 1
0
        public void TestEquals()
        {
            Vector2H a = new Vector2H(1.0f, 2.0f);
            Vector2H b = new Vector2H(4.0f, 5.0f);
            Vector2H c = new Vector2H(1.0f, 2.0f);

            Assert.IsTrue(a.Equals(c));
            Assert.IsTrue(c.Equals(a));
            Assert.IsTrue(a == c);
            Assert.IsTrue(c == a);
            Assert.IsFalse(c != a);
            Assert.IsFalse(c != a);
            Assert.IsFalse(a.Equals(b));
            Assert.IsFalse(b.Equals(a));
            Assert.IsFalse(a == b);
            Assert.IsFalse(b == a);
            Assert.IsTrue(a != b);
            Assert.IsTrue(b != a);

            object objA = a;
            object objB = b;
            object objC = c;

            Assert.IsTrue(a.Equals(objA));
            Assert.IsTrue(a.Equals(objC));
            Assert.IsFalse(a.Equals(objB));

            Assert.IsTrue(objA.Equals(objC));
            Assert.IsFalse(objA.Equals(objB));

            Assert.IsFalse(a.Equals(null));
            Assert.IsFalse(a.Equals(5));
        }
Exemplo n.º 2
0
        public void Construct()
        {
            Vector2H v1 = new Vector2H(1.0f, 2.0f);
            Assert.AreEqual((Half)1.0f, v1.X);
            Assert.AreEqual((Half)2.0f, v1.Y);

            Vector2H v2 = new Vector2H(1.0, 2.0);
            Assert.AreEqual((Half)1.0, v2.X);
            Assert.AreEqual((Half)2.0, v2.Y);
        }
Exemplo n.º 3
0
        private void UpdateAll(Context context)
        {
            //
            // Since billboards were added or removed, all billboards are
            // rewritten so dirty billboards are automatically cleaned.
            //
            _dirtyBillboards.Clear();

            //
            // Create vertex array with appropriately sized vertex buffers
            //
            DisposeVertexArray();

            if (_billboards.Count != 0)
            {
                CreateVertexArray(context);

                //
                // Write vertex buffers
                //
                Vector3F[]      positions          = new Vector3F[_billboards.Count];
                Vector4H[]      textureCoordinates = new Vector4H[_billboards.Count];
                BlittableRGBA[] colors             = new BlittableRGBA[_billboards.Count];
                byte[]          origins            = new byte[_billboards.Count];
                Vector2H[]      pixelOffets        = new Vector2H[_billboards.Count];

                for (int i = 0; i < _billboards.Count; ++i)
                {
                    Billboard b = _billboards[i];

                    positions[i]          = b.Position.ToVector3F();
                    textureCoordinates[i] = new Vector4H(
                        b.TextureCoordinates.LowerLeft.X, b.TextureCoordinates.LowerLeft.Y,
                        b.TextureCoordinates.UpperRight.X, b.TextureCoordinates.UpperRight.Y);
                    colors[i]      = new BlittableRGBA(b.Color);
                    origins[i]     = BillboardOrigin(b);
                    pixelOffets[i] = b.PixelOffset;

                    b.VertexBufferOffset = i;
                    b.Dirty = false;
                }
                CopyBillboardsFromSystemMemory(positions, textureCoordinates, colors, origins, pixelOffets, 0, _billboards.Count);

                _rewriteBillboards = false;
            }
        }
Exemplo n.º 4
0
        internal void Update(Context context, ShaderProgram sp)
        {
            if (_va == null)
            {
                VertexBufferAttribute positionAttribute = new VertexBufferAttribute(
                    _positionBuffer, ComponentDatatype.Float, 2);
                VertexBufferAttribute textureCoordinatesAttribute = new VertexBufferAttribute(
                    _textureCoordinatesBuffer, ComponentDatatype.HalfFloat, 2);

                _va = context.CreateVertexArray();
                _va.Attributes[sp.VertexAttributes["position"].Location] = positionAttribute;
                _va.Attributes[sp.VertexAttributes["textureCoordinates"].Location] = textureCoordinatesAttribute;
            }

            if (_viewport != context.Viewport)
            {
                //
                // Bottom and top swapped:  MS -> OpenGL
                //
                float left = context.Viewport.Left;
                float bottom = context.Viewport.Top;
                float right = context.Viewport.Right;
                float top = context.Viewport.Bottom;

                Vector2F[] positions = new Vector2F[] 
                { 
                    new Vector2F(left, bottom), 
                    new Vector2F(right, bottom), 
                    new Vector2F(left, top), 
                    new Vector2F(right, top)
                };
                _positionBuffer.CopyFromSystemMemory(positions);

                Vector2H[] textureCoordinates = new Vector2H[] 
                { 
                    new Vector2H(0, 0), 
                    new Vector2H(1, 0), 
                    new Vector2H(0, 1), 
                    new Vector2H(1, 1)
                };
                _textureCoordinatesBuffer.CopyFromSystemMemory(textureCoordinates);

                _viewport = context.Viewport;
            }
        }
        internal void Update(Context context, ShaderProgram sp)
        {
            if (_va == null)
            {
                VertexBufferAttribute positionAttribute = new VertexBufferAttribute(
                    _positionBuffer, ComponentDatatype.Float, 2);
                VertexBufferAttribute textureCoordinatesAttribute = new VertexBufferAttribute(
                    _textureCoordinatesBuffer, ComponentDatatype.HalfFloat, 2);

                _va = context.CreateVertexArray();
                _va.Attributes[sp.VertexAttributes["position"].Location]           = positionAttribute;
                _va.Attributes[sp.VertexAttributes["textureCoordinates"].Location] = textureCoordinatesAttribute;
            }

            if (_viewport != context.Viewport)
            {
                //
                // Bottom and top swapped:  MS -> OpenGL
                //
                float left   = context.Viewport.Left;
                float bottom = context.Viewport.Top;
                float right  = context.Viewport.Right;
                float top    = context.Viewport.Bottom;

                Vector2F[] positions = new Vector2F[]
                {
                    new Vector2F(left, bottom),
                    new Vector2F(right, bottom),
                    new Vector2F(left, top),
                    new Vector2F(right, top)
                };
                _positionBuffer.CopyFromSystemMemory(positions);

                Vector2H[] textureCoordinates = new Vector2H[]
                {
                    new Vector2H(0, 0),
                    new Vector2H(1, 0),
                    new Vector2H(0, 1),
                    new Vector2H(1, 1)
                };
                _textureCoordinatesBuffer.CopyFromSystemMemory(textureCoordinates);

                _viewport = context.Viewport;
            }
        }
Exemplo n.º 6
0
        private void UpdateDirty()
        {
            // PERFORMANCE:  Sort by buffer offset
            // PERFORMANCE:  Map buffer range
            // PERFORMANCE:  Round robin multiple buffers

            Vector3F[]      positions          = new Vector3F[_dirtyBillboards.Count];
            Vector4H[]      textureCoordinates = new Vector4H[_dirtyBillboards.Count];
            BlittableRGBA[] colors             = new BlittableRGBA[_dirtyBillboards.Count];
            byte[]          origins            = new byte[_dirtyBillboards.Count];
            Vector2H[]      pixelOffets        = new Vector2H[_dirtyBillboards.Count];

            int bufferOffset         = _dirtyBillboards[0].VertexBufferOffset;
            int previousBufferOffset = bufferOffset - 1;
            int length = 0;

            for (int i = 0; i < _dirtyBillboards.Count; ++i)
            {
                Billboard b = _dirtyBillboards[i];

                if (previousBufferOffset != b.VertexBufferOffset - 1)
                {
                    CopyBillboardsFromSystemMemory(positions, textureCoordinates, colors, origins, pixelOffets, bufferOffset, length);

                    bufferOffset = b.VertexBufferOffset;
                    length       = 0;
                }

                positions[length]          = b.Position.ToVector3F();
                textureCoordinates[length] = new Vector4H(
                    b.TextureCoordinates.LowerLeft.X, b.TextureCoordinates.LowerLeft.Y,
                    b.TextureCoordinates.UpperRight.X, b.TextureCoordinates.UpperRight.Y);
                colors[length]      = new BlittableRGBA(b.Color);
                origins[length]     = BillboardOrigin(b);
                pixelOffets[length] = b.PixelOffset;
                ++length;

                previousBufferOffset = b.VertexBufferOffset;
                b.Dirty = false;
            }
            CopyBillboardsFromSystemMemory(positions, textureCoordinates, colors, origins, pixelOffets, bufferOffset, length);

            _dirtyBillboards.Clear();
        }
Exemplo n.º 7
0
 public void ToVector2B()
 {
     Vector2H a = new Vector2H(1.0, 0.0);
     Vector2B sA = a.ToVector2B();
     Assert.IsTrue(sA.X);
     Assert.IsFalse(sA.Y);
 }
Exemplo n.º 8
0
 public void ToVector2I()
 {
     Vector2H a = new Vector2H(1.0, 2.0);
     Vector2I sA = a.ToVector2I();
     Assert.AreEqual(1, sA.X);
     Assert.AreEqual(2, sA.Y);
 }
Exemplo n.º 9
0
 public void ToVector2D()
 {
     Vector2H a = new Vector2H(1.0, 2.0);
     Vector2D sA = a.ToVector2D();
     Assert.AreEqual(1.0, sA.X, 1e-7);
     Assert.AreEqual(2.0, sA.Y, 1e-7);
 }
Exemplo n.º 10
0
 public void TestToString()
 {
     CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
     try
     {
         Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR");
         Vector2H a = new Vector2H(1.23f, 2.34f);
         Assert.AreEqual("(1,230469, 2,339844)", a.ToString());
     }
     finally
     {
         Thread.CurrentThread.CurrentCulture = originalCulture;
     }
 }
Exemplo n.º 11
0
        public void TestGetHashCode()
        {
            Vector2H a = new Vector2H(1.0f, 2.0f);
            Vector2H b = new Vector2H(4.0f, 5.0f);
            Vector2H c = new Vector2H(1.0f, 2.0f);

            Assert.AreEqual(a.GetHashCode(), c.GetHashCode());
            Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode());
        }
Exemplo n.º 12
0
        internal void Update(Context context, ShaderProgram sp)
        {
            if (_va == null)
            {
                VertexBufferAttribute positionAttribute = new VertexBufferAttribute(
                    _positionBuffer, ComponentDatatype.Float, 2);
                VertexBufferAttribute textureCoordinatesAttribute = new VertexBufferAttribute(
                    _textureCoordinatesBuffer, ComponentDatatype.HalfFloat, 2);

                _va = context.CreateVertexArray();
                _va.Attributes[sp.VertexAttributes["position"].Location]           = positionAttribute;
                _va.Attributes[sp.VertexAttributes["textureCoordinates"].Location] = textureCoordinatesAttribute;
                _va.IndexBuffer = _indexBuffer;
            }

            // 检测当前视口变换并重新计算视口矩形
            if (_viewport != context.Viewport)
            {
                //
                // Bottom and top swapped:  MS -> OpenGL
                //
                float left   = context.Viewport.Left;
                float bottom = context.Viewport.Top;
                float right  = context.Viewport.Right;
                float top    = context.Viewport.Bottom;

                Vector2F[] positions = new Vector2F[]
                {
                    // left eye verts
                    new Vector2F(left, bottom),                  // -1, -1
                    new Vector2F((left + right) / 2.0f, bottom), // 0, -1
                    new Vector2F(left, top),                     // -1, 1
                    new Vector2F((left + right) / 2.0f, top),    // 0, 1

                    // right eye verts
                    new Vector2F((left + right) / 2.0f, bottom), // 0, -1
                    new Vector2F(right, bottom),                 // 1, -1
                    new Vector2F((left + right) / 2.0f, top),    // 0, 1
                    new Vector2F(right, top)                     // 1, 1
                };
                _positionBuffer.CopyFromSystemMemory(positions);

                Vector2H[] textureCoordinates = new Vector2H[]
                {
                    // left eye tex coord
                    new Vector2H(0, 1),
                    new Vector2H(1, 1),
                    new Vector2H(0, 0),
                    new Vector2H(1, 0),

                    // right eye tex coord
                    new Vector2H(0, 1),
                    new Vector2H(1, 1),
                    new Vector2H(0, 0),
                    new Vector2H(1, 0),
                };
                _textureCoordinatesBuffer.CopyFromSystemMemory(textureCoordinates);

                ushort[] index = new ushort[] { 0, 1, 3, 0, 3, 2, 4, 5, 7, 4, 7, 6 };
                _indexBuffer.CopyFromSystemMemory(index);

                _viewport = context.Viewport;
            }
        }