Пример #1
0
base::app::app()
	: _velocity_boost(false)
    , _position(0.0, 10.3, 0.0)
	, _frame_number(0)
    , _fovy(45.f)
    , _aspect(float(get_wnd_width()) / float(get_wnd_height()))
	, _benchmark_mode(cfg().test != -1)

    , _shutdown(false)
	, _shutdown_code(base::ecOK)
{ 
	assert(_app == 0);
    _app = this; 

	// init mouse stuff
	base::set_mouse_pos(glm::ivec2(200));
	_last_mouse_pos = base::get_mouse_pos();
	_mouse_pos = glm::ivec2(180, 0);

	if (base::cfg().sceneType == base::config::stGrass){
		_position = glm::vec3(0.0, 1.8, 0.0);
	} 
	else if (base::cfg().sceneType == base::config::stBuildings){
		_mouse_pos = glm::vec2(45.4f, 0.4f);
		_position = glm::vec3(-987.37, 26.44, 981.66);
	}
}
Пример #2
0
void base::app::create_perspective_matrix(frame_context *fc)
{
	fc->_mprj=glm::perspective(
		45.0f,
		float(get_wnd_width()) / float(get_wnd_height()),
		0.1f,
		500.0f);
}
	ClassifierInformation RecognitionController::load_classifier_from_file(const std::string& classifier_file_name)
	{
		MultiClassViolaJonesController* controller = (MultiClassViolaJonesController*)_multi_class_viola_jones_controller;
		int my_id = _last_classifier_id++;

		try
		{
			auto classifier = ClassifierLoader::load_from_file(classifier_file_name, ClassificationTag(my_id), ClassificationTag(0));
			int wnd_width = classifier.get_wnd_width();
			int wnd_height = classifier.get_wnd_height();

			controller->add_recognizer(my_id, std::move(classifier));
			
			return ClassifierInformation(my_id, wnd_width, wnd_height);
		}
		catch (ClassifierLoadingException& cl_exc)
		{
			throw RecognitionException(std::string("Classifier loading exception: ") + cl_exc.what());
		}
		catch (LibraryException& l_exc)
		{
			throw RecognitionException(std::string("Library exception: ") + l_exc.what());
		}
	}
