예제 #1
0
        protected override void Draw(List <GizmoPoint> gizmoData)
        {
            if (gizmoData.Count == 0)
            {
                return;
            }

            if (data.Length < gizmoData.Count * 3)
            {
                Array.Resize(ref data, gizmoData.Count * 3);
            }

            int dataIndex = 0;

            for (int i = 0; i < gizmoData.Count; i++)
            {
                GizmoPoint gizmo = gizmoData[i];
                data[dataIndex++] = gizmo.Point.x;
                data[dataIndex++] = gizmo.Point.y;
                data[dataIndex++] = gizmo.Point.z;
            }

            //VBO config
            Ogl.BindBuffer(BufferTarget.ArrayBuffer, vbo);
            Ogl.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * dataIndex, data, BufferUsageHint.StreamDraw);

            //VAO config
            Ogl.BindVertexArray(vao);
            Ogl.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, sizeof(float) * 3, 0);
            Ogl.EnableVertexAttribArray(0);

            Ogl.DrawArray(PrimitiveType.Points, 0, gizmoData.Count);
        }
예제 #2
0
        public void CreateDeviceResources()
        {
            vertexBufferSize = 100_000;
            indexBufferSize  = 20_000;

            vao = Ogl.GenVertexArray("Dear IMGUI");
            Ogl.BindVertexArray(vao);

            vertexBuffer = Ogl.GenBuffer("Dear IMGUI - Vertex Buffer");
            indexBuffer  = Ogl.GenBuffer("Dear IMGUI - Index Buffer");

            Ogl.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer);
            Ogl.BufferData(BufferTarget.ArrayBuffer, vertexBufferSize, IntPtr.Zero, BufferUsageHint.DynamicDraw);
            //Ogl.NamedBufferData(vertexBuffer, vertexBufferSize, IntPtr.Zero, BufferUsageHint.DynamicDraw);

            Ogl.BindBuffer(BufferTarget.ElementArrayBuffer, indexBuffer);
            Ogl.BufferData(BufferTarget.ElementArrayBuffer, indexBufferSize, IntPtr.Zero, BufferUsageHint.DynamicDraw);
            //Ogl.NamedBufferData(indexBuffer, indexBufferSize, IntPtr.Zero, BufferUsageHint.DynamicDraw);

            RecreateFontDeviceTexture();

            Shader shader = Shader.CreateShaderWithProgram(imgui_vert, imgui_frag, "ImGUI Shader");

            material = new Material(shader, fontTexture);
            material.LoadMaterial();

            Ogl.VertexArrayVertexBuffer(vao, 0, vertexBuffer, IntPtr.Zero, Unsafe.SizeOf <ImDrawVert>());
            Ogl.VertexArrayElementBuffer(vao, indexBuffer);

            Ogl.EnableVertexArrayAttrib(vao, 0);
            Ogl.VertexArrayAttribBinding(vao, 0, 0);
            Ogl.VertexArrayAttribFormat(vao, 0, 2, VertexAttribType.Float, false, 0);

            Ogl.EnableVertexArrayAttrib(vao, 1);
            Ogl.VertexArrayAttribBinding(vao, 1, 0);
            Ogl.VertexArrayAttribFormat(vao, 1, 2, VertexAttribType.Float, false, 8);

            Ogl.EnableVertexArrayAttrib(vao, 2);
            Ogl.VertexArrayAttribBinding(vao, 2, 0);
            Ogl.VertexArrayAttribFormat(vao, 2, 4, VertexAttribType.UnsignedByte, true, 16);
        }