GraphicsDefs.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. // Copyright (c) 2008-2022 the Urho3D project
  2. // License: MIT
  3. /// \file
  4. #pragma once
  5. #include "../Container/FlagSet.h"
  6. #include "../Container/HashBase.h"
  7. #include "../Math/StringHash.h"
  8. #include "../Math/Vector3.h"
  9. namespace Urho3D
  10. {
  11. class Vector3;
  12. // Graphics capability support level. Web platform (Emscripten) also uses OpenGL ES, but is considered a desktop platform capability-wise
  13. #if defined(IOS) || defined(TVOS) || defined(__ANDROID__) || defined(__arm__) || defined(__aarch64__)
  14. #define MOBILE_GRAPHICS
  15. #else
  16. #define DESKTOP_GRAPHICS
  17. #endif
  18. enum GAPI
  19. {
  20. GAPI_NONE = 0,
  21. GAPI_OPENGL,
  22. GAPI_D3D11
  23. };
  24. /// Primitive type.
  25. enum PrimitiveType
  26. {
  27. TRIANGLE_LIST = 0,
  28. LINE_LIST,
  29. POINT_LIST,
  30. TRIANGLE_STRIP,
  31. LINE_STRIP,
  32. TRIANGLE_FAN
  33. };
  34. /// %Geometry type for vertex shader geometry variations.
  35. enum GeometryType
  36. {
  37. GEOM_STATIC = 0,
  38. GEOM_SKINNED = 1,
  39. GEOM_INSTANCED = 2,
  40. GEOM_BILLBOARD = 3,
  41. GEOM_DIRBILLBOARD = 4,
  42. GEOM_TRAIL_FACE_CAMERA = 5,
  43. GEOM_TRAIL_BONE = 6,
  44. MAX_GEOMETRYTYPES = 7,
  45. // This is not a real geometry type for VS, but used to mark objects that do not desire to be instanced
  46. GEOM_STATIC_NOINSTANCING = 7,
  47. };
  48. /// Blending mode.
  49. enum BlendMode
  50. {
  51. BLEND_REPLACE = 0,
  52. BLEND_ADD,
  53. BLEND_MULTIPLY,
  54. BLEND_ALPHA,
  55. BLEND_ADDALPHA,
  56. BLEND_PREMULALPHA,
  57. BLEND_INVDESTALPHA,
  58. BLEND_SUBTRACT,
  59. BLEND_SUBTRACTALPHA,
  60. MAX_BLENDMODES
  61. };
  62. /// Depth or stencil compare mode.
  63. enum CompareMode
  64. {
  65. CMP_ALWAYS = 0,
  66. CMP_EQUAL,
  67. CMP_NOTEQUAL,
  68. CMP_LESS,
  69. CMP_LESSEQUAL,
  70. CMP_GREATER,
  71. CMP_GREATEREQUAL,
  72. MAX_COMPAREMODES
  73. };
  74. /// Culling mode.
  75. enum CullMode
  76. {
  77. CULL_NONE = 0,
  78. CULL_CCW,
  79. CULL_CW,
  80. MAX_CULLMODES
  81. };
  82. /// Fill mode.
  83. enum FillMode
  84. {
  85. FILL_SOLID = 0,
  86. FILL_WIREFRAME,
  87. FILL_POINT
  88. };
  89. /// Stencil operation.
  90. enum StencilOp
  91. {
  92. OP_KEEP = 0,
  93. OP_ZERO,
  94. OP_REF,
  95. OP_INCR,
  96. OP_DECR
  97. };
  98. /// Vertex/index buffer lock state.
  99. enum LockState
  100. {
  101. LOCK_NONE = 0,
  102. LOCK_HARDWARE,
  103. LOCK_SHADOW,
  104. LOCK_SCRATCH
  105. };
  106. /// Hardcoded legacy vertex elements.
  107. enum LegacyVertexElement
  108. {
  109. ELEMENT_POSITION = 0,
  110. ELEMENT_NORMAL,
  111. ELEMENT_COLOR,
  112. ELEMENT_TEXCOORD1,
  113. ELEMENT_TEXCOORD2,
  114. ELEMENT_CUBETEXCOORD1,
  115. ELEMENT_CUBETEXCOORD2,
  116. ELEMENT_TANGENT,
  117. ELEMENT_BLENDWEIGHTS,
  118. ELEMENT_BLENDINDICES,
  119. ELEMENT_INSTANCEMATRIX1,
  120. ELEMENT_INSTANCEMATRIX2,
  121. ELEMENT_INSTANCEMATRIX3,
  122. // Custom 32-bit integer object index. Due to API limitations, not supported on D3D9
  123. ELEMENT_OBJECTINDEX,
  124. MAX_LEGACY_VERTEX_ELEMENTS
  125. };
  126. /// Arbitrary vertex declaration element datatypes.
  127. enum VertexElementType
  128. {
  129. TYPE_INT = 0,
  130. TYPE_FLOAT,
  131. TYPE_VECTOR2,
  132. TYPE_VECTOR3,
  133. TYPE_VECTOR4,
  134. TYPE_UBYTE4,
  135. TYPE_UBYTE4_NORM,
  136. MAX_VERTEX_ELEMENT_TYPES
  137. };
  138. /// Arbitrary vertex declaration element semantics.
  139. enum VertexElementSemantic
  140. {
  141. SEM_POSITION = 0,
  142. SEM_NORMAL,
  143. SEM_BINORMAL,
  144. SEM_TANGENT,
  145. SEM_TEXCOORD,
  146. SEM_COLOR,
  147. SEM_BLENDWEIGHTS,
  148. SEM_BLENDINDICES,
  149. SEM_OBJECTINDEX,
  150. MAX_VERTEX_ELEMENT_SEMANTICS
  151. };
  152. /// Vertex element description for arbitrary vertex declarations.
  153. struct URHO3D_API VertexElement
  154. {
  155. /// Default-construct.
  156. VertexElement() noexcept :
  157. type_(TYPE_VECTOR3),
  158. semantic_(SEM_POSITION),
  159. index_(0),
  160. perInstance_(false),
  161. offset_(0)
  162. {
  163. }
  164. /// Construct with type, semantic, index and whether is per-instance data.
  165. VertexElement(VertexElementType type, VertexElementSemantic semantic, i8 index = 0, bool perInstance = false) noexcept :
  166. type_(type),
  167. semantic_(semantic),
  168. index_(index),
  169. perInstance_(perInstance),
  170. offset_(0)
  171. {
  172. }
  173. /// 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.
  174. bool operator ==(const VertexElement& rhs) const
  175. {
  176. return type_ == rhs.type_ && semantic_ == rhs.semantic_ && index_ == rhs.index_ && perInstance_ == rhs.perInstance_;
  177. }
  178. /// Test for inequality with another vertex element.
  179. bool operator !=(const VertexElement& rhs) const { return !(*this == rhs); }
  180. /// Data type of element.
  181. VertexElementType type_;
  182. /// Semantic of element.
  183. VertexElementSemantic semantic_;
  184. /// Semantic index of element, for example multi-texcoords.
  185. i8 index_;
  186. /// Per-instance flag.
  187. bool perInstance_;
  188. /// Offset of element from vertex start. Filled by VertexBuffer once the vertex declaration is built.
  189. i32 offset_;
  190. };
  191. /// Sizes of vertex element types.
  192. extern URHO3D_API const i32 ELEMENT_TYPESIZES[];
  193. /// Vertex element definitions for the legacy elements.
  194. extern URHO3D_API const VertexElement LEGACY_VERTEXELEMENTS[];
  195. /// Texture filtering mode.
  196. enum TextureFilterMode
  197. {
  198. FILTER_NEAREST = 0,
  199. FILTER_BILINEAR,
  200. FILTER_TRILINEAR,
  201. FILTER_ANISOTROPIC,
  202. FILTER_NEAREST_ANISOTROPIC,
  203. FILTER_DEFAULT,
  204. MAX_FILTERMODES
  205. };
  206. /// Texture addressing mode.
  207. enum TextureAddressMode
  208. {
  209. ADDRESS_WRAP = 0,
  210. ADDRESS_MIRROR,
  211. ADDRESS_CLAMP,
  212. ADDRESS_BORDER,
  213. MAX_ADDRESSMODES
  214. };
  215. /// Texture coordinates.
  216. enum TextureCoordinate
  217. {
  218. COORD_U = 0,
  219. COORD_V,
  220. COORD_W,
  221. MAX_COORDS
  222. };
  223. /// Texture usage types.
  224. enum TextureUsage
  225. {
  226. TEXTURE_STATIC = 0,
  227. TEXTURE_DYNAMIC,
  228. TEXTURE_RENDERTARGET,
  229. TEXTURE_DEPTHSTENCIL
  230. };
  231. /// Cube map faces.
  232. enum CubeMapFace
  233. {
  234. FACE_POSITIVE_X = 0,
  235. FACE_NEGATIVE_X,
  236. FACE_POSITIVE_Y,
  237. FACE_NEGATIVE_Y,
  238. FACE_POSITIVE_Z,
  239. FACE_NEGATIVE_Z,
  240. MAX_CUBEMAP_FACES
  241. };
  242. /// Cubemap single image layout modes.
  243. enum CubeMapLayout
  244. {
  245. CML_HORIZONTAL = 0,
  246. CML_HORIZONTALNVIDIA,
  247. CML_HORIZONTALCROSS,
  248. CML_VERTICALCROSS,
  249. CML_BLENDER
  250. };
  251. /// Update mode for render surface viewports.
  252. enum RenderSurfaceUpdateMode
  253. {
  254. SURFACE_MANUALUPDATE = 0,
  255. SURFACE_UPDATEVISIBLE,
  256. SURFACE_UPDATEALWAYS
  257. };
  258. /// Shader types.
  259. enum ShaderType
  260. {
  261. VS = 0,
  262. PS,
  263. };
  264. /// Shader parameter groups for determining need to update. On APIs that support constant buffers, these correspond to different constant buffers.
  265. enum ShaderParameterGroup
  266. {
  267. SP_FRAME = 0,
  268. SP_CAMERA,
  269. SP_ZONE,
  270. SP_LIGHT,
  271. SP_MATERIAL,
  272. SP_OBJECT,
  273. SP_CUSTOM,
  274. MAX_SHADER_PARAMETER_GROUPS
  275. };
  276. /// Texture units.
  277. /// @manualbind
  278. enum TextureUnit
  279. {
  280. TU_DIFFUSE = 0,
  281. TU_ALBEDOBUFFER = 0,
  282. TU_NORMAL = 1,
  283. TU_NORMALBUFFER = 1,
  284. TU_SPECULAR = 2,
  285. TU_EMISSIVE = 3,
  286. TU_ENVIRONMENT = 4,
  287. #ifdef DESKTOP_GRAPHICS
  288. TU_VOLUMEMAP = 5,
  289. TU_CUSTOM1 = 6,
  290. TU_CUSTOM2 = 7,
  291. TU_LIGHTRAMP = 8,
  292. TU_LIGHTSHAPE = 9,
  293. TU_SHADOWMAP = 10,
  294. TU_FACESELECT = 11,
  295. TU_INDIRECTION = 12,
  296. TU_DEPTHBUFFER = 13,
  297. TU_LIGHTBUFFER = 14,
  298. TU_ZONE = 15,
  299. MAX_MATERIAL_TEXTURE_UNITS = 8,
  300. MAX_TEXTURE_UNITS = 16
  301. #else
  302. TU_LIGHTRAMP = 5,
  303. TU_LIGHTSHAPE = 6,
  304. TU_SHADOWMAP = 7,
  305. MAX_MATERIAL_TEXTURE_UNITS = 5,
  306. MAX_TEXTURE_UNITS = 8
  307. #endif
  308. };
  309. /// Billboard camera facing modes.
  310. enum FaceCameraMode
  311. {
  312. FC_NONE = 0,
  313. FC_ROTATE_XYZ,
  314. FC_ROTATE_Y,
  315. FC_LOOKAT_XYZ,
  316. FC_LOOKAT_Y,
  317. FC_LOOKAT_MIXED,
  318. FC_DIRECTION,
  319. };
  320. /// Shadow type.
  321. enum ShadowQuality
  322. {
  323. SHADOWQUALITY_SIMPLE_16BIT = 0,
  324. SHADOWQUALITY_SIMPLE_24BIT,
  325. SHADOWQUALITY_PCF_16BIT,
  326. SHADOWQUALITY_PCF_24BIT,
  327. SHADOWQUALITY_VSM,
  328. SHADOWQUALITY_BLUR_VSM
  329. };
  330. // Inbuilt shader parameters.
  331. inline const StringHash VSP_AMBIENTENDCOLOR{"AmbientEndColor"};
  332. inline const StringHash VSP_AMBIENTSTARTCOLOR{"AmbientStartColor"};
  333. inline const StringHash VSP_BILLBOARDROT{"BillboardRot"};
  334. inline const StringHash VSP_CLIPPLANE{"ClipPlane"};
  335. inline const StringHash VSP_DEPTHMODE{"DepthMode"};
  336. inline const StringHash VSP_FRUSTUMSIZE{"FrustumSize"};
  337. inline const StringHash VSP_GBUFFEROFFSETS{"GBufferOffsets"};
  338. inline const StringHash VSP_MODEL{"Model"};
  339. inline const StringHash VSP_SKINMATRICES{"SkinMatrices"};
  340. inline const StringHash VSP_UOFFSET{"UOffset"};
  341. inline const StringHash VSP_VERTEXLIGHTS{"VertexLights"};
  342. inline const StringHash VSP_VIEW{"View"};
  343. inline const StringHash VSP_VIEWINV{"ViewInv"};
  344. inline const StringHash VSP_VIEWPROJ{"ViewProj"};
  345. inline const StringHash VSP_VOFFSET{"VOffset"};
  346. inline const StringHash VSP_ZONE{"Zone"};
  347. inline const StringHash PSP_AMBIENTCOLOR{"AmbientColor"};
  348. inline const StringHash PSP_DEPTHRECONSTRUCT{"DepthReconstruct"};
  349. inline const StringHash PSP_FOGCOLOR{"FogColor"};
  350. inline const StringHash PSP_FOGPARAMS{"FogParams"};
  351. inline const StringHash PSP_GBUFFERINVSIZE{"GBufferInvSize"};
  352. inline const StringHash PSP_LIGHTCOLOR{"LightColor"};
  353. inline const StringHash PSP_LIGHTLENGTH{"LightLength"};
  354. inline const StringHash PSP_LIGHTRAD{"LightRad"};
  355. inline const StringHash PSP_MATDIFFCOLOR{"MatDiffColor"};
  356. inline const StringHash PSP_MATEMISSIVECOLOR{"MatEmissiveColor"};
  357. inline const StringHash PSP_MATENVMAPCOLOR{"MatEnvMapColor"};
  358. inline const StringHash PSP_MATSPECCOLOR{"MatSpecColor"};
  359. inline const StringHash PSP_METALLIC{"Metallic"};
  360. inline const StringHash PSP_ROUGHNESS{"Roughness"};
  361. inline const StringHash PSP_SHADOWCUBEADJUST{"ShadowCubeAdjust"};
  362. inline const StringHash PSP_SHADOWDEPTHFADE{"ShadowDepthFade"};
  363. inline const StringHash PSP_SHADOWINTENSITY{"ShadowIntensity"};
  364. inline const StringHash PSP_SHADOWMAPINVSIZE{"ShadowMapInvSize"};
  365. inline const StringHash PSP_SHADOWSPLITS{"ShadowSplits"};
  366. inline const StringHash PSP_VSMSHADOWPARAMS{"VSMShadowParams"};
  367. inline const StringHash PSP_ZONEMAX{"ZoneMax"};
  368. inline const StringHash PSP_ZONEMIN{"ZoneMin"};
  369. inline const StringHash VSP_CAMERAPOS{"CameraPos"};
  370. inline const StringHash PSP_CAMERAPOS{"CameraPosPS"};
  371. inline const StringHash VSP_DELTATIME{"DeltaTime"};
  372. inline const StringHash PSP_DELTATIME{"DeltaTimePS"};
  373. inline const StringHash VSP_ELAPSEDTIME{"ElapsedTime"};
  374. inline const StringHash PSP_ELAPSEDTIME{"ElapsedTimePS"};
  375. inline const StringHash VSP_FARCLIP{"FarClip"};
  376. inline const StringHash PSP_FARCLIP{"FarClipPS"};
  377. inline const StringHash VSP_LIGHTDIR{"LightDir"};
  378. inline const StringHash PSP_LIGHTDIR{"LightDirPS"};
  379. inline const StringHash VSP_LIGHTMATRICES{"LightMatrices"};
  380. inline const StringHash PSP_LIGHTMATRICES{"LightMatricesPS"};
  381. inline const StringHash VSP_LIGHTPOS{"LightPos"};
  382. inline const StringHash PSP_LIGHTPOS{"LightPosPS"};
  383. inline const StringHash VSP_NEARCLIP{"NearClip"};
  384. inline const StringHash PSP_NEARCLIP{"NearClipPS"};
  385. inline const StringHash VSP_NORMALOFFSETSCALE{"NormalOffsetScale"};
  386. inline const StringHash PSP_NORMALOFFSETSCALE{"NormalOffsetScalePS"};
  387. // Scale calculation from bounding box diagonal.
  388. inline const Vector3 DOT_SCALE{1 / 3.0f, 1 / 3.0f, 1 / 3.0f};
  389. enum MaterialQuality : u32
  390. {
  391. QUALITY_LOW = 0,
  392. QUALITY_MEDIUM = 1,
  393. QUALITY_HIGH = 2,
  394. QUALITY_MAX = 15,
  395. };
  396. enum ClearTarget : u32
  397. {
  398. CLEAR_COLOR = 0x1,
  399. CLEAR_DEPTH = 0x2,
  400. CLEAR_STENCIL = 0x4,
  401. };
  402. URHO3D_FLAGSET(ClearTarget, ClearTargetFlags);
  403. /// Legacy vertex element bitmasks.
  404. enum class VertexElements : u32
  405. {
  406. None = 0,
  407. Position = 1 << 0,
  408. Normal = 1 << 1,
  409. Color = 1 << 2,
  410. TexCoord1 = 1 << 3,
  411. TexCoord2 = 1 << 4,
  412. CubeTexCoord1 = 1 << 5,
  413. CubeTexCoord2 = 1 << 6,
  414. Tangent = 1 << 7,
  415. BlendWeights = 1 << 8,
  416. BlendIndices = 1 << 9,
  417. InstanceMatrix1 = 1 << 10,
  418. InstanceMatrix2 = 1 << 11,
  419. InstanceMatrix3 = 1 << 12,
  420. ObjectIndex = 1 << 13
  421. };
  422. URHO3D_FLAGS(VertexElements);
  423. inline constexpr i32 MAX_RENDERTARGETS = 4;
  424. inline constexpr i32 MAX_VERTEX_STREAMS = 4;
  425. inline constexpr i32 MAX_CONSTANT_REGISTERS = 256;
  426. inline constexpr i32 BITS_PER_COMPONENT = 8;
  427. } // namespace Urho3D