/* +------------------------------------------------------+ ____/ \____ /| - Open source game framework licensed to freely use, | \ / / | copy, modify and sell without restriction | +--\ ^__^ /--+ | | | ~/ \~ | | - created for | | ~~~~~~~~~~~~ | +------------------------------------------------------+ | SPACE ~~~~~ | / | ~~~~~~~ BOX |/ +-------------*/ #include "Log.hpp" void sb::Log::log(const std::string& message, const Level level, const int category) { SDL_LogMessage(category, static_cast(level), "%s", message.c_str()); } void sb::Log::log(const std::ostringstream& message, const Level level, const int category) { log(message.str(), level, category); } bool sb::Log::gl_errors(const std::string& heading) { GLenum error; bool error_logged = false; while ((error = glGetError()) != GL_NO_ERROR) { error_logged = true; std::ostringstream message; if (!heading.empty()) { message << heading << ": "; } if (error == GL_INVALID_ENUM) { message << "GL_INVALID_ENUM, an unacceptable value is specified for an enumerated argument"; } else if (error == GL_INVALID_VALUE) { message << "GL_INVALID_VALUE, a numeric argument is out of range"; } else if (error == GL_INVALID_OPERATION) { message << "GL_INVALID_OPERATION, the specified operation is not allowed in the current state"; } else if (error == GL_INVALID_FRAMEBUFFER_OPERATION) { message << "GL_INVALID_FRAMEBUFFER_OPERATION, the framebuffer object is not complete"; } else if (error == GL_OUT_OF_MEMORY) { message << "GL_OUT_OF_MEMORY, there is not enough memory left to execute the command"; } /* The following error codes aren't available in Open GL ES or on macOS */ #if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !defined(ANDROID) && !defined(__MACOS__) else if (error == GL_STACK_UNDERFLOW) { message << "GL_STACK_UNDERFLOW, an attempt has been made to perform an operation that would " << "cause an internal stack to underflow"; } else if (error == GL_STACK_OVERFLOW) { message << "GL_STACK_OVERFLOW, an attempt has been made to perform an operation that would " << "cause an internal stack to overflow"; } #endif log(message); } return error_logged; } std::ostringstream sb::Log::sdl_error(const std::string& message, const Level level) { std::ostringstream full_message; full_message << message << " " << SDL_GetError(); log(full_message, level); return full_message; }