#ifndef	ARCH_COMMON_GL_CTX_H
#define	ARCH_COMMON_GL_CTX_H

#include <../arch/common/winlib.h>
#include <../include/GL/gl.h>

#ifdef	ARCH_WINDOWING_SUPPORTED

#define ARCH_COMMON_GL_CONTEXT_FIELDS \
	libv_object_t base; \
	arch_window_p wnd; \
	vhandle_t font; \
	char *vendor, *renderer, *version, *extensions; \
	char *libv_gl_version_string;

EXTERN_STRING(gl_context_name)
#define	GL_CONTEXT_MAGIC	0x47435458 /* GCTX */

#define ARCH_CLEAR_COMMON_GL_CONTEXT_FIELDS(ctx) \
	if((ctx)->vendor) { \
		memFree((ctx)->vendor); \
		(ctx)->vendor = NULL; \
	} \
	if((ctx)->renderer) { \
		memFree((ctx)->renderer); \
		(ctx)->renderer = NULL; \
	} \
	if((ctx)->version) { \
		memFree((ctx)->version); \
		(ctx)->version = NULL; \
	} \
	if((ctx)->extensions) { \
		memFree((ctx)->extensions); \
		(ctx)->extensions = NULL; \
	} \
	if((ctx)->wnd) { \
		archWinClose((ctx)->wnd); \
		(ctx)->wnd = NULL; \
	} \
	if((ctx)->font != LIBV_INVALID_HANDLE) { \
		vglDestroyFont((ctx)->font); \
		(ctx)->font = NULL; \
	}

#define	IF_NO_GLCONTEXT(ctx) \
	(ctx) = (gl_context_p)libvIsHandle(GetThreadData()->gl_context, \
		caller_name, gl_context_name, GL_CONTEXT_MAGIC); \
	if((ctx) == LIBV_INVALID_HANDLE)

#endif	/* ARCH_WINDOWING_SUPPORTED */

#endif	/* !ARCH_COMMON_GL_CTX_H */
