31 #define TEXTUREOBJ_USE_MEMPOOL 34 #ifdef TEXTUREOBJ_USE_MEMPOOL 38 struct CTexturedObject_MemPoolParams
43 inline bool isSuitable(
const CTexturedObject_MemPoolParams& req)
const 45 return len == req.len;
50 vector<unsigned char>
data;
63 m_texture_is_loaded(false),
64 m_enableTransparency(false)
150 #ifdef TEXTUREOBJ_USE_MEMPOOL 154 CTexturedObject_MemPoolParams mem_params;
155 mem_params.len =
len;
177 #if MRPT_HAS_OPENGL_GLUT 178 unsigned char* dataAligned =
nullptr;
179 vector<unsigned char>
data;
181 #ifdef TEXTUREOBJ_PROFILE_MEM_ALLOC 241 #ifdef TEXTUREOBJ_PROFILE_MEM_ALLOC 244 "opengl_texture: load %ix%i %s %stransp",
width,
height,
247 tim.
enter(sSec.c_str());
274 #ifdef TEXTUREOBJ_PROFILE_MEM_ALLOC 276 "opengl_texture_alloc %ix%i (color,trans)",
width,
height);
277 tim.
enter(sSec.c_str());
282 #ifdef TEXTUREOBJ_PROFILE_MEM_ALLOC 283 tim.
leave(sSec.c_str());
290 unsigned char* ptr = dataAligned +
y *
width * 4;
294 *ptr++ = *ptrSrcCol++;
295 *ptr++ = *ptrSrcCol++;
296 *ptr++ = *ptrSrcCol++;
297 *ptr++ = *ptrSrcAlfa++;
303 const bool is_RGB_order =
314 height, 0 , img_format, img_type, dataAligned);
330 const bool is_RGB_order =
334 const GLenum img_format = nBytesPerPixel == 3
345 height, 0 , img_format, img_type,
360 #ifdef TEXTUREOBJ_PROFILE_MEM_ALLOC 362 "opengl_texture_alloc %ix%i (gray,transp)",
width,
height);
363 tim.
enter(sSec.c_str());
369 #ifdef TEXTUREOBJ_PROFILE_MEM_ALLOC 370 tim.
leave(sSec.c_str());
377 unsigned char* ptr = dataAligned +
y *
width * 2;
380 *ptr++ = *ptrSrcCol++;
381 *ptr++ = *ptrSrcAlfa++;
394 height, 0 , img_format, img_type, dataAligned);
415 height, 0 , img_format, img_type,
429 #ifdef TEXTUREOBJ_PROFILE_MEM_ALLOC 432 "opengl_texture: load %ix%i %s %stransp",
width,
height,
435 tim.
leave(sSec.c_str());
439 #ifdef TEXTUREOBJ_USE_MEMPOOL 446 CTexturedObject_MemPoolParams mem_params;
447 mem_params.len =
data.size();
504 #if MRPT_HAS_OPENGL_GLUT 507 std::cerr <<
"render_pre: Error" << std::endl;
510 std::cerr <<
"render_texturedobj: Error" << std::endl;
513 std::cerr <<
"render_post: Error" << std::endl;
519 #if MRPT_HAS_OPENGL_GLUT 545 #if MRPT_HAS_OPENGL_GLUT
virtual void render_post() const
void assignImage(const mrpt::utils::CImage &img, const mrpt::utils::CImage &imgAlpha)
Assigns a texture and a transparency image, and enables transparency (If the images are not 2^N x 2^M...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
#define GL_TEXTURE_WRAP_T
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
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.
GLAPI void GLAPIENTRY glEnable(GLenum cap)
A class for storing images as grayscale or RGB bitmaps.
void copyFastFrom(CImage &o)
Moves an image from another object, erasing the origin image in the process (this is much faster than...
#define THROW_EXCEPTION(msg)
virtual ~CTexturedObject()
const char * getChannelsOrder() const
Returns a string of the form "BGR","RGB" or "GRAY" indicating the channels ordering.
void dump_to_pool(const DATA_PARAMS ¶ms, POOLABLE_DATA *block)
Saves the passed data block (characterized by params) to the pool.
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...
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
#define GL_ONE_MINUS_SRC_ALPHA
int r_width
Size of the texture image, rounded up to next power of 2.
POOLABLE_DATA * request_memory(const DATA_PARAMS ¶ms)
Request a block of data which fulfils the size requirements stated in params.
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
A renderizable object suitable for rendering with OpenGL's display lists.
GLAPI void GLAPIENTRY glTexParameterf(GLenum target, GLenum pname, GLfloat param)
A generic system for versatile memory pooling.
GLAPI void GLAPIENTRY glBindTexture(GLenum target, GLuint texture)
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
vector< unsigned char > data
This base provides a set of functions for maths stuff.
size_t getWidth() const override
Returns the width of the image in pixels.
IMPLEMENTS_VIRTUAL_SERIALIZABLE(CTexturedObject, CRenderizableDisplayList, mrpt::opengl) struct CTexturedObject_MemPoolParams
bool m_enableTransparency
Of the texture using "m_textureImageAlpha".
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
size_t getHeight() const override
Returns the height of the image in pixels.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
mrpt::utils::TColor m_color
Color components in the range [0,255].
size_t getRowStride() const
Returns the row stride of the image: this is the number of bytes between two consecutive rows...
unsigned int m_glTextureName
virtual void render_pre() const
void writeToStreamTexturedObject(mrpt::utils::CStream &out) const
void assignImage_fast(mrpt::utils::CImage &img, mrpt::utils::CImage &imgAlpha)
Similar to assignImage, but the passed images will be returned as empty: it avoids making a copy of t...
GLsizei const GLchar ** string
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
virtual void render_texturedobj() const =0
Must be implemented by derived classes.
unsigned char * reserveDataBuffer(const size_t len, vector< unsigned char > &data)
static void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define GL_UNPACK_ROW_LENGTH
#define GL_TEXTURE_MIN_FILTER
#define GL_UNPACK_ALIGNMENT
static unsigned int getNewTextureNumber()
Returns the lowest next free texture name (avoid using OpenGL's own function since we may call them f...
unsigned long POINTER_TYPE
For performing type casting from a pointer to its numeric value.
#define GL_TEXTURE_MAG_FILTER
mrpt::utils::CImage m_textureImage
CImage scaleHalf() const
Returns a new image scaled down to half its original size.
GLAPI void GLAPIENTRY glGetIntegerv(GLenum pname, GLint *params)
GLAPI GLenum GLAPIENTRY glGetError(void)
The namespace for 3D scene representation and rendering.
A versatile "profiler" that logs the time spent within each pair of calls to enter(X)-leave(X), among other stats.
double leave(const char *func_name)
End of a named section.
mrpt::system::CGenericMemoryPool< CTexturedObject_MemPoolParams, CTexturedObject_MemPoolData > TMyMemPool
bool isColor() const
Returns true if the image is RGB, false if it is grayscale.
unsigned char * get_unsafe(unsigned int col, unsigned int row, unsigned int channel=0) const
Access to pixels without checking boundaries - Use normally the () operator better, which checks the coordinates.
#define GL_MAX_TEXTURE_SIZE
#define GL_LUMINANCE_ALPHA
void loadTextureInOpenGL() const
VERY IMPORTANT: If you use a multi-thread application, you MUST call this from the same thread that w...
GLenum GLsizei GLsizei height
void enter(const char *func_name)
Start of a named section.
GLAPI void GLAPIENTRY glDisable(GLenum cap)
GLsizei GLsizei GLenum GLenum const GLvoid * data
GLAPI void GLAPIENTRY glPixelStorei(GLenum pname, GLint param)
#define GL_TEXTURE_WRAP_S
static void releaseTextureName(unsigned int i)
GLAPI void GLAPIENTRY glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
mrpt::utils::CImage m_textureImageAlpha
void readFromStreamTexturedObject(mrpt::utils::CStream &in)
static CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA > * getInstance(const size_t max_pool_entries=5)
Construct-on-first-use (~singleton) pattern: Return the unique instance of this class for a given tem...