[英]DX11 OpenGL interop: can't copy buffer
I am trying to make DirectX - OpenGL interop to work, with no success so far. 我正在尝试使DirectX-OpenGL互操作正常运行,但到目前为止没有成功。 In my case rendering is done in OpenGL (by OSG library), and I would like to have the rendered image as DirectX Texture2D.
在我的情况下,渲染是在OpenGL中完成的(通过OSG库),我希望渲染的图像为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. 在OSG摄像机渲染的每一帧上,我都会收到回调。 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
. 首先,我从
glReadBuffer(GL_FRONT)
开始,直到那一点似乎还可以,因为我可以使用glReadPixels
将渲染的缓冲区读入内存。 The problem is that I can't copy the pixels to previously created GL_TEXTURE_2D
: 问题是我无法将像素复制到先前创建的
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. 最后一次调用
glCopyTexImage2D
会产生错误0x502( GL_INVALID_OPERATION
),但我不知道为什么。 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
: 无需调用
glCopyTexImage2D
(它会创建一个新的纹理), glCopyTexSubImage2D
需要使用glCopyTexSubImage2D
:
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.