File indexing completed on 2025-01-18 09:30:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_TEXTURE_HPP
0012 #define BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_TEXTURE_HPP
0013
0014 #include <boost/compute/image/image_object.hpp>
0015 #include <boost/compute/interop/opengl/gl.hpp>
0016 #include <boost/compute/interop/opengl/cl_gl.hpp>
0017 #include <boost/compute/detail/get_object_info.hpp>
0018 #include <boost/compute/type_traits/type_name.hpp>
0019 #include <boost/compute/utility/extents.hpp>
0020
0021 namespace boost {
0022 namespace compute {
0023
0024
0025
0026
0027 class opengl_texture : public image_object
0028 {
0029 public:
0030
0031 opengl_texture()
0032 : image_object()
0033 {
0034 }
0035
0036
0037 explicit opengl_texture(cl_mem mem, bool retain = true)
0038 : image_object(mem, retain)
0039 {
0040 }
0041
0042
0043
0044
0045
0046 opengl_texture(const context &context,
0047 GLenum texture_target,
0048 GLint miplevel,
0049 GLuint texture,
0050 cl_mem_flags flags = read_write)
0051 {
0052 cl_int error = 0;
0053
0054 #ifdef BOOST_COMPUTE_CL_VERSION_1_2
0055 m_mem = clCreateFromGLTexture(context,
0056 flags,
0057 texture_target,
0058 miplevel,
0059 texture,
0060 &error);
0061 #else
0062 m_mem = clCreateFromGLTexture2D(context,
0063 flags,
0064 texture_target,
0065 miplevel,
0066 texture,
0067 &error);
0068 #endif
0069
0070 if(!m_mem){
0071 BOOST_THROW_EXCEPTION(opencl_error(error));
0072 }
0073 }
0074
0075
0076 opengl_texture(const opengl_texture &other)
0077 : image_object(other)
0078 {
0079 }
0080
0081
0082 opengl_texture& operator=(const opengl_texture &other)
0083 {
0084 if(this != &other){
0085 image_object::operator=(other);
0086 }
0087
0088 return *this;
0089 }
0090
0091
0092 ~opengl_texture()
0093 {
0094 }
0095
0096
0097 extents<2> size() const
0098 {
0099 extents<2> size;
0100 size[0] = get_image_info<size_t>(CL_IMAGE_WIDTH);
0101 size[1] = get_image_info<size_t>(CL_IMAGE_HEIGHT);
0102 return size;
0103 }
0104
0105
0106 extents<2> origin() const
0107 {
0108 return extents<2>();
0109 }
0110
0111
0112
0113
0114 template<class T>
0115 T get_texture_info(cl_gl_texture_info info) const
0116 {
0117 return detail::get_object_info<T>(clGetGLTextureInfo, m_mem, info);
0118 }
0119 };
0120
0121 namespace detail {
0122
0123
0124 template<>
0125 struct set_kernel_arg<opengl_texture> : public set_kernel_arg<image_object> { };
0126
0127 }
0128 }
0129 }
0130
0131 BOOST_COMPUTE_TYPE_NAME(boost::compute::opengl_texture, image2d_t)
0132
0133 #endif