| 641 | CHECK_CUDART_ERROR(cudart.cudaGraphicsUnmapResources(1, self.cu_tex, torch.cuda.current_stream().cuda_stream)) |
| 642 | |
| 643 | def upload_to_texture(self, ptr: np.ndarray, x: int = 0, y: int = 0, w: int = 0, h: int = 0): |
| 644 | w = w or self.W |
| 645 | h = h or self.H |
| 646 | if isinstance(ptr, torch.Tensor): |
| 647 | ptr = ptr.detach().cpu().numpy() # slow sync and copy operation # MARK: SYNC |
| 648 | |
| 649 | gl.glBindTexture(gl.GL_TEXTURE_2D, self.tex) |
| 650 | gl.glTexSubImage2D(gl.GL_TEXTURE_2D, 0, x, y, w, h, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, ptr) # to gpu, might slow down? |
| 651 | |
| 652 | @property |
| 653 | def verts_data(self): # a heavy copy operation |