More texnode preview fixes. Previews now have correct aspect ratio and are drawn...
authorRobin Allen <roblovski@gmail.com>
Wed, 19 Aug 2009 15:45:16 +0000 (15:45 +0000)
committerRobin Allen <roblovski@gmail.com>
Wed, 19 Aug 2009 15:45:16 +0000 (15:45 +0000)
source/blender/blenkernel/BKE_node.h
source/blender/editors/preview/previewrender.c
source/blender/editors/space_node/node_edit.c
source/blender/editors/space_node/space_node.c
source/blender/nodes/intern/TEX_util.c
source/blender/nodes/intern/TEX_util.h
source/blender/render/intern/source/texture.c

index 4ac95b61a5e7600940f581e39cc4d7a77869f6f7..40afa1dba361ac5dcf5a294441a3536d5cc3ebd1 100644 (file)
@@ -421,10 +421,9 @@ extern struct ListBase node_all_textures;
 
 /* API */
 int  ntreeTexTagAnimated(struct bNodeTree *ntree);
 
 /* API */
 int  ntreeTexTagAnimated(struct bNodeTree *ntree);
-void ntreeTexUpdatePreviews( struct bNodeTree* nodetree );
-void ntreeTexExecTree(struct bNodeTree *ntree, struct TexResult *target, float *coord, float *dxt, float *dyt, char do_preview, short thread, struct Tex *tex, short which_output, int cfra);
+void ntreeTexSetPreviewFlag(int);
+void ntreeTexExecTree(struct bNodeTree *ntree, struct TexResult *target, float *coord, float *dxt, float *dyt, short thread, struct Tex *tex, short which_output, int cfra);
 void ntreeTexCheckCyclics(struct bNodeTree *ntree);
 void ntreeTexCheckCyclics(struct bNodeTree *ntree);
-void ntreeTexAssignIndex(struct bNodeTree *ntree, struct bNode *node);
 char* ntreeTexOutputMenu(struct bNodeTree *ntree);
 
 
 char* ntreeTexOutputMenu(struct bNodeTree *ntree);
 
 
index 8fcf65202ee4fc3b72508329bb6cc9656465971e..94db74c18d9d417ae10e357d0b5f00d276de1ee9 100644 (file)
@@ -946,7 +946,11 @@ void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, M
        /* XXX ugly global still, but we can't do preview while rendering */
        if(G.rendering)
                return;
        /* XXX ugly global still, but we can't do preview while rendering */
        if(G.rendering)
                return;
-
+       
+       if(GS(id->name) == ID_TE) {
+               ntreeTexSetPreviewFlag(1);
+       }
+       
        steve= WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), owner);
        sp= MEM_callocN(sizeof(ShaderPreview), "shader preview");
 
        steve= WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), owner);
        sp= MEM_callocN(sizeof(ShaderPreview), "shader preview");
 
index e1b612d74e1d1a173f8dcf6f2fc8021957fcea2d..bc81c25d106c43010dd9d213e6f3655518eed93e 100644 (file)
@@ -574,7 +574,6 @@ void ED_node_texture_default(Tex *tx)
        nodeAddLink(tx->nodetree, in, fromsock, out, tosock);
        
        ntreeSolveOrder(tx->nodetree);  /* needed for pointers */
        nodeAddLink(tx->nodetree, in, fromsock, out, tosock);
        
        ntreeSolveOrder(tx->nodetree);  /* needed for pointers */
-       ntreeTexUpdatePreviews(tx->nodetree); /* XXX texture nodes should follow shader node methods (ton) */
 }
 
 /* Here we set the active tree(s), even called for each redraw now, so keep it fast :) */
 }
 
 /* Here we set the active tree(s), even called for each redraw now, so keep it fast :) */
@@ -1111,9 +1110,6 @@ static int node_resize_modal(bContext *C, wmOperator *op, wmEvent *event)
                                node->width= nsw->oldwidth + mx - nsw->mxstart;
                                CLAMP(node->width, node->typeinfo->minwidth, node->typeinfo->maxwidth);
                        }
                                node->width= nsw->oldwidth + mx - nsw->mxstart;
                                CLAMP(node->width, node->typeinfo->minwidth, node->typeinfo->maxwidth);
                        }
-                       // XXX
-                       if(snode->nodetree->type == NTREE_TEXTURE)
-                               ntreeTexUpdatePreviews(snode->nodetree); /* XXX texture nodes should follow shader node methods (ton) */
                                
                        ED_region_tag_redraw(ar);
 
                                
                        ED_region_tag_redraw(ar);
 
