1 /*
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.
6  *
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.
11  *
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.
15  *
16  * Copyright 2016, Blender Foundation.
17  */
18 
19 /** \file
20  * \ingroup draw
21  */
22 
23 #pragma once
24 
25 struct DRWPass;
26 struct DRWShadingGroup;
27 struct FluidModifierData;
28 struct GPUMaterial;
29 struct ModifierData;
30 struct Object;
31 struct ParticleSystem;
32 struct RegionView3D;
33 struct ViewLayer;
34 
35 #define UBO_FIRST_COLOR colorWire
36 #define UBO_LAST_COLOR colorUVShadow
37 
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) */
43   float colorWire[4];
44   float colorWireEdit[4];
45   float colorActive[4];
46   float colorSelect[4];
47   float colorDupliSelect[4];
48   float colorDupli[4];
49   float colorLibrarySelect[4];
50   float colorLibrary[4];
51   float colorTransform[4];
52   float colorLight[4];
53   float colorSpeaker[4];
54   float colorCamera[4];
55   float colorCameraPath[4];
56   float colorEmpty[4];
57   float colorVertex[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];
69   float colorFace[4];
70   float colorFaceSelect[4];
71   float colorFaceFreestyle[4];
72   float colorGpencilVertex[4];
73   float colorGpencilVertexSelect[4];
74   float colorNormal[4];
75   float colorVNormal[4];
76   float colorLNormal[4];
77   float colorFaceDot[4];
78   float colorSkinRoot[4];
79 
80   float colorDeselect[4];
81   float colorOutline[4];
82   float colorLightNoAlpha[4];
83 
84   float colorBackground[4];
85   float colorBackgroundGradient[4];
86   float colorCheckerPrimary[4];
87   float colorCheckerSecondary[4];
88   float colorClippingBorder[4];
89   float colorEditMeshMiddle[4];
90 
91   float colorHandleFree[4];
92   float colorHandleAuto[4];
93   float colorHandleVect[4];
94   float colorHandleAlign[4];
95   float colorHandleAutoclamp[4];
96   float colorHandleSelFree[4];
97   float colorHandleSelAuto[4];
98   float colorHandleSelVect[4];
99   float colorHandleSelAlign[4];
100   float colorHandleSelAutoclamp[4];
101   float colorNurbUline[4];
102   float colorNurbVline[4];
103   float colorNurbSelUline[4];
104   float colorNurbSelVline[4];
105   float colorActiveSpline[4];
106 
107   float colorBonePose[4];
108   float colorBonePoseActive[4];
109   float colorBonePoseActiveUnsel[4];
110   float colorBonePoseConstraint[4];
111   float colorBonePoseIK[4];
112   float colorBonePoseSplineIK[4];
113   float colorBonePoseTarget[4];
114   float colorBoneSolid[4];
115   float colorBoneLocked[4];
116   float colorBoneActive[4];
117   float colorBoneActiveUnsel[4];
118   float colorBoneSelect[4];
119   float colorBoneIKLine[4];
120   float colorBoneIKLineNoTarget[4];
121   float colorBoneIKLineSpline[4];
122 
123   float colorText[4];
124   float colorTextHi[4];
125 
126   float colorBundleSolid[4];
127 
128   float colorMballRadius[4];
129   float colorMballRadiusSelect[4];
130   float colorMballStiffness[4];
131   float colorMballStiffnessSelect[4];
132 
133   float colorCurrentFrame[4];
134 
135   float colorGrid[4];
136   float colorGridEmphasise[4];
137   float colorGridAxisX[4];
138   float colorGridAxisY[4];
139   float colorGridAxisZ[4];
140 
141   float colorFaceBack[4];
142   float colorFaceFront[4];
143 
144   float colorUVShadow[4];
145 
146   /* NOTE! Put all color before UBO_LAST_COLOR */
147   float screenVecs[2][4];                    /* padded as vec4  */
148   float sizeViewport[2], sizeViewportInv[2]; /* packed as vec4 in glsl */
149 
150   /* Pack individual float at the end of the buffer to avoid alignment errors */
151   float sizePixel, pixelFac;
152   float sizeObjectCenter, sizeLightCenter, sizeLightCircle, sizeLightCircleShadow;
153   float sizeVertex, sizeEdge, sizeEdgeFix, sizeFaceDot;
154   float sizeChecker;
155   float sizeVertexGpencil;
156 } GlobalsUboStorage;
157 /* Keep in sync with globalsBlock in shaders */
158 BLI_STATIC_ASSERT_ALIGN(GlobalsUboStorage, 16)
159 
160 void DRW_globals_update(void);
161 void DRW_globals_free(void);
162 
163 struct DRWView *DRW_view_create_with_zoffset(const struct DRWView *parent_view,
164                                              const struct RegionView3D *rv3d,
165                                              float offset);
166 
167 int DRW_object_wire_theme_get(struct Object *ob, struct ViewLayer *view_layer, float **r_color);
168 float *DRW_color_background_blend_get(int theme_id);
169 
170 bool DRW_object_is_flat(struct Object *ob, int *r_axis);
171 bool DRW_object_axis_orthogonal_to_view(struct Object *ob, int axis);
172 
173 /* draw_hair.c */
174 
175 /* This creates a shading group with display hairs.
176  * The draw call is already added by this function, just add additional uniforms. */
177 struct DRWShadingGroup *DRW_shgroup_hair_create_sub(struct Object *object,
178                                                     struct ParticleSystem *psys,
179                                                     struct ModifierData *md,
180                                                     struct DRWShadingGroup *shgrp);
181 struct GPUVertBuf *DRW_hair_pos_buffer_get(struct Object *object,
182                                            struct ParticleSystem *psys,
183                                            struct ModifierData *md);
184 void DRW_hair_duplimat_get(struct Object *object,
185                            struct ParticleSystem *psys,
186                            struct ModifierData *md,
187                            float (*dupli_mat)[4]);
188 
189 void DRW_hair_init(void);
190 void DRW_hair_update(void);
191 void DRW_hair_free(void);
192 
193 /* draw_fluid.c */
194 
195 /* Fluid simulation.  */
196 void DRW_smoke_ensure(struct FluidModifierData *fmd, int highres);
197 void DRW_smoke_ensure_coba_field(struct FluidModifierData *fmd);
198 void DRW_smoke_ensure_velocity(struct FluidModifierData *fmd);
199 void DRW_fluid_ensure_flags(struct FluidModifierData *fmd);
200 void DRW_fluid_ensure_range_field(struct FluidModifierData *fmd);
201 
202 void DRW_smoke_free(struct FluidModifierData *fmd);
203 void DRW_smoke_free_velocity(struct FluidModifierData *fmd);
204 
205 /* draw_common.c */
206 struct DRW_Global {
207   /** If needed, contains all global/Theme colors
208    * Add needed theme colors / values to DRW_globals_update() and update UBO
209    * Not needed for constant color. */
210   GlobalsUboStorage block;
211   /** Define "globalsBlock" uniform for 'block'.  */
212   struct GPUUniformBuf *block_ubo;
213 
214   struct GPUTexture *ramp;
215   struct GPUTexture *weight_ramp;
216 
217   struct GPUUniformBuf *view_ubo;
218 };
219 extern struct DRW_Global G_draw;
220