コード例 #1
0
 int                 getSamplesLog2  (void) const    { return popc8(m_numSamples - 1); } // log2(numSamples)
コード例 #2
0
ファイル: CudaSurface.cpp プロジェクト: venceslas/ocull
CudaSurface::CudaSurface(const Vec2i& size, Format format, int numSamples)
  : m_isMapped  (false),
    m_cudaArray (0)
{
  // Check parameters.
  if (min(size) <= 0) {
    fail("CudaSurface: Size must be positive!");
  }

  if (max(size) > CR_MAXVIEWPORT_SIZE) {
    fail("CudaSurface: CR_MAXVIEWPORT_SIZE exceeded!");
  }
  
  if (format < 0 || format >= NUM_FORMAT) {
    fail("CudaSurface: Invalid format!");
  }
  
  if (numSamples > 8) {
    fail("CudaSurface: numSamples cannot exceed 8!");
  }
  
  if (numSamples < 1 || popc8(numSamples) != 1) {
    fail("CudaSurface: numSamples must be a power of two!");
  }

  // Identify format.
  int glInternal, glFormat, glType;

  switch (format)
  {
    case FORMAT_RGBA8:    
      glInternal = GL_RGBA; 
      glFormat = GL_RGBA; 
      glType = GL_UNSIGNED_BYTE; 
    break;
    
    case FORMAT_DEPTH32:        
      glInternal = GL_LUMINANCE32UI_EXT; 
      glFormat = GL_LUMINANCE_INTEGER_EXT; 
      glType = GL_UNSIGNED_INT; 
    break;
    
    default:
      FW_ASSERT(false); 
    return;
  }

  // Initialize.
  m_size        = size;
  m_roundedSize = (size + CR_TILE_SIZE - 1) & -CR_TILE_SIZE;
  m_textureSize = m_roundedSize * Vec2i(numSamples, 1);
  m_format      = format;
  m_numSamples  = numSamples;

  // Create GL texture.
  glGenTextures(1, &m_glTexture);
  glBindTexture(GL_TEXTURE_2D, m_glTexture);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexImage2D(GL_TEXTURE_2D, 0, glInternal, m_textureSize.x, m_textureSize.y, 0, 
                              glFormat, glType, NULL);
  GLContext::checkErrors();

  // Register to CUDA.
  CudaModule::staticInit(); // 

  CUresult res = cuGraphicsGLRegisterImage( &m_cudaResource, 
                                            m_glTexture, 
                                            GL_TEXTURE_2D, 
                                            CU_GRAPHICS_REGISTER_FLAGS_SURFACE_LDST);
  CudaModule::checkError("cuGraphicsGLRegisterImage", res);
}