예제 #1
0
        protected BufferObject InitializeArrayBuffer(uint index, int components, VertexAttribPointerType type, bool normalized,
                                                     int stride, int offset, BufferUsageHint hint)
        {
            if (index < 0 || index >= ArrayBufferObjects.Length)
            {
                throw new IndexOutOfRangeException(
                          "Index must be within range of the number of array buffer objects for this vertex buffer!");
            }

            if (ArrayBufferObjects[index] != null)
            {
                throw new InvalidOperationException(
                          string.Format("ArrayBuffer {0} was already initialized for this vertex buffer!", index));
            }

            GLError.Begin();

            BufferObject buffer = new BufferObject(BufferTarget.ArrayBuffer, hint);

            buffer.Bind();
            GL.VertexAttribPointer(index, components, type, normalized, stride, new IntPtr(offset));
            GL.EnableVertexAttribArray(index);

            ErrorCode err = GLError.End();

            if (err != ErrorCode.NoError)
            {
                throw new Exception(string.Format("Failed to initialize array buffer: {0}", err));
            }

            ArrayBufferObjects[index] = buffer;
            return(buffer);
        }
예제 #2
0
        public Mesh(BufferUsageHint usageHint, int numArrayBuffers)
        {
            BufferUsage = usageHint;
            BeginMode   = BeginMode.Triangles;

            VAO = GManager.GenVertexArray();
            ArrayBufferObjects = new BufferObject[numArrayBuffers];
        }
예제 #3
0
        protected BufferObject InitializeElementBuffer(BufferUsageHint hint)
        {
            if (ElementBuffer != null)
            {
                throw new InvalidOperationException("This vertex buffer already has an element buffer!");
            }

            ElementBuffer = new BufferObject(BufferTarget.ElementArrayBuffer, hint);
            ElementBuffer.Bind();
            return(ElementBuffer);
        }