2.5
authorTon Roosendaal <ton@blender.org>
Mon, 8 Jun 2009 10:00:14 +0000 (10:00 +0000)
committerTon Roosendaal <ton@blender.org>
Mon, 8 Jun 2009 10:00:14 +0000 (10:00 +0000)
Preview renders:

- Added proper button type (BUT_EXTRA) for preview buttons, to
  handle drawing better. It now first draws an alpha mask, to
  ensure the preview is correctly fitting inside the widget style.
  It then draws the outline.
- Added protection for executing preview renders while regular
  rendering, that's not going to work...

source/blender/blenlib/BLI_threads.h
source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_intern.h
source/blender/editors/interface/interface_layout.c
source/blender/editors/interface/interface_templates.c
source/blender/editors/interface/interface_widgets.c
source/blender/editors/preview/previewrender.c
source/blender/render/intern/source/pipeline.c
source/blender/windowmanager/intern/wm_subwindow.c

index 5a7e84c42fb0818c92aea4b9e7497459b59824df..8babb5fe780130a0f56f82ccc9e54c161f05eb55 100644 (file)
@@ -53,6 +53,10 @@ void BLI_unlock_thread       (int type);
 
 int            BLI_system_thread_count( void ); /* gets the number of threads the system can make use of */
 
+               /* exported by preview render, it has to ensure render buffers are not freed while draw */
+void   BLI_lock_malloc_thread(void);
+void   BLI_unlock_malloc_thread(void);
+
 /* ThreadedWorker is a simple tool for dispatching work to a limited number of threads in a transparent
  * fashion from the caller's perspective
  * */
index f7a0fccf12b60e8a272afe6fab315aeaa4b27349..14394b124c3ebc6e597ee8608c31f0bcdf5e8b6a 100644 (file)
@@ -193,6 +193,7 @@ typedef struct uiLayout uiLayout;
 #define OPTION         (38<<9)
 #define OPTIONN                (39<<9)
 #define SEARCH_MENU    (40<<9)
+#define BUT_EXTRA      (41<<9)
 #define BUTTYPE        (63<<9)
 
 /* Drawing
index 072bc5a6febe5f46544399decfda02bcd705838a..bef01b5a45410a5ee18fef7f9deac29ca58bc8ae 100644 (file)
@@ -665,13 +665,7 @@ void uiDrawBlock(const bContext *C, uiBlock *block)
        /* widgets */
        for(but= block->buttons.first; but; but= but->next) {
                ui_but_to_pixelrect(&rect, ar, block, but);
-               ui_draw_but(ar, &style, but, &rect);
-               
-               /* temp? roundbox defines size/location of preview, and ID type */
-               if(but->type==ROUNDBOX)
-                       if(block->drawextra) 
-                               block->drawextra(C, but->poin, &rect);
-               
+               ui_draw_but(C, ar, &style, but, &rect);
        }
        
        /* restore matrix */
index 1cab28abc4eb8e3af3d39c05536c7ed491f5ef46..18423434eef43a5dd6ac0eca8f63db6168acc406 100644 (file)
@@ -403,7 +403,7 @@ void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y
 void ui_draw_menu_back(struct uiStyle *style, uiBlock *block, rcti *rect);
 void ui_draw_search_back(struct uiStyle *style, uiBlock *block, rcti *rect);
 
-extern void ui_draw_but(ARegion *ar, struct uiStyle *style, uiBut *but, rcti *rect);
+extern void ui_draw_but(const struct bContext *C, ARegion *ar, struct uiStyle *style, uiBut *but, rcti *rect);
                /* theme color init */
 struct ThemeUI;
 void ui_widget_color_init(struct ThemeUI *tui);
index df7d81b8806667b25ff317793341608d03849ca5..911d10f74d7c8c6acbb6b9ec52f08b2984ccda69 100644 (file)
@@ -51,8 +51,6 @@
 #include "UI_resources.h"
 #include "UI_view2d.h"
 
