123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- #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 : public image_object
- {
- public:
-
- opengl_texture()
- : image_object()
- {
- }
-
- explicit opengl_texture(cl_mem mem, bool retain = true)
- : image_object(mem, retain)
- {
- }
-
-
-
-
- opengl_texture(const context &context,
- GLenum texture_target,
- GLint miplevel,
- GLuint texture,
- cl_mem_flags flags = read_write)
- {
- cl_int error = 0;
- #ifdef BOOST_COMPUTE_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));
- }
- }
-
- opengl_texture(const opengl_texture &other)
- : image_object(other)
- {
- }
-
- opengl_texture& operator=(const opengl_texture &other)
- {
- if(this != &other){
- image_object::operator=(other);
- }
- return *this;
- }
-
- ~opengl_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;
- }
-
- extents<2> origin() const
- {
- return extents<2>();
- }
-
-
-
- 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 {
- template<>
- struct set_kernel_arg<opengl_texture> : public set_kernel_arg<image_object> { };
- }
- }
- }
- BOOST_COMPUTE_TYPE_NAME(boost::compute::opengl_texture, image2d_t)
- #endif
|