@@ -1659,7 +1655,6 @@ bNode *node_add_node(SpaceNode *snode, Scene *scene, int type, float locx, float
        
        if(snode->nodetree->type==NTREE_TEXTURE) {
                ntreeTexCheckCyclics(snode->edittree);
        
        if(snode->nodetree->type==NTREE_TEXTURE) {
                ntreeTexCheckCyclics(snode->edittree);
-               ntreeTexUpdatePreviews(snode->edittree); /* XXX texture nodes should follow shader node methods (ton) */
        }
        
        return node;
        }
        
        return node;
index cb25d29fd276b86f59921fff94cc69262d91e88f..2233a4db3a065b8adea18f62e43cfc30a67c9df5 100644 (file)
@@ -184,8 +184,9 @@ static void node_area_refresh(const struct bContext *C, struct ScrArea *sa)
                }
                else if(snode->treetype==NTREE_TEXTURE) {
                        Tex *tex= (Tex *)snode->id;
                }
                else if(snode->treetype==NTREE_TEXTURE) {
                        Tex *tex= (Tex *)snode->id;
-                       if(tex->use_nodes)
-                               ntreeTexUpdatePreviews(tex->nodetree);
+                       if(tex->use_nodes) {
+                               ED_preview_shader_job(C, sa, snode->id, NULL, NULL, 100, 100);
+                       }
                }
        }
 }
                }
        }
 }
index a6a5877722b4bab6bbdfdd73f0280c833be7f9ed..2c21627dad95bfb75d1d7ed47eabdedb58c12337 100644 (file)
@@ -47,6 +47,8 @@
 
 #define PREV_RES 128 /* default preview resolution */
 
 
 #define PREV_RES 128 /* default preview resolution */
 
