Exemplo n.º 1
0
std::string read_text_file(const std::string& path)
{
#if 1
	const auto vec = read_binary_file(path);
	return std::string(begin(vec), end(vec));
#else
	ifstream file;
	file.open(path.c_str());

	std::string content = "";
	std::string line;

	if (!file.is_open()) {
		ABORT_F("Failed to open '%s'", path.c_str());
	}

	while (!file.eof()) {
		getline(file, line);
		content += line + "\n";
	}

	file.close();
	return content;
#endif
}
Exemplo n.º 2
0
size_t VertComp::sizeBytes() const
{
	if (type == GL_BYTE)           { return num_comps * sizeof(int8_t);   }
	if (type == GL_UNSIGNED_BYTE)  { return num_comps * sizeof(uint8_t);  }
	if (type == GL_SHORT)          { return num_comps * sizeof(int16_t);  }
	if (type == GL_UNSIGNED_SHORT) { return num_comps * sizeof(uint16_t); }
	if (type == GL_FLOAT)          { return num_comps * sizeof(float);    }
	ABORT_F("Unknow type: %u", type);
}
Exemplo n.º 3
0
int Program::get_attribute_loc(const std::string& attrib_name) const
{
	for (const auto& attrib : _attributes) {
		if (attrib.name == attrib_name) {
			return attrib.location;
		}
	}
	ABORT_F("Failed to find location for attribute '%s' in program '%s'",
			attrib_name.c_str(), _debug_name.c_str());
}
Exemplo n.º 4
0
int Program::get_uniform_loc(const std::string& uniform_name) const
{
	for (const auto& uniform : _uniforms) {
		if (uniform.name == uniform_name) {
			return uniform.location;
		}
	}
	ABORT_F("Failed to find location for uniform '%s' in program '%s'",
			uniform_name.c_str(), _debug_name.c_str());
}
Exemplo n.º 5
0
unsigned Texture::bits_per_pixel() const
{
	if (_bpp != 0) {
		return _bpp;
	} else {
		switch (_format) {
			case ImageFormat::Alpha8:  return  1 * 8;
			case ImageFormat::Red8:    return  1 * 8;
			case ImageFormat::RGB24:   return  3 * 8;
			case ImageFormat::RGBA32:  return  4 * 8;
			case ImageFormat::BGRA32:  return  4 * 8;
			case ImageFormat::AlphaHF: return  2 * 8;
			case ImageFormat::RGBAHF:  return  8 * 8;
			case ImageFormat::RGBAf:   return 16 * 8;
			default: ABORT_F("Unknown image format: %d", (int)_format);
		}
	}
}
Exemplo n.º 6
0
bool link_program(unsigned prog, const char* debug_name)
{
	CHECK_FOR_GL_ERROR;

	glLinkProgram(prog);

#if defined(DEBUG)
	print_link_log(prog, debug_name);
#endif

	GLint status;
	glGetProgramiv(prog, GL_LINK_STATUS, &status);
	if (status == GL_FALSE) {
		print_link_log(prog, debug_name);
		ABORT_F("Failed to link GL program");
	}

	return true;
}
Exemplo n.º 7
0
bool validate_program(GLuint prog, const char* debug_name)
{
	CHECK_FOR_GL_ERROR;

	GLint log_length, status;

	glValidateProgram(prog);
	glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &log_length);
	if (log_length > 0) {
		std::vector<GLchar> log((size_t)log_length);
		glGetProgramInfoLog(prog, log_length, &log_length, log.data());
		LOG_F(INFO, "Program '%s' validate log:\n%s", debug_name, log.data());
	}

	glGetProgramiv(prog, GL_VALIDATE_STATUS, &status);
	if (status == 0) {
		ABORT_F("Program status is zero: %s", debug_name);
	}

	return true;
}
Exemplo n.º 8
0
void test_error_contex()
{
	{ ERROR_CONTEXT("THIS SHOULDN'T BE PRINTED", "scoped"); }
	ERROR_CONTEXT("Parent thread value", 42);
	{ ERROR_CONTEXT("THIS SHOULDN'T BE PRINTED", "scoped"); }
	char parent_thread_name[17];
	loguru::get_thread_name(parent_thread_name, sizeof(parent_thread_name), false);
	ERROR_CONTEXT("Parent thread name", &parent_thread_name[0]);

	const auto parent_ec_handle = loguru::get_thread_ec_handle();

	std::thread([=]{
		loguru::set_thread_name("EC test thread");
		ERROR_CONTEXT("parent error context", parent_ec_handle);
		{ ERROR_CONTEXT("THIS SHOULDN'T BE PRINTED", "scoped"); }
		ERROR_CONTEXT("const char*",       "test string");
		ERROR_CONTEXT("integer",           42);
		ERROR_CONTEXT("float",              3.14f);
		ERROR_CONTEXT("double",             3.14);
		{ ERROR_CONTEXT("THIS SHOULDN'T BE PRINTED", "scoped"); }
		ERROR_CONTEXT("char A",            'A');
		ERROR_CONTEXT("char backslash",    '\\');
		ERROR_CONTEXT("char double-quote", '\"');
		ERROR_CONTEXT("char single-quote", '\'');
		ERROR_CONTEXT("char zero",         '\0');
		ERROR_CONTEXT("char bell",         '\b');
		ERROR_CONTEXT("char feed",         '\f');
		ERROR_CONTEXT("char newline",      '\n');
		ERROR_CONTEXT("char return",       '\r');
		ERROR_CONTEXT("char tab",          '\t');
		ERROR_CONTEXT("char x13",          '\u0013');
		{ ERROR_CONTEXT("THIS SHOULDN'T BE PRINTED", "scoped"); }
		CustomType custom{"custom_contents"};
		ERROR_CONTEXT("CustomType", &custom);
		ABORT_F("Intentional abort");
	}).join();
}
Exemplo n.º 9
0
int main(int argc, char* argv[])
{
	if (argc > 1 && argv[1] == std::string("test"))
	{
		return main_test(argc, argv);
	}

	loguru::init(argc, argv);

	// auto verbose_type_name = loguru::demangle(typeid(std::ofstream).name());
	// loguru::add_stack_cleanup(verbose_type_name.c_str(), "std::ofstream");
	// std::ofstream os;
	// die(os);

	if (argc == 1)
	{
		loguru::add_file("latest_readable.log", loguru::Truncate, loguru::Verbosity_INFO);
		loguru::add_file("everything.log",      loguru::Append,   loguru::Verbosity_MAX);

		LOG_F(INFO, "Loguru test");
		test_thread_names();

		test_scopes();
		test_levels();
		test_stream();
	}
	else
	{
		std::string test = argv[1];
		if (test == "ABORT_F") {
			ABORT_F("ABORT_F format message");
		} else if (test == "ABORT_S") {
			ABORT_S() << "ABORT_S stream message";
		} else if (test == "assert") {
			const char* ptr = 0;
			assert(ptr && "Error that was unexpected");
		} else if (test == "LOG_F(FATAL)") {
			LOG_F(FATAL, "Fatal format message");
		} else if (test == "LOG_S(FATAL)") {
			LOG_S(FATAL) << "Fatal stream message";
		} else if (test == "CHECK_NOTNULL_F") {
			const char* ptr = 0;
			CHECK_NOTNULL_F(ptr);
		} else if (test == "CHECK_F") {
			CHECK_F(1 > 2);
		} else if (test == "CHECK_EQ_F") {
			CHECK_EQ_F(always_increasing(),  0);
			CHECK_EQ_F(always_increasing(),  1);
			CHECK_EQ_F(always_increasing(), 42);
		} else if (test == "CHECK_EQ_F_int") {
			int x = 42;
			CHECK_EQ_F(x, x + 1);
		} else if (test == "CHECK_EQ_F_unsigned") {
			unsigned x = 42;
			CHECK_EQ_F(x, x + 1);
		} else if (test == "CHECK_EQ_F_size_t") {
			size_t x = 42;
			CHECK_EQ_F(x, x + 1);
		} else if (test == "CHECK_EQ_F_message") {
			CHECK_EQ_F(always_increasing(),  0, "Should pass");
			CHECK_EQ_F(always_increasing(),  1, "Should pass");
			CHECK_EQ_F(always_increasing(), 42, "Should fail");
		} else if (test == "CHECK_EQ_S") {
			std::string str = "right";
			CHECK_EQ_S(str, "wrong") << "Expected to fail, since `str` isn't \"wrong\" but \"" << str << "\"";
		} else if (test == "CHECK_LT_S") {
			CHECK_EQ_S(always_increasing(), 0);
			CHECK_EQ_S(always_increasing(), 1);
			CHECK_EQ_S(always_increasing(), 42);
		} else if (test == "CHECK_LT_S_message") {
			CHECK_EQ_S(always_increasing(),  0) << "Should pass";
			CHECK_EQ_S(always_increasing(),  1) << "Should pass";
			CHECK_EQ_S(always_increasing(), 42) << "Should fail!";
		} else if (test == "deep_abort") {
			deep_abort_10({"deep_abort"});
		} else if (test == "SIGSEGV") {
			test_SIGSEGV_2();
		} else if (test == "hang") {
			test_hang_2();
		} else {
			LOG_F(ERROR, "Unknown test: '%s'", test.c_str());
		}
	}
}
Exemplo n.º 10
0
void the_one_where_the_problem_is(const std::vector<std::string>& v) {
	ABORT_F("Abort deep in stack trace, msg: %s", v[0].c_str());
}
Exemplo n.º 11
0
void Texture::set_mip_data(const void* data_ptr, Size size, unsigned mip_level)
{
	NAME_PAINT_FUNCTION();
	bind();

	//glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // FIXME

	CHECK_FOR_GL_ERROR;

	GLenum src_format;
	GLint  dst_format;
	GLenum element_format;

	switch (_format)
	{
		case ImageFormat::Alpha8:
			src_format = GL_RED;
			dst_format = GL_RED;
			element_format = GL_UNSIGNED_BYTE;
			break;

		case ImageFormat::Red8:
			src_format = GL_RED;
			dst_format = src_format;
			element_format = GL_UNSIGNED_BYTE;
			break;

		case ImageFormat::RGB24:
			src_format = GL_RGB;
			dst_format = GL_RGB;
			element_format = GL_UNSIGNED_BYTE;
			break;

		case ImageFormat::RGBA32:
			src_format = GL_RGBA;
			dst_format = GL_RGBA;
			element_format = GL_UNSIGNED_BYTE;
			break;

		case ImageFormat::BGRA32:
			src_format = GL_BGRA;
			dst_format = GL_RGBA;
			element_format = GL_UNSIGNED_BYTE;
			break;

		case ImageFormat::AlphaHF:
			//src_format = GL_R16F_EXT; // WRONG
			//src_format = GL_RGBA16F_EXT; // WRONG
			//src_format = GL_LUMINANCE; // Doesn't work with FBO
			src_format = GL_ALPHA; // The number of components
			dst_format = src_format;
#if TARGET_OS_IPHONE
			element_format = GL_HALF_FLOAT_OES;
#else
			element_format = GL_HALF_FLOAT;
#endif
			// TODO: GL_EXT_texture_rg ?
			break;

		case ImageFormat::RGBAHF:
			src_format = GL_RGBA; // The number of components
			dst_format = src_format;
#if TARGET_OS_IPHONE
			element_format = GL_HALF_FLOAT_OES;
#else
			element_format = GL_HALF_FLOAT;
#endif
			break;

		default:
			ABORT_F("Unknown image format");
	}

	CHECK_FOR_GL_ERROR;

	glTexImage2D(GL_TEXTURE_2D, mip_level, dst_format,
					 (GLsizei)size.x, (GLsizei)size.y, 0,
					 src_format, element_format, data_ptr);

	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL,  mip_level);

	CHECK_FOR_GL_ERROR;

	_has_data = true;
}