Reusing graphic context.

Hi all,

I am getting doubts about how to manage graphic context. That is, Handle(V3d_Viewer) and Handle(Graphic3d_WNTGraphicDevice) objects.

I have a MFC MDI Application, and for each document, I have got a view with four rendering screens. By now, I am creating this two objects for each document, and sharing between the four different views.

My question is what is better in performance (speed and memory consumption):
1.- Create a viewer and a graphic device for all the application and use whenever I need (even setting dialog or whatever).
2.- Create a viewer and a grahpic device for each MFC View, so I will have one context for each 4 rendering views (Because they share geometry).
3.- Create a viewer and a graphic device for each rendering screen(I guess this is the worst).

Thank you very much for your help. If starts are bad, then it is too late...

Roman Lygin's picture

Look at how MFC MDI samples shipped with Open CASCADE are made. They implement one-to-one relationship between a document and AIS_InteractiveContext. AIS_IC contains one V3d_Viewer (+1 viewer for collector). Graphic3d_WNTGraphicDevice is used only once when creating a V3d_Viewer.
That's a typical approach used for creating OCC-based MDI apps.

Hope this helps.

--- - blog on Open CASCADE

arkoala's picture

Ok, I've checked into the MFC samples and I find there are defined by Document.

Problem is that each document has only a viewer, so I cannot get a conclusion.

The best reason to make a decission is to know what those objects are using for, because it could be a very cheapest method for me to not to spend memory.


P.D. Interesting blog, Roman.

arkoala's picture

I answer to me to fix my errors.

Handle(Graphic3d_WNTGraphicDevice) is created by the App class, so one instance per program.

Handle(V3d_Viewer) is created by the Doc class. In my case, and only because I am sharing geometry between different rendering CWnd for each document, I will get the same, a unique V3d_Viewer for each Doc.


Wang Chris's picture

Hi, Roman,

Is there any way to control "AIS2D_InteractiveContext" or V2d_view to dispay different graphics in two split views?

I want to dispaly a complicated graphics from one view to two split views (top & bottom) in a childframe. I want to display a block diagram in the top view, and then when clicking some block in the top view, the detail about the block would be displayed in the bottom view. AIS2D_InteractiveContext is used for the display.

My problem is at each time, both of the views display the same graphics. The two view use the same class for I want to use the same displaye methods for them.

Thanks a lot!


Roman Lygin's picture