MeshLib C++ Docs
Loading...
Searching...
No Matches
MRViewportGL.h
Go to the documentation of this file.
1#pragma once
2#include "MRViewerFwd.h"
3#include "MRMesh/MRVector4.h"
4#include "MRMesh/MRVector2.h"
5#include "MRMesh/MRBox.h"
6#include "MRMesh/MRPlane3.h"
7#include "MRMesh/MRColor.h"
10
11#include <span>
12
13namespace MR
14{
15// colors of segment ends
17{
18 Vector4f a, b;
19};
20
21inline bool operator==( const SegmEndColors& a, const SegmEndColors& b )
22{
23 return a.a == b.a && a.b == b.b;
24}
25
26// stores points and corresponding colors (sizes of vectors should be the same)
28{
29 std::vector<Vector3f> points;
30 std::vector<Vector4f> colors;
31};
32
34{
35 return a.points == b.points && a.colors == b.colors;
36}
37
38// This class holds data needed to render viewport primitives and accumulative picker via OpenGL
40{
41public:
42 typedef unsigned int GLuint;
43 typedef float GLfloat;
44
45 ViewportGL() = default;
46 // Copy operators do nothing, not to share GL data
48 ViewportGL& operator = ( const ViewportGL& ) { return *this; }
49
50 MRVIEWER_API ViewportGL( ViewportGL&& other ) noexcept;
53
54 // Initialize all GL buffers and arrays
55 void init();
56 // Free all GL data
57 void free();
58
59 // Binds and draws viewport border
60 void drawBorder( const Box2f& rect, const Color& color ) const;
61
62 // Fills viewport with given color (clear frame buffer)
63 void fillViewport( const Box2f& rect, const Color& color ) const;
64
65 // Check that members have been initialized
66 bool checkInit() const;
67
68 // Parameters of objects picking
70 {
71 std::span<VisualObject* const> renderVector; // objects to pick
72 BaseRenderParams baseRenderParams; // parameters for rendering pick object
73 Plane3f clippingPlane; // viewport clip plane (it is not applied while object does not have clipping flag set)
74 };
76 {
77 unsigned geomId{ unsigned( -1 ) }; // id of picked object in PickParameters::renderVector (-1 means invalid)
78 unsigned primId{ unsigned( -1 ) }; // id of picked primitive (-1 means invalid)
79 // Note: for point clouds, primId is a point index after discretization
80 };
81 // Result of object picking
83 {
84 float zBuffer{1.0f}; // camera z coordinate of picked point (1.0f means far plane)
85 };
86 using PickResults = std::vector<PickResult>;
87 // Find picked object, face id and z coordinate, of objects given in parameters (works for vector of picks)
88 PickResults pickObjects( const PickParameters& params, const std::vector<Vector2i>& picks ) const;
89 // Find unique objects in given rect (return vector of ids of objects from params)
90 // if maxRenderResolutionSide less then current rect size, downscale rendering for better performance
91 std::vector<unsigned> findUniqueObjectsInRect( const PickParameters& params, const Box2i& rect,
92 int maxRenderResolutionSide ) const;
93
94 using BasePickResults = std::vector<BasePickResult>;
100 // Pick all pixels in rect
101 // if maxRenderResolutionSide less then current rect size, downscale rendering for better performance
102 ScaledPickRes pickObjectsInRect( const PickParameters& params, const Box2i& rect,
103 int maxRenderResolutionSide ) const;
104
105private:
106 struct PickColor
107 {
108 unsigned color[4];
109 };
110
111 struct PickTextureFrameBuffer
112 {
113 void resize( const Vector2i& size );
114 void del();
115 void bind( bool read );
116 private:
117 unsigned int framebuffer_{ 0 };
118 unsigned int colorTexture_{ 0 };
119 unsigned int renderbuffer_{ 0 };
120 Vector2i size_;
121 };
122 mutable PickTextureFrameBuffer pickFBO_;
123
124 std::vector<PickColor> pickObjectsInRect_( const PickParameters& params, const Box2i& rect ) const;
125
126 bool inited_ = false;
127
128 GLuint add_line_colors_vbo = 0;
129 GLuint add_line_vbo = 0;
130 GLuint add_line_vao = 0;
131
132 GLuint add_point_colors_vbo = 0;
133 GLuint add_point_vbo = 0;
134 GLuint add_point_vao = 0;
135
136 GLuint border_line_vbo = 0;
137 GLuint border_line_vao = 0;
138};
139
140}
Definition MRViewportGL.h:40
MRVIEWER_API ViewportGL(ViewportGL &&other) noexcept
std::vector< BasePickResult > BasePickResults
Definition MRViewportGL.h:94
unsigned int GLuint
Definition MRViewportGL.h:42
void fillViewport(const Box2f &rect, const Color &color) const
ViewportGL(const ViewportGL &)
Definition MRViewportGL.h:47
float GLfloat
Definition MRViewportGL.h:43
bool checkInit() const
std::vector< PickResult > PickResults
Definition MRViewportGL.h:86
ViewportGL()=default
PickResults pickObjects(const PickParameters &params, const std::vector< Vector2i > &picks) const
ViewportGL & operator=(const ViewportGL &)
Definition MRViewportGL.h:48
void drawBorder(const Box2f &rect, const Color &color) const
std::vector< unsigned > findUniqueObjectsInRect(const PickParameters &params, const Box2i &rect, int maxRenderResolutionSide) const
ScaledPickRes pickObjectsInRect(const PickParameters &params, const Box2i &rect, int maxRenderResolutionSide) const
MRMESH_API bool operator==(const BitSet &a, const BitSet &b)
compare that two bit sets have the same set bits (they can be equal even if sizes are distinct but la...
Definition MRCameraOrientationPlugin.h:8
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:29
Common rendering parameters for meshes and UI.
Definition MRIRenderObject.h:33
Definition MRMesh/MRColor.h:9
Definition MRViewportGL.h:17
Vector4f a
Definition MRViewportGL.h:18
Vector4f b
Definition MRViewportGL.h:18
Definition MRViewportGL.h:76
unsigned primId
Definition MRViewportGL.h:78
unsigned geomId
Definition MRViewportGL.h:77
Definition MRViewportGL.h:70
BaseRenderParams baseRenderParams
Definition MRViewportGL.h:72
std::span< VisualObject *const > renderVector
Definition MRViewportGL.h:71
Plane3f clippingPlane
Definition MRViewportGL.h:73
Definition MRViewportGL.h:83
float zBuffer
Definition MRViewportGL.h:84
Definition MRViewportGL.h:96
BasePickResults pickRes
Definition MRViewportGL.h:97
Box2i updatedBox
Definition MRViewportGL.h:98
Definition MRViewportGL.h:28
std::vector< Vector3f > points
Definition MRViewportGL.h:29
std::vector< Vector4f > colors
Definition MRViewportGL.h:30