#pragma once

#if !defined(TD_IMPL_OPENGL_ES2) \
 && !defined(TD_IMPL_OPENGL_ES3) \
 && !defined(TD_IMPL_OPENGL_LOADER_GL3W) \
 && !defined(TD_IMPL_OPENGL_LOADER_GLEW) \
 && !defined(TD_IMPL_OPENGL_LOADER_GLAD) \
 && !defined(TD_IMPL_OPENGL_LOADER_GLBINDING2) \
 && !defined(TD_IMPL_OPENGL_LOADER_GLBINDING3) \
 && !defined(TD_IMPL_OPENGL_LOADER_CUSTOM) \
 && !defined(__ANDROID__)

#if defined(__has_include)

#if __has_include(<GL/glew.h>)
	#define TD_IMPL_OPENGL_LOADER_GLEW
#elif __has_include(<glad/glad.h>)
	#define TD_IMPL_OPENGL_LOADER_GLAD
#elif __has_include(<GL/gl3w.h>)
	#define TD_IMPL_OPENGL_LOADER_GL3W
#elif __has_include(<glbinding/glbinding.h>)
	#define TD_IMPL_OPENGL_LOADER_GLBINDING3
#elif __has_include(<glbinding/Binding.h>)
	#define TD_IMPL_OPENGL_LOADER_GLBINDING2
#else
	#error "Cannot detect OpenGL loader!"
#endif

#else
	#error "Cannot detect loader with include detection !"
#endif
#endif



// Include correct files

#if defined(__ANDROID__)
	#include <GLES3/gl3.h>
#elif defined(TD_IMPL_OPENGL_LOADER_GL3W)
	#include <GL/gl3w.h>            // Needs to be initialized with gl3wInit() in user's code
#elif defined(TD_IMPL_OPENGL_LOADER_GLEW)
	#include <GL/glew.h>            // Needs to be initialized with glewInit() in user's code.
#elif defined(TD_IMPL_OPENGL_LOADER_GLAD)
	#include <glad/glad.h>          // Needs to be initialized with gladLoadGL() in user's code.
#elif defined(TD_IMPL_OPENGL_LOADER_GLBINDING2)
	#ifndef GLFW_INCLUDE_NONE
	#define GLFW_INCLUDE_NONE       // GLFW including OpenGL headers causes ambiguity or multiple definition errors.
	#endif
	#include <glbinding/Binding.h>  // Needs to be initialized with glbinding::Binding::initialize() in user's code.
	#include <glbinding/gl/gl.h>
	using namespace gl;
#elif defined(TD_IMPL_OPENGL_LOADER_GLBINDING3)
	#ifndef GLFW_INCLUDE_NONE
	#define GLFW_INCLUDE_NONE       // GLFW including OpenGL headers causes ambiguity or multiple definition errors.
	#endif
	#include <glbinding/glbinding.h>// Needs to be initialized with glbinding::initialize() in user's code.
	#include <glbinding/gl/gl.h>
	using namespace gl;
#else
	#include TD_IMPL_OPENGL_LOADER_CUSTOM
#endif