Welcome to mirror list, hosted at ThFree Co, Russian Federation.

draw_common.h « intern « draw « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 12f88fb84a60b5aee1b96bbd3390d5170827b7d4 (plain)
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
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Copyright 2016, Blender Foundation.
 */

/** \file
 * \ingroup draw
 */

#ifndef __DRAW_COMMON_H__
#define __DRAW_COMMON_H__

struct DRWCallBuffer;
struct DRWPass;
struct DRWShadingGroup;
struct GPUBatch;
struct GPUMaterial;
struct ModifierData;
struct Object;
struct PTCacheEdit;
struct ParticleSystem;
struct ViewLayer;

#define UBO_FIRST_COLOR colorWire
#define UBO_LAST_COLOR colorGridAxisZ

/* Used as ubo but colors can be directly referenced as well */
/* Keep in sync with: common_globals_lib.glsl (globalsBlock) */
/* NOTE! Also keep all color as vec4 and between UBO_FIRST_COLOR and UBO_LAST_COLOR */
typedef struct GlobalsUboStorage {
  /* UBOs data needs to be 16 byte aligned (size of vec4) */
  float colorWire[4];
  float colorWireEdit[4];
  float colorActive[4];
  float colorSelect[4];
  float colorDupliSelect[4];
  float colorDupli[4];
  float colorLibrarySelect[4];
  float colorLibrary[4];
  float colorTransform[4];
  float colorLight[4];
  float colorSpeaker[4];
  float colorCamera[4];
  float colorEmpty[4];
  float colorVertex[4];
  float colorVertexSelect[4];
  float colorVertexUnreferenced[4];
  float colorVertexMissingData[4];
  float colorEditMeshActive[4];
  float colorEdgeSelect[4];
  float colorEdgeSeam[4];
  float colorEdgeSharp[4];
  float colorEdgeCrease[4];
  float colorEdgeBWeight[4];
  float colorEdgeFaceSelect[4];
  float colorEdgeFreestyle[4];
  float colorFace[4];
  float colorFaceSelect[4];
  float colorFaceFreestyle[4];
  float colorNormal[4];
  float colorVNormal[4];
  float colorLNormal[4];
  float colorFaceDot[4];

  float colorDeselect[4];
  float colorOutline[4];
  float colorLightNoAlpha[4];

  float colorBackground[4];
  float colorEditMeshMiddle[4];

  float colorHandleFree[4];
  float colorHandleAuto[4];
  float colorHandleVect[4];
  float colorHandleAlign[4];
  float colorHandleAutoclamp[4];
  float colorHandleSelFree[4];
  float colorHandleSelAuto[4];
  float colorHandleSelVect[4];
  float colorHandleSelAlign[4];
  float colorHandleSelAutoclamp[4];
  float colorNurbUline[4];
  float colorNurbVline[4];
  float colorNurbSelUline[4];
  float colorNurbSelVline[4];
  float colorActiveSpline[4];

  float colorBonePose[4];

  float colorCurrentFrame[4];

  float colorGrid[4];
  float colorGridEmphasise[4];
  float colorGridAxisX[4];
  float colorGridAxisY[4];
  float colorGridAxisZ[4];

  /* NOTE! Put all color before UBO_LAST_COLOR */

  /* Pack individual float at the end of the buffer to avoid alignment errors */
  float sizeLightCenter, sizeLightCircle, sizeLightCircleShadow;
  float sizeVertex, sizeEdge, sizeEdgeFix, sizeFaceDot;
  float gridDistance, gridResolution, gridSubdivisions, gridScale;

  float pad_globalsBlock;
} GlobalsUboStorage;
/* Keep in sync with globalsBlock in shaders */
BLI_STATIC_ASSERT_ALIGN(GlobalsUboStorage, 16)

void DRW_globals_update(void);
void DRW_globals_free(void);

typedef struct DRWEmptiesBufferList {
  struct DRWCallBuffer *plain_axes;
  struct DRWCallBuffer *cube;
  struct DRWCallBuffer *circle;
  struct DRWCallBuffer *sphere;
  struct DRWCallBuffer *sphere_solid;
  struct DRWCallBuffer *cylinder;
  struct DRWCallBuffer *capsule_cap;
  struct DRWCallBuffer *capsule_body;
  struct DRWCallBuffer *cone;
  struct DRWCallBuffer *single_arrow;
  struct DRWCallBuffer *single_arrow_line;
  struct DRWCallBuffer *empty_axes;
} DRWEmptiesBufferList;