Пример #4
0
void base::app::capture_screen()
{
	const int screen_size = 
		get_wnd_width() 
			* get_wnd_height() 
			* base::get_pfd(CAPTURE_PF)->_size;
	const int tmp_head = (_rb_head + 1) & RB_BUFFERS_MASK;
	if(tmp_head == _rb_tail) {
		printf("we are too fast there is no free screen buffer!\n");
	}
	else {
		screen_buffer *sc = _screen_buffers_rb + tmp_head;

		glReadBuffer(GL_BACK);

		glBindTexture(GL_TEXTURE_2D, sc->_tmp_texture);
		glCopyTexSubImage2D(
			GL_TEXTURE_2D,
			0,
			0, 0,
			0, 0,
			get_wnd_width(), get_wnd_height());
		glBindTexture(GL_TEXTURE_2D, 0);

		glQueryCounter(sc->_queries[0], GL_TIMESTAMP);

		glBindBuffer(
			GL_PIXEL_PACK_BUFFER,
			base::cfg().use_nvidia_fast_download ? sc->_tmp_buffer : sc->_buffer);
		glReadPixels(
			0,
			0,
			get_wnd_width(),
			get_wnd_height(),
			base::get_pfd(CAPTURE_PF)->_format,
			base::get_pfd(CAPTURE_PF)->_type,
			0);
		glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
		
		glQueryCounter(sc->_queries[1], GL_TIMESTAMP);

		if(base::cfg().use_nvidia_fast_download) {
			glBindBuffer(GL_COPY_READ_BUFFER, sc->_tmp_buffer);
			glBindBuffer(GL_COPY_WRITE_BUFFER, sc->_buffer);
			glCopyBufferSubData(
				GL_COPY_READ_BUFFER,
				GL_COPY_WRITE_BUFFER,
				0,
				0,
				screen_size);
		}
		
		glQueryCounter(sc->_queries[2], GL_TIMESTAMP);
		
		sc->_fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
		sc->_frame_num = _frame_number;
		sc->_stage = 0;

		// update ring buffer head
		_rb_head = tmp_head;
	}
}
Пример #5
0
void base::app::process_captured_screen()
{
	while(_rb_tail != _rb_head) {
		const int screen_size = 
			get_wnd_width() 
				* get_wnd_height() 
				* base::get_pfd(CAPTURE_PF)->_size;
		const int tmp_tail = (_rb_tail + 1) & RB_BUFFERS_MASK;
		screen_buffer *sc = _screen_buffers_rb + tmp_tail;

		GLenum res = glClientWaitSync(sc->_fence, 0, 0);
		if(res == GL_ALREADY_SIGNALED || res == GL_CONDITION_SATISFIED) { // AMD returns GL_CONDITION_SATISFIED only BUG?
			glDeleteSync(sc->_fence);

			_timer.start();

			if(base::cfg().use_pinned_memory) {
				// process data
				//memcpy(ptr_dst, sc->_pinned_ptr_aligned, screen_size);
				glBindBuffer(GL_PIXEL_UNPACK_BUFFER, sc->_buffer);
			}
			else {
				glBindBuffer(GL_COPY_READ_BUFFER, sc->_buffer);
				/*glBindBuffer(GL_PIXEL_UNPACK_BUFFER, sc->_showtime_buffer);
				char *ptr_dst = reinterpret_cast<char*>(
					glMapBufferRange(
						GL_PIXEL_UNPACK_BUFFER,
						0,
						screen_size,
						GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT));*/
				char *ptr_src = reinterpret_cast<char*>(
					glMapBufferRange(
						GL_COPY_READ_BUFFER,
						0,
						screen_size,
						GL_MAP_READ_BIT));

				//memcpy(ptr_dst, ptr_src, screen_size);

				glUnmapBuffer(GL_COPY_READ_BUFFER);
				//glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
			}

			glBindTexture(GL_TEXTURE_2D, _showtime_tex);
			glTexImage2D(
				GL_TEXTURE_2D,
				0,
				base::get_pfd(CAPTURE_PF)->_internal,
				get_wnd_width(),
				get_wnd_height(),
				0,
				base::get_pfd(CAPTURE_PF)->_format,
				base::get_pfd(CAPTURE_PF)->_type, 
				0);
			glBindTexture(GL_TEXTURE_2D, 0);

			glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);

			const double map_time = _timer.elapsed_time();

			__int64 result[3]={0,};
			glGetQueryObjecti64v(sc->_queries[2], GL_QUERY_RESULT, result + 2);
			glGetQueryObjecti64v(sc->_queries[1], GL_QUERY_RESULT, result + 1);
			glGetQueryObjecti64v(sc->_queries[0], GL_QUERY_RESULT, result);
			const double coef_n2m = 1.0 / 1000000.0;
			const double time0 = double(result[1] - result[0]) * coef_n2m;
			const double time1 = double(result[2] - result[1]) * coef_n2m;
			static int counter = 0;

			if((counter++ % 64) == 0) {
				printf("read %.2f ms / %.2f GB/s copy: %.2f ms / %.2f GB/s lag: %u  map: %.2f ms / %.2f GB/s\n",
					time0,
					(double(screen_size) / time0) * (1.0 / double(0x100000)),
					time1,
					time1 > 0.01 ? (double(screen_size) / time1) * (1.0 / double(0x100000)) : 0.0,
					_frame_number - sc->_frame_num,
					map_time,
					map_time > 0.01 ? (double(screen_size) / map_time) * (1.0 / double(0x100000)) : 0.0);
			}

			_rb_tail = tmp_tail;
		}
		else {
			break;
		}
	}
}
Пример #6
0
void base::app::init_screen_capture()
{
	// pre-allocate buffers for screen capture
	const int screen_size = 
		get_wnd_width() 
			* get_wnd_height() 
			* base::get_pfd(CAPTURE_PF)->_size;
	
	screen_buffer * const e = _screen_buffers_rb + RB_BUFFERS_SIZE;
	for(screen_buffer *i = _screen_buffers_rb; i != e; ++i) {
		glGenBuffers(1, &i->_buffer);

		if(base::cfg().use_pinned_memory) {
			i->_pinned_ptr = new char[screen_size + 0x1000];
			i->_pinned_ptr_aligned = reinterpret_cast<char*>(
				unsigned(i->_pinned_ptr + 0xfff) & (~0xfff));

			glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_AMD, i->_buffer);
			glBufferData(
				GL_EXTERNAL_VIRTUAL_MEMORY_AMD,
				screen_size,
				i->_pinned_ptr_aligned,
				GL_STREAM_READ);
			glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_AMD, 0);
		}
		else {
			glBindBuffer(GL_PIXEL_PACK_BUFFER, i->_buffer);
			glBufferData(GL_PIXEL_PACK_BUFFER, screen_size, 0, GL_STREAM_READ);
		}

		glGenBuffers(1, &i->_tmp_buffer);
		glBindBuffer(GL_PIXEL_PACK_BUFFER, i->_tmp_buffer);
		glBufferData(GL_PIXEL_PACK_BUFFER, screen_size, 0, GL_STREAM_COPY);
		glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);

		i->_tmp_texture = base::create_texture(
			get_wnd_width(),
			get_wnd_height(),
			CAPTURE_PF,
			0);

		glGenQueries(3, i->_queries);

		glGenBuffers(1, &i->_showtime_buffer);
		glBindBuffer(GL_PIXEL_UNPACK_BUFFER, i->_showtime_buffer);
		glBufferData(GL_PIXEL_UNPACK_BUFFER, screen_size, 0, GL_STREAM_DRAW);
		glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
	}
	
	_showtime_tex = base::create_texture(
			get_wnd_width(),
			get_wnd_height(),
			CAPTURE_PF,
			0);

	// init round buffer positions
	_rb_head = _rb_tail = 0;

	// create framebuffer
	glGenFramebuffers(1, &_fb);
}