コード例 #1
0
            public VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader)
            {
                if (bufferName == strPosition)
                {
                    if (positionBufferPtr == null)
                    {
                        using (var buffer = new VertexAttributeBuffer <vec3>(
                                   varNameInShader, VertexAttributeConfig.Vec3, 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();
                        }
                    }

                    return(positionBufferPtr);
                }
                else
                {
                    throw new ArgumentException();
                }
            }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bufferName"></param>
        /// <param name="varNameInShader"></param>
        /// <returns></returns>
        public VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader)
        {
            if (bufferName == position)
            {
                if (positionBufferPtr == null)
                {
                    using (var buffer = new VertexAttributeBuffer <vec3>(
                               varNameInShader, VertexAttributeConfig.Vec3, 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();
                    }
                }
                return(positionBufferPtr);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
コード例 #3
0
 public VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader)
 {
     if (bufferName == strPosition)
     {
         if (positionBuffer == null)
         {
             using (var buffer = new VertexAttributeBuffer <float>(varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.DynamicDraw))
             {
                 buffer.Create(positions.Length);
                 unsafe
                 {
                     var array = (float *)buffer.Header.ToPointer();
                     for (int i = 0; i < positions.Length; i++)
                     {
                         array[i] = positions[i];
                     }
                 }
                 positionBuffer = buffer.GetBufferPtr();
             }
         }
         return(positionBuffer);
     }
     else
     {
         return(null);
     }
 }
コード例 #4
0
        private VertexAttributeBufferPtr GetPositionBufferPtr(string varNameInShader)
        {
            VertexAttributeBufferPtr ptr = null;

            using (var buffer = new VertexAttributeBuffer <HexahedronPosition>(varNameInShader, VertexAttributeConfig.Vec3, 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();
            }

            return(ptr);
        }
コード例 #5
0
 public VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader)
 {
     if (bufferName == strPosition)
     {
         if (positionBuffer == null)
         {
             using (var buffer = new VertexAttributeBuffer <vec4>(varNameInShader, VertexAttributeConfig.Vec4, BufferUsage.DynamicDraw))
             {
                 buffer.Create(this.SideLength * this.SideLength);
                 unsafe
                 {
                     var pointer = (vec4 *)buffer.Header.ToPointer();
                     for (int z = 0; z < this.SideLength; z++)
                     {
                         for (int x = 0; x < this.SideLength; x++)
                         {
                             pointer[x + z * this.SideLength] = new vec4(
                                 -(float)this.SideLength / 2.0f + 0.5f + (float)x,
                                 0.0f,
                                 (float)this.SideLength / 2.0f - 0.5f - (float)z,
                                 1.0f
                                 );
                         }
                     }
                 }
                 positionBuffer = buffer.GetBufferPtr();
             }
         }
         return(positionBuffer);
     }
     else
     {
         throw new System.ArgumentException();
     }
 }
コード例 #6
0
        public VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader)
        {
            if (bufferName == strPosition)
            {
                if (positionBufferPtr == null)
                {
                    using (var buffer = new VertexAttributeBuffer <vec3>(
                               varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw))
                    {
                        buffer.Create(positions.Length);
                        unsafe
                        {
                            var array = (vec3 *)buffer.Header.ToPointer();
                            for (int i = 0; i < positions.Length; i++)
                            {
                                array[i] = positions[i];
                            }
                        }

                        positionBufferPtr = buffer.GetBufferPtr();
                    }
                }
                return(positionBufferPtr);
            }
            else
            {
                throw new ArgumentException();
            }
        }
コード例 #7
0
        protected override void DoInitialize()
        {
            base.DoInitialize();

            {
                // velocity
                var buffer = new VertexAttributeBuffer <vec4>("empty", VertexAttributeConfig.Vec4, BufferUsage.DynamicCopy);
                buffer.Create(ParticleModel.particleCount);
                unsafe
                {
                    var random = new Random();
                    var array  = (vec4 *)buffer.Header.ToPointer();
                    for (int i = 0; i < ParticleModel.particleCount; i++)
                    {
                        array[i] = new vec4(
                            (float)(random.NextDouble() - 0.5) * 0.2f,
                            (float)(random.NextDouble() - 0.5) * 0.2f,
                            (float)(random.NextDouble() - 0.5) * 0.2f,
                            0);
                    }
                }
                var ptr = buffer.GetBufferPtr();
                this.VelocityBufferPtr = ptr;
            }

            this.PositionBufferPtr = this.Model.GetVertexAttributeBufferPtr(ParticleModel.strPosition, null);
        }
コード例 #8
0
        private VertexAttributeBufferPtr GetTexCoordBufferPtr(string varNameInShader)
        {
            VertexAttributeBufferPtr texCoordBufferPtr = null;

            using (var buffer = new VertexAttributeBuffer <float>(
                       varNameInShader, VertexAttributeConfig.Float, BufferUsage.StaticDraw))
            {
                int uCount = GetUCount(interval);
                int vCount = GetVCount(interval);
                buffer.Create(uCount * vCount);
                unsafe
                {
                    int index = 0;
                    var array = (float *)buffer.Header.ToPointer();
                    for (int uIndex = 0; uIndex < uCount; uIndex++)
                    {
                        for (int vIndex = 0; vIndex < vCount; vIndex++)
                        {
                            array[index++] = (float)uIndex / (float)uCount;
                        }
                    }
                }

                texCoordBufferPtr = buffer.GetBufferPtr();

                return(texCoordBufferPtr);
            }
        }
コード例 #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bufferName"></param>
        /// <param name="varNameInShader"></param>
        /// <returns></returns>
        public VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader)
        {
            if (bufferName == position)
            {
                if (positionBufferPtr == null)
                {
                    using (var buffer = new VertexAttributeBuffer <vec3>(
                               varNameInShader, VertexAttributeConfig.Vec3, 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();
                    }
                }
                return(positionBufferPtr);
            }
            else if (bufferName == color)
            {
                if (colorBufferPtr == null)
                {
                    using (var buffer = new VertexAttributeBuffer <vec3>(
                               varNameInShader, VertexAttributeConfig.Vec3, 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();
                    }
                }
                return(colorBufferPtr);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
コード例 #10
0
        private VertexAttributeBufferPtr GetPositionBufferPtr(string varNameInShader)
        {
            VertexAttributeBufferPtr positionBufferPtr = null;

            using (var buffer = new VertexAttributeBuffer <vec3>(
                       varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw))
            {
                bool initialized = false;
                vec3 max         = new vec3();
                vec3 min         = new vec3();
                int  uCount      = GetUCount(interval);
                int  vCount      = GetVCount(interval);
                buffer.Create(uCount * vCount);
                unsafe
                {
                    int index = 0;
                    var array = (vec3 *)buffer.Header.ToPointer();
                    for (int uIndex = 0; uIndex < uCount; uIndex++)
                    {
                        for (int vIndex = 0; vIndex < vCount; vIndex++)
                        {
                            double u        = Math.PI * uIndex / uCount;
                            double v        = Math.PI * 2 * vIndex / vCount;
                            var    position = GetPosition(u, v);

                            if (!initialized)
                            {
                                max         = position;
                                min         = position;
                                initialized = true;
                            }
                            else
                            {
                                position.UpdateMax(ref max);
                                position.UpdateMin(ref min);
                            }
                            array[index++] = position;
                        }
                    }
                    //this.Lengths = max - min;
                    vec3 worldPosition = max / 2.0f + min / 2.0f;
                    for (int i = 0; i < index; i++)
                    {
                        array[i] = array[i] - worldPosition;
                    }
                }

                positionBufferPtr = buffer.GetBufferPtr();

                return(positionBufferPtr);
            }
        }
コード例 #11
0
            public VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader)
            {
                if (bufferName == strposition)
                {
                    if (positionBufferPtr == null)
                    {
                        using (var buffer = new VertexAttributeBuffer <vec3>(
                                   varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw))
                        {
                            buffer.Create(particleCount);
                            unsafe
                            {
                                var array = (vec3 *)buffer.Header.ToPointer();
                                for (int i = 0; i < particleCount; i++)
                                {
                                    if (i % 2 == 0)
                                    {
                                        while (true)
                                        {
                                            var x = (float)(random.NextDouble() * 2 - 1) * factor;
                                            var y = (float)(random.NextDouble() * 2 - 1) * factor;
                                            var z = (float)(random.NextDouble() * 2 - 1) * factor;
                                            if (y < 0 && x * x + y * y + z * z >= factor * factor)
                                            {
                                                array[i] = new vec3(x, y, z);
                                                break;
                                            }
                                        }
                                    }
                                    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)) * factor,
                                            (float)(Math.Sin(theta) * Math.Sin(alpha)) * factor,
                                            (float)(Math.Cos(theta)) * factor);
                                    }
                                }
                            }

                            positionBufferPtr = buffer.GetBufferPtr();
                        }
                    }

                    return(positionBufferPtr);
                }
                else
                {
                    throw new ArgumentException();
                }
            }
