public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
            {
                if (bufferName == strPosition)
                {
                    if (positionBufferPtr == null)
                    {
                        using (var buffer = new PropertyBuffer <vec3>(
                                   varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
                        {
                            buffer.Alloc(vertsData.Length);
                            unsafe
                            {
                                var array = (vec3 *)buffer.Header.ToPointer();
                                for (int i = 0; i < vertsData.Length; i++)
                                {
                                    array[i] = vertsData[i];
                                }
                            }

                            positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
                        }
                    }

                    return(positionBufferPtr);
                }
                else
                {
                    throw new ArgumentException();
                }
            }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bufferName"></param>
        /// <param name="varNameInShader"></param>
        /// <returns></returns>
        public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
        {
            if (bufferName == position)
            {
                if (positionBufferPtr == null)
                {
                    using (var buffer = new PropertyBuffer <vec3>(
                               varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
                    {
                        buffer.Create(this.markerCount * 2);
                        unsafe
                        {
                            var array = (vec3 *)buffer.Header.ToPointer();
                            for (int i = 0; i < this.markerCount; i++)
                            {
                                array[i * 2 + 0] = new vec3(-0.5f + (float)i / (float)(this.markerCount - 1), 0.5f, 0);
                                array[i * 2 + 1] = new vec3(-0.5f + (float)i / (float)(this.markerCount - 1), -0.5f, 0);
                            }
                        }

                        positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
                    }
                }
                return(positionBufferPtr);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Beispiel #3
0
        private Geometry CreateQuadGeometry()
        {
            PropertyBuffer vertexData = CreatePropertyBuffer();

            TexturedQuadVertex vertex1 = new TexturedQuadVertex();
            TexturedQuadVertex vertex2 = new TexturedQuadVertex();
            TexturedQuadVertex vertex3 = new TexturedQuadVertex();
            TexturedQuadVertex vertex4 = new TexturedQuadVertex();

            vertex1.position = new Vec2(-0.5f, -0.5f);
            vertex2.position = new Vec2(-0.5f, 0.5f);
            vertex3.position = new Vec2(0.5f, -0.5f);
            vertex4.position = new Vec2(0.5f, 0.5f);


            TexturedQuadVertex[] texturedQuadVertexData = new TexturedQuadVertex[4] {
                vertex1, vertex2, vertex3, vertex4
            };

            int    lenght = Marshal.SizeOf(vertex1);
            IntPtr pA     = Marshal.AllocHGlobal(lenght * 4);

            for (int i = 0; i < 4; i++)
            {
                Marshal.StructureToPtr(texturedQuadVertexData[i], pA + i * lenght, true);
            }
            vertexData.SetData(pA, 4);

            Geometry geometry = new Geometry();

            geometry.AddVertexBuffer(vertexData);
            geometry.SetType(Geometry.Type.TRIANGLE_STRIP);
            return(geometry);
        }
        private PropertyBufferPtr GetPositionBufferPtr(string varNameInShader)
        {
            PropertyBufferPtr ptr = null;
            using (var buffer = new PropertyBuffer<HexahedronPosition>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
            {
                int dimSize = this.DataSource.DimenSize;
                buffer.Alloc(dimSize);
                unsafe
                {
                    var array = (HexahedronPosition*)buffer.Header.ToPointer();
                    int I, J, K;
                    for (int gridIndex = 0; gridIndex < dimSize; gridIndex++)
                    {
                        this.DataSource.InvertIJK(gridIndex, out I, out J, out K);
                        array[gridIndex].FLT = this.DataSource.TranslateMatrix + this.DataSource.PointFLT(I, J, K);
                        array[gridIndex].FRT = this.DataSource.TranslateMatrix + this.DataSource.PointFRT(I, J, K);
                        array[gridIndex].BRT = this.DataSource.TranslateMatrix + this.DataSource.PointBRT(I, J, K);
                        array[gridIndex].BLT = this.DataSource.TranslateMatrix + this.DataSource.PointBLT(I, J, K);
                        array[gridIndex].FLB = this.DataSource.TranslateMatrix + this.DataSource.PointFLB(I, J, K);
                        array[gridIndex].FRB = this.DataSource.TranslateMatrix + this.DataSource.PointFRB(I, J, K);
                        array[gridIndex].BRB = this.DataSource.TranslateMatrix + this.DataSource.PointBRB(I, J, K);
                        array[gridIndex].BLB = this.DataSource.TranslateMatrix + this.DataSource.PointBLB(I, J, K);
                    }
                }
                ptr = buffer.GetBufferPtr() as PropertyBufferPtr;
            }

            return ptr;
        }
Beispiel #5
0
        public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
        {
            if (bufferName == strPosition)
            {
                if (this.positionBufferPtr != null)
                {
                    return(this.positionBufferPtr);
                }

                using (var buffer = new PropertyBuffer <vec3>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
                {
                    buffer.Create(this.positions.Count);
                    unsafe
                    {
                        var array = (vec3 *)buffer.Header.ToPointer();
                        for (int i = 0; i < this.positions.Count; i++)
                        {
                            array[i] = this.positions[i];
                        }
                    }
                    this.positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
                }

                return(this.positionBufferPtr);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Beispiel #6
0
        private PropertyBufferPtr GetPositionBufferPtr(string varNameInShader)
        {
            PropertyBufferPtr ptr = null;

            using (var buffer = new PropertyBuffer <HexahedronPosition>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
            {
                int dimSize = this.DataSource.DimenSize;
                buffer.Create(dimSize);
                unsafe
                {
                    var array = (HexahedronPosition *)buffer.Header.ToPointer();
                    int I, J, K;
                    for (int gridIndex = 0; gridIndex < dimSize; gridIndex++)
                    {
                        this.DataSource.InvertIJK(gridIndex, out I, out J, out K);
                        array[gridIndex].FLT = this.DataSource.Position + this.DataSource.PointFLT(I, J, K);
                        array[gridIndex].FRT = this.DataSource.Position + this.DataSource.PointFRT(I, J, K);
                        array[gridIndex].BRT = this.DataSource.Position + this.DataSource.PointBRT(I, J, K);
                        array[gridIndex].BLT = this.DataSource.Position + this.DataSource.PointBLT(I, J, K);
                        array[gridIndex].FLB = this.DataSource.Position + this.DataSource.PointFLB(I, J, K);
                        array[gridIndex].FRB = this.DataSource.Position + this.DataSource.PointFRB(I, J, K);
                        array[gridIndex].BRB = this.DataSource.Position + this.DataSource.PointBRB(I, J, K);
                        array[gridIndex].BLB = this.DataSource.Position + this.DataSource.PointBLB(I, J, K);
                    }
                }
                ptr = buffer.GetBufferPtr() as PropertyBufferPtr;
            }

            return(ptr);
        }
Beispiel #7
0
            public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
            {
                if (bufferName == strPosition)
                {
                    if (positionBufferPtr == null)
                    {
                        using (var buffer = new PropertyBuffer <vec3>(
                                   varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
                        {
                            buffer.Create(particleCount);
                            unsafe
                            {
                                var array = (vec3 *)buffer.Header.ToPointer();
                                for (int i = 0; i < particleCount; i++)
                                {
                                    double beta  = random.NextDouble() * Math.PI;
                                    double theta = random.NextDouble() * Math.PI * 2;
                                    float  x     = (float)(a * Math.Sin(beta) * Math.Cos(theta));
                                    float  y     = (float)(b * Math.Sin(beta) * Math.Sin(theta));
                                    float  z     = (float)(c * Math.Cos(beta));
                                    array[i] = new vec3(x, y, z);
                                }
                            }

                            positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
                        }
                    }

                    return(positionBufferPtr);
                }
                else
                {
                    throw new ArgumentException();
                }
            }
Beispiel #8
0
        public void PropertyBufferSetData()
        {
            tlog.Debug(tag, $"PropertyBufferSetData START");

            PropertyMap buffer = new PropertyMap();

            Assert.IsNotNull(buffer, "should be not null");
            Assert.IsInstanceOf <PropertyMap>(buffer, "should be an instance of PropertyMap class!");
            buffer.Add("aIndex", new PropertyValue((int)PropertyType.Float));
            buffer.Add("aValue", new PropertyValue((int)PropertyType.Float));

            var testingTarget = new PropertyBuffer(buffer);

            Assert.IsNotNull(testingTarget, "should be not null");
            Assert.IsInstanceOf <PropertyBuffer>(testingTarget, "Should be an instance of PropertyBuffer class!");
            try
            {
                global::System.IntPtr data = new global::System.IntPtr();
                testingTarget.SetData(data, 0);
            }
            catch (Exception e)
            {
                LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
                Assert.Fail("Caught Exception" + e.ToString());
            }
            Assert.AreEqual(0, testingTarget.GetSize(), "Should be Equal.");

            testingTarget.Dispose();
            buffer.Dispose();
            tlog.Debug(tag, $"PropertyBufferSetData END (OK)");
        }
Beispiel #9
0
 public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
 {
     if (bufferName == strPosition)
     {
         if (positionBuffer == null)
         {
             using (var buffer = new PropertyBuffer <float>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.DynamicDraw))
             {
                 buffer.Alloc(positions.Length);
                 unsafe
                 {
                     var array = (float *)buffer.Header.ToPointer();
                     for (int i = 0; i < positions.Length; i++)
                     {
                         array[i] = positions[i];
                     }
                 }
                 positionBuffer = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return(positionBuffer);
     }
     else
     {
         return(null);
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="bufferName"></param>
        /// <param name="varNameInShader"></param>
        /// <returns></returns>
        public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
        {
            if (bufferName == position)
            {
                if (positionBufferPtr == null)
                {
                    using (var buffer = new PropertyBuffer <vec3>(
                               varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
                    {
                        buffer.Create((this.quadCount + 1) * 2);
                        unsafe
                        {
                            var array = (vec3 *)buffer.Header.ToPointer();
                            for (int i = 0; i < (this.quadCount + 1); i++)
                            {
                                array[i * 2 + 0] = new vec3(-0.5f + (float)i / (float)(this.quadCount), 0.5f, 0);
                                array[i * 2 + 1] = new vec3(-0.5f + (float)i / (float)(this.quadCount), -0.5f, 0);
                            }
                        }

                        positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
                    }
                }
                return(positionBufferPtr);
            }
            else if (bufferName == color)
            {
                if (colorBufferPtr == null)
                {
                    using (var buffer = new PropertyBuffer <vec3>(
                               varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
                    {
                        buffer.Create((this.quadCount + 1) * 2);
                        unsafe
                        {
                            var array = (vec3 *)buffer.Header.ToPointer();
                            for (int i = 0; i < (this.quadCount + 1); i++)
                            {
                                int x = this.bitmap.Width * i / this.quadCount;
                                if (x == this.bitmap.Width)
                                {
                                    x = this.bitmap.Width - 1;
                                }
                                vec3 value = this.bitmap.GetPixel(x, 0).ToVec3();
                                array[i * 2 + 0] = value;
                                array[i * 2 + 1] = value;
                            }
                        }

                        colorBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
                    }
                }
                return(colorBufferPtr);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Beispiel #11
0
        private PropertyBuffer CreatePropertyBuffer()
        {
            PropertyMap vertexFormat = new PropertyMap();

            vertexFormat.Add("aPosition", new PropertyValue((int)PropertyType.Vector2));
            PropertyBuffer vertexBuffer = new PropertyBuffer(vertexFormat);

            return(vertexBuffer);
        }
Beispiel #12
0
        /// <summary>
        /// Adds a PropertyBuffer to be used as source of geometry vertices.
        /// </summary>
        /// <param name="vertexBuffer">PropertyBuffer to be used as source of geometry vertices.</param>
        /// <returns>Index of the newly added buffer.</returns>
        /// <since_tizen> 3 </since_tizen>
        public uint AddVertexBuffer(PropertyBuffer vertexBuffer)
        {
            uint ret = NDalicPINVOKE.Geometry_AddVertexBuffer(swigCPtr, PropertyBuffer.getCPtr(vertexBuffer));

            if (NDalicPINVOKE.SWIGPendingException.Pending)
            {
                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Beispiel #13
0
        public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
        {
            if (bufferName == position)
            {
                if (!propertyBufferPtrDict.ContainsKey(bufferName))
                {
                    using (var buffer = new PropertyBuffer<vec3>(
                        varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
                    {
                        buffer.Alloc(BigDipperModel.positions.Length);
                        unsafe
                        {
                            var array = (vec3*)buffer.Header.ToPointer();
                            for (int i = 0; i < BigDipperModel.positions.Length; i++)
                            {
                                array[i] = BigDipperModel.positions[i];
                            }
                        }

                        propertyBufferPtrDict.Add(bufferName, buffer.GetBufferPtr() as PropertyBufferPtr);
                    }
                }
                return propertyBufferPtrDict[bufferName];
            }
            else if (bufferName == color)
            {
                if (!propertyBufferPtrDict.ContainsKey(bufferName))
                {
                    using (var buffer = new PropertyBuffer<vec3>(
                        varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
                    {
                        buffer.Alloc(BigDipperModel.colors.Length);
                        unsafe
                        {
                            var array = (vec3*)buffer.Header.ToPointer();
                            for (int i = 0; i < BigDipperModel.colors.Length; i++)
                            {
                                array[i] = BigDipperModel.colors[i];
                            }
                        }

                        propertyBufferPtrDict.Add(bufferName, buffer.GetBufferPtr() as PropertyBufferPtr);
                    }
                }
                return propertyBufferPtrDict[bufferName];
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Beispiel #14
0
        private Renderer CreateRenderer()
        {
            TexturedQuadVertex vertex1 = new TexturedQuadVertex();
            TexturedQuadVertex vertex2 = new TexturedQuadVertex();
            TexturedQuadVertex vertex3 = new TexturedQuadVertex();
            TexturedQuadVertex vertex4 = new TexturedQuadVertex();

            vertex1.position = new Vec2(-0.5f, -0.5f);
            vertex2.position = new Vec2(0.5f, -0.5f);
            vertex3.position = new Vec2(-0.5f, 0.5f);
            vertex4.position = new Vec2(0.5f, 0.5f);
            vertex1.texCoord = new Vec2(0.0f, 0.0f);
            vertex2.texCoord = new Vec2(1.0f, 0.0f);
            vertex3.texCoord = new Vec2(0.0f, 1.0f);
            vertex4.texCoord = new Vec2(1.0f, 1.0f);

            TexturedQuadVertex[] texturedQuadVertexData = new TexturedQuadVertex[4] {
                vertex1, vertex2, vertex3, vertex4
            };

            PropertyMap property = new PropertyMap();

            property.Add("aPosition", new PropertyValue((int)PropertyType.Vector2));
            property.Add("aTexCoord", new PropertyValue((int)PropertyType.Vector2));
            PropertyBuffer vertexBuffer = new PropertyBuffer(property);

            const int vertexCount = 4;

            unsafe
            {
                float *pc = (float *)Marshal.UnsafeAddrOfPinnedArrayElement(texturedQuadVertexData, 0);
                IntPtr pA = new IntPtr(pc);
                vertexBuffer.SetData(pA, vertexCount);
            }

            Geometry geometry = new Geometry();

            geometry.AddVertexBuffer(vertexBuffer);
            geometry.SetType(Geometry.Type.TRIANGLE_STRIP);

            // Create the shader
            Shader shader = new Shader(VERSION_3_ES + VERTEX_SHADER, VERSION_3_ES + FRAGMENT_SHADER);

            // Create the renderer
            Renderer renderer = new Renderer(geometry, shader);

            return(renderer);
        }
Beispiel #15
0
        protected override void OnCreate()
        {
            base.OnCreate();
            Window window = NUIApplication.GetDefaultWindow();

            window.BackgroundColor = Color.Black;

            View view = new View()
            {
                Size = new Size(window.WindowSize)
            };

            window.Add(view);


            PropertyMap vertexFormat = new PropertyMap();

            vertexFormat.Add("aPosition", new PropertyValue((int)PropertyType.Vector2));
            PropertyBuffer vertexBuffer = new PropertyBuffer(vertexFormat);

            vertexBuffer.SetData(RectangleDataPtr(), 4);
            Geometry geometry = new Geometry();

            geometry.AddVertexBuffer(vertexBuffer);
            geometry.SetType(Geometry.Type.TRIANGLE_STRIP);
            Shader shader = new Shader(VERTEX_SHADER, FRAGMENT_SHADER);

            PixelData pixelData = PixelBuffer.Convert(ImageLoading.LoadImageFromFile(
                                                          "./res/background_image.jpg",
                                                          new Size2D(),
                                                          FittingModeType.ScaleToFill
                                                          ));
            Texture texture = new Texture(
                TextureType.TEXTURE_2D,
                pixelData.GetPixelFormat(),
                pixelData.GetWidth(),
                pixelData.GetHeight()
                );

            texture.Upload(pixelData);
            TextureSet textureSet = new TextureSet();

            textureSet.SetTexture(0u, texture);
            Renderer renderer = new Renderer(geometry, shader);

            renderer.SetTextures(textureSet);
            view.AddRenderer(renderer);
        }
Beispiel #16
0
 public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
 {
     if (bufferName == strPosition)
     {
         if (positionBuffer == null)
         {
             using (var buffer = new PropertyBuffer <float>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 buffer.Create(boundingBox.Length);
                 unsafe
                 {
                     var array = (float *)buffer.Header.ToPointer();
                     for (int i = 0; i < boundingBox.Length; i++)
                     {
                         array[i] = boundingBox[i] - 0.5f;
                     }
                 }
                 positionBuffer = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return(positionBuffer);
     }
     else if (bufferName == strBoundingBox)
     {
         if (colorBuffer == null)
         {
             using (var buffer = new PropertyBuffer <float>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 buffer.Create(boundingBox.Length);
                 unsafe
                 {
                     var array = (float *)buffer.Header.ToPointer();
                     for (int i = 0; i < boundingBox.Length; i++)
                     {
                         array[i] = boundingBox[i];
                     }
                 }
                 colorBuffer = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return(colorBuffer);
     }
     else
     {
         return(null);
     }
 }
 public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
 {
     if (bufferName == strposition)
     {
         if (positionBufferPtr == null)
         {
             using (var buffer = new PropertyBuffer <vec3>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 buffer.Alloc(4);
                 unsafe
                 {
                     var array = (vec3 *)buffer.Header.ToPointer();
                     array[0] = new vec3(-1.0f, -1.0f, 0.5f);
                     array[1] = new vec3(1.0f, -1.0f, 0.5f);
                     array[2] = new vec3(1.0f, 1.0f, 0.5f);
                     array[3] = new vec3(-1.0f, 1.0f, 0.5f);
                 }
                 positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return(positionBufferPtr);
     }
     else if (bufferName == struv)
     {
         if (uvBufferPtr == null)
         {
             using (var buffer = new PropertyBuffer <vec2>(varNameInShader, 2, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 buffer.Alloc(4);
                 unsafe
                 {
                     var array = (vec2 *)buffer.Header.ToPointer();
                     array[0] = new vec2(1, 1);
                     array[1] = new vec2(0, 1);
                     array[2] = new vec2(0, 0);
                     array[3] = new vec2(1, 0);
                 }
                 uvBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return(uvBufferPtr);
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Beispiel #18
0
            public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
            {
                if (bufferName == strPosition)
                {
                    if (positionBufferPtr == null)
                    {
                        using (var buffer = new PropertyBuffer <vec3>(
                                   varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
                        {
                            buffer.Alloc(particleCount);
                            unsafe
                            {
                                var array = (vec3 *)buffer.Header.ToPointer();
                                for (int i = 0; i < particleCount; i++)
                                {
                                    //if (i % 2 == 0)
                                    {
                                        array[i] = new vec3(
                                            (float)((random.NextDouble() * 2 - 1) * backgroundRadius),
                                            (float)((random.NextDouble() * 2 - 1) * backgroundRadius),
                                            (float)((random.NextDouble() * 2 - 1) * backgroundRadius));
                                    }
                                    //else
                                    //{
                                    //    double theta = random.NextDouble() * 2 * Math.PI - Math.PI;
                                    //    double alpha = random.NextDouble() * 2 * Math.PI - Math.PI;
                                    //    array[i] = new vec3(
                                    //        (float)(Math.Sin(theta) * Math.Cos(alpha)) * backgroundRadius,
                                    //        (float)(Math.Sin(theta) * Math.Sin(alpha)) * backgroundRadius,
                                    //        (float)(Math.Cos(theta)) * backgroundRadius);
                                    //}
                                }
                            }

                            positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
                        }
                    }

                    return(positionBufferPtr);
                }
                else
                {
                    throw new ArgumentException();
                }
            }
Beispiel #19
0
        public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
        {
            if (bufferName == strPosition)
            {
                if (positionBufferPtr == null)
                {
                    using (var buffer = new PropertyBuffer <vec4>(
                               varNameInShader, 4, OpenGL.GL_FLOAT, BufferUsage.DynamicCopy))
                    {
                        buffer.Alloc(particleCount);
                        unsafe
                        {
                            var array = (vec4 *)buffer.Header.ToPointer();
                            for (int i = 0; i < particleCount; i++)
                            {
                                array[i] = new vec4(
                                    (float)(
                                        (random.NextDouble() - 0.5) * 2
                                        * ((random.NextDouble() * (maxRadius - minRadius) + minRadius))
                                        ),
                                    (float)(
                                        (random.NextDouble() - 0.5) * 2
                                        * ((random.NextDouble() * (maxRadius - minRadius) + minRadius))
                                        ),
                                    (float)(
                                        (random.NextDouble() - 0.5) * 2
                                        * ((random.NextDouble() * (maxRadius - minRadius) + minRadius))
                                        ),
                                    (float)(random.NextDouble())
                                    );
                            }
                        }

                        positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
                    }
                }

                return(positionBufferPtr);
            }
            else
            {
                throw new ArgumentException();
            }
        }
Beispiel #20
0
        public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
        {
            if (bufferName == position)
            {
                using (var buffer = new PropertyBuffer <vec3>(
                           varNameInShader, 3, GL.GL_FLOAT, BufferUsage.StaticDraw))
                {
                    buffer.Alloc(model.Positions.Length);
                    unsafe
                    {
                        var array = (vec3 *)buffer.FirstElement();
                        for (int i = 0; i < model.Positions.Length; i++)
                        {
                            array[i] = model.Positions[i];
                        }
                    }

                    return(buffer.GetBufferPtr() as PropertyBufferPtr);
                }
            }
            else if (bufferName == color)
            {
                using (var buffer = new PropertyBuffer <vec3>(
                           varNameInShader, 3, GL.GL_FLOAT, BufferUsage.StaticDraw))
                {
                    buffer.Alloc(model.Colors.Length);
                    unsafe
                    {
                        var array = (vec3 *)buffer.FirstElement();
                        for (int i = 0; i < model.Colors.Length; i++)
                        {
                            array[i] = model.Colors[i];
                        }
                    }

                    return(buffer.GetBufferPtr() as PropertyBufferPtr);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Beispiel #21
0
        public void PropertyBufferConstructor()
        {
            tlog.Debug(tag, $"PropertyBufferConstructor START");

            PropertyMap buffer = new PropertyMap();

            Assert.IsNotNull(buffer, "should be not null");
            Assert.IsInstanceOf <PropertyMap>(buffer, "should be an instance of PropertyMap class!");
            buffer.Add("aIndex", new PropertyValue((int)PropertyType.Float));
            buffer.Add("aValue", new PropertyValue((int)PropertyType.Float));

            var testingTarget = new PropertyBuffer(buffer);

            Assert.IsNotNull(testingTarget, "Can't create success object PropertyBuffer");
            Assert.IsInstanceOf <PropertyBuffer>(testingTarget, "Should be an instance of PropertyBuffer class!");

            testingTarget.Dispose();
            buffer.Dispose();
            tlog.Debug(tag, $"PropertyBufferConstructor END (OK)");
        }
Beispiel #22
0
        private Geometry GenerateGeometry()
        {
            PropertyMap vertexFormat = new PropertyMap();

            vertexFormat.Add("aPosition", new PropertyValue((int)PropertyType.Vector3));
            vertexFormat.Add("aNormal", new PropertyValue((int)PropertyType.Vector3));
            vertexFormat.Add("aTexCoord", new PropertyValue((int)PropertyType.Vector2));
            PropertyBuffer vertexBuffer = new PropertyBuffer(vertexFormat);

            vertexBuffer.SetData(SphereVertexDataPtr(), SPHERE_VERTEX_NUMBER);

            ushort[] indexBuffer = SphereIndexData();

            Geometry geometry = new Geometry();

            geometry.AddVertexBuffer(vertexBuffer);
            geometry.SetIndexBuffer(indexBuffer, SPHERE_INDEX_NUMBER);
            geometry.SetType(Geometry.Type.TRIANGLES);
            return(geometry);
        }
Beispiel #23
0
        public void PropertyBufferGetSize()
        {
            tlog.Debug(tag, $"PropertyBufferGetSize START");

            PropertyMap buffer = new PropertyMap();

            Assert.IsNotNull(buffer, "should be not null");
            Assert.IsInstanceOf <PropertyMap>(buffer, "should be an instance of PropertyMap class!");
            buffer.Add("aIndex", new PropertyValue((int)PropertyType.Float));
            buffer.Add("aValue", new PropertyValue((int)PropertyType.Float));

            var testingTarget = new PropertyBuffer(buffer);

            Assert.IsNotNull(testingTarget, "should be not null");
            Assert.IsInstanceOf <PropertyBuffer>(testingTarget, "Should be an instance of PropertyBuffer class!");
            Assert.AreEqual(0, testingTarget.GetSize(), "Should be Equal.");

            testingTarget.Dispose();
            buffer.Dispose();
            tlog.Debug(tag, $"PropertyBufferGetSize END (OK)");
        }
Beispiel #24
0
        private PropertyBufferPtr GetColorBufferPtr(string varNameInShader)
        {
            PropertyBufferPtr ptr = null;

            using (var buffer = new PropertyBuffer <HexahedronTexCoord>(varNameInShader, 1, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
            {
                float[] textures = GetTextureCoords(this.GridBlockProperties[this.defaultBlockPropertyIndex]);

                int gridCellCount = this.DataSource.DimenSize;
                buffer.Create(gridCellCount);
                unsafe
                {
                    var array = (HexahedronTexCoord *)buffer.Header.ToPointer();
                    for (int gridIndex = 0; gridIndex < gridCellCount; gridIndex++)
                    {
                        array[gridIndex].SetCoord(textures[gridIndex]);
                    }
                }
                ptr = buffer.GetBufferPtr() as PropertyBufferPtr;
            }

            return(ptr);
        }
Beispiel #25
0
 public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
 {
     if (bufferName == strPosition)
     {
         if (positionBufferPtr == null)
         {
             using (var buffer = new PropertyBuffer<vec3>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 buffer.Alloc(model.positions.Length);
                 unsafe
                 {
                     var array = (vec3*)buffer.Header.ToPointer();
                     for (int i = 0; i < model.positions.Length; i++)
                     {
                         array[i] = model.positions[i];
                     }
                 }
                 positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return positionBufferPtr;
     }
         else if (bufferName == strNormal)
     {
         if (normalBufferPtr == null)
         {
             using (var buffer = new PropertyBuffer<vec3>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 buffer.Alloc(model.normals.Length);
                 unsafe
                 {
                     var array = (vec3*)buffer.Header.ToPointer();
                     for (int i = 0; i < model.normals.Length; i++)
                     {
                         array[i] = model.normals[i];
                     }
                 }
                 normalBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return normalBufferPtr;
     }
     else if (bufferName == strColor)
     {
         if (colorBufferPtr == null)
         {
             using (var buffer = new PropertyBuffer<vec3>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 buffer.Alloc(model.colors.Length);
                 unsafe
                 {
                     var array = (vec3*)buffer.Header.ToPointer();
                     for (int i = 0; i < model.colors.Length; i++)
                     {
                         array[i] = model.colors[i];
                     }
                 }
                 colorBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return colorBufferPtr;
     }
     else if (bufferName == strUV)
     {
         if (uvBufferPtr == null)
         {
             using (var buffer = new PropertyBuffer<vec2>(varNameInShader, 2, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 buffer.Alloc(model.uv.Length);
                 unsafe
                 {
                     var array = (vec2*)buffer.Header.ToPointer();
                     for (int i = 0; i < model.uv.Length; i++)
                     {
                         array[i] = model.uv[i];
                     }
                 }
                 uvBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return uvBufferPtr;
     }
     else
     {
         return null;
     }
 }
 public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
 {
     if (bufferName == strposition)
     {
         if (positionBufferPtr == null)
         {
             using (var buffer = new PropertyBuffer<vec3>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 buffer.Alloc(4);
                 unsafe
                 {
                     var array = (vec3*)buffer.Header.ToPointer();
                     array[0] = new vec3(-1.0f, -1.0f, 0.5f);
                     array[1] = new vec3(1.0f, -1.0f, 0.5f);
                     array[2] = new vec3(1.0f, 1.0f, 0.5f);
                     array[3] = new vec3(-1.0f, 1.0f, 0.5f);
                 }
                 positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return positionBufferPtr;
     }
     else if (bufferName == struv)
     {
         if (uvBufferPtr == null)
         {
             using (var buffer = new PropertyBuffer<vec2>(varNameInShader, 2, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 buffer.Alloc(4);
                 unsafe
                 {
                     var array = (vec2*)buffer.Header.ToPointer();
                     array[0] = new vec2(1, 1);
                     array[1] = new vec2(0, 1);
                     array[2] = new vec2(0, 0);
                     array[3] = new vec2(1, 0);
                 }
                 uvBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return uvBufferPtr;
     }
     else
     { throw new NotImplementedException(); }
 }
Beispiel #27
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PropertyBuffer obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
            public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
            {
                if (bufferName == strPosition)
                {
                    if (positionBufferPtr == null)
                    {
                        using (var buffer = new PropertyBuffer<vec3>(
                            varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
                        {
                            buffer.Alloc(particleCount);
                            unsafe
                            {
                                var array = (vec3*)buffer.Header.ToPointer();
                                for (int i = 0; i < particleCount; i++)
                                {
                                    double beta = random.NextDouble() * Math.PI;
                                    double theta = random.NextDouble() * Math.PI * 2;
                                    float x = (float)(a * Math.Sin(beta) * Math.Cos(theta));
                                    float y = (float)(b * Math.Sin(beta) * Math.Sin(theta));
                                    float z = (float)(c * Math.Cos(beta));
                                    array[i] = new vec3(x, y, z);
                                }
                            }

                            positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
                        }
                    }

                    return positionBufferPtr;
                }
                else
                {
                    throw new ArgumentException();
                }
            }
Beispiel #29
0
 public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
 {
     if (bufferName == strPosition)
     {
         if (positionBufferPtr == null)
         {
             using (var buffer = new PropertyBuffer <vec3>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 buffer.Alloc(model.positions.Length);
                 unsafe
                 {
                     var array = (vec3 *)buffer.Header.ToPointer();
                     for (int i = 0; i < model.positions.Length; i++)
                     {
                         array[i] = model.positions[i];
                     }
                 }
                 positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return(positionBufferPtr);
     }
     else if (bufferName == strUV)
     {
         if (uvBufferPtr == null)
         {
             using (var buffer = new PropertyBuffer <vec2>(varNameInShader, 2, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 buffer.Alloc(model.uv.Length);
                 unsafe
                 {
                     var array = (vec2 *)buffer.Header.ToPointer();
                     for (int i = 0; i < model.uv.Length; i++)
                     {
                         array[i] = model.uv[i];
                     }
                 }
                 uvBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return(uvBufferPtr);
     }
     else if (bufferName == strNormal)
     {
         if (normalBufferPtr == null)
         {
             using (var buffer = new PropertyBuffer <vec3>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 buffer.Alloc(model.normals.Length);
                 unsafe
                 {
                     var array = (vec3 *)buffer.Header.ToPointer();
                     for (int i = 0; i < model.normals.Length; i++)
                     {
                         array[i] = model.normals[i];
                     }
                 }
                 normalBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return(normalBufferPtr);
     }
     else
     {
         throw new ArgumentException();
     }
 }
Beispiel #30
0
        private static void CreateGeometry()
        {
            if (geometry == null)
            {
                geometry = new Geometry();

                const int vertexCount = 34;

                circleArray = new float[vertexCount * 2];
                quadArray   = new float[vertexCount * 2];

                // Create the circle geometry

                // Radius is bound to actor's dimensions so this should not be increased.
                // If a bigger circle is required then the actor size should be increased.
                const float radius = 0.5f;
                Vector2     center = new Vector2(0.0f, 0.0f);

                // Create a buffer for vertex data
                Vector2[] circleBuffer = new Vector2[vertexCount];
                int       idx          = 0;

                // Center vertex for triangle fan
                circleBuffer[idx++] = center;

                // Outer vertices of the circle
                const int outerVertexCount = vertexCount - 1;

                for (int i = 0; i < outerVertexCount; ++i)
                {
                    float percent = (i / (float)(outerVertexCount - 1));
                    float rad     = percent * 2.0f * (float)Math.PI;

                    // Vertex position
                    Vector2 tmpvec = new Vector2(0, 0);
                    tmpvec.X = (float)(center.X + radius * Math.Cos(rad));
                    tmpvec.Y = (float)(center.Y + radius * Math.Sin(rad));

                    circleBuffer[idx++] = tmpvec;
                }

                for (int i = 0; i < idx; i++)
                {
                    circleArray[i * 2]     = circleBuffer[i].X;
                    circleArray[i * 2 + 1] = circleBuffer[i].Y;
                }

                PropertyMap circleVertexFormat = new PropertyMap();
                circleVertexFormat.Add("aPositionCircle", new PropertyValue((int)PropertyType.Vector2));
                PropertyBuffer circleVertices = new PropertyBuffer(circleVertexFormat);

                unsafe
                {
                    float *pc = (float *)Marshal.UnsafeAddrOfPinnedArrayElement(circleArray, 0);
                    IntPtr pA = new IntPtr(pc);
                    circleVertices.SetData(pA, vertexCount);
                }


                // Create the Quad Geometry
                Vector2[] quadBuffer = new Vector2[vertexCount];
                idx = 0;
                quadBuffer[idx++] = new Vector2(center.X, center.Y);

                const int vertsPerSide = (vertexCount - 2) / 4;
                Vector2   outer        = new Vector2(0.5f, 0.0f);
                quadBuffer[idx++] = new Vector2(outer.X, outer.Y);
                float incrementPerBuffer = 1.0f / (float)(vertsPerSide);

                for (int i = 0; i < vertsPerSide && outer.Y < 0.5f; ++i)
                {
                    outer.Y          += incrementPerBuffer;
                    quadBuffer[idx++] = new Vector2(outer.X, outer.Y);
                }

                for (int i = 0; i < vertsPerSide && outer.X > -0.5f; ++i)
                {
                    outer.X          -= incrementPerBuffer;
                    quadBuffer[idx++] = new Vector2(outer.X, outer.Y);
                }

                for (int i = 0; i < vertsPerSide && outer.Y > -0.5f; ++i)
                {
                    outer.Y          -= incrementPerBuffer;
                    quadBuffer[idx++] = new Vector2(outer.X, outer.Y);
                }

                for (int i = 0; i < vertsPerSide && outer.X < 0.5f; ++i)
                {
                    outer.X          += incrementPerBuffer;
                    quadBuffer[idx++] = new Vector2(outer.X, outer.Y);
                }

                for (int i = 0; i < vertsPerSide && outer.Y < 0.0f; ++i)
                {
                    outer.Y          += incrementPerBuffer;
                    quadBuffer[idx++] = new Vector2(outer.X, outer.Y);
                }

                for (int i = 0; i < idx; i++)
                {
                    quadArray[i * 2]     = quadBuffer[i].X;
                    quadArray[i * 2 + 1] = quadBuffer[i].Y;
                }

                PropertyMap vertexFormat = new PropertyMap();
                vertexFormat.Add("aPositionQuad", new PropertyValue((int)PropertyType.Vector2));
                PropertyBuffer quadVertices2 = new PropertyBuffer(vertexFormat);
                unsafe
                {
                    float *pc = (float *)Marshal.UnsafeAddrOfPinnedArrayElement(quadArray, 0);
                    IntPtr pA = new IntPtr(pc);
                    quadVertices2.SetData(pA, vertexCount);
                }
                //int length2 = Marshal.SizeOf(quadBuffer[0]);
                //IntPtr p2 = Marshal.AllocHGlobal(length2 * vertexCount);
                //quadVertices2.SetData(p2, vertexCount);

                // Create the geometry object itself
                geometry.AddVertexBuffer(circleVertices);
                geometry.AddVertexBuffer(quadVertices2);
                geometry.SetType(Geometry.Type.TRIANGLE_FAN);
            }
        }
Beispiel #31
0
        /// <summary>
        /// View which is clipping image and applying mask
        /// </summary>
        /// <param name="resourceImageUrl">Image which will be cripped</param>
        /// <param name="maskImageUrl">Image for masking</param>
        public ClippingMaskView(string resourceImageUrl, string maskImageUrl)
        {
            // Load mask image file and make PixelData
            PixelData pixelData = PixelBuffer.Convert(
                ImageLoading.LoadImageFromFile(
                    maskImageUrl,
                    new Size2D(),
                    FittingModeType.ScaleToFill
                    )
                );

            // Make mask image texture and upload.
            Texture maskTexture = new Texture(
                TextureType.TEXTURE_2D,
                pixelData.GetPixelFormat(),
                pixelData.GetWidth(),
                pixelData.GetHeight()
                );

            maskTexture.Upload(pixelData);

            Size maskImageSize = new Size(maskTexture.GetWidth(), maskTexture.GetHeight());

            // Background Image will be clipped
            BackgroundImage = new ImageView()
            {
                PositionUsesPivotPoint = true,
                PivotPoint             = Tizen.NUI.PivotPoint.Center,
                ParentOrigin           = Tizen.NUI.ParentOrigin.Center,
                Size        = maskImageSize,
                ResourceUrl = resourceImageUrl,
            };
            Add(BackgroundImage);

            // Set properties for render task
            Camera camera = new Camera(new Vector2(maskImageSize.Width, maskImageSize.Height))
            {
                PositionUsesPivotPoint = true,
                PivotPoint             = Tizen.NUI.PivotPoint.Center,
                ParentOrigin           = Tizen.NUI.ParentOrigin.Center,
            };

            camera.SetInvertYAxis(true);
            Add(camera);

            RenderTask task = NUIApplication.GetDefaultWindow().GetRenderTaskList().CreateTask();

            task.SetRefreshRate((uint)RenderTask.RefreshRate.REFRESH_ALWAYS);
            task.SetSourceView(BackgroundImage);
            task.SetExclusive(true);
            task.SetInputEnabled(false);
            task.SetClearColor(new Vector4(1.0f, 1.0f, 1.0f, 1.0f));
            task.SetClearEnabled(true);
            task.SetCamera(camera);

            // Clipped Texture
            Texture clippedTexture = new Texture(
                TextureType.TEXTURE_2D,
                PixelFormat.RGBA8888,
                (uint)maskImageSize.Width,
                (uint)maskImageSize.Height
                );

            FrameBuffer frameBuffer = new FrameBuffer(
                (uint)maskImageSize.Width,
                (uint)maskImageSize.Height,
                (uint)FrameBuffer.Attachment.Mask.NONE
                );

            frameBuffer.AttachColorTexture(clippedTexture);
            task.SetFrameBuffer(frameBuffer);

            /* Create Renderer to apply mask */
            PropertyMap vertexFormat = new PropertyMap();

            vertexFormat.Add("aPosition", new PropertyValue((int)PropertyType.Vector2));
            PropertyBuffer vertexBuffer = new PropertyBuffer(vertexFormat);

            vertexBuffer.SetData(RectangleDataPtr(), 4);

            /* Create geometry */
            Geometry geometry = new Geometry();

            geometry.AddVertexBuffer(vertexBuffer);
            geometry.SetType(Geometry.Type.TRIANGLE_STRIP);

            /* Create Shader */
            Shader shader = new Shader(VERTEX_SHADER, FRAGMENT_SHADER);

            TextureSet textureSet = new TextureSet();

            textureSet.SetTexture(0u, clippedTexture);
            textureSet.SetTexture(1u, maskTexture);

            Renderer renderer = new Renderer(geometry, shader);

            renderer.SetTextures(textureSet);

            AddRenderer(renderer);
        }
Beispiel #32
0
        public unsafe PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
        {
            if (bufferName == strPosition)
            {
                if (positionBufferPtr != null)
                {
                    return(positionBufferPtr);
                }

                using (var buffer = new PropertyBuffer <vec3>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
                {
                    int vertexCount = (faceCount * 2 + 2) * (pipeline.Count - 1);
                    buffer.Create(vertexCount);
                    var array = (vec3 *)buffer.Header.ToPointer();
                    int index = 0;
                    var max   = new vec3(float.MinValue, float.MinValue, float.MinValue);
                    var min   = new vec3(float.MaxValue, float.MaxValue, float.MaxValue);
                    for (int i = 1; i < pipeline.Count; i++)
                    {
                        vec3 p1     = pipeline[i - 1];
                        vec3 p2     = pipeline[i];
                        vec3 vector = p2 - p1;// 从p1到p2的向量
                        // 找到互相垂直的三个向量:vector, orthogontalVector1和orthogontalVector2
                        vec3 orthogontalVector1 = new vec3(vector.y - vector.z, vector.z - vector.x, vector.x - vector.y);
                        vec3 orthogontalVector2 = vector.cross(orthogontalVector1);
                        orthogontalVector1 = orthogontalVector1.normalize() * (float)Math.Sqrt(this.radius);
                        orthogontalVector2 = orthogontalVector2.normalize() * (float)Math.Sqrt(this.radius);
                        for (int faceIndex = 0; faceIndex < faceCount + 1; faceIndex++)
                        {
                            double angle = (Math.PI * 2 * faceIndex) / faceCount;
                            vec3   delta = orthogontalVector1 * (float)Math.Cos(angle) + orthogontalVector2 * (float)Math.Sin(angle);
                            vec3   tmp1 = p1 + delta, tmp2 = p2 + delta;
                            tmp1.UpdateMax(ref max); tmp1.UpdateMin(ref min);
                            tmp2.UpdateMax(ref max); tmp2.UpdateMin(ref min);
                            array[index++] = tmp1;
                            array[index++] = tmp2;
                        }
                    }
                    this.lengths = max - min;

                    positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
                }

                return(positionBufferPtr);
            }
            else if (bufferName == strBrightness)
            {
                if (brightnessBufferPtr != null)
                {
                    return(brightnessBufferPtr);
                }

                using (var buffer = new PropertyBuffer <vec3>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
                {
                    int vertexCount = (faceCount * 2 + 2) * (pipeline.Count - 1);
                    buffer.Create(vertexCount);
                    var array  = (vec3 *)buffer.Header.ToPointer();
                    var random = new Random();
                    for (int i = 0; i < buffer.Length; i++)
                    {
                        var x = (float)(random.NextDouble() * 0.5 + 0.5);
                        array[i] = new vec3(x, x, x);
                    }

                    brightnessBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
                }

                return(brightnessBufferPtr);
            }
            else
            {
                throw new ArgumentException();
            }
        }
 public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
 {
     if (bufferName == strPosition)
     {
         if (this.positionBufferPtr == null)
         {
             const float lower = -0.3f;
             var positions = new vec2[codedColors.Length * 2 + 4];
             for (int i = 0; i < codedColors.Length; i++)
             {
                 positions[i * 2 + 0] = new vec2(codedColors[i].Coord*2, lower);
                 positions[i * 2 + 1] = new vec2(codedColors[i].Coord * 2, 1);
             }
             int index = codedColors.Length * 2 + 0;
             positions[index++] = new vec2(codedColors[0].Coord * 2, 0);
             positions[index++] = new vec2(codedColors[codedColors.Length - 1].Coord * 2, 0);
             positions[index++] = new vec2(codedColors[0].Coord * 2, 1);
             positions[index++] = new vec2(codedColors[codedColors.Length - 1].Coord * 2, 1);
             // Move2Cente
             float min = positions[0].x, max = positions[0].x;
             for (int i = 1; i < positions.Length; i++)
             {
                 vec2 value = positions[i];
                 if (value.x < min) { min = value.x; }
                 if (max < value.x) { max = value.x; }
             }
             float mid = max / 2 + min / 2;
             for (int i = 0; i < positions.Length; i++)
             {
                 positions[i].x = positions[i].x - mid;
             }
             using (var buffer = new PropertyBuffer<vec2>(varNameInShader, 2, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 buffer.Alloc(positions.Length);
                 unsafe
                 {
                     var array = (vec2*)buffer.Header.ToPointer();
                     for (int i = 0; i < positions.Length; i++)
                     { array[i] = positions[i]; }
                 }
                 this.positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return this.positionBufferPtr;
     }
     else
     {
         throw new NotImplementedException();
     }
 }