#include <../arch/arch.h>

#ifdef	ARCH_WINDOWING_SUPPORTED

/*
 * Under Win32, no special initialization is needed.
 */

V_LOCAL vboolean V_CALL
vgl_load_proc_real(char *proc_name,void **ptr_ret, vboolean *terminate)
{
	/* NOTE: at this point LibV global lock must be hold */
	PROC proc = wglGetProcAddress((LPCSTR)proc_name);
	if(*ptr_ret && *ptr_ret != proc)
	{
		/*
		 * Different implementation (M$ generic after HW or vice versa).
		 */
		*terminate = true;
		return false;
	}
	if(proc)
	{
		*ptr_ret = (void*)proc;
		return true;
	}
	return false;
}

vboolean (V_CALL *vgl_load_proc)(char *proc_name,void **ptr_ret,
	vboolean *terminate_ret) = vgl_load_proc_real;

#ifdef	BASEGL11_DYNAMIC

HINSTANCE ogldriver = NULL;

V_LOCAL vboolean V_CALL
vgl_load_base_proc_real(char *proc_name,void **ptr_ret, vboolean *terminate)
{
	PROC proc = GetProcAddress(ogldriver,(LPCSTR)proc_name);
	if(*ptr_ret && *ptr_ret != proc)
	{
		/*
		 * Different implementation (M$ generic after HW or vice versa).
		 */
		*terminate = true;
		return false;
	}
	if(proc)
	{
		*ptr_ret = (void*)proc;
		return true;
	}
	return false;
}

V_LOCAL vboolean V_CALL
vgl_load_base_proc_init(char *proc_name,void **ptr_ret, vboolean *terminate);

vboolean (V_CALL *vgl_load_base_proc)(char *proc_name,void **ptr_ret,
	vboolean *terminate_ret) = vgl_load_base_proc_init;

V_LOCAL vboolean V_CALL
vgl_load_base_proc_init(char *proc_name,void **ptr_ret, vboolean *terminate)
{
	ogldriver = LoadLibrary("opengl32.dll");
	V_ASSERT(ogldriver);
	vgl_load_base_proc = vgl_load_base_proc_real;
	return vgl_load_base_proc(proc_name,ptr_ret,terminate);
}

#endif	/* BASEGL11_DYNAMIC */

#endif	/* ARCH_WINDOWING_SUPPORTED */
