CUDA/OpenGL interop, draw to OpenGL texture with CUDA

前端 未结 1 1116
梦如初夏
梦如初夏 2020-12-29 10:13

I am writing a rendering system in CUDA and want results to be quickly displayed via OpenGL, without touching main memory. I basically do the following:

Create and i

1条回答
  •  伪装坚强ぢ
    2020-12-29 10:39

    It seems interop requires to re-register textures upon resize. The following works:

    void resize() {
        glViewport(0, 0, view.getWidth(), view.getHeight());
    
            // unregister
        cudaGraphicsUnregisterResource(viewCudaResource);
            // resize
        glBindTexture(GL_TEXTURE_2D, viewGLTexture);
        {
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, view.getWidth(), view.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
        }
        glBindTexture(GL_TEXTURE_2D, 0);
            // register back
        cudaGraphicsGLRegisterImage(&viewCudaResource, viewGLTexture, GL_TEXTURE_2D, cudaGraphicsRegisterFlagsWriteDiscard);
    }
    

    0 讨论(0)
提交回复
热议问题