123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- #pragma once
- #ifndef __spoutGLDXinterop__
- #define __spoutGLDXinterop__
- #include "SpoutCommon.h"
- #include "spoutDirectX.h"
- #include "spoutSenderNames.h"
- #include "SpoutMemoryShare.h"
- #include "spoutCopy.h"
- #include <windowsx.h>
- #include <d3d9.h>
- #include <d3d11.h>
- #include <gl/gl.h>
- #include <gl/glu.h>
- #include <shlwapi.h>
- #include "spoutGLextensions.h"
- class SPOUT_DLLEXP spoutGLDXinterop {
- public:
- spoutGLDXinterop();
- ~spoutGLDXinterop();
-
- spoutSenderNames senders;
- spoutDirectX spoutdx;
- spoutCopy spoutcopy;
- spoutMemoryShare memoryshare;
-
- bool LoadGLextensions();
- bool CreateInterop(HWND hWnd, const char* sendername, unsigned int width, unsigned int height, DWORD dwFormat, bool bReceive = true);
- void CleanupInterop(bool bExit = false);
- bool getSharedInfo(char* sharedMemoryName, SharedTextureInfo* info);
- bool setSharedInfo(char* sharedMemoryName, SharedTextureInfo* info);
-
- bool WriteTexture(GLuint TextureID, GLuint TextureTarget, unsigned int width, unsigned int height, bool bInvert=true, GLuint HostFBO=0);
- bool ReadTexture (GLuint TextureID, GLuint TextureTarget, unsigned int width, unsigned int height, bool bInvert=false, GLuint HostFBO=0);
- bool WriteTexturePixels(const unsigned char *pixels, unsigned int width, unsigned int height, GLenum glFormat = GL_RGBA, bool bInvert = false, GLuint HostFBO = 0);
- bool ReadTexturePixels (unsigned char *pixels, unsigned int width, unsigned int height, GLenum glFormat = GL_RGBA, bool bInvert = false, GLuint HostFBO=0);
- bool DrawSharedTexture (float max_x = 1.0, float max_y = 1.0, float aspect = 1.0, bool bInvert = true, GLuint HostFBO = 0);
- bool DrawToSharedTexture (GLuint TexID, GLuint TexTarget, unsigned int width, unsigned int height, float max_x = 1.0, float max_y = 1.0, float aspect = 1.0, bool bInvert = false, GLuint HostFBO = 0);
- bool BindSharedTexture();
- bool UnBindSharedTexture();
-
-
- bool WriteTexture(ID3D11Texture2D** texture);
- bool ReadTexture (ID3D11Texture2D** texture);
-
- bool UnloadTexturePixels(GLuint TextureID, GLuint TextureTarget,
- unsigned int width, unsigned int height,
- unsigned char *data, GLenum glFormat = GL_RGBA,
- bool bInvert = false, GLuint HostFBO = 0);
- bool LoadTexturePixels(GLuint TextureID, GLuint TextureTarget,
- unsigned int width, unsigned int height,
- const unsigned char *data, GLenum glFormat = GL_RGBA,
- bool bInvert = false);
-
- bool m_bUseDX9;
- bool GetDX9();
- bool SetDX9(bool bDX9);
- bool UseDX9(bool bDX9);
- bool isDX9();
- bool m_bUseCPU;
- bool SetCPUmode(bool bCPU = true);
- bool GetCPUmode();
- bool m_bUseMemory;
- bool SetMemoryShareMode(bool bMem = true);
- bool GetMemoryShareMode();
- int GetShareMode();
- bool SetShareMode(int mode);
- bool IsBGRAavailable();
- bool IsPBOavailable();
- void SetBufferMode(bool bActive);
- bool GetBufferMode();
- int GetNumAdapters();
- bool GetAdapterName(int index, char *adaptername, int maxchars);
- bool SetAdapter(int index);
- int GetAdapter();
- bool GetHostPath(const char *sendername, char *hostpath, int maxchars);
-
- D3DFORMAT DX9format;
- void SetDX9format(D3DFORMAT textureformat);
- bool CreateDX9interop(unsigned int width, unsigned int height, DWORD dwFormat, bool bReceive = true);
- bool OpenDirectX9(HWND hWnd);
- void CleanupDX9(bool bExit = false);
-
- DXGI_FORMAT DX11format;
- void SetDX11format(DXGI_FORMAT textureformat);
- bool CreateDX11interop(unsigned int width, unsigned int height, DWORD dwFormat, bool bReceive);
- bool OpenDirectX11();
- bool DX11available();
- void CleanupDX11(bool bExit = false);
-
- bool OpenDirectX(HWND hWnd, bool bDX9);
- void CleanupDirectX(bool bExit = false);
- HANDLE LinkGLDXtextures(void* pDXdevice, void* pSharedTexture, HANDLE dxShareHandle, GLuint glTextureID);
-
-
- HRESULT LockInteropObject(HANDLE hDevice, HANDLE *hObject);
- HRESULT UnlockInteropObject(HANDLE hDevice, HANDLE *hObject);
-
- bool GLDXcompatible();
- bool isOptimus();
- int GetVerticalSync();
- bool SetVerticalSync(bool bSync = true);
- bool GetAdapterInfo(char *renderadapter,
- char *renderdescription, char *renderversion,
- char *displaydescription, char *displayversion,
- int maxsize, bool &bUseDX9);
- DWORD GetSpoutVersion();
-
-
- bool InitOpenGL();
- bool CloseOpenGL();
- bool CopyTexture(GLuint SourceID, GLuint SourceTarget, GLuint DestID, GLuint DestTarget,
- unsigned int width, unsigned int height, bool bInvert, GLuint HostFBO);
- void InitTexture(GLuint &texID, GLenum GLformat, unsigned int width, unsigned int height);
- void CheckOpenGLTexture(GLuint &texID, GLenum GLformat,
- unsigned int newWidth, unsigned int newHeight,
- unsigned int &texWidth, unsigned int &texHeight);
- void SaveOpenGLstate(unsigned int width, unsigned int height, bool bFitWindow = true);
- void RestoreOpenGLstate();
- GLuint GetGLtextureID();
- void GLerror();
- void PrintFBOstatus(GLenum status);
- GLuint m_glTexture;
- GLuint m_fbo;
-
- IDirect3DDevice9Ex* m_pDevice;
- LPDIRECT3DTEXTURE9 m_dxTexture;
- HANDLE m_dxShareHandle;
- ID3D11Device* g_pd3dDevice;
- ID3D11Texture2D* g_pSharedTexture;
- protected:
- bool m_bInitialized;
- bool m_bExtensionsLoaded;
- unsigned int m_caps;
- bool m_bFBOavailable;
- bool m_bBLITavailable;
- bool m_bPBOavailable;
- bool m_bSWAPavailable;
- bool m_bBGRAavailable;
- bool m_bGLDXavailable;
- HWND m_hWnd;
- HANDLE m_hSharedMemory;
- SharedTextureInfo m_TextureInfo;
- GLuint m_TexID;
- unsigned int m_TexWidth;
- unsigned int m_TexHeight;
-
- GLuint m_pbo[2];
- int PboIndex;
- int NextPboIndex;
-
- HDC m_hdc;
- HWND m_hwndButton;
- HGLRC m_hRc;
-
- ID3D11DeviceContext* g_pImmediateContext;
- D3D_DRIVER_TYPE g_driverType;
- D3D_FEATURE_LEVEL g_featureLevel;
- ID3D11Texture2D* g_pStagingTexture;
-
- IDirect3D9Ex* m_pD3D;
- LPDIRECT3DSURFACE9 g_DX9surface;
-
-
- HANDLE m_hInteropDevice;
- HANDLE m_hInteropObject;
- HANDLE m_hAccessMutex;
- bool getSharedTextureInfo(const char* sharedMemoryName);
- bool setSharedTextureInfo(const char* sharedMemoryName);
-
- bool WriteGLDXtexture (GLuint TextureID, GLuint TextureTarget, unsigned int width, unsigned int height, bool bInvert=true, GLuint HostFBO=0);
- bool ReadGLDXtexture (GLuint TextureID, GLuint TextureTarget, unsigned int width, unsigned int height, bool bInvert=false, GLuint HostFBO=0);
- bool WriteGLDXpixels (const unsigned char *pixels, unsigned int width, unsigned int height, GLenum glFormat = GL_RGBA, bool bInvert = false, GLuint HostFBO = 0);
- bool ReadGLDXpixels (unsigned char *pixels, unsigned int width, unsigned int height, GLenum glFormat = GL_RGBA, bool bInvert = false, GLuint HostFBO=0);
- bool DrawGLDXtexture (float max_x = 1.0, float max_y = 1.0, float aspect = 1.0, bool bInvert = true);
- bool DrawToGLDXtexture(GLuint TexID, GLuint TexTarget, unsigned int width, unsigned int height, float max_x = 1.0, float max_y = 1.0, float aspect = 1.0, bool bInvert = false, GLuint HostFBO = 0);
-
- bool WriteDX11texture (GLuint TextureID, GLuint TextureTarget, unsigned int width, unsigned int height, bool bInvert=false, GLuint HostFBO=0);
- bool ReadDX11texture (GLuint TextureID, GLuint TextureTarget, unsigned int width, unsigned int height, bool bInvert=false, GLuint HostFBO=0);
- bool WriteDX11pixels (const unsigned char *pixels, unsigned int width, unsigned int height, GLenum glFormat = GL_RGBA, bool bInvert=false);
- bool ReadDX11pixels (unsigned char *pixels, unsigned int width, unsigned int height, GLenum glFormat = GL_RGBA, bool bInvert=false);
- bool DrawDX11texture (float max_x = 1.0, float max_y = 1.0, float aspect = 1.0, bool bInvert = false, GLuint HostFBO=0);
- bool DrawToDX11texture(GLuint TextureID, GLuint TextureTarget, unsigned int width, unsigned int height, float max_x = 1.0, float max_y = 1.0, float aspect = 1.0, bool bInvert = false, GLuint HostFBO = 0);
- bool CheckStagingTexture(unsigned int width, unsigned int height);
- void FlushWait();
-
- bool WriteDX9surface (LPDIRECT3DSURFACE9 source_surface);
- bool WriteDX9texture (GLuint TextureID, GLuint TextureTarget, unsigned int width, unsigned int height, bool bInvert=false, GLuint HostFBO=0);
- bool ReadDX9texture (GLuint TextureID, GLuint TextureTarget, unsigned int width, unsigned int height, bool bInvert=false, GLuint HostFBO=0);
- bool WriteDX9pixels (const unsigned char *pixels, unsigned int width, unsigned int height, GLenum glFormat = GL_RGBA, bool bInvert=false);
- bool ReadDX9pixels (unsigned char *pixels, unsigned int width, unsigned int height, GLenum glFormat = GL_RGBA, bool bInvert=false);
- bool DrawDX9texture (float max_x = 1.0, float max_y = 1.0, float aspect = 1.0, bool bInvert = false, GLuint HostFBO = 0);
- bool DrawToDX9texture(GLuint TextureID, GLuint TextureTarget, unsigned int width, unsigned int height, float max_x = 1.0, float max_y = 1.0, float aspect = 1.0, bool bInvert = false, GLuint HostFBO = 0);
- bool CheckDX9surface (unsigned int width, unsigned int height);
-
- bool WriteMemory (GLuint TexID, GLuint TextureTarget, unsigned int width, unsigned int height, bool bInvert = false, GLuint HostFBO=0);
- bool ReadMemory (GLuint TexID, GLuint TextureTarget, unsigned int width, unsigned int height, bool bInvert = false, GLuint HostFBO=0);
- bool WriteMemoryPixels (const unsigned char *pixels, unsigned int width, unsigned int height, GLenum glFormat = GL_RGBA, bool bInvert = false);
- bool ReadMemoryPixels (unsigned char *pixels, unsigned int width, unsigned int height, GLenum glFormat = GL_RGBA, bool bInvert = false);
- bool DrawSharedMemory (float max_x = 1.0, float max_y = 1.0, float aspect = 1.0, bool bInvert = false);
- bool DrawToSharedMemory(GLuint TextureID, GLuint TextureTarget, unsigned int width, unsigned int height, float max_x = 1.0, float max_y = 1.0, float aspect = 1.0, bool bInvert = false, GLuint HostFBO = 0);
-
- bool OpenDeviceKey(const char* key, int maxsize, char *description, char *version);
- void trim(char * s);
- };
- #endif
|