Exemple #1
0
        public static void Render()
        {
            nk_buffer Cmds, Verts, Idx;

            Nuklear.nk_buffer_init(&Cmds, Allocator, new IntPtr(4 * 1024));
            Nuklear.nk_buffer_init(&Verts, Allocator, new IntPtr(4 * 1024));
            Nuklear.nk_buffer_init(&Idx, Allocator, new IntPtr(4 * 1024));
            nk_convert_result R = (nk_convert_result)Nuklear.nk_convert(Ctx, &Cmds, &Verts, &Idx, ConvertCfg);

            if (R != nk_convert_result.NK_CONVERT_SUCCESS)
            {
                throw new Exception(R.ToString());
            }

            NkVertex[] NkVerts  = new NkVertex[(int)Verts.needed / sizeof(NkVertex)];
            NkVertex * VertsPtr = (NkVertex *)Verts.memory.ptr;

            for (int i = 0; i < NkVerts.Length; i++)
            {
                NkVerts[i] = VertsPtr[i];
            }

            ushort[] NkIndices  = new ushort[(int)Idx.needed / sizeof(ushort)];
            ushort * IndicesPtr = (ushort *)Idx.memory.ptr;

            for (int i = 0; i < NkIndices.Length; i++)
            {
                NkIndices[i] = IndicesPtr[i];
            }

            uint Offset = 0;

            Nuklear.nk_draw_foreach(Ctx, &Cmds, (Cmd) => {
                if (Cmd->elem_count == 0)
                {
                    return;
                }

                Dev.Render(Cmd->userdata, Cmd->texture.id, Cmd->clip_rect, Offset, Cmd->elem_count, NkVerts, NkIndices);
                Offset += Cmd->elem_count;
            });

            Nuklear.nk_buffer_free(&Cmds);
            Nuklear.nk_buffer_free(&Verts);
            Nuklear.nk_buffer_free(&Idx);
            Nuklear.nk_clear(Ctx);
        }