2
0

GraphicsDefs.h 12 KB

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