public virtual void ReplaceBufferData(OpenGL gl, OGLBufferDataTarget target, int offset, int size, IntPtr newData,
                                       bool bind = false, OGLBindBufferTarget bindTarget = OGLBindBufferTarget.ArrayBuffer)
 {
     if (bind)
     {
         BindBuffer(gl, bindTarget);
     }
     gl.BufferSubData((uint)target, offset, size, newData);
 }
Ejemplo n.º 2
0
        private void FlushVertexArray(OpenGL gl, int vertexCount, int triangleCount)
        {
            if (vertexCount == 0 || triangleCount == 0)
            {
                return;
            }

            gl.PushMatrix();

            gl.Translate(0, -300, 0);

            var bufferArrayData = vertexArray;

            gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, _vertexBuffer);

            if (_bufferSize < sizeof(float) * vertexCount * 8)
            {
                gl.BufferData(
                    OpenGL.GL_ARRAY_BUFFER,
                    sizeof(float) * vertexCount * 8,
                    Marshal.UnsafeAddrOfPinnedArrayElement(bufferArrayData, 0),
                    OpenGL.GL_DYNAMIC_DRAW);
            }
            else
            {
                gl.BufferSubData(
                    OpenGL.GL_ARRAY_BUFFER,
                    0,
                    sizeof(float) * vertexCount * 8,
                    Marshal.UnsafeAddrOfPinnedArrayElement(bufferArrayData, 0));
            }

            _bufferSize = Math.Max(sizeof(float) * vertexCount * 8, _bufferSize);

            gl.EnableClientState(OpenGL.GL_VERTEX_ARRAY);
            gl.EnableClientState(OpenGL.GL_COLOR_ARRAY);
            gl.EnableClientState(OpenGL.GL_TEXTURE_COORD_ARRAY);

            gl.VertexPointer(2, OpenGL.GL_FLOAT, 8 * sizeof(float), (IntPtr)0);
            gl.ColorPointer(4, OpenGL.GL_FLOAT, 8 * sizeof(float), (IntPtr)(2 * sizeof(float)));
            gl.TexCoordPointer(2, OpenGL.GL_FLOAT, 8 * sizeof(float), (IntPtr)(6 * sizeof(float)));

            gl.DrawElements(
                OpenGL.GL_TRIANGLES, triangleCount,
                OpenGL.GL_UNSIGNED_SHORT,
                Marshal.UnsafeAddrOfPinnedArrayElement(triangles, 0));

            gl.DisableClientState(OpenGL.GL_VERTEX_ARRAY);
            gl.DisableClientState(OpenGL.GL_COLOR_ARRAY);
            gl.DisableClientState(OpenGL.GL_TEXTURE_COORD_ARRAY);

            gl.PopMatrix();
        }
Ejemplo n.º 3
0
        public static void SetArraySubData(OpenGL gl, float[] data, int sizeInBytes)
        {
            unsafe
            {
                fixed(float *pointerToData = data)
                {
                    IntPtr pointerToVerticesData = new IntPtr((void *)pointerToData);

                    gl.BufferSubData(OpenGL.GL_ARRAY_BUFFER, 0, sizeInBytes, pointerToVerticesData);
                }
            }
        }
Ejemplo n.º 4
0
        protected void Flush()
        {
            if (indexCount == 0)
            {
                return;
            }

            currTexture.Bind(gl);

            using (var handle = new DisposableGCHandle(vertices, GCHandleType.Pinned))
            {
                gl.BufferSubData(GL_ARRAY_BUFFER, 0, vertexCount * VertexPosTexColor.SizeOf, handle.AddrOfPinnedObject());
            }

            using (var handle = new DisposableGCHandle(indices, GCHandleType.Pinned))
            {
                gl.BufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, indexCount * sizeof(int), handle.AddrOfPinnedObject());
            }

            gl.DrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, new IntPtr(0));

            vertexCount = 0;
            indexCount  = 0;
        }