MRPT  2.0.4
CRenderizableShaderTexturedTriangles.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/img/CImage.h>
15 #include <mrpt/opengl/TTriangle.h>
16 
17 namespace mrpt::opengl
18 {
19 /** Renderizable generic renderer for objects using the triangles-with-a-texture
20  * shader.
21  *
22  * \sa CTexturedPlane, opengl::CSetOfTexturedTriangles
23  * \ingroup mrpt_opengl_grp
24  */
26 {
28 
29  public:
31  virtual ~CRenderizableShaderTexturedTriangles() override;
32 
33  virtual shader_list_t requiredShaders() const override
34  {
36  }
37  void render(const RenderContext& rc) const override;
38  void renderUpdateBuffers() const override;
39 
40  /** Must be implemented in derived classes to update the geometric entities
41  * to be drawn in "m_*_buffer" fields. */
42  virtual void onUpdateBuffers_TexturedTriangles() = 0;
43 
44  // See base docs
45  void freeOpenGLResources() override
46  {
48  m_vao.destroy();
49  }
50 
51  /** Assigns a texture and a transparency image, and enables transparency (If
52  * the images are not 2^N x 2^M, they will be internally filled to its
53  * dimensions to be powers of two)
54  * \note Images are copied, the original ones can be deleted.
55  */
56  void assignImage(
57  const mrpt::img::CImage& img, const mrpt::img::CImage& imgAlpha);
58 
59  /** Assigns a texture image, and disable transparency.
60  * \note Images are copied, the original ones can be deleted. */
61  void assignImage(const mrpt::img::CImage& img);
62 
63  /** Similar to assignImage, but the passed images are moved in (move
64  * semantic). */
65  void assignImage(mrpt::img::CImage&& img, mrpt::img::CImage&& imgAlpha);
66 
67  /** Similar to assignImage, but with move semantics. */
68  void assignImage(mrpt::img::CImage&& img);
69 
70  bool isLightEnabled() const { return m_enableLight; }
71  void enableLight(bool enable = true) { m_enableLight = enable; }
72 
73  /** VERY IMPORTANT: If you use a multi-thread application, you MUST call
74  * this from the same thread that will later destruct the object in order to
75  * the OpenGL texture memory to be correctly deleted.
76  * Calling this method more than once has no effects. If you use one
77  * thread, this method will be automatically called when rendering, so there
78  * is no need to explicitly call it.
79  */
80  virtual void initializeTextures() const override;
81 
83 
85  {
86  return m_textureImageAlpha;
87  }
88 
90 
91  /** Enable linear interpolation of textures (default=false, use nearest
92  * pixel) */
94  {
95  m_textureInterpolate = enable;
96  }
97 
98  /** @name Raw access to textured-triangle shader buffer data
99  * @{ */
100  const auto& shaderTexturedTrianglesBuffer() const { return m_triangles; }
101  /** @} */
102 
103  protected:
104  /** List of triangles \sa TTriangle */
105  mutable std::vector<mrpt::opengl::TTriangle> m_triangles;
106 
109 
110  private:
111  bool m_enableLight = false;
112 
113  mutable unsigned int m_glTextureName{0};
114  mutable bool m_texture_is_loaded{false};
118 
119  /** Of the texture using "m_textureImageAlpha" */
120  mutable bool m_enableTransparency{false};
121 
122  bool m_textureInterpolate = false;
123 
124  void unloadTexture();
125 
126  static unsigned int getNewTextureNumber();
127  static void releaseTextureName(unsigned int i);
128 
131 };
132 
133 } // namespace mrpt::opengl
bool m_enableTransparency
Of the texture using "m_textureImageAlpha".
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
static constexpr shader_id_t TEXTURED_TRIANGLES
A wrapper for an OpenGL vertex array object (VAO).
A wrapper for an OpenGL buffer object.
Definition: COpenGLBuffer.h:21
void enableTextureLinearInterpolation(bool enable)
Enable linear interpolation of textures (default=false, use nearest pixel)
void destroy()
Automatically called upon destructor, no need for the user to call it in normal situations.
Definition: COpenGLBuffer.h:68
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:48
void destroy()
Automatically called upon destructor, no need for the user to call it in normal situations.
std::vector< shader_id_t > shader_list_t
A list of shader IDs.
Definition: Shader.h:26
#define DEFINE_VIRTUAL_SERIALIZABLE(class_name)
This declaration must be inserted in virtual CSerializable classes definition:
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
virtual void onUpdateBuffers_TexturedTriangles()=0
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
virtual shader_list_t requiredShaders() const override
Returns the ID of the OpenGL shader program required to render this class.
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
mrpt::vision::TStereoCalibResults out
void writeToStreamTexturedObject(mrpt::serialization::CArchive &out) const
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
std::vector< mrpt::opengl::TTriangle > m_triangles
List of triangles.
virtual void initializeTextures() const override
VERY IMPORTANT: If you use a multi-thread application, you MUST call this from the same thread that w...
Renderizable generic renderer for objects using the triangles-with-a-texture shader.
void assignImage(const mrpt::img::CImage &img, const mrpt::img::CImage &imgAlpha)
Assigns a texture and a transparency image, and enables transparency (If the images are not 2^N x 2^M...
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:148



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020