Forge: OpenCLCopy.hpp Source File

Forge

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

OpenCLCopy.hpp
Go to the documentation of this file.
1 /*******************************************************
2 * Copyright (c) 2015-2019, ArrayFire
3 * All rights reserved.
4 *
5 * This file is distributed under 3-clause BSD license.
6 * The complete license agreement can be obtained at:
7 * http://arrayfire.com/licenses/BSD-3-Clause
8 ********************************************************/
9
10 #ifndef __OPENCL_DATA_COPY_H__
11 #define __OPENCL_DATA_COPY_H__
12
13 namespace fg
14 {
15
16 static void copy(fg::Image& out, const cl::Buffer& in, const cl::CommandQueue& queue)
17 {
18 cl::BufferGL pboMapBuffer(queue.getInfo<CL_QUEUE_CONTEXT>(), CL_MEM_WRITE_ONLY, out.pbo(), NULL);
19
20 std::vector<cl::Memory> shared_objects;
21 shared_objects.push_back(pboMapBuffer);
22
23 glFinish();
24 queue.enqueueAcquireGLObjects(&shared_objects);
25 queue.enqueueCopyBuffer(in, pboMapBuffer, 0, 0, out.size(), NULL, NULL);
26 queue.finish();
27 queue.enqueueReleaseGLObjects(&shared_objects);
28 }
29
30 /*
31 * Below functions takes any renderable forge object that has following member functions
32 * defined
33 *
34 * `unsigned Renderable::vbo() const;`
35 * `unsigned Renderable::size() const;`
36 *
37 * Currently fg::Plot, fg::Histogram objects in Forge library fit the bill
38 */
39 template<class Renderable>
40 void copy(Renderable& out, const cl::Buffer& in, const cl::CommandQueue& queue)
41 {
42 cl::BufferGL vboMapBuffer(queue.getInfo<CL_QUEUE_CONTEXT>(), CL_MEM_WRITE_ONLY, out.vbo(), NULL);
43
44 std::vector<cl::Memory> shared_objects;
45 shared_objects.push_back(vboMapBuffer);
46
47 glFinish();
48 queue.enqueueAcquireGLObjects(&shared_objects);
49 queue.enqueueCopyBuffer(in, vboMapBuffer, 0, 0, out.size(), NULL, NULL);
50 queue.finish();
51 queue.enqueueReleaseGLObjects(&shared_objects);
52 }
53
54 }
55
56 #endif //__OPENCL_DATA_COPY_H__
fg
Definition: CPUCopy.hpp:13
fg::Image::size
FGAPI unsigned size() const
Get the OpenGL Pixel Buffer Object resource size.
fg::copy
void copy(fg::Image &out, const T *dataPtr)
Definition: CPUCopy.hpp:17
fg::Image::pbo
FGAPI unsigned pbo() const
Get the OpenGL Pixel Buffer Object identifier.
fg::Image
Definition: image.h:25