Hi Chris, >I suppose I could use something other than an OSG::Image to bind to the BYTE property of my struct.
whatever you bind, the way you copy rendered results to layered window ( see your memcpy which is exactly copying via system memory ) will move video memory to system memory and this is a bottleneck the suggestion was to avoid this step and perform whatever you want in video memory ( even if a copy will occur- the copy between video memory is much faster than a copy to system memory. You might remember, I already sent you three approaches to avoid working via system memory ( maybe others will find this tip useful too in case of such an attempt ). 1) use windows DWM trick as in http://www.youtube.com/watch?v=4qWKSYWIqdk the code to look at how it is achived is here https://github.com/sphair/ClanLib/tree/master/Examples/GUI/GUI_Layered the idea is here is that you render using DWM system calls and then compose layered windows without old layered windows api which you try to use to achive result. Here layering is achieved by exploiting the fact that in new windows ( since Vista ) all windows first are rendered to offscreen surface, but then are composed to produce final screen result - you will be limited here to any windows operation system above windows xp ( but it is already retired and Vista is also not widely used - so limiting yourself just to Win7+ will make all coding much easier ). BTW on linux the same result possibly could be achieved via wayland compositor. You might compile ClanLib and see how that achieved - it is fairly easy and takes just few lines of code during creation of window and the complete code to achive what you need is provided, so you will need just add the same code to osg window creation function ( and use appropriate flags elsewhere to use DWM hack, but still, as in this example it is fairly easy to achive ). 2) use http://msdn.microsoft.com/en-us/magazine/ee819134.aspx approach and then https://sites.google.com/site/snippetsanddriblits/OpenglDxInterop to copy opengl rendered result to Direct2D layered window in video memory ( currently NV_DX_interop <http://www.opengl.org/registry/specs/NV/DX_interop2.txt> and NV_DX_interop2 <http://www.opengl.org/registry/specs/NV/DX_interop2.txt> are supported on almost all video cards ), that might not work, due to possible problems with very difficult path via Direct3D/Direct2D texture, but still it is possible that it will work and will give you better results than now 3) you might use rendering with OpenGL ES with osg ( though you would need to have your own model loader ) via ANGLE to use http://msdn.microsoft.com/en-us/magazine/ee819134.aspx trick, as final rendered result in ANGLE might be a direct3d texture, which you could apply to Direct2D layered window. all approaches are not easy to implement to novice, but still - in case you want to significantly improve fps - you should avoid working via system memory, maybe someone else can offer some other insights - but I think that there are hardly any more, so you still will have to implement one of suggested approaches. And looks like the first suggested approach is most simple one and also can be possibly ported to linux, at least ClanLib team tries to have that example to run on linux too ,to significantly improve fps for the task you wish to solve. Regards Sergey On Mon, Sep 1, 2014 at 7:27 PM, Chris Hidden <[email protected]> wrote: > Hey Robert > > > > > > Thanks for the more detailed explanation. From what I can make out you > are able to render the 3 models to a pbuffer than render this with > transparency over the desktop OK, this part if functioning as intended. Is > this correct? > > > > > Yes this is correct! > > As for the HUD Ill try getting it working in a standard OSG graphics > context first as you said. Probably the best idea. > > As far as your suggestions for optimization. I think I understand. > However I was under the impression that the osg::Image was the pbuffer. > > In order to to my transparent screen trick I have a struct: > > > Code: > > typedef struct > { > int width; > int height; > int pitch; > HDC hdc; > HBITMAP hBitmap; > BITMAPINFO info; > BYTE *pPixels; > } Scene; > > > > > Then I initiate the struct with some init values. Then the I do a memcpy > from the pbuffer/image to the struct: > > > Code: > > for (int i = 0; i < g_image->t(); ++i) > { > memcpy(&g_scene.pPixels[g_scene.pitch * i], > &g_image->data()[((sHeight - 1) - i) * (sWidth * > 4)], > sWidth * 4); > } > > > > > Here g_image is my osg::image and g_scene is my struct. Once I have > copied the data I redraw to my "layered window" . This method takes care > of applying the necessary actions using BLENDFUNCTION and > UpdateLayeredWindow. > > > Code: > > void RedrawLayeredWindow() > { > // The call to UpdateLayeredWindow() is what makes a > non-rectangular > // window possible. To enable per pixel alpha blending we pass in > the > // argument ULW_ALPHA, and provide a BLENDFUNCTION structure > filled in > // to do per pixel alpha blending. > > HDC hdc = GetDC(g_hWnd); > > if (hdc) > { > HGDIOBJ hPrevObj = 0; > POINT ptDest = { 0, 0 }; > POINT ptSrc = { 0, 0 }; > SIZE client = { g_scene.width, > g_scene.height }; > BLENDFUNCTION blendFunc = { AC_SRC_OVER, 0, 255, > AC_SRC_ALPHA }; > hPrevObj = > SelectObject(g_scene.hdc, g_scene.hBitmap); > > ClientToScreen(g_hWnd, &ptDest); > UpdateLayeredWindow( > g_hWnd, > hdc, > &ptDest, > &client, > g_scene.hdc, > &ptSrc, > 0, > &blendFunc, > ULW_ALPHA); > > SelectObject(g_scene.hdc, hPrevObj); > ReleaseDC(g_hWnd, hdc); > } > } > > > > > I suppose I could use something other than an OSG::Image to bind to the > BYTE property of my struct. The thing is Im still quite new to a lot of > this so I don't know how I would do that. > > Let me know if Ive been unclear. Its also a challenge explaining this > stuff for me as well :S > > ------------------ > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=60891#60891 > > > > > > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org >
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

