當前位置: 首頁>>代碼示例>>C#>>正文


C# OpenGL.BufferData方法代碼示例

本文整理匯總了C#中SharpGL.OpenGL.BufferData方法的典型用法代碼示例。如果您正苦於以下問題:C# OpenGL.BufferData方法的具體用法?C# OpenGL.BufferData怎麽用?C# OpenGL.BufferData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SharpGL.OpenGL的用法示例。


在下文中一共展示了OpenGL.BufferData方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CreateVertexNormalBuffer

        public uint CreateVertexNormalBuffer(OpenGL gl)
        {
            Vertex[] verts = new Vertex[VertexCount * 2];
            int count = 0;

            float ds = 1.0f / Slices;
            float dt = 1.0f / Stacks;

            // The upper bounds in these loops are tweaked to reduce the
            // chance of precision error causing an incorrect # of iterations.

            for (float s = 0; s < 1 - ds / 2; s += ds)
            {
                for (float t = 0; t < 1 - dt / 2; t += dt)
                {
                    const float E = 0.01f;
                    Vertex p = EvaluateTrefoil(s, t);
                    Vertex u = EvaluateTrefoil(s + E, t) - p;
                    Vertex v = EvaluateTrefoil(s, t + E) - p;
                    Vertex n = u.VectorProduct(v);
                    n.Normalize();
                    verts[count++] = p;
                    verts[count++] = n;
                }
            }
            
            //  Pin the data.
            GCHandle vertsHandle = GCHandle.Alloc(verts, GCHandleType.Pinned);
            IntPtr vertsPtr = vertsHandle.AddrOfPinnedObject();
            var size = Marshal.SizeOf(typeof(Vertex)) * VertexCount;

            uint[] buffers = new uint[1];
            gl.GenBuffers(1, buffers);
            uint handle = buffers[0];
            gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, handle);
            gl.BufferData(OpenGL.GL_ARRAY_BUFFER, size, vertsPtr, OpenGL.GL_STATIC_DRAW);

            //  Free the data.
            vertsHandle.Free();

            return handle;
        }
開發者ID:mind0n,項目名稱:hive,代碼行數:42,代碼來源:TrefoilKnot.cs

示例2: BufferData

        public void BufferData(OpenGL gl,
            uint[] indices, float[] vertices, float[] normals, 
            float[] ambs, float[] diffs, float[] specs, float[] shinis,
            float[] htColor)
        {
            gl.BindBuffer(_iboTarget, Ibo);
            gl.BufferData(_iboTarget, indices, _usage);

            gl.BindBuffer(_vboTarget, Position);
            gl.BufferData(_vboTarget, vertices, _usage);

            gl.BindBuffer(_vboTarget, Normal);
            gl.BufferData(_vboTarget, normals, _usage);

            gl.BindBuffer(_vboTarget, AmbientMaterial);
            gl.BufferData(_vboTarget, ambs, _usage);

            gl.BindBuffer(_vboTarget, DiffuseMaterial);
            gl.BufferData(_vboTarget, diffs, _usage);

            gl.BindBuffer(_vboTarget, SpecularMaterial);
            gl.BufferData(_vboTarget, specs, _usage);

            gl.BindBuffer(_vboTarget, ShininessValue);
            gl.BufferData(_vboTarget, shinis, _usage);

            gl.BindBuffer(_vboTarget, HTColorId);
            gl.BufferData(_vboTarget, htColor, _usage);
        }
開發者ID:jochemgeussens,項目名稱:sharpgl,代碼行數:29,代碼來源:NMHTBufferGroup.cs

示例3: CreateIndexBuffer

        private uint CreateIndexBuffer(OpenGL gl)
        {
            ushort[] inds = new ushort[IndexCount];
            int count = 0;

            ushort n = 0;
            for (ushort i = 0; i < Slices; i++)
            {
                for (ushort j = 0; j < Stacks; j++)
                {
                    inds[count++] = (ushort)(n + j);
                    inds[count++] = (ushort)(n + (j + 1) % Stacks);
                    inds[count++] = (ushort)((n + j + Stacks) % VertexCount);

                    inds[count++] = (ushort)((n + j + Stacks) % VertexCount);
                    inds[count++] = (ushort)((n + (j + 1) % Stacks) % VertexCount);
                    inds[count++] = (ushort)((n + (j + 1) % Stacks + Stacks) % VertexCount);
                }

                n += (ushort)Stacks;
            }
            
            //  Pin the data.
            GCHandle indsHandle = GCHandle.Alloc(inds, GCHandleType.Pinned);
            IntPtr indsPtr = indsHandle.AddrOfPinnedObject();
            var size = Marshal.SizeOf(typeof(ushort)) * VertexCount;

            uint[] buffers = new uint[1];
            gl.GenBuffers(1, buffers);
            uint handle = buffers[0];
            gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, handle);
            gl.BufferData(OpenGL.GL_ELEMENT_ARRAY_BUFFER, (int)size, indsPtr, OpenGL.GL_STATIC_DRAW);

            //  Free the data.
            indsHandle.Free();

            return handle;
        }
