#include "utils.h"
#include <GL/glew.h>
#include <stdexcept>

namespace utils {
	void throwIfGLError(const std::string& msg) {
		std::string err;
		while(true) {
			GLenum error = glGetError();
			if(error != GL_NO_ERROR) {
				const char* errorStr = (const char*)gluErrorString(error);
				if(errorStr) {
					err += std::string(errorStr) + "\n";
				}
			} else {
				break;
			}
		}

		if(!err.empty()) {
			throw std::runtime_error(msg + ": " + err);
		}
	}

	void clearGLError() {
		while(glGetError() != GL_NO_ERROR);
	}
}
