Source

dark-hammer / include / engine / gfx-types.h

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
/***********************************************************************************
 * Copyright (c) 2012, Sepehr Taghdisian
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice, 
 *   this list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation 
 *   and/or other materials provided with the distribution.
 *
 ***********************************************************************************/


#ifndef __GFXTYPES_H__
#define __GFXTYPES_H__

#include "core/types.h"
#include "core/vec-math.h"

/* fwd */
struct camera;

/* include mostly enums that their values may be different in each API */
#if defined(_D3D_)
#include "d3d/gfx-types-d3d.h"
#elif defined(_GL_)
#include "gl/gfx-types-gl.h"
#endif

#include "gfx-input-types.h"

#define GFX_MAX_CBUFFERS 8
#define GFX_MAX_SAMPLERS 16
#define GFX_MAX_SHADERRESOURCES 16
#define GFX_MAX_RENDERTARGETS 8
#define GFX_MAX_VIEWPORTS 8
#define GFX_MAX_INPUTS 16
#define GFX_PROGRAM_MAX_SHADERS 3
#define GFX_RT_MAX_TEXTURES	4
#define GFX_DRAWCALL_GROUP_COUNT 12

/* render passes
 * note that their order is important
 */
#define GFX_RENDERPASS_SUNSHADOW 0 /* sun shadow render-path used for shadow casting objects */
#define GFX_RENDERPASS_SPOTSHADOW 1
#define GFX_RENDERPASS_POINTSHADOW 2
#define GFX_RENDERPASS_MIRROR 3 /* mirror render-path used for water and other reflection effects */
#define GFX_RENDERPASS_PRIMARY 4 /* Primary render-path that is used for every drawable object */
#define GFX_RENDERPASS_TRANSPARENT 5 /* transparent objects should use previous z-buffer and z-ordering*/
#define GFX_RENDERPASS_MAX 6

/* each drawable object can have multiple passes assigned */
struct gfx_renderpass_item
{
	const struct gfx_rpath* rpath;
	uint32 shader_id;
};

/* render override callback function */
/* shader flags are used for picking the right shader for each object */
enum gfx_rpath_flag
{
	GFX_RPATH_DIFFUSEMAP = (1<<0),	/* has diffuse-map */
	GFX_RPATH_NORMALMAP = (1<<1),	/* has normal-map */
	GFX_RPATH_REFLECTIONMAP = (1<<3), /* has reflection-map */
	GFX_RPATH_EMISSIVEMAP = (1<<4),	/* has emissive-map */
	GFX_RPATH_GLOSSMAP = (1<<5),	/* has gloss-map */
	GFX_RPATH_SPECULAR = (1<<6),	/* has specular-map */
	GFX_RPATH_ALPHABLEND = (1<<7),	/* transparent */
	GFX_RPATH_CSMSHADOW = (1<<8),	/* is sun-shadow object */
	GFX_RPATH_SKINNED = (1<<9),	/* is skinned object (skeletal) */
	GFX_RPATH_SPOTSHADOW = (1<<10), /* is spot-shadow object */
	GFX_RPATH_POINTSHADOW = (1<<11), /* is point-shadow object */
	GFX_RPATH_ISOTROPIC = (1<<12), /* has isotropic BRDF */
	GFX_RPATH_SSS = (1<<13), /* has sub-surface-scattering BRDF */
	GFX_RPATH_WATER = (1<<14),	/* is water */
	GFX_RPATH_MIRROR = (1<<15), /* is mirror */
	GFX_RPATH_PARTICLE = (1<<16), /* is particle */
	GFX_RPATH_RAW = (1<<17),	/* most basic primitive rendering */
    GFX_RPATH_ALPHAMAP = (1<<18), /* we have alpha test */
	GFX_RPATH_ALL = 0xffffffff
};

enum gfx_obj_type
{
    GFX_OBJ_NULL = 0,
    GFX_OBJ_PROGRAM, /* program contains all shaders (vertex/pixel/geo/..) */
    GFX_OBJ_DEPTHSTENCILSTATE,
    GFX_OBJ_RASTERSTATE,
    GFX_OBJ_BLENDSTATE,
    GFX_OBJ_SAMPLER,
    GFX_OBJ_BUFFER,	/* constant-blocks, texture-buffers, vertex-buffers, etc. */
    GFX_OBJ_TEXTURE, /* textures that are loaded with image data and used in shaders */
    GFX_OBJ_INPUTLAYOUT,
    GFX_OBJ_RENDERTARGET
};

enum gfx_shader_type
{
    GFX_SHADER_NONE = 0,
    GFX_SHADER_VERTEX = 1,
    GFX_SHADER_PIXEL = 2,
    GFX_SHADER_GEOMETRY = 3,
    GFX_SHADER_HULL = 4,
    GFX_SHADER_DOMAIN = 5
};

enum gfx_gpu_vendor
{
    GFX_GPU_UNKNOWN = 0,
    GFX_GPU_NVIDIA,
    GFX_GPU_ATI,
    GFX_GPU_INTEL
};

