forked from arrayfire/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage.cpp
More file actions
52 lines (41 loc) · 1.38 KB
/
image.cpp
File metadata and controls
52 lines (41 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
// Parts of this code sourced from SnopyDogy
// https://gist.github.com/SnopyDogy/a9a22497a893ec86aa3e
#include <Array.hpp>
#include <common/graphics_common.hpp>
#include <err_cpu.hpp>
#include <image.hpp>
#include <platform.hpp>
#include <queue.hpp>
namespace cpu {
template<typename T>
void copy_image(const Array<T> &in, fg_image image) {
ForgeModule &_ = graphics::forgePlugin();
CheckGL("Before CopyArrayToImage");
const T *d_X = in.get();
getQueue().sync();
unsigned data_size = 0, buffer = 0;
FG_CHECK(_.fg_get_pixel_buffer(&buffer, image));
FG_CHECK(_.fg_get_image_size(&data_size, image));
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer);
glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, data_size, d_X);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
CheckGL("In CopyArrayToImage");
}
#define INSTANTIATE(T) template void copy_image<T>(const Array<T> &, fg_image);
INSTANTIATE(float)
INSTANTIATE(double)
INSTANTIATE(int)
INSTANTIATE(uint)
INSTANTIATE(uchar)
INSTANTIATE(char)
INSTANTIATE(ushort)
INSTANTIATE(short)
} // namespace cpu