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_RENDERBUFFER_HPP
0012 #define BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_RENDERBUFFER_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/type_traits/type_name.hpp>
0018 #include <boost/compute/utility/extents.hpp>
0019
0020 namespace boost {
0021 namespace compute {
0022
0023
0024
0025
0026 class opengl_renderbuffer : public image_object
0027 {
0028 public:
0029
0030 opengl_renderbuffer()
0031 : image_object()
0032 {
0033 }
0034
0035
0036 explicit opengl_renderbuffer(cl_mem mem, bool retain = true)
0037 : image_object(mem, retain)
0038 {
0039 }
0040
0041
0042
0043
0044
0045 opengl_renderbuffer(const context &context,
0046 GLuint renderbuffer,
0047 cl_mem_flags flags = read_write)
0048 {
0049 cl_int error = 0;
0050
0051 m_mem = clCreateFromGLRenderbuffer(
0052 context, flags, renderbuffer, &error
0053 );
0054
0055 if(!m_mem){
0056 BOOST_THROW_EXCEPTION(opencl_error(error));
0057 }
0058 }
0059
0060
0061 opengl_renderbuffer(const opengl_renderbuffer &other)
0062 : image_object(other)
0063 {
0064 }
0065
0066
0067 opengl_renderbuffer& operator=(const opengl_renderbuffer &other)
0068 {
0069 if(this != &other){
0070 image_object::operator=(other);
0071 }
0072
0073 return *this;
0074 }
0075
0076
0077 ~opengl_renderbuffer()
0078 {
0079 }
0080
0081
0082 extents<2> size() const
0083 {
0084 extents<2> size;
0085 size[0] = get_image_info<size_t>(CL_IMAGE_WIDTH);
0086 size[1] = get_image_info<size_t>(CL_IMAGE_HEIGHT);
0087 return size;
0088 }
0089
0090
0091 extents<2> origin() const
0092 {
0093 return extents<2>();
0094 }
0095
0096
0097
0098
0099 GLuint get_opengl_object() const
0100 {
0101 GLuint object = 0;
0102 clGetGLObjectInfo(m_mem, 0, &object);
0103 return object;
0104 }
0105
0106
0107
0108
0109 cl_gl_object_type get_opengl_type() const
0110 {
0111 cl_gl_object_type type;
0112 clGetGLObjectInfo(m_mem, &type, 0);
0113 return type;
0114 }
0115 };
0116
0117 namespace detail {
0118
0119
0120 template<>
0121 struct set_kernel_arg<opengl_renderbuffer> : public set_kernel_arg<image_object> { };
0122
0123 }
0124 }
0125 }
0126
0127 BOOST_COMPUTE_TYPE_NAME(boost::compute::opengl_renderbuffer, image2d_t)
0128
0129 #endif