コード例 #12
0
 public VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader)
 {
     if (bufferName == strposition)
     {
         if (positionBuffer == null)
         {
             using (var buffer = new VertexAttributeBuffer <float>(varNameInShader, VertexAttributeConfig.Vec3, 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();
             }
         }
         return(positionBuffer);
     }
     else if (bufferName == strcolor)
     {
         if (colorBuffer == null)
         {
             using (var buffer = new VertexAttributeBuffer <float>(varNameInShader, VertexAttributeConfig.Vec3, 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();
             }
         }
         return(colorBuffer);
     }
     else
     {
         return(null);
     }
 }
コード例 #13
0
 public VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader)
 {
     if (bufferName == strposition)
     {
         if (positionBufferPtr == null)
         {
             using (var buffer = new VertexAttributeBuffer <vec3>(varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw))
             {
                 buffer.Create(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();
             }
         }
         return(positionBufferPtr);
     }
     else if (bufferName == struv)
     {
         if (uvBufferPtr == null)
         {
             using (var buffer = new VertexAttributeBuffer <vec2>(varNameInShader, VertexAttributeConfig.Vec2, BufferUsage.StaticDraw))
             {
                 buffer.Create(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();
             }
         }
         return(uvBufferPtr);
     }
     else
     {
         throw new NotImplementedException();
     }
 }
コード例 #14
0
ファイル: Square.cs プロジェクト: hhxx1314/CSharpGL
 /// <summary>
 ///
 /// </summary>
 /// <param name="bufferName"></param>
 /// <param name="varNameInShader"></param>
 /// <returns></returns>
 public VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader)
 {
     if (bufferName == strPosition)
     {
         if (positionBufferPtr == null)
         {
             using (var buffer = new VertexAttributeBuffer <vec3>(varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw))
             {
                 buffer.Create(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();
             }
         }
         return(positionBufferPtr);
     }
     else if (bufferName == strTexCoord)
     {
         if (uvBufferPtr == null)
         {
             using (var buffer = new VertexAttributeBuffer <vec2>(varNameInShader, VertexAttributeConfig.Vec2, BufferUsage.StaticDraw))
             {
                 buffer.Create(model.texCoords.Length);
                 unsafe
                 {
                     var array = (vec2 *)buffer.Header.ToPointer();
                     for (int i = 0; i < model.texCoords.Length; i++)
                     {
                         array[i] = model.texCoords[i];
                     }
                 }
                 uvBufferPtr = buffer.GetBufferPtr();
             }
         }
         return(uvBufferPtr);
     }
     else
     {
         return(null);
     }
 }
コード例 #15
0
        private VertexAttributeBufferPtr GetColorBufferPtr(string varNameInShader)
        {
            VertexAttributeBufferPtr ptr = null;

            using (var buffer = new VertexAttributeBuffer <HexahedronTexCoord>(varNameInShader, VertexAttributeConfig.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();
            }

            return(ptr);
        }
コード例 #16
0
ファイル: WellModel.cs プロジェクト: hhxx1314/CSharpGL
        public unsafe VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader)
        {
            if (bufferName == strPosition)
            {
                if (positionBufferPtr != null)
                {
                    return(positionBufferPtr);
                }

                using (var buffer = new VertexAttributeBuffer <vec3>(varNameInShader, VertexAttributeConfig.Vec3, 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();
                }

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

                using (var buffer = new VertexAttributeBuffer <vec3>(varNameInShader, VertexAttributeConfig.Vec3, 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();
                }

                return(brightnessBufferPtr);
            }
            else
            {
                throw new ArgumentException();
            }
        }
コード例 #17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="bufferName"></param>
 /// <param name="varNameInShader"></param>
 /// <returns></returns>
 public VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader)
 {
     if (bufferName == strPosition)
     {
         if (positionBufferPtr == null)
         {
             using (var buffer = new VertexAttributeBuffer <float>(varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw))
             {
                 float[] positions = model.GetPositions();
                 //List<vec3> pos = new List<vec3>();
                 //for (int i = 0; i < positions.Length; i += 3)
                 //{
                 //    pos.Add(new vec3(positions[i], positions[i + 1], positions[i + 2]));
                 //}
                 //IBoundingBox box = pos.Move2Center();
                 //vec3 lengths = box.MaxPosition - box.MinPosition;
                 buffer.Create(positions.Length);
                 unsafe
                 {
                     var array = (float *)buffer.Header.ToPointer();
                     for (int i = 0; i < positions.Length; i++)
                     {
                         array[i] = positions[i];
                     }
                 }
                 positionBufferPtr = buffer.GetBufferPtr();
             }
         }
         return(positionBufferPtr);
     }
     else if (bufferName == strColor)
     {
         if (colorBufferPtr == null)
         {
             using (var buffer = new VertexAttributeBuffer <float>(varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw))
             {
                 float[] normals = model.GetNormals();
                 buffer.Create(normals.Length);
                 unsafe
                 {
                     var array = (float *)buffer.Header.ToPointer();
                     for (int i = 0; i < normals.Length; i++)
                     {
                         array[i] = normals[i];
                     }
                 }
                 colorBufferPtr = buffer.GetBufferPtr();
             }
         }
         return(colorBufferPtr);
     }
     else if (bufferName == strNormal)
     {
         if (normalBufferPtr == null)
         {
             using (var buffer = new VertexAttributeBuffer <float>(varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw))
             {
                 float[] normals = model.GetNormals();
                 buffer.Create(normals.Length);
                 unsafe
                 {
                     var array = (float *)buffer.Header.ToPointer();
                     for (int i = 0; i < normals.Length; i++)
                     {
                         array[i] = normals[i];
                     }
                 }
                 normalBufferPtr = buffer.GetBufferPtr();
             }
         }
         return(normalBufferPtr);
     }
     else
     {
         return(null);
     }
 }
コード例 #18
0
ファイル: PlaneModel.cs プロジェクト: hhxx1314/CSharpGL
        public VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader)
        {
            if (bufferName == strPosition)
            {
                if (positionBufferPtr == null)
                {
                    using (var buffer = new VertexAttributeBuffer <float>(
                               varNameInShader, VertexAttributeConfig.Vec4, BufferUsage.StaticDraw))
                    {
                        buffer.Create(xy_vertices.Length);
                        unsafe
                        {
                            var array = (float *)buffer.Header.ToPointer();
                            for (int i = 0; i < xy_vertices.Length; i++)
                            {
                                array[i] = xy_vertices[i] * this.halfExtent;
                            }
                        }

                        positionBufferPtr = buffer.GetBufferPtr();
                    }
                }
                return(positionBufferPtr);
            }
            else if (bufferName == strNormal)
            {
                if (normalBufferPtr == null)
                {
                    using (var buffer = new VertexAttributeBuffer <float>(
                               varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw))
                    {
                        buffer.Create(xy_normals.Length);
                        unsafe
                        {
                            var array = (float *)buffer.Header.ToPointer();
                            for (int i = 0; i < xy_normals.Length; i++)
                            {
                                array[i] = xy_normals[i];
                            }
                        }

                        normalBufferPtr = buffer.GetBufferPtr();
                    }
                }
                return(normalBufferPtr);
            }
            else if (bufferName == strTangent)
            {
                if (tangentBufferPtr == null)
                {
                    using (var buffer = new VertexAttributeBuffer <float>(
                               varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw))
                    {
                        buffer.Create(xy_tangents.Length);
                        unsafe
                        {
                            var array = (float *)buffer.Header.ToPointer();
                            for (int i = 0; i < xy_tangents.Length; i++)
                            {
                                array[i] = xy_tangents[i];
                            }
                        }

                        tangentBufferPtr = buffer.GetBufferPtr();
                    }
                }
                return(tangentBufferPtr);
            }
            else if (bufferName == strTexCoord)
            {
                if (texCoordBufferPtr == null)
                {
                    using (var buffer = new VertexAttributeBuffer <float>(
                               varNameInShader, VertexAttributeConfig.Vec2, BufferUsage.StaticDraw))
                    {
                        buffer.Create(xy_texCoords.Length);
                        unsafe
                        {
                            var array = (float *)buffer.Header.ToPointer();
                            for (int i = 0; i < xy_texCoords.Length; i++)
                            {
                                array[i] = xy_texCoords[i];
                            }
                        }

                        texCoordBufferPtr = buffer.GetBufferPtr();
                    }
                }
                return(texCoordBufferPtr);
            }
            else
            {
                throw new ArgumentException();
            }
        }
コード例 #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bufferName"></param>
        /// <param name="varNameInShader"></param>
        /// <returns></returns>
        public VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader)
        {
            if (bufferName == strPosition)
            {
                if (positionBufferPtr == null)
                {
                    using (var buffer = new VertexAttributeBuffer <vec3>(varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw))
                    {
                        buffer.Create(TetrahedronModel.position.Length);
                        unsafe
                        {
                            var array = (vec3 *)buffer.Header.ToPointer();
                            for (int i = 0; i < TetrahedronModel.position.Length; i++)
                            {
                                array[i] = TetrahedronModel.position[i];
                            }
                        }

                        positionBufferPtr = buffer.GetBufferPtr();
                    }
                }
                return(positionBufferPtr);
            }
            else if (bufferName == strColor)
            {
                if (colorBufferPtr == null)
                {
                    using (var buffer = new VertexAttributeBuffer <vec3>(varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw))
                    {
                        buffer.Create(TetrahedronModel.color.Length);
                        unsafe
                        {
                            var array = (vec3 *)buffer.Header.ToPointer();
                            for (int i = 0; i < TetrahedronModel.color.Length; i++)
                            {
                                array[i] = TetrahedronModel.color[i];
                            }
                        }

                        colorBufferPtr = buffer.GetBufferPtr();
                    }
                }
                return(colorBufferPtr);
            }
            else if (bufferName == strNormal)
            {
                if (normalBufferPtr == null)
                {
                    using (var buffer = new VertexAttributeBuffer <vec3>(varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw))
                    {
                        buffer.Create(TetrahedronModel.normal.Length);
                        unsafe
                        {
                            var array = (vec3 *)buffer.Header.ToPointer();
                            for (int i = 0; i < TetrahedronModel.normal.Length; i++)
                            {
                                array[i] = TetrahedronModel.normal[i];
                            }
                        }

                        normalBufferPtr = buffer.GetBufferPtr();
                    }
                }
                return(normalBufferPtr);
            }
            else
            {
                return(null);
            }
        }
コード例 #20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bufferName"></param>
        /// <param name="varNameInShader"></param>
        /// <returns></returns>
        public VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader)
        {
            if (bufferName == strPosition)
            {
                if (positionBufferPtr == null)
                {
                    using (var buffer = new VertexAttributeBuffer <CubeModel.CubePosition>(varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw))
                    {
                        buffer.Create(1);
                        unsafe
                        {
                            var positionArray = (CubeModel.CubePosition *)buffer.Header.ToPointer();
                            positionArray[0] = CubeModel.position;
                        }
                        unsafe
                        {
                            var positionArray = (vec3 *)buffer.Header.ToPointer();
                            for (int i = 0; i < 24; i++)
                            {
                                positionArray[i] = positionArray[i] / 2 * Lengths;
                            }
                        }

                        positionBufferPtr = buffer.GetBufferPtr();
                    }
                }
                return(positionBufferPtr);
            }
            else if (bufferName == strColor)
            {
                if (colorBufferPtr == null)
                {
                    using (var buffer = new VertexAttributeBuffer <CubeModel.CubeColor>(varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw))
                    {
                        buffer.Create(1);
                        unsafe
                        {
                            var colorArray = (CubeModel.CubeColor *)buffer.Header.ToPointer();
                            colorArray[0] = CubeModel.color;
                        }

                        colorBufferPtr = buffer.GetBufferPtr();
                    }
                }
                return(colorBufferPtr);
            }
            else if (bufferName == strNormal)
            {
                if (normalBufferPtr == null)
                {
                    using (var buffer = new VertexAttributeBuffer <CubeModel.CubeNormal>(varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw))
                    {
                        buffer.Create(1);
                        unsafe
                        {
                            var normalArray = (CubeModel.CubeNormal *)buffer.Header.ToPointer();
                            normalArray[0] = CubeModel.normal;
                        }

                        normalBufferPtr = buffer.GetBufferPtr();
                    }
                }
                return(normalBufferPtr);
            }
            else
            {
                return(null);
            }
        }
コード例 #21
0
ファイル: ParticleModel.cs プロジェクト: hhxx1314/CSharpGL
        public VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader)
        {
            if (bufferName == strPosition)
            {
                if (positionBufferPtr == null)
                {
                    using (var buffer = new VertexAttributeBuffer <vec4>(
                               varNameInShader, VertexAttributeConfig.Vec4, BufferUsage.DynamicCopy))
                    {
                        buffer.Create(particleCount);
                        unsafe
                        {
                            var array = (vec4 *)buffer.Header.ToPointer();
                            for (int i = 0; i < particleCount; i++)
                            {
                                array[i] = new vec4(
                                    (float)(random.NextDouble() - 0.5) * 20,
                                    (float)(random.NextDouble() - 0.5) * 20,
                                    (float)(random.NextDouble() - 0.5) * 20,
                                    (float)(random.NextDouble())
                                    );
                            }
                        }

                        positionBufferPtr = buffer.GetBufferPtr();
                    }
                }

                return(positionBufferPtr);
            }
            else if (bufferName == strVelocity)
            {
                if (velocityBufferPtr == null)
                {
                    using (var buffer = new VertexAttributeBuffer <vec4>(
                               varNameInShader, VertexAttributeConfig.Vec4, BufferUsage.DynamicCopy))
                    {
                        buffer.Create(particleCount);
                        unsafe
                        {
                            var array = (vec4 *)buffer.Header.ToPointer();
                            for (int i = 0; i < particleCount; i++)
                            {
                                array[i] = new vec4(
                                    (float)(random.NextDouble() - 0.5) * 0.2f,
                                    (float)(random.NextDouble() - 0.5) * 0.2f,
                                    (float)(random.NextDouble() - 0.5) * 0.2f,
                                    0
                                    );
                            }
                        }

                        velocityBufferPtr = buffer.GetBufferPtr();
                    }
                }

                return(velocityBufferPtr);
            }
            else
            {
                throw new ArgumentException();
            }
        }