summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/picture.cc
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/utils/asymptote/picture.cc')
-rw-r--r--Build/source/utils/asymptote/picture.cc203
1 files changed, 116 insertions, 87 deletions
diff --git a/Build/source/utils/asymptote/picture.cc b/Build/source/utils/asymptote/picture.cc
index c59c28e91b4..af334730f31 100644
--- a/Build/source/utils/asymptote/picture.cc
+++ b/Build/source/utils/asymptote/picture.cc
@@ -459,17 +459,6 @@ bool picture::texprocess(const string& texname, const string& outname,
cmd.push_back("-o"+outname);
ostringstream buf;
bbox B=svgbbox(b,bboxshift);
- /*
- double height=b.top-b.bottom;
- double threshold=12.0*tex2ps;
- if(height < threshold) {
- double offset=threshold-height;
- b.top += offset;
- b.bottom += offset;
- }
- bbox B=b;
- B.shift(bboxshift+pair(1.99*cm,1.9*cm));
- */
buf << "--bbox="
<< B.left << "bp "
<< B.bottom << "bp "
@@ -746,6 +735,10 @@ bool picture::postprocess(const string& prename, const string& outname,
bool wait, bool view, bool pdftex,
bool epsformat, bool svg)
{
+ if(outputformat == "html") {
+ if(getSetting<Int>("render") == 0)
+ reportError("For 2D pictures, use outformat=\"svg\" instead of \"html\"; if this is a 3D picture, use settings.render=1 or the -render=1 command-line option");
+ }
static mem::map<CONST string,int> pids;
int status=0;
bool pdfformat=(settings::pdf(getSetting<string>("tex"))
@@ -1176,23 +1169,16 @@ bool picture::shipout(picture *preamble, const string& Prefix,
// render viewport with width x height pixels.
void picture::render(double size2, const triple& Min, const triple& Max,
- double perspective, bool transparent, bool remesh) const
+ double perspective, bool remesh) const
{
- if(remesh) {
- for(nodelist::const_iterator p=nodes.begin(); p != nodes.end(); ++p) {
- assert(*p);
- (*p)->render(size2,Min,Max,perspective,transparent);
- }
+ for(nodelist::const_iterator p=nodes.begin(); p != nodes.end(); ++p) {
+ assert(*p);
+ if(remesh) (*p)->meshinit();
+ (*p)->render(size2,Min,Max,perspective,remesh);
}
#ifdef HAVE_GL
- if(transparent)
- drawBezierPatch::S.drawTransparent();
- else {
- drawBezierPatch::S.drawOpaque();
- drawPath3::R.draw();
- drawPixel::R.draw();
- }
+ drawBuffers();
#endif
}
@@ -1207,6 +1193,7 @@ struct Communicate : public gc {
triple m;
triple M;
pair shift;
+ pair margin;
double *t;
double *background;
size_t nlights;
@@ -1226,25 +1213,33 @@ void glrenderWrapper()
endwait(initSignal,initLock);
#endif
glrender(com.prefix,com.pic,com.format,com.width,com.height,com.angle,
- com.zoom,com.m,com.M,com.shift,com.t,com.background,com.nlights,
- com.lights,com.diffuse,com.specular,com.view);
+ com.zoom,com.m,com.M,com.shift,com.margin,com.t,com.background,
+ com.nlights,com.lights,com.diffuse,com.specular,com.view);
#endif
}
bool picture::shipout3(const string& prefix, const string& format,
double width, double height, double angle, double zoom,
const triple& m, const triple& M, const pair& shift,
- double *t, double *background, size_t nlights,
- triple *lights, double *diffuse, double *specular, bool view)
+ const pair& margin, double *t, double *background,
+ size_t nlights, triple *lights, double *diffuse,
+ double *specular, bool view)
{
if(getSetting<bool>("interrupt"))
return true;
-#ifndef HAVE_LIBGLUT
- if(!getSetting<bool>("offscreen"))
+ bool webgl=format == "html";
+
+#ifndef HAVE_GL
+ if(!webgl && !getSetting<bool>("offscreen"))
camp::reportError("to support onscreen rendering, please install glut library, run ./configure, and recompile");
#endif
+#ifndef HAVE_LIBGLM
+ if(webgl)
+ camp::reportError("to support WebGL rendering, please install glm header files, run ./configure, and recompile");
+#endif
+
#ifndef HAVE_LIBOSMESA
if(getSetting<bool>("offscreen"))
camp::reportError("to support offscreen rendering; please install OSMesa library, run ./configure --enable-offscreen, and recompile");
@@ -1278,71 +1273,106 @@ bool picture::shipout3(const string& prefix, const string& format,
const string outputformat=format.empty() ?
getSetting<string>("outformat") : format;
-#ifdef HAVE_GL
- bool View=settings::view() && view;
+#ifdef HAVE_LIBGLM
static int oldpid=0;
+ bool View=settings::view() && view;
+#endif
+
+#ifdef HAVE_GL
bool offscreen=getSetting<bool>("offscreen");
#ifdef HAVE_PTHREAD
bool animating=getSetting<bool>("animating");
bool Wait=!interact::interactive || !View || animating;
#endif
-#endif
+#endif
-#if defined(HAVE_LIBGLUT) && defined(HAVE_GL)
- if(glthread && !offscreen) {
+ if(!webgl) {
+#ifdef HAVE_GL
+ if(glthread && !offscreen) {
#ifdef HAVE_PTHREAD
- if(gl::initialize) {
- gl::initialize=false;
- com.prefix=prefix;
- com.pic=pic;
- com.format=outputformat;
- com.width=width;
- com.height=height;
- com.angle=angle;
- com.zoom=zoom;
- com.m=m;
- com.M=M;
- com.shift=shift;
- com.t=t;
- com.background=background;
- com.nlights=nlights;
- com.lights=lights;
- com.diffuse=diffuse;
- com.specular=specular;
- com.view=View;
- if(Wait)
- pthread_mutex_lock(&readyLock);
- wait(initSignal,initLock);
- endwait(initSignal,initLock);
- static bool initialize=true;
- if(initialize) {
+ if(gl::initialize) {
+ gl::initialize=false;
+ com.prefix=prefix;
+ com.pic=pic;
+ com.format=outputformat;
+ com.width=width;
+ com.height=height;
+ com.angle=angle;
+ com.zoom=zoom;
+ com.m=m;
+ com.M=M;
+ com.shift=shift;
+ com.margin=margin;
+ com.t=t;
+ com.background=background;
+ com.nlights=nlights;
+ com.lights=lights;
+ com.diffuse=diffuse;
+ com.specular=specular;
+ com.view=View;
+ if(Wait)
+ pthread_mutex_lock(&readyLock);
wait(initSignal,initLock);
endwait(initSignal,initLock);
- initialize=false;
+ static bool initialize=true;
+ if(initialize) {
+ wait(initSignal,initLock);
+ endwait(initSignal,initLock);
+ initialize=false;
+ }
+ if(Wait) {
+ pthread_cond_wait(&readySignal,&readyLock);
+ pthread_mutex_unlock(&readyLock);
+ }
+ return true;
}
- if(Wait) {
- pthread_cond_wait(&readySignal,&readyLock);
- pthread_mutex_unlock(&readyLock);
+ if(Wait)
+ pthread_mutex_lock(&readyLock);
+#endif
+ } else {
+ int pid=fork();
+ if(pid == -1)
+ camp::reportError("Cannot fork process");
+ if(pid != 0) {
+ oldpid=pid;
+ waitpid(pid,NULL,interact::interactive && View ? WNOHANG : 0);
+ return true;
}
- return true;
}
- if(Wait)
- pthread_mutex_lock(&readyLock);
#endif
- } else {
- int pid=fork();
- if(pid == -1)
- camp::reportError("Cannot fork process");
- if(pid != 0) {
- oldpid=pid;
- waitpid(pid,NULL,interact::interactive && View ? WNOHANG : 0);
- return true;
- }
}
+
+#if HAVE_LIBGLM
+ glrender(prefix,pic,outputformat,width,height,angle,zoom,m,M,shift,margin,t,
+ background,nlights,lights,diffuse,specular,View,oldpid);
+
+ if(webgl) {
+ jsfile js;
+ string name=buildname(prefix,format);
+ js.open(name);
+
+ for(nodelist::iterator p=pic->nodes.begin(); p != pic->nodes.end(); ++p) {
+ assert(*p);
+ (*p)->write(&js);
+ }
+ if(verbose > 0)
+ cout << "Wrote " << name << endl;
+ if(View) {
+ mem::vector<string> cmd;
+ push_command(cmd,getSetting<string>("htmlviewer"));
+#ifdef __MSDOS__
+ cmd.push_back("file://%CD%/"+name);
+#else
+ cmd.push_back(name);
#endif
+ push_split(cmd,getSetting<string>("htmlviewerOptions"));
+ System(cmd,2,false);
+ }
+ return true;
+ }
+#endif
+
#ifdef HAVE_GL
- glrender(prefix,pic,outputformat,width,height,angle,zoom,m,M,shift,t,
- background,nlights,lights,diffuse,specular,View,oldpid);
#ifdef HAVE_PTHREAD
if(glthread && !offscreen && Wait) {
pthread_cond_wait(&readySignal,&readyLock);
@@ -1351,17 +1381,17 @@ bool picture::shipout3(const string& prefix, const string& format,
return true;
#endif
#endif
-
+
return false;
}
-bool picture::shipout3(const string& prefix)
+bool picture::shipout3(const string& prefix, const string format)
{
bounds3();
- bool status = true;
+ bool status;
- string prcname=buildname(prefix,"prc");
- prcfile prc(prcname);
+ string name=buildname(prefix,"prc");
+ prcfile prc(name);
static const double limit=2.5*10.0/INT_MAX;
double compressionlimit=max(length(b3.Max()),length(b3.Min()))*limit;
@@ -1372,12 +1402,11 @@ bool picture::shipout3(const string& prefix)
(*p)->write(&prc,&billboard,compressionlimit,groups);
}
groups.pop_back();
- if(status)
- status=prc.finish();
-
+ status=prc.finish();
+
if(!status) reportError("shipout3 failed");
- if(verbose > 0) cout << "Wrote " << prcname << endl;
+ if(verbose > 0) cout << "Wrote " << name << endl;
return true;
}