

#ifndef __XGLVIEW_H__
#define __XGLVIEW_H__

#ifndef PandaWave_XVIEW
#include <XView.h>
#endif

#ifndef PandaWave_XDRAW
#include <XDraw.h>
#endif

#if OPT_MACOS && !defined(_AGL_H)
#include <agl.h>
#else
#include <gl.h>
#endif


class XGOpenGLView: public XGView {
	public:
		friend class		XGOpenGLDraw;
		
							XGOpenGLView( XGView *parent, XGArgStream &s );
		virtual				~XGOpenGLView();
		
		enum {
			kClassID = 'opgl'
		};
		
		void				DoDrawView( XRect );
		void				DoSizeView();
		void				DoMoveView();
	#if OPT_WINOS
		void				DoShowHide();
	#endif
		
		void				ShowBackBuffer();
		
		
		static XGOpenGLView	*GetCurrentContext();
		static void			SetCurrentContext( XGOpenGLView * );
		
	protected:
		static XGOpenGLView	*sCurrentCtx;
		
		void 				InitOpenGLView( bool doublebuffer = true,
											bool depthbuffer = true );
		virtual void		UpdateViewport();
		
		bool				fBackBuffer;
		bool				fDepthBuffer;
#if OPT_MACOS
		AGLContext			fCtx;
#endif
#if OPT_WINOS
		HWND				fHWND;
		HDC					fDC;
		HGLRC				fGLRC;
		bool				fWindowShown;
		static LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
		static ATOM			sWindowClass;
#endif
};


class XGOpenGLDraw: public XGDraw {
	public:
		XGOpenGLDraw( XGOpenGLView *v );
		~XGOpenGLDraw();
	
	private:
		XGOpenGLView *old_ctx;
};


#endif

