Beispiel #1
0
ThreadPool::ThreadPool(size_t num_threads)
{
    CHECK_NE_F(num_threads, 0u);
    for (size_t i = 0; i < num_threads; ++i) {
        _threads.emplace_back([=](){ _thread_worker(i); });
    }
}
Beispiel #2
0
MemMap::MemMap(const char* path)
{
	auto file = open(path, O_RDONLY);
	struct stat file_status;
	auto ret = fstat(file, &file_status);
	if (ret != 0) {
		throw std::runtime_error(
			(std::string)"Failed to stat file '" + path + "' - maybe it's not there?");
	}

	_size = (size_t)file_status.st_size;
	_data = mmap(0, _size, PROT_READ, MAP_PRIVATE, file, 0);
	CHECK_NE_F(_data, MAP_FAILED);

	// Note this will not close the file/mapping right now, as it will be held until unmapped.
	close(file);
}
Beispiel #3
0
Program::Program(const std::string& vs, const std::string& fs, const std::string& debug_name)
	: _debug_name(debug_name)
{
	VLOG_SCOPE_F(1, "Compiling GLSL %s", debug_name.c_str());

	CHECK_FOR_GL_ERROR;

	GLuint vs_id = load_shader(GL_VERTEX_SHADER,   vs.c_str(), debug_name.c_str());
	GLuint fs_id = load_shader(GL_FRAGMENT_SHADER, fs.c_str(), debug_name.c_str());

	_program = glCreateProgram();

#if TARGET_OS_IPHONE
	// For debugger:
	glLabelObjectEXT(GL_PROGRAM_OBJECT_EXT, _program, 0, debug_name.c_str());
#endif

	glAttachShader(_program, vs_id);
	glAttachShader(_program, fs_id);

	//GLuint color_number = 0;
	//glBindFragDataLocation(_program, color_number, "out_frag_color");

	link_program(_program, debug_name.c_str());

	/* too early to validate: uniforms haven't been bound yet.
	   Using two samplers of different type (sampler2D and sampler_cube)
	   will break the validation.
	 */
	//validate();

	CHECK_FOR_GL_ERROR;

	//debug_print();

#if 0
	LOG_F(INFO, "Shader: %s", debug_name.c_str());
	LOG_F(INFO, "-------------------------------------");
	LOG_F(INFO, "%s", vs.c_str());
	LOG_F(INFO, "-------------------------------------");
	LOG_F(INFO, "%s", fs.c_str());
	LOG_F(INFO, "-------------------------------------");
#endif

	GLint num_attribs;
	glGetProgramiv(_program, GL_ACTIVE_ATTRIBUTES, &num_attribs);

	for (int i=0; i<num_attribs; ++i) {
		GLint size;
		GLenum type;
		GLchar name[1024];
		glGetActiveAttrib(_program, i, sizeof(name), NULL, &size, &type, name);
		int location = glGetAttribLocation(_program, name);
		CHECK_NE_F(location, -1, "Attribute '%s' not found in shader '%s'", name, _debug_name.c_str());
		VLOG_F(1, "Attribute %d: %10s, %d x %s, location: %d", i, name, size, type_to_string(type), location);
		_attributes.emplace_back(Attribute{name, size, type, location});
	}

	GLint num_uniforms;
	glGetProgramiv(_program, GL_ACTIVE_UNIFORMS, &num_uniforms);

	for (int i=0; i<num_uniforms; ++i) {
		GLint size;
		GLenum type;
		GLchar name[1024];
		glGetActiveUniform(_program, i, sizeof(name), NULL, &size, &type, name);
		int location = glGetUniformLocation(_program, name);
		CHECK_NE_F(location, -1, "Uniform '%s' not found in shader '%s'", name, _debug_name.c_str());
		VLOG_F(1, "Uniform %d: %10s, %d x %s, location: %d", i, name, size, type_to_string(type), location);
		_uniforms.emplace_back(Uniform{name, size, type, location});
	}
}