Пример #1
0
        public void BufferData <T>(int offset, T[] data, BufferUsageHint hint) where T : struct
        {
            //if (data.Length < 1) throw new Exception("Buffer is empty!");
            //if (data.Length == 0) return;

            dataLen = data.Length;

            if (data.Length != 0)
            {
                size = (Marshal.SizeOf(data[0]) * data.Length);
            }

            if (addr == IntPtr.Zero)
            {
                GPUStateMachine.BindBuffer(target, id);

                GL.BufferData(target, (IntPtr)size, data, hint);

                GPUStateMachine.UnbindBuffer(target);
            }
            else
            {
                throw new Exception("This buffer is mapped!");
            }
        }
Пример #2
0
        public void SetBufferObject(int index, GPUBuffer buffer, int elementCount, VertexAttribPointerType type)
        {
            GPUStateMachine.BindVertexArray(id);

            GL.EnableVertexAttribArray(index);
            GPUStateMachine.BindBuffer(buffer.target, buffer.id);
            GL.VertexAttribPointer(index, elementCount, type, false, 0, 0);
            GPUStateMachine.UnbindBuffer(buffer.target);

            GPUStateMachine.UnbindVertexArray();
        }
Пример #3
0
        public GPUBuffer(BufferTarget target, int size, bool read)
        {
            id          = GL.GenBuffer();
            this.target = target;

            this.size = size;

            GPUStateMachine.BindBuffer(target, id);
            GL.BufferStorage(target, (IntPtr)size, IntPtr.Zero, BufferStorageFlags.MapPersistentBit | BufferStorageFlags.MapWriteBit | (read ? BufferStorageFlags.MapReadBit : 0));

            addr = GL.MapBufferRange(target, IntPtr.Zero, (IntPtr)size, BufferAccessMask.MapPersistentBit | BufferAccessMask.MapUnsynchronizedBit | BufferAccessMask.MapInvalidateBufferBit | BufferAccessMask.MapFlushExplicitBit | BufferAccessMask.MapWriteBit | (read ? BufferAccessMask.MapReadBit : 0));
            GPUStateMachine.UnbindBuffer(target);
        }
Пример #4
0
        public static void SetIndexBuffer(GPUBuffer indices)
        {
            if (indices.target != BufferTarget.ElementArrayBuffer)
            {
                throw new ArgumentException("Argument must be an index buffer!");
            }

            if (curIndices != null && indices.id != curIndices.id)
            {
                GPUStateMachine.UnbindBuffer(BufferTarget.ElementArrayBuffer);
            }
            curIndices = indices;
        }
Пример #5
0
 public void MapBuffer(bool read, int offset, int size)
 {
     GPUStateMachine.BindBuffer(target, id);
     addr = GL.MapBufferRange(target, (IntPtr)offset, (IntPtr)size, BufferAccessMask.MapPersistentBit | BufferAccessMask.MapUnsynchronizedBit | BufferAccessMask.MapFlushExplicitBit | BufferAccessMask.MapInvalidateBufferBit | BufferAccessMask.MapWriteBit | (read ? BufferAccessMask.MapReadBit : 0));
     GPUStateMachine.UnbindBuffer(target);
 }
Пример #6
0
 public void UnMapBuffer()
 {
     GPUStateMachine.BindBuffer(target, id);
     GL.UnmapBuffer(target);
     GPUStateMachine.UnbindBuffer(target);
 }
Пример #7
0
        public static void Draw(PrimitiveType type, int first, int count)
        {
            if (count == 0)
            {
                return;
            }

            if (curVarray == null)
            {
                return;
            }
            if (curProg == null)
            {
                return;
            }
            if (curFramebuffer == null)
            {
                return;
            }


            for (int i = 0; i < textures.Count; i++)
            {
                GPUStateMachine.BindTexture(i, textures[i].texTarget, textures[i].id);
            }
            for (int i = 0; i < feedbackBufs.Count; i++)
            {
                GPUStateMachine.BindBuffer(BufferTarget.TransformFeedbackBuffer, feedbackBufs[i].Item1.id, i, (IntPtr)feedbackBufs[i].Item2, (IntPtr)feedbackBufs[i].Item3);
            }



            GPUStateMachine.BindFramebuffer(curFramebuffer.id);
            if (feedbackBufs.Count > 0)
            {
                GL.BeginTransformFeedback((TransformFeedbackPrimitiveType)feedbackPrimitive);
            }

            GL.UseProgram(curProg.id);
            GPUStateMachine.BindVertexArray(curVarray.id);
            if (curIndices != null)
            {
                GPUStateMachine.BindBuffer(BufferTarget.ElementArrayBuffer, curIndices.id);
            }

            if (curIndices != null)
            {
                GL.DrawElements(type, count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            }
            else
            {
                GL.DrawArrays(type, first, count);
            }

            if (feedbackBufs.Count > 0)
            {
                GL.EndTransformFeedback();
            }

            for (int i = 0; i < feedbackBufs.Count; i++)
            {
                GPUStateMachine.UnbindBuffer(BufferTarget.TransformFeedbackBuffer, i);
            }
            for (int i = 0; i < textures.Count; i++)
            {
                GPUStateMachine.UnbindTexture(i, textures[i].texTarget);
            }

            textures.Clear();
            feedbackBufs.Clear();
        }