-#include "BIF_gl.h"
-
 #include "ED_util.h"
 #include "ED_types.h"
 #include "ED_screen.h"
index 1d44fc90ce9c4da36a5d78c8dd73a64190c7a934..020d442bfe66366f1d2ce9e51adf1dbcc4c20db3 100644 (file)
@@ -1321,8 +1321,8 @@ void uiTemplatePreview(uiLayout *layout, ID *id)
 
        col= uiLayoutColumn(row, 0);
        uiLayoutSetKeepAspect(col, 1);
-       uiDefBut(block, ROUNDBOX, 0, "", 0, 0, UI_UNIT_X*6, UI_UNIT_Y*6, id, 0.0, 0.0, 0, 0, "");
-       /* extra draw is tied to roundbox for now */
+       
+       uiDefBut(block, BUT_EXTRA, 0, "", 0, 0, UI_UNIT_X*6, UI_UNIT_Y*6, id, 0.0, 0.0, 0, 0, "");
        uiBlockSetDrawExtraFunc(block, ED_preview_draw);
        
        uiBlockSetHandleFunc(block, do_preview_buttons, NULL);
index e3f850ddfd4a0b520baac1d5ba1a856cd2520a0b..cb4d30213caf1680a1ba7551aa96af66409a6bb2 100644 (file)
@@ -545,12 +545,20 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol)
        /* backdrop non AA */
        if(wtb->inner) {
                if(wcol->shaded==0) {
+                       
+                       /* this is to enable drawing zero alpha masks */
+                       if(wcol->inner[3]==0)
+                               glDisable(GL_BLEND);
+                       
                        /* filled center, solid */
                        glColor4ubv(wcol->inner);
                        glBegin(GL_POLYGON);
                        for(a=0; a<wtb->totvert; a++)
                                glVertex2fv(wtb->inner_v[a]);
                        glEnd();
+
+                       if(wcol->inner[3]==0)
+                               glEnable(GL_BLEND);
                }
                else {
                        char col1[4], col2[4];
@@ -1596,6 +1604,46 @@ static void widget_roundbut(uiWidgetColors *wcol, rcti *rect, int state, int rou
        widgetbase_draw(&wtb, wcol);
 }
 
+static void widget_draw_extra_mask(const bContext *C, uiBut *but, uiWidgetType *wt, rcti *rect)
+{
+       uiWidgetBase wtb;
+       uiWidgetColors *wcol= &wt->wcol;
+       char col[4];
+       
+       /* state copy! */
+       wt->wcol= *(wt->wcol_theme);
+       
+       widget_init(&wtb);
+       
+       /* filled rect in back color, alpha 1 */
+       UI_GetThemeColor4ubv(TH_BACK, col);
+       col[3]= 255;
+       glColor4ubv(col);
+       glRecti(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
+       
+       /* inner mask with alpha zero */
+       wcol->inner[0]= wcol->inner[1]= wcol->inner[2]= wcol->inner[3]= 0;
+       wtb.outline= 0;
+       round_box_edges(&wtb, 15, rect, 5.0f);
+       widgetbase_draw(&wtb, wcol);
+       
+       if(but->block->drawextra) {
+               glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);
+               glEnable(GL_BLEND);
+               
+               but->block->drawextra(C, but->poin, rect);
+               
+               glDisable(GL_BLEND);
+               glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+       }
+       /* outline */
+       wtb.outline= 1;
+       wtb.inner= 0;
+       widgetbase_draw(&wtb, wcol);
+       
+}
+
+
 static void widget_disabled(rcti *rect)
 {
        float col[4];
@@ -1774,7 +1822,7 @@ static int widget_roundbox_set(uiBut *but, rcti *rect)
 }
 
 /* conversion from old to new buttons, so still messy */
-void ui_draw_but(ARegion *ar, uiStyle *style, uiBut *but, rcti *rect)
+void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rcti *rect)
 {
        bTheme *btheme= U.themes.first;
        ThemeUI *tui= &btheme->tui;
@@ -1864,6 +1912,10 @@ void ui_draw_but(ARegion *ar, uiStyle *style, uiBut *but, rcti *rect)
                        case ROUNDBOX:
                                wt= widget_type(UI_WTYPE_BOX);
                                break;
+                       
+                       case BUT_EXTRA:
+                               widget_draw_extra_mask(C, but, widget_type(UI_WTYPE_BOX), rect);
+                               break;
                                
                                 // XXX four old button types
                        case HSVCUBE:
index 096282a0f58d4111ef01afa3baa25672025f6cfa..56ec22a44b0515302214f33c1426ac8f8663f150 100644 (file)
@@ -640,14 +640,8 @@ void ED_preview_draw(const bContext *C, void *idp, rcti *rect)
 
        if(rres.rectf) {
                if(rres.rectx==newx && rres.recty==newy) {
-                       glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
-                       glEnable(GL_BLEND);
-                       
                        glaDrawPixelsSafe(rect->xmin, rect->ymin, rres.rectx, rres.recty, rres.rectx, GL_RGBA, GL_FLOAT, rres.rectf);
                        ok= 1;
-                       
-                       glDisable(GL_BLEND);
-                       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                }
        }
        BLI_unlock_malloc_thread();
@@ -1083,8 +1077,15 @@ static void shader_preview_free(void *customdata)
 
 void ED_preview_shader_job(const bContext *C, void *owner, ID *id, int sizex, int sizey)
 {
-       wmJob *steve= WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), owner);
-       ShaderPreview *sp= MEM_callocN(sizeof(ShaderPreview), "shader preview");
+       wmJob *steve;
+       ShaderPreview *sp;
+
+       /* XXX ugly global still, but we can't do preview while rendering */
+       if(G.rendering)
+               return;
+
+       steve= WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), owner);
+       sp= MEM_callocN(sizeof(ShaderPreview), "shader preview");
 
        /* customdata for preview thread */
        sp->scene= CTX_data_scene(C);
