Exemplo n.º 1
0
void GLPresenter::reshape(int w, int h)
{
	wSizeW = w; wSizeH = h;
	Console::get().setSize(w, h);
	NONRELEASE( RT_GL_ASSERT("Error before resizing viewport.") );
	if(oneToNScaleFactor > 0.0) {
		int x = 0, y = 0, targetW = (int)(reqW*oneToNScaleFactor), targetH = (int)(reqH*oneToNScaleFactor);
		Console::get().setSize(targetW, targetH);
		int dw = targetW-w;
		x = -dw/2; w += dw;
		int dh = targetH-h;
		y = -dh/2; h += dh;
		glViewport(x, y, w, h);
	}
	else {
		const static double epsilon = 0.00001;
		if(fabs((w/(double)h) - aspect) < epsilon) {
			glViewport(0, 0, w, h);
		} else if(h*aspect>w) { // need letterboxing
			GLsizei newh = (GLsizei)(w/aspect);
			GLint box = (h-newh)/2;
			glViewport(0, box, w, newh);
			h = newh;
		} else { // need pillarboxing
			GLsizei neww = (GLsizei)(h*aspect);
			GLint box = (w-neww)/2;
			glViewport(box, 0, neww, h);
			w = neww;
		}
	}
	NONRELEASE( RT_GL_ASSERT("Error resizing viewport.") );
}
Exemplo n.º 2
0
bool GLPresenter::run()
{
	if(!running) {
		return false;
	}
	if(frameIndex > drawnFrameIndex) {
		glBindTexture(GL_TEXTURE_2D, texId);
		drawnFrameIndex = frameIndex;
		glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, reqW/2, reqH, GL_ABGR_EXT, GL_UNSIGNED_BYTE, dataPointers[drawnFrameIndex%2]);
		NONRELEASE( RT_GL_ASSERT("Error uploading frame data.") );

		// convert UYVY
		buffer->makeCurrent();
		convertUYVY->use();
		glutil::drawQuad();
		convertUYVY->stopUsing();
		buffer->releaseCurrent();
		// apply AA
		aaManager->applyAA(buffer, buffer2);
		// apply IP
		ipManager->applyIP(buffer2, buffer);	
		display();
	}
	glfwPollEvents();
	if(clock()>cursorTimeout) {
		if(GetFocus() == hwnd) glfwDisable(GLFW_MOUSE_CURSOR);
	} else {
		glfwEnable(GLFW_MOUSE_CURSOR);
	}
	return true;
}
Exemplo n.º 3
0
GLPresenter::GLPresenter(DeckLinkCapture &capture, int w, int h, int hz) : 
	data_size(w*h*2),
	capture(capture), running(true), fullscreen(false), useVsync(false), rgbFull(false),
	texId(0), displayList(0), 
	convertUYVY(NULL),
	buffer(NULL), buffer2(NULL),
	reqW(w), reqH(h), reqHz(hz), 
	frameIndex(0), drawnFrameIndex(0), aspect(16.0/9.0), oneToNScaleFactor(-1.0)
{
	self = this;

	sprintf(prepend, "#define FRAME_WIDTH %d\n#define FRAME_HEIGHT %d\n", reqW, reqH);

	RT_ASSERT(glfwInit() == GL_TRUE, "Failed to initalize GLFW.");
	RT_ASSERT(glfwOpenWindow(w, h, 0, 0, 0, 0, 0, 0, GLFW_WINDOW) == GL_TRUE, "Failed to open GLFW window.");

	string title("PtBi ");
	title += VER_STRING;
	glfwSetWindowTitle(title.c_str());
	glfwSetWindowPos(10, 10);

	dataPointers[0] = malloc(data_size);
	dataPointers[1] = malloc(data_size);

	glewInit();
	checkExtensions();

	ilInit();

	glfwDisable(GLFW_AUTO_POLL_EVENTS);
	glfwSwapInterval(0);
	glfwSetWindowCloseCallback(closeCallback);
	glfwSetWindowSizeCallback(resizeCallback);
	glfwSetMousePosCallback(mousePosCallback);
	glfwSetKeyCallback(keyCallback);

	hdc = wglGetCurrentDC();
	hrc = wglGetCurrentContext();

	initGL();

	convertUYVY = new GLFragmentProgram("shaders/uyvy_to_rgb_smooth.glsl", getShaderPrependString());

	buffer = new GLRenderTexture(getW(), getH(), GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE);
	buffer->setFilterMode(GL_LINEAR);
	buffer2 = new GLRenderTexture(getW(), getH(), GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE);
	buffer2->setFilterMode(GL_LINEAR);

	scalingManager = new ScalingManager(*this);
	aaManager = new AAManager(*this);
	ipManager = new IPManager(*this);
	keyBinding = new KeyBinding(this);
	capture.registerDisplayListener(this);

	hwnd = GetForegroundWindow();

	RT_GL_ASSERT("Error during GL initialization.");

	reshape(reqW, reqH);
}
Exemplo n.º 4
0
bool GLPresenter::run()
{
	if(!running) {
		return false;
	}
	if(frameIndex > drawnFrameIndex) {
		Timer t;
		glBindTexture(GL_TEXTURE_2D, texId);
		drawnFrameIndex = frameIndex;
		glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, captureBufferW, reqH, GL_ABGR_EXT, GL_UNSIGNED_BYTE, dataPointers[drawnFrameIndex % 2]);
		NONRELEASE( RT_GL_ASSERT("Error uploading frame data.") );

		// convert UYVY
		buffer->makeCurrent();
		initialConvert->use();
		glutil::drawQuad();
		initialConvert->stopUsing();
		buffer->releaseCurrent();
		// apply AA
		aaManager->applyAA(buffer, buffer2);
		// apply IP
		ipManager->applyIP(buffer2, buffer);	
		display();

		// statistics
		frameProcTimes.add(t.elapsed()/1000.0);
		graphicsReportText->text = format("Frame processing time (CPU): \n% 6.2lf ms avg, % 6.2lf ms max", frameProcTimes.get(), frameProcTimes.getMax());
	}
	glfwPollEvents();

	if(GetFocus() == hwnd) {
		if(clock()>cursorTimeout) {
			glfwDisable(GLFW_MOUSE_CURSOR);
		} else {
			glfwEnable(GLFW_MOUSE_CURSOR);
		}
	}
	return true;
}
Exemplo n.º 5
0
GLPresenter::GLPresenter(DeckLinkCapture &capture, int w, int h, int hz) : 
	data_size(w*h*capture.getBytesPerPixel()),
	capture(capture), running(true), fullscreen(false), useVsync(false), rgbFull(false),
	texId(0), displayList(0), 
	initialConvert(NULL),
	buffer(NULL), buffer2(NULL),
	reqW(w), reqH(h), reqHz(hz), captureBufferW(reqW / (4 / capture.getBytesPerPixel())),
	frameIndex(0), drawnFrameIndex(0), aspect(16.0/9.0), oneToNScaleFactor(-1.0),
	frameProcTimes(300)
{
	self = this;

	sprintf(prepend, "#version 410 compatibility \n#define FRAME_WIDTH %d \n#define FRAME_HEIGHT %d \n", reqW, reqH);

	RT_ASSERT(glfwInit() == GL_TRUE, "Failed to initalize GLFW.");
	RT_ASSERT(glfwOpenWindow(w, h, 0, 0, 0, 0, 0, 0, GLFW_WINDOW) == GL_TRUE, "Failed to open GLFW window.");

	string title("PtBi ");
	title += VER_STRING;
	glfwSetWindowTitle(title.c_str());
	glfwSetWindowPos(10, 10);

	dataPointers[0] = malloc(data_size);
	dataPointers[1] = malloc(data_size);

	glewInit();
	checkExtensions();

	ilInit();

	glfwDisable(GLFW_AUTO_POLL_EVENTS);
	glfwSwapInterval(0);
	glfwSetWindowCloseCallback(closeCallback);
	glfwSetWindowSizeCallback(resizeCallback);
	glfwSetMousePosCallback(mousePosCallback);
	glfwSetKeyCallback(keyCallback);

	hdc = wglGetCurrentDC();
	hrc = wglGetCurrentContext();

	initGL();

	switch(capture.getPixelFormat()) {
	case CapturePixelFormat::YUV: 
		initialConvert = new GLFragmentProgram("shaders/uyvy_to_rgb_smooth.glsl", getShaderPrependString());
		break;
	case CapturePixelFormat::ARGB8:
		initialConvert = new GLFragmentProgram("shaders/argb_input.glsl", getShaderPrependString());
		break;
	case CapturePixelFormat::BGRA8:
		initialConvert = new GLFragmentProgram("shaders/bgra_input.glsl", getShaderPrependString());
		break;
	default:
		RT_ASSERT(false, "Unsupported pixel type.");
	}

	buffer = new GLRenderTexture(getW(), getH(), GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE);
	buffer->setFilterMode(GL_LINEAR);
	buffer2 = new GLRenderTexture(getW(), getH(), GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE);
	buffer2->setFilterMode(GL_LINEAR);

	scalingManager = new ScalingManager(*this);
	aaManager = new AAManager(*this);
	ipManager = new IPManager(*this);
	keyBinding = new KeyBinding(this);
	capture.registerDisplayListener(this);

	hwnd = GetForegroundWindow();

	RT_GL_ASSERT("Error during GL initialization.");

	reshape(reqW, reqH);
	
	graphicsReportText = std::make_shared<StaticText>("", 25.0f,440.0f);
	Console::get().add(graphicsReportText);
}