2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software Foundation,
14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * Copyright 2016, Blender Foundation.
19 /** \file \ingroup draw
22 #ifndef __DRAW_COMMON_H__
23 #define __DRAW_COMMON_H__
26 struct DRWShadingGroup;
32 struct ParticleSystem;
35 #define UBO_FIRST_COLOR colorWire
36 #define UBO_LAST_COLOR colorGridAxisZ
38 /* Used as ubo but colors can be directly referenced as well */
39 /* Keep in sync with: common_globals_lib.glsl (globalsBlock) */
40 /* NOTE! Also keep all color as vec4 and between UBO_FIRST_COLOR and UBO_LAST_COLOR */
41 typedef struct GlobalsUboStorage {
42 /* UBOs data needs to be 16 byte aligned (size of vec4) */
44 float colorWireEdit[4];
47 float colorDupliSelect[4];
49 float colorLibrarySelect[4];
50 float colorLibrary[4];
51 float colorTransform[4];
53 float colorSpeaker[4];
57 float colorVertexSelect[4];
58 float colorVertexUnreferenced[4];
59 float colorVertexMissingData[4];
60 float colorEditMeshActive[4];
61 float colorEdgeSelect[4];
62 float colorEdgeSeam[4];
63 float colorEdgeSharp[4];
64 float colorEdgeCrease[4];
65 float colorEdgeBWeight[4];
66 float colorEdgeFaceSelect[4];
67 float colorEdgeFreestyle[4];
69 float colorFaceSelect[4];
70 float colorFaceFreestyle[4];
72 float colorVNormal[4];
73 float colorLNormal[4];
74 float colorFaceDot[4];
76 float colorDeselect[4];
77 float colorOutline[4];
78 float colorLampNoAlpha[4];
80 float colorBackground[4];
81 float colorEditMeshMiddle[4];
83 float colorHandleFree[4];
84 float colorHandleAuto[4];
85 float colorHandleVect[4];
86 float colorHandleAlign[4];
87 float colorHandleAutoclamp[4];
88 float colorHandleSelFree[4];
89 float colorHandleSelAuto[4];
90 float colorHandleSelVect[4];
91 float colorHandleSelAlign[4];
92 float colorHandleSelAutoclamp[4];
93 float colorNurbUline[4];
94 float colorNurbVline[4];
95 float colorNurbSelUline[4];
96 float colorNurbSelVline[4];
97 float colorActiveSpline[4];
99 float colorBonePose[4];
101 float colorCurrentFrame[4];
104 float colorGridEmphasise[4];
105 float colorGridAxisX[4];
106 float colorGridAxisY[4];
107 float colorGridAxisZ[4];
109 /* NOTE! Put all color before UBO_LAST_COLOR */
111 /* Pack individual float at the end of the buffer to avoid alignment errors */
112 float sizeLampCenter, sizeLampCircle, sizeLampCircleShadow;
113 float sizeVertex, sizeEdge, sizeEdgeFix, sizeFaceDot;
114 float gridDistance, gridResolution, gridSubdivisions, gridScale;
116 float pad_globalsBlock;
118 /* Keep in sync with globalsBlock in shaders */
119 BLI_STATIC_ASSERT_ALIGN(GlobalsUboStorage, 16)
121 void DRW_globals_update(void);
122 void DRW_globals_free(void);
124 void DRW_shgroup_world_clip_planes_from_rv3d(struct DRWShadingGroup *shgrp, const RegionView3D *rv3d);
126 struct DRWShadingGroup *shgroup_dynlines_flat_color(struct DRWPass *pass, eGPUShaderConfig sh_cfg);
127 struct DRWShadingGroup *shgroup_dynlines_dashed_uniform_color(struct DRWPass *pass, const float color[4]);
128 struct DRWShadingGroup *shgroup_dynpoints_uniform_color(struct DRWPass *pass, const float color[4], const float *size, eGPUShaderConfig sh_cfg);
129 struct DRWShadingGroup *shgroup_groundlines_uniform_color(struct DRWPass *pass, const float color[4], eGPUShaderConfig sh_cfg);
130 struct DRWShadingGroup *shgroup_groundpoints_uniform_color(struct DRWPass *pass, const float color[4], eGPUShaderConfig sh_cfg);
131 struct DRWShadingGroup *shgroup_instance_screenspace(struct DRWPass *pass, struct GPUBatch *geom, const float *size, eGPUShaderConfig sh_cfg);
132 struct DRWShadingGroup *shgroup_instance_solid(struct DRWPass *pass, struct GPUBatch *geom);
133 struct DRWShadingGroup *shgroup_instance_wire(struct DRWPass *pass, struct GPUBatch *geom);
134 struct DRWShadingGroup *shgroup_instance_screen_aligned(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig sh_cfg);
135 struct DRWShadingGroup *shgroup_instance_empty_axes(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig sh_cfg);
136 struct DRWShadingGroup *shgroup_instance_scaled(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig sh_cfg);
137 struct DRWShadingGroup *shgroup_instance(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig sh_cfg);
138 struct DRWShadingGroup *shgroup_instance_alpha(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig sh_cfg);
139 struct DRWShadingGroup *shgroup_instance_outline(struct DRWPass *pass, struct GPUBatch *geom, int *baseid);
140 struct DRWShadingGroup *shgroup_camera_instance(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig sh_cfg);
141 struct DRWShadingGroup *shgroup_distance_lines_instance(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig sh_cfg);
142 struct DRWShadingGroup *shgroup_spot_instance(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig sh_cfg);
143 struct DRWShadingGroup *shgroup_instance_mball_handles(struct DRWPass *pass, eGPUShaderConfig sh_cfg);
144 struct DRWShadingGroup *shgroup_instance_bone_axes(struct DRWPass *pass);
145 struct DRWShadingGroup *shgroup_instance_bone_envelope_distance(struct DRWPass *pass);
146 struct DRWShadingGroup *shgroup_instance_bone_envelope_outline(struct DRWPass *pass);
147 struct DRWShadingGroup *shgroup_instance_bone_envelope_solid(struct DRWPass *pass, bool transp);
148 struct DRWShadingGroup *shgroup_instance_bone_shape_outline(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig sh_cfg);
149 struct DRWShadingGroup *shgroup_instance_bone_shape_solid(struct DRWPass *pass, struct GPUBatch *geom, bool transp, eGPUShaderConfig sh_cfg);
150 struct DRWShadingGroup *shgroup_instance_bone_sphere_outline(struct DRWPass *pass);
151 struct DRWShadingGroup *shgroup_instance_bone_sphere_solid(struct DRWPass *pass, bool transp);
152 struct DRWShadingGroup *shgroup_instance_bone_stick(struct DRWPass *pass, eGPUShaderConfig sh_cfg);
153 struct DRWShadingGroup *shgroup_instance_bone_dof(struct DRWPass *pass, struct GPUBatch *geom);
155 struct GPUShader *mpath_line_shader_get(void);
156 struct GPUShader *mpath_points_shader_get(void);
158 struct GPUShader *volume_velocity_shader_get(bool use_needle);
160 int DRW_object_wire_theme_get(
161 struct Object *ob, struct ViewLayer *view_layer, float **r_color);
162 float *DRW_color_background_blend_get(int theme_id);
164 bool DRW_object_is_flat(Object *ob, int *axis);
165 bool DRW_object_axis_orthogonal_to_view(Object *ob, int axis);
167 /* draw_armature.c */
168 typedef struct DRWArmaturePasses {
169 struct DRWPass *bone_solid;
170 struct DRWPass *bone_outline;
171 struct DRWPass *bone_wire;
172 struct DRWPass *bone_envelope;
173 struct DRWPass *bone_axes;
174 struct DRWPass *relationship_lines;
177 void DRW_shgroup_armature_object(struct Object *ob, struct ViewLayer *view_layer, struct DRWArmaturePasses passes);
178 void DRW_shgroup_armature_pose(struct Object *ob, struct DRWArmaturePasses passes, bool transp);
179 void DRW_shgroup_armature_edit(struct Object *ob, struct DRWArmaturePasses passes, bool transp);
183 /* This creates a shading group with display hairs.
184 * The draw call is already added by this function, just add additional uniforms. */
185 struct DRWShadingGroup *DRW_shgroup_hair_create(
186 struct Object *object, struct ParticleSystem *psys, struct ModifierData *md,
187 struct DRWPass *hair_pass,
188 struct GPUShader *shader);
190 struct DRWShadingGroup *DRW_shgroup_material_hair_create(
191 struct Object *object, struct ParticleSystem *psys, struct ModifierData *md,
192 struct DRWPass *hair_pass,
193 struct GPUMaterial *material);
195 void DRW_hair_init(void);
196 void DRW_hair_update(void);
197 void DRW_hair_free(void);
200 bool DRW_pose_mode_armature(
201 struct Object *ob, struct Object *active_ob);
205 /** If needed, contains all global/Theme colors
206 * Add needed theme colors / values to DRW_globals_update() and update UBO
207 * Not needed for constant color. */
208 GlobalsUboStorage block;
209 /** Define "globalsBlock" uniform for 'block'. */
210 struct GPUUniformBuffer *block_ubo;
212 struct GPUTexture *ramp;
213 struct GPUTexture *weight_ramp;
215 extern struct DRW_Global G_draw;
217 #endif /* __DRAW_COMMON_H__ */