Added support for linked objects from libraries which can have names that

are already defined locally, probably does not work fully yet.
Added extra 'threads' parameter as requested by Lynx3d.

Optimized drawing of rendered tiles, so that the entire image doesn't have
to be redrawn every time a tile is complete.
The blender code that handles this part was not yet complete and could only
draw (sets of) scanlines. I extended the renderwin_progress() function in
renderwin.c to handle a given subrectangle.
This code needs review!
For the limited test I did it seems to work at least...
This commit is contained in:
2006-06-06 01:57:07 +00:00
parent 4467c26337
commit f832e30669
3 changed files with 50 additions and 25 deletions

View File

@@ -797,7 +797,7 @@ static void renderwin_progress(RenderWin *rw, RenderResult *rr, volatile rcti *r
rcti win_rct;
float *rectf= NULL, fullrect[2][2];
unsigned int *rect32= NULL;
int ymin, ymax;
int ymin, ymax, xmin, xmax;
/* if renrect argument, we only display scanlines */
if(renrect) {
@@ -805,15 +805,21 @@ static void renderwin_progress(RenderWin *rw, RenderResult *rr, volatile rcti *r
if(rr->renlay==NULL || renrect->ymax>=rr->recty)
return;
/* xmin here is first subrect x coord, xmax defines subrect width */
xmin = renrect->xmin;
xmax = renrect->xmax - xmin;
if (xmax<2) return;
ymin= renrect->ymin;
ymax= renrect->ymax-ymin;
ymax= renrect->ymax - ymin;
if(ymax<2)
return;
renrect->ymin= renrect->ymax;
}
else {
ymin= 0;
ymax= rr->recty-2*rr->crop;
xmin = ymin = 0;
xmax = rr->rectx - 2*rr->crop;
ymax = rr->recty - 2*rr->crop;
}
/* renderwindow cruft */
@@ -835,7 +841,7 @@ static void renderwin_progress(RenderWin *rw, RenderResult *rr, volatile rcti *r
}
if(rectf) {
/* if scanline updates... */
rectf+= 4*rr->rectx*ymin;
rectf+= 4*(rr->rectx*ymin + xmin);
/* when rendering more pixels than needed, we crop away cruft */
if(rr->crop)
@@ -844,8 +850,8 @@ static void renderwin_progress(RenderWin *rw, RenderResult *rr, volatile rcti *r
/* tilerect defines drawing offset from (0,0) */
/* however, tilerect (xmin, ymin) is first pixel */
fullrect[0][0] += (rr->tilerect.xmin+rr->crop)*rw->zoom;
fullrect[0][1] += (rr->tilerect.ymin+rr->crop + ymin)*rw->zoom;
fullrect[0][0] += (rr->tilerect.xmin + rr->crop + xmin)*rw->zoom;
fullrect[0][1] += (rr->tilerect.ymin + rr->crop + ymin)*rw->zoom;
glEnable(GL_SCISSOR_TEST);
glaDefine2DArea(&win_rct);
@@ -857,11 +863,9 @@ static void renderwin_progress(RenderWin *rw, RenderResult *rr, volatile rcti *r
glPixelZoom(rw->zoom, rw->zoom);
if(rect32)
glaDrawPixelsSafe(fullrect[0][0], fullrect[0][1], rr->rectx-2*rr->crop, ymax, rr->rectx,
GL_RGBA, GL_UNSIGNED_BYTE, rect32);
glaDrawPixelsSafe(fullrect[0][0], fullrect[0][1], xmax, ymax, rr->rectx, GL_RGBA, GL_UNSIGNED_BYTE, rect32);
else
glaDrawPixelsSafe_to32(fullrect[0][0], fullrect[0][1], rr->rectx-2*rr->crop, ymax, rr->rectx,
GL_RGBA, GL_FLOAT, rectf);
glaDrawPixelsSafe_to32(fullrect[0][0], fullrect[0][1], xmax, ymax, rr->rectx, GL_RGBA, GL_FLOAT, rectf);
glPixelZoom(1.0, 1.0);

View File

@@ -1177,7 +1177,11 @@ void yafrayFileRender_t::writeObject(Object* obj, const vector<VlakRen*> &VLR_li
xmlfile << ostr.str();
ostr.str("");
ostr << "<object name=\"" << obj->id.name << "\"";
// if objects are externally linked from a library, they could have a name that is already
// defined locally, so to prevent name clashes, prefix name with 'lib'
string obname(obj->id.name);
if (obj->id.flag & (LIB_EXTERN|LIB_INDIRECT))obname = "lib_" + obname;
ostr << "<object name=\"" << obname << "\"";
// Yafray still needs default shader name in object def.,
// since we write a shader with every face, simply use the material of the first face.
// If this is an empty string, assume default material.

View File

@@ -242,6 +242,8 @@ bool yafrayPluginRender_t::writeRender()
}
params["bias"] = yafray::parameter_t(re->r.YF_raybias);
params["clamp_rgb"] = yafray::parameter_t((re->r.YF_clamprgb==0) ? "on" : "off");
// lynx request
params["threads"] = yafray::parameter_t((int)re->r.YF_numprocs);
blenderYafrayOutput_t output(re);
yafrayGate->render(params, output);
cout << "render finished" << endl;
@@ -1350,7 +1352,11 @@ void yafrayPluginRender_t::writeObject(Object* obj, const vector<VlakRen*> &VLR_
genCompleFace(faces, faceshader, uvcoords, vcol, vert_idx, vlr, has_orco, has_uv);
}
yafrayGate->addObject_trimesh(string(obj->id.name), verts, faces, uvcoords, vcol,
// if objects are externally linked from a library, they could have a name that is already
// defined locally, so to prevent name clashes, prefix name with 'lib'
string obname(obj->id.name);
if (obj->id.flag & (LIB_EXTERN|LIB_INDIRECT))obname = "lib_" + obname;
yafrayGate->addObject_trimesh(obname, verts, faces, uvcoords, vcol,
shaders, faceshader, sm_angle, castShadows, true, true, caus, has_orco,
caus_rcolor, caus_tcolor, caus_IOR);
yafrayGate->transformPop();
@@ -1883,14 +1889,15 @@ extern "C" {
bool blenderYafrayOutput_t::putPixel(int x, int y, const yafray::color_t &c,
yafray::CFLOAT alpha, yafray::PFLOAT depth)
{
/* XXX how to get the image from Blender and write to it. This call doesn't allow to change buffer rects */
// XXX how to get the image from Blender and write to it. This call doesn't allow to change buffer rects
RenderResult rres;
RE_GetResultImage(re, &rres);
// rres.rectx, rres.recty is width/height
// rres.rectf is float buffer, scanlines starting in bottom
// rres.rectz is zbuffer, available when associated pass is set
const unsigned int yy = (rres.recty - 1) - y;
const unsigned int maxy = rres.recty-1;
const unsigned int yy = maxy - y;
const unsigned int px = yy * rres.rectx;
// rgba
@@ -1901,15 +1908,25 @@ bool blenderYafrayOutput_t::putPixel(int x, int y, const yafray::color_t &c,
*fpt = alpha;
// depth values
float* zbuf = rres.rectz + px;
if (zbuf) zbuf[x] = depth;
if (rres.rectz) rres.rectz[px + x] = depth;
out++;
// draw on completion of bucket & end of pass
if (((out & 4095)==0) || ((out % (re->rectx*re->recty))==0)) {
// attempt to optimize drawing, by only drawing the tile currently rendered by yafray,
// and not the entire display every time (blender has to to do float->char conversion),
// but since the tile is not actually known, it has to be calculated from the coords.
// not sure if it really makes all that much difference at all... unless rendering really large pictures
// (renderwin.c also had to be adapted for this)
// tile start & end coords
int txs = x & 0xffffffc0, tys = y & 0xffffffc0;
int txe = txs + 63, tye = tys + 63;
// tile border clip
if (txe >= rres.rectx) txe = rres.rectx-1;
if (tye >= rres.recty) tye = maxy;
// draw tile if last pixel reached
if ((y*rres.rectx + x) == (tye*rres.rectx + txe)) {
re->result->renlay = render_get_active_layer(re, re->result);
/* XXX second arg is rcti *rect, allows to indicate sub-rect in image to draw */
re->display_draw(re->result, NULL);
// note: ymin/ymax swapped here, img. upside down!
rcti rt = {txs, txe+1, maxy-tye, ((tys==0) ? maxy : ((maxy+1)-tys))}; // !!! tys can be zero
re->display_draw(re->result, &rt);
}
if (re->test_break()) return false;