예제 #1
0
        public void DrawPrimitives(PrimitiveType primitiveType, int vertexStart, int primitiveCount)
        {
            // Flush the GL state before moving on!
            ApplyState();

            // Set up the vertex buffers.
            for (int i = 0; i < vertexBufferCount; i += 1)
            {
                GLDevice.BindVertexBuffer(
                    vertexBufferBindings[i].VertexBuffer.Handle
                    );
                vertexBufferBindings[i].VertexBuffer.VertexDeclaration.Apply(
                    VertexShader,
                    (IntPtr)(
                        vertexBufferBindings[i].VertexBuffer.VertexDeclaration.VertexStride *
                        vertexBufferBindings[i].VertexOffset
                        )
                    );
            }

            // Enable the appropriate vertex attributes.
            GLDevice.FlushGLVertexAttributes();

            // Draw!
            GLDevice.glDrawArrays(
                PrimitiveTypeGL(primitiveType),
                vertexStart,
                GetElementCountArray(primitiveType, primitiveCount)
                );
        }
예제 #2
0
        public void DrawUserPrimitives <T>(
            PrimitiveType primitiveType,
            T[] vertexData,
            int vertexOffset,
            int primitiveCount,
            VertexDeclaration vertexDeclaration
            ) where T : struct
        {
            // Flush the GL state before moving on!
            ApplyState();

            // Unbind current VBOs.
            GLDevice.BindVertexBuffer(OpenGLDevice.OpenGLVertexBuffer.NullBuffer);

            // Pin the buffers.
            GCHandle vbHandle = GCHandle.Alloc(vertexData, GCHandleType.Pinned);

            // Setup the vertex declaration to point at the VB data.
            vertexDeclaration.GraphicsDevice = this;
            vertexDeclaration.Apply(VertexShader, vbHandle.AddrOfPinnedObject());

            // Enable the appropriate vertex attributes.
            GLDevice.FlushGLVertexAttributes();

            // Draw!
            GLDevice.glDrawArrays(
                PrimitiveTypeGL(primitiveType),
                vertexOffset,
                GetElementCountArray(primitiveType, primitiveCount)
                );

            // Release the handles.
            vbHandle.Free();
        }