File indexing completed on 2026-04-10 07:49:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 #include "ssys.h"
0038 #include "stree.h"
0039 #include "OPTICKS_LOG.hh"
0040 #include "SEventConfig.hh"
0041 #include "CSGFoundry.h"
0042 #include "CSGOptiX.h"
0043 #include "SGLFW.h"
0044 #include "SGLFW_CUDA.h"
0045 #include "SGLFW_Evt.h"
0046
0047 #include "SScene.h"
0048
0049
0050
0051 struct CSGOptiXRenderInteractiveTest
0052 {
0053 static constexpr const char* _level = "CSGOptiXRenderInteractiveTest__level" ;
0054 static constexpr const char* _ALLOW_REMOTE = "CSGOptiXRenderInteractiveTest__ALLOW_REMOTE" ;
0055 static int Initialize(bool allow_remote);
0056
0057 int level ;
0058 bool ALLOW_REMOTE ;
0059 int irc ;
0060
0061 SRecord* ar ;
0062 SRecord* br ;
0063
0064 CSGFoundry* fd ;
0065 SGLM* gm ;
0066 CSGOptiX* cx ;
0067
0068 SGLFW* gl ;
0069 SGLFW_CUDA* interop ;
0070 SGLFW_Evt* glev ;
0071
0072 CSGOptiXRenderInteractiveTest();
0073
0074 void init();
0075
0076 void handle_snap_cx();
0077 void optix_render_to_buffer();
0078 void display_optix_buffer();
0079 void optix_render();
0080
0081 std::string desc() const ;
0082 };
0083
0084
0085 inline int CSGOptiXRenderInteractiveTest::Initialize(bool allow_remote)
0086 {
0087 SEventConfig::SetRGModeRender();
0088 bool is_remote_session = ssys::is_remote_session();
0089 if(is_remote_session && allow_remote == false )
0090 {
0091 std::cout << "CSGOptiXRenderInteractiveTest::Initialize : ABORTING : as detected remote session from SSH_TTY SSH_CLIENT \n";
0092 std::cout << "to override : export " << _ALLOW_REMOTE << "=1 ## warning have see gnome-shell crash with Wayland \n" ;
0093 return 1 ;
0094 }
0095 return 0 ;
0096 }
0097
0098
0099 inline CSGOptiXRenderInteractiveTest::CSGOptiXRenderInteractiveTest()
0100 :
0101 level(ssys::getenvint(_level,0)),
0102 ALLOW_REMOTE(ssys::getenvbool(_ALLOW_REMOTE)),
0103 irc(Initialize(ALLOW_REMOTE)),
0104 ar(SRecord::Load("$AFOLD", "$AFOLD_RECORD_SLICE")),
0105 br(SRecord::Load("$BFOLD", "$BFOLD_RECORD_SLICE")),
0106 fd(CSGFoundry::Load()),
0107 gm(new SGLM),
0108 cx(nullptr),
0109 gl(nullptr),
0110 interop(nullptr),
0111 glev(nullptr)
0112 {
0113 init();
0114 }
0115
0116 inline void CSGOptiXRenderInteractiveTest::init()
0117 {
0118 assert( irc == 0 );
0119 assert(fd);
0120 stree* tree = fd->getTree();
0121 assert(tree);
0122 SScene* scene = fd->getScene() ;
0123 assert(scene);
0124 gm->setTreeScene(tree, scene);
0125 gm->setRecord(ar, br);
0126
0127 cx = CSGOptiX::Create(fd) ;
0128 gl = new SGLFW(*gm);
0129 interop = new SGLFW_CUDA(*gm);
0130 glev = new SGLFW_Evt(*gl);
0131
0132 if(gl->level > 0) std::cout << "CSGOptiXRenderInteractiveTest::init before render loop gl.get_wanted_frame_idx " << gl->get_wanted_frame_idx() << "\n" ;
0133 if(level > 0) std::cout << "CSGOptiXRenderInteractiveTest::init [" << _level << "][" << level << "]\n" << desc() ;
0134
0135 }
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147 inline void CSGOptiXRenderInteractiveTest::handle_snap_cx()
0148 {
0149 int wanted_snap = gl->get_wanted_snap();
0150 if(cx->handle_snap(wanted_snap)) gl->set_wanted_snap(0);
0151 }
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166 inline void CSGOptiXRenderInteractiveTest::optix_render_to_buffer()
0167 {
0168 uchar4* d_pixels = interop->output_buffer->map() ;
0169 cx->setExternalDevicePixels(d_pixels);
0170 cx->render_launch();
0171 interop->output_buffer->unmap() ;
0172 }
0173
0174 inline void CSGOptiXRenderInteractiveTest::display_optix_buffer()
0175 {
0176 interop->displayOutputBuffer(gl->window);
0177 }
0178
0179
0180 inline void CSGOptiXRenderInteractiveTest::optix_render()
0181 {
0182 handle_snap_cx();
0183 optix_render_to_buffer();
0184 display_optix_buffer();
0185 }
0186
0187 inline std::string CSGOptiXRenderInteractiveTest::desc() const
0188 {
0189 std::stringstream ss ;
0190 ss
0191 << "[CSGOptiXRenderInteractiveTest::desc\n"
0192 << " ar\n" << ( ar ? ar->desc() : "-" ) << "\n"
0193 << " br\n" << ( br ? br->desc() : "-" ) << "\n"
0194 << "]CSGOptiXRenderInteractiveTest::desc\n"
0195 ;
0196 std::string str = ss.str() ;
0197 return str ;
0198 }
0199
0200
0201
0202 int main(int argc, char** argv)
0203 {
0204 OPTICKS_LOG(argc, argv);
0205
0206 CSGOptiXRenderInteractiveTest t ;
0207
0208 SGLFW* gl = t.gl ;
0209
0210 while(gl->renderloop_proceed())
0211 {
0212 gl->renderloop_head();
0213 gl->handle_frame_hop();
0214
0215 if(gl->gm.option.O) t.optix_render();
0216 t.glev->render();
0217
0218 gl->renderloop_tail();
0219 }
0220 return 0 ;
0221 }
0222