MRPT  1.9.9
CTexturedObject.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef opengl_CTexturedObject_H
10 #define opengl_CTexturedObject_H
11 
13 #include <mrpt/img/CImage.h>
14 #include <mrpt/math/geometry.h>
15 
16 namespace mrpt::opengl
17 {
18 /** A base class for all OpenGL objects with loadable textures.
19  * \sa opengl::COpenGLScene, opengl::CTexturedPlane,
20  * opengl::CSetOfTexturedTriangles
21  * \ingroup mrpt_opengl_grp
22  */
24 {
26 
27  protected:
28  mutable unsigned int m_glTextureName{0};
29  mutable bool m_texture_is_loaded{false};
32  /** Of the texture using "m_textureImageAlpha" */
33  mutable bool m_enableTransparency{false};
34  /** Size of the texture image, rounded up to next power of 2 */
35  mutable int r_width{0}, r_height{0};
36  /** The size of the fill in pixels in the textured image, w.r.t the image
37  * passed by the user. */
38  mutable int m_pad_x_right{0}, m_pad_y_bottom{0};
39 
40  virtual ~CTexturedObject();
41  void unloadTexture();
42 
43  virtual void render_pre() const;
44  virtual void render_post() const;
45 
46  /** Must be implemented by derived classes */
47  virtual void render_texturedobj() const = 0;
48 
51 
52  public:
53  /** Assigns a texture and a transparency image, and enables transparency (If
54  * the images are not 2^N x 2^M, they will be internally filled to its
55  * dimensions to be powers of two)
56  * \note Images are copied, the original ones can be deleted.
57  */
58  void assignImage(
59  const mrpt::img::CImage& img, const mrpt::img::CImage& imgAlpha);
60 
61  /** Assigns a texture image, and disable transparency.
62  * \note Images are copied, the original ones can be deleted. */
63  void assignImage(const mrpt::img::CImage& img);
64 
65  /** Similar to assignImage, but the passed images will be returned as empty:
66  * it avoids making a copy of the whole image, just copies a pointer. */
68 
69  /** Similar to assignImage, but the passed images will be returned as empty:
70  * it avoids making a copy of the whole image, just copies a pointer. */
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  void loadTextureInOpenGL() const;
81 
82  virtual void render_dl() const override;
83 };
84 
85 }
86 #endif
87 
88 
virtual void render_post() const
A base class for all OpenGL objects with loadable textures.
virtual 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:3763
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:52
mrpt::img::CImage m_textureImage
GLuint in
Definition: glext.h:7274
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:130



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020