mcneel / rhino-developer-samples

Rhino and Grasshopper developer sample code
http://developer.rhino3d.com
Other
607 stars 330 forks source link

SampleViewportRenderer doesn't work in Rhino 6 #7

Closed brendanmig closed 5 years ago

brendanmig commented 6 years ago

Hi,

I originally came across this issue in our own CRhinoDisplayPipeline implementation however I encounter the same thing in the SampleViewportRenderer in this repo.

In short, it doesn't work. When you activate the renderer nothing ever gets displayed in the viewport. It just keeps displaying whatever was there previously and if you navigate the display remains unchanged.

I can fix this by providing a derived implementation of the EngineClass() virtual method. EG:

const ON_ClassId* CSampleDisplayPipeline::EngineClass()
{
    return &CRhinoDisplayEngine_OGL::m_CRhinoDisplayEngine_OGL_class_rtti;
}

On my machine I then get the viewport renders.

If I change the EngineClass() implementation to just return CRhinoDisplayPipeline::EngineClass() then things stop working again. In fact, the EngineClass() method gets called about 15 times. When it returns the OGL engine class it only gets called once.

Unfortunately, even though with these fixes it works on my desktop development machine it does not work on the laptop we tested. The ShowFrameBuffer method gets called however the viewport never gets updated. The only real difference we can think of between the two machines is that the laptop has an integrated and dedicated GPU (Rhino is running on the dedicated) while the development machine is just a dedicated GPU. So far we've only tested one desktop and one laptop but will be trying another laptop tomorrow. However, I can't think why there should be any issue given that ShowFrameBuffer is working at the MFC/WindowsSDK level.

Note that the Rhino 5 version of the plugins (both sample and our one) works fine in all cases. It's only for Rhino 6 that we've needed to override EngineClass() and are encountering the laptop issue.

jesterKing commented 6 years ago

I let @dalefugier look at the SampleViewportRenderer plug-in code.

@brendanmig have you looked into using the new realtime renderer integration SDK we have introduced for Rhino 6? https://github.com/mcneel/rhino-developer-samples/tree/6/cpp/SampleRealtimeRenderer

andylebihan commented 6 years ago

@brendanmig This sample is deprecated in V6. Use SampleRealtimeRenderer. I will remove the V6 code and replace it with a placeholder.

brendanmig commented 6 years ago

No, I haven't looked at the SampleRealtimeRenderer since the API it uses isn't documented so I had no idea those APIs now existed. The ViewportPipeline API also wasn't marked as deprecated or not functioning so didn't know it should be replaced with anything else. Will look into what we need to do to switch over.

brendanmig commented 6 years ago

OK, So I have replaced our view pipeline with the realtime renderer but in both my implementation and in SampleRealtimeRenderer in this repo all images get overlayed with a wireframe of the scene objects. See attached. How do I prevent this?

image

brendanmig commented 6 years ago

Also, is there any documentation on this feature beyond SampleRealtimeRenderer? I'm basically finding myself reverse engineering what virtual methods get called when to work out how to display something and know when updates have occured. I also found that you can't just assign any CRhinoDib to FRAME_BUFFER_INFO_OUTPUTS::pointer_to_dib. It has to match the format of the DIB provided by IRhRdkRenderWindow. This took quite a while to work out my core DIBs were 24bpp whereas I needed to be providing 32bpp dibs otherwise it only displayed black.

dalefugier commented 6 years ago

@andylebihan, @jesterKing, can you help here?

jesterKing commented 6 years ago

@brendanmig would it possible for you to conduct discussion on our Discourse forum at https://discourse.mcneel.com ?

That said: the wires you can turn off by unchecking the show curves and show mesh wires boxes. You can do that programmatically by tweaking the display pipeline attributes. On m_pAttrs you should be able to set m_bShowCurves, m_bShowMeshWires, m_bShowEdges and so on.

The most documented is the .NET wrapping we've created around the C++ classes. Not everything is documented, as for instance the usage of the FRAME_BUFFER_INFO_OUTPUTS is handled for the dev by the wrapping code. That said, I think much of the ideas will transfer back well to C++: http://developer.rhino3d.com/guides/#advanced , the articles on Render Engine Integration.