Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #pragma once
0002 
0003 #include "sppm.h"
0004 
0005 struct SOPTIX_Pixels
0006 {
0007     const SGLM& gm ;
0008     size_t num_pixel ; 
0009     size_t num_bytes ; 
0010     uchar4* d_pixels ;
0011     uchar4* pixels ; 
0012 
0013     SOPTIX_Pixels(const SGLM& gm ); 
0014     void init(); 
0015 
0016     void download(); 
0017     void save_ppm(const char* path); 
0018 };
0019 
0020 inline SOPTIX_Pixels::SOPTIX_Pixels(const SGLM& _gm )
0021     :
0022     gm(_gm),
0023     num_pixel(gm.Width_Height()),
0024     num_bytes(num_pixel*sizeof(uchar4)),
0025     d_pixels(nullptr),
0026     pixels(new uchar4[num_pixel]) 
0027 {
0028     init(); 
0029 } 
0030 
0031 inline void SOPTIX_Pixels::init()
0032 {
0033     CUDA_CHECK( cudaMalloc(reinterpret_cast<void**>( &d_pixels ), num_bytes )); 
0034 } 
0035 inline void SOPTIX_Pixels::download() 
0036 {
0037     CUDA_CHECK( cudaMemcpy( pixels, reinterpret_cast<void*>(d_pixels), num_bytes, cudaMemcpyDeviceToHost ));
0038 }    
0039 inline void SOPTIX_Pixels::save_ppm(const char* path)
0040 {
0041     bool yflip = true ; 
0042     int ncomp = 4 ; 
0043     sppm::Write(path, gm.Width(), gm.Height(), ncomp, (unsigned char*)pixels, yflip );  
0044 }
0045