Combine es2::Image and es1::Image into egl::Image.

Change-Id: Iadd4ce8ac36ad3458741f244423731fa00d7fd84
Reviewed-on: https://swiftshader-review.googlesource.com/2982
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
diff --git a/src/Android.mk b/src/Android.mk
index dbf2932..9695f3b 100644
--- a/src/Android.mk
+++ b/src/Android.mk
@@ -67,6 +67,7 @@
 
 LOCAL_SRC_FILES += \
 	OpenGL/common/AndroidCommon.cpp \
+	OpenGL/common/Image.cpp \
 	OpenGL/common/NameSpace.cpp \
 	OpenGL/common/Object.cpp \
 	OpenGL/common/MatrixStack.cpp \
diff --git a/src/OpenGL/common/AndroidCommon.hpp b/src/OpenGL/common/AndroidCommon.hpp
index 0d5f890..e02171d 100644
--- a/src/OpenGL/common/AndroidCommon.hpp
+++ b/src/OpenGL/common/AndroidCommon.hpp
@@ -1,6 +1,11 @@
 #ifndef ANDROID_COMMON
 #define ANDROID_COMMON
 
+namespace egl
+{
+class Image;
+}
+
 // Used internally
 GLenum getColorFormatFromAndroid(int format);
 
@@ -10,21 +15,4 @@
 // Used in V1 & V2 Context.cpp
 GLenum isSupportedAndroidBuffer(GLuint name);
 
-// Used in V1 & V2 Context.cpp
-template <typename I> I* wrapAndroidNativeWindow(GLuint name)
-{
-    ANativeWindowBuffer *nativeBuffer = reinterpret_cast<ANativeWindowBuffer*>(name);
-    ALOGV("%s: wrapping %p", __FUNCTION__, nativeBuffer);
-    nativeBuffer->common.incRef(&nativeBuffer->common);
-
-    GLenum format = getColorFormatFromAndroid(nativeBuffer->format);
-    GLenum type = getPixelFormatFromAndroid(nativeBuffer->format);
-
-    I *image = new I(0, nativeBuffer->width, nativeBuffer->height, format, type);
-    image->setNativeBuffer(nativeBuffer);
-    image->markShared();
-
-    return image;
-}
-
 #endif  // ANDROID_COMMON
diff --git a/src/OpenGL/libGLESv2/Image.cpp b/src/OpenGL/common/Image.cpp
similarity index 85%
rename from src/OpenGL/libGLESv2/Image.cpp
rename to src/OpenGL/common/Image.cpp
index f2e5c23..88c9b7a 100644
--- a/src/OpenGL/libGLESv2/Image.cpp
+++ b/src/OpenGL/common/Image.cpp
@@ -11,12 +11,16 @@
 
 #include "Image.hpp"
 
-#include "Texture.h"
-#include "utilities.h"
+#include "../libEGL/Texture.hpp"
 #include "../common/debug.h"
 #include "Common/Thread.hpp"
 
+#define GL_GLEXT_PROTOTYPES
+#include <GLES/glext.h>
 #include <GLES2/gl2ext.h>
+#include <GLES3/gl3.h>
+
+#include <string.h>
 
 namespace
 {
@@ -342,37 +346,99 @@
 	}
 }
 
-namespace es2
+namespace egl
 {
-	static sw::Resource *getParentResource(Texture *texture)
+	// Returns the size, in bytes, of a single texel in an Image
+	int ComputePixelSize(GLenum format, GLenum type)
 	{
-		if(texture)
+		switch(type)
 		{
-			return texture->getResource();
+		case GL_UNSIGNED_BYTE:
+			switch(format)
+			{
+			case GL_ALPHA:           return sizeof(unsigned char);
+			case GL_LUMINANCE:       return sizeof(unsigned char);
+			case GL_LUMINANCE_ALPHA: return sizeof(unsigned char) * 2;
+			case GL_RGB:             return sizeof(unsigned char) * 3;
+			case GL_RGBA:            return sizeof(unsigned char) * 4;
+			case GL_BGRA_EXT:        return sizeof(unsigned char) * 4;
+			default: UNREACHABLE();
+			}
+			break;
+		case GL_UNSIGNED_SHORT_4_4_4_4:
+		case GL_UNSIGNED_SHORT_5_5_5_1:
+		case GL_UNSIGNED_SHORT_5_6_5:
+		case GL_UNSIGNED_SHORT:
+			return sizeof(unsigned short);
+		case GL_UNSIGNED_INT:
+		case GL_UNSIGNED_INT_24_8_OES:
+			return sizeof(unsigned int);
+		case GL_FLOAT:
+			switch(format)
+			{
+			case GL_ALPHA:           return sizeof(float);
+			case GL_LUMINANCE:       return sizeof(float);
+			case GL_LUMINANCE_ALPHA: return sizeof(float) * 2;
+			case GL_RGB:             return sizeof(float) * 3;
+			case GL_RGBA:            return sizeof(float) * 4;
+			default: UNREACHABLE();
+			}
+			break;
+		case GL_HALF_FLOAT_OES:
+			switch(format)
+			{
+			case GL_ALPHA:           return sizeof(unsigned short);
+			case GL_LUMINANCE:       return sizeof(unsigned short);
+			case GL_LUMINANCE_ALPHA: return sizeof(unsigned short) * 2;
+			case GL_RGB:             return sizeof(unsigned short) * 3;
+			case GL_RGBA:            return sizeof(unsigned short) * 4;
+			default: UNREACHABLE();
+			}
+			break;
+		default: UNREACHABLE();
 		}
 
 		return 0;
 	}
 
-	Image::Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type)
-		: parentTexture(parentTexture)
-		, egl::Image(getParentResource(parentTexture), width, height, 1, format, type, selectInternalFormat(format, type))
+	GLsizei ComputePitch(GLsizei width, GLenum format, GLenum type, GLint alignment)
 	{
-		referenceCount = 1;
+		ASSERT(alignment > 0 && sw::isPow2(alignment));
+
+		GLsizei rawPitch = ComputePixelSize(format, type) * width;
+		return (rawPitch + alignment - 1) & ~(alignment - 1);
 	}
 
-	Image::Image(Texture *parentTexture, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type)
-		: parentTexture(parentTexture)
-		, egl::Image(getParentResource(parentTexture), width, height, depth, format, type, selectInternalFormat(format, type))
+
+	GLsizei ComputeCompressedPitch(GLsizei width, GLenum format)
 	{
-		referenceCount = 1;
+		return ComputeCompressedSize(width, 1, format);
 	}
 
-	Image::Image(Texture *parentTexture, GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable, bool renderTarget)
-		: parentTexture(parentTexture)
-		, egl::Image(getParentResource(parentTexture), width, height, multiSampleDepth, internalFormat, lockable, renderTarget)
+	GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format)
 	{
-		referenceCount = 1;
+		switch(format)
+		{
+		case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
+		case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
+        case GL_ETC1_RGB8_OES:
+		case GL_COMPRESSED_R11_EAC:
+		case GL_COMPRESSED_SIGNED_R11_EAC:
+		case GL_COMPRESSED_RGB8_ETC2:
+		case GL_COMPRESSED_SRGB8_ETC2:
+		case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
+		case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
+			return 8 * (GLsizei)ceil((float)width / 4.0f) * (GLsizei)ceil((float)height / 4.0f);
+		case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
+		case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
+		case GL_COMPRESSED_RG11_EAC:
+		case GL_COMPRESSED_SIGNED_RG11_EAC:
+		case GL_COMPRESSED_RGBA8_ETC2_EAC:
+		case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
+			return 16 * (GLsizei)ceil((float)width / 4.0f) * (GLsizei)ceil((float)height / 4.0f);
+		default:
+			return 0;
+		}
 	}
 
 	Image::~Image()
@@ -572,6 +638,7 @@
 			case GL_FLOAT:
 				switch(format)
 				{
+				// float textures are converted to RGBA, not BGRA
 				case GL_ALPHA:
 					LoadImageData<AlphaFloat>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, getPitch(), getHeight(), input, buffer);
 					break;
diff --git a/src/OpenGL/common/Image.hpp b/src/OpenGL/common/Image.hpp
new file mode 100644
index 0000000..7ab29cd
--- /dev/null
+++ b/src/OpenGL/common/Image.hpp
@@ -0,0 +1,251 @@
+#ifndef egl_Image_hpp

+#define egl_Image_hpp

+

+#include "libEGL/Texture.hpp"

+#include "Renderer/Surface.hpp"

+

+#define GL_API

+#define GL_APICALL

+#include <GLES/gl.h>

+#include <GLES2/gl2.h>

+

+#if defined(__ANDROID__)

+#include <hardware/gralloc.h>

+#include <system/window.h>

+#include "../../Common/GrallocAndroid.hpp"

+#include "../common/AndroidCommon.hpp"

+#endif

+

+#ifdef __ANDROID__

+#include "../../Common/DebugAndroid.hpp"

+#else

+#include <assert.h>

+#endif

+

+namespace egl

+{

+// Types common between gl.h and gl2.h

+// We can't include either header in EGL

+typedef unsigned int GLenum;

+typedef int GLint;

+typedef int GLsizei;

+

+int ComputePixelSize(GLenum format, GLenum type);

+GLsizei ComputePitch(GLsizei width, GLenum format, GLenum type, GLint alignment);

+GLsizei ComputeCompressedPitch(GLsizei width, GLenum format);

+GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format);

+

+static inline sw::Resource *getParentResource(egl::Texture *texture)

+{

+	if (texture)

+	{

+		return texture->getResource();

+	}

+	return 0;

+}

+

+class Image : public sw::Surface

+{

+public:

+	Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type)

+			: sw::Surface(getParentResource(parentTexture), width, height, 1, selectInternalFormat(format, type), true, true),

+			  width(width), height(height), format(format), type(type), internalFormat(selectInternalFormat(format, type)), depth(1),

+			  parentTexture(parentTexture)

+	{

+		shared = false;

+		referenceCount = 1;

+	}

+

+	Image(Texture *parentTexture, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type)

+			: sw::Surface(getParentResource(parentTexture), width, height, depth, selectInternalFormat(format, type), true, true),

+			  width(width), height(height), format(format), type(type), internalFormat(selectInternalFormat(format, type)), depth(depth),

+			  parentTexture(parentTexture)

+	{

+		shared = false;

+		referenceCount = 1;

+	}

+

+	Image(Texture *parentTexture, GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable, bool renderTarget)

+			: sw::Surface(getParentResource(parentTexture), width, height, multiSampleDepth, internalFormat, lockable, renderTarget),

+			  width(width), height(height), format(0 /*GL_NONE*/), type(0 /*GL_NONE*/), internalFormat(internalFormat), depth(multiSampleDepth), parentTexture(parentTexture)

+	{

+		shared = false;

+		referenceCount = 1;

+	}

+

+	GLsizei getWidth() const

+	{

+		return width;

+	}

+

+	GLsizei getHeight() const

+	{

+		return height;

+	}

+

+	int getDepth() const

+	{

+		// FIXME: add member if the depth dimension (for 3D textures or 2D testure arrays)

+		// and multi sample depth are ever simultaneously required.

+		return depth;

+	}

+

+	GLenum getFormat() const

+	{

+		return format;

+	}

+

+	GLenum getType() const

+	{

+		return type;

+	}

+

+	sw::Format getInternalFormat() const

+	{

+		return internalFormat;

+	}

+

+	bool isShared() const

+    {

+        return shared;

+    }

+

+    void markShared()

+    {

+        shared = true;

+    }

+

+	virtual void *lock(unsigned int left, unsigned int top, sw::Lock lock)

+	{

+		return lockExternal(left, top, 0, lock, sw::PUBLIC);

+	}

+

+	unsigned int getPitch() const

+	{

+		return getExternalPitchB();

+	}

+

+	virtual void unlock()

+	{

+		unlockExternal();

+	}

+

+	void loadImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint unpackAlignment, const void *input);

+	void loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);

+

+	static sw::Format selectInternalFormat(GLenum format, GLenum type);

+

+	virtual void addRef();

+	virtual void release();

+	virtual void unbind(const Texture *parent);   // Break parent ownership and release

+

+	virtual void destroyShared()   // Release a shared image

+	{

+		assert(shared);

+		shared = false;

+		release();

+	}

+

+

+protected:

