- performance improve for color picking using pbo
This commit is contained in:
parent
724d274367
commit
2fd89f11d5
|
@ -225,6 +225,7 @@ public:
|
||||||
static Pixmap2D *getPixelBufferFor(int x,int y,int w,int h, int colorComponents);
|
static Pixmap2D *getPixelBufferFor(int x,int y,int w,int h, int colorComponents);
|
||||||
static void begin();
|
static void begin();
|
||||||
static void end();
|
static void end();
|
||||||
|
static bool getIsPBOEnable() { return isPBOEnabled; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool isPBOEnabled;
|
static bool isPBOEnabled;
|
||||||
|
@ -239,7 +240,7 @@ class BaseColorPickEntity {
|
||||||
public:
|
public:
|
||||||
BaseColorPickEntity();
|
BaseColorPickEntity();
|
||||||
|
|
||||||
static const int COLOR_COMPONENTS = 3;
|
static const int COLOR_COMPONENTS = 4;
|
||||||
static void init(int bufferSize);
|
static void init(int bufferSize);
|
||||||
static void beginPicking();
|
static void beginPicking();
|
||||||
static void endPicking();
|
static void endPicking();
|
||||||
|
|
|
@ -1002,9 +1002,9 @@ Pixmap2D *PixelBufferWrapper::getPixelBufferFor(int x,int y,int w,int h, int col
|
||||||
// OpenGL should perform asynch DMA transfer, so glReadPixels() will return immediately.
|
// OpenGL should perform asynch DMA transfer, so glReadPixels() will return immediately.
|
||||||
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[index]);
|
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[index]);
|
||||||
|
|
||||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
//glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||||
glReadPixels(x, y, w, h, GL_RGB, GL_UNSIGNED_BYTE, 0);
|
glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
|
|
||||||
// measure the time reading framebuffer
|
// measure the time reading framebuffer
|
||||||
//t1.stop();
|
//t1.stop();
|
||||||
|
@ -1195,15 +1195,16 @@ vector<int> BaseColorPickEntity::getPickedList(int x,int y,int w,int h, const ve
|
||||||
//printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
//printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
static Chrono lastSnapshot(true);
|
static Chrono lastSnapshot(true);
|
||||||
|
const int selectionMillisecondUpdate = 350;
|
||||||
|
|
||||||
Pixmap2D *pixmapScreenShot = BaseColorPickEntity::pbo->getPixelBufferFor(x,y,w,h, COLOR_COMPONENTS);
|
if(PixelBufferWrapper::getIsPBOEnable() == true) {
|
||||||
if(pixmapScreenShot != NULL) {
|
// Only update the pixel buffer every x milliseconds or as required
|
||||||
// Only update the pixel buffer every 350 milliseconds or as required
|
|
||||||
if(cachedPixels.get() == NULL || cachedPixelsW != w+1 || cachedPixelsH != h+1 ||
|
if(cachedPixels.get() == NULL || cachedPixelsW != w+1 || cachedPixelsH != h+1 ||
|
||||||
lastSnapshot.getMillis() > 350) {
|
lastSnapshot.getMillis() > selectionMillisecondUpdate) {
|
||||||
//printf("Updating selection millis = %ld\n",lastSnapshot.getMillis());
|
//printf("Updating selection millis = %ld\n",lastSnapshot.getMillis());
|
||||||
|
|
||||||
lastSnapshot.reset();
|
lastSnapshot.reset();
|
||||||
|
Pixmap2D *pixmapScreenShot = BaseColorPickEntity::pbo->getPixelBufferFor(x,y,w,h, COLOR_COMPONENTS);
|
||||||
|
|
||||||
cachedPixels.reset(new unsigned char[(unsigned int)pixmapScreenShot->getPixelByteCount()]);
|
cachedPixels.reset(new unsigned char[(unsigned int)pixmapScreenShot->getPixelByteCount()]);
|
||||||
memcpy(cachedPixels.get(),pixmapScreenShot->getPixels(),(size_t)pixmapScreenShot->getPixelByteCount());
|
memcpy(cachedPixels.get(),pixmapScreenShot->getPixels(),(size_t)pixmapScreenShot->getPixelByteCount());
|
||||||
|
@ -1214,18 +1215,18 @@ vector<int> BaseColorPickEntity::getPickedList(int x,int y,int w,int h, const ve
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Only update the pixel buffer every 350 milliseconds or as required
|
// Only update the pixel buffer every x milliseconds or as required
|
||||||
if(cachedPixels.get() == NULL || cachedPixelsW != w+1 || cachedPixelsH != h+1 ||
|
if(cachedPixels.get() == NULL || cachedPixelsW != w+1 || cachedPixelsH != h+1 ||
|
||||||
lastSnapshot.getMillis() > 350) {
|
lastSnapshot.getMillis() > selectionMillisecondUpdate) {
|
||||||
//printf("Updating selection millis = %ld\n",lastSnapshot.getMillis());
|
//printf("Updating selection millis = %ld\n",lastSnapshot.getMillis());
|
||||||
|
|
||||||
lastSnapshot.reset();
|
lastSnapshot.reset();
|
||||||
|
|
||||||
pixmapScreenShot = new Pixmap2D(w+1, h+1, COLOR_COMPONENTS);
|
Pixmap2D *pixmapScreenShot = new Pixmap2D(w+1, h+1, COLOR_COMPONENTS);
|
||||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
//glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||||
glReadPixels(x, y, w, h, GL_RGB, GL_UNSIGNED_BYTE, pixmapScreenShot->getPixels());
|
//glReadPixels(x, y, w, h, GL_RGB, GL_UNSIGNED_BYTE, pixmapScreenShot->getPixels());
|
||||||
//glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixmapScreenShot->getPixels());
|
glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixmapScreenShot->getPixels());
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
|
|
||||||
cachedPixels.reset(new unsigned char[(unsigned int)pixmapScreenShot->getPixelByteCount()]);
|
cachedPixels.reset(new unsigned char[(unsigned int)pixmapScreenShot->getPixelByteCount()]);
|
||||||
memcpy(cachedPixels.get(),pixmapScreenShot->getPixels(),(size_t)pixmapScreenShot->getPixelByteCount());
|
memcpy(cachedPixels.get(),pixmapScreenShot->getPixels(),(size_t)pixmapScreenShot->getPixelByteCount());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user