summaryrefslogtreecommitdiff
path: root/boost/compute/interop/opengl/opengl_texture.hpp
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2016-10-06 10:38:45 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2016-10-06 10:39:52 +0900
commit5cde13f21d36c7224b0e13d11c4b49379ae5210d (patch)
treee8269ac85a4b0f7d416e2565fa4f451b5cb41351 /boost/compute/interop/opengl/opengl_texture.hpp
parentd9ec475d945d3035377a0d89ed42e382d8988891 (diff)
downloadboost-5cde13f21d36c7224b0e13d11c4b49379ae5210d.tar.gz
boost-5cde13f21d36c7224b0e13d11c4b49379ae5210d.tar.bz2
boost-5cde13f21d36c7224b0e13d11c4b49379ae5210d.zip
Imported Upstream version 1.61.0
Change-Id: I96a1f878d1e6164f01e9aadd5147f38fca448d90 Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'boost/compute/interop/opengl/opengl_texture.hpp')
-rw-r--r--boost/compute/interop/opengl/opengl_texture.hpp133
1 files changed, 133 insertions, 0 deletions
diff --git a/boost/compute/interop/opengl/opengl_texture.hpp b/boost/compute/interop/opengl/opengl_texture.hpp
new file mode 100644
index 0000000000..c1f3f4f441
--- /dev/null
+++ b/boost/compute/interop/opengl/opengl_texture.hpp
@@ -0,0 +1,133 @@
+//---------------------------------------------------------------------------//
+// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
+//
+// Distributed under the Boost Software License, Version 1.0
+// See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+//
+// See http://boostorg.github.com/compute for more information.
+//---------------------------------------------------------------------------//
+
+#ifndef BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_TEXTURE_HPP
+#define BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_TEXTURE_HPP
+
+#include <boost/compute/image/image_object.hpp>
+#include <boost/compute/interop/opengl/gl.hpp>
+#include <boost/compute/interop/opengl/cl_gl.hpp>
+#include <boost/compute/detail/get_object_info.hpp>
+#include <boost/compute/type_traits/type_name.hpp>
+#include <boost/compute/utility/extents.hpp>
+
+namespace boost {
+namespace compute {
+
+/// \class opengl_texture
+///
+/// A OpenCL image2d for accessing an OpenGL texture object.
+class opengl_texture : public image_object
+{
+public:
+ /// Creates a null OpenGL texture object.
+ opengl_texture()
+ : image_object()
+ {
+ }
+
+ /// Creates a new OpenGL texture object for \p mem.
+ explicit opengl_texture(cl_mem mem, bool retain = true)
+ : image_object(mem, retain)
+ {
+ }
+
+ /// Creates a new OpenGL texture object in \p context for \p texture
+ /// with \p flags.
+ ///
+ /// \see_opencl_ref{clCreateFromGLTexture}
+ opengl_texture(const context &context,
+ GLenum texture_target,
+ GLint miplevel,
+ GLuint texture,
+ cl_mem_flags flags = read_write)
+ {
+ cl_int error = 0;
+
+ #ifdef CL_VERSION_1_2
+ m_mem = clCreateFromGLTexture(context,
+ flags,
+ texture_target,
+ miplevel,
+ texture,
+ &error);
+ #else
+ m_mem = clCreateFromGLTexture2D(context,
+ flags,
+ texture_target,
+ miplevel,
+ texture,
+ &error);
+ #endif
+
+ if(!m_mem){
+ BOOST_THROW_EXCEPTION(opencl_error(error));
+ }
+ }
+
+ /// Creates a new OpenGL texture object as a copy of \p other.
+ opengl_texture(const opengl_texture &other)
+ : image_object(other)
+ {
+ }
+
+ /// Copies the OpenGL texture object from \p other.
+ opengl_texture& operator=(const opengl_texture &other)
+ {
+ if(this != &other){
+ image_object::operator=(other);
+ }
+
+ return *this;
+ }
+
+ /// Destroys the texture object.
+ ~opengl_texture()
+ {
+ }
+
+ /// Returns the size (width, height) of the texture.
+ extents<2> size() const
+ {
+ extents<2> size;
+ size[0] = get_image_info<size_t>(CL_IMAGE_WIDTH);
+ size[1] = get_image_info<size_t>(CL_IMAGE_HEIGHT);
+ return size;
+ }
+
+ /// Returns the origin of the texture (\c 0, \c 0).
+ extents<2> origin() const
+ {
+ return extents<2>();
+ }
+
+ /// Returns information about the texture.
+ ///
+ /// \see_opencl_ref{clGetGLTextureInfo}
+ template<class T>
+ T get_texture_info(cl_gl_texture_info info) const
+ {
+ return detail::get_object_info<T>(clGetGLTextureInfo, m_mem, info);
+ }
+};
+
+namespace detail {
+
+// set_kernel_arg() specialization for opengl_texture
+template<>
+struct set_kernel_arg<opengl_texture> : public set_kernel_arg<image_object> { };
+
+} // end detail namespace
+} // end compute namespace
+} // end boost namespace
+
+BOOST_COMPUTE_TYPE_NAME(boost::compute::opengl_texture, image2d_t)
+
+#endif // BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_TEXTURE_HPP