+	const GLsizei width;

+	const GLsizei height;

+	const GLenum format;

+	const GLenum type;

+	const sw::Format internalFormat;

+	const int depth;

+

+	bool shared;   // Used as an EGLImage

+

+	egl::Texture *parentTexture;

+

+	volatile int referenceCount;

+

+	virtual ~Image();

+

+	void loadD24S8ImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, int inputPitch, const void *input, void *buffer);

+};

+

+#ifdef __ANDROID__

+

+class AndroidNativeImage : public egl::Image

+{

+public:

+	explicit AndroidNativeImage(ANativeWindowBuffer *nativeBuffer)

+		: egl::Image(0, nativeBuffer->width, nativeBuffer->height, 1,

+					getColorFormatFromAndroid(nativeBuffer->format),

+					getPixelFormatFromAndroid(nativeBuffer->format)),

+		  nativeBuffer(nativeBuffer)

+{

+    nativeBuffer->common.incRef(&nativeBuffer->common);

+    markShared();

+}

+

+private:

+	ANativeWindowBuffer *nativeBuffer;

+

+	virtual ~AndroidNativeImage() { }

+

+	void setNativeBuffer(ANativeWindowBuffer* buffer)

+	{

+		nativeBuffer = buffer;

+		nativeBuffer->common.incRef(&nativeBuffer->common);

+	}

+

+	virtual void *lockInternal(int x, int y, int z, sw::Lock lock, sw::Accessor client)

+	{

+		if(nativeBuffer)   // Lock the buffer from ANativeWindowBuffer

+		{

+			return lockNativeBuffer(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);

+		}

+		return sw::Surface::lockInternal(x, y, z, lock, client);

+	}

+

+	virtual void unlockInternal()

+	{

+		if(nativeBuffer)   // Unlock the buffer from ANativeWindowBuffer

+		{

+			return unlockNativeBuffer();

+		}

+		return sw::Surface::unlockInternal();

+	}

+

+	virtual void *lock(unsigned int /*left*/, unsigned int /*top*/, sw::Lock /*lock*/)

+	{

+		return lockNativeBuffer(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);

+	}

+

+	virtual void unlock()

+	{

+		unlockNativeBuffer();

+	}

+

+	void* lockNativeBuffer(int usage)

+	{

+		void *buffer = 0;

+		GrallocModule::getInstance()->lock(

+			nativeBuffer->handle, usage, 0, 0,

+			nativeBuffer->width, nativeBuffer->height, &buffer);

+		return buffer;

+	}

+

+	void unlockNativeBuffer()

+	{

+		GrallocModule::getInstance()->unlock(nativeBuffer->handle);

+	}

+

+	virtual void destroyShared()   // Release a shared image

+	{

+		if(nativeBuffer)

+		{

+			nativeBuffer->common.decRef(&nativeBuffer->common);

+		}

+		egl::Image::destroyShared();

+	}

+};

+

+#endif  // __ANDROID__

+

+}

+

+#endif   // egl_Image_hpp

diff --git a/src/OpenGL/libEGL/Android.mk b/src/OpenGL/libEGL/Android.mk
index 2057c40..08793af 100644
--- a/src/OpenGL/libEGL/Android.mk
+++ b/src/OpenGL/libEGL/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_STATIC_LIBRARIES += swiftshader_top libgceframebufferconfig libgcemetadata
 LOCAL_C_INCLUDES += device/google/gce/include
 
-LOCAL_SHARED_LIBRARIES += libdl liblog libandroid libutils libcutils $(GCE_STLPORT_LIBS)
+LOCAL_SHARED_LIBRARIES += libdl liblog libandroid libutils libcutils libhardware  $(GCE_STLPORT_LIBS)
 LOCAL_LDFLAGS += -Wl,--version-script=$(LOCAL_PATH)/exports.map -Wl,--hash-style=sysv
 
 LOCAL_C_INCLUDES += \
diff --git a/src/OpenGL/libEGL/Image.hpp b/src/OpenGL/libEGL/Image.hpp
deleted file mode 100644
index f96402c..0000000
--- a/src/OpenGL/libEGL/Image.hpp
+++ /dev/null
@@ -1,205 +0,0 @@
-#ifndef egl_Image_hpp

-#define egl_Image_hpp

-

-#include "Renderer/Surface.hpp"

-

-#if defined(__ANDROID__)

-#include <hardware/gralloc.h>

-#include <system/window.h>

-#include "../../Common/GrallocAndroid.hpp"

-#endif

-

-#ifdef __ANDROID__

-#include "../../Common/DebugAndroid.hpp"

-#else

-#include <assert.h>

-#endif

-

-namespace egl

-{

-// Types common between gl.h and gl2.h

-// We can't include either header in EGL

-typedef unsigned int GLenum;

-typedef int GLint;

-typedef int GLsizei;

-

-class Texture;

-

-class Image : public sw::Surface

-{

-public:

-	Image(sw::Resource *resource, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, sw::Format internalFormat)

-		: sw::Surface(resource, width, height, depth, internalFormat, true, true),

-		  width(width), height(height), format(format), type(type), internalFormat(internalFormat), depth(depth)

-	{

-		shared = false;

-

-		#if defined(__ANDROID__)

-			nativeBuffer = 0;

-		#endif

-	}

-

-	Image(sw::Resource *resource, int width, int height, int depth, sw::Format internalFormat, bool lockable, bool renderTarget)

-		: sw::Surface(resource, width, height, depth, internalFormat, lockable, renderTarget),

-		  width(width), height(height), format(0 /*GL_NONE*/), type(0 /*GL_NONE*/), internalFormat(internalFormat), depth(depth)

-	{

-		shared = false;

-

-		#if defined(__ANDROID__)

-			nativeBuffer = 0;

-		#endif

-	}

-

-	GLsizei getWidth() const

-	{

-		return width;

-	}

-

-	GLsizei getHeight() const

-	{

-		return height;

-	}

-

-	int getDepth() const

-	{

-		// FIXME: add member if the depth dimension (for 3D textures or 2D testure arrays)

-		// and multi sample depth are ever simultaneously required.

-		return depth;

-	}

-

-	GLenum getFormat() const

-	{

-		return format;

-	}

-

-	GLenum getType() const

-	{

-		return type;

-	}

-

-	sw::Format getInternalFormat() const

-	{

-		return internalFormat;

-	}

-

-	bool isShared() const

-    {

-        return shared;

-    }

-

-    void markShared()

-    {

-        shared = true;

-    }

-

-	void *lock(unsigned int left, unsigned int top, sw::Lock lock)

-	{

-		#if defined(__ANDROID__)

-			if(nativeBuffer)   // Lock the buffer from ANativeWindowBuffer

-			{

-				return lockNativeBuffer(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);

-			}

-		#endif

-

-		return lockExternal(left, top, 0, lock, sw::PUBLIC);

-	}

-

-	unsigned int getPitch() const

-	{

-		return getExternalPitchB();

-	}

-

-	void unlock()

-	{

-		#if defined(__ANDROID__)

-			if(nativeBuffer)   // Unlock the buffer from ANativeWindowBuffer

-			{

-				return unlockNativeBuffer();

-			}

-		#endif

-

-		unlockExternal();

-	}

-

-	virtual void addRef() = 0;

-	virtual void release() = 0;

-	virtual void unbind(const Texture *parent) = 0;   // Break parent ownership and release

-

-	void destroyShared()   // Release a shared image

-	{

-		#if defined(__ANDROID__)

-			if(nativeBuffer)

-			{

-				nativeBuffer->common.decRef(&nativeBuffer->common);

-			}

-		#endif

-

-		assert(shared);

-		shared = false;

-		release();

-	}

-

-	virtual void loadImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint unpackAlignment, const void *input) = 0;

-	virtual void loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels) = 0;

-

-	#if defined(__ANDROID__)

-	void setNativeBuffer(ANativeWindowBuffer* buffer)

-	{

-		nativeBuffer = buffer;

-		nativeBuffer->common.incRef(&nativeBuffer->common);

-	}

-

-	virtual void *lockInternal(int x, int y, int z, sw::Lock lock, sw::Accessor client)

-	{

-		if(nativeBuffer)   // Lock the buffer from ANativeWindowBuffer

-		{

-			return lockNativeBuffer(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);

-		}

-		return sw::Surface::lockInternal(x, y, z, lock, client);

-	}

-

-	virtual void unlockInternal()

-	{

-		if(nativeBuffer)   // Unlock the buffer from ANativeWindowBuffer

-		{

-			return unlockNativeBuffer();

-		}

-		return sw::Surface::unlockInternal();

-	}

-	#endif

-

-protected:

-	virtual ~Image()

-	{

-	}

-

-	const GLsizei width;

-	const GLsizei height;

-	const GLenum format;

-	const GLenum type;

-	const sw::Format internalFormat;

-	const int depth;

-

-	bool shared;   // Used as an EGLImage

-

-	#if defined(__ANDROID__)

-	ANativeWindowBuffer *nativeBuffer;

-

-	void* lockNativeBuffer(int usage)

-	{

-		void *buffer = 0;

-		GrallocModule::getInstance()->lock(

-			nativeBuffer->handle, usage, 0, 0,

-			nativeBuffer->width, nativeBuffer->height, &buffer);

-		return buffer;

-	}

-

-	void unlockNativeBuffer()

-	{

-		GrallocModule::getInstance()->unlock(nativeBuffer->handle);

-	}

-	#endif

-};

-}

-

-#endif   // egl_Image_hpp

diff --git a/src/OpenGL/libEGL/Surface.cpp b/src/OpenGL/libEGL/Surface.cpp
index 17e8586..333ba4f 100644
--- a/src/OpenGL/libEGL/Surface.cpp
+++ b/src/OpenGL/libEGL/Surface.cpp
@@ -18,7 +18,7 @@
 #include "main.h"

 #include "Display.h"

 #include "Texture.hpp"

-#include "Image.hpp"

+#include "common/Image.hpp"

 #include "Context.hpp"

 #include "common/debug.h"

 #include "Main/FrameBuffer.hpp"

diff --git a/src/OpenGL/libEGL/Texture.hpp b/src/OpenGL/libEGL/Texture.hpp
index 958a595..6d6e22b 100644
--- a/src/OpenGL/libEGL/Texture.hpp
+++ b/src/OpenGL/libEGL/Texture.hpp
@@ -3,6 +3,11 @@
 

 #include "common/Object.hpp"

 

+namespace sw

+{

+	class Resource;

+}

+

 namespace egl

 {

 class Texture : public gl::NamedObject

@@ -10,6 +15,7 @@
 public:

 	Texture(GLuint name) : NamedObject(name) {};

 	virtual void releaseTexImage() = 0;

+	virtual sw::Resource *getResource() const = 0;

 };

 }

 

diff --git a/src/OpenGL/libEGL/libEGL.cbp b/src/OpenGL/libEGL/libEGL.cbp
index 16c273f..746ac6f 100644
--- a/src/OpenGL/libEGL/libEGL.cbp
+++ b/src/OpenGL/libEGL/libEGL.cbp
@@ -122,7 +122,6 @@
 		<Unit filename="Config.h" />
 		<Unit filename="Display.cpp" />
 		<Unit filename="Display.h" />
-		<Unit filename="Image.hpp" />
 		<Unit filename="Surface.cpp" />
 		<Unit filename="Surface.h" />
 		<Unit filename="exports.map" />
diff --git a/src/OpenGL/libEGL/libEGL.cpp b/src/OpenGL/libEGL/libEGL.cpp
index f7befcf..ffd4c5a 100644
--- a/src/OpenGL/libEGL/libEGL.cpp
+++ b/src/OpenGL/libEGL/libEGL.cpp
@@ -16,7 +16,7 @@
 #include "Surface.h"

 #include "Texture.hpp"

 #include "Context.hpp"

-#include "Image.hpp"

+#include "common/Image.hpp"

 #include "common/debug.h"

 #include "Common/Version.h"

 

@@ -887,9 +887,7 @@
 	#if defined(__ANDROID__)

 		if(target == EGL_NATIVE_BUFFER_ANDROID)

 		{

-			// When target is EGL_NATIVE_BUFFER_ANDROID, ctx is always EGL_NO_CONTEXT.

-			// Get the current context so that we can validate and create shared image

-			context = static_cast<egl::Context*>(egl::getCurrentContext());

+			return new AndroidNativeImage(reinterpret_cast<ANativeWindowBuffer*>(name));

 		}

 	#endif

 

