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_BUFFER_HPP
0012 #define BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_BUFFER_HPP
0013
0014 #include <boost/compute/buffer.hpp>
0015 #include <boost/compute/interop/opengl/gl.hpp>
0016 #include <boost/compute/interop/opengl/cl_gl.hpp>
0017
0018 namespace boost {
0019 namespace compute {
0020
0021
0022
0023
0024 class opengl_buffer : public buffer
0025 {
0026 public:
0027
0028 opengl_buffer()
0029 : buffer()
0030 {
0031 }
0032
0033
0034 explicit opengl_buffer(cl_mem mem, bool retain = true)
0035 : buffer(mem, retain)
0036 {
0037 }
0038
0039
0040
0041
0042
0043 opengl_buffer(const context &context,
0044 GLuint bufobj,
0045 cl_mem_flags flags = read_write)
0046 {
0047 cl_int error = 0;
0048 m_mem = clCreateFromGLBuffer(context, flags, bufobj, &error);
0049 if(!m_mem){
0050 BOOST_THROW_EXCEPTION(opencl_error(error));
0051 }
0052 }
0053
0054
0055 opengl_buffer(const opengl_buffer &other)
0056 : buffer(other)
0057 {
0058 }
0059
0060
0061 opengl_buffer& operator=(const opengl_buffer &other)
0062 {
0063 if(this != &other){
0064 buffer::operator=(other);
0065 }
0066
0067 return *this;
0068 }
0069
0070
0071 ~opengl_buffer()
0072 {
0073 }
0074
0075
0076
0077
0078 GLuint get_opengl_object() const
0079 {
0080 GLuint object = 0;
0081 clGetGLObjectInfo(m_mem, 0, &object);
0082 return object;
0083 }
0084
0085
0086
0087
0088 cl_gl_object_type get_opengl_type() const
0089 {
0090 cl_gl_object_type type;
0091 clGetGLObjectInfo(m_mem, &type, 0);
0092 return type;
0093 }
0094 };
0095
0096 namespace detail {
0097
0098
0099 template<>
0100 struct set_kernel_arg<opengl_buffer> : set_kernel_arg<memory_object> { };
0101
0102 }
0103 }
0104 }
0105
0106 #endif