#include "stdafx.h"
#include "Graphics.h"
#include "Exception.h"

namespace gui {

	Graphics3D::Graphics3D(Nat id) : identifier(id) {
		resources = new (engine()) WeakSet<Resource3D>();
	}

	Graphics3D::~Graphics3D() {
		// Things might be null in the destructor...
		if (resources) {
			WeakSet<Resource3D>::Iter i = resources->iter();
			while (Resource3D *r = i.next()) {
				if (runtime::liveObject(r))
					r->destroy(this);
			}
		}
	}

	void Graphics3D::destroy() {
		WeakSet<Resource3D>::Iter i = resources->iter();
		while (Resource3D *r = i.next()) {
			r->destroy(this);
		}
		resources->clear();
	}

	void Graphics3D::beforeRender() {}

	Bool Graphics3D::afterRender() {
		return true;
	}

	void Graphics3D::surfaceDestroyed() {}

	Bool Graphics3D::attach(Resource3D *resource) {
		return resources->put(resource);
	}

	void Graphics3D::createResource(Resource3D *resource, void *&data, Resource3D::Cleanup &cleanup) {
		throw new (this) NotSupported(S("Can not create this resource type."));
	}

	void Graphics3D::updateResource(Resource3D *resource, void *data, const DirtyRange &dirty) {
		throw new (this) NotSupported(S("Can not update this resource type."));
	}

}