diff --git a/src/OpenGL/libGLES_CM/Android.mk b/src/OpenGL/libGLES_CM/Android.mk
index 8f96378..7f95ac4 100644
--- a/src/OpenGL/libGLES_CM/Android.mk
+++ b/src/OpenGL/libGLES_CM/Android.mk
@@ -11,7 +11,6 @@
 	Context.cpp \
 	Device.cpp \
 	Framebuffer.cpp \
-	Image.cpp \
 	IndexDataManager.cpp \
 	libGLES_CM.cpp \
 	main.cpp \
diff --git a/src/OpenGL/libGLES_CM/Context.cpp b/src/OpenGL/libGLES_CM/Context.cpp
index 403cb20..dd21ff5 100644
--- a/src/OpenGL/libGLES_CM/Context.cpp
+++ b/src/OpenGL/libGLES_CM/Context.cpp
@@ -30,10 +30,6 @@
 

 #include <EGL/eglext.h>

 

-#ifdef __ANDROID__

-	#include "../common/AndroidCommon.hpp"

-#endif  // __ANDROID__

-

 #undef near

 #undef far

 

@@ -1920,7 +1916,7 @@
 		}

 	}

 

-	GLsizei outputPitch = ComputePitch(width, format, type, mState.packAlignment);

+	GLsizei outputPitch = egl::ComputePitch(width, format, type, mState.packAlignment);

 

 	// Sized query sanity check

     if(bufSize)

@@ -2585,10 +2581,6 @@
         break;

     case EGL_GL_RENDERBUFFER_KHR:

         break;

-    #if defined(__ANDROID__)

-    case EGL_NATIVE_BUFFER_ANDROID:

-        break;

-    #endif

     default:

         return EGL_BAD_PARAMETER;

     }

@@ -2636,12 +2628,6 @@
             return EGL_BAD_ACCESS;

         }

     }

-    #if defined(__ANDROID__)

-    else if(target == EGL_NATIVE_BUFFER_ANDROID)

-    {

-		return isSupportedAndroidBuffer(name);

-    }

-    #endif

     else UNREACHABLE();

 

 	return EGL_SUCCESS;

@@ -2661,12 +2647,6 @@
 

         return renderbuffer->createSharedImage();

     }

-    #if defined(__ANDROID__)

-    else if(target == EGL_NATIVE_BUFFER_ANDROID)

-    {

-		return wrapAndroidNativeWindow<es1::Image>(name);

-    }

-    #endif

     else UNREACHABLE();

 

 	return 0;

diff --git a/src/OpenGL/libGLES_CM/Context.h b/src/OpenGL/libGLES_CM/Context.h
index 387c527..5d6209d 100644
--- a/src/OpenGL/libGLES_CM/Context.h
+++ b/src/OpenGL/libGLES_CM/Context.h
@@ -19,7 +19,7 @@
 #include "ResourceManager.h"

 #include "common/NameSpace.hpp"

 #include "common/Object.hpp"

-#include "Image.hpp"

+#include "common/Image.hpp"

 #include "Renderer/Sampler.hpp"

 #include "common/MatrixStack.hpp"

 

diff --git a/src/OpenGL/libGLES_CM/Device.cpp b/src/OpenGL/libGLES_CM/Device.cpp
index 6aab251..57667ab 100644
--- a/src/OpenGL/libGLES_CM/Device.cpp
+++ b/src/OpenGL/libGLES_CM/Device.cpp
@@ -11,7 +11,7 @@
 

 #include "Device.hpp"

 

-#include "Image.hpp"

+#include "common/Image.hpp"

 #include "Texture.h"

 

 #include "Renderer/Renderer.hpp"

@@ -209,7 +209,7 @@
 		depthStencil->clearStencilBuffer(stencil, mask, x0, y0, width, height);

 	}

 

-	Image *Device::createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard)