/* TODO(fclem) ideally, most of the DRWCallBuffer functions shouldn't create a shgroup. */
struct DRWCallBuffer *buffer_dynlines_flat_color(struct DRWPass *pass, eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_dynlines_dashed_uniform_color(struct DRWPass *pass,
                                                           const float color[4],
                                                           eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_dynpoints_uniform_color(struct DRWShadingGroup *grp);
struct DRWCallBuffer *buffer_groundlines_uniform_color(struct DRWPass *pass,
                                                       const float color[4],
                                                       eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_groundpoints_uniform_color(struct DRWPass *pass,
                                                        const float color[4],
                                                        eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_instance_screenspace(struct DRWPass *pass,
                                                  struct GPUBatch *geom,
                                                  const float *size,
                                                  eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_instance_solid(struct DRWPass *pass, struct GPUBatch *geom);
struct DRWCallBuffer *buffer_instance_wire(struct DRWPass *pass, struct GPUBatch *geom);
struct DRWCallBuffer *buffer_instance_screen_aligned(struct DRWPass *pass,
                                                     struct GPUBatch *geom,
                                                     eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_instance_empty_axes(struct DRWPass *pass,
                                                 struct GPUBatch *geom,
                                                 eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_instance_scaled(struct DRWPass *pass,
                                             struct GPUBatch *geom,
                                             eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_instance(struct DRWPass *pass,
                                      struct GPUBatch *geom,
                                      eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_instance_alpha(struct DRWShadingGroup *grp, struct GPUBatch *geom);
struct DRWCallBuffer *buffer_instance_outline(struct DRWPass *pass,
                                              struct GPUBatch *geom,
                                              const int *baseid,
                                              eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_camera_instance(struct DRWPass *pass,
                                             struct GPUBatch *geom,
                                             eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_distance_lines_instance(struct DRWPass *pass,
                                                     struct GPUBatch *geom,
                                                     eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_spot_instance(struct DRWPass *pass,
                                           struct GPUBatch *geom,
                                           eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_instance_mball_handles(struct DRWPass *pass, eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_instance_bone_axes(struct DRWPass *pass, eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_instance_bone_envelope_distance(struct DRWPass *pass,
                                                             eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_instance_bone_envelope_outline(struct DRWPass *pass,
                                                            eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_instance_bone_envelope_solid(struct DRWPass *pass,
                                                          bool transp,
                                                          eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_instance_bone_shape_outline(struct DRWPass *pass,
                                                         struct GPUBatch *geom,
                                                         eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_instance_bone_shape_solid(struct DRWPass *pass,
                                                       struct GPUBatch *geom,
                                                       bool transp,
                                                       eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_instance_bone_sphere_outline(struct DRWPass *pass,
                                                          eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_instance_bone_sphere_solid(struct DRWPass *pass,
                                                        bool transp,
                                                        eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_instance_bone_stick(struct DRWPass *pass, eGPUShaderConfig sh_cfg);
struct DRWCallBuffer *buffer_instance_bone_dof(struct DRWPass *pass,
                                               struct GPUBatch *geom,
                                               bool blend);

void empties_callbuffers_create(struct DRWPass *pass,
                                struct DRWEmptiesBufferList *buffers,
                                eGPUShaderConfig sh_cfg);

struct GPUShader *mpath_line_shader_get(void);
struct GPUShader *mpath_points_shader_get(void);

struct GPUShader *volume_velocity_shader_get(bool use_needle);

struct DRWView *DRW_view_create_with_zoffset(const RegionView3D *rv3d, float offset);

int DRW_theme_value_get_i(int colorid);
float DRW_theme_value_get_f(int colorid);
void DRW_theme_color_get_4fv(int colorid, float r_col[4]);
void DRW_theme_color_get_4ubv(int colorid, uchar r_col[4]);
void DRW_theme_color_get_3fv(int colorid, float r_col[3]);
void DRW_theme_color_get_3ubv(int colorid, uchar r_col[3]);
void DRW_theme_color_shade_get_4fv(int colorid, int offset, float r_col[4]);
void DRW_theme_color_shade_alpha_get_4fv(int colorid, int offset, int alphaoffset, float r_col[4]);
void DRW_theme_color_shade_get_3fv(int colorid, int offset, float r_col[3]);
void DRW_theme_color_blend_shade_get_4fv(
    int colorid1, int colorid2, float fac, int offset, float r_col[4]);
void DRW_theme_color_blend_shade_get_3fv(
    int colorid1, int colorid2, float fac, int offset, float r_col[3]);
int DRW_object_wire_theme_get(struct Object *ob, struct ViewLayer *view_layer, float **r_color);
float *DRW_color_background_blend_get(int theme_id);

bool DRW_object_is_flat(Object *ob, int *r_axis);
bool DRW_object_axis_orthogonal_to_view(Object *ob, int axis);

/* draw_armature.c */
typedef struct DRWArmaturePasses {
  struct DRWPass *bone_solid;
  struct DRWPass *bone_outline;
  struct DRWPass *bone_wire;
  struct DRWPass *bone_envelope;
  struct DRWPass *bone_axes;
  struct DRWPass *relationship_lines;
  struct GHash *custom_shapes;
} DRWArmaturePasses;

void DRW_shgroup_armature_object(struct Object *ob,
                                 struct ViewLayer *view_layer,
                                 struct DRWArmaturePasses passes,
                                 bool transp);
void DRW_shgroup_armature_pose(struct Object *ob, struct DRWArmaturePasses passes, bool transp);
void DRW_shgroup_armature_edit(struct Object *ob, struct DRWArmaturePasses passes, bool transp);

/* draw_hair.c */

/* This creates a shading group with display hairs.
 * The draw call is already added by this function, just add additional uniforms. */
struct DRWShadingGroup *DRW_shgroup_hair_create(struct Object *object,
                                                struct ParticleSystem *psys,
                                                struct ModifierData *md,
                                                struct DRWPass *hair_pass,
                                                struct GPUShader *shader);

struct DRWShadingGroup *DRW_shgroup_material_hair_create(struct Object *object,
                                                         struct ParticleSystem *psys,
                                                         struct ModifierData *md,
                                                         struct DRWPass *hair_pass,
                                                         struct GPUMaterial *material);

void DRW_hair_init(void);
void DRW_hair_update(void);
void DRW_hair_free(void);

/* pose_mode.c */
bool DRW_pose_mode_armature(struct Object *ob, struct Object *active_ob);

/* draw_common.c */
struct DRW_Global {
  /** If needed, contains all global/Theme colors
   * Add needed theme colors / values to DRW_globals_update() and update UBO
   * Not needed for constant color. */
  GlobalsUboStorage block;
  /** Define "globalsBlock" uniform for 'block'.  */
  struct GPUUniformBuffer *block_ubo;

  struct GPUTexture *ramp;
  struct GPUTexture *weight_ramp;

  struct GPUUniformBuffer *view_ubo;
};
extern struct DRW_Global G_draw;

#endif /* __DRAW_COMMON_H__ */