Go to the documentation of this file.
32 #define TEXTUREOBJ_USE_MEMPOOL
35 #ifdef TEXTUREOBJ_USE_MEMPOOL
39 struct CTexturedObject_MemPoolParams
44 inline bool isSuitable(
const CTexturedObject_MemPoolParams& req)
const
46 return len == req.len;
51 vector<unsigned char>
data;
68 m_textureImageAlpha = imgAlpha;
70 m_enableTransparency =
true;
89 m_enableTransparency =
false;
106 m_textureImage.copyFastFrom(
img);
107 m_textureImageAlpha.copyFastFrom(imgAlpha);
109 m_enableTransparency =
true;
126 m_textureImage.copyFastFrom(
img);
128 m_enableTransparency =
false;
137 #ifdef TEXTUREOBJ_USE_MEMPOOL
141 CTexturedObject_MemPoolParams mem_params;
142 mem_params.len =
len;
155 void* ptr = &
data[0];
157 return reinterpret_cast<unsigned char*
>(
158 std::align(16, 1 , ptr, space));
166 #if MRPT_HAS_OPENGL_GLUT
167 unsigned char* dataAligned =
nullptr;
168 vector<unsigned char>
data;
170 #ifdef TEXTUREOBJ_PROFILE_MEM_ALLOC
176 if (m_texture_is_loaded)
186 m_glTextureName = getNewTextureNumber();
220 while (m_textureImage.getHeight() > (
unsigned int)texSize ||
221 m_textureImage.getWidth() > (
unsigned int)texSize)
223 m_textureImage = m_textureImage.scaleHalf();
224 m_textureImageAlpha = m_textureImageAlpha.scaleHalf();
227 const int width = m_textureImage.getWidth();
228 const int height = m_textureImage.getHeight();
230 #ifdef TEXTUREOBJ_PROFILE_MEM_ALLOC
233 "opengl_texture: load %ix%i %s %stransp",
width,
height,
234 m_textureImage.isColor() ?
"RGB" :
"BW",
235 m_enableTransparency ?
"" :
"no ");
236 tim.
enter(sSec.c_str());
244 m_pad_x_right = (r_width -
width);
245 m_pad_y_bottom = (r_height -
height);
247 if (m_enableTransparency)
249 ASSERT_(!m_textureImageAlpha.isColor());
251 m_textureImageAlpha.getWidth() == m_textureImage.getWidth());
253 m_textureImageAlpha.getHeight() == m_textureImage.getHeight());
256 if (m_textureImage.isColor())
259 if (m_enableTransparency)
263 #ifdef TEXTUREOBJ_PROFILE_MEM_ALLOC
265 "opengl_texture_alloc %ix%i (color,trans)",
width,
height);
266 tim.
enter(sSec.c_str());
271 #ifdef TEXTUREOBJ_PROFILE_MEM_ALLOC
272 tim.
leave(sSec.c_str());
277 unsigned char* ptrSrcCol = m_textureImage(0,
y, 0);
278 unsigned char* ptrSrcAlfa = m_textureImageAlpha(0,
y);
279 unsigned char* ptr = dataAligned +
y *
width * 4;
283 *ptr++ = *ptrSrcCol++;
284 *ptr++ = *ptrSrcCol++;
285 *ptr++ = *ptrSrcCol++;
286 *ptr++ = *ptrSrcAlfa++;
292 const bool is_RGB_order = (!::strcmp(
293 m_textureImage.getChannelsOrder(),
302 height, 0 , img_format, img_type, dataAligned);
317 const int nBytesPerPixel = m_textureImage.isColor() ? 3 : 1;
318 const bool is_RGB_order = (!::strcmp(
319 m_textureImage.getChannelsOrder(),
321 const GLenum img_format = nBytesPerPixel == 3
329 m_textureImage.getRowStride() / nBytesPerPixel);
332 height, 0 , img_format, img_type,
333 m_textureImage.get_unsafe(0, 0));
345 if (m_enableTransparency)
347 #ifdef TEXTUREOBJ_PROFILE_MEM_ALLOC
349 "opengl_texture_alloc %ix%i (gray,transp)",
width,
height);
350 tim.
enter(sSec.c_str());
356 #ifdef TEXTUREOBJ_PROFILE_MEM_ALLOC
357 tim.
leave(sSec.c_str());
362 unsigned char* ptrSrcCol = m_textureImage(0,
y);
363 unsigned char* ptrSrcAlfa = m_textureImageAlpha(0,
y);
364 unsigned char* ptr = dataAligned +
y *
width * 2;
367 *ptr++ = *ptrSrcCol++;
368 *ptr++ = *ptrSrcAlfa++;
381 height, 0 , img_format, img_type, dataAligned);
402 height, 0 , img_format, img_type,
403 m_textureImage(0, 0));
414 m_texture_is_loaded =
true;
416 #ifdef TEXTUREOBJ_PROFILE_MEM_ALLOC
419 "opengl_texture: load %ix%i %s %stransp",
width,
height,
420 m_textureImage.isColor() ?
"RGB" :
"BW",
421 m_enableTransparency ?
"" :
"no ");
422 tim.
leave(sSec.c_str());
426 #ifdef TEXTUREOBJ_USE_MEMPOOL
433 CTexturedObject_MemPoolParams mem_params;
434 mem_params.len =
data.size();
448 format(
"m_glTextureName=%i\n%s", m_glTextureName, e.what()));
466 if (m_texture_is_loaded)
468 m_texture_is_loaded =
false;
469 releaseTextureName(m_glTextureName);
480 out << m_enableTransparency;
481 out << m_textureImage;
482 if (m_enableTransparency) out << m_textureImageAlpha;
487 #if MRPT_HAS_OPENGL_GLUT
490 std::cerr <<
"render_pre: Error" << std::endl;
491 render_texturedobj();
493 std::cerr <<
"render_texturedobj: Error" << std::endl;
496 std::cerr <<
"render_post: Error" << std::endl;
502 #if MRPT_HAS_OPENGL_GLUT
507 if (m_enableTransparency || m_color.A != 255)
521 loadTextureInOpenGL();
528 #if MRPT_HAS_OPENGL_GLUT
531 if (m_enableTransparency || m_color.A != 255)
561 in >> m_enableTransparency;
562 in >> m_textureImage;
563 if (m_enableTransparency)
565 in >> m_textureImageAlpha;
566 assignImage(m_textureImage, m_textureImageAlpha);
570 assignImage(m_textureImage);
virtual void render_pre() const
POOLABLE_DATA * request_memory(const DATA_PARAMS ¶ms)
Request a block of data which fulfils the size requirements stated in params.
void dump_to_pool(const DATA_PARAMS ¶ms, POOLABLE_DATA *block)
Saves the passed data block (characterized by params) to the pool.
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 GL_MAX_TEXTURE_SIZE
A versatile "profiler" that logs the time spent within each pair of calls to enter(X)-leave(X),...
void readFromStreamTexturedObject(mrpt::serialization::CArchive &in)
GLAPI void GLAPIENTRY glPixelStorei(GLenum pname, GLint param)
#define GL_LUMINANCE_ALPHA
A renderizable object suitable for rendering with OpenGL's display lists.
virtual void render_post() const
GLAPI void GLAPIENTRY glDisable(GLenum cap)
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated)
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...
GLAPI void GLAPIENTRY glEnable(GLenum cap)
virtual void render_dl() const override
Derived classes must implement this method to the render the object.
A generic system for versatile memory pooling.
GLAPI void GLAPIENTRY glTexParameterf(GLenum target, GLenum pname, GLfloat param)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLAPI void GLAPIENTRY glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
void loadTextureInOpenGL() const
VERY IMPORTANT: If you use a multi-thread application, you MUST call this from the same thread that w...
#define THROW_EXCEPTION(msg)
#define ASSERT_(f)
Defines an assertion mechanism.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
void enter(const char *func_name)
Start of a named section.
virtual ~CTexturedObject()
Virtual base class for "archives": classes abstracting I/O streams.
double leave(const char *func_name)
End of a named section.
GLsizei GLsizei GLenum GLenum const GLvoid * data
void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
#define GL_ONE_MINUS_SRC_ALPHA
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
vector< unsigned char > data
A base class for all OpenGL objects with loadable textures.
#define GL_UNPACK_ALIGNMENT
#define GL_TEXTURE_MAG_FILTER
GLenum GLsizei GLsizei height
GLAPI void GLAPIENTRY glGetIntegerv(GLenum pname, GLint *params)
A class for storing images as grayscale or RGB bitmaps.
unsigned char * reserveDataBuffer(const size_t len, vector< unsigned char > &data)
This base provides a set of functions for maths stuff.
void writeToStreamTexturedObject(mrpt::serialization::CArchive &out) const
GLsizei const GLchar ** string
#define GL_TEXTURE_WRAP_T
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...
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
#define GL_TEXTURE_MIN_FILTER
The namespace for 3D scene representation and rendering.
#define GL_UNPACK_ROW_LENGTH
IMPLEMENTS_VIRTUAL_SERIALIZABLE(CTexturedObject, CRenderizableDisplayList, mrpt::opengl) struct CTexturedObject_MemPoolParams
GLAPI void GLAPIENTRY glBindTexture(GLenum target, GLuint texture)
#define GL_TEXTURE_WRAP_S
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
GLAPI GLenum GLAPIENTRY glGetError(void)
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at mié 12 jul 2023 10:03:34 CEST | |