+	egl::Image *Device::createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard)

 	{

 		if(width == 0 || height == 0 || height > OUTLINE_RESOLUTION)

 		{

@@ -242,7 +242,7 @@
 			UNREACHABLE();

 		}

 

-		Image *surface = new Image(0, width, height, format, multiSampleDepth, lockable, true);

+		egl::Image *surface = new egl::Image(0, width, height, format, multiSampleDepth, lockable, true);

 

 		if(!surface)

 		{

@@ -253,7 +253,7 @@
 		return surface;

 	}

 

-	Image *Device::createRenderTarget(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool lockable)

+	egl::Image *Device::createRenderTarget(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool lockable)

 	{

 		if(height > OUTLINE_RESOLUTION)

 		{

@@ -261,7 +261,7 @@
 			return 0;

 		}

 

-		Image *surface = new Image(0, width, height, format, multiSampleDepth, lockable, true);

+		egl::Image *surface = new egl::Image(0, width, height, format, multiSampleDepth, lockable, true);

 

 		if(!surface)

 		{

@@ -450,7 +450,7 @@
 

 		bool scaling = (sRect.x1 - sRect.x0 != dRect.x1 - dRect.x0) || (sRect.y1 - sRect.y0 != dRect.y1 - dRect.y0);

 		bool equalFormats = source->getInternalFormat() == dest->getInternalFormat();

-		bool depthStencil = Image::isDepth(source->getInternalFormat()) || Image::isStencil(source->getInternalFormat());

+		bool depthStencil = egl::Image::isDepth(source->getInternalFormat()) || egl::Image::isStencil(source->getInternalFormat());

 		bool alpha0xFF = false;

 

 		if((source->getInternalFormat() == FORMAT_A8R8G8B8 && dest->getInternalFormat() == FORMAT_X8R8G8B8) ||

@@ -513,7 +513,7 @@
 

 			unsigned int width = dRect.x1 - dRect.x0;

 			unsigned int height = dRect.y1 - dRect.y0;

-			unsigned int bytes = width * Image::bytes(source->getInternalFormat());

+			unsigned int bytes = width * egl::Image::bytes(source->getInternalFormat());

 

 			for(unsigned int y = 0; y < height; y++)

 			{

diff --git a/src/OpenGL/libGLES_CM/Device.hpp b/src/OpenGL/libGLES_CM/Device.hpp
index 8790154..75845b8 100644
--- a/src/OpenGL/libGLES_CM/Device.hpp
+++ b/src/OpenGL/libGLES_CM/Device.hpp
@@ -22,7 +22,6 @@
 namespace es1

 {

 	class Texture;

-	class Image;

 

 	enum PrimitiveType

 	{

@@ -55,8 +54,8 @@
 		virtual void clearColor(unsigned int color, unsigned int rgbaMask);

 		virtual void clearDepth(float z);

 		virtual void clearStencil(unsigned int stencil, unsigned int mask);

-		virtual Image *createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard);

-		virtual Image *createRenderTarget(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool lockable);

+		virtual egl::Image *createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard);

+		virtual egl::Image *createRenderTarget(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool lockable);

 		virtual void drawIndexedPrimitive(PrimitiveType type, unsigned int indexOffset, unsigned int primitiveCount, int indexSize);

 		virtual void drawPrimitive(PrimitiveType primitiveType, unsigned int primiveCount);

 		virtual void setDepthStencilSurface(egl::Image *newDepthStencil);

diff --git a/src/OpenGL/libGLES_CM/Framebuffer.h b/src/OpenGL/libGLES_CM/Framebuffer.h
index fc10515..99e9c96 100644
--- a/src/OpenGL/libGLES_CM/Framebuffer.h
+++ b/src/OpenGL/libGLES_CM/Framebuffer.h
@@ -16,7 +16,7 @@
 #define LIBGLES_CM_FRAMEBUFFER_H_

 

 #include "common/Object.hpp"

-#include "Image.hpp"

+#include "common/Image.hpp"

 

 #define GL_API

 #include <GLES/gl.h>

diff --git a/src/OpenGL/libGLES_CM/Image.cpp b/src/OpenGL/libGLES_CM/Image.cpp
deleted file mode 100644
index c68ec5c..0000000
--- a/src/OpenGL/libGLES_CM/Image.cpp
+++ /dev/null
@@ -1,534 +0,0 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2013 TransGaming Inc.
-//
-// All rights reserved. No part of this software may be copied, distributed, transmitted,
-// transcribed, stored in a retrieval system, translated into any human or computer
-// language by any means, or disclosed to third parties without the explicit written
-// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
-//
-
-#include "Image.hpp"
-
-#include "Texture.h"
-#include "utilities.h"
-#include "../common/debug.h"
-#include "Common/Thread.hpp"
-
-#define GL_GLEXT_PROTOTYPES
-#include <GLES/glext.h>
-
-namespace es1
-{
-	static sw::Resource *getParentResource(Texture *texture)
-	{
-		if(texture)
-		{
-			return texture->getResource();
-		}
-
-		return 0;
-	}
-
-	Image::Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type)
-		: parentTexture(parentTexture)
-		, egl::Image(getParentResource(parentTexture), width, height, 1, format, type, selectInternalFormat(format, type))
-	{
-		referenceCount = 1;
-	}
-
-	Image::Image(Texture *parentTexture, GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable, bool renderTarget)
-		: parentTexture(parentTexture)
-		, egl::Image(getParentResource(parentTexture), width, height, multiSampleDepth, internalFormat, lockable, renderTarget)
-	{
-		referenceCount = 1;
-	}
-
-	Image::~Image()
-	{
-		ASSERT(referenceCount == 0);
-	}
-
-	void Image::addRef()
-	{
-		if(parentTexture)
-		{
-			return parentTexture->addRef();
-		}
-
-		sw::atomicIncrement(&referenceCount);
-	}
-
-	void Image::release()
-	{
-		if(parentTexture)
-		{
-			return parentTexture->release();
-		}
-
-		if(referenceCount > 0)
-		{
-			sw::atomicDecrement(&referenceCount);
-		}
-
-		if(referenceCount == 0)
-		{
-			ASSERT(!shared);   // Should still hold a reference if eglDestroyImage hasn't been called
-			delete this;
-		}
-	}
-
-	void Image::unbind(const egl::Texture *parent)
-	{
-		if(parentTexture == parent)
-		{
-			parentTexture = 0;
-		}
-
-		release();
-	}
-
-	sw::Format Image::selectInternalFormat(GLenum format, GLenum type)
-	{
-		if(format == GL_ETC1_RGB8_OES)
-		{
-			return sw::FORMAT_ETC1;
-		}
-		else
-		#if S3TC_SUPPORT
-		if(format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ||
-		   format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT)
-		{
-			return sw::FORMAT_DXT1;
-		}
-		else
-		#endif
-		if(type == GL_FLOAT)
-		{
-			return sw::FORMAT_A32B32G32R32F;
-		}
-		else if(type == GL_UNSIGNED_BYTE)
-		{
-			if(format == GL_LUMINANCE)
-			{
-				return sw::FORMAT_L8;
-			}
-			else if(format == GL_LUMINANCE_ALPHA)
-			{
-				return sw::FORMAT_A8L8;
-			}
-			else if(format == GL_RGBA)
-			{
-				return sw::FORMAT_A8B8G8R8;
-			}
-			else if(format == GL_BGRA_EXT)
-			{
-				return sw::FORMAT_A8R8G8B8;
-			}
-			else if(format == GL_RGB)
-			{
-				return sw::FORMAT_X8B8G8R8;
-			}
-			else if(format == GL_ALPHA)
-			{
-				return sw::FORMAT_A8;
-			}
-			else UNREACHABLE();
-		}
-		else if(type == GL_UNSIGNED_INT_24_8_OES)
-		{
-			if(format == GL_DEPTH_STENCIL_OES)
-			{
-				return sw::FORMAT_D32FS8_TEXTURE;
-			}
-			else UNREACHABLE();
-		}
-		else if(type == GL_UNSIGNED_SHORT_4_4_4_4)
-		{
-			return sw::FORMAT_A8R8G8B8;
-		}
-		else if(type == GL_UNSIGNED_SHORT_5_5_5_1)
-		{
-			return sw::FORMAT_A8R8G8B8;
-		}
-		else if(type == GL_UNSIGNED_SHORT_5_6_5)
-		{
-			return sw::FORMAT_X8R8G8B8;
-		}
-		else UNREACHABLE();
-
-		return sw::FORMAT_A8B8G8R8;
-	}
-
-	void Image::loadImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint unpackAlignment, const void *input)
-	{
-		ASSERT(zoffset == 0 && depth == 1);
-
-		GLsizei inputPitch = ComputePitch(width, format, type, unpackAlignment);
-		void *buffer = lock(0, 0, sw::LOCK_WRITEONLY);
-
-		if(buffer)
-		{
-			switch(type)
-			{
-			case GL_UNSIGNED_BYTE:
-				switch(format)
-				{
-				case GL_ALPHA:
-					loadAlphaImageData(xoffset, yoffset, width, height, inputPitch, input, buffer);
-					break;
-				case GL_LUMINANCE:
-					loadLuminanceImageData(xoffset, yoffset, width, height, inputPitch, input, buffer);
-					break;
-				case GL_LUMINANCE_ALPHA:
-					loadLuminanceAlphaImageData(xoffset, yoffset, width, height, inputPitch, input, buffer);
-					break;
-				case GL_RGB:
-					loadRGBUByteImageData(xoffset, yoffset, width, height, inputPitch, input, buffer);
-					break;
-				case GL_RGBA:
-				case GL_BGRA_EXT:
-					loadRGBAUByteImageData(xoffset, yoffset, width, height, inputPitch, input, buffer);
-					break;
-				default: UNREACHABLE();
-				}
-				break;
-			case GL_UNSIGNED_SHORT_5_6_5:
-				switch(format)
-				{
-				case GL_RGB:
-					loadRGB565ImageData(xoffset, yoffset, width, height, inputPitch, input, buffer);
-					break;
-				default: UNREACHABLE();
-				}
-				break;
-			case GL_UNSIGNED_SHORT_4_4_4_4:
-				switch(format)
-				{
-				case GL_RGBA:
-					loadRGBA4444ImageData(xoffset, yoffset, width, height, inputPitch, input, buffer);
-					break;
-				default: UNREACHABLE();
-				}
-				break;
-			case GL_UNSIGNED_SHORT_5_5_5_1:
-				switch(format)
-				{
-				case GL_RGBA:
-					loadRGBA5551ImageData(xoffset, yoffset, width, height, inputPitch, input, buffer);
-					break;
-				default: UNREACHABLE();
-				}
-				break;
-			case GL_FLOAT:
-				switch(format)
-				{
-				// float textures are converted to RGBA, not BGRA
-				case GL_ALPHA:
-					loadAlphaFloatImageData(xoffset, yoffset, width, height, inputPitch, input, buffer);
-					break;
-				case GL_LUMINANCE:
-					loadLuminanceFloatImageData(xoffset, yoffset, width, height, inputPitch, input, buffer);
-					break;
-				case GL_LUMINANCE_ALPHA:
-					loadLuminanceAlphaFloatImageData(xoffset, yoffset, width, height, inputPitch, input, buffer);
-					break;
-				case GL_RGB:
-					loadRGBFloatImageData(xoffset, yoffset, width, height, inputPitch, input, buffer);
-					break;
-				case GL_RGBA:
-					loadRGBAFloatImageData(xoffset, yoffset, width, height, inputPitch, input, buffer);
-					break;
-				default: UNREACHABLE();
-				}
-				break;
-			case GL_UNSIGNED_SHORT:
-				loadD16ImageData(xoffset, yoffset, width, height, inputPitch, input, buffer);
-				break;
-			case GL_UNSIGNED_INT:
-				loadD32ImageData(xoffset, yoffset, width, height, inputPitch, input, buffer);
-				break;
-			case GL_UNSIGNED_INT_24_8_OES:
-				loadD24S8ImageData(xoffset, yoffset, width, height, inputPitch, input, buffer);
-				break;
-			default: UNREACHABLE();
-			}
-		}
-
-		unlock();
-	}
-
-	void Image::loadAlphaImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
-	{
-		for(int y = 0; y < height; y++)
-		{
-			const unsigned char *source = static_cast<const unsigned char*>(input) + y * inputPitch;
-			unsigned char *dest = static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset;
-
-			memcpy(dest, source, width);
-		}
-	}
-
-	void Image::loadAlphaFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
-	{
-		for(int y = 0; y < height; y++)
-		{
-			const float *source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch);
-			float *dest = reinterpret_cast<float*>(static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 16);
-
-			for(int x = 0; x < width; x++)
-			{
-				dest[4 * x + 0] = 0;
-				dest[4 * x + 1] = 0;
-				dest[4 * x + 2] = 0;
-				dest[4 * x + 3] = source[x];
-			}
-		}
-	}
-
-	void Image::loadLuminanceImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
-	{
-		for(int y = 0; y < height; y++)
-		{
-			const unsigned char *source = static_cast<const unsigned char*>(input) + y * inputPitch;
-			unsigned char *dest = static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset;
-
-			memcpy(dest, source, width);
-		}
-	}
-
-	void Image::loadLuminanceFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
-	{
-		for(int y = 0; y < height; y++)
-		{
-			const float *source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch);
-			float *dest = reinterpret_cast<float*>(static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 16);
-
-			for(int x = 0; x < width; x++)
-			{
-				dest[4 * x + 0] = source[x];
-				dest[4 * x + 1] = source[x];
-				dest[4 * x + 2] = source[x];
-				dest[4 * x + 3] = 1.0f;
-			}
-		}
-	}
-
-	void Image::loadLuminanceAlphaImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
-	{
-		for(int y = 0; y < height; y++)
-		{
-			const unsigned char *source = static_cast<const unsigned char*>(input) + y * inputPitch;
-			unsigned char *dest = static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 2;
-
-			memcpy(dest, source, width * 2);
-		}
-	}
-
-	void Image::loadLuminanceAlphaFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
-	{
-		for(int y = 0; y < height; y++)
-		{
-			const float *source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch);
-			float *dest = reinterpret_cast<float*>(static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 16);
-
-			for(int x = 0; x < width; x++)
-			{
-				dest[4 * x + 0] = source[2*x+0];
-				dest[4 * x + 1] = source[2*x+0];
-				dest[4 * x + 2] = source[2*x+0];
-				dest[4 * x + 3] = source[2*x+1];
-			}
-		}
-	}
-
-	void Image::loadRGBUByteImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
-	{
-		for(int y = 0; y < height; y++)
-		{
-			const unsigned char *source = static_cast<const unsigned char*>(input) + y * inputPitch;
-			unsigned char *dest = static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 4;
-
-			for(int x = 0; x < width; x++)
-			{
-				dest[4 * x + 0] = source[x * 3 + 0];
-				dest[4 * x + 1] = source[x * 3 + 1];
-				dest[4 * x + 2] = source[x * 3 + 2];
-				dest[4 * x + 3] = 0xFF;
-			}
-		}
-	}
-
-	void Image::loadRGB565ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
-	{
-		for(int y = 0; y < height; y++)
-		{
-			const unsigned short *source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
-			unsigned char *dest = static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 4;
-
-			for(int x = 0; x < width; x++)
-			{
-				unsigned short rgba = source[x];
-				dest[4 * x + 0] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2);
-				dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9);
-				dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
-				dest[4 * x + 3] = 0xFF;
-			}
-		}
-	}
-
-	void Image::loadRGBFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
-	{
-		for(int y = 0; y < height; y++)
-		{
-			const float *source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch);
-			float *dest = reinterpret_cast<float*>(static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 16);
-
-			for(int x = 0; x < width; x++)
-			{
-				dest[4 * x + 0] = source[x * 3 + 0];
-				dest[4 * x + 1] = source[x * 3 + 1];
-				dest[4 * x + 2] = source[x * 3 + 2];
-				dest[4 * x + 3] = 1.0f;
-			}
-		}
-	}
-
-	void Image::loadRGBAUByteImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
-	{
-		for(int y = 0; y < height; y++)
-		{
-			const unsigned int *source = reinterpret_cast<const unsigned int*>(static_cast<const unsigned char*>(input) + y * inputPitch);
-			unsigned int *dest = reinterpret_cast<unsigned int*>(static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 4);
-
-			memcpy(dest, source, width * 4);
-		}
-	}
-
-	void Image::loadRGBA4444ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
-	{
-		for(int y = 0; y < height; y++)
-		{
-			const unsigned short *source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
-			unsigned char *dest = static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 4;
-
-			for(int x = 0; x < width; x++)
-			{
-				unsigned short rgba = source[x];
-				dest[4 * x + 0] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
-				dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
-				dest[4 * x + 2] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
-				dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
-			}
-		}
-	}
-
-	void Image::loadRGBA5551ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
-	{
-		for(int y = 0; y < height; y++)
-		{
-			const unsigned short *source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
-			unsigned char *dest = static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 4;
-
-			for(int x = 0; x < width; x++)
-			{
-				unsigned short rgba = source[x];
-				dest[4 * x + 0] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
-				dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
-				dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
-				dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
-			}
-		}
-	}
-
-	void Image::loadRGBAFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
-	{
-		for(int y = 0; y < height; y++)
-		{
-			const float *source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch);
-			float *dest = reinterpret_cast<float*>(static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 16);
-
-			memcpy(dest, source, width * 16);
-		}
-	}
-
-	void Image::loadD16ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
-	{
-		for(int y = 0; y < height; y++)
-		{
-			const unsigned short *source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
-			float *dest = reinterpret_cast<float*>(static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 4);
-
-			for(int x = 0; x < width; x++)
-			{
-				dest[x] = (float)source[x] / 0xFFFF;
-			}
-		}
-	}
-
-	void Image::loadD32ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
-	{
-		for(int y = 0; y < height; y++)
-		{
-			const unsigned int *source = reinterpret_cast<const unsigned int*>(static_cast<const unsigned char*>(input) + y * inputPitch);
-			float *dest = reinterpret_cast<float*>(static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 4);
-
-			for(int x = 0; x < width; x++)
-			{
-				dest[x] = (float)source[x] / 0xFFFFFFFF;
-			}
-		}
-	}
-
-	void Image::loadD24S8ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer)
-	{
-		for(int y = 0; y < height; y++)
-		{
-			const unsigned int *source = reinterpret_cast<const unsigned int*>(static_cast<const unsigned char*>(input) + y * inputPitch);
-			float *dest = reinterpret_cast<float*>(static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 4);
-
-			for(int x = 0; x < width; x++)
-			{
-				dest[x] = (float)(source[x] & 0xFFFFFF00) / 0xFFFFFF00;
-			}
-		}
-
-		unsigned char *stencil = reinterpret_cast<unsigned char*>(lockStencil(0, sw::PUBLIC));
-
-		if(stencil)
-		{
-			for(int y = 0; y < height; y++)
-			{
-				const unsigned int *source = reinterpret_cast<const unsigned int*>(static_cast<const unsigned char*>(input) + y * inputPitch);
-				unsigned char *dest = static_cast<unsigned char*>(stencil) + (y + yoffset) * getStencilPitchB() + xoffset;
-
-				for(int x = 0; x < width; x++)
-				{
-					dest[x] = static_cast<unsigned char>(source[x] & 0x000000FF);   // FIXME: Quad layout
-				}
-			}
-
-			unlockStencil();
-		}
-	}
-
-	void Image::loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels)
-	{
-		ASSERT(zoffset == 0 && depth == 1);
-
-		int inputPitch = ComputeCompressedPitch(width, format);
-		int rows = imageSize / inputPitch;
-		void *buffer = lock(xoffset, yoffset, sw::LOCK_WRITEONLY);
-
-        if(buffer)
-        {
-			for(int i = 0; i < rows; i++)
-			{
-				memcpy((void*)((GLbyte*)buffer + i * getPitch()), (void*)((GLbyte*)pixels + i * inputPitch), inputPitch);
-			}
-        }
-
-		unlock();
-	}
-}
diff --git a/src/OpenGL/libGLES_CM/Image.hpp b/src/OpenGL/libGLES_CM/Image.hpp
deleted file mode 100644
index 1c491d8..0000000
--- a/src/OpenGL/libGLES_CM/Image.hpp
+++ /dev/null
@@ -1,66 +0,0 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2013 TransGaming Inc.
-//
-// All rights reserved. No part of this software may be copied, distributed, transmitted,
-// transcribed, stored in a retrieval system, translated into any human or computer
-// language by any means, or disclosed to third parties without the explicit written
-// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
-//
-
-#ifndef gl_Image_hpp
-#define gl_Image_hpp
-
-#include "Renderer/Surface.hpp"
-#include "libEGL/Image.hpp"
-
-#define GL_API
-#include <GLES/gl.h>
-
-namespace es1
-{
-	class Texture;
-
-	class Image : public egl::Image
-	{
-	public:
-		Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type);
-		Image(Texture *parentTexture, GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable, bool renderTarget);
-
-		void loadImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint unpackAlignment, const void *input);
-		void loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
-
-		virtual void addRef();
-		virtual void release();
-		virtual void unbind(const egl::Texture *parent);   // Break parent ownership and release
-
-		static sw::Format selectInternalFormat(GLenum format, GLenum type);
-
-	private:
-		virtual ~Image();
-
-		void loadAlphaImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
-		void loadAlphaFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
-		void loadLuminanceImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
-		void loadLuminanceFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
-		void loadLuminanceAlphaImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
-		void loadLuminanceAlphaFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
-		void loadRGBUByteImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
-		void loadRGB565ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
-		void loadRGBFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
-		void loadRGBAUByteImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
-		void loadRGBA4444ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
-		void loadRGBA5551ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
-		void loadRGBAFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
-		void loadD16ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
-		void loadD32ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
-		void loadD24S8ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer);
-
-		egl::Texture *parentTexture;
-
-		volatile int referenceCount;
-	};
-}
-
-#endif   // gl_Image_hpp
diff --git a/src/OpenGL/libGLES_CM/Renderbuffer.h b/src/OpenGL/libGLES_CM/Renderbuffer.h
index 31f12ee..672cca6 100644
--- a/src/OpenGL/libGLES_CM/Renderbuffer.h
+++ b/src/OpenGL/libGLES_CM/Renderbuffer.h
@@ -18,7 +18,7 @@
 #define LIBGLES_CM_RENDERBUFFER_H_

 

 #include "common/Object.hpp"

