Skip to content

Commit

Permalink
VK: Move vkrender arguments to a struct.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamievlin committed Dec 15, 2024
1 parent cc0b0f4 commit 66ac1a3
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 74 deletions.
56 changes: 25 additions & 31 deletions picture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
69 changes: 32 additions & 37 deletions vkrender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("offscreen");
Expand All @@ -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<float>(background[i]);
this->Background[i] = static_cast<float>(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;
Expand All @@ -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<bool>("animating")))) {
Expand All @@ -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) {
Expand All @@ -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;
Expand Down
36 changes: 30 additions & 6 deletions vkrender.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 66ac1a3

Please sign in to comment.