take jose's latest changes plus minor typo corrections EGL_MERGE
authorFaisal Memon <faisal.memon@nokia.com>
Fri, 17 Sep 2010 09:40:01 +0100
branchEGL_MERGE
changeset 180 f767bd5f4cfc
parent 119 5f371025658c
child 181 c1509651cd2b
take jose's latest changes plus minor typo corrections
egl/sfopenvg/include/eglinternal.h
egl/sfopenvg/include/openvginternal.h
egl/sfopenvg/include/riMiniEGL.h
egl/sfopenvg/include/vguinternal.h
egl/sfopenvg/riApi.cpp
egl/sfopenvg/riArray.h
egl/sfopenvg/riContext.cpp
egl/sfopenvg/riContext.h
egl/sfopenvg/riDefs.h
egl/sfopenvg/riFont.cpp
egl/sfopenvg/riFont.h
egl/sfopenvg/riImage.cpp
egl/sfopenvg/riImage.h
egl/sfopenvg/riMath.cpp
egl/sfopenvg/riMath.h
egl/sfopenvg/riMiniEGL.cpp
egl/sfopenvg/riMiniEGL.h
egl/sfopenvg/riPath.cpp
egl/sfopenvg/riPath.h
egl/sfopenvg/riPixelPipe.cpp
egl/sfopenvg/riPixelPipe.h
egl/sfopenvg/riRasterizer.cpp
egl/sfopenvg/riRasterizer.h
egl/sfopenvg/riVGU.cpp
egl/sfopenvg/symbian/eglosnativewindowtype.h
egl/sfopenvg/symbian/riEGLOS.cpp
openvg/openvgrefimplementation/sfopenvg/group/vgi.mmp
openvg/openvgrefimplementation/sfopenvg/sfopenvg/symbian/riEGLOS.cpp
openvg/openvgrefimplementation/sfopenvg/vgi/vgi.cpp
--- a/egl/sfopenvg/include/eglinternal.h	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-/*
-* Copyright (c) 2009 Symbian Foundation Ltd
-* This component and the accompanying materials are made available
-* under the terms of the License "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Symbian Foundation Ltd - initial contribution.
-* 
-* Contributors:
-*
-* Description:
-* Declaration of EGL like interface . Basically every EGL API names but prefixed with do_ e.g. do_eglInitialize
-*/
-
-#ifndef EGLINTERNAL_H
-#define EGLINTERNAL_H
-
-#include <egl.h>
-
-
-/*
- * defines set of internal egl functiosn that are 1:1 with the published egl functions.
- * E.g. eglInitialize -> do_eglInitialize
- * 
- * These do_XXX fucntions are called from the libegl.dll (which is a shim) to be processed here
- */
-
-IMPORT_C EGLint do_eglGetError(void);
-IMPORT_C EGLDisplay do_eglGetDisplay(EGLNativeDisplayType display_id);
-IMPORT_C EGLBoolean do_eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor);
-IMPORT_C EGLBoolean do_eglTerminate(EGLDisplay dpy);
-IMPORT_C const char* do_eglQueryString(EGLDisplay dpy, EGLint name);
-IMPORT_C EGLBoolean do_eglGetConfigs(EGLDisplay dpy, EGLConfig *configs,EGLint config_size, EGLint *num_config);
-IMPORT_C EGLBoolean do_eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list,EGLConfig *configs, EGLint config_size,EGLint *num_config);
-IMPORT_C EGLBoolean do_eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,EGLint attribute, EGLint *value);
-IMPORT_C EGLSurface do_eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,EGLNativeWindowType win,const EGLint *attrib_list);
-IMPORT_C EGLSurface do_eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config,const EGLint *attrib_list);
-IMPORT_C EGLSurface do_eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config,EGLNativePixmapType pixmap,const EGLint *attrib_list);
-IMPORT_C EGLBoolean do_eglDestroySurface(EGLDisplay dpy, EGLSurface surface);
-IMPORT_C EGLBoolean do_eglQuerySurface(EGLDisplay dpy, EGLSurface surface,EGLint attribute, EGLint *value);
-IMPORT_C EGLBoolean do_eglBindAPI(EGLenum api);
-IMPORT_C EGLenum do_eglQueryAPI(void);
-IMPORT_C EGLBoolean do_eglWaitClient(void);
-IMPORT_C EGLBoolean do_eglReleaseThread(void);
-IMPORT_C EGLSurface do_eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer,EGLConfig config, const EGLint *attrib_list);
-IMPORT_C EGLBoolean do_eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface,EGLint attribute, EGLint value);
-IMPORT_C EGLBoolean do_eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
-IMPORT_C EGLBoolean do_eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
-IMPORT_C EGLBoolean do_eglSwapInterval(EGLDisplay dpy, EGLint interval);
-IMPORT_C EGLContext do_eglCreateContext(EGLDisplay dpy, EGLConfig config,EGLContext share_context,const EGLint *attrib_list);
-IMPORT_C EGLBoolean do_eglDestroyContext(EGLDisplay dpy, EGLContext ctx);
-IMPORT_C EGLBoolean do_eglMakeCurrent(EGLDisplay dpy, EGLSurface draw,EGLSurface read, EGLContext ctx);
-IMPORT_C EGLContext do_eglGetCurrentContext(void);
-IMPORT_C EGLSurface do_eglGetCurrentSurface(EGLint readdraw);
-IMPORT_C EGLDisplay do_eglGetCurrentDisplay(void);
-IMPORT_C EGLBoolean do_eglQueryContext(EGLDisplay dpy, EGLContext ctx,EGLint attribute, EGLint *value);
-IMPORT_C EGLBoolean do_eglWaitGL(void);
-IMPORT_C EGLBoolean do_eglWaitNative(EGLint engine);
-IMPORT_C EGLBoolean do_eglSwapBuffers(EGLDisplay dpy, EGLSurface surface);
-IMPORT_C EGLBoolean do_eglCopyBuffers(EGLDisplay dpy, EGLSurface surface,EGLNativePixmapType target);
-IMPORT_C void (* EGLAPIENTRY do_eglGetProcAddress (const char *procname))(...);
-
-
-
-
-#endif
--- a/egl/sfopenvg/include/openvginternal.h	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,117 +0,0 @@
-/*
-* Copyright (c) 2009 Symbian Foundation Ltd
-* This component and the accompanying materials are made available
-* under the terms of the License "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Symbian Foundation Ltd - initial contribution.
-* 
-* Contributors:
-*
-* Description:
-* Implementation of a OpenVG like interface. Basically every OpenVG API names but prefixed with do_ e.g. do_vgSetf
-*/
-
-#ifndef OPENVGINTERNAL_H
-#define OPENVGINTERNAL_H
-
-#include <openvg.h>
-
-/*
- * defines set of internal vgu functions that are 1:1 with the published openvg functions. 
- * E.g. vgSetf -> do_vgSetf
- * 
- * These do_XXX fucntions are called from the libopenvg.dll (which is a shim) to be processed here
- */
-
-IMPORT_C VGErrorCode do_vgGetError(void);
-IMPORT_C void do_vgFlush(void);
-IMPORT_C void do_vgFinish(void);
-IMPORT_C void do_vgSetf(VGParamType type, VGfloat value);
-IMPORT_C void do_vgSeti(VGParamType type, VGint value);
-IMPORT_C void do_vgSetfv(VGParamType type, VGint count ,const VGfloat* values);
-IMPORT_C void do_vgSetiv(VGParamType type, VGint count ,const VGint* values);
-IMPORT_C VGfloat do_vgGetf(VGParamType type);
-IMPORT_C VGint do_vgGeti(VGParamType type);
-IMPORT_C VGint do_vgGetVectorSize(VGParamType type);
-IMPORT_C void do_vgGetfv(VGParamType type, VGint count ,VGfloat* values);
-IMPORT_C void do_vgGetiv(VGParamType type, VGint count ,VGint* values);
-IMPORT_C void do_vgSetParameterf(VGHandle object ,VGint paramType ,VGfloat value);
-IMPORT_C void do_vgSetParameteri(VGHandle object ,VGint paramType ,VGint value);
-IMPORT_C void do_vgSetParameterfv(VGHandle object ,VGint paramType ,VGint count ,const VGfloat* values);
-IMPORT_C void do_vgSetParameteriv(VGHandle object ,VGint paramType ,VGint count ,const VGint* values);
-IMPORT_C VGfloat do_vgGetParameterf(VGHandle object ,VGint paramType);
-IMPORT_C VGint do_vgGetParameteri(VGHandle object ,VGint paramType);
-IMPORT_C VGint do_vgGetParameterVectorSize(VGHandle object ,VGint paramType);
-IMPORT_C void do_vgGetParameterfv(VGHandle object ,VGint paramType ,VGint count ,VGfloat* values);
-IMPORT_C void do_vgGetParameteriv(VGHandle object ,VGint paramType ,VGint count ,VGint* values);
-IMPORT_C void do_vgLoadIdentity(void);
-IMPORT_C void do_vgLoadMatrix(const VGfloat* m);
-IMPORT_C void do_vgGetMatrix(VGfloat* m);
-IMPORT_C void do_vgMultMatrix(const  VGfloat* m);
-IMPORT_C void do_vgTranslate(VGfloat tx, VGfloat ty);
-IMPORT_C void do_vgScale(VGfloat sx, VGfloat sy);
-IMPORT_C void do_vgShear(VGfloat shx, VGfloat shy);
-IMPORT_C void do_vgRotate(VGfloat angle);
-IMPORT_C void do_vgMask(VGHandle mask, VGMaskOperation operation ,VGint x, VGint y ,VGint width, VGint height);
-IMPORT_C void do_vgRenderToMask(VGPath path ,VGbitfield paintModes ,VGMaskOperation operation);
-IMPORT_C VGMaskLayer do_vgCreateMaskLayer(VGint width, VGint height);
-IMPORT_C void do_vgDestroyMaskLayer(VGMaskLayer maskLayer);
-IMPORT_C void do_vgFillMaskLayer(VGMaskLayer maskLayer ,VGint x, VGint y ,VGint width, VGint height ,VGfloat value);
-IMPORT_C void do_vgCopyMask(VGMaskLayer maskLayer ,VGint sx, VGint sy ,VGint dx, VGint dy ,VGint width, VGint height);
-IMPORT_C void do_vgClear(VGint x, VGint y ,VGint width, VGint height);
-IMPORT_C VGPath do_vgCreatePath(VGint pathFormat ,VGPathDatatype datatype ,VGfloat scale, VGfloat bias ,VGint segmentCapacityHint ,VGint coordCapacityHint ,VGbitfield capabilities);
-IMPORT_C void do_vgClearPath(VGPath path, VGbitfield capabilities);
-IMPORT_C void do_vgDestroyPath(VGPath path);
-IMPORT_C void do_vgRemovePathCapabilities(VGPath path ,VGbitfield capabilities);
-IMPORT_C VGbitfield do_vgGetPathCapabilities(VGPath path);
-IMPORT_C void do_vgAppendPath(VGPath dstPath, VGPath srcPath);
-IMPORT_C void do_vgAppendPathData(VGPath dstPath ,VGint numSegments ,const  VGubyte* pathSegments ,const  void* pathData);
-IMPORT_C void do_vgModifyPathCoords(VGPath dstPath ,VGint startIndex ,VGint numSegments ,const void* pathData);
-IMPORT_C void do_vgTransformPath(VGPath dstPath, VGPath srcPath);
-IMPORT_C VGboolean do_vgInterpolatePath(VGPath dstPath ,VGPath startPath ,VGPath endPath ,VGfloat amount);
-IMPORT_C VGfloat do_vgPathLength(VGPath path ,VGint startSegment ,VGint numSegments);
-IMPORT_C void do_vgPointAlongPath(VGPath path ,VGint startSegment ,VGint numSegments ,VGfloat distance ,VGfloat* x, VGfloat* y ,VGfloat* tangentX ,VGfloat* tangentY);
-IMPORT_C void do_vgPathBounds(VGPath path ,VGfloat* minX ,VGfloat* minY ,VGfloat* width ,VGfloat* height);
-IMPORT_C void do_vgPathTransformedBounds(VGPath path ,VGfloat* minX ,VGfloat* minY ,VGfloat* width ,VGfloat* height);
-IMPORT_C void do_vgDrawPath(VGPath path, VGbitfield paintModes);
-IMPORT_C VGPaint do_vgCreatePaint(void);
-IMPORT_C void do_vgDestroyPaint(VGPaint paint);
-IMPORT_C void do_vgSetPaint(VGPaint paint, VGbitfield paintModes);
-IMPORT_C VGPaint do_vgGetPaint(VGPaintMode paintMode);
-IMPORT_C void do_vgSetColor(VGPaint paint, VGuint rgba);
-IMPORT_C VGuint do_vgGetColor(VGPaint paint);
-IMPORT_C void do_vgPaintPattern(VGPaint paint, VGImage pattern);
-IMPORT_C VGImage do_vgCreateImage(VGImageFormat format ,VGint width, VGint height ,VGbitfield allowedQuality);
-IMPORT_C void do_vgDestroyImage(VGImage image);
-IMPORT_C void do_vgClearImage(VGImage image ,VGint x, VGint y ,VGint width, VGint height);
-IMPORT_C void do_vgImageSubData(VGImage image ,const void* data ,VGint dataStride ,VGImageFormat dataFormat ,VGint x, VGint y ,VGint width, VGint height);
-IMPORT_C void do_vgGetImageSubData(VGImage image ,void* data ,VGint dataStride ,VGImageFormat dataFormat ,VGint x, VGint y ,VGint width, VGint height);
-IMPORT_C VGImage do_vgChildImage(VGImage parent ,VGint x, VGint y ,VGint width, VGint height);
-IMPORT_C VGImage do_vgGetParent(VGImage image);
-IMPORT_C void do_vgCopyImage(VGImage dst, VGint dx, VGint dy ,VGImage src, VGint sx, VGint sy ,VGint width, VGint height ,VGboolean dither);
-IMPORT_C void do_vgDrawImage(VGImage image);
-IMPORT_C void do_vgSetPixels(VGint dx, VGint dy ,VGImage src, VGint sx, VGint sy ,VGint width, VGint height);
-IMPORT_C void do_vgWritePixels(const void* data, VGint dataStride ,VGImageFormat dataFormat ,VGint dx, VGint dy ,VGint width, VGint height);
-IMPORT_C void do_vgGetPixels(VGImage dst, VGint dx, VGint dy ,VGint sx, VGint sy ,VGint width, VGint height);
-IMPORT_C void do_vgReadPixels(void* data, VGint dataStride ,VGImageFormat dataFormat ,VGint sx, VGint sy ,VGint width, VGint height);
-IMPORT_C void do_vgCopyPixels(VGint dx, VGint dy ,VGint sx, VGint sy ,VGint width, VGint height);
-IMPORT_C VGFont do_vgCreateFont(VGint glyphCapacityHint);
-IMPORT_C void do_vgDestroyFont(VGFont font);
-IMPORT_C void do_vgSetGlyphToPath(VGFont font ,VGuint glyphIndex ,VGPath path ,VGboolean isHinted ,const VGfloat glyphOrigin [2] ,const VGfloat escapement[2]);
-IMPORT_C void do_vgSetGlyphToImage(VGFont font ,VGuint glyphIndex ,VGImage image ,const VGfloat glyphOrigin [2] ,const VGfloat escapement[2]);
-IMPORT_C void do_vgClearGlyph(VGFont font ,VGuint glyphIndex);
-IMPORT_C void do_vgDrawGlyph(VGFont font ,VGuint glyphIndex ,VGbitfield paintModes ,VGboolean allowAutoHinting);
-IMPORT_C void do_vgDrawGlyphs(VGFont font ,VGint glyphCount ,const VGuint* glyphIndices ,const VGfloat* adjustments_x ,const VGfloat* adjustments_y ,VGbitfield paintModes ,VGboolean allowAutoHinting);
-IMPORT_C void do_vgColorMatrix(VGImage dst, VGImage src ,const VGfloat* matrix);
-IMPORT_C void do_vgConvolve(VGImage dst, VGImage src ,VGint kernelWidth, VGint kernelHeight ,VGint shiftX, VGint shiftY ,const VGshort* kernel ,VGfloat scale ,VGfloat bias ,VGTilingMode tilingMode);
-IMPORT_C void do_vgSeparableConvolve(VGImage dst, VGImage src ,VGint kernelWidth ,VGint kernelHeight ,VGint shiftX, VGint shiftY ,const VGshort* kernelX ,const VGshort* kernelY ,VGfloat scale ,VGfloat bias ,VGTilingMode tilingMode);
-IMPORT_C void do_vgGaussianBlur(VGImage dst, VGImage src ,VGfloat stdDeviationX ,VGfloat stdDeviationY ,VGTilingMode tilingMode);
-IMPORT_C void do_vgLookup(VGImage dst, VGImage src ,const VGubyte* redLUT ,const VGubyte* greenLUT ,const VGubyte* blueLUT ,const VGubyte* alphaLUT ,VGboolean outputLinear ,VGboolean outputPremultiplied);
-IMPORT_C void do_vgLookupSingle(VGImage dst, VGImage src ,const VGuint* lookupTable ,VGImageChannel sourceChannel ,VGboolean outputLinear ,VGboolean outputPremultiplied);
-IMPORT_C VGHardwareQueryResult do_vgHardwareQuery(VGHardwareQueryType key ,VGint setting);
-IMPORT_C const VGubyte * do_vgGetString(VGStringID name);
-
-#endif
--- a/egl/sfopenvg/include/riMiniEGL.h	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-
--- a/egl/sfopenvg/include/vguinternal.h	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-/*
-* Copyright (c) 2009 Symbian Foundation Ltd
-* This component and the accompanying materials are made available
-* under the terms of the License "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Symbian Foundation Ltd - initial contribution.
-* 
-* Contributors:
-*
-* Description:
-* Implementation of VGU like interface. Basically every VGU API names but prefixed with do_ e.g. do_vguLine
-*/
-
-#ifndef VGUINTERNAL_H
-#define VGUINTERNAL_H
-
-#include <vgu.h>
-
-/*
- * defines set of internal vgu functions that are 1:1 with the published vgu functions.
- * E.g. vguLine -> do_vguLine
- * 
- * These do_XXX fucntions are called from the libopenvgu.dll (which is a shim) to be processed here
- */
-
-IMPORT_C VGUErrorCode do_vguLine(VGPath path, VGfloat x0, VGfloat y0, VGfloat x1, VGfloat y1);
-IMPORT_C VGUErrorCode do_vguPolygon(VGPath path, const VGfloat * points, VGint count, VGboolean closed);
-IMPORT_C VGUErrorCode do_vguRect(VGPath path, VGfloat x, VGfloat y, VGfloat width, VGfloat height);
-IMPORT_C VGUErrorCode do_vguRoundRect(VGPath path, VGfloat x, VGfloat y, VGfloat width, VGfloat height, VGfloat arcWidth, VGfloat arcHeight);
-IMPORT_C VGUErrorCode do_vguEllipse(VGPath path, VGfloat cx, VGfloat cy, VGfloat width, VGfloat height);
-IMPORT_C VGUErrorCode do_vguArc(VGPath path, VGfloat x, VGfloat y, VGfloat width, VGfloat height, VGfloat startAngle, VGfloat angleExtent, VGUArcType arcType);
-IMPORT_C VGUErrorCode do_vguComputeWarpQuadToSquare(VGfloat sx0, VGfloat sy0, VGfloat sx1, VGfloat sy1, VGfloat sx2, VGfloat sy2, VGfloat sx3, VGfloat sy3, VGfloat * matrix);
-IMPORT_C VGUErrorCode do_vguComputeWarpSquareToQuad(VGfloat dx0, VGfloat dy0, VGfloat dx1, VGfloat dy1, VGfloat dx2, VGfloat dy2, VGfloat dx3, VGfloat dy3, VGfloat * matrix);
-IMPORT_C VGUErrorCode do_vguComputeWarpQuadToQuad(VGfloat dx0, VGfloat dy0, VGfloat dx1, VGfloat dy1, VGfloat dx2, VGfloat dy2, VGfloat dx3, VGfloat dy3, VGfloat sx0, VGfloat sy0, VGfloat sx1, VGfloat sy1, VGfloat sx2, VGfloat sy2, VGfloat sx3, VGfloat sy3, VGfloat * matrix);
-
-#endif
--- a/egl/sfopenvg/riApi.cpp	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,4040 +0,0 @@
-/*------------------------------------------------------------------------
- *
- * OpenVG 1.1 Reference Implementation
- * -----------------------------------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief	Implementations of OpenVG API functions.
- * \note	The actual processing is done in Path, Image, Rasterizer and PixelPipe classes.
- *//*-------------------------------------------------------------------*/
-
-#include "openvg.h"
-#include "egl.h"
-#include "riMiniEGL.h"
-#include "riContext.h"
-#include "riRasterizer.h"
-#include "riPixelPipe.h"
-#include "riPath.h"
-#include <stdio.h>
-#include <e32debug.h>
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-#include "openvginternal.h"
-#endif
-
-//==============================================================================================
-
-namespace OpenVGRI
-{
-
-/* EGL&OS functions for use in an OpenVG implementation */
-void* eglvgGetCurrentVGContext(void);
-bool  eglvgIsInUse(void* image);
-void  OSAcquireMutex(void);
-void  OSReleaseMutex(void);
-
-
-#define RI_NO_RETVAL
-
-//this must be the first line in an API function
-#define RI_GET_CONTEXT(RETVAL) \
-	OSAcquireMutex(); \
-	VGContext* context = (VGContext*)eglvgGetCurrentVGContext(); \
-	if(!context) \
-	{ \
-		OSReleaseMutex(); \
-		return RETVAL;\
-	}
-
-#define RI_IF_ERROR(COND, ERRORCODE, RETVAL) \
-	if(COND) { context->setError(ERRORCODE); OSReleaseMutex(); return RETVAL; }
-
-//all API functions must call this as their last operation (also functions that don't return values)
-//NOTE: don't evaluate anything or read state in RETVAL (it'll be executed after the mutex has been released)
-#define RI_RETURN(RETVAL) \
-	{ OSReleaseMutex(); \
-	return RETVAL; }
-
-static bool isAligned(const void* ptr, int alignment)
-{
-	RI_ASSERT(alignment == 1 || alignment == 2 || alignment == 4);
-	if(((RIuintptr)ptr) & (alignment-1))
-		return false;
-	return true;
-}
-
-static bool isAligned(const void* ptr, VGImageFormat format)
-{
-	RI_ASSERT(isValidImageFormat(format));
-	int alignment = Color::formatToDescriptor(format).bitsPerPixel >> 3;
-	if(alignment <= 1)
-		return true;	//one bit or byte per pixel
-	return isAligned(ptr, alignment);
-}
-
-bool isValidImageFormat(int f)
-{
-	if(f < VG_sRGBX_8888 || f > VG_lABGR_8888_PRE)
-		return false;
-	return true;
-}
-
-bool isValidImageFormat(EGLNativePixmapType f)
-  {
-#warning TODO: implement isValidImageFormat for EGLNativePixmapType arg
-  return false;
-  }
-
-}	//namespace OpenVGRI
-
-using namespace OpenVGRI;
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgFlush(void)
-#else
-void RI_APIENTRY vgFlush(void)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	//the RI doesn't cache anything, so this is a no-op
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-----
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgFinish(void)
-#else
-void RI_APIENTRY vgFinish(void)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	//the RI doesn't cache anything, so this is a no-op
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-VGErrorCode RI_APIENTRY do_vgGetError(void)
-#else
-VGErrorCode RI_APIENTRY vgGetError(void)
-#endif
-{
-	RI_GET_CONTEXT(VG_NO_CONTEXT_ERROR);
-	VGErrorCode error = context->m_error;
-	context->m_error = VG_NO_ERROR;
-	RI_RETURN(error);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-namespace OpenVGRI
-{
-
-RIfloat inputFloat(VGfloat f)
-{
-	//this function is used for all floating point input values
-	if(RI_ISNAN(f)) return 0.0f;	//convert NaN to zero
-	return RI_CLAMP(f, -RI_FLOAT_MAX, RI_FLOAT_MAX);	//clamp +-inf to +-RIfloat max
-}
-
-Vector2 inputVector2(const Vector2& v)
-{
-    return Vector2(inputFloat(v.x), inputFloat(v.y));
-}
-
-Color inputColor(const Color& c)
-{
-    Color r = c;
-    r.r = inputFloat(r.r);
-    r.g = inputFloat(r.g);
-    r.b = inputFloat(r.b);
-    r.a = inputFloat(r.a);
-    return r;
-}
-
-static int inputFloatToInt(VGfloat value)
-{
-	double v = (double)floor(value);
-	v = v > (double)RI_INT32_MAX ? (double)RI_INT32_MAX : v;
-	v = v < (double)RI_INT32_MIN ? (double)RI_INT32_MIN : v;
-	return (int)v;
-}
-
-static int paramToInt(const void* values, bool floats, int count, int i)
-{
-	RI_ASSERT(i >= 0);
-	if(i >= count || !values)
-		return 0;
-	if(floats)
-		return inputFloatToInt(((const VGfloat*)values)[i]);
-	return (int)((const VGint*)values)[i];
-}
-
-static RIfloat paramToFloat(const void* values, bool floats, int count, int i)
-{
-	RI_ASSERT(i >= 0);
-	if(i >= count || !values)
-		return 0.0f;
-	if(floats)
-		return ((const VGfloat*)values)[i];
-	return (RIfloat)((const VGint*)values)[i];
-}
-
-static void floatToParam(void* output, bool outputFloats, int count, int i, VGfloat value)
-{
-	RI_ASSERT(i >= 0);
-	RI_ASSERT(output);
-	if(i >= count)
-		return;
-	if(outputFloats)
-		((VGfloat*)output)[i] = value;
-	else
-		((VGint*)output)[i] = (VGint)inputFloatToInt(value);
-}
-
-static void intToParam(void* output, bool outputFloats, int count, int i, VGint value)
-{
-	RI_ASSERT(i >= 0);
-	RI_ASSERT(output);
-	if(i >= count)
-		return;
-	if(outputFloats)
-		((VGfloat*)output)[i] = (VGfloat)value;
-	else
-		((VGint*)output)[i] = value;
-}
-
-}	//namespace OpenVGRI
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static void setifv(VGContext* context, VGParamType type, VGint count, const void* values, bool floats)
-{
-	RI_ASSERT(context);
-	RI_ASSERT(!count || (count && values));
-
-	int ivalue = paramToInt(values, floats, count, 0);
-	RIfloat fvalue = paramToFloat(values, floats, count, 0);
-
-	switch(type)
-	{
-	case VG_MATRIX_MODE:
-		if(count != 1 || ivalue < VG_MATRIX_PATH_USER_TO_SURFACE || ivalue > VG_MATRIX_GLYPH_USER_TO_SURFACE)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		context->m_matrixMode = (VGMatrixMode)ivalue;
-		break;
-
-	case VG_FILL_RULE:
-		if(count != 1 || ivalue < VG_EVEN_ODD || ivalue > VG_NON_ZERO)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		context->m_fillRule = (VGFillRule)ivalue;
-		break;
-
-	case VG_IMAGE_QUALITY:
-		if(count != 1 || ivalue < VG_IMAGE_QUALITY_NONANTIALIASED || ivalue > VG_IMAGE_QUALITY_BETTER)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		context->m_imageQuality = (VGImageQuality)ivalue;
-		break;
-
-	case VG_RENDERING_QUALITY:
-		if(count != 1 || ivalue < VG_RENDERING_QUALITY_NONANTIALIASED || ivalue > VG_RENDERING_QUALITY_BETTER)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		context->m_renderingQuality = (VGRenderingQuality)ivalue;
-		break;
-
-	case VG_BLEND_MODE:
-		if(count != 1 || ivalue < VG_BLEND_SRC || ivalue > VG_BLEND_ADDITIVE)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		context->m_blendMode = (VGBlendMode)ivalue;
-		break;
-
-	case VG_IMAGE_MODE:
-		if(count != 1 || ivalue < VG_DRAW_IMAGE_NORMAL || ivalue > VG_DRAW_IMAGE_STENCIL)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		context->m_imageMode = (VGImageMode)ivalue;
-		break;
-
-	case VG_SCISSOR_RECTS:
-	{
-		if(count & 3)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }	//count must be a multiple of four
-		try
-		{
-			Array<Rectangle> scissor;
-			for(int i=0;i<RI_INT_MIN(count, RI_MAX_SCISSOR_RECTANGLES*4);i+=4)
-			{
-				Rectangle s;
-				s.x = paramToInt(values, floats, count, i+0);
-				s.y = paramToInt(values, floats, count, i+1);
-				s.width = paramToInt(values, floats, count, i+2);
-				s.height = paramToInt(values, floats, count, i+3);
-				scissor.push_back(s);	//throws bad_alloc
-			}
-			context->m_scissor.swap(scissor);	//replace context data
-		}
-		catch(std::bad_alloc)
-		{
-			context->setError(VG_OUT_OF_MEMORY_ERROR);
-		}
-		break;
-	}
-
-	case VG_COLOR_TRANSFORM:
-		if(count != 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		context->m_colorTransform = ivalue ? VG_TRUE : VG_FALSE;
-		break;
-
-	case VG_COLOR_TRANSFORM_VALUES:
-		if(count != 8 || !values) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-        {
-            for(int i=0;i<8;i++)
-            {
-                context->m_inputColorTransformValues[i] = paramToFloat(values, floats, count, i);
-                context->m_colorTransformValues[i] = inputFloat(context->m_inputColorTransformValues[i]);
-            }
-        }
-		break;
-
-	case VG_STROKE_LINE_WIDTH:
-		if(count != 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		context->m_inputStrokeLineWidth = fvalue;
-        context->m_strokeLineWidth = inputFloat(fvalue);
-		break;
-
-	case VG_STROKE_CAP_STYLE:
-		if(count != 1 || ivalue < VG_CAP_BUTT || ivalue > VG_CAP_SQUARE)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		context->m_strokeCapStyle = (VGCapStyle)ivalue;
-		break;
-
-	case VG_STROKE_JOIN_STYLE:
-		if(count != 1 || ivalue < VG_JOIN_MITER || ivalue > VG_JOIN_BEVEL)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		context->m_strokeJoinStyle = (VGJoinStyle)ivalue;
-		break;
-
-	case VG_STROKE_MITER_LIMIT:
-		if(count != 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		context->m_inputStrokeMiterLimit = fvalue;
-		context->m_strokeMiterLimit = inputFloat(fvalue);
-		break;
-
-	case VG_STROKE_DASH_PATTERN:
-	{
-		try
-		{
-			Array<RIfloat> inputStrokeDashPattern;
-			Array<RIfloat> strokeDashPattern;
-			for(int i=0;i<RI_INT_MIN(count, RI_MAX_DASH_COUNT);i++)
-            {
-                RIfloat v = paramToFloat(values, floats, count, i);
-				inputStrokeDashPattern.push_back(v);	//throws bad_alloc
-				strokeDashPattern.push_back(inputFloat(v));	//throws bad_alloc
-            }
-			context->m_inputStrokeDashPattern.swap(inputStrokeDashPattern);	//replace context data
-			context->m_strokeDashPattern.swap(strokeDashPattern);	//replace context data
-		}
-		catch(std::bad_alloc)
-		{
-			context->setError(VG_OUT_OF_MEMORY_ERROR);
-		}
-		break;
-	}
-
-	case VG_STROKE_DASH_PHASE:
-		if(count != 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		context->m_inputStrokeDashPhase = fvalue;
-		context->m_strokeDashPhase = inputFloat(fvalue);
-		break;
-
-	case VG_STROKE_DASH_PHASE_RESET:
-		if(count != 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		context->m_strokeDashPhaseReset = ivalue ? VG_TRUE : VG_FALSE;
-		break;
-
-	case VG_TILE_FILL_COLOR:
-		if(count != 4 || !values) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		context->m_inputTileFillColor.set(paramToFloat(values, floats, count, 0),
-									 paramToFloat(values, floats, count, 1),
-									 paramToFloat(values, floats, count, 2),
-									 paramToFloat(values, floats, count, 3),
-									 Color::sRGBA);
-        context->m_tileFillColor = inputColor(context->m_inputTileFillColor);
-		break;
-
-	case VG_GLYPH_ORIGIN:
-		if(count != 2 || !values) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		context->m_inputGlyphOrigin.x = paramToFloat(values, floats, count, 0);
-		context->m_inputGlyphOrigin.y = paramToFloat(values, floats, count, 1);
-		context->m_glyphOrigin = inputVector2(context->m_inputGlyphOrigin);
-		break;
-
-	case VG_CLEAR_COLOR:
-		if(count != 4 || !values) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		context->m_inputClearColor.set(paramToFloat(values, floats, count, 0),
-								  paramToFloat(values, floats, count, 1),
-								  paramToFloat(values, floats, count, 2),
-								  paramToFloat(values, floats, count, 3),
-								  Color::sRGBA);
-        context->m_clearColor = inputColor(context->m_inputClearColor);
-		break;
-
-	case VG_MASKING:
-		if(count != 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		context->m_masking = ivalue ? VG_TRUE : VG_FALSE;
-		break;
-
-	case VG_SCISSORING:
-		if(count != 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		context->m_scissoring = ivalue ? VG_TRUE : VG_FALSE;
-		break;
-
-	case VG_PIXEL_LAYOUT:
-		if(count != 1 || ivalue < VG_PIXEL_LAYOUT_UNKNOWN || ivalue > VG_PIXEL_LAYOUT_BGR_HORIZONTAL)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		context->m_pixelLayout = (VGPixelLayout)ivalue;
-		break;
-
-	case VG_SCREEN_LAYOUT:
-		if(count != 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		break;	//setting read-only values has no effect
-
-	case VG_FILTER_FORMAT_LINEAR:
-		if(count != 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		context->m_filterFormatLinear = ivalue ? VG_TRUE : VG_FALSE;
-		break;
-
-	case VG_FILTER_FORMAT_PREMULTIPLIED:
-		if(count != 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		context->m_filterFormatPremultiplied = ivalue ? VG_TRUE : VG_FALSE;
-		break;
-
-	case VG_FILTER_CHANNEL_MASK:
-		if(count != 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		//undefined bits are ignored
-		context->m_filterChannelMask = (VGbitfield)ivalue;
-		break;
-
-	case VG_MAX_SCISSOR_RECTS:
-	case VG_MAX_DASH_COUNT:
-	case VG_MAX_KERNEL_SIZE:
-	case VG_MAX_SEPARABLE_KERNEL_SIZE:
-	case VG_MAX_COLOR_RAMP_STOPS:
-	case VG_MAX_IMAGE_WIDTH:
-	case VG_MAX_IMAGE_HEIGHT:
-	case VG_MAX_IMAGE_PIXELS:
-	case VG_MAX_IMAGE_BYTES:
-	case VG_MAX_FLOAT:
-	case VG_MAX_GAUSSIAN_STD_DEVIATION:
-		if(count != 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		break;	//setting read-only values has no effect
-
-	default:
-		context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-		break;
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgSetf(VGParamType type, VGfloat value)
-#else
-void RI_APIENTRY vgSetf(VGParamType type, VGfloat value)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(type == VG_SCISSOR_RECTS || type == VG_STROKE_DASH_PATTERN || type == VG_TILE_FILL_COLOR ||
-				type == VG_CLEAR_COLOR, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);	//vector type value
-	VGfloat values[1] = {value};
-	setifv(context, type, 1, values, true);
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgSeti(VGParamType type, VGint value)
-#else
-void RI_APIENTRY vgSeti(VGParamType type, VGint value)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(type == VG_SCISSOR_RECTS || type == VG_STROKE_DASH_PATTERN || type == VG_TILE_FILL_COLOR ||
-				type == VG_CLEAR_COLOR, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);	//vector type value
-	VGint values[1] = {value};
-	setifv(context, type, 1, values, false);
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgSetiv(VGParamType type, VGint count, const VGint * values)
-#else 
-void RI_APIENTRY vgSetiv(VGParamType type, VGint count, const VGint * values)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(count < 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR((!values && count > 0) || (values && !isAligned(values,4)), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	setifv(context, type, count, values, false);
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgSetfv(VGParamType type, VGint count, const VGfloat * values)
-#else
-void RI_APIENTRY vgSetfv(VGParamType type, VGint count, const VGfloat * values)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(count < 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR((!values && count > 0) || (values && !isAligned(values,4)), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	setifv(context, type, count, values, true);
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static void getifv(VGContext* context, VGParamType type, VGint count, void* values, bool floats)
-{
-	switch(type)
-	{
-	case VG_MATRIX_MODE:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, context->m_matrixMode);
-		break;
-
-	case VG_FILL_RULE:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, context->m_fillRule);
-		break;
-
-	case VG_IMAGE_QUALITY:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, context->m_imageQuality);
-		break;
-
-	case VG_RENDERING_QUALITY:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, context->m_renderingQuality);
-		break;
-
-	case VG_BLEND_MODE:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, context->m_blendMode);
-		break;
-
-	case VG_IMAGE_MODE:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, context->m_imageMode);
-		break;
-
-	case VG_SCISSOR_RECTS:
-	{
-		if(count > context->m_scissor.size()*4)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		for(int i=0;i<context->m_scissor.size();i++)
-		{
-			intToParam(values, floats, count, i*4+0, context->m_scissor[i].x);
-			intToParam(values, floats, count, i*4+1, context->m_scissor[i].y);
-			intToParam(values, floats, count, i*4+2, context->m_scissor[i].width);
-			intToParam(values, floats, count, i*4+3, context->m_scissor[i].height);
-		}
-		break;
-	}
-
-	case VG_COLOR_TRANSFORM:
-		if(count != 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, context->m_colorTransform);
-		break;
-
-	case VG_COLOR_TRANSFORM_VALUES:
-		if(count > 8) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-        {
-            for(int i=0;i<count;i++)
-            {
-                floatToParam(values, floats, count, i, context->m_inputColorTransformValues[i]);
-            }
-        }
-		break;
-
-	case VG_STROKE_LINE_WIDTH:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		floatToParam(values, floats, count, 0, context->m_inputStrokeLineWidth);
-		break;
-
-	case VG_STROKE_CAP_STYLE:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, context->m_strokeCapStyle);
-		break;
-
-	case VG_STROKE_JOIN_STYLE:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, context->m_strokeJoinStyle);
-		break;
-
-	case VG_STROKE_MITER_LIMIT:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		floatToParam(values, floats, count, 0, context->m_inputStrokeMiterLimit);
-		break;
-
-	case VG_STROKE_DASH_PATTERN:
-	{
-		if(count > context->m_inputStrokeDashPattern.size())	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		for(int i=0;i<context->m_inputStrokeDashPattern.size();i++)
-			floatToParam(values, floats, count, i, context->m_inputStrokeDashPattern[i]);
-		break;
-	}
-
-	case VG_STROKE_DASH_PHASE:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		floatToParam(values, floats, count, 0, context->m_inputStrokeDashPhase);
-		break;
-
-	case VG_STROKE_DASH_PHASE_RESET:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, context->m_strokeDashPhaseReset);
-		break;
-
-	case VG_TILE_FILL_COLOR:
-		if(count > 4)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		floatToParam(values, floats, count, 0, context->m_inputTileFillColor.r);
-		floatToParam(values, floats, count, 1, context->m_inputTileFillColor.g);
-		floatToParam(values, floats, count, 2, context->m_inputTileFillColor.b);
-		floatToParam(values, floats, count, 3, context->m_inputTileFillColor.a);
-		break;
-
-	case VG_CLEAR_COLOR:
-		if(count > 4)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		floatToParam(values, floats, count, 0, context->m_inputClearColor.r);
-		floatToParam(values, floats, count, 1, context->m_inputClearColor.g);
-		floatToParam(values, floats, count, 2, context->m_inputClearColor.b);
-		floatToParam(values, floats, count, 3, context->m_inputClearColor.a);
-		break;
-
-	case VG_GLYPH_ORIGIN:
-		if(count > 2)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		floatToParam(values, floats, count, 0, context->m_inputGlyphOrigin.x);
-		floatToParam(values, floats, count, 1, context->m_inputGlyphOrigin.y);
-		break;
-
-	case VG_MASKING:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, context->m_masking);
-		break;
-
-	case VG_SCISSORING:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, context->m_scissoring);
-		break;
-
-	case VG_PIXEL_LAYOUT:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, context->m_pixelLayout);
-		break;
-
-	case VG_SCREEN_LAYOUT:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, VG_PIXEL_LAYOUT_UNKNOWN);
-		break;
-
-	case VG_FILTER_FORMAT_LINEAR:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, context->m_filterFormatLinear);
-		break;
-
-	case VG_FILTER_FORMAT_PREMULTIPLIED:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, context->m_filterFormatPremultiplied);
-		break;
-
-	case VG_FILTER_CHANNEL_MASK:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, context->m_filterChannelMask);
-		break;
-
-	case VG_MAX_SCISSOR_RECTS:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, RI_MAX_SCISSOR_RECTANGLES);
-		break;
-
-	case VG_MAX_DASH_COUNT:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, RI_MAX_DASH_COUNT);
-		break;
-
-	case VG_MAX_KERNEL_SIZE:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, RI_MAX_KERNEL_SIZE);
-		break;
-
-	case VG_MAX_SEPARABLE_KERNEL_SIZE:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, RI_MAX_SEPARABLE_KERNEL_SIZE);
-		break;
-
-	case VG_MAX_COLOR_RAMP_STOPS:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, RI_MAX_COLOR_RAMP_STOPS);
-		break;
-
-	case VG_MAX_IMAGE_WIDTH:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, RI_MAX_IMAGE_WIDTH);
-		break;
-
-	case VG_MAX_IMAGE_HEIGHT:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, RI_MAX_IMAGE_HEIGHT);
-		break;
-
-	case VG_MAX_IMAGE_PIXELS:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, RI_MAX_IMAGE_PIXELS);
-		break;
-
-	case VG_MAX_IMAGE_BYTES:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, RI_MAX_IMAGE_BYTES);
-		break;
-
-	case VG_MAX_FLOAT:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		floatToParam(values, floats, count, 0, RI_FLOAT_MAX);
-		break;
-
-	case VG_MAX_GAUSSIAN_STD_DEVIATION:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		floatToParam(values, floats, count, 0, RI_MAX_GAUSSIAN_STD_DEVIATION);
-		break;
-
-	default:
-		context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-		break;
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-VGfloat RI_APIENTRY do_vgGetf(VGParamType type)
-#else
-VGfloat RI_APIENTRY vgGetf(VGParamType type)
-#endif
-{
-	RI_GET_CONTEXT(0.0f);
-	RI_IF_ERROR(type == VG_SCISSOR_RECTS || type == VG_STROKE_DASH_PATTERN || type == VG_TILE_FILL_COLOR ||
-				type == VG_CLEAR_COLOR, VG_ILLEGAL_ARGUMENT_ERROR, 0.0f);	//vector type value
-	RIfloat ret = 0.0f;
-	getifv(context, type, 1, &ret, true);
-	RI_RETURN(ret);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-VGint RI_APIENTRY do_vgGeti(VGParamType type)
-#else
-VGint RI_APIENTRY vgGeti(VGParamType type)
-#endif
-{
-	RI_GET_CONTEXT(0);
-	RI_IF_ERROR(type == VG_SCISSOR_RECTS || type == VG_STROKE_DASH_PATTERN || type == VG_TILE_FILL_COLOR ||
-				type == VG_CLEAR_COLOR, VG_ILLEGAL_ARGUMENT_ERROR, 0);	//vector type value
-	VGint ret = 0;
-	getifv(context, type, 1, &ret, false);
-	RI_RETURN(ret);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgGetiv(VGParamType type, VGint count, VGint * values)
-#else
-void RI_APIENTRY vgGetiv(VGParamType type, VGint count, VGint * values)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(count <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(!values || !isAligned(values,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	getifv(context, type, count, values, false);
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgGetfv(VGParamType type, VGint count, VGfloat * values)
-#else
-void RI_APIENTRY vgGetfv(VGParamType type, VGint count, VGfloat * values)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(count <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(!values || !isAligned(values,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	getifv(context, type, count, values, true);
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-VGint RI_APIENTRY do_vgGetVectorSize(VGParamType type)
-#else
-VGint RI_APIENTRY vgGetVectorSize(VGParamType type)
-#endif
-{
-	RI_GET_CONTEXT(0);
-	VGint ret = 0;
-	switch(type)
-	{
-	case VG_MATRIX_MODE:
-	case VG_FILL_RULE:
-	case VG_IMAGE_QUALITY:
-	case VG_RENDERING_QUALITY:
-	case VG_BLEND_MODE:
-	case VG_IMAGE_MODE:
-		ret = 1;
-		break;
-
-	case VG_SCISSOR_RECTS:
-		ret = 4*context->m_scissor.size();
-		break;
-
-    case VG_COLOR_TRANSFORM:
-        ret = 1;
-        break;
-
-    case VG_COLOR_TRANSFORM_VALUES:
-        ret = 8;
-        break;
-
-	case VG_STROKE_LINE_WIDTH:
-	case VG_STROKE_CAP_STYLE:
-	case VG_STROKE_JOIN_STYLE:
-	case VG_STROKE_MITER_LIMIT:
-		ret = 1;
-		break;
-
-	case VG_STROKE_DASH_PATTERN:
-		ret = context->m_inputStrokeDashPattern.size();
-		break;
-
-	case VG_STROKE_DASH_PHASE:
-	case VG_STROKE_DASH_PHASE_RESET:
-		ret = 1;
-		break;
-
-	case VG_TILE_FILL_COLOR:
-	case VG_CLEAR_COLOR:
-		ret = 4;
-		break;
-
-	case VG_GLYPH_ORIGIN:
-		ret = 2;
-		break;
-
-	case VG_MASKING:
-	case VG_SCISSORING:
-	case VG_PIXEL_LAYOUT:
-	case VG_SCREEN_LAYOUT:
-	case VG_FILTER_FORMAT_LINEAR:
-	case VG_FILTER_FORMAT_PREMULTIPLIED:
-	case VG_FILTER_CHANNEL_MASK:
-	case VG_MAX_SCISSOR_RECTS:
-	case VG_MAX_DASH_COUNT:
-	case VG_MAX_KERNEL_SIZE:
-	case VG_MAX_SEPARABLE_KERNEL_SIZE:
-	case VG_MAX_COLOR_RAMP_STOPS:
-	case VG_MAX_IMAGE_WIDTH:
-	case VG_MAX_IMAGE_HEIGHT:
-	case VG_MAX_IMAGE_PIXELS:
-	case VG_MAX_IMAGE_BYTES:
-	case VG_MAX_FLOAT:
-	case VG_MAX_GAUSSIAN_STD_DEVIATION:
-		ret = 1;
-		break;
-
-	default:
-		context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-		break;
-	}
-	RI_RETURN(ret);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static void setPaintParameterifv(VGContext* context, Paint* paint, VGPaintParamType paramType, VGint count, const void* values, bool floats)
-{
-	RI_ASSERT(context);
-	RI_ASSERT(paint);
-
-	int ivalue = paramToInt(values, floats, count, 0);
-
-	switch(paramType)
-	{
-	case VG_PAINT_TYPE:
-		if(count != 1 || ivalue < VG_PAINT_TYPE_COLOR || ivalue > VG_PAINT_TYPE_PATTERN)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		paint->m_paintType = (VGPaintType)ivalue;
-		break;
-
-	case VG_PAINT_COLOR:
-		if(count != 4)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		paint->m_inputPaintColor.set(paramToFloat(values, floats, count, 0),
-									 paramToFloat(values, floats, count, 1),
-									 paramToFloat(values, floats, count, 2),
-									 paramToFloat(values, floats, count, 3),
-									 Color::sRGBA);
-		paint->m_paintColor = inputColor(paint->m_inputPaintColor);
-		paint->m_paintColor.clamp();
-		paint->m_paintColor.premultiply();
-		break;
-
-	case VG_PAINT_COLOR_RAMP_SPREAD_MODE:
-		if(count != 1 || ivalue < VG_COLOR_RAMP_SPREAD_PAD || ivalue > VG_COLOR_RAMP_SPREAD_REFLECT)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		paint->m_colorRampSpreadMode = (VGColorRampSpreadMode)ivalue;
-		break;
-
-	case VG_PAINT_COLOR_RAMP_STOPS:
-	{
-		int numStops = count/5;
-		if(count != numStops*5)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }	//count must be a multiple of five
-		try
-		{
-			Array<Paint::GradientStop> colorRampStops;
-			Array<Paint::GradientStop> inputColorRampStops;
-			RIfloat prevOffset = -RI_FLOAT_MAX;
-			bool valid = true;
-			for(int i=0;i<RI_INT_MIN(numStops, RI_MAX_COLOR_RAMP_STOPS);i++)	//NOTE: ignores the final stop if there is not enough parameters
-			{
-				Paint::GradientStop gs;
-				gs.offset = paramToFloat(values, floats, count, i*5);
-				gs.color.set(paramToFloat(values, floats, count, i*5+1),
-							 paramToFloat(values, floats, count, i*5+2),
-							 paramToFloat(values, floats, count, i*5+3),
-							 paramToFloat(values, floats, count, i*5+4),
-							 Color::sRGBA);
-				inputColorRampStops.push_back(gs);
-
-				if(gs.offset < prevOffset)
-					valid = false;	//decreasing sequence, ignore it
-
-				if(gs.offset >= 0.0f && gs.offset <= 1.0f)
-				{
-					gs.color.clamp();
-
-					if(!colorRampStops.size() && gs.offset > 0.0f)
-					{	//the first valid stop is not at 0, replicate the first one
-						RIfloat tmp = gs.offset;
-						gs.offset = 0.0f;
-						colorRampStops.push_back(gs);	//throws bad_alloc
-						gs.offset = tmp;
-					}
-					colorRampStops.push_back(gs);	//throws bad_alloc
-				}
-				prevOffset = gs.offset;
-			}
-			if(valid && colorRampStops.size() && colorRampStops[colorRampStops.size()-1].offset < 1.0f)
-			{	//there is at least one stop, but the last one is not at 1, replicate the last one
-				Paint::GradientStop gs = colorRampStops[colorRampStops.size()-1];
-				gs.offset = 1.0f;
-				colorRampStops.push_back(gs);	//throws bad_alloc
-			}
-			if(!valid || !colorRampStops.size())
-			{	//there are no valid stops, add implicit stops
-				colorRampStops.clear();
-				Paint::GradientStop gs;
-				gs.offset = 0.0f;
-				gs.color.set(0,0,0,1,Color::sRGBA);
-				colorRampStops.push_back(gs);	//throws bad_alloc
-				gs.offset = 1.0f;
-				gs.color.set(1,1,1,1,Color::sRGBA);
-				colorRampStops.push_back(gs);	//throws bad_alloc
-			}
-			RI_ASSERT(colorRampStops.size() >= 2 && colorRampStops.size() <= RI_MAX_COLOR_RAMP_STOPS);
-			paint->m_colorRampStops.swap(colorRampStops);	//set paint array
-			paint->m_inputColorRampStops.swap(inputColorRampStops);	//set paint array
-		}
-		catch(std::bad_alloc)
-		{
-			context->setError(VG_OUT_OF_MEMORY_ERROR);
-		}
-		break;
-	}
-
-	case VG_PAINT_COLOR_RAMP_PREMULTIPLIED:
-		if(count != 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		paint->m_colorRampPremultiplied = ivalue ? VG_TRUE : VG_FALSE;
-		break;
-
-	case VG_PAINT_LINEAR_GRADIENT:
-		if(count != 4)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		paint->m_inputLinearGradientPoint0.set(paramToFloat(values, floats, count, 0),
-										  paramToFloat(values, floats, count, 1));
-		paint->m_inputLinearGradientPoint1.set(paramToFloat(values, floats, count, 2),
-										  paramToFloat(values, floats, count, 3));
-        paint->m_linearGradientPoint0 = inputVector2(paint->m_inputLinearGradientPoint0);
-        paint->m_linearGradientPoint1 = inputVector2(paint->m_inputLinearGradientPoint1);
-		break;
-
-	case VG_PAINT_RADIAL_GRADIENT:
-		if(count != 5)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		paint->m_inputRadialGradientCenter.set(paramToFloat(values, floats, count, 0),
-										  paramToFloat(values, floats, count, 1));
-		paint->m_inputRadialGradientFocalPoint.set(paramToFloat(values, floats, count, 2),
-											  paramToFloat(values, floats, count, 3));
-		paint->m_inputRadialGradientRadius = paramToFloat(values, floats, count, 4);
-        paint->m_radialGradientCenter = inputVector2(paint->m_inputRadialGradientCenter);
-        paint->m_radialGradientFocalPoint = inputVector2(paint->m_inputRadialGradientFocalPoint);
-        paint->m_radialGradientRadius = inputFloat(paint->m_inputRadialGradientRadius);
-		break;
-
-	case VG_PAINT_PATTERN_TILING_MODE:
-		if(count != 1 || ivalue < VG_TILE_FILL || ivalue > VG_TILE_REFLECT)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		paint->m_patternTilingMode = (VGTilingMode)ivalue;
-		break;
-
-	default:
-		context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-		break;
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgSetParameterf(VGHandle object, VGint paramType, VGfloat value)
-#else
-void RI_APIENTRY vgSetParameterf(VGHandle object, VGint paramType, VGfloat value)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	bool isImage = context->isValidImage(object);
-	bool isPath = context->isValidPath(object);
-	bool isPaint = context->isValidPaint(object);
-	bool isMaskLayer = context->isValidMaskLayer(object);
-	bool isFont = context->isValidFont(object);
-	RI_IF_ERROR(!isImage && !isPath && !isPaint && !isMaskLayer && !isFont, VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid object handle
-	RI_IF_ERROR(paramType == VG_PAINT_COLOR || paramType == VG_PAINT_COLOR_RAMP_STOPS || paramType == VG_PAINT_LINEAR_GRADIENT ||
-				paramType == VG_PAINT_RADIAL_GRADIENT, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL); //vector valued parameter
-	VGfloat values[1] = {value};
-	if(isImage)
-	{	//read only, the function does nothing
-		RI_ASSERT(!isPath && !isPaint && !isMaskLayer && !isFont);
-		if(paramType < VG_IMAGE_FORMAT || paramType > VG_IMAGE_HEIGHT)
-			context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-	}
-	else if(isPath)
-	{	//read only, the function does nothing
-		RI_ASSERT(!isImage && !isPaint && !isMaskLayer && !isFont);
-		if(paramType < VG_PATH_FORMAT || paramType > VG_PATH_NUM_COORDS)
-			context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-	}
-	else if(isPaint)
-	{
-		RI_ASSERT(!isImage && !isPath && !isMaskLayer && !isFont);
-		setPaintParameterifv(context, (Paint*)object, (VGPaintParamType)paramType, 1, values, true);
-	}
-	else if(isMaskLayer)
-	{
-		RI_ASSERT(!isImage && !isPath && !isPaint && !isFont);
-		context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-	}
-    else
-	{	//read only, the function does nothing
-		RI_ASSERT(!isImage && !isPath && !isPaint && !isMaskLayer && isFont);
-        if (paramType != VG_FONT_NUM_GLYPHS)
-    		context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-    }
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgSetParameteri(VGHandle object, VGint paramType, VGint value)
-#else
-void RI_APIENTRY vgSetParameteri(VGHandle object, VGint paramType, VGint value)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	bool isImage = context->isValidImage(object);
-	bool isPath = context->isValidPath(object);
-	bool isPaint = context->isValidPaint(object);
-	bool isMaskLayer = context->isValidMaskLayer(object);
-	bool isFont = context->isValidFont(object);
-	RI_IF_ERROR(!isImage && !isPath && !isPaint && !isMaskLayer && !isFont, VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid object handle
-	RI_IF_ERROR(paramType == VG_PAINT_COLOR || paramType == VG_PAINT_COLOR_RAMP_STOPS || paramType == VG_PAINT_LINEAR_GRADIENT ||
-				paramType == VG_PAINT_RADIAL_GRADIENT, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);	//vector valued parameter
-	VGint values[1] = {value};
-	if(isImage)
-	{	//read only, the function does nothing
-		RI_ASSERT(!isPath && !isPaint && !isMaskLayer && !isFont);
-		if(paramType < VG_IMAGE_FORMAT || paramType > VG_IMAGE_HEIGHT)
-			context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-	}
-	else if(isPath)
-	{	//read only, the function does nothing
-		RI_ASSERT(!isImage && !isPaint && !isMaskLayer && !isFont);
-		if(paramType < VG_PATH_FORMAT || paramType > VG_PATH_NUM_COORDS)
-			context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-	}
-	else if(isPaint)
-	{
-		RI_ASSERT(!isImage && !isPath && !isMaskLayer && !isFont);
-		setPaintParameterifv(context, (Paint*)object, (VGPaintParamType)paramType, 1, values, false);
-	}
-	else if(isMaskLayer)
-	{
-		RI_ASSERT(!isImage && !isPath && !isPaint && !isFont);
-		context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-	}
-    else
-	{	//read only, the function does nothing
-		RI_ASSERT(!isImage && !isPath && !isPaint && !isMaskLayer && isFont);
-        if (paramType != VG_FONT_NUM_GLYPHS)
-    		context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-    }
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgSetParameterfv(VGHandle object, VGint paramType, VGint count, const VGfloat * values)
-#else
-void RI_APIENTRY vgSetParameterfv(VGHandle object, VGint paramType, VGint count, const VGfloat * values)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(count < 0 || (!values && count > 0) || (values && !isAligned(values,4)), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	bool isImage = context->isValidImage(object);
-	bool isPath = context->isValidPath(object);
-	bool isPaint = context->isValidPaint(object);
-	bool isMaskLayer = context->isValidMaskLayer(object);
-	bool isFont = context->isValidFont(object);
-	RI_IF_ERROR(!isImage && !isPath && !isPaint && !isMaskLayer && !isFont, VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid object handle
-	if(isImage)
-	{	//read only, the function does nothing
-		RI_ASSERT(!isPath && !isPaint && !isMaskLayer && !isFont);
-		if(paramType < VG_IMAGE_FORMAT || paramType > VG_IMAGE_HEIGHT)
-			context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-	}
-	else if(isPath)
-	{	//read only, the function does nothing
-		RI_ASSERT(!isImage && !isPaint && !isMaskLayer && !isFont);
-		if(paramType < VG_PATH_FORMAT || paramType > VG_PATH_NUM_COORDS)
-			context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-	}
-	else if(isPaint)
-	{
-		RI_ASSERT(!isImage && !isPath && !isMaskLayer && !isFont);
-		setPaintParameterifv(context, (Paint*)object, (VGPaintParamType)paramType, count, values, true);
-	}
-	else if(isMaskLayer)
-	{
-		RI_ASSERT(!isImage && !isPath && !isPaint && !isFont);
-		context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-	}
-    else
-	{	//read only, the function does nothing
-		RI_ASSERT(!isImage && !isPath && !isPaint && !isMaskLayer && isFont);
-        if (paramType != VG_FONT_NUM_GLYPHS)
-    		context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-    }
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgSetParameteriv(VGHandle object, VGint paramType, VGint count, const VGint * values)
-#else
-void RI_APIENTRY vgSetParameteriv(VGHandle object, VGint paramType, VGint count, const VGint * values)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(count < 0 || (!values && count > 0) || (values && !isAligned(values,4)), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	bool isImage = context->isValidImage(object);
-	bool isPath = context->isValidPath(object);
-	bool isPaint = context->isValidPaint(object);
-	bool isMaskLayer = context->isValidMaskLayer(object);
-	bool isFont = context->isValidFont(object);
-	RI_IF_ERROR(!isImage && !isPath && !isPaint && !isMaskLayer && !isFont, VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid object handle
-	if(isImage)
-	{	//read only, the function does nothing
-		RI_ASSERT(!isPath && !isPaint && !isMaskLayer && !isFont);
-		if(paramType < VG_IMAGE_FORMAT || paramType > VG_IMAGE_HEIGHT)
-			context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-	}
-	else if(isPath)
-	{	//read only, the function does nothing
-		RI_ASSERT(!isImage && !isPaint && !isMaskLayer && !isFont);
-		if(paramType < VG_PATH_FORMAT || paramType > VG_PATH_NUM_COORDS)
-			context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-	}
-	else if(isPaint)
-	{
-		RI_ASSERT(!isImage && !isPath && !isMaskLayer && !isFont);
-		setPaintParameterifv(context, (Paint*)object, (VGPaintParamType)paramType, count, values, false);
-	}
-	else if(isMaskLayer)
-	{
-		RI_ASSERT(!isImage && !isPath && !isPaint && !isFont);
-		context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-	}
-    else
-	{	//read only, the function does nothing
-		RI_ASSERT(!isImage && !isPath && !isPaint && !isMaskLayer && isFont);
-        if (paramType != VG_FONT_NUM_GLYPHS)
-    		context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-    }
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static void getPaintParameterifv(VGContext* context, Paint* paint, VGPaintParamType type, VGint count, void* values, bool floats)
-{
-	switch(type)
-	{
-	case VG_PAINT_TYPE:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, paint->m_paintType);
-		break;
-
-	case VG_PAINT_COLOR:
-		if(count > 4)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		floatToParam(values, floats, count, 0, paint->m_inputPaintColor.r);
-		floatToParam(values, floats, count, 1, paint->m_inputPaintColor.g);
-		floatToParam(values, floats, count, 2, paint->m_inputPaintColor.b);
-		floatToParam(values, floats, count, 3, paint->m_inputPaintColor.a);
-		break;
-
-	case VG_PAINT_COLOR_RAMP_SPREAD_MODE:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, paint->m_colorRampSpreadMode);
-		break;
-
-	case VG_PAINT_COLOR_RAMP_STOPS:
-		{
-			if(count > paint->m_inputColorRampStops.size()*5)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-			int j = 0;
-			for(int i=0;i<paint->m_inputColorRampStops.size();i++)
-			{
-				floatToParam(values, floats, count, j++, paint->m_inputColorRampStops[i].offset);
-				floatToParam(values, floats, count, j++, paint->m_inputColorRampStops[i].color.r);
-				floatToParam(values, floats, count, j++, paint->m_inputColorRampStops[i].color.g);
-				floatToParam(values, floats, count, j++, paint->m_inputColorRampStops[i].color.b);
-				floatToParam(values, floats, count, j++, paint->m_inputColorRampStops[i].color.a);
-			}
-			break;
-		}
-
-	case VG_PAINT_COLOR_RAMP_PREMULTIPLIED:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, paint->m_colorRampPremultiplied);
-		break;
-
-	case VG_PAINT_LINEAR_GRADIENT:
-		if(count > 4)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		floatToParam(values, floats, count, 0, paint->m_inputLinearGradientPoint0.x);
-		floatToParam(values, floats, count, 1, paint->m_inputLinearGradientPoint0.y);
-		floatToParam(values, floats, count, 2, paint->m_inputLinearGradientPoint1.x);
-		floatToParam(values, floats, count, 3, paint->m_inputLinearGradientPoint1.y);
-		break;
-
-	case VG_PAINT_RADIAL_GRADIENT:
-		if(count > 5)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		floatToParam(values, floats, count, 0, paint->m_inputRadialGradientCenter.x);
-		floatToParam(values, floats, count, 1, paint->m_inputRadialGradientCenter.y);
-		floatToParam(values, floats, count, 2, paint->m_inputRadialGradientFocalPoint.x);
-		floatToParam(values, floats, count, 3, paint->m_inputRadialGradientFocalPoint.y);
-		floatToParam(values, floats, count, 4, paint->m_inputRadialGradientRadius);
-		break;
-
-	case VG_PAINT_PATTERN_TILING_MODE:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, paint->m_patternTilingMode);
-		break;
-
-	default:
-		context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-		break;
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static void getPathParameterifv(VGContext* context, Path* path, VGPathParamType type, VGint count, void* values, bool floats)
-{
-	switch(type)
-	{
-	case VG_PATH_FORMAT:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, path->getFormat());
-		break;
-
-	case VG_PATH_DATATYPE:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, path->getDatatype());
-		break;
-
-	case VG_PATH_SCALE:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		floatToParam(values, floats, count, 0, path->getScale());
-		break;
-
-	case VG_PATH_BIAS:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		floatToParam(values, floats, count, 0, path->getBias());
-		break;
-
-	case VG_PATH_NUM_SEGMENTS:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, path->getNumSegments());
-		break;
-
-	case VG_PATH_NUM_COORDS:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, path->getNumCoordinates());
-		break;
-
-	default:
-		context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-		break;
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static void getImageParameterifv(VGContext* context, Image* image, VGImageParamType type, VGint count, void* values, bool floats)
-{
-	switch(type)
-	{
-	case VG_IMAGE_FORMAT:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		RI_ASSERT(isValidImageFormat(image->getDescriptor().format));
-		intToParam(values, floats, count, 0, image->getDescriptor().format);
-		break;
-
-	case VG_IMAGE_WIDTH:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, image->getWidth());
-		break;
-
-	case VG_IMAGE_HEIGHT:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, image->getHeight());
-		break;
-
-	default:
-		context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-		break;
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static void getFontParameterifv(VGContext* context, Font* font, VGFontParamType type, VGint count, void* values, bool floats)
-{
-	switch(type)
-	{
-	case VG_FONT_NUM_GLYPHS:
-		if(count > 1)	{ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
-		intToParam(values, floats, count, 0, font->getNumGlyphs());
-		break;
-
-	default:
-		context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid VGParamType
-		break;
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-VGfloat RI_APIENTRY do_vgGetParameterf(VGHandle object, VGint paramType)
-#else
-VGfloat RI_APIENTRY vgGetParameterf(VGHandle object, VGint paramType)
-#endif
-{
-	RI_GET_CONTEXT(0.0f);
-	RI_IF_ERROR(paramType == VG_PAINT_COLOR || paramType == VG_PAINT_COLOR_RAMP_STOPS || paramType == VG_PAINT_LINEAR_GRADIENT ||
-				paramType == VG_PAINT_RADIAL_GRADIENT, VG_ILLEGAL_ARGUMENT_ERROR, 0.0f);	//vector valued parameter
-	bool isImage = context->isValidImage(object);
-	bool isPath = context->isValidPath(object);
-	bool isPaint = context->isValidPaint(object);
-	bool isFont = context->isValidFont(object);
-	RI_IF_ERROR(!isImage && !isPath && !isPaint && !isFont, VG_BAD_HANDLE_ERROR, 0.0f);	//invalid object handle
-	VGfloat ret = 0.0f;
-	if(isImage)
-	{
-		RI_ASSERT(!isPath && !isPaint && !isFont);
-		getImageParameterifv(context, (Image*)object, (VGImageParamType)paramType, 1, &ret, true);
-	}
-	else if(isPath)
-	{
-		RI_ASSERT(!isImage && !isPaint && !isFont);
-		getPathParameterifv(context, (Path*)object, (VGPathParamType)paramType, 1, &ret, true);
-	}
-	else if(isPaint)
-	{
-		RI_ASSERT(!isImage && !isPath && !isFont);
-		getPaintParameterifv(context, (Paint*)object, (VGPaintParamType)paramType, 1, &ret, true);
-	}
-	else
-	{
-		RI_ASSERT(!isImage && !isPath && !isPaint && isFont);
-		getFontParameterifv(context, (Font*)object, (VGFontParamType)paramType, 1, &ret, true);
-	}
-	RI_RETURN(ret);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-VGint RI_APIENTRY do_vgGetParameteri(VGHandle object, VGint paramType)
-#else
-VGint RI_APIENTRY vgGetParameteri(VGHandle object, VGint paramType)
-#endif
-{
-	RI_GET_CONTEXT(0);
-	RI_IF_ERROR(paramType == VG_PAINT_COLOR || paramType == VG_PAINT_COLOR_RAMP_STOPS || paramType == VG_PAINT_LINEAR_GRADIENT ||
-				paramType == VG_PAINT_RADIAL_GRADIENT, VG_ILLEGAL_ARGUMENT_ERROR, 0);	//vector valued parameter
-	bool isImage = context->isValidImage(object);
-	bool isPath = context->isValidPath(object);
-	bool isPaint = context->isValidPaint(object);
-	bool isFont = context->isValidFont(object);
-	RI_IF_ERROR(!isImage && !isPath && !isPaint && !isFont, VG_BAD_HANDLE_ERROR, 0);	//invalid object handle
-	VGint ret = 0;
-	if(isImage)
-	{
-		RI_ASSERT(!isPath && !isPaint && !isFont);
-		getImageParameterifv(context, (Image*)object, (VGImageParamType)paramType, 1, &ret, false);
-	}
-	else if(isPath)
-	{
-		RI_ASSERT(!isImage && !isPaint && !isFont);
-		getPathParameterifv(context, (Path*)object, (VGPathParamType)paramType, 1, &ret, false);
-	}
-	else if(isPaint)
-	{
-		RI_ASSERT(!isImage && !isPath && !isFont);
-		getPaintParameterifv(context, (Paint*)object, (VGPaintParamType)paramType, 1, &ret, false);
-	}
-	else
-	{
-		RI_ASSERT(!isImage && !isPath && !isPaint && isFont);
-		getFontParameterifv(context, (Font*)object, (VGFontParamType)paramType, 1, &ret, false);
-	}
-	RI_RETURN(ret);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgGetParameterfv(VGHandle object, VGint paramType, VGint count, VGfloat * values)
-#else
-void RI_APIENTRY vgGetParameterfv(VGHandle object, VGint paramType, VGint count, VGfloat * values)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(count <= 0 || !values || !isAligned(values,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	bool isImage = context->isValidImage(object);
-	bool isPath = context->isValidPath(object);
-	bool isPaint = context->isValidPaint(object);
-	bool isFont = context->isValidFont(object);
-	RI_IF_ERROR(!isImage && !isPath && !isPaint && !isFont, VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid object handle
-	if(isImage)
-	{
-		RI_ASSERT(!isPath && !isPaint && !isFont);
-		getImageParameterifv(context, (Image*)object, (VGImageParamType)paramType, count, values, true);
-	}
-	else if(isPath)
-	{
-		RI_ASSERT(!isImage && !isPaint && !isFont);
-		getPathParameterifv(context, (Path*)object, (VGPathParamType)paramType, count, values, true);
-	}
-	else if(isPaint)
-	{
-		RI_ASSERT(!isImage && !isPath && !isFont);
-		getPaintParameterifv(context, (Paint*)object, (VGPaintParamType)paramType, count, values, true);
-	}
-	else
-	{
-		RI_ASSERT(!isImage && !isPath && !isPaint && isFont);
-		getFontParameterifv(context, (Font*)object, (VGFontParamType)paramType, count, values, true);
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgGetParameteriv(VGHandle object, VGint paramType, VGint count, VGint * values)
-#else
-void RI_APIENTRY vgGetParameteriv(VGHandle object, VGint paramType, VGint count, VGint * values)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(count <= 0 || !values || !isAligned(values,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	bool isImage = context->isValidImage(object);
-	bool isPath = context->isValidPath(object);
-	bool isPaint = context->isValidPaint(object);
-	bool isFont = context->isValidFont(object);
-	RI_IF_ERROR(!isImage && !isPath && !isPaint && !isFont, VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid object handle
-	if(isImage)
-	{
-		RI_ASSERT(!isPath && !isPaint && !isFont);
-		getImageParameterifv(context, (Image*)object, (VGImageParamType)paramType, count, values, false);
-	}
-	else if(isPath)
-	{
-		RI_ASSERT(!isImage && !isPaint && !isFont);
-		getPathParameterifv(context, (Path*)object, (VGPathParamType)paramType, count, values, false);
-	}
-	else if(isPaint)
-	{
-		RI_ASSERT(!isImage && !isPath && !isFont);
-		getPaintParameterifv(context, (Paint*)object, (VGPaintParamType)paramType, count, values, false);
-	}
-	else
-	{
-		RI_ASSERT(!isImage && !isPath && !isPaint && isFont);
-		getFontParameterifv(context, (Font*)object, (VGFontParamType)paramType, count, values, false);
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-VGint RI_APIENTRY do_vgGetParameterVectorSize(VGHandle object, VGint paramType)
-#else
-VGint RI_APIENTRY vgGetParameterVectorSize(VGHandle object, VGint paramType)
-#endif
-{
-	RI_GET_CONTEXT(0);
-	bool isImage = context->isValidImage(object);
-	bool isPath = context->isValidPath(object);
-	bool isPaint = context->isValidPaint(object);
-	bool isFont = context->isValidFont(object);
-	RI_IF_ERROR(!isImage && !isPath && !isPaint && !isFont, VG_BAD_HANDLE_ERROR, 0);	//invalid object handle
-	int ret = 0;
-	if(isImage)
-	{
-		RI_ASSERT(!isPath && !isPaint && !isFont);
-		switch(paramType)
-		{
-		case VG_IMAGE_FORMAT:
-		case VG_IMAGE_WIDTH:
-		case VG_IMAGE_HEIGHT:
-			ret = 1;
-			break;
-
-		default:
-			context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid paramType
-			break;
-		}
-	}
-	else if(isPath)
-	{
-		RI_ASSERT(!isImage && !isPaint && !isFont);
-		switch(paramType)
-		{
-		case VG_PATH_FORMAT:
-		case VG_PATH_DATATYPE:
-		case VG_PATH_SCALE:
-		case VG_PATH_BIAS:
-		case VG_PATH_NUM_SEGMENTS:
-		case VG_PATH_NUM_COORDS:
-			ret = 1;
-			break;
-
-		default:
-			context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid paramType
-			break;
-		}
-	}
-	else if(isPaint)
-	{
-		RI_ASSERT(!isImage && !isPath && !isFont);
-		switch(paramType)
-		{
-		case VG_PAINT_TYPE:
-		case VG_PAINT_COLOR_RAMP_SPREAD_MODE:
-		case VG_PAINT_PATTERN_TILING_MODE:
-			ret = 1;
-			break;
-
-		case VG_PAINT_COLOR:
-		case VG_PAINT_LINEAR_GRADIENT:
-			ret = 4;
-			break;
-
-		case VG_PAINT_COLOR_RAMP_STOPS:
-			ret = ((Paint*)object)->m_inputColorRampStops.size() * 5;
-			break;
-
-		case VG_PAINT_COLOR_RAMP_PREMULTIPLIED:
-			ret = 1;
-			break;
-
-		case VG_PAINT_RADIAL_GRADIENT:
-			ret = 5;
-			break;
-			
-		default:
-			context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid paramType
-			break;
-		}
-	}
-	else
-	{
-		RI_ASSERT(!isImage && !isPath && !isPaint && isFont);
-		switch(paramType)
-		{
-		case VG_FONT_NUM_GLYPHS:
-			ret = 1;
-			break;
-
-		default:
-			context->setError(VG_ILLEGAL_ARGUMENT_ERROR);	//invalid paramType
-			break;
-		}
-	}
-	RI_RETURN(ret);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static Matrix3x3* getCurrentMatrix(VGContext* context)
-{
-	RI_ASSERT(context);
-	switch(context->m_matrixMode)
-	{
-	case VG_MATRIX_PATH_USER_TO_SURFACE:
-		return &context->m_pathUserToSurface;
-
-	case VG_MATRIX_IMAGE_USER_TO_SURFACE:
-		return &context->m_imageUserToSurface;
-
-	case VG_MATRIX_FILL_PAINT_TO_USER:
-		return &context->m_fillPaintToUser;
-
-	case VG_MATRIX_STROKE_PAINT_TO_USER:
-		return &context->m_strokePaintToUser;
-
-	default:
-		RI_ASSERT(context->m_matrixMode == VG_MATRIX_GLYPH_USER_TO_SURFACE);
-		return &context->m_glyphUserToSurface;
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgLoadIdentity(void)
-#else
-void RI_APIENTRY vgLoadIdentity(void)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	Matrix3x3* d = getCurrentMatrix(context);
-	d->identity();
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgLoadMatrix(const VGfloat * m)
-#else
-void RI_APIENTRY vgLoadMatrix(const VGfloat * m)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!m || !isAligned(m,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	Matrix3x3* d = getCurrentMatrix(context);
-	d->set(inputFloat(m[0]), inputFloat(m[3]), inputFloat(m[6]),
-		   inputFloat(m[1]), inputFloat(m[4]), inputFloat(m[7]),
-		   inputFloat(m[2]), inputFloat(m[5]), inputFloat(m[8]));
-	if(context->m_matrixMode != VG_MATRIX_IMAGE_USER_TO_SURFACE)
-	{
-		(*d)[2].set(0,0,1);
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgGetMatrix(VGfloat * m)
-#else
-void RI_APIENTRY vgGetMatrix(VGfloat * m)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!m || !isAligned(m,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	Matrix3x3* d = getCurrentMatrix(context);
-	m[0] = (*d)[0][0];
-	m[1] = (*d)[1][0];
-	m[2] = (*d)[2][0];
-	m[3] = (*d)[0][1];
-	m[4] = (*d)[1][1];
-	m[5] = (*d)[2][1];
-	m[6] = (*d)[0][2];
-	m[7] = (*d)[1][2];
-	m[8] = (*d)[2][2];
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgMultMatrix(const VGfloat * m)
-#else
-void RI_APIENTRY vgMultMatrix(const VGfloat * m)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!m || !isAligned(m,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	Matrix3x3 n(inputFloat(m[0]), inputFloat(m[3]), inputFloat(m[6]),
-				inputFloat(m[1]), inputFloat(m[4]), inputFloat(m[7]),
-				inputFloat(m[2]), inputFloat(m[5]), inputFloat(m[8]));
-	if(context->m_matrixMode != VG_MATRIX_IMAGE_USER_TO_SURFACE)
-		n[2].set(0,0,1);
-
-	Matrix3x3* d = getCurrentMatrix(context);
-	*d *= n;
-	if(context->m_matrixMode != VG_MATRIX_IMAGE_USER_TO_SURFACE)
-	{
-		(*d)[2].set(0,0,1);	//force affinity
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgTranslate(VGfloat tx, VGfloat ty)
-#else
-void RI_APIENTRY vgTranslate(VGfloat tx, VGfloat ty)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	Matrix3x3 n(1, 0, inputFloat(tx),
-				0, 1, inputFloat(ty),
-				0, 0, 1 );
-	Matrix3x3* d = getCurrentMatrix(context);
-	*d *= n;
-	if(context->m_matrixMode != VG_MATRIX_IMAGE_USER_TO_SURFACE)
-	{
-		(*d)[2].set(0,0,1);	//force affinity
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgScale(VGfloat sx, VGfloat sy)
-#else
-void RI_APIENTRY vgScale(VGfloat sx, VGfloat sy)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	Matrix3x3 n(inputFloat(sx), 0,              0,
-				0,              inputFloat(sy), 0,
-				0,              0,              1 );
-	Matrix3x3* d = getCurrentMatrix(context);
-	*d *= n;
-	if(context->m_matrixMode != VG_MATRIX_IMAGE_USER_TO_SURFACE)
-	{
-		(*d)[2].set(0,0,1);	//force affinity
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgShear(VGfloat shx, VGfloat shy)
-#else
-void RI_APIENTRY vgShear(VGfloat shx, VGfloat shy)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	Matrix3x3 n(1,               inputFloat(shx), 0,
-				inputFloat(shy), 1,               0,
-				0,               0,               1);
-	Matrix3x3* d = getCurrentMatrix(context);
-	*d *= n;
-	if(context->m_matrixMode != VG_MATRIX_IMAGE_USER_TO_SURFACE)
-	{
-		(*d)[2].set(0,0,1);	//force affinity
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgRotate(VGfloat angle)
-#else
-void RI_APIENTRY vgRotate(VGfloat angle)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RIfloat a = RI_DEG_TO_RAD(inputFloat(angle));
-	Matrix3x3 n((RIfloat)cos(a), -(RIfloat)sin(a), 0,
-				(RIfloat)sin(a),  (RIfloat)cos(a), 0,
-				0,              0,             1 );
-	Matrix3x3* d = getCurrentMatrix(context);
-	*d *= n;
-	if(context->m_matrixMode != VG_MATRIX_IMAGE_USER_TO_SURFACE)
-	{
-		(*d)[2].set(0,0,1);	//force affinity
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgMask(VGHandle mask, VGMaskOperation operation, VGint x, VGint y, VGint width, VGint height)
-#else
-void RI_APIENTRY vgMask(VGHandle mask, VGMaskOperation operation, VGint x, VGint y, VGint width, VGint height)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-    bool isImage = context->isValidImage(mask);
-    bool isMaskLayer = context->isValidMaskLayer(mask);
-	RI_IF_ERROR(operation != VG_CLEAR_MASK && operation != VG_FILL_MASK && !isImage && !isMaskLayer, VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(operation != VG_CLEAR_MASK && operation != VG_FILL_MASK && isImage && eglvgIsInUse((Image*)mask), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(operation < VG_CLEAR_MASK || operation > VG_SUBTRACT_MASK, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-    Drawable* drawable = context->getCurrentDrawable();
-	RI_IF_ERROR(isMaskLayer && drawable->getNumSamples() != ((Surface*)mask)->getNumSamples(), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-    if(!drawable || !drawable->getMaskBuffer())
-    {
-        RI_RETURN(RI_NO_RETVAL);	//no EGL surface is current at the moment or context has no mask buffer
-    }
-    if(isImage)
-        drawable->getMaskBuffer()->mask((Image*)mask, operation, x, y, width, height);
-    else
-        drawable->getMaskBuffer()->mask((Surface*)mask, operation, x, y, width, height);
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static void renderStroke(const VGContext* context, int w, int h, int numSamples, Path* path, Rasterizer& rasterizer, const PixelPipe* pixelPipe, const Matrix3x3& userToSurface)
-{
-    RI_ASSERT(context);
-    RI_ASSERT(w > 0 && h > 0 && numSamples >= 1 && numSamples <= 32);
-
-    RIuint32* covBuffer = RI_NEW_ARRAY(RIuint32, w*h);
-    memset(covBuffer, 0, w*h*sizeof(RIuint32));
-
-    rasterizer.setup(0, 0, w, h, VG_NON_ZERO, NULL, covBuffer);
-    path->stroke(userToSurface, rasterizer, context->m_strokeDashPattern, context->m_strokeDashPhase, context->m_strokeDashPhaseReset ? true : false,
-                 context->m_strokeLineWidth, context->m_strokeCapStyle, context->m_strokeJoinStyle, RI_MAX(context->m_strokeMiterLimit, 1.0f));	//throws bad_alloc
-
-    int sx,sy,ex,ey;
-    rasterizer.getBBox(sx,sy,ex,ey);
-    RI_ASSERT(sx >= 0 && sx <= w);
-    RI_ASSERT(sy >= 0 && sy <= h);
-    RI_ASSERT(ex >= 0 && ex <= w);
-    RI_ASSERT(ey >= 0 && ey <= h);
-
-    for(int j=sy;j<ey;j++)
-    {
-        for(int i=sx;i<ex;i++)
-        {
-            unsigned int c = covBuffer[j*w+i];
-            if(c)
-            {
-                int coverage = 0;
-                for(int k=0;k<numSamples;k++)
-                {
-                    if(c & (1<<k))
-                        coverage++;
-                }
-                pixelPipe->pixelPipe(i, j, (RIfloat)coverage/(RIfloat)numSamples, c);
-            }
-        }
-    }
-    RI_DELETE_ARRAY(covBuffer);
-}
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgRenderToMask(VGPath path, VGbitfield paintModes, VGMaskOperation operation)
-#else
-void RI_APIENTRY vgRenderToMask(VGPath path, VGbitfield paintModes, VGMaskOperation operation)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidPath(path), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid path handle
-	RI_IF_ERROR(!paintModes || (paintModes & ~(VG_FILL_PATH | VG_STROKE_PATH)), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);	//invalid paint mode
-	RI_IF_ERROR(operation < VG_CLEAR_MASK || operation > VG_SUBTRACT_MASK, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-    Drawable* curr = context->getCurrentDrawable();
-    if(!curr || !curr->getMaskBuffer())
-    {
-        RI_RETURN(RI_NO_RETVAL);	//no EGL surface is current at the moment or context has no mask buffer
-    }
-
-    if(operation == VG_CLEAR_MASK || operation == VG_FILL_MASK)
-    {
-        Surface* dummy = NULL;
-        curr->getMaskBuffer()->mask(dummy, operation, 0, 0, curr->getWidth(), curr->getHeight());
-        RI_RETURN(RI_NO_RETVAL);
-    }
-
-	try
-	{
-        Drawable drawable(Color::formatToDescriptor(VG_A_8), curr->getWidth(), curr->getHeight(), curr->getNumSamples(), 1);    //TODO 0 mask bits (mask buffer is not used)
-
-        Rasterizer rasterizer;
-        if(context->m_scissoring)
-            rasterizer.setScissor(context->m_scissor);	//throws bad_alloc
-        int numSamples = rasterizer.setupSamplingPattern(context->m_renderingQuality, drawable.getNumSamples());
-
-        PixelPipe pixelPipe;
-        pixelPipe.setDrawable(&drawable);
-        pixelPipe.setMask(false);
-        pixelPipe.setPaint(NULL);   //use default paint (solid color alpha = 1)
-        pixelPipe.setBlendMode(VG_BLEND_SRC);   //write solid color * coverage to dest
-
-        Matrix3x3 userToSurface = context->m_pathUserToSurface;
-        userToSurface[2].set(0,0,1);	//force affinity
-
-        if(paintModes & VG_FILL_PATH)
-        {
-            drawable.getColorBuffer()->clear(Color(0,0,0,0,drawable.getColorBuffer()->getDescriptor().internalFormat), 0, 0, drawable.getWidth(), drawable.getHeight());
-            ((Path*)path)->fill(userToSurface, rasterizer);	//throws bad_alloc
-            rasterizer.setup(0, 0, drawable.getWidth(), drawable.getHeight(), context->m_fillRule, &pixelPipe, NULL);
-            rasterizer.fill();	//throws bad_alloc
-            curr->getMaskBuffer()->mask(drawable.getColorBuffer(), operation, 0, 0, drawable.getWidth(), drawable.getHeight());
-        }
-
-        if(paintModes & VG_STROKE_PATH && context->m_strokeLineWidth > 0.0f)
-        {
-            drawable.getColorBuffer()->clear(Color(0,0,0,0,drawable.getColorBuffer()->getDescriptor().internalFormat), 0, 0, drawable.getWidth(), drawable.getHeight());
-            renderStroke(context, drawable.getWidth(), drawable.getHeight(), numSamples, (Path*)path, rasterizer, &pixelPipe, userToSurface);
-            curr->getMaskBuffer()->mask(drawable.getColorBuffer(), operation, 0, 0, drawable.getWidth(), drawable.getHeight());
-        }
-	}
-	catch(std::bad_alloc)
-	{
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-VGMaskLayer RI_APIENTRY do_vgCreateMaskLayer(VGint width, VGint height)
-#else
-VGMaskLayer RI_APIENTRY vgCreateMaskLayer(VGint width, VGint height)
-#endif
-{
-	RI_GET_CONTEXT(VG_INVALID_HANDLE);
-	RI_IF_ERROR(width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, VG_INVALID_HANDLE);
-	RI_IF_ERROR(width > RI_MAX_IMAGE_WIDTH || height > RI_MAX_IMAGE_HEIGHT || width*height > RI_MAX_IMAGE_PIXELS ||
-				width*height > RI_MAX_IMAGE_BYTES, VG_ILLEGAL_ARGUMENT_ERROR, VG_INVALID_HANDLE);
-    Drawable* curr = context->getCurrentDrawable();
-    if(!curr || !curr->getMaskBuffer())
-        RI_RETURN(VG_INVALID_HANDLE);   //no current drawing surface
-
-	Surface* layer = NULL;
-	try
-	{
-		layer = RI_NEW(Surface, (Color::formatToDescriptor(VG_A_8), width, height, curr->getNumSamples()));	//throws bad_alloc
-		RI_ASSERT(layer);
-		context->m_maskLayerManager->addResource(layer, context);	//throws bad_alloc
-        layer->clear(Color(1,1,1,1,Color::sRGBA), 0, 0, width, height);
-		RI_RETURN((VGMaskLayer)layer);
-	}
-	catch(std::bad_alloc)
-	{
-		RI_DELETE(layer);
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-		RI_RETURN(VG_INVALID_HANDLE);
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgDestroyMaskLayer(VGMaskLayer maskLayer)
-#else
-void RI_APIENTRY vgDestroyMaskLayer(VGMaskLayer maskLayer)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidMaskLayer(maskLayer), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid handle
-
-	context->m_maskLayerManager->removeResource((Surface*)maskLayer);
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgFillMaskLayer(VGMaskLayer maskLayer, VGint x, VGint y, VGint width, VGint height, VGfloat value)
-#else
-void RI_APIENTRY vgFillMaskLayer(VGMaskLayer maskLayer, VGint x, VGint y, VGint width, VGint height, VGfloat value)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidMaskLayer(maskLayer), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid handle
-    RI_IF_ERROR(value < 0.0f || value > 1.0f, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-    Surface* layer = (Surface*)maskLayer;
-    RI_IF_ERROR(width <= 0 || height <= 0 || x < 0 || y < 0 || x > layer->getWidth()-width || y > layer->getHeight()-height, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-    layer->clear(Color(1,1,1,value,Color::sRGBA), x, y, width, height);
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgCopyMask(VGMaskLayer maskLayer, VGint dx, VGint dy, VGint sx, VGint sy, VGint width, VGint height)
-#else
-void RI_APIENTRY vgCopyMask(VGMaskLayer maskLayer, VGint dx, VGint dy, VGint sx, VGint sy, VGint width, VGint height)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidMaskLayer(maskLayer), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid handle
-    Drawable* drawable = context->getCurrentDrawable();
-    if(!drawable || !drawable->getMaskBuffer())
-    {
-        RI_RETURN(RI_NO_RETVAL);	//no EGL surface is current at the moment or context has no mask buffer
-    }
-    Surface* layer = (Surface*)maskLayer;
-    RI_IF_ERROR(width <= 0 || height <= 0 || drawable->getNumSamples() != layer->getNumSamples(), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-    try
-    {   //copy drawing surface mask to mask layer
-        layer->blit(drawable->getMaskBuffer(), sx, sy, dx, dy, width, height);	//throws bad_alloc
-    }
-	catch(std::bad_alloc)
-	{
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-	}
-    RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgClear(VGint x, VGint y, VGint width, VGint height)
-#else
-void RI_APIENTRY vgClear(VGint x, VGint y, VGint width, VGint height)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-    Drawable* drawable = context->getCurrentDrawable();
-    if(!drawable)
-    {
-        RI_RETURN(RI_NO_RETVAL);	//no EGL surface is current at the moment
-    }
-
-	try
-	{
-		if(context->m_scissoring)
-			drawable->getColorBuffer()->clear(context->m_clearColor, x, y, width, height, context->m_scissor);	//throws bad_alloc
-		else
-			drawable->getColorBuffer()->clear(context->m_clearColor, x, y, width, height);
-	}
-	catch(std::bad_alloc)
-	{
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-VGPath RI_APIENTRY do_vgCreatePath(VGint pathFormat, VGPathDatatype datatype, VGfloat scale, VGfloat bias, VGint segmentCapacityHint, VGint coordCapacityHint, VGbitfield capabilities)
-#else
-VGPath RI_APIENTRY vgCreatePath(VGint pathFormat, VGPathDatatype datatype, VGfloat scale, VGfloat bias, VGint segmentCapacityHint, VGint coordCapacityHint, VGbitfield capabilities)
-#endif
-{
-	RI_GET_CONTEXT(VG_INVALID_HANDLE);
-	RI_IF_ERROR(pathFormat != VG_PATH_FORMAT_STANDARD, VG_UNSUPPORTED_PATH_FORMAT_ERROR, VG_INVALID_HANDLE);
-	RI_IF_ERROR(datatype < VG_PATH_DATATYPE_S_8 || datatype > VG_PATH_DATATYPE_F, VG_ILLEGAL_ARGUMENT_ERROR, VG_INVALID_HANDLE);
-	RIfloat s = inputFloat(scale);
-	RIfloat b = inputFloat(bias);
-	RI_IF_ERROR(s == 0.0f, VG_ILLEGAL_ARGUMENT_ERROR, VG_INVALID_HANDLE);
-	capabilities &= VG_PATH_CAPABILITY_ALL;	//undefined bits are ignored
-
-	Path* path = NULL;
-	try
-	{
-		path = RI_NEW(Path, (pathFormat, datatype, s, b, segmentCapacityHint, coordCapacityHint, capabilities));	//throws bad_alloc
-		RI_ASSERT(path);
-		context->m_pathManager->addResource(path, context);	//throws bad_alloc
-		RI_RETURN((VGPath)path);
-	}
-	catch(std::bad_alloc)
-	{
-		RI_DELETE(path);
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-		RI_RETURN(VG_INVALID_HANDLE);
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgClearPath(VGPath path, VGbitfield capabilities)
-#else
-void RI_APIENTRY vgClearPath(VGPath path, VGbitfield capabilities)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidPath(path), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid path handle
-	capabilities &= VG_PATH_CAPABILITY_ALL;	//undefined bits are ignored
-	((Path*)path)->clear(capabilities);
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgDestroyPath(VGPath path)
-#else
-void RI_APIENTRY vgDestroyPath(VGPath path)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidPath(path), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid path handle
-
-	context->m_pathManager->removeResource((Path*)path);
-
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgRemovePathCapabilities(VGPath path, VGbitfield capabilities)
-#else
-void RI_APIENTRY vgRemovePathCapabilities(VGPath path, VGbitfield capabilities)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidPath(path), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid path handle
-	capabilities &= VG_PATH_CAPABILITY_ALL;	//undefined bits are ignored
-
-	VGbitfield caps = ((Path*)path)->getCapabilities();
-	caps &= ~capabilities;
-	((Path*)path)->setCapabilities(caps);
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-VGbitfield RI_APIENTRY do_vgGetPathCapabilities(VGPath path)
-#else
-VGbitfield RI_APIENTRY vgGetPathCapabilities(VGPath path)
-#endif
-{
-	RI_GET_CONTEXT(0);
-	RI_IF_ERROR(!context->isValidPath(path), VG_BAD_HANDLE_ERROR, 0);	//invalid path handle
-	VGbitfield ret = ((Path*)path)->getCapabilities();
-	RI_RETURN(ret);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgAppendPathData(VGPath dstPath, VGint numSegments, const VGubyte * pathSegments, const void * pathData)
-#else
-void RI_APIENTRY vgAppendPathData(VGPath dstPath, VGint numSegments, const VGubyte * pathSegments, const void * pathData)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidPath(dstPath), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid path handle
-	Path* p = (Path*)dstPath;
-	RI_IF_ERROR(!(p->getCapabilities() & VG_PATH_CAPABILITY_APPEND_TO), VG_PATH_CAPABILITY_ERROR, RI_NO_RETVAL);	//no append cap
-	RI_IF_ERROR(numSegments <= 0 || !pathSegments || !pathData, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);	//no segments or data
-	RI_IF_ERROR((p->getDatatype() == VG_PATH_DATATYPE_S_16 && !isAligned(pathData,2)) ||
-				((p->getDatatype() == VG_PATH_DATATYPE_S_32 || p->getDatatype() == VG_PATH_DATATYPE_F) && !isAligned(pathData,4)),
-				VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);	//invalid alignment
-	for(int i=0;i<numSegments;i++)
-	{
-		VGPathSegment c = (VGPathSegment)(pathSegments[i] & 0x1e);
-		RI_IF_ERROR(c < VG_CLOSE_PATH || c > VG_LCWARC_TO, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);	//invalid segment
-		RI_IF_ERROR(c & ~0x1f, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);	//reserved bits are nonzero
-	}
-
-	try
-	{
-		p->appendData((const RIuint8*)pathSegments, numSegments, (const RIuint8*)pathData);	//throws bad_alloc
-	}
-	catch(std::bad_alloc)
-	{
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgModifyPathCoords(VGPath dstPath, VGint startIndex, VGint numSegments, const void * pathData)
-#else
-void RI_APIENTRY vgModifyPathCoords(VGPath dstPath, VGint startIndex, VGint numSegments, const void * pathData)
-#endif
-
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidPath(dstPath), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid path handle
-	Path* p = (Path*)dstPath;
-	RI_IF_ERROR(!(p->getCapabilities() & VG_PATH_CAPABILITY_MODIFY), VG_PATH_CAPABILITY_ERROR, RI_NO_RETVAL);	//no modify cap
-	RI_IF_ERROR(!pathData || startIndex < 0 || numSegments <= 0 || RI_INT_ADDSATURATE(startIndex, numSegments) > p->getNumSegments(), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);	//no segments
-	RI_IF_ERROR((p->getDatatype() == VG_PATH_DATATYPE_S_16 && !isAligned(pathData,2)) ||
-				((p->getDatatype() == VG_PATH_DATATYPE_S_32 || p->getDatatype() == VG_PATH_DATATYPE_F) && !isAligned(pathData,4)),
-				VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);	//invalid alignment
-	p->modifyCoords(startIndex, numSegments, (const RIuint8*)pathData);
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgAppendPath(VGPath dstPath, VGPath srcPath)
-#else
-void RI_APIENTRY vgAppendPath(VGPath dstPath, VGPath srcPath)
-#endif
-
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidPath(dstPath) || !context->isValidPath(srcPath), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid path handle
-	RI_IF_ERROR(!(((Path*)dstPath)->getCapabilities() & VG_PATH_CAPABILITY_APPEND_TO) ||
-				!(((Path*)srcPath)->getCapabilities() & VG_PATH_CAPABILITY_APPEND_FROM), VG_PATH_CAPABILITY_ERROR, RI_NO_RETVAL);	//invalid caps
-
-	try
-	{
-		((Path*)dstPath)->append((Path*)srcPath);	//throws bad_alloc
-	}
-	catch(std::bad_alloc)
-	{
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgTransformPath(VGPath dstPath, VGPath srcPath)
-#else
-void RI_APIENTRY vgTransformPath(VGPath dstPath, VGPath srcPath)
-#endif
-
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidPath(dstPath) || !context->isValidPath(srcPath), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid path handle
-	RI_IF_ERROR(!(((Path*)dstPath)->getCapabilities() & VG_PATH_CAPABILITY_TRANSFORM_TO) ||
-				!(((Path*)srcPath)->getCapabilities() & VG_PATH_CAPABILITY_TRANSFORM_FROM), VG_PATH_CAPABILITY_ERROR, RI_NO_RETVAL);	//invalid caps
-	try
-	{
-		((Path*)dstPath)->transform((Path*)srcPath, context->m_pathUserToSurface);	//throws bad_alloc
-	}
-	catch(std::bad_alloc)
-	{
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static bool drawPath(VGContext* context, VGPath path, const Matrix3x3& userToSurfaceMatrix, VGbitfield paintModes)
-{
-	//set up rendering surface and mask buffer
-    Drawable* drawable = context->getCurrentDrawable();
-      
-    if(!drawable)
-        return false;   //no EGL surface is current at the moment
-
-	Rasterizer rasterizer;
-	if(context->m_scissoring)
-		rasterizer.setScissor(context->m_scissor);	//throws bad_alloc
-	int numSamples = rasterizer.setupSamplingPattern(context->m_renderingQuality, drawable->getNumSamples());
-
-	PixelPipe pixelPipe;
-	pixelPipe.setDrawable(drawable);
-	pixelPipe.setMask(context->m_masking ? true : false);
-	pixelPipe.setBlendMode(context->m_blendMode);
-	pixelPipe.setTileFillColor(context->m_tileFillColor);
-	pixelPipe.setImageQuality(context->m_imageQuality);
-    pixelPipe.setColorTransform(context->m_colorTransform ? true : false, context->m_colorTransformValues);
-
-	Matrix3x3 userToSurface = userToSurfaceMatrix;
-	userToSurface[2].set(0,0,1);	//force affinity
-
-	if(paintModes & VG_FILL_PATH)
-	{
-		pixelPipe.setPaint((Paint*)context->m_fillPaint);
-
-		Matrix3x3 surfaceToPaintMatrix = userToSurface * context->m_fillPaintToUser;
-		if(surfaceToPaintMatrix.invert())
-		{
-			surfaceToPaintMatrix[2].set(0,0,1);		//force affinity
-			pixelPipe.setSurfaceToPaintMatrix(surfaceToPaintMatrix);
-
-            rasterizer.setup(0, 0, drawable->getWidth(), drawable->getHeight(), context->m_fillRule, &pixelPipe, NULL);
-			((Path*)path)->fill(userToSurface, rasterizer);	//throws bad_alloc
-			rasterizer.fill();	//throws bad_alloc
-		}
-	}
-
-	if(paintModes & VG_STROKE_PATH && context->m_strokeLineWidth > 0.0f)
-	{
-		pixelPipe.setPaint((Paint*)context->m_strokePaint);
-
-		Matrix3x3 surfaceToPaintMatrix = userToSurface * context->m_strokePaintToUser;
-		if(surfaceToPaintMatrix.invert())
-		{
-			surfaceToPaintMatrix[2].set(0,0,1);		//force affinity
-			pixelPipe.setSurfaceToPaintMatrix(surfaceToPaintMatrix);
-		    renderStroke(context, drawable->getWidth(), drawable->getHeight(), numSamples, (Path*)path, rasterizer, &pixelPipe, userToSurface);
-		}
-	}
-	return true;
-}
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgDrawPath(VGPath path, VGbitfield paintModes)
-#else
-void RI_APIENTRY vgDrawPath(VGPath path, VGbitfield paintModes)
-#endif
-
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidPath(path), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid path handle
-	RI_IF_ERROR(!paintModes || (paintModes & ~(VG_FILL_PATH | VG_STROKE_PATH)), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);	//invalid paint mode
-
-	try
-	{
-		if(!drawPath(context, path, context->m_pathUserToSurface, paintModes))
-		{
-			RI_RETURN(RI_NO_RETVAL);
-		}
-	}
-	catch(std::bad_alloc)
-	{
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-VGfloat RI_APIENTRY do_vgPathLength(VGPath path, VGint startSegment, VGint numSegments)
-#else
-VGfloat RI_APIENTRY vgPathLength(VGPath path, VGint startSegment, VGint numSegments)
-#endif
-
-{
-	RI_GET_CONTEXT(-1.0f);
-	RI_IF_ERROR(!context->isValidPath(path), VG_BAD_HANDLE_ERROR, -1.0f);	//invalid path handle
-	Path* p = (Path*)path;
-	RI_IF_ERROR(!(p->getCapabilities() & VG_PATH_CAPABILITY_PATH_LENGTH), VG_PATH_CAPABILITY_ERROR, -1.0f);	//invalid caps
-	RI_IF_ERROR(startSegment < 0 || numSegments <= 0 || RI_INT_ADDSATURATE(startSegment, numSegments) > p->getNumSegments(), VG_ILLEGAL_ARGUMENT_ERROR, -1.0f);
-	RIfloat pathLength = -1.0f;
-	try
-	{
-		pathLength = p->getPathLength(startSegment, numSegments);	//throws bad_alloc
-	}
-	catch(std::bad_alloc)
-	{
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-	}
-	RI_RETURN(pathLength);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgPointAlongPath(VGPath path, VGint startSegment, VGint numSegments, VGfloat distance, VGfloat * x, VGfloat * y, VGfloat * tangentX, VGfloat * tangentY)
-#else
-void RI_APIENTRY vgPointAlongPath(VGPath path, VGint startSegment, VGint numSegments, VGfloat distance, VGfloat * x, VGfloat * y, VGfloat * tangentX, VGfloat * tangentY)
-#endif
-
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidPath(path), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid path handle
-	Path* p = (Path*)path;
-	RI_IF_ERROR((x && y && !(p->getCapabilities() & VG_PATH_CAPABILITY_POINT_ALONG_PATH)) ||
-				(tangentX && tangentY && !(p->getCapabilities() & VG_PATH_CAPABILITY_TANGENT_ALONG_PATH)), VG_PATH_CAPABILITY_ERROR, RI_NO_RETVAL);	//invalid caps
-	RI_IF_ERROR(startSegment < 0 || numSegments <= 0 || RI_INT_ADDSATURATE(startSegment, numSegments) > p->getNumSegments(), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(!isAligned(x,4) || !isAligned(y,4) || !isAligned(tangentX,4) || !isAligned(tangentY,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	try
-	{
-		Vector2 point, tangent;
-		p->getPointAlong(startSegment, numSegments, distance, point, tangent);	//throws bad_alloc
-		if(x && y)
-		{
-			*x = point.x;
-			*y = point.y;
-		}
-		if(tangentX && tangentY)
-		{
-			tangent.normalize();
-			*tangentX = tangent.x;
-			*tangentY = tangent.y;
-		}
-	}
-	catch(std::bad_alloc)
-	{
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgPathBounds(VGPath path, VGfloat * minx, VGfloat * miny, VGfloat * width, VGfloat * height)
-#else
-void RI_APIENTRY vgPathBounds(VGPath path, VGfloat * minx, VGfloat * miny, VGfloat * width, VGfloat * height)
-#endif
-
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidPath(path), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid path handle
-	RI_IF_ERROR(!(((Path*)path)->getCapabilities() & VG_PATH_CAPABILITY_PATH_BOUNDS), VG_PATH_CAPABILITY_ERROR, RI_NO_RETVAL);	//invalid caps
-	RI_IF_ERROR(!minx || !miny || !width || !height, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(!isAligned(minx,4) || !isAligned(miny,4) || !isAligned(width,4) || !isAligned(height,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	try
-	{
-		RIfloat pminx,pminy,pmaxx,pmaxy;
-		((Path*)path)->getPathBounds(pminx, pminy, pmaxx, pmaxy);	//throws bad_alloc
-		*minx = pminx;
-		*miny = pminy;
-		*width = pmaxx - pminx;
-		*height = pmaxy - pminy;
-	}
-	catch(std::bad_alloc)
-	{
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgPathTransformedBounds(VGPath path, VGfloat * minx, VGfloat * miny, VGfloat * width, VGfloat * height)
-#else
-void RI_APIENTRY vgPathTransformedBounds(VGPath path, VGfloat * minx, VGfloat * miny, VGfloat * width, VGfloat * height)
-#endif
-
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidPath(path), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid path handle
-	RI_IF_ERROR(!(((Path*)path)->getCapabilities() & VG_PATH_CAPABILITY_PATH_TRANSFORMED_BOUNDS), VG_PATH_CAPABILITY_ERROR, RI_NO_RETVAL);	//invalid caps
-	RI_IF_ERROR(!minx || !miny || !width || !height, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(!isAligned(minx,4) || !isAligned(miny,4) || !isAligned(width,4) || !isAligned(height,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	try
-	{
-		RIfloat pminx, pminy, pmaxx, pmaxy;
-		((Path*)path)->getPathTransformedBounds(context->m_pathUserToSurface, pminx, pminy, pmaxx, pmaxy);	//throws bad_alloc
-		*minx = pminx;
-		*miny = pminy;
-		*width = pmaxx - pminx;
-		*height = pmaxy - pminy;
-	}
-	catch(std::bad_alloc)
-	{
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-VGboolean RI_APIENTRY do_vgInterpolatePath(VGPath dstPath, VGPath startPath, VGPath endPath, VGfloat amount)
-#else
-VGboolean RI_APIENTRY vgInterpolatePath(VGPath dstPath, VGPath startPath, VGPath endPath, VGfloat amount)
-#endif
-
-{
-	RI_GET_CONTEXT(VG_FALSE);
-	RI_IF_ERROR(!context->isValidPath(dstPath) || !context->isValidPath(startPath) || !context->isValidPath(endPath), VG_BAD_HANDLE_ERROR, VG_FALSE);	//invalid path handle
-	RI_IF_ERROR(!(((Path*)dstPath)->getCapabilities() & VG_PATH_CAPABILITY_INTERPOLATE_TO) ||
-				!(((Path*)startPath)->getCapabilities() & VG_PATH_CAPABILITY_INTERPOLATE_FROM) ||
-				!(((Path*)endPath)->getCapabilities() & VG_PATH_CAPABILITY_INTERPOLATE_FROM), VG_PATH_CAPABILITY_ERROR, VG_FALSE);	//invalid caps
-	VGboolean ret = VG_FALSE;
-	try
-	{
-		if(((Path*)dstPath)->interpolate((const Path*)startPath, (const Path*)endPath, inputFloat(amount)))	//throws bad_alloc
-			ret = VG_TRUE;
-	}
-	catch(std::bad_alloc)
-	{
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-	}
-	RI_RETURN(ret);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-VGPaint RI_APIENTRY do_vgCreatePaint(void)
-#else
-VGPaint RI_APIENTRY vgCreatePaint(void)
-#endif
-
-{
-	RI_GET_CONTEXT(VG_INVALID_HANDLE);
-	Paint* paint = NULL;
-	try
-	{
-		paint = RI_NEW(Paint, ());	//throws bad_alloc
-		RI_ASSERT(paint);
-		context->m_paintManager->addResource(paint, context);	//throws bad_alloc
-		RI_RETURN((VGPaint)paint);
-	}
-	catch(std::bad_alloc)
-	{
-		RI_DELETE(paint);
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-		RI_RETURN(VG_INVALID_HANDLE);
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgDestroyPaint(VGPaint paint)
-#else
-void RI_APIENTRY vgDestroyPaint(VGPaint paint)
-#endif
-
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidPaint(paint), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid paint handle
-
-	context->m_paintManager->removeResource((Paint*)paint);
-
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgSetPaint(VGPaint paint, VGbitfield paintModes)
-#else
-void RI_APIENTRY vgSetPaint(VGPaint paint, VGbitfield paintModes)
-#endif
-
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(paint && !context->isValidPaint(paint), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid paint handle
-	RI_IF_ERROR(!paintModes || paintModes & ~(VG_FILL_PATH | VG_STROKE_PATH), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);	//invalid paint mode
-
-	context->releasePaint(paintModes);
-
-	if(paintModes & VG_FILL_PATH)
-	{
-		if(paint)
-			((Paint*)paint)->addReference();
-		context->m_fillPaint = paint;
-	}
-	if(paintModes & VG_STROKE_PATH)
-	{
-		if(paint)
-			((Paint*)paint)->addReference();
-		context->m_strokePaint = paint;
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgSetColor(VGPaint paint, VGuint rgba)
-#else
-void RI_APIENTRY vgSetColor(VGPaint paint, VGuint rgba)
-#endif
-
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidPaint(paint), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid paint handle
-	Paint* p = (Paint*)paint;
-	p->m_inputPaintColor.unpack(rgba, Color::formatToDescriptor(VG_sRGBA_8888));
-	p->m_paintColor = inputColor(p->m_inputPaintColor);
-	p->m_paintColor.clamp();
-	p->m_paintColor.premultiply();
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-VGuint RI_APIENTRY do_vgGetColor(VGPaint paint)
-#else
-VGuint RI_APIENTRY vgGetColor(VGPaint paint)
-#endif
-
-{
-	RI_GET_CONTEXT(0);
-	RI_IF_ERROR(!context->isValidPaint(paint), VG_BAD_HANDLE_ERROR, 0);	//invalid paint handle
-	unsigned int ret = ((Paint*)paint)->m_inputPaintColor.pack(Color::formatToDescriptor(VG_sRGBA_8888));
-	RI_RETURN(ret);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-VGPaint RI_APIENTRY do_vgGetPaint(VGPaintMode paintMode)
-#else
-VGPaint RI_APIENTRY vgGetPaint(VGPaintMode paintMode)
-#endif
-
-{
-	RI_GET_CONTEXT(VG_INVALID_HANDLE);
-	RI_IF_ERROR(paintMode != VG_FILL_PATH && paintMode != VG_STROKE_PATH, VG_ILLEGAL_ARGUMENT_ERROR, VG_INVALID_HANDLE);	//invalid paint mode
-
-	if(paintMode == VG_FILL_PATH)
-	{
-		RI_RETURN(context->m_fillPaint);
-	}
-	RI_RETURN(context->m_strokePaint);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgPaintPattern(VGPaint paint, VGImage image)
-#else
-void RI_APIENTRY vgPaintPattern(VGPaint paint, VGImage image)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidPaint(paint) || (image != VG_INVALID_HANDLE && !context->isValidImage(image)), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid handle
-	Image* img = (Image*)image;
-	Paint* pnt = (Paint*)paint;
-	RI_IF_ERROR(image != VG_INVALID_HANDLE && eglvgIsInUse(img), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
-	Image* pattern = pnt->m_pattern;
-	if(pattern)
-	{
-		pattern->removeInUse();
-		if(!pattern->removeReference())
-			RI_DELETE(pattern);
-	}
-	pnt->m_pattern = img;
-	if(img)
-	{
-		img->addReference();
-		img->addInUse();
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-VGImage RI_APIENTRY do_vgCreateImage(VGImageFormat format, VGint width, VGint height, VGbitfield allowedQuality)
-#else
-VGImage RI_APIENTRY vgCreateImage(VGImageFormat format, VGint width, VGint height, VGbitfield allowedQuality)
-#endif
-{
-	RI_GET_CONTEXT(VG_INVALID_HANDLE);
-	RI_IF_ERROR(!isValidImageFormat(format), VG_UNSUPPORTED_IMAGE_FORMAT_ERROR, VG_INVALID_HANDLE);
-	RI_IF_ERROR(width <= 0 || height <= 0 || !allowedQuality ||
-				(allowedQuality & ~(VG_IMAGE_QUALITY_NONANTIALIASED | VG_IMAGE_QUALITY_FASTER | VG_IMAGE_QUALITY_BETTER)), VG_ILLEGAL_ARGUMENT_ERROR, VG_INVALID_HANDLE);
-	RI_IF_ERROR(width > RI_MAX_IMAGE_WIDTH || height > RI_MAX_IMAGE_HEIGHT || width*height > RI_MAX_IMAGE_PIXELS ||
-				((width*Color::formatToDescriptor(format).bitsPerPixel+7)/8)*height > RI_MAX_IMAGE_BYTES, VG_ILLEGAL_ARGUMENT_ERROR, VG_INVALID_HANDLE);
-
-	Image* image = NULL;
-	try
-	{
-		image = RI_NEW(Image, (Color::formatToDescriptor(format), width, height, allowedQuality));	//throws bad_alloc
-		RI_ASSERT(image);
-		context->m_imageManager->addResource(image, context);	//throws bad_alloc
-		RI_RETURN((VGImage)image);
-	}
-	catch(std::bad_alloc)
-	{
-		RI_DELETE(image);
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-		RI_RETURN(VG_INVALID_HANDLE);
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgDestroyImage(VGImage image)
-#else
-void RI_APIENTRY vgDestroyImage(VGImage image)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidImage(image), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid image handle
-
-	context->m_imageManager->removeResource((Image*)image);
-
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgClearImage(VGImage image, VGint x, VGint y, VGint width, VGint height)
-#else
-void RI_APIENTRY vgClearImage(VGImage image, VGint x, VGint y, VGint width, VGint height)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidImage(image), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
-	Image* img = (Image*)image;
-	RI_IF_ERROR(eglvgIsInUse(img), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	img->clear(context->m_clearColor, x, y, width, height);
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgImageSubData(VGImage image, const void * data, VGint dataStride, VGImageFormat dataFormat, VGint x, VGint y, VGint width, VGint height)
-#else
-void RI_APIENTRY vgImageSubData(VGImage image, const void * data, VGint dataStride, VGImageFormat dataFormat, VGint x, VGint y, VGint width, VGint height)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidImage(image), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
-	Image* img = (Image*)image;
-	RI_IF_ERROR(eglvgIsInUse(img), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(!isValidImageFormat(dataFormat), VG_UNSUPPORTED_IMAGE_FORMAT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(!data || !isAligned(data, dataFormat) || width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	{
-		Image input(Color::formatToDescriptor(dataFormat), width, height, dataStride, const_cast<RIuint8*>((const RIuint8*)data));
-		input.addReference();
-		try
-		{
-			img->blit(input, 0, 0, x, y, width, height, false);	//throws bad_alloc
-		}
-		catch(std::bad_alloc)
-		{
-		}
-		input.removeReference();
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgGetImageSubData(VGImage image, void * data, VGint dataStride, VGImageFormat dataFormat, VGint x, VGint y, VGint width, VGint height)
-#else
-void RI_APIENTRY vgGetImageSubData(VGImage image, void * data, VGint dataStride, VGImageFormat dataFormat, VGint x, VGint y, VGint width, VGint height)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidImage(image), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
-	Image* img = (Image*)image;
-	RI_IF_ERROR(eglvgIsInUse(img), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(!isValidImageFormat(dataFormat), VG_UNSUPPORTED_IMAGE_FORMAT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(!data || !isAligned(data, dataFormat) || width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	{
-		Image output(Color::formatToDescriptor(dataFormat), width, height, dataStride, (RIuint8*)data);
-		output.addReference();
-		try
-		{
-			output.blit(*img, x, y, 0, 0, width, height, false);	//throws bad_alloc
-		}
-		catch(std::bad_alloc)
-		{
-		}
-		output.removeReference();
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-VGImage RI_APIENTRY do_vgChildImage(VGImage parent, VGint x, VGint y, VGint width, VGint height)
-#else
-VGImage RI_APIENTRY vgChildImage(VGImage parent, VGint x, VGint y, VGint width, VGint height)
-#endif
-{
-	RI_GET_CONTEXT(VG_INVALID_HANDLE);
-	RI_IF_ERROR(!context->isValidImage(parent), VG_BAD_HANDLE_ERROR, VG_INVALID_HANDLE);
-	Image* p = (Image*)parent;
-	RI_IF_ERROR(eglvgIsInUse((Image*)parent), VG_IMAGE_IN_USE_ERROR, VG_INVALID_HANDLE);
-	RI_IF_ERROR(x < 0 || x >= p->getWidth() || y < 0 || y >= p->getHeight() ||
-				width <= 0 || height <= 0 || RI_INT_ADDSATURATE(x, width) > p->getWidth() || RI_INT_ADDSATURATE(y, height) > p->getHeight(), VG_ILLEGAL_ARGUMENT_ERROR, VG_INVALID_HANDLE);
-
-	Image* child = NULL;
-	try
-	{
-		child = RI_NEW(Image, (p, x, y, width, height));	//throws bad_alloc
-		RI_ASSERT(child);
-		context->m_imageManager->addResource(child, context);	//throws bad_alloc
-		RI_RETURN((VGImage)child);
-	}
-	catch(std::bad_alloc)
-	{
-		RI_DELETE(child);
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-		RI_RETURN(VG_INVALID_HANDLE);
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-VGImage RI_APIENTRY do_vgGetParent(VGImage image)
-#else
-VGImage RI_APIENTRY vgGetParent(VGImage image)
-#endif
-{
-	RI_GET_CONTEXT(VG_INVALID_HANDLE);
-	RI_IF_ERROR(!context->isValidImage(image), VG_BAD_HANDLE_ERROR, VG_INVALID_HANDLE);
-	VGImage ret = image;	//if image has no ancestors, image is returned.
-
-    //The vgGetParent function returns the closest valid ancestor (i.e., one that has not been the target of a vgDestroyImage call)
-    // of the given image.
-	Image* im = ((Image*)image)->getParent();
-    for(;im;im = im->getParent())
-    {
-		if(context->isValidImage((VGImage)im))
-		{	//the parent is valid and alive
-			ret = (VGImage)im;
-            break;
-		}
-	}
-	RI_RETURN(ret);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgCopyImage(VGImage dst, VGint dx, VGint dy, VGImage src, VGint sx, VGint sy, VGint width, VGint height, VGboolean dither)
-#else
-void RI_APIENTRY vgCopyImage(VGImage dst, VGint dx, VGint dy, VGImage src, VGint sx, VGint sy, VGint width, VGint height, VGboolean dither)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidImage(dst) || !context->isValidImage(src), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(eglvgIsInUse((Image*)dst) || eglvgIsInUse((Image*)src), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	try
-	{
-		((Image*)dst)->blit(*(Image*)src, sx, sy, dx, dy, width, height, dither ? true : false);	//throws bad_alloc
-	}
-	catch(std::bad_alloc)
-	{
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static bool drawImage(VGContext* context, VGImage image, const Matrix3x3& userToSurfaceMatrix)
-{
-    Drawable* drawable = context->getCurrentDrawable();
-    if(!drawable)
-        return false;   //no EGL surface is current at the moment
-
-	Image* img = (Image*)image;
-	//transform image corners into the surface space
-	Vector3 p0(0, 0, 1);
-	Vector3 p1(0, (RIfloat)img->getHeight(), 1);
-	Vector3 p2((RIfloat)img->getWidth(), (RIfloat)img->getHeight(), 1);
-	Vector3 p3((RIfloat)img->getWidth(), 0, 1);
-	p0 = userToSurfaceMatrix * p0;
-	p1 = userToSurfaceMatrix * p1;
-	p2 = userToSurfaceMatrix * p2;
-	p3 = userToSurfaceMatrix * p3;
-	if(p0.z <= 0.0f || p1.z <= 0.0f || p2.z <= 0.0f || p3.z <= 0.0f)
-		return false;
-
-	//projection
-	p0 *= 1.0f/p0.z;
-	p1 *= 1.0f/p1.z;
-	p2 *= 1.0f/p2.z;
-	p3 *= 1.0f/p3.z;
-
-	Rasterizer rasterizer;
-	if(context->m_scissoring)
-		rasterizer.setScissor(context->m_scissor);	//throws bad_alloc
-	rasterizer.setupSamplingPattern(context->m_renderingQuality, drawable->getNumSamples());
-
-	PixelPipe pixelPipe;
-	pixelPipe.setTileFillColor(context->m_tileFillColor);
-	pixelPipe.setPaint((Paint*)context->m_fillPaint);
-	pixelPipe.setImageQuality(context->m_imageQuality);
-	pixelPipe.setBlendMode(context->m_blendMode);
-	pixelPipe.setDrawable(drawable);
-	pixelPipe.setMask(context->m_masking ? true : false);
-    pixelPipe.setColorTransform(context->m_colorTransform ? true : false, context->m_colorTransformValues);
-
-	Matrix3x3 surfaceToImageMatrix = userToSurfaceMatrix;
-	Matrix3x3 surfaceToPaintMatrix = userToSurfaceMatrix * context->m_fillPaintToUser;
-	if(surfaceToImageMatrix.invert() && surfaceToPaintMatrix.invert())
-	{
-		VGImageMode imode = context->m_imageMode;
-		if(!surfaceToPaintMatrix.isAffine())
-			imode = VG_DRAW_IMAGE_NORMAL;	//if paint matrix is not affine, always use normal image mode
-		surfaceToPaintMatrix[2].set(0,0,1);	//force affine
-
-		pixelPipe.setImage(img, imode);
-		pixelPipe.setSurfaceToPaintMatrix(surfaceToPaintMatrix);
-		pixelPipe.setSurfaceToImageMatrix(surfaceToImageMatrix);
-
-		rasterizer.addEdge(Vector2(p0.x,p0.y), Vector2(p1.x,p1.y));	//throws bad_alloc
-		rasterizer.addEdge(Vector2(p1.x,p1.y), Vector2(p2.x,p2.y));	//throws bad_alloc
-		rasterizer.addEdge(Vector2(p2.x,p2.y), Vector2(p3.x,p3.y));	//throws bad_alloc
-		rasterizer.addEdge(Vector2(p3.x,p3.y), Vector2(p0.x,p0.y));	//throws bad_alloc
-        rasterizer.setup(0, 0, drawable->getWidth(), drawable->getHeight(), VG_EVEN_ODD, &pixelPipe, NULL);
-		rasterizer.fill();	//throws bad_alloc
-	}
-	return true;
-}
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgDrawImage(VGImage image)
-#else
-void RI_APIENTRY vgDrawImage(VGImage image)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidImage(image), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
-	Image* img = (Image*)image;
-	RI_IF_ERROR(eglvgIsInUse(img), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
-
-	try
-	{
-		if(!drawImage(context, image, context->m_imageUserToSurface))
-		{
-			RI_RETURN(RI_NO_RETVAL);
-		}
-	}
-	catch(std::bad_alloc)
-	{
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgSetPixels(VGint dx, VGint dy, VGImage src, VGint sx, VGint sy, VGint width, VGint height)
-#else
-void RI_APIENTRY vgSetPixels(VGint dx, VGint dy, VGImage src, VGint sx, VGint sy, VGint width, VGint height)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidImage(src), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(eglvgIsInUse((Image*)src), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-    Drawable* drawable = context->getCurrentDrawable();
-    if(!drawable)
-    {
-        RI_RETURN(RI_NO_RETVAL);	//no EGL surface is current at the moment
-    }
-	try
-	{
-		if(context->m_scissoring)
-			drawable->getColorBuffer()->blit(*(Image*)src, sx, sy, dx, dy, width, height, context->m_scissor);	//throws bad_alloc
-		else
-			drawable->getColorBuffer()->blit(*(Image*)src, sx, sy, dx, dy, width, height);	//throws bad_alloc
-	}
-	catch(std::bad_alloc)
-	{
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgWritePixels(const void * data, VGint dataStride, VGImageFormat dataFormat, VGint dx, VGint dy, VGint width, VGint height)
-#else
-void RI_APIENTRY vgWritePixels(const void * data, VGint dataStride, VGImageFormat dataFormat, VGint dx, VGint dy, VGint width, VGint height)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!isValidImageFormat(dataFormat), VG_UNSUPPORTED_IMAGE_FORMAT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(!data || !isAligned(data, dataFormat) || width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-    Drawable* drawable = context->getCurrentDrawable();
-    if(!drawable)
-    {
-        RI_RETURN(RI_NO_RETVAL);	//no EGL surface is current at the moment
-    }
-	{
-		Image input(Color::formatToDescriptor(dataFormat), width, height, dataStride, const_cast<RIuint8*>((const RIuint8*)data));
-		input.addReference();
-		try
-		{
-			if(context->m_scissoring)
-				drawable->getColorBuffer()->blit(input, 0, 0, dx, dy, width, height, context->m_scissor);	//throws bad_alloc
-			else
-				drawable->getColorBuffer()->blit(input, 0, 0, dx, dy, width, height);	//throws bad_alloc
-		}
-		catch(std::bad_alloc)
-		{
-		}
-		input.removeReference();
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgGetPixels(VGImage dst, VGint dx, VGint dy, VGint sx, VGint sy, VGint width, VGint height)
-#else
-void RI_APIENTRY vgGetPixels(VGImage dst, VGint dx, VGint dy, VGint sx, VGint sy, VGint width, VGint height)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidImage(dst), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(eglvgIsInUse((Image*)dst), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-    Drawable* drawable = context->getCurrentDrawable();
-    if(!drawable)
-    {
-        RI_RETURN(RI_NO_RETVAL);	//no EGL surface is current at the moment
-    }
-	try
-	{
-		((Image*)dst)->blit(drawable->getColorBuffer(), sx, sy, dx, dy, width, height);	//throws bad_alloc
-	}
-	catch(std::bad_alloc)
-	{
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgReadPixels(void* data, VGint dataStride, VGImageFormat dataFormat, VGint sx, VGint sy, VGint width, VGint height)
-#else
-void RI_APIENTRY vgReadPixels(void* data, VGint dataStride, VGImageFormat dataFormat, VGint sx, VGint sy, VGint width, VGint height)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!isValidImageFormat(dataFormat), VG_UNSUPPORTED_IMAGE_FORMAT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(!data || !isAligned(data, dataFormat) || width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-    Drawable* drawable = context->getCurrentDrawable();
-    if(!drawable)
-    {
-        RI_RETURN(RI_NO_RETVAL);	//no EGL surface is current at the moment
-    }
-	{
-		Image output(Color::formatToDescriptor(dataFormat), width, height, dataStride, (RIuint8*)data);
-		output.addReference();
-		try
-		{
-			output.blit(drawable->getColorBuffer(), sx, sy, 0, 0, width, height);	//throws bad_alloc
-		}
-		catch(std::bad_alloc)
-		{
-		}
-		output.removeReference();
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgCopyPixels(VGint dx, VGint dy, VGint sx, VGint sy, VGint width, VGint height)
-#else
-void RI_APIENTRY vgCopyPixels(VGint dx, VGint dy, VGint sx, VGint sy, VGint width, VGint height)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-    Drawable* drawable = context->getCurrentDrawable();
-    if(!drawable)
-    {
-        RI_RETURN(RI_NO_RETVAL);	//no EGL surface is current at the moment
-    }
-	try
-	{
-		if(context->m_scissoring)
-			drawable->getColorBuffer()->blit(drawable->getColorBuffer(), sx, sy, dx, dy, width, height, context->m_scissor);	//throws bad_alloc
-		else
-			drawable->getColorBuffer()->blit(drawable->getColorBuffer(), sx, sy, dx, dy, width, height);	//throws bad_alloc
-	}
-	catch(std::bad_alloc)
-	{
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgColorMatrix(VGImage dst, VGImage src, const VGfloat * matrix)
-#else
-void RI_APIENTRY vgColorMatrix(VGImage dst, VGImage src, const VGfloat * matrix)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidImage(dst) || !context->isValidImage(src), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
-	Image* d = (Image*)dst;
-	Image* s = (Image*)src;
-	RI_IF_ERROR(eglvgIsInUse(d) || eglvgIsInUse(s), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(d->overlaps(s), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(!matrix || !isAligned(matrix,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	unsigned int channelMask = context->m_filterChannelMask & (VG_RED|VG_GREEN|VG_BLUE|VG_ALPHA);	//undefined bits are ignored
-
-	RIfloat m[20];
-	for(int i=0;i<20;i++)
-	{
-		m[i] = inputFloat(matrix[i]);
-	}
-	try
-	{
-		d->colorMatrix(*s, m, context->m_filterFormatLinear ? true : false, context->m_filterFormatPremultiplied ? true : false, channelMask);
-	}
-	catch(std::bad_alloc)
-	{
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgConvolve(VGImage dst, VGImage src, VGint kernelWidth, VGint kernelHeight, VGint shiftX, VGint shiftY, const VGshort * kernel, VGfloat scale, VGfloat bias, VGTilingMode tilingMode)
-#else
-void RI_APIENTRY vgConvolve(VGImage dst, VGImage src, VGint kernelWidth, VGint kernelHeight, VGint shiftX, VGint shiftY, const VGshort * kernel, VGfloat scale, VGfloat bias, VGTilingMode tilingMode)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidImage(dst) || !context->isValidImage(src), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
-	Image* d = (Image*)dst;
-	Image* s = (Image*)src;
-	RI_IF_ERROR(eglvgIsInUse(d) || eglvgIsInUse(s), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(d->overlaps(s), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(!kernel || !isAligned(kernel,2) || kernelWidth <= 0 || kernelHeight <= 0 || kernelWidth > RI_MAX_KERNEL_SIZE || kernelHeight > RI_MAX_KERNEL_SIZE, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(tilingMode < VG_TILE_FILL || tilingMode > VG_TILE_REFLECT, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	unsigned int channelMask = context->m_filterChannelMask & (VG_RED|VG_GREEN|VG_BLUE|VG_ALPHA);	//undefined bits are ignored
-	try
-	{
-		d->convolve(*s, kernelWidth, kernelHeight, shiftX, shiftY, (const RIint16*)kernel, inputFloat(scale), inputFloat(bias), tilingMode, context->m_tileFillColor, context->m_filterFormatLinear ? true : false, context->m_filterFormatPremultiplied ? true : false, channelMask);
-	}
-	catch(std::bad_alloc)
-	{
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgSeparableConvolve(VGImage dst, VGImage src, VGint kernelWidth, VGint kernelHeight, VGint shiftX, VGint shiftY, const VGshort * kernelX, const VGshort * kernelY, VGfloat scale, VGfloat bias, VGTilingMode tilingMode)
-#else
-void RI_APIENTRY vgSeparableConvolve(VGImage dst, VGImage src, VGint kernelWidth, VGint kernelHeight, VGint shiftX, VGint shiftY, const VGshort * kernelX, const VGshort * kernelY, VGfloat scale, VGfloat bias, VGTilingMode tilingMode)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidImage(dst) || !context->isValidImage(src), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
-	Image* d = (Image*)dst;
-	Image* s = (Image*)src;
-	RI_IF_ERROR(eglvgIsInUse(d) || eglvgIsInUse(s), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(d->overlaps(s), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(!kernelX || !kernelY || !isAligned(kernelX,2) || !isAligned(kernelY,2) || kernelWidth <= 0 || kernelHeight <= 0 || kernelWidth > RI_MAX_SEPARABLE_KERNEL_SIZE || kernelHeight > RI_MAX_SEPARABLE_KERNEL_SIZE, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(tilingMode < VG_TILE_FILL || tilingMode > VG_TILE_REFLECT, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	unsigned int channelMask = context->m_filterChannelMask & (VG_RED|VG_GREEN|VG_BLUE|VG_ALPHA);	//undefined bits are ignored
-	try
-	{
-		d->separableConvolve(*s, kernelWidth, kernelHeight, shiftX, shiftY, (const RIint16*)kernelX, (const RIint16*)kernelY,
-										 inputFloat(scale), inputFloat(bias), tilingMode, context->m_tileFillColor, context->m_filterFormatLinear ? true : false,
-										 context->m_filterFormatPremultiplied ? true : false, channelMask);
-	}
-	catch(std::bad_alloc)
-	{
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgGaussianBlur(VGImage dst, VGImage src, VGfloat stdDeviationX, VGfloat stdDeviationY, VGTilingMode tilingMode)
-#else
-void RI_APIENTRY vgGaussianBlur(VGImage dst, VGImage src, VGfloat stdDeviationX, VGfloat stdDeviationY, VGTilingMode tilingMode)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidImage(dst) || !context->isValidImage(src), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
-	Image* d = (Image*)dst;
-	Image* s = (Image*)src;
-	RI_IF_ERROR(eglvgIsInUse(d) || eglvgIsInUse(s), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(d->overlaps(s), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	RIfloat sx = inputFloat(stdDeviationX);
-	RIfloat sy = inputFloat(stdDeviationY);
-	RI_IF_ERROR(sx <= 0.0f || sy <= 0.0f || sx > (RIfloat)RI_MAX_GAUSSIAN_STD_DEVIATION || sy > (RIfloat)RI_MAX_GAUSSIAN_STD_DEVIATION, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(tilingMode < VG_TILE_FILL || tilingMode > VG_TILE_REFLECT, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	unsigned int channelMask = context->m_filterChannelMask & (VG_RED|VG_GREEN|VG_BLUE|VG_ALPHA);	//undefined bits are ignored
-	try
-	{
-		d->gaussianBlur(*s, sx, sy, tilingMode, context->m_tileFillColor, context->m_filterFormatLinear ? true : false,
-						context->m_filterFormatPremultiplied ? true : false, channelMask);
-	}
-	catch(std::bad_alloc)
-	{
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgLookup(VGImage dst, VGImage src, const VGubyte * redLUT, const VGubyte * greenLUT, const VGubyte * blueLUT, const VGubyte * alphaLUT, VGboolean outputLinear, VGboolean outputPremultiplied)
-#else
-void RI_APIENTRY vgLookup(VGImage dst, VGImage src, const VGubyte * redLUT, const VGubyte * greenLUT, const VGubyte * blueLUT, const VGubyte * alphaLUT, VGboolean outputLinear, VGboolean outputPremultiplied)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidImage(dst) || !context->isValidImage(src), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
-	Image* d = (Image*)dst;
-	Image* s = (Image*)src;
-	RI_IF_ERROR(eglvgIsInUse(d) || eglvgIsInUse(s), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(d->overlaps(s), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(!redLUT || !greenLUT || !blueLUT || !alphaLUT, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	unsigned int channelMask = context->m_filterChannelMask & (VG_RED|VG_GREEN|VG_BLUE|VG_ALPHA);	//undefined bits are ignored
-	try
-	{
-		d->lookup(*s, (const RIuint8*)redLUT, (const RIuint8*)greenLUT, (const RIuint8*)blueLUT, (const RIuint8*)alphaLUT,
-				  outputLinear ? true : false, outputPremultiplied ? true : false, context->m_filterFormatLinear ? true : false,
-				  context->m_filterFormatPremultiplied ? true : false, channelMask);
-	}
-	catch(std::bad_alloc)
-	{
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgLookupSingle(VGImage dst, VGImage src, const VGuint * lookupTable, VGImageChannel sourceChannel, VGboolean outputLinear, VGboolean outputPremultiplied)
-#else
-void RI_APIENTRY vgLookupSingle(VGImage dst, VGImage src, const VGuint * lookupTable, VGImageChannel sourceChannel, VGboolean outputLinear, VGboolean outputPremultiplied)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidImage(dst) || !context->isValidImage(src), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
-	Image* d = (Image*)dst;
-	Image* s = (Image*)src;
-	RI_IF_ERROR(eglvgIsInUse(d) || eglvgIsInUse(s), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(d->overlaps(s), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(!lookupTable || !isAligned(lookupTable,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	const Color::Descriptor& desc = s->getDescriptor();
-	RI_ASSERT(Color::isValidDescriptor(desc));
-	//give an error if src is in rgb format and the source channel is not valid
-	RI_IF_ERROR((!desc.isLuminance() && !desc.isAlphaOnly()) && (sourceChannel != VG_RED && sourceChannel != VG_GREEN && sourceChannel != VG_BLUE && sourceChannel != VG_ALPHA), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	unsigned int channelMask = context->m_filterChannelMask & (VG_RED|VG_GREEN|VG_BLUE|VG_ALPHA);	//undefined bits are ignored
-	try
-	{
-		d->lookupSingle(*s, (const RIuint32*)lookupTable, sourceChannel, outputLinear ? true : false, outputPremultiplied ? true : false,
-						context->m_filterFormatLinear ? true : false, context->m_filterFormatPremultiplied ? true : false, channelMask);
-	}
-	catch(std::bad_alloc)
-	{
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-VGHardwareQueryResult RI_APIENTRY do_vgHardwareQuery(VGHardwareQueryType key, VGint setting)
-#else
-VGHardwareQueryResult RI_APIENTRY vgHardwareQuery(VGHardwareQueryType key, VGint setting)
-#endif
-{
-	RI_GET_CONTEXT(VG_HARDWARE_UNACCELERATED);
-	RI_IF_ERROR(key != VG_IMAGE_FORMAT_QUERY && key != VG_PATH_DATATYPE_QUERY, VG_ILLEGAL_ARGUMENT_ERROR, VG_HARDWARE_UNACCELERATED);
-	RI_IF_ERROR(key == VG_IMAGE_FORMAT_QUERY && !isValidImageFormat(setting), VG_ILLEGAL_ARGUMENT_ERROR, VG_HARDWARE_UNACCELERATED);
-	RI_IF_ERROR(key == VG_PATH_DATATYPE_QUERY && (setting < VG_PATH_DATATYPE_S_8 || setting > VG_PATH_DATATYPE_F), VG_ILLEGAL_ARGUMENT_ERROR, VG_HARDWARE_UNACCELERATED);
-	RI_RETURN(VG_HARDWARE_UNACCELERATED);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-RI_APIENTRY const VGubyte * do_vgGetString(VGStringID name)
-#else
-RI_APIENTRY const VGubyte * vgGetString(VGStringID name)
-#endif
-{
-	static const VGubyte vendor[] = "Khronos Group";
-	static const VGubyte renderer[] = {"OpenVG 1.1 Reference Implementation May 13 2008"};
-	static const VGubyte version[] = "1.1";
-	static const VGubyte extensions[] = "";
-	const VGubyte* r = NULL;
-	RI_GET_CONTEXT(NULL);
-	switch(name)
-	{
-	case VG_VENDOR:
-		r = vendor;
-		break;
-	case VG_RENDERER:
-		r = renderer;
-		break;
-	case VG_VERSION:
-		r = version;
-		break;
-	case VG_EXTENSIONS:
-		r = extensions;
-		break;
-	default:
-		break;
-	}
-	RI_RETURN(r);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-VGFont RI_APIENTRY do_vgCreateFont(VGint glyphCapacityHint)
-#else
-VGFont RI_APIENTRY vgCreateFont(VGint glyphCapacityHint)
-#endif
-{
-	RI_GET_CONTEXT(VG_INVALID_HANDLE);
-	RI_IF_ERROR(glyphCapacityHint < 0, VG_ILLEGAL_ARGUMENT_ERROR, VG_INVALID_HANDLE);
-
-	Font* font = NULL;
-	try
-	{
-		font = RI_NEW(Font, (glyphCapacityHint));	//throws bad_alloc
-		RI_ASSERT(font);
-		context->m_fontManager->addResource(font, context);	//throws bad_alloc
-		RI_RETURN((VGFont)font);
-	}
-	catch(std::bad_alloc)
-	{
-		RI_DELETE(font);
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-		RI_RETURN(VG_INVALID_HANDLE);
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgDestroyFont(VGFont font)
-#else
-void RI_APIENTRY vgDestroyFont(VGFont font)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidFont(font), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid font handle
-
-	context->m_fontManager->removeResource((Font*)font);
-
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgSetGlyphToPath(VGFont font, VGuint glyphIndex, VGPath path, VGboolean isHinted, const VGfloat glyphOrigin[2], const VGfloat escapement[2])
-#else
-void RI_APIENTRY vgSetGlyphToPath(VGFont font, VGuint glyphIndex, VGPath path, VGboolean isHinted, const VGfloat glyphOrigin[2], const VGfloat escapement[2])
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidFont(font), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid font handle
-	RI_IF_ERROR(path != VG_INVALID_HANDLE && !context->isValidPath(path), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid path handle
-    RI_IF_ERROR(!glyphOrigin || !escapement || !isAligned(glyphOrigin,sizeof(VGfloat)) || !isAligned(escapement,sizeof(VGfloat)), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	Font* f = (Font*)font;
-
-	try
-	{
-        f->setGlyphToPath(glyphIndex, path, isHinted ? true : false, Vector2(inputFloat(glyphOrigin[0]), inputFloat(glyphOrigin[1])), Vector2(inputFloat(escapement[0]), inputFloat(escapement[1])));
-	}
-	catch(std::bad_alloc)
-	{
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgSetGlyphToImage(VGFont font, VGuint glyphIndex, VGImage image, const VGfloat glyphOrigin[2], const VGfloat escapement[2])
-#else
-void RI_APIENTRY vgSetGlyphToImage(VGFont font, VGuint glyphIndex, VGImage image, const VGfloat glyphOrigin[2], const VGfloat escapement[2])
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidFont(font), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid font handle
-    if(image != VG_INVALID_HANDLE)
-    {
-        RI_IF_ERROR(!context->isValidImage(image), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid image handle
-        RI_IF_ERROR(eglvgIsInUse((Image*)image), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL); //image in use
-    }
-    RI_IF_ERROR(!glyphOrigin || !escapement || !isAligned(glyphOrigin,sizeof(VGfloat)) || !isAligned(escapement,sizeof(VGfloat)), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	Font* f = (Font*)font;
-
-	try
-	{
-        f->setGlyphToImage(glyphIndex, image, Vector2(inputFloat(glyphOrigin[0]), inputFloat(glyphOrigin[1])), Vector2(inputFloat(escapement[0]), inputFloat(escapement[1])));
-	}
-	catch(std::bad_alloc)
-	{
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-	}
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgClearGlyph(VGFont font, VGuint glyphIndex)
-#else
-void RI_APIENTRY vgClearGlyph(VGFont font, VGuint glyphIndex)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidFont(font), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid font handle
-	Font* f = (Font*)font;
-    Font::Glyph* g = f->findGlyph(glyphIndex);
-    RI_IF_ERROR(!g, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);   //glyphIndex not defined
-
-	f->clearGlyph(g);
-
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgDrawGlyph(VGFont font, VGuint glyphIndex, VGbitfield paintModes, VGboolean allowAutoHinting)
-#else
-void RI_APIENTRY vgDrawGlyph(VGFont font, VGuint glyphIndex, VGbitfield paintModes, VGboolean allowAutoHinting)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidFont(font), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid font handle
-	RI_IF_ERROR(paintModes & ~(VG_FILL_PATH | VG_STROKE_PATH), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);	//invalid paint mode
-	Font* f = (Font*)font;
-    Font::Glyph* g = f->findGlyph(glyphIndex);
-    RI_IF_ERROR(!g, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);   //glyphIndex not defined
-    RI_UNREF(allowAutoHinting); //RI doesn't implement autohinting
-
-	try
-	{
-        if(paintModes)
-        {
-            Matrix3x3 userToSurfaceMatrix = context->m_glyphUserToSurface;
-            Vector2 t = context->m_glyphOrigin - g->m_origin;
-            Matrix3x3 n(1, 0, t.x,
-                        0, 1, t.y,
-                        0, 0, 1 );
-            userToSurfaceMatrix *= n;
-            userToSurfaceMatrix[2].set(0,0,1);		//force affinity
-
-            bool ret = true;
-            if(g->m_image != VG_INVALID_HANDLE)
-                ret = drawImage(context, g->m_image, userToSurfaceMatrix);
-            else if(g->m_path != VG_INVALID_HANDLE)
-                ret = drawPath(context, g->m_path, userToSurfaceMatrix, paintModes);
-            if(!ret)
-            {
-                RI_RETURN(RI_NO_RETVAL);
-            }
-        }
-
-        context->m_glyphOrigin += g->m_escapement;
-        context->m_inputGlyphOrigin = context->m_glyphOrigin;
-	}
-	catch(std::bad_alloc)
-	{
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-	}
-
-	RI_RETURN(RI_NO_RETVAL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-void RI_APIENTRY do_vgDrawGlyphs(VGFont font, VGint glyphCount, const VGuint *glyphIndices, const VGfloat *adjustments_x, const VGfloat *adjustments_y, VGbitfield paintModes, VGboolean allowAutoHinting)
-#else
-void RI_APIENTRY vgDrawGlyphs(VGFont font, VGint glyphCount, const VGuint *glyphIndices, const VGfloat *adjustments_x, const VGfloat *adjustments_y, VGbitfield paintModes, VGboolean allowAutoHinting)
-#endif
-{
-	RI_GET_CONTEXT(RI_NO_RETVAL);
-	RI_IF_ERROR(!context->isValidFont(font), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);	//invalid font handle
-	RI_IF_ERROR(!glyphIndices || !isAligned(glyphIndices, sizeof(VGuint)) || glyphCount <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR((adjustments_x && !isAligned(adjustments_x, sizeof(VGfloat))) || (adjustments_y && !isAligned(adjustments_y, sizeof(VGfloat))), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
-	RI_IF_ERROR(paintModes & ~(VG_FILL_PATH | VG_STROKE_PATH), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);	//invalid paint mode
-	Font* f = (Font*)font;
-	for(int i=0;i<glyphCount;i++)
-	{
-        Font::Glyph* g = f->findGlyph(glyphIndices[i]);
-        RI_IF_ERROR(!g, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);   //glyphIndex not defined
-    }
-    RI_UNREF(allowAutoHinting); //RI doesn't implement autohinting
-
-	try
-	{
-		for(int i=0;i<glyphCount;i++)
-		{
-            Font::Glyph* g = f->findGlyph(glyphIndices[i]);
-
-            if(paintModes)
-            {
-                Matrix3x3 userToSurfaceMatrix = context->m_glyphUserToSurface;
-                Vector2 t = context->m_glyphOrigin - g->m_origin;
-                Matrix3x3 n(1, 0, t.x,
-                            0, 1, t.y,
-                            0, 0, 1 );
-                userToSurfaceMatrix *= n;
-                userToSurfaceMatrix[2].set(0,0,1);		//force affinity
-
-                bool ret = true;
-                if(g->m_image != VG_INVALID_HANDLE)
-                    ret = drawImage(context, g->m_image, userToSurfaceMatrix);
-                else if(g->m_path != VG_INVALID_HANDLE)
-                    ret = drawPath(context, g->m_path, userToSurfaceMatrix, paintModes);
-                if(!ret)
-                {
-                    RI_RETURN(RI_NO_RETVAL);
-                }
-            }
-
-            context->m_glyphOrigin += g->m_escapement;
-            if(adjustments_x)
-                context->m_glyphOrigin.x += inputFloat(adjustments_x[i]);
-            if(adjustments_y)
-                context->m_glyphOrigin.y += inputFloat(adjustments_y[i]);
-            context->m_inputGlyphOrigin = context->m_glyphOrigin;
-		}
-	}
-	catch(std::bad_alloc)
-	{
-		context->setError(VG_OUT_OF_MEMORY_ERROR);
-	}
-
-	RI_RETURN(RI_NO_RETVAL);
-}
-
--- a/egl/sfopenvg/riArray.h	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,211 +0,0 @@
-#ifndef __RIARRAY_H
-#define __RIARRAY_H
-
-/*------------------------------------------------------------------------
- *
- * OpenVG 1.1 Reference Implementation
- * -----------------------------------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief	Array class.
- * \note	
- *//*-------------------------------------------------------------------*/
-
-#ifndef __RIDEFS_H
-#include "riDefs.h"
-#endif
-
-#include <string.h>	//for memcpy
-
-namespace OpenVGRI
-{
-
-//=======================================================================
-
-/*-------------------------------------------------------------------*//*!
-* \brief	An array class similar to std::vector.
-* \param	
-* \return	
-* \note		Follows std::vector's naming convention (except resizeAndReallocate).
-*//*-------------------------------------------------------------------*/
-
-template <class Item> class Array
-{
-public:
-	Array() : m_array(NULL), m_size(0), m_allocated(0) {}	//throws bad_alloc
-	~Array()
-	{
-		RI_DELETE_ARRAY(m_array);
-	}
-
-	void		swap(Array& s)
-	{
-		Item* tarray = m_array;
-		m_array = s.m_array;
-		s.m_array = tarray;
-
-		int tsize = m_size;
-		m_size = s.m_size;
-		s.m_size = tsize;
-
-		int tallocated = m_allocated;
-		m_allocated = s.m_allocated;
-		s.m_allocated = tallocated;
-	}
-
-	//if more room is needed, reallocate, otherwise return
-	void		reserve( int items )	//throws bad_alloc
-	{
-		RI_ASSERT( items >= 0 );
-		if( items <= m_allocated )
-			return;	//if there is room already, return
-
-		RI_ASSERT( items > m_allocated );
-
-		Item* newa = RI_NEW_ARRAY(Item, items);	//throws bad_alloc if runs out of memory
-		for(int i=0;i<m_size;i++)
-			newa[i] = m_array[i];
-		RI_DELETE_ARRAY(m_array);
-		m_array = newa;
-		m_allocated = items;
-		//doesn't change size
-	}
-
-	//reserve and change size
-	void		resize( int items )	//throws bad_alloc
-	{
-		reserve( items );	//throws bad_alloc if runs out of memory
-		m_size = items;
-	}
-
-	//resize and allocate exactly the correct amount of memory
-	void		resizeAndReallocate( int items )	//throws bad_alloc
-	{
-		RI_ASSERT( items >= 0 );
-		if( items == m_allocated )
-		{
-			m_size = items;
-			return;
-		}
-
-		if( items == 0 )
-		{
-			RI_DELETE_ARRAY(m_array);
-			m_size = 0;
-			m_allocated = 0;
-			return;
-		}
-
-		Item* newa = RI_NEW_ARRAY(Item, items);	//throws bad_alloc if runs out of memory
-		int copySize = (m_size < items) ? m_size : items;	//min(m_size,items)
-		for(int i=0;i<copySize;i++)
-			newa[i] = m_array[i];
-		RI_DELETE_ARRAY(m_array);
-		m_array = newa;
-		m_allocated = items;
-		m_size = items;		//changes also size
-	}
-	void		clear()
-	{
-		m_size = 0;
-	}
-
-    //sort array (needs operator< defined for Item. Define it with < for increasing order and > for decreasing.)
-	void		sort()
-	{
-		if(m_size <= 1)
-			return;
-		quicksort(0, m_size - 1);
-	}
-
-    //remove the first occurrence of an item from the array
-    bool        remove(const Item& item)
-    {
-        int i=0;
-        for(;i<m_size;i++)
-        {
-            if(m_array[i] == item)
-                break;
-        }
-        if(i >= m_size)
-            return false;   //not found
-        for(;i<m_size-1;i++)
-        {
-            m_array[i] = m_array[i+1];
-        }
-        m_size--;
-        return true;
-    }
-
-	RI_INLINE void			push_back( const Item& item )	//throws bad_alloc
-	{
-		if( m_size >= m_allocated )
-			reserve( (!m_allocated) ? 8 : m_allocated * 2 );	//by default, reserve 8. throws bad_alloc if runs out of memory
-		m_array[m_size++] = item;
-	}
-	RI_INLINE int			size() const				{ return m_size; }
-	RI_INLINE Item&			operator[](int i)			{ RI_ASSERT(i >= 0 && i < m_size); return m_array[i]; }
-	RI_INLINE const Item&	operator[](int i) const		{ RI_ASSERT(i >= 0 && i < m_size); return m_array[i]; }
-
-private:
-	Array(const Array& s);				//!< Not allowed.
-	void operator=(const Array& s);		//!< Not allowed.
-
-	void quicksort(int left, int right)
-	{
-		int i = left, j = right;
-		Item x = m_array[(left+right)>>1];
-
-		do
-		{    
-			while (m_array[i] < x)
-				i++;
-			while (x < m_array[j])
-				j--;
-			if (i<=j)
-			{
-				Item tmp = m_array[i];
-				m_array[i] = m_array[j];
-				m_array[j] = tmp;
-				i++;
-				j--;
-			}
-		} while (i<=j);
-
-		if(left < j) quicksort(left, j);
-		if(i < right) quicksort(i, right);
-	}
-
-
-	Item*		m_array;
-	int			m_size;
-	int			m_allocated;
-};
-
-//=======================================================================
-
-}	//namespace OpenVGRI
-
-#endif /* __RIARRAY_H */
--- a/egl/sfopenvg/riContext.cpp	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,329 +0,0 @@
-/*------------------------------------------------------------------------
- *
- * OpenVG 1.1 Reference Implementation
- * -----------------------------------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief	Implementation of VGContext functions.
- * \note	
- *//*-------------------------------------------------------------------*/
-
-#include "riContext.h"
-
-namespace OpenVGRI
-{
-
-/*-------------------------------------------------------------------*//*!
-* \brief	VGContext constructor.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-VGContext::VGContext(VGContext* shareContext) :
-	// Mode settings
-	m_matrixMode(VG_MATRIX_PATH_USER_TO_SURFACE),
-	m_fillRule(VG_EVEN_ODD),
-	m_imageQuality(VG_IMAGE_QUALITY_FASTER),
-	m_renderingQuality(VG_RENDERING_QUALITY_BETTER),
-	m_blendMode(VG_BLEND_SRC_OVER),
-	m_imageMode(VG_DRAW_IMAGE_NORMAL),
-
-	// Scissor rectangles
-	m_scissor(),
-		
-	// Stroke parameters
-	m_strokeLineWidth(1.0f),
-	m_inputStrokeLineWidth(1.0f),
-	m_strokeCapStyle(VG_CAP_BUTT),
-	m_strokeJoinStyle(VG_JOIN_MITER),
-	m_strokeMiterLimit(4.0f),
-	m_inputStrokeMiterLimit(4.0f),
-	m_strokeDashPattern(),
-	m_inputStrokeDashPattern(),
-	m_strokeDashPhase(0.0f),
-	m_inputStrokeDashPhase(0.0f),
-	m_strokeDashPhaseReset(VG_FALSE),
-		
-	// Edge fill color for vgConvolve and pattern paint
-	m_tileFillColor(0,0,0,0, Color::sRGBA),
-	m_inputTileFillColor(0,0,0,0, Color::sRGBA),
-		
-	// Color for vgClear
-	m_clearColor(0,0,0,0, Color::sRGBA),
-	m_inputClearColor(0,0,0,0, Color::sRGBA),
-
-    m_glyphOrigin(0.0f, 0.0f),
-    m_inputGlyphOrigin(0.0f, 0.0f),
-
-	m_masking(VG_FALSE),
-	m_scissoring(VG_FALSE),
-
-	m_pixelLayout(VG_PIXEL_LAYOUT_UNKNOWN),
-
-	m_filterFormatLinear(VG_FALSE),
-	m_filterFormatPremultiplied(VG_FALSE),
-	m_filterChannelMask(VG_RED|VG_GREEN|VG_BLUE|VG_ALPHA),
-
-	// Matrices
-	m_pathUserToSurface(),
-	m_imageUserToSurface(),
-	m_glyphUserToSurface(),
-	m_fillPaintToUser(),
-	m_strokePaintToUser(),
-
-	m_fillPaint(VG_INVALID_HANDLE),
-	m_strokePaint(VG_INVALID_HANDLE),
-
-    m_colorTransform(VG_FALSE),
-    m_colorTransformValues(),
-    m_inputColorTransformValues(),
-
-	m_error(VG_NO_ERROR),
-
-	m_imageManager(NULL),
-	m_pathManager(NULL),
-	m_paintManager(NULL),
-	m_fontManager(NULL),
-	m_maskLayerManager(NULL),
-
-    m_eglDrawable(NULL)
-{
-	if(shareContext)
-	{
-		m_imageManager = shareContext->m_imageManager;
-		m_pathManager = shareContext->m_pathManager;
-		m_paintManager = shareContext->m_paintManager;
-		m_fontManager = shareContext->m_fontManager;
-		m_maskLayerManager = shareContext->m_maskLayerManager;
-	}
-	else
-	{
-		try
-		{
-			m_imageManager = RI_NEW(OpenVGRI::ResourceManager<Image>, ());	//throws bad_alloc
-			m_pathManager = RI_NEW(OpenVGRI::ResourceManager<Path>, ());	//throws bad_alloc
-			m_paintManager = RI_NEW(OpenVGRI::ResourceManager<Paint>, ());	//throws bad_alloc
-			m_fontManager = RI_NEW(OpenVGRI::ResourceManager<Font>, ());	//throws bad_alloc
-			m_maskLayerManager = RI_NEW(OpenVGRI::ResourceManager<Surface>, ());	//throws bad_alloc
-		}
-		catch(std::bad_alloc)
-		{
-			RI_DELETE(m_imageManager);
-			RI_DELETE(m_pathManager);
-			RI_DELETE(m_paintManager);
-			RI_DELETE(m_fontManager);
-			RI_DELETE(m_maskLayerManager);
-			throw;
-		}
-	}
-	RI_ASSERT(m_imageManager);
-	RI_ASSERT(m_pathManager);
-	RI_ASSERT(m_paintManager);
-	RI_ASSERT(m_fontManager);
-	RI_ASSERT(m_maskLayerManager);
-	m_imageManager->addReference();
-	m_pathManager->addReference();
-	m_paintManager->addReference();
-	m_fontManager->addReference();
-	m_maskLayerManager->addReference();
-
-    m_inputColorTransformValues[0] = 1.0f;
-    m_inputColorTransformValues[1] = 1.0f;
-    m_inputColorTransformValues[2] = 1.0f;
-    m_inputColorTransformValues[3] = 1.0f;
-    m_inputColorTransformValues[4] = 0.0f;
-    m_inputColorTransformValues[5] = 0.0f;
-    m_inputColorTransformValues[6] = 0.0f;
-    m_inputColorTransformValues[7] = 0.0f;
-    m_colorTransformValues[0] = 1.0f;
-    m_colorTransformValues[1] = 1.0f;
-    m_colorTransformValues[2] = 1.0f;
-    m_colorTransformValues[3] = 1.0f;
-    m_colorTransformValues[4] = 0.0f;
-    m_colorTransformValues[5] = 0.0f;
-    m_colorTransformValues[6] = 0.0f;
-    m_colorTransformValues[7] = 0.0f;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	VGContext destructor.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-VGContext::~VGContext()
-{
-	releasePaint(VG_FILL_PATH | VG_STROKE_PATH);
-    setDefaultDrawable(NULL);
-
-	//destroy own images, paths and paints
-	while(Image* i = m_imageManager->getFirstResource(this))
-		m_imageManager->removeResource(i);
-	while(Path* p = m_pathManager->getFirstResource(this))
-		m_pathManager->removeResource(p);
-	while(Paint* t = m_paintManager->getFirstResource(this))
-		m_paintManager->removeResource(t);
-	while(Font* t = m_fontManager->getFirstResource(this))
-		m_fontManager->removeResource(t);
-	while(Surface* t = m_maskLayerManager->getFirstResource(this))
-		m_maskLayerManager->removeResource(t);
-
-	//decrease the reference count of resource managers
-	if(!m_imageManager->removeReference())
-		RI_DELETE(m_imageManager);
-	if(!m_pathManager->removeReference())
-		RI_DELETE(m_pathManager);
-	if(!m_paintManager->removeReference())
-		RI_DELETE(m_paintManager);
-	if(!m_fontManager->removeReference())
-		RI_DELETE(m_fontManager);
-	if(!m_maskLayerManager->removeReference())
-		RI_DELETE(m_maskLayerManager);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Sets new default drawable.
-* \param	drawable New drawable or NULL when context is unbound
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void VGContext::setDefaultDrawable(Drawable* drawable)
-{
-	if(m_eglDrawable)
-	{
-		if(!m_eglDrawable->removeReference())
-			RI_DELETE(m_eglDrawable);
-	}
-	m_eglDrawable = drawable;
-	if(m_eglDrawable)
-	{
-		m_eglDrawable->addReference();
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Returns true if the given image is generated through any
-*			context that is shared with this one.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-bool VGContext::isValidImage(VGImage image)
-{
-	return m_imageManager->isValid((Image*)image);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Returns true if the given path is generated through any
-*			context that is shared with this one.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-bool VGContext::isValidPath(VGPath path)
-{
-	return m_pathManager->isValid((Path*)path);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Returns true if the given paint is generated through any
-*			context that is shared with this one.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-bool VGContext::isValidPaint(VGPaint paint)
-{
-	return m_paintManager->isValid((Paint*)paint);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Returns true if the given font is generated through any
-*			context that is shared with this one.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-bool VGContext::isValidFont(VGFont font)
-{
-	return m_fontManager->isValid((Font*)font);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Returns true if the given mask layer is generated through any
-*			context that is shared with this one.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-bool VGContext::isValidMaskLayer(VGMaskLayer layer)
-{
-	return m_maskLayerManager->isValid((Surface*)layer);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Releases the given paint objects of the context.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void VGContext::releasePaint(VGbitfield paintModes)
-{
-	if(paintModes & VG_FILL_PATH)
-	{
-		//release previous paint
-		Paint* prev = (Paint*)m_fillPaint;
-		if(prev)
-		{
-			if(!prev->removeReference())
-				RI_DELETE(prev);
-		}
-		m_fillPaint = VG_INVALID_HANDLE;
-	}
-	if(paintModes & VG_STROKE_PATH)
-	{
-		//release previous paint
-		Paint* prev = (Paint*)m_strokePaint;
-		if(prev)
-		{
-			if(!prev->removeReference())
-				RI_DELETE(prev);
-		}
-		m_strokePaint = VG_INVALID_HANDLE;
-	}
-}
-
-//==============================================================================================
-
-}	//namespace OpenVGRI
--- a/egl/sfopenvg/riContext.h	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,277 +0,0 @@
-#ifndef __RICONTEXT_H
-#define __RICONTEXT_H
-
-/*------------------------------------------------------------------------
- *
- * OpenVG 1.1 Reference Implementation
- * -----------------------------------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief	VGContext class. Used for storing OpenVG state.
- * \note	
- *//*-------------------------------------------------------------------*/
-
-#ifndef OPENVG_H
-#include "openvg.h"
-#endif
-
-#ifndef __RIDEFS_H
-#include "riDefs.h"
-#endif
-
-#ifndef __RIMATH_H
-#include "riMath.h"
-#endif
-
-#ifndef __RIIMAGE_H
-#include "riImage.h"
-#endif
-
-#ifndef __RIPATH_H
-#include "riPath.h"
-#endif
-
-#ifndef __RIFONT_H
-#include "riFont.h"
-#endif
-
-#ifndef __RIARRAY_H
-#include "riArray.h"
-#endif
-
-//==============================================================================================
-
-namespace OpenVGRI
-{
-
-class VGContext;
-
-/*-------------------------------------------------------------------*//*!
-* \brief	A list of resources (Images, Paths, or Paints) shared by a
-*			set of contexts.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-template <class Resource> class ResourceManager
-{
-public:
-	ResourceManager() :
-		m_referenceCount(0),
-		m_resources()
-	{
-	}
-
-	~ResourceManager()
-	{
-		RI_ASSERT(m_referenceCount == 0);
-		RI_ASSERT(m_resources.size() == 0);
-	}
-
-	void			addReference()
-	{
-		m_referenceCount++;
-	}
-
-	int				removeReference()
-	{
-		m_referenceCount--;
-		RI_ASSERT(m_referenceCount >= 0);
-		return m_referenceCount;
-	}
-
-	void			addResource(Resource* resource, VGContext* context)
-	{
-		Entry r;
-		r.resource = resource;
-		r.context = context;
-		m_resources.push_back(r);	//throws bad_alloc
-		resource->addReference();
-	}
-
-	void			removeResource(Resource* resource)
-	{
-		if(!resource->removeReference())
-			RI_DELETE(resource);
-
-		int i=0;
-		bool found = false;
-		for(;i<m_resources.size();i++)
-		{
-			if(m_resources[i].resource == resource)
-			{
-				found = true;
-				break;
-			}
-		}
-		RI_ASSERT(found);
-
-		for(;i<m_resources.size()-1;i++)
-		{
-			m_resources[i] = m_resources[i+1];
-		}
-		m_resources.resize(m_resources.size()-1);
-	}
-
-	bool			isValid(Resource* resource)
-	{
-		for(int i=0;i<m_resources.size();i++)
-		{
-			if(m_resources[i].resource == resource)
-				return true;
-		}
-		return false;
-	}
-
-	Resource*		getFirstResource(VGContext* context)
-	{
-		for(int i=0;i<m_resources.size();i++)
-		{
-			if(m_resources[i].context == context)
-				return m_resources[i].resource;
-		}
-		return NULL;
-	}
-
-private:
-	ResourceManager(const ResourceManager&);
-	ResourceManager operator=(const ResourceManager&);
-
-	struct Entry
-	{
-		Resource*	resource;
-		VGContext*	context;
-	};
-
-	int				m_referenceCount;
-	Array<Entry>	m_resources;
-};
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-class VGContext
-{
-public:
-	VGContext(VGContext* shareContext);	//throws bad_alloc
-	~VGContext();
-
-    void            setDefaultDrawable(Drawable* drawable); //called from EGL
-    Drawable*       getCurrentDrawable()        { return m_eglDrawable; }
-
-	bool			isValidImage(VGImage image);
-	bool			isValidPath(VGPath path);
-	bool			isValidPaint(VGPaint paint);
-	bool			isValidFont(VGFont font);
-	bool			isValidMaskLayer(VGMaskLayer layer);
-
-	void			releasePaint(VGbitfield paintModes);
-
-	void			setError(VGErrorCode error)		{ if(m_error == VG_NO_ERROR) m_error = error; }
-
-	// Mode settings
-	VGMatrixMode					m_matrixMode;
-	VGFillRule						m_fillRule;
-	VGImageQuality					m_imageQuality;
-	VGRenderingQuality				m_renderingQuality;
-	VGBlendMode						m_blendMode;
-	VGImageMode						m_imageMode;
-	
-	// Scissor rectangles
-	Array<Rectangle>				m_scissor;
-
-	// Stroke parameters
-	RIfloat							m_strokeLineWidth;
-	RIfloat							m_inputStrokeLineWidth;
-	VGCapStyle						m_strokeCapStyle;
-	VGJoinStyle						m_strokeJoinStyle;
-	RIfloat							m_strokeMiterLimit;
-	RIfloat							m_inputStrokeMiterLimit;
-	Array<RIfloat>					m_strokeDashPattern;
-	Array<RIfloat>					m_inputStrokeDashPattern;
-	RIfloat							m_strokeDashPhase;
-	RIfloat							m_inputStrokeDashPhase;
-	VGboolean						m_strokeDashPhaseReset;
-
-	// Edge fill color for vgConvolve and pattern paint
-	Color							m_tileFillColor;
-	Color							m_inputTileFillColor;
-
-	// Color for vgClear
-	Color							m_clearColor;
-	Color							m_inputClearColor;
-
-    Vector2                         m_glyphOrigin;
-    Vector2                         m_inputGlyphOrigin;
-
-	VGboolean						m_masking;
-	VGboolean						m_scissoring;
-
-	VGPixelLayout					m_pixelLayout;
-
-	VGboolean						m_filterFormatLinear;
-	VGboolean						m_filterFormatPremultiplied;
-	VGbitfield						m_filterChannelMask;
-
-	// Matrices
-	Matrix3x3						m_pathUserToSurface;
-	Matrix3x3						m_imageUserToSurface;
-	Matrix3x3						m_glyphUserToSurface;
-	Matrix3x3						m_fillPaintToUser;
-	Matrix3x3						m_strokePaintToUser;
-
-	VGPaint							m_fillPaint;
-	VGPaint							m_strokePaint;
-
-    VGboolean                       m_colorTransform;
-    RIfloat                         m_colorTransformValues[8];
-    RIfloat                         m_inputColorTransformValues[8];
-
-	VGErrorCode						m_error;
-
-	ResourceManager<Image>*			m_imageManager;
-	ResourceManager<Path>*			m_pathManager;
-	ResourceManager<Paint>*			m_paintManager;
-	ResourceManager<Font>*			m_fontManager;
-	ResourceManager<Surface>*		m_maskLayerManager;
-private:
-	Drawable*                       m_eglDrawable;
-
-	VGContext(const VGContext&);			//!< Not allowed.
-	void operator=(const VGContext&);		//!< Not allowed.
-};
-
-//==============================================================================================
-
-}	//namespace OpenVGRI
-
-//==============================================================================================
-
-#endif /* __RICONTEXT_H */
--- a/egl/sfopenvg/riDefs.h	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,155 +0,0 @@
-#ifndef __RIDEFS_H
-#define __RIDEFS_H
-
-/*------------------------------------------------------------------------
- *
- * OpenVG 1.1 Reference Implementation
- * -----------------------------------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief	Platform- and compiler-dependent type and macro definitions.
- * \note	
- *//*-------------------------------------------------------------------*/
-
-#include <float.h>
-#include <math.h>
-#include <assert.h>
-#include <new>	//for bad_alloc
-#include <egl.h>
-
-#ifdef USE_NEW_ELEAVE
-//this is sometimes useful to include so that alloc fails ca be caught.
-//I have found intermittent OOM (-4) problems when rasterizing the tiger image
-#include <e32std.h>
-#endif
-
-namespace OpenVGRI
-{
-
-//make for-clause scope c++ standard compliant on msvc
-#if defined (_MSC_VER)
-#	if !defined (for)
-		__forceinline bool getFalse (void) { return false; }
-#		define for if(getFalse()); else for
-#	endif // for
-
-#pragma warning(disable:4710)	//disable function not inlined warning
-#pragma warning(disable:4714)	//disable function not __forceinlined warning
-#endif  // _MSC_VER
-
-//=======================================================================
-
-typedef int				RIint32;
-typedef unsigned int	RIuint32;
-typedef short			RIint16;
-typedef unsigned short	RIuint16;
-typedef signed char		RIint8;
-typedef unsigned char	RIuint8;
-typedef float			RIfloat32;
-//TODO add compile-time assertions to guarantee the sizes
-
-#if defined (_MSC_VER) // MSVC WIN32
-#	define RI_INLINE __forceinline
-#elif defined __APPLE__ || defined (__GNUC__) || defined (__GCC32__) || (__SYMBIAN32__)
-#	define RI_INLINE inline
-#endif
-
-/*!< Unsigned int that can hold a pointer to any type */
-/*!< Signed int that can hold a pointer to any type */
-#if defined (_MSC_VER) && (_MSC_VER >= 1300)
-typedef uintptr_t		RIuintptr;
-typedef intptr_t		RIintptr;
-#else
-typedef unsigned long   RIuintptr;
-typedef signed long     RIintptr;
-#endif
-
-#define RI_UINT32_MAX (0xffffffffu)
-#define RI_INT32_MAX  (0x7fffffff)
-#define RI_INT32_MIN  (-0x7fffffff-1)
-
-/* maximum mantissa is 23 */
-#define RI_MANTISSA_BITS 23
-
-/* maximum exponent is 8 */
-#define RI_EXPONENT_BITS 8
-
-typedef union
-{
-	RIfloat32	f;
-	RIuint32	i;
-} RIfloatInt;
-
-RI_INLINE float	getFloatMax()
-{
-	RIfloatInt v;
-	v.i = (((1<<(RI_EXPONENT_BITS-1))-1+127) << 23) | (((1<<RI_MANTISSA_BITS)-1) << (23-RI_MANTISSA_BITS));
-	return v.f;
-}
-#define RI_FLOAT_MAX  getFloatMax()
-
-#define RI_MAX_IMAGE_WIDTH				16384
-#define RI_MAX_IMAGE_HEIGHT				16384
-#define RI_MAX_IMAGE_PIXELS				(RI_MAX_IMAGE_WIDTH*RI_MAX_IMAGE_HEIGHT)
-#define RI_MAX_IMAGE_BYTES				(4*RI_MAX_IMAGE_WIDTH*RI_MAX_IMAGE_HEIGHT)
-#define RI_MAX_DASH_COUNT				256
-#define RI_MAX_COLOR_RAMP_STOPS			256
-#define RI_MAX_KERNEL_SIZE				256
-#define RI_MAX_SEPARABLE_KERNEL_SIZE	256
-#define RI_MAX_GAUSSIAN_STD_DEVIATION	16.0f
-#define RI_MAX_SCISSOR_RECTANGLES		256
-#define RI_MAX_EDGES					262144
-#define RI_MAX_SAMPLES					32
-#define RI_NUM_TESSELLATED_SEGMENTS		256
-
-#define RI_DEBUG
-
-#ifdef RI_DEBUG
-#	define RI_ASSERT assert
-#else
-#	define RI_ASSERT
-#endif
-
-#define RI_UNREF(X) ((void)(X))
-#define RI_APIENTRY EXPORT_C
-
-#ifdef USE_NEW_ELEAVE
-#define RI_NEW(TYPE, PARAMS)           (new(ELeave) TYPE PARAMS)
-#define RI_NEW_ARRAY(TYPE, ITEMS)      (new(ELeave) TYPE[ITEMS])
-#else
-#define RI_NEW(TYPE, PARAMS)           (new TYPE PARAMS)
-#define RI_NEW_ARRAY(TYPE, ITEMS)      (new TYPE[ITEMS])
-#endif
-#define RI_DELETE(PARAMS)              (delete (PARAMS))
-#define RI_DELETE_ARRAY(PARAMS)        (delete[] (PARAMS))
-
-bool			isValidImageFormat(int format);
-bool      isValidImageFormat(EGLNativePixmapType f);
-
-//=======================================================================
-
-}	//namespace OpenVGRI
-
-#endif /* __RIDEFS_H */
--- a/egl/sfopenvg/riFont.cpp	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,203 +0,0 @@
-/*------------------------------------------------------------------------
- *
- * OpenVG 1.1 Reference Implementation
- * -----------------------------------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief	Implementation of Font class.
- * \note	
- *//*-------------------------------------------------------------------*/
-
-#include "riFont.h"
-
-//==============================================================================================
-
-namespace OpenVGRI
-{
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Font constructor.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Font::Font(int capacityHint) :
-	m_referenceCount(0),
-	m_glyphs()
-{
-	RI_ASSERT(capacityHint >= 0);
-	m_glyphs.reserve(capacityHint);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Font destructor.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Font::~Font()
-{
-	//remove references to paths and images
-	for(int i=0;i<m_glyphs.size();i++)
-		clearGlyph(&m_glyphs[i]);
-	RI_ASSERT(m_referenceCount == 0);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Find a glyph based on glyphIndex.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Font::Glyph* Font::findGlyph(unsigned int index)
-{
-    for(int i=0;i<m_glyphs.size();i++)
-    {
-        if(m_glyphs[i].m_state != Glyph::GLYPH_UNINITIALIZED && m_glyphs[i].m_index == index)
-            return &m_glyphs[i];
-    }
-    return NULL;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Find a free glyph or allocate a new one.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Font::Glyph* Font::newGlyph()
-{
-    for(int i=0;i<m_glyphs.size();i++)
-    {
-        if(m_glyphs[i].m_state == Glyph::GLYPH_UNINITIALIZED)
-            return &m_glyphs[i];
-    }
-    m_glyphs.resize(m_glyphs.size()+1);
-    return &m_glyphs[m_glyphs.size()-1];
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Free glyph and its data.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Font::clearGlyph(Glyph* g)
-{
-    RI_ASSERT(g);
-	if(g->m_path != VG_INVALID_HANDLE)
-	{
-		Path* p = (Path*)g->m_path;
-		if(!p->removeReference())
-			RI_DELETE(p);
-	}
-	if(g->m_image != VG_INVALID_HANDLE)
-	{
-		Image* p = (Image*)g->m_image;
-		p->removeInUse();
-		if(!p->removeReference())
-			RI_DELETE(p);
-	}
-	Glyph a;
-	*g = a;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Font::setGlyphToPath(unsigned int index, VGPath path, bool isHinted, const Vector2& origin, const Vector2& escapement)
-{
-    Glyph* g = findGlyph(index);
-    if(g)
-    {   //glyph exists, replace
-        clearGlyph(g);
-    }
-    else
-    {   //glyph doesn't exist, allocate a new one
-        g = newGlyph();
-    }
-
-    g->m_index = index;
-    g->m_state = Glyph::GLYPH_PATH;
-	g->m_path = path;
-    g->m_image = VG_INVALID_HANDLE;
-	g->m_isHinted = isHinted;
-	g->m_origin = origin;
-	g->m_escapement = escapement;
-
-    if(path != VG_INVALID_HANDLE)
-    {
-        Path* p = (Path*)path;
-        p->addReference();
-    }
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Font::setGlyphToImage(unsigned int index, VGImage image, const Vector2& origin, const Vector2& escapement)
-{
-    Glyph* g = findGlyph(index);
-    if(g)
-    {   //glyph exists, replace
-        clearGlyph(g);
-    }
-    else
-    {   //glyph doesn't exist, allocate a new one
-        g = newGlyph();
-    }
-
-    g->m_index = index;
-    g->m_state = Glyph::GLYPH_IMAGE;
-	g->m_path = VG_INVALID_HANDLE;
-    g->m_image = image;
-	g->m_isHinted = false;
-	g->m_origin = origin;
-	g->m_escapement = escapement;
-
-    if(image != VG_INVALID_HANDLE)
-    {
-        Image* p = (Image*)image;
-        p->addReference();
-        p->addInUse();
-    }
-}
-
-//=======================================================================
-
-}	//namespace OpenVGRI
--- a/egl/sfopenvg/riFont.h	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,116 +0,0 @@
-#ifndef __RIFONT_H
-#define __RIFONT_H
-
-/*------------------------------------------------------------------------
- *
- * OpenVG 1.1 Reference Implementation
- * -----------------------------------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief	VGContext class. Used for storing OpenVG state.
- * \note	
- *//*-------------------------------------------------------------------*/
-
-#ifndef _OPENVG_H
-#include "openvg.h"
-#endif
-
-#ifndef __RIMATH_H
-#include "riMath.h"
-#endif
-
-#ifndef __RIARRAY_H
-#include "riArray.h"
-#endif
-
-#ifndef __RIPATH_H
-#include "riPath.h"
-#endif
-
-#ifndef __RIIMAGE_H
-#include "riImage.h"
-#endif
-
-//==============================================================================================
-
-namespace OpenVGRI
-{
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Storage and operations for VGFont.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-class Font
-{
-public:
-	struct Glyph
-	{
-        enum State
-        {
-            GLYPH_UNINITIALIZED     = 0,
-            GLYPH_PATH              = 1,
-            GLYPH_IMAGE             = 2
-        };
-		Glyph()				{ m_state = GLYPH_UNINITIALIZED; m_path = m_image = VG_INVALID_HANDLE; m_isHinted = false; m_origin.set(0.0f, 0.0f); m_escapement.set(0.0f, 0.0f); }
-        unsigned int m_index;
-        State        m_state;
-		VGPath		 m_path;
-		VGImage		 m_image;
-		bool		 m_isHinted;
-		Vector2		 m_origin;
-		Vector2		 m_escapement;
-	};
-
-	Font(int capacityHint);	//throws bad_alloc
-	~Font();
-
-	int				getNumGlyphs() const					{ int n=0; for(int i=0;i<m_glyphs.size();i++) { if(m_glyphs[i].m_state != Glyph::GLYPH_UNINITIALIZED) n++; } return n; }
-	void			addReference()							{ m_referenceCount++; }
-	int				removeReference()						{ m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
-
-	void			setGlyphToPath(unsigned int index, VGPath path, bool isHinted, const Vector2& origin, const Vector2& escapement);    //throws bad_alloc
-	void			setGlyphToImage(unsigned int index, VGImage image, const Vector2& origin, const Vector2& escapement);    //throws bad_alloc
-    Glyph*          findGlyph(unsigned int index);
-    void            clearGlyph(Glyph* g);
-private:
-	Font(const Font&);						//!< Not allowed.
-	void operator=(const Font&);			//!< Not allowed.
-
-    Glyph*          newGlyph();    //throws bad_alloc
-
-	int				m_referenceCount;
-	Array<Glyph>	m_glyphs;
-};
-
-//=======================================================================
-
-}	//namespace OpenVGRI
-
-//=======================================================================
-
-#endif /* __RIFONT_H */
--- a/egl/sfopenvg/riImage.cpp	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2673 +0,0 @@
-/*------------------------------------------------------------------------
- *
- * OpenVG 1.1 Reference Implementation
- * -----------------------------------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief	Implementation of Color and Image functions.
- * \note	
- *//*-------------------------------------------------------------------*/
-
-#include "riImage.h"
-#include "riRasterizer.h"
-//==============================================================================================
-
-namespace OpenVGRI
-{
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Converts from numBits into a shifted mask
-* \param	
-* \return	
-* \note
-*//*-------------------------------------------------------------------*/
-	
-static unsigned int bitsToMask(unsigned int bits, unsigned int shift)
-{
-	return ((1<<bits)-1) << shift;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Converts from color (RIfloat) to an int with 1.0f mapped to the
-*			given maximum with round-to-nearest semantics.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-	
-static unsigned int colorToInt(RIfloat c, int maxc)
-{
-	return RI_INT_MIN(RI_INT_MAX((int)floor(c * (RIfloat)maxc + 0.5f), 0), maxc);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Converts from int to color (RIfloat) with the given maximum
-*			mapped to 1.0f.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static RI_INLINE RIfloat intToColor(unsigned int i, unsigned int maxi)
-{
-	return (RIfloat)(i & maxi) / (RIfloat)maxi;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Converts from packed integer in a given format to a Color.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Color::unpack(unsigned int inputData, const Color::Descriptor& inputDesc)
-{
-	int rb = inputDesc.redBits;
-	int gb = inputDesc.greenBits;
-	int bb = inputDesc.blueBits;
-	int ab = inputDesc.alphaBits;
-	int lb = inputDesc.luminanceBits;
-	int rs = inputDesc.redShift;
-	int gs = inputDesc.greenShift;
-	int bs = inputDesc.blueShift;
-	int as = inputDesc.alphaShift;
-	int ls = inputDesc.luminanceShift;
-
-	m_format = inputDesc.internalFormat;
-	if(lb)
-	{	//luminance
-		r = g = b = intToColor(inputData >> ls, (1<<lb)-1);
-		a = 1.0f;
-	}
-	else
-	{	//rgba
-		r = rb ? intToColor(inputData >> rs, (1<<rb)-1) : (RIfloat)1.0f;
-		g = gb ? intToColor(inputData >> gs, (1<<gb)-1) : (RIfloat)1.0f;
-		b = bb ? intToColor(inputData >> bs, (1<<bb)-1) : (RIfloat)1.0f;
-		a = ab ? intToColor(inputData >> as, (1<<ab)-1) : (RIfloat)1.0f;
-
-		if(isPremultiplied())
-		{	//clamp premultiplied color to alpha to enforce consistency
-			r = RI_MIN(r, a);
-			g = RI_MIN(g, a);
-			b = RI_MIN(b, a);
-		}
-	}
-
-    assertConsistency();
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Converts from Color to a packed integer in a given format.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-unsigned int Color::pack(const Color::Descriptor& outputDesc) const
-{
-    assertConsistency();
-
-	int rb = outputDesc.redBits;
-	int gb = outputDesc.greenBits;
-	int bb = outputDesc.blueBits;
-	int ab = outputDesc.alphaBits;
-	int lb = outputDesc.luminanceBits;
-	int rs = outputDesc.redShift;
-	int gs = outputDesc.greenShift;
-	int bs = outputDesc.blueShift;
-	int as = outputDesc.alphaShift;
-	int ls = outputDesc.luminanceShift;
-
-	if(lb)
-	{	//luminance
-		RI_ASSERT(isLuminance());
-		return colorToInt(r, (1<<lb)-1) << ls;
-	}
-	else
-	{	//rgb
-		RI_ASSERT(!isLuminance());
-		unsigned int cr = rb ? colorToInt(r, (1<<rb)-1) : 0;
-		unsigned int cg = gb ? colorToInt(g, (1<<gb)-1) : 0;
-		unsigned int cb = bb ? colorToInt(b, (1<<bb)-1) : 0;
-		unsigned int ca = ab ? colorToInt(a, (1<<ab)-1) : 0;
-		return (cr << rs) | (cg << gs) | (cb << bs) | (ca << as);
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Converts from the current internal format to another.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static RIfloat gamma(RIfloat c)
-{
-	if( c <= 0.00304f )
-		c *= 12.92f;
-	else
-		c = 1.0556f * (RIfloat)pow(c, 1.0f/2.4f) - 0.0556f;
-	return c;
-}
-
-static RIfloat invgamma(RIfloat c)
-{
-	if( c <= 0.03928f )
-		c /= 12.92f;
-	else
-		c = (RIfloat)pow((c + 0.0556f)/1.0556f, 2.4f);
-	return c;
-}
-
-static RIfloat lRGBtoL(RIfloat r, RIfloat g, RIfloat b)
-{
-	return 0.2126f*r + 0.7152f*g + 0.0722f*b;
-}
-
-void Color::convert(InternalFormat outputFormat)
-{
-    assertConsistency();
-
-	if( m_format == outputFormat )
-		return;
-
-	if(isPremultiplied())
-	{	//unpremultiply
-		RIfloat ooa = (a != 0.0f) ? 1.0f / a : (RIfloat)0.0f;
-		r *= ooa;
-		g *= ooa;
-		b *= ooa;
-	}
-
-	//From Section 3.4.2 of OpenVG spec
-	//1: sRGB = gamma(lRGB)
-	//2: lRGB = invgamma(sRGB)
-	//3: lL = 0.2126 lR + 0.7152 lG + 0.0722 lB
-	//4: lRGB = lL
-	//5: sL = gamma(lL)
-	//6: lL = invgamma(sL)
-	//7: sRGB = sL
-
-	//Source/Dest lRGB sRGB   lL   sL 
-	//lRGB          -    1    3    3,5 
-	//sRGB          2    -    2,3  2,3,5 
-	//lL            4    4,1  -    5 
-	//sL            7,2  7    6    - 
-
-	const unsigned int shift = 3;
-	unsigned int conversion = (m_format & (NONLINEAR | LUMINANCE)) | ((outputFormat & (NONLINEAR | LUMINANCE)) << shift);
-
-	switch(conversion)
-	{
-	case lRGBA | (sRGBA << shift): r = gamma(r); g = gamma(g); b = gamma(b); break;							//1
-	case lRGBA | (lLA << shift)  : r = g = b = lRGBtoL(r, g, b); break;										//3
-	case lRGBA | (sLA << shift)  : r = g = b = gamma(lRGBtoL(r, g, b)); break;								//3,5
-	case sRGBA | (lRGBA << shift): r = invgamma(r); g = invgamma(g); b = invgamma(b); break;				//2
-	case sRGBA | (lLA << shift)  : r = g = b = lRGBtoL(invgamma(r), invgamma(g), invgamma(b)); break;		//2,3
-	case sRGBA | (sLA << shift)  : r = g = b = gamma(lRGBtoL(invgamma(r), invgamma(g), invgamma(b))); break;//2,3,5
-	case lLA   | (lRGBA << shift): break;																	//4
-	case lLA   | (sRGBA << shift): r = g = b = gamma(r); break;												//4,1
-	case lLA   | (sLA << shift)  : r = g = b = gamma(r); break;												//5
-	case sLA   | (lRGBA << shift): r = g = b = invgamma(r); break;											//7,2
-	case sLA   | (sRGBA << shift): break;																	//7
-	case sLA   | (lLA << shift)  : r = g = b = invgamma(r); break;											//6
-	default: RI_ASSERT((m_format & (LUMINANCE | NONLINEAR)) == (outputFormat & (LUMINANCE | NONLINEAR))); break;	//nop
-	}
-
-	if(outputFormat & PREMULTIPLIED)
-	{	//premultiply
-		r *= a;
-		g *= a;
-		b *= a;
-	}
-	m_format = outputFormat;
-
-    assertConsistency();
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Creates a pixel format descriptor out of VGImageFormat
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Color::Descriptor Color::formatToDescriptor(VGImageFormat format)
-{
-	Descriptor desc;
-	memset(&desc, 0, sizeof(Descriptor));
-	RI_ASSERT(isValidImageFormat(format));
-
-	int baseFormat = (int)format & 15;
-	const int numBaseFormats = 15;
-	RI_ASSERT(baseFormat >= 0 && baseFormat < numBaseFormats);
-	int swizzleBits = ((int)format >> 6) & 3;
-
-	/* base formats
-	VG_sRGBX_8888                               =  0,
-	VG_sRGBA_8888                               =  1,
-	VG_sRGBA_8888_PRE                           =  2,
-	VG_sRGB_565                                 =  3,
-	VG_sRGBA_5551                               =  4,
-	VG_sRGBA_4444                               =  5,
-	VG_sL_8                                     =  6,
-	VG_lRGBX_8888                               =  7,
-	VG_lRGBA_8888                               =  8,
-	VG_lRGBA_8888_PRE                           =  9,
-	VG_lL_8                                     = 10,
-	VG_A_8                                      = 11,
-	VG_BW_1                                     = 12,
-	VG_A_1                                      = 13,
-	VG_A_4                                      = 14,
-	*/
-
-	static const int redBits[numBaseFormats] =       {8, 8, 8, 5, 5, 4, 0, 8, 8, 8, 0, 0, 0, 0, 0};
-	static const int greenBits[numBaseFormats] =     {8, 8, 8, 6, 5, 4, 0, 8, 8, 8, 0, 0, 0, 0, 0};
-	static const int blueBits[numBaseFormats] =      {8, 8, 8, 5, 5, 4, 0, 8, 8, 8, 0, 0, 0, 0, 0};
-	static const int alphaBits[numBaseFormats] =     {0, 8, 8, 0, 1, 4, 0, 0, 8, 8, 0, 8, 0, 1, 4};
-	static const int luminanceBits[numBaseFormats] = {0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 8, 0, 1, 0, 0};
-
-	static const int redShifts[4*numBaseFormats] = {24, 24, 24, 11, 11, 12, 0, 24, 24, 24, 0, 0, 0, 0, 0,	//RGBA
-													16, 16, 16, 11, 10, 8,  0, 16, 16, 16, 0, 0, 0, 0, 0,	//ARGB
-													8,  8,  8,  0,  1,  4,  0, 8,  8,  8,  0, 0, 0, 0, 0,	//BGRA
-													0,  0,  0,  0,  0,  0,  0, 0,  0,  0,  0, 0, 0, 0, 0};	//ABGR
-
-	static const int greenShifts[4*numBaseFormats] = {16, 16, 16, 5,  6,  8,  0, 16, 16, 16, 0, 0, 0, 0, 0,	//RGBA
-													  8,  8,  8,  5,  5,  4,  0, 8,  8,  8,  0, 0, 0, 0, 0,	//ARGB
-													  16, 16, 16, 5,  6,  8,  0, 16, 16, 16, 0, 0, 0, 0, 0,	//BGRA
-													  8,  8,  8,  5,  5,  4,  0, 8,  8,  8,  0, 0, 0, 0, 0};//ABGR
-
-	static const int blueShifts[4*numBaseFormats] =  {8,  8,  8,  0,  1,  4,  0, 8,  8,  8,  0, 0, 0, 0, 0,	//RGBA
-													  0,  0,  0,  0,  0,  0,  0, 0,  0,  0,  0, 0, 0, 0, 0,	//ARGB
-													  24, 24, 24, 11, 11, 12, 0, 24, 24, 24, 0, 0, 0, 0, 0,	//BGRA
-													  16, 16, 16, 11, 10, 8,  0, 16, 16, 16, 0, 0, 0, 0, 0};//ABGR
-
-	static const int alphaShifts[4*numBaseFormats] = {0,  0,  0,  0,  0,  0,  0, 0,  0,  0,  0, 0, 0, 0, 0,	//RGBA
-													  0,  24, 24, 0,  15, 12, 0, 0,  24, 24, 0, 0, 0, 0, 0,	//ARGB
-													  0,  0,  0,  0,  0,  0,  0, 0,  0,  0,  0, 0, 0, 0, 0,	//BGRA
-													  0,  24, 24, 0,  15, 12, 0, 0,  24, 24, 0, 0, 0, 0, 0};//ABGR
-
-	static const int bpps[numBaseFormats] = {32, 32, 32, 16, 16, 16, 8, 32, 32, 32, 8, 8, 1, 1, 4};
-
-	static const InternalFormat internalFormats[numBaseFormats] = {sRGBA, sRGBA, sRGBA_PRE, sRGBA, sRGBA, sRGBA, sLA, lRGBA, lRGBA, lRGBA_PRE, lLA, lRGBA, lLA, lRGBA, lRGBA};
-
-	desc.redBits = redBits[baseFormat];
-	desc.greenBits = greenBits[baseFormat];
-	desc.blueBits = blueBits[baseFormat];
-	desc.alphaBits = alphaBits[baseFormat];
-	desc.luminanceBits = luminanceBits[baseFormat];
-
-	desc.redShift = redShifts[swizzleBits * numBaseFormats + baseFormat];
-	desc.greenShift = greenShifts[swizzleBits * numBaseFormats + baseFormat];
-	desc.blueShift = blueShifts[swizzleBits * numBaseFormats + baseFormat];
-	desc.alphaShift = alphaShifts[swizzleBits * numBaseFormats + baseFormat];
-	desc.luminanceShift = 0;	//always zero
-
-	desc.format = format;
-	desc.bitsPerPixel = bpps[baseFormat];
-	desc.internalFormat = internalFormats[baseFormat];
-
-	return desc;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Checks if the pixel format descriptor is valid (i.e. all the
-*           values are supported by the RI)
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-bool Color::isValidDescriptor(const Color::Descriptor& desc)
-{
-	//A valid descriptor has 1, 2, 4, 8, 16, or 32 bits per pixel, and either luminance or rgba channels, but not both.
-	//Any of the rgba channels can be missing, and not all bits need to be used. Maximum channel bit depth is 8.
-	int rb = desc.redBits;
-	int gb = desc.greenBits;
-	int bb = desc.blueBits;
-	int ab = desc.alphaBits;
-	int lb = desc.luminanceBits;
-	int rs = desc.redShift;
-	int gs = desc.greenShift;
-	int bs = desc.blueShift;
-	int as = desc.alphaShift;
-	int ls = desc.luminanceShift;
-	int bpp = desc.bitsPerPixel;
-
-	int rgbaBits = rb + gb + bb + ab;
-	if(rb < 0 || rb > 8 || rs < 0 || rs + rb > bpp || !(rb || !rs))
-		return false;	//invalid channel description
-	if(gb < 0 || gb > 8 || gs < 0 || gs + gb > bpp || !(gb || !gs))
-		return false;	//invalid channel description
-	if(bb < 0 || bb > 8 || bs < 0 || bs + bb > bpp || !(bb || !bs))
-		return false;	//invalid channel description
-	if(ab < 0 || ab > 8 || as < 0 || as + ab > bpp || !(ab || !as))
-		return false;	//invalid channel description
-	if(lb < 0 || lb > 8 || ls < 0 || ls + lb > bpp || !(lb || !ls))
-		return false;	//invalid channel description
-
-	if(rgbaBits && lb)
-		return false;	//can't have both rgba and luminance
-	if(!rgbaBits && !lb)
-		return false;	//must have either rgba or luminance
-	if(rgbaBits)
-	{	//rgba
-		if(rb+gb+bb == 0)
-		{	//alpha only
-			if(rs || gs || bs || as || ls)
-				return false;	//wrong shifts (even alpha shift must be zero)
-			if((ab != 1 && ab != 2  && ab != 4 && ab != 8) || bpp != ab)
-				return false;	//alpha size must be 1, 2, 4, or, 8, bpp must match
-		}
-		else
-		{	//rgba
-			if(rgbaBits > bpp)
-				return false;	//bpp must be greater than or equal to the sum of rgba bits
-			if(!(bpp == 32 || bpp == 16 || bpp == 8))
-				return false;	//only 1, 2, and 4 byte formats are supported for rgba
-			
-			unsigned int rm = bitsToMask((unsigned int)rb, (unsigned int)rs);
-			unsigned int gm = bitsToMask((unsigned int)gb, (unsigned int)gs);
-			unsigned int bm = bitsToMask((unsigned int)bb, (unsigned int)bs);
-			unsigned int am = bitsToMask((unsigned int)ab, (unsigned int)as);
-			if((rm & gm) || (rm & bm) || (rm & am) || (gm & bm) || (gm & am) || (bm & am))
-				return false;	//channels overlap
-		}
-	}
-	else
-	{	//luminance
-		if(rs || gs || bs || as || ls)
-			return false;	//wrong shifts (even luminance shift must be zero)
-		if(!(lb == 1 || lb == 8) || bpp != lb)
-			return false;	//luminance size must be either 1 or 8, bpp must match
-	}
-
-	if(desc.format != -1)
-	{
-		if(!isValidImageFormat(desc.format))
-			return false;	//invalid image format
-
-		Descriptor d = formatToDescriptor(desc.format);
-		if(d.redBits != rb || d.greenBits != gb || d.blueBits != bb || d.alphaBits != ab || d.luminanceBits != lb ||
-		   d.redShift != rs || d.greenShift != gs || d.blueShift != bs || d.alphaShift != as || d.luminanceShift != ls ||
-		   d.bitsPerPixel != bpp)
-		   return false;	//if the descriptor has a VGImageFormat, it must match the bits, shifts, and bpp
-	}
-
-	if((unsigned int)desc.internalFormat & ~(Color::PREMULTIPLIED | Color::NONLINEAR | Color::LUMINANCE))
-		return false;	//invalid internal format
-
-	return true;
-}
-
-//==============================================================================================
-
-
-
-
-//==============================================================================================
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Constructs a blank image.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Image::Image(const Color::Descriptor& desc, int width, int height, VGbitfield allowedQuality) :
-	m_desc(desc),
-	m_width(width),
-	m_height(height),
-	m_allowedQuality(allowedQuality),
-	m_inUse(0),
-	m_stride(0),
-	m_data(NULL),
-	m_referenceCount(0),
-	m_ownsData(true),
-	m_parent(NULL),
-    m_storageOffsetX(0),
-    m_storageOffsetY(0),
-	m_mipmapsValid(false),
-	m_mipmaps()
-{
-	RI_ASSERT(Color::isValidDescriptor(m_desc));
-	RI_ASSERT(width > 0 && height > 0);
-	
-	m_stride = (m_width*m_desc.bitsPerPixel+7)/8;
-	
-	m_data = RI_NEW_ARRAY(RIuint8, m_stride*m_height);	//throws bad_alloc
-	memset(m_data, 0, m_stride*m_height);	//clear image
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Constructs an image that uses an external array for its data
-*			storage.
-* \param	
-* \return	
-* \note		this is meant for internal use to make blitting easier
-*//*-------------------------------------------------------------------*/
-
-Image::Image(const Color::Descriptor& desc, int width, int height, int stride, RIuint8* data) :
-	m_desc(desc),
-	m_width(width),
-	m_height(height),
-	m_allowedQuality(0),
-	m_inUse(0),
-	m_stride(stride),
-	m_data(data),
-	m_referenceCount(0),
-	m_ownsData(false),
-	m_parent(NULL),
-    m_storageOffsetX(0),
-    m_storageOffsetY(0),
-	m_mipmapsValid(false),
-	m_mipmaps()
-{
-	RI_ASSERT(Color::isValidDescriptor(m_desc));
-	RI_ASSERT(width > 0 && height > 0);
-	RI_ASSERT(data);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Construcs a child image.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Image::Image(Image* parent, int x, int y, int width, int height) :
-	m_desc(Color::formatToDescriptor(VG_sRGBA_8888)),	//dummy initialization, will be overwritten below (can't read from parent->m_desc before knowing the pointer is valid)
-	m_width(width),
-	m_height(height),
-	m_allowedQuality(0),
-	m_inUse(0),
-	m_stride(0),
-	m_data(NULL),
-	m_referenceCount(0),
-	m_ownsData(false),
-	m_parent(parent),
-    m_storageOffsetX(0),
-    m_storageOffsetY(0),
-	m_mipmapsValid(false),
-	m_mipmaps()
-{
-	RI_ASSERT(parent);
-	RI_ASSERT(x >= 0 && y >= 0 && width > 0 && height > 0);
-	RI_ASSERT(RI_INT_ADDSATURATE(x,width) <= parent->m_width && RI_INT_ADDSATURATE(y,height) <= parent->m_height);	//child image must be contained in parent
-
-	m_desc = parent->m_desc;
-	RI_ASSERT(Color::isValidDescriptor(m_desc));
-	m_allowedQuality = parent->m_allowedQuality;
-	m_stride = parent->m_stride;
-	m_data = parent->m_data;
-    m_storageOffsetX = parent->m_storageOffsetX + x;
-    m_storageOffsetY = parent->m_storageOffsetY + y;
-
-	//increase the reference and use count of the parent
-	addInUse();
-	parent->addInUse();
-	parent->addReference();
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Image destructor.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Image::~Image()
-{
-	RI_ASSERT(m_referenceCount == 0);
-
-	if(m_parent)
-	{
-		//decrease the reference and use count of the parent
-		removeInUse();
-		m_parent->removeInUse();
-		if(!m_parent->removeReference())
-			RI_DELETE(m_parent);
-	}
-	RI_ASSERT(m_inUse == 0);
-
-	for(int i=0;i<m_mipmaps.size();i++)
-	{
-		if(!m_mipmaps[i]->removeReference())
-			RI_DELETE(m_mipmaps[i]);
-		else
-		{
-			RI_ASSERT(0);	//there can't be any other references to the mipmap levels
-		}
-	}
-	m_mipmaps.clear();
-
-	if(m_ownsData)
-	{
-		RI_ASSERT(!m_parent);		//can't have parent if owns the data
-		RI_DELETE_ARRAY(m_data);	//delete image data if we own it
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Returns true if the two images share pixels.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-bool Image::overlaps(const Image* src) const
-{
-	RI_ASSERT(src);
-
-	if(m_data != src->m_data)
-		return false;	//images don't share data
-
-	//check if the image storage regions overlap
-	Rectangle r(m_storageOffsetX, m_storageOffsetY, m_width, m_height);
-	r.intersect(Rectangle(src->m_storageOffsetX, src->m_storageOffsetY, src->m_width, src->m_height));
-	if(!r.width || !r.height)
-		return false;	//intersection is empty, images don't overlap	
-
-	return true;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Clears a rectangular portion of an image with the given clear color.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Image::clear(const Color& clearColor, int x, int y, int w, int h)
-{
-	RI_ASSERT(m_data);
-	RI_ASSERT(m_referenceCount > 0);
-
-	//intersect clear region with image bounds
-	Rectangle r(0,0,m_width,m_height);
-	r.intersect(Rectangle(x,y,w,h));
-	if(!r.width || !r.height)
-		return;		//intersection is empty or one of the rectangles is invalid
-
-	Color col = clearColor;
-	col.clamp();
-	col.convert(m_desc.internalFormat);
-
-	for(int j=r.y;j<r.y + r.height;j++)
-	{
-		for(int i=r.x;i<r.x + r.width;i++)
-		{
-			writePixel(i, j, col);
-		}
-	}
-
-	m_mipmapsValid = false;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Blits a source region to destination. Source and destination
-*			can overlap.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static RIfloat ditherChannel(RIfloat c, int bits, RIfloat m)
-{
-	RIfloat fc = c * (RIfloat)((1<<bits)-1);
-	RIfloat ic = (RIfloat)floor(fc);
-	if(fc - ic > m) ic += 1.0f;
-	return RI_MIN(ic / (RIfloat)((1<<bits)-1), 1.0f);
-}
-
-static void computeBlitRegion(int& sx, int& sy, int& dx, int& dy, int& w, int& h, int srcWidth, int srcHeight, int dstWidth, int dstHeight)
-{
-	RI_ASSERT(w > 0 && h > 0);
-	sx = RI_INT_MIN(RI_INT_MAX(sx, (int)(RI_INT32_MIN>>2)), (int)(RI_INT32_MAX>>2));
-	sy = RI_INT_MIN(RI_INT_MAX(sy, (int)(RI_INT32_MIN>>2)), (int)(RI_INT32_MAX>>2));
-	dx = RI_INT_MIN(RI_INT_MAX(dx, (int)(RI_INT32_MIN>>2)), (int)(RI_INT32_MAX>>2));
-	dy = RI_INT_MIN(RI_INT_MAX(dy, (int)(RI_INT32_MIN>>2)), (int)(RI_INT32_MAX>>2));
-	w = RI_INT_MIN(w, (int)(RI_INT32_MAX>>2));
-	h = RI_INT_MIN(h, (int)(RI_INT32_MAX>>2));
-	int srcsx = sx, srcex = sx + w, dstsx = dx, dstex = dx + w;
-	if(srcsx < 0)
-	{
-		dstsx -= srcsx;
-		srcsx = 0;
-	}
-	if(srcex > srcWidth)
-	{
-		dstex -= srcex - srcWidth;
-		srcex = srcWidth;
-	}
-	if(dstsx < 0)
-	{
-		srcsx -= dstsx;
-		dstsx = 0;
-	}
-	if(dstex > dstWidth)
-	{
-		srcex -= dstex - dstWidth;
-		dstex = dstWidth;
-	}
-	RI_ASSERT(srcsx >= 0 && dstsx >= 0 && srcex <= srcWidth && dstex <= dstWidth);
-	w = srcex - srcsx;
-	RI_ASSERT(w == dstex - dstsx);
-
-	int srcsy = sy, srcey = sy + h, dstsy = dy, dstey = dy + h;
-	if(srcsy < 0)
-	{
-		dstsy -= srcsy;
-		srcsy = 0;
-	}
-	if(srcey > srcHeight)
-	{
-		dstey -= srcey - srcHeight;
-		srcey = srcHeight;
-	}
-	if(dstsy < 0)
-	{
-		srcsy -= dstsy;
-		dstsy = 0;
-	}
-	if(dstey > dstHeight)
-	{
-		srcey -= dstey - dstHeight;
-		dstey = dstHeight;
-	}
-	RI_ASSERT(srcsy >= 0 && dstsy >= 0 && srcey <= srcHeight && dstey <= dstHeight);
-	h = srcey - srcsy;
-	RI_ASSERT(h == dstey - dstsy);
-	sx = srcsx;
-	sy = srcsy;
-	dx = dstsx;
-	dy = dstsy;
-}
-
-void Image::blit(const Image& src, int sx, int sy, int dx, int dy, int w, int h, bool dither)
-{
-	//img=>img: vgCopyImage
-	//img=>user: vgGetImageSubData
-	//user=>img: vgImageSubData
-	RI_ASSERT(src.m_data);	//source exists
-	RI_ASSERT(m_data);	//destination exists
-	RI_ASSERT(m_referenceCount > 0 && src.m_referenceCount > 0);
-
-	computeBlitRegion(sx, sy, dx, dy, w, h, src.m_width, src.m_height, m_width, m_height);
-	if(w <= 0 || h <= 0)
-		return;	//zero area
-
-	Array<Color> tmp;
-	tmp.resize(w*h);	//throws bad_alloc
-
-	//copy source region to tmp
-	for(int j=0;j<h;j++)
-	{
-		for(int i=0;i<w;i++)
-		{
-			Color c = src.readPixel(sx + i, sy + j);
-			c.convert(m_desc.internalFormat);
-			tmp[j*w+i] = c;
-		}
-	}
-
-	int rbits = m_desc.redBits, gbits = m_desc.greenBits, bbits = m_desc.blueBits, abits = m_desc.alphaBits;
-	if(m_desc.isLuminance())
-	{
-		rbits = gbits = bbits = m_desc.luminanceBits;
-		abits = 0;
-	}
-
-	//write tmp to destination region
-	for(int j=0;j<h;j++)
-	{
-		for(int i=0;i<w;i++)
-		{
-			Color col = tmp[j*w+i];
-
-			if(dither)
-			{
-				static const int matrix[16] = {
-					0,  8,  2,  10,
-					12, 4,  14, 6,
-					3,  11, 1,  9,
-					15, 7,  13, 5};
-				int x = i & 3;
-				int y = j & 3;
-				RIfloat m = matrix[y*4+x] / 16.0f;
-
-				if(rbits) col.r = ditherChannel(col.r, rbits, m);
-				if(gbits) col.g = ditherChannel(col.g, gbits, m);
-				if(bbits) col.b = ditherChannel(col.b, bbits, m);
-				if(abits) col.a = ditherChannel(col.a, abits, m);
-			}
-
-			writePixel(dx + i, dy + j, col);
-		}
-	}
-	m_mipmapsValid = false;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Converts from multisampled format to display format.
-* \param	
-* \return	
-* \note
-*//*-------------------------------------------------------------------*/
-
-void Image::blit(const Surface* src, int sx, int sy, int dx, int dy, int w, int h)
-{
-	//fb=>img: vgGetPixels
-	//fb=>user: vgReadPixels
-	RI_ASSERT(!src->isInUse(this));
-
-	computeBlitRegion(sx, sy, dx, dy, w, h, src->getWidth(), src->getHeight(), m_width, m_height);
-	if(w <= 0 || h <= 0)
-		return;	//zero area
-
-	for(int y=0;y<h;y++)
-	{
-		for(int x=0;x<w;x++)
-		{
-			Color r = src->FSAAResolve(sx + x, sy + y);
-			r.convert(getDescriptor().internalFormat);
-			writePixel(dx + x, dy + y, r);
-		}
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Returns the color at pixel (x,y).
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Color Image::readPixel(int x, int y) const
-{
-	RI_ASSERT(m_data);
-	RI_ASSERT(x >= 0 && x < m_width);
-	RI_ASSERT(y >= 0 && y < m_height);
-	RI_ASSERT(m_referenceCount > 0);
-    x += m_storageOffsetX;
-    y += m_storageOffsetY;
-
-	unsigned int p = 0;
-	RIuint8* scanline = m_data + y * m_stride;
-	switch(m_desc.bitsPerPixel)
-	{
-	case 32:
-	{
-		RIuint32* s = (((RIuint32*)scanline) + x);
-		p = (unsigned int)*s;
-		break;
-	}
-
-	case 16:
-	{
-		RIuint16* s = ((RIuint16*)scanline) + x;
-		p = (unsigned int)*s;
-		break;
-	}
-
-    case 8:
-	{
-		RIuint8* s = ((RIuint8*)scanline) + x;
-		p = (unsigned int)*s;
-		break;
-	}
-
-    case 4:
-	{
-		RIuint8* s = ((RIuint8*)scanline) + (x>>1);
-		p = (unsigned int)(*s >> ((x&1)<<2)) & 0xf;
-		break;
-	}
-
-    case 2:
-	{
-		RIuint8* s = ((RIuint8*)scanline) + (x>>2);
-		p = (unsigned int)(*s >> ((x&3)<<1)) & 0x3;
-		break;
-	}
-
-    default:
-	{
-		RI_ASSERT(m_desc.bitsPerPixel == 1);
-		RIuint8* s = ((RIuint8*)scanline) + (x>>3);
-		p = (unsigned int)(*s >> (x&7)) & 0x1;
-		break;
-	}
-	}
-	Color c;
-	c.unpack(p, m_desc);
-	return c;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Writes the color to pixel (x,y). Internal color formats must
-*			match.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Image::writePixel(int x, int y, const Color& c)
-{
-	RI_ASSERT(m_data);
-	RI_ASSERT(x >= 0 && x < m_width);
-	RI_ASSERT(y >= 0 && y < m_height);
-	RI_ASSERT(m_referenceCount > 0);
-	RI_ASSERT(c.getInternalFormat() == m_desc.internalFormat);
-    x += m_storageOffsetX;
-    y += m_storageOffsetY;
-
-	unsigned int p = c.pack(m_desc);
-	RIuint8* scanline = m_data + y * m_stride;
-	switch(m_desc.bitsPerPixel)
-	{
-	case 32:
-	{
-		RIuint32* s = ((RIuint32*)scanline) + x;
-		*s = (RIuint32)p;
-		break;
-	}
-
-	case 16:
-	{
-		RIuint16* s = ((RIuint16*)scanline) + x;
-		*s = (RIuint16)p;
-		break;
-	}
-
-	case 8:
-	{
-		RIuint8* s = ((RIuint8*)scanline) + x;
-		*s = (RIuint8)p;
-		break;
-	}
-    case 4:
-	{
-		RIuint8* s = ((RIuint8*)scanline) + (x>>1);
-        *s = (RIuint8)((p << ((x&1)<<2)) | ((unsigned int)*s & ~(0xf << ((x&1)<<2))));
-		break;
-	}
-
-    case 2:
-	{
-		RIuint8* s = ((RIuint8*)scanline) + (x>>2);
-        *s = (RIuint8)((p << ((x&3)<<1)) | ((unsigned int)*s & ~(0x3 << ((x&3)<<1))));
-		break;
-	}
-
-    default:
-	{
-		RI_ASSERT(m_desc.bitsPerPixel == 1);
-		RIuint8* s = ((RIuint8*)scanline) + (x>>3);
-        *s = (RIuint8)((p << (x&7)) | ((unsigned int)*s & ~(0x1 << (x&7))));
-		break;
-	}
-	}
-	m_mipmapsValid = false;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Writes a filtered color to destination surface
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Image::writeFilteredPixel(int i, int j, const Color& color, VGbitfield channelMask)
-{
-	//section 3.4.4: before color space conversion, premultiplied colors are
-	//clamped to alpha, and the color is converted to nonpremultiplied format
-	//section 11.2: how to deal with channel mask
-	//step 1
-	Color f = color;
-	f.clamp();			//vgColorMatrix and vgLookups can produce colors that exceed alpha or [0,1] range
-
-	//step 2: color space conversion
-	f.convert((Color::InternalFormat)(m_desc.internalFormat & (Color::NONLINEAR | Color::LUMINANCE)));
-
-	//step 3: read the destination color and convert it to nonpremultiplied
-	Color d = readPixel(i,j);
-	d.unpremultiply();
-	RI_ASSERT(d.getInternalFormat() == f.getInternalFormat());
-
-	//step 4: replace the destination channels specified by the channelMask (channelmask is ignored for luminance formats)
-    if(!m_desc.isLuminance())
-    {   //rgba format => use channelmask
-        if(channelMask & VG_RED)
-            d.r = f.r;
-        if(channelMask & VG_GREEN)
-            d.g = f.g;
-        if(channelMask & VG_BLUE)
-            d.b = f.b;
-        if(channelMask & VG_ALPHA)
-            d.a = f.a;
-    }
-    else d = f;
-
-	//step 5: if destination is premultiplied, convert to premultiplied format
-	if(m_desc.isPremultiplied())
-		d.premultiply();
-	//write the color to destination
-	writePixel(i,j,d);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Reads the pixel (x,y) and converts it into an alpha mask value.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-RIfloat Image::readMaskPixel(int x, int y) const
-{
-	RI_ASSERT(m_data);
-	RI_ASSERT(x >= 0 && x < m_width);
-	RI_ASSERT(y >= 0 && y < m_height);
-	RI_ASSERT(m_referenceCount > 0);
-
-	Color c = readPixel(x,y);
-	if(m_desc.isLuminance())
-	{
-		return c.r;
-	}
-	else
-	{	//rgba
-		if(m_desc.alphaBits)
-			return c.a;
-		return c.r;
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Writes the alpha mask to pixel (x,y).
-* \param	
-* \return	
-* \note		Overwrites color.
-*//*-------------------------------------------------------------------*/
-
-void Image::writeMaskPixel(int x, int y, RIfloat m)
-{
-	RI_ASSERT(m_data);
-	RI_ASSERT(x >= 0 && x < m_width);
-	RI_ASSERT(y >= 0 && y < m_height);
-	RI_ASSERT(m_referenceCount > 0);
-
-    //if luminance or no alpha, red channel will be used, otherwise alpha channel will be used
-    writePixel(x, y, Color(m,m,m,m,m_desc.internalFormat));
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Reads a texel (u,v) at the given mipmap level. Tiling modes and
-*			color space conversion are applied. Outputs color in premultiplied
-*			format.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Color Image::readTexel(int u, int v, int level, VGTilingMode tilingMode, const Color& tileFillColor) const
-{
-	const Image* image = this;
-	if( level > 0 )
-	{
-		RI_ASSERT(level <= m_mipmaps.size());
-		image = m_mipmaps[level-1];
-	}
-	RI_ASSERT(image);
-
-	Color p;
-	if(tilingMode == VG_TILE_FILL)
-	{
-		if(u < 0 || v < 0 || u >= image->m_width || v >= image->m_height)
-			p = tileFillColor;
-		else
-			p = image->readPixel(u, v);
-	}
-	else if(tilingMode == VG_TILE_PAD)
-	{
-		u = RI_INT_MIN(RI_INT_MAX(u,0),image->m_width-1);
-		v = RI_INT_MIN(RI_INT_MAX(v,0),image->m_height-1);
-		p = image->readPixel(u, v);
-	}
-	else if(tilingMode == VG_TILE_REPEAT)
-	{
-		u = RI_INT_MOD(u, image->m_width);
-		v = RI_INT_MOD(v, image->m_height);
-		p = image->readPixel(u, v);
-	}
-	else
-	{
-		RI_ASSERT(tilingMode == VG_TILE_REFLECT);
-
-		u = RI_INT_MOD(u, image->m_width*2);
-		v = RI_INT_MOD(v, image->m_height*2);
-		if( u >= image->m_width ) u = image->m_width*2-1 - u;
-		if( v >= image->m_height ) v = image->m_height*2-1 - v;
-		p = image->readPixel(u, v);
-	}
-
-	p.premultiply();    //interpolate in premultiplied format
-	return p;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Maps point (x,y) to an image and returns a filtered,
-*			premultiplied color value.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Color Image::resample(RIfloat x, RIfloat y, const Matrix3x3& surfaceToImage, VGImageQuality quality, VGTilingMode tilingMode, const Color& tileFillColor)	//throws bad_alloc
-{
-	RI_ASSERT(m_referenceCount > 0);
-
-	VGbitfield aq = getAllowedQuality();
-	aq &= (VGbitfield)quality;
-
-	Vector3 uvw(x,y,1.0f);
-	uvw = surfaceToImage * uvw;
-	RIfloat oow = 1.0f / uvw.z;
-	uvw *= oow;
-
-	if(aq & VG_IMAGE_QUALITY_BETTER)
-	{	//EWA on mipmaps
-		makeMipMaps();	//throws bad_alloc
-
-		Color::InternalFormat procFormat = (Color::InternalFormat)(m_desc.internalFormat | Color::PREMULTIPLIED);
-
-		RIfloat m_pixelFilterRadius = 1.25f;
-		RIfloat m_resamplingFilterRadius = 1.25f;
-
-		RIfloat Ux = (surfaceToImage[0][0] - uvw.x * surfaceToImage[2][0]) * oow * m_pixelFilterRadius;
-		RIfloat Vx = (surfaceToImage[1][0] - uvw.y * surfaceToImage[2][0]) * oow * m_pixelFilterRadius;
-		RIfloat Uy = (surfaceToImage[0][1] - uvw.x * surfaceToImage[2][1]) * oow * m_pixelFilterRadius;
-		RIfloat Vy = (surfaceToImage[1][1] - uvw.y * surfaceToImage[2][1]) * oow * m_pixelFilterRadius;
-		RIfloat U0 = uvw.x;
-		RIfloat V0 = uvw.y;
-
-		//calculate mip level
-		int level = 0;
-		RIfloat axis1sq = Ux*Ux + Vx*Vx;
-		RIfloat axis2sq = Uy*Uy + Vy*Vy;
-		RIfloat minorAxissq = RI_MIN(axis1sq,axis2sq);
-		while(minorAxissq > 9.0f && level < m_mipmaps.size())	//half the minor axis must be at least three texels
-		{
-			level++;
-			minorAxissq *= 0.25f;
-		}
-
-		RIfloat sx = 1.0f;
-		RIfloat sy = 1.0f;
-		if(level > 0)
-		{
-			sx = (RIfloat)m_mipmaps[level-1]->m_width / (RIfloat)m_width;
-			sy = (RIfloat)m_mipmaps[level-1]->m_height / (RIfloat)m_height;
-		}
-		Ux *= sx;
-		Vx *= sx;
-		U0 *= sx;
-		Uy *= sy;
-		Vy *= sy;
-		V0 *= sy;
-		
-		//clamp filter size so that filtering doesn't take excessive amount of time (clamping results in aliasing)
-		RIfloat lim = 100.0f;
-		axis1sq = Ux*Ux + Vx*Vx;
-		axis2sq = Uy*Uy + Vy*Vy;
-		if( axis1sq > lim*lim )
-		{
-			RIfloat s = lim / (RIfloat)sqrt(axis1sq);
-			Ux *= s;
-			Vx *= s;
-		}
-		if( axis2sq > lim*lim )
-		{
-			RIfloat s = lim / (RIfloat)sqrt(axis2sq);
-			Uy *= s;
-			Vy *= s;
-		}
-		
-		
-		//form elliptic filter by combining texel and pixel filters
-		RIfloat A = Vx*Vx + Vy*Vy + 1.0f;
-		RIfloat B = -2.0f*(Ux*Vx + Uy*Vy);
-		RIfloat C = Ux*Ux + Uy*Uy + 1.0f;
-		//scale by the user-defined size of the kernel
-		A *= m_resamplingFilterRadius;
-		B *= m_resamplingFilterRadius;
-		C *= m_resamplingFilterRadius;
-		
-		//calculate bounding box in texture space
-		RIfloat usize = (RIfloat)sqrt(C);
-		RIfloat vsize = (RIfloat)sqrt(A);
-		int u1 = (int)floor(U0 - usize + 0.5f);
-		int u2 = (int)floor(U0 + usize + 0.5f);
-		int v1 = (int)floor(V0 - vsize + 0.5f);
-		int v2 = (int)floor(V0 + vsize + 0.5f);
-		if( u1 == u2 || v1 == v2 )
-			return Color(0,0,0,0,procFormat);
-
-		//scale the filter so that Q = 1 at the cutoff radius
-		RIfloat F = A*C - 0.25f * B*B;
-		if( F <= 0.0f )
-			return Color(0,0,0,0,procFormat);	//invalid filter shape due to numerical inaccuracies => return black
-		RIfloat ooF = 1.0f / F;
-		A *= ooF;
-		B *= ooF;
-		C *= ooF;
-		
-		//evaluate filter by using forward differences to calculate Q = A*U^2 + B*U*V + C*V^2
-		Color color(0,0,0,0,procFormat);
-		RIfloat sumweight = 0.0f;
-		RIfloat DDQ = 2.0f * A;
-		RIfloat U = (RIfloat)u1 - U0 + 0.5f;
-		for(int v=v1;v<v2;v++)
-		{
-			RIfloat V = (RIfloat)v - V0 + 0.5f;
-			RIfloat DQ = A*(2.0f*U+1.0f) + B*V;
-			RIfloat Q = (C*V+B*U)*V + A*U*U;
-			for(int u=u1;u<u2;u++)
-			{
-				if( Q >= 0.0f && Q < 1.0f )
-				{	//Q = r^2, fit gaussian to the range [0,1]
-					RIfloat weight = (RIfloat)exp(-0.5f * 10.0f * Q);	//gaussian at radius 10 equals 0.0067
-					color += weight * readTexel(u, v, level, tilingMode, tileFillColor);
-					sumweight += weight;
-				}
-				Q += DQ;
-				DQ += DDQ;
-			}
-		}
-		if( sumweight == 0.0f )
-			return Color(0,0,0,0,procFormat);
-		RI_ASSERT(sumweight > 0.0f);
-		sumweight = 1.0f / sumweight;
-		return color * sumweight;
-	}
-	else if(aq & VG_IMAGE_QUALITY_FASTER)
-	{	//bilinear
-		uvw.x -= 0.5f;
-		uvw.y -= 0.5f;
-		int u = (int)floor(uvw.x);
-		int v = (int)floor(uvw.y);
-		Color c00 = readTexel(u,v, 0, tilingMode, tileFillColor);
-		Color c10 = readTexel(u+1,v, 0, tilingMode, tileFillColor);
-		Color c01 = readTexel(u,v+1, 0, tilingMode, tileFillColor);
-		Color c11 = readTexel(u+1,v+1, 0, tilingMode, tileFillColor);
-		RIfloat fu = uvw.x - (RIfloat)u;
-		RIfloat fv = uvw.y - (RIfloat)v;
-		Color c0 = c00 * (1.0f - fu) + c10 * fu;
-		Color c1 = c01 * (1.0f - fu) + c11 * fu;
-		return c0 * (1.0f - fv) + c1 * fv;
-	}
-	else
-	{	//point sampling
-		return readTexel((int)floor(uvw.x), (int)floor(uvw.y), 0, tilingMode, tileFillColor);
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Generates mip maps for an image.
-* \param	
-* \return	
-* \note		Downsampling is done in the input color space. We use a box
-*			filter for downsampling.
-*//*-------------------------------------------------------------------*/
-
-void Image::makeMipMaps()
-{
-	RI_ASSERT(m_data);
-	RI_ASSERT(m_referenceCount > 0);
-
-	if(m_mipmapsValid)
-		return;
-
-	//delete existing mipmaps
-	for(int i=0;i<m_mipmaps.size();i++)
-	{
-		if(!m_mipmaps[i]->removeReference())
-			RI_DELETE(m_mipmaps[i]);
-		else
-		{
-			RI_ASSERT(0);	//there can't be any other references to the mipmap levels
-		}
-	}
-	m_mipmaps.clear();
-
-	try
-	{
-		Color::InternalFormat procFormat = m_desc.internalFormat;
-		procFormat = (Color::InternalFormat)(procFormat | Color::PREMULTIPLIED);	//premultiplied
-
-		//generate mipmaps until width and height are one
-		Image* prev = this;
-		while( prev->m_width > 1 || prev->m_height > 1 )
-		{
-			int nextw = (int)ceil(prev->m_width*0.5f);
-			int nexth = (int)ceil(prev->m_height*0.5f);
-			RI_ASSERT(nextw >= 1 && nexth >= 1);
-			RI_ASSERT(nextw < prev->m_width || nexth < prev->m_height);
-
-			m_mipmaps.resize(m_mipmaps.size()+1);	//throws bad_alloc
-			m_mipmaps[m_mipmaps.size()-1] = NULL;
-
-			Image* next = RI_NEW(Image, (m_desc, nextw, nexth, m_allowedQuality));	//throws bad_alloc
-			next->addReference();
-			for(int j=0;j<next->m_height;j++)
-			{
-				for(int i=0;i<next->m_width;i++)
-				{
-					RIfloat u0 = (RIfloat)i / (RIfloat)next->m_width;
-					RIfloat u1 = (RIfloat)(i+1) / (RIfloat)next->m_width;
-					RIfloat v0 = (RIfloat)j / (RIfloat)next->m_height;
-					RIfloat v1 = (RIfloat)(j+1) / (RIfloat)next->m_height;
-
-					u0 *= prev->m_width;
-					u1 *= prev->m_width;
-					v0 *= prev->m_height;
-					v1 *= prev->m_height;
-
-					int su = (int)floor(u0);
-					int eu = (int)ceil(u1);
-					int sv = (int)floor(v0);
-					int ev = (int)ceil(v1);
-
-					Color c(0,0,0,0,procFormat);
-					int samples = 0;
-					for(int y=sv;y<ev;y++)
-					{
-						for(int x=su;x<eu;x++)
-						{
-							Color p = prev->readPixel(x, y);
-							p.convert(procFormat);
-							c += p;
-							samples++;
-						}
-					}
-					c *= (1.0f/samples);
-					c.convert(m_desc.internalFormat);
-					next->writePixel(i,j,c);
-				}
-			}
-			m_mipmaps[m_mipmaps.size()-1] = next;
-			prev = next;
-		}
-		RI_ASSERT(prev->m_width == 1 && prev->m_height == 1);
-		m_mipmapsValid = true;
-	}
-	catch(std::bad_alloc)
-	{
-		//delete existing mipmaps
-		for(int i=0;i<m_mipmaps.size();i++)
-		{
-			if(m_mipmaps[i])
-			{
-				if(!m_mipmaps[i]->removeReference())
-					RI_DELETE(m_mipmaps[i]);
-				else
-				{
-					RI_ASSERT(0);	//there can't be any other references to the mipmap levels
-				}
-			}
-		}
-		m_mipmaps.clear();
-		m_mipmapsValid = false;
-		throw;
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Applies color matrix filter.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Image::colorMatrix(const Image& src, const RIfloat* matrix, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask)
-{
-	RI_ASSERT(src.m_data);	//source exists
-	RI_ASSERT(m_data);	//destination exists
-	RI_ASSERT(matrix);
-	RI_ASSERT(m_referenceCount > 0 && src.m_referenceCount > 0);
-
-	int w = RI_INT_MIN(m_width, src.m_width);
-	int h = RI_INT_MIN(m_height, src.m_height);
-	RI_ASSERT(w > 0 && h > 0);
-
-	Color::InternalFormat srcFormat = src.m_desc.internalFormat;
-	Color::InternalFormat procFormat = (Color::InternalFormat)(srcFormat & ~Color::LUMINANCE);	//process in RGB, not luminance
-	if(filterFormatLinear)
-		procFormat = (Color::InternalFormat)(procFormat & ~Color::NONLINEAR);
-	else
-		procFormat = (Color::InternalFormat)(procFormat | Color::NONLINEAR);
-
-	if(filterFormatPremultiplied)
-		procFormat = (Color::InternalFormat)(procFormat | Color::PREMULTIPLIED);
-	else
-		procFormat = (Color::InternalFormat)(procFormat & ~Color::PREMULTIPLIED);
-
-	for(int j=0;j<h;j++)
-	{
-		for(int i=0;i<w;i++)
-		{
-			Color s = src.readPixel(i,j);	//convert to RGBA [0,1]
-			s.convert(procFormat);
-
-			Color d(0,0,0,0,procFormat);
-			d.r = matrix[0+4*0] * s.r + matrix[0+4*1] * s.g + matrix[0+4*2] * s.b + matrix[0+4*3] * s.a + matrix[0+4*4];
-			d.g = matrix[1+4*0] * s.r + matrix[1+4*1] * s.g + matrix[1+4*2] * s.b + matrix[1+4*3] * s.a + matrix[1+4*4];
-			d.b = matrix[2+4*0] * s.r + matrix[2+4*1] * s.g + matrix[2+4*2] * s.b + matrix[2+4*3] * s.a + matrix[2+4*4];
-			d.a = matrix[3+4*0] * s.r + matrix[3+4*1] * s.g + matrix[3+4*2] * s.b + matrix[3+4*3] * s.a + matrix[3+4*4];
-
-			writeFilteredPixel(i, j, d, channelMask);
-		}
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Reads a pixel from image with tiling mode applied.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static Color readTiledPixel(int x, int y, int w, int h, VGTilingMode tilingMode, const Array<Color>& image, const Color& edge)
-{
-	Color s;
-	if(x < 0 || x >= w || y < 0 || y >= h)
-	{	//apply tiling mode
-		switch(tilingMode)
-		{
-		case VG_TILE_FILL:
-			s = edge;
-			break;
-		case VG_TILE_PAD:
-			x = RI_INT_MIN(RI_INT_MAX(x, 0), w-1);
-			y = RI_INT_MIN(RI_INT_MAX(y, 0), h-1);
-			RI_ASSERT(x >= 0 && x < w && y >= 0 && y < h);
-			s = image[y*w+x];
-			break;
-		case VG_TILE_REPEAT:
-			x = RI_INT_MOD(x, w);
-			y = RI_INT_MOD(y, h);
-			RI_ASSERT(x >= 0 && x < w && y >= 0 && y < h);
-			s = image[y*w+x];
-			break;
-		default:
-			RI_ASSERT(tilingMode == VG_TILE_REFLECT);
-			x = RI_INT_MOD(x, w*2);
-			y = RI_INT_MOD(y, h*2);
-			if(x >= w) x = w*2-1-x;
-			if(y >= h) y = h*2-1-y;
-			RI_ASSERT(x >= 0 && x < w && y >= 0 && y < h);
-			s = image[y*w+x];
-			break;
-		}
-	}
-	else
-	{
-		RI_ASSERT(x >= 0 && x < w && y >= 0 && y < h);
-		s = image[y*w+x];
-	}
-	return s;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Returns processing format for filtering.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static Color::InternalFormat getProcessingFormat(Color::InternalFormat srcFormat, bool filterFormatLinear, bool filterFormatPremultiplied)
-{
-	Color::InternalFormat procFormat = (Color::InternalFormat)(srcFormat & ~Color::LUMINANCE);	//process in RGB, not luminance
-	if(filterFormatLinear)
-		procFormat = (Color::InternalFormat)(procFormat & ~Color::NONLINEAR);
-	else
-		procFormat = (Color::InternalFormat)(procFormat | Color::NONLINEAR);
-
-	if(filterFormatPremultiplied)
-		procFormat = (Color::InternalFormat)(procFormat | Color::PREMULTIPLIED);
-	else
-		procFormat = (Color::InternalFormat)(procFormat & ~Color::PREMULTIPLIED);
-	return procFormat;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Applies convolution filter.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Image::convolve(const Image& src, int kernelWidth, int kernelHeight, int shiftX, int shiftY, const RIint16* kernel, RIfloat scale, RIfloat bias, VGTilingMode tilingMode, const Color& edgeFillColor, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask)
-{
-	RI_ASSERT(src.m_data);	//source exists
-	RI_ASSERT(m_data);	//destination exists
-	RI_ASSERT(kernel && kernelWidth > 0 && kernelHeight > 0);
-	RI_ASSERT(m_referenceCount > 0 && src.m_referenceCount > 0);
-
-	//the area to be written is an intersection of source and destination image areas.
-	//lower-left corners of the images are aligned.
-	int w = RI_INT_MIN(m_width, src.m_width);
-	int h = RI_INT_MIN(m_height, src.m_height);
-	RI_ASSERT(w > 0 && h > 0);
-
-	Color::InternalFormat procFormat = getProcessingFormat(src.m_desc.internalFormat, filterFormatLinear, filterFormatPremultiplied);
-
-	Color edge = edgeFillColor;
-	edge.clamp();
-	edge.convert(procFormat);
-
-	Array<Color> tmp;
-	tmp.resize(src.m_width*src.m_height);	//throws bad_alloc
-
-	//copy source region to tmp and do conversion
-	for(int j=0;j<src.m_height;j++)
-	{
-		for(int i=0;i<src.m_width;i++)
-		{
-			Color s = src.readPixel(i, j);
-			s.convert(procFormat);
-			tmp[j*src.m_width+i] = s;
-		}
-	}
-
-	for(int j=0;j<h;j++)
-	{
-		for(int i=0;i<w;i++)
-		{
-			Color sum(0,0,0,0,procFormat);
-
-			for(int kj=0;kj<kernelHeight;kj++)
-			{
-				for(int ki=0;ki<kernelWidth;ki++)
-				{
-					int x = i+ki-shiftX;
-					int y = j+kj-shiftY;
-					Color s = readTiledPixel(x, y, src.m_width, src.m_height, tilingMode, tmp, edge);
-
-					int kx = kernelWidth-ki-1;
-					int ky = kernelHeight-kj-1;
-					RI_ASSERT(kx >= 0 && kx < kernelWidth && ky >= 0 && ky < kernelHeight);
-
-					sum += (RIfloat)kernel[kx*kernelHeight+ky] * s;
-				}
-			}
-
-			sum *= scale;
-			sum.r += bias;
-			sum.g += bias;
-			sum.b += bias;
-			sum.a += bias;
-
-			writeFilteredPixel(i, j, sum, channelMask);
-		}
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Applies separable convolution filter.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Image::separableConvolve(const Image& src, int kernelWidth, int kernelHeight, int shiftX, int shiftY, const RIint16* kernelX, const RIint16* kernelY, RIfloat scale, RIfloat bias, VGTilingMode tilingMode, const Color& edgeFillColor, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask)
-{
-	RI_ASSERT(src.m_data);	//source exists
-	RI_ASSERT(m_data);	//destination exists
-	RI_ASSERT(kernelX && kernelY && kernelWidth > 0 && kernelHeight > 0);
-	RI_ASSERT(m_referenceCount > 0 && src.m_referenceCount > 0);
-
-	//the area to be written is an intersection of source and destination image areas.
-	//lower-left corners of the images are aligned.
-	int w = RI_INT_MIN(m_width, src.m_width);
-	int h = RI_INT_MIN(m_height, src.m_height);
-	RI_ASSERT(w > 0 && h > 0);
-
-	Color::InternalFormat procFormat = getProcessingFormat(src.m_desc.internalFormat, filterFormatLinear, filterFormatPremultiplied);
-
-	Color edge = edgeFillColor;
-	edge.clamp();
-	edge.convert(procFormat);
-
-	Array<Color> tmp;
-	tmp.resize(src.m_width*src.m_height);	//throws bad_alloc
-
-	//copy source region to tmp and do conversion
-	for(int j=0;j<src.m_height;j++)
-	{
-		for(int i=0;i<src.m_width;i++)
-		{
-			Color s = src.readPixel(i, j);
-			s.convert(procFormat);
-			tmp[j*src.m_width+i] = s;
-		}
-	}
-
-	Array<Color> tmp2;
-	tmp2.resize(w*src.m_height);	//throws bad_alloc
-	for(int j=0;j<src.m_height;j++)
-	{
-		for(int i=0;i<w;i++)
-		{
-			Color sum(0,0,0,0,procFormat);
-			for(int ki=0;ki<kernelWidth;ki++)
-			{
-				int x = i+ki-shiftX;
-				Color s = readTiledPixel(x, j, src.m_width, src.m_height, tilingMode, tmp, edge);
-
-				int kx = kernelWidth-ki-1;
-				RI_ASSERT(kx >= 0 && kx < kernelWidth);
-
-				sum += (RIfloat)kernelX[kx] * s;
-			}
-			tmp2[j*w+i] = sum;
-		}
-	}
-
-	if(tilingMode == VG_TILE_FILL)
-	{	//convolve the edge color
-		Color sum(0,0,0,0,procFormat);
-		for(int ki=0;ki<kernelWidth;ki++)
-		{
-			sum += (RIfloat)kernelX[ki] * edge;
-		}
-		edge = sum;
-	}
-
-	for(int j=0;j<h;j++)
-	{
-		for(int i=0;i<w;i++)
-		{
-			Color sum(0,0,0,0,procFormat);
-			for(int kj=0;kj<kernelHeight;kj++)
-			{
-				int y = j+kj-shiftY;
-				Color s = readTiledPixel(i, y, w, src.m_height, tilingMode, tmp2, edge);
-
-				int ky = kernelHeight-kj-1;
-				RI_ASSERT(ky >= 0 && ky < kernelHeight);
-
-				sum += (RIfloat)kernelY[ky] * s;
-			}
-
-			sum *= scale;
-			sum.r += bias;
-			sum.g += bias;
-			sum.b += bias;
-			sum.a += bias;
-
-			writeFilteredPixel(i, j, sum, channelMask);
-		}
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Applies Gaussian blur filter.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Image::gaussianBlur(const Image& src, RIfloat stdDeviationX, RIfloat stdDeviationY, VGTilingMode tilingMode, const Color& edgeFillColor, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask)
-{
-	RI_ASSERT(src.m_data);	//source exists
-	RI_ASSERT(m_data);	//destination exists
-	RI_ASSERT(stdDeviationX > 0.0f && stdDeviationY > 0.0f);
-	RI_ASSERT(stdDeviationX <= RI_MAX_GAUSSIAN_STD_DEVIATION && stdDeviationY <= RI_MAX_GAUSSIAN_STD_DEVIATION);
-	RI_ASSERT(m_referenceCount > 0 && src.m_referenceCount > 0);
-
-	//the area to be written is an intersection of source and destination image areas.
-	//lower-left corners of the images are aligned.
-	int w = RI_INT_MIN(m_width, src.m_width);
-	int h = RI_INT_MIN(m_height, src.m_height);
-	RI_ASSERT(w > 0 && h > 0);
-
-	Color::InternalFormat procFormat = getProcessingFormat(src.m_desc.internalFormat, filterFormatLinear, filterFormatPremultiplied);
-
-	Color edge = edgeFillColor;
-	edge.clamp();
-	edge.convert(procFormat);
-
-	Array<Color> tmp;
-	tmp.resize(src.m_width*src.m_height);	//throws bad_alloc
-
-	//copy source region to tmp and do conversion
-	for(int j=0;j<src.m_height;j++)
-	{
-		for(int i=0;i<src.m_width;i++)
-		{
-			Color s = src.readPixel(i, j);
-			s.convert(procFormat);
-			tmp[j*src.m_width+i] = s;
-		}
-	}
-
-	RIfloat expScaleX = -1.0f / (2.0f*stdDeviationX*stdDeviationX);
-	RIfloat expScaleY = -1.0f / (2.0f*stdDeviationY*stdDeviationY);
-
-	int kernelWidth = (int)(stdDeviationX * 4.0f + 1.0f);
-	int kernelHeight = (int)(stdDeviationY * 4.0f + 1.0f);
-
-	//make a separable kernel
-	Array<RIfloat> kernelX;
-	kernelX.resize(kernelWidth*2+1);
-	int shiftX = kernelWidth;
-	RIfloat scaleX = 0.0f;
-	for(int i=0;i<kernelX.size();i++)
-	{
-		int x = i-shiftX;
-		kernelX[i] = (RIfloat)exp((RIfloat)x*(RIfloat)x * expScaleX);
-		scaleX += kernelX[i];
-	}
-	scaleX = 1.0f / scaleX;	//NOTE: using the mathematical definition of the scaling term doesn't work since we cut the filter support early for performance
-
-	Array<RIfloat> kernelY;
-	kernelY.resize(kernelHeight*2+1);
-	int shiftY = kernelHeight;
-	RIfloat scaleY = 0.0f;
-	for(int i=0;i<kernelY.size();i++)
-	{
-		int y = i-shiftY;
-		kernelY[i] = (RIfloat)exp((RIfloat)y*(RIfloat)y * expScaleY);
-		scaleY += kernelY[i];
-	}
-	scaleY = 1.0f / scaleY;	//NOTE: using the mathematical definition of the scaling term doesn't work since we cut the filter support early for performance
-
-	Array<Color> tmp2;
-	tmp2.resize(w*src.m_height);	//throws bad_alloc
-	//horizontal pass
-	for(int j=0;j<src.m_height;j++)
-	{
-		for(int i=0;i<w;i++)
-		{
-			Color sum(0,0,0,0,procFormat);
-			for(int ki=0;ki<kernelX.size();ki++)
-			{
-				int x = i+ki-shiftX;
-				sum += kernelX[ki] * readTiledPixel(x, j, src.m_width, src.m_height, tilingMode, tmp, edge);
-			}
-			tmp2[j*w+i] = sum * scaleX;
-		}
-	}
-	//vertical pass
-	for(int j=0;j<h;j++)
-	{
-		for(int i=0;i<w;i++)
-		{
-			Color sum(0,0,0,0,procFormat);
-			for(int kj=0;kj<kernelY.size();kj++)
-			{
-				int y = j+kj-shiftY;
-				sum += kernelY[kj] * readTiledPixel(i, y, w, src.m_height, tilingMode, tmp2, edge);
-			}
-			writeFilteredPixel(i, j, sum * scaleY, channelMask);
-		}
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Returns lookup table format for lookup filters.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static Color::InternalFormat getLUTFormat(bool outputLinear, bool outputPremultiplied)
-{
-	Color::InternalFormat lutFormat = Color::lRGBA;
-	if(outputLinear && outputPremultiplied)
-		lutFormat = Color::lRGBA_PRE;
-	else if(!outputLinear && !outputPremultiplied)
-		lutFormat = Color::sRGBA;
-	else if(!outputLinear && outputPremultiplied)
-		lutFormat = Color::sRGBA_PRE;
-	return lutFormat;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Applies multi-channel lookup table filter.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Image::lookup(const Image& src, const RIuint8 * redLUT, const RIuint8 * greenLUT, const RIuint8 * blueLUT, const RIuint8 * alphaLUT, bool outputLinear, bool outputPremultiplied, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask)
-{
-	RI_ASSERT(src.m_data);	//source exists
-	RI_ASSERT(m_data);	//destination exists
-	RI_ASSERT(redLUT && greenLUT && blueLUT && alphaLUT);
-	RI_ASSERT(m_referenceCount > 0 && src.m_referenceCount > 0);
-
-	//the area to be written is an intersection of source and destination image areas.
-	//lower-left corners of the images are aligned.
-	int w = RI_INT_MIN(m_width, src.m_width);
-	int h = RI_INT_MIN(m_height, src.m_height);
-	RI_ASSERT(w > 0 && h > 0);
-
-	Color::InternalFormat procFormat = getProcessingFormat(src.m_desc.internalFormat, filterFormatLinear, filterFormatPremultiplied);
-	Color::InternalFormat lutFormat = getLUTFormat(outputLinear, outputPremultiplied);
-
-	for(int j=0;j<h;j++)
-	{
-		for(int i=0;i<w;i++)
-		{
-			Color s = src.readPixel(i,j);	//convert to RGBA [0,1]
-			s.convert(procFormat);
-
-			Color d(0,0,0,0,lutFormat);
-			d.r = intToColor(  redLUT[colorToInt(s.r, 255)], 255);
-			d.g = intToColor(greenLUT[colorToInt(s.g, 255)], 255);
-			d.b = intToColor( blueLUT[colorToInt(s.b, 255)], 255);
-			d.a = intToColor(alphaLUT[colorToInt(s.a, 255)], 255);
-
-			writeFilteredPixel(i, j, d, channelMask);
-		}
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Applies single channel lookup table filter.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Image::lookupSingle(const Image& src, const RIuint32 * lookupTable, VGImageChannel sourceChannel, bool outputLinear, bool outputPremultiplied, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask)
-{
-	RI_ASSERT(src.m_data);	//source exists
-	RI_ASSERT(m_data);	//destination exists
-	RI_ASSERT(lookupTable);
-	RI_ASSERT(m_referenceCount > 0 && src.m_referenceCount > 0);
-
-	//the area to be written is an intersection of source and destination image areas.
-	//lower-left corners of the images are aligned.
-	int w = RI_INT_MIN(m_width, src.m_width);
-	int h = RI_INT_MIN(m_height, src.m_height);
-	RI_ASSERT(w > 0 && h > 0);
-
-	if(src.m_desc.isLuminance())
-		sourceChannel = VG_RED;
-	else if(src.m_desc.redBits + src.m_desc.greenBits + src.m_desc.blueBits == 0)
-	{
-		RI_ASSERT(src.m_desc.alphaBits);
-		sourceChannel = VG_ALPHA;
-	}
-
-	Color::InternalFormat procFormat = getProcessingFormat(src.m_desc.internalFormat, filterFormatLinear, filterFormatPremultiplied);
-	Color::InternalFormat lutFormat = getLUTFormat(outputLinear, outputPremultiplied);
-
-	for(int j=0;j<h;j++)
-	{
-		for(int i=0;i<w;i++)
-		{
-			Color s = src.readPixel(i,j);	//convert to RGBA [0,1]
-			s.convert(procFormat);
-			int e;
-			switch(sourceChannel)
-			{
-			case VG_RED:
-				e = colorToInt(s.r, 255);
-				break;
-			case VG_GREEN:
-				e = colorToInt(s.g, 255);
-				break;
-			case VG_BLUE:
-				e = colorToInt(s.b, 255);
-				break;
-			default:
-				RI_ASSERT(sourceChannel == VG_ALPHA);
-				e = colorToInt(s.a, 255);
-				break;
-			}
-
-			RIuint32 l = ((const RIuint32*)lookupTable)[e];
-			Color d(0,0,0,0,lutFormat);
-			d.r = intToColor((l>>24), 255);
-			d.g = intToColor((l>>16), 255);
-			d.b = intToColor((l>> 8), 255);
-			d.a = intToColor((l    ), 255);
-
-			writeFilteredPixel(i, j, d, channelMask);
-		}
-	}
-}
-
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Surface::Surface(const Color::Descriptor& desc, int width, int height, int numSamples) :
-	m_width(width),
-	m_height(height),
-	m_numSamples(numSamples),
-	m_referenceCount(0),
-	m_image(NULL)
-{
-	RI_ASSERT(width > 0 && height > 0 && numSamples > 0 && numSamples <= 32);
-	m_image = RI_NEW(Image, (desc, width*numSamples, height, 0));	//throws bad_alloc
-	m_image->addReference();
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Surface::Surface(Image* image) :
-	m_width(0),
-	m_height(0),
-	m_numSamples(1),
-	m_referenceCount(0),
-	m_image(image)
-{
-	RI_ASSERT(image);
-	m_width = image->getWidth();
-	m_height = image->getHeight();
-	m_image->addReference();
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Surface::Surface(const Color::Descriptor& desc, int width, int height, int stride, RIuint8* data) :
-	m_width(width),
-	m_height(height),
-	m_numSamples(1),
-	m_referenceCount(0),
-	m_image(NULL)
-{
-	RI_ASSERT(width > 0 && height > 0);
-	m_image = RI_NEW(Image, (desc, width, height, stride, data));	//throws bad_alloc
-	m_image->addReference();
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Surface::~Surface()
-{
-	RI_ASSERT(m_referenceCount == 0);
-	if(!m_image->removeReference())
-		RI_DELETE(m_image);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Surface::clear(const Color& clearColor, int x, int y, int w, int h)
-{
-	Rectangle rect;
-	rect.x = 0;
-	rect.y = 0;
-	rect.width = getWidth();
-	rect.height = getHeight();
-	Array<Rectangle> scissors;
-	scissors.push_back(rect);
-	clear(clearColor, x, y, w, h, scissors);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Surface::clear(const Color& clearColor, int x, int y, int w, int h, const Array<Rectangle>& scissors)
-{
-	RI_ASSERT(w > 0 && h > 0);
-
-	//intersect clear region with image bounds
-	Rectangle r(0,0,getWidth(),getHeight());
-	r.intersect(Rectangle(x,y,w,h));
-	if(!r.width || !r.height)
-		return;		//intersection is empty or one of the rectangles is invalid
-
-	Array<ScissorEdge> scissorEdges;
-	for(int i=0;i<scissors.size();i++)
-	{
-		if(scissors[i].width > 0 && scissors[i].height > 0)
-		{
-			ScissorEdge e;
-			e.miny = scissors[i].y;
-			e.maxy = RI_INT_ADDSATURATE(scissors[i].y, scissors[i].height);
-
-			e.x = scissors[i].x;
-			e.direction = 1;
-			scissorEdges.push_back(e);	//throws bad_alloc
-			e.x = RI_INT_ADDSATURATE(scissors[i].x, scissors[i].width);
-			e.direction = -1;
-			scissorEdges.push_back(e);	//throws bad_alloc
-		}
-	}
-	if(!scissorEdges.size())
-		return;	//there are no scissor rectangles => nothing is visible
-
-	//sort scissor edges by edge x
-    scissorEdges.sort();
-
-	//clear the image
-	Color col = clearColor;
-	col.clamp();
-	col.convert(m_image->getDescriptor().internalFormat);
-
-	Array<ScissorEdge> scissorAet;
-	for(int j=r.y;j<r.y + r.height;j++)
-	{
-		//gather scissor edges intersecting this scanline
-		scissorAet.clear();
-		for(int e=0;e<scissorEdges.size();e++)
-		{
-			const ScissorEdge& se = scissorEdges[e];
-			if(j >= se.miny && j < se.maxy)
-				scissorAet.push_back(scissorEdges[e]);	//throws bad_alloc
-		}
-		if(!scissorAet.size())
-			continue;	//scissoring is on, but there are no scissor rectangles on this scanline
-
-		//clear a scanline
-		int scissorWinding = 0;
-		int scissorIndex = 0;
-		for(int i=r.x;i<r.x + r.width;i++)
-		{
-			while(scissorIndex < scissorAet.size() && scissorAet[scissorIndex].x <= i)
-				scissorWinding += scissorAet[scissorIndex++].direction;
-			RI_ASSERT(scissorWinding >= 0);
-
-			if(scissorWinding)
-			{
-                for(int s=0;s<m_numSamples;s++)
-                    writeSample(i, j, s, col);
-			}
-		}
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Surface::blit(const Image& src, int sx, int sy, int dx, int dy, int w, int h)
-{
-	Rectangle rect;
-	rect.x = 0;
-	rect.y = 0;
-	rect.width = getWidth();
-	rect.height = getHeight();
-	Array<Rectangle> scissors;
-	scissors.push_back(rect);
-	blit(src, sx, sy, dx, dy, w, h, scissors);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		no overlap is possible. Single sample to single or multisample (replicate)
-*//*-------------------------------------------------------------------*/
-
-void Surface::blit(const Image& src, int sx, int sy, int dx, int dy, int w, int h, const Array<Rectangle>& scissors)
-{
-	//img=>fb: vgSetPixels
-	//user=>fb: vgWritePixels
-	computeBlitRegion(sx, sy, dx, dy, w, h, src.getWidth(), src.getHeight(), getWidth(), getHeight());
-	if(w <= 0 || h <= 0)
-		return;	//zero area
-
-	Array<ScissorEdge> scissorEdges;
-	for(int i=0;i<scissors.size();i++)
-	{
-		if(scissors[i].width > 0 && scissors[i].height > 0)
-		{
-			ScissorEdge e;
-			e.miny = scissors[i].y;
-			e.maxy = RI_INT_ADDSATURATE(scissors[i].y, scissors[i].height);
-
-			e.x = scissors[i].x;
-			e.direction = 1;
-			scissorEdges.push_back(e);	//throws bad_alloc
-			e.x = RI_INT_ADDSATURATE(scissors[i].x, scissors[i].width);
-			e.direction = -1;
-			scissorEdges.push_back(e);	//throws bad_alloc
-		}
-	}
-	if(!scissorEdges.size())
-		return;	//there are no scissor rectangles => nothing is visible
-
-	//sort scissor edges by edge x
-    scissorEdges.sort();
-
-	Array<ScissorEdge> scissorAet;
-	for(int j=0;j<h;j++)
-	{
-		//gather scissor edges intersecting this scanline
-		scissorAet.clear();
-		for(int e=0;e<scissorEdges.size();e++)
-		{
-			const ScissorEdge& se = scissorEdges[e];
-			if(dy + j >= se.miny && dy + j < se.maxy)
-				scissorAet.push_back(scissorEdges[e]);	//throws bad_alloc
-		}
-		if(!scissorAet.size())
-			continue;	//scissoring is on, but there are no scissor rectangles on this scanline
-
-		//blit a scanline
-		int scissorWinding = 0;
-		int scissorIndex = 0;
-		for(int i=0;i<w;i++)
-		{
-			while(scissorIndex < scissorAet.size() && scissorAet[scissorIndex].x <= dx + i)
-				scissorWinding += scissorAet[scissorIndex++].direction;
-			RI_ASSERT(scissorWinding >= 0);
-
-			if(scissorWinding)
-			{
-				Color c = src.readPixel(sx + i, sy + j);
-				c.convert(getDescriptor().internalFormat);
-                for(int s=0;s<m_numSamples;s++)
-                    writeSample(dx + i, dy + j, s, c);
-			}
-		}
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Surface::blit(const Surface* src, int sx, int sy, int dx, int dy, int w, int h)
-{
-	Rectangle rect;
-	rect.x = 0;
-	rect.y = 0;
-	rect.width = getWidth();
-	rect.height = getHeight();
-	Array<Rectangle> scissors;
-	scissors.push_back(rect);
-	blit(src, sx, sy, dx, dy, w, h, scissors);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Surface::blit(const Surface* src, int sx, int sy, int dx, int dy, int w, int h, const Array<Rectangle>& scissors)
-{
-    RI_ASSERT(m_numSamples == src->m_numSamples);
-
-	//fb=>fb: vgCopyPixels
-	computeBlitRegion(sx, sy, dx, dy, w, h, src->getWidth(), src->getHeight(), getWidth(), getHeight());
-	if(w <= 0 || h <= 0)
-		return;	//zero area
-
-	Array<ScissorEdge> scissorEdges;
-	for(int i=0;i<scissors.size();i++)
-	{
-		if(scissors[i].width > 0 && scissors[i].height > 0)
-		{
-			ScissorEdge e;
-			e.miny = scissors[i].y;
-			e.maxy = RI_INT_ADDSATURATE(scissors[i].y, scissors[i].height);
-
-			e.x = scissors[i].x;
-			e.direction = 1;
-			scissorEdges.push_back(e);	//throws bad_alloc
-			e.x = RI_INT_ADDSATURATE(scissors[i].x, scissors[i].width);
-			e.direction = -1;
-			scissorEdges.push_back(e);	//throws bad_alloc
-		}
-	}
-	if(!scissorEdges.size())
-		return;	//there are no scissor rectangles => nothing is visible
-
-	//sort scissor edges by edge x
-    scissorEdges.sort();
-
-	Array<Color> tmp;
-	tmp.resize(w*m_numSamples*h);	//throws bad_alloc
-
-	//copy source region to tmp
-	for(int j=0;j<h;j++)
-	{
-		for(int i=0;i<w;i++)
-		{
-			int numSamples = m_numSamples;
-			for(int s=0;s<numSamples;s++)
-			{
-				Color c = src->m_image->readPixel((sx + i)*m_numSamples+s, sy + j);
-				c.convert(m_image->getDescriptor().internalFormat);
-				tmp[(j*w+i)*m_numSamples+s] = c;
-			}
-		}
-	}
-
-	Array<ScissorEdge> scissorAet;
-	for(int j=0;j<h;j++)
-	{
-		//gather scissor edges intersecting this scanline
-		scissorAet.clear();
-		for(int e=0;e<scissorEdges.size();e++)
-		{
-			const ScissorEdge& se = scissorEdges[e];
-			if(dy + j >= se.miny && dy + j < se.maxy)
-				scissorAet.push_back(scissorEdges[e]);	//throws bad_alloc
-		}
-		if(!scissorAet.size())
-			continue;	//scissoring is on, but there are no scissor rectangles on this scanline
-
-		//blit a scanline
-		int scissorWinding = 0;
-		int scissorIndex = 0;
-		for(int i=0;i<w;i++)
-		{
-			while(scissorIndex < scissorAet.size() && scissorAet[scissorIndex].x <= dx + i)
-				scissorWinding += scissorAet[scissorIndex++].direction;
-			RI_ASSERT(scissorWinding >= 0);
-
-			if(scissorWinding)
-			{
-				int numSamples = m_numSamples;
-				for(int s=0;s<numSamples;s++)
-				{
-					m_image->writePixel((dx + i)*m_numSamples+s, dy + j, tmp[(j*w+i)*m_numSamples+s]);
-				}
-			}
-		}
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Surface::mask(const Image* src, VGMaskOperation operation, int x, int y, int w, int h)
-{
-	RI_ASSERT(w > 0 && h > 0);
-
-	if(operation == VG_CLEAR_MASK || operation == VG_FILL_MASK)
-	{
-		//intersect clear region with image bounds
-		Rectangle r(0,0,getWidth(),getHeight());
-		r.intersect(Rectangle(x,y,w,h));
-		if(!r.width || !r.height)
-			return;		//intersection is empty or one of the rectangles is invalid
-
-		if(m_numSamples == 1)
-		{
-			RIfloat m = 0.0f;
-			if(operation == VG_FILL_MASK)
-				m = 1.0f;
-			for(int j=r.y;j<r.y + r.height;j++)
-			{
-				for(int i=r.x;i<r.x + r.width;i++)
-				{
-					writeMaskCoverage(i, j, m);
-				}
-			}
-		}
-		else
-		{
-			unsigned int m = 0;
-			if(operation == VG_FILL_MASK)
-				m = (1<<m_numSamples)-1;
-			for(int j=r.y;j<r.y + r.height;j++)
-			{
-				for(int i=r.x;i<r.x + r.width;i++)
-				{
-					writeMaskMSAA(i, j, m);
-				}
-			}
-		}
-	}
-	else
-	{
-		RI_ASSERT(src);
-
-		int sx = 0, sy = 0, dx = x, dy = y;
-		computeBlitRegion(sx, sy, dx, dy, w, h, src->getWidth(), src->getHeight(), getWidth(), getHeight());
-		if(w <= 0 || h <= 0)
-			return;	//zero area
-
-		if(m_numSamples == 1)
-		{
-			for(int j=0;j<h;j++)
-			{
-				for(int i=0;i<w;i++)
-				{
-					RIfloat amask = src->readMaskPixel(sx + i, sy + j);
-					if(operation == VG_SET_MASK)
-						writeMaskCoverage(dx + i, dy + j, amask);
-					else
-					{
-						RIfloat aprev = readMaskCoverage(dx + i, dy + j);
-						RIfloat anew = 0.0f;
-						switch(operation)
-						{
-						case VG_UNION_MASK:		anew = 1.0f - (1.0f - amask)*(1.0f - aprev); break;
-						case VG_INTERSECT_MASK:	anew = amask * aprev; break;
-						default:				anew = aprev * (1.0f - amask); RI_ASSERT(operation == VG_SUBTRACT_MASK); break;
-						}
-						writeMaskCoverage(dx + i, dy + j, anew);
-					}
-				}
-			}
-		}
-		else
-		{
-			for(int j=0;j<h;j++)
-			{
-				for(int i=0;i<w;i++)
-				{
-					RIfloat fmask = src->readMaskPixel(sx + i, sy + j);
-					//TODO implement dithering?
-					unsigned int amask = fmask > 0.5f ? (1<<m_numSamples)-1 : 0;
-					if(operation == VG_SET_MASK)
-						writeMaskMSAA(dx + i, dy + j, amask);
-					else
-					{
-						unsigned int aprev = readMaskMSAA(dx + i, dy + j);
-						unsigned int anew = 0;
-						switch(operation)
-						{
-						case VG_UNION_MASK:		anew = amask | aprev; break;
-						case VG_INTERSECT_MASK:	anew = amask & aprev; break;
-						default:				anew = ~amask & aprev; RI_ASSERT(operation == VG_SUBTRACT_MASK); break;
-						}
-						writeMaskMSAA(dx + i, dy + j, anew);
-					}
-				}
-			}
-		}
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Surface::mask(const Surface* src, VGMaskOperation operation, int x, int y, int w, int h)
-{
-	RI_ASSERT(w > 0 && h > 0);
-
-	if(operation == VG_CLEAR_MASK || operation == VG_FILL_MASK)
-	{
-		//intersect clear region with image bounds
-		Rectangle r(0,0,getWidth(),getHeight());
-		r.intersect(Rectangle(x,y,w,h));
-		if(!r.width || !r.height)
-			return;		//intersection is empty or one of the rectangles is invalid
-
-		if(m_numSamples == 1)
-		{
-			RIfloat m = 0.0f;
-			if(operation == VG_FILL_MASK)
-				m = 1.0f;
-			for(int j=r.y;j<r.y + r.height;j++)
-			{
-				for(int i=r.x;i<r.x + r.width;i++)
-				{
-					writeMaskCoverage(i, j, m);
-				}
-			}
-		}
-		else
-		{
-			unsigned int m = 0;
-			if(operation == VG_FILL_MASK)
-				m = (1<<m_numSamples)-1;
-			for(int j=r.y;j<r.y + r.height;j++)
-			{
-				for(int i=r.x;i<r.x + r.width;i++)
-				{
-					writeMaskMSAA(i, j, m);
-				}
-			}
-		}
-	}
-	else
-	{
-		RI_ASSERT(src);
-        RI_ASSERT(m_numSamples == src->m_numSamples);
-
-		int sx = 0, sy = 0, dx = x, dy = y;
-		computeBlitRegion(sx, sy, dx, dy, w, h, src->getWidth(), src->getHeight(), getWidth(), getHeight());
-		if(w <= 0 || h <= 0)
-			return;	//zero area
-
-		if(m_numSamples == 1)
-		{
-			for(int j=0;j<h;j++)
-			{
-				for(int i=0;i<w;i++)
-				{
-					RIfloat amask = src->readMaskCoverage(sx + i, sy + j);
-					if(operation == VG_SET_MASK)
-						writeMaskCoverage(dx + i, dy + j, amask);
-					else
-					{
-						RIfloat aprev = readMaskCoverage(dx + i, dy + j);
-						RIfloat anew = 0.0f;
-						switch(operation)
-						{
-						case VG_UNION_MASK:		anew = 1.0f - (1.0f - amask)*(1.0f - aprev); break;
-						case VG_INTERSECT_MASK:	anew = amask * aprev; break;
-						default:				anew = aprev * (1.0f - amask); RI_ASSERT(operation == VG_SUBTRACT_MASK); break;
-						}
-						writeMaskCoverage(dx + i, dy + j, anew);
-					}
-				}
-			}
-		}
-		else
-		{
-			for(int j=0;j<h;j++)
-			{
-				for(int i=0;i<w;i++)
-				{
-					unsigned int amask = src->readMaskMSAA(sx + i, sy + j);
-					if(operation == VG_SET_MASK)
-						writeMaskMSAA(dx + i, dy + j, amask);
-					else
-					{
-						unsigned int aprev = readMaskMSAA(dx + i, dy + j);
-						unsigned int anew = 0;
-						switch(operation)
-						{
-						case VG_UNION_MASK:		anew = amask | aprev; break;
-						case VG_INTERSECT_MASK:	anew = amask & aprev; break;
-						default:				anew = ~amask & aprev; RI_ASSERT(operation == VG_SUBTRACT_MASK); break;
-						}
-						writeMaskMSAA(dx + i, dy + j, anew);
-					}
-				}
-			}
-		}
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-RIfloat Surface::readMaskCoverage(int x, int y) const
-{
-	RI_ASSERT(x >= 0 && x < m_width && y >= 0 && y < m_height);
-    RI_ASSERT(m_numSamples == 1);
-	return m_image->readMaskPixel(x, y);
-}
-
-void Surface::writeMaskCoverage(int x, int y, RIfloat m)
-{
-	RI_ASSERT(x >= 0 && x < m_width && y >= 0 && y < m_height);
-    RI_ASSERT(m_numSamples == 1);
-    m_image->writeMaskPixel(x, y, m);    //TODO support other than alpha formats but don't write to color channels?
-}
-
-unsigned int Surface::readMaskMSAA(int x, int y) const
-{
-	RI_ASSERT(x >= 0 && x < m_width && y >= 0 && y < m_height);
-    RI_ASSERT(m_numSamples > 1);
-    unsigned int m = 0;
-    for(int i=0;i<m_numSamples;i++)
-    {
-        if(m_image->readMaskPixel(x*m_numSamples+i, y) > 0.5f)   //TODO is this the right formula for converting alpha to bit mask? does it matter?
-            m |= 1<<i;
-    }
-    return m;
-}
-
-void Surface::writeMaskMSAA(int x, int y, unsigned int m)
-{
-	RI_ASSERT(x >= 0 && x < m_width && y >= 0 && y < m_height);
-    RI_ASSERT(m_numSamples > 1);
-    for(int i=0;i<m_numSamples;i++)
-    {
-        RIfloat a = 0.0f;
-        if(m & (1<<i))
-            a = 1.0f;
-        m_image->writeMaskPixel(x*m_numSamples+i, y, a);    //TODO support other than alpha formats but don't write to color channels?
-    }
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Color Surface::FSAAResolve(int x, int y) const
-{
-	if(m_numSamples == 1)
-		return readSample(x, y, 0);
-
-	Color::InternalFormat aaFormat = getDescriptor().isLuminance() ? Color::lLA_PRE : Color::lRGBA_PRE;	//antialias in linear color space
-	Color r(0.0f, 0.0f, 0.0f, 0.0f, aaFormat);
-	for(int i=0;i<m_numSamples;i++)
-	{
-		Color d = readSample(x, y, i);
-		d.convert(aaFormat);
-		r += d;
-	}
-	r *= 1.0f/m_numSamples;
-	return r;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Drawable::Drawable(const Color::Descriptor& desc, int width, int height, int numSamples, int maskBits) :
-	m_referenceCount(0),
-	m_color(NULL),
-	m_mask(NULL)
-{
-	RI_ASSERT(width > 0 && height > 0 && numSamples > 0 && numSamples <= 32);
-	RI_ASSERT(maskBits == 0 || maskBits == 1 || maskBits == 4 || maskBits == 8);
-    m_color = RI_NEW(Surface, (desc, width, height, numSamples));	//throws bad_alloc
-	m_color->addReference();
-    if(maskBits)
-    {
-        VGImageFormat mf = VG_A_1;
-        if(maskBits == 4)
-            mf = VG_A_4;
-        else if(maskBits == 8)
-            mf = VG_A_8;
-        m_mask = RI_NEW(Surface, (Color::formatToDescriptor(mf), width, height, numSamples));
-        m_mask->addReference();
-        m_mask->clear(Color(1,1,1,1,Color::sRGBA), 0, 0, width, height);
-    }
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Drawable::Drawable(Image* image, int maskBits) :
-	m_referenceCount(0),
-	m_color(NULL),
-	m_mask(NULL)
-{
-	RI_ASSERT(maskBits == 0 || maskBits == 1 || maskBits == 4 || maskBits == 8);
-	RI_ASSERT(image);
-    m_color = RI_NEW(Surface, (image));
-	m_color->addReference();
-    if(maskBits)
-    {
-        VGImageFormat mf = VG_A_1;
-        if(maskBits == 4)
-            mf = VG_A_4;
-        else if(maskBits == 8)
-            mf = VG_A_8;
-        m_mask = RI_NEW(Surface, (Color::formatToDescriptor(mf), image->getWidth(), image->getHeight(), 1));
-        m_mask->addReference();
-        m_mask->clear(Color(1,1,1,1,Color::sRGBA), 0, 0, image->getWidth(), image->getHeight());
-    }
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Drawable::Drawable(const Color::Descriptor& desc, int width, int height, int stride, RIuint8* data, int maskBits) :
-	m_referenceCount(0),
-	m_color(NULL),
-	m_mask(NULL)
-{
-	RI_ASSERT(width > 0 && height > 0);
-	RI_ASSERT(maskBits == 0 || maskBits == 1 || maskBits == 4 || maskBits == 8);
-	m_color = RI_NEW(Surface, (desc, width, height, stride, data));	//throws bad_alloc
-	m_color->addReference();
-    if(maskBits)
-    {
-        VGImageFormat mf = VG_A_1;
-        if(maskBits == 4)
-            mf = VG_A_4;
-        else if(maskBits == 8)
-            mf = VG_A_8;
-        m_mask = RI_NEW(Surface, (Color::formatToDescriptor(mf), width, height, 1));
-        m_mask->addReference();
-        m_mask->clear(Color(1,1,1,1,Color::sRGBA), 0, 0, width, height);
-    }
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Drawable::~Drawable()
-{
-	RI_ASSERT(m_referenceCount == 0);
-	if(!m_color->removeReference())
-		RI_DELETE(m_color);
-    if(m_mask)
-        if(!m_mask->removeReference())
-            RI_DELETE(m_mask);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Drawable::resize(int newWidth, int newHeight)
-{
-	Surface* oldcolor = m_color;
-	Surface* oldmask = m_mask;
-	int oldWidth = m_color->getWidth();
-	int oldHeight = m_color->getHeight();
-
-	//TODO check that image is not a proxy
-	m_color = RI_NEW(Surface, (m_color->getDescriptor(), newWidth, newHeight, m_color->getNumSamples()));
-	m_color->addReference();
-    if(m_mask)
-    {
-        m_mask = RI_NEW(Surface, (m_mask->getDescriptor(), newWidth, newHeight, m_mask->getNumSamples()));
-        m_mask->addReference();
-    }
-
-	int wmin = RI_INT_MIN(newWidth,oldWidth);
-	int hmin = RI_INT_MIN(newHeight,oldHeight);
-	m_color->clear(Color(0.0f, 0.0f, 0.0f, 0.0f, getDescriptor().internalFormat), 0, 0, m_color->getWidth(), m_color->getHeight());
-    m_color->blit(oldcolor, 0, 0, 0, 0, wmin, hmin);
-    if(m_mask)
-    {
-        m_mask->clear(Color(1.0f, 1.0f, 1.0f, 1.0f, getDescriptor().internalFormat), 0, 0, m_mask->getWidth(), m_mask->getHeight());
-        m_mask->blit(oldmask, 0, 0, 0, 0, wmin, hmin);
-    }
-
-	if(!oldcolor->removeReference())
-		RI_DELETE(oldcolor);
-    if(oldmask)
-        if(!oldmask->removeReference())
-            RI_DELETE(oldmask);
-}
-
-//==============================================================================================
-
-}	//namespace OpenVGRI
-
-//==============================================================================================
--- a/egl/sfopenvg/riImage.h	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,379 +0,0 @@
-#ifndef __RIIMAGE_H
-#define __RIIMAGE_H
-
-/*------------------------------------------------------------------------
- *
- * OpenVG 1.1 Reference Implementation
- * -----------------------------------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief	Color and Image classes.
- * \note	
- *//*-------------------------------------------------------------------*/
-
-#ifndef OPENVG_H
-#include "openvg.h"
-#endif
-
-#ifndef __RIMATH_H
-#include "riMath.h"
-#endif
-
-#ifndef __RIARRAY_H
-#include "riArray.h"
-#endif
-
-//==============================================================================================
-
-namespace OpenVGRI
-{
-
-/*-------------------------------------------------------------------*//*!
-* \brief	A class representing rectangles.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-class Rectangle
-{
-public:
-	Rectangle() : x(0), y(0), width(0), height(0) {}
-	Rectangle(int rx, int ry, int rw, int rh) : x(rx), y(ry), width(rw), height(rh) {}
-	void		intersect(const Rectangle& r)
-	{
-		if(width >= 0 && r.width >= 0 && height >= 0 && r.height >= 0)
-		{
-			int x1 = RI_INT_MIN(RI_INT_ADDSATURATE(x, width), RI_INT_ADDSATURATE(r.x, r.width));
-			x = RI_INT_MAX(x, r.x);
-			width = RI_INT_MAX(x1 - x, 0);
-
-			int y1 = RI_INT_MIN(RI_INT_ADDSATURATE(y, height), RI_INT_ADDSATURATE(r.y, r.height));
-			y = RI_INT_MAX(y, r.y);
-			height = RI_INT_MAX(y1 - y, 0);
-		}
-		else
-		{
-			x = 0;
-			y = 0;
-			width = 0;
-			height = 0;
-		}
-	}
-
-	int			x;
-	int			y;
-	int			width;
-	int			height;
-};
-
-/*-------------------------------------------------------------------*//*!
-* \brief	A class representing color for processing and converting it
-*			to and from various surface formats.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-class Color
-{
-public:
-	enum InternalFormat
-	{
-		lRGBA			= 0,
-		sRGBA			= 1,
-		lRGBA_PRE		= 2,
-		sRGBA_PRE		= 3,
-		lLA				= 4,
-		sLA				= 5,
-		lLA_PRE			= 6,
-		sLA_PRE			= 7
-	};
-	enum FormatBits
-	{
-		NONLINEAR		= (1<<0),
-		PREMULTIPLIED	= (1<<1),
-		LUMINANCE		= (1<<2)
-	};
-	class Descriptor
-	{
-    public:
-        bool                        isNonlinear() const                                 { return (internalFormat & NONLINEAR) ? true : false; }
-        bool                        isPremultiplied() const                             { return (internalFormat & PREMULTIPLIED) ? true : false; }
-        bool                        isLuminance() const                                 { return (internalFormat & LUMINANCE) ? true : false; }
-        bool                        isAlphaOnly() const                                 { return (alphaBits && (redBits+greenBits+blueBits+luminanceBits) == 0) ? true : false; }
-
-		int				redBits;
-		int				redShift;
-		int				greenBits;
-		int				greenShift;
-		int				blueBits;
-		int				blueShift;
-		int				alphaBits;
-		int				alphaShift;
-		int				luminanceBits;
-		int				luminanceShift;
-		VGImageFormat	format;
-		InternalFormat	internalFormat;
-		int				bitsPerPixel;
-	};
-
-	RI_INLINE Color() : r(0.0f), g(0.0f), b(0.0f), a(0.0f), m_format(lRGBA)													{}
-	RI_INLINE Color(RIfloat cl, RIfloat ca, InternalFormat cs) : r(cl), g(cl), b(cl), a(ca), m_format(cs)							{ RI_ASSERT(cs == lLA || cs == sLA || cs == lLA_PRE || cs == sLA_PRE); }
-	RI_INLINE Color(RIfloat cr, RIfloat cg, RIfloat cb, RIfloat ca, InternalFormat cs) : r(cr), g(cg), b(cb), a(ca), m_format(cs)	{ RI_ASSERT(cs == lRGBA || cs == sRGBA || cs == lRGBA_PRE || cs == sRGBA_PRE || cs == lLA || cs == sLA || cs == lLA_PRE || cs == sLA_PRE); }
-	RI_INLINE Color(const Color& c) : r(c.r), g(c.g), b(c.b), a(c.a), m_format(c.m_format)									{}
-	RI_INLINE Color& operator=(const Color&c)										{ r = c.r; g = c.g; b = c.b; a = c.a; m_format = c.m_format; return *this; }
-	RI_INLINE void operator*=(RIfloat f)											{ r *= f; g *= f; b *= f; a*= f; }
-	RI_INLINE void operator+=(const Color& c1)										{ RI_ASSERT(m_format == c1.getInternalFormat()); r += c1.r; g += c1.g; b += c1.b; a += c1.a; }
-	RI_INLINE void operator-=(const Color& c1)										{ RI_ASSERT(m_format == c1.getInternalFormat()); r -= c1.r; g -= c1.g; b -= c1.b; a -= c1.a; }
-
-	void						set(RIfloat cl, RIfloat ca, InternalFormat cs)							{ RI_ASSERT(cs == lLA || cs == sLA || cs == lLA_PRE || cs == sLA_PRE); r = cl; g = cl; b = cl; a = ca; m_format = cs; }
-	void						set(RIfloat cr, RIfloat cg, RIfloat cb, RIfloat ca, InternalFormat cs)	{ RI_ASSERT(cs == lRGBA || cs == sRGBA || cs == lRGBA_PRE || cs == sRGBA_PRE); r = cr; g = cg; b = cb; a = ca; m_format = cs; }
-	void						unpack(unsigned int inputData, const Descriptor& inputDesc);
-	unsigned int				pack(const Descriptor& outputDesc) const;
-	RI_INLINE InternalFormat	getInternalFormat() const							{ return m_format; }
-
-	//clamps nonpremultiplied colors and alpha to [0,1] range, and premultiplied alpha to [0,1], colors to [0,a]
-	void						clamp()												{ a = RI_CLAMP(a,0.0f,1.0f); RIfloat u = (m_format & PREMULTIPLIED) ? a : (RIfloat)1.0f; r = RI_CLAMP(r,0.0f,u); g = RI_CLAMP(g,0.0f,u); b = RI_CLAMP(b,0.0f,u); }
-	void						convert(InternalFormat outputFormat);
-	void						premultiply()										{ if(!(m_format & PREMULTIPLIED)) { r *= a; g *= a; b *= a; m_format = (InternalFormat)(m_format | PREMULTIPLIED); } }
-	void						unpremultiply()										{ if(m_format & PREMULTIPLIED) { RIfloat ooa = (a != 0.0f) ? 1.0f/a : (RIfloat)0.0f; r *= ooa; g *= ooa; b *= ooa; m_format = (InternalFormat)(m_format & ~PREMULTIPLIED); } }
-    void                        luminanceToRGB()                                    { if(m_format & LUMINANCE) { RI_ASSERT(r == g && g == b); m_format = (InternalFormat)(m_format & ~LUMINANCE); } }
-
-    bool                        isNonlinear() const                                 { return (m_format & NONLINEAR) ? true : false; }
-    bool                        isPremultiplied() const                             { return (m_format & PREMULTIPLIED) ? true : false; }
-    bool                        isLuminance() const                                 { return (m_format & LUMINANCE) ? true : false; }
-
-    RI_INLINE void              assertConsistency() const;
-
-	static Descriptor			formatToDescriptor(VGImageFormat format);
-	static bool					isValidDescriptor(const Descriptor& desc);
-
-	RIfloat		r;
-	RIfloat		g;
-	RIfloat		b;
-	RIfloat		a;
-private:
-	InternalFormat	m_format;
-};
-
-RI_INLINE Color operator*(const Color& c, RIfloat f)			{ return Color(c.r*f, c.g*f, c.b*f, c.a*f, c.getInternalFormat()); }
-RI_INLINE Color operator*(RIfloat f, const Color& c)			{ return Color(c.r*f, c.g*f, c.b*f, c.a*f, c.getInternalFormat()); }
-RI_INLINE Color operator+(const Color& c0, const Color& c1)		{ RI_ASSERT(c0.getInternalFormat() == c1.getInternalFormat()); return Color(c0.r+c1.r, c0.g+c1.g, c0.b+c1.b, c0.a+c1.a, c0.getInternalFormat()); }
-RI_INLINE Color operator-(const Color& c0, const Color& c1)		{ RI_ASSERT(c0.getInternalFormat() == c1.getInternalFormat()); return Color(c0.r-c1.r, c0.g-c1.g, c0.b-c1.b, c0.a-c1.a, c0.getInternalFormat()); }
-RI_INLINE void  Color::assertConsistency() const
-{
-	RI_ASSERT(r >= 0.0f && r <= 1.0f);
-	RI_ASSERT(g >= 0.0f && g <= 1.0f);
-	RI_ASSERT(b >= 0.0f && b <= 1.0f);
-	RI_ASSERT(a >= 0.0f && a <= 1.0f);
-	RI_ASSERT(!isPremultiplied() || (r <= a && g <= a && b <= a));	//premultiplied colors must have color channels less than or equal to alpha
-	RI_ASSERT((isLuminance() && r == g && r == b) || !isLuminance());	//if luminance, r=g=b
-}
-
-//==============================================================================================
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Storage and operations for VGImage.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-class Surface;
-class Image
-{
-public:
-	Image(const Color::Descriptor& desc, int width, int height, VGbitfield allowedQuality);	//throws bad_alloc
-	//use data from a memory buffer. NOTE: data is not copied, so it is user's responsibility to make sure the data remains valid while the Image is in use.
-	Image(const Color::Descriptor& desc, int width, int height, int stride, RIuint8* data);	//throws bad_alloc
-	//child image constructor
-	Image(Image* parent, int x, int y, int width, int height);	//throws bad_alloc
-	~Image();
-
-	const Color::Descriptor&	getDescriptor() const		{ return m_desc; }
-	int					getWidth() const					{ return m_width; }
-	int					getHeight() const					{ return m_height; }
-	int					getStride() const					{ return m_stride; }
-	Image*				getParent() const					{ return m_parent; }
-	VGbitfield			getAllowedQuality() const			{ return m_allowedQuality; }
-	void				addInUse()							{ m_inUse++; }
-	void				removeInUse()						{ RI_ASSERT(m_inUse > 0); m_inUse--; }
-	int					isInUse() const						{ return m_inUse; }
-	RIuint8*			getData() const						{ return m_data; }
-	void				addReference()						{ m_referenceCount++; }
-	int					removeReference()					{ m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
-	bool				overlaps(const Image* src) const;
-
-	void				clear(const Color& clearColor, int x, int y, int w, int h);
-	void				blit(const Image& src, int sx, int sy, int dx, int dy, int w, int h, bool dither);	//throws bad_alloc
-	void				blit(const Surface* src, int sx, int sy, int dx, int dy, int w, int h);	//throws bad_alloc
-
-	Color				readPixel(int x, int y) const;
-	void				writePixel(int x, int y, const Color& c);
-	void				writeFilteredPixel(int x, int y, const Color& c, VGbitfield channelMask);
-
-	RIfloat				readMaskPixel(int x, int y) const;		//can read any image format
-	void				writeMaskPixel(int x, int y, RIfloat m);	//can write only to VG_A_x
-
-	Color				resample(RIfloat x, RIfloat y, const Matrix3x3& surfaceToImage, VGImageQuality quality, VGTilingMode tilingMode, const Color& tileFillColor);	//throws bad_alloc
-	void				makeMipMaps();	//throws bad_alloc
-
-	void				colorMatrix(const Image& src, const RIfloat* matrix, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask);
-	void				convolve(const Image& src, int kernelWidth, int kernelHeight, int shiftX, int shiftY, const RIint16* kernel, RIfloat scale, RIfloat bias, VGTilingMode tilingMode, const Color& edgeFillColor, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask);
-	void				separableConvolve(const Image& src, int kernelWidth, int kernelHeight, int shiftX, int shiftY, const RIint16* kernelX, const RIint16* kernelY, RIfloat scale, RIfloat bias, VGTilingMode tilingMode, const Color& edgeFillColor, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask);
-	void				gaussianBlur(const Image& src, RIfloat stdDeviationX, RIfloat stdDeviationY, VGTilingMode tilingMode, const Color& edgeFillColor, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask);
-	void				lookup(const Image& src, const RIuint8 * redLUT, const RIuint8 * greenLUT, const RIuint8 * blueLUT, const RIuint8 * alphaLUT, bool outputLinear, bool outputPremultiplied, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask);
-	void				lookupSingle(const Image& src, const RIuint32 * lookupTable, VGImageChannel sourceChannel, bool outputLinear, bool outputPremultiplied, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask);
-private:
-	Image(const Image&);					//!< Not allowed.
-	void operator=(const Image&);			//!< Not allowed.
-
-	Color				readTexel(int u, int v, int level, VGTilingMode tilingMode, const Color& tileFillColor) const;
-
-	Color::Descriptor	m_desc;
-	int					m_width;
-	int					m_height;
-	VGbitfield			m_allowedQuality;
-	int					m_inUse;
-	int					m_stride;
-	RIuint8*			m_data;
-	int					m_referenceCount;
-	bool				m_ownsData;
-	Image*				m_parent;
-	int					m_storageOffsetX;
-	int					m_storageOffsetY;
-
-	bool				m_mipmapsValid;
-	Array<Image*>		m_mipmaps;
-};
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Surface class abstracting multisampled rendering surface.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-class Surface
-{
-public:
-	Surface(const Color::Descriptor& desc, int width, int height, int numSamples);	//throws bad_alloc
-	Surface(Image* image);	//throws bad_alloc
-	Surface(const Color::Descriptor& desc, int width, int height, int stride, RIuint8* data);	//throws bad_alloc
-	~Surface();
-
-	RI_INLINE const Color::Descriptor&	getDescriptor() const		{ return m_image->getDescriptor(); }
-	RI_INLINE int		getWidth() const							{ return m_width; }
-	RI_INLINE int		getHeight() const							{ return m_height; }
-	RI_INLINE int		getNumSamples() const						{ return m_numSamples; }
-	RI_INLINE void		addReference()								{ m_referenceCount++; }
-	RI_INLINE int		removeReference()							{ m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
-	RI_INLINE int		isInUse() const								{ return m_image->isInUse(); }
-	RI_INLINE bool		isInUse(Image* image) const					{ return image == m_image ? true : false; }
-
-	void				clear(const Color& clearColor, int x, int y, int w, int h);
-	void				clear(const Color& clearColor, int x, int y, int w, int h, const Array<Rectangle>& scissors);
-	void				blit(const Image& src, int sx, int sy, int dx, int dy, int w, int h);	//throws bad_alloc
-	void				blit(const Image& src, int sx, int sy, int dx, int dy, int w, int h, const Array<Rectangle>& scissors);	//throws bad_alloc
-	void				blit(const Surface* src, int sx, int sy, int dx, int dy, int w, int h);	//throws bad_alloc
-	void				blit(const Surface* src, int sx, int sy, int dx, int dy, int w, int h, const Array<Rectangle>& scissors);	//throws bad_alloc
-	void				mask(const Image* src, VGMaskOperation operation, int x, int y, int w, int h);
-	void				mask(const Surface* src, VGMaskOperation operation, int x, int y, int w, int h);
-
-	RI_INLINE Color		readSample(int x, int y, int sample) const                   { return m_image->readPixel(x*m_numSamples+sample, y); }
-	RI_INLINE void		writeSample(int x, int y, int sample, const Color& c)        { m_image->writePixel(x*m_numSamples+sample, y, c); }
-
-	RIfloat				readMaskCoverage(int x, int y) const;
-	void				writeMaskCoverage(int x, int y, RIfloat m);
-	unsigned int		readMaskMSAA(int x, int y) const;
-	void				writeMaskMSAA(int x, int y, unsigned int m);
-
-	Color				FSAAResolve(int x, int y) const;	//for fb=>img: vgGetPixels, vgReadPixels
-private:
-	Surface(const Surface&);			//!< Not allowed.
-	void operator=(const Surface&);			//!< Not allowed.
-
-	struct ScissorEdge
-	{
-		ScissorEdge() : x(0), miny(0), maxy(0), direction(0) {}
-		bool operator<(const ScissorEdge& e) const	{ return x < e.x; }
-		int			x;
-		int			miny;
-		int			maxy;
-		int			direction;		//1 start, -1 end
-	};
-
-	int				m_width;
-	int				m_height;
-	int				m_numSamples;
-	int				m_referenceCount;
-	Image*			m_image;
-};
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Drawable class for encapsulating color and mask buffers.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-class Drawable
-{
-public:
-	Drawable(const Color::Descriptor& desc, int width, int height, int numSamples, int maskBits);	//throws bad_alloc
-	Drawable(Image* image, int maskBits);	//throws bad_alloc
-	Drawable(const Color::Descriptor& desc, int width, int height, int stride, RIuint8* data, int maskBits);	//throws bad_alloc
-	~Drawable();
-
-	RI_INLINE const Color::Descriptor&	getDescriptor() const		{ return m_color->getDescriptor(); }
-    RI_INLINE int       getNumMaskBits() const                      { if(!m_mask) return 0; return m_mask->getDescriptor().alphaBits; }
-	RI_INLINE int		getWidth() const							{ return m_color->getWidth(); }
-	RI_INLINE int		getHeight() const							{ return m_color->getHeight(); }
-	RI_INLINE int		getNumSamples() const						{ return m_color->getNumSamples(); }
-	RI_INLINE void		addReference()								{ m_referenceCount++; }
-	RI_INLINE int		removeReference()							{ m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
-	RI_INLINE int		isInUse() const								{ return m_color->isInUse() || (m_mask && m_mask->isInUse()); }
-	RI_INLINE bool		isInUse(Image* image) const					{ return m_color->isInUse(image) || (m_mask && m_mask->isInUse(image)); }
-    RI_INLINE Surface*  getColorBuffer() const                      { return m_color; }
-    RI_INLINE Surface*  getMaskBuffer() const                       { return m_mask; }
-
-	void				resize(int newWidth, int newHeight);	//throws bad_alloc
-private:
-    Drawable(const Drawable&);			//!< Not allowed.
-    void operator=(const Drawable&);	//!< Not allowed.
-
-	int                 m_referenceCount;
-	Surface*			m_color;
-	Surface*            m_mask;
-};
-
-//==============================================================================================
-
-}	//namespace OpenVGRI
-
-//==============================================================================================
-
-#endif /* __RIIMAGE_H */
--- a/egl/sfopenvg/riMath.cpp	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,75 +0,0 @@
-/*------------------------------------------------------------------------
- *
- * OpenVG 1.1 Reference Implementation
- * -----------------------------------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief	Implementation of non-inline matrix functions.
- * \note	
- *//*-------------------------------------------------------------------*/
-
-#include "riDefs.h"
-#include "riMath.h"
-
-namespace OpenVGRI
-{
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Inverts a 3x3 matrix. Returns false if the matrix is singular.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-bool Matrix3x3::invert()
-{
-	bool affine = isAffine();
-	RIfloat det00 = matrix[1][1]*matrix[2][2] - matrix[2][1]*matrix[1][2];
-	RIfloat det01 = matrix[2][0]*matrix[1][2] - matrix[1][0]*matrix[2][2];
-	RIfloat det02 = matrix[1][0]*matrix[2][1] - matrix[2][0]*matrix[1][1];
-
-	RIfloat d = matrix[0][0]*det00 + matrix[0][1]*det01 + matrix[0][2]*det02;
-	if( d == 0.0f ) return false;	//singular, leave the matrix unmodified and return false
-	d = 1.0f / d;
-
-	Matrix3x3 t;
-	t[0][0] = d * det00;
-	t[1][0] = d * det01;
-	t[2][0] = d * det02;
-	t[0][1] = d * (matrix[2][1]*matrix[0][2] - matrix[0][1]*matrix[2][2]);
-	t[1][1] = d * (matrix[0][0]*matrix[2][2] - matrix[2][0]*matrix[0][2]);
-	t[2][1] = d * (matrix[2][0]*matrix[0][1] - matrix[0][0]*matrix[2][1]);
-	t[0][2] = d * (matrix[0][1]*matrix[1][2] - matrix[1][1]*matrix[0][2]);
-	t[1][2] = d * (matrix[1][0]*matrix[0][2] - matrix[0][0]*matrix[1][2]);
-	t[2][2] = d * (matrix[0][0]*matrix[1][1] - matrix[1][0]*matrix[0][1]);
-	if(affine)
-		t[2].set(0,0,1);	//affine matrix stays affine
-	*this = t;
-	return true;
-}
-
-//==============================================================================================
-
-}	//namespace OpenVGRI
--- a/egl/sfopenvg/riMath.h	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,382 +0,0 @@
-#ifndef __RIMATH_H
-#define __RIMATH_H
-
-/*------------------------------------------------------------------------
- *
- * OpenVG 1.1 Reference Implementation
- * -----------------------------------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief	Math functions, Vector and Matrix classes.
- * \note	
- *//*-------------------------------------------------------------------*/
-
-#ifndef __RIDEFS_H
-#include "riDefs.h"
-#endif
-
-#include <math.h>
-
-namespace OpenVGRI
-{
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-RI_INLINE int		RI_ISNAN(float a)
-{
-	RIfloatInt p;
-	p.f = a;
-	unsigned int exponent = (p.i>>23) & 0xff;
-	unsigned int mantissa = p.i & 0x7fffff;
-	if(exponent == 255 && mantissa)
-		return 1;
-	return 0;
-}
-
-#if (RI_MANTISSA_BITS > 23)
-#error RI_MANTISSA_BITS is greater than 23
-#elif (RI_EXPONENT_BITS > 8)
-#error RI_EXPONENT_BITS is greater than 8
-#elif (RI_MANTISSA_BITS != 23) || (RI_EXPONENT_BITS != 8)
-
-class RIfloat
-{
-public:
-	RIfloat() : v(0.0f)						{ removeBits(); }
-	RIfloat(float a) : v(a)					{ removeBits(); }
-	RIfloat(double a) : v((float)a)			{ removeBits(); }
-	RIfloat(int a) : v((float)a)			{ removeBits(); }
-	RIfloat(unsigned int a) : v((float)a)	{ removeBits(); }
-	RIfloat&	operator=(const RIfloat &a)	{ v = a.v; removeBits(); return *this; }
-	RIfloat&	operator+=(const RIfloat &a){ v += a.v; removeBits(); return *this; }
-	RIfloat&	operator-=(const RIfloat &a){ v -= a.v; removeBits(); return *this; }
-	RIfloat&	operator*=(const RIfloat &a){ v *= a.v; removeBits(); return *this; }
-	RIfloat&	operator/=(const RIfloat &a){ v /= a.v; removeBits(); return *this; }
-	RIfloat		operator-() const			{ return -v; }
-	operator float() const					{ return v; }
-	operator double() const					{ return (double)v; }
-	operator int() const					{ return (int)v; }
-
-	friend RIfloat	operator+(const RIfloat &a, const RIfloat &b);
-	friend RIfloat	operator+(float a, const RIfloat &b);
-	friend RIfloat	operator+(const RIfloat &a, float b);
-	friend RIfloat	operator-(const RIfloat &a, const RIfloat &b);
-	friend RIfloat	operator-(float a, const RIfloat &b);
-	friend RIfloat	operator-(const RIfloat &a, float b);
-	friend RIfloat	operator*(const RIfloat &a, const RIfloat &b);
-	friend RIfloat	operator*(float a, const RIfloat &b);
-	friend RIfloat	operator*(const RIfloat &a, float b);
-	friend RIfloat	operator/(const RIfloat &a, const RIfloat &b);
-	friend RIfloat	operator/(float a, const RIfloat &b);
-	friend RIfloat	operator/(const RIfloat &a, float b);
-
-	friend bool		operator<(const RIfloat &a, const RIfloat &b);
-	friend bool		operator<(float a, const RIfloat &b);
-	friend bool		operator<(const RIfloat &a, float b);
-	friend bool		operator>(const RIfloat &a, const RIfloat &b);
-	friend bool		operator>(float a, const RIfloat &b);
-	friend bool		operator>(const RIfloat &a, float b);
-	friend bool		operator<=(const RIfloat &a, const RIfloat &b);
-	friend bool		operator<=(float a, const RIfloat &b);
-	friend bool		operator<=(const RIfloat &a, float b);
-	friend bool		operator>=(const RIfloat &a, const RIfloat &b);
-	friend bool		operator>=(float a, const RIfloat &b);
-	friend bool		operator>=(const RIfloat &a, float b);
-	friend bool		operator==(const RIfloat &a, const RIfloat &b);
-	friend bool		operator==(float a, const RIfloat &b);
-	friend bool		operator==(const RIfloat &a, float b);
-	friend bool		operator!=(const RIfloat &a, const RIfloat &b);
-	friend bool		operator!=(float a, const RIfloat &b);
-	friend bool		operator!=(const RIfloat &a, float b);
-private:
-	void	removeBits()
-	{
-		RIfloatInt p;
-		p.f = v;
-		unsigned int exponent = (p.i>>23) & 0xff;
-		if(exponent == 0 || exponent == 255)
-			return;	//zero, denormal, infinite, or NaN
-
-		p.i &= ~((1<<(23-RI_MANTISSA_BITS))-1);
-
-#if (RI_EXPONENT_BITS != 8)
-		if (exponent > 127 + (1 << (RI_EXPONENT_BITS-1)))
-			exponent = 127 + (1 << (RI_EXPONENT_BITS-1));
-
-		if (exponent < 127 + 1 - (1 << (RI_EXPONENT_BITS-1)))
-			exponent = 127 + 1 - (1 << (RI_EXPONENT_BITS-1));
-
-		p.i &= ~(0xff<<23);
-		p.i |= exponent<<23;
-#endif
-		v = p.f;
-	}
-
-	float		v;
-};
-
-RI_INLINE RIfloat operator+(const RIfloat &a, const RIfloat &b)	{ return RIfloat(a.v+b.v); }
-RI_INLINE RIfloat operator+(float a, const RIfloat &b)			{ return RIfloat(a+b.v); }
-RI_INLINE RIfloat operator+(const RIfloat &a, float b)			{ return RIfloat(a.v+b); }
-RI_INLINE RIfloat operator-(const RIfloat &a, const RIfloat &b)	{ return RIfloat(a.v-b.v); }
-RI_INLINE RIfloat operator-(float a, const RIfloat &b)			{ return RIfloat(a-b.v); }
-RI_INLINE RIfloat operator-(const RIfloat &a, float b)			{ return RIfloat(a.v-b); }
-RI_INLINE RIfloat operator*(const RIfloat &a, const RIfloat &b)	{ return RIfloat(a.v*b.v); }
-RI_INLINE RIfloat operator*(float a, const RIfloat &b)			{ return RIfloat(a*b.v); }
-RI_INLINE RIfloat operator*(const RIfloat &a, float b)			{ return RIfloat(a.v*b); }
-RI_INLINE RIfloat operator/(const RIfloat &a, const RIfloat &b)	{ return RIfloat(a.v/b.v); }
-RI_INLINE RIfloat operator/(float a, const RIfloat &b)			{ return RIfloat(a/b.v); }
-RI_INLINE RIfloat operator/(const RIfloat &a, float b)			{ return RIfloat(a.v/b); }
-
-RI_INLINE bool operator<(const RIfloat &a, const RIfloat &b)	{ return a.v < b.v ? true : false; }
-RI_INLINE bool operator<(float a, const RIfloat &b)				{ return a < b.v ? true : false; }
-RI_INLINE bool operator<(const RIfloat &a, float b)				{ return a.v < b ? true : false; }
-RI_INLINE bool operator>(const RIfloat &a, const RIfloat &b)	{ return a.v > b.v ? true : false; }
-RI_INLINE bool operator>(float a, const RIfloat &b)				{ return a > b.v ? true : false; }
-RI_INLINE bool operator>(const RIfloat &a, float b)				{ return a.v > b ? true : false; }
-RI_INLINE bool operator<=(const RIfloat &a, const RIfloat &b)	{ return a.v <= b.v ? true : false; }
-RI_INLINE bool operator<=(float a, const RIfloat &b)			{ return a <= b.v ? true : false; }
-RI_INLINE bool operator<=(const RIfloat &a, float b)			{ return a.v <= b ? true : false; }
-RI_INLINE bool operator>=(const RIfloat &a, const RIfloat &b)	{ return a.v >= b.v ? true : false; }
-RI_INLINE bool operator>=(float a, const RIfloat &b)			{ return a >= b.v ? true : false; }
-RI_INLINE bool operator>=(const RIfloat &a, float b)			{ return a.v >= b ? true : false; }
-RI_INLINE bool operator==(const RIfloat &a, const RIfloat &b)	{ return a.v == b.v ? true : false; }
-RI_INLINE bool operator==(float a, const RIfloat &b)			{ return a == b.v ? true : false; }
-RI_INLINE bool operator==(const RIfloat &a, float b)			{ return a.v == b ? true : false; }
-RI_INLINE bool operator!=(const RIfloat &a, const RIfloat &b)	{ return a.v != b.v ? true : false; }
-RI_INLINE bool operator!=(float a, const RIfloat &b)			{ return a != b.v ? true : false; }
-RI_INLINE bool operator!=(const RIfloat &a, float b)			{ return a.v != b ? true : false; }
-
-#else
-typedef float RIfloat;
-#endif
-
-#define	PI						3.141592654f
-
-RI_INLINE RIfloat	RI_MAX(RIfloat a, RIfloat b)				{ return (a > b) ? a : b; }
-RI_INLINE RIfloat	RI_MIN(RIfloat a, RIfloat b)				{ return (a < b) ? a : b; }
-RI_INLINE RIfloat	RI_CLAMP(RIfloat a, RIfloat l, RIfloat h)	{ if(RI_ISNAN(a)) return l; RI_ASSERT(l <= h); return (a < l) ? l : (a > h) ? h : a; }
-RI_INLINE void		RI_SWAP(RIfloat &a, RIfloat &b)				{ RIfloat tmp = a; a = b; b = tmp; }
-RI_INLINE RIfloat	RI_ABS(RIfloat a)							{ return (a < 0.0f) ? -a : a; }
-RI_INLINE RIfloat	RI_SQR(RIfloat a)							{ return a * a; }
-RI_INLINE RIfloat	RI_DEG_TO_RAD(RIfloat a)					{ return a * PI / 180.0f; }
-RI_INLINE RIfloat	RI_RAD_TO_DEG(RIfloat a)					{ return a * 180.0f/ PI; }
-RI_INLINE RIfloat	RI_MOD(RIfloat a, RIfloat b)				{ if(RI_ISNAN(a) || RI_ISNAN(b)) return 0.0f; RI_ASSERT(b >= 0.0f); if(b == 0.0f) return 0.0f; RIfloat f = (RIfloat)fmod(a, b); if(f < 0.0f) f += b; RI_ASSERT(f >= 0.0f && f <= b); return f; }
-
-RI_INLINE int		RI_INT_MAX(int a, int b)			{ return (a > b) ? a : b; }
-RI_INLINE int		RI_INT_MIN(int a, int b)			{ return (a < b) ? a : b; }
-RI_INLINE void		RI_INT_SWAP(int &a, int &b)			{ int tmp = a; a = b; b = tmp; }
-RI_INLINE int		RI_INT_MOD(int a, int b)			{ RI_ASSERT(b >= 0); if(!b) return 0; int i = a % b; if(i < 0) i += b; RI_ASSERT(i >= 0 && i < b); return i; }
-RI_INLINE int		RI_INT_ADDSATURATE(int a, int b)	{ RI_ASSERT(b >= 0); int r = a + b; return (r >= a) ? r : RI_INT32_MAX; }
-
-class Matrix3x3;
-class Vector2;
-class Vector3;
-
-//==============================================================================================
-
-//MatrixRxC, R = number of rows, C = number of columns
-//indexing: matrix[row][column]
-//Matrix3x3 inline functions cannot be inside the class because Vector3 is not defined yet when Matrix3x3 is defined
-
-class Matrix3x3
-{
-public:
-	RI_INLINE					Matrix3x3		();						//initialized to identity
-	RI_INLINE					Matrix3x3		( const Matrix3x3& m );
-	RI_INLINE					Matrix3x3		( RIfloat m00, RIfloat m01, RIfloat m02, RIfloat m10, RIfloat m11, RIfloat m12, RIfloat m20, RIfloat m21, RIfloat m22 );
-	RI_INLINE					~Matrix3x3		();
-	RI_INLINE Matrix3x3&		operator=		( const Matrix3x3& m );
-	RI_INLINE Vector3&			operator[]		( int i );				//returns a row vector
-	RI_INLINE const Vector3&	operator[]		( int i ) const;
-	RI_INLINE void				set				( RIfloat m00, RIfloat m01, RIfloat m02, RIfloat m10, RIfloat m11, RIfloat m12, RIfloat m20, RIfloat m21, RIfloat m22 );
-	RI_INLINE const Vector3		getRow			( int i ) const;
-	RI_INLINE const Vector3		getColumn		( int i ) const;
-	RI_INLINE void				setRow			( int i, const Vector3& v );
-	RI_INLINE void				setColumn		( int i, const Vector3& v );
-	RI_INLINE void				operator*=		( const Matrix3x3& m );
-	RI_INLINE void				operator*=		( RIfloat f );
-	RI_INLINE void				operator+=		( const Matrix3x3& m );
-	RI_INLINE void				operator-=		( const Matrix3x3& m );
-	RI_INLINE const Matrix3x3	operator-		() const;
-	RI_INLINE void				identity		();
-	RI_INLINE void				transpose		();
-	bool						invert			();	//if the matrix is singular, returns false and leaves it unmodified
-	RI_INLINE RIfloat				det				() const;
-	RI_INLINE bool				isAffine		() const;
-
-private:
-	RIfloat						matrix[3][3];
-};
-
-//==============================================================================================
-
-class Vector2
-{
-public:
-	RI_INLINE					Vector2			() : x(0.0f), y(0.0f)					{}
-	RI_INLINE					Vector2			( const Vector2& v ) : x(v.x), y(v.y)	{}
-	RI_INLINE					Vector2			( RIfloat fx, RIfloat fy ) : x(fx), y(fy)	{}
-	RI_INLINE					~Vector2		()								{}
-	RI_INLINE Vector2&			operator=		( const Vector2& v )			{ x = v.x; y = v.y; return *this; }
-	RI_INLINE RIfloat&			operator[]		( int i )						{ RI_ASSERT(i>=0&&i<2); return (&x)[i]; }
-	RI_INLINE const RIfloat&	operator[]		( int i ) const					{ RI_ASSERT(i>=0&&i<2); return (&x)[i]; }
-	RI_INLINE void				set				( RIfloat fx, RIfloat fy )			{ x = fx; y = fy; }
-	RI_INLINE void				operator*=		( RIfloat f )						{ x *= f; y *= f; }
-	RI_INLINE void				operator+=		( const Vector2& v )			{ x += v.x; y += v.y; }
-	RI_INLINE void				operator-=		( const Vector2& v )			{ x -= v.x; y -= v.y; }
-	RI_INLINE const Vector2		operator-		() const						{ return Vector2(-x,-y); }
-	//if the vector is zero, returns false and leaves it unmodified
-	RI_INLINE bool				normalize		()								{ double l = (double)x*(double)x+(double)y*(double)y; if( l == 0.0 ) return false; l = 1.0 / sqrt(l); x = (RIfloat)((double)x * l); y = (RIfloat)((double)y * l); return true; }
-	RI_INLINE RIfloat			length			() const						{ return (RIfloat)sqrt((double)x*(double)x+(double)y*(double)y); }
-	RI_INLINE void				scale			( const Vector2& v )			{ x *= v.x; y *= v.y; }	//component-wise scale
-	RI_INLINE void				negate			()								{ x = -x; y = -y; }
-
-	RIfloat						x,y;
-};
-
-//==============================================================================================
-
-class Vector3
-{
-public:
-	RI_INLINE					Vector3			() : x(0.0f), y(0.0f), z(0.0f)							{}
-	RI_INLINE					Vector3			( const Vector3& v ) : x(v.x), y(v.y), z(v.z)			{}
-	RI_INLINE					Vector3			( RIfloat fx, RIfloat fy, RIfloat fz ) : x(fx), y(fy), z(fz)	{}
-	RI_INLINE					~Vector3		()								{}
-	RI_INLINE Vector3&			operator=		( const Vector3& v )			{ x = v.x; y = v.y; z = v.z; return *this; }
-	RI_INLINE RIfloat&			operator[]		( int i )						{ RI_ASSERT(i>=0&&i<3); return (&x)[i]; }
-	RI_INLINE const RIfloat&	operator[]		( int i ) const					{ RI_ASSERT(i>=0&&i<3); return (&x)[i]; }
-	RI_INLINE void				set				( RIfloat fx, RIfloat fy, RIfloat fz ){ x = fx; y = fy; z = fz; }
-	RI_INLINE void				operator*=		( RIfloat f )						{ x *= f; y *= f; z *= f; }
-	RI_INLINE void				operator+=		( const Vector3& v )			{ x += v.x; y += v.y; z += v.z; }
-	RI_INLINE void				operator-=		( const Vector3& v )			{ x -= v.x; y -= v.y; z -= v.z; }
-	RI_INLINE const Vector3		operator-		() const						{ return Vector3(-x,-y,-z); }
-	//if the vector is zero, returns false and leaves it unmodified
-	RI_INLINE bool				normalize		()								{ double l = (double)x*(double)x+(double)y*(double)y+(double)z*(double)z; if( l == 0.0 ) return false; l = 1.0 / sqrt(l); x = (RIfloat)((double)x * l); y = (RIfloat)((double)y * l); z = (RIfloat)((double)z * l); return true; }
-	RI_INLINE RIfloat			length			() const						{ return (RIfloat)sqrt((double)x*(double)x+(double)y*(double)y+(double)z*(double)z); }
-	RI_INLINE void				scale			( const Vector3& v )			{ x *= v.x; y *= v.y; z *= v.z; }	//component-wise scale
-	RI_INLINE void				negate			()								{ x = -x; y = -y; z = -z; }
-
-	RIfloat						x,y,z;
-};
-
-//==============================================================================================
-
-//Vector2 global functions
-RI_INLINE bool			operator==	( const Vector2& v1, const Vector2& v2 )	{ return (v1.x == v2.x) && (v1.y == v2.y); }
-RI_INLINE bool			operator!=	( const Vector2& v1, const Vector2& v2 )	{ return (v1.x != v2.x) || (v1.y != v2.y); }
-RI_INLINE bool			isEqual		( const Vector2& v1, const Vector2& v2, RIfloat epsilon )	{ return RI_SQR(v2.x-v1.x) + RI_SQR(v2.y-v1.y) <= epsilon*epsilon; }
-RI_INLINE bool			isZero		( const Vector2& v )						{ return (v.x == 0.0f) && (v.y == 0.0f); }
-RI_INLINE const Vector2	operator*	( RIfloat f, const Vector2& v )				{ return Vector2(v.x*f,v.y*f); }
-RI_INLINE const Vector2	operator*	( const Vector2& v, RIfloat f )				{ return Vector2(v.x*f,v.y*f); }
-RI_INLINE const Vector2	operator+	( const Vector2& v1, const Vector2& v2 )	{ return Vector2(v1.x+v2.x, v1.y+v2.y); }
-RI_INLINE const Vector2	operator-	( const Vector2& v1, const Vector2& v2 )	{ return Vector2(v1.x-v2.x, v1.y-v2.y); }
-RI_INLINE RIfloat		dot			( const Vector2& v1, const Vector2& v2 )	{ return v1.x*v2.x+v1.y*v2.y; }
-//if v is a zero vector, returns a zero vector
-RI_INLINE const Vector2	normalize	( const Vector2& v )						{ double l = (double)v.x*(double)v.x+(double)v.y*(double)v.y; if( l != 0.0 ) l = 1.0 / sqrt(l); return Vector2((RIfloat)((double)v.x * l), (RIfloat)((double)v.y * l)); }
-//if onThis is a zero vector, returns a zero vector
-RI_INLINE const Vector2	project		( const Vector2& v, const Vector2& onThis ) { RIfloat l = dot(onThis,onThis); if( l != 0.0f ) l = dot(v, onThis)/l; return onThis * l; }
-RI_INLINE const Vector2	lerp		( const Vector2& v1, const Vector2& v2, RIfloat ratio )	{ return v1 + ratio * (v2 - v1); }
-RI_INLINE const Vector2	scale		( const Vector2& v1, const Vector2& v2 )	{ return Vector2(v1.x*v2.x, v1.y*v2.y); }
-//matrix * column vector. The input vector2 is implicitly expanded to (x,y,1)
-RI_INLINE const Vector2 affineTransform( const Matrix3x3& m, const Vector2& v )	{ RI_ASSERT(m.isAffine()); return Vector2(v.x * m[0][0] + v.y * m[0][1] + m[0][2], v.x * m[1][0] + v.y * m[1][1] + m[1][2]); }
-//matrix * column vector. The input vector2 is implicitly expanded to (x,y,0)
-RI_INLINE const Vector2 affineTangentTransform(const Matrix3x3& m, const Vector2& v)	{ RI_ASSERT(m.isAffine()); return Vector2(v.x * m[0][0] + v.y * m[0][1], v.x * m[1][0] + v.y * m[1][1]); }
-RI_INLINE const Vector2 perpendicularCW(const Vector2& v)						{ return Vector2(v.y, -v.x); }
-RI_INLINE const Vector2 perpendicularCCW(const Vector2& v)						{ return Vector2(-v.y, v.x); }
-RI_INLINE const Vector2 perpendicular(const Vector2& v, bool cw)				{ if(cw) return Vector2(v.y, -v.x); return Vector2(-v.y, v.x); }
-
-//==============================================================================================
-
-//Vector3 global functions
-RI_INLINE bool			operator==	( const Vector3& v1, const Vector3& v2 )	{ return (v1.x == v2.x) && (v1.y == v2.y) && (v1.z == v2.z); }
-RI_INLINE bool			operator!=	( const Vector3& v1, const Vector3& v2 )	{ return (v1.x != v2.x) || (v1.y != v2.y) || (v1.z != v2.z); }
-RI_INLINE bool			isEqual		( const Vector3& v1, const Vector3& v2, RIfloat epsilon )	{ return RI_SQR(v2.x-v1.x) + RI_SQR(v2.y-v1.y) + RI_SQR(v2.z-v1.z) <= epsilon*epsilon; }
-RI_INLINE const Vector3	operator*	( RIfloat f, const Vector3& v )				{ return Vector3(v.x*f,v.y*f,v.z*f); }
-RI_INLINE const Vector3	operator*	( const Vector3& v, RIfloat f )				{ return Vector3(v.x*f,v.y*f,v.z*f); }
-RI_INLINE const Vector3	operator+	( const Vector3& v1, const Vector3& v2 )	{ return Vector3(v1.x+v2.x, v1.y+v2.y, v1.z+v2.z); }
-RI_INLINE const Vector3	operator-	( const Vector3& v1, const Vector3& v2 )	{ return Vector3(v1.x-v2.x, v1.y-v2.y, v1.z-v2.z); }
-RI_INLINE RIfloat		dot			( const Vector3& v1, const Vector3& v2 )	{ return v1.x*v2.x+v1.y*v2.y+v1.z*v2.z; }
-RI_INLINE const Vector3	cross		( const Vector3& v1, const Vector3& v2 )	{ return Vector3( v1.y*v2.z-v1.z*v2.y, v1.z*v2.x-v1.x*v2.z, v1.x*v2.y-v1.y*v2.x ); }
-//if v is a zero vector, returns a zero vector
-RI_INLINE const Vector3	normalize	( const Vector3& v )						{ double l = (double)v.x*(double)v.x+(double)v.y*(double)v.y+(double)v.z*(double)v.z; if( l != 0.0 ) l = 1.0 / sqrt(l); return Vector3((RIfloat)((double)v.x * l), (RIfloat)((double)v.y * l), (RIfloat)((double)v.z * l)); }
-RI_INLINE const Vector3	lerp		( const Vector3& v1, const Vector3& v2, RIfloat ratio )	{ return v1 + ratio * (v2 - v1); }
-RI_INLINE const Vector3	scale		( const Vector3& v1, const Vector3& v2 )	{ return Vector3(v1.x*v2.x, v1.y*v2.y, v1.z*v2.z); }
-
-//==============================================================================================
-
-//matrix * column vector
-RI_INLINE const Vector3	operator*	( const Matrix3x3& m, const Vector3& v)		{ return Vector3( v.x*m[0][0]+v.y*m[0][1]+v.z*m[0][2], v.x*m[1][0]+v.y*m[1][1]+v.z*m[1][2], v.x*m[2][0]+v.y*m[2][1]+v.z*m[2][2] ); }
-
-//==============================================================================================
-
-//Matrix3x3 global functions
-RI_INLINE bool				operator==	( const Matrix3x3& m1, const Matrix3x3& m2 )	{ for(int i=0;i<3;i++) for(int j=0;j<3;j++) if( m1[i][j] != m2[i][j] ) return false; return true; }
-RI_INLINE bool				operator!=	( const Matrix3x3& m1, const Matrix3x3& m2 )	{ return !(m1 == m2); }
-RI_INLINE const Matrix3x3	operator*	( const Matrix3x3& m1, const Matrix3x3& m2 )	{ Matrix3x3 t; for(int i=0;i<3;i++) for(int j=0;j<3;j++) t[i][j] = m1[i][0] * m2[0][j] + m1[i][1] * m2[1][j] + m1[i][2] * m2[2][j]; return t; }
-RI_INLINE const Matrix3x3	operator*	( RIfloat f, const Matrix3x3& m )					{ Matrix3x3 t(m); t *= f; return t; }
-RI_INLINE const Matrix3x3	operator*	( const Matrix3x3& m, RIfloat f )					{ Matrix3x3 t(m); t *= f; return t; }
-RI_INLINE const Matrix3x3	operator+	( const Matrix3x3& m1, const Matrix3x3& m2 )	{ Matrix3x3 t(m1); t += m2; return t; }
-RI_INLINE const Matrix3x3	operator-	( const Matrix3x3& m1, const Matrix3x3& m2 )	{ Matrix3x3 t(m1); t -= m2; return t; }
-RI_INLINE const Matrix3x3	transpose	( const Matrix3x3& m )							{ Matrix3x3 t(m); t.transpose(); return t; }
-// if the matrix is singular, returns it unmodified
-RI_INLINE const Matrix3x3	invert		( const Matrix3x3& m )							{ Matrix3x3 t(m); t.invert(); return t; }
-
-//==============================================================================================
-
-//Matrix3x3 inline functions (cannot be inside the class because Vector3 is not defined yet when Matrix3x3 is defined)
-RI_INLINE					Matrix3x3::Matrix3x3	()									{ identity(); }
-RI_INLINE					Matrix3x3::Matrix3x3	( const Matrix3x3& m )				{ *this = m; }
-RI_INLINE					Matrix3x3::Matrix3x3	( RIfloat m00, RIfloat m01, RIfloat m02, RIfloat m10, RIfloat m11, RIfloat m12, RIfloat m20, RIfloat m21, RIfloat m22 )	{ set(m00,m01,m02,m10,m11,m12,m20,m21,m22); }
-RI_INLINE					Matrix3x3::~Matrix3x3	()									{}
-RI_INLINE Matrix3x3&		Matrix3x3::operator=	( const Matrix3x3& m )				{ for(int i=0;i<3;i++) for(int j=0;j<3;j++) matrix[i][j] = m.matrix[i][j]; return *this; }
-RI_INLINE Vector3&			Matrix3x3::operator[]	( int i )							{ RI_ASSERT(i>=0&&i<3); return (Vector3&)matrix[i][0]; }
-RI_INLINE const Vector3&	Matrix3x3::operator[]	( int i ) const						{ RI_ASSERT(i>=0&&i<3); return (const Vector3&)matrix[i][0]; }
-RI_INLINE void				Matrix3x3::set			( RIfloat m00, RIfloat m01, RIfloat m02, RIfloat m10, RIfloat m11, RIfloat m12, RIfloat m20, RIfloat m21, RIfloat m22 ) { matrix[0][0] = m00; matrix[0][1] = m01; matrix[0][2] = m02; matrix[1][0] = m10; matrix[1][1] = m11; matrix[1][2] = m12; matrix[2][0] = m20; matrix[2][1] = m21; matrix[2][2] = m22; }
-RI_INLINE const Vector3		Matrix3x3::getRow		( int i ) const						{ RI_ASSERT(i>=0&&i<3); return Vector3(matrix[i][0], matrix[i][1], matrix[i][2]); }
-RI_INLINE const Vector3		Matrix3x3::getColumn	( int i ) const						{ RI_ASSERT(i>=0&&i<3); return Vector3(matrix[0][i], matrix[1][i], matrix[2][i]); }
-RI_INLINE void				Matrix3x3::setRow		( int i, const Vector3& v )			{ RI_ASSERT(i>=0&&i<3); matrix[i][0] = v.x; matrix[i][1] = v.y; matrix[i][2] = v.z; }
-RI_INLINE void				Matrix3x3::setColumn	( int i, const Vector3& v )			{ RI_ASSERT(i>=0&&i<3); matrix[0][i] = v.x; matrix[1][i] = v.y; matrix[2][i] = v.z; }
-RI_INLINE void				Matrix3x3::operator*=	( const Matrix3x3& m )				{ *this = *this * m; }
-RI_INLINE void				Matrix3x3::operator*=	( RIfloat f )							{ for(int i=0;i<3;i++) for(int j=0;j<3;j++) matrix[i][j] *= f; }
-RI_INLINE void				Matrix3x3::operator+=	( const Matrix3x3& m )				{ for(int i=0;i<3;i++) for(int j=0;j<3;j++) matrix[i][j] += m.matrix[i][j]; }
-RI_INLINE void				Matrix3x3::operator-=	( const Matrix3x3& m )				{ for(int i=0;i<3;i++) for(int j=0;j<3;j++) matrix[i][j] -= m.matrix[i][j]; }
-RI_INLINE const Matrix3x3	Matrix3x3::operator-	() const							{ return Matrix3x3( -matrix[0][0],-matrix[0][1],-matrix[0][2], -matrix[1][0],-matrix[1][1],-matrix[1][2], -matrix[2][0],-matrix[2][1],-matrix[2][2]); }
-RI_INLINE void				Matrix3x3::identity		()									{ for(int i=0;i<3;i++) for(int j=0;j<3;j++) matrix[i][j] = (i == j) ? 1.0f : 0.0f; }
-RI_INLINE void				Matrix3x3::transpose	()									{ RI_SWAP(matrix[1][0], matrix[0][1]); RI_SWAP(matrix[2][0], matrix[0][2]); RI_SWAP(matrix[2][1], matrix[1][2]); }
-RI_INLINE RIfloat			Matrix3x3::det			() const							{ return matrix[0][0] * (matrix[1][1]*matrix[2][2] - matrix[2][1]*matrix[1][2]) + matrix[0][1] * (matrix[2][0]*matrix[1][2] - matrix[1][0]*matrix[2][2]) + matrix[0][2] * (matrix[1][0]*matrix[2][1] - matrix[2][0]*matrix[1][1]); }
-RI_INLINE bool				Matrix3x3::isAffine		() const							{ if(matrix[2][0] == 0.0f && matrix[2][1] == 0.0f && matrix[2][2] == 1.0f) return true; return false; }
-
-//==============================================================================================
-
-}	//namespace OpenVGRI
-
-#endif /* __RIMATH_H */
--- a/egl/sfopenvg/riMiniEGL.cpp	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2238 +0,0 @@
-/*------------------------------------------------------------------------
- *
- * EGL 1.3
- * -------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief	Simple implementation of EGL 1.3
- * \note	caveats:
-			- always renders into the backbuffer and blits it to window (no single buffered rendering)
-			- no native Windows or Mac OS X pixmap support
-			- no power management events
-			- no support for swap interval
- * \todo	what happens in egl functions when eglTerminate has been called but the context and surface are still in use?
- * \todo	OSDeinitMutex should be called in case getEGL fails.
- *//*-------------------------------------------------------------------*/
-
-//#include "riMiniEGL.h"
-#include "eglprivate.h"
-#include "riMath.h"
-#include <e32debug.h>
-
-//==============================================================================================
-
-namespace OpenVGRI
-{
-void* OSGetCurrentThreadID(void);
-void OSAcquireMutex(void);
-void OSReleaseMutex(void);
-void OSDeinitMutex(void);
-
-EGLDisplay OSGetDisplay(EGLNativeDisplayType display_id);
-void* OSCreateWindowContext(EGLNativeWindowType window);
-void OSDestroyWindowContext(void* context);
-bool OSIsWindow(const void* context);
-void OSGetWindowSize(const void* context, int& width, int& height);
-void OSBlitToWindow(void* context, const Drawable* drawable);
-EGLBoolean OSGetNativePixmapInfo(NativePixmapType pixmap, int* width, int* height, int* stride, VGImageFormat* format, int** data);
-
-
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-class RIEGLContext
-{
-public:
-	RIEGLContext(OpenVGRI::VGContext* vgctx, const EGLConfig config);
-	~RIEGLContext();
-	void	addReference()				{ m_referenceCount++; }
-	int		removeReference()			{ m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
-
-    VGContext*      getVGContext() const      { return m_vgContext; }
-    EGLConfig getConfig() const         { return m_config; }
-private:
-	RIEGLContext(const RIEGLContext&);
-	RIEGLContext& operator=(const RIEGLContext&);
-	VGContext*		m_vgContext;
-	const EGLConfig	m_config;
-	int				m_referenceCount;
-};
-
-RIEGLContext* CastToRIEGLContext(EGLContext aCtxId);
-EGLContext CastFromRIEGLContext(RIEGLContext* aCtx);
-
-RIEGLContext::RIEGLContext(OpenVGRI::VGContext* vgctx, const EGLConfig config) :
-	m_vgContext(vgctx),
-	m_config(config),
-	m_referenceCount(0)
-{
-}
-RIEGLContext::~RIEGLContext()
-{
-	RI_ASSERT(m_referenceCount == 0);
-	RI_DELETE(m_vgContext);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-class RIEGLSurface
-{
-public:
-    RIEGLSurface(void* OSWindowContext, const EGLConfig config, Drawable* drawable, bool largestPbuffer, int renderBuffer);
-	~RIEGLSurface();
-	void	addReference()				{ m_referenceCount++; }
-	int		removeReference()			{ m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
-
-    void*           getOSWindowContext() const { return m_OSWindowContext; }
-    EGLConfig       getConfig() const          { return m_config; }
-    Drawable*       getDrawable() const        { return m_drawable; }
-    bool            isLargestPbuffer() const   { return m_largestPbuffer; }
-    int             getRenderBuffer() const    { return m_renderBuffer; }
-
-private:
-	RIEGLSurface(const RIEGLSurface&);
-	RIEGLSurface& operator=(const RIEGLSurface&);
-    void*            m_OSWindowContext;
-	const EGLConfig	 m_config;
-	Drawable*        m_drawable;
-	bool			 m_largestPbuffer;
-	int				 m_renderBuffer;		//EGL_BACK_BUFFER or EGL_SINGLE_BUFFER
-	int				 m_referenceCount;
-};
-
-RIEGLSurface* CastToRIEGLSurface(EGLSurface aSurfaceId);
-EGLSurface CastFromRIEGLSurface(RIEGLSurface* aSurface);
-
-RIEGLSurface::RIEGLSurface(void* OSWindowContext, const EGLConfig config, Drawable* drawable, bool largestPbuffer, int renderBuffer) :
-    m_OSWindowContext(OSWindowContext),
-	m_config(config),
-	m_drawable(drawable),
-	m_largestPbuffer(largestPbuffer),
-	m_renderBuffer(renderBuffer),
-	m_referenceCount(0)
-{
-    RI_ASSERT(m_renderBuffer == EGL_BACK_BUFFER);   //only back buffer rendering is supported
-    m_drawable->addReference();
-}
-
-RIEGLSurface::~RIEGLSurface()
-{
-	RI_ASSERT(m_referenceCount == 0);
-    OSDestroyWindowContext(m_OSWindowContext);
-	if(m_drawable)
-	{
-		if(!m_drawable->removeReference())
-			RI_DELETE(m_drawable);
-	}
-}
-
-RIEGLDisplay::RIEGLDisplay(EGLDisplay id) :
-	m_id(id),
-	m_contexts(),
-	m_surfaces()
-{
-	RI_ASSERT(EGL_NUMCONFIGS == 60);
-
-	//sorted by RGB/LUMINANCE (exact), larger total number of color bits (at least), buffer size (at least), config ID (exact)
-	//NOTE: 16 bit configs need to be sorted on the fly if the request ignores some channels
-	//NOTE: config IDs start from 1
-	//               R  B  G  A  L  bpp samples maskBits ID
-	m_configs[0].set(8, 8, 8, 8, 0, 32, 1, 8, 1);	//EGL_RGB_BUFFER, buffer size = 32
-	m_configs[1].set(8, 8, 8, 0, 0, 32, 1, 8, 2);	//EGL_RGB_BUFFER, buffer size = 24
-	m_configs[2].set(5, 5, 5, 1, 0, 16, 1, 4, 3);	//EGL_RGB_BUFFER, buffer size = 16
-	m_configs[3].set(5, 6, 5, 0, 0, 16, 1, 4, 4);	//EGL_RGB_BUFFER, buffer size = 16
-	m_configs[4].set(4, 4, 4, 4, 0, 16, 1, 4, 5);	//EGL_RGB_BUFFER, buffer size = 16
-	m_configs[5].set(0, 0, 0, 8, 0, 8,  1, 8, 6);	//EGL_RGB_BUFFER, buffer size = 8
-	m_configs[6].set(0, 0, 0, 4, 0, 4,  1, 4, 7);	//EGL_RGB_BUFFER, buffer size = 8
-	m_configs[7].set(0, 0, 0, 1, 0, 1,  1, 1, 8);	//EGL_RGB_BUFFER, buffer size = 8
-	m_configs[8].set(0, 0, 0, 0, 8, 8,  1, 8, 9);	//EGL_LUMINANCE_BUFFER, buffer size = 8
-	m_configs[9].set(0, 0, 0, 0, 1, 1,  1, 1, 10);	//EGL_LUMINANCE_BUFFER, buffer size = 1
-
-	m_configs[10].set(8, 8, 8, 8, 0, 32, 4, 1, 11);	//EGL_RGB_BUFFER, buffer size = 32
-	m_configs[11].set(8, 8, 8, 0, 0, 32, 4, 1, 12);	//EGL_RGB_BUFFER, buffer size = 24
-	m_configs[12].set(5, 5, 5, 1, 0, 16, 4, 1, 13);	//EGL_RGB_BUFFER, buffer size = 16
-	m_configs[13].set(5, 6, 5, 0, 0, 16, 4, 1, 14);	//EGL_RGB_BUFFER, buffer size = 16
-	m_configs[14].set(4, 4, 4, 4, 0, 16, 4, 1, 15);	//EGL_RGB_BUFFER, buffer size = 16
-	m_configs[15].set(0, 0, 0, 8, 0, 8,  4, 1, 16);	//EGL_RGB_BUFFER, buffer size = 8
-	m_configs[16].set(0, 0, 0, 4, 0, 4,  4, 1, 17);	//EGL_RGB_BUFFER, buffer size = 8
-	m_configs[17].set(0, 0, 0, 1, 0, 1,  4, 1, 18);	//EGL_RGB_BUFFER, buffer size = 8
-	m_configs[18].set(0, 0, 0, 0, 8, 8,  4, 1, 19);	//EGL_LUMINANCE_BUFFER, buffer size = 8
-	m_configs[19].set(0, 0, 0, 0, 1, 1,  4, 1, 20);	//EGL_LUMINANCE_BUFFER, buffer size = 1
-
-	m_configs[20].set(8, 8, 8, 8, 0, 32, 32, 1, 21);	//EGL_RGB_BUFFER, buffer size = 32
-	m_configs[21].set(8, 8, 8, 0, 0, 32, 32, 1, 22);	//EGL_RGB_BUFFER, buffer size = 24
-	m_configs[22].set(5, 5, 5, 1, 0, 16, 32, 1, 23);	//EGL_RGB_BUFFER, buffer size = 16
-	m_configs[23].set(5, 6, 5, 0, 0, 16, 32, 1, 24);	//EGL_RGB_BUFFER, buffer size = 16
-	m_configs[24].set(4, 4, 4, 4, 0, 16, 32, 1, 25);	//EGL_RGB_BUFFER, buffer size = 16
-	m_configs[25].set(0, 0, 0, 8, 0, 8,  32, 1, 26);	//EGL_RGB_BUFFER, buffer size = 8
-	m_configs[26].set(0, 0, 0, 4, 0, 4,  32, 1, 27);	//EGL_RGB_BUFFER, buffer size = 8
-	m_configs[27].set(0, 0, 0, 1, 0, 1,  32, 1, 28);	//EGL_RGB_BUFFER, buffer size = 8
-	m_configs[28].set(0, 0, 0, 0, 8, 8,  32, 1, 29);	//EGL_LUMINANCE_BUFFER, buffer size = 8
-	m_configs[29].set(0, 0, 0, 0, 1, 1,  32, 1, 30);	//EGL_LUMINANCE_BUFFER, buffer size = 1
-
-    //configs without mask
-	m_configs[30].set(8, 8, 8, 8, 0, 32, 1, 0, 31);	//EGL_RGB_BUFFER, buffer size = 32
-	m_configs[31].set(8, 8, 8, 0, 0, 32, 1, 0, 32);	//EGL_RGB_BUFFER, buffer size = 24
-	m_configs[32].set(5, 5, 5, 1, 0, 16, 1, 0, 33);	//EGL_RGB_BUFFER, buffer size = 16
-	m_configs[33].set(5, 6, 5, 0, 0, 16, 1, 0, 34);	//EGL_RGB_BUFFER, buffer size = 16
-	m_configs[34].set(4, 4, 4, 4, 0, 16, 1, 0, 35);	//EGL_RGB_BUFFER, buffer size = 16
-	m_configs[35].set(0, 0, 0, 8, 0, 8,  1, 0, 36);	//EGL_RGB_BUFFER, buffer size = 8
-	m_configs[36].set(0, 0, 0, 4, 0, 4,  1, 0, 37);	//EGL_RGB_BUFFER, buffer size = 8
-	m_configs[37].set(0, 0, 0, 1, 0, 1,  1, 0, 38);	//EGL_RGB_BUFFER, buffer size = 8
-	m_configs[38].set(0, 0, 0, 0, 8, 8,  1, 0, 39);	//EGL_LUMINANCE_BUFFER, buffer size = 8
-	m_configs[39].set(0, 0, 0, 0, 1, 1,  1, 0, 40);	//EGL_LUMINANCE_BUFFER, buffer size = 1
-
-	m_configs[40].set(8, 8, 8, 8, 0, 32, 4, 0, 41);	//EGL_RGB_BUFFER, buffer size = 32
-	m_configs[41].set(8, 8, 8, 0, 0, 32, 4, 0, 42);	//EGL_RGB_BUFFER, buffer size = 24
-	m_configs[42].set(5, 5, 5, 1, 0, 16, 4, 0, 43);	//EGL_RGB_BUFFER, buffer size = 16
-	m_configs[43].set(5, 6, 5, 0, 0, 16, 4, 0, 44);	//EGL_RGB_BUFFER, buffer size = 16
-	m_configs[44].set(4, 4, 4, 4, 0, 16, 4, 0, 45);	//EGL_RGB_BUFFER, buffer size = 16
-	m_configs[45].set(0, 0, 0, 8, 0, 8,  4, 0, 46);	//EGL_RGB_BUFFER, buffer size = 8
-	m_configs[46].set(0, 0, 0, 4, 0, 4,  4, 0, 47);	//EGL_RGB_BUFFER, buffer size = 8
-	m_configs[47].set(0, 0, 0, 1, 0, 1,  4, 0, 48);	//EGL_RGB_BUFFER, buffer size = 8
-	m_configs[48].set(0, 0, 0, 0, 8, 8,  4, 0, 49);	//EGL_LUMINANCE_BUFFER, buffer size = 8
-	m_configs[49].set(0, 0, 0, 0, 1, 1,  4, 0, 50);	//EGL_LUMINANCE_BUFFER, buffer size = 1
-
-	m_configs[50].set(8, 8, 8, 8, 0, 32, 32, 0, 51);	//EGL_RGB_BUFFER, buffer size = 32
-	m_configs[51].set(8, 8, 8, 0, 0, 32, 32, 0, 52);	//EGL_RGB_BUFFER, buffer size = 24
-	m_configs[52].set(5, 5, 5, 1, 0, 16, 32, 0, 53);	//EGL_RGB_BUFFER, buffer size = 16
-	m_configs[53].set(5, 6, 5, 0, 0, 16, 32, 0, 54);	//EGL_RGB_BUFFER, buffer size = 16
-	m_configs[54].set(4, 4, 4, 4, 0, 16, 32, 0, 55);	//EGL_RGB_BUFFER, buffer size = 16
-	m_configs[55].set(0, 0, 0, 8, 0, 8,  32, 0, 56);	//EGL_RGB_BUFFER, buffer size = 8
-	m_configs[56].set(0, 0, 0, 4, 0, 4,  32, 0, 57);	//EGL_RGB_BUFFER, buffer size = 8
-	m_configs[57].set(0, 0, 0, 1, 0, 1,  32, 0, 58);	//EGL_RGB_BUFFER, buffer size = 8
-	m_configs[58].set(0, 0, 0, 0, 8, 8,  32, 0, 59);	//EGL_LUMINANCE_BUFFER, buffer size = 8
-	m_configs[59].set(0, 0, 0, 0, 1, 1,  32, 0, 60);	//EGL_LUMINANCE_BUFFER, buffer size = 1
-/*
-attrib                default        criteria order   priority
---------------------------------------------------------------
-EGL_COLOR_BUFFER_TYPE EGL_RGB_BUFFER Exact    None    2 
-EGL_RED_SIZE          0              AtLeast  Special 3 
-EGL_GREEN_SIZE        0              AtLeast  Special 3 
-EGL_BLUE_SIZE         0              AtLeast  Special 3 
-EGL_LUMINANCE_SIZE    0              AtLeast  Special 3 
-EGL_ALPHA_SIZE        0              AtLeast  Special 3 
-EGL_BUFFER_SIZE       0              AtLeast  Smaller 4 
-EGL_CONFIG_ID         EGL_DONT_CARE  Exact    Smaller 11
-*/
-}
-
-RIEGLDisplay::~RIEGLDisplay()
-{
-	//mark everything for deletion, but don't delete the current context and surface
-	for(int i=0;i<m_contexts.size();i++)
-	{
-		if(!m_contexts[i]->removeReference())
-			RI_DELETE(m_contexts[i]);
-	}
-	m_contexts.clear();	//remove all contexts from the list (makes further references to the current contexts invalid)
-
-	for(int i=0;i<m_surfaces.size();i++)
-	{
-		if(!m_surfaces[i]->removeReference())
-			RI_DELETE(m_surfaces[i]);
-	}
-	m_surfaces.clear();	//remove all surfaces from the list (makes further references to the current surfaces invalid)
-}
-
-EGLBoolean RIEGLDisplay::contextExists(const EGLContext ctx) const
-{
-	for(int i=0;i<m_contexts.size();i++)
-	{
-		if(m_contexts[i] == CastToRIEGLContext(ctx))
-			return EGL_TRUE;
-	}
-	return EGL_FALSE;
-}
-
-EGLBoolean RIEGLDisplay::surfaceExists(const EGLSurface surf) const
-{
-	for(int i=0;i<m_surfaces.size();i++)
-	{
-		if(m_surfaces[i] == CastToRIEGLSurface(surf))
-			return EGL_TRUE;
-	}
-	return EGL_FALSE;
-}
-
-EGLBoolean RIEGLDisplay::configExists(const EGLConfig config) const
-{
-    for(int i=0;i<EGL_NUMCONFIGS;i++)
-    {
-        if(m_configs[i].m_config == config)
-		return EGL_TRUE;
-    }
-	return EGL_FALSE;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-class RIEGLThread
-{
-public:
-	RIEGLThread(void* currentThreadID);
-	~RIEGLThread();
-
-    void*           getThreadID() const       { return m_threadID; }
-
-    void            makeCurrent(RIEGLContext* c, RIEGLSurface* s)       { m_context = c; m_surface = s; }
-	RIEGLContext*	getCurrentContext() const   { return m_context; }
-	RIEGLSurface*	getCurrentSurface() const   { return m_surface; }
-
-    void            setError(EGLint error)      { m_error = error; }
-    EGLint          getError() const            { return m_error; }
-
-    void            bindAPI(EGLint api)         { m_boundAPI = api; }
-    EGLint          getBoundAPI() const         { return m_boundAPI; }
-
-private:
-	RIEGLThread(const RIEGLThread&);
-	RIEGLThread operator=(const RIEGLThread&);
-
-	RIEGLContext*		m_context;
-	RIEGLSurface*		m_surface;
-	EGLint              m_error;
-	void*               m_threadID;
-	EGLint              m_boundAPI;
-};
-
-RIEGLThread::RIEGLThread(void* currentThreadID) :
-	m_context(NULL),
-	m_surface(NULL),
-	m_error(EGL_SUCCESS),
-	m_threadID(currentThreadID),
-	m_boundAPI(EGL_NONE)
-{
-}
-
-RIEGLThread::~RIEGLThread()
-{
-}
-
-
-
-
-
-Image* CastToImage(EGLClientBuffer aBufferId);
-EGLClientBuffer CastFromImage(Image* aBUffer);
-
-
-
-EGL::EGL() :
-	m_threads(),
-	m_currentThreads(),
-	m_displays(),
-	m_referenceCount(0)
-{
-}
-EGL::~EGL()
-{
-	for(int i=0;i<m_displays.size();i++)
-	{
-		RI_DELETE(m_displays[i]);
-	}
-	for(int i=0;i<m_threads.size();i++)
-	{
-		RI_DELETE(m_threads[i]);
-	}
-	//currentThreads contain just pointers to threads we just deleted
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-//static EGL* g_egl = NULL;	//never use this directly
-EGL* getEGL()
-{
-	/*if(!g_egl)
-	{
-		try
-		{
-			g_egl = RI_NEW(EGL, ());				//throws bad_alloc
-			g_egl->addReference();
-		}
-		catch(std::bad_alloc)
-		{
-			g_egl = NULL;
-		}
-	}
-	return g_egl;
-	*/
-
-
-	//use TLS to store static global g_egl
-	EGL* pEgl = NULL;
-	
-	CEglThreadSession* es = reinterpret_cast<CEglThreadSession*>(Dll::Tls());
-	if (es)
-		{
-		return es->getEgl();
-		}
-	
-	const TInt err = CEglDriver::Open();
-	if (err != KErrNone)
-		{
-		return NULL;
-		}
-
-	// CEglDriver is reference counted. As we successfuly open the driver, pls.iDriver will be non-null
-	// and it should be safe to cache the pointer inside CEglThreadSession
-	CEglDriver* drv = CEglDriver::GetDriver();
-	__ASSERT_DEBUG(drv, User::Panic(KEglPanicCategory, EEglPanicDriverNull));
-
-	// create session object on default thread's heap
-	es = new CEglThreadSession(*drv);
-
-	if (!es || Dll::SetTls(es)!= KErrNone)
-		{
-		delete es;
-		return NULL;
-		}
-	return es->getEgl();
-}
-static void releaseEGL()
-{
-/*
-	if(g_egl)
-	{
-		if(!g_egl->removeReference())
-		{
-			RI_DELETE(g_egl);
-			g_egl = NULL;
-		}
-	}
-	*/
-	CEglThreadSession* es = reinterpret_cast<CEglThreadSession*>(Dll::Tls());
-	if (es)
-		{
-		delete es;
-		}
-	Dll::SetTls(NULL);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Given a display ID, return the corresponding object, or NULL
-*			if the ID hasn't been initialized.
-* \param	
-* \return	
-* \note		if egl has been initialized for this display, the display ID can
-*			be found from egl->m_displays
-*//*-------------------------------------------------------------------*/
-
-RIEGLDisplay* EGL::getDisplay(EGLDisplay displayID) const
-{
-	for(int i=0;i<m_displays.size();i++)
-	{
-		if(displayID == m_displays[i]->getID())
-			return m_displays[i];
-	}
-	return NULL;		//error: the display hasn't been eglInitialized
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	return EGLDisplay for the current context
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-EGLDisplay EGL::findDisplay(EGLContext ctx) const
-{
-	for(int i=0;i<m_displays.size();i++)
-	{
-        if(m_displays[i]->contextExists(ctx))
-            return m_displays[i]->getID();
-	}
-    return EGL_NO_DISPLAY;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	return an EGL thread struct for the thread made current, or
-*            NULL if there's no current context.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-RIEGLThread* EGL::getCurrentThread() const
-{
-	void* currentThreadID = OSGetCurrentThreadID();
-	for(int i=0;i<m_currentThreads.size();i++)
-	{
-		if(currentThreadID == m_currentThreads[i]->getThreadID())
-			return m_currentThreads[i];
-	}
-	return NULL;		//thread is not current
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	return an EGL thread struct corresponding to current OS thread.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-RIEGLThread* EGL::getThread()
-{
-	void* currentThreadID = OSGetCurrentThreadID();
-	for(int i=0;i<m_threads.size();i++)
-	{
-		if(currentThreadID == m_threads[i]->getThreadID())
-			return m_threads[i];
-	}
-
-	//EGL doesn't have a struct for the thread yet, add it to EGL's list
-	RIEGLThread* newThread = NULL;
-	try
-	{
-		newThread = RI_NEW(RIEGLThread, (OSGetCurrentThreadID()));	//throws bad_alloc
-		m_threads.push_back(newThread);	//throws bad_alloc
-		return newThread;
-	}
-	catch(std::bad_alloc)
-	{
-		RI_DELETE(newThread);
-		return NULL;
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	destroy an EGL thread struct
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void EGL::destroyThread()
-{
-	void* currentThreadID = OSGetCurrentThreadID();
-	for(int i=0;i<m_threads.size();i++)
-	{
-		if(currentThreadID == m_threads[i]->getThreadID())
-        {
-            RIEGLThread* thread = m_threads[i];
-            bool res = m_threads.remove(thread);
-            RI_ASSERT(res);
-            RI_UNREF(res);
-            RI_DELETE(thread);
-            break;
-        }
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-bool EGL::isInUse(const void* image) const
-{
-    for(int i=0;i<m_currentThreads.size();i++)
-    {
-        RIEGLSurface* s = m_currentThreads[i]->getCurrentSurface();
-        if(s && s->getDrawable() && s->getDrawable()->isInUse((Image*)image))
-            return true;
-    }
-    return false;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#define EGL_GET_DISPLAY(DISPLAY, RETVAL) \
-	OSAcquireMutex(); \
-	EGL* egl = getEGL(); \
-    if(!egl) \
-    { \
-		OSReleaseMutex(); \
-		return RETVAL; \
-    } \
-	RIEGLDisplay* display = egl->getDisplay(DISPLAY); \
-
-#define EGL_GET_EGL(RETVAL) \
-	OSAcquireMutex(); \
-	EGL* egl = getEGL(); \
-    if(!egl) \
-    { \
-		OSReleaseMutex(); \
-		return RETVAL; \
-    } \
-
-#define EGL_IF_ERROR(COND, ERRORCODE, RETVAL) \
-	if(COND) { eglSetError(egl, ERRORCODE); OSReleaseMutex(); return RETVAL; } \
-
-#define EGL_RETURN(ERRORCODE, RETVAL) \
-	{ \
-		eglSetError(egl, ERRORCODE); \
-		OSReleaseMutex(); \
-		return RETVAL; \
-	}
-
-// Note: egl error handling model differs from OpenVG. The latest error is stored instead of the oldest one.
-static void eglSetError(EGL* egl, EGLint error)
-{
-	RIEGLThread* thread = egl->getThread();
-	if(thread)
-		thread->setError(error);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Returns the OpenVG context current to the calling thread.
-* \param	
-* \return	
-* \note		This function is always called from a mutexed API function
-*//*-------------------------------------------------------------------*/
-
-void* eglvgGetCurrentVGContext(void)
-{
-	EGL* egl = getEGL();
-    if(egl)
-    {
-        RIEGLThread* thread = egl->getCurrentThread();
-        if(thread)
-        {
-            RI_ASSERT(thread->getCurrentContext() && thread->getCurrentSurface());
-            return thread->getCurrentContext()->getVGContext();
-        }
-    }
-	return NULL;	//not initialized or made current
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Check if the image is current in any of the displays
-* \param	
-* \return	
-* \note		This function is always called from a mutexed API function
-*//*-------------------------------------------------------------------*/
-
-bool eglvgIsInUse(void* image)
-{
-	EGL* egl = getEGL();
-    if(egl)
-    {
-        return egl->isInUse(image);
-    }
-	return false;
-}
-
-//helper functions
-RIEGLContext* CastToRIEGLContext(EGLContext aCtxId)
-  {
-  return (RIEGLContext*)(aCtxId);
-  }
-EGLContext CastFromRIEGLContext(RIEGLContext* aCtx)
-  {
-  return (EGLContext)(aCtx);
-  }
-
-RIEGLSurface* CastToRIEGLSurface(EGLSurface aSurfaceId)
-  {
-  return (RIEGLSurface*)(aSurfaceId);
-  }
-EGLSurface CastFromRIEGLSurface(RIEGLSurface* aSurface)
-  {
-  return (EGLSurface)(aSurface);
-  }
-
-Image* CastToImage(EGLClientBuffer aBufferId)
-  {
-  return (Image*)(aBufferId);
-  }
-
-EGLClientBuffer CastFromImage(Image* aBUffer)
-  {
-  return (EGLClientBuffer)(aBUffer);
-  }
-
-//==============================================================================================
-
-}	//namespace OpenVGRI
-
-using namespace OpenVGRI;
-
-
-
-
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLint do_eglGetError()
-#else
-EGLint eglGetError()
-#endif
-{
-    OSAcquireMutex();
-    EGLint ret = EGL_SUCCESS;
-	EGL* egl = getEGL();
-    if(egl)
-    {
-        RIEGLThread* thread = egl->getThread();
-        if(thread)
-            ret = thread->getError();	//initialized, return error code
-    }
-    else ret = EGL_NOT_INITIALIZED;
-    OSReleaseMutex();
-    return ret;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLDisplay do_eglGetDisplay(EGLNativeDisplayType display_id)
-#else
-EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id)
-#endif
-{
-    return OSGetDisplay(display_id);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLBoolean do_eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
-#else
-EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
-#endif
-{
-	EGL_GET_DISPLAY(dpy, EGL_FALSE);
-	EGL_IF_ERROR(display, EGL_SUCCESS, EGL_TRUE);	//already initialized
-
-	//create the current display
-	//if a context and a surface are bound by the time of eglTerminate, they remain bound until eglMakeCurrent is called
-	RIEGLDisplay* newDisplay = NULL;
-	try
-	{
-		newDisplay = RI_NEW(RIEGLDisplay, (dpy));	//throws bad_alloc
-		egl->addDisplay(newDisplay);	//throws bad_alloc
-		display = newDisplay;
-		RI_ASSERT(display);
-	}
-	catch(std::bad_alloc)
-	{
-		RI_DELETE(newDisplay);
-		EGL_RETURN(EGL_BAD_ALLOC, EGL_FALSE);
-	}
-
-	if(major) *major = 1;
-	if(minor) *minor = 2;
-	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLBoolean do_eglTerminate(EGLDisplay dpy)
-#else
-EGLBoolean eglTerminate(EGLDisplay dpy)
-#endif
-{
-	EGL_GET_DISPLAY(dpy, EGL_FALSE);
-	EGL_IF_ERROR(!display, EGL_SUCCESS, EGL_TRUE);
-    egl->removeDisplay(display);
-    RI_DELETE(display);
-	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY const char *do_eglQueryString(EGLDisplay dpy, EGLint name)
-#else
-const char *eglQueryString(EGLDisplay dpy, EGLint name)
-#endif
-{
-	EGL_GET_DISPLAY(dpy, NULL);
-	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, NULL);
-
-	static const char apis[] = "OpenVG";
-	static const char extensions[] = "";
-	static const char vendor[] = "Khronos Group";
-	static const char version[] = "1.3";
-
-	const char* ret = NULL;
-	switch(name)
-	{
-	case EGL_CLIENT_APIS:
-		ret = apis;
-		break;
-
-	case EGL_EXTENSIONS:
-		ret = extensions;
-		break;
-
-	case EGL_VENDOR:
-		ret = vendor;
-		break;
-
-	case EGL_VERSION:
-		ret = version;
-		break;
-
-	default:
-		EGL_RETURN(EGL_BAD_PARAMETER, NULL);
-	}
-	EGL_RETURN(EGL_SUCCESS, ret);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLBoolean do_eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config)
-#else
-EGLBoolean eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config)
-#endif
-{
-	EGL_GET_DISPLAY(dpy, EGL_FALSE);
-	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
-	EGL_IF_ERROR(!num_config, EGL_BAD_PARAMETER, EGL_FALSE);
-	if(!configs)
-	{
-		*num_config = display->getNumConfigs();
-		EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-	}
-	*num_config = RI_INT_MIN(config_size, display->getNumConfigs());
-	for(int i=0;i<*num_config;i++)
-		configs[i] = display->getConfigByIdx(i).m_config;
-
-	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static bool smaller(EGLint c, EGLint filter)
-{
-	return (filter != EGL_DONT_CARE) && (c < filter);
-}
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLBoolean do_eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
-#else
-EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
-#endif
-{
-	EGL_GET_DISPLAY(dpy, EGL_FALSE);
-	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
-	EGL_IF_ERROR(!num_config, EGL_BAD_PARAMETER, EGL_FALSE);
-
-	if(!configs)
-	{
-		*num_config = display->getNumConfigs();
-		EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-	}
-	*num_config = 0;
-	if(!config_size)
-		EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-
-	int bufferSize = 0;
-	int redSize = 0;
-	int greenSize = 0;
-	int blueSize = 0;
-	int luminanceSize = 0;
-	int alphaSize = 0;
-	int colorBufferType = EGL_RGB_BUFFER;
-	int configID = EGL_DONT_CARE;
-	int sampleBuffers = 0;
-	int samples = 0;
-	if(attrib_list)
-	{
-		for(int i=0;attrib_list[i] != EGL_NONE;i+=2)
-		{
-			switch(attrib_list[i])
-			{
-			case EGL_BUFFER_SIZE:				//depth of the color buffer
-				bufferSize = attrib_list[i+1];
-				break;
-			case EGL_RED_SIZE:					//bits of Red in the color buffer
-				redSize = attrib_list[i+1];
-				break;
-			case EGL_GREEN_SIZE:				//bits of Green in the color buffer
-				greenSize = attrib_list[i+1];
-				break;
-			case EGL_BLUE_SIZE:					//bits of Blue in the color buffer
-				blueSize = attrib_list[i+1];
-				break;
-			case EGL_LUMINANCE_SIZE:			//bits of Luminance in the color buffer
-				luminanceSize = attrib_list[i+1];
-				break;
-			case EGL_ALPHA_SIZE:				//bits of Alpha in the color buffer
-				alphaSize = attrib_list[i+1];
-				break;
-			case EGL_ALPHA_MASK_SIZE:			//bits of Alpha in the alpha mask buffer
-				if(attrib_list[i+1] > 8)
-					EGL_RETURN(EGL_SUCCESS, EGL_TRUE);	//not supported
-				break;
-			case EGL_COLOR_BUFFER_TYPE:			//enum color buffer type (EGL_RGB_BUFFER, EGL_LUMINANCE_BUFFER)
-				EGL_IF_ERROR(attrib_list[i+1] != EGL_RGB_BUFFER && attrib_list[i+1] != EGL_LUMINANCE_BUFFER && attrib_list[i+1] != EGL_DONT_CARE, EGL_BAD_ATTRIBUTE, EGL_FALSE);
-				colorBufferType = attrib_list[i+1];
-				break;
-			case EGL_CONFIG_ID:					//unique EGLConfig identifier
-				configID = attrib_list[i+1];
-				break;
-
-			case EGL_SAMPLE_BUFFERS:			//integer number of multisample buffers
-				sampleBuffers = attrib_list[i+1];
-				break;
-			case EGL_SAMPLES:					//integer number of samples per pixel
-				samples = attrib_list[i+1];
-				break;
-
-			case EGL_BIND_TO_TEXTURE_RGB:		//boolean True if bindable to RGB textures. (always EGL_FALSE)
-			case EGL_BIND_TO_TEXTURE_RGBA:		//boolean True if bindable to RGBA textures. (always EGL_FALSE)
-			case EGL_DEPTH_SIZE:				//integer bits of Z in the depth buffer (always 0)
-			case EGL_LEVEL:						//integer frame buffer level (always 0)
-			case EGL_NATIVE_RENDERABLE:			//boolean EGL TRUE if native rendering APIs can render to surface (always EGL_FALSE)
-			case EGL_STENCIL_SIZE:				//integer bits of Stencil in the stencil buffer (always 0)
-				if(attrib_list[i+1])
-					EGL_RETURN(EGL_SUCCESS, EGL_TRUE);	//not supported
-				break;
-
-			case EGL_CONFIG_CAVEAT:				//enum any caveats for the configuration (always EGL_NONE)
-			case EGL_NATIVE_VISUAL_TYPE:		//integer native visual type of the associated visual (always EGL_NONE)
-				if(attrib_list[i+1] != EGL_NONE)
-					EGL_RETURN(EGL_SUCCESS, EGL_TRUE);	//not supported
-				break;
-
-			case EGL_MAX_SWAP_INTERVAL:			//integer maximum swap interval (always 1)
-			case EGL_MIN_SWAP_INTERVAL:			//integer minimum swap interval (always 1)
-				if(attrib_list[i+1] != 1)
-					EGL_RETURN(EGL_SUCCESS, EGL_TRUE);	//not supported
-				break;
-
-			case EGL_RENDERABLE_TYPE:			//bitmask which client rendering APIs are supported. (always EGL_OPENVG_BIT)
-				if(!(attrib_list[i+1] & EGL_OPENVG_BIT))
-					EGL_RETURN(EGL_SUCCESS, EGL_TRUE);	//not supported
-				break;
-
-			case EGL_SURFACE_TYPE:				//bitmask which types of EGL surfaces are supported. (always EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT | EGL_VG_COLORSPACE_LINEAR_BIT | EGL_VG_ALPHA_FORMAT_PRE_BIT)
-				break;	//all types are always supported
-
-			case EGL_TRANSPARENT_TYPE:			//enum type of transparency supported (always EGL_NONE)
-			case EGL_NATIVE_VISUAL_ID:			//integer handle of corresponding native visual (always 0)
-			case EGL_MAX_PBUFFER_WIDTH:			//integer maximum width of pbuffer (always INT_MAX)
-			case EGL_MAX_PBUFFER_HEIGHT:		//integer maximum height of pbuffer (always INT_MAX)
-			case EGL_MAX_PBUFFER_PIXELS:		//integer maximum size of pbuffer (always INT_MAX)
-			case EGL_TRANSPARENT_RED_VALUE:		//integer transparent red value (undefined)
-			case EGL_TRANSPARENT_GREEN_VALUE:	//integer transparent green value (undefined)
-			case EGL_TRANSPARENT_BLUE_VALUE:	//integer transparent blue value (undefined)
-				break;	//ignored
-
-			default:
-				EGL_RETURN(EGL_BAD_ATTRIBUTE, EGL_FALSE);	//unknown attribute
-			}
-		}
-	}
-
-	if(configID && configID != EGL_DONT_CARE)
-	{	//if CONFIG_ID is defined, ignore the rest of the attribs
-        for(int i=0;i<EGL_NUMCONFIGS;i++)
-        {
-            if(display->getConfigByIdx(i).m_configID == configID)
-            {
-                *num_config = 1;
-                *configs = display->getConfigByIdx(i).m_config;
-            }
-        }
-		EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-	}
-
-	//go through all configs, add passed configs to return list
-    //TODO take alpha mask size into account
-	EGLConfig found[EGL_NUMCONFIGS];
-    int keys[EGL_NUMCONFIGS];
-	int numFound = 0;
-	for(int i=0;i<display->getNumConfigs();i++)
-	{
-		const RIEGLConfig& c = display->getConfigByIdx(i);
-
-		int colorBits = c.m_desc.redBits + c.m_desc.greenBits + c.m_desc.blueBits;
-		int luminanceBits = c.m_desc.luminanceBits;
-		int configBufferSize;
-		if(colorBits)
-		{
-			RI_ASSERT(!luminanceBits);
-			colorBits += c.m_desc.alphaBits;
-			configBufferSize = colorBits;
-		}
-		else if(luminanceBits)
-		{
-			luminanceBits += c.m_desc.alphaBits;
-			configBufferSize = luminanceBits;
-		}
-		else
-		{	//alpha only surface
-			colorBits = c.m_desc.alphaBits;
-			luminanceBits = c.m_desc.alphaBits;
-			configBufferSize = colorBits;
-		}
-
-		if (smaller(configBufferSize, bufferSize))
-			continue;
-
-		int configSampleBuffers = c.m_samples == 1 ? 0 : 1;
-		if (smaller(configSampleBuffers, sampleBuffers))
-			continue;
-		if (smaller(c.m_samples, samples))
-			continue;
-
-		if (smaller(c.m_desc.redBits, redSize)
-			|| smaller(c.m_desc.greenBits, greenSize)
-			|| smaller(c.m_desc.blueBits, blueSize) 
-			|| smaller(c.m_desc.alphaBits, alphaSize) )
-			continue;
-
-		if (smaller(c.m_desc.luminanceBits, luminanceSize))
-			continue;
-
-		if ((colorBufferType == EGL_RGB_BUFFER && !colorBits) ||
-			(colorBufferType == EGL_LUMINANCE_BUFFER && !luminanceBits))
-			continue;
-
-		int sortKey = c.m_configID;	//sort from smaller to larger
-		int sortBits = 0;
-		if(redSize != 0 && redSize != EGL_DONT_CARE)
-			sortBits += c.m_desc.redBits;
-		if(greenSize != 0 && greenSize != EGL_DONT_CARE)
-			sortBits += c.m_desc.greenBits;
-		if(blueSize != 0 && blueSize != EGL_DONT_CARE)
-			sortBits += c.m_desc.blueBits;
-		if(alphaSize != 0 && alphaSize != EGL_DONT_CARE)
-			sortBits += c.m_desc.alphaBits;
-		if(luminanceSize != 0 && luminanceSize != EGL_DONT_CARE)
-			sortBits += c.m_desc.luminanceBits;
-		RI_ASSERT(c.m_configID <= EGL_NUMCONFIGS);	//if there are more configs, increase the shift value
-		RI_ASSERT(sortBits <= 32);
-		sortKey += (32-sortBits) << 4;	//sort from larger to smaller
-
-		found[numFound] = c.m_config;
-		keys[numFound++] = sortKey;
-	}
-	if(!numFound)
-		EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-
-	//sort return list into increasing order
-	for(int e=0;e<numFound-1;e++)
-	{
-		for(int f=e+1;f<numFound;f++)
-		{
-			if(keys[e] > keys[f])
-			{
-                EGLConfig tmp = found[e];
-                found[e] = found[f];
-                found[f] = tmp;
-				RI_INT_SWAP(keys[e], keys[f]);
-			}
-		}
-	}
-
-	//write configs into return array
-	numFound = RI_INT_MIN(numFound, config_size);
-	for(int i=0;i<numFound;i++)
-	{
-		configs[i] = found[i];
-	}
-	*num_config = numFound;
-
-	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLBoolean do_eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
-#else
-EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
-#endif
-{
-	EGL_GET_DISPLAY(dpy, EGL_FALSE);
-	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
-	EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_FALSE);
-	const RIEGLConfig& c = display->getConfig(config);
-	switch(attribute)
-	{
-	case EGL_BUFFER_SIZE:
-		*value = RI_INT_MAX(c.m_desc.redBits + c.m_desc.greenBits + c.m_desc.blueBits + c.m_desc.alphaBits, c.m_desc.luminanceBits + c.m_desc.alphaBits);
-		break;
-
-	case EGL_RED_SIZE:
-		*value = c.m_desc.redBits;
-		break;
-
-	case EGL_GREEN_SIZE:
-		*value = c.m_desc.greenBits;
-		break;
-
-	case EGL_BLUE_SIZE:
-		*value = c.m_desc.blueBits;
-		break;
-
-	case EGL_LUMINANCE_SIZE:
-		*value = c.m_desc.luminanceBits;
-		break;
-
-	case EGL_ALPHA_SIZE:
-		*value = c.m_desc.alphaBits;
-		break;
-
-	case EGL_ALPHA_MASK_SIZE:
-		*value = c.m_maskBits;
-		break;
-
-	case EGL_BIND_TO_TEXTURE_RGB:
-	case EGL_BIND_TO_TEXTURE_RGBA:
-		*value = EGL_FALSE;
-		break;
-
-	case EGL_COLOR_BUFFER_TYPE:
-		if(c.m_desc.redBits)
-			*value = EGL_RGB_BUFFER;
-		else
-			*value = EGL_LUMINANCE_BUFFER;
-		break;
-
-	case EGL_CONFIG_CAVEAT:
-		*value = EGL_NONE;
-		break;
-
-	case EGL_CONFIG_ID:
-		*value = c.m_configID;
-		break;
-
-	case EGL_DEPTH_SIZE:
-		*value = 0;
-		break;
-
-	case EGL_LEVEL:
-		*value = 0;
-		break;
-
-	case EGL_MAX_PBUFFER_WIDTH:
-	case EGL_MAX_PBUFFER_HEIGHT:
-		*value = 16384;			//NOTE arbitrary maximum
-		break;
-		
-	case EGL_MAX_PBUFFER_PIXELS:
-		*value = 16384*16384;	//NOTE arbitrary maximum
-		break;
-
-	case EGL_MAX_SWAP_INTERVAL:
-	case EGL_MIN_SWAP_INTERVAL:
-		*value = 1;
-		break;
-
-	case EGL_NATIVE_RENDERABLE:
-		*value = EGL_FALSE;
-		break;
-
-	case EGL_NATIVE_VISUAL_ID:
-		*value = 0;
-		break;
-
-	case EGL_NATIVE_VISUAL_TYPE:
-		*value = EGL_NONE;
-		break;
-
-	case EGL_RENDERABLE_TYPE:
-		*value = EGL_OPENVG_BIT;
-		break;
-
-	case EGL_SAMPLE_BUFFERS:
-		*value = c.m_samples > 1 ? 1 : 0;
-		break;
-
-	case EGL_SAMPLES:
-		*value = c.m_samples > 1 ? c.m_samples : 0;
-		break;
-
-	case EGL_STENCIL_SIZE:
-		*value = 0;
-		break;
-
-	case EGL_SURFACE_TYPE:
-		*value = EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT | EGL_VG_COLORSPACE_LINEAR_BIT | EGL_VG_ALPHA_FORMAT_PRE_BIT;
-		break;
-
-	case EGL_TRANSPARENT_TYPE:
-		*value = EGL_NONE;
-		break;
-
-	case EGL_TRANSPARENT_RED_VALUE:
-	case EGL_TRANSPARENT_GREEN_VALUE:
-	case EGL_TRANSPARENT_BLUE_VALUE:
-		*value = 0;
-		break;
-
-    case EGL_CONFORMANT:
-        *value = EGL_OPENVG_BIT;  //TODO return proper value
-        break;
-
-	default:
-		EGL_RETURN(EGL_BAD_ATTRIBUTE, EGL_FALSE);
-	}
-	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLSurface do_eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
-#else
-EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
-#endif
-{
-	EGL_GET_DISPLAY(dpy, EGL_NO_SURFACE);
-	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_NO_SURFACE);
-	EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_NO_SURFACE);
-
-	int renderBuffer = EGL_BACK_BUFFER;
-	int colorSpace = EGL_VG_COLORSPACE_sRGB;
-	int alphaFormat = EGL_VG_ALPHA_FORMAT_NONPRE;
-	if(attrib_list)
-	{
-		for(int i=0;attrib_list[i] != EGL_NONE;i+=2)
-		{
-			switch(attrib_list[i])
-			{
-			case EGL_RENDER_BUFFER:
-				renderBuffer = attrib_list[i+1];
-				break;
-
-			case EGL_VG_COLORSPACE:
-				colorSpace = attrib_list[i+1];
-				break;
-
-			case EGL_VG_ALPHA_FORMAT:
-				alphaFormat = attrib_list[i+1];
-				break;
-
-			default:
-				EGL_RETURN(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
-			}
-		}
-	}
-	//we ignore the renderBuffer parameter since we can only render to double buffered surfaces
-
-	//TODO If the attributes of win do not correspond to config, then an EGL BAD MATCH error is generated.
-	//TODO If there is already an EGLConfig associated with win (as a result of a previous eglCreateWindowSurface call), then an EGL BAD ALLOC error is generated
-
-    void* wc = NULL;
-    Drawable* d = NULL;
-	RIEGLSurface* s = NULL;
-	try
-	{
-        wc = OSCreateWindowContext(win);
-		RI_ASSERT(wc);
-		//TODO what should happen if window width or height is zero?
-		int windowWidth = 0, windowHeight = 0;
-		OSGetWindowSize(wc, windowWidth, windowHeight);
-        bool isWindow = OSIsWindow(wc);
-		if(windowWidth <= 0 || windowHeight <= 0 || !isWindow)
-		{
-            OSDestroyWindowContext(wc);
-            EGL_IF_ERROR(!isWindow, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
-			EGL_IF_ERROR(windowWidth <= 0 || windowHeight <= 0, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
-		}
-		d = RI_NEW(Drawable, (display->getConfig(config).configToDescriptor((colorSpace == EGL_VG_COLORSPACE_LINEAR) ? false : true, (alphaFormat == EGL_VG_ALPHA_FORMAT_PRE) ? true : false), windowWidth, windowHeight, display->getConfig(config).m_samples, display->getConfig(config).m_maskBits));	//throws bad_alloc
-		RI_ASSERT(d);
-		s = RI_NEW(RIEGLSurface,(wc, config, d, false, renderBuffer));	//throws bad_alloc
-		RI_ASSERT(s);
-		s->addReference();
-		display->addSurface(s);	//throws bad_alloc
-	}
-	catch(std::bad_alloc)
-	{
-        OSDestroyWindowContext(wc);
-        RI_DELETE(d);
-        RI_DELETE(s);
-		EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_SURFACE);
-	}
-	EGL_RETURN(EGL_SUCCESS, (EGLSurface)s);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLSurface do_eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list)
-#else
-EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list)
-#endif
-{
-	EGL_GET_DISPLAY(dpy, EGL_NO_SURFACE);
-	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_NO_SURFACE);
-	EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_NO_SURFACE);
-
-	int width = 0, height = 0;
-	bool largestPbuffer = false;
-	int colorSpace = EGL_VG_COLORSPACE_sRGB;
-	int alphaFormat = EGL_VG_ALPHA_FORMAT_NONPRE;
-	if(attrib_list)
-	{
-		for(int i=0;attrib_list[i] != EGL_NONE;i+=2)
-		{
-			switch(attrib_list[i])
-			{
-			case EGL_WIDTH:
-				width = attrib_list[i+1];
-				break;
-
-			case EGL_HEIGHT:
-				height = attrib_list[i+1];
-				break;
-
-			case EGL_LARGEST_PBUFFER:
-				largestPbuffer = attrib_list[i+1] ? true : false;
-				break;
-
-			case EGL_VG_COLORSPACE:
-				colorSpace = attrib_list[i+1];
-				break;
-
-			case EGL_VG_ALPHA_FORMAT:
-				alphaFormat = attrib_list[i+1];
-				break;
-
-			case EGL_TEXTURE_FORMAT:	//config doesn't support OpenGL ES
-			case EGL_TEXTURE_TARGET:	//config doesn't support OpenGL ES
-			case EGL_MIPMAP_TEXTURE:	//config doesn't support OpenGL ES
-			default:
-				EGL_RETURN(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
-			}
-		}
-	}
-	EGL_IF_ERROR(width <= 0 || height <= 0, EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
-
-    Drawable* d = NULL;
-	RIEGLSurface* s = NULL;
-	try
-	{
-		d = RI_NEW(Drawable, (display->getConfig(config).configToDescriptor((colorSpace == EGL_VG_COLORSPACE_LINEAR) ? false : true, (alphaFormat == EGL_VG_ALPHA_FORMAT_PRE) ? true : false), width, height, display->getConfig(config).m_samples, display->getConfig(config).m_maskBits));	//throws bad_alloc
-		RI_ASSERT(d);
-		s = RI_NEW(RIEGLSurface,(NULL, config, d, largestPbuffer, EGL_BACK_BUFFER));	//throws bad_alloc
-		RI_ASSERT(s);
-		s->addReference();
-		display->addSurface(s);	//throws bad_alloc
-	}
-	catch(std::bad_alloc)
-	{
-        RI_DELETE(d);
-        RI_DELETE(s);
-		EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_SURFACE);
-	}
-	EGL_RETURN(EGL_SUCCESS, (EGLSurface)s);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLSurface do_eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list)
-#else
-EGLSurface eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list)
-#endif
-{
-	EGL_GET_DISPLAY(dpy, EGL_NO_SURFACE);
-	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_NO_SURFACE);
-	EGL_IF_ERROR(buftype != EGL_OPENVG_IMAGE, EGL_BAD_PARAMETER, EGL_NO_SURFACE);
-	EGL_IF_ERROR(!buffer, EGL_BAD_PARAMETER, EGL_NO_SURFACE);	//TODO should also check if buffer really is a valid VGImage object (needs VG context for that)
-    Image* image = (Image*)buffer;
-	EGL_IF_ERROR(image->isInUse(), EGL_BAD_ACCESS, EGL_NO_SURFACE);	//buffer is in use by OpenVG
-	EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_NO_SURFACE);
-	EGL_IF_ERROR(attrib_list && attrib_list[0] != EGL_NONE, EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);	//there are no valid attribs for OpenVG
-	const Color::Descriptor& bc = ((Image*)buffer)->getDescriptor();
-	const Color::Descriptor& cc = display->getConfig(config).m_desc;
-	EGL_IF_ERROR(bc.redBits != cc.redBits || bc.greenBits != cc.greenBits || bc.blueBits != cc.blueBits ||
-				 bc.alphaBits != cc.alphaBits || bc.luminanceBits != cc.luminanceBits, EGL_BAD_MATCH, EGL_NO_SURFACE);
-
-	//TODO If buffer is already bound to another pbuffer, an EGL BAD ACCESS error is generated.
-
-    Drawable* d = NULL;
-	RIEGLSurface* s = NULL;
-	try
-	{
-		d = RI_NEW(Drawable, (image, display->getConfig(config).m_maskBits));
-		RI_ASSERT(d);
-		s = RI_NEW(RIEGLSurface,(NULL, config, d, false, EGL_BACK_BUFFER));	//throws bad_alloc
-		RI_ASSERT(s);
-		s->addReference();
-		display->addSurface(s);	//throws bad_alloc
-	}
-	catch(std::bad_alloc)
-	{
-        RI_DELETE(d);
-        RI_DELETE(s);
-		EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_SURFACE);
-	}
-	EGL_RETURN(EGL_SUCCESS, (EGLSurface)s);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLSurface do_eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list)
-#else
-EGLSurface eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list)
-#endif
-{
-    EGL_GET_DISPLAY(dpy, EGL_NO_SURFACE);
-	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_NO_SURFACE);
-	EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_NO_SURFACE);
-	//EGL_IF_ERROR(!pixmap || !isValidImageFormat(pixmap->format) || !pixmap->data || pixmap->width <= 0 || pixmap->height <= 0, EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE);
-
-	RI_UNREF(attrib_list);
-	EGL_IF_ERROR(display->getConfig(config).m_samples != 1, EGL_BAD_MATCH, EGL_NO_SURFACE);
-
-	//TODO If there is already an EGLSurface associated with pixmap (as a result of a previous eglCreatePixmapSurface call), then a EGL BAD ALLOC error is generated.
-	
-	
-	EGLint  width  = -1;
-	EGLint  height = -1;
-	EGLint  stride = -1;
-	VGImageFormat format;
-	int* data = NULL;
-	EGLBoolean err = OSGetNativePixmapInfo(pixmap, &width, &height, &stride,&format, &data);
-	
-    Drawable* d = NULL;
-	RIEGLSurface* s = NULL;
-	try
-	{
-		d = RI_NEW(Drawable, (Color::formatToDescriptor(format), width, height, stride, (RIuint8*)data, display->getConfig(config).m_maskBits));	//throws bad_alloc
-		RI_ASSERT(d);
-		s = RI_NEW(RIEGLSurface,(NULL, config, d, false, EGL_BACK_BUFFER));	//throws bad_alloc
-		RI_ASSERT(s);
-		s->addReference();
-		display->addSurface(s);	//throws bad_alloc
-	}
-	catch(std::bad_alloc)
-	{
-        RI_DELETE(d);
-        RI_DELETE(s);
-		EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_SURFACE);
-	}
-	EGL_RETURN(EGL_SUCCESS, (EGLSurface)s);
-	
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLBoolean do_eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
-#else
-EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
-#endif
-{
-	EGL_GET_DISPLAY(dpy, EGL_FALSE);
-	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
-	EGL_IF_ERROR(!display->surfaceExists(surface), EGL_BAD_SURFACE, EGL_FALSE);
-
-    display->removeSurface((RIEGLSurface*)surface);
-	if(!((RIEGLSurface*)surface)->removeReference())
-		RI_DELETE((RIEGLSurface*)surface);
-
-	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLBoolean do_eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
-#else
-EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
-#endif
-{
-	EGL_GET_DISPLAY(dpy, EGL_FALSE);
-	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
-	EGL_IF_ERROR(!display->surfaceExists(surface), EGL_BAD_SURFACE, EGL_FALSE);
-	RI_UNREF(attribute);
-	RI_UNREF(value);
-	//do nothing
-	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLBoolean do_eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value)
-#else
-EGLBoolean eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value)
-#endif
-{
-	EGL_GET_DISPLAY(dpy, EGL_FALSE);
-	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
-	EGL_IF_ERROR(!display->surfaceExists(surface), EGL_BAD_SURFACE, EGL_FALSE);
-	//TODO give an error if value is NULL?
-
-	RIEGLSurface* s = (RIEGLSurface*)surface;
-	switch(attribute)
-	{
-	case EGL_VG_ALPHA_FORMAT:
-		*value = (s->getDrawable()->getDescriptor().isPremultiplied()) ? EGL_VG_ALPHA_FORMAT_PRE : EGL_VG_ALPHA_FORMAT_NONPRE;
-		break;
-
-	case EGL_VG_COLORSPACE:
-		*value = (s->getDrawable()->getDescriptor().isNonlinear()) ? EGL_VG_COLORSPACE_sRGB : EGL_VG_COLORSPACE_LINEAR;
-		break;
-
-	case EGL_CONFIG_ID:
-		*value = display->getConfig(s->getConfig()).m_configID;
-		break;
-
-	case EGL_HEIGHT:
-		*value = s->getDrawable()->getHeight();
-		break;
-
-	case EGL_HORIZONTAL_RESOLUTION:
-		*value = EGL_UNKNOWN;			//TODO Horizontal dot pitch
-		break;
-
-	case EGL_LARGEST_PBUFFER:
-		if(!s->getOSWindowContext())
-			*value = s->isLargestPbuffer() ? EGL_TRUE : EGL_FALSE;
-		break;
-
-	case EGL_MIPMAP_TEXTURE:
-		if(!s->getOSWindowContext())
-			*value = EGL_FALSE;
-		break;
-
-	case EGL_MIPMAP_LEVEL:
-		if(!s->getOSWindowContext())
-			*value = 0;
-		break;
-
-	case EGL_PIXEL_ASPECT_RATIO:
-		*value = EGL_UNKNOWN;			//TODO Display aspect ratio
-		break;
-
-	case EGL_RENDER_BUFFER:
-		*value = s->getRenderBuffer();
-		break;
-
-	case EGL_SWAP_BEHAVIOR:
-		*value = EGL_BUFFER_PRESERVED;
-		break;
-
-	case EGL_TEXTURE_FORMAT:
-		if(!s->getOSWindowContext())
-			*value = EGL_NO_TEXTURE;
-		break;
-
-	case EGL_TEXTURE_TARGET:
-		if(!s->getOSWindowContext())
-			*value = EGL_NO_TEXTURE;
-		break;
-
-	case EGL_VERTICAL_RESOLUTION:
-		*value = EGL_UNKNOWN;			//TODO Vertical dot pitch
-		break;
-
-	case EGL_WIDTH:
-		*value = s->getDrawable()->getWidth();
-		break;
-
-	default:
-		EGL_RETURN(EGL_BAD_ATTRIBUTE, EGL_FALSE);
-	}
-	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLContext do_eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
-#else
-EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
-#endif
-{
-	EGL_GET_DISPLAY(dpy, EGL_NO_CONTEXT);
-	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_NO_CONTEXT);
-	EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_NO_CONTEXT);
-	RI_UNREF(attrib_list);
-
-	RIEGLThread* thread = egl->getThread();
-	if(!thread)
-		EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_CONTEXT);
-
-	//creation of OpenGL ES contexts is not allowed in this implementation
-	if(thread->getBoundAPI() != EGL_OPENVG_API)
-		EGL_RETURN(EGL_BAD_MATCH, EGL_NO_CONTEXT);
-
-    OpenVGRI::VGContext* vgctx = NULL;
-	RIEGLContext* c = NULL;
-	try
-	{
-		vgctx = RI_NEW(OpenVGRI::VGContext, (share_context ? ((RIEGLContext*)share_context)->getVGContext() : NULL));	//throws bad_alloc
-		c = RI_NEW(RIEGLContext, (vgctx, config));	//throws bad_alloc
-		c->addReference();
-		display->addContext(c);	//throws bad_alloc
-	}
-	catch(std::bad_alloc)
-	{
-        RI_DELETE(vgctx);
-        RI_DELETE(c);
-		EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_CONTEXT);
-	}
-
-	EGL_RETURN(EGL_SUCCESS, (EGLContext)c);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLBoolean do_eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
-#else
-EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
-#endif
-{
-	EGL_GET_DISPLAY(dpy, EGL_FALSE);
-	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
-	EGL_IF_ERROR(!display->contextExists(ctx), EGL_BAD_CONTEXT, EGL_FALSE);
-
-	RIEGLContext* context = (RIEGLContext*)ctx;
-    display->removeContext(context);
-	if(!context->removeReference() )
-		RI_DELETE(context);
-
-	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLBoolean do_eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
-#else
-EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
-#endif
-{
-	EGL_GET_DISPLAY(dpy, EGL_FALSE);
-	EGL_IF_ERROR(ctx != EGL_NO_CONTEXT && !display->contextExists(ctx), EGL_BAD_CONTEXT, EGL_FALSE);
-	EGL_IF_ERROR(draw != EGL_NO_SURFACE && !display->surfaceExists(draw), EGL_BAD_SURFACE, EGL_FALSE);
-	EGL_IF_ERROR(read != EGL_NO_SURFACE && !display->surfaceExists(read), EGL_BAD_SURFACE, EGL_FALSE);
-	EGL_IF_ERROR(draw != read, EGL_BAD_MATCH, EGL_FALSE);	//TODO what's the proper error code?
-	EGL_IF_ERROR((draw != EGL_NO_SURFACE && ctx == EGL_NO_CONTEXT) || (draw == EGL_NO_SURFACE && ctx != EGL_NO_CONTEXT), EGL_BAD_MATCH, EGL_FALSE);
-
-	RIEGLSurface* s = NULL;
-	RIEGLContext* c = NULL;
-	if(draw != EGL_NO_SURFACE && ctx != EGL_NO_CONTEXT)
-	{
-		EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
-
-		s = (RIEGLSurface*)draw;
-		c = (RIEGLContext*)ctx;
-
-        //If either draw or read are pbuffers created with eglCreatePbufferFromClientBuffer, and the underlying bound client API buffers
-        //are in use by the client API that created them, an EGL BAD ACCESS error is generated.
-		EGL_IF_ERROR(s->getDrawable()->isInUse(), EGL_BAD_ACCESS, EGL_FALSE);
-
-
-		//TODO properly check compatibility of surface and context:
-		//-both have RGB or LUMINANCE configs
-		//-buffer bit depths match
-		//-configs support OpenVG
-		//-both have the same display
-		EGL_IF_ERROR(s->getConfig() != c->getConfig(), EGL_BAD_MATCH, EGL_FALSE);
-		//TODO check if context or surfaces are already bound to another thread
-
-		//If a native window underlying either draw or read is no longer valid, an EGL BAD NATIVE WINDOW error is generated.
-        EGL_IF_ERROR(s->getOSWindowContext() && !OSIsWindow(s->getOSWindowContext()), EGL_BAD_NATIVE_WINDOW, EGL_FALSE);
-
-		//TODO If the previous context of the calling display has unflushed commands, and the previous surface is no longer valid, an EGL BAD CURRENT SURFACE error is generated. (can this happen?)
-		//TODO If the ancillary buffers for draw and read cannot be allocated, an EGL BAD ALLOC error is generated. (mask buffer?)
-	}
-
-	//check if the thread is current
-	RIEGLThread* thread = egl->getCurrentThread();
-	if(thread)
-	{	//thread is current, release the old bindinds and remove the thread from the current thread list
-		RIEGLContext* pc = thread->getCurrentContext();
-		RIEGLSurface* ps = thread->getCurrentSurface();
-		if(pc)
-		{
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-			do_vgFlush();
-#else
-			vgFlush();
-#endif
-			pc->getVGContext()->setDefaultDrawable(NULL);
-			if(!pc->removeReference())
-				RI_DELETE(pc);
-		}
-		if(ps)
-		{
-			if(!ps->removeReference())
-				RI_DELETE(ps);
-		}
-
-        egl->removeCurrentThread(thread);
-	}
-
-	if( c && s )
-	{
-		//bind context and surface to the current display
-		RIEGLThread* newThread = egl->getThread();
-		if(!newThread)
-			EGL_RETURN(EGL_BAD_ALLOC, EGL_FALSE);
-        newThread->makeCurrent(c, s);
-		c->getVGContext()->setDefaultDrawable(s->getDrawable());
-
-		try
-		{
-			egl->addCurrentThread(newThread);	//throws bad_alloc
-		}
-		catch(std::bad_alloc)
-		{
-			EGL_RETURN(EGL_BAD_ALLOC, EGL_FALSE);
-		}
-
-		c->addReference();
-		s->addReference();
-	}
-	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLContext do_eglGetCurrentContext()
-#else
-EGLContext eglGetCurrentContext()
-#endif
-{
-    EGL_GET_EGL(EGL_NO_CONTEXT);
-	EGLContext ret = EGL_NO_CONTEXT;
-	RIEGLThread* thread = egl->getCurrentThread();
-	if(thread && thread->getBoundAPI() == EGL_OPENVG_API)
-    {
-        ret = CastFromRIEGLContext(thread->getCurrentContext());
-        RI_ASSERT(ret);
-    }
-	EGL_RETURN(EGL_SUCCESS, ret);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLSurface do_eglGetCurrentSurface(EGLint readdraw)
-#else
-EGLSurface eglGetCurrentSurface(EGLint readdraw)
-#endif
-{
-    EGL_GET_EGL(EGL_NO_SURFACE);
-	EGL_IF_ERROR(readdraw != EGL_READ && readdraw != EGL_DRAW, EGL_BAD_PARAMETER, EGL_NO_SURFACE);
-	EGLContext ret = EGL_NO_SURFACE;
-	RIEGLThread* thread = egl->getCurrentThread();
-	if(thread && thread->getBoundAPI() == EGL_OPENVG_API)
-    {
-        ret = CastFromRIEGLSurface(thread->getCurrentSurface());
-        RI_ASSERT(ret);
-    }
-	EGL_RETURN(EGL_SUCCESS, ret);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Returns the current display
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLDisplay do_eglGetCurrentDisplay(void)
-#else
-EGLDisplay eglGetCurrentDisplay(void)
-#endif
-{
-    EGL_GET_EGL(EGL_NO_DISPLAY);
-
-	RIEGLThread* thread = egl->getCurrentThread();
-	if(!thread || thread->getBoundAPI() != EGL_OPENVG_API)
-		EGL_RETURN(EGL_SUCCESS, EGL_NO_DISPLAY);
-
-	RIEGLContext* ctx = thread->getCurrentContext();
-    RI_ASSERT(ctx);
-    EGLDisplay ret = egl->findDisplay(CastFromRIEGLContext(ctx));
-	EGL_RETURN(EGL_SUCCESS, ret);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLBoolean do_eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint* value)
-#else
-EGLBoolean eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint* value)
-#endif
-{
-	EGL_GET_DISPLAY(dpy, EGL_FALSE);
-	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
-	EGL_IF_ERROR(!display->contextExists(ctx), EGL_BAD_CONTEXT, EGL_FALSE);
-	EGL_IF_ERROR(attribute != EGL_CONFIG_ID && attribute != EGL_CONTEXT_CLIENT_TYPE, EGL_BAD_ATTRIBUTE, EGL_FALSE);
-	if(attribute == EGL_CONFIG_ID)
-		*value = display->getConfig(((RIEGLContext*)ctx)->getConfig()).m_configID;
-	if(attribute == EGL_CONTEXT_CLIENT_TYPE)
-		*value = EGL_OPENVG_API;
-	// \todo [kalle 05/Jul/05] Handling of EGL_RENDER_BUFFER attribute is missing.
-	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLBoolean do_eglBindAPI(EGLenum api)
-#else
-EGLBoolean eglBindAPI(EGLenum api)
-#endif
-{
-    EGL_GET_EGL(EGL_FALSE);
-	EGL_IF_ERROR(api != EGL_OPENVG_API && api != EGL_OPENGL_ES_API, EGL_BAD_PARAMETER, EGL_FALSE);
-	RIEGLThread* thread = egl->getThread();
-	if(thread)
-		thread->bindAPI(api);
-	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLenum do_eglQueryAPI(void)
-#else
-EGLenum eglQueryAPI(void)
-#endif
-{
-    EGL_GET_EGL(EGL_NONE);
-	RIEGLThread* thread = egl->getThread();
-	if(thread)
-		EGL_RETURN(EGL_SUCCESS, thread->getBoundAPI());
-	EGL_RETURN(EGL_SUCCESS, EGL_NONE);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLBoolean do_eglWaitClient()
-#else
-EGLBoolean eglWaitClient()
-#endif
-{
-    EGL_GET_EGL(EGL_FALSE);
-	RIEGLThread* thread = egl->getCurrentThread();
-	if(thread && thread->getBoundAPI() == EGL_OPENVG_API)
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-		do_vgFlush();
-#else
-		vgFinish();
-#endif
-	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Waits for OpenGL ES
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLBoolean do_eglWaitGL(void)
-#else
-EGLBoolean eglWaitGL(void)
-#endif
-{
-	return EGL_TRUE;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		We don't support native rendering
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLBoolean do_eglWaitNative(EGLint engine)
-#else
-EGLBoolean eglWaitNative(EGLint engine)
-#endif
-{
-	RI_UNREF(engine);
-	return EGL_TRUE;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLBoolean do_eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
-#else
-EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
-#endif
-{
-	EGL_GET_DISPLAY(dpy, EGL_FALSE);
-	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
-	EGL_IF_ERROR(!display->surfaceExists(surface), EGL_BAD_SURFACE, EGL_FALSE);
-
-	RIEGLSurface* s = (RIEGLSurface*)surface;
-
-	RIEGLThread* currentThread = egl->getCurrentThread();
-	EGL_IF_ERROR(!currentThread || currentThread->getCurrentSurface() != s, EGL_BAD_SURFACE, EGL_FALSE);
-	EGL_IF_ERROR(!OSIsWindow(s->getOSWindowContext()), EGL_BAD_NATIVE_WINDOW, EGL_FALSE);
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-	do_vgFlush();
-#else
-	vgFlush();
-#endif
-
-	if(!s->getOSWindowContext())
-	{	//do nothing for other than window surfaces (NOTE: single-buffered window surfaces should return immediately as well)
-		EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-	}
-
-	int windowWidth = 0, windowHeight = 0;
-    OSGetWindowSize(s->getOSWindowContext(), windowWidth, windowHeight);
-
-	if(windowWidth != s->getDrawable()->getWidth() || windowHeight != s->getDrawable()->getHeight())
-	{	//resize the back buffer
-		RIEGLContext* c = currentThread->getCurrentContext();
-		RI_ASSERT(c);
-		try
-		{
-			s->getDrawable()->resize(windowWidth, windowHeight);	//throws bad_alloc
-		}
-		catch(std::bad_alloc)
-		{
-			c->getVGContext()->setDefaultDrawable(NULL);
-			EGL_RETURN(EGL_BAD_ALLOC, EGL_FALSE);
-		}
-	}
-
-    OSBlitToWindow(s->getOSWindowContext(), s->getDrawable());
-
-	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLBoolean do_eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
-#else
-EGLBoolean eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
-#endif
-{
-	EGL_GET_DISPLAY(dpy, EGL_FALSE);
-	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
-	EGL_IF_ERROR(!display->surfaceExists(surface), EGL_BAD_SURFACE, EGL_FALSE);
-	//EGL_IF_ERROR(!target || !isValidImageFormat(target->format) || !target->data || target->width <= 0 || target->height <= 0, EGL_BAD_NATIVE_PIXMAP, EGL_FALSE);
-	EGLint  width  = -1;
-	EGLint  height = -1;
-	EGLint  stride = -1;
-	VGImageFormat format;
-	int* data = NULL;
-	EGLBoolean err = OSGetNativePixmapInfo(target, &width, &height, &stride,&format, &data);
-	
-	TUint* fdata = (TUint*)((TUint)data + ( stride * ( height - 1  ) ) );	
-	try
-	{
-		Image output(Color::formatToDescriptor(format), width, height, -stride, (RIuint8*)fdata);
-        output.addReference();
-		output.blit(((RIEGLSurface*)surface)->getDrawable()->getColorBuffer(), 0, 0, 0, 0, width, height);	//throws bad_alloc
-        output.removeReference();
-	}
-	catch(std::bad_alloc)
-	{
-	}
-	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-	
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		We support only swap interval one
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLBoolean do_eglSwapInterval(EGLDisplay dpy, EGLint interval)
-#else
-EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval)
-#endif
-{
-	EGL_GET_DISPLAY(dpy, EGL_FALSE);
-	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
-	RI_UNREF(interval);
-	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-typedef void RI_Proc();
-
-//EGLAPI void (* EGLAPIENTRY      eglGetProcAddress(const char *procname))(void);
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY void (*do_eglGetProcAddress(const char *procname))(...)
-#else
-void (*eglGetProcAddress(const char *procname))(...)
-#endif
-{
-	if(!procname)
-		return NULL;
-	return NULL;
-}
-
-
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLBoolean do_eglReleaseThread(void)
-#else
-EGLBoolean eglReleaseThread(void)
-#endif
-{
-    EGL_GET_EGL(EGL_FALSE);
-
-	//check if the thread is current
-	RIEGLThread* thread = egl->getCurrentThread();
-	if(thread)
-	{	//thread is current, release the old bindings and remove the thread from the current thread list
-		RIEGLContext* pc = thread->getCurrentContext();
-		RIEGLSurface* ps = thread->getCurrentSurface();
-		if(pc)
-		{
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-			do_vgFlush();
-#else
-			vgFlush();
-#endif
-			pc->getVGContext()->setDefaultDrawable(NULL);
-			if(!pc->removeReference())
-				RI_DELETE(pc);
-		}
-		if(ps)
-		{
-			if(!ps->removeReference())
-				RI_DELETE(ps);
-		}
-
-        egl->removeCurrentThread(thread);
-	}
-
-    //destroy EGL's thread struct
-    egl->destroyThread();
-
-	//destroy the EGL instance
-	releaseEGL();
-
-	OSReleaseMutex();
-    OSDeinitMutex();
-
-	return EGL_SUCCESS;
-}
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLBoolean do_eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
-#else
-EGLBoolean eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
-#endif
-	{
-	//not implemented
-	RI_ASSERT(0);
-	return false;
-	}
-
-#ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY EGLBoolean do_eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
-#else 
-EGLBoolean eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
-#endif
-	{
-	//not implemented
-	RI_ASSERT(0);
-	return false;
-	}
-#undef EGL_NUMCONFIGS
--- a/egl/sfopenvg/riMiniEGL.h	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,233 +0,0 @@
-#ifndef __RIMINIEGL_H
-#define __RIMINIEGL_H
-
-/*------------------------------------------------------------------------
- *
- * EGL 1.3
- * -------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief	Simple implementation of EGL 1.3
- * \note	caveats:
-			- always renders into the backbuffer and blits it to window (no single buffered rendering)
-			- no native Windows or Mac OS X pixmap support
-			- no power management events
-			- no support for swap interval
- * \todo	what happens in egl functions when eglTerminate has been called but the context and surface are still in use?
- * \todo	OSDeinitMutex should be called in case getEGL fails.
- *//*-------------------------------------------------------------------*/
-#include "egl.h"
-#include "riContext.h"
-
-#ifdef BUILD_WITH_PRIVATE_EGL 
-#include "eglinternal.h"
-#endif
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-#include "openvginternal.h"
-#endif
-
-//==============================================================================================
-
-namespace OpenVGRI
-{
-class RIEGLSurface;
-class RIEGLContext;
-class RIEGLThread;
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-class RIEGLConfig
-{
-public:
-	RIEGLConfig() : m_desc(Color::formatToDescriptor(VG_sRGBA_8888)), m_configID(0)	{}
-	~RIEGLConfig()							{}
-	void		set(int r, int g, int b, int a, int l, int bpp, int samples, int maskBits, int ID)
-	{
-		m_desc.redBits = r;
-		m_desc.greenBits = g;
-		m_desc.blueBits = b;
-		m_desc.alphaBits = a;
-		m_desc.luminanceBits = l;
-		m_desc.alphaShift = 0;
-		m_desc.luminanceShift = 0;
-		m_desc.blueShift = b ? a : 0;
-		m_desc.greenShift = g ? a + b : 0;
-		m_desc.redShift = r ? a + b + g : 0;
-		m_desc.format = (VGImageFormat)-1;
-		m_desc.internalFormat = l ? Color::sLA : Color::sRGBA;
-		m_desc.bitsPerPixel = bpp;
-		RI_ASSERT(Color::isValidDescriptor(m_desc));
-		m_samples = samples;
-        m_maskBits = maskBits;
-		m_configID = ID;
-        m_config = (EGLConfig)ID;
-	}
-
-    Color::Descriptor configToDescriptor(bool sRGB, bool premultiplied) const
-    {
-        Color::Descriptor desc = m_desc;
-        unsigned int f = m_desc.luminanceBits ? Color::LUMINANCE : 0;
-        f |= sRGB ? Color::NONLINEAR : 0;
-        f |= premultiplied ? Color::PREMULTIPLIED : 0;
-        desc.internalFormat = (Color::InternalFormat)f;
-        return desc;
-    }
-
-	//EGL RED SIZE bits of Red in the color buffer
-	//EGL GREEN SIZE bits of Green in the color buffer
-	//EGL BLUE SIZE bits of Blue in the color buffer
-	//EGL ALPHA SIZE bits of Alpha in the color buffer
-	//EGL LUMINANCE SIZE bits of Luminance in the color buffer
-	Color::Descriptor	m_desc;
-	int					m_samples;
-    int                 m_maskBits;
-	EGLint				m_configID;			//EGL CONFIG ID unique EGLConfig identifier
-    EGLConfig           m_config;
-	//EGL BUFFER SIZE depth of the color buffer (sum of channel bits)
-	//EGL ALPHA MASK SIZE number alpha mask bits (always 8)
-	//EGL BIND TO TEXTURE RGB boolean True if bindable to RGB textures. (always EGL_FALSE)
-	//EGL BIND TO TEXTURE RGBA boolean True if bindable to RGBA textures. (always EGL_FALSE)
-	//EGL COLOR BUFFER TYPE enum color buffer type (EGL_RGB_BUFFER, EGL_LUMINANCE_BUFFER)
-	//EGL CONFIG CAVEAT enum any caveats for the configuration (always EGL_NONE)
-	//EGL DEPTH SIZE integer bits of Z in the depth buffer (always 0)
-	//EGL LEVEL integer frame buffer level (always 0)
-	//EGL MAX PBUFFER WIDTH integer maximum width of pbuffer (always INT_MAX)
-	//EGL MAX PBUFFER HEIGHT integer maximum height of pbuffer (always INT_MAX)
-	//EGL MAX PBUFFER PIXELS integer maximum size of pbuffer (always INT_MAX)
-	//EGL MAX SWAP INTERVAL integer maximum swap interval (always 1)
-	//EGL MIN SWAP INTERVAL integer minimum swap interval (always 1)
-	//EGL NATIVE RENDERABLE boolean EGL TRUE if native rendering APIs can render to surface (always EGL_FALSE)
-	//EGL NATIVE VISUAL ID integer handle of corresponding native visual (always 0)
-	//EGL NATIVE VISUAL TYPE integer native visual type of the associated visual (always EGL_NONE)
-	//EGL RENDERABLE TYPE bitmask which client rendering APIs are supported. (always EGL_OPENVG_BIT)
-	//EGL SAMPLE BUFFERS integer number of multisample buffers (always 0)
-	//EGL SAMPLES integer number of samples per pixel (always 0)
-	//EGL STENCIL SIZE integer bits of Stencil in the stencil buffer (always 0)
-	//EGL SURFACE TYPE bitmask which types of EGL surfaces are supported. (always EGL WINDOW BIT | EGL PIXMAP BIT | EGL PBUFFER BIT)
-	//EGL TRANSPARENT TYPE enum type of transparency supported (always EGL_NONE)
-	//EGL TRANSPARENT RED VALUE integer transparent red value (undefined)
-	//EGL TRANSPARENT GREEN VALUE integer transparent green value (undefined)
-	//EGL TRANSPARENT BLUE VALUE integer transparent blue value (undefined)
-};
-
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#define EGL_NUMCONFIGS		60
-
-class RIEGLDisplay
-{
-public:
-	RIEGLDisplay(EGLDisplay id);
-	~RIEGLDisplay();
-
-	int                getNumConfigs() const              { return EGL_NUMCONFIGS; }
-    const RIEGLConfig& getConfigByIdx(int i) const             { RI_ASSERT(i >= 0 && i < EGL_NUMCONFIGS); return m_configs[i]; }
-    const RIEGLConfig& getConfig(const EGLConfig config) const        { for(int i=0;i<EGL_NUMCONFIGS;i++) { if(m_configs[i].m_config == config) return m_configs[i]; } RI_ASSERT(0); return m_configs[0]; }
-
-    EGLDisplay        getID() const                       { return m_id; }
-
-    void              addContext(RIEGLContext* ctx)       { RI_ASSERT(ctx); m_contexts.push_back(ctx); }  //throws bad_alloc
-    void              removeContext(RIEGLContext* ctx)    { RI_ASSERT(ctx); bool res = m_contexts.remove(ctx); RI_ASSERT(res); RI_UNREF(res); }
-
-    void              addSurface(RIEGLSurface* srf)       { RI_ASSERT(srf); m_surfaces.push_back(srf); }  //throws bad_alloc
-    void              removeSurface(RIEGLSurface* srf)    { RI_ASSERT(srf); bool res = m_surfaces.remove(srf); RI_ASSERT(res); RI_UNREF(res); }
-
-    EGLBoolean        contextExists(const EGLContext ctx) const;
-    EGLBoolean        surfaceExists(const EGLSurface srf) const;
-    EGLBoolean        configExists(const EGLConfig cfg) const;
-
-private:
-	RIEGLDisplay(const RIEGLDisplay& t);
-	RIEGLDisplay& operator=(const RIEGLDisplay&t);
-
-	EGLDisplay              m_id;
-
-	Array<RIEGLContext*>	m_contexts;
-	Array<RIEGLSurface*>	m_surfaces;
-
-	RIEGLConfig             m_configs[EGL_NUMCONFIGS];
-};
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-class EGL
-{
-public:
-	EGL();
-	~EGL();
-
-	void	addReference()				{ m_referenceCount++; }
-	int		removeReference()			{ m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
-
-    void                addDisplay(RIEGLDisplay* display)           { RI_ASSERT(display); m_displays.push_back(display); }  //throws bad alloc
-    void                removeDisplay(RIEGLDisplay* display)        { RI_ASSERT(display); bool res = m_displays.remove(display); RI_ASSERT(res); RI_UNREF(res); }
-    RIEGLDisplay*       getDisplay(const EGLDisplay displayID) const;
-    EGLDisplay          findDisplay(const EGLContext ctx) const;
-
-    void                addCurrentThread(RIEGLThread* thread)       { RI_ASSERT(thread); m_currentThreads.push_back(thread); }  //throws bad alloc
-    void                removeCurrentThread(RIEGLThread* thread)    { RI_ASSERT(thread); bool res = m_currentThreads.remove(thread); RI_ASSERT(res); RI_UNREF(res); }
-    RIEGLThread*        getCurrentThread() const;
-
-    RIEGLThread*        getThread();
-    void                destroyThread();
-
-    bool                isInUse(const void* image) const;
-
-private:
-	EGL(const EGL&);						// Not allowed.
-	const EGL& operator=(const EGL&);		// Not allowed.
-
-	Array<RIEGLThread*>		m_threads;			//threads that have called EGL
-	Array<RIEGLThread*>		m_currentThreads;	//threads that have a bound context
-	Array<RIEGLDisplay*>	m_displays;
-
-	int                     m_referenceCount;
-};
-
-void* eglvgGetCurrentVGContext(void);
-bool  eglvgIsInUse(void* image);
-
-} //end of namespace
-
-#endif /* __RIMINIEGL_H */
-
-
--- a/egl/sfopenvg/riPath.cpp	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2580 +0,0 @@
-/*------------------------------------------------------------------------
- *
- * OpenVG 1.1 Reference Implementation
- * -----------------------------------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief	Implementation of Path functions.
- * \note	
- *//*-------------------------------------------------------------------*/
-
-#include "riPath.h"
-
-using namespace OpenVGRI;
-//==============================================================================================
-
-
-//==============================================================================================
-
-namespace OpenVGRI
-{
-
-RIfloat inputFloat(VGfloat f);	//defined in riApi.cpp
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Form a reliable normalized average of the two unit input vectors.
-*           The average always lies to the given direction from the first
-*			vector.
-* \param	u0, u1 Unit input vectors.
-* \param	cw True if the average should be clockwise from u0, false if
-*              counterclockwise.
-* \return	Average of the two input vectors.
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static const Vector2 unitAverage(const Vector2& u0, const Vector2& u1, bool cw)
-{
-	Vector2 u = 0.5f * (u0 + u1);
-	Vector2 n0 = perpendicularCCW(u0);
-
-	if( dot(u, u) > 0.25f )
-	{	//the average is long enough and thus reliable
-		if( dot(n0, u1) < 0.0f )
-			u = -u;	//choose the larger angle
-	}
-	else
-	{	// the average is too short, use the average of the normals to the vectors instead
-		Vector2 n1 = perpendicularCW(u1);
-		u = 0.5f * (n0 + n1);
-	}
-	if( cw )
-		u = -u;
-
-	return normalize(u);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Form a reliable normalized average of the two unit input vectors.
-*			The average lies on the side where the angle between the input
-*			vectors is less than 180 degrees.
-* \param	u0, u1 Unit input vectors.
-* \return	Average of the two input vectors.
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static const Vector2 unitAverage(const Vector2& u0, const Vector2& u1)
-{
-	Vector2 u = 0.5f * (u0 + u1);
-
-	if( dot(u, u) < 0.25f )
-	{	// the average is unreliable, use the average of the normals to the vectors instead
-		Vector2 n0 = perpendicularCCW(u0);
-		Vector2 n1 = perpendicularCW(u1);
-		u = 0.5f * (n0 + n1);
-		if( dot(n1, u0) < 0.0f )
-			u = -u;
-	}
-
-	return normalize(u);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Interpolate the given unit tangent vectors to the given
-*			direction on a unit circle.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static const Vector2 circularLerp(const Vector2& t0, const Vector2& t1, RIfloat ratio, bool cw)
-{
-	Vector2 u0 = t0, u1 = t1;
-	RIfloat l0 = 0.0f, l1 = 1.0f;
-	for(int i=0;i<18;i++)
-	{
-		Vector2 n = unitAverage(u0, u1, cw);
-		RIfloat l = 0.5f * (l0 + l1);
-		if( ratio < l )
-		{
-			u1 = n;
-			l1 = l;
-		}
-		else
-		{
-			u0 = n;
-			l0 = l;
-		}
-	}
-	return u0;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Interpolate the given unit tangent vectors on a unit circle.
-*			Smaller angle between the vectors is used.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static const Vector2 circularLerp(const Vector2& t0, const Vector2& t1, RIfloat ratio)
-{
-	Vector2 u0 = t0, u1 = t1;
-	RIfloat l0 = 0.0f, l1 = 1.0f;
-	for(int i=0;i<18;i++)
-	{
-		Vector2 n = unitAverage(u0, u1);
-		RIfloat l = 0.5f * (l0 + l1);
-		if( ratio < l )
-		{
-			u1 = n;
-			l1 = l;
-		}
-		else
-		{
-			u0 = n;
-			l0 = l;
-		}
-	}
-	return u0;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Path constructor.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Path::Path(VGint format, VGPathDatatype datatype, RIfloat scale, RIfloat bias, int segmentCapacityHint, int coordCapacityHint, VGbitfield caps) :
-	m_format(format),
-	m_datatype(datatype),
-	m_scale(scale),
-	m_bias(bias),
-	m_capabilities(caps),
-	m_referenceCount(0),
-	m_segments(),
-	m_data(),
-	m_vertices(),
-	m_segmentToVertex(),
-	m_userMinx(0.0f),
-	m_userMiny(0.0f),
-	m_userMaxx(0.0f),
-	m_userMaxy(0.0f)
-{
-	RI_ASSERT(format == VG_PATH_FORMAT_STANDARD);
-	RI_ASSERT(datatype >= VG_PATH_DATATYPE_S_8 && datatype <= VG_PATH_DATATYPE_F);
-	if(segmentCapacityHint > 0)
-		m_segments.reserve(RI_INT_MIN(segmentCapacityHint, 65536));
-	if(coordCapacityHint > 0)
-		m_data.reserve(RI_INT_MIN(coordCapacityHint, 65536) * getBytesPerCoordinate(datatype));
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Path destructor.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Path::~Path()
-{
-	RI_ASSERT(m_referenceCount == 0);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Reads a coordinate and applies scale and bias.
-* \param	
-* \return	
-*//*-------------------------------------------------------------------*/
-
-RIfloat Path::getCoordinate(int i) const
-{
-	RI_ASSERT(i >= 0 && i < m_data.size() / getBytesPerCoordinate(m_datatype));
-	RI_ASSERT(m_scale != 0.0f);
-
-	const RIuint8* ptr = &m_data[0];
-	switch(m_datatype)
-	{
-	case VG_PATH_DATATYPE_S_8:
-		return (RIfloat)(((const RIint8*)ptr)[i]) * m_scale + m_bias;
-
-	case VG_PATH_DATATYPE_S_16:
-		return (RIfloat)(((const RIint16*)ptr)[i]) * m_scale + m_bias;
-
-	case VG_PATH_DATATYPE_S_32:
-		return (RIfloat)(((const RIint32*)ptr)[i]) * m_scale + m_bias;
-
-	default:
-		RI_ASSERT(m_datatype == VG_PATH_DATATYPE_F);
-		return (RIfloat)(((const RIfloat32*)ptr)[i]) * m_scale + m_bias;
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Writes a coordinate, subtracting bias and dividing out scale.
-* \param	
-* \return	
-* \note		If the coordinates do not fit into path datatype range, they
-*			will overflow silently.
-*//*-------------------------------------------------------------------*/
-
-void Path::setCoordinate(Array<RIuint8>& data, VGPathDatatype datatype, RIfloat scale, RIfloat bias, int i, RIfloat c)
-{
-	RI_ASSERT(i >= 0 && i < data.size()/getBytesPerCoordinate(datatype));
-	RI_ASSERT(scale != 0.0f);
-
-	c -= bias;
-	c /= scale;
-
-	RIuint8* ptr = &data[0];
-	switch(datatype)
-	{
-	case VG_PATH_DATATYPE_S_8:
-		((RIint8*)ptr)[i] = (RIint8)floor(c + 0.5f);	//add 0.5 for correct rounding
-		break;
-
-	case VG_PATH_DATATYPE_S_16:
-		((RIint16*)ptr)[i] = (RIint16)floor(c + 0.5f);	//add 0.5 for correct rounding
-		break;
-
-	case VG_PATH_DATATYPE_S_32:
-		((RIint32*)ptr)[i] = (RIint32)floor(c + 0.5f);	//add 0.5 for correct rounding
-		break;
-
-	default:
-		RI_ASSERT(datatype == VG_PATH_DATATYPE_F);
-		((RIfloat32*)ptr)[i] = (RIfloat32)c;
-		break;
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Given a datatype, returns the number of bytes per coordinate.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-int Path::getBytesPerCoordinate(VGPathDatatype datatype)
-{
-	if(datatype == VG_PATH_DATATYPE_S_8)
-		return 1;
-	if(datatype == VG_PATH_DATATYPE_S_16)
-		return 2;
-	RI_ASSERT(datatype == VG_PATH_DATATYPE_S_32 || datatype == VG_PATH_DATATYPE_F);
-	return 4;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Given a path segment type, returns the number of coordinates
-*			it uses.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-int Path::segmentToNumCoordinates(VGPathSegment segment)
-{
-	RI_ASSERT(((int)segment >> 1) >= 0 && ((int)segment >> 1) <= 12);
-	static const int coords[13] = {0,2,2,1,1,4,6,2,4,5,5,5,5};
-	return coords[(int)segment >> 1];
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Computes the number of coordinates a segment sequence uses.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-int Path::countNumCoordinates(const RIuint8* segments, int numSegments)
-{
-	RI_ASSERT(segments);
-	RI_ASSERT(numSegments >= 0);
-
-	int coordinates = 0;
-	for(int i=0;i<numSegments;i++)
-		coordinates += segmentToNumCoordinates(getPathSegment(segments[i]));
-	return coordinates;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Clears path segments and data, and resets capabilities.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Path::clear(VGbitfield capabilities)
-{
-	m_segments.clear();
-	m_data.clear();
-	m_capabilities = capabilities;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Appends user segments and data.
-* \param	
-* \return	
-* \note		if runs out of memory, throws bad_alloc and leaves the path as it was
-*//*-------------------------------------------------------------------*/
-
-void Path::appendData(const RIuint8* segments, int numSegments, const RIuint8* data)
-{
-	RI_ASSERT(numSegments > 0);
-	RI_ASSERT(segments && data);
-	RI_ASSERT(m_referenceCount > 0);
-
-	//allocate new arrays
-	int oldSegmentsSize = m_segments.size();
-	int newSegmentsSize = oldSegmentsSize + numSegments;
-	Array<RIuint8> newSegments;
-	newSegments.resize(newSegmentsSize);	//throws bad_alloc
-
-	int newCoords = countNumCoordinates(segments, numSegments);
-	int bytesPerCoordinate = getBytesPerCoordinate(m_datatype);
-	int newDataSize = m_data.size() + newCoords * bytesPerCoordinate;
-	Array<RIuint8> newData;
-	newData.resize(newDataSize);	//throws bad_alloc
-	//if we get here, the memory allocations have succeeded
-
-	//copy old segments and append new ones
-	if(m_segments.size())
-		memcpy(&newSegments[0], &m_segments[0], m_segments.size());
-	memcpy(&newSegments[0] + m_segments.size(), segments, numSegments);
-
-	//copy old data and append new ones
-	if(newData.size())
-	{
-		if(m_data.size())
-			memcpy(&newData[0], &m_data[0], m_data.size());
-		if(m_datatype == VG_PATH_DATATYPE_F)
-		{
-			RIfloat32* d = (RIfloat32*)(&newData[0] + m_data.size());
-			const RIfloat32* s = (const RIfloat32*)data;
-			for(int i=0;i<newCoords;i++)
-				*d++ = (RIfloat32)inputFloat(*s++);
-		}
-		else
-		{
-			memcpy(&newData[0] + m_data.size(), data, newCoords * bytesPerCoordinate);
-		}
-	}
-
-	RI_ASSERT(newData.size() == countNumCoordinates(&newSegments[0],newSegments.size()) * getBytesPerCoordinate(m_datatype));
-
-	//replace old arrays
-	m_segments.swap(newSegments);
-	m_data.swap(newData);
-
-	int c = 0;
-	for(int i=0;i<m_segments.size();i++)
-	{
-		VGPathSegment segment = getPathSegment(m_segments[i]);
-		int coords = segmentToNumCoordinates(segment);
-		c += coords;
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Appends a path.
-* \param	
-* \return	
-* \note		if runs out of memory, throws bad_alloc and leaves the path as it was
-*//*-------------------------------------------------------------------*/
-
-void Path::append(const Path* srcPath)
-{
-	RI_ASSERT(srcPath);
-	RI_ASSERT(m_referenceCount > 0 && srcPath->m_referenceCount > 0);
-
-	if(srcPath->m_segments.size())
-	{
-		//allocate new arrays
-		int newSegmentsSize = m_segments.size() + srcPath->m_segments.size();
-		Array<RIuint8> newSegments;
-		newSegments.resize(newSegmentsSize);	//throws bad_alloc
-
-		int newDataSize = m_data.size() + srcPath->getNumCoordinates() * getBytesPerCoordinate(m_datatype);
-		Array<RIuint8> newData;
-		newData.resize(newDataSize);	//throws bad_alloc
-		//if we get here, the memory allocations have succeeded
-
-		//copy old segments and append new ones
-		if(m_segments.size())
-			memcpy(&newSegments[0], &m_segments[0], m_segments.size());
-		if(srcPath->m_segments.size())
-			memcpy(&newSegments[0] + m_segments.size(), &srcPath->m_segments[0], srcPath->m_segments.size());
-
-		//copy old data and append new ones
-		if(m_data.size())
-			memcpy(&newData[0], &m_data[0], m_data.size());
-		for(int i=0;i<srcPath->getNumCoordinates();i++)
-			setCoordinate(newData, m_datatype, m_scale, m_bias, i + getNumCoordinates(), srcPath->getCoordinate(i));
-
-		RI_ASSERT(newData.size() == countNumCoordinates(&newSegments[0],newSegments.size()) * getBytesPerCoordinate(m_datatype));
-
-		//replace old arrays
-		m_segments.swap(newSegments);
-		m_data.swap(newData);
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Modifies existing coordinate data.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Path::modifyCoords(int startIndex, int numSegments, const RIuint8* data)
-{
-	RI_ASSERT(numSegments > 0);
-	RI_ASSERT(startIndex >= 0 && startIndex + numSegments <= m_segments.size());
-	RI_ASSERT(data);
-	RI_ASSERT(m_referenceCount > 0);
-
-	int startCoord = countNumCoordinates(&m_segments[0], startIndex);
-	int numCoords = countNumCoordinates(&m_segments[startIndex], numSegments);
-	if(!numCoords)
-		return;
-	int bytesPerCoordinate = getBytesPerCoordinate(m_datatype);
-	RIuint8* dst = &m_data[startCoord * bytesPerCoordinate];
-	if(m_datatype == VG_PATH_DATATYPE_F)
-	{
-		RIfloat32* d = (RIfloat32*)dst;
-		const RIfloat32* s = (const RIfloat32*)data;
-		for(int i=0;i<numCoords;i++)
-			*d++ = (RIfloat32)inputFloat(*s++);
-	}
-	else
-	{
-		memcpy(dst, data, numCoords*bytesPerCoordinate);
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Appends a transformed copy of the source path.
-* \param	
-* \return	
-* \note		if runs out of memory, throws bad_alloc and leaves the path as it was
-*//*-------------------------------------------------------------------*/
-
-void Path::transform(const Path* srcPath, const Matrix3x3& matrix)
-{
-	RI_ASSERT(srcPath);
-	RI_ASSERT(m_referenceCount > 0 && srcPath->m_referenceCount > 0);
-	RI_ASSERT(matrix.isAffine());
-
-	if(!srcPath->m_segments.size())
-		return;
-
-	//count the number of resulting coordinates
-	int numSrcCoords = 0;
-	int numDstCoords = 0;
-	for(int i=0;i<srcPath->m_segments.size();i++)
-	{
-		VGPathSegment segment = getPathSegment(srcPath->m_segments[i]);
-		int coords = segmentToNumCoordinates(segment);
-		numSrcCoords += coords;
-		if(segment == VG_HLINE_TO || segment == VG_VLINE_TO)
-			coords = 2;	//convert hline and vline to lines
-		numDstCoords += coords;
-	}
-
-	//allocate new arrays
-	Array<RIuint8> newSegments;
-	newSegments.resize(m_segments.size() + srcPath->m_segments.size());	//throws bad_alloc
-	Array<RIuint8> newData;
-	newData.resize(m_data.size() + numDstCoords * getBytesPerCoordinate(m_datatype));	//throws bad_alloc
-	//if we get here, the memory allocations have succeeded
-
-	//copy old segments
-	if(m_segments.size())
-		memcpy(&newSegments[0], &m_segments[0], m_segments.size());
-
-	//copy old data
-	if(m_data.size())
-		memcpy(&newData[0], &m_data[0], m_data.size());
-
-	int srcCoord = 0;
-	int dstCoord = getNumCoordinates();
-	Vector2 s(0,0);		//the beginning of the current subpath
-	Vector2 o(0,0);		//the last point of the previous segment
-	for(int i=0;i<srcPath->m_segments.size();i++)
-	{
-		VGPathSegment segment = getPathSegment(srcPath->m_segments[i]);
-		VGPathAbsRel absRel = getPathAbsRel(srcPath->m_segments[i]);
-		int coords = segmentToNumCoordinates(segment);
-
-		switch(segment)
-		{
-		case VG_CLOSE_PATH:
-		{
-			RI_ASSERT(coords == 0);
-			o = s;
-			break;
-		}
-
-		case VG_MOVE_TO:
-		{
-			RI_ASSERT(coords == 2);
-			Vector2 c(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
-            Vector2 tc;
-
-			if (absRel == VG_ABSOLUTE)
-                tc = affineTransform(matrix, c);
-            else
-            {
-                tc = affineTangentTransform(matrix, c);
-				c += o;
-            }
-			
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.x);
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.y);
-			s = c;
-			o = c;
-			break;
-		}
-
-		case VG_LINE_TO:
-		{
-			RI_ASSERT(coords == 2);
-			Vector2 c(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
-            Vector2 tc;
-
-			if (absRel == VG_ABSOLUTE)
-                tc = affineTransform(matrix, c);
-            else
-            {
-                tc = affineTangentTransform(matrix, c);
-				c += o;
-            }
-
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.x);
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.y);
-			o = c;
-			break;
-		}
-
-		case VG_HLINE_TO:
-		{
-			RI_ASSERT(coords == 1);
-			Vector2 c(srcPath->getCoordinate(srcCoord+0), 0);
-            Vector2 tc;
-
-			if (absRel == VG_ABSOLUTE)
-            {
-                c.y = o.y;
-                tc = affineTransform(matrix, c);
-            }
-            else
-            {
-                tc = affineTangentTransform(matrix, c);
-				c += o;
-            }
-
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.x);
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.y);
-			o = c;
-			segment = VG_LINE_TO;
-			break;
-		}
-
-		case VG_VLINE_TO:
-		{
-			RI_ASSERT(coords == 1);
-			Vector2 c(0, srcPath->getCoordinate(srcCoord+0));
-            Vector2 tc;
-
-			if (absRel == VG_ABSOLUTE)
-            {
-                c.x = o.x;
-                tc = affineTransform(matrix, c);
-            }
-            else
-            {
-                tc = affineTangentTransform(matrix, c);
-				c += o;
-            }
-
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.x);
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.y);
-			o = c;
-			segment = VG_LINE_TO;
-			break;
-		}
-
-		case VG_QUAD_TO:
-		{
-			RI_ASSERT(coords == 4);
-			Vector2 c0(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
-			Vector2 c1(srcPath->getCoordinate(srcCoord+2), srcPath->getCoordinate(srcCoord+3));
-            Vector2 tc0, tc1;
-
-			if (absRel == VG_ABSOLUTE)
-            {
-                tc0 = affineTransform(matrix, c0);
-                tc1 = affineTransform(matrix, c1);
-            }
-            else
-            {
-                tc0 = affineTangentTransform(matrix, c0);
-                tc1 = affineTangentTransform(matrix, c1);
-                c1 += o;
-            }
-
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc0.x);
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc0.y);
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.x);
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.y);
-			o = c1;
-			break;
-		}
-
-		case VG_CUBIC_TO:
-		{
-			RI_ASSERT(coords == 6);
-			Vector2 c0(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
-			Vector2 c1(srcPath->getCoordinate(srcCoord+2), srcPath->getCoordinate(srcCoord+3));
-			Vector2 c2(srcPath->getCoordinate(srcCoord+4), srcPath->getCoordinate(srcCoord+5));
-            Vector2 tc0, tc1, tc2;
-
-			if (absRel == VG_ABSOLUTE)
-            {
-                tc0 = affineTransform(matrix, c0);
-                tc1 = affineTransform(matrix, c1);
-                tc2 = affineTransform(matrix, c2);
-            }
-            else
-            {
-                tc0 = affineTangentTransform(matrix, c0);
-                tc1 = affineTangentTransform(matrix, c1);
-                tc2 = affineTangentTransform(matrix, c2);
-                c2 += o;
-            }
-
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc0.x);
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc0.y);
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.x);
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.y);
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc2.x);
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc2.y);
-			o = c2;
-			break;
-		}
-
-		case VG_SQUAD_TO:
-		{
-			RI_ASSERT(coords == 2);
-			Vector2 c1(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
-            Vector2 tc1;
-
-			if (absRel == VG_ABSOLUTE)
-                tc1 = affineTransform(matrix, c1);
-            else
-            {
-                tc1 = affineTangentTransform(matrix, c1);
-                c1 += o;
-            }
-
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.x);
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.y);
-			o = c1;
-			break;
-		}
-
-		case VG_SCUBIC_TO:
-		{
-			RI_ASSERT(coords == 4);
-			Vector2 c1(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
-			Vector2 c2(srcPath->getCoordinate(srcCoord+2), srcPath->getCoordinate(srcCoord+3));
-            Vector2 tc1, tc2;
-
-			if (absRel == VG_ABSOLUTE)
-            {
-                tc1 = affineTransform(matrix, c1);
-                tc2 = affineTransform(matrix, c2);
-            }
-            else
-            {
-                tc1 = affineTangentTransform(matrix, c1);
-                tc2 = affineTangentTransform(matrix, c2);
-                c2 += o;
-            }
-
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.x);
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.y);
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc2.x);
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc2.y);
-			o = c2;
-			break;
-		}
-
-		default:
-		{
-			RI_ASSERT(segment == VG_SCCWARC_TO || segment == VG_SCWARC_TO ||
-					  segment == VG_LCCWARC_TO || segment == VG_LCWARC_TO);
-			RI_ASSERT(coords == 5);
-			RIfloat rh = srcPath->getCoordinate(srcCoord+0);
-			RIfloat rv = srcPath->getCoordinate(srcCoord+1);
-			RIfloat rot = srcPath->getCoordinate(srcCoord+2);
-			Vector2 c(srcPath->getCoordinate(srcCoord+3), srcPath->getCoordinate(srcCoord+4));
-
-			rot = RI_DEG_TO_RAD(rot);
-			Matrix3x3 u((RIfloat)cos(rot)*rh, -(RIfloat)sin(rot)*rv,  0,
-						(RIfloat)sin(rot)*rh,  (RIfloat)cos(rot)*rv,  0,
-						0,                   0,                   1);
-			u = matrix * u;
-			u[2].set(0,0,1);		//force affinity
-			//u maps from the unit circle to transformed ellipse
-
-			//compute new rh, rv and rot
-			Vector2	p(u[0][0], u[1][0]);
-			Vector2	q(u[1][1], -u[0][1]);
-			bool swapped = false;
-			if(dot(p,p) < dot(q,q))
-			{
-				RI_SWAP(p.x,q.x);
-				RI_SWAP(p.y,q.y);
-				swapped = true;
-			}
-			Vector2 h = (p+q) * 0.5f;
-			Vector2 hp = (p-q) * 0.5f;
-			RIfloat hlen = h.length();
-			RIfloat hplen = hp.length();
-			rh = hlen + hplen;
-			rv = hlen - hplen;
-			h = hplen * h + hlen * hp;
-			hlen = dot(h,h);
-			if(hlen == 0.0f)
-				rot = 0.0f;
-			else
-			{
-				h.normalize();
-				rot = (RIfloat)acos(h.x);
-				if(h.y < 0.0f)
-					rot = 2.0f*PI - rot;
-			}
-			if(swapped)
-				rot += PI*0.5f;
-
-            Vector2 tc;
-			if (absRel == VG_ABSOLUTE)
-                tc = affineTransform(matrix, c);
-            else
-            {
-                tc = affineTangentTransform(matrix, c);
-                c += o;
-            }
-
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, rh);
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, rv);
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, RI_RAD_TO_DEG(rot));
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.x);
-			setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.y);
-			o = c;
-
-            //flip winding if the determinant is negative
-            if (matrix.det() < 0)
-            {
-                switch (segment)
-                {
-                case VG_SCCWARC_TO: segment = VG_SCWARC_TO;     break;
-                case VG_SCWARC_TO:  segment = VG_SCCWARC_TO;    break;
-                case VG_LCCWARC_TO: segment = VG_LCWARC_TO;     break;
-                case VG_LCWARC_TO:  segment = VG_LCCWARC_TO;    break;
-                default:                                        break;
-                }
-            }
-            break;
-		}
-		}
-
-		newSegments[m_segments.size() + i] = (RIuint8)(segment | absRel);
-		srcCoord += coords;
-	}
-	RI_ASSERT(srcCoord == numSrcCoords);
-	RI_ASSERT(dstCoord == getNumCoordinates() + numDstCoords);
-
-	RI_ASSERT(newData.size() == countNumCoordinates(&newSegments[0],newSegments.size()) * getBytesPerCoordinate(m_datatype));
-
-	//replace old arrays
-	m_segments.swap(newSegments);
-	m_data.swap(newData);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Normalizes a path for interpolation.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Path::normalizeForInterpolation(const Path* srcPath)
-{
-	RI_ASSERT(srcPath);
-	RI_ASSERT(srcPath != this);
-	RI_ASSERT(srcPath->m_referenceCount > 0);
-
-	//count the number of resulting coordinates
-	int numSrcCoords = 0;
-	int numDstCoords = 0;
-	for(int i=0;i<srcPath->m_segments.size();i++)
-	{
-		VGPathSegment segment = getPathSegment(srcPath->m_segments[i]);
-		int coords = segmentToNumCoordinates(segment);
-		numSrcCoords += coords;
-		switch(segment)
-		{
-		case VG_CLOSE_PATH:
-		case VG_MOVE_TO:
-		case VG_LINE_TO:
-			break;
-
-		case VG_HLINE_TO:
-		case VG_VLINE_TO:
-			coords = 2;
-			break;
-
-		case VG_QUAD_TO:
-		case VG_CUBIC_TO:
-		case VG_SQUAD_TO:
-		case VG_SCUBIC_TO:
-			coords = 6;
-			break;
-
-		default:
-			RI_ASSERT(segment == VG_SCCWARC_TO || segment == VG_SCWARC_TO ||
-					  segment == VG_LCCWARC_TO || segment == VG_LCWARC_TO);
-			break;
-		}
-		numDstCoords += coords;
-	}
-
-	m_segments.resize(srcPath->m_segments.size());	//throws bad_alloc
-	m_data.resize(numDstCoords * getBytesPerCoordinate(VG_PATH_DATATYPE_F));	//throws bad_alloc
-
-	int srcCoord = 0;
-	int dstCoord = 0;
-	Vector2 s(0,0);		//the beginning of the current subpath
-	Vector2 o(0,0);		//the last point of the previous segment
-
-	// the last internal control point of the previous segment, if the
-	//segment was a (regular or smooth) quadratic or cubic
-	//Bezier, or else the last point of the previous segment
-	Vector2 p(0,0);		
-	for(int i=0;i<srcPath->m_segments.size();i++)
-	{
-		VGPathSegment segment = getPathSegment(srcPath->m_segments[i]);
-		VGPathAbsRel absRel = getPathAbsRel(srcPath->m_segments[i]);
-		int coords = segmentToNumCoordinates(segment);
-
-		switch(segment)
-		{
-		case VG_CLOSE_PATH:
-		{
-			RI_ASSERT(coords == 0);
-			p = s;
-			o = s;
-			break;
-		}
-
-		case VG_MOVE_TO:
-		{
-			RI_ASSERT(coords == 2);
-			Vector2 c(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
-			if(absRel == VG_RELATIVE)
-				c += o;
-			setCoordinate(dstCoord++, c.x);
-			setCoordinate(dstCoord++, c.y);
-			s = c;
-			p = c;
-			o = c;
-			break;
-		}
-
-		case VG_LINE_TO:
-		{
-			RI_ASSERT(coords == 2);
-			Vector2 c(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
-			if(absRel == VG_RELATIVE)
-				c += o;
-			setCoordinate(dstCoord++, c.x);
-			setCoordinate(dstCoord++, c.y);
-			p = c;
-			o = c;
-			break;
-		}
-
-		case VG_HLINE_TO:
-		{
-			RI_ASSERT(coords == 1);
-			Vector2 c(srcPath->getCoordinate(srcCoord+0), o.y);
-			if(absRel == VG_RELATIVE)
-				c.x += o.x;
-			setCoordinate(dstCoord++, c.x);
-			setCoordinate(dstCoord++, c.y);
-			p = c;
-			o = c;
-			segment = VG_LINE_TO;
-			break;
-		}
-
-		case VG_VLINE_TO:
-		{
-			RI_ASSERT(coords == 1);
-			Vector2 c(o.x, srcPath->getCoordinate(srcCoord+0));
-			if(absRel == VG_RELATIVE)
-				c.y += o.y;
-			setCoordinate(dstCoord++, c.x);
-			setCoordinate(dstCoord++, c.y);
-			p = c;
-			o = c;
-			segment = VG_LINE_TO;
-			break;
-		}
-
-		case VG_QUAD_TO:
-		{
-			RI_ASSERT(coords == 4);
-			Vector2 c0(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
-			Vector2 c1(srcPath->getCoordinate(srcCoord+2), srcPath->getCoordinate(srcCoord+3));
-			if(absRel == VG_RELATIVE)
-			{
-				c0 += o;
-				c1 += o;
-			}
-			Vector2 d0 = (1.0f/3.0f) * (o + 2.0f * c0);
-			Vector2 d1 = (1.0f/3.0f) * (c1 + 2.0f * c0);
-			setCoordinate(dstCoord++, d0.x);
-			setCoordinate(dstCoord++, d0.y);
-			setCoordinate(dstCoord++, d1.x);
-			setCoordinate(dstCoord++, d1.y);
-			setCoordinate(dstCoord++, c1.x);
-			setCoordinate(dstCoord++, c1.y);
-			p = c0;
-			o = c1;
-			segment = VG_CUBIC_TO;
-			break;
-		}
-
-		case VG_CUBIC_TO:
-		{
-			RI_ASSERT(coords == 6);
-			Vector2 c0(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
-			Vector2 c1(srcPath->getCoordinate(srcCoord+2), srcPath->getCoordinate(srcCoord+3));
-			Vector2 c2(srcPath->getCoordinate(srcCoord+4), srcPath->getCoordinate(srcCoord+5));
-			if(absRel == VG_RELATIVE)
-			{
-				c0 += o;
-				c1 += o;
-				c2 += o;
-			}
-			setCoordinate(dstCoord++, c0.x);
-			setCoordinate(dstCoord++, c0.y);
-			setCoordinate(dstCoord++, c1.x);
-			setCoordinate(dstCoord++, c1.y);
-			setCoordinate(dstCoord++, c2.x);
-			setCoordinate(dstCoord++, c2.y);
-			p = c1;
-			o = c2;
-			break;
-		}
-
-		case VG_SQUAD_TO:
-		{
-			RI_ASSERT(coords == 2);
-			Vector2 c0 = 2.0f * o - p;
-			Vector2 c1(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
-			if(absRel == VG_RELATIVE)
-				c1 += o;
-			Vector2 d0 = (1.0f/3.0f) * (o + 2.0f * c0);
-			Vector2 d1 = (1.0f/3.0f) * (c1 + 2.0f * c0);
-			setCoordinate(dstCoord++, d0.x);
-			setCoordinate(dstCoord++, d0.y);
-			setCoordinate(dstCoord++, d1.x);
-			setCoordinate(dstCoord++, d1.y);
-			setCoordinate(dstCoord++, c1.x);
-			setCoordinate(dstCoord++, c1.y);
-			p = c0;
-			o = c1;
-			segment = VG_CUBIC_TO;
-			break;
-		}
-
-		case VG_SCUBIC_TO:
-		{
-			RI_ASSERT(coords == 4);
-			Vector2 c0 = 2.0f * o - p;
-			Vector2 c1(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
-			Vector2 c2(srcPath->getCoordinate(srcCoord+2), srcPath->getCoordinate(srcCoord+3));
-			if(absRel == VG_RELATIVE)
-			{
-				c1 += o;
-				c2 += o;
-			}
-			setCoordinate(dstCoord++, c0.x);
-			setCoordinate(dstCoord++, c0.y);
-			setCoordinate(dstCoord++, c1.x);
-			setCoordinate(dstCoord++, c1.y);
-			setCoordinate(dstCoord++, c2.x);
-			setCoordinate(dstCoord++, c2.y);
-			p = c1;
-			o = c2;
-			segment = VG_CUBIC_TO;
-			break;
-		}
-
-		default:
-		{
-			RI_ASSERT(segment == VG_SCCWARC_TO || segment == VG_SCWARC_TO ||
-					  segment == VG_LCCWARC_TO || segment == VG_LCWARC_TO);
-			RI_ASSERT(coords == 5);
-			RIfloat rh = srcPath->getCoordinate(srcCoord+0);
-			RIfloat rv = srcPath->getCoordinate(srcCoord+1);
-			RIfloat rot = srcPath->getCoordinate(srcCoord+2);
-			Vector2 c(srcPath->getCoordinate(srcCoord+3), srcPath->getCoordinate(srcCoord+4));
-			if(absRel == VG_RELATIVE)
-				c += o;
-			setCoordinate(dstCoord++, rh);
-			setCoordinate(dstCoord++, rv);
-			setCoordinate(dstCoord++, rot);
-			setCoordinate(dstCoord++, c.x);
-			setCoordinate(dstCoord++, c.y);
-			p = c;
-			o = c;
-			break;
-		}
-		}
-
-		m_segments[i] = (RIuint8)(segment | VG_ABSOLUTE);
-		srcCoord += coords;
-	}
-	RI_ASSERT(srcCoord == numSrcCoords);
-	RI_ASSERT(dstCoord == numDstCoords);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Appends a linearly interpolated copy of the two source paths.
-* \param	
-* \return	
-* \note		if runs out of memory, throws bad_alloc and leaves the path as it was
-*//*-------------------------------------------------------------------*/
-
-bool Path::interpolate(const Path* startPath, const Path* endPath, RIfloat amount)
-{
-	RI_ASSERT(startPath && endPath);
-	RI_ASSERT(m_referenceCount > 0 && startPath->m_referenceCount > 0 && endPath->m_referenceCount > 0);
-
-	if(!startPath->m_segments.size() || startPath->m_segments.size() != endPath->m_segments.size())
-		return false;	//start and end paths are incompatible or zero length
-
-	Path start(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, 0);
-	start.normalizeForInterpolation(startPath);	//throws bad_alloc
-
-	Path end(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, 0);
-	end.normalizeForInterpolation(endPath);	//throws bad_alloc
-
-	//check that start and end paths are compatible
-	if(start.m_data.size() != end.m_data.size() || start.m_segments.size() != end.m_segments.size())
-		return false;	//start and end paths are incompatible
-
-	//allocate new arrays
-	Array<RIuint8> newSegments;
-	newSegments.resize(m_segments.size() + start.m_segments.size());	//throws bad_alloc
-	Array<RIuint8> newData;
-	newData.resize(m_data.size() + start.m_data.size() * getBytesPerCoordinate(m_datatype) / getBytesPerCoordinate(start.m_datatype));	//throws bad_alloc
-	//if we get here, the memory allocations have succeeded
-
-	//copy old segments
-	if(m_segments.size())
-		memcpy(&newSegments[0], &m_segments[0], m_segments.size());
-
-	//copy old data
-	if(m_data.size())
-		memcpy(&newData[0], &m_data[0], m_data.size());
-
-	//copy segments
-	for(int i=0;i<start.m_segments.size();i++)
-	{
-		VGPathSegment s = getPathSegment(start.m_segments[i]);
-		VGPathSegment e = getPathSegment(end.m_segments[i]);
-
-		if(s == VG_SCCWARC_TO || s == VG_SCWARC_TO || s == VG_LCCWARC_TO || s == VG_LCWARC_TO)
-		{
-			if(e != VG_SCCWARC_TO && e != VG_SCWARC_TO && e != VG_LCCWARC_TO && e != VG_LCWARC_TO)
-				return false;	//start and end paths are incompatible
-			if(amount < 0.5f)
-				newSegments[m_segments.size() + i] = start.m_segments[i];
-			else
-				newSegments[m_segments.size() + i] = end.m_segments[i];
-		}
-		else
-		{
-			if(s != e)
-				return false;	//start and end paths are incompatible
-			newSegments[m_segments.size() + i] = start.m_segments[i];
-		}
-	}
-
-	//interpolate data
-	int oldNumCoords = getNumCoordinates();
-	for(int i=0;i<start.getNumCoordinates();i++)
-		setCoordinate(newData, m_datatype, m_scale, m_bias, oldNumCoords + i, start.getCoordinate(i) * (1.0f - amount) + end.getCoordinate(i) * amount);
-
-	RI_ASSERT(newData.size() == countNumCoordinates(&newSegments[0],newSegments.size()) * getBytesPerCoordinate(m_datatype));
-
-	//replace old arrays
-	m_segments.swap(newSegments);
-	m_data.swap(newData);
-
-	return true;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Tessellates a path for filling and appends resulting edges
-*			to a rasterizer.
-* \param	
-* \return	
-* \note		if runs out of memory, throws bad_alloc and leaves the path as it was
-*//*-------------------------------------------------------------------*/
-
-void Path::fill(const Matrix3x3& pathToSurface, Rasterizer& rasterizer)
-{
-	RI_ASSERT(m_referenceCount > 0);
-	RI_ASSERT(pathToSurface.isAffine());
-
-	tessellate(pathToSurface, 0.0f);	//throws bad_alloc
-
-	try
-	{
-		Vector2 p0(0,0), p1(0,0);
-		for(int i=0;i<m_vertices.size();i++)
-		{
-			p1 = affineTransform(pathToSurface, m_vertices[i].userPosition);
-
-			if(!(m_vertices[i].flags & START_SEGMENT))
-			{	//in the middle of a segment
-				rasterizer.addEdge(p0, p1);	//throws bad_alloc
-			}
-
-			p0 = p1;
-		}
-	}
-	catch(std::bad_alloc)
-	{
-		rasterizer.clear();	//remove the unfinished path
-		throw;
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Smoothly interpolates between two StrokeVertices. Positions
-*			are interpolated linearly, while tangents are interpolated
-*			on a unit circle. Stroking is implemented so that overlapping
-*			geometry doesnt cancel itself when filled with nonzero rule.
-*			The resulting polygons are closed.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Path::interpolateStroke(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const StrokeVertex& v0, const StrokeVertex& v1, RIfloat strokeWidth) const
-{
-	Vector2 pccw = affineTransform(pathToSurface, v0.ccw);
-	Vector2 pcw = affineTransform(pathToSurface, v0.cw);
-	Vector2 p = affineTransform(pathToSurface, v0.p);
-	Vector2 endccw = affineTransform(pathToSurface, v1.ccw);
-	Vector2 endcw = affineTransform(pathToSurface, v1.cw);
-	Vector2 endp = affineTransform(pathToSurface, v1.p);
-
-	const RIfloat tessellationAngle = 5.0f;
-
-	RIfloat angle = RI_RAD_TO_DEG((RIfloat)acos(RI_CLAMP(dot(v0.t, v1.t), -1.0f, 1.0f))) / tessellationAngle;
-	int samples = RI_INT_MAX((int)ceil(angle), 1);
-
-	for(int j=0;j<samples-1;j++)
-	{
-		RIfloat t = (RIfloat)(j+1) / (RIfloat)samples;
-		Vector2 position = v0.p * (1.0f - t) + v1.p * t;
-		Vector2 tangent = circularLerp(v0.t, v1.t, t);
-		Vector2 normal = normalize(perpendicularCCW(tangent)) * strokeWidth * 0.5f;
-
-		Vector2 nccw = affineTransform(pathToSurface, position + normal);
-		Vector2 ncw = affineTransform(pathToSurface, position - normal);
-		Vector2 n = affineTransform(pathToSurface, position);
-
-        rasterizer.clear();
-		rasterizer.addEdge(p, pccw);	//throws bad_alloc
-		rasterizer.addEdge(pccw, nccw);	//throws bad_alloc
-		rasterizer.addEdge(nccw, n);	//throws bad_alloc
-		rasterizer.addEdge(n, ncw);     //throws bad_alloc
-		rasterizer.addEdge(ncw, pcw);	//throws bad_alloc
-		rasterizer.addEdge(pcw, p);	    //throws bad_alloc
-        rasterizer.fill();
-
-		pccw = nccw;
-		pcw = ncw;
-        p = n;
-	}
-
-	//connect the last segment to the end coordinates
-    rasterizer.clear();
-	rasterizer.addEdge(p, pccw);	    //throws bad_alloc
-	rasterizer.addEdge(pccw, endccw);	//throws bad_alloc
-	rasterizer.addEdge(endccw, endp);	//throws bad_alloc
-	rasterizer.addEdge(endp, endcw);	//throws bad_alloc
-	rasterizer.addEdge(endcw, pcw);     //throws bad_alloc
-	rasterizer.addEdge(pcw, p);         //throws bad_alloc
-    rasterizer.fill();
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Generate edges for stroke caps. Resulting polygons are closed.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Path::doCap(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const StrokeVertex& v, RIfloat strokeWidth, VGCapStyle capStyle) const
-{
-	Vector2 ccwt = affineTransform(pathToSurface, v.ccw);
-	Vector2 cwt = affineTransform(pathToSurface, v.cw);
-	Vector2 p = affineTransform(pathToSurface, v.p);
-
-    rasterizer.clear();
-	switch(capStyle)
-	{
-	case VG_CAP_BUTT:
-		break;
-
-	case VG_CAP_ROUND:
-	{
-        const RIfloat tessellationAngle = 5.0f;
-
-		RIfloat angle = 180.0f / tessellationAngle;
-
-		int samples = (int)ceil(angle);
-		RIfloat step = 1.0f / samples;
-		RIfloat t = step;
-		Vector2 u0 = normalize(v.ccw - v.p);
-		Vector2 u1 = normalize(v.cw - v.p);
-		Vector2 prev = ccwt;
-		rasterizer.addEdge(p, ccwt);	//throws bad_alloc
-		for(int j=1;j<samples;j++)
-		{
-			Vector2 next = v.p + circularLerp(u0, u1, t, true) * strokeWidth * 0.5f;
-			next = affineTransform(pathToSurface, next);
-
-			rasterizer.addEdge(prev, next);	//throws bad_alloc
-			prev = next;
-			t += step;
-		}
-		rasterizer.addEdge(prev, cwt);	//throws bad_alloc
-		rasterizer.addEdge(cwt, p);     //throws bad_alloc
-		break;
-	}
-
-	default:
-	{
-		RI_ASSERT(capStyle == VG_CAP_SQUARE);
-		Vector2 t = v.t;
-		t.normalize();
-		Vector2 ccws = affineTransform(pathToSurface, v.ccw + t * strokeWidth * 0.5f);
-		Vector2 cws = affineTransform(pathToSurface, v.cw + t * strokeWidth * 0.5f);
-		rasterizer.addEdge(p, ccwt);	//throws bad_alloc
-		rasterizer.addEdge(ccwt, ccws);	//throws bad_alloc
-		rasterizer.addEdge(ccws, cws);	//throws bad_alloc
-		rasterizer.addEdge(cws, cwt);	//throws bad_alloc
-		rasterizer.addEdge(cwt, p);     //throws bad_alloc
-		break;
-	}
-	}
-    rasterizer.fill();
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Generate edges for stroke joins. Resulting polygons are closed.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Path::doJoin(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const StrokeVertex& v0, const StrokeVertex& v1, RIfloat strokeWidth, VGJoinStyle joinStyle, RIfloat miterLimit) const
-{
-	Vector2 ccw0t = affineTransform(pathToSurface, v0.ccw);
-	Vector2 cw0t = affineTransform(pathToSurface, v0.cw);
-	Vector2 m0t = affineTransform(pathToSurface, v0.p);
-	Vector2 ccw1t = affineTransform(pathToSurface, v1.ccw);
-	Vector2 cw1t = affineTransform(pathToSurface, v1.cw);
-	Vector2 m1t = affineTransform(pathToSurface, v1.p);
-
-	Vector2 tccw = v1.ccw - v0.ccw;
-	Vector2 s, e, m, st, et;
-	bool cw;
-
-    rasterizer.clear();
-
-	if( dot(tccw, v0.t) > 0.0f )
-	{	//draw ccw miter (draw from point 0 to 1)
-		s = ccw0t;
-		e = ccw1t;
-		st = v0.t;
-		et = v1.t;
-		m = v0.ccw;
-		cw = false;
-		rasterizer.addEdge(m0t, ccw0t);	//throws bad_alloc
-		rasterizer.addEdge(ccw1t, m1t);	//throws bad_alloc
-		rasterizer.addEdge(m1t, m0t);	//throws bad_alloc
-	}
-	else
-	{	//draw cw miter (draw from point 1 to 0)
-		s = cw1t;
-		e = cw0t;
-		st = v1.t;
-		et = v0.t;
-		m = v0.cw;
-		cw = true;
-		rasterizer.addEdge(cw0t, m0t);	//throws bad_alloc
-		rasterizer.addEdge(m1t, cw1t);	//throws bad_alloc
-		rasterizer.addEdge(m0t, m1t);	//throws bad_alloc
-	}
-
-	switch(joinStyle)
-	{
-	case VG_JOIN_MITER:
-	{
-		RIfloat theta = (RIfloat)acos(RI_CLAMP(dot(v0.t, -v1.t), -1.0f, 1.0f));
-		RIfloat miterLengthPerStrokeWidth = 1.0f / (RIfloat)sin(theta*0.5f);
-		if( miterLengthPerStrokeWidth < miterLimit )
-		{	//miter
-			RIfloat l = (RIfloat)cos(theta*0.5f) * miterLengthPerStrokeWidth * (strokeWidth * 0.5f);
-			l = RI_MIN(l, RI_FLOAT_MAX);	//force finite
-			Vector2 c = m + v0.t * l;
-			c = affineTransform(pathToSurface, c);
-			rasterizer.addEdge(s, c);	//throws bad_alloc
-			rasterizer.addEdge(c, e);	//throws bad_alloc
-		}
-		else
-		{	//bevel
-			rasterizer.addEdge(s, e);	//throws bad_alloc
-		}
-		break;
-	}
-
-	case VG_JOIN_ROUND:
-	{
-		const RIfloat tessellationAngle = 5.0f;
-
-		Vector2 prev = s;
-		RIfloat angle = RI_RAD_TO_DEG((RIfloat)acos(RI_CLAMP(dot(st, et), -1.0f, 1.0f))) / tessellationAngle;
-		int samples = (int)ceil(angle);
-		if( samples )
-		{
-			RIfloat step = 1.0f / samples;
-			RIfloat t = step;
-			for(int j=1;j<samples;j++)
-			{
-				Vector2 position = v0.p * (1.0f - t) + v1.p * t;
-				Vector2 tangent = circularLerp(st, et, t, true);
-
-				Vector2 next = position + normalize(perpendicular(tangent, cw)) * strokeWidth * 0.5f;
-				next = affineTransform(pathToSurface, next);
-
-				rasterizer.addEdge(prev, next);	//throws bad_alloc
-				prev = next;
-				t += step;
-			}
-		}
-		rasterizer.addEdge(prev, e);	//throws bad_alloc
-		break;
-	}
-
-	default:
-		RI_ASSERT(joinStyle == VG_JOIN_BEVEL);
-		if(!cw)
-			rasterizer.addEdge(ccw0t, ccw1t);	//throws bad_alloc
-		else
-			rasterizer.addEdge(cw1t, cw0t);		//throws bad_alloc
-		break;
-	}
-    rasterizer.fill();
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Tessellate a path, apply stroking, dashing, caps and joins, and
-*			append resulting edges to a rasterizer.
-* \param	
-* \return	
-* \note		if runs out of memory, throws bad_alloc and leaves the path as it was
-*//*-------------------------------------------------------------------*/
-
-void Path::stroke(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const Array<RIfloat>& dashPattern, RIfloat dashPhase, bool dashPhaseReset, RIfloat strokeWidth, VGCapStyle capStyle, VGJoinStyle joinStyle, RIfloat miterLimit)
-{
-	RI_ASSERT(pathToSurface.isAffine());
-	RI_ASSERT(m_referenceCount > 0);
-	RI_ASSERT(strokeWidth >= 0.0f);
-	RI_ASSERT(miterLimit >= 1.0f);
-
-	tessellate(pathToSurface, strokeWidth);	//throws bad_alloc
-
-	if(!m_vertices.size())
-		return;
-
-	bool dashing = true;
-	int dashPatternSize = dashPattern.size();
-	if( dashPattern.size() & 1 )
-		dashPatternSize--;	//odd number of dash pattern entries, discard the last one
-	RIfloat dashPatternLength = 0.0f;
-	for(int i=0;i<dashPatternSize;i++)
-		dashPatternLength += RI_MAX(dashPattern[i], 0.0f);
-	if(!dashPatternSize || dashPatternLength == 0.0f )
-		dashing = false;
-	dashPatternLength = RI_MIN(dashPatternLength, RI_FLOAT_MAX);
-
-	//walk along the path
-	//stop at the next event which is either:
-	//-path vertex
-	//-dash stop
-	//for robustness, decisions based on geometry are done only once.
-	//inDash keeps track whether the last point was in dash or not
-
-	//loop vertex events
-	try
-	{
-		RIfloat nextDash = 0.0f;
-		int d = 0;
-		bool inDash = true;
-		StrokeVertex v0, v1, vs;
-		for(int i=0;i<m_vertices.size();i++)
-		{
-			//read the next vertex
-			Vertex& v = m_vertices[i];
-			v1.p = v.userPosition;
-			v1.t = v.userTangent;
-			RI_ASSERT(!isZero(v1.t));	//don't allow zero tangents
-			v1.ccw = v1.p + normalize(perpendicularCCW(v1.t)) * strokeWidth * 0.5f;
-			v1.cw = v1.p + normalize(perpendicularCW(v1.t)) * strokeWidth * 0.5f;
-			v1.pathLength = v.pathLength;
-			v1.flags = v.flags;
-			v1.inDash = dashing ? inDash : true;	//NOTE: for other than START_SEGMENT vertices inDash will be updated after dashing
-
-			//process the vertex event
-			if(v.flags & START_SEGMENT)
-			{
-				if(v.flags & START_SUBPATH)
-				{
-					if( dashing )
-					{	//initialize dashing by finding which dash or gap the first point of the path lies in
-						if(dashPhaseReset || i == 0)
-						{
-							d = 0;
-							inDash = true;
-							nextDash = v1.pathLength - RI_MOD(dashPhase, dashPatternLength);
-							for(;;)
-							{
-								RIfloat prevDash = nextDash;
-								nextDash = prevDash + RI_MAX(dashPattern[d], 0.0f);
-								if(nextDash >= v1.pathLength)
-									break;
-
-								if( d & 1 )
-									inDash = true;
-								else
-									inDash = false;
-								d = (d+1) % dashPatternSize;
-							}
-							v1.inDash = inDash;
-							//the first point of the path lies between prevDash and nextDash
-							//d in the index of the next dash stop
-							//inDash is true if the first point is in a dash
-						}
-					}
-					vs = v1;	//save the subpath start point
-				}
-				else
-				{
-					if( v.flags & IMPLICIT_CLOSE_SUBPATH )
-					{	//do caps for the start and end of the current subpath
-						if( v0.inDash )
-							doCap(pathToSurface, rasterizer, v0, strokeWidth, capStyle);	//end cap	//throws bad_alloc
-						if( vs.inDash )
-						{
-							StrokeVertex vi = vs;
-							vi.t = -vi.t;
-							RI_SWAP(vi.ccw.x, vi.cw.x);
-							RI_SWAP(vi.ccw.y, vi.cw.y);
-							doCap(pathToSurface, rasterizer, vi, strokeWidth, capStyle);	//start cap	//throws bad_alloc
-						}
-					}
-					else
-					{	//join two segments
-						RI_ASSERT(v0.inDash == v1.inDash);
-						if( v0.inDash )
-							doJoin(pathToSurface, rasterizer, v0, v1, strokeWidth, joinStyle, miterLimit);	//throws bad_alloc
-					}
-				}
-			}
-			else
-			{	//in the middle of a segment
-				if( !(v.flags & IMPLICIT_CLOSE_SUBPATH) )
-				{	//normal segment, do stroking
-					if( dashing )
-					{
-						StrokeVertex prevDashVertex = v0;	//dashing of the segment starts from the previous vertex
-
-						if(nextDash + 10000.0f * dashPatternLength < v1.pathLength)
-							throw std::bad_alloc();		//too many dashes, throw bad_alloc
-
-						//loop dash events until the next vertex event
-						//zero length dashes are handled as a special case since if they hit the vertex,
-						//we want to include their starting point to this segment already in order to generate a join
-						int numDashStops = 0;
-						while(nextDash < v1.pathLength || (nextDash <= v1.pathLength && dashPattern[(d+1) % dashPatternSize] == 0.0f))
-						{
-							RIfloat edgeLength = v1.pathLength - v0.pathLength;
-							RIfloat ratio = 0.0f;
-							if(edgeLength > 0.0f)
-								ratio = (nextDash - v0.pathLength) / edgeLength;
-							StrokeVertex nextDashVertex;
-							nextDashVertex.p = v0.p * (1.0f - ratio) + v1.p * ratio;
-							nextDashVertex.t = circularLerp(v0.t, v1.t, ratio);
-							nextDashVertex.ccw = nextDashVertex.p + normalize(perpendicularCCW(nextDashVertex.t)) * strokeWidth * 0.5f;
-							nextDashVertex.cw = nextDashVertex.p + normalize(perpendicularCW(nextDashVertex.t)) * strokeWidth * 0.5f;
-
-							if( inDash )
-							{	//stroke from prevDashVertex -> nextDashVertex
-								if( numDashStops )
-								{	//prevDashVertex is not the start vertex of the segment, cap it (start vertex has already been joined or capped)
-									StrokeVertex vi = prevDashVertex;
-									vi.t = -vi.t;
-									RI_SWAP(vi.ccw.x, vi.cw.x);
-									RI_SWAP(vi.ccw.y, vi.cw.y);
-									doCap(pathToSurface, rasterizer, vi, strokeWidth, capStyle);	//throws bad_alloc
-								}
-								interpolateStroke(pathToSurface, rasterizer, prevDashVertex, nextDashVertex, strokeWidth);	//throws bad_alloc
-								doCap(pathToSurface, rasterizer, nextDashVertex, strokeWidth, capStyle);	//end cap	//throws bad_alloc
-							}
-							prevDashVertex = nextDashVertex;
-
-							if( d & 1 )
-							{	//dash starts
-								RI_ASSERT(!inDash);
-								inDash = true;
-							}
-							else
-							{	//dash ends
-								RI_ASSERT(inDash);
-								inDash = false;
-							}
-							d = (d+1) % dashPatternSize;
-							nextDash += RI_MAX(dashPattern[d], 0.0f);
-							numDashStops++;
-						}
-						
-						if( inDash )
-						{	//stroke prevDashVertex -> v1
-							if( numDashStops )
-							{	//prevDashVertex is not the start vertex of the segment, cap it (start vertex has already been joined or capped)
-								StrokeVertex vi = prevDashVertex;
-								vi.t = -vi.t;
-								RI_SWAP(vi.ccw.x, vi.cw.x);
-								RI_SWAP(vi.ccw.y, vi.cw.y);
-								doCap(pathToSurface, rasterizer, vi, strokeWidth, capStyle);	//throws bad_alloc
-							}
-							interpolateStroke(pathToSurface, rasterizer, prevDashVertex, v1, strokeWidth);	//throws bad_alloc
-							//no cap, leave path open
-						}
-
-						v1.inDash = inDash;	//update inDash status of the segment end point
-					}
-					else	//no dashing, just interpolate segment end points
-						interpolateStroke(pathToSurface, rasterizer, v0, v1, strokeWidth);	//throws bad_alloc
-				}
-			}
-
-			if((v.flags & END_SEGMENT) && (v.flags & CLOSE_SUBPATH))
-			{	//join start and end of the current subpath
-				if( v1.inDash && vs.inDash )
-					doJoin(pathToSurface, rasterizer, v1, vs, strokeWidth, joinStyle, miterLimit);	//throws bad_alloc
-				else
-				{	//both start and end are not in dash, cap them
-					if( v1.inDash )
-						doCap(pathToSurface, rasterizer, v1, strokeWidth, capStyle);	//end cap	//throws bad_alloc
-					if( vs.inDash )
-					{
-						StrokeVertex vi = vs;
-						vi.t = -vi.t;
-						RI_SWAP(vi.ccw.x, vi.cw.x);
-						RI_SWAP(vi.ccw.y, vi.cw.y);
-						doCap(pathToSurface, rasterizer, vi, strokeWidth, capStyle);	//start cap	//throws bad_alloc
-					}
-				}
-			}
-
-			v0 = v1;
-		}
-	}
-	catch(std::bad_alloc)
-	{
-		rasterizer.clear();	//remove the unfinished path
-		throw;
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Tessellates a path, and returns a position and a tangent on the path
-*			given a distance along the path.
-* \param	
-* \return	
-* \note		if runs out of memory, throws bad_alloc and leaves the path as it was
-*//*-------------------------------------------------------------------*/
-
-void Path::getPointAlong(int startIndex, int numSegments, RIfloat distance, Vector2& p, Vector2& t)
-{
-	RI_ASSERT(m_referenceCount > 0);
-	RI_ASSERT(startIndex >= 0 && startIndex + numSegments <= m_segments.size() && numSegments > 0);
-
-	Matrix3x3 identity;
-	identity.identity();
-	tessellate(identity, 0.0f);	//throws bad_alloc
-
-	RI_ASSERT(startIndex >= 0 && startIndex < m_segmentToVertex.size());
-	RI_ASSERT(startIndex + numSegments >= 0 && startIndex + numSegments <= m_segmentToVertex.size());
-
-    // ignore move segments at the start of the path
-    while (numSegments && (m_segments[startIndex] & ~VG_RELATIVE) == VG_MOVE_TO)
-    {
-        startIndex++;
-        numSegments--;
-    }
-
-    // ignore move segments at the end of the path
-    while (numSegments && (m_segments[startIndex + numSegments - 1] & ~VG_RELATIVE) == VG_MOVE_TO)
-        numSegments--;
-
-    // empty path?
-    if (!m_vertices.size() || !numSegments)
-    {
-		p.set(0,0);
-		t.set(1,0);
-		return;
-    }
-
-	int startVertex = m_segmentToVertex[startIndex].start;
-	int endVertex = m_segmentToVertex[startIndex + numSegments - 1].end;
-
-	if(startVertex == -1)
-		startVertex = 0;
-
-    // zero length?
-    if (startVertex >= endVertex)
-    {
-		p = m_vertices[startVertex].userPosition;
-		t.set(1,0);
-		return;
-    }
-
-	RI_ASSERT(startVertex >= 0 && startVertex < m_vertices.size());
-	RI_ASSERT(endVertex >= 0 && endVertex < m_vertices.size());
-
-	distance += m_vertices[startVertex].pathLength;	//map distance to the range of the whole path
-
-	if(distance <= m_vertices[startVertex].pathLength)
-	{	//return the first point of the path
-		p = m_vertices[startVertex].userPosition;
-		t = m_vertices[startVertex].userTangent;
-		return;
-	}
-
-	if(distance >= m_vertices[endVertex].pathLength)
-	{	//return the last point of the path
-		p = m_vertices[endVertex].userPosition;
-		t = m_vertices[endVertex].userTangent;
-		return;
-	}
-
-	//search for the segment containing the distance
-	for(int s=startIndex;s<startIndex+numSegments;s++)
-	{
-		int start = m_segmentToVertex[s].start;
-		int end = m_segmentToVertex[s].end;
-		if(start < 0)
-			start = 0;
-		if(end < 0)
-			end = 0;
-		RI_ASSERT(start >= 0 && start < m_vertices.size());
-		RI_ASSERT(end >= 0 && end < m_vertices.size());
-
-		if(distance >= m_vertices[start].pathLength && distance < m_vertices[end].pathLength)
-		{	//segment contains the queried distance
-			for(int i=start;i<end;i++)
-			{
-				const Vertex& v0 = m_vertices[i];
-				const Vertex& v1 = m_vertices[i+1];
-				if(distance >= v0.pathLength && distance < v1.pathLength)
-				{	//segment found, interpolate linearly between its end points
-					RIfloat edgeLength = v1.pathLength - v0.pathLength;
-					RI_ASSERT(edgeLength > 0.0f);
-					RIfloat r = (distance - v0.pathLength) / edgeLength;
-					p = (1.0f - r) * v0.userPosition + r * v1.userPosition;
-					t = (1.0f - r) * v0.userTangent + r * v1.userTangent;
-					return;
-				}
-			}
-		}
-	}
-
-	RI_ASSERT(0);	//point not found (should never get here)
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Tessellates a path, and computes its length.
-* \param	
-* \return	
-* \note		if runs out of memory, throws bad_alloc and leaves the path as it was
-*//*-------------------------------------------------------------------*/
-
-RIfloat Path::getPathLength(int startIndex, int numSegments)
-{
-	RI_ASSERT(m_referenceCount > 0);
-	RI_ASSERT(startIndex >= 0 && startIndex + numSegments <= m_segments.size() && numSegments > 0);
-
-	Matrix3x3 identity;
-	identity.identity();
-	tessellate(identity, 0.0f);	//throws bad_alloc
-
-	RI_ASSERT(startIndex >= 0 && startIndex < m_segmentToVertex.size());
-	RI_ASSERT(startIndex + numSegments >= 0 && startIndex + numSegments <= m_segmentToVertex.size());
-
-	int startVertex = m_segmentToVertex[startIndex].start;
-	int endVertex = m_segmentToVertex[startIndex + numSegments - 1].end;
-
-	if(!m_vertices.size())
-		return 0.0f;
-
-	RIfloat startPathLength = 0.0f;
-	if(startVertex >= 0)
-	{
-		RI_ASSERT(startVertex >= 0 && startVertex < m_vertices.size());
-		startPathLength = m_vertices[startVertex].pathLength;
-	}
-	RIfloat endPathLength = 0.0f;
-	if(endVertex >= 0)
-	{
-		RI_ASSERT(endVertex >= 0 && endVertex < m_vertices.size());
-		endPathLength = m_vertices[endVertex].pathLength;
-	}
-
-	return endPathLength - startPathLength;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Tessellates a path, and computes its bounding box in user space.
-* \param	
-* \return	
-* \note		if runs out of memory, throws bad_alloc and leaves the path as it was
-*//*-------------------------------------------------------------------*/
-
-void Path::getPathBounds(RIfloat& minx, RIfloat& miny, RIfloat& maxx, RIfloat& maxy)
-{
-	RI_ASSERT(m_referenceCount > 0);
-
-	Matrix3x3 identity;
-	identity.identity();
-	tessellate(identity, 0.0f);	//throws bad_alloc
-
-	if(m_vertices.size())
-	{
-		minx = m_userMinx;
-		miny = m_userMiny;
-		maxx = m_userMaxx;
-		maxy = m_userMaxy;
-	}
-	else
-	{
-		minx = miny = 0;
-		maxx = maxy = -1;
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Tessellates a path, and computes its bounding box in surface space.
-* \param	
-* \return	
-* \note		if runs out of memory, throws bad_alloc and leaves the path as it was
-*//*-------------------------------------------------------------------*/
-
-void Path::getPathTransformedBounds(const Matrix3x3& pathToSurface, RIfloat& minx, RIfloat& miny, RIfloat& maxx, RIfloat& maxy)
-{
-	RI_ASSERT(m_referenceCount > 0);
-	RI_ASSERT(pathToSurface.isAffine());
-
-	Matrix3x3 identity;
-	identity.identity();
-	tessellate(identity, 0.0f);	//throws bad_alloc
-
-	if(m_vertices.size())
-	{
-		Vector3 p0(m_userMinx, m_userMiny, 1.0f);
-		Vector3 p1(m_userMinx, m_userMaxy, 1.0f);
-		Vector3 p2(m_userMaxx, m_userMaxy, 1.0f);
-		Vector3 p3(m_userMaxx, m_userMiny, 1.0f);
-		p0 = pathToSurface * p0;
-		p1 = pathToSurface * p1;
-		p2 = pathToSurface * p2;
-		p3 = pathToSurface * p3;
-
-		minx = RI_MIN(RI_MIN(RI_MIN(p0.x, p1.x), p2.x), p3.x);
-		miny = RI_MIN(RI_MIN(RI_MIN(p0.y, p1.y), p2.y), p3.y);
-		maxx = RI_MAX(RI_MAX(RI_MAX(p0.x, p1.x), p2.x), p3.x);
-		maxy = RI_MAX(RI_MAX(RI_MAX(p0.y, p1.y), p2.y), p3.y);
-	}
-	else
-	{
-		minx = miny = 0;
-		maxx = maxy = -1;
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Adds a vertex to a tessellated path.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Path::addVertex(const Vector2& p, const Vector2& t, RIfloat pathLength, unsigned int flags)
-{
-	RI_ASSERT(!isZero(t));
-
-	Vertex v;
-	v.pathLength = pathLength;
-	v.userPosition = p;
-	v.userTangent = t;
-	v.flags = flags;
-	m_vertices.push_back(v);	//throws bad_alloc
-    m_numTessVertices++;
-
-	m_userMinx = RI_MIN(m_userMinx, v.userPosition.x);
-	m_userMiny = RI_MIN(m_userMiny, v.userPosition.y);
-	m_userMaxx = RI_MAX(m_userMaxx, v.userPosition.x);
-	m_userMaxy = RI_MAX(m_userMaxy, v.userPosition.y);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Adds an edge to a tessellated path.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Path::addEdge(const Vector2& p0, const Vector2& p1, const Vector2& t0, const Vector2& t1, unsigned int startFlags, unsigned int endFlags)
-{
-	Vertex v;
-	RIfloat pathLength = 0.0f;
-
-	RI_ASSERT(!isZero(t0) && !isZero(t1));
-
-	//segment midpoints are shared between edges
-	if(!m_numTessVertices)
-	{
-		if(m_vertices.size() > 0)
-			pathLength = m_vertices[m_vertices.size()-1].pathLength;
-
-		addVertex(p0, t0, pathLength, startFlags);	//throws bad_alloc
-	}
-
-	//other than implicit close paths (caused by a MOVE_TO) add to path length
-	if( !(endFlags & IMPLICIT_CLOSE_SUBPATH) )
-	{
-		//NOTE: with extremely large coordinates the floating point path length is infinite
-		RIfloat l = (p1 - p0).length();
-		pathLength = m_vertices[m_vertices.size()-1].pathLength + l;
-		pathLength = RI_MIN(pathLength, RI_FLOAT_MAX);
-	}
-
-	addVertex(p1, t1, pathLength, endFlags);	//throws bad_alloc
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Tessellates a close-path segment.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Path::addEndPath(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, bool subpathHasGeometry, unsigned int flags)
-{
-	RI_UNREF(pathToSurface);
-    m_numTessVertices = 0;
-	if(!subpathHasGeometry)
-	{	//single vertex
-		Vector2 t(1.0f,0.0f);
-		addEdge(p0, p1, t, t, START_SEGMENT | START_SUBPATH, END_SEGMENT | END_SUBPATH);	//throws bad_alloc
-        m_numTessVertices = 0;
-		addEdge(p0, p1, -t, -t, IMPLICIT_CLOSE_SUBPATH | START_SEGMENT, IMPLICIT_CLOSE_SUBPATH | END_SEGMENT);	//throws bad_alloc
-		return;
-	}
-	//the subpath contains segment commands that have generated geometry
-
-	//add a close path segment to the start point of the subpath
-	RI_ASSERT(m_vertices.size() > 0);
-	m_vertices[m_vertices.size()-1].flags |= END_SUBPATH;
-
-	Vector2 t = normalize(p1 - p0);
-	if(isZero(t))
-		t = m_vertices[m_vertices.size()-1].userTangent;	//if the segment is zero-length, use the tangent of the last segment end point so that proper join will be generated
-	RI_ASSERT(!isZero(t));
-
-	addEdge(p0, p1, t, t, flags | START_SEGMENT, flags | END_SEGMENT);	//throws bad_alloc
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Tessellates a line-to segment.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-bool Path::addLineTo(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, bool subpathHasGeometry)
-{
-	RI_UNREF(pathToSurface);
-	if(p0 == p1)
-		return false;	//discard zero-length segments
-
-	//compute end point tangents
-	Vector2 t = normalize(p1 - p0);
-	RI_ASSERT(!isZero(t));
-
-    m_numTessVertices = 0;
-	unsigned int startFlags = START_SEGMENT;
-	if(!subpathHasGeometry)
-		startFlags |= START_SUBPATH;
-	addEdge(p0, p1, t, t, startFlags, END_SEGMENT);	//throws bad_alloc
-	return true;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Tessellates a quad-to segment.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-bool Path::addQuadTo(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, const Vector2& p2, bool subpathHasGeometry, float strokeWidth)
-{
-	RI_UNREF(pathToSurface);
-	RI_UNREF(strokeWidth);
-	if(p0 == p1 && p0 == p2)
-	{
-		RI_ASSERT(p1 == p2);
-		return false;	//discard zero-length segments
-	}
-
-	//compute end point tangents
-
-	Vector2 incomingTangent = normalize(p1 - p0);
-	Vector2 outgoingTangent = normalize(p2 - p1);
-	if(p0 == p1)
-		incomingTangent = normalize(p2 - p0);
-	if(p1 == p2)
-		outgoingTangent = normalize(p2 - p0);
-	RI_ASSERT(!isZero(incomingTangent) && !isZero(outgoingTangent));
-
-    m_numTessVertices = 0;
-	unsigned int startFlags = START_SEGMENT;
-	if(!subpathHasGeometry)
-		startFlags |= START_SUBPATH;
-
-	const int segments = RI_NUM_TESSELLATED_SEGMENTS;
-	Vector2 pp = p0;
-	Vector2 tp = incomingTangent;
-	unsigned int prevFlags = startFlags;
-	for(int i=1;i<segments;i++)
-	{
-		RIfloat t = (RIfloat)i / (RIfloat)segments;
-		RIfloat u = 1.0f-t;
-		Vector2 pn = u*u * p0 + 2.0f*t*u * p1 + t*t * p2;
-		Vector2 tn = (-1.0f+t) * p0 + (1.0f-2.0f*t) * p1 + t * p2;
-		tn = normalize(tn);
-		if(isZero(tn))
-			tn = tp;
-
-		addEdge(pp, pn, tp, tn, prevFlags, 0);	//throws bad_alloc
-
-		pp = pn;
-		tp = tn;
-		prevFlags = 0;
-	}
-	addEdge(pp, p2, tp, outgoingTangent, prevFlags, END_SEGMENT);	//throws bad_alloc
-	return true;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Tessellates a cubic-to segment.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-bool Path::addCubicTo(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, const Vector2& p2, const Vector2& p3, bool subpathHasGeometry, float strokeWidth)
-{
-	RI_UNREF(pathToSurface);
-	RI_UNREF(strokeWidth);
-
-	if(p0 == p1 && p0 == p2 && p0 == p3)
-	{
-		RI_ASSERT(p1 == p2 && p1 == p3 && p2 == p3);
-		return false;	//discard zero-length segments
-	}
-
-	//compute end point tangents
-	Vector2 incomingTangent = normalize(p1 - p0);
-	Vector2 outgoingTangent = normalize(p3 - p2);
-	if(p0 == p1)
-	{
-		incomingTangent = normalize(p2 - p0);
-		if(p1 == p2)
-			incomingTangent = normalize(p3 - p0);
-	}
-	if(p2 == p3)
-	{
-		outgoingTangent = normalize(p3 - p1);
-		if(p1 == p2)
-			outgoingTangent = normalize(p3 - p0);
-	}
-	RI_ASSERT(!isZero(incomingTangent) && !isZero(outgoingTangent));
-
-    m_numTessVertices = 0;
-	unsigned int startFlags = START_SEGMENT;
-	if(!subpathHasGeometry)
-		startFlags |= START_SUBPATH;
-
-	const int segments = RI_NUM_TESSELLATED_SEGMENTS;
-	Vector2 pp = p0;
-	Vector2 tp = incomingTangent;
-	unsigned int prevFlags = startFlags;
-	for(int i=1;i<segments;i++)
-	{
-		RIfloat t = (RIfloat)i / (RIfloat)segments;
-		Vector2 pn = (1.0f - 3.0f*t + 3.0f*t*t - t*t*t) * p0 + (3.0f*t - 6.0f*t*t + 3.0f*t*t*t) * p1 + (3.0f*t*t - 3.0f*t*t*t) * p2 + t*t*t * p3;
-		Vector2 tn = (-3.0f + 6.0f*t - 3.0f*t*t) * p0 + (3.0f - 12.0f*t + 9.0f*t*t) * p1 + (6.0f*t - 9.0f*t*t) * p2 + 3.0f*t*t * p3;
-
-		tn = normalize(tn);
-		if(isZero(tn))
-			tn = tp;
-
-		addEdge(pp, pn, tp, tn, prevFlags, 0);	//throws bad_alloc
-
-		pp = pn;
-		tp = tn;
-		prevFlags = 0;
-	}
-	addEdge(pp, p3, tp, outgoingTangent, prevFlags, END_SEGMENT);	//throws bad_alloc
-	return true;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Finds an ellipse center and transformation from the unit circle to
-*			that ellipse.
-* \param	rh Length of the horizontal axis
-*			rv Length of the vertical axis
-*			rot Rotation angle
-*			p0,p1 User space end points of the arc
-*			c0,c1 (Return value) Unit circle space center points of the two ellipses
-*			u0,u1 (Return value) Unit circle space end points of the arc
-*			unitCircleToEllipse (Return value) A matrix mapping from unit circle space to user space
-* \return	true if ellipse exists, false if doesn't
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static bool findEllipses(RIfloat rh, RIfloat rv, RIfloat rot, const Vector2& p0, const Vector2& p1, VGPathSegment segment, Vector2& c0, Vector2& c1, Vector2& u0, Vector2& u1, Matrix3x3& unitCircleToEllipse, bool& cw)
-{
-	rh = RI_ABS(rh);
-	rv = RI_ABS(rv);
-	if(rh == 0.0f || rv == 0.0f || p0 == p1)
-		return false;	//degenerate ellipse
-
-	rot = RI_DEG_TO_RAD(rot);
-	unitCircleToEllipse.set((RIfloat)cos(rot)*rh, -(RIfloat)sin(rot)*rv,  0,
-							(RIfloat)sin(rot)*rh,  (RIfloat)cos(rot)*rv,  0,
-							0,                   0,                   1);
-	Matrix3x3 ellipseToUnitCircle = invert(unitCircleToEllipse);
-	//force affinity
-	ellipseToUnitCircle[2][0] = 0.0f;
-	ellipseToUnitCircle[2][1] = 0.0f;
-	ellipseToUnitCircle[2][2] = 1.0f;
-
-	// Transform p0 and p1 into unit space
-	u0 = affineTransform(ellipseToUnitCircle, p0);
-	u1 = affineTransform(ellipseToUnitCircle, p1);
-
-	Vector2 m = 0.5f * (u0 + u1);
-	Vector2 d = u0 - u1;
-
-	RIfloat lsq = (RIfloat)dot(d,d);
-	if(lsq <= 0.0f)
-		return false;	//the points are coincident
-
-	RIfloat disc = (1.0f / lsq) - 0.25f;
-	if(disc < 0.0f)
-	{	//the points are too far apart for a solution to exist, scale the axes so that there is a solution
-		RIfloat l = (RIfloat)sqrt(lsq);
-		rh *= 0.5f * l;
-		rv *= 0.5f * l;
-
-		//redo the computation with scaled axes
-		unitCircleToEllipse.set((RIfloat)cos(rot)*rh, -(RIfloat)sin(rot)*rv,  0,
-								(RIfloat)sin(rot)*rh,  (RIfloat)cos(rot)*rv,  0,
-								0,                   0,                   1);
-		ellipseToUnitCircle = invert(unitCircleToEllipse);
-		//force affinity
-		ellipseToUnitCircle[2][0] = 0.0f;
-		ellipseToUnitCircle[2][1] = 0.0f;
-		ellipseToUnitCircle[2][2] = 1.0f;
-
-		// Transform p0 and p1 into unit space
-		u0 = affineTransform(ellipseToUnitCircle, p0);
-		u1 = affineTransform(ellipseToUnitCircle, p1);
-
-		// Solve for intersecting unit circles
-		d = u0 - u1;
-		m = 0.5f * (u0 + u1);
-
-		lsq = dot(d,d);
-		if(lsq <= 0.0f)
-			return false;	//the points are coincident
-
-		disc = RI_MAX(0.0f, 1.0f / lsq - 0.25f);
-	}
-
-	if(u0 == u1)
-		return false;
-
-	Vector2 sd = d * (RIfloat)sqrt(disc);
-	Vector2 sp = perpendicularCW(sd);
-	c0 = m + sp;
-	c1 = m - sp;
-
-	//choose the center point and direction
-	Vector2 cp = c0;
-	if(segment == VG_SCWARC_TO || segment == VG_LCCWARC_TO)
-		cp = c1;
-	cw = false;
-	if(segment == VG_SCWARC_TO || segment == VG_LCWARC_TO)
-		cw = true;
-
-	//move the unit circle origin to the chosen center point
-	u0 -= cp;
-	u1 -= cp;
-
-	if(u0 == u1 || isZero(u0) || isZero(u1))
-		return false;
-
-	//transform back to the original coordinate space
-	cp = affineTransform(unitCircleToEllipse, cp);
-	unitCircleToEllipse[0][2] = cp.x;
-	unitCircleToEllipse[1][2] = cp.y;
-	return true;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Tessellates an arc-to segment.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-bool Path::addArcTo(const Matrix3x3& pathToSurface, const Vector2& p0, RIfloat rh, RIfloat rv, RIfloat rot, const Vector2& p1, const Vector2& p1r, VGPathSegment segment, bool subpathHasGeometry, float strokeWidth)
-{
-	RI_UNREF(pathToSurface);
-	RI_UNREF(strokeWidth);
-	if(p0 == p1)
-		return false;	//discard zero-length segments
-
-	Vector2 c0, c1, u0, u1;
-	Matrix3x3 unitCircleToEllipse;
-	bool cw;
-
-    m_numTessVertices = 0;
-	unsigned int startFlags = START_SEGMENT;
-	if(!subpathHasGeometry)
-		startFlags |= START_SUBPATH;
-
-	if(!findEllipses(rh, rv, rot, Vector2(), p1r, segment, c0, c1, u0, u1, unitCircleToEllipse, cw))
-	{	//ellipses don't exist, add line instead
-		Vector2 t = normalize(p1r);
-		RI_ASSERT(!isZero(t));
-		addEdge(p0, p1, t, t, startFlags, END_SEGMENT);	//throws bad_alloc
-		return true;
-	}
-
-	//compute end point tangents
-	Vector2 incomingTangent = perpendicular(u0, cw);
-	incomingTangent = affineTangentTransform(unitCircleToEllipse, incomingTangent);
-	incomingTangent = normalize(incomingTangent);
-	Vector2 outgoingTangent = perpendicular(u1, cw);
-	outgoingTangent = affineTangentTransform(unitCircleToEllipse, outgoingTangent);
-	outgoingTangent = normalize(outgoingTangent);
-	RI_ASSERT(!isZero(incomingTangent) && !isZero(outgoingTangent));
-
-	const int segments = RI_NUM_TESSELLATED_SEGMENTS;
-	Vector2 pp = p0;
-	Vector2 tp = incomingTangent;
-	unsigned int prevFlags = startFlags;
-	for(int i=1;i<segments;i++)
-	{
-		RIfloat t = (RIfloat)i / (RIfloat)segments;
-		Vector2 pn = circularLerp(u0, u1, t, cw);
-		Vector2 tn = perpendicular(pn, cw);
-		tn = affineTangentTransform(unitCircleToEllipse, tn);
-		pn = affineTransform(unitCircleToEllipse, pn) + p0;
-		tn = normalize(tn);
-		if(isZero(tn))
-			tn = tp;
-
-		addEdge(pp, pn, tp, tn, prevFlags, 0);	//throws bad_alloc
-
-		pp = pn;
-		tp = tn;
-		prevFlags = 0;
-	}
-	addEdge(pp, p1, tp, outgoingTangent, prevFlags, END_SEGMENT);	//throws bad_alloc
-	return true;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Tessellates a path.
-* \param	
-* \return	
-* \note		tessellation output format: A list of vertices describing the
-*			path tessellated into line segments and relevant aspects of the
-*			input data. Each path segment has a start vertex, a number of
-*			internal vertices (possibly zero), and an end vertex. The start
-*			and end of segments and subpaths have been flagged, as well as
-*			implicit and explicit close subpath segments.
-*//*-------------------------------------------------------------------*/
-
-void Path::tessellate(const Matrix3x3& pathToSurface, float strokeWidth)
-{
-	m_vertices.clear();
-
-	m_userMinx = RI_FLOAT_MAX;
-	m_userMiny = RI_FLOAT_MAX;
-	m_userMaxx = -RI_FLOAT_MAX;
-	m_userMaxy = -RI_FLOAT_MAX;
-
-	try
-	{
-		m_segmentToVertex.resize(m_segments.size());
-
-		int coordIndex = 0;
-		Vector2 s(0,0);		//the beginning of the current subpath
-		Vector2 o(0,0);		//the last point of the previous segment
-		Vector2 p(0,0);		//the last internal control point of the previous segment, if the segment was a (regular or smooth) quadratic or cubic Bezier, or else the last point of the previous segment
-
-		//tessellate the path segments
-		coordIndex = 0;
-		s.set(0,0);
-		o.set(0,0);
-		p.set(0,0);
-		bool subpathHasGeometry = false;
-		VGPathSegment prevSegment = VG_MOVE_TO;
-		for(int i=0;i<m_segments.size();i++)
-		{
-			VGPathSegment segment = getPathSegment(m_segments[i]);
-			VGPathAbsRel absRel = getPathAbsRel(m_segments[i]);
-			int coords = segmentToNumCoordinates(segment);
-			m_segmentToVertex[i].start = m_vertices.size();
-
-			switch(segment)
-			{
-			case VG_CLOSE_PATH:
-			{
-				RI_ASSERT(coords == 0);
-				addEndPath(pathToSurface, o, s, subpathHasGeometry, CLOSE_SUBPATH);
-				p = s;
-				o = s;
-				subpathHasGeometry = false;
-				break;
-			}
-
-			case VG_MOVE_TO:
-			{
-				RI_ASSERT(coords == 2);
-				Vector2 c(getCoordinate(coordIndex+0), getCoordinate(coordIndex+1));
-				if(absRel == VG_RELATIVE)
-					c += o;
-				if(prevSegment != VG_MOVE_TO && prevSegment != VG_CLOSE_PATH)
-					addEndPath(pathToSurface, o, s, subpathHasGeometry, IMPLICIT_CLOSE_SUBPATH);
-				s = c;
-				p = c;
-				o = c;
-				subpathHasGeometry = false;
-				break;
-			}
-
-			case VG_LINE_TO:
-			{
-				RI_ASSERT(coords == 2);
-				Vector2 c(getCoordinate(coordIndex+0), getCoordinate(coordIndex+1));
-				if(absRel == VG_RELATIVE)
-					c += o;
-				if(addLineTo(pathToSurface, o, c, subpathHasGeometry))
-					subpathHasGeometry = true;
-				p = c;
-				o = c;
-				break;
-			}
-
-			case VG_HLINE_TO:
-			{
-				RI_ASSERT(coords == 1);
-				Vector2 c(getCoordinate(coordIndex+0), o.y);
-				if(absRel == VG_RELATIVE)
-					c.x += o.x;
-				if(addLineTo(pathToSurface, o, c, subpathHasGeometry))
-					subpathHasGeometry = true;
-				p = c;
-				o = c;
-				break;
-			}
-
-			case VG_VLINE_TO:
-			{
-				RI_ASSERT(coords == 1);
-				Vector2 c(o.x, getCoordinate(coordIndex+0));
-				if(absRel == VG_RELATIVE)
-					c.y += o.y;
-				if(addLineTo(pathToSurface, o, c, subpathHasGeometry))
-					subpathHasGeometry = true;
-				p = c;
-				o = c;
-				break;
-			}
-
-			case VG_QUAD_TO:
-			{
-				RI_ASSERT(coords == 4);
-				Vector2 c0(getCoordinate(coordIndex+0), getCoordinate(coordIndex+1));
-				Vector2 c1(getCoordinate(coordIndex+2), getCoordinate(coordIndex+3));
-				if(absRel == VG_RELATIVE)
-				{
-					c0 += o;
-					c1 += o;
-				}
-				if(addQuadTo(pathToSurface, o, c0, c1, subpathHasGeometry, strokeWidth))
-					subpathHasGeometry = true;
-				p = c0;
-				o = c1;
-				break;
-			}
-
-			case VG_SQUAD_TO:
-			{
-				RI_ASSERT(coords == 2);
-				Vector2 c0 = 2.0f * o - p;
-				Vector2 c1(getCoordinate(coordIndex+0), getCoordinate(coordIndex+1));
-				if(absRel == VG_RELATIVE)
-					c1 += o;
-				if(addQuadTo(pathToSurface, o, c0, c1, subpathHasGeometry, strokeWidth))
-					subpathHasGeometry = true;
-				p = c0;
-				o = c1;
-				break;
-			}
-
-			case VG_CUBIC_TO:
-			{
-				RI_ASSERT(coords == 6);
-				Vector2 c0(getCoordinate(coordIndex+0), getCoordinate(coordIndex+1));
-				Vector2 c1(getCoordinate(coordIndex+2), getCoordinate(coordIndex+3));
-				Vector2 c2(getCoordinate(coordIndex+4), getCoordinate(coordIndex+5));
-				if(absRel == VG_RELATIVE)
-				{
-					c0 += o;
-					c1 += o;
-					c2 += o;
-				}
-				if(addCubicTo(pathToSurface, o, c0, c1, c2, subpathHasGeometry, strokeWidth))
-					subpathHasGeometry = true;
-				p = c1;
-				o = c2;
-				break;
-			}
-
-			case VG_SCUBIC_TO:
-			{
-				RI_ASSERT(coords == 4);
-				Vector2 c0 = 2.0f * o - p;
-				Vector2 c1(getCoordinate(coordIndex+0), getCoordinate(coordIndex+1));
-				Vector2 c2(getCoordinate(coordIndex+2), getCoordinate(coordIndex+3));
-				if(absRel == VG_RELATIVE)
-				{
-					c1 += o;
-					c2 += o;
-				}
-				if(addCubicTo(pathToSurface, o, c0, c1, c2, subpathHasGeometry, strokeWidth))
-					subpathHasGeometry = true;
-				p = c1;
-				o = c2;
-				break;
-			}
-
-			default:
-			{
-				RI_ASSERT(segment == VG_SCCWARC_TO || segment == VG_SCWARC_TO ||
-						  segment == VG_LCCWARC_TO || segment == VG_LCWARC_TO);
-				RI_ASSERT(coords == 5);
-				RIfloat rh = getCoordinate(coordIndex+0);
-				RIfloat rv = getCoordinate(coordIndex+1);
-				RIfloat rot = getCoordinate(coordIndex+2);
-				Vector2 c(getCoordinate(coordIndex+3), getCoordinate(coordIndex+4));
-
-                Vector2 cr = c;
-				if(absRel == VG_ABSOLUTE)
-                    cr -= o;
-                else
-					c += o;
-
-				if(addArcTo(pathToSurface, o, rh, rv, rot, c, cr, segment, subpathHasGeometry, strokeWidth))
-					subpathHasGeometry = true;
-				p = c;
-				o = c;
-				break;
-			}
-			}
-
-			if(m_vertices.size() > m_segmentToVertex[i].start)
-			{	//segment produced vertices
-				m_segmentToVertex[i].end = m_vertices.size() - 1;
-			}
-			else
-			{	//segment didn't produce vertices (zero-length segment). Ignore it.
-				m_segmentToVertex[i].start = m_segmentToVertex[i].end = m_vertices.size()-1;
-			}
-			prevSegment = segment;
-			coordIndex += coords;
-		}
-
-		//add an implicit MOVE_TO to the end to close the last subpath.
-		//if the subpath contained only zero-length segments, this produces the necessary geometry to get it stroked
-		// and included in path bounds. The geometry won't be included in the pointAlongPath query.
-		if(prevSegment != VG_MOVE_TO && prevSegment != VG_CLOSE_PATH)
-			addEndPath(pathToSurface, o, s, subpathHasGeometry, IMPLICIT_CLOSE_SUBPATH);
-
-		//check that the flags are correct
-#ifdef RI_DEBUG
-		int prev = -1;
-		bool subpathStarted = false;
-		bool segmentStarted = false;
-		for(int i=0;i<m_vertices.size();i++)
-		{
-			Vertex& v = m_vertices[i];
-
-			if(v.flags & START_SUBPATH)
-			{
-				RI_ASSERT(!subpathStarted);
-				RI_ASSERT(v.flags & START_SEGMENT);
-				RI_ASSERT(!(v.flags & END_SUBPATH));
-				RI_ASSERT(!(v.flags & END_SEGMENT));
-				RI_ASSERT(!(v.flags & CLOSE_SUBPATH));
-				RI_ASSERT(!(v.flags & IMPLICIT_CLOSE_SUBPATH));
-				subpathStarted = true;
-			}
-			
-			if(v.flags & START_SEGMENT)
-			{
-				RI_ASSERT(subpathStarted || (v.flags & CLOSE_SUBPATH) || (v.flags & IMPLICIT_CLOSE_SUBPATH));
-				RI_ASSERT(!segmentStarted);
-				RI_ASSERT(!(v.flags & END_SUBPATH));
-				RI_ASSERT(!(v.flags & END_SEGMENT));
-				segmentStarted = true;
-			}
-			
-			if( v.flags & CLOSE_SUBPATH )
-			{
-				RI_ASSERT(segmentStarted);
-				RI_ASSERT(!subpathStarted);
-				RI_ASSERT((v.flags & START_SEGMENT) || (v.flags & END_SEGMENT));
-				RI_ASSERT(!(v.flags & IMPLICIT_CLOSE_SUBPATH));
-				RI_ASSERT(!(v.flags & START_SUBPATH));
-				RI_ASSERT(!(v.flags & END_SUBPATH));
-			}
-			if( v.flags & IMPLICIT_CLOSE_SUBPATH )
-			{
-				RI_ASSERT(segmentStarted);
-				RI_ASSERT(!subpathStarted);
-				RI_ASSERT((v.flags & START_SEGMENT) || (v.flags & END_SEGMENT));
-				RI_ASSERT(!(v.flags & CLOSE_SUBPATH));
-				RI_ASSERT(!(v.flags & START_SUBPATH));
-				RI_ASSERT(!(v.flags & END_SUBPATH));
-			}
-			
-			if( prev >= 0 )
-			{
-				RI_ASSERT(segmentStarted);
-				RI_ASSERT(subpathStarted || ((m_vertices[prev].flags & CLOSE_SUBPATH) && (m_vertices[i].flags & CLOSE_SUBPATH)) ||
-						  ((m_vertices[prev].flags & IMPLICIT_CLOSE_SUBPATH) && (m_vertices[i].flags & IMPLICIT_CLOSE_SUBPATH)));
-			}
-
-			prev = i;
-			if(v.flags & END_SEGMENT)
-			{
-				RI_ASSERT(subpathStarted || (v.flags & CLOSE_SUBPATH) || (v.flags & IMPLICIT_CLOSE_SUBPATH));
-				RI_ASSERT(segmentStarted);
-				RI_ASSERT(!(v.flags & START_SUBPATH));
-				RI_ASSERT(!(v.flags & START_SEGMENT));
-				segmentStarted = false;
-				prev = -1;
-			}
-			
-			if(v.flags & END_SUBPATH)
-			{
-				RI_ASSERT(subpathStarted);
-				RI_ASSERT(v.flags & END_SEGMENT);
-				RI_ASSERT(!(v.flags & START_SUBPATH));
-				RI_ASSERT(!(v.flags & START_SEGMENT));
-				RI_ASSERT(!(v.flags & CLOSE_SUBPATH));
-				RI_ASSERT(!(v.flags & IMPLICIT_CLOSE_SUBPATH));
-				subpathStarted = false;
-			}
-		}
-#endif	//RI_DEBUG
-	}
-	catch(std::bad_alloc)
-	{
-		m_vertices.clear();
-		throw;
-	}
-}
-
-//==============================================================================================
-
-}		//namespace OpenVGRI
-
-//==============================================================================================
--- a/egl/sfopenvg/riPath.h	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,188 +0,0 @@
-#ifndef __RIPATH_H
-#define __RIPATH_H
-
-/*------------------------------------------------------------------------
- *
- * OpenVG 1.1 Reference Implementation
- * -----------------------------------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief	Path class.
- * \note	
- *//*-------------------------------------------------------------------*/
-
-#ifndef _OPENVG_H
-#include "openvg.h"
-#endif
-
-#ifndef __RIMATH_H
-#include "riMath.h"
-#endif
-
-#ifndef __RIARRAY_H
-#include "riArray.h"
-#endif
-
-#ifndef __RIRASTERIZER_H
-#include "riRasterizer.h"
-#endif
-
-//==============================================================================================
-
-namespace OpenVGRI
-{
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Storage and operations for VGPath.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-class Path
-{
-public:
-	Path(VGint format, VGPathDatatype datatype, RIfloat scale, RIfloat bias, int segmentCapacityHint, int coordCapacityHint, VGbitfield caps);	//throws bad_alloc
-	~Path();
-
-	VGint				getFormat() const						{ return m_format; }
-	VGPathDatatype		getDatatype() const						{ return m_datatype; }
-	RIfloat				getScale() const						{ return m_scale; }
-	RIfloat				getBias() const							{ return m_bias; }
-	VGbitfield			getCapabilities() const					{ return m_capabilities; }
-	void				setCapabilities(VGbitfield caps)		{ m_capabilities = caps; }
-	int					getNumSegments() const					{ return m_segments.size(); }
-	int					getNumCoordinates() const				{ return m_data.size() / getBytesPerCoordinate(m_datatype); }
-	void				addReference()							{ m_referenceCount++; }
-	int					removeReference()						{ m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
-
-	void				clear(VGbitfield capabilities);
-	void				appendData(const RIuint8* segments, int numSegments, const RIuint8* data);	//throws bad_alloc
-	void				append(const Path* srcPath);	//throws bad_alloc
-	void				modifyCoords(int startIndex, int numSegments, const RIuint8* data);
-	void				transform(const Path* srcPath, const Matrix3x3& matrix);	//throws bad_alloc
-	//returns true if interpolation succeeds, false if start and end paths are not compatible
-	bool				interpolate(const Path* startPath, const Path* endPath, RIfloat amount);	//throws bad_alloc
-	void				fill(const Matrix3x3& pathToSurface, Rasterizer& rasterizer);	//throws bad_alloc
-	void				stroke(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const Array<RIfloat>& dashPattern, RIfloat dashPhase, bool dashPhaseReset, RIfloat strokeWidth, VGCapStyle capStyle, VGJoinStyle joinStyle, RIfloat miterLimit);	//throws bad_alloc
-
-	void				getPointAlong(int startIndex, int numSegments, RIfloat distance, Vector2& p, Vector2& t);	//throws bad_alloc
-	RIfloat				getPathLength(int startIndex, int numSegments);	//throws bad_alloc
-	void				getPathBounds(RIfloat& minx, RIfloat& miny, RIfloat& maxx, RIfloat& maxy);	//throws bad_alloc
-	void				getPathTransformedBounds(const Matrix3x3& pathToSurface, RIfloat& minx, RIfloat& miny, RIfloat& maxx, RIfloat& maxy);	//throws bad_alloc
-
-private:
-	enum VertexFlags
-	{
-		START_SUBPATH			= (1<<0),
-		END_SUBPATH				= (1<<1),
-		START_SEGMENT			= (1<<2),
-		END_SEGMENT				= (1<<3),
-		CLOSE_SUBPATH			= (1<<4),
-		IMPLICIT_CLOSE_SUBPATH	= (1<<5)
-	};
-	struct Vertex
-	{
-		Vertex() : userPosition(), userTangent(), pathLength(0.0f), flags(0) {}
-		Vector2			userPosition;
-		Vector2			userTangent;
-		RIfloat			pathLength;
-		unsigned int	flags;
-	};
-	struct StrokeVertex
-	{
-		StrokeVertex() : p(), t(), ccw(), cw(), pathLength(0.0f), flags(0), inDash(false) {}
-		Vector2			p;
-		Vector2			t;
-		Vector2			ccw;
-		Vector2			cw;
-		RIfloat			pathLength;
-		unsigned int	flags;
-		bool			inDash;
-	};
-
-	Path(const Path&);						//!< Not allowed.
-	const Path& operator=(const Path&);		//!< Not allowed.
-
-	static VGPathSegment getPathSegment(RIuint8 data)				{ return (VGPathSegment)(data & 0x1e); }
-	static VGPathAbsRel	getPathAbsRel(RIuint8 data)					{ return (VGPathAbsRel)(data & 0x1); }
-	static int			segmentToNumCoordinates(VGPathSegment segment);
-	static int			countNumCoordinates(const RIuint8* segments, int numSegments);
-	static int			getBytesPerCoordinate(VGPathDatatype datatype);
-
-	static void			setCoordinate(Array<RIuint8>& data, VGPathDatatype datatype, RIfloat scale, RIfloat bias, int i, RIfloat c);
-
-	RIfloat				getCoordinate(int i) const;
-	void				setCoordinate(int i, RIfloat c)				{ setCoordinate(m_data, m_datatype, m_scale, m_bias, i, c); }
-
-	void				addVertex(const Vector2& p, const Vector2& t, RIfloat pathLength, unsigned int flags);	//throws bad_alloc
-	void				addEdge(const Vector2& p0, const Vector2& p1, const Vector2& t0, const Vector2& t1, unsigned int startFlags, unsigned int endFlags);	//throws bad_alloc
-
-	void				addEndPath(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, bool subpathHasGeometry, unsigned int flags);	//throws bad_alloc
-	bool				addLineTo(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, bool subpathHasGeometry);	//throws bad_alloc
-	bool				addQuadTo(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, const Vector2& p2, bool subpathHasGeometry, float strokeWidth);	//throws bad_alloc
-	bool				addCubicTo(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, const Vector2& p2, const Vector2& p3, bool subpathHasGeometry, float strokeWidth);	//throws bad_alloc
-	bool				addArcTo(const Matrix3x3& pathToSurface, const Vector2& p0, RIfloat rh, RIfloat rv, RIfloat rot, const Vector2& p1, const Vector2& p1r, VGPathSegment segment, bool subpathHasGeometry, float strokeWidth);	//throws bad_alloc
-
-	void				tessellate(const Matrix3x3& pathToSurface, float strokeWidth);	//throws bad_alloc
-
-	void				normalizeForInterpolation(const Path* srcPath);	//throws bad_alloc
-
-	void				interpolateStroke(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const StrokeVertex& v0, const StrokeVertex& v1, RIfloat strokeWidth) const;	//throws bad_alloc
-	void				doCap(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const StrokeVertex& v, RIfloat strokeWidth, VGCapStyle capStyle) const;	//throws bad_alloc
-	void				doJoin(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const StrokeVertex& v0, const StrokeVertex& v1, RIfloat strokeWidth, VGJoinStyle joinStyle, RIfloat miterLimit) const;	//throws bad_alloc
-
-	//input data
-	VGint				m_format;
-	VGPathDatatype		m_datatype;
-	RIfloat				m_scale;
-	RIfloat				m_bias;
-	VGbitfield			m_capabilities;
-	int					m_referenceCount;
-	Array<RIuint8>		m_segments;
-	Array<RIuint8>		m_data;
-
-	//data produced by tessellation
-	struct VertexIndex
-	{
-		int		start;
-		int		end;
-	};
-	Array<Vertex>		m_vertices;
-    int                 m_numTessVertices;
-	Array<VertexIndex>	m_segmentToVertex;
-	RIfloat				m_userMinx;
-	RIfloat				m_userMiny;
-	RIfloat				m_userMaxx;
-	RIfloat				m_userMaxy;
-};
-
-//==============================================================================================
-
-}	//namespace OpenVGRI
-
-//==============================================================================================
-
-#endif /* __RIPATH_H */
--- a/egl/sfopenvg/riPixelPipe.cpp	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,894 +0,0 @@
-/*------------------------------------------------------------------------
- *
- * OpenVG 1.1 Reference Implementation
- * -----------------------------------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief   Implementation of Paint and pixel pipe functionality.
- * \note    
- *//*-------------------------------------------------------------------*/
-
-#include "riPixelPipe.h"
-
-//==============================================================================================
-
-namespace OpenVGRI
-{
-
-/*-------------------------------------------------------------------*//*!
-* \brief    Paint constructor.
-* \param    
-* \return   
-* \note     
-*//*-------------------------------------------------------------------*/
-
-Paint::Paint() :
-    m_paintType(VG_PAINT_TYPE_COLOR),
-    m_paintColor(0,0,0,1,Color::sRGBA_PRE),
-    m_inputPaintColor(0,0,0,1,Color::sRGBA),
-    m_colorRampSpreadMode(VG_COLOR_RAMP_SPREAD_PAD),
-    m_colorRampStops(),
-    m_inputColorRampStops(),
-    m_colorRampPremultiplied(VG_TRUE),
-    m_inputLinearGradientPoint0(0,0),
-    m_inputLinearGradientPoint1(1,0),
-    m_inputRadialGradientCenter(0,0),
-    m_inputRadialGradientFocalPoint(0,0),
-    m_inputRadialGradientRadius(1.0f),
-    m_linearGradientPoint0(0,0),
-    m_linearGradientPoint1(1,0),
-    m_radialGradientCenter(0,0),
-    m_radialGradientFocalPoint(0,0),
-    m_radialGradientRadius(1.0f),
-    m_patternTilingMode(VG_TILE_FILL),
-    m_pattern(NULL),
-    m_referenceCount(0)
-{
-    Paint::GradientStop gs;
-    gs.offset = 0.0f;
-    gs.color.set(0,0,0,1,Color::sRGBA);
-    m_colorRampStops.push_back(gs); //throws bad_alloc
-    gs.offset = 1.0f;
-    gs.color.set(1,1,1,1,Color::sRGBA);
-    m_colorRampStops.push_back(gs); //throws bad_alloc
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief    Paint destructor.
-* \param    
-* \return   
-* \note     
-*//*-------------------------------------------------------------------*/
-
-Paint::~Paint()
-{
-    RI_ASSERT(m_referenceCount == 0);
-    if(m_pattern)
-    {
-        m_pattern->removeInUse();
-        if(!m_pattern->removeReference())
-            RI_DELETE(m_pattern);
-    }
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief    PixelPipe constructor.
-* \param    
-* \return   
-* \note     
-*//*-------------------------------------------------------------------*/
-
-PixelPipe::PixelPipe() :
-    m_drawable(NULL),
-    m_image(NULL),
-    m_paint(NULL),
-    m_defaultPaint(),
-    m_blendMode(VG_BLEND_SRC_OVER),
-    m_imageMode(VG_DRAW_IMAGE_NORMAL),
-    m_imageQuality(VG_IMAGE_QUALITY_FASTER),
-    m_tileFillColor(0,0,0,0,Color::sRGBA),
-    m_colorTransform(false),
-    m_colorTransformValues(),
-    m_surfaceToPaintMatrix(),
-    m_surfaceToImageMatrix()
-{
-    for(int i=0;i<8;i++)
-        m_colorTransformValues[i] = (i < 4) ? 1.0f : 0.0f;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief    PixelPipe destructor.
-* \param    
-* \return   
-* \note     
-*//*-------------------------------------------------------------------*/
-
-PixelPipe::~PixelPipe()
-{
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief    Sets the rendering surface.
-* \param    
-* \return   
-* \note     
-*//*-------------------------------------------------------------------*/
-
-void PixelPipe::setDrawable(Drawable* drawable)
-{
-    RI_ASSERT(drawable);
-    m_drawable = drawable;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief    Sets the blend mode.
-* \param    
-* \return   
-* \note     
-*//*-------------------------------------------------------------------*/
-
-void PixelPipe::setBlendMode(VGBlendMode blendMode)
-{
-    RI_ASSERT(blendMode >= VG_BLEND_SRC && blendMode <= VG_BLEND_ADDITIVE);
-    m_blendMode = blendMode;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief    Sets the mask image. NULL disables masking.
-* \param    
-* \return   
-* \note     
-*//*-------------------------------------------------------------------*/
-
-void PixelPipe::setMask(bool masking)
-{
-    m_masking = masking;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief    Sets the image to be drawn. NULL disables image drawing.
-* \param    
-* \return   
-* \note     
-*//*-------------------------------------------------------------------*/
-
-void PixelPipe::setImage(Image* image, VGImageMode imageMode)
-{
-    RI_ASSERT(imageMode == VG_DRAW_IMAGE_NORMAL || imageMode == VG_DRAW_IMAGE_MULTIPLY || imageMode == VG_DRAW_IMAGE_STENCIL);
-    m_image = image;
-    m_imageMode = imageMode;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief    Sets the surface-to-paint matrix.
-* \param    
-* \return   
-* \note     
-*//*-------------------------------------------------------------------*/
-
-void PixelPipe::setSurfaceToPaintMatrix(const Matrix3x3& surfaceToPaintMatrix)
-{
-    m_surfaceToPaintMatrix = surfaceToPaintMatrix;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief    Sets the surface-to-image matrix.
-* \param    
-* \return   
-* \note     
-*//*-------------------------------------------------------------------*/
-
-void PixelPipe::setSurfaceToImageMatrix(const Matrix3x3& surfaceToImageMatrix)
-{
-    m_surfaceToImageMatrix = surfaceToImageMatrix;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief    Sets image quality.
-* \param    
-* \return   
-* \note     
-*//*-------------------------------------------------------------------*/
-
-void PixelPipe::setImageQuality(VGImageQuality imageQuality)
-{
-    RI_ASSERT(imageQuality == VG_IMAGE_QUALITY_NONANTIALIASED || imageQuality == VG_IMAGE_QUALITY_FASTER || imageQuality == VG_IMAGE_QUALITY_BETTER);
-    m_imageQuality = imageQuality;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief    Sets fill color for VG_TILE_FILL tiling mode (pattern only).
-* \param    
-* \return   
-* \note     
-*//*-------------------------------------------------------------------*/
-
-void PixelPipe::setTileFillColor(const Color& c)
-{
-    m_tileFillColor = c;
-    m_tileFillColor.clamp();
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief    Sets paint.
-* \param    
-* \return   
-* \note     
-*//*-------------------------------------------------------------------*/
-
-void PixelPipe::setPaint(const Paint* paint)
-{
-    m_paint = paint;
-    if(!m_paint)
-        m_paint = &m_defaultPaint;
-    if(m_paint->m_pattern)
-        m_tileFillColor.convert(m_paint->m_pattern->getDescriptor().internalFormat);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief    Color transform.
-* \param    
-* \return   
-* \note     
-*//*-------------------------------------------------------------------*/
-
-void PixelPipe::setColorTransform(bool enable, RIfloat values[8])
-{
-    m_colorTransform = enable;
-    for(int i=0;i<4;i++)
-    {
-        m_colorTransformValues[i] = RI_CLAMP(values[i], -127.0f, 127.0f);
-        m_colorTransformValues[i+4] = RI_CLAMP(values[i+4], -1.0f, 1.0f);
-    }
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief    Computes the linear gradient function at (x,y).
-* \param    
-* \return   
-* \note     
-*//*-------------------------------------------------------------------*/
-
-void PixelPipe::linearGradient(RIfloat& g, RIfloat& rho, RIfloat x, RIfloat y) const
-{
-    RI_ASSERT(m_paint);
-    Vector2 u = m_paint->m_linearGradientPoint1 - m_paint->m_linearGradientPoint0;
-    RIfloat usq = dot(u,u);
-    if( usq <= 0.0f )
-    {   //points are equal, gradient is always 1.0f
-        g = 1.0f;
-        rho = 0.0f;
-        return;
-    }
-    RIfloat oou = 1.0f / usq;
-
-    Vector2 p(x, y);
-    p = affineTransform(m_surfaceToPaintMatrix, p);
-    p -= m_paint->m_linearGradientPoint0;
-    RI_ASSERT(usq >= 0.0f);
-    g = dot(p, u) * oou;
-    RIfloat dgdx = oou * u.x * m_surfaceToPaintMatrix[0][0] + oou * u.y * m_surfaceToPaintMatrix[1][0];
-    RIfloat dgdy = oou * u.x * m_surfaceToPaintMatrix[0][1] + oou * u.y * m_surfaceToPaintMatrix[1][1];
-    rho = (RIfloat)sqrt(dgdx*dgdx + dgdy*dgdy);
-    RI_ASSERT(rho >= 0.0f);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief    Computes the radial gradient function at (x,y).
-* \param    
-* \return   
-* \note     
-*//*-------------------------------------------------------------------*/
-
-void PixelPipe::radialGradient(RIfloat &g, RIfloat &rho, RIfloat x, RIfloat y) const
-{
-    RI_ASSERT(m_paint);
-    if( m_paint->m_radialGradientRadius <= 0.0f )
-    {
-        g = 1.0f;
-        rho = 0.0f;
-        return;
-    }
-
-    RIfloat r = m_paint->m_radialGradientRadius;
-    Vector2 c = m_paint->m_radialGradientCenter;
-    Vector2 f = m_paint->m_radialGradientFocalPoint;
-    Vector2 gx(m_surfaceToPaintMatrix[0][0], m_surfaceToPaintMatrix[1][0]);
-    Vector2 gy(m_surfaceToPaintMatrix[0][1], m_surfaceToPaintMatrix[1][1]);
-
-    Vector2 fp = f - c;
-
-    //clamp the focal point inside the gradient circle
-    RIfloat fpLen = fp.length();
-    if( fpLen > 0.999f * r )
-        fp *= 0.999f * r / fpLen;
-
-    RIfloat D = -1.0f / (dot(fp,fp) - r*r);
-    Vector2 p(x, y);
-    p = affineTransform(m_surfaceToPaintMatrix, p) - c;
-    Vector2 d = p - fp;
-    RIfloat s = (RIfloat)sqrt(r*r*dot(d,d) - RI_SQR(p.x*fp.y - p.y*fp.x));
-    g = (dot(fp,d) + s) * D;
-    if(RI_ISNAN(g))
-        g = 0.0f;
-    RIfloat dgdx = D*dot(fp,gx) + (r*r*dot(d,gx) - (gx.x*fp.y - gx.y*fp.x)*(p.x*fp.y - p.y*fp.x)) * (D / s);
-    RIfloat dgdy = D*dot(fp,gy) + (r*r*dot(d,gy) - (gy.x*fp.y - gy.y*fp.x)*(p.x*fp.y - p.y*fp.x)) * (D / s);
-    rho = (RIfloat)sqrt(dgdx*dgdx + dgdy*dgdy);
-    if(RI_ISNAN(rho))
-        rho = 0.0f;
-    RI_ASSERT(rho >= 0.0f);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief    Returns the average color within an offset range in the color ramp.
-* \param    
-* \return   
-* \note     
-*//*-------------------------------------------------------------------*/
-
-static Color readStopColor(const Array<Paint::GradientStop>& colorRampStops, int i, VGboolean colorRampPremultiplied)
-{
-    RI_ASSERT(i >= 0 && i < colorRampStops.size());
-    Color c = colorRampStops[i].color;
-    RI_ASSERT(c.getInternalFormat() == Color::sRGBA);
-    if(colorRampPremultiplied)
-        c.premultiply();
-    return c;
-}
-
-Color PixelPipe::integrateColorRamp(RIfloat gmin, RIfloat gmax) const
-{
-    RI_ASSERT(gmin <= gmax);
-    RI_ASSERT(gmin >= 0.0f && gmin <= 1.0f);
-    RI_ASSERT(gmax >= 0.0f && gmax <= 1.0f);
-    RI_ASSERT(m_paint->m_colorRampStops.size() >= 2);   //there are at least two stops
-
-    Color c(0,0,0,0,m_paint->m_colorRampPremultiplied ? Color::sRGBA_PRE : Color::sRGBA);
-    if(gmin == 1.0f || gmax == 0.0f)
-        return c;
-
-    int i=0;
-    for(;i<m_paint->m_colorRampStops.size()-1;i++)
-    {
-        if(gmin >= m_paint->m_colorRampStops[i].offset && gmin < m_paint->m_colorRampStops[i+1].offset)
-        {
-            RIfloat s = m_paint->m_colorRampStops[i].offset;
-            RIfloat e = m_paint->m_colorRampStops[i+1].offset;
-            RI_ASSERT(s < e);
-            RIfloat g = (gmin - s) / (e - s);
-
-            Color sc = readStopColor(m_paint->m_colorRampStops, i, m_paint->m_colorRampPremultiplied);
-            Color ec = readStopColor(m_paint->m_colorRampStops, i+1, m_paint->m_colorRampPremultiplied);
-            Color rc = (1.0f-g) * sc + g * ec;
-
-            //subtract the average color from the start of the stop to gmin
-            c -= 0.5f*(gmin - s)*(sc + rc);
-            break;
-        }
-    }
-
-    for(;i<m_paint->m_colorRampStops.size()-1;i++)
-    {
-        RIfloat s = m_paint->m_colorRampStops[i].offset;
-        RIfloat e = m_paint->m_colorRampStops[i+1].offset;
-        RI_ASSERT(s <= e);
-
-        Color sc = readStopColor(m_paint->m_colorRampStops, i, m_paint->m_colorRampPremultiplied);
-        Color ec = readStopColor(m_paint->m_colorRampStops, i+1, m_paint->m_colorRampPremultiplied);
-
-        //average of the stop
-        c += 0.5f*(e-s)*(sc + ec);
-
-        if(gmax >= m_paint->m_colorRampStops[i].offset && gmax < m_paint->m_colorRampStops[i+1].offset)
-        {
-            RIfloat g = (gmax - s) / (e - s);
-            Color rc = (1.0f-g) * sc + g * ec;
-
-            //subtract the average color from gmax to the end of the stop
-            c -= 0.5f*(e - gmax)*(rc + ec);
-            break;
-        }
-    }
-    return c;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief    Maps a gradient function value to a color.
-* \param    
-* \return   
-* \note     
-*//*-------------------------------------------------------------------*/
-
-Color PixelPipe::colorRamp(RIfloat gradient, RIfloat rho) const
-{
-    RI_ASSERT(m_paint);
-    RI_ASSERT(rho >= 0.0f);
-
-    Color c(0,0,0,0,m_paint->m_colorRampPremultiplied ? Color::sRGBA_PRE : Color::sRGBA);
-    Color avg;
-
-    if(rho == 0.0f)
-    {   //filter size is zero or gradient is degenerate
-        switch(m_paint->m_colorRampSpreadMode)
-        {
-        case VG_COLOR_RAMP_SPREAD_PAD:
-            gradient = RI_CLAMP(gradient, 0.0f, 1.0f);
-            break;
-        case VG_COLOR_RAMP_SPREAD_REFLECT:
-        {
-            RIfloat g = RI_MOD(gradient, 2.0f);
-            gradient = (g < 1.0f) ? g : 2.0f - g;
-            break;
-        }
-        default:
-            RI_ASSERT(m_paint->m_colorRampSpreadMode == VG_COLOR_RAMP_SPREAD_REPEAT);
-            gradient = gradient - (RIfloat)floor(gradient);
-            break;
-        }
-        RI_ASSERT(gradient >= 0.0f && gradient <= 1.0f);
-
-        for(int i=0;i<m_paint->m_colorRampStops.size()-1;i++)
-        {
-            if(gradient >= m_paint->m_colorRampStops[i].offset && gradient < m_paint->m_colorRampStops[i+1].offset)
-            {
-                RIfloat s = m_paint->m_colorRampStops[i].offset;
-                RIfloat e = m_paint->m_colorRampStops[i+1].offset;
-                RI_ASSERT(s < e);
-                RIfloat g = RI_CLAMP((gradient - s) / (e - s), 0.0f, 1.0f); //clamp needed due to numerical inaccuracies
-
-                Color sc = readStopColor(m_paint->m_colorRampStops, i, m_paint->m_colorRampPremultiplied);
-                Color ec = readStopColor(m_paint->m_colorRampStops, i+1, m_paint->m_colorRampPremultiplied);
-                return (1.0f-g) * sc + g * ec;  //return interpolated value
-            }
-        }
-        return readStopColor(m_paint->m_colorRampStops, m_paint->m_colorRampStops.size()-1, m_paint->m_colorRampPremultiplied);
-    }
-
-    RIfloat gmin = gradient - rho*0.5f;         //filter starting from the gradient point (if starts earlier, radial gradient center will be an average of the first and the last stop, which doesn't look good)
-    RIfloat gmax = gradient + rho*0.5f;
-
-    switch(m_paint->m_colorRampSpreadMode)
-    {
-    case VG_COLOR_RAMP_SPREAD_PAD:
-    {
-        if(gmin < 0.0f)
-            c += (RI_MIN(gmax, 0.0f) - gmin) * readStopColor(m_paint->m_colorRampStops, 0, m_paint->m_colorRampPremultiplied);
-        if(gmax > 1.0f)
-            c += (gmax - RI_MAX(gmin, 1.0f)) * readStopColor(m_paint->m_colorRampStops, m_paint->m_colorRampStops.size()-1, m_paint->m_colorRampPremultiplied);
-        gmin = RI_CLAMP(gmin, 0.0f, 1.0f);
-        gmax = RI_CLAMP(gmax, 0.0f, 1.0f);
-        c += integrateColorRamp(gmin, gmax);
-        c *= 1.0f/rho;
-        c.clamp();  //clamp needed due to numerical inaccuracies
-        return c;
-    }
-
-    case VG_COLOR_RAMP_SPREAD_REFLECT:
-    {
-        avg = integrateColorRamp(0.0f, 1.0f);
-        RIfloat gmini = (RIfloat)floor(gmin);
-        RIfloat gmaxi = (RIfloat)floor(gmax);
-        c = (gmaxi + 1.0f - gmini) * avg;       //full ramps
-
-        //subtract beginning
-        if(((int)gmini) & 1)
-            c -= integrateColorRamp(RI_CLAMP(1.0f - (gmin - gmini), 0.0f, 1.0f), 1.0f);
-        else
-            c -= integrateColorRamp(0.0f, RI_CLAMP(gmin - gmini, 0.0f, 1.0f));
-
-        //subtract end
-        if(((int)gmaxi) & 1)
-            c -= integrateColorRamp(0.0f, RI_CLAMP(1.0f - (gmax - gmaxi), 0.0f, 1.0f));
-        else
-            c -= integrateColorRamp(RI_CLAMP(gmax - gmaxi, 0.0f, 1.0f), 1.0f);
-        break;
-    }
-
-    default:
-    {
-        RI_ASSERT(m_paint->m_colorRampSpreadMode == VG_COLOR_RAMP_SPREAD_REPEAT);
-        avg = integrateColorRamp(0.0f, 1.0f);
-        RIfloat gmini = (RIfloat)floor(gmin);
-        RIfloat gmaxi = (RIfloat)floor(gmax);
-        c = (gmaxi + 1.0f - gmini) * avg;       //full ramps
-        c -= integrateColorRamp(0.0f, RI_CLAMP(gmin - gmini, 0.0f, 1.0f));  //subtract beginning
-        c -= integrateColorRamp(RI_CLAMP(gmax - gmaxi, 0.0f, 1.0f), 1.0f);  //subtract end
-        break;
-    }
-    }
-
-    //divide color by the length of the range
-    c *= 1.0f / rho;
-    c.clamp();  //clamp needed due to numerical inaccuracies
-
-    //hide aliasing by fading to the average color
-    const RIfloat fadeStart = 0.5f;
-    const RIfloat fadeMultiplier = 2.0f;    //the larger, the earlier fade to average is done
-
-    if(rho < fadeStart)
-        return c;
-
-    RIfloat ratio = RI_MIN((rho - fadeStart) * fadeMultiplier, 1.0f);
-    return ratio * avg + (1.0f - ratio) * c;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief    Computes blend.
-* \param    
-* \return   
-* \note     premultiplied blending formulas
-            //src
-            a = asrc
-            r = rsrc
-            //src over
-            a = asrc + adst * (1-asrc)
-            r = rsrc + rdst * (1-asrc)
-            //dst over
-            a = asrc * (1-adst) + adst
-            r = rsrc * (1-adst) + adst
-            //src in
-            a = asrc * adst
-            r = rsrc * adst
-            //dst in
-            a = adst * asrc
-            r = rdst * asrc
-            //multiply
-            a = asrc + adst * (1-asrc)
-            r = rsrc * (1-adst) + rdst * (1-asrc) + rsrc * rdst
-            //screen
-            a = asrc + adst * (1-asrc)
-            r = rsrc + rdst - rsrc * rdst
-            //darken
-            a = asrc + adst * (1-asrc)
-            r = MIN(rsrc + rdst * (1-asrc), rdst + rsrc * (1-adst))
-            //lighten
-            a = asrc + adst * (1-asrc)
-            r = MAX(rsrc + rdst * (1-asrc), rdst + rsrc * (1-adst))
-            //additive
-            a = MIN(asrc+adst,1)
-            r = rsrc + rdst
-*//*-------------------------------------------------------------------*/
-
-Color PixelPipe::blend(const Color& s, RIfloat ar, RIfloat ag, RIfloat ab, const Color& d, VGBlendMode blendMode) const
-{
-    //apply blending in the premultiplied format
-    Color r(0,0,0,0,d.getInternalFormat());
-    RI_ASSERT(s.a >= 0.0f && s.a <= 1.0f);
-    RI_ASSERT(s.r >= 0.0f && s.r <= s.a && s.r <= ar);
-    RI_ASSERT(s.g >= 0.0f && s.g <= s.a && s.g <= ag);
-    RI_ASSERT(s.b >= 0.0f && s.b <= s.a && s.b <= ab);
-    RI_ASSERT(d.a >= 0.0f && d.a <= 1.0f);
-    RI_ASSERT(d.r >= 0.0f && d.r <= d.a);
-    RI_ASSERT(d.g >= 0.0f && d.g <= d.a);
-    RI_ASSERT(d.b >= 0.0f && d.b <= d.a);
-    switch(blendMode)
-    {
-    case VG_BLEND_SRC:
-        r = s;
-        break;
-
-    case VG_BLEND_SRC_OVER:
-        r.r = s.r + d.r * (1.0f - ar);
-        r.g = s.g + d.g * (1.0f - ag);
-        r.b = s.b + d.b * (1.0f - ab);
-        r.a = s.a + d.a * (1.0f - s.a);
-        break;
-
-    case VG_BLEND_DST_OVER:
-        r.r = s.r * (1.0f - d.a) + d.r;
-        r.g = s.g * (1.0f - d.a) + d.g;
-        r.b = s.b * (1.0f - d.a) + d.b;
-        r.a = s.a * (1.0f - d.a) + d.a;
-        break;
-
-    case VG_BLEND_SRC_IN:
-        r.r = s.r * d.a;
-        r.g = s.g * d.a;
-        r.b = s.b * d.a;
-        r.a = s.a * d.a;
-        break;
-
-    case VG_BLEND_DST_IN:
-        r.r = d.r * ar;
-        r.g = d.g * ag;
-        r.b = d.b * ab;
-        r.a = d.a * s.a;
-        break;
-
-    case VG_BLEND_MULTIPLY:
-        r.r = s.r * (1.0f - d.a + d.r) + d.r * (1.0f - ar);
-        r.g = s.g * (1.0f - d.a + d.g) + d.g * (1.0f - ag);
-        r.b = s.b * (1.0f - d.a + d.b) + d.b * (1.0f - ab);
-        r.a = s.a + d.a * (1.0f - s.a);
-        break;
-
-    case VG_BLEND_SCREEN:
-        r.r = s.r + d.r * (1.0f - s.r);
-        r.g = s.g + d.g * (1.0f - s.g);
-        r.b = s.b + d.b * (1.0f - s.b);
-        r.a = s.a + d.a * (1.0f - s.a);
-        break;
-
-    case VG_BLEND_DARKEN:
-        r.r = RI_MIN(s.r + d.r * (1.0f - ar), d.r + s.r * (1.0f - d.a));
-        r.g = RI_MIN(s.g + d.g * (1.0f - ag), d.g + s.g * (1.0f - d.a));
-        r.b = RI_MIN(s.b + d.b * (1.0f - ab), d.b + s.b * (1.0f - d.a));
-        r.a = s.a + d.a * (1.0f - s.a);
-        break;
-
-    case VG_BLEND_LIGHTEN:
-        r.r = RI_MAX(s.r + d.r * (1.0f - ar), d.r + s.r * (1.0f - d.a));
-        r.g = RI_MAX(s.g + d.g * (1.0f - ag), d.g + s.g * (1.0f - d.a));
-        r.b = RI_MAX(s.b + d.b * (1.0f - ab), d.b + s.b * (1.0f - d.a));
-        //although the statement below is equivalent to r.a = s.a + d.a * (1.0f - s.a)
-        //in practice there can be a very slight difference because
-        //of the max operation in the blending formula that may cause color to exceed alpha.
-        //Because of this, we compute the result both ways and return the maximum.
-        r.a = RI_MAX(s.a + d.a * (1.0f - s.a), d.a + s.a * (1.0f - d.a));
-        break;
-
-    default:
-        RI_ASSERT(blendMode == VG_BLEND_ADDITIVE);
-        r.r = RI_MIN(s.r + d.r, 1.0f);
-        r.g = RI_MIN(s.g + d.g, 1.0f);
-        r.b = RI_MIN(s.b + d.b, 1.0f);
-        r.a = RI_MIN(s.a + d.a, 1.0f);
-        break;
-    }
-    return r;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief    Applies color transform.
-* \param    
-* \return   
-* \note
-*//*-------------------------------------------------------------------*/
-
-void PixelPipe::colorTransform(Color& c) const
-{
-    if(m_colorTransform)
-    {
-        c.unpremultiply();
-        c.luminanceToRGB();
-        c.r = c.r * m_colorTransformValues[0] + m_colorTransformValues[4];
-        c.g = c.g * m_colorTransformValues[1] + m_colorTransformValues[5];
-        c.b = c.b * m_colorTransformValues[2] + m_colorTransformValues[6];
-        c.a = c.a * m_colorTransformValues[3] + m_colorTransformValues[7];
-        c.clamp();
-        c.premultiply();
-    }
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief    Applies paint, image drawing, masking and blending at pixel (x,y).
-* \param    
-* \return   
-* \note
-*//*-------------------------------------------------------------------*/
-
-void PixelPipe::pixelPipe(int x, int y, RIfloat coverage, unsigned int sampleMask) const
-{
-    RI_ASSERT(m_drawable);
-    RI_ASSERT(sampleMask);
-    RI_ASSERT(coverage > 0.0f);
-    Color::InternalFormat dstFormat = (Color::InternalFormat)(m_drawable->getDescriptor().internalFormat | Color::PREMULTIPLIED);
-
-    //evaluate paint
-    RI_ASSERT(m_paint);
-    Color s;
-    switch(m_paint->m_paintType)
-    {
-    case VG_PAINT_TYPE_COLOR:
-        s = m_paint->m_paintColor;
-        break;
-
-    case VG_PAINT_TYPE_LINEAR_GRADIENT:
-    {
-        RIfloat g, rho;
-        linearGradient(g, rho, x+0.5f, y+0.5f);
-        s = colorRamp(g, rho);
-        RI_ASSERT((s.getInternalFormat() == Color::sRGBA && !m_paint->m_colorRampPremultiplied) || (s.getInternalFormat() == Color::sRGBA_PRE && m_paint->m_colorRampPremultiplied));
-        s.premultiply();
-        break;
-    }
-
-    case VG_PAINT_TYPE_RADIAL_GRADIENT:
-    {
-        RIfloat g, rho;
-        radialGradient(g, rho, x+0.5f, y+0.5f);
-        s = colorRamp(g, rho);
-        RI_ASSERT((s.getInternalFormat() == Color::sRGBA && !m_paint->m_colorRampPremultiplied) || (s.getInternalFormat() == Color::sRGBA_PRE && m_paint->m_colorRampPremultiplied));
-        s.premultiply();
-        break;
-    }
-
-    default:
-        RI_ASSERT(m_paint->m_paintType == VG_PAINT_TYPE_PATTERN);
-        if(m_paint->m_pattern)
-            s = m_paint->m_pattern->resample(x+0.5f, y+0.5f, m_surfaceToPaintMatrix, m_imageQuality, m_paint->m_patternTilingMode, m_tileFillColor);
-        else
-            s = m_paint->m_paintColor;
-        break;
-    }
-    s.assertConsistency();
-
-    //apply image (vgDrawImage only)
-    //1. paint: convert paint to dst space
-    //2. image: convert image to dst space
-    //3. paint MULTIPLY image: convert paint to image number of channels, multiply with image, and convert to dst
-    //4. paint STENCIL image: convert paint to dst, convert image to dst number of channels, multiply
-
-    //color transform:
-    //paint => transform paint color
-    //image normal => transform image color
-    //image multiply => transform paint*image color
-    //image stencil => transform paint color
-
-    RIfloat ar = 0.0f, ag = 0.0f, ab = 0.0f;
-    if(m_image)
-    {
-        Color im = m_image->resample(x+0.5f, y+0.5f, m_surfaceToImageMatrix, m_imageQuality, VG_TILE_PAD, Color(0,0,0,0,m_image->getDescriptor().internalFormat));
-        im.assertConsistency();
-
-        switch(m_imageMode)
-        {
-        case VG_DRAW_IMAGE_NORMAL:
-            s = im;
-            colorTransform(s);
-            ar = s.a;
-            ag = s.a;
-            ab = s.a;
-            s.convert(dstFormat);   //convert image color to destination color space
-            break;
-        case VG_DRAW_IMAGE_MULTIPLY:
-            //the result will be in image color space, except when paint is RGB and image is L the result will be RGB.
-            //paint == RGB && image == RGB: RGB*RGB
-            //paint == RGB && image == L  : RGB*LLL
-            //paint == L   && image == RGB: LLL*RGB
-            //paint == L   && image == L  : L*L
-            RI_ASSERT(m_surfaceToPaintMatrix.isAffine());
-            if(!s.isLuminance() && im.isLuminance())
-                im.convert((Color::InternalFormat)(im.getInternalFormat() & ~Color::LUMINANCE));
-            im.r *= s.r;
-            im.g *= s.g;
-            im.b *= s.b;
-            im.a *= s.a;
-            s = im;     //use image color space
-            colorTransform(s);
-            ar = s.a;
-            ag = s.a;
-            ab = s.a;
-            s.convert(dstFormat);   //convert resulting color to destination color space
-            break;
-        default:
-            //the result will be in paint color space.
-            //dst == RGB && image == RGB: RGB*RGB
-            //dst == RGB && image == L  : RGB*LLL
-            //dst == L   && image == RGB: L*(0.2126 R + 0.7152 G + 0.0722 B)
-            //dst == L   && image == L  : L*L
-            RI_ASSERT(m_imageMode == VG_DRAW_IMAGE_STENCIL);
-            if(dstFormat & Color::LUMINANCE && !im.isLuminance())
-            {
-                im.r = im.g = im.b = RI_MIN(0.2126f*im.r + 0.7152f*im.g + 0.0722f*im.b, im.a);
-            }
-            RI_ASSERT(m_surfaceToPaintMatrix.isAffine());
-            //s and im are both in premultiplied format. Each image channel acts as an alpha channel.
-            colorTransform(s);
-            s.convert(dstFormat);   //convert paint color to destination space already here, since convert cannot deal with per channel alphas used in this mode.
-            //compute per channel alphas
-            ar = s.a * im.r;
-            ag = s.a * im.g;
-            ab = s.a * im.b;
-            //premultiply each channel by per channel alphas from the image
-            s.r *= im.r;
-            s.g *= im.g;
-            s.b *= im.b;
-            s.a *= im.a;
-            //in nonpremultiplied form the result is
-            // s.rgb = paint.a * paint.rgb * image.a * image.rgb
-            // s.a = paint.a * image.a
-            // argb = paint.a * image.a * image.rgb
-            break;
-        }
-    }
-    else
-    {    //paint only
-        colorTransform(s);
-        ar = s.a;
-        ag = s.a;
-        ab = s.a;
-        s.convert(dstFormat);   //convert paint color to destination color space
-    }
-    RI_ASSERT(s.getInternalFormat() == Color::lRGBA_PRE || s.getInternalFormat() == Color::sRGBA_PRE || s.getInternalFormat() == Color::lLA_PRE || s.getInternalFormat() == Color::sLA_PRE);
-    s.assertConsistency();
-
-    Surface* colorBuffer = m_drawable->getColorBuffer();
-    Surface* maskBuffer = m_drawable->getMaskBuffer();
-    RI_ASSERT(colorBuffer);
-
-    if(m_drawable->getNumSamples() == 1)
-    {   //coverage-based antialiasing
-        RIfloat cov = coverage;
-        if(m_masking && maskBuffer)
-        {
-            cov *= maskBuffer->readMaskCoverage(x, y);
-            if(cov == 0.0f)
-                return;
-        }
-
-        //read destination color
-        Color d = colorBuffer->readSample(x, y, 0);
-        d.premultiply();
-        RI_ASSERT(dstFormat == Color::lRGBA_PRE || dstFormat == Color::sRGBA_PRE || dstFormat == Color::lLA_PRE || dstFormat == Color::sLA_PRE);
-
-        //blend
-        Color r = blend(s, ar, ag, ab, d, m_blendMode);
-
-        //apply antialiasing in linear color space
-        Color::InternalFormat aaFormat = (dstFormat & Color::LUMINANCE) ? Color::lLA_PRE : Color::lRGBA_PRE;
-        r.convert(aaFormat);
-        d.convert(aaFormat);
-        r = r * cov + d * (1.0f - cov);
-
-        //write result to the destination surface
-        r.convert(colorBuffer->getDescriptor().internalFormat);
-        colorBuffer->writeSample(x, y, 0, r);
-    }
-    else
-    {   //multisampling FSAA
-        if(m_masking && maskBuffer)
-        {
-            sampleMask &= maskBuffer->readMaskMSAA(x, y);
-            if(!sampleMask)
-                return;
-        }
-
-        {
-            for(int i=0;i<m_drawable->getNumSamples();i++)
-            {
-                if(sampleMask & (1<<i)) //1-bit coverage
-                {
-                    //read destination color
-                    Color d = colorBuffer->readSample(x, y, i);
-
-                    d.premultiply();
-                    RI_ASSERT(dstFormat == Color::lRGBA_PRE || dstFormat == Color::sRGBA_PRE || dstFormat == Color::lLA_PRE || dstFormat == Color::sLA_PRE);
-
-                    //blend
-                    Color r = blend(s, ar, ag, ab, d, m_blendMode);
-
-                    //write result to the destination surface
-                    r.convert(colorBuffer->getDescriptor().internalFormat);
-                    colorBuffer->writeSample(x, y, i, r);
-                }
-            }
-        }
-    }
-}
-
-//=======================================================================
-    
-}   //namespace OpenVGRI
--- a/egl/sfopenvg/riPixelPipe.h	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,155 +0,0 @@
-#ifndef __RIPIXELPIPE_H
-#define __RIPIXELPIPE_H
-
-/*------------------------------------------------------------------------
- *
- * OpenVG 1.1 Reference Implementation
- * -----------------------------------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief	Paint and PixelPipe classes.
- * \note	
- *//*-------------------------------------------------------------------*/
-
-#ifndef __RIMATH_H
-#include "riMath.h"
-#endif
-
-#ifndef __RIIMAGE_H
-#include "riImage.h"
-#endif
-
-//=======================================================================
-
-namespace OpenVGRI
-{
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Storage and operations for VGPaint.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-class Paint
-{
-public:
-	Paint();
-	~Paint();
-	void					addReference()							{ m_referenceCount++; }
-	int						removeReference()						{ m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
-
-	struct GradientStop
-	{
-		GradientStop() : offset(0.0f), color(0.0f, 0.0f, 0.0f, 0.0f, Color::sRGBA) {}
-		RIfloat		offset;
-		Color		color;
-	};
-
-	VGPaintType				m_paintType;
-	Color					m_paintColor;
-	Color					m_inputPaintColor;
-	VGColorRampSpreadMode	m_colorRampSpreadMode;
-	Array<GradientStop>		m_colorRampStops;
-	Array<GradientStop>		m_inputColorRampStops;
-	VGboolean				m_colorRampPremultiplied;
-	Vector2					m_inputLinearGradientPoint0;
-	Vector2					m_inputLinearGradientPoint1;
-	Vector2					m_inputRadialGradientCenter;
-	Vector2					m_inputRadialGradientFocalPoint;
-	RIfloat					m_inputRadialGradientRadius;
-	Vector2					m_linearGradientPoint0;
-	Vector2					m_linearGradientPoint1;
-	Vector2					m_radialGradientCenter;
-	Vector2					m_radialGradientFocalPoint;
-	RIfloat					m_radialGradientRadius;
-	VGTilingMode			m_patternTilingMode;
-	Image*					m_pattern;
-private:
-	Paint(const Paint&);						//!< Not allowed.
-	const Paint& operator=(const Paint&);		//!< Not allowed.
-
-	int						m_referenceCount;
-};
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Encapsulates all information needed for painting a pixel.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-	
-class PixelPipe
-{
-public:
-	PixelPipe();	//throws bad_alloc
-	~PixelPipe();
-
-	void	pixelPipe(int x, int y, RIfloat coverage, unsigned int sampleMask) const;	//rasterizer calls this function for each pixel
-
-	void	setDrawable(Drawable* drawable);
-	void	setBlendMode(VGBlendMode blendMode);
-	void	setMask(bool masking);
-	void	setImage(Image* image, VGImageMode imageMode);	//image = NULL disables drawImage functionality
-	void	setSurfaceToPaintMatrix(const Matrix3x3& surfaceToPaintMatrix);
-	void	setSurfaceToImageMatrix(const Matrix3x3& surfaceToImageMatrix);
-	void	setImageQuality(VGImageQuality imageQuality);
-	void	setTileFillColor(const Color& c);
-	void	setPaint(const Paint* paint);
-    void    setColorTransform(bool enable, RIfloat values[8]);
-
-private:
-	void	linearGradient(RIfloat& g, RIfloat& rho, RIfloat x, RIfloat y) const;
-	void	radialGradient(RIfloat& g, RIfloat& rho, RIfloat x, RIfloat y) const;
-	Color	integrateColorRamp(RIfloat gmin, RIfloat gmax) const;
-	Color	colorRamp(RIfloat gradient, RIfloat rho) const;
-	Color	blend(const Color& s, RIfloat ar, RIfloat ag, RIfloat ab, const Color& d, VGBlendMode blendMode) const;
-    void    colorTransform(Color& c) const;
-
-	PixelPipe(const PixelPipe&);						//!< Not allowed.
-	const PixelPipe& operator=(const PixelPipe&);		//!< Not allowed.
-
-	Drawable*               m_drawable;
-	bool					m_masking;
-	Image*					m_image;
-	const Paint*			m_paint;
-	Paint					m_defaultPaint;
-	VGBlendMode				m_blendMode;
-	VGImageMode				m_imageMode;
-	VGImageQuality			m_imageQuality;
-	Color					m_tileFillColor;
-    bool                    m_colorTransform;
-    RIfloat                 m_colorTransformValues[8];
-	Matrix3x3				m_surfaceToPaintMatrix;
-	Matrix3x3				m_surfaceToImageMatrix;
-};
-
-//=======================================================================
-
-}	//namespace OpenVGRI
-
-//=======================================================================
-
-#endif /* __RIPIXELPIPE_H */
--- a/egl/sfopenvg/riRasterizer.cpp	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,499 +0,0 @@
-/*------------------------------------------------------------------------
- *
- * OpenVG 1.1 Reference Implementation
- * -----------------------------------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief	Implementation of polygon rasterizer.
- * \note	
- *//*-------------------------------------------------------------------*/
-
-#include "riRasterizer.h"
-
-//==============================================================================================
-
-namespace OpenVGRI
-{
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Rasterizer constructor.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Rasterizer::Rasterizer() :
-	m_edges(),
-	m_scissorEdges(),
-	m_scissor(false),
-	m_samples(),
-	m_numSamples(0),
-	m_numFSAASamples(0),
-	m_sumWeights(0.0f),
-	m_sampleRadius(0.0f),
-    m_vpx(0),
-    m_vpy(0),
-    m_vpwidth(0),
-    m_vpheight(0),
-    m_fillRule(VG_EVEN_ODD),
-    m_pixelPipe(NULL),
-    m_covBuffer(NULL)
-{}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Rasterizer destructor.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-Rasterizer::~Rasterizer()
-{
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Removes all appended edges.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Rasterizer::clear()
-{
-	m_edges.clear();
-    m_edgeMin.set(RI_FLOAT_MAX, RI_FLOAT_MAX);
-    m_edgeMax.set(-RI_FLOAT_MAX, -RI_FLOAT_MAX);
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Appends an edge to the rasterizer.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Rasterizer::addBBox(const Vector2& v)
-{
-    if(v.x < m_edgeMin.x) m_edgeMin.x = v.x;
-    if(v.y < m_edgeMin.y) m_edgeMin.y = v.y;
-    if(v.x > m_edgeMax.x) m_edgeMax.x = v.x;
-    if(v.y > m_edgeMax.y) m_edgeMax.y = v.y;
-}
-
-void Rasterizer::addEdge(const Vector2& v0, const Vector2& v1)
-{
-	if( m_edges.size() >= RI_MAX_EDGES )
-		throw std::bad_alloc();	//throw an out of memory error if there are too many edges
-
-	if(v0.y == v1.y)
-		return;	//skip horizontal edges (they don't affect rasterization since we scan horizontally)
-
-	Edge e;
-	if(v0.y < v1.y)
-	{	//edge is going upward
-		e.v0 = v0;
-		e.v1 = v1;
-		e.direction = 1;
-	}
-	else
-	{	//edge is going downward
-		e.v0 = v1;
-		e.v1 = v0;
-		e.direction = -1;
-	}
-
-    addBBox(v0);
-    addBBox(v1);
-
-	m_edges.push_back(e);	//throws bad_alloc
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Set up rasterizer
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Rasterizer::setup(int vpx, int vpy, int vpwidth, int vpheight, VGFillRule fillRule, const PixelPipe* pixelPipe, unsigned int* covBuffer)
-{
-	RI_ASSERT(vpwidth >= 0 && vpheight >= 0);
-	RI_ASSERT(vpx + vpwidth >= vpx && vpy + vpheight >= vpy);
-	RI_ASSERT(fillRule == VG_EVEN_ODD || fillRule == VG_NON_ZERO);
-    RI_ASSERT(pixelPipe || covBuffer);
-    m_vpx = vpx;
-    m_vpy = vpy;
-    m_vpwidth = vpwidth;
-    m_vpheight = vpheight;
-    m_fillRule = fillRule;
-    m_pixelPipe = pixelPipe;
-    m_covBuffer = covBuffer;
-    m_covMinx = vpx+vpwidth;
-    m_covMiny = vpy+vpheight;
-    m_covMaxx = vpx;
-    m_covMaxy = vpy;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Sets scissor rectangles.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Rasterizer::setScissor(const Array<Rectangle>& scissors)
-{
-	m_scissor = true;
-	try
-	{
-		m_scissorEdges.clear();
-		for(int i=0;i<scissors.size();i++)
-		{
-			if(scissors[i].width > 0 && scissors[i].height > 0)
-			{
-				ScissorEdge e;
-				e.miny = scissors[i].y;
-				e.maxy = RI_INT_ADDSATURATE(scissors[i].y, scissors[i].height);
-
-				e.x = scissors[i].x;
-				e.direction = 1;
-				m_scissorEdges.push_back(e);	//throws bad_alloc
-				e.x = RI_INT_ADDSATURATE(scissors[i].x, scissors[i].width);
-				e.direction = -1;
-				m_scissorEdges.push_back(e);	//throws bad_alloc
-			}
-		}
-	}
-	catch(std::bad_alloc)
-	{
-		m_scissorEdges.clear();
-		throw;
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Returns a radical inverse of a given integer for Hammersley
-*			point set.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static double radicalInverseBase2(unsigned int i)
-{
-	if( i == 0 )
-		return 0.0;
-	double p = 0.0;
-	double f = 0.5;
-	double ff = f;
-	for(unsigned int j=0;j<32;j++)
-	{
-		if( i & (1<<j) )
-			p += f;
-		f *= ff;
-	}
-	return p;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Calls PixelPipe::pixelPipe for each pixel with coverage greater
-*			than zero.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-int Rasterizer::setupSamplingPattern(VGRenderingQuality renderingQuality, int numFSAASamples)
-{
-	RI_ASSERT(renderingQuality == VG_RENDERING_QUALITY_NONANTIALIASED ||
-			  renderingQuality == VG_RENDERING_QUALITY_FASTER ||
-			  renderingQuality == VG_RENDERING_QUALITY_BETTER);
-	RI_ASSERT(numFSAASamples > 0 && numFSAASamples <= RI_MAX_SAMPLES);
-
-	//make a sampling pattern
-	m_sumWeights = 0.0f;
-	m_sampleRadius = 0.0f;		//max offset of the sampling points from a pixel center
-	m_numFSAASamples = numFSAASamples;
-	if(numFSAASamples == 1)
-	{
-		if(renderingQuality == VG_RENDERING_QUALITY_NONANTIALIASED)
-		{
-			m_numSamples = 1;
-			m_samples[0].x = 0.0f;
-			m_samples[0].y = 0.0f;
-			m_samples[0].weight = 1.0f;
-			m_sampleRadius = 0.0f;
-			m_sumWeights = 1.0f;
-		}
-		else if(renderingQuality == VG_RENDERING_QUALITY_FASTER)
-		{	//box filter of diameter 1.0f, 8-queen sampling pattern
-			m_numSamples = 8;
-			m_samples[0].x = 3;
-			m_samples[1].x = 7;
-			m_samples[2].x = 0;
-			m_samples[3].x = 2;
-			m_samples[4].x = 5;
-			m_samples[5].x = 1;
-			m_samples[6].x = 6;
-			m_samples[7].x = 4;
-			for(int i=0;i<m_numSamples;i++)
-			{
-				m_samples[i].x = (m_samples[i].x + 0.5f) / (RScalar)m_numSamples - 0.5f;
-				m_samples[i].y = ((RScalar)i + 0.5f) / (RScalar)m_numSamples - 0.5f;
-				m_samples[i].weight = 1.0f / (RScalar)m_numSamples;
-				m_sumWeights += m_samples[i].weight;
-			}
-			m_sampleRadius = 0.5f;
-		}
-		else
-		{
-			RI_ASSERT(renderingQuality == VG_RENDERING_QUALITY_BETTER);
-			m_numSamples = RI_MAX_SAMPLES;
-			m_sampleRadius = 0.75f;
-			for(int i=0;i<m_numSamples;i++)
-			{	//Gaussian filter, implemented using Hammersley point set for sample point locations
-				RScalar x = (RScalar)radicalInverseBase2(i);
-				RScalar y = ((RScalar)i + 0.5f) / (RScalar)m_numSamples;
-				RI_ASSERT(x >= 0.0f && x < 1.0f);
-				RI_ASSERT(y >= 0.0f && y < 1.0f);
-
-				//map unit square to unit circle
-				RScalar r = (RScalar)sqrt(x) * m_sampleRadius;
-				x = r * (RScalar)sin(y*2.0f*PI);
-				y = r * (RScalar)cos(y*2.0f*PI);
-				m_samples[i].weight = (RScalar)exp(-0.5f * RI_SQR(r/m_sampleRadius));
-
-				RI_ASSERT(x >= -1.5f && x <= 1.5f && y >= -1.5f && y <= 1.5f);	//the specification restricts the filter radius to be less than or equal to 1.5
-				
-				m_samples[i].x = x;
-				m_samples[i].y = y;
-				m_sumWeights += m_samples[i].weight;
-			}
-		}
-	}
-	else
-	{	//box filter
-        m_numSamples = numFSAASamples;
-        RI_ASSERT(numFSAASamples >= 1 && numFSAASamples <= 32);	//sample mask is a 32-bit uint => can't support more than 32 samples
-		//use Hammersley point set as a sampling pattern
-        for(int i=0;i<m_numSamples;i++)
-        {
-            m_samples[i].x = (RScalar)radicalInverseBase2(i) + 1.0f / (RScalar)(m_numSamples<<1) - 0.5f;
-            m_samples[i].y = ((RScalar)i + 0.5f) / (RScalar)m_numSamples - 0.5f;
-            m_samples[i].weight = 1.0f;
-			RI_ASSERT(m_samples[i].x > -0.5f && m_samples[i].x < 0.5f);
-			RI_ASSERT(m_samples[i].y > -0.5f && m_samples[i].y < 0.5f);
-        }
-        m_sumWeights = (RScalar)m_numSamples;
-        m_sampleRadius = 0.5f;
-	}
-    return m_numSamples;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Calls PixelPipe::pixelPipe for each pixel with coverage greater
-*			than zero.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void Rasterizer::fill()
-{
-	if(m_scissor && !m_scissorEdges.size())
-		return;	//scissoring is on, but there are no scissor rectangles => nothing is visible
-
-	//proceed scanline by scanline
-	//keep track of edges that can intersect the pixel filters of the current scanline (Active Edge Table)
-	//until all pixels of the scanline have been processed
-	//  for all sampling points of the current pixel
-	//    determine the winding number using edge functions
-	//    add filter weight to coverage
-	//  divide coverage by the number of samples
-	//  determine a run of pixels with constant coverage
-	//  call fill callback for each pixel of the run
-
-	int fillRuleMask = 1;
-	if(m_fillRule == VG_NON_ZERO)
-		fillRuleMask = -1;
-
-    int bbminx = (int)floor(m_edgeMin.x);
-    int bbminy = (int)floor(m_edgeMin.y);
-    int bbmaxx = (int)floor(m_edgeMax.x)+1;
-    int bbmaxy = (int)floor(m_edgeMax.y)+1;
-    int sx = RI_INT_MAX(m_vpx, bbminx);
-    int ex = RI_INT_MIN(m_vpx+m_vpwidth, bbmaxx);
-    int sy = RI_INT_MAX(m_vpy, bbminy);
-    int ey = RI_INT_MIN(m_vpy+m_vpheight, bbmaxy);
-    if(sx < m_covMinx) m_covMinx = sx;
-    if(sy < m_covMiny) m_covMiny = sy;
-    if(ex > m_covMaxx) m_covMaxx = ex;
-    if(ey > m_covMaxy) m_covMaxy = ey;
-
-	//fill the screen
-	Array<ActiveEdge> aet;
-	Array<ScissorEdge> scissorAet;
-	for(int j=sy;j<ey;j++)
-	{
-		//gather scissor edges intersecting this scanline
-		scissorAet.clear();
-		if( m_scissor )
-		{
-			for(int e=0;e<m_scissorEdges.size();e++)
-			{
-				const ScissorEdge& se = m_scissorEdges[e];
-				if(j >= se.miny && j < se.maxy)
-					scissorAet.push_back(m_scissorEdges[e]);	//throws bad_alloc
-			}
-			if(!scissorAet.size())
-				continue;	//scissoring is on, but there are no scissor rectangles on this scanline
-		}
-
-		//simple AET: scan through all the edges and pick the ones intersecting this scanline
-		aet.clear();
-		for(int e=0;e<m_edges.size();e++)
-		{
-			RScalar cminy = (RScalar)j - m_sampleRadius + 0.5f;
-			RScalar cmaxy = (RScalar)j + m_sampleRadius + 0.5f;
-			const Edge& ed = m_edges[e];
-			RI_ASSERT(ed.v0.y <= ed.v1.y);	//horizontal edges should have been dropped already
-
-			ActiveEdge ae;
-			ae.v0 = ed.v0;
-			ae.v1 = ed.v1;
-			ae.direction = ed.direction;
-
-			if(cmaxy >= ae.v0.y && cminy < ae.v1.y)
-			{
-				ae.n.set(ae.v0.y - ae.v1.y, ae.v1.x - ae.v0.x);	//edge normal
-				ae.cnst = ae.v0.x * ae.n.x + ae.v0.y * ae.n.y;	//distance of v0 from the origin along the edge normal
-				
-				//compute edge min and max x-coordinates for this scanline
-				Vector2 vd(ae.v1.x - ae.v0.x, ae.v1.y - ae.v0.y);
-				RScalar wl = 1.0f / vd.y;
-				RScalar sx = ae.v0.x + vd.x * (cminy - ae.v0.y) * wl;
-				RScalar ex = ae.v0.x + vd.x * (cmaxy - ae.v0.y) * wl;
-				RScalar bminx = RI_MIN(ae.v0.x, ae.v1.x);
-				RScalar bmaxx = RI_MAX(ae.v0.x, ae.v1.x);
-				sx = RI_CLAMP(sx, bminx, bmaxx);
-				ex = RI_CLAMP(ex, bminx, bmaxx);
-				ae.minx = RI_MIN(sx,ex);
-				ae.maxx = RI_MAX(sx,ex);
-				aet.push_back(ae);	//throws bad_alloc
-			}
-		}
-		if(!aet.size())
-			continue;	//no edges on the whole scanline, skip it
-
-		//sort AET by edge minx
-		aet.sort();
-		
-		//sort scissor AET by edge x
-		scissorAet.sort();
-
-		//fill the scanline
-		int scissorWinding = m_scissor ? 0 : 1;	//if scissoring is off, winding is always 1
-		int scissorIndex = 0;
-		int aes = 0;
-		int aen = 0;
-		for(int i=sx;i<ex;)
-		{
-			Vector2 pc(i + 0.5f, j + 0.5f);		//pixel center
-			
-			//find edges that intersect or are to the left of the pixel antialiasing filter
-			while(aes < aet.size() && pc.x + m_sampleRadius >= aet[aes].minx)
-				aes++;
-			//edges [0,aes[ may have an effect on winding, and need to be evaluated while sampling
-
-			//compute coverage
-			RScalar coverage = 0.0f;
-			unsigned int sampleMask = 0;
-			for(int s=0;s<m_numSamples;s++)
-			{
-				Vector2 sp = pc;	//sampling point
-				sp.x += m_samples[s].x;
-				sp.y += m_samples[s].y;
-
-				//compute winding number by evaluating the edge functions of edges to the left of the sampling point
-				int winding = 0;
-				for(int e=0;e<aes;e++)
-				{
-					if(sp.y >= aet[e].v0.y && sp.y < aet[e].v1.y)
-					{	//evaluate edge function to determine on which side of the edge the sampling point lies
-						RScalar side = sp.x * aet[e].n.x + sp.y * aet[e].n.y - aet[e].cnst;
-						if(side <= 0.0f)	//implicit tie breaking: a sampling point on an opening edge is in, on a closing edge it's out
-						{
-                            winding += aet[e].direction;
-						}
-					}
-				}
-                if(winding & fillRuleMask)
-				{
-					coverage += m_samples[s].weight;
-					sampleMask |= (unsigned int)(1<<s);
-				}
-			}
-
-			//constant coverage optimization:
-			//scan AET from left to right and skip all the edges that are completely to the left of the pixel filter.
-			//since AET is sorted by minx, the edge we stop at is the leftmost of the edges we haven't passed yet.
-			//if that edge is to the right of this pixel, coverage is constant between this pixel and the start of the edge.
-			while(aen < aet.size() && aet[aen].maxx < pc.x - m_sampleRadius - 0.01f)	//0.01 is a safety region to prevent too aggressive optimization due to numerical inaccuracy
-				aen++;
-
-			int endSpan = m_vpx + m_vpwidth;	//endSpan is the first pixel NOT part of the span
-			if(aen < aet.size())
-				endSpan = RI_INT_MAX(i+1, RI_INT_MIN(endSpan, (int)ceil(aet[aen].minx - m_sampleRadius - 0.5f)));
-
-			coverage /= m_sumWeights;
-			RI_ASSERT(coverage >= 0.0f && coverage <= 1.0f);
-
-			//fill a run of pixels with constant coverage
-			if(sampleMask)
-			{
-				for(;i<endSpan;i++)
-				{
-					//update scissor winding number
-					while(scissorIndex < scissorAet.size() && scissorAet[scissorIndex].x <= i)
-						scissorWinding += scissorAet[scissorIndex++].direction;
-					RI_ASSERT(scissorWinding >= 0);
-
-					if(scissorWinding)
-                    {
-                        if(m_covBuffer)
-                            m_covBuffer[j*m_vpwidth+i] |= (RIuint32)sampleMask;
-                        else
-                            m_pixelPipe->pixelPipe(i, j, coverage, sampleMask);
-                    }
-				}
-			}
-			i = endSpan;
-		}
-	}
-}
-
-//=======================================================================
-
-}	//namespace OpenVGRI
--- a/egl/sfopenvg/riRasterizer.h	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,173 +0,0 @@
-#ifndef __RIRASTERIZER_H
-#define __RIRASTERIZER_H
-
-/*------------------------------------------------------------------------
- *
- * OpenVG 1.1 Reference Implementation
- * -----------------------------------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief	Rasterizer class.
- * \note	
- *//*-------------------------------------------------------------------*/
-
-#ifndef __RIMATH_H
-#include "riMath.h"
-#endif
-
-#ifndef __RIARRAY_H
-#include "riArray.h"
-#endif
-
-#ifndef __RIPIXELPIPE_H
-#include "riPixelPipe.h"
-#endif
-
-//=======================================================================
-
-namespace OpenVGRI
-{
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Scalar and vector data types used by the rasterizer.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-typedef RIfloat RScalar;	//change this if you want to have different precision for rasterizer scalars and RIfloat
-
-struct RVector2
-{
-	RI_INLINE RVector2()							{ }
-	RI_INLINE RVector2(const Vector2& v)			{ x = v.x; y = v.y; }
-	RI_INLINE RVector2(RIfloat vx, RIfloat vy)		{ x = vx; y = vy; }
-	RI_INLINE void set(RIfloat vx, RIfloat vy)		{ x = vx; y = vy; }
-	RScalar		x;
-	RScalar		y;
-};
-
-/*-------------------------------------------------------------------*//*!
-* \brief	Converts a set of edges to coverage values for each pixel and
-*			calls PixelPipe::pixelPipe for painting a pixel.
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-class Rasterizer
-{
-public:
-	Rasterizer();	//throws bad_alloc
-	~Rasterizer();
-
-    void        setup(int vpx, int vpy, int vpwidth, int vpheight, VGFillRule fillRule, const PixelPipe* pixelPipe, RIuint32* covBuffer);
-	void		setScissor(const Array<Rectangle>& scissors);	//throws bad_alloc
-
-	void		clear();
-	void		addEdge(const Vector2& v0, const Vector2& v1);	//throws bad_alloc
-
-	int         setupSamplingPattern(VGRenderingQuality renderingQuality, int numFSAASamples);
-	void		fill();	//throws bad_alloc
-
-    void        getBBox(int& sx, int& sy, int& ex, int& ey) const       { sx = m_covMinx; sy = m_covMiny; ex = m_covMaxx; ey = m_covMaxy; }
-private:
-	Rasterizer(const Rasterizer&);						//!< Not allowed.
-	const Rasterizer& operator=(const Rasterizer&);		//!< Not allowed.
-
-	struct ScissorEdge
-	{
-		ScissorEdge() : x(0), miny(0), maxy(0), direction(0) {}
-		bool operator<(const ScissorEdge& e) const	{ return x < e.x; }
-		int			x;
-		int			miny;
-		int			maxy;
-		int			direction;		//1 start, -1 end
-	};
-
-	struct Edge
-	{
-		Edge() : v0(), v1(), direction(1) {}
-		bool operator<(const Edge& e) const	{ return v0.y < e.v0.y; }
-		RVector2	v0;
-		RVector2	v1;
-		int			direction;
-	};
-
-	struct ActiveEdge
-	{
-		ActiveEdge() : v0(), v1(), direction(0), minx(0.0f), maxx(0.0f), n(), cnst(0.0f) {}
-		bool operator<(const ActiveEdge& e) const	{ return minx < e.minx; }
-		RVector2	v0;
-		RVector2	v1;
-		int			direction;		//-1 down, 1 up
-		RScalar		minx;			//for the current scanline
-		RScalar		maxx;			//for the current scanline
-		RVector2	n;
-		RScalar		cnst;
-	};
-
-	struct Sample
-	{
-		Sample() : x(0.0f), y(0.0f), weight(0.0f) {}
-		RScalar		x;
-		RScalar		y;
-		RScalar		weight;
-	};
-
-    void                addBBox(const Vector2& v);
-
-	Array<Edge>				m_edges;
-	Array<ScissorEdge>		m_scissorEdges;
-	bool					m_scissor;
-
-	Sample				m_samples[RI_MAX_SAMPLES];
-	int					m_numSamples;
-	int					m_numFSAASamples;
-	RScalar				m_sumWeights;
-	RScalar				m_sampleRadius;
-
-    Vector2             m_edgeMin;
-    Vector2             m_edgeMax;
-    int                 m_covMinx;
-    int                 m_covMiny;
-    int                 m_covMaxx;
-    int                 m_covMaxy;
-    int                 m_vpx;
-    int                 m_vpy;
-    int                 m_vpwidth;
-    int                 m_vpheight;
-    VGFillRule          m_fillRule;
-    const PixelPipe*    m_pixelPipe;
-    RIuint32*           m_covBuffer;
-};
-
-//=======================================================================
-
-}	//namespace OpenVGRI
-
-//=======================================================================
-
-#endif /* __RIRASTERIZER_H */
--- a/egl/sfopenvg/riVGU.cpp	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,606 +0,0 @@
-/*------------------------------------------------------------------------
- *
- * VGU library for OpenVG 1.1 Reference Implementation
- * ---------------------------------------------------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief	Implementation of the VGU utility library for OpenVG
- *//*-------------------------------------------------------------------*/
-
-#include "vgu.h"
-#include "openvg.h"
-#include "riMath.h"
-
-#ifdef BUILD_WITH_PRIVATE_VGU
-#include "vguinternal.h"
-#endif
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-#include "openvginternal.h"
-#endif
-
-using namespace OpenVGRI;
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-static void append(VGPath path, int numSegments, const VGubyte* segments, int numCoordinates, const VGfloat* coordinates)
-{
-	RI_ASSERT(numCoordinates <= 26);
-
-
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-	VGPathDatatype datatype = (VGPathDatatype)do_vgGetParameteri(path, VG_PATH_DATATYPE);
-	VGfloat scale = do_vgGetParameterf(path, VG_PATH_SCALE);
-	VGfloat bias = do_vgGetParameterf(path, VG_PATH_BIAS);
-#else
-	VGPathDatatype datatype = (VGPathDatatype)vgGetParameteri(path, VG_PATH_DATATYPE);
-	VGfloat scale = vgGetParameterf(path, VG_PATH_SCALE);
-	VGfloat bias = vgGetParameterf(path, VG_PATH_BIAS);
-#endif
-
-	switch(datatype)
-	{
-	case VG_PATH_DATATYPE_S_8:
-	{
-		RIint8 data[26];
-		for(int i=0;i<numCoordinates;i++)
-			data[i] = (RIint8)floor((coordinates[i] - bias) / scale + 0.5f);	//add 0.5 for correct rounding
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-		do_vgAppendPathData(path, numSegments, segments, data);
-#else
-		vgAppendPathData(path, numSegments, segments, data);
-#endif
-		break;
-	}
-
-	case VG_PATH_DATATYPE_S_16:
-	{
-		RIint16 data[26];
-		for(int i=0;i<numCoordinates;i++)
-			data[i] = (RIint16)floor((coordinates[i] - bias) / scale + 0.5f);	//add 0.5 for correct rounding
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-		do_vgAppendPathData(path, numSegments, segments, data);
-#else
-		vgAppendPathData(path, numSegments, segments, data);
-#endif
-		break;
-	}
-
-	case VG_PATH_DATATYPE_S_32:
-	{
-		RIint32 data[26];
-		for(int i=0;i<numCoordinates;i++)
-			data[i] = (RIint32)floor((coordinates[i] - bias) / scale + 0.5f);	//add 0.5 for correct rounding
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-		do_vgAppendPathData(path, numSegments, segments, data);
-#else
-		vgAppendPathData(path, numSegments, segments, data);
-#endif
-		break;
-	}
-
-	default:
-	{
-		RI_ASSERT(datatype == VG_PATH_DATATYPE_F);
-		RIfloat32 data[26];
-		for(int i=0;i<numCoordinates;i++)
-			data[i] = (RIfloat32)((coordinates[i] - bias) / scale);
-#ifdef BUILD_WITH_PRIVATE_OPENVG
-		do_vgAppendPathData(path, numSegments, segments, data);
-#else
-		vgAppendPathData(path, numSegments, segments, data);
-#endif
-		break;
-	}
-	}
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_VGU
-VGUErrorCode RI_APIENTRY do_vguLine(VGPath path, VGfloat x0, VGfloat y0, VGfloat x1, VGfloat y1)
-#else
-VGUErrorCode RI_APIENTRY vguLine(VGPath path, VGfloat x0, VGfloat y0, VGfloat x1, VGfloat y1)
-#endif
-{
-	#ifdef BUILD_WITH_PRIVATE_OPENVG
-		VGErrorCode error = do_vgGetError();	//clear the error state
-	#else
-		VGErrorCode error = vgGetError();	//clear the error state
-	#endif
-		
-	
-	static const VGubyte segments[2] = {VG_MOVE_TO | VG_ABSOLUTE, VG_LINE_TO | VG_ABSOLUTE};
-	const VGfloat data[4] = {x0, y0, x1, y1};
-	append(path, 2, segments, 4, data);
-
-	
-	#ifdef BUILD_WITH_PRIVATE_OPENVG
-		error = do_vgGetError();	
-	#else
-		error = vgGetError();	
-	#endif
-		
-	if(error == VG_BAD_HANDLE_ERROR)
-		return VGU_BAD_HANDLE_ERROR;
-	else if(error == VG_PATH_CAPABILITY_ERROR)
-		return VGU_PATH_CAPABILITY_ERROR;
-	return VGU_NO_ERROR;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_VGU
-VGUErrorCode RI_APIENTRY do_vguPolygon(VGPath path, const VGfloat * points, VGint count, VGboolean closed)
-#else
-VGUErrorCode RI_APIENTRY vguPolygon(VGPath path, const VGfloat * points, VGint count, VGboolean closed)
-#endif
-{
-	#ifdef BUILD_WITH_PRIVATE_OPENVG
-		VGErrorCode error = do_vgGetError();	
-	#else
-		VGErrorCode error = vgGetError();	//clear the error state	
-	#endif
-	
-	if(!points || (((RIuintptr)points) & 3) || count <= 0)
-		return VGU_ILLEGAL_ARGUMENT_ERROR;
-
-	VGubyte segments[1] = {VG_MOVE_TO | VG_ABSOLUTE};
-	VGfloat data[2];
-	for(int i=0;i<count;i++)
-	{
-		data[0] = points[i*2+0];
-		data[1] = points[i*2+1];
-		append(path, 1, segments, 2, data);
-		segments[0] = VG_LINE_TO | VG_ABSOLUTE;
-	}
-	if(closed)
-	{
-		segments[0] = VG_CLOSE_PATH;
-		append(path, 1, segments, 0, data);
-	}
-
-	#ifdef BUILD_WITH_PRIVATE_OPENVG
-		error = do_vgGetError();	
-	#else
-		error = vgGetError();	//clear the error state	
-	#endif
-	
-	if(error == VG_BAD_HANDLE_ERROR)
-		return VGU_BAD_HANDLE_ERROR;
-	else if(error == VG_PATH_CAPABILITY_ERROR)
-		return VGU_PATH_CAPABILITY_ERROR;
-	return VGU_NO_ERROR;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_VGU
-VGUErrorCode RI_APIENTRY do_vguRect(VGPath path, VGfloat x, VGfloat y, VGfloat width, VGfloat height)
-#else
-VGUErrorCode RI_APIENTRY vguRect(VGPath path, VGfloat x, VGfloat y, VGfloat width, VGfloat height)
-#endif
-{
-	#ifdef BUILD_WITH_PRIVATE_OPENVG
-		VGErrorCode error = do_vgGetError();	
-	#else
-		VGErrorCode error = vgGetError();	//clear the error state	
-	#endif
-	
-	if(width <= 0 || height <= 0)
-		return VGU_ILLEGAL_ARGUMENT_ERROR;
-
-	static const VGubyte segments[5] = {VG_MOVE_TO | VG_ABSOLUTE,
-										VG_HLINE_TO | VG_ABSOLUTE,
-										VG_VLINE_TO | VG_ABSOLUTE,
-										VG_HLINE_TO | VG_ABSOLUTE,
-										VG_CLOSE_PATH};
-	const VGfloat data[5] = {x, y, x + width, y + height, x};
-	append(path, 5, segments, 5, data);
-
-
-	#ifdef BUILD_WITH_PRIVATE_OPENVG
-		error = do_vgGetError();	
-	#else
-		error = vgGetError();	//clear the error state
-	#endif
-		
-	if(error == VG_BAD_HANDLE_ERROR)
-		return VGU_BAD_HANDLE_ERROR;
-	else if(error == VG_PATH_CAPABILITY_ERROR)
-		return VGU_PATH_CAPABILITY_ERROR;
-	return VGU_NO_ERROR;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-#ifdef BUILD_WITH_PRIVATE_VGU
-VGUErrorCode RI_APIENTRY do_vguRoundRect(VGPath path, VGfloat x, VGfloat y, VGfloat width, VGfloat height, VGfloat arcWidth, VGfloat arcHeight)
-#else
-VGUErrorCode RI_APIENTRY vguRoundRect(VGPath path, VGfloat x, VGfloat y, VGfloat width, VGfloat height, VGfloat arcWidth, VGfloat arcHeight)
-#endif
-{
-	#ifdef BUILD_WITH_PRIVATE_OPENVG
-		VGErrorCode error = do_vgGetError();	
-	#else
-		VGErrorCode error = vgGetError();	//clear the error state
-	#endif
-	
-	if(width <= 0 || height <= 0)
-		return VGU_ILLEGAL_ARGUMENT_ERROR;
-
-	arcWidth = RI_CLAMP(arcWidth, 0.0f, width);
-	arcHeight = RI_CLAMP(arcHeight, 0.0f, height);
-
-	static const VGubyte segments[10] = {VG_MOVE_TO | VG_ABSOLUTE,
-										 VG_HLINE_TO | VG_ABSOLUTE,
-										 VG_SCCWARC_TO | VG_ABSOLUTE,
-										 VG_VLINE_TO | VG_ABSOLUTE,
-										 VG_SCCWARC_TO | VG_ABSOLUTE,
-										 VG_HLINE_TO | VG_ABSOLUTE,
-										 VG_SCCWARC_TO | VG_ABSOLUTE,
-										 VG_VLINE_TO | VG_ABSOLUTE,
-										 VG_SCCWARC_TO | VG_ABSOLUTE,
-										 VG_CLOSE_PATH};
-	const VGfloat data[26] = {x + arcWidth/2, y,
-							  x + width - arcWidth/2,
-							  arcWidth/2, arcHeight/2, 0, x + width, y + arcHeight/2,
-							  y + height - arcHeight/2,
-							  arcWidth/2, arcHeight/2, 0, x + width - arcWidth/2, y + height,
-							  x + arcWidth/2,
-							  arcWidth/2, arcHeight/2, 0, x, y + height - arcHeight/2,
-							  y + arcHeight/2,
-							  arcWidth/2, arcHeight/2, 0, x + arcWidth/2, y};
-	append(path, 10, segments, 26, data);
-
-	#ifdef BUILD_WITH_PRIVATE_OPENVG
-		do_vgGetError();	
-	#else
-		error = vgGetError();	//clear the error state
-	#endif
-	
-	if(error == VG_BAD_HANDLE_ERROR)
-		return VGU_BAD_HANDLE_ERROR;
-	else if(error == VG_PATH_CAPABILITY_ERROR)
-		return VGU_PATH_CAPABILITY_ERROR;
-	return VGU_NO_ERROR;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-#ifdef BUILD_WITH_PRIVATE_VGU
-VGUErrorCode RI_APIENTRY do_vguEllipse(VGPath path, VGfloat cx, VGfloat cy, VGfloat width, VGfloat height)
-#else
-VGUErrorCode RI_APIENTRY vguEllipse(VGPath path, VGfloat cx, VGfloat cy, VGfloat width, VGfloat height)
-#endif
-{
-	#ifdef BUILD_WITH_PRIVATE_OPENVG
-		VGErrorCode error = do_vgGetError();	
-	#else
-		VGErrorCode error = vgGetError();	//clear the error state
-	#endif
-		
-	if(width <= 0 || height <= 0)
-		return VGU_ILLEGAL_ARGUMENT_ERROR;
-
-	static const VGubyte segments[4] = {VG_MOVE_TO | VG_ABSOLUTE,
-										VG_SCCWARC_TO | VG_ABSOLUTE,
-										VG_SCCWARC_TO | VG_ABSOLUTE,
-										VG_CLOSE_PATH};
-	const VGfloat data[12] = {cx + width/2, cy,
-							  width/2, height/2, 0, cx - width/2, cy,
-							  width/2, height/2, 0, cx + width/2, cy};
-	append(path, 4, segments, 12, data);
-
-	#ifdef BUILD_WITH_PRIVATE_OPENVG
-		error = do_vgGetError();	
-	#else
-		error = vgGetError();	//clear the error state
-	#endif
-		
-	if(error == VG_BAD_HANDLE_ERROR)
-		return VGU_BAD_HANDLE_ERROR;
-	else if(error == VG_PATH_CAPABILITY_ERROR)
-		return VGU_PATH_CAPABILITY_ERROR;
-	return VGU_NO_ERROR;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-#ifdef BUILD_WITH_PRIVATE_VGU
-VGUErrorCode RI_APIENTRY do_vguArc(VGPath path, VGfloat x, VGfloat y, VGfloat width, VGfloat height, VGfloat startAngle, VGfloat angleExtent, VGUArcType arcType)
-#else
-VGUErrorCode RI_APIENTRY vguArc(VGPath path, VGfloat x, VGfloat y, VGfloat width, VGfloat height, VGfloat startAngle, VGfloat angleExtent, VGUArcType arcType)
-#endif
-{
-	#ifdef BUILD_WITH_PRIVATE_OPENVG
-		VGErrorCode error = do_vgGetError();	
-	#else
-		VGErrorCode error = vgGetError();	//clear the error state
-	#endif
-		
-	if((arcType != VGU_ARC_OPEN && arcType != VGU_ARC_CHORD && arcType != VGU_ARC_PIE) || width <= 0.0f || height <= 0.0f)
-		return VGU_ILLEGAL_ARGUMENT_ERROR;
-
-	startAngle = RI_DEG_TO_RAD(startAngle);
-	angleExtent = RI_DEG_TO_RAD(angleExtent);
-
-	VGfloat w = width/2.0f;
-	VGfloat h = height/2.0f;
-
-	VGubyte segments[1];
-	VGfloat data[5];
-
-	segments[0] = VG_MOVE_TO | VG_ABSOLUTE;
-	data[0] = x + w * (VGfloat)cos(startAngle);
-	data[1] = y + h * (VGfloat)sin(startAngle);
-	append(path, 1, segments, 2, data);
-
-	data[0] = w;
-	data[1] = h;
-	data[2] = 0.0f;
-	VGfloat endAngle = startAngle + angleExtent;
-	if(angleExtent >= 0.0f)
-	{
-		segments[0] = VG_SCCWARC_TO | VG_ABSOLUTE;
-		for(VGfloat a = startAngle + PI;a < endAngle; a += PI)
-		{
-			data[3] = x + w * (VGfloat)cos(a);
-			data[4] = y + h * (VGfloat)sin(a);
-			append(path, 1, segments, 5, data);
-		}
-	}
-	else
-	{
-		segments[0] = VG_SCWARC_TO | VG_ABSOLUTE;
-		for(VGfloat a = startAngle - PI;a > endAngle; a -= PI)
-		{
-			data[3] = x + w * (VGfloat)cos(a);
-			data[4] = y + h * (VGfloat)sin(a);
-			append(path, 1, segments, 5, data);
-		}
-	}
-	data[3] = x + w * (VGfloat)cos(endAngle);
-	data[4] = y + h * (VGfloat)sin(endAngle);
-	append(path, 1, segments, 5, data);
-
-	if(arcType == VGU_ARC_CHORD)
-	{
-		segments[0] = VG_CLOSE_PATH;
-		append(path, 1, segments, 0, data);
-	}
-	else if(arcType == VGU_ARC_PIE)
-	{
-		segments[0] = VG_LINE_TO | VG_ABSOLUTE;
-		data[0] = x;
-		data[1] = y;
-		append(path, 1, segments, 2, data);
-		segments[0] = VG_CLOSE_PATH;
-		append(path, 1, segments, 0, data);
-	}
-
-	#ifdef BUILD_WITH_PRIVATE_OPENVG
-		error = do_vgGetError();	
-	#else
-		error = vgGetError();	//clear the error state
-	#endif
-		
-	if(error == VG_BAD_HANDLE_ERROR)
-		return VGU_BAD_HANDLE_ERROR;
-	else if(error == VG_PATH_CAPABILITY_ERROR)
-		return VGU_PATH_CAPABILITY_ERROR;
-	return VGU_NO_ERROR;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-#ifdef BUILD_WITH_PRIVATE_VGU
-VGUErrorCode RI_APIENTRY do_vguComputeWarpQuadToSquare(VGfloat sx0, VGfloat sy0, VGfloat sx1, VGfloat sy1, VGfloat sx2, VGfloat sy2, VGfloat sx3, VGfloat sy3, VGfloat * matrix)
-#else
-VGUErrorCode RI_APIENTRY vguComputeWarpQuadToSquare(VGfloat sx0, VGfloat sy0, VGfloat sx1, VGfloat sy1, VGfloat sx2, VGfloat sy2, VGfloat sx3, VGfloat sy3, VGfloat * matrix)
-#endif
-{
-	if(!matrix || ((RIuintptr)matrix) & 3)
-		return VGU_ILLEGAL_ARGUMENT_ERROR;
-
-	VGfloat mat[9];
-#ifdef BUILD_WITH_PRIVATE_VGU
-	VGUErrorCode ret = do_vguComputeWarpSquareToQuad(sx0, sy0, sx1, sy1, sx2, sy2, sx3, sy3, mat);
-#else
-	VGUErrorCode ret = vguComputeWarpSquareToQuad(sx0, sy0, sx1, sy1, sx2, sy2, sx3, sy3, mat);
-#endif
-	if(ret == VGU_BAD_WARP_ERROR)
-		return VGU_BAD_WARP_ERROR;
-	Matrix3x3 m(mat[0], mat[3], mat[6],
-				mat[1], mat[4], mat[7],
-				mat[2], mat[5], mat[8]);
-	bool nonsingular = m.invert();
-	if(!nonsingular)
-		return VGU_BAD_WARP_ERROR;
-	matrix[0] = m[0][0];
-	matrix[1] = m[1][0];
-	matrix[2] = m[2][0];
-	matrix[3] = m[0][1];
-	matrix[4] = m[1][1];
-	matrix[5] = m[2][1];
-	matrix[6] = m[0][2];
-	matrix[7] = m[1][2];
-	matrix[8] = m[2][2];
-	return VGU_NO_ERROR;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-#ifdef BUILD_WITH_PRIVATE_VGU
-VGUErrorCode RI_APIENTRY do_vguComputeWarpSquareToQuad(VGfloat dx0, VGfloat dy0, VGfloat dx1, VGfloat dy1, VGfloat dx2, VGfloat dy2, VGfloat dx3, VGfloat dy3, VGfloat * matrix)
-#else
-VGUErrorCode RI_APIENTRY vguComputeWarpSquareToQuad(VGfloat dx0, VGfloat dy0, VGfloat dx1, VGfloat dy1, VGfloat dx2, VGfloat dy2, VGfloat dx3, VGfloat dy3, VGfloat * matrix)
-#endif
-{
-	if(!matrix || ((RIuintptr)matrix) & 3)
-		return VGU_ILLEGAL_ARGUMENT_ERROR;
-
-	//from Heckbert:Fundamentals of Texture Mapping and Image Warping
-	//Note that his mapping of vertices is different from OpenVG's
-	//(0,0) => (dx0,dy0)
-	//(1,0) => (dx1,dy1)
-	//(0,1) => (dx2,dy2)
-	//(1,1) => (dx3,dy3)
-
-	VGfloat diffx1 = dx1 - dx3;
-	VGfloat diffy1 = dy1 - dy3;
-	VGfloat diffx2 = dx2 - dx3;
-	VGfloat diffy2 = dy2 - dy3;
-
-	VGfloat det = diffx1*diffy2 - diffx2*diffy1;
-	if(det == 0.0f)
-		return VGU_BAD_WARP_ERROR;
-
-	VGfloat sumx = dx0 - dx1 + dx3 - dx2;
-	VGfloat sumy = dy0 - dy1 + dy3 - dy2;
-
-	if(sumx == 0.0f && sumy == 0.0f)
-	{	//affine mapping
-		matrix[0] = dx1 - dx0;
-		matrix[1] = dy1 - dy0;
-		matrix[2] = 0.0f;
-		matrix[3] = dx3 - dx1;
-		matrix[4] = dy3 - dy1;
-		matrix[5] = 0.0f;
-		matrix[6] = dx0;
-		matrix[7] = dy0;
-		matrix[8] = 1.0f;
-		return VGU_NO_ERROR;
-	}
-
-	VGfloat oodet = 1.0f / det;
-	VGfloat g = (sumx*diffy2 - diffx2*sumy) * oodet;
-	VGfloat h = (diffx1*sumy - sumx*diffy1) * oodet;
-
-	matrix[0] = dx1-dx0+g*dx1;
-	matrix[1] = dy1-dy0+g*dy1;
-	matrix[2] = g;
-	matrix[3] = dx2-dx0+h*dx2;
-	matrix[4] = dy2-dy0+h*dy2;
-	matrix[5] = h;
-	matrix[6] = dx0;
-	matrix[7] = dy0;
-	matrix[8] = 1.0f;
-	return VGU_NO_ERROR;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-#ifdef BUILD_WITH_PRIVATE_VGU
-VGUErrorCode RI_APIENTRY do_vguComputeWarpQuadToQuad(VGfloat dx0, VGfloat dy0, VGfloat dx1, VGfloat dy1, VGfloat dx2, VGfloat dy2, VGfloat dx3, VGfloat dy3, VGfloat sx0, VGfloat sy0, VGfloat sx1, VGfloat sy1, VGfloat sx2, VGfloat sy2, VGfloat sx3, VGfloat sy3, VGfloat * matrix)
-#else
-VGUErrorCode RI_APIENTRY vguComputeWarpQuadToQuad(VGfloat dx0, VGfloat dy0, VGfloat dx1, VGfloat dy1, VGfloat dx2, VGfloat dy2, VGfloat dx3, VGfloat dy3, VGfloat sx0, VGfloat sy0, VGfloat sx1, VGfloat sy1, VGfloat sx2, VGfloat sy2, VGfloat sx3, VGfloat sy3, VGfloat * matrix)
-#endif
-{
-	if(!matrix || ((RIuintptr)matrix) & 3)
-		return VGU_ILLEGAL_ARGUMENT_ERROR;
-
-	VGfloat qtos[9];
-#ifdef BUILD_WITH_PRIVATE_VGU
-	VGUErrorCode ret1 = do_vguComputeWarpQuadToSquare(sx0, sy0, sx1, sy1, sx2, sy2, sx3, sy3, qtos);
-#else
-	VGUErrorCode ret1 = vguComputeWarpQuadToSquare(sx0, sy0, sx1, sy1, sx2, sy2, sx3, sy3, qtos);
-#endif
-	if(ret1 == VGU_BAD_WARP_ERROR)
-		return VGU_BAD_WARP_ERROR;
-
-	VGfloat stoq[9];
-#ifdef BUILD_WITH_PRIVATE_VGU
-	VGUErrorCode ret2 = do_vguComputeWarpSquareToQuad(dx0, dy0, dx1, dy1, dx2, dy2, dx3, dy3, stoq);
-#else
-	VGUErrorCode ret2 = vguComputeWarpSquareToQuad(dx0, dy0, dx1, dy1, dx2, dy2, dx3, dy3, stoq);
-#endif
-	if(ret2 == VGU_BAD_WARP_ERROR)
-		return VGU_BAD_WARP_ERROR;
-
-	Matrix3x3 m1(qtos[0], qtos[3], qtos[6],
-				 qtos[1], qtos[4], qtos[7],
-				 qtos[2], qtos[5], qtos[8]);
-	Matrix3x3 m2(stoq[0], stoq[3], stoq[6],
-				 stoq[1], stoq[4], stoq[7],
-				 stoq[2], stoq[5], stoq[8]);
-	Matrix3x3 r = m2 * m1;
-
-	matrix[0] = r[0][0];
-	matrix[1] = r[1][0];
-	matrix[2] = r[2][0];
-	matrix[3] = r[0][1];
-	matrix[4] = r[1][1];
-	matrix[5] = r[2][1];
-	matrix[6] = r[0][2];
-	matrix[7] = r[1][2];
-	matrix[8] = r[2][2];
-	return VGU_NO_ERROR;
-}
--- a/egl/sfopenvg/symbian/eglosnativewindowtype.h	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-/*
-* Copyright (c) 2009 Symbian Foundation Ltd
-* This component and the accompanying materials are made available
-* under the terms of the License "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Symbian Foundation Ltd - initial contribution.
-* 
-* Contributors:
-*
-* Description:
-* Declaration of native window type structure
-*/
-
-#include <e32std.h>
-#include <w32std.h>
-
-#ifndef EGLOSNATVIEWINDOWTYPE_H
-#define EGLOSNATVIEWINDOWTYPE_H
-
-struct TNativeWindowType
-	{
-public:
-	TNativeWindowType() :
-	iSize(0,0),
-	iBitmap(NULL)
-	{};
-	TSize				iSize; //to keep
-	CFbsBitmap* 		iBitmap; //to keep
-	};
-
-#endif //EGLOSCALLBACK_H
--- a/egl/sfopenvg/symbian/riEGLOS.cpp	Fri Jul 16 18:54:03 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,258 +0,0 @@
-/*------------------------------------------------------------------------
- *
- * EGL 1.3
- * -------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief	Generic OS EGL functionality (not thread safe, no window rendering)
- * \note
-  *//*-------------------------------------------------------------------*/
-
-#include "egl.h"
-#include "riImage.h"
-#include "riDefs.h"
-
-#include <e32std.h>
-#include <w32std.h>
-#include <eglosnativewindowtype.h>
-
-namespace OpenVGRI
-{
-//internal fucntions
-VGImageFormat MapSymbianDisplayModeToVG(TDisplayMode aMode);
-void ReadPixelsToCFbsBitmap(CFbsBitmap& aBitmap, TUint aW, TUint aH);
-
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void* OSGetCurrentThreadID(void)
-{
-	int g_threadid = RThread().Id();
-	return (void*)g_threadid;
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-void OSDeinitMutex(void)
-{
-}
-
-void OSAcquireMutex(void)
-{
-}
-
-void OSReleaseMutex(void)
-{
-}
-
-/*-------------------------------------------------------------------*//*!
-* \brief	
-* \param	
-* \return	
-* \note		
-*//*-------------------------------------------------------------------*/
-
-struct OSWindowContext
-{
-	//RDrawableWindow*    iDrawWindow;
-	TNativeWindowType   iNativeWindowType;
-	   
-};
-
-void* OSCreateWindowContext(EGLNativeWindowType window)
-{
-    OSWindowContext* ctx = NULL;
-    try
-    {
-        ctx = RI_NEW(OSWindowContext, ());
-    }
-	catch(std::bad_alloc)
-	{
-		return NULL;
-	}
-    //ctx->iNativeWindowType = (TNativeWindowType*)window;
-	
-	RDrawableWindow* drawbleWindow = (RDrawableWindow*)window;
-	ctx->iNativeWindowType.iSize.iHeight = drawbleWindow->Size().iHeight;
-	ctx->iNativeWindowType.iSize.iWidth = drawbleWindow->Size().iWidth;
-		
-    return ctx;
-}
-
-void OSDestroyWindowContext(void* context)
-{
-    OSWindowContext* ctx = (OSWindowContext*)context;
-    if(ctx)
-    {
-        RI_DELETE(ctx);
-    }
-}
-
-bool OSIsWindow(const void* context)
-{
-    OSWindowContext* ctx = (OSWindowContext*)context;
-    if(ctx)
-    {
-        return true;
-    }
-    return false;
-}
-
-void OSGetWindowSize(const void* context, int& width, int& height)
-{
-	OSWindowContext* ctx = (OSWindowContext*)context;
-	
-	
-    if(ctx)
-    {
-    	width=ctx->iNativeWindowType.iSize.iWidth;
-		height=ctx->iNativeWindowType.iSize.iHeight; 
-	}
-    else
-    {
-        width = 0;
-        height = 0;
-    }
-}
-
-
-EGLDisplay OSGetDisplay(EGLNativeDisplayType display_id)
-{
-    RI_UNREF(display_id);
-    return (EGLDisplay)1;    //support only a single display
-}
-
-
-void OSBlitToWindow(void* context, const Drawable* drawable)
-{
-	TUint w = drawable->getWidth();
-	TUint h = drawable->getHeight();
-    
-	OSWindowContext* ctx = (OSWindowContext*)context;
-    //blit if either of iBitmap or iMaskBitmap exist
-    if(ctx && ctx->iNativeWindowType.iBitmap)
-    {
-      
-        //these should be same as bitmap
-        if(ctx->iNativeWindowType.iBitmap)
-        	{
-        	CFbsBitmap* bitmap = ctx->iNativeWindowType.iBitmap;        	
-        	ReadPixelsToCFbsBitmap(*bitmap, w, h);        	
-        	}
-    }
-}
-
-void ReadPixelsToCFbsBitmap(CFbsBitmap& aBitmap, TUint aW, TUint aH)
-	{
-	TSize sz = aBitmap.SizeInPixels();
-	RI_ASSERT(aW==sz.iWidth);
-	RI_ASSERT(aH==sz.iHeight);
-	
-	VGImageFormat f = MapSymbianDisplayModeToVG(aBitmap.DisplayMode());
-	
-	TInt bitmapDataStride = aBitmap.DataStride();
-	
-	//copy from source OpenVG model to target(CFbsBitmap) buffer			
-	aBitmap.BeginDataAccess();
-	//openvg returns pixels in cartesian coordinates (y+) where as CFbsBitmap
-	//wants screen coordinates (y-) so we read pixels out starting at top left corner 
-	TUint8* ptarget = (TUint8*)aBitmap.DataAddress()+(aH-1)*bitmapDataStride;
-	
-	#ifdef BUILD_WITH_PRIVATE_OPENVG
-	//	do_vgReadPixels(ptarget, -bitmapDataStride, f, 0, 0, aW, aH);             //added by Jose.Need to remove the comments	
-	#else
-		vgReadPixels(ptarget, -bitmapDataStride, f, 0, 0, aW, aH);
-	#endif
-	
-	aBitmap.EndDataAccess(EFalse);
-	}
-
-VGImageFormat MapSymbianDisplayModeToVG(TDisplayMode aMode)
-	{
-	VGImageFormat f;
-	switch(aMode)
-		{
-		case EColor16MA:
-			f = VG_sARGB_8888;
-			break;
-		case EColor16MU:
-			f = VG_sRGBX_8888;
-			break;
-		case EColor64K:
-			f = VG_sRGB_565;
-			break;
-		case EGray256:
-			f = VG_A_8;
-			break;
-		case EGray2:
-			f = VG_BW_1;
-			break;
-		default:
-			RI_ASSERT(0);
-		}
-	return f;
-	}
-EGLBoolean OSGetNativePixmapInfo(NativePixmapType pixmap, int* width, int* height, int* stride, VGImageFormat* format, int** data)
-{
-	TSize size = ((CFbsBitmap*)pixmap)->SizeInPixels();
-    *width  = size.iWidth;
-    *height = size.iHeight;
-    *stride = ((CFbsBitmap*)pixmap)->DataStride();   
-   
-    *data = (int*)(((CFbsBitmap*)pixmap)->DataAddress());
-    TDisplayMode mode = ((CFbsBitmap*)pixmap)->DisplayMode(); 
-	switch(mode)
-	{
-	case EColor16MA:
-		*format = VG_sRGBA_8888;
-		break;
-	case EColor16MU:
-		*format = VG_sRGBX_8888;
-		break;
-	case EColor64K:
-		*format = VG_sRGB_565;
-		break;
-	case EGray256:
-		*format = VG_A_8;
-		break;
-	case EGray2:
-		*format = VG_BW_1;
-		break;
-	default:
-		RI_ASSERT(0);
-	}
-    return EGL_TRUE;
-}
-}   //namespace OpenVGRI
--- a/openvg/openvgrefimplementation/sfopenvg/group/vgi.mmp	Fri Jul 16 18:54:03 2010 +0100
+++ b/openvg/openvgrefimplementation/sfopenvg/group/vgi.mmp	Fri Sep 17 09:40:01 2010 +0100
@@ -37,11 +37,8 @@
 
 library         euser.lib     		// Mandatory
 
-#ifdef BUILD_WITH_PRIVATE_EGL
 library		libEGL.lib
-#else
-library		libegl_sw.lib
-#endif
+
 
 library			fbscli.lib
 
--- a/openvg/openvgrefimplementation/sfopenvg/sfopenvg/symbian/riEGLOS.cpp	Fri Jul 16 18:54:03 2010 +0100
+++ b/openvg/openvgrefimplementation/sfopenvg/sfopenvg/symbian/riEGLOS.cpp	Fri Sep 17 09:40:01 2010 +0100
@@ -86,7 +86,7 @@
 
 struct OSWindowContext
 {
-	TNativeWindowType*  iNativeWindowType;   
+	TNativeWindowType   iNativeWindowType;
 };
 
 void* OSCreateWindowContext(EGLNativeWindowType window)
@@ -100,11 +100,9 @@
 	{
 		return NULL;
 	}
-    ctx->iNativeWindowType = (TNativeWindowType*)window;
-    RWindow* win = (RWindow*) window;
-    TSize size = TSize(win->Size());
-    ctx->iNativeWindowType->iSize.iWidth = size.iWidth;
-    ctx->iNativeWindowType->iSize.iHeight = size.iHeight;
+	RDrawableWindow* drawableWindow = (RDrawableWindow*)window;
+	ctx->iNativeWindowType.iSize.iHeight = drawableWindow->Size().iHeight;
+	ctx->iNativeWindowType.iSize.iWidth = drawableWindow->Size().iWidth;
     return ctx;
 }
 
@@ -132,14 +130,8 @@
     OSWindowContext* ctx = (OSWindowContext*)context;
     if(ctx)
     {
-        if ( ctx->iNativeWindowType->iSize.iWidth < 360 )
-    	    ctx->iNativeWindowType->iSize.iWidth;
-        else
-          width= 360;//ctx->iNativeWindowType->iSize.iWidth;
-        if ( ctx->iNativeWindowType->iSize.iHeight < 640 )
-          ctx->iNativeWindowType->iSize.iHeight;
-		    else
-          height= 640; //ctx->iNativeWindowType->iSize.iHeight; 
+    	width=ctx->iNativeWindowType.iSize.iWidth;
+		height=ctx->iNativeWindowType.iSize.iHeight; 
     }
     else
     {
@@ -160,15 +152,15 @@
 {
     OSWindowContext* ctx = (OSWindowContext*)context;
     //blit if either of iBitmap or iMaskBitmap exist
-    if(ctx && ctx->iNativeWindowType->iBitmap)
+    if(ctx && ctx->iNativeWindowType.iBitmap)
     {
         TUint w = drawable->getWidth();
         TUint h = drawable->getHeight();
         
         //these should be same as bitmap
-        if(ctx->iNativeWindowType->iBitmap)
+        if(ctx->iNativeWindowType.iBitmap)
         	{
-        	CFbsBitmap* bitmap = ctx->iNativeWindowType->iBitmap;        	
+        	CFbsBitmap* bitmap = ctx->iNativeWindowType.iBitmap;        	
         	ReadPixelsToCFbsBitmap(*bitmap, w, h);        	
         	}
     }
--- a/openvg/openvgrefimplementation/sfopenvg/vgi/vgi.cpp	Fri Jul 16 18:54:03 2010 +0100
+++ b/openvg/openvgrefimplementation/sfopenvg/vgi/vgi.cpp	Fri Sep 17 09:40:01 2010 +0100
@@ -138,7 +138,7 @@
 		__ASSERT_ALWAYS(eglGetError() == EGL_SUCCESS,User::Invariant());
 		__ASSERT_ALWAYS(numconfigs == 1,User::Invariant());
 		
-		TSize maxSize(MAX_WIDTH,MAX_HEIGHT);
+		TSize maxSize(aSize.iWidth, aSize.iHeight);
 	    
 		egl.iPixmap = new(ELeave) CFbsBitmap();
 		egl.iPixmap->Create( maxSize, EColor16MA );
@@ -182,6 +182,7 @@
 	eglDestroySurface(egl.iEgldisplay, egl.iEglsurface);
 	delete egl.iPixmap;
 	ReleaseTls();
+	eglReleaseThread();
 }
 
 VGI_API_CALL TInt VGISymbianResize( TSize aSize )