-#include "Image.hpp"

+#include "common/Image.hpp"

 

 #define GL_API

 #include <GLES/gl.h>

diff --git a/src/OpenGL/libGLES_CM/Texture.cpp b/src/OpenGL/libGLES_CM/Texture.cpp
index cd2c35b..4d252de 100644
--- a/src/OpenGL/libGLES_CM/Texture.cpp
+++ b/src/OpenGL/libGLES_CM/Texture.cpp
@@ -427,7 +427,7 @@
 		image[level]->unbind(this);

 	}

 

-	image[level] = new Image(this, width, height, format, type);

+	image[level] = new egl::Image(this, width, height, format, type);

 

 	if(!image[level])

 	{

@@ -492,7 +492,7 @@
 		image[level]->unbind(this);

 	}

 

-	image[level] = new Image(this, width, height, format, GL_UNSIGNED_BYTE);

+	image[level] = new egl::Image(this, width, height, format, GL_UNSIGNED_BYTE);

 

 	if(!image[level])

 	{

@@ -527,7 +527,7 @@
 		image[level]->unbind(this);

 	}

 

-	image[level] = new Image(this, width, height, format, GL_UNSIGNED_BYTE);

+	image[level] = new egl::Image(this, width, height, format, GL_UNSIGNED_BYTE);

 

 	if(!image[level])

 	{

@@ -677,7 +677,7 @@
 			image[i]->unbind(this);

 		}

 

-		image[i] = new Image(this, std::max(image[0]->getWidth() >> i, 1), std::max(image[0]->getHeight() >> i, 1), image[0]->getFormat(), image[0]->getType());

+		image[i] = new egl::Image(this, std::max(image[0]->getWidth() >> i, 1), std::max(image[0]->getHeight() >> i, 1), image[0]->getFormat(), image[0]->getType());

 

 		if(!image[i])

 		{

@@ -762,7 +762,7 @@
 {

 	if(config)

 	{

-		return new es1::Image(0, width, height, config->mAlphaSize ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE);

+		return new egl::Image(0, width, height, config->mAlphaSize ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE);

 	}

 

 	return 0;

@@ -801,7 +801,7 @@
 		UNREACHABLE();

 	}

 

-	es1::Image *surface = new es1::Image(0, width, height, format, multiSampleDepth, lockable, true);

+	egl::Image *surface = new egl::Image(0, width, height, format, multiSampleDepth, lockable, true);

 

 	if(!surface)

 	{

diff --git a/src/OpenGL/libGLES_CM/libGLES_CM.cbp b/src/OpenGL/libGLES_CM/libGLES_CM.cbp
index f0769f6..1a8bff3 100644
--- a/src/OpenGL/libGLES_CM/libGLES_CM.cbp
+++ b/src/OpenGL/libGLES_CM/libGLES_CM.cbp
@@ -250,6 +250,8 @@
 		<Unit filename="../../Shader/VertexRoutine.hpp" />
 		<Unit filename="../../Shader/VertexShader.cpp" />
 		<Unit filename="../../Shader/VertexShader.hpp" />
+		<Unit filename="../common/Image.cpp" />
+		<Unit filename="../common/Image.hpp" />
 		<Unit filename="../common/MatrixStack.cpp" />
 		<Unit filename="../common/MatrixStack.hpp" />
 		<Unit filename="../common/NameSpace.cpp" />
@@ -273,8 +275,6 @@
 		<Unit filename="Device.hpp" />
 		<Unit filename="Framebuffer.cpp" />
 		<Unit filename="Framebuffer.h" />
-		<Unit filename="Image.cpp" />
-		<Unit filename="Image.hpp" />
 		<Unit filename="IndexDataManager.cpp" />
 		<Unit filename="IndexDataManager.h" />
 		<Unit filename="Renderbuffer.cpp" />
diff --git a/src/OpenGL/libGLES_CM/libGLES_CM.cpp b/src/OpenGL/libGLES_CM/libGLES_CM.cpp
index b60dddf..ddfe638 100644
--- a/src/OpenGL/libGLES_CM/libGLES_CM.cpp
+++ b/src/OpenGL/libGLES_CM/libGLES_CM.cpp
@@ -892,7 +892,7 @@
 			return error(GL_INVALID_ENUM);

 		}

 

-		if(imageSize != es1::ComputeCompressedSize(width, height, internalformat))

+		if(imageSize != egl::ComputeCompressedSize(width, height, internalformat))

 		{

 			return error(GL_INVALID_VALUE);

 		}

@@ -959,7 +959,7 @@
 			return error(GL_INVALID_VALUE);

 		}

 

-		if(imageSize != es1::ComputeCompressedSize(width, height, format))

+		if(imageSize != egl::ComputeCompressedSize(width, height, format))

 		{

 			return error(GL_INVALID_VALUE);

 		}

diff --git a/src/OpenGL/libGLES_CM/libGLES_CM.vcxproj b/src/OpenGL/libGLES_CM/libGLES_CM.vcxproj
index ce35b8d..300cd43 100644
--- a/src/OpenGL/libGLES_CM/libGLES_CM.vcxproj
+++ b/src/OpenGL/libGLES_CM/libGLES_CM.vcxproj
@@ -318,6 +318,7 @@
     </PostBuildEvent>

   </ItemDefinitionGroup>

   <ItemGroup>

+    <ClCompile Include="..\common\Image.cpp" />

     <ClCompile Include="..\common\MatrixStack.cpp" />

     <ClCompile Include="..\common\NameSpace.cpp" />

     <ClCompile Include="..\common\Object.cpp" />

@@ -326,7 +327,6 @@
     <ClCompile Include="..\common\debug.cpp" />

     <ClCompile Include="Device.cpp" />

     <ClCompile Include="Framebuffer.cpp" />

-    <ClCompile Include="Image.cpp" />

     <ClCompile Include="IndexDataManager.cpp" />

     <ClCompile Include="libGLES_CM.cpp" />

     <ClCompile Include="main.cpp" />

@@ -338,6 +338,7 @@
   </ItemGroup>

   <ItemGroup>

     <ClInclude Include="..\common\debug.h" />

+    <ClInclude Include="..\common\Image.hpp" />

     <ClInclude Include="..\common\MatrixStack.hpp" />

     <ClInclude Include="..\common\NameSpace.hpp" />

     <ClInclude Include="..\common\Object.hpp" />

@@ -349,7 +350,6 @@
     <ClInclude Include="Context.h" />

     <ClInclude Include="Device.hpp" />

     <ClInclude Include="Framebuffer.h" />

-    <ClInclude Include="Image.hpp" />

     <ClInclude Include="IndexDataManager.h" />

     <ClInclude Include="libGLES_CM.hpp" />

     <ClInclude Include="main.h" />

diff --git a/src/OpenGL/libGLES_CM/libGLES_CM.vcxproj.filters b/src/OpenGL/libGLES_CM/libGLES_CM.vcxproj.filters
index 47f9aaa..96ea959 100644
--- a/src/OpenGL/libGLES_CM/libGLES_CM.vcxproj.filters
+++ b/src/OpenGL/libGLES_CM/libGLES_CM.vcxproj.filters
@@ -47,9 +47,6 @@
     <ClCompile Include="Device.cpp">

       <Filter>Source Files</Filter>

     </ClCompile>

-    <ClCompile Include="Image.cpp">

-      <Filter>Source Files</Filter>

-    </ClCompile>

     <ClCompile Include="libGLES_CM.cpp">

       <Filter>Source Files</Filter>

     </ClCompile>

@@ -62,6 +59,9 @@
     <ClCompile Include="..\common\MatrixStack.cpp">

       <Filter>Source Files</Filter>

     </ClCompile>

+    <ClCompile Include="..\common\Image.cpp">

+      <Filter>Source Files</Filter>

+    </ClCompile>

   </ItemGroup>

   <ItemGroup>

     <ClInclude Include="Buffer.h">

@@ -103,9 +103,6 @@
     <ClInclude Include="Device.hpp">

       <Filter>Header Files</Filter>

     </ClInclude>

-    <ClInclude Include="Image.hpp">

-      <Filter>Header Files</Filter>

-    </ClInclude>

     <ClInclude Include="..\common\debug.h">

       <Filter>Header Files</Filter>

     </ClInclude>

@@ -133,6 +130,9 @@
     <ClInclude Include="libGLES_CM.hpp">

       <Filter>Header Files</Filter>

     </ClInclude>

+    <ClInclude Include="..\common\Image.hpp">

+      <Filter>Header Files</Filter>

+    </ClInclude>

   </ItemGroup>

   <ItemGroup>

     <ResourceCompile Include="libGLES_CM.rc" />

diff --git a/src/OpenGL/libGLES_CM/utilities.cpp b/src/OpenGL/libGLES_CM/utilities.cpp
index e583e2e..799c537 100644
--- a/src/OpenGL/libGLES_CM/utilities.cpp
+++ b/src/OpenGL/libGLES_CM/utilities.cpp
@@ -22,32 +22,6 @@
 

 namespace es1

 {

-	GLsizei ComputePitch(GLsizei width, GLenum format, GLenum type, GLint alignment)

-	{

-		ASSERT(alignment > 0 && isPow2(alignment));

-

-		GLsizei rawPitch = ComputePixelSize(format, type) * width;

-		return (rawPitch + alignment - 1) & ~(alignment - 1);

-	}

-

-	GLsizei ComputeCompressedPitch(GLsizei width, GLenum format)

-	{

-		return ComputeCompressedSize(width, 1, format);

-	}

-

-	GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format)

-	{

-		switch(format)

-		{

-		case GL_ETC1_RGB8_OES:

-		case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:

-		case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:

-			return 8 * (GLsizei)ceil((float)width / 4.0f) * (GLsizei)ceil((float)height / 4.0f);

-		default:

-			return 0;

-		}

-	}

-

 	bool IsCompressed(GLenum format)

 	{

 		return format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ||

@@ -65,48 +39,6 @@
 		return format == GL_DEPTH_STENCIL_OES;

 	}

 

-	// Returns the size, in bytes, of a single texel in an Image

-	int ComputePixelSize(GLenum format, GLenum type)

