Easy3D 2.5.3
read_pixel.h
1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
27#ifndef EASY3D_RENDERER_OPENGL_READ_PIXEL_H
28#define EASY3D_RENDERER_OPENGL_READ_PIXEL_H
29
30#include <string>
31#include <vector>
32
33
34namespace easy3d {
35
36 namespace opengl {
37
38 // NOTE: For the multisample-version functions, a normal fbo will be created for bliting color/depth from the
39 // multisample framebuffer object. So for high-frequent queries, you'd better create a normal fbo for
40 // bliting operations. This way, you can avoid frequently allocating and deallocating GPU memories. But,
41 // do remember to do the cleaning when all queries are done.
42
43 // read color value at pixel (x, y) from current fbo.
44 // (x, y): the pixel coordinates, which are in the OpenGL coordinate system.
45 void read_color(unsigned char rgba[4], int x, int y);
46 void read_color_ms(int index, unsigned char rgba[4], int x, int y); // multisample framebuffer object
47
48 // read depth value at pixel (x, y) from current fbo.
49 // (x, y): the pixel coordinates, which are in the OpenGL coordinate system.
50 void read_depth(float& depth, int x, int y);
51 void read_depth_ms(float& depth, int x, int y); // multisample framebuffer object
52
53 // read the color data of the framebuffer into a specified buffer.
54 // format: format of the pixel data. The following formats are accepted: GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA.
55 void read_color(int index, std::vector<unsigned char>& buffer, unsigned int format, bool flip_vertically = true);
56 void read_color_ms(int index, std::vector<unsigned char>& buffer, unsigned int format, bool flip_vertically = true); // multisample framebuffer object
57
58 // read the depth data of the framebuffer into a specified buffer.
59 void read_depth(std::vector<float>& buffer, bool flip_vertically = true);
60 void read_depth_ms(std::vector<float>& buffer, bool flip_vertically = true); // multisample framebuffer object
61
63
64 // snapshot the color render buffer attached to color attachment index into an image file.
65 // This is very useful for debugging.
66 // Only png, jpg, bmp, tga, ppm are supported. File format is determined by the given extension.
67 void snapshot_color(const std::string& file_name);
68 void snapshot_color_ms(int index, const std::string& file_name); // multisample framebuffer object
69
70 // snapshot the depth render buffer into an image file. This is very useful for debugging.
71 // Only png, jpg, bmp, tga, ppm are supported. File format is determined by the given extension.
72 void snapshot_depth(const std::string& file_name);
73 void snapshot_depth_ms(const std::string& file_name); // multisample framebuffer object
74
75 }
76
77}
78
79#endif // EASY3D_RENDERER_OPENGL_READ_PIXEL_H
80
81
Definition: collider.cpp:182