From 724d274367058ddc945e56f065c5a433ed21be89 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 13 Dec 2011 22:21:21 +0000 Subject: [PATCH] - fixed pixel buffer logic on windows (wacky vc++ 2008 doesn't properly allocate memory on vector.reserve(); --- source/shared_lib/include/graphics/model.h | 4 ++- source/shared_lib/sources/graphics/model.cpp | 30 ++++++++++++------- .../sources/platform/sdl/gl_wrap.cpp | 1 + 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/source/shared_lib/include/graphics/model.h b/source/shared_lib/include/graphics/model.h index 000cbf88b..31ca33989 100644 --- a/source/shared_lib/include/graphics/model.h +++ b/source/shared_lib/include/graphics/model.h @@ -229,7 +229,9 @@ public: private: static bool isPBOEnabled; static int index; - static vector pboIds; + static vector pboIds; + + void cleanup(); }; class BaseColorPickEntity { diff --git a/source/shared_lib/sources/graphics/model.cpp b/source/shared_lib/sources/graphics/model.cpp index 7b4a3bd14..7e0e56ca3 100644 --- a/source/shared_lib/sources/graphics/model.cpp +++ b/source/shared_lib/sources/graphics/model.cpp @@ -964,12 +964,18 @@ int PixelBufferWrapper::index = 0; vector PixelBufferWrapper::pboIds; PixelBufferWrapper::PixelBufferWrapper(int pboCount,int bufferSize) { - if(isGlExtensionSupported("GL_ARB_pixel_buffer_object")) { + //if(isGlExtensionSupported("GL_ARB_pixel_buffer_object") == true && + if(GLEW_ARB_pixel_buffer_object) { PixelBufferWrapper::isPBOEnabled = true; - pboIds.reserve(pboCount); - glGenBuffersARB(pboCount, &pboIds[0]); + cleanup(); + // For some wacky reason this fails in VC++ 2008 + //pboIds.reserve(pboCount); + //glGenBuffersARB(pboCount, (GLuint*)&pboIds[0]); + // - for(unsigned int i = 0; i < pboCount; ++i) { + for(int i = 0; i < pboCount; ++i) { + pboIds.push_back(0); + glGenBuffersARB(1, (GLuint*)&pboIds[i]); // create pixel buffer objects, you need to delete them when program exits. // glBufferDataARB with NULL pointer reserves only memory space. glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[i]); @@ -1013,7 +1019,7 @@ Pixmap2D *PixelBufferWrapper::getPixelBufferFor(int x,int y,int w,int h, int col GLubyte* src = (GLubyte*)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB); if(src) { pixmapScreenShot = new Pixmap2D(w+1, h+1, colorComponents); - memcpy(pixmapScreenShot->getPixels(),src,pixmapScreenShot->getPixelByteCount()); + memcpy(pixmapScreenShot->getPixels(),src,(size_t)pixmapScreenShot->getPixelByteCount()); glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB); // release pointer to the mapped buffer @@ -1044,7 +1050,7 @@ void PixelBufferWrapper::end() { } } -PixelBufferWrapper::~PixelBufferWrapper() { +void PixelBufferWrapper::cleanup() { if(PixelBufferWrapper::isPBOEnabled == true) { if(pboIds.empty() == false) { glDeleteBuffersARB(pboIds.size(), &pboIds[0]); @@ -1053,6 +1059,10 @@ PixelBufferWrapper::~PixelBufferWrapper() { } } +PixelBufferWrapper::~PixelBufferWrapper() { + cleanup(); +} + //unsigned char BaseColorPickEntity::nextColorID[COLOR_COMPONENTS] = {1, 1, 1, 1}; unsigned char BaseColorPickEntity::nextColorID[COLOR_COMPONENTS] = { 1, 1, 1 }; Mutex BaseColorPickEntity::mutexNextColorID; @@ -1195,8 +1205,8 @@ vector BaseColorPickEntity::getPickedList(int x,int y,int w,int h, const ve lastSnapshot.reset(); - cachedPixels.reset(new unsigned char[pixmapScreenShot->getPixelByteCount()]); - memcpy(cachedPixels.get(),pixmapScreenShot->getPixels(),pixmapScreenShot->getPixelByteCount()); + cachedPixels.reset(new unsigned char[(unsigned int)pixmapScreenShot->getPixelByteCount()]); + memcpy(cachedPixels.get(),pixmapScreenShot->getPixels(),(size_t)pixmapScreenShot->getPixelByteCount()); cachedPixelsW = w+1; cachedPixelsH = h+1; @@ -1217,8 +1227,8 @@ vector BaseColorPickEntity::getPickedList(int x,int y,int w,int h, const ve //glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixmapScreenShot->getPixels()); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - cachedPixels.reset(new unsigned char[pixmapScreenShot->getPixelByteCount()]); - memcpy(cachedPixels.get(),pixmapScreenShot->getPixels(),pixmapScreenShot->getPixelByteCount()); + cachedPixels.reset(new unsigned char[(unsigned int)pixmapScreenShot->getPixelByteCount()]); + memcpy(cachedPixels.get(),pixmapScreenShot->getPixels(),(size_t)pixmapScreenShot->getPixelByteCount()); cachedPixelsW = w+1; cachedPixelsH = h+1; diff --git a/source/shared_lib/sources/platform/sdl/gl_wrap.cpp b/source/shared_lib/sources/platform/sdl/gl_wrap.cpp index cc505b76c..913b5626e 100644 --- a/source/shared_lib/sources/platform/sdl/gl_wrap.cpp +++ b/source/shared_lib/sources/platform/sdl/gl_wrap.cpp @@ -173,6 +173,7 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,bool //return 1; throw std::runtime_error((char *)glewGetErrorString(err)); } + //fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); int bufferSize = (resW * resH * BaseColorPickEntity::COLOR_COMPONENTS); BaseColorPickEntity::init(bufferSize);