-	{

-		switch(type)

-		{

-		case GL_UNSIGNED_BYTE:

-			switch(format)

-			{

-			case GL_ALPHA:           return sizeof(unsigned char);

-			case GL_LUMINANCE:       return sizeof(unsigned char);

-			case GL_LUMINANCE_ALPHA: return sizeof(unsigned char) * 2;

-			case GL_RGB:             return sizeof(unsigned char) * 3;

-			case GL_RGBA:            return sizeof(unsigned char) * 4;

-			case GL_BGRA_EXT:        return sizeof(unsigned char) * 4;

-			default: UNREACHABLE();

-			}

-			break;

-		case GL_UNSIGNED_SHORT_4_4_4_4:

-		case GL_UNSIGNED_SHORT_5_5_5_1:

-		case GL_UNSIGNED_SHORT_5_6_5:

-		case GL_UNSIGNED_SHORT:

-			return sizeof(unsigned short);

-		case GL_UNSIGNED_INT:

-		case GL_UNSIGNED_INT_24_8_OES:

-			return sizeof(unsigned int);

-		case GL_FLOAT:

-			switch(format)

-			{

-			case GL_ALPHA:           return sizeof(float);

-			case GL_LUMINANCE:       return sizeof(float);

-			case GL_LUMINANCE_ALPHA: return sizeof(float) * 2;

-			case GL_RGB:             return sizeof(float) * 3;

-			case GL_RGBA:            return sizeof(float) * 4;

-			default: UNREACHABLE();

-			}

-			break;

-		default: UNREACHABLE();

-		}

-

-		return 0;

-	}

-

 	bool IsCubemapTextureTarget(GLenum target)

 	{

 		return (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_OES && target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_OES);

diff --git a/src/OpenGL/libGLES_CM/utilities.h b/src/OpenGL/libGLES_CM/utilities.h
index c64d600..ec3563c 100644
--- a/src/OpenGL/libGLES_CM/utilities.h
+++ b/src/OpenGL/libGLES_CM/utilities.h
@@ -15,7 +15,7 @@
 #define LIBGLES_CM_UTILITIES_H

 

 #include "Device.hpp"

-#include "Image.hpp"

+#include "common/Image.hpp"

 #include "Texture.h"

 

 #define GL_API

@@ -29,10 +29,6 @@
 {

 	struct Color;

 

-	int ComputePixelSize(GLenum format, GLenum type);

-	GLsizei ComputePitch(GLsizei width, GLenum format, GLenum type, GLint alignment);

-	GLsizei ComputeCompressedPitch(GLsizei width, GLenum format);

-	GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format);

 	bool IsCompressed(GLenum format);

 	bool IsDepthTexture(GLenum format);

 	bool IsStencilTexture(GLenum format);

diff --git a/src/OpenGL/libGLESv2/Android.mk b/src/OpenGL/libGLESv2/Android.mk
index b28364a..33cd6ee 100644
--- a/src/OpenGL/libGLESv2/Android.mk
+++ b/src/OpenGL/libGLESv2/Android.mk
@@ -12,7 +12,6 @@
 	Device.cpp \
 	Fence.cpp \
 	Framebuffer.cpp \
-	Image.cpp \
 	IndexDataManager.cpp \
 	libGLESv2.cpp \
 	main.cpp \
diff --git a/src/OpenGL/libGLESv2/Context.cpp b/src/OpenGL/libGLESv2/Context.cpp
index 6fc64fb..8c44729 100644
--- a/src/OpenGL/libGLESv2/Context.cpp
+++ b/src/OpenGL/libGLESv2/Context.cpp
@@ -37,10 +37,6 @@
 

 #include <EGL/eglext.h>

 

-#ifdef __ANDROID__

-	#include "../common/AndroidCommon.hpp"

-#endif  // __ANDROID__

-

 #undef near

 #undef far

 

@@ -2971,7 +2967,7 @@
 		}

 	}

 

-	GLsizei outputPitch = ComputePitch(width, format, type, mState.packAlignment);

+	GLsizei outputPitch = egl::ComputePitch(width, format, type, mState.packAlignment);

     

 	// Sized query sanity check

     if(bufSize)

@@ -3973,10 +3969,6 @@
         break;

     case EGL_GL_RENDERBUFFER_KHR:

         break;

-    #if defined(__ANDROID__)

-    case EGL_NATIVE_BUFFER_ANDROID:

-        break;

-    #endif

     default:

         return EGL_BAD_PARAMETER;

     }

@@ -4024,12 +4016,6 @@
             return EGL_BAD_ACCESS;

         }

     }

-    #if defined(__ANDROID__)

-    else if(target == EGL_NATIVE_BUFFER_ANDROID)

-    {

-		return isSupportedAndroidBuffer(name);

-    }

-    #endif

     else UNREACHABLE();

 

 	return EGL_SUCCESS;

@@ -4062,12 +4048,6 @@
 

         return renderbuffer->createSharedImage();

     }

-    #if defined(__ANDROID__)

-    else if(target == EGL_NATIVE_BUFFER_ANDROID)

-    {

-		return wrapAndroidNativeWindow<es2::Image>(name);

-    }

-    #endif

     else UNREACHABLE();

 

 	return 0;

diff --git a/src/OpenGL/libGLESv2/Context.h b/src/OpenGL/libGLESv2/Context.h
index 80b2be9..01e08d8 100644
--- a/src/OpenGL/libGLESv2/Context.h
+++ b/src/OpenGL/libGLESv2/Context.h
@@ -19,7 +19,7 @@
 #include "ResourceManager.h"

 #include "common/NameSpace.hpp"

 #include "common/Object.hpp"

-#include "Image.hpp"

+#include "common/Image.hpp"

 #include "Renderer/Sampler.hpp"

 #include "TransformFeedback.h"

 

diff --git a/src/OpenGL/libGLESv2/Device.cpp b/src/OpenGL/libGLESv2/Device.cpp
index 499e3e3..57a0df7 100644
--- a/src/OpenGL/libGLESv2/Device.cpp
+++ b/src/OpenGL/libGLESv2/Device.cpp
@@ -11,7 +11,7 @@
 

 #include "Device.hpp"

 

-#include "Image.hpp"

+#include "common/Image.hpp"

 #include "Texture.h"

 

 #include "Renderer/Renderer.hpp"

@@ -231,7 +231,7 @@
 		depthStencil->clearStencilBuffer(stencil, mask, x0, y0, width, height);

 	}

 

-	Image *Device::createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard)

