GraphicsDefs.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. //
  2. // Copyright (c) 2008-2016 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(__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.
  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. GEOM_STATIC_NOINSTANCING = 7,
  55. MAX_GEOMETRYTYPES = 7,
  56. };
  57. /// Blending mode.
  58. enum BlendMode
  59. {
  60. BLEND_REPLACE = 0,
  61. BLEND_ADD,
  62. BLEND_MULTIPLY,
  63. BLEND_ALPHA,
  64. BLEND_ADDALPHA,
  65. BLEND_PREMULALPHA,
  66. BLEND_INVDESTALPHA,
  67. BLEND_SUBTRACT,
  68. BLEND_SUBTRACTALPHA,
  69. MAX_BLENDMODES
  70. };
  71. /// Depth or stencil compare mode.
  72. enum CompareMode
  73. {
  74. CMP_ALWAYS = 0,
  75. CMP_EQUAL,
  76. CMP_NOTEQUAL,
  77. CMP_LESS,
  78. CMP_LESSEQUAL,
  79. CMP_GREATER,
  80. CMP_GREATEREQUAL,
  81. MAX_COMPAREMODES
  82. };
  83. /// Culling mode.
  84. enum CullMode
  85. {
  86. CULL_NONE = 0,
  87. CULL_CCW,
  88. CULL_CW,
  89. MAX_CULLMODES
  90. };
  91. /// Fill mode.
  92. enum FillMode
  93. {
  94. FILL_SOLID = 0,
  95. FILL_WIREFRAME,
  96. FILL_POINT
  97. };
  98. /// Stencil operation.
  99. enum StencilOp
  100. {
  101. OP_KEEP = 0,
  102. OP_ZERO,
  103. OP_REF,
  104. OP_INCR,
  105. OP_DECR
  106. };
  107. /// Vertex/index buffer lock state.
  108. enum LockState
  109. {
  110. LOCK_NONE = 0,
  111. LOCK_HARDWARE,
  112. LOCK_SHADOW,
  113. LOCK_SCRATCH
  114. };
  115. /// Hardcoded legacy vertex elements.
  116. enum LegacyVertexElement
  117. {
  118. ELEMENT_POSITION = 0,
  119. ELEMENT_NORMAL,
  120. ELEMENT_COLOR,
  121. ELEMENT_TEXCOORD1,
  122. ELEMENT_TEXCOORD2,
  123. ELEMENT_CUBETEXCOORD1,
  124. ELEMENT_CUBETEXCOORD2,
  125. ELEMENT_TANGENT,
  126. ELEMENT_BLENDWEIGHTS,
  127. ELEMENT_BLENDINDICES,
  128. ELEMENT_INSTANCEMATRIX1,
  129. ELEMENT_INSTANCEMATRIX2,
  130. ELEMENT_INSTANCEMATRIX3,
  131. // Custom 32-bit integer object index. Due to API limitations, not supported on D3D9
  132. ELEMENT_OBJECTINDEX,
  133. MAX_LEGACY_VERTEX_ELEMENTS
  134. };
  135. /// Arbitrary vertex declaration element datatypes.
  136. enum VertexElementType
  137. {
  138. TYPE_INT = 0,
  139. TYPE_FLOAT,
  140. TYPE_VECTOR2,
  141. TYPE_VECTOR3,
  142. TYPE_VECTOR4,
  143. TYPE_UBYTE4,
  144. TYPE_UBYTE4_NORM,
  145. MAX_VERTEX_ELEMENT_TYPES
  146. };
  147. /// Arbitrary vertex declaration element semantics.
  148. enum VertexElementSemantic
  149. {
  150. SEM_POSITION = 0,
  151. SEM_NORMAL,
  152. SEM_BINORMAL,
  153. SEM_TANGENT,
  154. SEM_TEXCOORD,
  155. SEM_COLOR,
  156. SEM_BLENDWEIGHTS,
  157. SEM_BLENDINDICES,
  158. SEM_OBJECTINDEX,
  159. MAX_VERTEX_ELEMENT_SEMANTICS
  160. };
  161. /// Vertex element description for arbitrary vertex declarations.
  162. struct ATOMIC_API VertexElement
  163. {
  164. /// Default-construct.
  165. VertexElement() :
  166. type_(TYPE_VECTOR3),
  167. semantic_(SEM_POSITION),
  168. index_(0),
  169. perInstance_(false),
  170. offset_(0)
  171. {
  172. }
  173. /// Construct with type, semantic, index and whether is per-instance data.
  174. VertexElement(VertexElementType type, VertexElementSemantic semantic, unsigned char index = 0, bool perInstance = false) :
  175. type_(type),
  176. semantic_(semantic),
  177. index_(index),
  178. perInstance_(perInstance),
  179. offset_(0)
  180. {
  181. }
  182. /// 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.
  183. bool operator ==(const VertexElement& rhs) const { return type_ == rhs.type_ && semantic_ == rhs.semantic_ && index_ == rhs.index_ && perInstance_ == rhs.perInstance_; }
  184. /// Test for inequality with another vertex element.
  185. bool operator !=(const VertexElement& rhs) const { return !(*this == rhs); }
  186. /// Data type of element.
  187. VertexElementType type_;
  188. /// Semantic of element.
  189. VertexElementSemantic semantic_;
  190. /// Semantic index of element, for example multi-texcoords.
  191. unsigned char index_;
  192. /// Per-instance flag.
  193. bool perInstance_;
  194. /// Offset of element from vertex start. Filled by VertexBuffer once the vertex declaration is built.
  195. unsigned offset_;
  196. };
  197. /// Sizes of vertex element types.
  198. extern ATOMIC_API const unsigned ELEMENT_TYPESIZES[];
  199. /// Vertex element definitions for the legacy elements.
  200. extern ATOMIC_API const VertexElement LEGACY_VERTEXELEMENTS[];
  201. /// Texture filtering mode.
  202. enum TextureFilterMode
  203. {
  204. FILTER_NEAREST = 0,
  205. FILTER_BILINEAR,
  206. FILTER_TRILINEAR,
  207. FILTER_ANISOTROPIC,
  208. FILTER_DEFAULT,
  209. MAX_FILTERMODES
  210. };
  211. /// Texture addressing mode.
  212. enum TextureAddressMode
  213. {
  214. ADDRESS_WRAP = 0,
  215. ADDRESS_MIRROR,
  216. ADDRESS_CLAMP,
  217. ADDRESS_BORDER,
  218. MAX_ADDRESSMODES
  219. };
  220. /// Texture coordinates.
  221. enum TextureCoordinate
  222. {
  223. COORD_U = 0,
  224. COORD_V,
  225. COORD_W,
  226. MAX_COORDS
  227. };
  228. /// Texture usage types.
  229. enum TextureUsage
  230. {
  231. TEXTURE_STATIC = 0,
  232. TEXTURE_DYNAMIC,
  233. TEXTURE_RENDERTARGET,
  234. TEXTURE_DEPTHSTENCIL
  235. };
  236. /// Cube map faces.
  237. enum CubeMapFace
  238. {
  239. FACE_POSITIVE_X = 0,
  240. FACE_NEGATIVE_X,
  241. FACE_POSITIVE_Y,
  242. FACE_NEGATIVE_Y,
  243. FACE_POSITIVE_Z,
  244. FACE_NEGATIVE_Z,
  245. MAX_CUBEMAP_FACES
  246. };
  247. /// Cubemap single image layout modes.
  248. enum CubeMapLayout
  249. {
  250. CML_HORIZONTAL = 0,
  251. CML_HORIZONTALNVIDIA,
  252. CML_HORIZONTALCROSS,
  253. CML_VERTICALCROSS,
  254. CML_BLENDER
  255. };
  256. /// Update mode for render surface viewports.
  257. enum RenderSurfaceUpdateMode
  258. {
  259. SURFACE_MANUALUPDATE = 0,
  260. SURFACE_UPDATEVISIBLE,
  261. SURFACE_UPDATEALWAYS
  262. };
  263. /// Shader types.
  264. enum ShaderType
  265. {
  266. VS = 0,
  267. PS,
  268. };
  269. /// Shader parameter groups for determining need to update. On APIs that support constant buffers, these correspond to different constant buffers.
  270. enum ShaderParameterGroup
  271. {
  272. SP_FRAME = 0,
  273. SP_CAMERA,
  274. SP_ZONE,
  275. SP_LIGHT,
  276. SP_MATERIAL,
  277. SP_OBJECT,
  278. SP_CUSTOM,
  279. MAX_SHADER_PARAMETER_GROUPS
  280. };
  281. /// Texture units.
  282. enum TextureUnit
  283. {
  284. TU_DIFFUSE = 0,
  285. TU_ALBEDOBUFFER = 0,
  286. TU_NORMAL = 1,
  287. TU_NORMALBUFFER = 1,
  288. TU_SPECULAR = 2,
  289. TU_EMISSIVE = 3,
  290. TU_ENVIRONMENT = 4,
  291. #ifdef DESKTOP_GRAPHICS
  292. TU_VOLUMEMAP = 5,
  293. TU_CUSTOM1 = 6,
  294. TU_CUSTOM2 = 7,
  295. TU_LIGHTRAMP = 8,
  296. TU_LIGHTSHAPE = 9,
  297. TU_SHADOWMAP = 10,
  298. TU_FACESELECT = 11,
  299. TU_INDIRECTION = 12,
  300. TU_DEPTHBUFFER = 13,
  301. TU_LIGHTBUFFER = 14,
  302. TU_ZONE = 15,
  303. MAX_MATERIAL_TEXTURE_UNITS = 8,
  304. MAX_TEXTURE_UNITS = 16
  305. #else
  306. TU_LIGHTRAMP = 5,
  307. TU_LIGHTSHAPE = 6,
  308. TU_SHADOWMAP = 7,
  309. MAX_MATERIAL_TEXTURE_UNITS = 5,
  310. MAX_TEXTURE_UNITS = 8
  311. #endif
  312. };
  313. /// Billboard camera facing modes.
  314. enum FaceCameraMode
  315. {
  316. FC_NONE = 0,
  317. FC_ROTATE_XYZ,
  318. FC_ROTATE_Y,
  319. FC_LOOKAT_XYZ,
  320. FC_LOOKAT_Y,
  321. FC_LOOKAT_MIXED,
  322. FC_DIRECTION,
  323. };
  324. /// Shadow type.
  325. enum ShadowQuality
  326. {
  327. SHADOWQUALITY_SIMPLE_16BIT = 0,
  328. SHADOWQUALITY_SIMPLE_24BIT,
  329. SHADOWQUALITY_PCF_16BIT,
  330. SHADOWQUALITY_PCF_24BIT,
  331. SHADOWQUALITY_VSM,
  332. SHADOWQUALITY_BLUR_VSM
  333. };
  334. // Inbuilt shader parameters.
  335. extern ATOMIC_API const StringHash VSP_AMBIENTSTARTCOLOR;
  336. extern ATOMIC_API const StringHash VSP_AMBIENTENDCOLOR;
  337. extern ATOMIC_API const StringHash VSP_BILLBOARDROT;
  338. extern ATOMIC_API const StringHash VSP_CAMERAPOS;
  339. extern ATOMIC_API const StringHash VSP_CLIPPLANE;
  340. extern ATOMIC_API const StringHash VSP_NEARCLIP;
  341. extern ATOMIC_API const StringHash VSP_FARCLIP;
  342. extern ATOMIC_API const StringHash VSP_DEPTHMODE;
  343. extern ATOMIC_API const StringHash VSP_DELTATIME;
  344. extern ATOMIC_API const StringHash VSP_ELAPSEDTIME;
  345. extern ATOMIC_API const StringHash VSP_FRUSTUMSIZE;
  346. extern ATOMIC_API const StringHash VSP_GBUFFEROFFSETS;
  347. extern ATOMIC_API const StringHash VSP_LIGHTDIR;
  348. extern ATOMIC_API const StringHash VSP_LIGHTPOS;
  349. extern ATOMIC_API const StringHash VSP_NORMALOFFSETSCALE;
  350. extern ATOMIC_API const StringHash VSP_MODEL;
  351. extern ATOMIC_API const StringHash VSP_VIEW;
  352. extern ATOMIC_API const StringHash VSP_VIEWINV;
  353. extern ATOMIC_API const StringHash VSP_VIEWPROJ;
  354. extern ATOMIC_API const StringHash VSP_UOFFSET;
  355. extern ATOMIC_API const StringHash VSP_VOFFSET;
  356. extern ATOMIC_API const StringHash VSP_ZONE;
  357. extern ATOMIC_API const StringHash VSP_LIGHTMATRICES;
  358. extern ATOMIC_API const StringHash VSP_SKINMATRICES;
  359. extern ATOMIC_API const StringHash VSP_VERTEXLIGHTS;
  360. extern ATOMIC_API const StringHash PSP_AMBIENTCOLOR;
  361. extern ATOMIC_API const StringHash PSP_CAMERAPOS;
  362. extern ATOMIC_API const StringHash PSP_DELTATIME;
  363. extern ATOMIC_API const StringHash PSP_DEPTHRECONSTRUCT;
  364. extern ATOMIC_API const StringHash PSP_ELAPSEDTIME;
  365. extern ATOMIC_API const StringHash PSP_FOGCOLOR;
  366. extern ATOMIC_API const StringHash PSP_FOGPARAMS;
  367. extern ATOMIC_API const StringHash PSP_GBUFFERINVSIZE;
  368. extern ATOMIC_API const StringHash PSP_LIGHTCOLOR;
  369. extern ATOMIC_API const StringHash PSP_LIGHTDIR;
  370. extern ATOMIC_API const StringHash PSP_LIGHTPOS;
  371. extern ATOMIC_API const StringHash PSP_NORMALOFFSETSCALE;
  372. extern ATOMIC_API const StringHash PSP_MATDIFFCOLOR;
  373. extern ATOMIC_API const StringHash PSP_MATEMISSIVECOLOR;
  374. extern ATOMIC_API const StringHash PSP_MATENVMAPCOLOR;
  375. extern ATOMIC_API const StringHash PSP_MATSPECCOLOR;
  376. extern ATOMIC_API const StringHash PSP_NEARCLIP;
  377. extern ATOMIC_API const StringHash PSP_FARCLIP;
  378. extern ATOMIC_API const StringHash PSP_SHADOWCUBEADJUST;
  379. extern ATOMIC_API const StringHash PSP_SHADOWDEPTHFADE;
  380. extern ATOMIC_API const StringHash PSP_SHADOWINTENSITY;
  381. extern ATOMIC_API const StringHash PSP_SHADOWMAPINVSIZE;
  382. extern ATOMIC_API const StringHash PSP_SHADOWSPLITS;
  383. extern ATOMIC_API const StringHash PSP_LIGHTMATRICES;
  384. extern ATOMIC_API const StringHash PSP_VSMSHADOWPARAMS;
  385. extern ATOMIC_API const StringHash PSP_ROUGHNESS;
  386. extern ATOMIC_API const StringHash PSP_METALLIC;
  387. // Scale calculation from bounding box diagonal.
  388. extern ATOMIC_API const Vector3 DOT_SCALE;
  389. static const int QUALITY_LOW = 0;
  390. static const int QUALITY_MEDIUM = 1;
  391. static const int QUALITY_HIGH = 2;
  392. static const int QUALITY_MAX = 15;
  393. static const unsigned CLEAR_COLOR = 0x1;
  394. static const unsigned CLEAR_DEPTH = 0x2;
  395. static const unsigned CLEAR_STENCIL = 0x4;
  396. // Legacy vertex element bitmasks.
  397. static const unsigned MASK_NONE = 0x0;
  398. static const unsigned MASK_POSITION = 0x1;
  399. static const unsigned MASK_NORMAL = 0x2;
  400. static const unsigned MASK_COLOR = 0x4;
  401. static const unsigned MASK_TEXCOORD1 = 0x8;
  402. static const unsigned MASK_TEXCOORD2 = 0x10;
  403. static const unsigned MASK_CUBETEXCOORD1 = 0x20;
  404. static const unsigned MASK_CUBETEXCOORD2 = 0x40;
  405. static const unsigned MASK_TANGENT = 0x80;
  406. static const unsigned MASK_BLENDWEIGHTS = 0x100;
  407. static const unsigned MASK_BLENDINDICES = 0x200;
  408. static const unsigned MASK_INSTANCEMATRIX1 = 0x400;
  409. static const unsigned MASK_INSTANCEMATRIX2 = 0x800;
  410. static const unsigned MASK_INSTANCEMATRIX3 = 0x1000;
  411. static const unsigned MASK_OBJECTINDEX = 0x2000;
  412. static const int MAX_RENDERTARGETS = 4;
  413. static const int MAX_VERTEX_STREAMS = 4;
  414. static const int MAX_CONSTANT_REGISTERS = 256;
  415. static const int BITS_PER_COMPONENT = 8;
  416. }