void DRGeometrieSphere::makeSphericalLandscape(GLuint numIterations, GLuint randomSeed) { if(!mVertexCount) LOG_ERROR_VOID("keine Vertices zum manipulieren!"); DRRandom::seed(randomSeed); const int threadCount = g_CPU_Count; PlaneData planes(numIterations, randomSeed); LandscapeGenerateMultithreadData* workingData = new LandscapeGenerateMultithreadData[threadCount]; SDL_Thread** threads = new SDL_Thread*[threadCount]; for(int i = 0; i < threadCount; i++) { workingData[i].planes = &planes; workingData[i].vertices = &mVertices[mVertexCount/threadCount*i]; workingData[i].vertexCount = mVertexCount/threadCount; #if SDL_VERSION_ATLEAST(1,3,0) threads[i] = SDL_CreateThread(makeLandscapeThread, "DRGeoLSC" ,&workingData[i]); #else threads[i] = SDL_CreateThread(makeLandscapeThread, &workingData[i]); #endif printf("thread: %d, vertexIndex: %ld, vertexCount: %ld, ges vertexCount: %ld\n",i, mVertexCount/threadCount*i, mVertexCount/threadCount, mVertexCount); } for(int i = 0; i < threadCount; i++) { int returnValue = 0; SDL_WaitThread(threads[i], &returnValue); if(returnValue) { LOG_WARNING("Fehler in Thread occured"); DRLog.writeToLog("Thread %d return with error: %d", i, returnValue); } } DR_SAVE_DELETE_ARRAY(threads); DR_SAVE_DELETE_ARRAY(workingData); }
void HeightMapTexture::copyPixelData(u8* data, DRVector2i size) { if(!mPixelHeightData || mSize != size) { DR_SAVE_DELETE_ARRAY(mPixelHeightData); mSize = size; mMaxGradient = -10.0f; mMaxHeight = -10.0f; mPixelHeightData = new float[size.x*size.y]; } if(sizeof(float) != sizeof(u8)*4) LOG_ERROR_VOID("datatypes not like expected"); //memcpy(mPixelHeightData, data, 4*size.x*size.y*sizeof(u8)); for(uint y = 0; y < size.y; y++) { for(uint x = 0; x < size.x; x++) { int i = x+y*size.x; int ix = x-1+y*size.x; int iy = x+(y-1)*size.x; float red = static_cast<float>(data[i*4+2]); float green = static_cast<float>(data[i*4+1]); float blue = static_cast<float>(data[i*4]); mPixelHeightData[i] = ((red+green*256.0f + (blue*256.0f*256.0f))/(256.0f*256.0f*256.0f))*2.0f-1.0f; if(mPixelHeightData[i] > mMaxHeight) mMaxHeight = mPixelHeightData[i]; if(x > 0) { float xGradient = fabs(mPixelHeightData[i] - mPixelHeightData[ix]); if(xGradient > mMaxGradient) mMaxGradient = xGradient; } if(y > 0) { float yGradient = fabs(mPixelHeightData[i] - mPixelHeightData[iy]); if(yGradient > mMaxGradient) mMaxGradient = yGradient; } } } //DREngineLog.writeToLog("[HeightMapTexture::copyPixelData]: maxHeight: %f, maxGradient: %f", mMaxHeight, mMaxGradient); SDL_LockMutex(mPixelCopyMutex); LOG_WARNING_SDL(); mState++; SDL_UnlockMutex(mPixelCopyMutex); LOG_WARNING_SDL(); }
DRReturn HeightMapLoader::saveImage() { if(mSavingState < 2) LOG_ERROR("Image data not ready!", DR_ERROR); if(mSize.x <= 0 || mSize.y <= 0) LOG_ERROR("error getSize return zero", DR_ERROR); if(mSavingBuffer) { mImage->setPixel(mSavingBuffer); mParent->copyPixelData(mSavingBuffer, mSize); DR_SAVE_DELETE_ARRAY(mSavingBuffer); } DRIImage::deleteImage(mImage); mImage = NULL; mSavingState = 3; //printf("image saved\n"); return DR_OK; }
HeightMapTexture::~HeightMapTexture() { DR_SAVE_DELETE_ARRAY(mPixelHeightData); SDL_LockMutex(mPixelCopyMutex); SDL_UnlockMutex(mPixelCopyMutex); SDL_DestroyMutex(mPixelCopyMutex); LOG_WARNING_SDL(); }