CmD3D9GpuProgram.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org/
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __D3D9GpuProgram_H_
  25. #define __D3D9GpuProgram_H_
  26. // Precompiler options
  27. #include "CmD3D9Prerequisites.h"
  28. #include "CmGpuProgram.h"
  29. #include "CmD3D9Resource.h"
  30. namespace CamelotFramework {
  31. /** Direct3D implementation of a few things common to low-level vertex & fragment programs. */
  32. class CM_D3D9_EXPORT D3D9GpuProgram : public GpuProgram, public D3D9Resource
  33. {
  34. public:
  35. ~D3D9GpuProgram();
  36. /** Sets whether matrix packing in column-major order. */
  37. void setColumnMajorMatrices(bool columnMajor) { mColumnMajorMatrices = columnMajor; }
  38. /** Gets whether matrix packed in column-major order. */
  39. bool getColumnMajorMatrices(void) const { return mColumnMajorMatrices; }
  40. /** Tells the program to load from some externally created microcode instead of a file or source.
  41. */
  42. void setExternalMicrocode(const void* pMicrocode, UINT32 size);
  43. /** Tells the program to load from some externally created microcode instead of a file or source.
  44. @remarks
  45. add ref count to pMicrocode when setting
  46. */
  47. void setExternalMicrocode(ID3DXBuffer* pMicrocode);
  48. /** Gets the external microcode buffer, if any. */
  49. LPD3DXBUFFER getExternalMicrocode(void);
  50. protected:
  51. friend class D3D9GpuProgramManager;
  52. D3D9GpuProgram(const String& source, const String& entryPoint, const String& language,
  53. GpuProgramType gptype, GpuProgramProfile profile);
  54. void createInternalResources(IDirect3DDevice9* d3d9Device);
  55. /**
  56. * @copydoc GpuProgram::initialize_internal().
  57. */
  58. void initialize_internal();
  59. /**
  60. * @copydoc GpuProgram::destroy_internal().
  61. */
  62. void destroy_internal();
  63. /** Loads this program from microcode, must be overridden by subclasses. */
  64. virtual void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode) = 0;
  65. /** Creates a new parameters object compatible with this program definition.
  66. @remarks
  67. It is recommended that you use this method of creating parameters objects
  68. rather than going direct to GpuProgramManager, because this method will
  69. populate any implementation-specific extras (like named parameters) where
  70. they are appropriate.
  71. */
  72. virtual GpuParamsPtr createParameters();
  73. protected:
  74. bool mColumnMajorMatrices;
  75. ID3DXBuffer* mpExternalMicrocode;
  76. };
  77. /** Direct3D implementation of low-level vertex programs. */
  78. class CM_D3D9_EXPORT D3D9GpuVertexProgram : public D3D9GpuProgram
  79. {
  80. public:
  81. ~D3D9GpuVertexProgram();
  82. /// Gets the vertex shader
  83. IDirect3DVertexShader9* getVertexShader(void);
  84. // Called immediately after the Direct3D device has been created.
  85. virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
  86. // Called before the Direct3D device is going to be destroyed.
  87. virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
  88. protected:
  89. friend class D3D9GpuProgramManager;
  90. D3D9GpuVertexProgram(const String& source, const String& entryPoint, const String& language, GpuProgramType gptype, GpuProgramProfile profile);
  91. /**
  92. * @copydoc D3D9GpuProgram::destroy_internal.
  93. */
  94. void destroy_internal();
  95. void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
  96. protected:
  97. typedef Map<IDirect3DDevice9*, IDirect3DVertexShader9*>::type DeviceToVertexShaderMap;
  98. typedef DeviceToVertexShaderMap::iterator DeviceToVertexShaderIterator;
  99. DeviceToVertexShaderMap mMapDeviceToVertexShader;
  100. };
  101. /** Direct3D implementation of low-level fragment programs. */
  102. class CM_D3D9_EXPORT D3D9GpuFragmentProgram : public D3D9GpuProgram
  103. {
  104. public:
  105. ~D3D9GpuFragmentProgram();
  106. /// Gets the pixel shader
  107. IDirect3DPixelShader9* getPixelShader(void);
  108. // Called immediately after the Direct3D device has been created.
  109. virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
  110. // Called before the Direct3D device is going to be destroyed.
  111. virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
  112. protected:
  113. friend class D3D9GpuProgramManager;
  114. D3D9GpuFragmentProgram(const String& source, const String& entryPoint, const String& language, GpuProgramType gptype, GpuProgramProfile profile);
  115. /**
  116. * @copydoc D3D9GpuProgram::destroy_internal.
  117. */
  118. void destroy_internal();
  119. void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
  120. protected:
  121. typedef Map<IDirect3DDevice9*, IDirect3DPixelShader9*>::type DeviceToPixelShaderMap;
  122. typedef DeviceToPixelShaderMap::iterator DeviceToPixelShaderIterator;
  123. DeviceToPixelShaderMap mMapDeviceToPixelShader;
  124. };
  125. typedef std::shared_ptr<D3D9GpuProgram> D3D9GpuProgramPtr;
  126. }
  127. #endif