+	egl::Image *Device::createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard)

 	{

 		if(width == 0 || height == 0 || height > OUTLINE_RESOLUTION)

 		{

@@ -264,7 +264,7 @@
 			UNREACHABLE();

 		}

 

-		Image *surface = new Image(0, width, height, format, multiSampleDepth, lockable, true);

+		egl::Image *surface = new egl::Image(0, width, height, format, multiSampleDepth, lockable, true);

 

 		if(!surface)

 		{

@@ -275,7 +275,7 @@
 		return surface;

 	}

 

-	Image *Device::createRenderTarget(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool lockable)

+	egl::Image *Device::createRenderTarget(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool lockable)

 	{

 		if(height > OUTLINE_RESOLUTION)

 		{

@@ -283,7 +283,7 @@
 			return 0;

 		}

 

-		Image *surface = new Image(0, width, height, format, multiSampleDepth, lockable, true);

+		egl::Image *surface = new egl::Image(0, width, height, format, multiSampleDepth, lockable, true);

 

 		if(!surface)

 		{

@@ -605,7 +605,7 @@
 

 		bool scaling = (sRect.x1 - sRect.x0 != dRect.x1 - dRect.x0) || (sRect.y1 - sRect.y0 != dRect.y1 - dRect.y0);

 		bool equalFormats = source->getInternalFormat() == dest->getInternalFormat();

-		bool depthStencil = Image::isDepth(source->getInternalFormat()) || Image::isStencil(source->getInternalFormat());

+		bool depthStencil = egl::Image::isDepth(source->getInternalFormat()) || egl::Image::isStencil(source->getInternalFormat());

 		bool alpha0xFF = false;

 

 		if((source->getInternalFormat() == FORMAT_A8R8G8B8 && dest->getInternalFormat() == FORMAT_X8R8G8B8) ||

@@ -622,7 +622,7 @@
 				sw::byte *sourceBuffer = (sw::byte*)source->lockInternal(0, 0, sourceRect->slice, LOCK_READONLY, PUBLIC);

 				sw::byte *destBuffer = (sw::byte*)dest->lockInternal(0, 0, destRect->slice, LOCK_DISCARD, PUBLIC);

 

-				copyBuffer(sourceBuffer, destBuffer, source->getInternalWidth(), source->getInternalHeight(), source->getInternalPitchB(), dest->getInternalPitchB(), Image::bytes(source->getInternalFormat()), flipX, flipY);

+				copyBuffer(sourceBuffer, destBuffer, source->getInternalWidth(), source->getInternalHeight(), source->getInternalPitchB(), dest->getInternalPitchB(), egl::Image::bytes(source->getInternalFormat()), flipX, flipY);

 

 				source->unlockInternal();

 				dest->unlockInternal();

@@ -633,7 +633,7 @@
 				sw::byte *sourceBuffer = (sw::byte*)source->lockStencil(0, PUBLIC);

 				sw::byte *destBuffer = (sw::byte*)dest->lockStencil(0, PUBLIC);

 

-				copyBuffer(sourceBuffer, destBuffer, source->getInternalWidth(), source->getInternalHeight(), source->getInternalPitchB(), dest->getInternalPitchB(), Image::bytes(source->getInternalFormat()), flipX, flipY);

+				copyBuffer(sourceBuffer, destBuffer, source->getInternalWidth(), source->getInternalHeight(), source->getInternalPitchB(), dest->getInternalPitchB(), egl::Image::bytes(source->getInternalFormat()), flipX, flipY);

 

 				source->unlockStencil();

 				dest->unlockStencil();

@@ -649,7 +649,7 @@
 			unsigned int width = dRect.x1 - dRect.x0;

 			unsigned int height = dRect.y1 - dRect.y0;

 

-			copyBuffer(sourceBytes, destBytes, width, height, sourcePitch, destPitch, Image::bytes(source->getInternalFormat()), flipX, flipY);

+			copyBuffer(sourceBytes, destBytes, width, height, sourcePitch, destPitch, egl::Image::bytes(source->getInternalFormat()), flipX, flipY);

 

 			if(alpha0xFF)

 			{

@@ -683,7 +683,7 @@
 

 	bool Device::stretchCube(egl::Image *source, egl::Image *dest)

 	{

-		if(!source || !dest || Image::isDepth(source->getInternalFormat()) || Image::isStencil(source->getInternalFormat()))

+		if(!source || !dest || egl::Image::isDepth(source->getInternalFormat()) || egl::Image::isStencil(source->getInternalFormat()))

 		{

 			ERR("Invalid parameters");

 			return false;

@@ -711,7 +711,7 @@
 		{

 			unsigned int sourcePitch = source->getInternalPitchB();

 			unsigned int destPitch = dest->getInternalPitchB();

-			unsigned int bytes = dWidth * Image::bytes(source->getInternalFormat());

+			unsigned int bytes = dWidth * egl::Image::bytes(source->getInternalFormat());

 

 			for(int z = 0; z < dDepth; ++z)

 			{

diff --git a/src/OpenGL/libGLESv2/Device.hpp b/src/OpenGL/libGLESv2/Device.hpp
index 04df465..26bc248 100644
--- a/src/OpenGL/libGLESv2/Device.hpp
+++ b/src/OpenGL/libGLESv2/Device.hpp
@@ -22,7 +22,6 @@
 namespace es2

 {

 	class Texture;

-	class Image;

 

 	enum PrimitiveType

 	{

@@ -55,8 +54,8 @@
 		virtual void clearColor(unsigned int color, unsigned int rgbaMask);

 		virtual void clearDepth(float z);

 		virtual void clearStencil(unsigned int stencil, unsigned int mask);

-		virtual Image *createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard);

-		virtual Image *createRenderTarget(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool lockable);

+		virtual egl::Image *createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard);

+		virtual egl::Image *createRenderTarget(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool lockable);

 		virtual void drawIndexedPrimitive(PrimitiveType type, unsigned int indexOffset, unsigned int primitiveCount, int indexSize);

 		virtual void drawPrimitive(PrimitiveType primitiveType, unsigned int primiveCount);

 		virtual void setDepthStencilSurface(egl::Image *newDepthStencil);

diff --git a/src/OpenGL/libGLESv2/Framebuffer.h b/src/OpenGL/libGLESv2/Framebuffer.h
index e3b3a2a..1d15b30 100644
--- a/src/OpenGL/libGLESv2/Framebuffer.h
+++ b/src/OpenGL/libGLESv2/Framebuffer.h
@@ -16,7 +16,7 @@
 #define LIBGLESV2_FRAMEBUFFER_H_

 

 #include "common/Object.hpp"

-#include "Image.hpp"

+#include "common/Image.hpp"

 

 #define GL_APICALL

 #include <GLES2/gl2.h>

diff --git a/src/OpenGL/libGLESv2/Image.hpp b/src/OpenGL/libGLESv2/Image.hpp
deleted file mode 100644
index 3824a8f..0000000
--- a/src/OpenGL/libGLESv2/Image.hpp
+++ /dev/null
@@ -1,52 +0,0 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2013 TransGaming Inc.
-//
-// All rights reserved. No part of this software may be copied, distributed, transmitted,
-// transcribed, stored in a retrieval system, translated into any human or computer
-// language by any means, or disclosed to third parties without the explicit written
-// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
-//
-
-#ifndef gl_Image_hpp
-#define gl_Image_hpp
-
-#include "Renderer/Surface.hpp"
-#include "libEGL/Image.hpp"
-
-#define GL_APICALL
-#include <GLES2/gl2.h>
-
-namespace es2
-{
-	class Texture;
-
-	class Image : public egl::Image
-	{
-	public:
-		Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type);
-		Image(Texture *parentTexture, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type);
-		Image(Texture *parentTexture, GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable, bool renderTarget);
-
-		void loadImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint unpackAlignment, const void *input);
-		void loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
-
-		virtual void addRef();
-		virtual void release();
-		virtual void unbind(const egl::Texture *parent);   // Break parent ownership and release
-
-		static sw::Format selectInternalFormat(GLenum format, GLenum type);
-
-	private:
-		virtual ~Image();
-
-		void loadD24S8ImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, int inputPitch, const void *input, void *buffer);
-
-		egl::Texture *parentTexture;
-
-		volatile int referenceCount;
-	};
-}
-
-#endif   // gl_Image_hpp
diff --git a/src/OpenGL/libGLESv2/Renderbuffer.cpp b/src/OpenGL/libGLESv2/Renderbuffer.cpp
index 38f4189..2ae4435 100644
--- a/src/OpenGL/libGLESv2/Renderbuffer.cpp
+++ b/src/OpenGL/libGLESv2/Renderbuffer.cpp
@@ -228,7 +228,7 @@
 
 // Increments refcount on image.
 // caller must release() the returned image
-Image *RenderbufferTextureCubeMap::getRenderTarget()
+egl::Image *RenderbufferTextureCubeMap::getRenderTarget()
 {
 	return mTextureCubeMap->getRenderTarget(mTarget, 0);
 }
diff --git a/src/OpenGL/libGLESv2/Renderbuffer.h b/src/OpenGL/libGLESv2/Renderbuffer.h
index 4ffae7c..6b336b5 100644
--- a/src/OpenGL/libGLESv2/Renderbuffer.h
+++ b/src/OpenGL/libGLESv2/Renderbuffer.h
@@ -18,7 +18,7 @@
 #define LIBGLESV2_RENDERBUFFER_H_

 

 #include "common/Object.hpp"

-#include "Image.hpp"

+#include "common/Image.hpp"

 

 #define GL_APICALL

 #include <GLES2/gl2.h>

@@ -118,7 +118,7 @@
 	virtual void addProxyRef(const Renderbuffer *proxy);

     virtual void releaseProxy(const Renderbuffer *proxy);

 

-	virtual Image *getRenderTarget();

+	virtual egl::Image *getRenderTarget();

     virtual egl::Image *createSharedImage();

     virtual bool isShared() const;

 

diff --git a/src/OpenGL/libGLESv2/Texture.cpp b/src/OpenGL/libGLESv2/Texture.cpp
index f1b3d46..d84fb86 100644
--- a/src/OpenGL/libGLESv2/Texture.cpp
+++ b/src/OpenGL/libGLESv2/Texture.cpp
@@ -398,7 +398,7 @@
     return image;

 }

 

-void Texture::setImage(GLenum format, GLenum type, GLint unpackAlignment, const void *pixels,egl:: Image *image)

+void Texture::setImage(GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, egl::Image *image)

 {

     if(pixels && image)

     {

@@ -613,7 +613,7 @@
 		image[level]->unbind(this);

 	}

 

-	image[level] = new Image(this, width, height, format, type);

+	image[level] = new egl::Image(this, width, height, format, type);

 

 	if(!image[level])

 	{

@@ -678,7 +678,7 @@
 		image[level]->unbind(this);

 	}

 

-	image[level] = new Image(this, width, height, format, GL_UNSIGNED_BYTE);

+	image[level] = new egl::Image(this, width, height, format, GL_UNSIGNED_BYTE);

 

 	if(!image[level])

 	{

@@ -713,7 +713,7 @@
 		image[level]->unbind(this);

 	}

 

-	image[level] = new Image(this, width, height, format, GL_UNSIGNED_BYTE);

+	image[level] = new egl::Image(this, width, height, format, GL_UNSIGNED_BYTE);

 

 	if(!image[level])

 	{

@@ -863,7 +863,7 @@
 			image[i]->unbind(this);

 		}

 

-		image[i] = new Image(this, std::max(image[0]->getWidth() >> i, 1), std::max(image[0]->getHeight() >> i, 1), image[0]->getFormat(), image[0]->getType());

+		image[i] = new egl::Image(this, std::max(image[0]->getWidth() >> i, 1), std::max(image[0]->getHeight() >> i, 1), image[0]->getFormat(), image[0]->getType());

 

 		if(!image[i])

 		{

@@ -1058,7 +1058,7 @@
 		image[face][level]->unbind(this);

 	}

 

-	image[face][level] = new Image(this, width, height, format, GL_UNSIGNED_BYTE);

+	image[face][level] = new egl::Image(this, width, height, format, GL_UNSIGNED_BYTE);

 

 	if(!image[face][level])

 	{

@@ -1199,7 +1199,7 @@
 		image[face][level]->unbind(this);

 	}

 

-	image[face][level] = new Image(this, width, height, format, type);

+	image[face][level] = new egl::Image(this, width, height, format, type);

 

 	if(!image[face][level])

 	{

@@ -1226,7 +1226,7 @@
 		image[face][level]->unbind(this);

 	}

 

-	image[face][level] = new Image(this, width, height, format, GL_UNSIGNED_BYTE);

+	image[face][level] = new egl::Image(this, width, height, format, GL_UNSIGNED_BYTE);

 

 	if(!image[face][level])

 	{

@@ -1244,12 +1244,12 @@
 	renderTarget->release();

 }

 

-Image *TextureCubeMap::getImage(int face, unsigned int level)

+egl::Image *TextureCubeMap::getImage(int face, unsigned int level)

 {

 	return image[face][level];

 }

 

-Image *TextureCubeMap::getImage(GLenum face, unsigned int level)

+egl::Image *TextureCubeMap::getImage(GLenum face, unsigned int level)

 {

     return image[CubeFaceIndex(face)][level];

 }

@@ -1304,7 +1304,7 @@
 				image[f][i]->unbind(this);

 			}

 

-			image[f][i] = new Image(this, std::max(image[0][0]->getWidth() >> i, 1), std::max(image[0][0]->getHeight() >> i, 1), image[0][0]->getFormat(), image[0][0]->getType());

+			image[f][i] = new egl::Image(this, std::max(image[0][0]->getWidth() >> i, 1), std::max(image[0][0]->getHeight() >> i, 1), image[0][0]->getFormat(), image[0][0]->getType());

 

 			if(!image[f][i])

 			{

@@ -1333,7 +1333,7 @@
     return mFaceProxies[face];

 }

 

-Image *TextureCubeMap::getRenderTarget(GLenum target, unsigned int level)

+egl::Image *TextureCubeMap::getRenderTarget(GLenum target, unsigned int level)

 {

     ASSERT(IsCubemapTextureTarget(target));

     ASSERT(level < IMPLEMENTATION_MAX_TEXTURE_LEVELS);

@@ -1482,7 +1482,7 @@
 		image[level]->unbind(this);

 	}

 

-	image[level] = new Image(this, width, height, depth, format, type);

+	image[level] = new egl::Image(this, width, height, depth, format, type);

 

 	if(!image[level])

 	{

@@ -1543,7 +1543,7 @@
 		image[level]->unbind(this);

 	}

 

-	image[level] = new Image(this, width, height, depth, format, GL_UNSIGNED_BYTE);

+	image[level] = new egl::Image(this, width, height, depth, format, GL_UNSIGNED_BYTE);

 

 	if(!image[level])

 	{

@@ -1578,7 +1578,7 @@
 		image[level]->unbind(this);

 	}

 

-	image[level] = new Image(this, width, height, depth, format, GL_UNSIGNED_BYTE);

+	image[level] = new egl::Image(this, width, height, depth, format, GL_UNSIGNED_BYTE);

 

 	if(!image[level])

 	{

@@ -1737,7 +1737,7 @@
 			image[i]->unbind(this);

 		}

 

-		image[i] = new Image(this, std::max(image[0]->getWidth() >> i, 1), std::max(image[0]->getHeight() >> i, 1), std::max(image[0]->getDepth() >> i, 1), image[0]->getFormat(), image[0]->getType());

+		image[i] = new egl::Image(this, std::max(image[0]->getWidth() >> i, 1), std::max(image[0]->getHeight() >> i, 1), std::max(image[0]->getDepth() >> i, 1), image[0]->getFormat(), image[0]->getType());

 

 		if(!image[i])

 		{

@@ -1823,7 +1823,7 @@
 {

 	if(config)

 	{

-		return new es2::Image(0, width, height, config->mAlphaSize ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE);

+		return new egl::Image(0, width, height, config->mAlphaSize ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE);

 	}

 

 	return 0;

@@ -1862,7 +1862,7 @@
 		UNREACHABLE();

 	}

 

-	es2::Image *surface = new es2::Image(0, width, height, format, multiSampleDepth, lockable, true);

+	egl::Image *surface = new egl::Image(0, width, height, format, multiSampleDepth, lockable, true);

 

 	if(!surface)

 	{

@@ -1872,4 +1872,3 @@
 

 	return surface;

 }

-

diff --git a/src/OpenGL/libGLESv2/Texture.h b/src/OpenGL/libGLESv2/Texture.h
index 7a9a3b4..f7b2095 100644
--- a/src/OpenGL/libGLESv2/Texture.h
+++ b/src/OpenGL/libGLESv2/Texture.h
@@ -58,7 +58,7 @@
 

     virtual ~Texture();

 

-	sw::Resource *getResource() const;

+	virtual sw::Resource *getResource() const;

 

 	virtual void addProxyRef(const Renderbuffer *proxy) = 0;

     virtual void releaseProxy(const Renderbuffer *proxy) = 0;

@@ -245,19 +245,19 @@
     virtual void generateMipmaps();

 

     virtual Renderbuffer *getRenderbuffer(GLenum target);

-	virtual Image *getRenderTarget(GLenum target, unsigned int level);

+	virtual egl::Image *getRenderTarget(GLenum target, unsigned int level);

 	virtual bool isShared(GLenum target, unsigned int level) const;

 

-	Image *getImage(int face, unsigned int level);

+	egl::Image *getImage(int face, unsigned int level);

 

 private:

 	bool isCubeComplete() const;

 	bool isMipmapCubeComplete() const;

 

     // face is one of the GL_TEXTURE_CUBE_MAP_* enumerants. Returns NULL on failure.

-    Image *getImage(GLenum face, unsigned int level);

+	egl::Image *getImage(GLenum face, unsigned int level);

 

-    Image *image[6][IMPLEMENTATION_MAX_TEXTURE_LEVELS];

+	egl::Image *image[6][IMPLEMENTATION_MAX_TEXTURE_LEVELS];

 	

 	// A specific internal reference count is kept for colorbuffer proxy references,

     // because, as the renderbuffer acting as proxy will maintain a binding pointer

diff --git a/src/OpenGL/libGLESv2/libGLESv2.cbp b/src/OpenGL/libGLESv2/libGLESv2.cbp
index d66dd06..2466e69 100644
--- a/src/OpenGL/libGLESv2/libGLESv2.cbp
+++ b/src/OpenGL/libGLESv2/libGLESv2.cbp
@@ -250,6 +250,8 @@
 		<Unit filename="../../Shader/VertexRoutine.hpp" />
 		<Unit filename="../../Shader/VertexShader.cpp" />
 		<Unit filename="../../Shader/VertexShader.hpp" />
+		<Unit filename="../common/Image.cpp" />
+		<Unit filename="../common/Image.hpp" />
 		<Unit filename="../common/NameSpace.cpp" />
 		<Unit filename="../common/NameSpace.hpp" />
 		<Unit filename="../common/Object.cpp" />
@@ -349,8 +351,6 @@
 		<Unit filename="Fence.h" />
 		<Unit filename="Framebuffer.cpp" />
 		<Unit filename="Framebuffer.h" />
-		<Unit filename="Image.cpp" />
-		<Unit filename="Image.hpp" />
 		<Unit filename="IndexDataManager.cpp" />
 		<Unit filename="IndexDataManager.h" />
 		<Unit filename="Program.cpp" />
diff --git a/src/OpenGL/libGLESv2/libGLESv2.cpp b/src/OpenGL/libGLESv2/libGLESv2.cpp
index a6e6156..9b356fd 100644
--- a/src/OpenGL/libGLESv2/libGLESv2.cpp
+++ b/src/OpenGL/libGLESv2/libGLESv2.cpp
@@ -1051,7 +1051,7 @@
 			return error(GL_INVALID_ENUM);

 		}

 

-		if(imageSize != es2::ComputeCompressedSize(width, height, internalformat))

+		if(imageSize != egl::ComputeCompressedSize(width, height, internalformat))

 		{

 			return error(GL_INVALID_VALUE);

 		}

@@ -1158,7 +1158,7 @@
 			return error(GL_INVALID_VALUE);

 		}

 

-		if(imageSize != es2::ComputeCompressedSize(width, height, format))

+		if(imageSize != egl::ComputeCompressedSize(width, height, format))

 		{

 			return error(GL_INVALID_VALUE);

 		}

@@ -6758,7 +6758,7 @@
 		return error(GL_INVALID_ENUM);

 	}

 

-	if(imageSize != es2::ComputeCompressedSize(width, height, internalformat) * depth)

+	if(imageSize != egl::ComputeCompressedSize(width, height, internalformat) * depth)

 	{

 		return error(GL_INVALID_VALUE);

 	}

diff --git a/src/OpenGL/libGLESv2/libGLESv2.vcxproj b/src/OpenGL/libGLESv2/libGLESv2.vcxproj
index 53592e9..b007bb6 100644
--- a/src/OpenGL/libGLESv2/libGLESv2.vcxproj
+++ b/src/OpenGL/libGLESv2/libGLESv2.vcxproj
@@ -318,6 +318,7 @@
     </PostBuildEvent>

   </ItemDefinitionGroup>

   <ItemGroup>

+    <ClCompile Include="..\common\Image.cpp" />

     <ClCompile Include="..\common\NameSpace.cpp" />

     <ClCompile Include="..\common\Object.cpp" />

     <ClCompile Include="Buffer.cpp" />

@@ -326,7 +327,6 @@
     <ClCompile Include="Device.cpp" />

     <ClCompile Include="Fence.cpp" />

     <ClCompile Include="Framebuffer.cpp" />

-    <ClCompile Include="Image.cpp" />

     <ClCompile Include="IndexDataManager.cpp" />

     <ClCompile Include="libGLESv2.cpp" />

     <ClCompile Include="libGLESv3.cpp" />

@@ -344,6 +344,7 @@
   </ItemGroup>

   <ItemGroup>

     <ClInclude Include="..\common\debug.h" />

+    <ClInclude Include="..\common\Image.hpp" />

     <ClInclude Include="..\common\NameSpace.hpp" />

     <ClInclude Include="..\common\Object.hpp" />

     <ClInclude Include="..\include\GLES2\gl2.h" />

@@ -354,7 +355,6 @@
     <ClInclude Include="Device.hpp" />

     <ClInclude Include="Fence.h" />

     <ClInclude Include="Framebuffer.h" />

-    <ClInclude Include="Image.hpp" />

     <ClInclude Include="IndexDataManager.h" />

     <ClInclude Include="libGLESv2.hpp" />

     <ClInclude Include="main.h" />

diff --git a/src/OpenGL/libGLESv2/libGLESv2.vcxproj.filters b/src/OpenGL/libGLESv2/libGLESv2.vcxproj.filters
index 05ea0bd..5ce9a98 100644
--- a/src/OpenGL/libGLESv2/libGLESv2.vcxproj.filters
+++ b/src/OpenGL/libGLESv2/libGLESv2.vcxproj.filters
@@ -59,9 +59,6 @@
     <ClCompile Include="Device.cpp">

       <Filter>Source Files</Filter>

     </ClCompile>

-    <ClCompile Include="Image.cpp">

-      <Filter>Source Files</Filter>

-    </ClCompile>

     <ClCompile Include="Query.cpp">

       <Filter>Source Files</Filter>

     </ClCompile>

@@ -80,6 +77,9 @@
     <ClCompile Include="VertexArray.cpp">

       <Filter>Source Files</Filter>

     </ClCompile>

+    <ClCompile Include="..\common\Image.cpp">

+      <Filter>Source Files</Filter>

+    </ClCompile>

   </ItemGroup>

   <ItemGroup>

     <ClInclude Include="Buffer.h">

@@ -130,9 +130,6 @@
     <ClInclude Include="Device.hpp">

       <Filter>Header Files</Filter>

     </ClInclude>

-    <ClInclude Include="Image.hpp">

-      <Filter>Header Files</Filter>

-    </ClInclude>

     <ClInclude Include="..\include\GLES2\gl2.h">

       <Filter>Header Files</Filter>

     </ClInclude>

@@ -166,6 +163,9 @@
     <ClInclude Include="libGLESv2.hpp">

       <Filter>Header Files</Filter>

     </ClInclude>

+    <ClInclude Include="..\common\Image.hpp">

+      <Filter>Header Files</Filter>

+    </ClInclude>

   </ItemGroup>

   <ItemGroup>

     <ResourceCompile Include="libGLESv2.rc" />

diff --git a/src/OpenGL/libGLESv2/libGLESv3.cpp b/src/OpenGL/libGLESv2/libGLESv3.cpp
index 83b73ed..b16a969 100644
--- a/src/OpenGL/libGLESv2/libGLESv3.cpp
+++ b/src/OpenGL/libGLESv2/libGLESv3.cpp
@@ -741,7 +741,7 @@
 		return error(GL_INVALID_ENUM);

 	}

 

-	if(imageSize != es2::ComputeCompressedSize(width, height, internalformat) * depth)

+	if(imageSize != egl::ComputeCompressedSize(width, height, internalformat) * depth)

 	{

 		return error(GL_INVALID_VALUE);

 	}

diff --git a/src/OpenGL/libGLESv2/utilities.cpp b/src/OpenGL/libGLESv2/utilities.cpp
index f15e210..8b30f37 100644
--- a/src/OpenGL/libGLESv2/utilities.cpp
+++ b/src/OpenGL/libGLESv2/utilities.cpp
@@ -191,45 +191,6 @@
 		return -1;

 	}

 

-	GLsizei ComputePitch(GLsizei width, GLenum format, GLenum type, GLint alignment)

-	{

-		ASSERT(alignment > 0 && isPow2(alignment));

-

-		GLsizei rawPitch = ComputePixelSize(format, type) * width;

-		return (rawPitch + alignment - 1) & ~(alignment - 1);

-	}

-

-	GLsizei ComputeCompressedPitch(GLsizei width, GLenum format)

-	{

-		return ComputeCompressedSize(width, 1, format);

-	}

-

-	GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format)

