简体   繁体   中英

DX11 OpenGL interop: can't copy buffer

I am trying to make DirectX - OpenGL interop to work, with no success so far. In my case rendering is done in OpenGL (by OSG library), and I would like to have the rendered image as DirectX Texture2D. What I am trying so far:

Initialization:

ID3D11Device *dev3D;
// init dev3D with D3D11CreateDevice
ID3D11Texture2D *dxTexture2D;
// init dxTexture2D with CreateTexture2D, with D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE
HANDLE hGlDev = wglDXOpenDeviceNV(dev3D);
GLuint glTex;
glGenTextures(1, &glTex);
HANDLE hGLTx = wglDXRegisterObjectNV(hGlDev, (void*) dxTexture2D, glTex, GL_TEXTURE_2D, WGL_ACCESS_READ_WRITE_NV);

On every frame rendered by OSG camera I am getting a callback. First I start with glReadBuffer(GL_FRONT) , and it seems to be OK till that point, as I am able to read the rendered buffer into memory with glReadPixels . The problem is that I can't copy the pixels to previously created GL_TEXTURE_2D :

BOOL lockOK = wglDXLockObjectsNV(hGlDev, 1, &hGLTx);
glBindTexture(GL_TEXTURE_2D, glTex);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, width, height, 0);
auto err = glGetError();

The last call to glCopyTexImage2D creates an error 0x502 ( GL_INVALID_OPERATION ), and I can't figure out why. Until this point everything else looks fine.

Any help is appreciated.

Found the problem. Instead of the call to glCopyTexImage2D (which creates a new texture), needed to use glCopyTexSubImage2D :

glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM