1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_TEXTURE_HPP
12 #define BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_TEXTURE_HPP
14 #include <boost/compute/image/image_object.hpp>
15 #include <boost/compute/interop/opengl/gl.hpp>
16 #include <boost/compute/interop/opengl/cl_gl.hpp>
17 #include <boost/compute/detail/get_object_info.hpp>
18 #include <boost/compute/type_traits/type_name.hpp>
19 #include <boost/compute/utility/extents.hpp>
24 /// \class opengl_texture
26 /// A OpenCL image2d for accessing an OpenGL texture object.
27 class opengl_texture : public image_object
30 /// Creates a null OpenGL texture object.
36 /// Creates a new OpenGL texture object for \p mem.
37 explicit opengl_texture(cl_mem mem, bool retain = true)
38 : image_object(mem, retain)
42 /// Creates a new OpenGL texture object in \p context for \p texture
45 /// \see_opencl_ref{clCreateFromGLTexture}
46 opengl_texture(const context &context,
47 GLenum texture_target,
50 cl_mem_flags flags = read_write)
54 #ifdef BOOST_COMPUTE_CL_VERSION_1_2
55 m_mem = clCreateFromGLTexture(context,
62 m_mem = clCreateFromGLTexture2D(context,
71 BOOST_THROW_EXCEPTION(opencl_error(error));
75 /// Creates a new OpenGL texture object as a copy of \p other.
76 opengl_texture(const opengl_texture &other)
81 /// Copies the OpenGL texture object from \p other.
82 opengl_texture& operator=(const opengl_texture &other)
85 image_object::operator=(other);
91 /// Destroys the texture object.
96 /// Returns the size (width, height) of the texture.
97 extents<2> size() const
100 size[0] = get_image_info<size_t>(CL_IMAGE_WIDTH);
101 size[1] = get_image_info<size_t>(CL_IMAGE_HEIGHT);
105 /// Returns the origin of the texture (\c 0, \c 0).
106 extents<2> origin() const
111 /// Returns information about the texture.
113 /// \see_opencl_ref{clGetGLTextureInfo}
115 T get_texture_info(cl_gl_texture_info info) const
117 return detail::get_object_info<T>(clGetGLTextureInfo, m_mem, info);
123 // set_kernel_arg() specialization for opengl_texture
125 struct set_kernel_arg<opengl_texture> : public set_kernel_arg<image_object> { };
127 } // end detail namespace
128 } // end compute namespace
129 } // end boost namespace
131 BOOST_COMPUTE_TYPE_NAME(boost::compute::opengl_texture, image2d_t)
133 #endif // BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_TEXTURE_HPP