CmD3D9GpuProgram.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 CamelotEngine {
  31. /** Direct3D implementation of a few things common to low-level vertex & fragment programs. */
  32. class _OgreD3D9Export D3D9GpuProgram : public GpuProgram, public D3D9Resource
  33. {
  34. public:
  35. D3D9GpuProgram();
  36. ~D3D9GpuProgram();
  37. virtual void load(void);
  38. /** Loads this program to specified device */
  39. virtual void load(IDirect3DDevice9* d3d9Device);
  40. /** Overridden from GpuProgram */
  41. virtual void unload(void);
  42. /** Sets whether matrix packing in column-major order. */
  43. void setColumnMajorMatrices(bool columnMajor) { mColumnMajorMatrices = columnMajor; }
  44. /** Gets whether matrix packed in column-major order. */
  45. bool getColumnMajorMatrices(void) const { return mColumnMajorMatrices; }
  46. /** Tells the program to load from some externally created microcode instead of a file or source.
  47. */
  48. void setExternalMicrocode(const void* pMicrocode, size_t size);
  49. /** Tells the program to load from some externally created microcode instead of a file or source.
  50. @remarks
  51. add ref count to pMicrocode when setting
  52. */
  53. void setExternalMicrocode(ID3DXBuffer* pMicrocode);
  54. /** Gets the external microcode buffer, if any. */
  55. LPD3DXBUFFER getExternalMicrocode(void);
  56. protected:
  57. /** Overridden from GpuProgram */
  58. void loadFromSource(void);
  59. /** Loads this program from source to specified device */
  60. void loadFromSource(IDirect3DDevice9* d3d9Device);
  61. /** Loads this program from microcode, must be overridden by subclasses. */
  62. virtual void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode) = 0;
  63. /** Creates a new parameters object compatible with this program definition.
  64. @remarks
  65. It is recommended that you use this method of creating parameters objects
  66. rather than going direct to GpuProgramManager, because this method will
  67. populate any implementation-specific extras (like named parameters) where
  68. they are appropriate.
  69. */
  70. virtual GpuProgramParametersSharedPtr createParameters(void);
  71. protected:
  72. bool mColumnMajorMatrices;
  73. ID3DXBuffer* mpExternalMicrocode;
  74. };
  75. /** Direct3D implementation of low-level vertex programs. */
  76. class _OgreD3D9Export D3D9GpuVertexProgram : public D3D9GpuProgram
  77. {
  78. public:
  79. D3D9GpuVertexProgram();
  80. ~D3D9GpuVertexProgram();
  81. void unload(void);
  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. void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
  90. protected:
  91. typedef map<IDirect3DDevice9*, IDirect3DVertexShader9*>::type DeviceToVertexShaderMap;
  92. typedef DeviceToVertexShaderMap::iterator DeviceToVertexShaderIterator;
  93. DeviceToVertexShaderMap mMapDeviceToVertexShader;
  94. };
  95. /** Direct3D implementation of low-level fragment programs. */
  96. class _OgreD3D9Export D3D9GpuFragmentProgram : public D3D9GpuProgram
  97. {
  98. public:
  99. D3D9GpuFragmentProgram();
  100. ~D3D9GpuFragmentProgram();
  101. void unload(void);
  102. /// Gets the pixel shader
  103. IDirect3DPixelShader9* getPixelShader(void);
  104. // Called immediately after the Direct3D device has been created.
  105. virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
  106. // Called before the Direct3D device is going to be destroyed.
  107. virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
  108. protected:
  109. void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
  110. protected:
  111. typedef map<IDirect3DDevice9*, IDirect3DPixelShader9*>::type DeviceToPixelShaderMap;
  112. typedef DeviceToPixelShaderMap::iterator DeviceToPixelShaderIterator;
  113. DeviceToPixelShaderMap mMapDeviceToPixelShader;
  114. };
  115. typedef std::shared_ptr<D3D9GpuProgram> D3D9GpuProgramPtr;
  116. }
  117. #endif