From 4ec94c97879aafef15f7663135745e4ba61e62cf Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 17 May 2021 00:15:33 +0200 Subject: Extract first public LiterateLB version --- tangle/util/texture.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tangle/util/texture.h (limited to 'tangle/util/texture.h') diff --git a/tangle/util/texture.h b/tangle/util/texture.h new file mode 100644 index 0000000..f2e0440 --- /dev/null +++ b/tangle/util/texture.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include +#include +#include + +cudaSurfaceObject_t bindTextureToCuda(sf::Texture& texture) { + GLuint gl_tex_handle = texture.getNativeHandle(); + cudaGraphicsResource* cuda_tex_handle; + cudaArray* buffer; + + cudaGraphicsGLRegisterImage(&cuda_tex_handle, gl_tex_handle, GL_TEXTURE_2D, cudaGraphicsRegisterFlagsNone); + cudaGraphicsMapResources(1, &cuda_tex_handle, 0); + cudaGraphicsSubResourceGetMappedArray(&buffer, cuda_tex_handle, 0, 0); + + cudaResourceDesc resDesc; + resDesc.resType = cudaResourceTypeArray; + + resDesc.res.array.array = buffer; + cudaSurfaceObject_t cudaSurfaceObject = 0; + cudaCreateSurfaceObject(&cudaSurfaceObject, &resDesc); + + return cudaSurfaceObject; +} -- cgit v1.2.3