+int preview_flag = 0;
+
 void tex_call_delegate(TexDelegate *dg, float *out, TexParams *params, short thread)
 {
        if(dg->node->need_exec)
 void tex_call_delegate(TexDelegate *dg, float *out, TexParams *params, short thread)
 {
        if(dg->node->need_exec)
@@ -108,12 +110,6 @@ static void init_preview(bNode *node)
        if(node->preview==NULL)
                node->preview= MEM_callocN(sizeof(bNodePreview), "node preview");
        
        if(node->preview==NULL)
                node->preview= MEM_callocN(sizeof(bNodePreview), "node preview");
        
-       if(node->preview->rect)
-               if(node->preview->xsize!=xsize && node->preview->ysize!=ysize) {
-                       MEM_freeN(node->preview->rect);
-                       node->preview->rect= NULL;
-               }
-       
        if(node->preview->rect==NULL) {
                node->preview->rect= MEM_callocN(4*xsize + xsize*ysize*sizeof(float)*4, "node preview rect");
                node->preview->xsize= xsize;
        if(node->preview->rect==NULL) {
                node->preview->rect= MEM_callocN(4*xsize + xsize*ysize*sizeof(float)*4, "node preview rect");
                node->preview->xsize= xsize;
@@ -136,6 +132,8 @@ void tex_do_preview(bNode *node, bNodeStack *ns, TexCallData *cdata)
        bNodePreview *preview;
        float coord[3] = {0, 0, 0};
        TexParams params;
        bNodePreview *preview;
        float coord[3] = {0, 0, 0};
        TexParams params;
+       int resolution;
+       int xsize, ysize;
        
        if(!cdata->do_preview)
                return;
        
        if(!cdata->do_preview)
                return;
@@ -146,19 +144,23 @@ void tex_do_preview(bNode *node, bNodeStack *ns, TexCallData *cdata)
        init_preview(node);
        
        preview = node->preview;
        init_preview(node);
        
        preview = node->preview;
+       xsize = preview->xsize;
+       ysize = preview->ysize;
        
        params.dxt = 0;
        params.dyt = 0;
        params.cfra = cdata->cfra;
        params.coord = coord;
        
        
        params.dxt = 0;
        params.dyt = 0;
        params.cfra = cdata->cfra;
        params.coord = coord;
        
-       for(x=0; x<preview->xsize; x++)
-       for(y=0; y<preview->ysize; y++)
+       resolution = (xsize < ysize) ? xsize : ysize;
+       
+       for(x=0; x<xsize; x++)
+       for(y=0; y<ysize; y++)
        {
        {
-               params.coord[0] = ((float) x / preview->xsize) * 2 - 1;
-               params.coord[1] = ((float) y / preview->ysize) * 2 - 1;
+               params.coord[0] = ((float) x / resolution) * 2 - 1;
+               params.coord[1] = ((float) y / resolution) * 2 - 1;
                
                
-               result = preview->rect + 4 * (preview->xsize*y + x);
+               result = preview->rect + 4 * (xsize*y + x);
                
                tex_input_rgba(result, ns, &params, cdata->thread);
        }
                
                tex_input_rgba(result, ns, &params, cdata->thread);
        }
@@ -212,7 +214,6 @@ void ntreeTexExecTree(
        TexResult *texres,
        float *coord,
        float *dxt, float *dyt,
        TexResult *texres,
        float *coord,
        float *dxt, float *dyt,
-       char do_preview, 
        short thread, 
        Tex *tex, 
        short which_output, 
        short thread, 
        Tex *tex, 
        short which_output, 
@@ -230,28 +231,19 @@ void ntreeTexExecTree(
        data.dxt = dxt;
        data.dyt = dyt;
        data.target = texres;
        data.dxt = dxt;
        data.dyt = dyt;
        data.target = texres;
-       data.do_preview = do_preview;
+       data.do_preview = preview_flag;
        data.thread = thread;
        data.which_output = which_output;
        data.cfra= cfra;
        
        data.thread = thread;
        data.which_output = which_output;
        data.cfra= cfra;
        
+       preview_flag = 0;
+       
        ntreeExecTree(nodes, &data, thread);
 }
 
        ntreeExecTree(nodes, &data, thread);
 }
 
-void ntreeTexUpdatePreviews(bNodeTree* nodetree)
+void ntreeTexSetPreviewFlag(int doit)
 {
 {
-       Tex *tex;
-       float coord[] = {0,0,0};
-       TexResult dummy_texres;
-       
-       for(tex= G.main->tex.first; tex; tex= tex->id.next)
-               if(tex->nodetree == nodetree) break;
-       if(tex) {
-               dummy_texres.nor = 0;
-       
-               ntreeBeginExecTree(nodetree);
-               ntreeTexExecTree(nodetree, &dummy_texres, coord, 0, 0, 1, 0, tex, 0, 0);
-       }
+       preview_flag = doit;
 }
 
 char* ntreeTexOutputMenu(bNodeTree *ntree)
 }
 
 char* ntreeTexOutputMenu(bNodeTree *ntree)
index 7fff8d046517d4d5b626825b8d7da515a9e10db8..87a9cf288d67e4f132d96b7ba357dee2ca79e933 100644 (file)
@@ -102,8 +102,7 @@ float tex_input_value(bNodeStack *in, TexParams *params, short thread);
 void tex_output(bNode *node, bNodeStack **in, bNodeStack *out, TexFn texfn);
 void tex_do_preview(bNode *node, bNodeStack *ns, TexCallData *cdata);
 
 void tex_output(bNode *node, bNodeStack **in, bNodeStack *out, TexFn texfn);
 void tex_do_preview(bNode *node, bNodeStack *ns, TexCallData *cdata);
 
-void ntreeTexUpdatePreviews( bNodeTree* nodetree );
-void ntreeTexExecTree(bNodeTree *nodes, TexResult *texres, float *coord, float *dxt, float *dyt, char do_preview, short thread, struct Tex *tex, short which_output, int cfra);
+void ntreeTexExecTree(bNodeTree *nodes, TexResult *texres, float *coord, float *dxt, float *dyt, short thread, struct Tex *tex, short which_output, int cfra);
 
 void params_from_cdata(TexParams *out, TexCallData *in);
 
 
 void params_from_cdata(TexParams *out, TexCallData *in);
 
index 3db78bfea932bc6951ad3c6ec0ffa04182784bfa..e6d6e78e27bd4a9c1a341846bed12c1845620e8d 100644 (file)
@@ -719,7 +719,7 @@ static int evalnodes(Tex *tex, float *texvec, float *dxt, float *dyt, TexResult
        short rv = TEX_INT;
        bNodeTree *nodes = tex->nodetree;
        
        short rv = TEX_INT;
        bNodeTree *nodes = tex->nodetree;
        
-       ntreeTexExecTree(nodes, texres, texvec, dxt, dyt, 0, thread, tex, which_output, R.r.cfra);
+       ntreeTexExecTree(nodes, texres, texvec, dxt, dyt, thread, tex, which_output, R.r.cfra);
        
        if(texres->nor) rv |= TEX_NOR;
        rv |= TEX_RGB;
        
        if(texres->nor) rv |= TEX_NOR;
        rv |= TEX_RGB;