MRPT  1.9.9
CTexturedObject.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-2019, 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>
12 #include <mrpt/math/geometry.h>
14 
15 namespace mrpt::opengl
16 {
17 /** A base class for all OpenGL objects with loadable textures.
18  * \sa opengl::COpenGLScene, opengl::CTexturedPlane,
19  * opengl::CSetOfTexturedTriangles
20  * \ingroup mrpt_opengl_grp
21  */
23 {
25 
26  protected:
27  mutable unsigned int m_glTextureName{0};
28  mutable bool m_texture_is_loaded{false};
31  /** Of the texture using "m_textureImageAlpha" */
32  mutable bool m_enableTransparency{false};
33  /** Size of the texture image, rounded up to next power of 2 */
34  mutable int r_width{0}, r_height{0};
35  /** The size of the fill in pixels in the textured image, w.r.t the image
36  * passed by the user. */
37  mutable int m_pad_x_right{0}, m_pad_y_bottom{0};
38 
39  ~CTexturedObject() override;
40  void unloadTexture();
41 
42  virtual void render_pre() const;
43  virtual void render_post() const;
44 
45  /** Must be implemented by derived classes */
46  virtual void render_texturedobj() const = 0;
47 
50 
51  public:
52  /** Assigns a texture and a transparency image, and enables transparency (If
53  * the images are not 2^N x 2^M, they will be internally filled to its
54  * dimensions to be powers of two)
55  * \note Images are copied, the original ones can be deleted.
56  */
57  void assignImage(
58  const mrpt::img::CImage& img, const mrpt::img::CImage& imgAlpha);
59 
60  /** Assigns a texture image, and disable transparency.
61  * \note Images are copied, the original ones can be deleted. */
62  void assignImage(const mrpt::img::CImage& img);
63 
64  /** Similar to assignImage, but the passed images will be returned as empty:
65  * it avoids making a copy of the whole image, just copies a pointer. */
67 
68  /** Similar to assignImage, but the passed images will be returned as empty:
69  * it avoids making a copy of the whole image, just copies a pointer. */
71 
72  /** VERY IMPORTANT: If you use a multi-thread application, you MUST call
73  * this from the same thread that will later destruct the object in order to
74  * the OpenGL texture memory to be correctly deleted.
75  * Calling this method more than once has no effects. If you use one
76  * thread, this method will be automatically called when rendering, so there
77  * is no need to explicitly call it.
78  */
79  void loadTextureInOpenGL() const;
80 
81  void render_dl() const override;
82 };
83 
84 } // namespace mrpt::opengl
virtual void render_post() const
A base class for all OpenGL objects with loadable textures.
void render_dl() const override
Derived classes must implement this method to the render the object.
int m_pad_x_right
The size of the fill in pixels in the textured image, w.r.t the image passed by the user...
int r_width
Size of the texture image, rounded up to next power of 2.
void assignImage_fast(mrpt::img::CImage &img, mrpt::img::CImage &imgAlpha)
Similar to assignImage, but the passed images will be returned as empty: it avoids making a copy of t...
#define DEFINE_VIRTUAL_SERIALIZABLE(class_name)
This declaration must be inserted in virtual CSerializable classes definition:
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
bool m_enableTransparency
Of the texture using "m_textureImageAlpha".
GLint GLvoid * img
Definition: glext.h:3769
virtual void render_pre() const
virtual void render_texturedobj() const =0
Must be implemented by derived classes.
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:53
mrpt::img::CImage m_textureImage
GLuint in
Definition: glext.h:7391
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
void readFromStreamTexturedObject(mrpt::serialization::CArchive &in)
mrpt::img::CImage m_textureImageAlpha
void loadTextureInOpenGL() const
VERY IMPORTANT: If you use a multi-thread application, you MUST call this from the same thread that w...
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...
void writeToStreamTexturedObject(mrpt::serialization::CArchive &out) const
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:147



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019