Example #1
0
void GlutIdle()
{
    static int lastRenderedPixels = 0;
    if ( mode == MODE_RENDERING ) {
        int nrp = renderImage.GetNumRenderedPixels();
        if ( lastRenderedPixels != nrp ) {
            lastRenderedPixels = nrp;
            if ( renderImage.IsRenderDone() ) {
                mode = MODE_RENDER_DONE;
                int endTime = (int) time(NULL);
                int t = endTime - startTime;
                int h = t / 3600;
                int m = (t % 3600) / 60;
                int s = t % 60;
                printf("\nRender time is %d:%02d:%02d.\n",h,m,s);

                renderImage.ComputeZBufferImage();
                
                std::string fileloc ("/Users/varunk/Desktop/RayTracerProj1/RayTracePrj11/RayTracePrj11/");
                
                renderImage.SaveZImage((fileloc + "zbuffer.ppm").c_str());
                
                renderImage.SaveImage((fileloc + "renderimage.ppm").c_str());
                
                renderImage.ComputeSampleCountImage();
                
                renderImage.SaveSampleCountImage((fileloc + "samplecountimage.ppm").c_str());
        
            }
            glutPostRedisplay();
        }
         if ( viewMode == VIEWMODE_IRRADCOMP ) glutPostRedisplay();
    }
}
Example #2
0
void Renderer::startRendering(size_t i_threadCount)
{
	threadCount = i_threadCount;
	mThreadHandle = ThreadHandle(threadCount);
	imageWidth = renderImage.GetWidth();
	imageHeight = renderImage.GetHeight();
	noOfRowsToRenderPerThread = imageHeight / threadCount;
	renderingImage = renderImage.GetPixels();
	zBufferImage = renderImage.GetZBuffer();
	sampleCountImage = renderImage.GetSampleCount();
	operationCountImage = renderImage.GetOperationCountImage();

	myEngine::Timing::Clock *clock = myEngine::Timing::Clock::createAndStart();

	/*for (int i = 0; i < renderImage.GetHeight(); ++i)
	{
		for (int j = 0; j < renderImage.GetWidth(); ++j)
		{
			calculatePixelColor(rootNode,lights,j, i);
		}
	}*/

	

	int *threadVal = new int[threadCount];
	for (size_t i = 0; i < threadCount; i++)
	{
		threadVal[i] = i;
		std::cout << "\nPassing Value to thread" << threadVal[i];
		mThreadHandle.thread[i] = CreateThread(nullptr, 0, static_cast<LPTHREAD_START_ROUTINE>(renderPixel), &threadVal[i], CREATE_SUSPENDED, nullptr);
	}

	for (size_t i = 0; i < threadCount;i++)
	{
		ResumeThread(mThreadHandle.thread[i]);
	}
	
	std::cout << "Wait Val"<<std::endl << WaitForMultipleObjects(threadCount, mThreadHandle.thread, TRUE, INFINITE) << std::endl;;
	std::cout << "Wait finished";
	
	if (WaitForMultipleObjects(threadCount + 1, mThreadHandle.thread, TRUE, INFINITE))
	{
		mThreadHandle.destroyThread();
	}

	TCHAR* mutexName = __T("WritingMutex");
	HANDLE mutexHandle = OpenMutex(MUTEX_ALL_ACCESS, FALSE, mutexName);
	CloseHandle(mutexHandle);


	renderImage.SaveImage("RayCasted.ppm");
	renderImage.ComputeZBufferImage();
	renderImage.SaveZImage("RayCastWithZ.ppm");
	renderImage.ComputeSampleCountImage();
	renderImage.SaveSampleCountImage("SampleCountImage.ppm");
	clock->updateDeltaTime();
	double time = clock->getdeltaTime();
	printf("Time to render ray casting  %f", clock->getdeltaTime());
}