예제 #1
0
 public NkVertex(NkVector2f position, NkVector2f uv, NkColor color)
 {
     Position = position;
     UV       = uv;
     Color    = color;
 }
예제 #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;

                    NkVector2f[] positions = new NkVector2f[NkVerts.Length];

                    for (int i = 0; i < NkVerts.Length; i++)
                    {
                        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, Vertices->memory.ptr);
                    FrameBuffered?.BeginBuffering();

                    uint Offset = 0;
                    Dev.BeginRender();

                    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;
                    });

                    Dev.EndRender();
                    FrameBuffered?.EndBuffering();
                }

                nk_draw_list *list = &Ctx->draw_list;
                if (list != null)
                {
                    if (list->buffer != null)
                    {
                        Nuklear.nk_buffer_clear(list->buffer);
                    }

                    if (list->vertices != null)
                    {
                        Nuklear.nk_buffer_clear(list->vertices);
                    }

                    if (list->elements != null)
                    {
                        Nuklear.nk_buffer_clear(list->elements);
                    }
                }

                Nuklear.nk_clear(Ctx);
            }

            FrameBuffered?.RenderFinal();
        }