示例#1
0
文件: VBO.cs 项目: Keilerr/csat
        public void DataToVBO(Vertex[] vertices, ushort[] indices, VertexMode mode)
        {
            if (numOfIndices > 0)
            {
                Dispose();
            }
            int size;

            vertexFlags  = mode;
            numOfIndices = indices.Length;
            Vertex.Size  = BlittableValueType.StrideOf(vertices);

            GL.GenBuffers(1, out vertexID);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vertexID);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * Vertex.Size), vertices, usage);
            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (vertices.Length * BlittableValueType.StrideOf(vertices) != size)
            {
                Log.Error("DataToVBO: Vertex data not uploaded correctly");
            }

            GL.GenBuffers(1, out indexID);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexID);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(ushort)), indices, usage);
            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (indices.Length * sizeof(short) != size)
            {
                throw new ApplicationException("DataToVBO: Element data not uploaded correctly");
            }

            Shader = GLSLShader.Load();

            if (Shader != null)
            {
                if (Settings.UseGL3)
                {
                    GL.GenVertexArrays(1, out vaoID);
                    GL.BindVertexArray(vaoID);
                }
                GL.BindBuffer(BufferTarget.ArrayBuffer, vertexID);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexID);
                Shader.SetAttributes();
                if (Settings.UseGL3)
                {
                    GL.BindVertexArray(0);
                }
            }

            GLExt.CheckGLError("DataToVBO");
        }
示例#2
0
文件: VBO.cs 项目: bosoni/csat
        public void DataToVBO(Vertex[] vertices, ushort[] indices, VertexMode mode)
        {
            if (numOfIndices > 0) Dispose();
            int size;
            vertexFlags = mode;
            numOfIndices = indices.Length;
            Vertex.Size = BlittableValueType.StrideOf(vertices);

            GL.GenBuffers(1, out vertexID);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vertexID);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * Vertex.Size), vertices, usage);
            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (vertices.Length * BlittableValueType.StrideOf(vertices) != size) Log.Error("DataToVBO: Vertex data not uploaded correctly");

            GL.GenBuffers(1, out indexID);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexID);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(ushort)), indices, usage);
            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (indices.Length * sizeof(short) != size) throw new ApplicationException("DataToVBO: Element data not uploaded correctly");

            Shader = GLSLShader.Load();

            if (Shader != null)
            {
                if (Settings.UseGL3)
                {
                    GL.GenVertexArrays(1, out vaoID);
                    GL.BindVertexArray(vaoID);
                }
                GL.BindBuffer(BufferTarget.ArrayBuffer, vertexID);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexID);
                Shader.SetAttributes();
                if (Settings.UseGL3) GL.BindVertexArray(0);
            }

            GLExt.CheckGLError("DataToVBO");
        }