Beispiel #1
0
 public ImGuiIOPtr(IntPtr nativePtr)
 {
     NativePtr = (ImGuiIO *)nativePtr;
 }
Beispiel #2
0
 public ImGuiIOPtr(ImGuiIO *nativePtr)
 {
     NativePtr = nativePtr;
 }
Beispiel #3
0
    public RendererBackend(string?glslVersion)
    {
        ImGuiIO *io = ImGui.GetIO();

        if (io->BackendRendererUserData != null)
        {
            throw new InvalidOperationException("A renderer backend has already been initialized for the current Dear ImGui context!");
        }

        // Unlike the native bindings we have an object associated with each context so we generally don't use the BackendRendererUserData and instead enforce
        // a 1:1 relationship between backend instances and Dear ImGui contexts. However we still use a GC handle in BackendRendererUserData for our platform callbacks.
        Context = ImGui.GetCurrentContext();

        ThisHandle = GCHandle.Alloc(this, GCHandleType.Weak);
        io->BackendRendererUserData = (void *)GCHandle.ToIntPtr(ThisHandle);

        // Set the backend name
        {
            string name          = GetType().FullName ?? nameof(RendererBackend);
            int    nameByteCount = Encoding.UTF8.GetByteCount(name) + 1;
            byte * nameP         = (byte *)ImGui.MemAlloc((nuint)nameByteCount);
            io->BackendRendererName = nameP;
            Span <byte> nameSpan         = new(nameP, nameByteCount);
            int         encodedByteCount = Encoding.UTF8.GetBytes(name.AsSpan().Slice(0, nameSpan.Length - 1), nameSpan);
            nameSpan[encodedByteCount] = 0; // Null terminator
        }

        // Query for GL version (e.g. 320 for GL 3.2)
        {
            int major = GL.GetInteger(GetPName.MajorVersion);
            int minor = GL.GetInteger(GetPName.MinorVersion);

            if (major == 0 && minor == 0)
            {
                throw new NotSupportedException("Ancient versions of OpenGL which do not support version queries are not supported.");
            }

            GlVersion = major * 100 + minor * 10;
        }

        //TODO: Handle GLES
        if (GlVersion >= 320)
        {
            io->BackendFlags |= ImGuiBackendFlags.RendererHasVtxOffset;
        }                                                           // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.

        io->BackendFlags |= ImGuiBackendFlags.RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)

        // Store GLSL version string so we can refer to it later in case we recreate shaders.
        // Note: GLSL version is NOT the same as GL version. Leave this to NULL if unsure.
        if (glslVersion is null)
        {
            //TODO: Handle GLES
            if (OperatingSystem.IsMacOS())
            {
                glslVersion = "#version 150";
            }
            else
            {
                glslVersion = "#version 130";
            }
        }

        GlslVersionString = glslVersion;

        // Detect extensions we support
        HasClipOrigin = GlVersion >= 450;

        //TODO: Handle GLES
        int extensionCount = GL.GetInteger(GetPName.NumExtensions);

        for (int i = 0; i < extensionCount; i++)
        {
            if (GL.GetString(StringNameIndexed.Extensions, i) == "GL_ARB_clip_control")
            {
                HasClipOrigin = true;
            }
        }

        if (io->ConfigFlags.HasFlag(ImGuiConfigFlags.ViewportsEnable))
        {
            // ImGui_ImplOpenGL3_InitPlatformInterface
            ImGui.GetPlatformIO()->Renderer_RenderWindow = &RenderWindow;
 public abstract void ImGuiIO_AddInputCharacter(ImGuiIO *self, ushort c);
 public abstract void ImGuiIO_ImGuiIO(ImGuiIO *self);
 public abstract void ImGuiIO_ClearInputCharacters(ImGuiIO *self);
 public abstract void ImGuiIO_AddInputCharactersUTF8(ImGuiIO *self, byte *utf8_chars);