開發者ID:RFExplorer,項目名稱:rfexplorer-1,代碼行數:38,代碼來源:TrefoilKnot.cs

示例4: BufferData

        public void BufferData(OpenGL gl,
            uint[] indices, float[] vertices, float[] colors)
        {
            if (indices != null)
            {
                gl.BindBuffer(_iboTarget, Ibo);
                gl.BufferData(_iboTarget, indices, _usage);
            }

            gl.BindBuffer(_vboTarget, Position);
            gl.BufferData(_vboTarget, vertices, _usage);

            gl.BindBuffer(_vboTarget, ColorValue);
            gl.BufferData(_vboTarget, colors, _usage);
        }
開發者ID:jochemgeussens,項目名稱:sharpgl,代碼行數:15,代碼來源:LinesBufferGroup.cs

示例5: SetBufferData

        public void SetBufferData(OpenGL gl, IEnumerable<TransformationMatrix> transformations, OGLModelUsage usage = OGLModelUsage.StaticRead)
        {
            var transCount = transformations.Count();

            // Validation.
            if(transCount > Math.Pow(2, 24))
            {
                throw new OverflowException(
                    "This shader can't handle more than 2^24 transformations while "+
                    "using 24 bit colors.");
            }

            #region get indices
            var indices = new ushort[transCount];
            for (ushort i = 0; i < indices.Length; i++)
            {
                indices[i] = i; // Do all transformations once.
            }
            #endregion get indices

            #region get transformations array
            var stride = 16; // Transformation matrix is a 4x4 = 16.

            var transformationsArray = new float[transCount * stride];
            for (int i = 0; i < transCount; i++)
            {
                float[] transAsFloats = transformations.ElementAt(i).ResultMatrix.to_array();
                for (int j = 0; j < stride; j++)
                {
                    transformationsArray[i * stride + j] = transAsFloats[j];
                }
            }
            #endregion get transformations array

            #region get color array
            int colorStride = 3;
            var colorArray = new float[transCount * colorStride];

            for (int i = 0; i < transCount; i++)
            {
                ulong id = transformations.ElementAt(i).UniqueId;
                var color = new ColorF((uint) id);

                colorArray[i * stride] = color.R;
                colorArray[i * stride + 1] = color.G;
                colorArray[i * stride + 2] = color.B;
            }
            #endregion get color array

            gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, _indicesBufferId.Value);
            gl.BufferData(OpenGL.GL_ARRAY_BUFFER, indices, (uint)usage);
            gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, _transformationsBufferId.Value);
            gl.BufferData(OpenGL.GL_ARRAY_BUFFER, transformationsArray, (uint)usage);
            gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, _colorsBufferId.Value);
            gl.BufferData(OpenGL.GL_ARRAY_BUFFER, colorArray, (uint)usage);
        }
開發者ID:jochemgeussens,項目名稱:OpenGLHelper-Using-SharpGL,代碼行數:56,代碼來源:ShaderBoundingBox.cs

示例6: SetBufferData

        /// <summary>
        /// Calls the glBufferData(...). The size will be used as value for Size property.
        /// </summary>
        /// <param name="gl">The gl.</param>
        /// <param name="target">The buffer data target.</param>
        /// <param name="size">The size of the data buffer.</param>
        /// <param name="data">The pointer to the data in memory.</param>
        /// <param name="usage">The usage.</param>
        public virtual void SetBufferData(OpenGL gl, OGLBufferDataTarget target, int size, IntPtr data, OGLModelUsage usage, int stride, OGLType bufferDataType,
            bool bind = false, OGLBindBufferTarget bindTarget = OGLBindBufferTarget.ArrayBuffer)
        {
            Size = size / stride;
            Stride = stride;

            if(bind)
                BindBuffer(gl, bindTarget);
            gl.BufferData((uint)target, size, data, (uint)usage);
        }
開發者ID:jochemgeussens,項目名稱:OpenGLHelper-Using-SharpGL,代碼行數:18,代碼來源:OGLBufferObject.cs


注:本文中的SharpGL.OpenGL.BufferData方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。