enum gfx_drawcall_type
{
    GFX_DRAWCALL_GBUFFER = 0,
    GFX_DRAWCALL_LIGHTING = 1,
    GFX_DRAWCALL_MTL = 2,
    GFX_DRAWCALL_2D = 3,
    GFX_DRAWCALL_DEBUG = 4,
    GFX_DRAWCALL_POSTFX = 5,
    GFX_DRAWCALL_MISC = 6,
    GFX_DRAWCALL_PARTICLES = 7,
    GFX_DRAWCALL_DECALS = 8,
    GFX_DRAWCALL_FWD = 9,
    GFX_DRAWCALL_SUNSHADOW = 10,
    GFX_DRAWCALL_LOCALSHADOW = 11,
};

/* works for D3D11 spec too */
enum gfx_color_write
{
    GFX_COLORWRITE_RED         = 0x1,
    GFX_COLORWRITE_GREEN       = 0x2,
    GFX_COLORWRITE_BLUE        = 0x4,
    GFX_COLORWRITE_ALPHA       = 0x8,
    GFX_COLORWRITE_ALL         = (GFX_COLORWRITE_RED | GFX_COLORWRITE_GREEN |
                                  GFX_COLORWRITE_BLUE | GFX_COLORWRITE_ALPHA),
    GFX_COLORWRITE_NONE        = 0x0,
    GFX_COLORWRITE_UNKNOWN     = 0xff
};

/*************************************************************************************************
 * SHARED STRUCTURES
 */
struct gfx_gpu_memstats
{
    uint32 texture_cnt;
    uint32 rttexture_cnt;
    uint32 buffer_cnt;

    size_t textures;
    size_t rt_textures;
    size_t buffers;
};

struct gfx_framestats
{
    uint32 draw_cnt;
    uint32 prims_cnt;
    uint32 draw_group_cnt[GFX_DRAWCALL_GROUP_COUNT];
    uint32 draw_prim_cnt[GFX_DRAWCALL_GROUP_COUNT];
    uint32 texchange_cnt;
    uint32 samplerchange_cnt;
    uint32 shaderchange_cnt;
    uint32 map_cnt;
    uint32 rtchange_cnt;
    uint32 blendstatechange_cnt;
    uint32 rsstatechange_cnt;
    uint32 dsstatechange_cnt;
    uint32 cbufferchange_cnt;
    uint32 clearrt_cnt;
    uint32 cleards_cnt;
    uint32 input_cnt;
};

struct gfx_subresource_data
{
	void* p;
	uint32 size;
	uint32 pitch_row;
	uint32 pitch_slice;
};

struct gfx_shader_define
{
	const char* name;
	const char* value;
};

struct gfx_blend_desc
{
    bool_t enable;
    enum gfx_blend_mode src_blend;
    enum gfx_blend_mode dest_blend;
    enum gfx_blend_op color_op;
    uint8 write_mask;	/* enum gfx_color_write combination */
};


struct gfx_stencilop_desc
{
    enum gfx_stencil_op fail_op;
    enum gfx_stencil_op depthfail_op;
    enum gfx_stencil_op pass_op;
    enum gfx_cmp_func cmp_func;
};

struct gfx_depthstencil_desc
{
    bool_t depth_enable;
    bool_t depth_write;
    enum gfx_cmp_func depth_func;

    bool_t stencil_enable;
    uint32 stencil_mask;
    struct gfx_stencilop_desc stencil_frontface_desc;
    struct gfx_stencilop_desc stencil_backface_desc;
};

struct gfx_threading_support
{
    bool_t concurrent_create;
    bool_t concurrent_cmdlist;
};

struct gfx_device_info
{
    enum gfx_gpu_vendor vendor;
    char desc[256];
    int32 mem_avail;	/* in kb */
    struct gfx_threading_support threading;
    uint32 fmt_support;
};

struct gfx_input_element
{
	enum gfx_input_element_id id;
	enum gfx_input_element_fmt fmt;	/* format of single component */
	int32 component_cnt;	/* number of components in element */
	int32 stride;	/* can be 0 if it's packed */
};

/* setting offset value to GFX_INPUTELEMENT_ID_xxxx defines if we want to override the ..
 * ID, but use the type of ID for element data and other properties from 'offset' (semantic, idx) */
struct gfx_input_element_binding
{
	enum gfx_input_element_id id;
	const char* var_name;	/* variable name in the shader */
    int32 offset; /* OPTIONAL: offset override (=-1 if want to be ignored) */
};

struct gfx_viewport
{
    fl32 x;
    fl32 y;
    fl32 w;
    fl32 h;
    fl32 depth_min;
    fl32 depth_max;
};

struct gfx_box
{
    uint32 left;
    uint32 top;
    uint32 front;
    uint32 right;
    uint32 bottom;
    uint32 back;
};

