From e4e1a856e6b8e31525932b554f1081b9be3d69de Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Wed, 30 Dec 2020 14:20:30 +0100 Subject: [PATCH] replace vrhr::state checking with nicer functions --- config.cpp | 2 +- control.cpp | 4 ++-- drawing.cpp | 18 +++++++++--------- graph.cpp | 19 +++++++------------ hypgraph.cpp | 22 +++++++++++----------- raycaster.cpp | 4 ++-- shaders.cpp | 18 +++++++++--------- sky.cpp | 4 +--- vr.cpp | 15 +++++++++++++++ 9 files changed, 57 insertions(+), 49 deletions(-) diff --git a/config.cpp b/config.cpp index 6b24b28b..d60efdfa 100644 --- a/config.cpp +++ b/config.cpp @@ -1913,7 +1913,7 @@ EX void show3D() { dialog::addItem(XLAT("stereo vision config"), 'e'); #if CAP_VR - dialog::addBoolItem(XLAT("VR settings"), vrhr::state > 0, 'v'); + dialog::addBoolItem(XLAT("VR settings"), vrhr::active(), 'v'); dialog::add_action_push(vrhr::show_vr_settings); #endif diff --git a/control.cpp b/control.cpp index 0a90c6c1..5b8480d9 100644 --- a/control.cpp +++ b/control.cpp @@ -601,7 +601,7 @@ EX bool need_mouseh = false; EX void fix_mouseh() { if(0) ; #if CAP_VR - else if(vrhr::state && which_pointer) { + else if(vrhr::active() && which_pointer) { vrhr::compute_point(which_pointer, mouseh, mouseover); } #endif @@ -792,7 +792,7 @@ EX void mainloopiter() { DEBB(DF_GRAPH, ("polling for events\n")); #if CAP_VR - if(vrhr::state) { + if(vrhr::active()) { rug::using_rugview urv; dynamicval ds(didsomething, didsomething); using namespace vrhr; diff --git a/drawing.cpp b/drawing.cpp index c757ed3a..1cd4fc26 100644 --- a/drawing.cpp +++ b/drawing.cpp @@ -227,7 +227,7 @@ EX void glflush() { }; #if CAP_VR - if(vrhr::state == 1 && !(cmode & sm::NORMAL)) + if(vrhr::should_render() && !(cmode & sm::NORMAL)) vrhr::in_vr_ui(drawer); else @@ -303,7 +303,7 @@ vector> tofix; EX bool two_sided_model() { #if CAP_VR - bool in_vr = vrhr::state == 2; + bool in_vr = vrhr::rendering(); #else constexpr bool in_vr = false; #endif @@ -378,7 +378,7 @@ void fixpoint(glvertex& hscr, hyperpoint H) { hyperpoint Hscr; applymodel(shiftless(good), Hscr); #if CAP_VR - if(vrhr::state == 2) + if(vrhr::rendering()) hscr = glhr::makevertex(Hscr[0], Hscr[1]*pconf.stretch, Hscr[2]); else #endif @@ -391,7 +391,7 @@ void addpoint(const shiftpoint& H) { // if(pconf.alpha + H[2] <= BEHIND_LIMIT && pmodel == mdDisk) poly_flags |= POLY_BEHIND; #if CAP_VR - if(vrhr::state == 2) z = 1; + if(vrhr::rendering()) z = 1; #endif if(spherespecial) { @@ -435,7 +435,7 @@ void addpoint(const shiftpoint& H) { Hlast = Hscr; } #if CAP_VR - if(vrhr::state == 2) { + if(vrhr::rendering()) { for(int i=0; i<3; i++) Hscr[i] *= z; } else @@ -967,7 +967,7 @@ void compute_side_by_centerin(dqi_poly *p, bool& nofill) { nofill = true; } applymodel(h1, hscr); - if(vrhr::state != 2) { + if(!vrhr::rendering()) { hscr[0] *= current_display->radius; hscr[1] *= current_display->radius * pconf.stretch; } for(int i=0; i 0 || equi)) can_have_inverse = true; - if(vrhr::state == 2) can_have_inverse = false; + if(vrhr::rendering()) can_have_inverse = false; if(sphere && among(pmodel, mdEquidistant, mdEquiarea)) can_have_inverse = true; if(pmodel == mdJoukowsky) can_have_inverse = true; if(pmodel == mdJoukowskyInverted && pconf.skiprope) can_have_inverse = true; @@ -2256,7 +2256,7 @@ EX void draw_main() { in_vr_sphere = false; #if CAP_VR - in_vr_sphere = vrhr::state == 2 && among(pmodel, mdDisk, mdBall, mdHyperboloid, mdHalfplane, mdHemisphere); + in_vr_sphere = vrhr::rendering() && among(pmodel, mdDisk, mdBall, mdHyperboloid, mdHalfplane, mdHemisphere); if(in_vr_sphere) { hyperpoint a, b; applymodel(shiftless(point3(0, 0, 1)), a); @@ -2363,7 +2363,7 @@ EX void drawqueue() { #endif #if CAP_VR - if(vrhr::state == 1) { + if(vrhr::should_render() == 1) { vrhr::render(); return; } diff --git a/graph.cpp b/graph.cpp index 8f6a74c8..ed468e02 100644 --- a/graph.cpp +++ b/graph.cpp @@ -3732,7 +3732,7 @@ void make_clipping_planes() { clipping_planes.clear(); if(!frustum_culling || PIU(sphere) || experimental || vid.stereo_mode == sODS || panini_alpha) return; #if CAP_VR - if(vrhr::state) return; + if(vrhr::active()) return; #endif auto add_clipping_plane = [] (ld x1, ld y1, ld x2, ld y2) { @@ -4163,7 +4163,7 @@ EX void queuecircleat(cell *c, double rad, color_t col) { EX cell *forwardcell() { #if CAP_VR - if(vrhr::state) { + if(vrhr::active()) { return vrhr::forward_cell; } #endif @@ -4178,7 +4178,7 @@ EX bool should_draw_mouse_cursor() { if(!mousing || inHighQual) return false; if(outofmap(mouseh.h)) return false; if(rug::rugged && !rug::renderonce) return true; - if(vrhr::state) return true; + if(vrhr::active()) return true; return false; } @@ -4259,7 +4259,7 @@ EX void drawMarkers() { if(lmouseover && vid.drawmousecircle && ok && DEFAULTCONTROL && MOBON && WDIM == 2) { cell *at = lmouseover; #if CAP_VR - if(vrhr::state == 2 && vrhr::forward_cell) + if(vrhr::active() && vrhr::forward_cell) at = vrhr::forward_cell; #endif queuecircleat(at, .8, darkena(lmouseover->cpdist > 1 ? 0x00FFFF : 0xFF0000, 0, 0xFF)); @@ -4903,10 +4903,7 @@ EX void calcparam() { cd->ycenter = lerp(vid.fsize + cd->scrsize, vid.yres - cd->scrsize - vid.fsize, .8); } else { - bool ok = true; - #if CAP_VR - ok = ok && !vrhr::state; - #endif + bool ok = !vrhr::active(); if(vid.xres > vid.yres * 4/3+16 && (cmode & sm::SIDE) && ok) current_display->sidescreen = true; #if CAP_TOUR @@ -5056,9 +5053,7 @@ EX void gamescreen(int _darken) { } darken = _darken; - #if CAP_VR - if(vrhr::state) darken = 0; - #endif + if(vrhr::active()) darken = 0; if(history::includeHistory) history::restore(); @@ -5106,7 +5101,7 @@ EX void gamescreen(int _darken) { #endif #if CAP_VR - if(vrhr::state && _darken) { + if(vrhr::active() && _darken) { int xsi = current_display->xsize; int ysi = current_display->ysize; color_t col = 0x000000C0; diff --git a/hypgraph.cpp b/hypgraph.cpp index b3fdc109..fb806cc0 100644 --- a/hypgraph.cpp +++ b/hypgraph.cpp @@ -165,7 +165,7 @@ void ballmodel(hyperpoint& ret, double alpha, double d, double zl) { bool use_z_coordinate() { #if CAP_VR - if(vrhr::state == 2) return true; + if(vrhr::rendering()) return true; #endif return current_display->stereo_active(); } @@ -468,7 +468,7 @@ EX void apply_other_model(shiftpoint H_orig, hyperpoint& ret, eModel md) { return; case mdBall: { - if(vrhr::state == 2) { + if(vrhr::rendering()) { vr_disk(ret, H); return; } @@ -497,7 +497,7 @@ EX void apply_other_model(shiftpoint H_orig, hyperpoint& ret, eModel md) { ret[3] = 1; break; } - if(vrhr::state == 2) { + if(vrhr::rendering()) { vr_disk(ret, H); return; } @@ -534,7 +534,7 @@ EX void apply_other_model(shiftpoint H_orig, hyperpoint& ret, eModel md) { } case mdHalfplane: { - if(sphere && vrhr::state == 2) { + if(sphere && vrhr::rendering()) { vr_sphere(ret, H, md); return; } @@ -682,7 +682,7 @@ EX void apply_other_model(shiftpoint H_orig, hyperpoint& ret, eModel md) { case mdHemisphere: { #if CAP_VR - ld dir = vrhr::state == 2 ? -1:1; + ld dir = vrhr::rendering() ? -1:1; #else constexpr ld dir = 1; #endif @@ -713,7 +713,7 @@ EX void apply_other_model(shiftpoint H_orig, hyperpoint& ret, eModel md) { } case gcSphere: { - if(vrhr::state == 2) { vr_sphere(ret, H, md); return; } + if(vrhr::rendering()) { vr_sphere(ret, H, md); return; } ret = H; if(pconf.depth_scaling != 1) { ld v = intval(H, Hypc); @@ -724,7 +724,7 @@ EX void apply_other_model(shiftpoint H_orig, hyperpoint& ret, eModel md) { } #if CAP_VR - if(vrhr::state == 2) { + if(vrhr::rendering()) { models::apply_vr(ret[2], ret[1]); return; } @@ -751,7 +751,7 @@ EX void apply_other_model(shiftpoint H_orig, hyperpoint& ret, eModel md) { } #if CAP_VR - if(vrhr::state == 2) { + if(vrhr::rendering()) { if(sphere) { vr_sphere(ret, H, md); return; } ret[0] = H[0] * pconf.hyperboloid_scaling; ret[1] = H[1] * pconf.hyperboloid_scaling; @@ -1718,7 +1718,7 @@ EX hyperpoint vertical_vector() { EX void spinEdge(ld aspd) { #if CAP_VR - if(vrhr::state && keep_vertical() && !vrhr::first) { + if(vrhr::active() && keep_vertical() && !vrhr::first) { transmatrix T = vrhr::hmd_ref_at; T = vrhr::sm * inverse(T); vrhr::be_33(T); @@ -2119,7 +2119,7 @@ EX color_t modelcolor = 0; EX void draw_model_elements() { #if CAP_VR - if(vrhr::state && pmodel == mdHyperboloid) return; + if(vrhr::active() && pmodel == mdHyperboloid) return; #endif dynamicval lw(vid.linewidth, vid.linewidth * vid.multiplier_ring); @@ -2256,7 +2256,7 @@ EX void draw_boundary(int w) { if(w == 1) return; if(nonisotropic || euclid || prod) return; #if CAP_VR - if(vrhr::state && pmodel == mdHyperboloid) return; + if(vrhr::active() && pmodel == mdHyperboloid) return; #endif dynamicval lw(vid.linewidth, vid.linewidth * vid.multiplier_ring); diff --git a/raycaster.cpp b/raycaster.cpp index 9967b183..646a036c 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -78,7 +78,7 @@ bool need_many_cell_types() { EX bool available() { #if CAP_VR /* would need a completely different implementation */ - if(vrhr::state && vrhr::eyes == vrhr::eEyes::equidistant) return false; + if(vrhr::active() && vrhr::eyes == vrhr::eEyes::equidistant) return false; #endif if(noGUI) return false; if(!vid.usingGL) return false; @@ -1340,7 +1340,7 @@ EX void cast() { cd->set_mask(global_projection); #if CAP_VR - if(vrhr::state == 2) { + if(vrhr::rendering_eye()) { glUniformMatrix4fv(o->uProjection, 1, 0, glhr::tmtogl_transpose3(vrhr::eyeproj).as_array()); } #else diff --git a/shaders.cpp b/shaders.cpp index 4f40f528..fa5f7d84 100644 --- a/shaders.cpp +++ b/shaders.cpp @@ -156,7 +156,7 @@ shared_ptr write_shader(flagtype shader_flags) { else if(!vid.consider_shader_projection) { shader_flags |= SF_PIXELS; } - else if(among(pmodel, mdDisk, mdBall) && GDIM == 2 && vrhr::state == 2 && !sphere) { + else if(among(pmodel, mdDisk, mdBall) && GDIM == 2 && vrhr::rendering() && !sphere) { shader_flags |= SF_DIRECT | SF_BOX; vsh += "uniform mediump float uAlpha, uDepth, uDepthScaling, uCamera;"; @@ -233,7 +233,7 @@ shared_ptr write_shader(flagtype shader_flags) { "mediump float ad = acosh(hz);\n" "mediump float m = d == 0. ? 0. : d >= 1. ? 1.e4 : (hz+1.) * ad / sinh(ad);\n"; #if CAP_VR - if(vrhr::state == 2) + if(vrhr::rendering_eye()) coordinator += "t.xyz *= ad/d;\n"; else #endif @@ -323,7 +323,7 @@ shared_ptr write_shader(flagtype shader_flags) { #if CAP_VR /* no z-fog in VR */ - if((shader_flags & SF_ZFOG) && vrhr::state == 2) + if((shader_flags & SF_ZFOG) && vrhr::rendering()) shader_flags &= ~SF_ZFOG; #endif @@ -338,7 +338,7 @@ shared_ptr write_shader(flagtype shader_flags) { vmain += coordinator; bool ok = true; #if CAP_VR - if(vrhr::state) ok = false; + if(vrhr::active()) ok = false; #endif if(GDIM == 3 && WDIM == 2 && hyperbolic && context_fog && ok && pmodel == mdPerspective) { vsh += @@ -509,7 +509,7 @@ void display_data::set_projection(int ed, ld shift) { glhr::new_projection(); #if CAP_VR - if(vrhr::state != 2) { + if(!vrhr::rendering_eye()) { #else if(true) { #endif @@ -554,7 +554,7 @@ void display_data::set_projection(int ed, ld shift) { if(shader_flags & SF_PIXELS) { #if CAP_VR - if(vrhr::state == 2) { + if(vrhr::rendering_eye()) { glhr::projection_multiply(glhr::tmtogl_transpose(vrhr::hmd_mvp)); glhr::id_modelview(); } @@ -564,7 +564,7 @@ void display_data::set_projection(int ed, ld shift) { } else if(shader_flags & SF_BOX) { #if CAP_VR - if(vrhr::state == 2) { + if(vrhr::rendering_eye()) { glhr::projection_multiply(glhr::tmtogl_transpose(vrhr::hmd_mvp)); glhr::id_modelview(); } @@ -578,7 +578,7 @@ void display_data::set_projection(int ed, ld shift) { } else if(shader_flags & SF_PERS3) { #if CAP_VR - if(vrhr::state == 2) { + if(vrhr::rendering_eye()) { glhr::projection_multiply(glhr::tmtogl_transpose(vrhr::hmd_mvp)); } #else @@ -736,7 +736,7 @@ EX flagtype get_shader_flags() { EX void glapplymatrix(const transmatrix& V) { #if CAP_VR transmatrix V3; - bool use_vr = vrhr::state; + bool use_vr = vrhr::rendering(); if(use_vr) V3 = vrhr::hmd_pre * V; const transmatrix& V2 = use_vr ? V3 : V; #else diff --git a/sky.cpp b/sky.cpp index 578ae95c..6f0e28ce 100644 --- a/sky.cpp +++ b/sky.cpp @@ -374,9 +374,7 @@ EX struct renderbuffer *airbuf; EX void make_air() { if(!sky) return; - #if CAP_VR - if(vrhr::state) return; - #endif + if(vrhr::active()) return; const int AIR_TEXTURE = 512; if(!airbuf) { airbuf = new renderbuffer(AIR_TEXTURE, AIR_TEXTURE, true); diff --git a/vr.cpp b/vr.cpp index 1d00bdfc..4ca8007a 100644 --- a/vr.cpp +++ b/vr.cpp @@ -10,8 +10,23 @@ namespace hr { EX namespace vrhr { +#if !CAP_VR +inline bool active() { return false; } +inline bool rendering() { return false; } +inline bool rendering_eye() { return false; } +#endif + #if CAP_VR +/** VR is active */ +EX bool active() { return state; } +/** called in drawqueue to see if we should switch to vrhr::render() */ +EX bool should_render() { return state == 1; } +/** currently rendering a VR-aware screen */ +EX bool rendering() { return state == 2 || state == 4; } +/** currently rendering a VR eye */ +EX bool rendering_eye() { return state == 2; } + #if HDR enum class eHeadset { none, rotation_only, reference, holonomy, model_viewing }; enum class eEyes { none, equidistant, truesim };