Rendering in editor only when required

Started by
5 comments, last by JoeJ 1 year, 12 months ago

My engine runs in C++ and uses DirectX11. I have a C# editor and a Managed C++ ‘shim’ library that sits in between the two which allows me to drive and render the engine from my C# editor.

What I've been doing for a while in C# is, on ApplicationIdle, calling my engine's render code for each view that is registered. I have several of these, including a scene editor view, a material editor view, material sample view, etc. The only view I'd like to render as fast as possible is the scene editor view but I'm also rendering the Material Editor window too, even when nothing's happening in there.

What I'd like to do is somehow only render to the Material Editor window when the control needs to be invalidated or when the mouse down event is registered and the mouse is moving, i.e. you're moving something around in the Material Editor window. The reason for this is that when you have a complex material loaded (a bit like Unreal's material editor), it slows down the render of the scene editor window because both are being rendered as fast as possible.

I've tried various OnPaint stuff in C# to try only render the Material Editor window when it needs it but for some reason it seems to render for a split second and then just go grey. Like somehow the engine as rendered to the control in the OnPaint but then it somehow gets over-rendered by the C# control. I find all this paint event stuff in C# a bit black-boxy, so is there a better way to do this?

Advertisement

RobM said:
Like somehow the engine as rendered to the control in the OnPaint but then it somehow gets over-rendered by the C# control. I find all this paint event stuff in C# a bit black-boxy, so is there a better way to do this?

IDK, but you could keep that as is, if you render your viewports to textures. Then you can control updates of such textures without bothering the application framework.

@JoeJ Thanks Joe, yes that's a good idea.

I have another question related to this. I'm starting to look at upgrading my editor to move from WinForms to WPF. The reason I'm doing this is because my asset browser essentially runs like a dog as I'm using a DockLayoutPanel with potentially hundreds of controls in it. It can take 5+ seconds to switch directories if you have hundreds of files to view which is not great.

One thing I've noticed about WPF is that the HWND only exists for the top parent window and my Engine code needs an HWND handle per swapchain (for things like scene editor window, material editor, etc). Has anyone done this yet with WPF using Interop?

RobM said:
I'm starting to look at upgrading my editor to move from WinForms to WPF.

Initially i had used Win32 controls, but at some point i wrote my own GUI and rendered this from OpenGL. It made my life a lot easier. Now i use ImGui.

Downside is: If your framerate gets low, GUI becomes slow too. But still, i don't look back.

@JoeJ I can imagine writing your own GUI is a huge amount of work - trying to avoid that if I can.

RobM said:
I can imagine writing your own GUI is a huge amount of work - trying to avoid that if I can.

My GUI was not very fancy, but still 2-3 weeks of work when i was young.
ImGui is much better anyway. The immediate way of doing it is a game changer. If you don't know it, i propose you try it out only for debugging purposes.
You should like it for that, and then maybe you'll consider to use it for everything. Does not really look professional, but it does its job for minor effort.

This topic is closed to new replies.

Advertisement