]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/compute/include/boost/compute/interop/opengl/opengl_buffer.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / compute / include / boost / compute / interop / opengl / opengl_buffer.hpp
CommitLineData
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_BUFFER_HPP
12#define BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_BUFFER_HPP
13
14#include <boost/compute/buffer.hpp>
15#include <boost/compute/interop/opengl/gl.hpp>
16#include <boost/compute/interop/opengl/cl_gl.hpp>
17
18namespace boost {
19namespace compute {
20
21/// \class opengl_buffer
22///
23/// A OpenCL buffer for accessing an OpenGL memory object.
24class opengl_buffer : public buffer
25{
26public:
27 /// Creates a null OpenGL buffer object.
28 opengl_buffer()
29 : buffer()
30 {
31 }
32
33 /// Creates a new OpenGL buffer object for \p mem.
34 explicit opengl_buffer(cl_mem mem, bool retain = true)
35 : buffer(mem, retain)
36 {
37 }
38
39 /// Creates a new OpenGL buffer object in \p context for \p bufobj
40 /// with \p flags.
41 ///
42 /// \see_opencl_ref{clCreateFromGLBuffer}
43 opengl_buffer(const context &context,
44 GLuint bufobj,
45 cl_mem_flags flags = read_write)
46 {
47 cl_int error = 0;
48 m_mem = clCreateFromGLBuffer(context, flags, bufobj, &error);
49 if(!m_mem){
50 BOOST_THROW_EXCEPTION(opencl_error(error));
51 }
52 }
53
54 /// Creates a new OpenGL buffer object as a copy of \p other.
55 opengl_buffer(const opengl_buffer &other)
56 : buffer(other)
57 {
58 }
59
60 /// Copies the OpenGL buffer object from \p other.
61 opengl_buffer& operator=(const opengl_buffer &other)
62 {
63 if(this != &other){
64 buffer::operator=(other);
65 }
66
67 return *this;
68 }
69
70 /// Destroys the OpenGL buffer object.
71 ~opengl_buffer()
72 {
73 }
74
75 /// Returns the OpenGL memory object ID.
76 ///
77 /// \see_opencl_ref{clGetGLObjectInfo}
78 GLuint get_opengl_object() const
79 {
80 GLuint object = 0;
81 clGetGLObjectInfo(m_mem, 0, &object);
82 return object;
83 }
84
85 /// Returns the OpenGL memory object type.
86 ///
87 /// \see_opencl_ref{clGetGLObjectInfo}
88 cl_gl_object_type get_opengl_type() const
89 {
90 cl_gl_object_type type;
91 clGetGLObjectInfo(m_mem, &type, 0);
92 return type;
93 }
94};
95
96namespace detail {
97
98// set_kernel_arg specialization for opengl_buffer
99template<>
100struct set_kernel_arg<opengl_buffer> : set_kernel_arg<memory_object> { };
101
102} // end detail namespace
103} // end compute namespace
104} // end boost namespace
105
106#endif // BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_BUFFER_HPP