-	{

-		switch(format)

-		{

-		case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:

-		case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:

-        case GL_ETC1_RGB8_OES:

-		case GL_COMPRESSED_R11_EAC:

-		case GL_COMPRESSED_SIGNED_R11_EAC:

-		case GL_COMPRESSED_RGB8_ETC2:

-		case GL_COMPRESSED_SRGB8_ETC2:

-		case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:

-		case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:

-			return 8 * (GLsizei)ceil((float)width / 4.0f) * (GLsizei)ceil((float)height / 4.0f);

-		case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:

-		case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:

-		case GL_COMPRESSED_RG11_EAC:

-		case GL_COMPRESSED_SIGNED_RG11_EAC:

-		case GL_COMPRESSED_RGBA8_ETC2_EAC:

-		case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:

-			return 16 * (GLsizei)ceil((float)width / 4.0f) * (GLsizei)ceil((float)height / 4.0f);

-		default:

-			return 0;

-		}

-	}

-

 	bool IsCompressed(GLenum format)

 	{

 		return format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ||

@@ -251,59 +212,6 @@
 		       format == GL_DEPTH_STENCIL_OES;

 	}

 

-	// Returns the size, in bytes, of a single texel in an Image

-	int ComputePixelSize(GLenum format, GLenum type)

-	{

-		switch(type)

-		{

-		case GL_UNSIGNED_BYTE:

-			switch(format)

-			{

-			case GL_ALPHA:           return sizeof(unsigned char);

-			case GL_LUMINANCE:       return sizeof(unsigned char);

-			case GL_LUMINANCE_ALPHA: return sizeof(unsigned char) * 2;

-			case GL_RGB:             return sizeof(unsigned char) * 3;

-			case GL_RGBA:            return sizeof(unsigned char) * 4;

-			case GL_BGRA_EXT:        return sizeof(unsigned char) * 4;

-			default: UNREACHABLE();

-			}

-			break;

-		case GL_UNSIGNED_SHORT_4_4_4_4:

-		case GL_UNSIGNED_SHORT_5_5_5_1:

-		case GL_UNSIGNED_SHORT_5_6_5:

-		case GL_UNSIGNED_SHORT:

-			return sizeof(unsigned short);

-		case GL_UNSIGNED_INT:

-		case GL_UNSIGNED_INT_24_8_OES:

-			return sizeof(unsigned int);

-		case GL_FLOAT:

-			switch(format)

-			{

-			case GL_ALPHA:           return sizeof(float);

-			case GL_LUMINANCE:       return sizeof(float);

-			case GL_LUMINANCE_ALPHA: return sizeof(float) * 2;

-			case GL_RGB:             return sizeof(float) * 3;

-			case GL_RGBA:            return sizeof(float) * 4;

-			default: UNREACHABLE();

-			}

-			break;

-		case GL_HALF_FLOAT_OES:

-			switch(format)

-			{

-			case GL_ALPHA:           return sizeof(unsigned short);

-			case GL_LUMINANCE:       return sizeof(unsigned short);

-			case GL_LUMINANCE_ALPHA: return sizeof(unsigned short) * 2;

-			case GL_RGB:             return sizeof(unsigned short) * 3;

-			case GL_RGBA:            return sizeof(unsigned short) * 4;

-			default: UNREACHABLE();

-			}

-			break;

-		default: UNREACHABLE();

-		}

-

-		return 0;

-	}

-

 	bool IsCubemapTextureTarget(GLenum target)

 	{

 		return (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z);

diff --git a/src/OpenGL/libGLESv2/utilities.h b/src/OpenGL/libGLESv2/utilities.h
index 3404648..66b5c4f 100644
--- a/src/OpenGL/libGLESv2/utilities.h
+++ b/src/OpenGL/libGLESv2/utilities.h
@@ -15,7 +15,7 @@
 #define LIBGLESV2_UTILITIES_H

 

 #include "Device.hpp"

-#include "Image.hpp"

+#include "common/Image.hpp"

 #include "Texture.h"

 

 #define GL_APICALL

@@ -36,10 +36,6 @@
 

 	int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsigned int bitsSize);

 

-	int ComputePixelSize(GLenum format, GLenum type);

-	GLsizei ComputePitch(GLsizei width, GLenum format, GLenum type, GLint alignment);

-	GLsizei ComputeCompressedPitch(GLsizei width, GLenum format);

-	GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format);

 	bool IsCompressed(GLenum format);

 	bool IsDepthTexture(GLenum format);

 	bool IsStencilTexture(GLenum format);