예제 #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);
        }
예제 #2
0
        static void Render(bool HadInput)
        {
            if (HadInput)
            {
                bool Dirty = true;

                if (FrameBuffered != null)
                {
                    Dirty = false;

                    IntPtr MemoryBuffer = Nuklear.nk_buffer_memory(&Ctx->memory);
                    if ((int)Ctx->memory.allocated == 0)
                    {
                        Dirty = true;
                    }

                    if (!Dirty)
                    {
                        if (LastMemory == null || LastMemory.Length < (int)Ctx->memory.allocated)
                        {
                            LastMemory = new byte[(int)Ctx->memory.allocated];
                            Dirty      = true;
                        }
                    }

                    if (!Dirty)
                    {
                        fixed(byte *LastMemoryPtr = LastMemory)
                        if (MemCmp(new IntPtr(LastMemoryPtr), MemoryBuffer, Ctx->memory.allocated) != 0)
                        {
                            Dirty = true;
                            Marshal.Copy(MemoryBuffer, LastMemory, 0, (int)Ctx->memory.allocated);
                        }
                    }
                }

                if (Dirty)
                {
                    NkConvertResult R = (NkConvertResult)Nuklear.nk_convert(Ctx, Commands, Vertices, Indices, ConvertCfg);
                    if (R != NkConvertResult.Success)
                    {
                        throw new Exception(R.ToString());
                    }

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

                    for (int i = 0; i < NkVerts.Length; i++)
                    {
                        //NkVertex* V = &VertsPtr[i];
                        //NkVerts[i] = new NkVertex() { Position = new NkVector2f() { X = (int)V->Position.X, Y = (int)V->Position.Y }, Color = V->Color, UV = V->UV };

                        NkVerts[i] = VertsPtr[i];
                    }

                    ushort[] NkIndices  = new ushort[(int)Indices->needed / sizeof(ushort)];
                    ushort * IndicesPtr = (ushort *)Indices->memory.ptr;
                    for (int i = 0; i < NkIndices.Length; i++)
                    {
                        NkIndices[i] = IndicesPtr[i];
                    }

                    Dev.SetBuffer(NkVerts, NkIndices);
                    FrameBuffered?.BeginBuffering();

                    uint Offset = 0;
                    Nuklear.nk_draw_foreach(Ctx, Commands, (Cmd) => {
                        if (Cmd->elem_count == 0)
                        {
                            return;
                        }

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

                    FrameBuffered?.EndBuffering();
                }

                Nuklear.nk_clear(Ctx);
            }

            FrameBuffered?.RenderFinal();
        }