Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:37

0001 #pragma once
0002 /**
0003 SGLFW_CUDA.h : Coordinate SCUDA_OutputBuffer and SGLDisplay for display of interop buffers
0004 ===========================================================================================
0005 
0006 
0007 **/
0008 
0009 
0010 #include "SCU.h"
0011 #include "SCUDA_OutputBuffer.h"
0012 #include "SGLDisplay.h"
0013 
0014 struct SGLFW_CUDA
0015 {
0016     SGLM& gm ; 
0017     SCUDA_OutputBuffer<uchar4>* output_buffer ; 
0018     SGLDisplay* gl_display ; 
0019 
0020     SGLFW_CUDA(SGLM& gm); 
0021     void init();
0022 
0023     void fillOutputBuffer(); 
0024     void displayOutputBuffer(GLFWwindow* window);
0025 }; 
0026 
0027 inline SGLFW_CUDA::SGLFW_CUDA(SGLM& _gm)
0028     :
0029     gm(_gm),
0030     output_buffer( nullptr ), 
0031     gl_display( nullptr )
0032 {
0033     init();
0034 }
0035 
0036 inline void SGLFW_CUDA::init()
0037 {
0038     output_buffer = new SCUDA_OutputBuffer<uchar4>( SCUDA_OutputBufferType::GL_INTEROP, gm.Width(), gm.Height() ) ; 
0039     //std::cout << "SGLFW_CUDA::init output_buffer.desc " << output_buffer->desc() ; 
0040     gl_display = new SGLDisplay ; 
0041     //std::cout << "SGLFW_CUDA::init gl_display.desc " << gl_display->desc() ; 
0042 }
0043 
0044 
0045 extern void SGLFW_CUDA__fillOutputBuffer( dim3 numBlocks, dim3 threadsPerBlock, uchar4* output_buffer, int width, int height ); 
0046 /**
0047 SGLFW_CUDA::fillOutputBuffer
0048 ----------------------------
0049 
0050 Unused ? In anycase intended for debug ? 
0051 
0052 **/
0053 inline void SGLFW_CUDA::fillOutputBuffer()
0054 {
0055     dim3 numBlocks ; 
0056     dim3 threadsPerBlock ; 
0057     SCU::ConfigureLaunch2D(numBlocks, threadsPerBlock, output_buffer->width(), output_buffer->height() );   
0058 
0059     SGLFW_CUDA__fillOutputBuffer(numBlocks, threadsPerBlock, 
0060          output_buffer->map(), 
0061          output_buffer->width(), 
0062          output_buffer->height() );           
0063 
0064     output_buffer->unmap();
0065     CUDA_SYNC_CHECK();
0066 }
0067 
0068 /**
0069 SGLFW_CUDA::displayOutputBuffer
0070 --------------------------------
0071 
0072 Primary method, eg called from render loop of CSGOptiX/tests/CSGOptiXRenderInteractiveTest.cc 
0073 
0074 This enables OpenGL presentation of GPU buffer writted by CUDA/OptiX
0075 
0076 **/
0077 
0078 inline void SGLFW_CUDA::displayOutputBuffer(GLFWwindow* window)
0079 {
0080     // Display
0081     int framebuf_res_x = 0;   // The display's resolution (could be HDPI res)
0082     int framebuf_res_y = 0;   //  
0083     glfwGetFramebufferSize( window, &framebuf_res_x, &framebuf_res_y );
0084 
0085     gl_display->display(
0086             output_buffer->width(),
0087             output_buffer->height(),
0088             framebuf_res_x,
0089             framebuf_res_y,
0090             output_buffer->getPBO()
0091             );  
0092 }
0093