- attempt to speed up color picking

This commit is contained in:
Mark Vejvoda 2013-01-23 23:20:54 +00:00
parent 86eac7451b
commit d7d83f7c5e
3 changed files with 104 additions and 96 deletions

View File

@ -6875,10 +6875,16 @@ void Renderer::selectUsingColorPicking(Selection::UnitContainer &units,
const Object *&obj, const bool withObjectSelection,
const Vec2i &posDown, const Vec2i &posUp) {
//glReadBuffer(GL_FRONT);
//glDrawBuffer(GL_FRONT);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
colorPickUnits(units,posDown, posUp);
if(units.empty() == true && withObjectSelection == true) {
colorPickObject(obj, posDown,posUp);
}
//glDrawBuffer(GL_BACK);
//glReadBuffer(GL_BACK);
}
void Renderer::colorPickUnits(Selection::UnitContainer &units,

View File

@ -251,7 +251,7 @@ public:
BaseColorPickEntity();
virtual ~BaseColorPickEntity() {}
static const int COLOR_COMPONENTS = 3;
static const int COLOR_COMPONENTS = 4;
struct ColorPickStruct {
unsigned char color[COLOR_COMPONENTS];

View File

@ -1435,6 +1435,8 @@ void PixelBufferWrapper::begin() {
if(PixelBufferWrapper::isPBOEnabled == true) {
// set the framebuffer to read
//glReadBuffer(GL_FRONT);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glClear(GL_COLOR_BUFFER_BIT);
}
}
@ -1458,8 +1460,9 @@ PixelBufferWrapper::~PixelBufferWrapper() {
cleanup();
}
const int colorSpacing = 8;
//unsigned char BaseColorPickEntity::nextColorID[COLOR_COMPONENTS] = {1, 1, 1, 1};
BaseColorPickEntity::ColorPickStruct BaseColorPickEntity::nextColorID = { 1, 1, 1 };
BaseColorPickEntity::ColorPickStruct BaseColorPickEntity::nextColorID = { colorSpacing, colorSpacing, colorSpacing };
vector<BaseColorPickEntity::ColorPickStruct> BaseColorPickEntity::nextColorIDReuseList;
Mutex BaseColorPickEntity::mutexNextColorID;
auto_ptr<PixelBufferWrapper> BaseColorPickEntity::pbo;
@ -1471,9 +1474,9 @@ void BaseColorPickEntity::recycleUniqueColor() {
void BaseColorPickEntity::resetUniqueColors() {
MutexSafeWrapper safeMutex(&mutexNextColorID);
nextColorID.color[0] = 1;
nextColorID.color[1] = 1;
nextColorID.color[2] = 1;
nextColorID.color[0] = colorSpacing;
nextColorID.color[1] = colorSpacing;
nextColorID.color[2] = colorSpacing;
nextColorIDReuseList.clear();
}
@ -1495,18 +1498,16 @@ BaseColorPickEntity::BaseColorPickEntity() {
uniqueColorID.color[2] = nextColorID.color[2];
//uniqueColorID[3] = nextColorID[3];
const int colorSpacing = 8;
if(nextColorID.color[0] + colorSpacing <= 255) {
nextColorID.color[0] += colorSpacing;
}
else {
nextColorID.color[0] = 1;
nextColorID.color[0] = colorSpacing;
if(nextColorID.color[1] + colorSpacing <= 255) {
nextColorID.color[1] += colorSpacing;
}
else {
nextColorID.color[1] = 1;
nextColorID.color[1] = colorSpacing;
if(nextColorID.color[2] + colorSpacing <= 255) {
nextColorID.color[2] += colorSpacing;
}
@ -1514,9 +1515,9 @@ BaseColorPickEntity::BaseColorPickEntity() {
//printf("Color rolled over on 3rd level!\n");
nextColorID.color[0] = 1;
nextColorID.color[1] = 1;
nextColorID.color[2] = 1;
nextColorID.color[0] = colorSpacing;
nextColorID.color[1] = colorSpacing;
nextColorID.color[2] = colorSpacing;
// nextColorID[2] = 1;
@ -1559,8 +1560,8 @@ void BaseColorPickEntity::beginPicking() {
glDisable(GL_BLEND);
glDisable(GL_MULTISAMPLE);
glDisable(GL_DITHER);
glDisable(GL_POLYGON_OFFSET_FILL);
glDisable(GL_NORMALIZE);
//glDisable(GL_POLYGON_OFFSET_FILL);
//glDisable(GL_NORMALIZE);
//glPushAttrib(GL_TEXTURE_2D | GL_LIGHTING | GL_BLEND | GL_MULTISAMPLE | GL_DITHER);
//glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_POLYGON_BIT | GL_CURRENT_BIT | GL_TEXTURE_BIT | GL_NORMALIZE | GL_BLEND | GL_POLYGON_OFFSET_FILL);
@ -1581,6 +1582,7 @@ void BaseColorPickEntity::endPicking() {
vector<int> BaseColorPickEntity::getPickedList(int x,int y,int w,int h,
const vector<BaseColorPickEntity *> &rendererModels) {
vector<int> pickedModels;
if(rendererModels.empty() == false) {
pickedModels.reserve(rendererModels.size());
//printf("In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
@ -1591,17 +1593,17 @@ vector<int> BaseColorPickEntity::getPickedList(int x,int y,int w,int h,
//printf("In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
static Chrono lastSnapshot(true);
//static Chrono lastSnapshot(true);
//const int selectionMillisecondUpdate = 100;
const int selectionMillisecondUpdate = 0;
//const int selectionMillisecondUpdate = 0;
if(PixelBufferWrapper::getIsPBOEnable() == true) {
// Only update the pixel buffer every x milliseconds or as required
if(cachedPixels.get() == NULL || cachedPixels->getW() != w+1 ||cachedPixels->getH() != h+1 ||
lastSnapshot.getMillis() > selectionMillisecondUpdate) {
if(cachedPixels.get() == NULL || cachedPixels->getW() != w+1 ||cachedPixels->getH() != h+1) { // ||
//lastSnapshot.getMillis() > selectionMillisecondUpdate) {
//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(BaseColorPickEntity::pbo->getPixelBufferFor(x,y,w,h, COLOR_COMPONENTS));
@ -1615,11 +1617,11 @@ vector<int> BaseColorPickEntity::getPickedList(int x,int y,int w,int h,
}
else {
// Only update the pixel buffer every x milliseconds or as required
if(cachedPixels.get() == NULL || cachedPixels->getW() != w+1 ||cachedPixels->getH() != h+1 ||
lastSnapshot.getMillis() > selectionMillisecondUpdate) {
if(cachedPixels.get() == NULL || cachedPixels->getW() != w+1 ||cachedPixels->getH() != h+1) {// ||
//lastSnapshot.getMillis() > selectionMillisecondUpdate) {
//printf("Updating selection millis = %ld\n",lastSnapshot.getMillis());
lastSnapshot.reset();
//lastSnapshot.reset();
//Pixmap2D *pixmapScreenShot = new Pixmap2D(w+1, h+1, COLOR_COMPONENTS);
cachedPixels.reset(new Pixmap2D(w+1, h+1, COLOR_COMPONENTS));
@ -1686,7 +1688,7 @@ vector<int> BaseColorPickEntity::getPickedList(int x,int y,int w,int h,
//printf("In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//delete pixmapScreenShot;
}
//printf("In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
return pickedModels;
}