当前位置: 首页>>代码示例>>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;未经允许,请勿转载。