Fix #27981: opengl render + render slots not working.
[blender.git] / source / blender / editors / render / render_opengl.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2008 Blender Foundation.
19  * All rights reserved.
20  *
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 /** \file blender/editors/render/render_opengl.c
26  *  \ingroup edrend
27  */
28
29
30 #include <math.h>
31 #include <string.h>
32 #include <stddef.h>
33
34 #include <GL/glew.h>
35
36 #include "MEM_guardedalloc.h"
37
38 #include "BLI_math.h"
39 #include "BLI_blenlib.h"
40 #include "BLI_editVert.h"
41 #include "BLI_dlrbTree.h"
42 #include "BLI_utildefines.h"
43
44 #include "DNA_scene_types.h"
45 #include "DNA_object_types.h"
46
47 #include "BKE_context.h"
48 #include "BKE_image.h"
49 #include "BKE_main.h"
50 #include "BKE_report.h"
51 #include "BKE_scene.h"
52 #include "BKE_writeavi.h"
53
54 #include "WM_api.h"
55 #include "WM_types.h"
56
57 #include "ED_screen.h"
58 #include "ED_view3d.h"
59 #include "ED_image.h"
60
61 #include "RE_pipeline.h"
62 #include "IMB_imbuf_types.h"
63 #include "IMB_imbuf.h"
64
65 #include "RNA_access.h"
66 #include "RNA_define.h"
67
68
69 #include "GPU_extensions.h"
70
71 #include "wm_window.h"
72
73 #include "render_intern.h"
74
75 typedef struct OGLRender {
76         Main *bmain;
77         Render *re;
78         Scene *scene;
79
80         View3D *v3d;
81         RegionView3D *rv3d;
82         ARegion *ar;
83
84         Image *ima;
85         ImageUser iuser;
86
87         GPUOffScreen *ofs;
88         int sizex, sizey;
89         int write_still;
90
91         ReportList *reports;
92         bMovieHandle *mh;
93         int cfrao, nfra;
94
95         wmTimer *timer; /* use to check if running modal or not (invoke'd or exec'd)*/
96 } OGLRender;
97
98 /* added because v3d is not always valid */
99 static unsigned int screen_opengl_layers(OGLRender *oglrender)
100 {
101         if(oglrender->v3d) {
102                 return oglrender->scene->lay | oglrender->v3d->lay;
103         }
104         else {
105                 return oglrender->scene->lay;
106         }
107 }
108
109 static void screen_opengl_render_apply(OGLRender *oglrender)
110 {
111         Scene *scene= oglrender->scene;
112         ARegion *ar= oglrender->ar;
113         View3D *v3d= oglrender->v3d;
114         RegionView3D *rv3d= oglrender->rv3d;
115         RenderResult *rr;
116         Object *camera= NULL;
117         ImBuf *ibuf;
118         void *lock;
119         float winmat[4][4];
120         int sizex= oglrender->sizex;
121         int sizey= oglrender->sizey;
122         const short view_context= (v3d != NULL);
123
124         rr= RE_AcquireResultRead(oglrender->re);
125         
126         if(view_context) {
127                 GPU_offscreen_bind(oglrender->ofs); /* bind */
128
129                 /* render 3d view */
130                 if(rv3d->persp==RV3D_CAMOB && v3d->camera) {
131                         /*int is_ortho= scene->r.mode & R_ORTHO;*/
132                         camera= v3d->camera;
133                         RE_GetCameraWindow(oglrender->re, camera, scene->r.cfra, winmat);
134                         
135                 }
136                 else {
137                         rctf viewplane;
138                         float clipsta, clipend;
139
140                         int is_ortho= ED_view3d_viewplane_get(v3d, rv3d, sizex, sizey, &viewplane, &clipsta, &clipend);
141                         if(is_ortho) orthographic_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, -clipend, clipend);
142                         else  perspective_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
143                 }
144
145                 if((scene->r.mode & R_OSA) == 0) { 
146                         ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat);
147                         GPU_offscreen_read_pixels(oglrender->ofs, GL_FLOAT, rr->rectf);
148                 }
149                 else {
150                         /* simple accumulation, less hassle then FSAA FBO's */
151 #                       define SAMPLES 5 /* fixed, easy to have more but for now this is ok */
152                         const float jit_ofs[SAMPLES][2] = {{0, 0}, {0.5f, 0.5f}, {-0.5f,-0.5f}, {-0.5f, 0.5f}, {0.5f, -0.5f}};
153                         float winmat_jitter[4][4];
154                         float *accum_buffer= MEM_mallocN(sizex * sizey * sizeof(float) * 4, "accum1");
155                         float *accum_tmp= MEM_mallocN(sizex * sizey * sizeof(float) * 4, "accum2");
156                         int j;
157
158                         /* first sample buffer, also initializes 'rv3d->persmat' */
159                         ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat);
160                         GPU_offscreen_read_pixels(oglrender->ofs, GL_FLOAT, accum_buffer);
161
162                         /* skip the first sample */
163                         for(j=1; j < SAMPLES; j++) {
164                                 copy_m4_m4(winmat_jitter, winmat);
165                                 window_translate_m4(winmat_jitter, rv3d->persmat, jit_ofs[j][0] / sizex, jit_ofs[j][1] / sizey);
166
167                                 ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat_jitter);
168                                 GPU_offscreen_read_pixels(oglrender->ofs, GL_FLOAT, accum_tmp);
169                                 add_vn_vn(accum_buffer, accum_tmp, sizex*sizey*sizeof(float));
170                         }
171
172                         mul_vn_vn_fl(rr->rectf, accum_buffer, sizex*sizey*sizeof(float), 1.0/SAMPLES);
173
174                         MEM_freeN(accum_buffer);
175                         MEM_freeN(accum_tmp);
176                 }
177
178                 GPU_offscreen_unbind(oglrender->ofs); /* unbind */
179         }
180         else {
181                 /* shouldnt suddenly give errors mid-render but possible */
182                 char err_out[256]= "unknown";
183                 ImBuf *ibuf_view= ED_view3d_draw_offscreen_imbuf_simple(scene, scene->camera, oglrender->sizex, oglrender->sizey, IB_rectfloat, OB_SOLID, err_out);
184                 camera= scene->camera;
185
186                 if(ibuf_view) {
187                         memcpy(rr->rectf, ibuf_view->rect_float, sizeof(float) * 4 * oglrender->sizex * oglrender->sizey);
188                         IMB_freeImBuf(ibuf_view);
189                 }
190                 else {
191                         fprintf(stderr, "screen_opengl_render_apply: failed to get buffer, %s\n", err_out);
192                 }
193         }
194         
195         /* rr->rectf is now filled with image data */
196
197         if((scene->r.stamp & R_STAMP_ALL) && (scene->r.stamp & R_STAMP_DRAW))
198                 BKE_stamp_buf(scene, camera, NULL, rr->rectf, rr->rectx, rr->recty, 4);
199
200         /* note on color management:
201          *
202          * OpenGL renders into sRGB colors, but render buffers are expected to be
203          * linear if color management is enabled. So we convert to linear here, so
204          * the conversion back to bytes using the color management flag can make it
205          * sRGB again, and so that e.g. openexr saving also saves the correct linear
206          * float buffer. */
207
208         if(oglrender->scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) {
209                 float *rctf = rr->rectf;
210                 int i;
211
212                 for (i = oglrender->sizex * oglrender->sizey; i > 0; i--, rctf+=4) {
213                         rctf[0]= srgb_to_linearrgb(rctf[0]);
214                         rctf[1]= srgb_to_linearrgb(rctf[1]);
215                         rctf[2]= srgb_to_linearrgb(rctf[2]);
216                 }
217         }
218
219         RE_ReleaseResult(oglrender->re);
220
221         /* update byte from float buffer */
222         ibuf= BKE_image_acquire_ibuf(oglrender->ima, &oglrender->iuser, &lock);
223
224         if(ibuf) {
225                 image_buffer_rect_update(scene, rr, ibuf, NULL);
226
227                 if(oglrender->write_still) {
228                         char name[FILE_MAX];
229                         int ok;
230
231                         if(scene->r.im_format.planes == R_IMF_CHAN_DEPTH_8) {
232                                 IMB_color_to_bw(ibuf);
233                         }
234
235                         BKE_makepicstring(name, scene->r.pic, oglrender->bmain->name, scene->r.cfra, scene->r.im_format.imtype, scene->r.scemode & R_EXTENSION, FALSE);
236                         ok= BKE_write_ibuf(ibuf, name, &scene->r.im_format); /* no need to stamp here */
237                         if(ok)  printf("OpenGL Render written to '%s'\n", name);
238                         else    printf("OpenGL Render failed to write '%s'\n", name);
239                 }
240         }
241         
242         BKE_image_release_ibuf(oglrender->ima, lock);
243 }
244
245 static int screen_opengl_render_init(bContext *C, wmOperator *op)
246 {
247         /* new render clears all callbacks */
248         Scene *scene= CTX_data_scene(C);
249         RenderResult *rr;
250         GPUOffScreen *ofs;
251         OGLRender *oglrender;
252         int sizex, sizey;
253         short is_view_context= RNA_boolean_get(op->ptr, "view_context");
254         const short is_animation= RNA_boolean_get(op->ptr, "animation");
255         const short is_write_still= RNA_boolean_get(op->ptr, "write_still");
256         char err_out[256]= "unknown";
257
258         /* ensure we have a 3d view */
259
260         if(!ED_view3d_context_activate(C)) {
261                 RNA_boolean_set(op->ptr, "view_context", 0);
262                 is_view_context= 0;
263         }
264
265         /* only one render job at a time */
266         if(WM_jobs_test(CTX_wm_manager(C), scene))
267                 return 0;
268         
269         if(!is_view_context && scene->camera==NULL) {
270                 BKE_report(op->reports, RPT_ERROR, "Scene has no camera");
271                 return 0;
272         }
273
274         if(!is_animation && is_write_still && BKE_imtype_is_movie(scene->r.im_format.imtype)) {
275                 BKE_report(op->reports, RPT_ERROR, "Can't write a single file with an animation format selected");
276                 return 0;
277         }
278
279         /* stop all running jobs, currently previews frustrate Render */
280         WM_jobs_stop_all(CTX_wm_manager(C));
281
282         /* handle UI stuff */
283         WM_cursor_wait(1);
284
285         /* create offscreen buffer */
286         sizex= (scene->r.size*scene->r.xsch)/100;
287         sizey= (scene->r.size*scene->r.ysch)/100;
288
289         /* corrects render size with actual size, not every card supports non-power-of-two dimensions */
290         ofs= GPU_offscreen_create(sizex, sizey, err_out);
291
292         if(!ofs) {
293                 BKE_reportf(op->reports, RPT_ERROR, "Failed to create OpenGL offscreen buffer, %s", err_out);
294                 return 0;
295         }
296
297         /* allocate opengl render */
298         oglrender= MEM_callocN(sizeof(OGLRender), "OGLRender");
299         op->customdata= oglrender;
300
301         oglrender->ofs= ofs;
302         oglrender->sizex= sizex;
303         oglrender->sizey= sizey;
304         oglrender->bmain= CTX_data_main(C);
305         oglrender->scene= scene;
306
307         oglrender->write_still= is_write_still && !is_animation;
308
309         if(is_view_context) {
310                 oglrender->v3d= CTX_wm_view3d(C);
311                 oglrender->ar= CTX_wm_region(C);
312                 oglrender->rv3d= CTX_wm_region_view3d(C);
313
314                 /* MUST be cleared on exit */
315                 oglrender->scene->customdata_mask_modal= ED_view3d_datamask(oglrender->scene, oglrender->v3d);
316         }
317
318         /* create render */
319         oglrender->re= RE_NewRender(scene->id.name);
320
321         /* create image and image user */
322         oglrender->ima= BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result");
323         BKE_image_signal(oglrender->ima, NULL, IMA_SIGNAL_FREE);
324         BKE_image_backup_render(oglrender->scene, oglrender->ima);
325
326         oglrender->iuser.scene= scene;
327         oglrender->iuser.ok= 1;
328
329         /* create render result */
330         RE_InitState(oglrender->re, NULL, &scene->r, NULL, sizex, sizey, NULL);
331
332         rr= RE_AcquireResultWrite(oglrender->re);
333         if(rr->rectf==NULL)
334                 rr->rectf= MEM_callocN(sizeof(float)*4*sizex*sizey, "screen_opengl_render_init rect");
335         RE_ReleaseResult(oglrender->re);
336
337         return 1;
338 }
339
340 static void screen_opengl_render_end(bContext *C, OGLRender *oglrender)
341 {
342         Main *bmain= CTX_data_main(C);
343         Scene *scene= oglrender->scene;
344
345         if(oglrender->mh) {
346                 if(BKE_imtype_is_movie(scene->r.im_format.imtype))
347                         oglrender->mh->end_movie();
348         }
349
350         if(oglrender->timer) { /* exec will not have a timer */
351                 scene->r.cfra= oglrender->cfrao;
352                 scene_update_for_newframe(bmain, scene, screen_opengl_layers(oglrender));
353
354                 WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), oglrender->timer);
355         }
356
357         WM_cursor_wait(0);
358         WM_event_add_notifier(C, NC_SCENE|ND_RENDER_RESULT, oglrender->scene);
359
360         GPU_offscreen_free(oglrender->ofs);
361
362         oglrender->scene->customdata_mask_modal= 0;
363
364         MEM_freeN(oglrender);
365 }
366
367 static int screen_opengl_render_cancel(bContext *C, wmOperator *op)
368 {
369         screen_opengl_render_end(C, op->customdata);
370
371         return OPERATOR_CANCELLED;
372 }
373
374 /* share between invoke and exec */
375 static int screen_opengl_render_anim_initialize(bContext *C, wmOperator *op)
376 {
377         /* initialize animation */
378         OGLRender *oglrender;
379         Scene *scene;
380
381         oglrender= op->customdata;
382         scene= oglrender->scene;
383
384         oglrender->reports= op->reports;
385         oglrender->mh= BKE_get_movie_handle(scene->r.im_format.imtype);
386         if(BKE_imtype_is_movie(scene->r.im_format.imtype)) {
387                 if(!oglrender->mh->start_movie(scene, &scene->r, oglrender->sizex, oglrender->sizey, oglrender->reports)) {
388                         screen_opengl_render_end(C, oglrender);
389                         return 0;
390                 }
391         }
392
393         oglrender->cfrao= scene->r.cfra;
394         oglrender->nfra= PSFRA;
395         scene->r.cfra= PSFRA;
396
397         return 1;
398 }
399 static int screen_opengl_render_anim_step(bContext *C, wmOperator *op)
400 {
401         Main *bmain= CTX_data_main(C);
402         OGLRender *oglrender= op->customdata;
403         Scene *scene= oglrender->scene;
404         ImBuf *ibuf;
405         void *lock;
406         char name[FILE_MAX];
407         int ok= 0;
408         const short  view_context= (oglrender->v3d != NULL);
409         Object *camera= NULL;
410
411         /* update animated image textures for gpu, etc,
412          * call before scene_update_for_newframe so modifiers with textuers dont lag 1 frame */
413         ED_image_update_frame(bmain, scene->r.cfra);
414
415         /* go to next frame */
416         while(CFRA<oglrender->nfra) {
417                 unsigned int lay= screen_opengl_layers(oglrender);
418
419                 if(lay & 0xFF000000)
420                         lay &= 0xFF000000;
421
422                 scene_update_for_newframe(bmain, scene, lay);
423                 CFRA++;
424         }
425
426         scene_update_for_newframe(bmain, scene, screen_opengl_layers(oglrender));
427
428         if(view_context) {
429                 if(oglrender->rv3d->persp==RV3D_CAMOB && oglrender->v3d->camera && oglrender->v3d->scenelock) {
430                         /* since scene_update_for_newframe() is used rather
431                          * then ED_update_for_newframe() the camera needs to be set */
432                         if(scene_camera_switch_update(scene)) {
433                                 oglrender->v3d->camera= scene->camera;
434                         }
435
436                         camera= oglrender->v3d->camera;
437                 }
438         }
439         else {
440                 scene_camera_switch_update(scene);
441
442                 camera= scene->camera;
443         }
444
445         /* render into offscreen buffer */
446         screen_opengl_render_apply(oglrender);
447
448         /* save to disk */
449         ibuf= BKE_image_acquire_ibuf(oglrender->ima, &oglrender->iuser, &lock);
450
451         if(ibuf) {
452                 /* color -> greyscale */
453                 /* editing directly would alter the render view */
454                 if(scene->r.im_format.planes == R_IMF_PLANES_BW) {
455                         ImBuf *ibuf_bw= IMB_dupImBuf(ibuf);
456                         IMB_color_to_bw(ibuf_bw);
457                         // IMB_freeImBuf(ibuf); /* owned by the image */
458                         ibuf= ibuf_bw;
459                 }
460                 else {
461                         /* this is lightweight & doesnt re-alloc the buffers, only do this
462                          * to save the correct bit depth since the image is always RGBA */
463                         ImBuf *ibuf_cpy= IMB_allocImBuf(ibuf->x, ibuf->y, scene->r.im_format.planes, 0);
464                         ibuf_cpy->rect= ibuf->rect;
465                         ibuf_cpy->rect_float= ibuf->rect_float;
466                         ibuf_cpy->zbuf_float= ibuf->zbuf_float;
467                         ibuf= ibuf_cpy;
468                 }
469
470                 if(BKE_imtype_is_movie(scene->r.im_format.imtype)) {
471                         ok= oglrender->mh->append_movie(&scene->r, CFRA, (int*)ibuf->rect, oglrender->sizex, oglrender->sizey, oglrender->reports);
472                         if(ok) {
473                                 printf("Append frame %d", scene->r.cfra);
474                                 BKE_reportf(op->reports, RPT_INFO, "Appended frame: %d", scene->r.cfra);
475                         }
476                 }
477                 else {
478                         BKE_makepicstring(name, scene->r.pic, oglrender->bmain->name, scene->r.cfra, scene->r.im_format.imtype, scene->r.scemode & R_EXTENSION, TRUE);
479                         ok= BKE_write_ibuf_stamp(scene, camera, ibuf, name, &scene->r.im_format);
480
481                         if(ok==0) {
482                                 printf("Write error: cannot save %s\n", name);
483                                 BKE_reportf(op->reports, RPT_ERROR, "Write error: cannot save %s", name);
484                         }
485                         else {
486                                 printf("Saved: %s", name);
487                                 BKE_reportf(op->reports, RPT_INFO, "Saved file: %s", name);
488                         }
489                 }
490
491                 /* imbuf knows which rects are not part of ibuf */
492                 IMB_freeImBuf(ibuf);
493         }
494
495         BKE_image_release_ibuf(oglrender->ima, lock);
496
497         /* movie stats prints have no line break */
498         printf("\n");
499
500         /* go to next frame */
501         oglrender->nfra += scene->r.frame_step;
502         scene->r.cfra++;
503
504         /* stop at the end or on error */
505         if(scene->r.cfra > PEFRA || !ok) {
506                 screen_opengl_render_end(C, op->customdata);
507                 return 0;
508         }
509
510         return 1;
511 }
512
513
514 static int screen_opengl_render_modal(bContext *C, wmOperator *op, wmEvent *event)
515 {
516         OGLRender *oglrender= op->customdata;
517         int anim= RNA_boolean_get(op->ptr, "animation");
518         int ret;
519
520         switch(event->type) {
521                 case ESCKEY:
522                         /* cancel */
523                         screen_opengl_render_end(C, op->customdata);
524                         return OPERATOR_FINISHED;
525                 case TIMER:
526                         /* render frame? */
527                         if(oglrender->timer == event->customdata)
528                                 break;
529                 default:
530                         /* nothing to do */
531                         return OPERATOR_RUNNING_MODAL;
532         }
533
534         /* run first because screen_opengl_render_anim_step can free oglrender */
535         WM_event_add_notifier(C, NC_SCENE|ND_RENDER_RESULT, oglrender->scene);
536         
537         if(anim == 0) {
538                 screen_opengl_render_apply(op->customdata);
539                 screen_opengl_render_end(C, op->customdata);
540                 return OPERATOR_FINISHED;
541         }
542         else
543                 ret= screen_opengl_render_anim_step(C, op);
544
545         /* stop at the end or on error */
546         if(ret == 0) {
547                 return OPERATOR_FINISHED;
548         }
549
550         return OPERATOR_RUNNING_MODAL;
551 }
552
553 static int screen_opengl_render_invoke(bContext *C, wmOperator *op, wmEvent *event)
554 {
555         OGLRender *oglrender;
556         int anim= RNA_boolean_get(op->ptr, "animation");
557
558         if(!screen_opengl_render_init(C, op))
559                 return OPERATOR_CANCELLED;
560
561         if(anim) {
562                 if(!screen_opengl_render_anim_initialize(C, op))
563                         return OPERATOR_CANCELLED;
564         }
565         
566         oglrender= op->customdata;
567         render_view_open(C, event->x, event->y);
568         
569         WM_event_add_modal_handler(C, op);
570         oglrender->timer= WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f);
571         
572         return OPERATOR_RUNNING_MODAL;
573 }
574
575 /* executes blocking render */
576 static int screen_opengl_render_exec(bContext *C, wmOperator *op)
577 {
578         const short is_animation= RNA_boolean_get(op->ptr, "animation");
579
580         if(!screen_opengl_render_init(C, op))
581                 return OPERATOR_CANCELLED;
582
583         if(!is_animation) { /* same as invoke */
584                 /* render image */
585                 screen_opengl_render_apply(op->customdata);
586                 screen_opengl_render_end(C, op->customdata);
587
588                 return OPERATOR_FINISHED;
589         }
590         else {
591                 int ret= 1;
592
593                 if(!screen_opengl_render_anim_initialize(C, op))
594                         return OPERATOR_CANCELLED;
595
596                 while(ret) {
597                         ret= screen_opengl_render_anim_step(C, op);
598                 }
599         }
600
601         // no redraw needed, we leave state as we entered it
602 //      ED_update_for_newframe(C, 1);
603         WM_event_add_notifier(C, NC_SCENE|ND_RENDER_RESULT, CTX_data_scene(C));
604
605         return OPERATOR_FINISHED;
606 }
607
608 void RENDER_OT_opengl(wmOperatorType *ot)
609 {
610         /* identifiers */
611         ot->name= "OpenGL Render";
612         ot->description= "OpenGL render active viewport";
613         ot->idname= "RENDER_OT_opengl";
614
615         /* api callbacks */
616         ot->invoke= screen_opengl_render_invoke;
617         ot->exec= screen_opengl_render_exec; /* blocking */
618         ot->modal= screen_opengl_render_modal;
619         ot->cancel= screen_opengl_render_cancel;
620
621         ot->poll= ED_operator_screenactive;
622
623         RNA_def_boolean(ot->srna, "animation", 0, "Animation", "Render files from the animation range of this scene");
624         RNA_def_boolean(ot->srna, "write_still", 0, "Write Image", "Save rendered the image to the output path (used only when animation is disabled)");
625         RNA_def_boolean(ot->srna, "view_context", 1, "View Context", "Use the current 3D view for rendering, else use scene settings");
626 }
627
628 /* function for getting an opengl buffer from a View3D, used by sequencer */
629 // extern void *sequencer_view3d_cb;