- performance improve for color picking using pbo

This commit is contained in:
Mark Vejvoda 2011-12-13 22:50:14 +00:00
parent 724d274367
commit 2fd89f11d5
2 changed files with 17 additions and 15 deletions

View File

@ -225,6 +225,7 @@ public:
static Pixmap2D *getPixelBufferFor(int x,int y,int w,int h, int colorComponents);
static void begin();
static void end();
static bool getIsPBOEnable() { return isPBOEnabled; }
private:
static bool isPBOEnabled;
@ -239,7 +240,7 @@ class BaseColorPickEntity {
public:
BaseColorPickEntity();
static const int COLOR_COMPONENTS = 3;
static const int COLOR_COMPONENTS = 4;
static void init(int bufferSize);
static void beginPicking();
static void endPicking();

View File

@ -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.
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[index]);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(x, y, w, h, GL_RGB, GL_UNSIGNED_BYTE, 0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
//glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, 0);
//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// measure the time reading framebuffer
//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__);
static Chrono lastSnapshot(true);
const int selectionMillisecondUpdate = 350;
Pixmap2D *pixmapScreenShot = BaseColorPickEntity::pbo->getPixelBufferFor(x,y,w,h, COLOR_COMPONENTS);
if(pixmapScreenShot != NULL) {
// Only update the pixel buffer every 350 milliseconds or as required
if(PixelBufferWrapper::getIsPBOEnable() == true) {
// Only update the pixel buffer every x milliseconds or as required
if(cachedPixels.get() == NULL || cachedPixelsW != w+1 || cachedPixelsH != h+1 ||
lastSnapshot.getMillis() > 350) {
lastSnapshot.getMillis() > selectionMillisecondUpdate) {
//printf("Updating selection millis = %ld\n",lastSnapshot.getMillis());
lastSnapshot.reset();
Pixmap2D *pixmapScreenShot = BaseColorPickEntity::pbo->getPixelBufferFor(x,y,w,h, COLOR_COMPONENTS);
cachedPixels.reset(new unsigned char[(unsigned int)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 {
// 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 ||
lastSnapshot.getMillis() > 350) {
lastSnapshot.getMillis() > selectionMillisecondUpdate) {
//printf("Updating selection millis = %ld\n",lastSnapshot.getMillis());
lastSnapshot.reset();
pixmapScreenShot = new Pixmap2D(w+1, h+1, COLOR_COMPONENTS);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(x, y, w, h, GL_RGB, GL_UNSIGNED_BYTE, pixmapScreenShot->getPixels());
//glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixmapScreenShot->getPixels());
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
Pixmap2D *pixmapScreenShot = new Pixmap2D(w+1, h+1, COLOR_COMPONENTS);
//glPixelStorei(GL_PACK_ALIGNMENT, 1);
//glReadPixels(x, y, w, h, GL_RGB, GL_UNSIGNED_BYTE, pixmapScreenShot->getPixels());
glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixmapScreenShot->getPixels());
//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
cachedPixels.reset(new unsigned char[(unsigned int)pixmapScreenShot->getPixelByteCount()]);
memcpy(cachedPixels.get(),pixmapScreenShot->getPixels(),(size_t)pixmapScreenShot->getPixelByteCount());