summaryrefslogtreecommitdiff
path: root/tangle/util/texture.h
diff options
context:
space:
mode:
Diffstat (limited to 'tangle/util/texture.h')
-rw-r--r--tangle/util/texture.h25
1 files changed, 25 insertions, 0 deletions
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 <cstring>
+#include <SFML/Graphics.hpp>
+#include <cuda_gl_interop.h>
+#include <LLBM/memory.h>
+
+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;
+}