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 draw_common.h
23 #ifndef __DRAW_COMMON_H__
24 #define __DRAW_COMMON_H__
27 struct DRWShadingGroup;
33 struct ParticleSystem;
36 #define UBO_FIRST_COLOR colorWire
37 #define UBO_LAST_COLOR colorGridAxisZ
39 /* Used as ubo but colors can be directly referenced as well */
40 /* Keep in sync with: common_globals_lib.glsl (globalsBlock) */
41 /* NOTE! Also keep all color as vec4 and between UBO_FIRST_COLOR and UBO_LAST_COLOR */
42 typedef struct GlobalsUboStorage {
43 /* UBOs data needs to be 16 byte aligned (size of vec4) */
45 float colorWireEdit[4];
48 float colorDupliSelect[4];
50 float colorLibrarySelect[4];
51 float colorLibrary[4];
52 float colorTransform[4];
54 float colorSpeaker[4];
58 float colorVertexSelect[4];
59 float colorVertexUnreferenced[4];
60 float colorVertexMissingData[4];
61 float colorEditMeshActive[4];
62 float colorEdgeSelect[4];
63 float colorEdgeSeam[4];
64 float colorEdgeSharp[4];
65 float colorEdgeCrease[4];
66 float colorEdgeBWeight[4];
67 float colorEdgeFaceSelect[4];
68 float colorEdgeFreestyle[4];
70 float colorFaceSelect[4];
71 float colorFaceFreestyle[4];
73 float colorVNormal[4];
74 float colorLNormal[4];
75 float colorFaceDot[4];
77 float colorDeselect[4];
78 float colorOutline[4];
79 float colorLampNoAlpha[4];
81 float colorBackground[4];
82 float colorEditMeshMiddle[4];
84 float colorHandleFree[4];
85 float colorHandleAuto[4];
86 float colorHandleVect[4];
87 float colorHandleAlign[4];
88 float colorHandleAutoclamp[4];
89 float colorHandleSelFree[4];
90 float colorHandleSelAuto[4];
91 float colorHandleSelVect[4];
92 float colorHandleSelAlign[4];
93 float colorHandleSelAutoclamp[4];
94 float colorNurbUline[4];
95 float colorNurbVline[4];
96 float colorNurbSelUline[4];
97 float colorNurbSelVline[4];
98 float colorActiveSpline[4];
100 float colorBonePose[4];
102 float colorCurrentFrame[4];
105 float colorGridEmphasise[4];
106 float colorGridAxisX[4];
107 float colorGridAxisY[4];
108 float colorGridAxisZ[4];
110 /* NOTE! Put all color before UBO_LAST_COLOR */
112 /* Pack individual float at the end of the buffer to avoid alignment errors */
113 float sizeLampCenter, sizeLampCircle, sizeLampCircleShadow;
114 float sizeVertex, sizeEdge, sizeEdgeFix, sizeFaceDot;
115 float gridDistance, gridResolution, gridSubdivisions, gridScale;
117 float pad_globalsBlock;
119 /* Keep in sync with globalsBlock in shaders */
120 BLI_STATIC_ASSERT_ALIGN(GlobalsUboStorage, 16)
122 void DRW_globals_update(void);
123 void DRW_globals_free(void);
125 void DRW_shgroup_world_clip_planes_from_rv3d(struct DRWShadingGroup *shgrp, const RegionView3D *rv3d);
127 struct DRWShadingGroup *shgroup_dynlines_flat_color(struct DRWPass *pass);
128 struct DRWShadingGroup *shgroup_dynlines_dashed_uniform_color(struct DRWPass *pass, const float color[4]);
129 struct DRWShadingGroup *shgroup_dynpoints_uniform_color(struct DRWPass *pass, const float color[4], const float *size, eGPUShaderConfig shader_cfg);
130 struct DRWShadingGroup *shgroup_groundlines_uniform_color(struct DRWPass *pass, const float color[4], eGPUShaderConfig shader_cfg);
131 struct DRWShadingGroup *shgroup_groundpoints_uniform_color(struct DRWPass *pass, const float color[4], eGPUShaderConfig shader_cfg);
132 struct DRWShadingGroup *shgroup_instance_screenspace(struct DRWPass *pass, struct GPUBatch *geom, const float *size, eGPUShaderConfig shader_cfg);
133 struct DRWShadingGroup *shgroup_instance_solid(struct DRWPass *pass, struct GPUBatch *geom);
134 struct DRWShadingGroup *shgroup_instance_wire(struct DRWPass *pass, struct GPUBatch *geom);
135 struct DRWShadingGroup *shgroup_instance_screen_aligned(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig shader_cfg);
136 struct DRWShadingGroup *shgroup_instance_empty_axes(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig shader_cfg);
137 struct DRWShadingGroup *shgroup_instance_scaled(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig shader_cfg);
138 struct DRWShadingGroup *shgroup_instance(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig shader_cfg);
139 struct DRWShadingGroup *shgroup_instance_alpha(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig shader_cfg);
140 struct DRWShadingGroup *shgroup_instance_outline(struct DRWPass *pass, struct GPUBatch *geom, int *baseid);
141 struct DRWShadingGroup *shgroup_camera_instance(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig shader_cfg);
142 struct DRWShadingGroup *shgroup_distance_lines_instance(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig shader_cfg);
143 struct DRWShadingGroup *shgroup_spot_instance(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig shader_cfg);
144 struct DRWShadingGroup *shgroup_instance_mball_handles(struct DRWPass *pass);
145 struct DRWShadingGroup *shgroup_instance_bone_axes(struct DRWPass *pass);
146 struct DRWShadingGroup *shgroup_instance_bone_envelope_distance(struct DRWPass *pass);
147 struct DRWShadingGroup *shgroup_instance_bone_envelope_outline(struct DRWPass *pass);
148 struct DRWShadingGroup *shgroup_instance_bone_envelope_solid(struct DRWPass *pass, bool transp);
149 struct DRWShadingGroup *shgroup_instance_bone_shape_outline(struct DRWPass *pass, struct GPUBatch *geom);
150 struct DRWShadingGroup *shgroup_instance_bone_shape_solid(struct DRWPass *pass, struct GPUBatch *geom, bool transp);
151 struct DRWShadingGroup *shgroup_instance_bone_sphere_outline(struct DRWPass *pass);
152 struct DRWShadingGroup *shgroup_instance_bone_sphere_solid(struct DRWPass *pass, bool transp);
153 struct DRWShadingGroup *shgroup_instance_bone_stick(struct DRWPass *pass);
154 struct DRWShadingGroup *shgroup_instance_bone_dof(struct DRWPass *pass, struct GPUBatch *geom);
156 struct GPUShader *mpath_line_shader_get(void);
157 struct GPUShader *mpath_points_shader_get(void);
159 struct GPUShader *volume_velocity_shader_get(bool use_needle);
161 int DRW_object_wire_theme_get(
162 struct Object *ob, struct ViewLayer *view_layer, float **r_color);
163 float *DRW_color_background_blend_get(int theme_id);
165 bool DRW_object_is_flat(Object *ob, int *axis);
166 bool DRW_object_axis_orthogonal_to_view(Object *ob, int axis);
168 /* draw_armature.c */
169 typedef struct DRWArmaturePasses {
170 struct DRWPass *bone_solid;
171 struct DRWPass *bone_outline;
172 struct DRWPass *bone_wire;
173 struct DRWPass *bone_envelope;
174 struct DRWPass *bone_axes;
175 struct DRWPass *relationship_lines;
178 void DRW_shgroup_armature_object(struct Object *ob, struct ViewLayer *view_layer, struct DRWArmaturePasses passes);
179 void DRW_shgroup_armature_pose(struct Object *ob, struct DRWArmaturePasses passes, bool transp);
180 void DRW_shgroup_armature_edit(struct Object *ob, struct DRWArmaturePasses passes, bool transp);
184 /* This creates a shading group with display hairs.
185 * The draw call is already added by this function, just add additional uniforms. */
186 struct DRWShadingGroup *DRW_shgroup_hair_create(
187 struct Object *object, struct ParticleSystem *psys, struct ModifierData *md,
188 struct DRWPass *hair_pass,
189 struct GPUShader *shader);
191 struct DRWShadingGroup *DRW_shgroup_material_hair_create(
192 struct Object *object, struct ParticleSystem *psys, struct ModifierData *md,
193 struct DRWPass *hair_pass,
194 struct GPUMaterial *material);
196 void DRW_hair_init(void);
197 void DRW_hair_update(void);
198 void DRW_hair_free(void);
201 bool DRW_pose_mode_armature(
202 struct Object *ob, struct Object *active_ob);
206 /** If needed, contains all global/Theme colors
207 * Add needed theme colors / values to DRW_globals_update() and update UBO
208 * Not needed for constant color. */
209 GlobalsUboStorage block;
210 /** Define "globalsBlock" uniform for 'block'. */
211 struct GPUUniformBuffer *block_ubo;
213 struct GPUTexture *ramp;
214 struct GPUTexture *weight_ramp;
216 extern struct DRW_Global G_draw;
218 #endif /* __DRAW_COMMON_H__ */