can be useful
- Opengl player and video GPU decoding via dxva.
what i know
1.create opengl.
2. call initdxg()
3.Create direct3d context g_pD3D->CreateDevice
int handle=wglDXOpenDeviceNVX(g_pd3dDevice)) takes direct3d device
return handle >0
0 error
wglDXCloseDeviceNVX(handle) takes handle
return >0 ok
0 error
open interop:
int dx;
int ret;
if((dx=wglDXOpenDeviceNVX(g_pd3dDevice))!=NULL)
printf("OpenGL DirectX interop is working!
");
else
printf("OpenGL DirectX interop not working!
");
close interop:
if(ret=wglDXCloseDeviceNVX((void )dx))
printf("OpenGL DirectX interop finished!
");
else
printf("OpenGL DirectX interop not finished!
");/
wglDXRegisterObjectNVX takes 5 parameters first is handle should also take opengl and object directx object and also object usage read_only,etc…
should be similar to cudaGLRegisterBufferObject
returns 0 error
cutilSafeCall(cudaGLRegisterBufferObject(*pbo));
cutilSafeCall(cudaGLSetBufferObjectMapFlags (*pbo, cudaGLMapFlagsReadOnly));
also
DXLockObjectsNVX equivalent to cuda cudaGLMapBufferObject
gldxinterop
#ifndef gldxinterop_h
#define gldxinterop_h
#include <windows.h>
#include <d3d9.h>
#include <GL/glew.h>
#include <GL/glut.h>
#include <GL/glext.h>
#if defined(__cplusplus)
extern “C” {
#endif /* __cplusplus */
extern int dx;
typedef int (__stdcall pwglDXOpenDeviceNVX)(IDirect3DDevice9 *ppDxDevice);//(int device);
typedef int (__stdcall pwglDXCloseDeviceNVX )(void *);//(int device);
typedef int (__stdcall pwglDXRegisterObjectNVX)(void *,void *,void *,void *,int);//(IDirect3DResource9 *pResource unsigned int flags)
typedef int (__stdcall pwglDXUnregisterObjectNVX)(GLuint bufObj);
typedef int (__stdcall pwglDXLockObjectsNVX)(void **dev_ptr,GLuint bufObj);
typedef int (__stdcall pwglDXUnlockObjectsNVX)(void **dev_ptr,GLuint bufObj);
typedef int (__stdcall pwglDXObjectAccessNVX)(GLuint bufObj);
extern pwglDXOpenDeviceNVX *wglDXOpenDeviceNVX;
extern pwglDXCloseDeviceNVX *wglDXCloseDeviceNVX;
extern pwglDXRegisterObjectNVX *wglDXRegisterObjectNVX;
extern pwglDXUnregisterObjectNVX *wglDXUnregisterObjectNVX;
extern pwglDXLockObjectsNVX *wglDXLockObjectsNVX;
extern pwglDXUnlockObjectsNVX *wglDXUnlockObjectsNVX;
extern pwglDXObjectAccessNVX *wglDXObjectAccessNVX;
void initdxgl();
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif
gldxinterop.c
#include “gldxinterop.h”
#include <stdio.h>
pwglDXOpenDeviceNVX *wglDXOpenDeviceNVX;
pwglDXCloseDeviceNVX *wglDXCloseDeviceNVX;
pwglDXRegisterObjectNVX *wglDXRegisterObjectNVX;
pwglDXUnregisterObjectNVX *wglDXUnregisterObjectNVX;
pwglDXLockObjectsNVX *wglDXLockObjectsNVX;
pwglDXUnlockObjectsNVX *wglDXUnlockObjectsNVX;
pwglDXObjectAccessNVX *wglDXObjectAccessNVX;
int dx;
void initdxgl()
{
#define DXNAPI 7
void *p[DXNAPI];
int i;
char wgldx[DXNAPI][100]={"wglDXOpenDeviceNVX","wglDXCloseDeviceNVX","wglDXRegisterObjectNVX","wglDXUnregisterObjectNVX","wglDXLockObjectsNVX","wglDXUnlockObjectsNVX","wglDXObjectAccessNVX"};
for(i=0; i<DXNAPI; i++)
{
p[i]=NULL;
p[i]=(void *)wglGetProcAddress(wgldx[i]);
if(p[i]==NULL) printf("Not found %s
",wgldx[i]);
else printf("Found %s
",wgldx[i]);
}
wglDXOpenDeviceNVX=(pwglDXOpenDeviceNVX *)p[0];
wglDXCloseDeviceNVX=(pwglDXCloseDeviceNVX )p[1];
wglDXRegisterObjectNVX=(pwglDXRegisterObjectNVX) p[2];
wglDXUnregisterObjectNVX=(pwglDXUnregisterObjectNVX *)p[3];
wglDXLockObjectsNVX=(pwglDXLockObjectsNVX *)p[4];
wglDXUnlockObjectsNVX=(pwglDXUnlockObjectsNVX *)p[5];
wglDXObjectAccessNVX=(pwglDXObjectAccessNVX *)p[6];
#undef DXNAPI
}