GraphicsDefs.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. //
  2. // Copyright (c) 2008-2017 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../Container/HashBase.h"
  24. #include "../Math/StringHash.h"
  25. namespace Atomic
  26. {
  27. class Vector3;
  28. /// Graphics capability support level. Web platform (Emscripten) also uses OpenGL ES, but is considered a desktop platform capability-wise
  29. #if defined(IOS) || defined(TVOS) || defined(__ANDROID__) || defined(__arm__) || defined(__aarch64__)
  30. #define MOBILE_GRAPHICS
  31. #else
  32. #define DESKTOP_GRAPHICS
  33. #endif
  34. /// Primitive type.
  35. enum PrimitiveType
  36. {
  37. TRIANGLE_LIST = 0,
  38. LINE_LIST,
  39. POINT_LIST,
  40. TRIANGLE_STRIP,
  41. LINE_STRIP,
  42. TRIANGLE_FAN
  43. };
  44. /// %Geometry type for vertex shader geometry variations.
  45. enum GeometryType
  46. {
  47. GEOM_STATIC = 0,
  48. GEOM_SKINNED = 1,
  49. GEOM_INSTANCED = 2,
  50. GEOM_BILLBOARD = 3,
  51. GEOM_DIRBILLBOARD = 4,
  52. GEOM_TRAIL_FACE_CAMERA = 5,
  53. GEOM_TRAIL_BONE = 6,
  54. MAX_GEOMETRYTYPES = 7,
  55. // This is not a real geometry type for VS, but used to mark objects that do not desire to be instanced
  56. GEOM_STATIC_NOINSTANCING = 7,
  57. };
  58. /// Blending mode.
  59. enum BlendMode
  60. {
  61. BLEND_REPLACE = 0,
  62. BLEND_ADD,
  63. BLEND_MULTIPLY,
  64. BLEND_ALPHA,
  65. BLEND_ADDALPHA,
  66. BLEND_PREMULALPHA,
  67. BLEND_INVDESTALPHA,
  68. BLEND_SUBTRACT,
  69. BLEND_SUBTRACTALPHA,
  70. MAX_BLENDMODES
  71. };
  72. /// Depth or stencil compare mode.
  73. enum CompareMode
  74. {
  75. CMP_ALWAYS = 0,
  76. CMP_EQUAL,
  77. CMP_NOTEQUAL,
  78. CMP_LESS,
  79. CMP_LESSEQUAL,
  80. CMP_GREATER,
  81. CMP_GREATEREQUAL,
  82. MAX_COMPAREMODES
  83. };
  84. /// Culling mode.
  85. enum CullMode
  86. {
  87. CULL_NONE = 0,
  88. CULL_CCW,
  89. CULL_CW,
  90. MAX_CULLMODES
  91. };
  92. /// Fill mode.
  93. enum FillMode
  94. {
  95. FILL_SOLID = 0,
  96. FILL_WIREFRAME,
  97. FILL_POINT
  98. };
  99. /// Stencil operation.
  100. enum StencilOp
  101. {
  102. OP_KEEP = 0,
  103. OP_ZERO,
  104. OP_REF,
  105. OP_INCR,
  106. OP_DECR
  107. };
  108. /// Vertex/index buffer lock state.
  109. enum LockState
  110. {
  111. LOCK_NONE = 0,
  112. LOCK_HARDWARE,
  113. LOCK_SHADOW,
  114. LOCK_SCRATCH
  115. };
  116. /// Hardcoded legacy vertex elements.
  117. enum LegacyVertexElement
  118. {
  119. ELEMENT_POSITION = 0,
  120. ELEMENT_NORMAL,
  121. ELEMENT_COLOR,
  122. ELEMENT_TEXCOORD1,
  123. ELEMENT_TEXCOORD2,
  124. ELEMENT_CUBETEXCOORD1,
  125. ELEMENT_CUBETEXCOORD2,
  126. ELEMENT_TANGENT,
  127. ELEMENT_BLENDWEIGHTS,
  128. ELEMENT_BLENDINDICES,
  129. ELEMENT_INSTANCEMATRIX1,
  130. ELEMENT_INSTANCEMATRIX2,
  131. ELEMENT_INSTANCEMATRIX3,
  132. // Custom 32-bit integer object index. Due to API limitations, not supported on D3D9
  133. ELEMENT_OBJECTINDEX,
  134. MAX_LEGACY_VERTEX_ELEMENTS
  135. };
  136. /// Arbitrary vertex declaration element datatypes.
  137. enum VertexElementType
  138. {
  139. TYPE_INT = 0,
  140. TYPE_FLOAT,
  141. TYPE_VECTOR2,
  142. TYPE_VECTOR3,
  143. TYPE_VECTOR4,
  144. TYPE_UBYTE4,
  145. TYPE_UBYTE4_NORM,
  146. MAX_VERTEX_ELEMENT_TYPES
  147. };
  148. /// Arbitrary vertex declaration element semantics.
  149. enum VertexElementSemantic
  150. {
  151. SEM_POSITION = 0,
  152. SEM_NORMAL,
  153. SEM_BINORMAL,
  154. SEM_TANGENT,
  155. SEM_TEXCOORD,
  156. SEM_COLOR,
  157. SEM_BLENDWEIGHTS,
  158. SEM_BLENDINDICES,
  159. SEM_OBJECTINDEX,
  160. MAX_VERTEX_ELEMENT_SEMANTICS
  161. };
  162. /// Vertex element description for arbitrary vertex declarations.
  163. struct ATOMIC_API VertexElement
  164. {
  165. /// Default-construct.
  166. VertexElement() :
  167. type_(TYPE_VECTOR3),
  168. semantic_(SEM_POSITION),
  169. index_(0),
  170. perInstance_(false),
  171. offset_(0)
  172. {
  173. }
  174. /// Construct with type, semantic, index and whether is per-instance data.
  175. VertexElement(VertexElementType type, VertexElementSemantic semantic, unsigned char index = 0, bool perInstance = false) :
  176. type_(type),
  177. semantic_(semantic),
  178. index_(index),
  179. perInstance_(perInstance),
  180. offset_(0)
  181. {
  182. }
  183. /// Test for equality with another vertex element. Offset is intentionally not compared, as it's relevant only when an element exists within a vertex buffer.
  184. bool operator ==(const VertexElement& rhs) const { return type_ == rhs.type_ && semantic_ == rhs.semantic_ && index_ == rhs.index_ && perInstance_ == rhs.perInstance_; }
  185. /// Test for inequality with another vertex element.
  186. bool operator !=(const VertexElement& rhs) const { return !(*this == rhs); }
  187. /// Data type of element.
  188. VertexElementType type_;
  189. /// Semantic of element.
  190. VertexElementSemantic semantic_;
  191. /// Semantic index of element, for example multi-texcoords.
  192. unsigned char index_;
  193. /// Per-instance flag.
  194. bool perInstance_;
  195. /// Offset of element from vertex start. Filled by VertexBuffer once the vertex declaration is built.
  196. unsigned offset_;
  197. };
  198. /// Sizes of vertex element types.
  199. extern ATOMIC_API const unsigned ELEMENT_TYPESIZES[];
  200. /// Vertex element definitions for the legacy elements.
  201. extern ATOMIC_API const VertexElement LEGACY_VERTEXELEMENTS[];
  202. /// Texture filtering mode.
  203. enum TextureFilterMode
  204. {
  205. FILTER_NEAREST = 0,
  206. FILTER_BILINEAR,
  207. FILTER_TRILINEAR,
  208. FILTER_ANISOTROPIC,
  209. FILTER_NEAREST_ANISOTROPIC,
  210. FILTER_DEFAULT,
  211. MAX_FILTERMODES
  212. };
  213. /// Texture addressing mode.
  214. enum TextureAddressMode
  215. {
  216. ADDRESS_WRAP = 0,
  217. ADDRESS_MIRROR,
  218. ADDRESS_CLAMP,
  219. ADDRESS_BORDER,
  220. MAX_ADDRESSMODES
  221. };
  222. /// Texture coordinates.
  223. enum TextureCoordinate
  224. {
  225. COORD_U = 0,
  226. COORD_V,
  227. COORD_W,
  228. MAX_COORDS
  229. };
  230. /// Texture usage types.
  231. enum TextureUsage
  232. {
  233. TEXTURE_STATIC = 0,
  234. TEXTURE_DYNAMIC,
  235. TEXTURE_RENDERTARGET,
  236. TEXTURE_DEPTHSTENCIL
  237. };
  238. /// Cube map faces.
  239. enum CubeMapFace
  240. {
  241. FACE_POSITIVE_X = 0,
  242. FACE_NEGATIVE_X,
  243. FACE_POSITIVE_Y,
  244. FACE_NEGATIVE_Y,
  245. FACE_POSITIVE_Z,
  246. FACE_NEGATIVE_Z,
  247. MAX_CUBEMAP_FACES
  248. };
  249. /// Cubemap single image layout modes.
  250. enum CubeMapLayout
  251. {
  252. CML_HORIZONTAL = 0,
  253. CML_HORIZONTALNVIDIA,
  254. CML_HORIZONTALCROSS,
  255. CML_VERTICALCROSS,
  256. CML_BLENDER
  257. };
  258. /// Update mode for render surface viewports.
  259. enum RenderSurfaceUpdateMode
  260. {
  261. SURFACE_MANUALUPDATE = 0,
  262. SURFACE_UPDATEVISIBLE,
  263. SURFACE_UPDATEALWAYS
  264. };
  265. /// Shader types.
  266. enum ShaderType
  267. {
  268. VS = 0,
  269. PS,
  270. };
  271. /// Shader parameter groups for determining need to update. On APIs that support constant buffers, these correspond to different constant buffers.
  272. enum ShaderParameterGroup
  273. {
  274. SP_FRAME = 0,
  275. SP_CAMERA,
  276. SP_ZONE,
  277. SP_LIGHT,
  278. SP_MATERIAL,
  279. SP_OBJECT,
  280. SP_CUSTOM,
  281. MAX_SHADER_PARAMETER_GROUPS
  282. };
  283. /// Texture units.
  284. enum TextureUnit
  285. {
  286. TU_DIFFUSE = 0,
  287. TU_ALBEDOBUFFER = 0,
  288. TU_NORMAL = 1,
  289. TU_NORMALBUFFER = 1,
  290. TU_SPECULAR = 2,
  291. TU_EMISSIVE = 3,
  292. TU_ENVIRONMENT = 4,
  293. #ifdef DESKTOP_GRAPHICS
  294. TU_VOLUMEMAP = 5,
  295. TU_CUSTOM1 = 6,
  296. TU_CUSTOM2 = 7,
  297. TU_LIGHTRAMP = 8,
  298. TU_LIGHTSHAPE = 9,
  299. TU_SHADOWMAP = 10,
  300. TU_FACESELECT = 11,
  301. TU_INDIRECTION = 12,
  302. TU_DEPTHBUFFER = 13,
  303. TU_LIGHTBUFFER = 14,
  304. TU_ZONE = 15,
  305. MAX_MATERIAL_TEXTURE_UNITS = 8,
  306. MAX_TEXTURE_UNITS = 16
  307. #else
  308. TU_LIGHTRAMP = 5,
  309. TU_LIGHTSHAPE = 6,
  310. TU_SHADOWMAP = 7,
  311. MAX_MATERIAL_TEXTURE_UNITS = 5,
  312. MAX_TEXTURE_UNITS = 8
  313. #endif
  314. };
  315. /// Billboard camera facing modes.
  316. enum FaceCameraMode
  317. {
  318. FC_NONE = 0,
  319. FC_ROTATE_XYZ,
  320. FC_ROTATE_Y,
  321. FC_LOOKAT_XYZ,
  322. FC_LOOKAT_Y,
  323. FC_LOOKAT_MIXED,
  324. FC_DIRECTION,
  325. };
  326. /// Shadow type.
  327. enum ShadowQuality
  328. {
  329. SHADOWQUALITY_SIMPLE_16BIT = 0,
  330. SHADOWQUALITY_SIMPLE_24BIT,
  331. SHADOWQUALITY_PCF_16BIT,
  332. SHADOWQUALITY_PCF_24BIT,
  333. SHADOWQUALITY_VSM,
  334. SHADOWQUALITY_BLUR_VSM
  335. };
  336. // Inbuilt shader parameters.
  337. extern ATOMIC_API const StringHash VSP_AMBIENTSTARTCOLOR;
  338. extern ATOMIC_API const StringHash VSP_AMBIENTENDCOLOR;
  339. extern ATOMIC_API const StringHash VSP_BILLBOARDROT;
  340. extern ATOMIC_API const StringHash VSP_CAMERAPOS;
  341. extern ATOMIC_API const StringHash VSP_CLIPPLANE;
  342. extern ATOMIC_API const StringHash VSP_NEARCLIP;
  343. extern ATOMIC_API const StringHash VSP_FARCLIP;
  344. extern ATOMIC_API const StringHash VSP_DEPTHMODE;
  345. extern ATOMIC_API const StringHash VSP_DELTATIME;
  346. extern ATOMIC_API const StringHash VSP_ELAPSEDTIME;
  347. extern ATOMIC_API const StringHash VSP_FRUSTUMSIZE;
  348. extern ATOMIC_API const StringHash VSP_GBUFFEROFFSETS;
  349. extern ATOMIC_API const StringHash VSP_LIGHTDIR;
  350. extern ATOMIC_API const StringHash VSP_LIGHTPOS;
  351. extern ATOMIC_API const StringHash VSP_NORMALOFFSETSCALE;
  352. extern ATOMIC_API const StringHash VSP_MODEL;
  353. extern ATOMIC_API const StringHash VSP_VIEW;
  354. extern ATOMIC_API const StringHash VSP_VIEWINV;
  355. extern ATOMIC_API const StringHash VSP_VIEWPROJ;
  356. extern ATOMIC_API const StringHash VSP_UOFFSET;
  357. extern ATOMIC_API const StringHash VSP_VOFFSET;
  358. extern ATOMIC_API const StringHash VSP_ZONE;
  359. extern ATOMIC_API const StringHash VSP_LIGHTMATRICES;
  360. extern ATOMIC_API const StringHash VSP_SKINMATRICES;
  361. extern ATOMIC_API const StringHash VSP_VERTEXLIGHTS;
  362. extern ATOMIC_API const StringHash PSP_AMBIENTCOLOR;
  363. extern ATOMIC_API const StringHash PSP_CAMERAPOS;
  364. extern ATOMIC_API const StringHash PSP_DELTATIME;
  365. extern ATOMIC_API const StringHash PSP_DEPTHRECONSTRUCT;
  366. extern ATOMIC_API const StringHash PSP_ELAPSEDTIME;
  367. extern ATOMIC_API const StringHash PSP_FOGCOLOR;
  368. extern ATOMIC_API const StringHash PSP_FOGPARAMS;
  369. extern ATOMIC_API const StringHash PSP_GBUFFERINVSIZE;
  370. extern ATOMIC_API const StringHash PSP_LIGHTCOLOR;
  371. extern ATOMIC_API const StringHash PSP_LIGHTDIR;
  372. extern ATOMIC_API const StringHash PSP_LIGHTPOS;
  373. extern ATOMIC_API const StringHash PSP_NORMALOFFSETSCALE;
  374. extern ATOMIC_API const StringHash PSP_MATDIFFCOLOR;
  375. extern ATOMIC_API const StringHash PSP_MATEMISSIVECOLOR;
  376. extern ATOMIC_API const StringHash PSP_MATENVMAPCOLOR;
  377. extern ATOMIC_API const StringHash PSP_MATSPECCOLOR;
  378. extern ATOMIC_API const StringHash PSP_NEARCLIP;
  379. extern ATOMIC_API const StringHash PSP_FARCLIP;
  380. extern ATOMIC_API const StringHash PSP_SHADOWCUBEADJUST;
  381. extern ATOMIC_API const StringHash PSP_SHADOWDEPTHFADE;
  382. extern ATOMIC_API const StringHash PSP_SHADOWINTENSITY;
  383. extern ATOMIC_API const StringHash PSP_SHADOWMAPINVSIZE;
  384. extern ATOMIC_API const StringHash PSP_SHADOWSPLITS;
  385. extern ATOMIC_API const StringHash PSP_LIGHTMATRICES;
  386. extern ATOMIC_API const StringHash PSP_VSMSHADOWPARAMS;
  387. extern ATOMIC_API const StringHash PSP_ROUGHNESS;
  388. extern ATOMIC_API const StringHash PSP_METALLIC;
  389. extern ATOMIC_API const StringHash PSP_LIGHTRAD;
  390. extern ATOMIC_API const StringHash PSP_LIGHTLENGTH;
  391. extern ATOMIC_API const StringHash PSP_ZONEMIN;
  392. extern ATOMIC_API const StringHash PSP_ZONEMAX;
  393. // Scale calculation from bounding box diagonal.
  394. extern ATOMIC_API const Vector3 DOT_SCALE;
  395. static const int QUALITY_LOW = 0;
  396. static const int QUALITY_MEDIUM = 1;
  397. static const int QUALITY_HIGH = 2;
  398. static const int QUALITY_MAX = 15;
  399. static const unsigned CLEAR_COLOR = 0x1;
  400. static const unsigned CLEAR_DEPTH = 0x2;
  401. static const unsigned CLEAR_STENCIL = 0x4;
  402. // Legacy vertex element bitmasks.
  403. static const unsigned MASK_NONE = 0x0;
  404. static const unsigned MASK_POSITION = 0x1;
  405. static const unsigned MASK_NORMAL = 0x2;
  406. static const unsigned MASK_COLOR = 0x4;
  407. static const unsigned MASK_TEXCOORD1 = 0x8;
  408. static const unsigned MASK_TEXCOORD2 = 0x10;
  409. static const unsigned MASK_CUBETEXCOORD1 = 0x20;
  410. static const unsigned MASK_CUBETEXCOORD2 = 0x40;
  411. static const unsigned MASK_TANGENT = 0x80;
  412. static const unsigned MASK_BLENDWEIGHTS = 0x100;
  413. static const unsigned MASK_BLENDINDICES = 0x200;
  414. static const unsigned MASK_INSTANCEMATRIX1 = 0x400;
  415. static const unsigned MASK_INSTANCEMATRIX2 = 0x800;
  416. static const unsigned MASK_INSTANCEMATRIX3 = 0x1000;
  417. static const unsigned MASK_OBJECTINDEX = 0x2000;
  418. static const int MAX_RENDERTARGETS = 4;
  419. static const int MAX_VERTEX_STREAMS = 4;
  420. static const int MAX_CONSTANT_REGISTERS = 256;
  421. static const int BITS_PER_COMPONENT = 8;
  422. }