예제 #1
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);
        }