]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | //---------------------------------------------------------------------------// |
2 | // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com> | |
3 | // | |
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 | |
7 | // | |
8 | // See http://boostorg.github.com/compute for more information. | |
9 | //---------------------------------------------------------------------------// | |
10 | ||
11 | #ifndef BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_RENDERBUFFER_HPP | |
12 | #define BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_RENDERBUFFER_HPP | |
13 | ||
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/type_traits/type_name.hpp> | |
18 | #include <boost/compute/utility/extents.hpp> | |
19 | ||
20 | namespace boost { | |
21 | namespace compute { | |
22 | ||
23 | /// \class opengl_renderbuffer | |
24 | /// | |
25 | /// A OpenCL buffer for accessing an OpenGL renderbuffer object. | |
26 | class opengl_renderbuffer : public image_object | |
27 | { | |
28 | public: | |
29 | /// Creates a null OpenGL renderbuffer object. | |
30 | opengl_renderbuffer() | |
31 | : image_object() | |
32 | { | |
33 | } | |
34 | ||
35 | /// Creates a new OpenGL renderbuffer object for \p mem. | |
36 | explicit opengl_renderbuffer(cl_mem mem, bool retain = true) | |
37 | : image_object(mem, retain) | |
38 | { | |
39 | } | |
40 | ||
41 | /// Creates a new OpenGL renderbuffer object in \p context for | |
42 | /// \p renderbuffer with \p flags. | |
43 | /// | |
44 | /// \see_opencl_ref{clCreateFromGLRenderbuffer} | |
45 | opengl_renderbuffer(const context &context, | |
46 | GLuint renderbuffer, | |
47 | cl_mem_flags flags = read_write) | |
48 | { | |
49 | cl_int error = 0; | |
50 | ||
51 | m_mem = clCreateFromGLRenderbuffer( | |
52 | context, flags, renderbuffer, &error | |
53 | ); | |
54 | ||
55 | if(!m_mem){ | |
56 | BOOST_THROW_EXCEPTION(opencl_error(error)); | |
57 | } | |
58 | } | |
59 | ||
60 | /// Creates a new OpenGL renderbuffer object as a copy of \p other. | |
61 | opengl_renderbuffer(const opengl_renderbuffer &other) | |
62 | : image_object(other) | |
63 | { | |
64 | } | |
65 | ||
66 | /// Copies the OpenGL renderbuffer object from \p other. | |
67 | opengl_renderbuffer& operator=(const opengl_renderbuffer &other) | |
68 | { | |
69 | if(this != &other){ | |
70 | image_object::operator=(other); | |
71 | } | |
72 | ||
73 | return *this; | |
74 | } | |
75 | ||
76 | /// Destroys the OpenGL buffer object. | |
77 | ~opengl_renderbuffer() | |
78 | { | |
79 | } | |
80 | ||
81 | /// Returns the size (width, height) of the renderbuffer. | |
82 | extents<2> size() const | |
83 | { | |
84 | extents<2> size; | |
85 | size[0] = get_image_info<size_t>(CL_IMAGE_WIDTH); | |
86 | size[1] = get_image_info<size_t>(CL_IMAGE_HEIGHT); | |
87 | return size; | |
88 | } | |
89 | ||
90 | /// Returns the origin of the renderbuffer (\c 0, \c 0). | |
91 | extents<2> origin() const | |
92 | { | |
93 | return extents<2>(); | |
94 | } | |
95 | ||
96 | /// Returns the OpenGL memory object ID. | |
97 | /// | |
98 | /// \see_opencl_ref{clGetGLObjectInfo} | |
99 | GLuint get_opengl_object() const | |
100 | { | |
101 | GLuint object = 0; | |
102 | clGetGLObjectInfo(m_mem, 0, &object); | |
103 | return object; | |
104 | } | |
105 | ||
106 | /// Returns the OpenGL memory object type. | |
107 | /// | |
108 | /// \see_opencl_ref{clGetGLObjectInfo} | |
109 | cl_gl_object_type get_opengl_type() const | |
110 | { | |
111 | cl_gl_object_type type; | |
112 | clGetGLObjectInfo(m_mem, &type, 0); | |
113 | return type; | |
114 | } | |
115 | }; | |
116 | ||
117 | namespace detail { | |
118 | ||
119 | // set_kernel_arg() specialization for opengl_renderbuffer | |
120 | template<> | |
121 | struct set_kernel_arg<opengl_renderbuffer> : public set_kernel_arg<image_object> { }; | |
122 | ||
123 | } // end detail namespace | |
124 | } // end compute namespace | |
125 | } // end boost namespace | |
126 | ||
127 | BOOST_COMPUTE_TYPE_NAME(boost::compute::opengl_renderbuffer, image2d_t) | |
128 | ||
129 | #endif // BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_RENDERBUFFER_HPP |