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