/***************************************************************************
                            QGLContext.m -  description
                             -------------------
    begin                : Wed Nov 21 12:08:37 2001
    copyright            : (C) 2000-2001 Lost Highway Ltd. All rights reserved.
    email                : Lost_Highway@tipitina.demon.co.uk
    generated by         : duke@tipitina on Wed Nov 21 12:08:37 2001, using kalyptus 0.9.
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This library is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 ***************************************************************************/

#include <qtc/qt_QString.h>
#include <qtc/qt_QCString.h>
#include <qtc/qt_QGLContext.h>
#include <qtobjc/QGLContext.h>
#include <qtobjc/QGLFormat.h>
#include <qtobjc/QPaintDevice.h>
#include <qtobjc/QColor.h>

@implementation  QGLContext


- initWithGLFormat: (QGLFormat*)format device: (QPaintDevice *)device
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QGLContext((qt_QGLFormat*) [format qt], (qt_QPaintDevice *) [device qt])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- (void) dealloc
{
	if ([self qt] != 0L) {
		if ([self allocatedInObjcWorld]) {
			qt_del_QGLContext((qt_QGLContext *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

- (BOOL) create: (QGLContext*)shareContext
{
	return (BOOL) qt_QGLContext_create((qt_QGLContext *)[self qt], (qt_QGLContext*) [shareContext qt]);
}

- (BOOL) create
{
	return (BOOL) qt_QGLContext_create((qt_QGLContext *)[self qt], 0);
}

- (BOOL) isValid
{
	return (BOOL) qt_QGLContext_isValid((qt_QGLContext *)[self qt]);
}

- (BOOL) isSharing
{
	return (BOOL) qt_QGLContext_isSharing((qt_QGLContext *)[self qt]);
}

- reset
{
	qt_QGLContext_reset((qt_QGLContext *)[self qt]);
	return self;
}

- (QGLFormat*) format
{
	return (QGLFormat*) [QtSupport objectForQtKey: qt_QGLContext_format((qt_QGLContext *)[self qt]) withClass: [QGLFormat class] allocatedInObjcWorld: YES];
}

- (QGLFormat*) requestedFormat
{
	return (QGLFormat*) [QtSupport objectForQtKey: qt_QGLContext_requestedFormat((qt_QGLContext *)[self qt]) withClass: [QGLFormat class] allocatedInObjcWorld: YES];
}

- setFormat: (QGLFormat*)format
{
	qt_QGLContext_setFormat((qt_QGLContext *)[self qt], (qt_QGLFormat*) [format qt]);
	return self;
}

- makeCurrent
{
	qt_QGLContext_makeCurrent((qt_QGLContext *)[self qt]);
	return self;
}

- swapBuffers
{
	qt_QGLContext_swapBuffers((qt_QGLContext *)[self qt]);
	return self;
}

- (QPaintDevice*) device
{
	return (QPaintDevice*) [QtSupport objectForQtKey: qt_QGLContext_device((qt_QGLContext *)[self qt]) withClass: [QPaintDevice class] allocatedInObjcWorld: YES];
}

- (QColor*) overlayTransparentColor
{
	return (QColor*) [QtSupport objectForQtKey: qt_QGLContext_overlayTransparentColor((qt_QGLContext *)[self qt]) withClass: [QColor class] allocatedInObjcWorld: YES];
}

+ (QGLContext*) currentContext
{
	return (QGLContext*) [QtSupport objectForQtKey: qt_QGLContext_currentContext() withClass: [QGLContext class] allocatedInObjcWorld: YES];
}

- (BOOL) chooseContext: (QGLContext*)shareContext
{
	return (BOOL) qt_QGLContext_chooseContext((qt_QGLContext *)[self qt], (qt_QGLContext*) [shareContext qt]);
}

- (BOOL) chooseContext
{
	return (BOOL) qt_QGLContext_chooseContext((qt_QGLContext *)[self qt], 0);
}

- doneCurrent
{
	qt_QGLContext_doneCurrent((qt_QGLContext *)[self qt]);
	return self;
}

//- (int) choosePixelFormat: (void*)pfd pdc: (void *)pdc
//{
//	return (int) qt_QGLContext_choosePixelFormat((qt_QGLContext *)[self qt], (void*)pfd, (void *)pdc);
//}

//- (void*) tryVisual: (QGLFormat*)f bufDepth: (int)bufDepth
//{
//	return (void*) qt_QGLContext_tryVisual((qt_QGLContext *)[self qt], (qt_QGLFormat*) [f qt], (int)bufDepth);
//}

//- (void*) tryVisual: (QGLFormat*)f
//{
//	return (void*) qt_QGLContext_tryVisual((qt_QGLContext *)[self qt], (qt_QGLFormat*) [f qt], 1);
//}

//- (void*) chooseVisual
//{
//	return (void*) qt_QGLContext_chooseVisual((qt_QGLContext *)[self qt]);
//}

//- (void*) chooseMacVisual: (GDHandle)arg1
//{
//	return (void*) qt_QGLContext_chooseMacVisual((qt_QGLContext *)[self qt], (GDHandle) arg1);
//}

- (BOOL) deviceIsPixmap
{
	return (BOOL) qt_QGLContext_deviceIsPixmap((qt_QGLContext *)[self qt]);
}

- (BOOL) windowCreated
{
	return (BOOL) qt_QGLContext_windowCreated((qt_QGLContext *)[self qt]);
}

- setWindowCreated: (BOOL)on
{
	qt_QGLContext_setWindowCreated((qt_QGLContext *)[self qt], (int)on);
	return self;
}

- (BOOL) initialized
{
	return (BOOL) qt_QGLContext_initialized((qt_QGLContext *)[self qt]);
}

- setInitialized: (BOOL)on
{
	qt_QGLContext_setInitialized((qt_QGLContext *)[self qt], (int)on);
	return self;
}

- (unsigned int) colorIndex: (QColor *)c
{
	return (unsigned int) qt_QGLContext_colorIndex((qt_QGLContext *)[self qt], (qt_QColor *) [c qt]);
}

@end
