Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Generic RAII for Backend Integration in ImGui #8237

Closed
pinwhell opened this issue Dec 17, 2024 · 2 comments
Closed

Proposal: Generic RAII for Backend Integration in ImGui #8237

pinwhell opened this issue Dec 17, 2024 · 2 comments

Comments

@pinwhell
Copy link

Version/Branch of Dear ImGui:

master

Back-ends:

Any

Compiler, OS:

Default

Full config/build information:

Default

Details:

Guys... how about implementing generic RAII for basic backend aspects... for example:

namespace ImGui {
namespace RAII {

struct Frame {
    Frame() {
        NewFrame();
    }

    ~Frame() {
        Render();
    }
};

namespace Backend {

template<void (*NewFrame)()>
struct Frame {
    Frame() {
        NewFrame();
    }
};

template<void (*NewFrame)(), void (*RenderDrawData)(ImDrawData*)>
struct FrameWithRender : public Frame<NewFrame> {
    ~FrameWithRender() {
        RenderDrawData(GetDrawData());
    }
};

}  // namespace Backend

}  // namespace RAII

Then instantiating it... example:

namespace ImGui {

using OpenGL2Frame = Backend::FrameWithRender<
    ImGui_ImplOpenGL2_NewFrame, ImGui_ImplOpenGL2_RenderDrawData>;

using Win32Frame = Backend::Frame<
    ImGui_ImplWin32_NewFrame>;

}

Using it would be as easy. as:

int main() {
    while (/* condition */) {
        {
              Win32Frame imw32Frame;
              OpenGL2Frame imglFrame;
              ImGui::Frame imFrame;
              /*User Imgui Code Here*/
        }
        // Platform Present
    }
}

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

No response

@PathogenDavid
Copy link
Contributor

See #2096 and #2197 for existing discussions/implementation of using RAII patterns with Dear ImGui.

Personally I feel that your specific examples feel like RAII for the sake of RAII.

@ocornut
Copy link
Owner

ocornut commented Dec 17, 2024

Hello,
I am afraid I also only see negative aspects to your proposal. It doesn’t seem like a good idea. I’ll close this.

@ocornut ocornut closed this as completed Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants