cgD3D9.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /*
  2. *
  3. * Copyright (c) 2002-2009, NVIDIA Corporation.
  4. *
  5. *
  6. *
  7. * NVIDIA Corporation("NVIDIA") supplies this software to you in consideration
  8. * of your agreement to the following terms, and your use, installation,
  9. * modification or redistribution of this NVIDIA software constitutes
  10. * acceptance of these terms. If you do not agree with these terms, please do
  11. * not use, install, modify or redistribute this NVIDIA software.
  12. *
  13. *
  14. *
  15. * In consideration of your agreement to abide by the following terms, and
  16. * subject to these terms, NVIDIA grants you a personal, non-exclusive license,
  17. * under NVIDIA's copyrights in this original NVIDIA software (the "NVIDIA
  18. * Software"), to use, reproduce, modify and redistribute the NVIDIA
  19. * Software, with or without modifications, in source and/or binary forms;
  20. * provided that if you redistribute the NVIDIA Software, you must retain the
  21. * copyright notice of NVIDIA, this notice and the following text and
  22. * disclaimers in all such redistributions of the NVIDIA Software. Neither the
  23. * name, trademarks, service marks nor logos of NVIDIA Corporation may be used
  24. * to endorse or promote products derived from the NVIDIA Software without
  25. * specific prior written permission from NVIDIA. Except as expressly stated
  26. * in this notice, no other rights or licenses express or implied, are granted
  27. * by NVIDIA herein, including but not limited to any patent rights that may be
  28. * infringed by your derivative works or by other works in which the NVIDIA
  29. * Software may be incorporated. No hardware is licensed hereunder.
  30. *
  31. *
  32. *
  33. * THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
  34. * WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
  35. * WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  36. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR ITS USE AND OPERATION
  37. * EITHER ALONE OR IN COMBINATION WITH OTHER PRODUCTS.
  38. *
  39. *
  40. *
  41. * IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
  42. * EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOST
  43. * PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44. * PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY OUT OF THE USE,
  45. * REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE NVIDIA SOFTWARE,
  46. * HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING
  47. * NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF NVIDIA HAS BEEN ADVISED
  48. * OF THE POSSIBILITY OF SUCH DAMAGE.
  49. *
  50. */
  51. #ifndef CGD3D9_INCLUDED
  52. #define CGD3D9_INCLUDED
  53. #ifdef _WIN32
  54. #pragma once
  55. #include "cg.h"
  56. #include <d3d9.h>
  57. #include <d3dx9.h>
  58. // Set up for either Win32 import/export/lib.
  59. #include <windows.h>
  60. #ifdef CGD3D9DLL_EXPORTS
  61. #define CGD3D9DLL_API __declspec(dllexport)
  62. #elif defined (CG_LIB)
  63. #define CGD3D9DLL_API
  64. #else
  65. #define CGD3D9DLL_API __declspec(dllimport)
  66. #endif
  67. #ifndef CGD3D9ENTRY
  68. # ifdef _WIN32
  69. # define CGD3D9ENTRY __cdecl
  70. # else
  71. # define CGD3D9ENTRY
  72. # endif
  73. #endif
  74. /*---------------------------------------------------------------------------
  75. // CGerrors that will be fed to cgSetError
  76. // Use cgD3D9TranslateCGerror() to translate these errors into strings.
  77. ---------------------------------------------------------------------------*/
  78. enum cgD3D9Errors
  79. {
  80. cgD3D9Failed = 1000,
  81. cgD3D9DebugTrace = 1001,
  82. };
  83. /*---------------------------------------------------------------------------
  84. // HRESULTs specific to cgD3D9. When the CGerror is set to cgD3D9Failed
  85. // cgD3D9GetLastError will return an HRESULT that could be one these.
  86. // Use cgD3D9TranslateHRESULT() to translate these errors into strings.
  87. ---------------------------------------------------------------------------*/
  88. static const HRESULT CGD3D9ERR_NOTLOADED = MAKE_HRESULT(1, 0x877, 1);
  89. static const HRESULT CGD3D9ERR_NODEVICE = MAKE_HRESULT(1, 0x877, 2);
  90. static const HRESULT CGD3D9ERR_NOTSAMPLER = MAKE_HRESULT(1, 0x877, 3);
  91. static const HRESULT CGD3D9ERR_INVALIDPROFILE = MAKE_HRESULT(1, 0x877, 4);
  92. static const HRESULT CGD3D9ERR_NULLVALUE = MAKE_HRESULT(1, 0x877, 5);
  93. static const HRESULT CGD3D9ERR_OUTOFRANGE = MAKE_HRESULT(1, 0x877, 6);
  94. static const HRESULT CGD3D9ERR_NOTUNIFORM = MAKE_HRESULT(1, 0x877, 7);
  95. static const HRESULT CGD3D9ERR_NOTMATRIX = MAKE_HRESULT(1, 0x877, 8);
  96. static const HRESULT CGD3D9ERR_INVALIDPARAM = MAKE_HRESULT(1, 0x877, 9);
  97. /*---------------------------------------------------------------------------
  98. // Other error return values
  99. ---------------------------------------------------------------------------*/
  100. static const DWORD CGD3D9_INVALID_USAGE = 0xFF;
  101. #ifdef __cplusplus
  102. extern "C"
  103. {
  104. #endif
  105. #ifndef CGD3D9_EXPLICIT
  106. /*---------------------------------------------------------------------------
  107. // Minimal Interface
  108. ---------------------------------------------------------------------------*/
  109. CGD3D9DLL_API DWORD CGD3D9ENTRY
  110. cgD3D9TypeToSize(
  111. CGtype type
  112. );
  113. CGD3D9DLL_API BYTE CGD3D9ENTRY
  114. cgD3D9ResourceToDeclUsage(
  115. CGresource resource
  116. );
  117. CGD3D9DLL_API CGbool CGD3D9ENTRY
  118. cgD3D9GetVertexDeclaration(
  119. CGprogram prog,
  120. D3DVERTEXELEMENT9 decl[MAXD3DDECLLENGTH]
  121. );
  122. CGD3D9DLL_API CGbool CGD3D9ENTRY
  123. cgD3D9ValidateVertexDeclaration(
  124. CGprogram prog,
  125. const D3DVERTEXELEMENT9* decl
  126. );
  127. /*---------------------------------------------------------------------------
  128. // Expanded Interface
  129. ---------------------------------------------------------------------------*/
  130. /* ----- D3D Device Control ----------- */
  131. CGD3D9DLL_API IDirect3DDevice9 * CGD3D9ENTRY
  132. cgD3D9GetDevice();
  133. CGD3D9DLL_API HRESULT CGD3D9ENTRY
  134. cgD3D9SetDevice(
  135. IDirect3DDevice9* pDevice
  136. );
  137. /* ----- Shader Management ----------- */
  138. CGD3D9DLL_API HRESULT CGD3D9ENTRY
  139. cgD3D9LoadProgram(
  140. CGprogram prog,
  141. CGbool paramShadowing,
  142. DWORD assemFlags
  143. );
  144. CGD3D9DLL_API HRESULT CGD3D9ENTRY
  145. cgD3D9UnloadProgram(
  146. CGprogram prog
  147. );
  148. CGD3D9DLL_API CGbool CGD3D9ENTRY
  149. cgD3D9IsProgramLoaded(
  150. CGprogram prog
  151. );
  152. CGD3D9DLL_API HRESULT CGD3D9ENTRY
  153. cgD3D9BindProgram(
  154. CGprogram prog
  155. );
  156. /* ----- Parameter Management ----------- */
  157. CGD3D9DLL_API HRESULT CGD3D9ENTRY
  158. cgD3D9SetUniform(
  159. CGparameter param,
  160. const void* floats
  161. );
  162. CGD3D9DLL_API HRESULT CGD3D9ENTRY
  163. cgD3D9SetUniformArray(
  164. CGparameter param,
  165. DWORD offset,
  166. DWORD numItems,
  167. const void* values
  168. );
  169. CGD3D9DLL_API HRESULT CGD3D9ENTRY
  170. cgD3D9SetUniformMatrix(
  171. CGparameter param,
  172. const D3DMATRIX* matrix
  173. );
  174. CGD3D9DLL_API HRESULT CGD3D9ENTRY
  175. cgD3D9SetUniformMatrixArray(
  176. CGparameter param,
  177. DWORD offset,
  178. DWORD numItems,
  179. const D3DMATRIX* matrices
  180. );
  181. CGD3D9DLL_API HRESULT CGD3D9ENTRY
  182. cgD3D9SetTexture(
  183. CGparameter param,
  184. IDirect3DBaseTexture9* tex
  185. );
  186. CGD3D9DLL_API HRESULT CGD3D9ENTRY
  187. cgD3D9SetSamplerState(
  188. CGparameter param,
  189. D3DSAMPLERSTATETYPE type,
  190. DWORD value
  191. );
  192. CGD3D9DLL_API HRESULT CGD3D9ENTRY
  193. cgD3D9SetTextureWrapMode(
  194. CGparameter param,
  195. DWORD value
  196. );
  197. /* ----- Parameter Management (Shadowing) ----------- */
  198. CGD3D9DLL_API HRESULT CGD3D9ENTRY
  199. cgD3D9EnableParameterShadowing(
  200. CGprogram prog,
  201. CGbool enable
  202. );
  203. CGD3D9DLL_API CGbool CGD3D9ENTRY
  204. cgD3D9IsParameterShadowingEnabled(
  205. CGprogram prog
  206. );
  207. /* --------- Profile Options ----------------- */
  208. CGD3D9DLL_API CGprofile CGD3D9ENTRY
  209. cgD3D9GetLatestVertexProfile();
  210. CGD3D9DLL_API CGprofile CGD3D9ENTRY
  211. cgD3D9GetLatestPixelProfile();
  212. CGD3D9DLL_API const char * * CGD3D9ENTRY
  213. cgD3D9GetOptimalOptions(
  214. CGprofile profile
  215. );
  216. CGD3D9DLL_API CGbool CGD3D9ENTRY
  217. cgD3D9IsProfileSupported(
  218. CGprofile profile
  219. );
  220. /* --------- Error reporting ----------------- */
  221. CGD3D9DLL_API HRESULT CGD3D9ENTRY
  222. cgD3D9GetLastError();
  223. CGD3D9DLL_API const char * CGD3D9ENTRY
  224. cgD3D9TranslateCGerror(
  225. CGerror error
  226. );
  227. CGD3D9DLL_API const char * CGD3D9ENTRY
  228. cgD3D9TranslateHRESULT(
  229. HRESULT hr
  230. );
  231. CGD3D9DLL_API void CGD3D9ENTRY
  232. cgD3D9EnableDebugTracing(
  233. CGbool enable
  234. );
  235. /* --------- CgFX support -------------------- */
  236. CGD3D9DLL_API void CGD3D9ENTRY
  237. cgD3D9RegisterStates(
  238. CGcontext ctx
  239. );
  240. CGD3D9DLL_API void CGD3D9ENTRY
  241. cgD3D9SetManageTextureParameters(
  242. CGcontext ctx,
  243. CGbool flag
  244. );
  245. CGD3D9DLL_API CGbool CGD3D9ENTRY
  246. cgD3D9GetManageTextureParameters(
  247. CGcontext ctx
  248. );
  249. CGD3D9DLL_API IDirect3DBaseTexture9 * CGD3D9ENTRY
  250. cgD3D9GetTextureParameter(
  251. CGparameter param
  252. );
  253. CGD3D9DLL_API void CGD3D9ENTRY
  254. cgD3D9SetTextureParameter(
  255. CGparameter param,
  256. IDirect3DBaseTexture9 *tex
  257. );
  258. CGD3D9DLL_API void CGD3D9ENTRY
  259. cgD3D9UnloadAllPrograms( void );
  260. #endif
  261. #ifdef __cplusplus
  262. };
  263. #endif
  264. #endif // _WIN32
  265. #endif
粤ICP备19079148号