struct gfx_sampler_desc
{
    enum gfx_filter_mode filter_min;
    enum gfx_filter_mode filter_mag;
    enum gfx_filter_mode filter_mip;
    enum gfx_address_mode address_u;
    enum gfx_address_mode address_v;
    enum gfx_address_mode address_w;
    uint32 aniso_max;
    enum gfx_cmp_func cmp_func;
    fl32 border_color[4];
    int32 lod_min;
    int32 lod_max;
};

struct gfx_rasterizer_desc
{
    enum gfx_fill_mode fill;
    enum gfx_cull_mode cull;
    fl32 depth_bias;
    fl32 slopescaled_depthbias;
    bool_t scissor_test;
    bool_t depth_clip;
};

struct gfx_msaa_desc
{
    uint32 count;
    uint32 quality;
};

struct gfx_displaytarget_desc
{
    uint32 width;
    uint32 height;
    uint32 refresh_rate;
    bool_t vsync;
    bool_t fullscreen;
    bool_t depthstencil;

    void* hwnd;

#if defined(_LINUX_)
    void* display; /* Display struct */
    void* vi; /* XVisualInfo struct */
#endif
};

struct gfx_shader_binary_data
{
#if defined(_GL_)
	void* prog_data;
	uint32 prog_size;
	uint32 fmt;
#elif defined(_D3D_)
	void* vs_data;
	uint32 vs_size;
	void* ps_data;
	uint32 ps_size;
	void* gs_data;
	uint32 gs_size;
#endif
};

struct gfx_shader_data
{
	void* vs_source;
	void* ps_source;
	void* gs_source;
	size_t vs_size;
	size_t ps_size;
	size_t gs_size;
};

/**
 * render view parameters, it is passed to many rendering functions for rendering
 * @ingroup gfx
 */
struct ALIGN16 gfx_view_params
{
    int32 width;    /**< width of the current render target */
    int32 height;   /**< height of the current render target */

    struct camera* cam; /**< current view camera @see camera */
    struct mat3f view; /**< current view matrix (calculated from camera) */
    struct mat4f proj; /**< current projection matrix (calculated from camera) */
    struct mat4f viewproj; /**< view(x)projection matrix */
    struct vec4f cam_pos; /**< camera position */
    struct vec4f projparams; /**< projection matrix parameters () */
};

/* brief/useful object description for gfx objects */
struct gfx_obj_desc
{
    union   {
    	/* programs */
        struct	{
        	uptr_t shaders[GFX_PROGRAM_MAX_SHADERS];
        	enum gfx_shader_type shader_types[GFX_PROGRAM_MAX_SHADERS];
        	uint32 shader_cnt;
            void* d3d_reflects[GFX_PROGRAM_MAX_SHADERS];
        	void* d3d_il;	/* input-layout object for d3d */
        } prog;

        /* textures */
        struct  {
        	enum gfx_texture_type type;
            uint32 width;
            uint32 height;
            uint32 depth;	/* .. same as array count (if not=1 then we have array/3d tex) */
            enum gfx_format fmt;
            bool_t has_alpha;
            void* d3d_srv;
            void* d3d_rtv;
            uint32 size;
            bool_t is_rt;
            uint32 mip_cnt;
            int32 gl_type;
            int32 gl_fmt;
        } tex;

        /* buffers */
        struct	{
        	enum gfx_buffer_type type;
            void* d3d_srv;  /* d3d tbuffers */
            uint32 gl_tbuff; /* gl tbuffer texture */
        	uint32 size;
        } buff;

        /* input-layouts */
        struct	{
        	void* vbuffs[GFX_MAX_VBUFFERS];	/* type = gfx_obj. any element can be NULL! */
            uint32 strides[GFX_MAX_VBUFFERS];
        	void* ibuff;	/* type = gfx_obj */
            enum gfx_index_type idxfmt;
        } il;

        /* render targets */
        struct	{
        	uint32 rt_cnt;
        	void* rt_textures[GFX_RT_MAX_TEXTURES]; /* type = gfx_obj */
        	void* ds_texture;	/* type = gfx_obj */
        	uint32 width;
        	uint32 height;
        } rt;

        struct gfx_blend_desc blend;
        struct gfx_rasterizer_desc raster;
        struct gfx_depthstencil_desc ds;
    };
};

struct gfx_obj_data
{
    uptr_t api_obj;
    enum gfx_obj_type type;
    struct gfx_obj_desc desc;
};

/* fwd */
struct gfx_cmdqueue_s;
struct gfx_displaytarget_s;

typedef struct gfx_cmdqueue_s* gfx_cmdqueue;

/* object typedefs (for readability) */
typedef struct gfx_obj_data* gfx_program;
typedef struct gfx_obj_data* gfx_depthstencilstate;
typedef struct gfx_obj_data* gfx_rasterstate;
typedef struct gfx_obj_data* gfx_blendstate;
typedef struct gfx_obj_data* gfx_sampler;
typedef struct gfx_obj_data* gfx_buffer;
typedef struct gfx_obj_data* gfx_texture;
typedef struct gfx_obj_data* gfx_inputlayout;
typedef struct gfx_obj_data* gfx_rendertarget;
typedef void* gfx_syncobj;

#endif /* __GFXTYPES_H__ */
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.