- attempt better debugging output for color picking crash
This commit is contained in:
parent
472e8bbaf0
commit
a0337c80e1
|
@ -1804,54 +1804,83 @@ void PixelBufferWrapper::addBuffersToPixelBuf(int pboCount) {
|
||||||
Pixmap2D *PixelBufferWrapper::getPixelBufferFor(int x,int y,int w,int h, int colorComponents) {
|
Pixmap2D *PixelBufferWrapper::getPixelBufferFor(int x,int y,int w,int h, int colorComponents) {
|
||||||
Pixmap2D *pixmapScreenShot = NULL;
|
Pixmap2D *pixmapScreenShot = NULL;
|
||||||
if(PixelBufferWrapper::isPBOEnabled == true) {
|
if(PixelBufferWrapper::isPBOEnabled == true) {
|
||||||
// increment current index first then get the next index
|
string codeSection = "A";
|
||||||
// "index" is used to read pixels from a framebuffer to a PBO
|
try {
|
||||||
// "nextIndex" is used to process pixels in the other PBO
|
// increment current index first then get the next index
|
||||||
index = (index + 1) % 2;
|
// "index" is used to read pixels from a framebuffer to a PBO
|
||||||
|
// "nextIndex" is used to process pixels in the other PBO
|
||||||
|
index = (index + 1) % 2;
|
||||||
|
|
||||||
// Check for out of range
|
codeSection = "B";
|
||||||
if(index >= (int)pboIds.size()) {
|
// Check for out of range
|
||||||
char szBuf[8096]="";
|
if(index >= (int)pboIds.size()) {
|
||||||
snprintf(szBuf,8096,"Error / Warning in [%s::%s] on line: %d pixel buffer out of range, index: %d size: %d, attempting to expand buffer...\n",__FILE__,__FUNCTION__,__LINE__,index, (int)pboIds.size());
|
char szBuf[8096]="";
|
||||||
//throw megaglest_runtime_error(szBuf);
|
snprintf(szBuf,8096,"Error / Warning in [%s::%s] on line: %d pixel buffer out of range, index: %d size: %d, attempting to expand buffer...\n",__FILE__,__FUNCTION__,__LINE__,index, (int)pboIds.size());
|
||||||
addBuffersToPixelBuf((index - pboIds.size()) + 1);
|
//throw megaglest_runtime_error(szBuf);
|
||||||
}
|
SystemFlags::OutputDebug(SystemFlags::debugError,"%s",szBuf);
|
||||||
// pbo index used for next frame
|
|
||||||
//int nextIndex = (index + 1) % 2;
|
|
||||||
|
|
||||||
// read framebuffer ///////////////////////////////
|
codeSection = "C";
|
||||||
// copy pixels from framebuffer to PBO
|
addBuffersToPixelBuf((index - pboIds.size()) + 1);
|
||||||
// Use offset instead of pointer.
|
}
|
||||||
// OpenGL should perform asynch DMA transfer, so glReadPixels() will return immediately.
|
// pbo index used for next frame
|
||||||
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[index]);
|
//int nextIndex = (index + 1) % 2;
|
||||||
//glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[nextIndex]);
|
|
||||||
|
|
||||||
//glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
codeSection = "D";
|
||||||
glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
// read framebuffer ///////////////////////////////
|
||||||
//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
// copy pixels from framebuffer to PBO
|
||||||
|
// Use offset instead of pointer.
|
||||||
|
// 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[nextIndex]);
|
||||||
|
|
||||||
// measure the time reading framebuffer
|
codeSection = "E";
|
||||||
//t1.stop();
|
//glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||||
//readTime = t1.getElapsedTimeInMilliSec();
|
glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||||
|
//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
|
|
||||||
// process pixel data /////////////////////////////
|
// measure the time reading framebuffer
|
||||||
//t1.start();
|
//t1.stop();
|
||||||
|
//readTime = t1.getElapsedTimeInMilliSec();
|
||||||
|
|
||||||
// map the PBO that contain framebuffer pixels before processing it
|
// process pixel data /////////////////////////////
|
||||||
//glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[nextIndex]);
|
//t1.start();
|
||||||
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[index]);
|
|
||||||
GLubyte* src = (GLubyte*)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB);
|
codeSection = "F";
|
||||||
if(src) {
|
// map the PBO that contain framebuffer pixels before processing it
|
||||||
pixmapScreenShot = new Pixmap2D(w, h, colorComponents);
|
//glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[nextIndex]);
|
||||||
memcpy(pixmapScreenShot->getPixels(),src,pixmapScreenShot->getPixelByteCount());
|
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[index]);
|
||||||
glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB); // release pointer to the mapped buffer
|
|
||||||
//pixmapScreenShot->save("debugPBO.png");
|
codeSection = "G";
|
||||||
|
GLubyte* src = (GLubyte*)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB);
|
||||||
|
if(src) {
|
||||||
|
codeSection = "H";
|
||||||
|
pixmapScreenShot = new Pixmap2D(w, h, colorComponents);
|
||||||
|
|
||||||
|
codeSection = "I";
|
||||||
|
memcpy(pixmapScreenShot->getPixels(),src,pixmapScreenShot->getPixelByteCount());
|
||||||
|
|
||||||
|
codeSection = "J";
|
||||||
|
glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB); // release pointer to the mapped buffer
|
||||||
|
//pixmapScreenShot->save("debugPBO.png");
|
||||||
|
}
|
||||||
|
codeSection = "K";
|
||||||
|
// measure the time reading framebuffer
|
||||||
|
//t1.stop();
|
||||||
|
//processTime = t1.getElapsedTimeInMilliSec();
|
||||||
|
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
|
||||||
|
}
|
||||||
|
catch(megaglest_runtime_error& ex) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] codeSection [%s] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,codeSection.c_str(),ex.what());
|
||||||
|
throw megaglest_runtime_error("Exception caught in getPixelBufferFor codeSection: " + codeSection +"\n"+ ex.what(),!ex.wantStackTrace());
|
||||||
|
}
|
||||||
|
catch(exception &e){
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] codeSection [%s] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,codeSection.c_str(),e.what());
|
||||||
|
throw megaglest_runtime_error("Exception caught in getPixelBufferFor codeSection: " + codeSection +"\n"+ e.what());
|
||||||
|
}
|
||||||
|
catch(...){
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] codeSection [%s] UNKNOWN Error!",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,codeSection.c_str());
|
||||||
|
throw megaglest_runtime_error("UNKNOWN Exception caught in getPixelBufferFor codeSection: " + codeSection +"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// measure the time reading framebuffer
|
|
||||||
//t1.stop();
|
|
||||||
//processTime = t1.getElapsedTimeInMilliSec();
|
|
||||||
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return pixmapScreenShot;
|
return pixmapScreenShot;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user