123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- #pragma once
- #ifndef __spoutGLDXinterop__
- #define __spoutGLDXinterop__
- #include "SpoutCommon.h"
- #include "spoutGLextensions.h"
- #include "spoutDirectX.h"
- #include "spoutSenderNames.h"
- #include "SpoutMemoryShare.h"
- #include <windowsx.h>
- #include <d3d9.h>
- #include <d3d11.h>
- #include <gl/gl.h>
- #include <gl/glu.h>
- #include <shlwapi.h>
- class SPOUT_DLLEXP spoutGLDXinterop {
- public:
- spoutGLDXinterop();
- ~spoutGLDXinterop();
-
- bool LoadGLextensions();
- bool CreateInterop(HWND hWnd, const char* sendername, unsigned int width, unsigned int height, DWORD dwFormat, bool bReceive = true);
- bool CheckInterop(HWND hWnd);
- void CleanupInterop(bool bExit = false);
- void setSharedMemoryName(char* sharedMemoryName, bool bReceive = true);
- 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(unsigned char *pixels, unsigned int width, unsigned int height, GLenum glFormat = GL_RGBA, bool bAlignment = true);
- bool ReadTexturePixels (unsigned char *pixels, unsigned int width, unsigned int height, GLenum glFormat = GL_RGBA, GLuint HostFBO=0);
- bool WriteDword(GLuint TextureID, GLuint TextureTarget, DWORD dwValue);
- bool ReadDword (GLuint TextureID, GLuint TextureTarget, DWORD &dwValue, unsigned int width, unsigned int height, bool bInvert = false);
- unsigned __int32 iLastFrame;
- bool InitOpenGL();
- bool CloseOpenGL();
- #ifdef USE_PBO_EXTENSIONS
- bool LoadTexture(GLuint TextureID, GLuint TextureTarget, unsigned int width, unsigned int height, unsigned char *data);
- #endif
- bool BindSharedTexture();
- bool UnBindSharedTexture();
- bool DrawSharedTexture(float max_x = 1.0, float max_y = 1.0, float aspect = 1.0, bool bInvert = true);
- bool DrawToSharedTexture(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 bUseDX9;
- bool UseDX9(bool bDX9);
- bool isDX9();
-
- void SetDX9(bool bDX9);
- bool GetDX9();
- bool bUseMemory;
- bool GetMemoryShareMode();
- bool SetMemoryShareMode(bool bMem = true);
- D3DFORMAT DX9format;
- void SetDX9format(D3DFORMAT textureformat);
- 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);
- bool CreateDX9interop(unsigned int width, unsigned int height, DWORD dwFormat, bool bReceive = true);
- bool OpenDirectX9(HWND hWnd);
- void CleanupDX9();
-
- 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 OpenDirectX(HWND hWnd, bool bDX9);
- void CleanupDirectX();
- HANDLE LinkGLDXtextures(void* pDXdevice, void* pSharedTexture, HANDLE dxShareHandle, GLuint glTextureID);
-
- bool GLDXcompatible();
- int GetVerticalSync();
- bool SetVerticalSync(bool bSync = true);
- bool GetAdapterInfo(char *renderadapter,
- char *renderdescription, char *renderversion,
- char *displaydescription, char *displayversion,
- int maxsize, bool &bUseDX9);
- bool CheckSpout2004();
-
-
-
-
-
-
- spoutMemoryShare memoryshare;
- spoutSenderNames senders;
- spoutDirectX spoutdx;
-
-
- HRESULT LockInteropObject(HANDLE hDevice, HANDLE *hObject);
- HRESULT UnlockInteropObject(HANDLE hDevice, HANDLE *hObject);
-
-
- bool WriteMemory (GLuint TexID, GLuint TextureTarget, unsigned int width, unsigned int height, bool bInvert = false);
- bool ReadMemory (GLuint TexID, GLuint TextureTarget, unsigned int width, unsigned int height, bool bInvert = false);
- bool WriteMemoryPixels (unsigned char *pixels, unsigned int width, unsigned int height);
- bool ReadMemoryPixels (unsigned char *pixels, unsigned int width, unsigned int height);
- 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);
- GLuint GetGLtextureID();
-
-
-
- GLuint m_glTexture;
- GLuint m_fbo;
-
- IDirect3DDevice9Ex* m_pDevice;
- LPDIRECT3DTEXTURE9 m_dxTexture;
- HANDLE m_dxShareHandle;
- ID3D11Device* g_pd3dDevice;
- ID3D11Texture2D* g_pSharedTexture;
- void GLerror();
- void PrintFBOstatus(GLenum status);
- protected:
- bool m_bInitialized;
- bool bExtensionsLoaded;
- bool bFBOavailable;
- bool bBLITavailable;
- bool bPBOavailable;
- bool bSWAPavailable;
- HWND m_hWnd;
- HANDLE m_hSharedMemory;
- SharedTextureInfo m_TextureInfo;
- GLuint m_TexID;
- unsigned int m_TexWidth;
- unsigned int m_TexHeight;
-
- ID3D11DeviceContext* g_pImmediateContext;
- D3D_DRIVER_TYPE g_driverType;
- D3D_FEATURE_LEVEL g_featureLevel;
-
- IDirect3D9Ex* m_pD3D;
-
- HANDLE m_hInteropDevice;
- HANDLE m_hInteropObject;
- HANDLE m_hAccessMutex;
-
- HANDLE m_hReceiverAccessMutex;
- bool getSharedTextureInfo(const char* sharedMemoryName);
- bool setSharedTextureInfo(const char* sharedMemoryName);
- bool OpenDeviceKey(const char* key, int maxsize, char *description, char *version);
- void trim(char * s);
- bool InitTexture(GLuint &texID, GLenum GLformat, unsigned int width, unsigned int height);
- };
- #endif
|