index 1de41d086de5c4280684e47075ece088b8e83916..e464cbd1f430eec638ba0173a296633047f0a1a3 100644 (file)
@@ -2432,7 +2432,7 @@ static int render_initialize_from_scene(Render *re, Scene *scene, int anim)
 /* general Blender frame render call */
 void RE_BlenderFrame(Render *re, Scene *scene, int frame)
 {
-       /* ugly global still... is to prevent renderwin events and signal subsurfs etc to make full resol */
+       /* ugly global still... is to prevent preview events and signal subsurfs etc to make full resol */
        G.rendering= 1;
        re->result_ok= 0;
        
index 67ba31b84c0ebe715057f28a3544fd33b7ce3164..9bd55e1c5a77887c5f2ea5b41b3395905ccb2dff 100644 (file)
@@ -307,10 +307,16 @@ void wmMultMatrix(float mat[][4])
                glGetFloatv(GL_MODELVIEW_MATRIX, (float *)_curswin->winmat);
 }
 
+static int debugpush= 0;
+
 void wmPushMatrix(void)
 {
        if(_curswin==NULL) return;
        
+       if(debugpush)
+               printf("wmPushMatrix error already pushed\n");
+       debugpush= 1;
+       
        Mat4CpyMat4(_curswin->viewmat1, _curswin->viewmat);
        Mat4CpyMat4(_curswin->winmat1, _curswin->winmat);
 }
@@ -319,6 +325,10 @@ void wmPopMatrix(void)
 {
        if(_curswin==NULL) return;
        
+       if(debugpush==0)
+               printf("wmPopMatrix error nothing popped\n");
+       debugpush= 0;
+       
        Mat4CpyMat4(_curswin->viewmat, _curswin->viewmat1);
        Mat4CpyMat4(_curswin->winmat, _curswin->winmat1);