LEFT | RIGHT |
1 /* | 1 /* |
2 * ***** BEGIN GPL LICENSE BLOCK ***** | 2 * ***** BEGIN GPL LICENSE BLOCK ***** |
3 * | 3 * |
4 * This program is free software; you can redistribute it and/or | 4 * This program is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU General Public License | 5 * modify it under the terms of the GNU General Public License |
6 * as published by the Free Software Foundation; either version 2 | 6 * as published by the Free Software Foundation; either version 2 |
7 * of the License, or (at your option) any later version.· | 7 * of the License, or (at your option) any later version.· |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 BoundBox *bb = rv3d->clipbb; | 153 BoundBox *bb = rv3d->clipbb; |
154 | 154 |
155 if (bb) { | 155 if (bb) { |
156 static unsigned int clipping_index[6][4] = {{0, 1, 2, 3}, | 156 static unsigned int clipping_index[6][4] = {{0, 1, 2, 3}, |
157 {0, 4, 5, 1}, | 157 {0, 4, 5, 1}, |
158 {4, 7, 6, 5}, | 158 {4, 7, 6, 5}, |
159 {7, 3, 2, 6}, | 159 {7, 3, 2, 6}, |
160 {1, 5, 6, 2}, | 160 {1, 5, 6, 2}, |
161 {7, 4, 0, 3}}; | 161 {7, 4, 0, 3}}; |
162 | 162 |
163 » » UI_ThemeColorShade(TH_BACK, -8); | 163 » » /* fill in zero alpha for rendering & re-projection [#31530] */ |
| 164 » » unsigned char col[4]; |
| 165 » » UI_GetThemeColorShade3ubv(TH_BACK, -8, col); |
| 166 » » col[3] = 0; |
| 167 » » glColor4ubv(col); |
164 | 168 |
165 glEnableClientState(GL_VERTEX_ARRAY); | 169 glEnableClientState(GL_VERTEX_ARRAY); |
166 glVertexPointer(3, GL_FLOAT, 0, bb->vec); | 170 glVertexPointer(3, GL_FLOAT, 0, bb->vec); |
167 glDrawElements(GL_QUADS, sizeof(clipping_index) / sizeof(unsigne
d int), GL_UNSIGNED_INT, clipping_index); | 171 glDrawElements(GL_QUADS, sizeof(clipping_index) / sizeof(unsigne
d int), GL_UNSIGNED_INT, clipping_index); |
168 glDisableClientState(GL_VERTEX_ARRAY); | 172 glDisableClientState(GL_VERTEX_ARRAY); |
169 | 173 |
170 } | 174 } |
171 } | 175 } |
172 | 176 |
173 void ED_view3d_clipping_set(RegionView3D *rv3d) | 177 void ED_view3d_clipping_set(RegionView3D *rv3d) |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 /* iter over 'Y' */ | 257 /* iter over 'Y' */ |
254 verts[0][1] = verts[1][1] = y - dx *floor(y / dx); | 258 verts[0][1] = verts[1][1] = y - dx *floor(y / dx); |
255 while (verts[0][1] < ar->winy) { | 259 while (verts[0][1] < ar->winy) { |
256 glDrawArrays(GL_LINES, 0, 2); | 260 glDrawArrays(GL_LINES, 0, 2); |
257 verts[0][1] = verts[1][1] = verts[0][1] + dx; | 261 verts[0][1] = verts[1][1] = verts[0][1] + dx; |
258 } | 262 } |
259 | 263 |
260 glDisableClientState(GL_VERTEX_ARRAY); | 264 glDisableClientState(GL_VERTEX_ARRAY); |
261 } | 265 } |
262 | 266 |
263 #define GRID_MIN_PX 6.0f | 267 #define GRID_MIN_PX_D 6.0 |
| 268 #define GRID_MIN_PX_F 6.0f |
264 | 269 |
265 static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, const char **
grid_unit) | 270 static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, const char **
grid_unit) |
266 { | 271 { |
267 /* extern short bgpicmode; */ | 272 /* extern short bgpicmode; */ |
268 RegionView3D *rv3d = ar->regiondata; | 273 RegionView3D *rv3d = ar->regiondata; |
269 double wx, wy, x, y, fw, fx, fy, dx; | 274 double wx, wy, x, y, fw, fx, fy, dx; |
270 double vec4[4]; | 275 double vec4[4]; |
271 unsigned char col[3], col2[3]; | 276 unsigned char col[3], col2[3]; |
272 | 277 |
273 fx = rv3d->persmat[3][0]; | 278 fx = rv3d->persmat[3][0]; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 double dx_scalar; | 310 double dx_scalar; |
306 float blend_fac; | 311 float blend_fac; |
307 | 312 |
308 bUnit_GetSystem(&usys, &len, unit->system, B_UNIT_LENGTH); | 313 bUnit_GetSystem(&usys, &len, unit->system, B_UNIT_LENGTH); |
309 | 314 |
310 if (usys) { | 315 if (usys) { |
311 i = len; | 316 i = len; |
312 while (i--) { | 317 while (i--) { |
313 double scalar = bUnit_GetScaler(usys, i); | 318 double scalar = bUnit_GetScaler(usys, i); |
314 | 319 |
315 » » » » dx_scalar = dx * scalar / unit->scale_length; | 320 » » » » dx_scalar = dx * scalar / (double)unit->scale_le
ngth; |
316 » » » » if (dx_scalar < (GRID_MIN_PX * 2.0)) | 321 » » » » if (dx_scalar < (GRID_MIN_PX_D * 2.0)) |
317 continue; | 322 continue; |
318 | 323 |
319 /* Store the smallest drawn grid size units name
so users know how big each grid cell is */ | 324 /* Store the smallest drawn grid size units name
so users know how big each grid cell is */ |
320 if (*grid_unit == NULL) { | 325 if (*grid_unit == NULL) { |
321 *grid_unit = bUnit_GetNameDisplay(usys,
i); | 326 *grid_unit = bUnit_GetNameDisplay(usys,
i); |
322 » » » » » rv3d->gridview = (float)((scalar * v3d->
grid) / (double)unit->scale_length); | 327 » » » » » rv3d->gridview = (float)((scalar * (doub
le)v3d->grid) / (double)unit->scale_length); |
323 } | 328 } |
324 » » » » blend_fac = 1.0f - ((GRID_MIN_PX * 2.0f) / (floa
t)dx_scalar); | 329 » » » » blend_fac = 1.0f - ((GRID_MIN_PX_F * 2.0f) / (fl
oat)dx_scalar); |
325 | 330 |
326 /* tweak to have the fade a bit nicer */ | 331 /* tweak to have the fade a bit nicer */ |
327 blend_fac = (blend_fac * blend_fac) * 2.0f; | 332 blend_fac = (blend_fac * blend_fac) * 2.0f; |
328 CLAMP(blend_fac, 0.3f, 1.0f); | 333 CLAMP(blend_fac, 0.3f, 1.0f); |
329 | 334 |
330 | 335 |
331 UI_ThemeColorBlend(TH_BACK, TH_GRID, blend_fac); | 336 UI_ThemeColorBlend(TH_BACK, TH_GRID, blend_fac); |
332 | 337 |
333 drawgrid_draw(ar, wx, wy, x, y, dx_scalar); | 338 drawgrid_draw(ar, wx, wy, x, y, dx_scalar); |
334 } | 339 } |
335 } | 340 } |
336 } | 341 } |
337 else { | 342 else { |
338 short sublines = v3d->gridsubdiv; | 343 short sublines = v3d->gridsubdiv; |
339 | 344 |
340 » » if (dx < GRID_MIN_PX) { | 345 » » if (dx < GRID_MIN_PX_D) { |
341 rv3d->gridview *= sublines; | 346 rv3d->gridview *= sublines; |
342 dx *= sublines; | 347 dx *= sublines; |
343 | 348 |
344 » » » if (dx < GRID_MIN_PX) { | 349 » » » if (dx < GRID_MIN_PX_D) { |
345 rv3d->gridview *= sublines; | 350 rv3d->gridview *= sublines; |
346 dx *= sublines; | 351 dx *= sublines; |
347 | 352 |
348 » » » » if (dx < GRID_MIN_PX) { | 353 » » » » if (dx < GRID_MIN_PX_D) { |
349 rv3d->gridview *= sublines; | 354 rv3d->gridview *= sublines; |
350 dx *= sublines; | 355 dx *= sublines; |
351 » » » » » if (dx < GRID_MIN_PX) ; | 356 » » » » » if (dx < GRID_MIN_PX_D) ; |
352 else { | 357 else { |
353 UI_ThemeColor(TH_GRID); | 358 UI_ThemeColor(TH_GRID); |
354 drawgrid_draw(ar, wx, wy, x, y,
dx); | 359 drawgrid_draw(ar, wx, wy, x, y,
dx); |
355 } | 360 } |
356 } | 361 } |
357 else { // start blending out | 362 else { // start blending out |
358 » » » » » UI_ThemeColorBlend(TH_BACK, TH_GRID, dx
/ (GRID_MIN_PX * 6.0f)); | 363 » » » » » UI_ThemeColorBlend(TH_BACK, TH_GRID, dx
/ (GRID_MIN_PX_D * 6.0)); |
359 drawgrid_draw(ar, wx, wy, x, y, dx); | 364 drawgrid_draw(ar, wx, wy, x, y, dx); |
360 | 365 |
361 UI_ThemeColor(TH_GRID); | 366 UI_ThemeColor(TH_GRID); |
362 drawgrid_draw(ar, wx, wy, x, y, sublines
* dx); | 367 drawgrid_draw(ar, wx, wy, x, y, sublines
* dx); |
363 } | 368 } |
364 } | 369 } |
365 else { // start blending out (GRID_MIN_PX < dx < (GRID_
MIN_PX*10)) | 370 else { // start blending out (GRID_MIN_PX < dx < (GRID_
MIN_PX*10)) |
366 » » » » UI_ThemeColorBlend(TH_BACK, TH_GRID, dx / (GRID_
MIN_PX * 6.0f)); | 371 » » » » UI_ThemeColorBlend(TH_BACK, TH_GRID, dx / (GRID_
MIN_PX_D * 6.0)); |
367 drawgrid_draw(ar, wx, wy, x, y, dx); | 372 drawgrid_draw(ar, wx, wy, x, y, dx); |
368 | 373 |
369 UI_ThemeColor(TH_GRID); | 374 UI_ThemeColor(TH_GRID); |
370 drawgrid_draw(ar, wx, wy, x, y, sublines * dx); | 375 drawgrid_draw(ar, wx, wy, x, y, sublines * dx); |
371 } | 376 } |
372 } | 377 } |
373 else { | 378 else { |
374 » » » if (dx > (GRID_MIN_PX * 10)) { // start blending in | 379 » » » if (dx > (GRID_MIN_PX_D * 10.0)) { // start blendin
g in |
375 rv3d->gridview /= sublines; | 380 rv3d->gridview /= sublines; |
376 dx /= sublines; | 381 dx /= sublines; |
377 » » » » if (dx > (GRID_MIN_PX * 10)) { // start ble
nding in | 382 » » » » if (dx > (GRID_MIN_PX_D * 10.0)) { // start
blending in |
378 rv3d->gridview /= sublines; | 383 rv3d->gridview /= sublines; |
379 dx /= sublines; | 384 dx /= sublines; |
380 » » » » » if (dx > (GRID_MIN_PX * 10)) { | 385 » » » » » if (dx > (GRID_MIN_PX_D * 10.0)) { |
381 UI_ThemeColor(TH_GRID); | 386 UI_ThemeColor(TH_GRID); |
382 drawgrid_draw(ar, wx, wy, x, y,
dx); | 387 drawgrid_draw(ar, wx, wy, x, y,
dx); |
383 } | 388 } |
384 else { | 389 else { |
385 » » » » » » UI_ThemeColorBlend(TH_BACK, TH_G
RID, dx / (GRID_MIN_PX * 6)); | 390 » » » » » » UI_ThemeColorBlend(TH_BACK, TH_G
RID, dx / (GRID_MIN_PX_D * 6.0)); |
386 drawgrid_draw(ar, wx, wy, x, y,
dx); | 391 drawgrid_draw(ar, wx, wy, x, y,
dx); |
387 UI_ThemeColor(TH_GRID); | 392 UI_ThemeColor(TH_GRID); |
388 drawgrid_draw(ar, wx, wy, x, y,
dx * sublines); | 393 drawgrid_draw(ar, wx, wy, x, y,
dx * sublines); |
389 } | 394 } |
390 } | 395 } |
391 else { | 396 else { |
392 » » » » » UI_ThemeColorBlend(TH_BACK, TH_GRID, dx
/ (GRID_MIN_PX * 6)); | 397 » » » » » UI_ThemeColorBlend(TH_BACK, TH_GRID, dx
/ (GRID_MIN_PX_D * 6.0)); |
393 drawgrid_draw(ar, wx, wy, x, y, dx); | 398 drawgrid_draw(ar, wx, wy, x, y, dx); |
394 UI_ThemeColor(TH_GRID); | 399 UI_ThemeColor(TH_GRID); |
395 drawgrid_draw(ar, wx, wy, x, y, dx * sub
lines); | 400 drawgrid_draw(ar, wx, wy, x, y, dx * sub
lines); |
396 } | 401 } |
397 } | 402 } |
398 else { | 403 else { |
399 » » » » UI_ThemeColorBlend(TH_BACK, TH_GRID, dx / (GRID_
MIN_PX * 6)); | 404 » » » » UI_ThemeColorBlend(TH_BACK, TH_GRID, dx / (GRID_
MIN_PX_D * 6.0)); |
400 drawgrid_draw(ar, wx, wy, x, y, dx); | 405 drawgrid_draw(ar, wx, wy, x, y, dx); |
401 UI_ThemeColor(TH_GRID); | 406 UI_ThemeColor(TH_GRID); |
402 drawgrid_draw(ar, wx, wy, x, y, dx * sublines); | 407 drawgrid_draw(ar, wx, wy, x, y, dx * sublines); |
403 } | 408 } |
404 } | 409 } |
405 } | 410 } |
406 | 411 |
407 | 412 |
408 x += (wx); | 413 x += (wx); |
409 y += (wy); | 414 y += (wy); |
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1289 scene->toolsettings && (scene->toolsettings->imapaint.flag & IM
AGEPAINT_PROJECT_DISABLE)) | 1294 scene->toolsettings && (scene->toolsettings->imapaint.flag & IM
AGEPAINT_PROJECT_DISABLE)) |
1290 { | 1295 { |
1291 /* do nothing */ | 1296 /* do nothing */ |
1292 } | 1297 } |
1293 else if ((base && (base->object->mode & OB_MODE_PARTICLE_EDIT)) && | 1298 else if ((base && (base->object->mode & OB_MODE_PARTICLE_EDIT)) && |
1294 v3d->drawtype > OB_WIRE && (v3d->flag & V3D_ZBUF_SELECT)) | 1299 v3d->drawtype > OB_WIRE && (v3d->flag & V3D_ZBUF_SELECT)) |
1295 { | 1300 { |
1296 /* do nothing */ | 1301 /* do nothing */ |
1297 } | 1302 } |
1298 else if (scene->obedit && v3d->drawtype > OB_WIRE && | 1303 else if (scene->obedit && v3d->drawtype > OB_WIRE && |
1299 » (v3d->flag & V3D_ZBUF_SELECT)) { | 1304 » (v3d->flag & V3D_ZBUF_SELECT)) |
| 1305 » { |
1300 /* do nothing */ | 1306 /* do nothing */ |
1301 } | 1307 } |
1302 else { | 1308 else { |
1303 v3d->flag &= ~V3D_INVALID_BACKBUF; | 1309 v3d->flag &= ~V3D_INVALID_BACKBUF; |
1304 return; | 1310 return; |
1305 } | 1311 } |
1306 | 1312 |
1307 if (!(v3d->flag & V3D_INVALID_BACKBUF) ) return; | 1313 if (!(v3d->flag & V3D_INVALID_BACKBUF) ) return; |
1308 | 1314 |
1309 // if (test) { | 1315 // if (test) { |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1850 if (dob_prev && dob_prev->ob != dob->ob) { | 1856 if (dob_prev && dob_prev->ob != dob->ob) { |
1851 if (use_displist == TRUE) | 1857 if (use_displist == TRUE) |
1852 glDeleteLists(displist, 1); | 1858 glDeleteLists(displist, 1); |
1853 | 1859 |
1854 use_displist = -1; | 1860 use_displist = -1; |
1855 } | 1861 } |
1856 | 1862 |
1857 /* generate displist */ | 1863 /* generate displist */ |
1858 if (use_displist == -1) { | 1864 if (use_displist == -1) { |
1859 | 1865 |
1860 » » » /* note, since this was added, its checked dob->type==OB
_DUPLIGROUP | 1866 » » » /* note, since this was added, its checked (dob->type ==
OB_DUPLIGROUP) |
1861 * however this is very slow, it was probably needed for
the NLA | 1867 * however this is very slow, it was probably needed for
the NLA |
1862 * offset feature (used in group-duplicate.blend but no
longer works in 2.5) | 1868 * offset feature (used in group-duplicate.blend but no
longer works in 2.5) |
1863 * so for now it should be ok to - campbell */ | 1869 * so for now it should be ok to - campbell */ |
1864 | 1870 |
1865 if ( /* if this is the last no need to make a displist
*/ | 1871 if ( /* if this is the last no need to make a displist
*/ |
1866 (dob_next == NULL || dob_next->ob != dob->ob) || | 1872 (dob_next == NULL || dob_next->ob != dob->ob) || |
1867 /* lamp drawing messes with matrices, could be handl
ed smarter... but this works */ | 1873 /* lamp drawing messes with matrices, could be handl
ed smarter... but this works */ |
1868 (dob->ob->type == OB_LAMP) || | 1874 (dob->ob->type == OB_LAMP) || |
1869 (dob->type == OB_DUPLIGROUP && dob->animated) || | 1875 (dob->type == OB_DUPLIGROUP && dob->animated) || |
1870 !(bb_tmp = BKE_object_boundbox_get(dob->ob))) | 1876 !(bb_tmp = BKE_object_boundbox_get(dob->ob))) |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2300 | 2306 |
2301 if (BKE_scene_use_new_shading_nodes(scene)) { | 2307 if (BKE_scene_use_new_shading_nodes(scene)) { |
2302 if (v3d->drawtype == OB_MATERIAL) | 2308 if (v3d->drawtype == OB_MATERIAL) |
2303 mask |= CD_MASK_ORCO; | 2309 mask |= CD_MASK_ORCO; |
2304 } | 2310 } |
2305 else { | 2311 else { |
2306 if (scene->gm.matmode == GAME_MAT_GLSL) | 2312 if (scene->gm.matmode == GAME_MAT_GLSL) |
2307 mask |= CD_MASK_ORCO; | 2313 mask |= CD_MASK_ORCO; |
2308 } | 2314 } |
2309 } | 2315 } |
2310 | 2316 |
2311 mask |= CD_MASK_MVERT_SKIN; | |
2312 | |
2313 return mask; | 2317 return mask; |
2314 } | 2318 } |
2315 | 2319 |
2316 CustomDataMask ED_view3d_object_datamask(Scene *scene) | 2320 CustomDataMask ED_view3d_object_datamask(Scene *scene) |
2317 { | 2321 { |
2318 Object *ob = scene->basact ? scene->basact->object : NULL; | 2322 Object *ob = scene->basact ? scene->basact->object : NULL; |
2319 CustomDataMask mask = 0; | 2323 CustomDataMask mask = 0; |
2320 | 2324 |
2321 if (ob) { | 2325 if (ob) { |
2322 /* check if we need tfaces & mcols due to face select or texture
paint */ | 2326 /* check if we need tfaces & mcols due to face select or texture
paint */ |
2323 if (paint_facesel_test(ob) || (ob->mode & OB_MODE_TEXTURE_PAINT)
) { | 2327 if (paint_facesel_test(ob) || (ob->mode & OB_MODE_TEXTURE_PAINT)
) { |
2324 mask |= CD_MASK_MTFACE | CD_MASK_MCOL; | 2328 mask |= CD_MASK_MTFACE | CD_MASK_MCOL; |
2325 } | 2329 } |
2326 | 2330 |
2327 /* check if we need mcols due to vertex paint or weightpaint */ | |
2328 if (ob->mode & OB_MODE_VERTEX_PAINT) { | |
2329 mask |= CD_MASK_MCOL; | |
2330 } | |
2331 | |
2332 if (ob->mode & OB_MODE_WEIGHT_PAINT) { | 2331 if (ob->mode & OB_MODE_WEIGHT_PAINT) { |
2333 mask |= CD_MASK_PREVIEW_MCOL; | 2332 mask |= CD_MASK_PREVIEW_MCOL; |
2334 } | 2333 } |
2335 } | 2334 } |
2336 | 2335 |
2337 return mask; | 2336 return mask; |
2338 } | |
2339 | |
2340 /* goes over all modes and view3d settings */ | |
2341 CustomDataMask ED_view3d_screen_datamask(bScreen *screen) | |
2342 { | |
2343 Scene *scene = screen->scene; | |
2344 CustomDataMask mask = CD_MASK_BAREMESH; | |
2345 ScrArea *sa; | |
2346 ········ | |
2347 /* check if we need tfaces & mcols due to view mode */ | |
2348 for (sa = screen->areabase.first; sa; sa = sa->next) { | |
2349 if (sa->spacetype == SPACE_VIEW3D) { | |
2350 mask |= ED_view3d_datamask(scene, (View3D *)sa->spacedat
a.first); | |
2351 } | |
2352 } | |
2353 | |
2354 mask |= ED_view3d_object_datamask(scene); | |
2355 | |
2356 return mask; | |
2357 } | |
2358 | |
2359 void ED_view3d_update_viewmat(Scene *scene, View3D *v3d, ARegion *ar, float view
mat[][4], float winmat[][4]) | |
2360 { | |
2361 RegionView3D *rv3d = ar->regiondata; | |
2362 | |
2363 /* setup window matrices */ | |
2364 if (winmat) | |
2365 copy_m4_m4(rv3d->winmat, winmat); | |
2366 else | |
2367 setwinmatrixview3d(ar, v3d, NULL); /* NULL= no pickrect */ | |
2368 | |
2369 /* setup view matrix */ | |
2370 if (viewmat) | |
2371 copy_m4_m4(rv3d->viewmat, viewmat); | |
2372 else | |
2373 setviewmatrixview3d(scene, v3d, rv3d); /* note: calls BKE_objec
t_where_is_calc for camera... */ | |
2374 | |
2375 /* update utilitity matrices */ | |
2376 mult_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat); | |
2377 invert_m4_m4(rv3d->persinv, rv3d->persmat); | |
2378 invert_m4_m4(rv3d->viewinv, rv3d->viewmat); | |
2379 | |
2380 /* calculate pixelsize factor once, is used for lamps and obcenters */ | |
2381 { | |
2382 /* note: '1.0f / len_v3(v1)' replaced 'len_v3(rv3d->viewmat[0
])' | |
2383 * because of float point precision problems at large values [#2
3908] */ | |
2384 float v1[3], v2[3]; | |
2385 float len1, len2; | |
2386 | |
2387 v1[0] = rv3d->persmat[0][0]; | |
2388 v1[1] = rv3d->persmat[1][0]; | |
2389 v1[2] = rv3d->persmat[2][0]; | |
2390 | |
2391 v2[0] = rv3d->persmat[0][1]; | |
2392 v2[1] = rv3d->persmat[1][1]; | |
2393 v2[2] = rv3d->persmat[2][1]; | |
2394 | |
2395 len1 = 1.0f / len_v3(v1); | |
2396 len2 = 1.0f / len_v3(v2); | |
2397 | |
2398 rv3d->pixsize = (2.0f * MAX2(len1, len2)) / (float)MAX2(ar->winx
, ar->winy); | |
2399 } | |
2400 } | |
2401 | |
2402 static void view3d_main_area_setup_view(Scene *scene, View3D *v3d, ARegion *ar,
float viewmat[][4], float winmat[][4]) | |
2403 { | |
2404 RegionView3D *rv3d = ar->regiondata; | |
2405 | |
2406 ED_view3d_update_viewmat(scene, v3d, ar, viewmat, winmat); | |
2407 | |
2408 /* set for opengl */ | |
2409 glMatrixMode(GL_PROJECTION); | |
2410 glLoadMatrixf(rv3d->winmat); | |
2411 glMatrixMode(GL_MODELVIEW); | |
2412 glLoadMatrixf(rv3d->viewmat); | |
2413 } | |
2414 | |
2415 void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, | |
2416 int winx, int winy, float viewmat[][4], float winm
at[][4], | |
2417 int draw_background) | |
2418 { | |
2419 RegionView3D *rv3d = ar->regiondata; | |
2420 Base *base; | |
2421 float backcol[3]; | |
2422 int bwinx, bwiny; | |
2423 rcti brect; | |
2424 ImBuf *bg_ibuf = NULL; | |
2425 | |
2426 glPushMatrix(); | |
2427 | |
2428 /* set temporary new size */ | |
2429 bwinx = ar->winx; | |
2430 bwiny = ar->winy; | |
2431 brect = ar->winrct; | |
2432 ········ | |
2433 ar->winx = winx; | |
2434 ar->winy = winy; | |
2435 ar->winrct.xmin = 0; | |
2436 ar->winrct.ymin = 0; | |
2437 ar->winrct.xmax = winx; | |
2438 ar->winrct.ymax = winy; | |
2439 | |
2440 /* set theme */ | |
2441 UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW); | |
2442 ········ | |
2443 /* set flags */ | |
2444 G.f |= G_RENDER_OGL; | |
2445 | |
2446 /* free images which can have changed on frame-change | |
2447 * warning! can be slow so only free animated images - campbell */ | |
2448 GPU_free_images_anim(); | |
2449 ········ | |
2450 /* shadow buffers, before we setup matrices */ | |
2451 if (draw_glsl_material(scene, NULL, v3d, v3d->drawtype)) | |
2452 gpu_update_lamps_shadows(scene, v3d); | |
2453 | |
2454 /* if scene has got active clip, use it for render backdrop */ | |
2455 if (draw_background && scene->clip && rv3d->persp == RV3D_CAMOB && v3d->
camera) { | |
2456 MovieClipUser user = {0}; | |
2457 | |
2458 BKE_movieclip_user_set_frame(&user, CFRA); | |
2459 bg_ibuf = BKE_movieclip_get_ibuf(scene->clip, &user); | |
2460 } | |
2461 | |
2462 if (!bg_ibuf) { | |
2463 /* set background color, fallback on the view background color | |
2464 * (if active clip is set but frame is failed to load fallback t
o horizon color as background) */ | |
2465 if (scene->world) { | |
2466 if (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) | |
2467 linearrgb_to_srgb_v3_v3(backcol, &scene->world->
horr); | |
2468 else | |
2469 copy_v3_v3(backcol, &scene->world->horr); | |
2470 glClearColor(backcol[0], backcol[1], backcol[2], 0.0); | |
2471 } | |
2472 else { | |
2473 UI_ThemeClearColor(TH_BACK); | |
2474 } | |
2475 } | |
2476 | |
2477 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
2478 | |
2479 if (bg_ibuf) { | |
2480 unsigned char *pixels, *cp, *dst_cp; | |
2481 int i; | |
2482 | |
2483 if (bg_ibuf->rect_float && !bg_ibuf->rect) | |
2484 IMB_rect_from_float(bg_ibuf); | |
2485 | |
2486 dst_cp = pixels = MEM_callocN(4 * sizeof(unsigned char) * bg_ibu
f->x * bg_ibuf->y, "draw offscreen clip pixels"); | |
2487 cp = (unsigned char *)bg_ibuf->rect; | |
2488 for (i = 0; i < bg_ibuf->x * bg_ibuf->y; i++, cp += 4, dst_cp +=
4) { | |
2489 dst_cp[0] = cp[0]; | |
2490 dst_cp[1] = cp[1]; | |
2491 dst_cp[2] = cp[2]; | |
2492 dst_cp[3] = 255; | |
2493 } | |
2494 | |
2495 glMatrixMode(GL_PROJECTION); | |
2496 glPushMatrix(); | |
2497 glMatrixMode(GL_MODELVIEW); | |
2498 glPushMatrix(); | |
2499 ED_region_pixelspace(ar); | |
2500 | |
2501 glPixelZoom((float)winx / bg_ibuf->x, (float)winy / bg_ibuf->y); | |
2502 glaDrawPixelsTex(0, 0, bg_ibuf->x, bg_ibuf->y, GL_UNSIGNED_BYTE,
pixels); | |
2503 | |
2504 glPixelZoom(1.0, 1.0); | |
2505 | |
2506 glMatrixMode(GL_PROJECTION); | |
2507 glPopMatrix(); | |
2508 glMatrixMode(GL_MODELVIEW); | |
2509 glPopMatrix(); | |
2510 | |
2511 IMB_freeImBuf(bg_ibuf); | |
2512 MEM_freeN(pixels); | |
2513 } | |
2514 | |
2515 /* setup view matrices */ | |
2516 view3d_main_area_setup_view(scene, v3d, ar, viewmat, winmat); | |
2517 | |
2518 if (rv3d->rflag & RV3D_CLIPPING) | |
2519 view3d_draw_clipping(rv3d); | |
2520 | |
2521 /* set zbuffer */ | |
2522 if (v3d->drawtype > OB_WIRE) { | |
2523 v3d->zbuf = TRUE; | |
2524 glEnable(GL_DEPTH_TEST); | |
2525 } | |
2526 else | |
2527 v3d->zbuf = FALSE; | |
2528 | |
2529 if (rv3d->rflag & RV3D_CLIPPING) | |
2530 ED_view3d_clipping_set(rv3d); | |
2531 | |
2532 /* draw set first */ | |
2533 if (scene->set) { | |
2534 Scene *sce_iter; | |
2535 for (SETLOOPER(scene->set, sce_iter, base)) { | |
2536 if (v3d->lay & base->lay) { | |
2537 UI_ThemeColorBlend(TH_WIRE, TH_BACK, 0.6f); | |
2538 draw_object(scene, ar, v3d, base, DRAW_CONSTCOLO
R | DRAW_SCENESET); | |
2539 ································ | |
2540 if (base->object->transflag & OB_DUPLI) | |
2541 draw_dupli_objects_color(scene, ar, v3d,
base, TH_WIRE); | |
2542 } | |
2543 } | |
2544 } | |
2545 ········ | |
2546 /* then draw not selected and the duplis, but skip editmode object */ | |
2547 for (base = scene->base.first; base; base = base->next) { | |
2548 if (v3d->lay & base->lay) { | |
2549 /* dupli drawing */ | |
2550 if (base->object->transflag & OB_DUPLI) | |
2551 draw_dupli_objects(scene, ar, v3d, base); | |
2552 | |
2553 draw_object(scene, ar, v3d, base, 0); | |
2554 } | |
2555 } | |
2556 | |
2557 /* must be before xray draw which clears the depth buffer */ | |
2558 if (v3d->zbuf) glDisable(GL_DEPTH_TEST); | |
2559 draw_gpencil_view3d(scene, v3d, ar, 1); | |
2560 if (v3d->zbuf) glEnable(GL_DEPTH_TEST); | |
2561 | |
2562 /* transp and X-ray afterdraw stuff */ | |
2563 if (v3d->afterdraw_transp.first) view3d_draw_transp(scene, ar, v3d); | |
2564 if (v3d->afterdraw_xray.first) view3d_draw_xray(scene, ar, v3d, 1)
; /* clears zbuffer if it is used! */ | |
2565 if (v3d->afterdraw_xraytransp.first) view3d_draw_xraytransp(scene, ar, v
3d, 1); | |
2566 | |
2567 if (rv3d->rflag & RV3D_CLIPPING) | |
2568 ED_view3d_clipping_disable(); | |
2569 | |
2570 /* cleanup */ | |
2571 if (v3d->zbuf) { | |
2572 v3d->zbuf = FALSE; | |
2573 glDisable(GL_DEPTH_TEST); | |
2574 } | |
2575 | |
2576 /* draw grease-pencil stuff */ | |
2577 ED_region_pixelspace(ar); | |
2578 | |
2579 /* draw grease-pencil stuff - needed to get paint-buffer shown too (sinc
e it's 2D) */ | |
2580 draw_gpencil_view3d(scene, v3d, ar, 0); | |
2581 | |
2582 /* freeing the images again here could be done after the operator runs,
leaving for now */ | |
2583 GPU_free_images_anim(); | |
2584 | |
2585 /* restore size */ | |
2586 ar->winx = bwinx; | |
2587 ar->winy = bwiny; | |
2588 ar->winrct = brect; | |
2589 | |
2590 glPopMatrix(); | |
2591 | |
2592 // XXX, without this the sequencer flickers with opengl draw enabled, ne
ed to find out why - campbell | |
2593 glColor4ub(255, 255, 255, 255); | |
2594 | |
2595 G.f &= ~G_RENDER_OGL; | |
2596 } | |
2597 | |
2598 /* utility func for ED_view3d_draw_offscreen */ | |
2599 ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar, | |
2600 int sizex, int sizey, unsigned int flag, i
nt draw_background, char err_out[256]) | |
2601 { | |
2602 RegionView3D *rv3d = ar->regiondata; | |
2603 ImBuf *ibuf; | |
2604 GPUOffScreen *ofs; | |
2605 ········ | |
2606 /* state changes make normal drawing go weird otherwise */ | |
2607 glPushAttrib(GL_LIGHTING_BIT); | |
2608 | |
2609 /* bind */ | |
2610 ofs = GPU_offscreen_create(sizex, sizey, err_out); | |
2611 if (ofs == NULL) | |
2612 return NULL; | |
2613 | |
2614 GPU_offscreen_bind(ofs); | |
2615 | |
2616 /* render 3d view */ | |
2617 if (rv3d->persp == RV3D_CAMOB && v3d->camera) { | |
2618 CameraParams params; | |
2619 | |
2620 BKE_camera_params_init(¶ms); | |
2621 BKE_camera_params_from_object(¶ms, v3d->camera); | |
2622 BKE_camera_params_compute_viewplane(¶ms, sizex, sizey, scene
->r.xasp, scene->r.yasp); | |
2623 BKE_camera_params_compute_matrix(¶ms); | |
2624 | |
2625 ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, par
ams.winmat, draw_background); | |
2626 } | |
2627 else { | |
2628 ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, NUL
L, draw_background); | |
2629 } | |
2630 | |
2631 /* read in pixels & stamp */ | |
2632 ibuf = IMB_allocImBuf(sizex, sizey, 32, flag); | |
2633 | |
2634 if (ibuf->rect_float) | |
2635 GPU_offscreen_read_pixels(ofs, GL_FLOAT, ibuf->rect_float); | |
2636 else if (ibuf->rect) | |
2637 GPU_offscreen_read_pixels(ofs, GL_UNSIGNED_BYTE, ibuf->rect); | |
2638 ········ | |
2639 //if ((scene->r.stamp & R_STAMP_ALL) && (scene->r.stamp & R_STAMP_DRAW)) | |
2640 // BKE_stamp_buf(scene, NULL, rr->rectf, rr->rectx, rr->recty, 4); | |
2641 | |
2642 /* unbind */ | |
2643 GPU_offscreen_unbind(ofs); | |
2644 GPU_offscreen_free(ofs); | |
2645 | |
2646 glPopAttrib(); | |
2647 ········ | |
2648 if (ibuf->rect_float && ibuf->rect) | |
2649 IMB_rect_from_float(ibuf); | |
2650 ········ | |
2651 return ibuf; | |
2652 } | |
2653 | |
2654 /* creates own 3d views, used by the sequencer */ | |
2655 ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Scene *scene, Object *camera, int w
idth, int height, | |
2656 unsigned int flag, int drawtype, in
t draw_background, char err_out[256]) | |
2657 { | |
2658 View3D v3d = {NULL}; | |
2659 ARegion ar = {NULL}; | |
2660 RegionView3D rv3d = {{{0}}}; | |
2661 | |
2662 /* connect data */ | |
2663 v3d.regionbase.first = v3d.regionbase.last = &ar; | |
2664 ar.regiondata = &rv3d; | |
2665 ar.regiontype = RGN_TYPE_WINDOW; | |
2666 | |
2667 v3d.camera = camera; | |
2668 v3d.lay = scene->lay; | |
2669 v3d.drawtype = drawtype; | |
2670 v3d.flag2 = V3D_RENDER_OVERRIDE; | |
2671 | |
2672 rv3d.persp = RV3D_CAMOB; | |
2673 | |
2674 copy_m4_m4(rv3d.viewinv, v3d.camera->obmat); | |
2675 normalize_m4(rv3d.viewinv); | |
2676 invert_m4_m4(rv3d.viewmat, rv3d.viewinv); | |
2677 | |
2678 { | |
2679 CameraParams params; | |
2680 | |
2681 BKE_camera_params_init(¶ms); | |
2682 BKE_camera_params_from_object(¶ms, v3d.camera); | |
2683 BKE_camera_params_compute_viewplane(¶ms, width, height, scen
e->r.xasp, scene->r.yasp); | |
2684 BKE_camera_params_compute_matrix(¶ms); | |
2685 | |
2686 copy_m4_m4(rv3d.winmat, params.winmat); | |
2687 v3d.near = params.clipsta; | |
2688 v3d.far = params.clipend; | |
2689 v3d.lens = params.lens; | |
2690 } | |
2691 | |
2692 mult_m4_m4m4(rv3d.persmat, rv3d.winmat, rv3d.viewmat); | |
2693 invert_m4_m4(rv3d.persinv, rv3d.viewinv); | |
2694 | |
2695 return ED_view3d_draw_offscreen_imbuf(scene, &v3d, &ar, width, height, f
lag, draw_background, err_out); | |
2696 | |
2697 // seq_view3d_cb(scene, cfra, render_size, seqrectx, seqrecty); | |
2698 } | |
2699 | |
2700 | |
2701 /* NOTE: the info that this uses is updated in ED_refresh_viewport_fps(),· | |
2702 * which currently gets called during SCREEN_OT_animation_step. | |
2703 */ | |
2704 static void draw_viewport_fps(Scene *scene, ARegion *ar) | |
2705 { | |
2706 ScreenFrameRateInfo *fpsi = scene->fps_info; | |
2707 float fps; | |
2708 char printable[16]; | |
2709 int i, tot; | |
2710 ········ | |
2711 if (!fpsi || !fpsi->lredrawtime || !fpsi->redrawtime) | |
2712 return; | |
2713 ········ | |
2714 printable[0] = '\0'; | |
2715 ········ | |
2716 #if 0 | |
2717 /* this is too simple, better do an average */ | |
2718 fps = (float)(1.0 / (fpsi->lredrawtime - fpsi->redrawtime)) | |
2719 #else | |
2720 fpsi->redrawtimes_fps[fpsi->redrawtime_index] = (float)(1.0 / (fpsi->lre
drawtime - fpsi->redrawtime)); | |
2721 ········ | |
2722 for (i = 0, tot = 0, fps = 0.0f; i < REDRAW_FRAME_AVERAGE; i++) { | |
2723 if (fpsi->redrawtimes_fps[i]) { | |
2724 fps += fpsi->redrawtimes_fps[i]; | |
2725 tot++; | |
2726 } | |
2727 } | |
2728 if (tot) { | |
2729 fpsi->redrawtime_index = (fpsi->redrawtime_index + 1) % REDRAW_F
RAME_AVERAGE; | |
2730 ················ | |
2731 //fpsi->redrawtime_index++; | |
2732 //if (fpsi->redrawtime >= REDRAW_FRAME_AVERAGE) | |
2733 // fpsi->redrawtime = 0; | |
2734 ················ | |
2735 fps = fps / tot; | |
2736 } | |
2737 #endif | |
2738 | |
2739 /* is this more then half a frame behind? */ | |
2740 if (fps + 0.5f < (float)(FPS)) { | |
2741 UI_ThemeColor(TH_REDALERT); | |
2742 BLI_snprintf(printable, sizeof(printable), "fps: %.2f", fps); | |
2743 }· | |
2744 else { | |
2745 UI_ThemeColor(TH_TEXT_HI); | |
2746 BLI_snprintf(printable, sizeof(printable), "fps: %i", (int)(fps
+ 0.5f)); | |
2747 } | |
2748 ········ | |
2749 BLF_draw_default_ascii(22, ar->winy - 17, 0.0f, printable, sizeof(print
able)); | |
2750 } | |
2751 | |
2752 static int view3d_main_area_draw_engine(const bContext *C, ARegion *ar) | |
2753 { | |
2754 Scene *scene = CTX_data_scene(C); | |
2755 View3D *v3d = CTX_wm_view3d(C); | |
2756 RegionView3D *rv3d = CTX_wm_region_view3d(C); | |
2757 RenderEngineType *type; | |
2758 | |
2759 /* create render engine */ | |
2760 if (!rv3d->render_engine) { | |
2761 type = RE_engines_find(scene->r.engine); | |
2762 | |
2763 if (!(type->view_update && type->view_draw)) | |
2764 return 0; | |
2765 | |
2766 rv3d->render_engine = RE_engine_create(type); | |
2767 type->view_update(rv3d->render_engine, C); | |
2768 } | |
2769 | |
2770 /* setup view matrices */ | |
2771 view3d_main_area_setup_view(scene, v3d, ar, NULL, NULL); | |
2772 | |
2773 /* background draw */ | |
2774 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); | |
2775 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
2776 | |
2777 ED_region_pixelspace(ar); | |
2778 | |
2779 /* render result draw */ | |
2780 if (v3d->flag & V3D_DISPBGPICS) | |
2781 draw_bgpic(scene, ar, v3d, FALSE); | |
2782 else | |
2783 fdrawcheckerboard(0, 0, ar->winx, ar->winy); | |
2784 | |
2785 type = rv3d->render_engine->type; | |
2786 type->view_draw(rv3d->render_engine, C); | |
2787 | |
2788 if (v3d->flag & V3D_DISPBGPICS) | |
2789 draw_bgpic(scene, ar, v3d, TRUE); | |
2790 | |
2791 return 1; | |
2792 } | |
2793 | |
2794 static void view3d_main_area_draw_engine_info(RegionView3D *rv3d, ARegion *ar) | |
2795 { | |
2796 if (!rv3d->render_engine || !rv3d->render_engine->text) | |
2797 return; | |
2798 | |
2799 ED_region_info_draw(ar, rv3d->render_engine->text, 1, 0.25); | |
2800 } | |
2801 | |
2802 /* warning: this function has duplicate drawing in ED_view3d_draw_offscreen() */ | |
2803 static void view3d_main_area_draw_objects(const bContext *C, ARegion *ar, const
char **grid_unit) | |
2804 { | |
2805 Scene *scene = CTX_data_scene(C); | |
2806 View3D *v3d = CTX_wm_view3d(C); | |
2807 RegionView3D *rv3d = CTX_wm_region_view3d(C); | |
2808 Base *base; | |
2809 float backcol[3]; | |
2810 unsigned int lay_used; | |
2811 | |
2812 /* shadow buffers, before we setup matrices */ | |
2813 if (draw_glsl_material(scene, NULL, v3d, v3d->drawtype)) | |
2814 gpu_update_lamps_shadows(scene, v3d); | |
2815 ········ | |
2816 /* reset default OpenGL lights if needed (i.e. after preferences have be
en altered) */ | |
2817 if (rv3d->rflag & RV3D_GPULIGHT_UPDATE) { | |
2818 rv3d->rflag &= ~RV3D_GPULIGHT_UPDATE; | |
2819 GPU_default_lights(); | |
2820 } | |
2821 | |
2822 /* clear background */ | |
2823 if ((v3d->flag2 & V3D_RENDER_OVERRIDE) && scene->world) { | |
2824 if (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) | |
2825 linearrgb_to_srgb_v3_v3(backcol, &scene->world->horr); | |
2826 else | |
2827 copy_v3_v3(backcol, &scene->world->horr); | |
2828 glClearColor(backcol[0], backcol[1], backcol[2], 0.0); | |
2829 } | |
2830 else | |
2831 UI_ThemeClearColor(TH_BACK); | |
2832 | |
2833 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
2834 ········ | |
2835 /* setup view matrices */ | |
2836 view3d_main_area_setup_view(scene, v3d, ar, NULL, NULL); | |
2837 | |
2838 ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW); | |
2839 | |
2840 if (rv3d->rflag & RV3D_CLIPPING) | |
2841 view3d_draw_clipping(rv3d); | |
2842 ········ | |
2843 /* set zbuffer after we draw clipping region */ | |
2844 if (v3d->drawtype > OB_WIRE) { | |
2845 v3d->zbuf = TRUE; | |
2846 glEnable(GL_DEPTH_TEST); | |
2847 } | |
2848 else | |
2849 v3d->zbuf = FALSE; | |
2850 | |
2851 /* enables anti-aliasing for 3D view drawing */ | |
2852 #if 0 | |
2853 if (!(U.gameflags & USER_DISABLE_AA)) | |
2854 glEnable(GL_MULTISAMPLE_ARB); | |
2855 #endif | |
2856 | |
2857 // needs to be done always, gridview is adjusted in drawgrid() now | |
2858 rv3d->gridview = v3d->grid; | |
2859 | |
2860 if ((rv3d->view == RV3D_VIEW_USER) || (rv3d->persp != RV3D_ORTHO)) { | |
2861 if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) { | |
2862 drawfloor(scene, v3d, grid_unit); | |
2863 } | |
2864 if (rv3d->persp == RV3D_CAMOB) { | |
2865 if (scene->world) { | |
2866 if (scene->world->mode & WO_STARS) { | |
2867 RE_make_stars(NULL, scene, star_stuff_in
it_func, star_stuff_vertex_func, | |
2868 star_stuff_term_func); | |
2869 } | |
2870 } | |
2871 } | |
2872 } | |
2873 else { | |
2874 if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) { | |
2875 ED_region_pixelspace(ar); | |
2876 drawgrid(&scene->unit, ar, v3d, grid_unit); | |
2877 /* XXX make function? replaces persp(1) */ | |
2878 glMatrixMode(GL_PROJECTION); | |
2879 glLoadMatrixf(rv3d->winmat); | |
2880 glMatrixMode(GL_MODELVIEW); | |
2881 glLoadMatrixf(rv3d->viewmat); | |
2882 } | |
2883 } | |
2884 | |
2885 draw_bgpics(scene, ar, v3d, FALSE); | |
2886 | |
2887 if (rv3d->rflag & RV3D_CLIPPING) | |
2888 ED_view3d_clipping_set(rv3d); | |
2889 | |
2890 /* draw set first */ | |
2891 if (scene->set) { | |
2892 Scene *sce_iter; | |
2893 for (SETLOOPER(scene->set, sce_iter, base)) { | |
2894 ························ | |
2895 if (v3d->lay & base->lay) { | |
2896 ································ | |
2897 UI_ThemeColorBlend(TH_WIRE, TH_BACK, 0.6f); | |
2898 draw_object(scene, ar, v3d, base, DRAW_CONSTCOLO
R | DRAW_SCENESET); | |
2899 ································ | |
2900 if (base->object->transflag & OB_DUPLI) { | |
2901 draw_dupli_objects_color(scene, ar, v3d,
base, TH_WIRE); | |
2902 } | |
2903 } | |
2904 } | |
2905 ················ | |
2906 /* Transp and X-ray afterdraw stuff for sets is done later */ | |
2907 } | |
2908 | |
2909 lay_used = 0; | |
2910 | |
2911 /* then draw not selected and the duplis, but skip editmode object */ | |
2912 for (base = scene->base.first; base; base = base->next) { | |
2913 lay_used |= base->lay & ((1 << 20) - 1); | |
2914 | |
2915 if (v3d->lay & base->lay) { | |
2916 ························ | |
2917 /* dupli drawing */ | |
2918 if (base->object->transflag & OB_DUPLI) { | |
2919 draw_dupli_objects(scene, ar, v3d, base); | |
2920 } | |
2921 if ((base->flag & SELECT) == 0) { | |
2922 if (base->object != scene->obedit) | |
2923 draw_object(scene, ar, v3d, base, 0); | |
2924 } | |
2925 } | |
2926 } | |
2927 | |
2928 if (v3d->lay_used != lay_used) { /* happens when loading old files or lo
ading with UI load */ | |
2929 /* find header and force tag redraw */ | |
2930 ScrArea *sa = CTX_wm_area(C); | |
2931 ARegion *ar_header = BKE_area_find_region_type(sa, RGN_TYPE_HEAD
ER); | |
2932 ED_region_tag_redraw(ar_header); /* can be NULL */ | |
2933 v3d->lay_used = lay_used; | |
2934 } | |
2935 | |
2936 /* draw selected and editmode */ | |
2937 for (base = scene->base.first; base; base = base->next) { | |
2938 if (v3d->lay & base->lay) { | |
2939 if (base->object == scene->obedit || (base->flag & SELEC
T) ) | |
2940 draw_object(scene, ar, v3d, base, 0); | |
2941 } | |
2942 } | |
2943 | |
2944 draw_bgpics(scene, ar, v3d, TRUE); | |
2945 | |
2946 // REEB_draw(); | |
2947 | |
2948 if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) { | |
2949 /* must be before xray draw which clears the depth buffer */ | |
2950 if (v3d->zbuf) glDisable(GL_DEPTH_TEST); | |
2951 draw_gpencil_view3d(scene, v3d, ar, 1); | |
2952 if (v3d->zbuf) glEnable(GL_DEPTH_TEST); | |
2953 } | |
2954 | |
2955 /* Transp and X-ray afterdraw stuff */ | |
2956 if (v3d->afterdraw_transp.first) view3d_draw_transp(scene, ar, v3d); | |
2957 if (v3d->afterdraw_xray.first) view3d_draw_xray(scene, ar, v3d, 1);
// clears zbuffer if it is used! | |
2958 if (v3d->afterdraw_xraytransp.first) view3d_draw_xraytransp(scene, ar, v
3d, 1); | |
2959 ········ | |
2960 ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW); | |
2961 | |
2962 if (rv3d->rflag & RV3D_CLIPPING) | |
2963 ED_view3d_clipping_disable(); | |
2964 ········ | |
2965 BIF_draw_manipulator(C); | |
2966 | |
2967 #if 0 | |
2968 /* Disable back anti-aliasing */ | |
2969 if (!(U.gameflags & USER_DISABLE_AA)) | |
2970 glDisable(GL_MULTISAMPLE_ARB); | |
2971 #endif | |
2972 | |
2973 if (v3d->zbuf) { | |
2974 v3d->zbuf = FALSE; | |
2975 glDisable(GL_DEPTH_TEST); | |
2976 } | |
2977 | |
2978 if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) { | |
2979 BDR_drawSketch(C); | |
2980 } | |
2981 | |
2982 if ((U.ndof_flag & NDOF_SHOW_GUIDE) && (rv3d->viewlock != RV3D_LOCKED) &
& (rv3d->persp != RV3D_CAMOB)) | |
2983 // TODO: draw something else (but not this) during fly mode | |
2984 draw_rotation_guide(rv3d); | |
2985 | |
2986 } | |
2987 | |
2988 static void view3d_main_area_draw_info(const bContext *C, ARegion *ar, const cha
r *grid_unit) | |
2989 { | |
2990 Scene *scene = CTX_data_scene(C); | |
2991 View3D *v3d = CTX_wm_view3d(C); | |
2992 RegionView3D *rv3d = CTX_wm_region_view3d(C); | |
2993 bScreen *screen = CTX_wm_screen(C); | |
2994 | |
2995 Object *ob; | |
2996 | |
2997 if (rv3d->persp == RV3D_CAMOB) | |
2998 drawviewborder(scene, ar, v3d); | |
2999 | |
3000 if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) { | |
3001 /* draw grease-pencil stuff - needed to get paint-buffer shown t
oo (since it's 2D) */ | |
3002 // if (v3d->flag2 & V3D_DISPGP) | |
3003 draw_gpencil_view3d(scene, v3d, ar, 0); | |
3004 | |
3005 drawcursor(scene, ar, v3d); | |
3006 } | |
3007 ········ | |
3008 if (U.uiflag & USER_SHOW_ROTVIEWICON) | |
3009 draw_view_axis(rv3d); | |
3010 else | |
3011 draw_view_icon(rv3d); | |
3012 ········ | |
3013 ob = OBACT; | |
3014 if (U.uiflag & USER_DRAWVIEWINFO) | |
3015 draw_selected_name(scene, ob); | |
3016 | |
3017 if (rv3d->render_engine) { | |
3018 view3d_main_area_draw_engine_info(rv3d, ar); | |
3019 return; | |
3020 } | |
3021 | |
3022 if ((U.uiflag & USER_SHOW_FPS) && screen->animtimer) { | |
3023 draw_viewport_fps(scene, ar); | |
3024 } | |
3025 else if (U.uiflag & USER_SHOW_VIEWPORTNAME) { | |
3026 draw_viewport_name(ar, v3d); | |
3027 } | |
3028 | |
3029 if (grid_unit) { /* draw below the viewport name */ | |
3030 char numstr[32] = ""; | |
3031 | |
3032 UI_ThemeColor(TH_TEXT_HI); | |
3033 if (v3d->grid != 1.0f) { | |
3034 BLI_snprintf(numstr, sizeof(numstr), "%s x %.4g", grid_u
nit, v3d->grid); | |
3035 } | |
3036 | |
3037 BLF_draw_default_ascii(22, ar->winy - (USER_SHOW_VIEWPORTNAME ?
40 : 20), 0.0f, | |
3038 numstr[0] ? numstr : grid_unit, sizeof(nu
mstr)); | |
3039 } | |
3040 } | |
3041 | |
3042 void view3d_main_area_draw(const bContext *C, ARegion *ar) | |
3043 { | |
3044 View3D *v3d = CTX_wm_view3d(C); | |
3045 const char *grid_unit = NULL; | |
3046 | |
3047 /* draw viewport using external renderer? */ | |
3048 if (!(v3d->drawtype == OB_RENDER && view3d_main_area_draw_engine(C, ar))
) { | |
3049 /* draw viewport using opengl */ | |
3050 view3d_main_area_draw_objects(C, ar, &grid_unit); | |
3051 ED_region_pixelspace(ar); | |
3052 } | |
3053 ········ | |
3054 view3d_main_area_draw_info(C, ar, grid_unit); | |
3055 | |
3056 v3d->flag |= V3D_INVALID_BACKBUF; | |
3057 } | |
3058 | |
LEFT | RIGHT |