Thanks David,
Since I’m not at all familiar with the intricacies of OpenGL/DirectX/Panda3D, here is a sketch (stuttering…) of what I’ve understood:
(1) in glGraphicsBuffer_src.h, make public:
GLuint _fbo;
PT(Texture) _tex[RTP_COUNT];
(2) then the code could look like
#include "glgsg.h"
#include "glGraphicsBuffer_src.h"
// assuming directx already on with d3ddev ptr
if( NULL == (d3d = Direct3DCreate9(D3D_SDK_VERSION))) exit(0); // create the Direct3D interface
....
HRESULT hr = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,&d3ddev);
...
// panda actions:
// set texture buffer (ABuffer) that will be written as a result of CameraA seiing the scene
PT(GraphicsBuffer) ABuffer =
DCAST(GraphicsBuffer,window->get_graphics_output()->make_texture_buffer("ABuffer", wtexture, htexture));
PT(Texture) ABuffertexture = ABuffer->get_texture();
camA = new Camera("camA");
camA_NP = camera.attach_new_node(camA);
ABuffer->set_sort(-200);
camA->set_scene(render);
PT(DisplayRegion) ADr = ABuffer->make_display_region(0,1,0,1);
ADr->set_camera(camA_NP);
// will do the same for additional cameras (B,C,D)
...
// If GraphicsBuffer is wglGraphicsBuffer get gl descriptors
if (ABuffer->get_type().get_name() == "GLGraphicsBuffer") {
PT(GLGraphicsBuffer) gl_ABuffer = DCAST(GLGraphicsBuffer,ABuffer);
// Register directx device for interop with opengl
gl_handleD3D = wglDXOpenDeviceNV(d3ddev); // interop device handle
// Create d3d surface (gImage)
d3ddev->CreateOffscreenPlainSurface(
ImageWidth,
ImageHeight,
D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, // Surface is in video memory
&gImage, NULL);
// Register this DirectX buffer as GL texture object
GLuint gl_name_image;
glGenTextures(1, &gl_name_image); // reserver le nom d'une texture
// prepares this DirectX object for use by the GL
HANDLE handle_image = wglDXRegisterObjectNV(gl_handleD3D, gImage,
gl_name_image, GL_TEXTURE_2D_MULTISAMPLE, WGL_ACCESS_READ_WRITE_NV);
// Lock the render target for GL access
wglDXLockObjectsNV(gl_handleD3D, 1, &handle_image);
// Now transfer openGL ABuffertexture into part of Directx gImage
BindFramebufferEXT(READ_FRAMEBUFFER_EXT, gl_ABuffer->fbo);
BindFramebufferEXT(DRAW_FRAMEBUFFER_EXT, gl_name_image );
BlitFramebufferEXT(0, 0, 1024, 768, 80, 80, 1024-80, 768-80,GL_COLOR_BUFFER_BIT,GL_NEAREST);
// Do the same for cameras B,C & D
// Unlock gImage from openGL
wglDXUnlockObjectsNV(gl_handleD3D, 1, &handle_image);
// Do some additional processing in directx on gImage
....
// Get the Backbuffer then Stretch the Surface on it.
RECT srcRect= { 0, 0, gImageWidth/2, gImageHeight/2};
RECT dstRect= { 0, 0, gImageWidth, gImageHeight};
d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &gBackBuf);
d3ddev->StretchRect(gImage, &srcRect, gBackBuf, &dstRect, D3DTEXF_NONE);
// then Direct3D presents the results on the screen
d3ddev->Present(NULL, NULL, NULL, NULL); // displays the created frame
}
By far I’m not sure that this is the correct approach, and obviously this rough code is not likely to work as such
How to make it work??