SpoutDirectX.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. spoutDirectX.h
  3. DirectX functions to manage DirectX 11 texture sharing
  4. Copyright (c) 2014 - 2017, Lynn Jarvis. All rights reserved.
  5. Redistribution and use in source and binary forms, with or without modification,
  6. are permitted provided that the following conditions are met:
  7. 1. Redistributions of source code must retain the above copyright notice,
  8. this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright notice,
  10. this list of conditions and the following disclaimer in the documentation
  11. and/or other materials provided with the distribution.
  12. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  13. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  14. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  15. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  16. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  17. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  18. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  19. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  20. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21. */
  22. #pragma once
  23. #ifndef __spoutDirectX__
  24. #define __spoutDirectX__
  25. #include "SpoutCommon.h"
  26. #include <windowsx.h>
  27. #include <d3d9.h>
  28. #include <d3d11.h>
  29. // #include <DXGI.h> // LJ DEBUG
  30. #include <string>
  31. #include <iostream>
  32. #pragma comment (lib, "d3d9.lib")
  33. #pragma comment (lib, "d3d11.lib")
  34. #pragma comment (lib, "DXGI.lib")
  35. using namespace std;
  36. class SPOUT_DLLEXP spoutDirectX {
  37. public:
  38. spoutDirectX();
  39. ~spoutDirectX();
  40. // DX9
  41. IDirect3D9Ex* CreateDX9object(); // Create a DirectX9 object
  42. IDirect3DDevice9Ex* CreateDX9device(IDirect3D9Ex* pD3D, HWND hWnd); // Create a DirectX9 device
  43. bool CreateSharedDX9Texture(IDirect3DDevice9Ex* pDevice, unsigned int width, unsigned int height, D3DFORMAT format, LPDIRECT3DTEXTURE9 &dxTexture, HANDLE &dxShareHandle);
  44. bool WriteDX9surface(IDirect3DDevice9Ex* pDevice, LPDIRECT3DTEXTURE9 dxTexture, LPDIRECT3DSURFACE9 source_surface);
  45. // DX11
  46. ID3D11Device* CreateDX11device(); // Create a DX11 device
  47. bool CreateSharedDX11Texture(ID3D11Device* pDevice, unsigned int width, unsigned int height, DXGI_FORMAT format, ID3D11Texture2D** pSharedTexture, HANDLE &dxShareHandle);
  48. bool CreateDX11StagingTexture(ID3D11Device* pDevice, unsigned int width, unsigned int height, DXGI_FORMAT format, ID3D11Texture2D** pStagingTexture);
  49. bool OpenDX11shareHandle(ID3D11Device* pDevice, ID3D11Texture2D** ppSharedTexture, HANDLE dxShareHandle);
  50. // Output adapter selection
  51. int GetNumAdapters(); // Get the number of graphics adapters in the system
  52. bool GetAdapterName(int index, char *adaptername, int maxchars); // Get an adapter name
  53. bool SetAdapter(int index); // Set required graphics adapter for output
  54. int GetAdapter(); // Get the current adapter index
  55. bool GetAdapterInfo(char *renderdescription, char *displaydescription, int maxchars);
  56. bool FindNVIDIA(int &nAdapter); // Find the index of the NVIDIA adapter in a multi-adapter system
  57. // Registry read/write - 20.11.15 - moved from interop class
  58. bool ReadDwordFromRegistry(DWORD *pValue, const char *subkey, const char *valuename);
  59. bool WriteDwordToRegistry(DWORD dwValue, const char *subkey, const char *valuename);
  60. // Mutex locks for shared texture access
  61. bool CreateAccessMutex(const char *name, HANDLE &hAccessMutex);
  62. void CloseAccessMutex(HANDLE &hAccessMutex);
  63. bool CheckAccess(HANDLE hAccessMutex);
  64. void AllowAccess(HANDLE hAccessMutex);
  65. // For debugging only - to toggle texture access locks disable/enable
  66. bool bUseAccessLocks;
  67. protected:
  68. IDXGIAdapter* GetAdapterPointer(int index); // Get adapter pointer for DirectX 11
  69. int g_AdapterIndex; // Used for DX9
  70. IDXGIAdapter* g_pAdapterDX11;
  71. ID3D11DeviceContext* g_pImmediateContext;
  72. D3D_DRIVER_TYPE g_driverType;
  73. D3D_FEATURE_LEVEL g_featureLevel;
  74. };
  75. #endif