From 66ac1a34d8c02dbda8c73b6f7266dfdd540d7fa7 Mon Sep 17 00:00:00 2001 From: Supakorn 'Jamie' Rassameemasmuang Date: Sat, 14 Dec 2024 15:57:12 -0700 Subject: [PATCH] VK: Move vkrender arguments to a struct. --- picture.cc | 56 +++++++++++++++++++------------------------ vkrender.cc | 69 +++++++++++++++++++++++++---------------------------- vkrender.h | 36 +++++++++++++++++++++++----- 3 files changed, 87 insertions(+), 74 deletions(-) diff --git a/picture.cc b/picture.cc index a530074ad..dad1fdfb9 100644 --- a/picture.cc +++ b/picture.cc @@ -1439,28 +1439,7 @@ void picture::render(double size2, const triple& Min, const triple& Max, } } -struct Communicate : public gc { - string prefix; - picture* pic; - string format; - double width; - double height; - double angle; - double zoom; - triple m; - triple M; - pair shift; - pair margin; - double *t; - double *background; - size_t nlights; - triple *lights; - double *diffuse; - double *specular; - bool view; -}; - -Communicate com; +AsyVkRender::VkrenderFunctionArgs com = {}; extern bool allowRender; @@ -1472,9 +1451,7 @@ void glrenderWrapper() vk->endwait(vk->initSignal,vk->initLock); #endif if(allowRender) { - vk->vkrender(com.prefix,com.pic,com.format,com.width,com.height,com.angle, - com.zoom,com.m,com.M,com.shift,com.margin,com.t,com.background, - com.nlights,com.lights,com.diffuse,com.specular,com.view); + vk->vkrender(com); } #endif } @@ -1570,7 +1547,7 @@ bool picture::shipout3(const string& prefix, const string& format, com.t=t; com.tup=tup; com.background=background; - com.nlights=nlights; + com.nlightsin=nlights; com.lights=lights; com.diffuse=diffuse; com.specular=specular; @@ -1612,11 +1589,28 @@ bool picture::shipout3(const string& prefix, const string& format, } #if HAVE_LIBGLM - vk->vkrender(prefix,pic,format,width,height,angle, - zoom,m,M,shift,margin,t,background, - nlights,lights,diffuse,specular,View, - oldpid); - + AsyVkRender::VkrenderFunctionArgs args = {}; + args.prefix = prefix; + args.pic = pic; + args.format = format; + args.width = width; + args.height = height; + args.angle = angle; + args.zoom = zoom; + args.m = m; + args.M = M; + args.shift = shift; + args.margin = margin; + args.t = t; + args.background = background; + args.nlightsin = nlights; + args.lights = lights; + args.diffuse = diffuse; + args.specular = specular; + args.view = view; + args.oldpid = oldpid; + + vk->vkrender(args); if(format3d) { string name=buildname(prefix,format); abs3Doutfile *fileObj=nullptr; diff --git a/vkrender.cc b/vkrender.cc index 31626eb7b..39f809522 100644 --- a/vkrender.cc +++ b/vkrender.cc @@ -541,15 +541,10 @@ void checkpow2(unsigned int n, string s) { void closeWindowHandler(GLFWwindow *); -void AsyVkRender::vkrender(const string& prefix, const picture* pic, const string& format, - double Width, double Height, double angle, double zoom, - const triple& mins, const triple& maxs, const pair& shift, - const pair& margin, double* t, double *tup, - double* background, size_t nlightsin, triple* lights, - double* diffuse, double* specular, bool view, int oldpid/*=0*/) -{ - bool v3d=format == "v3d"; - bool webgl=format == "html"; +void AsyVkRender::vkrender(VkrenderFunctionArgs const& args) +{ + bool v3d=args.format == "v3d"; + bool webgl=args.format == "html"; bool format3d=webgl || v3d; offscreen=settings::getSetting("offscreen"); @@ -561,36 +556,36 @@ void AsyVkRender::vkrender(const string& prefix, const picture* pic, const strin if(!monitor) offscreen=true; } - this->pic = pic; - this->Prefix=prefix; - this->Format = format; + this->pic = args.pic; + this->Prefix=args.prefix; + this->Format = args.format; this->redraw = true; this->remesh = true; - this->nlights = nlightsin; - this->Lights = lights; - this->LightsDiffuse = diffuse; - this->Oldpid = oldpid; + this->nlights = args.nlightsin; + this->Lights = args.lights; + this->LightsDiffuse = args.diffuse; + this->Oldpid = args.oldpid; - this->Angle = angle * radians; + this->Angle = args.angle * radians; this->lastZoom = 0; - this->Zoom0 = zoom; - this->Shift = shift / zoom; - this->Margin = margin; + this->Zoom0 = args.zoom; + this->Shift = args.shift / args.zoom; + this->Margin = args.margin; for (int i = 0; i < 4; i++) - this->Background[i] = static_cast(background[i]); + this->Background[i] = static_cast(args.background[i]); - this->ViewExport=view; - this->View = view && !offscreen; + this->ViewExport=args.view; + this->View = args.view && !offscreen; - this->title = std::string(PACKAGE_NAME)+": "+prefix.c_str(); + this->title = std::string(PACKAGE_NAME)+": "+ args.prefix.c_str(); - Xmin = mins.getx(); - Xmax = maxs.getx(); - Ymin = mins.gety(); - Ymax = maxs.gety(); - Zmin = mins.getz(); - Zmax = maxs.getz(); + Xmin = args.m.getx(); + Xmax = args.M.getx(); + Ymin = args.m.gety(); + Ymax = args.M.gety(); + Zmin = args.m.getz(); + Zmax = args.M.getz(); orthographic = (this->Angle == 0.0); H = orthographic ? 0.0 : -tan(0.5 * this->Angle) * Zmax; @@ -603,10 +598,10 @@ void AsyVkRender::vkrender(const string& prefix, const picture* pic, const strin #endif for(int i=0; i < 16; ++i) - T[i]=t[i]; + T[i]=args.t[i]; for(int i=0; i < 16; ++i) - Tup[i]=tup[i]; + Tup[i]=args.tup[i]; if(!(initialized && (interact::interactive || settings::getSetting("animating")))) { @@ -621,8 +616,8 @@ void AsyVkRender::vkrender(const string& prefix, const picture* pic, const strin if(antialias) expand *= 2.0; } - fullWidth=(int) ceil(expand*Width); - fullHeight=(int) ceil(expand*Height); + fullWidth=(int) ceil(expand*args.width); + fullHeight=(int) ceil(expand*args.height); if(!format3d) { if(offscreen) { @@ -634,9 +629,9 @@ void AsyVkRender::vkrender(const string& prefix, const picture* pic, const strin } } - oWidth=Width; - oHeight=Height; - Aspect=Width/Height; + oWidth=args.width; + oHeight=args.height; + Aspect=args.width / args.height; if(format3d) { width=fullWidth; diff --git a/vkrender.h b/vkrender.h index 197659081..5e86d99e1 100644 --- a/vkrender.h +++ b/vkrender.h @@ -357,12 +357,36 @@ class AsyVkRender AsyVkRender() = default; ~AsyVkRender(); - void vkrender(const string& prefix, const picture* pic, const string& format, - double width, double height, double angle, double zoom, - const triple& m, const triple& M, const pair& shift, - const pair& margin, double* t, double *tup, - double* background, size_t nlightsin, triple* lights, - double* diffuse, double* specular, bool view, int oldpid=0); + /** Argument for AsyVkRender::vkrender function */ + struct VkrenderFunctionArgs: public gc + { + string prefix; + picture const* pic; + string format; + double width; + double height; + double angle; + double zoom; + triple m; + triple M; + pair shift; + pair margin; + + double* t; + double* tup; + double* background; + + size_t nlightsin; + + triple* lights; + double* diffuse; + double* specular; + + bool view; + int oldpid=0; + }; + + void vkrender(VkrenderFunctionArgs const& args); triple billboardTransform(const triple& center, const triple& v) const; double getRenderResolution(triple Min) const;