cgD3D8.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 CGD3D8_INCLUDED
  52. #define CGD3D8_INCLUDED
  53. #ifdef _WIN32
  54. #pragma once
  55. #include "cg.h"
  56. #include <d3d8.h>
  57. #include <d3dx8.h>
  58. // Set up for either Win32 import/export/lib.
  59. #include <windows.h>
  60. #ifdef CGD3D8DLL_EXPORTS
  61. #define CGD3D8DLL_API __declspec(dllexport)
  62. #elif defined (CG_LIB)
  63. #define CGD3D8DLL_API
  64. #else
  65. #define CGD3D8DLL_API __declspec(dllimport)
  66. #endif
  67. #ifndef CGD3D8ENTRY
  68. # ifdef _WIN32
  69. # define CGD3D8ENTRY __cdecl
  70. # else
  71. # define CGD3D8ENTRY
  72. # endif
  73. #endif
  74. /*---------------------------------------------------------------------------
  75. // CGerrors that will be fed to cgSetError
  76. // Use cgD3D8TranslateCGerror() to translate these errors into strings.
  77. ---------------------------------------------------------------------------*/
  78. enum cgD3D8Errors
  79. {
  80. cgD3D8Failed = 1000,
  81. cgD3D8DebugTrace = 1001,
  82. };
  83. /*---------------------------------------------------------------------------
  84. // HRESULTs specific to cgD3D8. When the CGerror is set to cgD3D8Failed
  85. // cgD3D8GetLastError will return an HRESULT that could be one these.
  86. // Use cgD3D8TranslateHRESULT() to translate these errors into strings.
  87. ---------------------------------------------------------------------------*/
  88. static const HRESULT CGD3D8ERR_NOTLOADED = MAKE_HRESULT(1, 0x877, 1);
  89. static const HRESULT CGD3D8ERR_NODEVICE = MAKE_HRESULT(1, 0x877, 2);
  90. static const HRESULT CGD3D8ERR_NOTSAMPLER = MAKE_HRESULT(1, 0x877, 3);
  91. static const HRESULT CGD3D8ERR_INVALIDPROFILE = MAKE_HRESULT(1, 0x877, 4);
  92. static const HRESULT CGD3D8ERR_NULLVALUE = MAKE_HRESULT(1, 0x877, 5);
  93. static const HRESULT CGD3D8ERR_OUTOFRANGE = MAKE_HRESULT(1, 0x877, 6);
  94. static const HRESULT CGD3D8ERR_NOTUNIFORM = MAKE_HRESULT(1, 0x877, 7);
  95. static const HRESULT CGD3D8ERR_NOTMATRIX = MAKE_HRESULT(1, 0x877, 8);
  96. static const HRESULT CGD3D8ERR_INVALIDPARAM = MAKE_HRESULT(1, 0x877, 9);
  97. static const HRESULT CGD3D8ERR_INVALIDSAMPLERSTATE = MAKE_HRESULT(1, 0x877, 100);
  98. static const HRESULT CGD3D8ERR_INVALIDVEREXDECL = MAKE_HRESULT(1, 0x877, 101);
  99. /*---------------------------------------------------------------------------
  100. // Other error return values
  101. ---------------------------------------------------------------------------*/
  102. static const DWORD CGD3D8_INVALID_REG = 0xFFFFFFFF;
  103. #ifdef __cplusplus
  104. extern "C"
  105. {
  106. #endif
  107. /*---------------------------------------------------------------------------
  108. // Minimal Interface
  109. ---------------------------------------------------------------------------*/
  110. CGD3D8DLL_API DWORD CGD3D8ENTRY
  111. cgD3D8TypeToSize(
  112. CGtype type
  113. );
  114. CGD3D8DLL_API DWORD CGD3D8ENTRY
  115. cgD3D8ResourceToInputRegister(
  116. CGresource resource
  117. );
  118. CGD3D8DLL_API CGbool CGD3D8ENTRY
  119. cgD3D8GetVertexDeclaration(
  120. CGprogram prog,
  121. DWORD decl[MAX_FVF_DECL_SIZE]
  122. );
  123. CGD3D8DLL_API CGbool CGD3D8ENTRY
  124. cgD3D8ValidateVertexDeclaration(
  125. CGprogram prog,
  126. const DWORD* decl
  127. );
  128. /*---------------------------------------------------------------------------
  129. // Expanded Interface
  130. ---------------------------------------------------------------------------*/
  131. /* ----- D3D Device Control ----------- */
  132. CGD3D8DLL_API IDirect3DDevice8 * CGD3D8ENTRY
  133. cgD3D8GetDevice();
  134. CGD3D8DLL_API HRESULT CGD3D8ENTRY
  135. cgD3D8SetDevice(
  136. IDirect3DDevice8* pDevice
  137. );
  138. /* ----- Shader Management ----------- */
  139. CGD3D8DLL_API HRESULT CGD3D8ENTRY
  140. cgD3D8LoadProgram(
  141. CGprogram prog,
  142. CGbool paramShadowing,
  143. DWORD assemFlags,
  144. DWORD vshaderUsage,
  145. const DWORD* vertexDecl
  146. );
  147. CGD3D8DLL_API HRESULT CGD3D8ENTRY
  148. cgD3D8UnloadProgram(
  149. CGprogram prog
  150. );
  151. CGD3D8DLL_API CGbool CGD3D8ENTRY
  152. cgD3D8IsProgramLoaded(
  153. CGprogram prog
  154. );
  155. CGD3D8DLL_API HRESULT CGD3D8ENTRY
  156. cgD3D8BindProgram(
  157. CGprogram prog
  158. );
  159. /* ----- Parameter Management ----------- */
  160. CGD3D8DLL_API HRESULT CGD3D8ENTRY
  161. cgD3D8SetUniform(
  162. CGparameter param,
  163. const void* floats
  164. );
  165. CGD3D8DLL_API HRESULT CGD3D8ENTRY
  166. cgD3D8SetUniformArray(
  167. CGparameter param,
  168. DWORD offset,
  169. DWORD numItems,
  170. const void* values
  171. );
  172. CGD3D8DLL_API HRESULT CGD3D8ENTRY
  173. cgD3D8SetUniformMatrix(
  174. CGparameter param,
  175. const D3DMATRIX* matrix
  176. );
  177. CGD3D8DLL_API HRESULT CGD3D8ENTRY
  178. cgD3D8SetUniformMatrixArray(
  179. CGparameter param,
  180. DWORD offset,
  181. DWORD numItems,
  182. const D3DMATRIX* matrices
  183. );
  184. CGD3D8DLL_API HRESULT CGD3D8ENTRY
  185. cgD3D8SetTexture(
  186. CGparameter param,
  187. IDirect3DBaseTexture8* tex
  188. );
  189. CGD3D8DLL_API HRESULT CGD3D8ENTRY
  190. cgD3D8SetTextureStageState(
  191. CGparameter param,
  192. D3DTEXTURESTAGESTATETYPE type,
  193. DWORD value
  194. );
  195. CGD3D8DLL_API HRESULT CGD3D8ENTRY
  196. cgD3D8SetTextureWrapMode(
  197. CGparameter param,
  198. DWORD value
  199. );
  200. /* ----- Parameter Management (Shadowing) ----------- */
  201. CGD3D8DLL_API HRESULT CGD3D8ENTRY
  202. cgD3D8EnableParameterShadowing(
  203. CGprogram prog,
  204. CGbool enable
  205. );
  206. CGD3D8DLL_API CGbool CGD3D8ENTRY
  207. cgD3D8IsParameterShadowingEnabled(
  208. CGprogram prog
  209. );
  210. /* --------- Profile Options ----------------- */
  211. CGD3D8DLL_API CGprofile CGD3D8ENTRY
  212. cgD3D8GetLatestVertexProfile();
  213. CGD3D8DLL_API CGprofile CGD3D8ENTRY
  214. cgD3D8GetLatestPixelProfile();
  215. CGD3D8DLL_API const char * CGD3D8ENTRY
  216. cgD3D8GetOptimalOptions(
  217. CGprofile profile
  218. );
  219. /* --------- Error reporting ----------------- */
  220. CGD3D8DLL_API HRESULT CGD3D8ENTRY
  221. cgD3D8GetLastError();
  222. CGD3D8DLL_API const char * CGD3D8ENTRY
  223. cgD3D8TranslateCGerror(
  224. CGerror error
  225. );
  226. CGD3D8DLL_API const char * CGD3D8ENTRY
  227. cgD3D8TranslateHRESULT(
  228. HRESULT hr
  229. );
  230. CGD3D8DLL_API void CGD3D8ENTRY
  231. cgD3D8EnableDebugTracing(
  232. CGbool enable
  233. );
  234. #ifdef __cplusplus
  235. };
  236. #endif
  237. #endif // _WIN32
  238. #endif
粤ICP备19079148号