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 "MRRenderGLHelpers.h"
4#include "MRMesh/MRVector4.h"
5#include "MRMesh/MRVector2.h"
6#include "MRMesh/MRBox.h"
7#include "MRMesh/MRPlane3.h"
8#include "MRMesh/MRColor.h"
11
12#include <span>
13
14namespace MR
15{
18
19
22{
23public:
24 typedef unsigned int GLuint;
25 typedef float GLfloat;
26
27 ViewportGL() = default;
30 ViewportGL& operator = ( const ViewportGL& ) { return *this; }
31
32 MRVIEWER_API ViewportGL( ViewportGL&& other ) noexcept;
35
37 void init();
39 void free();
40
42 void drawBorder( const Box2f& rect, const Color& color ) const;
43
45 void fillViewport( const Box2f& rect, const Color& color ) const;
46
49 void drawBackgroundTexture( const Box2f& rect, const MeshTexture& texture, const Box2f& texRect, bool refresh );
51 void freeBackgroundTexture() { background_texture.del(); }
52
54 bool checkInit() const;
55
64 {
65 unsigned geomId{ unsigned( -1 ) };
66 unsigned primId{ unsigned( -1 ) };
68 };
69
71 {
72 float zBuffer{1.0f};
73 };
74 using PickResults = std::vector<PickResult>;
76 PickResults pickObjects( const PickParameters& params, const std::vector<Vector2i>& picks ) const;
79 std::vector<unsigned> findUniqueObjectsInRect( const PickParameters& params, const Box2i& rect,
80 int maxRenderResolutionSide ) const;
81
82 using BasePickResults = std::vector<BasePickResult>;
88
90 ScaledPickRes pickObjectsInRect( const PickParameters& params, const Box2i& rect,
91 int maxRenderResolutionSide ) const;
92
93private:
94 struct PickColor
95 {
96 unsigned color[4];
97 };
98
99 struct PickTextureFrameBuffer
100 {
101 void resize( const Vector2i& size );
102 void del();
103 void bind( bool read );
104 private:
105 unsigned int framebuffer_{ 0 };
106 unsigned int colorTexture_{ 0 };
107 unsigned int renderbuffer_{ 0 };
108 Vector2i size_;
109 };
110 mutable PickTextureFrameBuffer pickFBO_;
111
112 std::vector<PickColor> pickObjectsInRect_( const PickParameters& params, const Box2i& rect ) const;
113
114 bool inited_ = false;
115
116 GLuint add_line_colors_vbo = 0;
117 GLuint add_line_vbo = 0;
118 GLuint add_line_vao = 0;
119
120 GLuint add_point_colors_vbo = 0;
121 GLuint add_point_vbo = 0;
122 GLuint add_point_vao = 0;
123
124 GLuint border_line_vbo = 0;
125 GLuint border_line_vao = 0;
126
127 GLuint background_vbo = 0;
128 GLuint background_vao = 0;
129 GlTexture2 background_texture;
130};
131
132}
BasePickResults pickRes
Definition MRViewportGL.h:85
unsigned primId
id of picked object in PickParameters::renderVector (-1 means invalid)
Definition MRViewportGL.h:66
Box2i updatedBox
Definition MRViewportGL.h:86
std::vector< BasePickResult > BasePickResults
Definition MRViewportGL.h:82
unsigned int GLuint
Definition MRViewportGL.h:24
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:59
void fillViewport(const Box2f &rect, const Color &color) const
Fills viewport with given color (clear frame buffer)
ViewportGL(const ViewportGL &)
Copy operators do nothing, not to share GL data.
Definition MRViewportGL.h:29
float GLfloat
Definition MRViewportGL.h:25
bool checkInit() const
Check that members have been initialized.
BaseRenderParams baseRenderParams
objects to pick
Definition MRViewportGL.h:60
float zBuffer
Definition MRViewportGL.h:72
Plane3f
Definition MRMeshFwd.h:391
std::vector< PickResult > PickResults
Definition MRViewportGL.h:74
void freeBackgroundTexture()
Frees GL memory of the background texture.
Definition MRViewportGL.h:51
ViewportGL()=default
unsigned color[4]
Definition MRViewportGL.h:96
void resize(const Vector2i &size)
unsigned geomId
Definition MRViewportGL.h:65
PickResults pickObjects(const PickParameters &params, const std::vector< Vector2i > &picks) const
Find picked object, face id and z coordinate, of objects given in parameters (works for vector of pic...
void init()
Initialize all GL buffers and arrays.
ViewportGL(ViewportGL &&other) noexcept
void drawBackgroundTexture(const Box2f &rect, const MeshTexture &texture, const Box2f &texRect, bool refresh)
void free()
Free all GL data.
ViewportGL & operator=(const ViewportGL &)
Definition MRViewportGL.h:30
std::span< VisualObject *const > renderVector
Definition MRViewportGL.h:59
void drawBorder(const Box2f &rect, const Color &color) const
Binds and draws viewport border.
std::vector< unsigned > findUniqueObjectsInRect(const PickParameters &params, const Box2i &rect, int maxRenderResolutionSide) const
ScaledPickRes pickObjectsInRect(const PickParameters &params, const Box2i &rect, int maxRenderResolutionSide) const
Plane3f clippingPlane
parameters for rendering pick object
Definition MRViewportGL.h:61
@ other
Angle, normally float. Measure in radians.
Definition MRFeatureObject.h:27
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
Common rendering parameters for meshes and UI.
Definition MRIRenderObject.h:36
Definition MRColor.h:12
Definition MRMeshTexture.h:13
Definition MRViewportGL.h:64
Parameters of objects picking.
Definition MRViewportGL.h:58
Result of object picking.
Definition MRViewportGL.h:71
Definition MRViewportGL.h:84