void RenderThread::calculateProgress()
{
    // Calculate the render progress based on the program output
    if(renderprocess) {
        QString out;
        // Loop through as long as there is data to process
        while(!(out=renderprocess->readLine()).isEmpty()) {
            // If it says "Done!", we should emit a 100% completion
            if(out.contains("Done!")) {
                emit renderProgress(tr("Finished rendering ")+project.second, 100);
                break;
            } else {
                // Extract the current and total frames from the output
                QRegExp regex("^Frame \\d+ \\((\\d+)/(\\d+)\\)");
                if(out.contains(regex)) {
                    // Convert to float, then get a percentage from that
                    float current = regex.cap(1).toFloat();
                    float total = regex.cap(2).toFloat();
                    emit renderProgress(tr("Currently rendering ")+project.second,
                                        int((current/total)*100.0f));
                }
            }
        }
    }
}
Example #2
0
void UI::render ()
{
	std::vector<UIWindow*> renderOrder;
	UIStack stack = _stack;
	for (UIStackReverseIter i = stack.rbegin(); i != stack.rend(); ++i) {
		UIWindow* window = *i;
		renderOrder.push_back(window);
		// we can skip here
		if (window->isFullscreen())
			break;
	}

	for (std::vector<UIWindow*>::reverse_iterator i = renderOrder.rbegin(); i != renderOrder.rend(); ++i) {
		(*i)->render(0, 0);
	}

	// TODO: move cursor and progress bar into frontend
	if (_progress.active) {
		renderProgress();
	}

	if (_cursorX != -1 && _cursorY != -1 && _cursor) {
		const int w = _mouseCursor->getWidth();
		const int h = _mouseCursor->getHeight();
		_frontend->renderImage(_mouseCursor.get(), _cursorX, _cursorY, w, h, 0, 1.0f);
	}

	const bool debug = Config.getConfigVar("debugui")->getBoolValue();
	if (debug) {
		const BitmapFontPtr& font = getFont();
		const std::string s = String::format("%i:%i", _cursorX, _cursorY);
		font->print(s, colorWhite, 0, 0);
	}
}
void RayTracingRenderer::render(Scene & scene) {
	setRes(scene.camera->xRes(), scene.camera->yRes());

	//clear m_rgbaBuffer
	this->m_rgbaBuffer(scene.camera->xRes(), scene.camera->yRes());
	this->m_rgbaBuffer.reset(Color4f(0));

	//setup progress reporting using Platform::Progress
	Platform::Progress renderProgress("Initializing", (scene.camera->xRes()/50)+1);

	//for each pixel generate a camera ray 
	unsigned int xRes = scene.camera->xRes();
	unsigned int yRes = scene.camera->yRes();
	for (unsigned int i = 0; i < xRes; i++) {
		for (unsigned int j = 0; j < yRes; j++) {
			auto r = std::unique_ptr<Ray>(new Ray());
			scene.camera->generateRay(r.get(), static_cast<float>(i), static_cast<float>(j));
	
			//loop over all scene objects and find the closest intersection
			for (unsigned int k = 0; k < scene.shapes.size(); k++)
				scene.shapes[k]->intersect(r.get());

			//if ray hit something then shade it
			if (r->hit.shape != 0 && r->hit.surfaceShader != 0) {
				std::stack<float> refraction = std::stack<float>();
				refraction.push(1);
				Math::Color3f shaded = r->hit.surfaceShader->shade(r->hit, &scene, refraction);
				
				m_rgbaBuffer(i,j).x = shaded.x;
				m_rgbaBuffer(i,j).y = shaded.y;
				m_rgbaBuffer(i,j).z = shaded.z;
				m_rgbaBuffer(i,j).w = 1;
			} else
				m_rgbaBuffer(i,j) = scene.background->getBackground(r->d);
		}

		if (i % 50 == 0)
			renderProgress.step();
	}
	renderProgress.step();

	//Copy the final rendering to the texture
	glBindTexture(GL_TEXTURE_2D, m_fbo->colorTextureID(0));
	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_fbo->width(), m_fbo->height(), GL_RGBA, GL_FLOAT, &m_rgbaBuffer(0,0));
	glBindTexture(GL_TEXTURE_2D, 0);
	
	//Render to Screen
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	m_fbo->displayAsFullScreenTexture(FBO_COLOR0);
}
void RenderThread::executeRenderCommand(QString program, QStringList arguments)
{
    // Create a new process for the render job
    if(!renderprocess)
        renderprocess = new QProcess(this);

    // Get regular progress updates from the process, and have it emit a signal when finished
    connect(renderprocess, SIGNAL(readyReadStandardOutput()), this, SLOT(calculateProgress()));
    connect(renderprocess, SIGNAL(finished(int)), this, SLOT(renderFinished()));

    // Now start the process, and emit a signal saying we've done so
    renderprocess->start(program, arguments);
    emit renderProgress(tr("Currently rendering ")+project.second, 0);
}