doxygen: blender/editors tagged.
[blender.git] / source / blender / editors / space_image / image_render.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * Contributor(s): Blender Foundation, 2002-2009
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file blender/editors/space_image/image_render.c
29  *  \ingroup spimage
30  */
31
32
33 #include <stdlib.h>
34 #include <stdio.h>
35
36 #include "BLI_utildefines.h"
37
38 #include "DNA_screen_types.h"
39 #include "DNA_space_types.h"
40
41 #include "BKE_context.h"
42 #include "BKE_image.h"
43
44 #include "BIF_gl.h"
45 #include "BIF_glutil.h"
46
47
48 #include "RE_pipeline.h"
49
50
51 #define HEADER_HEIGHT 18
52
53 /* *********************** render callbacks ***************** */
54
55 /* set on initialize render, only one render output to imagewindow can exist, so the global isnt dangerous yet :) */
56 static ScrArea *image_area= NULL;
57
58 /* can get as well the full picture, as the parts while rendering */
59 /* XXX will be obsolete, here for reference now */
60 static void imagewindow_progress(SpaceImage *sima, RenderResult *rr, volatile rcti *renrect)
61 {
62         float x1, y1, *rectf= NULL;
63         unsigned int *rect32= NULL;
64         int ymin, ymax, xmin, xmax;
65         
66         /* if renrect argument, we only display scanlines */
67         if(renrect) {
68                 /* if ymax==recty, rendering of layer is ready, we should not draw, other things happen... */
69                 if(rr->renlay==NULL || renrect->ymax>=rr->recty)
70                         return;
71                 
72                 /* xmin here is first subrect x coord, xmax defines subrect width */
73                 xmin = renrect->xmin;
74                 xmax = renrect->xmax - xmin;
75                 if (xmax<2) return;
76                 
77                 ymin= renrect->ymin;
78                 ymax= renrect->ymax - ymin;
79                 if(ymax<2)
80                         return;
81                 renrect->ymin= renrect->ymax;
82         }
83         else {
84                 xmin = ymin = 0;
85                 xmax = rr->rectx - 2*rr->crop;
86                 ymax = rr->recty - 2*rr->crop;
87         }
88         
89         /* image window cruft */
90         
91         /* find current float rect for display, first case is after composit... still weak */
92         if(rr->rectf)
93                 rectf= rr->rectf;
94         else {
95                 if(rr->rect32)
96                         rect32= (unsigned int *)rr->rect32;
97                 else {
98                         if(rr->renlay==NULL || rr->renlay->rectf==NULL) return;
99                         rectf= rr->renlay->rectf;
100                 }
101         }
102         if(rectf) {
103                 /* if scanline updates... */
104                 rectf+= 4*(rr->rectx*ymin + xmin);
105                 
106                 /* when rendering more pixels than needed, we crop away cruft */
107                 if(rr->crop)
108                         rectf+= 4*(rr->crop*rr->rectx + rr->crop);
109         }
110         
111         /* tilerect defines drawing offset from (0,0) */
112         /* however, tilerect (xmin, ymin) is first pixel */
113         x1 = sima->centx + (rr->tilerect.xmin + rr->crop + xmin)*sima->zoom;
114         y1 = sima->centy + (rr->tilerect.ymin + rr->crop + ymin)*sima->zoom;
115         
116         /* needed for gla draw */
117         // XXX { rcti rct= ar->winrct; rct.ymax-= HEADER_HEIGHT; glaDefine2DArea(&rct);}
118
119         glPixelZoom(sima->zoom, sima->zoom);
120         
121         if(rect32)
122                 glaDrawPixelsSafe(x1, y1, xmax, ymax, rr->rectx, GL_RGBA, GL_UNSIGNED_BYTE, rect32);
123         else
124                 glaDrawPixelsSafe_to32(x1, y1, xmax, ymax, rr->rectx, rectf, 0);
125         
126         glPixelZoom(1.0, 1.0);
127         
128 }
129
130
131 /* coming from BIF_toggle_render_display() */
132 static void imagewindow_toggle_render(bContext *C)
133 {
134         bScreen *sc= CTX_wm_screen(C);
135         ScrArea *sa;
136         
137         /* check if any imagewindow is showing temporal render output */
138         for(sa=sc->areabase.first; sa; sa= sa->next) {
139                 if(sa->spacetype==SPACE_IMAGE) {
140                         SpaceImage *sima= sa->spacedata.first;
141                         
142                         if(sima->image && sima->image->type==IMA_TYPE_R_RESULT)
143                                 if(sima->flag & (SI_PREVSPACE|SI_FULLWINDOW))
144                                         break;
145                 }
146         }
147
148         if(sa) {
149                 // XXX addqueue(sa->win, ESCKEY, 1);    /* also returns from fullscreen */
150         }
151         else {
152 //              sa= imagewindow_set_render_display(C);
153                 // XXX scrarea_queue_headredraw(sa);
154                 // XXX scrarea_queue_winredraw(sa);
155         }
156 }
157
158 /* NOTE: called while render, so no malloc allowed! */
159 static void imagewindow_renderinfo_cb(void *UNUSED(handle), RenderStats *UNUSED(rs))
160 {
161         if(image_area) {
162                 // XXX BIF_make_render_text(rs);
163
164                 // XXX sima_draw_render_info(sima, ar);
165                 
166                 /* no screen_swapbuffers, prevent any other window to draw */
167                 // XXX myswapbuffers();
168         }
169 }
170
171 static void ED_space_image_render_callbacks(bContext *C, Render *re)
172 {
173         
174 //      RE_display_init_cb(re, C, imagewindow_init_display_cb);
175 //      RE_display_draw_cb(re, C, imagewindow_progress_display_cb);
176 //      RE_display_clear_cb(re, C, imagewindow_clear_display_cb);
177         RE_stats_draw_cb(re, C, imagewindow_renderinfo_cb);     
178 }
179