Ejemplo n.º 1
0
        public VBO LoadVBO <TVertex>(TVertex[] vertices, uint[] elements, InterleavedArrayFormat format) where TVertex : struct
        {
            var handle = new VBO {
                VertexFormat = format
            };

            // To create a VBO:
            // 1) Generate the buffer handles for the vertex and element buffers.
            // 2) Bind the vertex buffer handle and upload your vertex data. Check that the buffer was uploaded correctly.
            // 3) Bind the element buffer handle and upload your element data. Check that the buffer was uploaded correctly.

            GL.GenBuffers(1, out handle.VboID);
            GL.BindBuffer(BufferTarget.ArrayBuffer, handle.VboID);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * BlittableValueType.StrideOf(vertices)),
                          vertices,
                          BufferUsageHint.StaticDraw);
            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out int size);
            if (vertices.Length * BlittableValueType.StrideOf(vertices) != size)
            {
                throw new ApplicationException("Vertex data not uploaded correctly");
            }

            GL.GenBuffers(1, out handle.EboID);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, handle.EboID);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(elements.Length * sizeof(uint)), elements,
                          BufferUsageHint.StaticDraw);
            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (elements.Length * sizeof(uint) != size)
            {
                throw new ApplicationException("Element data not uploaded correctly");
            }

            handle.NumElements = elements.Length;
            return(handle);
        }
Ejemplo n.º 2
0
        public void Paint(bool showTexture, InterleavedArrayFormat vertexFormat, int numElements)
        {
            //DEM.SurfaceLines = true;
            if (false)
            {
                GL.Disable(EnableCap.Lighting);
                GL.Begin(BeginMode.Lines);
                GL.Color3(Color.Beige);
                var pt1 = Patch.Points[0][0] * Kilometers;
                var pt2 = Patch.Points[127][0] * Kilometers;
                var pt3 = Patch.Points[127][127] * Kilometers;
                var pt4 = Patch.Points[0][127] * Kilometers;

                GL.Vertex3(pt1.X, pt1.Y, pt1.Z);
                GL.Vertex3(pt2.X, pt2.Y, pt2.Z);

                GL.Vertex3(pt2.X, pt2.Y, pt2.Z);
                GL.Vertex3(pt3.X, pt3.Y, pt3.Z);

                GL.Vertex3(pt3.X, pt3.Y, pt3.Z);
                GL.Vertex3(pt4.X, pt4.Y, pt4.Z);

                GL.Vertex3(pt4.X, pt4.Y, pt4.Z);
                GL.Vertex3(pt1.X, pt1.Y, pt1.Z);

                GL.End();
                GL.Enable(EnableCap.Lighting);
            }

            if (VertexHandle > 0)
            {
                GL.Disable(EnableCap.Lighting);
                GL.Color3(Color);
                GL.BindBuffer(BufferTarget.ArrayBuffer, VertexHandle);
                GL.InterleavedArrays(vertexFormat, 0, IntPtr.Zero);       // Can this go outside the loop?

                if (TextureHandle > 0)
                {
                    GL.Enable(EnableCap.Texture2D);
                    GL.BindTexture(TextureTarget.Texture2D, TextureHandle);
                }

                if (!DEM.SurfaceLines)
                {
                    GL.DrawElements(showTexture ? BeginMode.Triangles : BeginMode.LineStrip,
                                    numElements, DrawElementsType.UnsignedInt, IntPtr.Zero);
                }
                else
                {
                    //   GL.DrawElements(BeginMode.Triangles, numElements, DrawElementsType.UnsignedInt, IntPtr.Zero);
                    //   GL.DepthFunc(DepthFunction.Lequal);

                    GL.Disable(EnableCap.Lighting);
                    GL.Color3(1f, 1f, 0f);
                    GL.DrawElements(BeginMode.LineStrip, numElements, DrawElementsType.UnsignedInt, IntPtr.Zero);
                    GL.DepthFunc(DepthFunction.Less);
                    GL.Enable(EnableCap.Lighting);
                }

                if (TextureHandle > 0)
                {
                    GL.Disable(EnableCap.Texture2D);
                }
                GL.Enable(EnableCap.Lighting);
            }
            else
            {
                Console.WriteLine($"Paint: no vertices for {Patch}]");
            }
        }
Ejemplo n.º 3
0
 public MoonDEM()
 {
     VertexFormat = InterleavedArrayFormat.T2fN3fV3f;
 }
Ejemplo n.º 4
0
 internal static extern void glInterleavedArrays(InterleavedArrayFormat format, Int32 stride, IntPtr pointer);
Ejemplo n.º 5
0
		internal static extern void glInterleavedArrays(InterleavedArrayFormat format, Int32 stride, IntPtr pointer);
Ejemplo n.º 6
0
		public static void InterleavedArrays(InterleavedArrayFormat format, Int32 stride, Object pointer)
		{
			GCHandle pin_pointer = GCHandle.Alloc(pointer, GCHandleType.Pinned);
			try {
				InterleavedArrays(format, stride, pin_pointer.AddrOfPinnedObject());
			} finally {
				pin_pointer.Free();
			}
		}
Ejemplo n.º 7
0
		public static void InterleavedArrays(InterleavedArrayFormat format, Int32 stride, IntPtr pointer)
		{
			Debug.Assert(Delegates.pglInterleavedArrays != null, "pglInterleavedArrays not implemented");
			Delegates.pglInterleavedArrays((Int32)format, stride, pointer);
			LogFunction("glInterleavedArrays({0}, {1}, 0x{2})", format, stride, pointer.ToString("X8"));
			DebugCheckErrors(null);
		}
Ejemplo n.º 8
0
 public static void glInterleavedArrays(InterleavedArrayFormat format, Int32 stride, IntPtr pointer)
 {
     i_OpenGL1_1.glInterleavedArrays(format, stride, pointer);
 }
Ejemplo n.º 9
0
 public static unsafe extern void InterleavedArrays( InterleavedArrayFormat format, int stride, void* pointer );