Update SwiftShader to April code dump.

April code dump from Transgaming. Adds new shader compiler.
diff --git a/src/Renderer/Blitter.cpp b/src/Renderer/Blitter.cpp
index bdd282c..2d709ca 100644
--- a/src/Renderer/Blitter.cpp
+++ b/src/Renderer/Blitter.cpp
@@ -1,6 +1,6 @@
 // SwiftShader Software Renderer
 //
-// Copyright(c) 2005-2011 TransGaming Inc.
+// Copyright(c) 2005-2012 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
@@ -12,7 +12,7 @@
 #include "Blitter.hpp"
 
 #include "Common/Debug.hpp"
-#include "Reactor/Shell.hpp"
+#include "Reactor/Reactor.hpp"
 
 namespace sw
 {
@@ -33,19 +33,19 @@
 			return;
 		}
 
-		source->lockInternal(sRect.left, sRect.top, 0, sw::LOCK_READONLY, sw::PUBLIC);
-		dest->lockInternal(dRect.left, dRect.top, 0, sw::LOCK_WRITEONLY, sw::PUBLIC);
+		source->lockInternal(sRect.x0, sRect.y0, 0, sw::LOCK_READONLY, sw::PUBLIC);
+		dest->lockInternal(dRect.x0, dRect.y0, 0, sw::LOCK_WRITEONLY, sw::PUBLIC);
 
-		float w = 1.0f / (dRect.right - dRect.left) * (sRect.right - sRect.left);
-		float h = 1.0f / (dRect.bottom - dRect.top) * (sRect.bottom - sRect.top);
+		float w = 1.0f / (dRect.x1 - dRect.x0) * (sRect.x1 - sRect.x0);
+		float h = 1.0f / (dRect.y1 - dRect.y0) * (sRect.y1 - sRect.y0);
 
-		float y = (float)sRect.top + 0.5f * h;
+		float y = (float)sRect.y0 + 0.5f * h;
 
-		for(int j = dRect.top; j < dRect.bottom; j++)
+		for(int j = dRect.y0; j < dRect.y1; j++)
 		{
-			float x = (float)sRect.left + 0.5f * w;
+			float x = (float)sRect.x0 + 0.5f * w;
 
-			for(int i = dRect.left; i < dRect.right; i++)
+			for(int i = dRect.x0; i < dRect.x1; i++)
 			{
 				sw::Color<float> color;
 
@@ -137,21 +137,21 @@
 				Float w = *Pointer<Float>(blit + OFFSET(BlitData,w));
 				Float h = *Pointer<Float>(blit + OFFSET(BlitData,h));
 
-				Int top = *Pointer<Int>(blit + OFFSET(BlitData,top));
-				Int bottom = *Pointer<Int>(blit + OFFSET(BlitData,bottom));
-				Int left = *Pointer<Int>(blit + OFFSET(BlitData,left));
-				Int right = *Pointer<Int>(blit + OFFSET(BlitData,right));
+				Int x0d = *Pointer<Int>(blit + OFFSET(BlitData,x0d));
+				Int x1d = *Pointer<Int>(blit + OFFSET(BlitData,x1d));
+				Int y0d = *Pointer<Int>(blit + OFFSET(BlitData,y0d));
+				Int y1d = *Pointer<Int>(blit + OFFSET(BlitData,y1d));
 
-				Int width = *Pointer<Int>(blit + OFFSET(BlitData,width));
-				Int height = *Pointer<Int>(blit + OFFSET(BlitData,height));
+				Int sWidth = *Pointer<Int>(blit + OFFSET(BlitData,sWidth));
+				Int sHeight = *Pointer<Int>(blit + OFFSET(BlitData,sHeight));
 
 				Float y = y0;
 
-				For(Int j = top, j < bottom, j++)
+				For(Int j = y0d, j < y1d, j++)
 				{
 					Float x = x0;
 
-					For(Int i = left, i < right, i++)
+					For(Int i = x0d, i < x1d, i++)
 					{
 						Float4 color;
 
@@ -172,14 +172,11 @@
 							Float x0 = x - Float(0.5f);
 							Float y0 = y - Float(0.5f);
 
-							Int X0 = Int(x0);
-							Int Y0 = Int(y0);
-
-							X0 = IfThenElse(X0 < 0, Int(0), X0);
-							Y0 = IfThenElse(Y0 < 0, Int(0), Y0);
-
-							Int X1 = IfThenElse(X0 + 1 >= width, X0, X0 + 1);
-							Int Y1 = IfThenElse(Y0 + 1 >= height, Y0, Y0 + 1);
+							Int X0 = Max(Int(x0), 0);
+							Int Y0 = Max(Int(y0), 0);
+							
+							Int X1 = IfThenElse(X0 + 1 >= sWidth, X0, X0 + 1);
+							Int Y1 = IfThenElse(Y0 + 1 >= sHeight, Y0, Y0 + 1);
 
 							Pointer<Byte> s00 = source + Y0 * sPitchB + X0 * Surface::bytes(state.sourceFormat);
 							Pointer<Byte> s01 = source + Y0 * sPitchB + X1 * Surface::bytes(state.sourceFormat);
@@ -322,18 +319,18 @@
 		data.sPitchB = source->getInternalPitchB();
 		data.dPitchB = dest->getInternalPitchB();
 
-		data.w = 1.0f / (dRect.right - dRect.left) * (sRect.right - sRect.left);
-		data.h = 1.0f / (dRect.bottom - dRect.top) * (sRect.bottom - sRect.top);
-		data.x0 = (float)sRect.left + 0.5f * data.w;
-		data.y0 = (float)sRect.top + 0.5f * data.h;
+		data.w = 1.0f / (dRect.x1 - dRect.x0) * (sRect.x1 - sRect.x0);
+		data.h = 1.0f / (dRect.y1 - dRect.y0) * (sRect.y1 - sRect.y0);
+		data.x0 = (float)sRect.x0 + 0.5f * data.w;
+		data.y0 = (float)sRect.y0 + 0.5f * data.h;
 		
-		data.top = dRect.top;
-		data.bottom = dRect.bottom;
-		data.left = dRect.left;
-		data.right = dRect.right;
+		data.x0d = dRect.x0;
+		data.x1d = dRect.x1;
+		data.y0d = dRect.y0;
+		data.y1d = dRect.y1;
 
-		data.width = source->getInternalWidth();
-		data.height = source->getInternalHeight();
+		data.sWidth = source->getInternalWidth();
+		data.sHeight = source->getInternalHeight();
 
 		blitFunction(&data);
 
diff --git a/src/Renderer/Blitter.hpp b/src/Renderer/Blitter.hpp
index 6eda305..8d9554d 100644
--- a/src/Renderer/Blitter.hpp
+++ b/src/Renderer/Blitter.hpp
@@ -1,6 +1,6 @@
 // SwiftShader Software Renderer

 //

-// Copyright(c) 2005-2011 TransGaming Inc.

+// Copyright(c) 2005-2012 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

@@ -57,13 +57,13 @@
 			float w;

 			float h;

 

-			int top;

-			int bottom;

-			int left;

-			int right;

+			int y0d;

+			int y1d;

+			int x0d;

+			int x1d;

 

-			int width;

-			int height;

+			int sWidth;

+			int sHeight;

 		};

 

 		LRUCache<BlitState, Routine> *blitCache;

diff --git a/src/Renderer/Clipper.cpp b/src/Renderer/Clipper.cpp
index 2c6c158..38918c9 100644
--- a/src/Renderer/Clipper.cpp
+++ b/src/Renderer/Clipper.cpp
@@ -1,6 +1,6 @@
 // SwiftShader Software Renderer
 //
-// Copyright(c) 2005-2011 TransGaming Inc.
+// Copyright(c) 2005-2012 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
@@ -167,8 +167,8 @@
 		{
 			int j = i == polygon.n - 1 ? 0 : i + 1;
 
-			float di = V[i]->w + (V[i]->x + data.offX[0] * V[i]->w);
-			float dj = V[j]->w + (V[j]->x + data.offX[0] * V[j]->w);
+			float di = V[i]->w + (V[i]->x + data.halfPixelX[0] * V[i]->w);
+			float dj = V[j]->w + (V[j]->x + data.halfPixelX[0] * V[j]->w);
 
 			if(di >= 0)
 			{
@@ -209,8 +209,8 @@
 		{
 			int j = i == polygon.n - 1 ? 0 : i + 1;
 
-			float di = V[i]->w - (V[i]->x + data.offX[0] * V[i]->w);
-			float dj = V[j]->w - (V[j]->x + data.offX[0] * V[j]->w);
+			float di = V[i]->w - (V[i]->x + data.halfPixelX[0] * V[i]->w);
+			float dj = V[j]->w - (V[j]->x + data.halfPixelX[0] * V[j]->w);
 
 			if(di >= 0)
 			{
@@ -251,8 +251,8 @@
 		{
 			int j = i == polygon.n - 1 ? 0 : i + 1;
 
-			float di = V[i]->w - (V[i]->y + data.offY[0] * V[i]->w);
-			float dj = V[j]->w - (V[j]->y + data.offY[0] * V[j]->w);
+			float di = V[i]->w - (V[i]->y + data.halfPixelY[0] * V[i]->w);
+			float dj = V[j]->w - (V[j]->y + data.halfPixelY[0] * V[j]->w);
 
 			if(di >= 0)
 			{
@@ -293,8 +293,8 @@
 		{
 			int j = i == polygon.n - 1 ? 0 : i + 1;
 
-			float di = V[i]->w + (V[i]->y + data.offY[0] * V[i]->w);
-			float dj = V[j]->w + (V[j]->y + data.offY[0] * V[j]->w);
+			float di = V[i]->w + (V[i]->y + data.halfPixelY[0] * V[i]->w);
+			float dj = V[j]->w + (V[j]->y + data.halfPixelY[0] * V[j]->w);
 
 			if(di >= 0)
 			{
diff --git a/src/Renderer/Clipper.hpp b/src/Renderer/Clipper.hpp
index fca7b0c..de017b8 100644
--- a/src/Renderer/Clipper.hpp
+++ b/src/Renderer/Clipper.hpp
@@ -1,66 +1,66 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2011 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 sw_Clipper_hpp
-#define sw_Clipper_hpp
-
-#include "Plane.hpp"
-#include "Common/Types.hpp"
-
-namespace sw
-{
-	struct Polygon;
-	struct DrawCall;
-	struct DrawData;
-
-	class Clipper
-	{
-	public:
-		enum ClipFlags
-		{
-			CLIP_RIGHT  = 1 << 0,
-			CLIP_TOP    = 1 << 1,
-			CLIP_FAR    = 1 << 2,
-			CLIP_LEFT   = 1 << 3,
-			CLIP_BOTTOM = 1 << 4,
-			CLIP_NEAR   = 1 << 5,
-
-			CLIP_FINITE = 1 << 7,
-
-			// User-defined clipping planes
-			CLIP_PLANE0	= 1 << 8,
-			CLIP_PLANE1	= 1 << 9,
-			CLIP_PLANE2	= 1 << 10,
-			CLIP_PLANE3	= 1 << 11,
-			CLIP_PLANE4	= 1 << 12,
-			CLIP_PLANE5	= 1 << 13
-		};
-
-		Clipper();
-
-		~Clipper();
-
-		bool clip(Polygon &polygon, int clipFlagsOr, const DrawCall &draw);
-
-	private:
-		void clipNear(Polygon &polygon);
-		void clipFar(Polygon &polygon);
-		void clipLeft(Polygon &polygon, const DrawData &data);
-		void clipRight(Polygon &polygon, const DrawData &data);
-		void clipTop(Polygon &polygon, const DrawData &data);
-		void clipBottom(Polygon &polygon, const DrawData &data);
-		void clipPlane(Polygon &polygon, const Plane &plane);
-
-		void clipEdge(float4 &Vo, const float4 &Vi, const float4 &Vj, float di, float dj) const;
-	};
-}
-
-#endif   // sw_Clipper_hpp
+// SwiftShader Software Renderer

+//

+// Copyright(c) 2005-2011 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 sw_Clipper_hpp

+#define sw_Clipper_hpp

+

+#include "Plane.hpp"

+#include "Common/Types.hpp"

+

+namespace sw

+{

+	struct Polygon;

+	struct DrawCall;

+	struct DrawData;

+

+	class Clipper

+	{

+	public:

+		enum ClipFlags

+		{

+			CLIP_RIGHT  = 1 << 0,

+			CLIP_TOP    = 1 << 1,

+			CLIP_FAR    = 1 << 2,

+			CLIP_LEFT   = 1 << 3,

+			CLIP_BOTTOM = 1 << 4,

+			CLIP_NEAR   = 1 << 5,

+

+			CLIP_FINITE = 1 << 7,

+

+			// User-defined clipping planes

+			CLIP_PLANE0	= 1 << 8,

+			CLIP_PLANE1	= 1 << 9,

+			CLIP_PLANE2	= 1 << 10,

+			CLIP_PLANE3	= 1 << 11,

+			CLIP_PLANE4	= 1 << 12,

+			CLIP_PLANE5	= 1 << 13

+		};

+

+		Clipper();

+

+		~Clipper();

+

+		bool clip(Polygon &polygon, int clipFlagsOr, const DrawCall &draw);

+

+	private:

+		void clipNear(Polygon &polygon);

+		void clipFar(Polygon &polygon);

+		void clipLeft(Polygon &polygon, const DrawData &data);

+		void clipRight(Polygon &polygon, const DrawData &data);

+		void clipTop(Polygon &polygon, const DrawData &data);

+		void clipBottom(Polygon &polygon, const DrawData &data);

+		void clipPlane(Polygon &polygon, const Plane &plane);

+

+		void clipEdge(float4 &Vo, const float4 &Vi, const float4 &Vj, float di, float dj) const;

+	};

+}

+

+#endif   // sw_Clipper_hpp

diff --git a/src/Renderer/Color.hpp b/src/Renderer/Color.hpp
index 786e897..febfb08 100644
--- a/src/Renderer/Color.hpp
+++ b/src/Renderer/Color.hpp
@@ -1,443 +1,443 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2011 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 sw_Color_hpp
-#define sw_Color_hpp
-
-#include "Common/Types.hpp"
-#include "Common/Math.hpp"
-
-namespace sw
-{
-	template<class T>
-	struct Color
-	{
-		Color();
-		
-		Color(const Color<byte> &c);
-		Color(const Color<short> &c);
-		Color(const Color<float> &c);
-		
-		Color(int c);
-		Color(unsigned short c);
-		Color(unsigned long c);
-		Color(unsigned int c);
-		
-		Color(T r, T g, T b, T a = 1);
-
-		operator unsigned int() const;
-
-		T &operator[](int i);
-		const T &operator[](int i) const;
-
-		Color operator+() const;
-		Color operator-() const;
-
-		Color& operator=(const Color& c);
-
-		Color &operator+=(const Color &c);
-		Color &operator*=(float l);
-
-		static Color gradient(const Color &c1, const Color  &c2, float d);
-		static Color shade(const Color &c1, const Color  &c2, float d);
-
-		template<class T>
-		friend Color operator+(const Color &c1, const Color &c2);
-		template<class T>
-		friend Color operator-(const Color &c1, const Color &c2);
-
-		template<class T>
-		friend Color operator*(float l, const Color &c);
-		template<class T>
-		friend Color operator*(const Color &c1, const Color &c2);
-		template<class T>
-		friend Color operator/(const Color &c, float l);
-
-		T r;
-		T g;
-		T b;
-		T a;
-	};
-}
-
-#include "Common/Math.hpp"
-
-namespace sw
-{
-	template<class T>
-	inline Color<T>::Color()
-	{
-	}
-
-	inline Color<byte>::Color(const Color<byte> &c)
-	{
-		r = c.r;
-		g = c.g;
-		b = c.b;
-		a = c.a;
-	}
-
-	inline Color<byte>::Color(const Color<short> &c)
-	{
-		r = clamp(c.r >> 4, 0, 255);
-		g = clamp(c.g >> 4, 0, 255);
-		b = clamp(c.b >> 4, 0, 255);
-		a = clamp(c.a >> 4, 0, 255);
-	}
-
-	inline Color<byte>::Color(const Color<float> &c)
-	{
-		r = ifloor(clamp(c.r * 256.0f, 0.0f, 255.0f));
-		g = ifloor(clamp(c.g * 256.0f, 0.0f, 255.0f));
-		b = ifloor(clamp(c.b * 256.0f, 0.0f, 255.0f));
-		a = ifloor(clamp(c.a * 256.0f, 0.0f, 255.0f));
-	}
-
-	inline Color<short>::Color(const Color<short> &c)
-	{
-		r = c.r;
-		g = c.g;
-		b = c.b;
-		a = c.a;
-	}
-
-	inline Color<short>::Color(const Color<byte> &c)
-	{
-		r = c.r << 4;
-		g = c.g << 4;
-		b = c.b << 4;
-		a = c.a << 4;
-	}
-
-	inline Color<float>::Color(const Color<float> &c)
-	{
-		r = c.r;
-		g = c.g;
-		b = c.b;
-		a = c.a;
-	}
-
-	inline Color<short>::Color(const Color<float> &c)
-	{
-		r = iround(clamp(c.r * 4095.0f, -4096.0f, 4095.0f));
-		g = iround(clamp(c.g * 4095.0f, -4096.0f, 4095.0f));
-		b = iround(clamp(c.b * 4095.0f, -4096.0f, 4095.0f));
-		a = iround(clamp(c.a * 4095.0f, -4096.0f, 4095.0f));
-	}
-
-	inline Color<float>::Color(const Color<byte> &c)
-	{
-		r = c.r / 255.0f;
-		g = c.g / 255.0f;
-		b = c.b / 255.0f;
-		a = c.a / 255.0f;
-	}
-
-	inline Color<float>::Color(const Color<short> &c)
-	{
-		r = c.r / 4095.0f;
-		g = c.g / 4095.0f;
-		b = c.b / 4095.0f;
-		a = c.a / 4095.0f;
-	}
-
-	inline Color<float>::Color(unsigned short c)
-	{
-		r = (float)(c & 0xF800) / (float)0xF800;
-		g = (float)(c & 0x07E0) / (float)0x07E0;
-		b = (float)(c & 0x001F) / (float)0x001F;
-		a = 1;
-	}
-
-	inline Color<short>::Color(unsigned short c)
-	{
-		// 4.12 fixed-point format
-		r = ((c & 0xF800) >> 4) + ((c & 0xF800) >> 9) + ((c & 0xF800) >> 14);
-		g = ((c & 0x07E0) << 1) + ((c & 0x07E0) >> 5);
-		b = ((c & 0x001F) << 7) + ((c & 0x001F) << 2) + ((c & 0x001F) >> 3);
-		a = 0x1000;
-	}
-
-	inline Color<byte>::Color(unsigned short c)
-	{
-		r = (byte)(((c & 0xF800) >> 8) + ((c & 0xE000) >> 13));
-		g = (byte)(((c & 0x07E0) >> 3) + ((c & 0x0600) >> 9));
-		b = (byte)(((c & 0x001F) << 3) + ((c & 0x001C) >> 2));
-		a = 0xFF;
-	}
-
-	inline Color<float>::Color(int c)
-	{
-		const float d = 1.0f / 255.0f;
-
-		r = (float)((c & 0x00FF0000) >> 16) * d;
-		g = (float)((c & 0x0000FF00) >> 8) * d;
-		b = (float)((c & 0x000000FF) >> 0) * d;
-		a = (float)((c & 0xFF000000) >> 24) * d;
-	}
-
-	inline Color<short>::Color(int c)
-	{
-		// 4.12 fixed-point format
-		r = (short)((c & 0x00FF0000) >> 12);
-		g = (short)((c & 0x0000FF00) >> 4);
-		b = (short)((c & 0x000000FF) << 4);
-		a = (short)((c & 0xFF000000) >> 20);
-	}
-
-	inline Color<byte>::Color(int c)
-	{
-		r = (byte)((c & 0x00FF0000) >> 16);
-		g = (byte)((c & 0x0000FF00) >> 8);
-		b = (byte)((c & 0x000000FF) >> 0);
-		a = (byte)((c & 0xFF000000) >> 24);
-	}
-
-	inline Color<float>::Color(unsigned int c)
-	{
-		const float d = 1.0f / 255.0f;
-
-		r = (float)((c & 0x00FF0000) >> 16) * d;
-		g = (float)((c & 0x0000FF00) >> 8) * d;
-		b = (float)((c & 0x000000FF) >> 0) * d;
-		a = (float)((c & 0xFF000000) >> 24) * d;
-	}
-
-	inline Color<short>::Color(unsigned int c)
-	{
-		// 4.12 fixed-point format
-		r = (short)((c & 0x00FF0000) >> 12);
-		g = (short)((c & 0x0000FF00) >> 4);
-		b = (short)((c & 0x000000FF) << 4);
-		a = (short)((c & 0xFF000000) >> 20);
-	}
-
-	inline Color<byte>::Color(unsigned int c)
-	{
-		r = (byte)((c & 0x00FF0000) >> 16);
-		g = (byte)((c & 0x0000FF00) >> 8);
-		b = (byte)((c & 0x000000FF) >> 0);
-		a = (byte)((c & 0xFF000000) >> 24);
-	}
-
-	inline Color<float>::Color(unsigned long c)
-	{
-		const float d = 1.0f / 255.0f;
-
-		r = (float)((c & 0x00FF0000) >> 16) * d;
-		g = (float)((c & 0x0000FF00) >> 8) * d;
-		b = (float)((c & 0x000000FF) >> 0) * d;
-		a = (float)((c & 0xFF000000) >> 24) * d;
-	}
-
-	inline Color<short>::Color(unsigned long c)
-	{
-		// 4.12 fixed-point format
-		r = (short)((c & 0x00FF0000) >> 12);
-		g = (short)((c & 0x0000FF00) >> 4);
-		b = (short)((c & 0x000000FF) << 4);
-		a = (short)((c & 0xFF000000) >> 20);
-	}
-
-	inline Color<byte>::Color(unsigned long c)
-	{
-		r = (byte)((c & 0x00FF0000) >> 16);
-		g = (byte)((c & 0x0000FF00) >> 8);
-		b = (byte)((c & 0x000000FF) >> 0);
-		a = (byte)((c & 0xFF000000) >> 24);
-	}
-
-	template<class T>
-	inline Color<T>::Color(T r_, T g_, T b_, T a_)
-	{
-		r = r_;
-		g = g_;
-		b = b_;
-		a = a_;
-	}
-
-	inline Color<float>::operator unsigned int() const
-	{
-		return ((unsigned int)min(b * 255.0f, 255.0f) << 0) |
-		       ((unsigned int)min(g * 255.0f, 255.0f) << 8) |
-		       ((unsigned int)min(r * 255.0f, 255.0f) << 16) |
-		       ((unsigned int)min(a * 255.0f, 255.0f) << 24);
-	}
-
-	inline Color<short>::operator unsigned int() const
-	{
-		return ((unsigned int)min(b >> 4, 255) << 0) |
-		       ((unsigned int)min(g >> 4, 255) << 8) |
-		       ((unsigned int)min(r >> 4, 255) << 16) |
-		       ((unsigned int)min(a >> 4, 255) << 24);
-	}
-
-	inline Color<byte>::operator unsigned int() const
-	{
-		return (b << 0) +
-		       (g << 8) +
-		       (r << 16) +
-			   (a << 24);
-	}
-
-	template<class T>
-	inline T &Color<T>::operator[](int i)
-	{
-		return (&r)[i];
-	}
-
-	template<class T>
-	inline const T &Color<T>::operator[](int i) const
-	{
-		return (&r)[i];
-	}
-
-	template<class T>
-	inline Color<T> Color<T>::operator+() const
-	{
-		return *this;
-	}
-
-	template<class T>
-	inline Color<T> Color<T>::operator-() const
-	{
-		return Color(-r, -g, -b, -a);
-	}
-
-	template<class T>
-	inline Color<T> &Color<T>::operator=(const Color& c)
-	{
-		r = c.r;
-		g = c.g;
-		b = c.b;
-		a = c.a;
-
-		return *this;
-	}
-
-	template<class T>
-	inline Color<T> &Color<T>::operator+=(const Color &c)
-	{
-		r += c.r;
-		g += c.g;
-		b += c.b;
-		a += c.a;
-
-		return *this;
-	}
-
-	template<class T>
-	inline Color<T> &Color<T>::operator*=(float l)
-	{
-		*this = l * *this;
-
-		return *this;
-	}
-
-	template<class T>
-	inline Color<T> operator+(const Color<T> &c1, const Color<T> &c2)
-	{
-		return Color<T>(c1.r + c2.r,
-		                c1.g + c2.g,
-		                c1.b + c2.b,
-		                c1.a + c2.a);	
-	}
-
-	template<class T>
-	inline Color<T> operator-(const Color<T> &c1, const Color<T> &c2)
-	{
-		return Color<T>(c1.r - c2.r,
-		                c1.g - c2.g,
-		                c1.b - c2.b,
-		                c1.a - c2.a);	
-	}
-
-	template<class T>
-	inline Color<T> operator*(float l, const Color<T> &c)
-	{
-		T r = (T)(l * c.r);
-		T g = (T)(l * c.g);
-		T b = (T)(l * c.b);
-		T a = (T)(l * c.a);
-
-		return Color<T>(r, g, b, a);
-	}
-
-	template<class T>
-	inline Color<T> operator*(const Color<T> &c1, const Color<T> &c2)
-	{
-		T r = c1.r * c2.r;
-		T g = c1.g * c2.g;
-		T b = c1.b * c2.b;
-		T a = c1.a * c2.a;
-
-		return Color<T>(r, g, b, a);
-	}
-
-	inline Color<short> operator*(const Color<short> &c1, const Color<short> &c2)
-	{
-		short r = c1.r * c2.r >> 12;
-		short g = c1.g * c2.g >> 12;
-		short b = c1.b * c2.b >> 12;
-		short a = c1.a * c2.a >> 12;
-
-		return Color<short>(r, g, b, a);
-	}
-
-	inline Color<byte> operator*(const Color<byte> &c1, const Color<byte> &c2)
-	{
-		byte r = c1.r * c2.r >> 8;
-		byte g = c1.g * c2.g >> 8;
-		byte b = c1.b * c2.b >> 8;
-		byte a = c1.a * c2.a >> 8;
-
-		return Color<byte>(r, g, b, a);
-	}
-
-	template<class T>
-	inline Color<T> operator/(const Color<T> &c, float l)
-	{
-		l = 1.0f / l; 
-
-		T r = (T)(l * c.r);
-		T g = (T)(l * c.g);
-		T b = (T)(l * c.b);
-		T a = (T)(l * c.a);
-
-		return Color<T>(r, g, b, a);
-	}
-
-	template<class T>
-	inline Color<T> Color<T>::gradient(const Color<T> &c1, const Color<T> &c2, float d)
-	{
-		d = 1.0f / d; 
-
-		T r = (c2.r - c1.r) * d;
-		T g = (c2.g - c1.g) * d;
-		T b = (c2.b - c1.b) * d;
-		T a = (c2.a - c1.a) * d;
-
-		return Color<T>(r, g, b, a);
-	}
-
-	template<class T>
-	inline Color<T> Color<T>::shade(const Color<T> &c1, const Color<T>  &c2, float d)
-	{
-		T r = c1.r + (T)(d * (c2.r - c1.r));
-		T g = c1.g + (T)(d * (c2.g - c1.g));
-		T b = c1.b + (T)(d * (c2.b - c1.b));
-		T a = c1.a + (T)(d * (c2.a - c1.a));
-
-		return Color<T>(r, g, b, a);
-	}
-}
-
-#endif   // sw_Color_hpp
+// SwiftShader Software Renderer

+//

+// Copyright(c) 2005-2011 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 sw_Color_hpp

+#define sw_Color_hpp

+

+#include "Common/Types.hpp"

+#include "Common/Math.hpp"

+

+namespace sw

+{

+	template<class T>

+	struct Color

+	{

+		Color();

+		

+		Color(const Color<byte> &c);

+		Color(const Color<short> &c);

+		Color(const Color<float> &c);

+		

+		Color(int c);

+		Color(unsigned short c);

+		Color(unsigned long c);

+		Color(unsigned int c);

+		

+		Color(T r, T g, T b, T a = 1);

+

+		operator unsigned int() const;

+

+		T &operator[](int i);

+		const T &operator[](int i) const;

+

+		Color operator+() const;

+		Color operator-() const;

+

+		Color& operator=(const Color& c);

+

+		Color &operator+=(const Color &c);

+		Color &operator*=(float l);

+

+		static Color gradient(const Color &c1, const Color  &c2, float d);

+		static Color shade(const Color &c1, const Color  &c2, float d);

+

+		template<class T>

+		friend Color operator+(const Color &c1, const Color &c2);

+		template<class T>

+		friend Color operator-(const Color &c1, const Color &c2);

+

+		template<class T>

+		friend Color operator*(float l, const Color &c);

+		template<class T>

+		friend Color operator*(const Color &c1, const Color &c2);

+		template<class T>

+		friend Color operator/(const Color &c, float l);

+

+		T r;

+		T g;

+		T b;

+		T a;

+	};

+}

+

+#include "Common/Math.hpp"

+

+namespace sw

+{

+	template<class T>

+	inline Color<T>::Color()

+	{

+	}

+

+	inline Color<byte>::Color(const Color<byte> &c)

+	{

+		r = c.r;

+		g = c.g;

+		b = c.b;

+		a = c.a;

+	}

+

+	inline Color<byte>::Color(const Color<short> &c)

+	{

+		r = clamp(c.r >> 4, 0, 255);

+		g = clamp(c.g >> 4, 0, 255);

+		b = clamp(c.b >> 4, 0, 255);

+		a = clamp(c.a >> 4, 0, 255);

+	}

+

+	inline Color<byte>::Color(const Color<float> &c)

+	{

+		r = ifloor(clamp(c.r * 256.0f, 0.0f, 255.0f));

+		g = ifloor(clamp(c.g * 256.0f, 0.0f, 255.0f));

+		b = ifloor(clamp(c.b * 256.0f, 0.0f, 255.0f));

+		a = ifloor(clamp(c.a * 256.0f, 0.0f, 255.0f));

+	}

+

+	inline Color<short>::Color(const Color<short> &c)

+	{

+		r = c.r;

+		g = c.g;

+		b = c.b;

+		a = c.a;

+	}

+

+	inline Color<short>::Color(const Color<byte> &c)

+	{

+		r = c.r << 4;

+		g = c.g << 4;

+		b = c.b << 4;

+		a = c.a << 4;

+	}

+

+	inline Color<float>::Color(const Color<float> &c)

+	{

+		r = c.r;

+		g = c.g;

+		b = c.b;

+		a = c.a;

+	}

+

+	inline Color<short>::Color(const Color<float> &c)

+	{

+		r = iround(clamp(c.r * 4095.0f, -4096.0f, 4095.0f));

+		g = iround(clamp(c.g * 4095.0f, -4096.0f, 4095.0f));

+		b = iround(clamp(c.b * 4095.0f, -4096.0f, 4095.0f));

+		a = iround(clamp(c.a * 4095.0f, -4096.0f, 4095.0f));

+	}

+

+	inline Color<float>::Color(const Color<byte> &c)

+	{

+		r = c.r / 255.0f;

+		g = c.g / 255.0f;

+		b = c.b / 255.0f;

+		a = c.a / 255.0f;

+	}

+

+	inline Color<float>::Color(const Color<short> &c)

+	{

+		r = c.r / 4095.0f;

+		g = c.g / 4095.0f;

+		b = c.b / 4095.0f;

+		a = c.a / 4095.0f;

+	}

+

+	inline Color<float>::Color(unsigned short c)

+	{

+		r = (float)(c & 0xF800) / (float)0xF800;

+		g = (float)(c & 0x07E0) / (float)0x07E0;

+		b = (float)(c & 0x001F) / (float)0x001F;

+		a = 1;

+	}

+

+	inline Color<short>::Color(unsigned short c)

+	{

+		// 4.12 fixed-point format

+		r = ((c & 0xF800) >> 4) + ((c & 0xF800) >> 9) + ((c & 0xF800) >> 14);

+		g = ((c & 0x07E0) << 1) + ((c & 0x07E0) >> 5);

+		b = ((c & 0x001F) << 7) + ((c & 0x001F) << 2) + ((c & 0x001F) >> 3);

+		a = 0x1000;

+	}

+

+	inline Color<byte>::Color(unsigned short c)

+	{

+		r = (byte)(((c & 0xF800) >> 8) + ((c & 0xE000) >> 13));

+		g = (byte)(((c & 0x07E0) >> 3) + ((c & 0x0600) >> 9));

+		b = (byte)(((c & 0x001F) << 3) + ((c & 0x001C) >> 2));

+		a = 0xFF;

+	}

+

+	inline Color<float>::Color(int c)

+	{

+		const float d = 1.0f / 255.0f;

+

+		r = (float)((c & 0x00FF0000) >> 16) * d;

+		g = (float)((c & 0x0000FF00) >> 8) * d;

+		b = (float)((c & 0x000000FF) >> 0) * d;

+		a = (float)((c & 0xFF000000) >> 24) * d;

+	}

+

+	inline Color<short>::Color(int c)

+	{

+		// 4.12 fixed-point format

+		r = (short)((c & 0x00FF0000) >> 12);

+		g = (short)((c & 0x0000FF00) >> 4);

+		b = (short)((c & 0x000000FF) << 4);

+		a = (short)((c & 0xFF000000) >> 20);

+	}

+

+	inline Color<byte>::Color(int c)

+	{

+		r = (byte)((c & 0x00FF0000) >> 16);

+		g = (byte)((c & 0x0000FF00) >> 8);

+		b = (byte)((c & 0x000000FF) >> 0);

+		a = (byte)((c & 0xFF000000) >> 24);

+	}

+

+	inline Color<float>::Color(unsigned int c)

+	{

+		const float d = 1.0f / 255.0f;

+

+		r = (float)((c & 0x00FF0000) >> 16) * d;

+		g = (float)((c & 0x0000FF00) >> 8) * d;

+		b = (float)((c & 0x000000FF) >> 0) * d;

+		a = (float)((c & 0xFF000000) >> 24) * d;

+	}

+

+	inline Color<short>::Color(unsigned int c)

+	{

+		// 4.12 fixed-point format

+		r = (short)((c & 0x00FF0000) >> 12);

+		g = (short)((c & 0x0000FF00) >> 4);

+		b = (short)((c & 0x000000FF) << 4);

+		a = (short)((c & 0xFF000000) >> 20);

+	}

+

+	inline Color<byte>::Color(unsigned int c)

+	{

+		r = (byte)((c & 0x00FF0000) >> 16);

+		g = (byte)((c & 0x0000FF00) >> 8);

+		b = (byte)((c & 0x000000FF) >> 0);

+		a = (byte)((c & 0xFF000000) >> 24);

+	}

+

+	inline Color<float>::Color(unsigned long c)

+	{

+		const float d = 1.0f / 255.0f;

+

+		r = (float)((c & 0x00FF0000) >> 16) * d;

+		g = (float)((c & 0x0000FF00) >> 8) * d;

+		b = (float)((c & 0x000000FF) >> 0) * d;

+		a = (float)((c & 0xFF000000) >> 24) * d;

+	}

+

+	inline Color<short>::Color(unsigned long c)

+	{

+		// 4.12 fixed-point format

+		r = (short)((c & 0x00FF0000) >> 12);

+		g = (short)((c & 0x0000FF00) >> 4);

+		b = (short)((c & 0x000000FF) << 4);

+		a = (short)((c & 0xFF000000) >> 20);

+	}

+

+	inline Color<byte>::Color(unsigned long c)

+	{

+		r = (byte)((c & 0x00FF0000) >> 16);

+		g = (byte)((c & 0x0000FF00) >> 8);

+		b = (byte)((c & 0x000000FF) >> 0);

+		a = (byte)((c & 0xFF000000) >> 24);

+	}

+

+	template<class T>

+	inline Color<T>::Color(T r_, T g_, T b_, T a_)

+	{

+		r = r_;

+		g = g_;

+		b = b_;

+		a = a_;

+	}

+

+	inline Color<float>::operator unsigned int() const

+	{

+		return ((unsigned int)min(b * 255.0f, 255.0f) << 0) |

+		       ((unsigned int)min(g * 255.0f, 255.0f) << 8) |

+		       ((unsigned int)min(r * 255.0f, 255.0f) << 16) |

+		       ((unsigned int)min(a * 255.0f, 255.0f) << 24);

+	}

+

+	inline Color<short>::operator unsigned int() const

+	{

+		return ((unsigned int)min(b >> 4, 255) << 0) |

+		       ((unsigned int)min(g >> 4, 255) << 8) |

+		       ((unsigned int)min(r >> 4, 255) << 16) |

+		       ((unsigned int)min(a >> 4, 255) << 24);

+	}

+

+	inline Color<byte>::operator unsigned int() const

+	{

+		return (b << 0) +

+		       (g << 8) +

+		       (r << 16) +

+			   (a << 24);

+	}

+

+	template<class T>

+	inline T &Color<T>::operator[](int i)

+	{

+		return (&r)[i];

+	}

+

+	template<class T>

+	inline const T &Color<T>::operator[](int i) const

+	{

+		return (&r)[i];

+	}

+

+	template<class T>

+	inline Color<T> Color<T>::operator+() const

+	{

+		return *this;

+	}

+

+	template<class T>

+	inline Color<T> Color<T>::operator-() const

+	{

+		return Color(-r, -g, -b, -a);

+	}

+

+	template<class T>

+	inline Color<T> &Color<T>::operator=(const Color& c)

+	{

+		r = c.r;

+		g = c.g;

+		b = c.b;

+		a = c.a;

+

+		return *this;

+	}

+

+	template<class T>

+	inline Color<T> &Color<T>::operator+=(const Color &c)

+	{

+		r += c.r;

+		g += c.g;

+		b += c.b;

+		a += c.a;

+

+		return *this;

+	}

+

+	template<class T>

+	inline Color<T> &Color<T>::operator*=(float l)

+	{

+		*this = l * *this;

+

+		return *this;

+	}

+

+	template<class T>

+	inline Color<T> operator+(const Color<T> &c1, const Color<T> &c2)

+	{

+		return Color<T>(c1.r + c2.r,

+		                c1.g + c2.g,

+		                c1.b + c2.b,

+		                c1.a + c2.a);	

+	}

+

+	template<class T>

+	inline Color<T> operator-(const Color<T> &c1, const Color<T> &c2)

+	{

+		return Color<T>(c1.r - c2.r,

+		                c1.g - c2.g,

+		                c1.b - c2.b,

+		                c1.a - c2.a);	

+	}

+

+	template<class T>

+	inline Color<T> operator*(float l, const Color<T> &c)

+	{

+		T r = (T)(l * c.r);

+		T g = (T)(l * c.g);

+		T b = (T)(l * c.b);

+		T a = (T)(l * c.a);

+

+		return Color<T>(r, g, b, a);

+	}

+

+	template<class T>

+	inline Color<T> operator*(const Color<T> &c1, const Color<T> &c2)

+	{

+		T r = c1.r * c2.r;

+		T g = c1.g * c2.g;

+		T b = c1.b * c2.b;

+		T a = c1.a * c2.a;

+

+		return Color<T>(r, g, b, a);

+	}

+

+	inline Color<short> operator*(const Color<short> &c1, const Color<short> &c2)

+	{

+		short r = c1.r * c2.r >> 12;

+		short g = c1.g * c2.g >> 12;

+		short b = c1.b * c2.b >> 12;

+		short a = c1.a * c2.a >> 12;

+

+		return Color<short>(r, g, b, a);

+	}

+

+	inline Color<byte> operator*(const Color<byte> &c1, const Color<byte> &c2)

+	{

+		byte r = c1.r * c2.r >> 8;

+		byte g = c1.g * c2.g >> 8;

+		byte b = c1.b * c2.b >> 8;

+		byte a = c1.a * c2.a >> 8;

+

+		return Color<byte>(r, g, b, a);

+	}

+

+	template<class T>

+	inline Color<T> operator/(const Color<T> &c, float l)

+	{

+		l = 1.0f / l; 

+

+		T r = (T)(l * c.r);

+		T g = (T)(l * c.g);

+		T b = (T)(l * c.b);

+		T a = (T)(l * c.a);

+

+		return Color<T>(r, g, b, a);

+	}

+

+	template<class T>

+	inline Color<T> Color<T>::gradient(const Color<T> &c1, const Color<T> &c2, float d)

+	{

+		d = 1.0f / d; 

+

+		T r = (c2.r - c1.r) * d;

+		T g = (c2.g - c1.g) * d;

+		T b = (c2.b - c1.b) * d;

+		T a = (c2.a - c1.a) * d;

+

+		return Color<T>(r, g, b, a);

+	}

+

+	template<class T>

+	inline Color<T> Color<T>::shade(const Color<T> &c1, const Color<T>  &c2, float d)

+	{

+		T r = c1.r + (T)(d * (c2.r - c1.r));

+		T g = c1.g + (T)(d * (c2.g - c1.g));

+		T b = c1.b + (T)(d * (c2.b - c1.b));

+		T a = c1.a + (T)(d * (c2.a - c1.a));

+

+		return Color<T>(r, g, b, a);

+	}

+}

+

+#endif   // sw_Color_hpp

diff --git a/src/Renderer/Context.cpp b/src/Renderer/Context.cpp
index 12a8398..794a23a 100644
--- a/src/Renderer/Context.cpp
+++ b/src/Renderer/Context.cpp
@@ -1,6 +1,6 @@
 // SwiftShader Software Renderer
 //
-// Copyright(c) 2005-2011 TransGaming Inc.
+// Copyright(c) 2005-2012 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
@@ -26,6 +26,11 @@
 {
 	extern bool perspectiveCorrection;
 
+	bool halfIntegerCoordinates = false;     // Pixel centers are not at integer coordinates
+	bool symmetricNormalizedDepth = false;   // [-1, 1] instead of [0, 1]
+	bool booleanFaceRegister = false;
+	bool fullPixelPositionRegister = false;
+
 	bool forceWindowed = false;
 	bool quadLayoutEnabled = false;
 	bool veryEarlyDepthTest = true;
@@ -193,8 +198,6 @@
 			input[i].defaults();
 		}
 
-		postTransform = false;
-
 		fogStart = 0.0f;
 		fogEnd = 1.0f;
 
@@ -502,7 +505,7 @@
 		return lightingEnable && !preTransformed;
 	}
 
-	bool Context::vertexTextureActive(int coordinate, int component)   // FIXME: Rename to texCoordActive
+	bool Context::texCoordActive(int coordinate, int component)
 	{
 		bool hasTexture = pointSpriteActive();
 
@@ -510,7 +513,7 @@
 		{
 			if(!preTransformed)
 			{
-				if(vertexShader->output[T0 + coordinate][component].usage == ShaderOperation::USAGE_TEXCOORD)
+				if(vertexShader->output[T0 + coordinate][component].usage == Shader::USAGE_TEXCOORD)
 				{
 					hasTexture = true;
 				}
@@ -563,12 +566,12 @@
 		return hasTexture && usesTexture;
 	}
 
-	bool Context::vertexTextureActive(int coordinate)   // FIXME: Rename to texCoordActive
+	bool Context::texCoordActive(int coordinate)
 	{
-		return vertexTextureActive(coordinate, 0) ||
-		       vertexTextureActive(coordinate, 1) ||
-			   vertexTextureActive(coordinate, 2) ||
-			   vertexTextureActive(coordinate, 3);
+		return texCoordActive(coordinate, 0) ||
+		       texCoordActive(coordinate, 1) ||
+			   texCoordActive(coordinate, 2) ||
+			   texCoordActive(coordinate, 3);
 	}
 
 	bool Context::isProjectionComponent(unsigned int coordinate, int component)
@@ -1103,7 +1106,7 @@
 
 	Context::TexGen Context::texGenActive(int stage)
 	{
-		if(vertexShader || !vertexTextureActive(stage))
+		if(vertexShader || !texCoordActive(stage))
 		{
 			return TEXGEN_PASSTHRU;
 		}
@@ -1113,7 +1116,7 @@
 	
 	int Context::textureTransformCountActive(int stage)
 	{
-		if(vertexShader || !vertexTextureActive(stage))
+		if(vertexShader || !texCoordActive(stage))
 		{
 			return 0;
 		}
@@ -1123,7 +1126,7 @@
 
 	int Context::texCoordIndexActive(int stage)
 	{
-		if(vertexShader || !vertexTextureActive(stage))
+		if(vertexShader || !texCoordActive(stage))
 		{
 			return stage;
 		}
@@ -1322,14 +1325,14 @@
 		return textureActive(coordinate, 0) || textureActive(coordinate, 1) || textureActive(coordinate, 2) || textureActive(coordinate, 3);
 	}
 
-	bool Context::textureActive(int coordinate, int component)   // FIXME: Rename to texCoordActive
+	bool Context::textureActive(int coordinate, int component)
 	{
 		if(!colorUsed())
 		{
 			return false;
 		}
 
-		if(!vertexTextureActive(coordinate, component))
+		if(!texCoordActive(coordinate, component))
 		{
 			return false;
 		}
@@ -1434,6 +1437,6 @@
 
 	bool Context::colorUsed()
 	{
-		return colorWriteActive() || alphaTestActive() || (pixelShader && pixelShader->containsTexkill());
+		return colorWriteActive() || alphaTestActive() || (pixelShader && pixelShader->containsKill());
 	}
 }
diff --git a/src/Renderer/Context.hpp b/src/Renderer/Context.hpp
index eb18ef8..6c7c99a 100644
--- a/src/Renderer/Context.hpp
+++ b/src/Renderer/Context.hpp
@@ -1,481 +1,480 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2011 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 sw_Context_hpp
-#define sw_Context_hpp
-
-#include "Sampler.hpp"
-#include "TextureStage.hpp"
-#include "Stream.hpp"
-#include "Point.hpp"
-#include "Vertex.hpp"
-
-namespace sw
-{
-	class Sampler;
-	class Surface;
-	class PixelShader;
-	class VertexShader;
-	struct Triangle;
-	struct Primitive;
-	struct Vertex;
-	class Resource;
-
-	enum In   // Default input stream semantic
-	{
-		Position = 0,
-		BlendWeight = 1,
-		BlendIndices = 2,
-		Normal = 3,
-		PSize = 4,
-		Color0 = 5,
-		Color1 = 6,
-		TexCoord0 = 7,
-		TexCoord1 = 8,
-		TexCoord2 = 9,
-		TexCoord3 = 10,
-		TexCoord4 = 11,
-		TexCoord5 = 12,
-		TexCoord6 = 13,
-		TexCoord7 = 14,
-		PositionT = 15
-	};
-
-	class Context
-	{
-	public:
-		enum DrawType
-		{
-			DRAW_POINTLIST,
-			DRAW_LINELIST,
-			DRAW_LINESTRIP,
-			DRAW_LINELOOP,
-			DRAW_TRIANGLELIST,
-			DRAW_TRIANGLESTRIP,
-			DRAW_TRIANGLEFAN,
-
-			DRAW_INDEXEDPOINTLIST8,
-			DRAW_INDEXEDLINELIST8,
-			DRAW_INDEXEDLINESTRIP8,
-			DRAW_INDEXEDLINELOOP8,
-			DRAW_INDEXEDTRIANGLELIST8,
-			DRAW_INDEXEDTRIANGLESTRIP8,
-			DRAW_INDEXEDTRIANGLEFAN8,
-
-			DRAW_INDEXEDPOINTLIST16,
-			DRAW_INDEXEDLINELIST16,
-			DRAW_INDEXEDLINESTRIP16,
-			DRAW_INDEXEDLINELOOP16,
-			DRAW_INDEXEDTRIANGLELIST16,
-			DRAW_INDEXEDTRIANGLESTRIP16,
-			DRAW_INDEXEDTRIANGLEFAN16,
-
-			DRAW_INDEXEDPOINTLIST32,
-			DRAW_INDEXEDLINELIST32,
-			DRAW_INDEXEDLINESTRIP32,
-			DRAW_INDEXEDLINELOOP32,
-			DRAW_INDEXEDTRIANGLELIST32,
-			DRAW_INDEXEDTRIANGLESTRIP32,
-			DRAW_INDEXEDTRIANGLEFAN32,
-
-			DRAW_LAST = DRAW_INDEXEDTRIANGLEFAN32
-		};
-
-		enum FillMode
-		{
-			FILL_SOLID,
-			FILL_WIREFRAME,
-			FILL_VERTEX,
-
-			FILL_LAST = FILL_VERTEX
-		};
-		
-		enum ShadingMode
-		{
-			SHADING_FLAT,
-			SHADING_GOURAUD,
-
-			SHADING_LAST = SHADING_GOURAUD
-		};
-
-		enum DepthCompareMode
-		{
-			DEPTH_ALWAYS,
-			DEPTH_NEVER,
-			DEPTH_EQUAL,
-			DEPTH_NOTEQUAL,
-			DEPTH_LESS,
-			DEPTH_LESSEQUAL,
-			DEPTH_GREATER,
-			DEPTH_GREATEREQUAL,
-
-			DEPTH_LAST = DEPTH_GREATEREQUAL
-		};
-
-		enum StencilCompareMode
-		{
-			STENCIL_ALWAYS,
-			STENCIL_NEVER,
-			STENCIL_EQUAL,
-			STENCIL_NOTEQUAL,
-			STENCIL_LESS,
-			STENCIL_LESSEQUAL,
-			STENCIL_GREATER,
-			STENCIL_GREATEREQUAL,
-
-			STENCIL_LAST = STENCIL_GREATEREQUAL
-		};
-
-		enum StencilOperation
-		{
-			OPERATION_KEEP,
-			OPERATION_ZERO,
-			OPERATION_REPLACE,
-			OPERATION_INCRSAT,
-			OPERATION_DECRSAT,
-			OPERATION_INVERT,
-			OPERATION_INCR,
-			OPERATION_DECR,
-
-			OPERATION_LAST = OPERATION_DECR
-		};
-
-		enum AlphaCompareMode
-		{
-			ALPHA_ALWAYS,
-			ALPHA_NEVER,
-			ALPHA_EQUAL,
-			ALPHA_NOTEQUAL,
-			ALPHA_LESS,
-			ALPHA_LESSEQUAL,
-			ALPHA_GREATER,
-			ALPHA_GREATEREQUAL,
-
-			ALPHA_LAST = ALPHA_GREATEREQUAL
-		};
-
-		enum CullMode
-		{
-			CULL_NONE,
-			CULL_CLOCKWISE,
-			CULL_COUNTERCLOCKWISE,
-
-			CULL_LAST = CULL_COUNTERCLOCKWISE
-		};
-
-		enum BlendFactor
-		{
-			BLEND_ZERO,
-			BLEND_ONE,
-			BLEND_SOURCE,
-			BLEND_INVSOURCE,
-			BLEND_DEST,
-			BLEND_INVDEST,
-			BLEND_SOURCEALPHA,
-			BLEND_INVSOURCEALPHA,
-			BLEND_DESTALPHA,
-			BLEND_INVDESTALPHA,
-			BLEND_SRCALPHASAT,
-			BLEND_CONSTANT,
-			BLEND_INVCONSTANT,
-			BLEND_CONSTANTALPHA,
-			BLEND_INVCONSTANTALPHA,
-
-			BLEND_LAST = BLEND_INVCONSTANT
-		};
-
-		enum BlendOperation
-		{
-			BLENDOP_ADD,
-			BLENDOP_SUB,
-			BLENDOP_INVSUB,
-			BLENDOP_MIN,
-			BLENDOP_MAX,
-
-			BLENDOP_SOURCE,   // Copy source
-			BLENDOP_DEST,     // Copy dest
-			BLENDOP_NULL,     // Nullify result
-
-			BLENDOP_LAST = BLENDOP_NULL
-		};
-
-		enum MaterialSource
-		{
-			MATERIAL,
-			COLOR1,
-			COLOR2,
-
-			MATERIAL_LAST = COLOR2
-		};
-
-		enum FogMode
-		{
-			FOG_NONE,
-			FOG_LINEAR,
-			FOG_EXP,
-			FOG_EXP2,
-
-			FOG_LAST = FOG_EXP2
-		};
-
-		enum TexGen
-		{
-			TEXGEN_PASSTHRU,
-			TEXGEN_NORMAL,
-			TEXGEN_POSITION,
-			TEXGEN_REFLECTION,
-			TEXGEN_SPHEREMAP,
-
-			TEXGEN_LAST = TEXGEN_SPHEREMAP
-		};
-
-		enum TransparencyAntialiasing
-		{
-			TRANSPARENCY_NONE,
-			TRANSPARENCY_ALPHA_TO_COVERAGE,
-
-			TRANSPARENCY_LAST = TRANSPARENCY_ALPHA_TO_COVERAGE
-		};
-
-		Context();
-
-		~Context();
-
-		void *operator new(size_t bytes);
-		void operator delete(void *pointer, size_t bytes);
-
-		bool isDrawPoint(bool fillModeAware = false) const;
-		bool isDrawLine(bool fillModeAware = false) const;
-		bool isDrawTriangle(bool fillModeAware = false) const;
-
-		void init();
-
-		const float &exp2Bias();   // NOTE: Needs address for JIT
-		
-		const Point &getLightPosition(int light);
-
-		void setGlobalMipmapBias(float bias);
-
-		// Set fixed-function vertex pipeline states
-		void setLightingEnable(bool lightingEnable);
-		void setSpecularEnable(bool specularEnable);
-		void setLightEnable(int light, bool lightEnable);
-		void setLightPosition(int light, Point worldLightPosition);
-
-		void setColorVertexEnable(bool colorVertexEnable);
-		void setAmbientMaterialSource(MaterialSource ambientMaterialSource);
-		void setDiffuseMaterialSource(MaterialSource diffuseMaterialSource);
-		void setSpecularMaterialSource(MaterialSource specularMaterialSource);
-		void setEmissiveMaterialSource(MaterialSource emissiveMaterialSource);
-
-		void setPointSpriteEnable(bool pointSpriteEnable);
-		void setPointScaleEnable(bool pointScaleEnable);
-
-		// Set fixed-function pixel pipeline states, return true when modified
-		bool setDepthBufferEnable(bool depthBufferEnable);
-
-		bool setAlphaBlendEnable(bool alphaBlendEnable);
-		bool setSourceBlendFactor(BlendFactor sourceBlendFactor);
-		bool setDestBlendFactor(BlendFactor destBlendFactor);
-		bool setBlendOperation(BlendOperation blendOperation);
-
-		bool setSeparateAlphaBlendEnable(bool separateAlphaBlendEnable);
-		bool setSourceBlendFactorAlpha(Context::BlendFactor sourceBlendFactorAlpha);
-		bool setDestBlendFactorAlpha(Context::BlendFactor destBlendFactorAlpha);
-		bool setBlendOperationAlpha(Context::BlendOperation blendOperationAlpha);
-
-		bool setColorWriteMask(int index, int colorWriteMask);
-		bool setWriteSRGB(bool sRGB);
-
-		// Active fixed-function pixel pipeline states
-		bool fogActive();
-		bool pointSizeActive();
-		Context::FogMode pixelFogActive();
-		bool depthWriteActive();
-		bool alphaTestActive();
-		bool depthBufferActive();
-		bool stencilActive();
-
-		bool perspectiveActive();
-
-		// Active fixed-function vertex pipeline states
-		bool vertexLightingActive();
-		bool vertexTextureActive(int coordinate, int component);
-		bool vertexTextureActive(int coordinate);
-		bool isProjectionComponent(unsigned int coordinate, int component);
-		bool vertexSpecularInputActive();
-		bool vertexSpecularActive();
-		bool vertexNormalActive();
-		bool vertexLightActive();
-		bool vertexLightActive(int i);
-		MaterialSource vertexDiffuseMaterialSourceActive();
-		MaterialSource vertexSpecularMaterialSourceActive();
-		MaterialSource vertexAmbientMaterialSourceActive();
-		MaterialSource vertexEmissiveMaterialSourceActive();
-
-		bool pointSpriteActive();
-		bool pointScaleActive();
-
-		bool alphaBlendActive();
-		BlendFactor sourceBlendFactor();
-		BlendFactor destBlendFactor();
-		BlendOperation blendOperation();
-
-		BlendFactor sourceBlendFactorAlpha();
-		BlendFactor destBlendFactorAlpha();
-		BlendOperation blendOperationAlpha();
-
-		bool indexedVertexBlendActive();
-		int vertexBlendMatrixCountActive();
-		bool localViewerActive();
-		bool normalizeNormalsActive();
-		FogMode vertexFogModeActive();
-		bool rangeFogActive();
-
-		TexGen texGenActive(int stage);
-		int textureTransformCountActive(int stage);
-		int texCoordIndexActive(int stage);
-
-		// Active context states
-		bool diffuseUsed();     // Used by pixel processor but not provided by vertex processor
-		bool diffuseUsed(int component);     // Used by pixel processor but not provided by vertex processor
-		bool diffuseActive();
-		bool diffuseActive(int component);
-		bool specularUsed();
-		bool specularUsed(int component);
-		bool specularActive();
-		bool specularActive(int component);
-		bool colorActive(int color, int component);
-		bool textureActive();
-		bool textureActive(int coordinate);
-		bool textureActive(int coordinate, int component);
-
-		unsigned short pixelShaderVersion() const;
-		unsigned short vertexShaderVersion() const;
-
-		DrawType drawType;
-
-		bool stencilEnable;
-		StencilCompareMode stencilCompareMode;
-		int stencilReference;
-		int stencilMask;
-		StencilOperation stencilFailOperation;
-		StencilOperation stencilPassOperation;
-		StencilOperation stencilZFailOperation;
-		int stencilWriteMask;
-		
-		bool twoSidedStencil;
-		StencilCompareMode stencilCompareModeCCW;
-		int stencilReferenceCCW;
-		int stencilMaskCCW;
-		StencilOperation stencilFailOperationCCW;
-		StencilOperation stencilPassOperationCCW;
-		StencilOperation stencilZFailOperationCCW;
-		int stencilWriteMaskCCW;
-
-		// Pixel processor states
-		AlphaCompareMode alphaCompareMode;
-		bool alphaTestEnable;
-		FillMode fillMode;
-		ShadingMode shadingMode;
-
-		CullMode cullMode;
-		int alphaReference;
-		
-		TextureStage textureStage[8];
-		Sampler sampler[16 + 4];
-
-		Format renderTargetInternalFormat(int index);
-		int colorWriteActive();
-		int colorWriteActive(int index);
-		bool colorUsed();
-
-		Resource *texture[16 + 4];
-		Stream input[16];
-		Resource *indexBuffer;
-
-		bool preTransformed;   // FIXME: Private
-		bool postTransform;
-
-		float fogStart;
-		float fogEnd;
-
-		void computeIllumination();
-
-		bool textureWrapActive;
-		unsigned char textureWrap[16];
-		Context::TexGen texGen[8];
-		bool localViewer;
-		bool normalizeNormals;
-		int textureTransformCount[8];
-		bool textureTransformProject[8];
-
-		Surface *renderTarget[4];
-		Surface *depthStencil;
-
-		// Fog
-		bool fogEnable;
-		FogMode pixelFogMode;
-		FogMode vertexFogMode;
-		bool wBasedFog;
-		bool rangeFogEnable;
-
-		// Vertex blending
-		bool indexedVertexBlendEnable;
-		int vertexBlendMatrixCount;
-
-		// Shaders
-		const PixelShader *pixelShader;
-		const VertexShader *vertexShader;
-
-		// Global mipmap bias
-		float bias;
-
-		// Fixed-function vertex pipeline state
-		bool lightingEnable;
-		bool specularEnable;
-		bool lightEnable[8];
-		Point worldLightPosition[8];
-
-		MaterialSource ambientMaterialSource;
-		MaterialSource diffuseMaterialSource;
-		MaterialSource specularMaterialSource;
-		MaterialSource emissiveMaterialSource;
-		bool colorVertexEnable;
-
-		bool occlusionEnabled;
-
-		// Pixel processor states
-		bool depthBufferEnable;
-		DepthCompareMode depthCompareMode;
-		bool depthWriteEnable;
-
-		bool alphaBlendEnable;
-		BlendFactor sourceBlendFactorState;
-		BlendFactor destBlendFactorState;
-		BlendOperation blendOperationState;
-
-		bool separateAlphaBlendEnable;
-		BlendFactor sourceBlendFactorStateAlpha;
-		BlendFactor destBlendFactorStateAlpha;
-		BlendOperation blendOperationStateAlpha;
-
-		bool pointSpriteEnable;
-		bool pointScaleEnable;
-
-		int colorWriteMask[4];   // RGBA
-		bool writeSRGB;
-		unsigned int sampleMask;
-		unsigned int multiSampleMask;
-	};
-}
-
-#endif   // sw_Context_hpp
+// SwiftShader Software Renderer

+//

+// Copyright(c) 2005-2012 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 sw_Context_hpp

+#define sw_Context_hpp

+

+#include "Sampler.hpp"

+#include "TextureStage.hpp"

+#include "Stream.hpp"

+#include "Point.hpp"

+#include "Vertex.hpp"

+

+namespace sw

+{

+	class Sampler;

+	class Surface;

+	class PixelShader;

+	class VertexShader;

+	struct Triangle;

+	struct Primitive;

+	struct Vertex;

+	class Resource;

+

+	enum In   // Default input stream semantic

+	{

+		Position = 0,

+		BlendWeight = 1,

+		BlendIndices = 2,

+		Normal = 3,

+		PSize = 4,

+		Color0 = 5,

+		Color1 = 6,

+		TexCoord0 = 7,

+		TexCoord1 = 8,

+		TexCoord2 = 9,

+		TexCoord3 = 10,

+		TexCoord4 = 11,

+		TexCoord5 = 12,

+		TexCoord6 = 13,

+		TexCoord7 = 14,

+		PositionT = 15

+	};

+

+	class Context

+	{

+	public:

+		enum DrawType

+		{

+			DRAW_POINTLIST,

+			DRAW_LINELIST,

+			DRAW_LINESTRIP,

+			DRAW_LINELOOP,

+			DRAW_TRIANGLELIST,

+			DRAW_TRIANGLESTRIP,

+			DRAW_TRIANGLEFAN,

+

+			DRAW_INDEXEDPOINTLIST8,

+			DRAW_INDEXEDLINELIST8,

+			DRAW_INDEXEDLINESTRIP8,

+			DRAW_INDEXEDLINELOOP8,

+			DRAW_INDEXEDTRIANGLELIST8,

+			DRAW_INDEXEDTRIANGLESTRIP8,

+			DRAW_INDEXEDTRIANGLEFAN8,

+

+			DRAW_INDEXEDPOINTLIST16,

+			DRAW_INDEXEDLINELIST16,

+			DRAW_INDEXEDLINESTRIP16,

+			DRAW_INDEXEDLINELOOP16,

+			DRAW_INDEXEDTRIANGLELIST16,

+			DRAW_INDEXEDTRIANGLESTRIP16,

+			DRAW_INDEXEDTRIANGLEFAN16,

+

+			DRAW_INDEXEDPOINTLIST32,

+			DRAW_INDEXEDLINELIST32,

+			DRAW_INDEXEDLINESTRIP32,

+			DRAW_INDEXEDLINELOOP32,

+			DRAW_INDEXEDTRIANGLELIST32,

+			DRAW_INDEXEDTRIANGLESTRIP32,

+			DRAW_INDEXEDTRIANGLEFAN32,

+

+			DRAW_LAST = DRAW_INDEXEDTRIANGLEFAN32

+		};

+

+		enum FillMode

+		{

+			FILL_SOLID,

+			FILL_WIREFRAME,

+			FILL_VERTEX,

+

+			FILL_LAST = FILL_VERTEX

+		};

+		

+		enum ShadingMode

+		{

+			SHADING_FLAT,

+			SHADING_GOURAUD,

+

+			SHADING_LAST = SHADING_GOURAUD

+		};

+

+		enum DepthCompareMode

+		{

+			DEPTH_ALWAYS,

+			DEPTH_NEVER,

+			DEPTH_EQUAL,

+			DEPTH_NOTEQUAL,

+			DEPTH_LESS,

+			DEPTH_LESSEQUAL,

+			DEPTH_GREATER,

+			DEPTH_GREATEREQUAL,

+

+			DEPTH_LAST = DEPTH_GREATEREQUAL

+		};

+

+		enum StencilCompareMode

+		{

+			STENCIL_ALWAYS,

+			STENCIL_NEVER,

+			STENCIL_EQUAL,

+			STENCIL_NOTEQUAL,

+			STENCIL_LESS,

+			STENCIL_LESSEQUAL,

+			STENCIL_GREATER,

+			STENCIL_GREATEREQUAL,

+

+			STENCIL_LAST = STENCIL_GREATEREQUAL

+		};

+

+		enum StencilOperation

+		{

+			OPERATION_KEEP,

+			OPERATION_ZERO,

+			OPERATION_REPLACE,

+			OPERATION_INCRSAT,

+			OPERATION_DECRSAT,

+			OPERATION_INVERT,

+			OPERATION_INCR,

+			OPERATION_DECR,

+

+			OPERATION_LAST = OPERATION_DECR

+		};

+

+		enum AlphaCompareMode

+		{

+			ALPHA_ALWAYS,

+			ALPHA_NEVER,

+			ALPHA_EQUAL,

+			ALPHA_NOTEQUAL,

+			ALPHA_LESS,

+			ALPHA_LESSEQUAL,

+			ALPHA_GREATER,

+			ALPHA_GREATEREQUAL,

+

+			ALPHA_LAST = ALPHA_GREATEREQUAL

+		};

+

+		enum CullMode

+		{

+			CULL_NONE,

+			CULL_CLOCKWISE,

+			CULL_COUNTERCLOCKWISE,

+

+			CULL_LAST = CULL_COUNTERCLOCKWISE

+		};

+

+		enum BlendFactor

+		{

+			BLEND_ZERO,

+			BLEND_ONE,

+			BLEND_SOURCE,

+			BLEND_INVSOURCE,

+			BLEND_DEST,

+			BLEND_INVDEST,

+			BLEND_SOURCEALPHA,

+			BLEND_INVSOURCEALPHA,

+			BLEND_DESTALPHA,

+			BLEND_INVDESTALPHA,

+			BLEND_SRCALPHASAT,

+			BLEND_CONSTANT,

+			BLEND_INVCONSTANT,

+			BLEND_CONSTANTALPHA,

+			BLEND_INVCONSTANTALPHA,

+

+			BLEND_LAST = BLEND_INVCONSTANT

+		};

+

+		enum BlendOperation

+		{

+			BLENDOP_ADD,

+			BLENDOP_SUB,

+			BLENDOP_INVSUB,

+			BLENDOP_MIN,

+			BLENDOP_MAX,

+

+			BLENDOP_SOURCE,   // Copy source

+			BLENDOP_DEST,     // Copy dest

+			BLENDOP_NULL,     // Nullify result

+

+			BLENDOP_LAST = BLENDOP_NULL

+		};

+

+		enum MaterialSource

+		{

+			MATERIAL,

+			COLOR1,

+			COLOR2,

+

+			MATERIAL_LAST = COLOR2

+		};

+

+		enum FogMode

+		{

+			FOG_NONE,

+			FOG_LINEAR,

+			FOG_EXP,

+			FOG_EXP2,

+

+			FOG_LAST = FOG_EXP2

+		};

+

+		enum TexGen

+		{

+			TEXGEN_PASSTHRU,

+			TEXGEN_NORMAL,

+			TEXGEN_POSITION,

+			TEXGEN_REFLECTION,

+			TEXGEN_SPHEREMAP,

+

+			TEXGEN_LAST = TEXGEN_SPHEREMAP

+		};

+

+		enum TransparencyAntialiasing

+		{

+			TRANSPARENCY_NONE,

+			TRANSPARENCY_ALPHA_TO_COVERAGE,

+

+			TRANSPARENCY_LAST = TRANSPARENCY_ALPHA_TO_COVERAGE

+		};

+

+		Context();

+

+		~Context();

+

+		void *operator new(size_t bytes);

+		void operator delete(void *pointer, size_t bytes);

+

+		bool isDrawPoint(bool fillModeAware = false) const;

+		bool isDrawLine(bool fillModeAware = false) const;

+		bool isDrawTriangle(bool fillModeAware = false) const;

+

+		void init();

+

+		const float &exp2Bias();   // NOTE: Needs address for JIT

+		

+		const Point &getLightPosition(int light);

+

+		void setGlobalMipmapBias(float bias);

+

+		// Set fixed-function vertex pipeline states

+		void setLightingEnable(bool lightingEnable);

+		void setSpecularEnable(bool specularEnable);

+		void setLightEnable(int light, bool lightEnable);

+		void setLightPosition(int light, Point worldLightPosition);

+

+		void setColorVertexEnable(bool colorVertexEnable);

+		void setAmbientMaterialSource(MaterialSource ambientMaterialSource);

+		void setDiffuseMaterialSource(MaterialSource diffuseMaterialSource);

+		void setSpecularMaterialSource(MaterialSource specularMaterialSource);

+		void setEmissiveMaterialSource(MaterialSource emissiveMaterialSource);

+

+		void setPointSpriteEnable(bool pointSpriteEnable);

+		void setPointScaleEnable(bool pointScaleEnable);

+

+		// Set fixed-function pixel pipeline states, return true when modified

+		bool setDepthBufferEnable(bool depthBufferEnable);

+

+		bool setAlphaBlendEnable(bool alphaBlendEnable);

+		bool setSourceBlendFactor(BlendFactor sourceBlendFactor);

+		bool setDestBlendFactor(BlendFactor destBlendFactor);

+		bool setBlendOperation(BlendOperation blendOperation);

+

+		bool setSeparateAlphaBlendEnable(bool separateAlphaBlendEnable);

+		bool setSourceBlendFactorAlpha(Context::BlendFactor sourceBlendFactorAlpha);

+		bool setDestBlendFactorAlpha(Context::BlendFactor destBlendFactorAlpha);

+		bool setBlendOperationAlpha(Context::BlendOperation blendOperationAlpha);

+

+		bool setColorWriteMask(int index, int colorWriteMask);

+		bool setWriteSRGB(bool sRGB);

+

+		// Active fixed-function pixel pipeline states

+		bool fogActive();

+		bool pointSizeActive();

+		Context::FogMode pixelFogActive();

+		bool depthWriteActive();

+		bool alphaTestActive();

+		bool depthBufferActive();

+		bool stencilActive();

+

+		bool perspectiveActive();

+

+		// Active fixed-function vertex pipeline states

+		bool vertexLightingActive();

+		bool texCoordActive(int coordinate, int component);

+		bool texCoordActive(int coordinate);

+		bool isProjectionComponent(unsigned int coordinate, int component);

+		bool vertexSpecularInputActive();

+		bool vertexSpecularActive();

+		bool vertexNormalActive();

+		bool vertexLightActive();

+		bool vertexLightActive(int i);

+		MaterialSource vertexDiffuseMaterialSourceActive();

+		MaterialSource vertexSpecularMaterialSourceActive();

+		MaterialSource vertexAmbientMaterialSourceActive();

+		MaterialSource vertexEmissiveMaterialSourceActive();

+

+		bool pointSpriteActive();

+		bool pointScaleActive();

+

+		bool alphaBlendActive();

+		BlendFactor sourceBlendFactor();

+		BlendFactor destBlendFactor();

+		BlendOperation blendOperation();

+

+		BlendFactor sourceBlendFactorAlpha();

+		BlendFactor destBlendFactorAlpha();

+		BlendOperation blendOperationAlpha();

+

+		bool indexedVertexBlendActive();

+		int vertexBlendMatrixCountActive();

+		bool localViewerActive();

+		bool normalizeNormalsActive();

+		FogMode vertexFogModeActive();

+		bool rangeFogActive();

+

+		TexGen texGenActive(int stage);

+		int textureTransformCountActive(int stage);

+		int texCoordIndexActive(int stage);

+

+		// Active context states

+		bool diffuseUsed();     // Used by pixel processor but not provided by vertex processor

+		bool diffuseUsed(int component);     // Used by pixel processor but not provided by vertex processor

+		bool diffuseActive();

+		bool diffuseActive(int component);

+		bool specularUsed();

+		bool specularUsed(int component);

+		bool specularActive();

+		bool specularActive(int component);

+		bool colorActive(int color, int component);

+		bool textureActive();

+		bool textureActive(int coordinate);

+		bool textureActive(int coordinate, int component);

+

+		unsigned short pixelShaderVersion() const;

+		unsigned short vertexShaderVersion() const;

+

+		DrawType drawType;

+

+		bool stencilEnable;

+		StencilCompareMode stencilCompareMode;

+		int stencilReference;

+		int stencilMask;

+		StencilOperation stencilFailOperation;

+		StencilOperation stencilPassOperation;

+		StencilOperation stencilZFailOperation;

+		int stencilWriteMask;

+		

+		bool twoSidedStencil;

+		StencilCompareMode stencilCompareModeCCW;

+		int stencilReferenceCCW;

+		int stencilMaskCCW;

+		StencilOperation stencilFailOperationCCW;

+		StencilOperation stencilPassOperationCCW;

+		StencilOperation stencilZFailOperationCCW;

+		int stencilWriteMaskCCW;

+

+		// Pixel processor states

+		AlphaCompareMode alphaCompareMode;

+		bool alphaTestEnable;

+		FillMode fillMode;

+		ShadingMode shadingMode;

+

+		CullMode cullMode;

+		int alphaReference;

+		

+		TextureStage textureStage[8];

+		Sampler sampler[16 + 4];

+

+		Format renderTargetInternalFormat(int index);

+		int colorWriteActive();

+		int colorWriteActive(int index);

+		bool colorUsed();

+

+		Resource *texture[16 + 4];

+		Stream input[16];

+		Resource *indexBuffer;

+

+		bool preTransformed;   // FIXME: Private

+

+		float fogStart;

+		float fogEnd;

+

+		void computeIllumination();

+

+		bool textureWrapActive;

+		unsigned char textureWrap[16];

+		Context::TexGen texGen[8];

+		bool localViewer;

+		bool normalizeNormals;

+		int textureTransformCount[8];

+		bool textureTransformProject[8];

+

+		Surface *renderTarget[4];

+		Surface *depthStencil;

+

+		// Fog

+		bool fogEnable;

+		FogMode pixelFogMode;

+		FogMode vertexFogMode;

+		bool wBasedFog;

+		bool rangeFogEnable;

+

+		// Vertex blending

+		bool indexedVertexBlendEnable;

+		int vertexBlendMatrixCount;

+

+		// Shaders

+		const PixelShader *pixelShader;

+		const VertexShader *vertexShader;

+

+		// Global mipmap bias

+		float bias;

+

+		// Fixed-function vertex pipeline state

+		bool lightingEnable;

+		bool specularEnable;

+		bool lightEnable[8];

+		Point worldLightPosition[8];

+

+		MaterialSource ambientMaterialSource;

+		MaterialSource diffuseMaterialSource;

+		MaterialSource specularMaterialSource;

+		MaterialSource emissiveMaterialSource;

+		bool colorVertexEnable;

+

+		bool occlusionEnabled;

+

+		// Pixel processor states

+		bool depthBufferEnable;

+		DepthCompareMode depthCompareMode;

+		bool depthWriteEnable;

+

+		bool alphaBlendEnable;

+		BlendFactor sourceBlendFactorState;

+		BlendFactor destBlendFactorState;

+		BlendOperation blendOperationState;

+

+		bool separateAlphaBlendEnable;

+		BlendFactor sourceBlendFactorStateAlpha;

+		BlendFactor destBlendFactorStateAlpha;

+		BlendOperation blendOperationStateAlpha;

+

+		bool pointSpriteEnable;

+		bool pointScaleEnable;

+

+		int colorWriteMask[4];   // RGBA

+		bool writeSRGB;

+		unsigned int sampleMask;

+		unsigned int multiSampleMask;

+	};

+}

+

+#endif   // sw_Context_hpp

diff --git a/src/Renderer/Matrix.hpp b/src/Renderer/Matrix.hpp
index d3c9377..1b9a39e 100644
--- a/src/Renderer/Matrix.hpp
+++ b/src/Renderer/Matrix.hpp
@@ -1,211 +1,211 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2011 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 Matrix_hpp
-#define Matrix_hpp
-
-namespace sw
-{
-	struct Vector;
-	struct Point;
-
-	struct Matrix
-	{
-		Matrix();
-		Matrix(const int i);
-		Matrix(const float m[16]);
-		Matrix(const float m[4][4]);
-		Matrix(float m11, float m12, float m13,
-		       float m21, float m22, float m23,
-		       float m31, float m32, float m33);
-		Matrix(float m11, float m12, float m13, float m14,
-		       float m21, float m22, float m23, float m24,
-		       float m31, float m32, float m33, float m34,
-		       float m41, float m42, float m43, float m44);
-		Matrix(const Vector &v1, const Vector &v2, const Vector &v3);   // Column vectors
-
-		Matrix &operator=(const Matrix &N);
-
-		// Row major order
-		float m[4][4];
-
-		static Matrix diag(float m11, float m22, float m33, float m44);
-
-		operator float*();
-
-		Matrix operator+() const;
-		Matrix operator-() const;
-
-		Matrix operator!() const;   // Inverse
-		Matrix operator~() const;   // Transpose
-
-		Matrix &operator+=(const Matrix &N);
-		Matrix &operator-=(const Matrix &N);
-		Matrix &operator*=(float s);
-		Matrix &operator*=(const Matrix &N);
-		Matrix &operator/=(float s);
-
-		float *operator[](int i);   // Access element [row][col], starting with [0][0]
-		const float *operator[](int i) const;
-
-		float &operator()(int i, int j);   // Access element (row, col), starting with (1, 1)
-		const float &operator()(int i, int j) const;
-
-		friend bool operator==(const Matrix &M, const Matrix &N);
-		friend bool operator!=(const Matrix &M, const Matrix &N);
-
-		friend Matrix operator+(const Matrix &M, const Matrix &N);
-		friend Matrix operator-(const Matrix &M, const Matrix &N);
-		friend Matrix operator*(float s, const Matrix &M);
-		friend Matrix operator*(const Matrix &M, const Matrix &N);
-		friend Matrix operator/(const Matrix &M, float s);
-
-		static float det(const Matrix &M);
-		static float det(float m11);
-		static float det(float m11, float m12,
-		                 float m21, float m22);
-		static float det(float m11, float m12, float m13,
-		                 float m21, float m22, float m23,
-		                 float m31, float m32, float m33);
-		static float det(float m11, float m12, float m13, float m14,
-		                 float m21, float m22, float m23, float m24,
-		                 float m31, float m32, float m33, float m34,
-		                 float m41, float m42, float m43, float m44);
-		static float det(const Vector &v1, const Vector &v2, const Vector &v3);
-		static float det3(const Matrix &M);
-
-		static float tr(const Matrix &M);
-
-		Matrix &orthogonalise();   // Gram-Schmidt orthogonalisation of 3x3 submatrix
-
-		static Matrix eulerRotate(const Vector &v);
-		static Matrix eulerRotate(float x, float y, float z);
-		
-		static Matrix translate(const Vector &v);
-		static Matrix translate(float x, float y, float z);
-		
-		static Matrix scale(const Vector &v);
-		static Matrix scale(float x, float y, float z);
-
-		static Matrix lookAt(const Vector &v);
-		static Matrix lookAt(float x, float y, float z);
-	};
-}
-
-#include "Vector.hpp"
-
-namespace sw
-{
-	inline Matrix::Matrix()
-	{
-	}
-
-	inline Matrix::Matrix(const int i)
-	{
-		const float s = (float)i;
-
-		Matrix &M = *this;
-
-		M(1, 1) = s; M(1, 2) = 0; M(1, 3) = 0; M(1, 4) = 0;
-		M(2, 1) = 0; M(2, 2) = s; M(2, 3) = 0; M(2, 4) = 0;
-		M(3, 1) = 0; M(3, 2) = 0; M(3, 3) = s; M(3, 4) = 0;
-		M(4, 1) = 0; M(4, 2) = 0; M(4, 3) = 0; M(4, 4) = s;
-	}
-
-	inline Matrix::Matrix(const float m[16])
-	{
-		Matrix &M = *this;
-
-		M(1, 1) = m[0];  M(1, 2) = m[1];  M(1, 3) = m[2];  M(1, 4) = m[3];
-		M(2, 1) = m[4];  M(2, 2) = m[5];  M(2, 3) = m[6];  M(2, 4) = m[7];
-		M(3, 1) = m[8];  M(3, 2) = m[8];  M(3, 3) = m[10]; M(3, 4) = m[11];
-		M(4, 1) = m[12]; M(4, 2) = m[13]; M(4, 3) = m[14]; M(4, 4) = m[15];
-	}
-
-	inline Matrix::Matrix(const float m[4][4])
-	{
-		Matrix &M = *this;
-
-		M[0][0] = m[0][0];  M[0][1] = m[0][1];  M[0][2] = m[0][2];  M[0][3] = m[0][3];
-		M[1][0] = m[1][0];  M[1][1] = m[1][1];  M[1][2] = m[1][2];  M[1][3] = m[1][3];
-		M[2][0] = m[2][0];  M[2][1] = m[2][1];  M[2][2] = m[2][2];  M[2][3] = m[2][3];
-		M[3][0] = m[3][0];  M[3][1] = m[3][1];  M[3][2] = m[3][2];  M[3][3] = m[3][3];
-	}
-
-	inline Matrix::Matrix(float m11, float m12, float m13, 
-	                      float m21, float m22, float m23, 
-	                      float m31, float m32, float m33)
-	{
-		Matrix &M = *this;
-
-		M(1, 1) = m11; M(1, 2) = m12; M(1, 3) = m13; M(1, 4) = 0;
-		M(2, 1) = m21; M(2, 2) = m22; M(2, 3) = m23; M(2, 4) = 0;
-		M(3, 1) = m31; M(3, 2) = m32; M(3, 3) = m33; M(3, 4) = 0;
-		M(4, 1) = 0;   M(4, 2) = 0;   M(4, 3) = 0;   M(4, 4) = 1;
-	}
-
-	inline Matrix::Matrix(float m11, float m12, float m13, float m14, 
-	                      float m21, float m22, float m23, float m24, 
-	                      float m31, float m32, float m33, float m34, 
-	                      float m41, float m42, float m43, float m44)
-	{
-		Matrix &M = *this;
-
-		M(1, 1) = m11; M(1, 2) = m12; M(1, 3) = m13; M(1, 4) = m14;
-		M(2, 1) = m21; M(2, 2) = m22; M(2, 3) = m23; M(2, 4) = m24;
-		M(3, 1) = m31; M(3, 2) = m32; M(3, 3) = m33; M(3, 4) = m34;
-		M(4, 1) = m41; M(4, 2) = m42; M(4, 3) = m43; M(4, 4) = m44;
-	}
-
-	inline Matrix::Matrix(const Vector &v1, const Vector &v2, const Vector &v3)
-	{
-		Matrix &M = *this;
-
-		M(1, 1) = v1.x; M(1, 2) = v2.x; M(1, 3) = v3.x; M(1, 4) = 0;
-		M(2, 1) = v1.y; M(2, 2) = v2.y; M(2, 3) = v3.y; M(2, 4) = 0;
-		M(3, 1) = v1.z; M(3, 2) = v2.z; M(3, 3) = v3.z; M(3, 4) = 0;
-		M(4, 1) = 0;    M(4, 2) = 0;    M(4, 3) = 0;    M(4, 4) = 1;
-	}
-
-	inline Matrix &Matrix::operator=(const Matrix &N)
-	{
-		Matrix &M = *this;
-
-		M(1, 1) = N(1, 1); M(1, 2) = N(1, 2); M(1, 3) = N(1, 3); M(1, 4) = N(1, 4);
-		M(2, 1) = N(2, 1); M(2, 2) = N(2, 2); M(2, 3) = N(2, 3); M(2, 4) = N(2, 4);
-		M(3, 1) = N(3, 1); M(3, 2) = N(3, 2); M(3, 3) = N(3, 3); M(3, 4) = N(3, 4);
-		M(4, 1) = N(4, 1); M(4, 2) = N(4, 2); M(4, 3) = N(4, 3); M(4, 4) = N(4, 4);
-
-		return M;
-	}
-
-	inline float *Matrix::operator[](int i)
-	{
-		return m[i];
-	}
-
-	inline const float *Matrix::operator[](int i) const
-	{
-		return m[i];
-	}
-
-	inline float &Matrix::operator()(int i, int j)
-	{
-		return m[i - 1][j - 1];
-	}
-
-	inline const float &Matrix::operator()(int i, int j) const
-	{
-		return m[i - 1][j - 1];
-	}
-}
-
-#endif   // Matrix_hpp
+// SwiftShader Software Renderer

+//

+// Copyright(c) 2005-2011 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 Matrix_hpp

+#define Matrix_hpp

+

+namespace sw

+{

+	struct Vector;

+	struct Point;

+

+	struct Matrix

+	{

+		Matrix();

+		Matrix(const int i);

+		Matrix(const float m[16]);

+		Matrix(const float m[4][4]);

+		Matrix(float m11, float m12, float m13,

+		       float m21, float m22, float m23,

+		       float m31, float m32, float m33);

+		Matrix(float m11, float m12, float m13, float m14,

+		       float m21, float m22, float m23, float m24,

+		       float m31, float m32, float m33, float m34,

+		       float m41, float m42, float m43, float m44);

+		Matrix(const Vector &v1, const Vector &v2, const Vector &v3);   // Column vectors

+

+		Matrix &operator=(const Matrix &N);

+

+		// Row major order

+		float m[4][4];

+

+		static Matrix diag(float m11, float m22, float m33, float m44);

+

+		operator float*();

+

+		Matrix operator+() const;

+		Matrix operator-() const;

+

+		Matrix operator!() const;   // Inverse

+		Matrix operator~() const;   // Transpose

+

+		Matrix &operator+=(const Matrix &N);

+		Matrix &operator-=(const Matrix &N);

+		Matrix &operator*=(float s);

+		Matrix &operator*=(const Matrix &N);

+		Matrix &operator/=(float s);

+

+		float *operator[](int i);   // Access element [row][col], starting with [0][0]

+		const float *operator[](int i) const;

+

+		float &operator()(int i, int j);   // Access element (row, col), starting with (1, 1)

+		const float &operator()(int i, int j) const;

+

+		friend bool operator==(const Matrix &M, const Matrix &N);

+		friend bool operator!=(const Matrix &M, const Matrix &N);

+

+		friend Matrix operator+(const Matrix &M, const Matrix &N);

+		friend Matrix operator-(const Matrix &M, const Matrix &N);

+		friend Matrix operator*(float s, const Matrix &M);

+		friend Matrix operator*(const Matrix &M, const Matrix &N);

+		friend Matrix operator/(const Matrix &M, float s);

+

+		static float det(const Matrix &M);

+		static float det(float m11);

+		static float det(float m11, float m12,

+		                 float m21, float m22);

+		static float det(float m11, float m12, float m13,

+		                 float m21, float m22, float m23,

+		                 float m31, float m32, float m33);

+		static float det(float m11, float m12, float m13, float m14,

+		                 float m21, float m22, float m23, float m24,

+		                 float m31, float m32, float m33, float m34,

+		                 float m41, float m42, float m43, float m44);

+		static float det(const Vector &v1, const Vector &v2, const Vector &v3);

+		static float det3(const Matrix &M);

+

+		static float tr(const Matrix &M);

+

+		Matrix &orthogonalise();   // Gram-Schmidt orthogonalisation of 3x3 submatrix

+

+		static Matrix eulerRotate(const Vector &v);

+		static Matrix eulerRotate(float x, float y, float z);

+		

+		static Matrix translate(const Vector &v);

+		static Matrix translate(float x, float y, float z);

+		

+		static Matrix scale(const Vector &v);

+		static Matrix scale(float x, float y, float z);

+

+		static Matrix lookAt(const Vector &v);

+		static Matrix lookAt(float x, float y, float z);

+	};

+}

+

+#include "Vector.hpp"

+

+namespace sw

+{

+	inline Matrix::Matrix()

+	{

+	}

+

+	inline Matrix::Matrix(const int i)

+	{

+		const float s = (float)i;

+

+		Matrix &M = *this;

+

+		M(1, 1) = s; M(1, 2) = 0; M(1, 3) = 0; M(1, 4) = 0;

+		M(2, 1) = 0; M(2, 2) = s; M(2, 3) = 0; M(2, 4) = 0;

+		M(3, 1) = 0; M(3, 2) = 0; M(3, 3) = s; M(3, 4) = 0;

+		M(4, 1) = 0; M(4, 2) = 0; M(4, 3) = 0; M(4, 4) = s;

+	}

+

+	inline Matrix::Matrix(const float m[16])

+	{

+		Matrix &M = *this;

+

+		M(1, 1) = m[0];  M(1, 2) = m[1];  M(1, 3) = m[2];  M(1, 4) = m[3];

+		M(2, 1) = m[4];  M(2, 2) = m[5];  M(2, 3) = m[6];  M(2, 4) = m[7];

+		M(3, 1) = m[8];  M(3, 2) = m[8];  M(3, 3) = m[10]; M(3, 4) = m[11];

+		M(4, 1) = m[12]; M(4, 2) = m[13]; M(4, 3) = m[14]; M(4, 4) = m[15];

+	}

+

+	inline Matrix::Matrix(const float m[4][4])

+	{

+		Matrix &M = *this;

+

+		M[0][0] = m[0][0];  M[0][1] = m[0][1];  M[0][2] = m[0][2];  M[0][3] = m[0][3];

+		M[1][0] = m[1][0];  M[1][1] = m[1][1];  M[1][2] = m[1][2];  M[1][3] = m[1][3];

+		M[2][0] = m[2][0];  M[2][1] = m[2][1];  M[2][2] = m[2][2];  M[2][3] = m[2][3];

+		M[3][0] = m[3][0];  M[3][1] = m[3][1];  M[3][2] = m[3][2];  M[3][3] = m[3][3];

+	}

+

+	inline Matrix::Matrix(float m11, float m12, float m13, 

+	                      float m21, float m22, float m23, 

+	                      float m31, float m32, float m33)

+	{

+		Matrix &M = *this;

+

+		M(1, 1) = m11; M(1, 2) = m12; M(1, 3) = m13; M(1, 4) = 0;

+		M(2, 1) = m21; M(2, 2) = m22; M(2, 3) = m23; M(2, 4) = 0;

+		M(3, 1) = m31; M(3, 2) = m32; M(3, 3) = m33; M(3, 4) = 0;

+		M(4, 1) = 0;   M(4, 2) = 0;   M(4, 3) = 0;   M(4, 4) = 1;

+	}

+

+	inline Matrix::Matrix(float m11, float m12, float m13, float m14, 

+	                      float m21, float m22, float m23, float m24, 

+	                      float m31, float m32, float m33, float m34, 

+	                      float m41, float m42, float m43, float m44)

+	{

+		Matrix &M = *this;

+

+		M(1, 1) = m11; M(1, 2) = m12; M(1, 3) = m13; M(1, 4) = m14;

+		M(2, 1) = m21; M(2, 2) = m22; M(2, 3) = m23; M(2, 4) = m24;

+		M(3, 1) = m31; M(3, 2) = m32; M(3, 3) = m33; M(3, 4) = m34;

+		M(4, 1) = m41; M(4, 2) = m42; M(4, 3) = m43; M(4, 4) = m44;

+	}

+

+	inline Matrix::Matrix(const Vector &v1, const Vector &v2, const Vector &v3)

+	{

+		Matrix &M = *this;

+

+		M(1, 1) = v1.x; M(1, 2) = v2.x; M(1, 3) = v3.x; M(1, 4) = 0;

+		M(2, 1) = v1.y; M(2, 2) = v2.y; M(2, 3) = v3.y; M(2, 4) = 0;

+		M(3, 1) = v1.z; M(3, 2) = v2.z; M(3, 3) = v3.z; M(3, 4) = 0;

+		M(4, 1) = 0;    M(4, 2) = 0;    M(4, 3) = 0;    M(4, 4) = 1;

+	}

+

+	inline Matrix &Matrix::operator=(const Matrix &N)

+	{

+		Matrix &M = *this;

+

+		M(1, 1) = N(1, 1); M(1, 2) = N(1, 2); M(1, 3) = N(1, 3); M(1, 4) = N(1, 4);

+		M(2, 1) = N(2, 1); M(2, 2) = N(2, 2); M(2, 3) = N(2, 3); M(2, 4) = N(2, 4);

+		M(3, 1) = N(3, 1); M(3, 2) = N(3, 2); M(3, 3) = N(3, 3); M(3, 4) = N(3, 4);

+		M(4, 1) = N(4, 1); M(4, 2) = N(4, 2); M(4, 3) = N(4, 3); M(4, 4) = N(4, 4);

+

+		return M;

+	}

+

+	inline float *Matrix::operator[](int i)

+	{

+		return m[i];

+	}

+

+	inline const float *Matrix::operator[](int i) const

+	{

+		return m[i];

+	}

+

+	inline float &Matrix::operator()(int i, int j)

+	{

+		return m[i - 1][j - 1];

+	}

+

+	inline const float &Matrix::operator()(int i, int j) const

+	{

+		return m[i - 1][j - 1];

+	}

+}

+

+#endif   // Matrix_hpp

diff --git a/src/Renderer/PixelProcessor.cpp b/src/Renderer/PixelProcessor.cpp
index b0b285a..bd6ea30 100644
--- a/src/Renderer/PixelProcessor.cpp
+++ b/src/Renderer/PixelProcessor.cpp
@@ -1,6 +1,6 @@
 // SwiftShader Software Renderer
 //
-// Copyright(c) 2005-2011 TransGaming Inc.
+// Copyright(c) 2005-2012 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
@@ -59,6 +59,7 @@
 		                             // Round to nearest LOD [0.7, 1.4]:  0.0
 		                             // Round to lowest LOD  [1.0, 2.0]:  0.5
 
+		precacheDLL = 0;
 		routineCache = 0;
 		setRoutineCacheSize(1024);
 	}
@@ -813,15 +814,15 @@
 
 		if(context->pixelShader)
 		{
-			state.shaderHash = context->pixelShader->getHash();
+			state.shaderID = context->pixelShader->getSerialID();
 		}
 		else
 		{
-			state.shaderHash = 0;
+			state.shaderID = 0;
 		}
 
 		state.depthOverride = context->pixelShader && context->pixelShader->depthOverride();
-		state.shaderContainsTexkill = context->pixelShader ? context->pixelShader->containsTexkill() : false;
+		state.shaderContainsKill = context->pixelShader ? context->pixelShader->containsKill() : false;
 		
 		if(context->alphaTestActive())
 		{
@@ -1004,8 +1005,8 @@
 
 						switch(context->pixelShader->semantic[interpolant][component].usage)
 						{
-						case ShaderOperation::USAGE_TEXCOORD:	flat = point && !sprite;	break;
-						case ShaderOperation::USAGE_COLOR:		flat = flatShading;			break;
+						case Shader::USAGE_TEXCOORD:	flat = point && !sprite;	break;
+						case Shader::USAGE_COLOR:		flat = flatShading;			break;
 						}
 
 						state.interpolant[interpolant].component |= 1 << component;
diff --git a/src/Renderer/PixelProcessor.hpp b/src/Renderer/PixelProcessor.hpp
index 98b73ca..0c0122a 100644
--- a/src/Renderer/PixelProcessor.hpp
+++ b/src/Renderer/PixelProcessor.hpp
@@ -1,309 +1,310 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2011 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 sw_PixelProcessor_hpp
-#define sw_PixelProcessor_hpp
-
-#include "Context.hpp"
-#include "LRUCache.hpp"
-
-namespace sw
-{
-	class PixelShader;
-	class Rasterizer;
-	struct Texture;
-	class Routine;
-	struct DrawData;
-
-	class PixelProcessor
-	{
-	public:
-		struct States
-		{
-			unsigned int computeHash();
-
-			uint64_t shaderHash;
-
-			unsigned int depthOverride            : 1;
-			unsigned int shaderContainsTexkill    : 1;
-
-			unsigned int depthCompareMode         : BITS(Context::DEPTH_LAST);
-			unsigned int alphaCompareMode         : BITS(Context::ALPHA_LAST);
-			unsigned int depthWriteEnable         : 1;
-			unsigned int quadLayoutDepthBuffer    : 1;
-
-			unsigned int stencilActive            : 1;
-			unsigned int stencilCompareMode       : BITS(Context::STENCIL_LAST);
-			unsigned int stencilFailOperation     : BITS(Context::OPERATION_LAST);
-			unsigned int stencilPassOperation     : BITS(Context::OPERATION_LAST);
-			unsigned int stencilZFailOperation    : BITS(Context::OPERATION_LAST);
-			unsigned int noStencilMask            : 1;
-			unsigned int noStencilWriteMask       : 1;
-			unsigned int stencilWriteMasked       : 1;
-			unsigned int twoSidedStencil          : 1;
-			unsigned int stencilCompareModeCCW    : BITS(Context::STENCIL_LAST);
-			unsigned int stencilFailOperationCCW  : BITS(Context::OPERATION_LAST);
-			unsigned int stencilPassOperationCCW  : BITS(Context::OPERATION_LAST);
-			unsigned int stencilZFailOperationCCW : BITS(Context::OPERATION_LAST);
-			unsigned int noStencilMaskCCW         : 1;
-			unsigned int noStencilWriteMaskCCW    : 1;
-			unsigned int stencilWriteMaskedCCW    : 1;
-
-			unsigned int depthTestActive          : 1;
-			unsigned int fogActive                : 1;
-			unsigned int pixelFogMode             : BITS(Context::FOG_LAST);
-			unsigned int specularAdd              : 1;
-			unsigned int occlusionEnabled         : 1;
-			unsigned int wBasedFog                : 1;
-			unsigned int perspective              : 1;
-
-			unsigned int alphaBlendActive         : 1;
-			unsigned int sourceBlendFactor        : BITS(Context::BLEND_LAST);
-			unsigned int destBlendFactor          : BITS(Context::BLEND_LAST);
-			unsigned int blendOperation           : BITS(Context::BLENDOP_LAST);
-			unsigned int sourceBlendFactorAlpha   : BITS(Context::BLEND_LAST);
-			unsigned int destBlendFactorAlpha     : BITS(Context::BLEND_LAST);
-			unsigned int blendOperationAlpha      : BITS(Context::BLENDOP_LAST);
-			
-			unsigned int colorWriteMask           : 16;   // (four times four component bit mask)
-			unsigned char targetFormat[4];
-			unsigned int writeSRGB                : 1;
-			unsigned int multiSample              : 3;
-			unsigned int multiSampleMask          : 4;
-			unsigned int transparencyAntialiasing : BITS(Context::TRANSPARENCY_LAST);
-			unsigned int centroid                 : 1;
-
-			Sampler::State sampler[16];
-			TextureStage::State textureStage[8];
-
-			struct Interpolant
-			{
-				unsigned char component : 4;
-				unsigned char flat : 4;
-				unsigned char project : 2;
-				unsigned char centroid : 1;
-			};
-
-			union
-			{
-				struct
-				{
-					Interpolant color[2];
-					Interpolant texture[8];
-					Interpolant fog;
-				};
-
-				Interpolant interpolant[10];
-			};
-		};
-
-		struct State : States
-		{
-			State();
-
-			bool operator==(const State &state) const;
-
-			int colorWriteActive(int index) const
-			{
-				return (colorWriteMask >> (index * 4)) & 0xF;
-			}
-
-			bool alphaTestActive() const
-			{
-				return alphaCompareMode != Context::ALPHA_ALWAYS;
-			}
-
-			bool pixelFogActive() const
-			{
-				return pixelFogMode != Context::FOG_NONE;
-			}
-
-			unsigned int hash;
-		};
-
-		struct Stencil
-		{
-			int64_t testMaskQ;
-			int64_t referenceMaskedQ;
-			int64_t referenceMaskedSignedQ;
-			int64_t writeMaskQ;
-			int64_t invWriteMaskQ;
-			int64_t referenceQ;
-
-			void set(int reference, int testMask, int writeMask)
-			{
-				referenceQ = replicate(reference);
-				testMaskQ = replicate(testMask);
-				writeMaskQ = replicate(writeMask);
-				invWriteMaskQ = ~writeMaskQ;
-				referenceMaskedQ = referenceQ & testMaskQ;
-				referenceMaskedSignedQ = replicate((reference + 0x80) & 0xFF & testMask);
-			}
-
-			static int64_t replicate(int b)
-			{
-				int64_t w = b & 0xFF;
-
-				return (w << 0) | (w << 8) | (w << 16) | (w << 24) | (w << 32) | (w << 40) | (w << 48) | (w << 56);
-			}
-		};
-
-		struct Fog
-		{
-			float4 scale;
-			float4 offset;
-			word4 color4[3];
-			float4 colorF[3];
-			float4 densityE;
-			float4 densityE2;
-		};
-
-		struct Factor
-		{
-			word4 textureFactor4[4];
-
-			word4 alphaReference4;
-
-			word4 blendConstant4W[4];
-			float4 blendConstant4F[4];
-			word4 invBlendConstant4W[4];
-			float4 invBlendConstant4F[4];
-		};
-
-	public:
-		typedef void (__cdecl *RoutinePointer)(const Primitive *primitive, int count, int thread, DrawData *draw);
-
-		PixelProcessor(Context *context);
-
-		virtual ~PixelProcessor();
-
-		virtual void setFloatConstant(unsigned int index, const float value[4]);
-		virtual void setIntegerConstant(unsigned int index, const int value[4]);
-		virtual void setBooleanConstant(unsigned int index, int boolean);
-
-		virtual void setRenderTarget(int index, Surface *renderTarget);
-		virtual void setDepthStencil(Surface *depthStencil);
-
-		virtual void setTexCoordIndex(unsigned int stage, int texCoordIndex);
-		virtual void setStageOperation(unsigned int stage, TextureStage::StageOperation stageOperation);
-		virtual void setFirstArgument(unsigned int stage, TextureStage::SourceArgument firstArgument);
-		virtual void setSecondArgument(unsigned int stage, TextureStage::SourceArgument secondArgument);
-		virtual void setThirdArgument(unsigned int stage, TextureStage::SourceArgument thirdArgument);
-		virtual void setStageOperationAlpha(unsigned int stage, TextureStage::StageOperation stageOperationAlpha);
-		virtual void setFirstArgumentAlpha(unsigned int stage, TextureStage::SourceArgument firstArgumentAlpha);
-		virtual void setSecondArgumentAlpha(unsigned int stage, TextureStage::SourceArgument secondArgumentAlpha);
-		virtual void setThirdArgumentAlpha(unsigned int stage, TextureStage::SourceArgument thirdArgumentAlpha);
-		virtual void setFirstModifier(unsigned int stage, TextureStage::ArgumentModifier firstModifier);
-		virtual void setSecondModifier(unsigned int stage, TextureStage::ArgumentModifier secondModifier);
-		virtual void setThirdModifier(unsigned int stage, TextureStage::ArgumentModifier thirdModifier);
-		virtual void setFirstModifierAlpha(unsigned int stage, TextureStage::ArgumentModifier firstModifierAlpha);
-		virtual void setSecondModifierAlpha(unsigned int stage, TextureStage::ArgumentModifier secondModifierAlpha);
-		virtual void setThirdModifierAlpha(unsigned int stage, TextureStage::ArgumentModifier thirdModifierAlpha);
-		virtual void setDestinationArgument(unsigned int stage, TextureStage::DestinationArgument destinationArgument);
-		virtual void setConstantColor(unsigned int stage, const Color<float> &constantColor);
-		virtual void setBumpmapMatrix(unsigned int stage, int element, float value);
-		virtual void setLuminanceScale(unsigned int stage, float value);
-		virtual void setLuminanceOffset(unsigned int stage, float value);
-
-		virtual void setTextureFilter(unsigned int sampler, FilterType textureFilter);
-		virtual void setMipmapFilter(unsigned int sampler, MipmapType mipmapFilter);
-		virtual void setGatherEnable(unsigned int sampler, bool enable);
-		virtual void setAddressingModeU(unsigned int sampler, AddressingMode addressingMode);
-		virtual void setAddressingModeV(unsigned int sampler, AddressingMode addressingMode);
-		virtual void setAddressingModeW(unsigned int sampler, AddressingMode addressingMode);
-		virtual void setReadSRGB(unsigned int sampler, bool sRGB);
-		virtual void setMipmapLOD(unsigned int sampler, float bias);
-		virtual void setBorderColor(unsigned int sampler, const Color<float> &borderColor);
-		virtual void setMaxAnisotropy(unsigned int sampler, unsigned int maxAnisotropy);
-
-		virtual void setWriteSRGB(bool sRGB);
-		virtual void setDepthBufferEnable(bool depthBufferEnable);
-		virtual void setDepthCompare(Context::DepthCompareMode depthCompareMode);
-		virtual void setAlphaCompare(Context::AlphaCompareMode alphaCompareMode);
-		virtual void setDepthWriteEnable(bool depthWriteEnable);
-		virtual void setAlphaTestEnable(bool alphaTestEnable);
-		virtual void setCullMode(Context::CullMode cullMode);
-		virtual void setColorWriteMask(int index, int rgbaMask);
-
-		virtual void setStencilEnable(bool stencilEnable);
-		virtual void setStencilCompare(Context::StencilCompareMode stencilCompareMode);
-		virtual void setStencilReference(int stencilReference);
-		virtual void setStencilMask(int stencilMask);
-		virtual void setStencilFailOperation(Context::StencilOperation stencilFailOperation);
-		virtual void setStencilPassOperation(Context::StencilOperation stencilPassOperation);
-		virtual void setStencilZFailOperation(Context::StencilOperation stencilZFailOperation);
-		virtual void setStencilWriteMask(int stencilWriteMask);
-		virtual void setTwoSidedStencil(bool enable);
-		virtual void setStencilCompareCCW(Context::StencilCompareMode stencilCompareMode);
-		virtual void setStencilReferenceCCW(int stencilReference);
-		virtual void setStencilMaskCCW(int stencilMask);
-		virtual void setStencilFailOperationCCW(Context::StencilOperation stencilFailOperation);
-		virtual void setStencilPassOperationCCW(Context::StencilOperation stencilPassOperation);
-		virtual void setStencilZFailOperationCCW(Context::StencilOperation stencilZFailOperation);
-		virtual void setStencilWriteMaskCCW(int stencilWriteMask);
-
-		virtual void setTextureFactor(const Color<float> &textureFactor);
-		virtual void setBlendConstant(const Color<float> &blendConstant);
-
-		virtual void setFillMode(Context::FillMode fillMode);
-		virtual void setShadingMode(Context::ShadingMode shadingMode);
-		
-		virtual void setAlphaBlendEnable(bool alphaBlendEnable);
-		virtual void setSourceBlendFactor(Context::BlendFactor sourceBlendFactor);
-		virtual void setDestBlendFactor(Context::BlendFactor destBlendFactor);
-		virtual void setBlendOperation(Context::BlendOperation blendOperation);
-
-		virtual void setSeparateAlphaBlendEnable(bool separateAlphaBlendEnable);
-		virtual void setSourceBlendFactorAlpha(Context::BlendFactor sourceBlendFactorAlpha);
-		virtual void setDestBlendFactorAlpha(Context::BlendFactor destBlendFactorAlpha);
-		virtual void setBlendOperationAlpha(Context::BlendOperation blendOperationAlpha);
-
-		virtual void setAlphaReference(int alphaReference);
-
-		virtual void setGlobalMipmapBias(float bias);
-
-		virtual void setFogStart(float start);
-		virtual void setFogEnd(float end);
-		virtual void setFogColor(Color<float> fogColor);
-		virtual void setFogDensity(float fogDensity);
-		virtual void setPixelFogMode(Context::FogMode fogMode);
-
-		virtual void setPerspectiveCorrection(bool perspectiveCorrection);
-
-		virtual void setOcclusionEnabled(bool enable);
-
-	protected:
-		const State update() const;
-		Routine *routine(const State &state);
-		void setRoutineCacheSize(int routineCacheSize);
-
-		// Shader constants
-		word4 cW[8][4];
-		float4 c[224];
-		int4 i[16];
-		bool b[16];
-
-		// Other semi-constants
-		Stencil stencil;
-		Stencil stencilCCW;
-		Fog fog;
-		Factor factor;
-
-	private:
-		void setFogRanges(float start, float end);
-
-		Context *const context;
-
-		LRUCache<State, Routine> *routineCache;
-	};
-}
-
-#endif   // sw_PixelProcessor_hpp
+// SwiftShader Software Renderer

+//

+// Copyright(c) 2005-2012 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 sw_PixelProcessor_hpp

+#define sw_PixelProcessor_hpp

+

+#include "Context.hpp"

+#include "LRUCache.hpp"

+

+namespace sw

+{

+	class PixelShader;

+	class Rasterizer;

+	struct Texture;

+	class Routine;

+	struct DrawData;

+

+	class PixelProcessor

+	{

+	public:

+		struct States

+		{

+			unsigned int computeHash();

+

+			int shaderID;

+

+			unsigned int depthOverride            : 1;

+			unsigned int shaderContainsKill       : 1;

+

+			unsigned int depthCompareMode         : BITS(Context::DEPTH_LAST);

+			unsigned int alphaCompareMode         : BITS(Context::ALPHA_LAST);

+			unsigned int depthWriteEnable         : 1;

+			unsigned int quadLayoutDepthBuffer    : 1;

+

+			unsigned int stencilActive            : 1;

+			unsigned int stencilCompareMode       : BITS(Context::STENCIL_LAST);

+			unsigned int stencilFailOperation     : BITS(Context::OPERATION_LAST);

+			unsigned int stencilPassOperation     : BITS(Context::OPERATION_LAST);

+			unsigned int stencilZFailOperation    : BITS(Context::OPERATION_LAST);

+			unsigned int noStencilMask            : 1;

+			unsigned int noStencilWriteMask       : 1;

+			unsigned int stencilWriteMasked       : 1;

+			unsigned int twoSidedStencil          : 1;

+			unsigned int stencilCompareModeCCW    : BITS(Context::STENCIL_LAST);

+			unsigned int stencilFailOperationCCW  : BITS(Context::OPERATION_LAST);

+			unsigned int stencilPassOperationCCW  : BITS(Context::OPERATION_LAST);

+			unsigned int stencilZFailOperationCCW : BITS(Context::OPERATION_LAST);

+			unsigned int noStencilMaskCCW         : 1;

+			unsigned int noStencilWriteMaskCCW    : 1;

+			unsigned int stencilWriteMaskedCCW    : 1;

+

+			unsigned int depthTestActive          : 1;

+			unsigned int fogActive                : 1;

+			unsigned int pixelFogMode             : BITS(Context::FOG_LAST);

+			unsigned int specularAdd              : 1;

+			unsigned int occlusionEnabled         : 1;

+			unsigned int wBasedFog                : 1;

+			unsigned int perspective              : 1;

+

+			unsigned int alphaBlendActive         : 1;

+			unsigned int sourceBlendFactor        : BITS(Context::BLEND_LAST);

+			unsigned int destBlendFactor          : BITS(Context::BLEND_LAST);

+			unsigned int blendOperation           : BITS(Context::BLENDOP_LAST);

+			unsigned int sourceBlendFactorAlpha   : BITS(Context::BLEND_LAST);

+			unsigned int destBlendFactorAlpha     : BITS(Context::BLEND_LAST);

+			unsigned int blendOperationAlpha      : BITS(Context::BLENDOP_LAST);

+			

+			unsigned int colorWriteMask           : 16;   // (four times four component bit mask)

+			unsigned char targetFormat[4];

+			unsigned int writeSRGB                : 1;

+			unsigned int multiSample              : 3;

+			unsigned int multiSampleMask          : 4;

+			unsigned int transparencyAntialiasing : BITS(Context::TRANSPARENCY_LAST);

+			unsigned int centroid                 : 1;

+

+			Sampler::State sampler[16];

+			TextureStage::State textureStage[8];

+

+			struct Interpolant

+			{

+				unsigned char component : 4;

+				unsigned char flat : 4;

+				unsigned char project : 2;

+				unsigned char centroid : 1;

+			};

+

+			union

+			{

+				struct

+				{

+					Interpolant color[2];

+					Interpolant texture[8];

+					Interpolant fog;

+				};

+

+				Interpolant interpolant[10];

+			};

+		};

+

+		struct State : States

+		{

+			State();

+

+			bool operator==(const State &state) const;

+

+			int colorWriteActive(int index) const

+			{

+				return (colorWriteMask >> (index * 4)) & 0xF;

+			}

+

+			bool alphaTestActive() const

+			{

+				return alphaCompareMode != Context::ALPHA_ALWAYS;

+			}

+

+			bool pixelFogActive() const

+			{

+				return pixelFogMode != Context::FOG_NONE;

+			}

+

+			unsigned int hash;

+		};

+

+		struct Stencil

+		{

+			int64_t testMaskQ;

+			int64_t referenceMaskedQ;

+			int64_t referenceMaskedSignedQ;

+			int64_t writeMaskQ;

+			int64_t invWriteMaskQ;

+			int64_t referenceQ;

+

+			void set(int reference, int testMask, int writeMask)

+			{

+				referenceQ = replicate(reference);

+				testMaskQ = replicate(testMask);

+				writeMaskQ = replicate(writeMask);

+				invWriteMaskQ = ~writeMaskQ;

+				referenceMaskedQ = referenceQ & testMaskQ;

+				referenceMaskedSignedQ = replicate((reference + 0x80) & 0xFF & testMask);

+			}

+

+			static int64_t replicate(int b)

+			{

+				int64_t w = b & 0xFF;

+

+				return (w << 0) | (w << 8) | (w << 16) | (w << 24) | (w << 32) | (w << 40) | (w << 48) | (w << 56);

+			}

+		};

+

+		struct Fog

+		{

+			float4 scale;

+			float4 offset;

+			word4 color4[3];

+			float4 colorF[3];

+			float4 densityE;

+			float4 densityE2;

+		};

+

+		struct Factor

+		{

+			word4 textureFactor4[4];

+

+			word4 alphaReference4;

+

+			word4 blendConstant4W[4];

+			float4 blendConstant4F[4];

+			word4 invBlendConstant4W[4];

+			float4 invBlendConstant4F[4];

+		};

+

+	public:

+		typedef void (__cdecl *RoutinePointer)(const Primitive *primitive, int count, int thread, DrawData *draw);

+

+		PixelProcessor(Context *context);

+

+		virtual ~PixelProcessor();

+

+		virtual void setFloatConstant(unsigned int index, const float value[4]);

+		virtual void setIntegerConstant(unsigned int index, const int value[4]);

+		virtual void setBooleanConstant(unsigned int index, int boolean);

+

+		virtual void setRenderTarget(int index, Surface *renderTarget);

+		virtual void setDepthStencil(Surface *depthStencil);

+

+		virtual void setTexCoordIndex(unsigned int stage, int texCoordIndex);

+		virtual void setStageOperation(unsigned int stage, TextureStage::StageOperation stageOperation);

+		virtual void setFirstArgument(unsigned int stage, TextureStage::SourceArgument firstArgument);

+		virtual void setSecondArgument(unsigned int stage, TextureStage::SourceArgument secondArgument);

+		virtual void setThirdArgument(unsigned int stage, TextureStage::SourceArgument thirdArgument);

+		virtual void setStageOperationAlpha(unsigned int stage, TextureStage::StageOperation stageOperationAlpha);

+		virtual void setFirstArgumentAlpha(unsigned int stage, TextureStage::SourceArgument firstArgumentAlpha);

+		virtual void setSecondArgumentAlpha(unsigned int stage, TextureStage::SourceArgument secondArgumentAlpha);

+		virtual void setThirdArgumentAlpha(unsigned int stage, TextureStage::SourceArgument thirdArgumentAlpha);

+		virtual void setFirstModifier(unsigned int stage, TextureStage::ArgumentModifier firstModifier);

+		virtual void setSecondModifier(unsigned int stage, TextureStage::ArgumentModifier secondModifier);

+		virtual void setThirdModifier(unsigned int stage, TextureStage::ArgumentModifier thirdModifier);

+		virtual void setFirstModifierAlpha(unsigned int stage, TextureStage::ArgumentModifier firstModifierAlpha);

+		virtual void setSecondModifierAlpha(unsigned int stage, TextureStage::ArgumentModifier secondModifierAlpha);

+		virtual void setThirdModifierAlpha(unsigned int stage, TextureStage::ArgumentModifier thirdModifierAlpha);

+		virtual void setDestinationArgument(unsigned int stage, TextureStage::DestinationArgument destinationArgument);

+		virtual void setConstantColor(unsigned int stage, const Color<float> &constantColor);

+		virtual void setBumpmapMatrix(unsigned int stage, int element, float value);

+		virtual void setLuminanceScale(unsigned int stage, float value);

+		virtual void setLuminanceOffset(unsigned int stage, float value);

+

+		virtual void setTextureFilter(unsigned int sampler, FilterType textureFilter);

+		virtual void setMipmapFilter(unsigned int sampler, MipmapType mipmapFilter);

+		virtual void setGatherEnable(unsigned int sampler, bool enable);

+		virtual void setAddressingModeU(unsigned int sampler, AddressingMode addressingMode);

+		virtual void setAddressingModeV(unsigned int sampler, AddressingMode addressingMode);

+		virtual void setAddressingModeW(unsigned int sampler, AddressingMode addressingMode);

+		virtual void setReadSRGB(unsigned int sampler, bool sRGB);

+		virtual void setMipmapLOD(unsigned int sampler, float bias);

+		virtual void setBorderColor(unsigned int sampler, const Color<float> &borderColor);

+		virtual void setMaxAnisotropy(unsigned int sampler, unsigned int maxAnisotropy);

+

+		virtual void setWriteSRGB(bool sRGB);

+		virtual void setDepthBufferEnable(bool depthBufferEnable);

+		virtual void setDepthCompare(Context::DepthCompareMode depthCompareMode);

+		virtual void setAlphaCompare(Context::AlphaCompareMode alphaCompareMode);

+		virtual void setDepthWriteEnable(bool depthWriteEnable);

+		virtual void setAlphaTestEnable(bool alphaTestEnable);

+		virtual void setCullMode(Context::CullMode cullMode);

+		virtual void setColorWriteMask(int index, int rgbaMask);

+

+		virtual void setStencilEnable(bool stencilEnable);

+		virtual void setStencilCompare(Context::StencilCompareMode stencilCompareMode);

+		virtual void setStencilReference(int stencilReference);

+		virtual void setStencilMask(int stencilMask);

+		virtual void setStencilFailOperation(Context::StencilOperation stencilFailOperation);

+		virtual void setStencilPassOperation(Context::StencilOperation stencilPassOperation);

+		virtual void setStencilZFailOperation(Context::StencilOperation stencilZFailOperation);

+		virtual void setStencilWriteMask(int stencilWriteMask);

+		virtual void setTwoSidedStencil(bool enable);

+		virtual void setStencilCompareCCW(Context::StencilCompareMode stencilCompareMode);

+		virtual void setStencilReferenceCCW(int stencilReference);

+		virtual void setStencilMaskCCW(int stencilMask);

+		virtual void setStencilFailOperationCCW(Context::StencilOperation stencilFailOperation);

+		virtual void setStencilPassOperationCCW(Context::StencilOperation stencilPassOperation);

+		virtual void setStencilZFailOperationCCW(Context::StencilOperation stencilZFailOperation);

+		virtual void setStencilWriteMaskCCW(int stencilWriteMask);

+

+		virtual void setTextureFactor(const Color<float> &textureFactor);

+		virtual void setBlendConstant(const Color<float> &blendConstant);

+

+		virtual void setFillMode(Context::FillMode fillMode);

+		virtual void setShadingMode(Context::ShadingMode shadingMode);

+		

+		virtual void setAlphaBlendEnable(bool alphaBlendEnable);

+		virtual void setSourceBlendFactor(Context::BlendFactor sourceBlendFactor);

+		virtual void setDestBlendFactor(Context::BlendFactor destBlendFactor);

+		virtual void setBlendOperation(Context::BlendOperation blendOperation);

+

+		virtual void setSeparateAlphaBlendEnable(bool separateAlphaBlendEnable);

+		virtual void setSourceBlendFactorAlpha(Context::BlendFactor sourceBlendFactorAlpha);

+		virtual void setDestBlendFactorAlpha(Context::BlendFactor destBlendFactorAlpha);

+		virtual void setBlendOperationAlpha(Context::BlendOperation blendOperationAlpha);

+

+		virtual void setAlphaReference(int alphaReference);

+

+		virtual void setGlobalMipmapBias(float bias);

+

+		virtual void setFogStart(float start);

+		virtual void setFogEnd(float end);

+		virtual void setFogColor(Color<float> fogColor);

+		virtual void setFogDensity(float fogDensity);

+		virtual void setPixelFogMode(Context::FogMode fogMode);

+

+		virtual void setPerspectiveCorrection(bool perspectiveCorrection);

+

+		virtual void setOcclusionEnabled(bool enable);

+

+	protected:

+		const State update() const;

+		Routine *routine(const State &state);

+		void setRoutineCacheSize(int routineCacheSize);

+

+		// Shader constants

+		word4 cW[8][4];

+		float4 c[224];

+		int4 i[16];

+		bool b[16];

+

+		// Other semi-constants

+		Stencil stencil;

+		Stencil stencilCCW;

+		Fog fog;

+		Factor factor;

+

+	private:

+		void setFogRanges(float start, float end);

+

+		Context *const context;

+

+		LRUCache<State, Routine> *routineCache;

+		HMODULE precacheDLL;

+	};

+}

+

+#endif   // sw_PixelProcessor_hpp

diff --git a/src/Renderer/Plane.hpp b/src/Renderer/Plane.hpp
index 34f7679..0c0ef32 100644
--- a/src/Renderer/Plane.hpp
+++ b/src/Renderer/Plane.hpp
@@ -1,69 +1,69 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2011 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 Plane_hpp
-#define Plane_hpp
-
-#include "Vector.hpp"
-
-namespace sw
-{
-	struct Matrix;
-	struct Point;
-
-	struct Plane
-	{
-		union
-		{
-			struct
-			{
-				float A;
-				float B;
-				float C;
-			};
-			struct
-			{
-				Vector n;
-			};
-		};
-
-		float D;   // Distance to origin along normal
-
-		Plane();
-		Plane(const Plane &p);
-		Plane(const Vector &n, float D);   // Normal and distance to origin
-		Plane(const Vector &n, const Point &P);   // Normal and point on plane
-		Plane(const Point &P0, const Point &P1, const Point &P2);   // Through three points
-		Plane(float A, float B, float C, float D);   // Plane equation 
-		Plane(const float ABCD[4]);
-
-		Plane &operator=(const Plane &p);
-
-		Plane operator+() const;
-		Plane operator-() const;   // Flip normal
-
-		Plane &operator*=(const Matrix &A);   // Transform plane by matrix (post-multiply)
-
-		friend Plane operator*(const Plane &p, const Matrix &A);   // Transform plane by matrix (post-multiply)
-		friend Plane operator*(const Matrix &A, const Plane &p);   // Transform plane by matrix (pre-multiply)
-
-		friend float operator^(const Plane &p1, const Plane &p2);   // Angle between planes
-
-		float d(const Point &P) const;   // Oriented distance between point and plane
-
-		static float d(const Point &P, const Plane &p);   // Oriented distance between point and plane
-		static float d(const Plane &p, const Point &P);   // Oriented distance between plane and point
-
-		Plane &normalise();   // Normalise the Plane equation
-	};
-}
-
-#endif   // Plane_hpp
+// SwiftShader Software Renderer

+//

+// Copyright(c) 2005-2011 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 Plane_hpp

+#define Plane_hpp

+

+#include "Vector.hpp"

+

+namespace sw

+{

+	struct Matrix;

+	struct Point;

+

+	struct Plane

+	{

+		union

+		{

+			struct

+			{

+				float A;

+				float B;

+				float C;

+			};

+			struct

+			{

+				Vector n;

+			};

+		};

+

+		float D;   // Distance to origin along normal

+

+		Plane();

+		Plane(const Plane &p);

+		Plane(const Vector &n, float D);   // Normal and distance to origin

+		Plane(const Vector &n, const Point &P);   // Normal and point on plane

+		Plane(const Point &P0, const Point &P1, const Point &P2);   // Through three points

+		Plane(float A, float B, float C, float D);   // Plane equation 

+		Plane(const float ABCD[4]);

+

+		Plane &operator=(const Plane &p);

+

+		Plane operator+() const;

+		Plane operator-() const;   // Flip normal

+

+		Plane &operator*=(const Matrix &A);   // Transform plane by matrix (post-multiply)

+

+		friend Plane operator*(const Plane &p, const Matrix &A);   // Transform plane by matrix (post-multiply)

+		friend Plane operator*(const Matrix &A, const Plane &p);   // Transform plane by matrix (pre-multiply)

+

+		friend float operator^(const Plane &p1, const Plane &p2);   // Angle between planes

+

+		float d(const Point &P) const;   // Oriented distance between point and plane

+

+		static float d(const Point &P, const Plane &p);   // Oriented distance between point and plane

+		static float d(const Plane &p, const Point &P);   // Oriented distance between plane and point

+

+		Plane &normalise();   // Normalise the Plane equation

+	};

+}

+

+#endif   // Plane_hpp

diff --git a/src/Renderer/Point.hpp b/src/Renderer/Point.hpp
index 7b50f58..1448ee0 100644
--- a/src/Renderer/Point.hpp
+++ b/src/Renderer/Point.hpp
@@ -1,136 +1,136 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2011 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 Point_hpp
-#define Point_hpp
-
-namespace sw
-{
-	struct Vector;
-	struct Matrix;
-
-	struct Point
-	{
-		Point();
-		Point(const int i);
-		Point(const Point &P);
-		Point(const Vector &v);
-		Point(float Px, float Py, float Pz);
-
-		Point &operator=(const Point &P);
-
-		union
-		{
-			float p[3];
-
-			struct
-			{		
-				float x;
-				float y;
-				float z;
-			};
-		};
-
-		float &operator[](int i);
-		float &operator()(int i);
-
-		const float &operator[](int i) const;
-		const float &operator()(int i) const;
-
-		Point &operator+=(const Vector &v);
-		Point &operator-=(const Vector &v);
-
-		friend Point operator+(const Point &P, const Vector &v);
-		friend Point operator-(const Point &P, const Vector &v);
-
-		friend Vector operator-(const Point &P, const Point &Q);
-
-		friend Point operator*(const Matrix &M, const Point& P);
-		friend Point operator*(const Point &P, const Matrix &M);
-		friend Point &operator*=(Point &P, const Matrix &M);
-
-		float d(const Point &P) const;   // Distance between two points
-		float d2(const Point &P) const;   // Squared distance between two points
-
-		static float d(const Point &P, const Point &Q);   // Distance between two points
-		static float d2(const Point &P, const Point &Q);   // Squared distance between two points
-	};
-}
-
-#include "Vector.hpp"
-
-namespace sw
-{
-	inline Point::Point()
-	{
-	}
-
-	inline Point::Point(const int i)
-	{
-		const float s = (float)i;
-
-		x = s;
-		y = s;
-		z = s;
-	}
-
-	inline Point::Point(const Point &P)
-	{
-		x = P.x;
-		y = P.y;
-		z = P.z;
-	}
-
-	inline Point::Point(const Vector &v)
-	{
-		x = v.x;
-		y = v.y;
-		z = v.z;
-	}
-
-	inline Point::Point(float P_x, float P_y, float P_z)
-	{
-		x = P_x;
-		y = P_y;
-		z = P_z;
-	}
-
-	inline Point &Point::operator=(const Point &P)
-	{
-		x = P.x;
-		y = P.y;
-		z = P.z;
-
-		return *this;
-	}
-
-	inline float &Point::operator()(int i)
-	{
-		return p[i];
-	}
-
-	inline float &Point::operator[](int i)
-	{
-		return p[i];
-	}
-
-	inline const float &Point::operator()(int i) const
-	{
-		return p[i];
-	}
-
-	inline const float &Point::operator[](int i) const
-	{
-		return p[i];
-	}
-}
-
-#endif   // Point_hpp
+// SwiftShader Software Renderer

+//

+// Copyright(c) 2005-2011 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 Point_hpp

+#define Point_hpp

+

+namespace sw

+{

+	struct Vector;

+	struct Matrix;

+

+	struct Point

+	{

+		Point();

+		Point(const int i);

+		Point(const Point &P);

+		Point(const Vector &v);

+		Point(float Px, float Py, float Pz);

+

+		Point &operator=(const Point &P);

+

+		union

+		{

+			float p[3];

+

+			struct

+			{		

+				float x;

+				float y;

+				float z;

+			};

+		};

+

+		float &operator[](int i);

+		float &operator()(int i);

+

+		const float &operator[](int i) const;

+		const float &operator()(int i) const;

+

+		Point &operator+=(const Vector &v);

+		Point &operator-=(const Vector &v);

+

+		friend Point operator+(const Point &P, const Vector &v);

+		friend Point operator-(const Point &P, const Vector &v);

+

+		friend Vector operator-(const Point &P, const Point &Q);

+

+		friend Point operator*(const Matrix &M, const Point& P);

+		friend Point operator*(const Point &P, const Matrix &M);

+		friend Point &operator*=(Point &P, const Matrix &M);

+

+		float d(const Point &P) const;   // Distance between two points

+		float d2(const Point &P) const;   // Squared distance between two points

+

+		static float d(const Point &P, const Point &Q);   // Distance between two points

+		static float d2(const Point &P, const Point &Q);   // Squared distance between two points

+	};

+}

+

+#include "Vector.hpp"

+

+namespace sw

+{

+	inline Point::Point()

+	{

+	}

+

+	inline Point::Point(const int i)

+	{

+		const float s = (float)i;

+

+		x = s;

+		y = s;

+		z = s;

+	}

+

+	inline Point::Point(const Point &P)

+	{

+		x = P.x;

+		y = P.y;

+		z = P.z;

+	}

+

+	inline Point::Point(const Vector &v)

+	{

+		x = v.x;

+		y = v.y;

+		z = v.z;

+	}

+

+	inline Point::Point(float P_x, float P_y, float P_z)

+	{

+		x = P_x;

+		y = P_y;

+		z = P_z;

+	}

+

+	inline Point &Point::operator=(const Point &P)

+	{

+		x = P.x;

+		y = P.y;

+		z = P.z;

+

+		return *this;

+	}

+

+	inline float &Point::operator()(int i)

+	{

+		return p[i];

+	}

+

+	inline float &Point::operator[](int i)

+	{

+		return p[i];

+	}

+

+	inline const float &Point::operator()(int i) const

+	{

+		return p[i];

+	}

+

+	inline const float &Point::operator[](int i) const

+	{

+		return p[i];

+	}

+}

+

+#endif   // Point_hpp

diff --git a/src/Renderer/QuadRasterizer.cpp b/src/Renderer/QuadRasterizer.cpp
index 10fcf16..d4548fe 100644
--- a/src/Renderer/QuadRasterizer.cpp
+++ b/src/Renderer/QuadRasterizer.cpp
@@ -1,6 +1,6 @@
 // SwiftShader Software Renderer
 //
-// Copyright(c) 2005-2011 TransGaming Inc.
+// Copyright(c) 2005-2012 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
@@ -45,7 +45,7 @@
 			Int cluster(function.arg(2));
 			Pointer<Byte> data(function.arg(3));
 
-			Registers r;
+			Registers r(shader);
 			r.constants = *Pointer<Pointer<Byte>>(data + OFFSET(DrawData,constants));
 			r.cluster = cluster;
 			r.data = data;
@@ -91,7 +91,7 @@
 			Return();
 		}
 
-		routine = function(L"PixelRoutine_%0.16llX", state.shaderHash);
+		routine = function(L"PixelRoutine_%0.8X", state.shaderID);
 	}
 
 	void QuadRasterizer::rasterize(Registers &r, Int &yMin, Int &yMax)
@@ -128,35 +128,35 @@
 
 			x0 = Int(*Pointer<Short>(r.primitive + OFFSET(Primitive,outline->left) + (y + 0) * sizeof(Primitive::Span)));
 			x2 = Int(*Pointer<Short>(r.primitive + OFFSET(Primitive,outline->left) + (y + 1) * sizeof(Primitive::Span)));
-			x0 = IfThenElse(x0 < x2, x0, x2);
+			x0 = Min(x0, x2);
 			
 			for(unsigned int q = 1; q < state.multiSample; q++)
 			{
 				Int x0q = Int(*Pointer<Short>(r.primitive + q * sizeof(Primitive) + OFFSET(Primitive,outline->left) + (y + 0) * sizeof(Primitive::Span)));
 				Int x2q = Int(*Pointer<Short>(r.primitive + q * sizeof(Primitive) + OFFSET(Primitive,outline->left) + (y + 1) * sizeof(Primitive::Span)));
-				x0q = IfThenElse(x0q < x2q, x0q, x2q);
+				x0q = Min(x0q, x2q);
 
-				x0 = IfThenElse(x0q < x0, x0q, x0);
+				x0 = Min(x0q, x0);
 			}
 			
 			x0 &= 0xFFFFFFFE;
 
 			x1 = Int(*Pointer<Short>(r.primitive + OFFSET(Primitive,outline->right) + (y + 0) * sizeof(Primitive::Span)));
 			x2 = Int(*Pointer<Short>(r.primitive + OFFSET(Primitive,outline->right) + (y + 1) * sizeof(Primitive::Span)));
-			x1 = IfThenElse(x1 > x2, x1, x2);
+			x1 = Max(x1, x2);
 
 			for(unsigned int q = 1; q < state.multiSample; q++)
 			{
 				Int x1q = Int(*Pointer<Short>(r.primitive + q * sizeof(Primitive) + OFFSET(Primitive,outline->right) + (y + 0) * sizeof(Primitive::Span)));
 				Int x2q = Int(*Pointer<Short>(r.primitive + q * sizeof(Primitive) + OFFSET(Primitive,outline->right) + (y + 1) * sizeof(Primitive::Span)));
-				x1q = IfThenElse(x1q > x2q, x1q, x2q);
+				x1q = Max(x1q, x2q);
 
-				x1 = IfThenElse(x1q > x1, x1q, x1);
+				x1 = Max(x1q, x1);
 			}
 
 			Float4 yyyy = Float4(Float(y)) + *Pointer<Float4>(r.primitive + OFFSET(Primitive,yQuad), 16);
 
-			if(state.depthTestActive || state.pixelFogActive())
+			if(interpolateZ())
 			{
 				for(unsigned int q = 0; q < state.multiSample; q++)
 				{
@@ -245,7 +245,7 @@
 
 			If(x0 < x1)
 			{
-				if(state.perspective)
+				if(interpolateW())
 				{
 					r.Dw = *Pointer<Float4>(r.primitive + OFFSET(Primitive,w.C), 16) + yyyy * *Pointer<Float4>(r.primitive + OFFSET(Primitive,w.B), 16);
 				}
@@ -299,18 +299,18 @@
 			{
 				if(state.colorWriteActive(index))
 				{
-					cBuffer[index] += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])) << (1 + log2(clusterCount));   // FIXME: Precompute
+					cBuffer[index] += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])) << (1 + sw::log2(clusterCount));   // FIXME: Precompute
 				}
 			}
 
 			if(state.depthTestActive)
 			{
-				zBuffer += *Pointer<Int>(r.data + OFFSET(DrawData,depthPitchB)) << (1 + log2(clusterCount));   // FIXME: Precompute
+				zBuffer += *Pointer<Int>(r.data + OFFSET(DrawData,depthPitchB)) << (1 + sw::log2(clusterCount));   // FIXME: Precompute
 			}
 
 			if(state.stencilActive)
 			{
-				sBuffer += *Pointer<Int>(r.data + OFFSET(DrawData,stencilPitchB)) << (1 + log2(clusterCount));   // FIXME: Precompute
+				sBuffer += *Pointer<Int>(r.data + OFFSET(DrawData,stencilPitchB)) << (1 + sw::log2(clusterCount));   // FIXME: Precompute
 			}
 
 			y += 2 * clusterCount;
diff --git a/src/Renderer/QuadRasterizer.hpp b/src/Renderer/QuadRasterizer.hpp
index 36184cc..4edfeac 100644
--- a/src/Renderer/QuadRasterizer.hpp
+++ b/src/Renderer/QuadRasterizer.hpp
@@ -1,34 +1,34 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2011 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 sw_QuadRasterizer_hpp
-#define sw_QuadRasterizer_hpp
-
-#include "Rasterizer.hpp"
-#include "PixelRoutine.hpp"
-
-namespace sw
-{
-	class QuadRasterizer : public PixelRoutine
-	{
-	public:
-		QuadRasterizer(const PixelProcessor::State &state, const PixelShader *pixelShader);
-
-		virtual ~QuadRasterizer();
-
-	private:
-		void generate();
-
-		void rasterize(Registers &r, Int &yMin, Int &yMax);
-	};
-}
-
-#endif   // sw_QuadRasterizer_hpp
+// SwiftShader Software Renderer

+//

+// Copyright(c) 2005-2011 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 sw_QuadRasterizer_hpp

+#define sw_QuadRasterizer_hpp

+

+#include "Rasterizer.hpp"

+#include "PixelRoutine.hpp"

+

+namespace sw

+{

+	class QuadRasterizer : public PixelRoutine

+	{

+	public:

+		QuadRasterizer(const PixelProcessor::State &state, const PixelShader *pixelShader);

+

+		virtual ~QuadRasterizer();

+

+	private:

+		void generate();

+

+		void rasterize(Registers &r, Int &yMin, Int &yMax);

+	};

+}

+

+#endif   // sw_QuadRasterizer_hpp

diff --git a/src/Renderer/Rasterizer.hpp b/src/Renderer/Rasterizer.hpp
index 0037379..061b399 100644
--- a/src/Renderer/Rasterizer.hpp
+++ b/src/Renderer/Rasterizer.hpp
@@ -1,39 +1,39 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2011 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 sw_Rasterizer_hpp
-#define sw_Rasterizer_hpp
-
-#include "Context.hpp"
-
-#include "PixelProcessor.hpp"
-#include "Config.hpp"
-
-namespace sw
-{
-	class Rasterizer
-	{
-	public:
-		Rasterizer(const PixelProcessor::State &state);
-
-		virtual ~Rasterizer();
-
-		virtual void generate() = 0;
-		Routine *getRoutine();
-
-	protected:
-		Routine *routine;
-
-		const PixelProcessor::State &state;
-	};
-}
-
-#endif   // sw_Rasterizer_hpp
+// SwiftShader Software Renderer

+//

+// Copyright(c) 2005-2011 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 sw_Rasterizer_hpp

+#define sw_Rasterizer_hpp

+

+#include "Context.hpp"

+

+#include "PixelProcessor.hpp"

+#include "Config.hpp"

+

+namespace sw

+{

+	class Rasterizer

+	{

+	public:

+		Rasterizer(const PixelProcessor::State &state);

+

+		virtual ~Rasterizer();

+

+		virtual void generate() = 0;

+		Routine *getRoutine();

+

+	protected:

+		Routine *routine;

+

+		const PixelProcessor::State &state;

+	};

+}

+

+#endif   // sw_Rasterizer_hpp

diff --git a/src/Renderer/Renderer.cpp b/src/Renderer/Renderer.cpp
index 0194f38..6a5195d 100644
--- a/src/Renderer/Renderer.cpp
+++ b/src/Renderer/Renderer.cpp
@@ -1,6 +1,6 @@
 // SwiftShader Software Renderer
 //
-// Copyright(c) 2005-2011 TransGaming Inc.
+// Copyright(c) 2005-2012 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
@@ -26,8 +26,7 @@
 #include "Resource.hpp"
 #include "Constants.hpp"
 #include "Debug.hpp"
-#include "SwiftShader.h"
-#include "Reactor/Shell.hpp"
+#include "Reactor/Reactor.hpp"
 
 #include <malloc.h>
 #include <assert.h>
@@ -35,10 +34,7 @@
 
 #undef max
 
-SWFILTER maximumFilterQuality = SWF_DEFAULT;
-SWFILTER maximumMipmapQuality = SWF_DEFAULT;
-SWPERSPECTIVE perspectiveQuality = SWP_DEFAULT;
-bool disableServer = false;
+bool disableServer = true;
 
 #ifndef NDEBUG
 unsigned int minPrimitives = 1;
@@ -47,6 +43,11 @@
 
 namespace sw
 {
+	extern bool halfIntegerCoordinates;     // Pixel centers are not at integer coordinates
+	extern bool symmetricNormalizedDepth;   // [-1, 1] instead of [0, 1]
+	extern bool booleanFaceRegister;
+	extern bool fullPixelPositionRegister;
+
 	extern bool forceWindowed;
 	extern bool complementaryDepthBuffer;
 	extern bool postBlendSRGB;
@@ -54,17 +55,17 @@
 	extern Context::TransparencyAntialiasing transparencyAntialiasing;
 	extern bool forceClearRegisters;
 
-	extern TranscendentalPrecision logPrecision;
-	extern TranscendentalPrecision expPrecision;
-	extern TranscendentalPrecision rcpPrecision;
-	extern TranscendentalPrecision rsqPrecision;
-	extern bool perspectiveCorrection;
-
 	int batchSize = 128;
 	int threadCount = 1;
 	int unitCount = 1;
 	int clusterCount = 1;
 
+	TranscendentalPrecision logPrecision = ACCURATE;
+	TranscendentalPrecision expPrecision = ACCURATE;
+	TranscendentalPrecision rcpPrecision = ACCURATE;
+	TranscendentalPrecision rsqPrecision = ACCURATE;
+	bool perspectiveCorrection = true;
+
 	struct Parameters
 	{
 		Renderer *renderer;
@@ -96,15 +97,17 @@
 		deallocate(data);
 	}
 
-	Renderer::Renderer(Context *context, Surface *renderTarget) : context(context), VertexProcessor(context), PixelProcessor(context), SetupProcessor(context), viewport()
+	Renderer::Renderer(Context *context, bool halfIntegerCoordinates, bool symmetricNormalizedDepth, bool booleanFaceRegister, bool fullPixelPositionRegister, bool exactColorRounding) : context(context), VertexProcessor(context), PixelProcessor(context), SetupProcessor(context), viewport()
 	{
-		setRenderTarget(0, renderTarget);
+		sw::halfIntegerCoordinates = halfIntegerCoordinates;
+		sw::symmetricNormalizedDepth = symmetricNormalizedDepth;
+		sw::booleanFaceRegister = booleanFaceRegister;
+		sw::fullPixelPositionRegister = fullPixelPositionRegister;
+		sw::exactColorRounding = exactColorRounding;
 
+		setRenderTarget(0, 0);
 		clipper = new Clipper();
 
-		posScale = vector(1.0f, 1.0f, 1.0f, 1.0f);
-		posOffset = vector(0.0f, 0.0f, 0.0f, 0.0f);
-
 		updateViewMatrix = true;
 		updateBaseMatrix = true;
 		updateProjectionMatrix = true;
@@ -158,11 +161,14 @@
 
 		swiftConfig = new SwiftConfig(disableServer);
 		updateConfiguration(true);
-		startupConfiguration();
+
+		sync = new Resource(0);
 	}
 
 	Renderer::~Renderer()
 	{
+		sync->destruct();
+
 		delete clipper;
 		clipper = 0;
 
@@ -204,13 +210,15 @@
 		for(int q = 0; q < ss; q++)
 		{
 			int oldMultiSampleMask = context->multiSampleMask;
-			context->multiSampleMask = (context->sampleMask >> (ms * q)) & ((unsigned)0xFFFFFFFF  >> (32 - ms));
+			context->multiSampleMask = (context->sampleMask >> (ms * q)) & ((unsigned)0xFFFFFFFF >> (32 - ms));
 
 			if(!context->multiSampleMask)
 			{
 				continue;
 			}
 
+			sync->lock(sw::PRIVATE);
+
 			if(update || oldMultiSampleMask != context->multiSampleMask)
 			{
 				vertexState = VertexProcessor::update();
@@ -471,12 +479,12 @@
 
 			// Viewport
 			{
-				float W = 0.5f * viewport.getWidth();
-				float H = 0.5f * viewport.getHeight();
-				float L = viewport.getLeft() + W;
-				float T = viewport.getTop() + H;
-				float N = viewport.getNear();
-				float F = viewport.getFar();
+				float W = 0.5f * viewport.width;
+				float H = 0.5f * viewport.height;
+				float X0 = viewport.x0 + W;
+				float Y0 = viewport.y0 + H;
+				float N = viewport.minZ;
+				float F = viewport.maxZ;
 				float Z = F - N;
 
 				if(context->isDrawTriangle(false))
@@ -510,17 +518,15 @@
 
 				int s = sw::log2(ss);
 
-				data->WWWWx16 = replicate(W * 16);
-				data->HHHHx16 = replicate(-H * 16);
-				data->LLLLx16 = replicate(L * 16);
-				data->TTTTx16 = replicate(T * 16);
+				data->Wx16 = replicate(W * 16);
+				data->Hx16 = replicate(H * 16);
+				data->X0x16 = replicate(X0 * 16);
+				data->Y0x16 = replicate(Y0 * 16);
 				data->XXXX = replicate(X[s][q] / W);
 				data->YYYY = replicate(Y[s][q] / H);
-				data->offX = replicate(+0.5f / W);
-				data->offY = replicate(-0.5f / H);
-				data->posScale = posScale;
-				data->posOffset = posOffset;
-				data->viewportHeight = viewport.getHeight();   // FIXME: Should use true viewport size, not scissored viewport
+				data->halfPixelX = replicate(0.5f / W);
+				data->halfPixelY = replicate(0.5f / H);
+				data->viewportHeight = abs(viewport.height);
 				data->slopeDepthBias = slopeDepthBias;
 				data->depthRange = Z;
 				data->depthNear = N;
@@ -565,6 +571,14 @@
 				}
 			}
 
+			// Scissor
+			{
+				data->scissorX0 = scissor.x0;
+				data->scissorX1 = scissor.x1;
+				data->scissorY0 = scissor.y0;
+				data->scissorY1 = scissor.y1;
+			}
+
 			draw->primitive = 0;
 			draw->count = count;
 
@@ -809,6 +823,12 @@
 		}
 	}
 
+	void Renderer::synchronize()
+	{
+		sync->lock(sw::PUBLIC);
+		sync->unlock();
+	}
+
 	void Renderer::finishRendering(Task &pixelTask)
 	{
 		int unit = pixelTask.primitiveUnit;
@@ -902,6 +922,8 @@
 				draw.setupRoutine->unbind();
 				draw.pixelRoutine->unbind();
 
+				sync->unlock();
+
 				draw.references = -1;
 				resumeApp->signal();
 			}
@@ -1534,8 +1556,8 @@
 			return false;
 		}
 
-		const float W =  data.WWWWx16[0] * (1.0f / 16.0f);
-		const float H = -data.HHHHx16[0] * (1.0f / 16.0f);
+		const float W = data.Wx16[0] * (1.0f / 16.0f);
+		const float H = data.Hx16[0] * (1.0f / 16.0f);
 
 		float dx = W * (P1.x / P1.w - P0.x / P0.w);
 		float dy = H * (P1.y / P1.w - P0.y / P0.w);
@@ -1570,20 +1592,20 @@
 			float dx1h = dx * P1.w / H;
 			float dy1w = dy * P1.w / W;
 
-			P[0].x += +dy0w + -dx0w;
-			P[0].y += -dx0h + -dy0h;
+			P[0].x += -dy0w + -dx0w;
+			P[0].y += -dx0h + +dy0h;
 			C[0] = computeClipFlags(P[0], data);
 
-			P[1].x += +dy1w + +dx1w;
+			P[1].x += -dy1w + +dx1w;
 			P[1].y += -dx1h + +dy1h;
 			C[1] = computeClipFlags(P[1], data);
 
-			P[2].x += -dy1w + +dx1w;
-			P[2].y += +dx1h + +dy1h;
+			P[2].x += +dy1w + +dx1w;
+			P[2].y += +dx1h + -dy1h;
 			C[2] = computeClipFlags(P[2], data);
 
-			P[3].x += -dy0w + -dx0w;
-			P[3].y += +dx0h + -dy0h;
+			P[3].x += +dy0w + -dx0w;
+			P[3].y += +dx0h + +dy0h;
 			C[3] = computeClipFlags(P[3], data);
 
 			if((C[0] & C[1] & C[2] & C[3]) == Clipper::CLIP_FINITE)
@@ -1626,34 +1648,34 @@
 			P[0].x += -dx0;
 			C[0] = computeClipFlags(P[0], data);
 
-			P[1].y += -dy0;
+			P[1].y += +dy0;
 			C[1] = computeClipFlags(P[1], data);
 
 			P[2].x += +dx0;
 			C[2] = computeClipFlags(P[2], data);
 
-			P[3].y += +dy0;
+			P[3].y += -dy0;
 			C[3] = computeClipFlags(P[3], data);
 
 			P[4].x += -dx1;
 			C[4] = computeClipFlags(P[4], data);
 
-			P[5].y += -dy1;
+			P[5].y += +dy1;
 			C[5] = computeClipFlags(P[5], data);
 
 			P[6].x += +dx1;
 			C[6] = computeClipFlags(P[6], data);
 
-			P[7].y += +dy1;
+			P[7].y += -dy1;
 			C[7] = computeClipFlags(P[7], data);
 
 			if((C[0] & C[1] & C[2] & C[3] & C[4] & C[5] & C[6] & C[7]) == Clipper::CLIP_FINITE)
 			{
 				float4 L[6];
 
-				if(dx > dy)
+				if(dx > -dy)
 				{
-					if(dx > -dy)   // Right
+					if(dx > dy)   // Right
 					{
 						L[0] = P[0];
 						L[1] = P[1];
@@ -1674,7 +1696,7 @@
 				}
 				else
 				{
-					if(dx > -dy)   // Up
+					if(dx > dy)   // Up
 					{
 						L[0] = P[0];
 						L[1] = P[1];
@@ -1746,30 +1768,30 @@
 		P[2] = v.v[pos];
 		P[3] = v.v[pos];
 
-		const float X = 0.5f * pSize * P[0].w /  (data.WWWWx16[0] * (1.0f / 16.0f));
-		const float Y = 0.5f * pSize * P[0].w / -(data.HHHHx16[0] * (1.0f / 16.0f));
+		const float X = pSize * P[0].w * data.halfPixelX[0];
+		const float Y = pSize * P[0].w * data.halfPixelY[0];
 
 		P[0].x -= X;
-		P[0].y -= Y;
+		P[0].y += Y;
 		C[0] = computeClipFlags(P[0], data);
 
 		P[1].x += X;
-		P[1].y -= Y;
+		P[1].y += Y;
 		C[1] = computeClipFlags(P[1], data);
 
 		P[2].x += X;
-		P[2].y += Y;
+		P[2].y -= Y;
 		C[2] = computeClipFlags(P[2], data);
 
 		P[3].x -= X;
-		P[3].y += Y;
+		P[3].y -= Y;
 		C[3] = computeClipFlags(P[3], data);
 
 		triangle.v1 = triangle.v0;
 		triangle.v2 = triangle.v0;
 
 		triangle.v1.X += iround(16 * 0.5f * pSize);
-		triangle.v2.Y -= iround(16 * 0.5f * pSize);
+		triangle.v2.Y -= iround(16 * 0.5f * pSize) * (data.Hx16[0] > 0.0f ? 1 : -1);   // Both Direct3D and OpenGL expect (0, 0) in the top-left corner
 
 		Polygon polygon(P, 4);
 
@@ -1793,8 +1815,8 @@
 
 	unsigned int Renderer::computeClipFlags(const float4 &v, const DrawData &data)
 	{
-		float clX = v.x + data.offX[0] * v.w;
-		float clY = v.y + data.offY[0] * v.w;
+		float clX = v.x + data.halfPixelX[0] * v.w;
+		float clY = v.y + data.halfPixelY[0] * v.w;
 
 		return ((clX > v.w)  << 0) |
 			   ((clY > v.w)  << 1) |
@@ -1846,7 +1868,7 @@
 	{
 		while(threadsAwake != 0)
 		{
-			Thread::sleep(100);
+			Thread::sleep(1);
 		}
 
 		for(int thread = 0; thread < threadCount; thread++)
@@ -1890,38 +1912,36 @@
 
 		for(int i = 0; i < count; i++)
 		{
-			const ShaderInstruction *instruction = vertexShader->getInstruction(i);
+			const Shader::Instruction *instruction = vertexShader->getInstruction(i);
 
-			if(instruction->getOpcode() == VertexShaderInstruction::Operation::OPCODE_DEF)
+			if(instruction->opcode == Shader::OPCODE_DEF)
 			{
-				int index = instruction->getDestinationParameter().index;
+				int index = instruction->dst.index;
 				float value[4];
 
-				value[0] = instruction->getSourceParameter(0).value;
-				value[1] = instruction->getSourceParameter(1).value;
-				value[2] = instruction->getSourceParameter(2).value;
-				value[3] = instruction->getSourceParameter(3).value;
+				value[0] = instruction->src[0].value[0];
+				value[1] = instruction->src[0].value[1];
+				value[2] = instruction->src[0].value[2];
+				value[3] = instruction->src[0].value[3];
 
 				setVertexShaderConstantF(index, value);
 			}
-			else if(instruction->getOpcode() == VertexShaderInstruction::Operation::OPCODE_DEFI)
+			else if(instruction->opcode == Shader::OPCODE_DEFI)
 			{
-				int index = instruction->getDestinationParameter().index;
+				int index = instruction->dst.index;
 				int integer[4];
 
-				integer[0] = instruction->getSourceParameter(0).integer;
-				integer[1] = instruction->getSourceParameter(1).integer;
-				integer[2] = instruction->getSourceParameter(2).integer;
-				integer[3] = instruction->getSourceParameter(3).integer;
+				integer[0] = instruction->src[0].integer[0];
+				integer[1] = instruction->src[0].integer[1];
+				integer[2] = instruction->src[0].integer[2];
+				integer[3] = instruction->src[0].integer[3];
 
 				setVertexShaderConstantI(index, integer);
 			}
-			else if(instruction->getOpcode() == VertexShaderInstruction::Operation::OPCODE_DEFB)
+			else if(instruction->opcode == Shader::OPCODE_DEFB)
 			{
-				int index = instruction->getDestinationParameter().index;
-				int boolean;
-
-				boolean = instruction->getSourceParameter(0).boolean;
+				int index = instruction->dst.index;
+				int boolean = instruction->src[0].boolean[0];
 
 				setVertexShaderConstantB(index, &boolean);
 			}
@@ -1936,38 +1956,36 @@
 
 		for(int i = 0; i < count; i++)
 		{
-			const ShaderInstruction *instruction = pixelShader->getInstruction(i);
+			const Shader::Instruction *instruction = pixelShader->getInstruction(i);
 
-			if(instruction->getOpcode() == PixelShaderInstruction::Operation::OPCODE_DEF)
+			if(instruction->opcode == Shader::OPCODE_DEF)
 			{
-				int index = instruction->getDestinationParameter().index;
+				int index = instruction->dst.index;
 				float value[4];
 
-				value[0] = instruction->getSourceParameter(0).value;
-				value[1] = instruction->getSourceParameter(1).value;
-				value[2] = instruction->getSourceParameter(2).value;
-				value[3] = instruction->getSourceParameter(3).value;
+				value[0] = instruction->src[0].value[0];
+				value[1] = instruction->src[0].value[1];
+				value[2] = instruction->src[0].value[2];
+				value[3] = instruction->src[0].value[3];
 
 				setPixelShaderConstantF(index, value);
 			}
-			else if(instruction->getOpcode() == PixelShaderInstruction::Operation::OPCODE_DEFI)
+			else if(instruction->opcode == Shader::OPCODE_DEFI)
 			{
-				int index = instruction->getDestinationParameter().index;
+				int index = instruction->dst.index;
 				int integer[4];
 
-				integer[0] = instruction->getSourceParameter(0).integer;
-				integer[1] = instruction->getSourceParameter(1).integer;
-				integer[2] = instruction->getSourceParameter(2).integer;
-				integer[3] = instruction->getSourceParameter(3).integer;
+				integer[0] = instruction->src[0].integer[0];
+				integer[1] = instruction->src[0].integer[1];
+				integer[2] = instruction->src[0].integer[2];
+				integer[3] = instruction->src[0].integer[3];
 
 				setPixelShaderConstantI(index, integer);
 			}
-			else if(instruction->getOpcode() == PixelShaderInstruction::Operation::OPCODE_DEFB)
+			else if(instruction->opcode == Shader::OPCODE_DEFB)
 			{
-				int index = instruction->getDestinationParameter().index;
-				int boolean;
-
-				boolean = instruction->getSourceParameter(0).boolean;
+				int index = instruction->dst.index;
+				int boolean = instruction->src[0].boolean[0];
 
 				setPixelShaderConstantB(index, &boolean);
 			}
@@ -2011,15 +2029,9 @@
 	{
 		if(updateClipPlanes)
 		{
-			// Transformation from viewport clip space to scissored viewport clip space
-			Matrix scissorClip(posScale.x, 0.0f,        0.0f, posOffset.x,
-			                   0.0f,       posScale.y,  0.0f, posOffset.y,
-			                   0.0f,       0.0f,        1.0f, 0.0f,
-			                   0.0f ,      0.0f,        0.0f, 1.0f);
-
 			if(VertexProcessor::isFixedFunction())   // User plane in world space
 			{
-				const Matrix &scissorWorld = scissorClip * getViewTransform();
+				const Matrix &scissorWorld = getViewTransform();
 
 				if(clipFlags & Clipper::CLIP_PLANE0) clipPlane[0] = scissorWorld * userPlane[0];
 				if(clipFlags & Clipper::CLIP_PLANE1) clipPlane[1] = scissorWorld * userPlane[1];
@@ -2030,12 +2042,12 @@
 			}
 			else   // User plane in clip space
 			{
-				if(clipFlags & Clipper::CLIP_PLANE0) clipPlane[0] = scissorClip * userPlane[0];
-				if(clipFlags & Clipper::CLIP_PLANE1) clipPlane[1] = scissorClip * userPlane[1];
-				if(clipFlags & Clipper::CLIP_PLANE2) clipPlane[2] = scissorClip * userPlane[2];
-				if(clipFlags & Clipper::CLIP_PLANE3) clipPlane[3] = scissorClip * userPlane[3];
-				if(clipFlags & Clipper::CLIP_PLANE4) clipPlane[4] = scissorClip * userPlane[4];
-				if(clipFlags & Clipper::CLIP_PLANE5) clipPlane[5] = scissorClip * userPlane[5];
+				if(clipFlags & Clipper::CLIP_PLANE0) clipPlane[0] = userPlane[0];
+				if(clipFlags & Clipper::CLIP_PLANE1) clipPlane[1] = userPlane[1];
+				if(clipFlags & Clipper::CLIP_PLANE2) clipPlane[2] = userPlane[2];
+				if(clipFlags & Clipper::CLIP_PLANE3) clipPlane[3] = userPlane[3];
+				if(clipFlags & Clipper::CLIP_PLANE4) clipPlane[4] = userPlane[4];
+				if(clipFlags & Clipper::CLIP_PLANE5) clipPlane[5] = userPlane[5];
 			}
 
 			updateClipPlanes = false;
@@ -2335,31 +2347,6 @@
 		updateClipPlanes = true;
 	}
 
-	void Renderer::setPostTransformEnable(bool enable)
-	{
-		context->postTransform = enable;
-	}
-
-	void Renderer::setPosScale(float x, float y)
-	{
-		posScale[0] = x;
-		posScale[1] = y;
-		posScale[2] = 1;
-		posScale[3] = 1;
-
-		updateClipPlanes = true;
-	}
-
-	void Renderer::setPosOffset(float x, float y)
-	{
-		posOffset[0] = x;
-		posOffset[1] = y;
-		posOffset[2] = 0;
-		posOffset[3] = 0;
-
-		updateClipPlanes = true;
-	}
-
 	void Renderer::addQuery(Query *query)
 	{
 		queries.push_back(query);
@@ -2407,6 +2394,11 @@
 		this->viewport = viewport;
 	}
 
+	void Renderer::setScissor(const Rect &scissor)
+	{
+		this->scissor = scissor;
+	}
+
 	void Renderer::setClipFlags(int flags)
 	{
 		clipFlags = flags << 8;   // Bottom 8 bits used by legacy frustum
@@ -2532,76 +2524,4 @@
 		#endif
 		}
 	}
-
-	void Renderer::startupConfiguration()
-	{
-		if(!CPUID::supportsSSE2())
-		{
-			MessageBox(0, "Failed to initialize graphics: software mode requires SSE2 support (Pentium 4, Athlon 64, or higher). Aborting application.", 0, MB_ICONERROR);
-
-			exit(0);
-		}
-
-		if(maximumFilterQuality != SWF_DEFAULT)
-		{
-			switch(maximumFilterQuality)
-			{
-			case SWF_DEFAULT:	Sampler::setFilterQuality(FILTER_LINEAR);	break;
-			case SWF_NONE:		Sampler::setFilterQuality(FILTER_POINT);	break;
-			case SWF_POINT:		Sampler::setFilterQuality(FILTER_POINT);	break;
-			case SWF_AVERAGE2:	Sampler::setFilterQuality(FILTER_LINEAR);	break;
-			case SWF_AVERAGE4:	Sampler::setFilterQuality(FILTER_LINEAR);	break;
-			case SWF_POLYGON:	Sampler::setFilterQuality(FILTER_LINEAR);	break;
-			case SWF_LINEAR:	Sampler::setFilterQuality(FILTER_LINEAR);	break;
-			case SWF_MAXIMUM:	Sampler::setFilterQuality(FILTER_LINEAR);	break;
-			default:
-				ASSERT(false);
-			}
-		}
-
-		if(maximumMipmapQuality != SWF_DEFAULT)
-		{
-			switch(maximumMipmapQuality)
-			{
-			case SWF_DEFAULT:	Sampler::setMipmapQuality(MIPMAP_POINT);	break;
-			case SWF_NONE:		Sampler::setMipmapQuality(MIPMAP_NONE);	break;
-			case SWF_POINT:		Sampler::setMipmapQuality(MIPMAP_POINT);	break;
-			case SWF_AVERAGE2:	Sampler::setMipmapQuality(MIPMAP_POINT);	break;
-			case SWF_AVERAGE4:	Sampler::setMipmapQuality(MIPMAP_POINT);	break;
-			case SWF_POLYGON:	Sampler::setMipmapQuality(MIPMAP_POINT);	break;
-			case SWF_LINEAR:	Sampler::setMipmapQuality(MIPMAP_LINEAR);	break;
-			case SWF_MAXIMUM:	Sampler::setMipmapQuality(MIPMAP_LINEAR);	break;
-			default:
-				ASSERT(false);
-			}
-		}
-
-		if(perspectiveQuality != SWP_DEFAULT)
-		{
-			switch(perspectiveQuality)
-			{
-			case SWP_DEFAULT:	setPerspectiveCorrection(true);		break;
-			case SWP_NONE:		setPerspectiveCorrection(false);	break;
-			case SWP_FAST:		setPerspectiveCorrection(true);		break;
-			case SWP_ACCURATE:	setPerspectiveCorrection(true);		break;
-			default:
-				ASSERT(false);
-			}
-		}
-
-		const char *commandLine = GetCommandLine();
-		bool whql = (strstr(commandLine, "-WHQL") != 0) || (strstr(commandLine, "-THQL") != 0);
-
-		if(whql)
-		{
-			Sampler::setFilterQuality(FILTER_ANISOTROPIC);
-			Sampler::setMipmapQuality(MIPMAP_LINEAR);
-
-			logPrecision = WHQL;
-			expPrecision = WHQL;
-			rcpPrecision = WHQL;
-			rsqPrecision = WHQL;
-			perspectiveCorrection = true;
-		}
-	}
 }
diff --git a/src/Renderer/Renderer.hpp b/src/Renderer/Renderer.hpp
index 0f68f39..2bdcdb9 100644
--- a/src/Renderer/Renderer.hpp
+++ b/src/Renderer/Renderer.hpp
@@ -1,411 +1,433 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2011 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 sw_Renderer_hpp
-#define sw_Renderer_hpp
-
-#include "VertexProcessor.hpp"
-#include "PixelProcessor.hpp"
-#include "SetupProcessor.hpp"
-#include "Viewport.hpp"
-#include "Plane.hpp"
-#include "Blitter.hpp"
-#include "Common/MutexLock.hpp"
-#include "Common/Thread.hpp"
-#include "Main/Config.hpp"
-
-#include <list>
-
-namespace sw
-{
-	class Clipper;
-	class Viewport;
-	class PixelShader;
-	class VertexShader;
-	class SwiftConfig;
-	struct Task;
-	class Resource;
-	class Renderer;
-
-	extern int batchSize;
-	extern int threadCount;
-	extern int unitCount;
-	extern int clusterCount;
-
-	struct Query
-	{
-		Query()
-		{
-			building = false;
-			reference = 0;
-			data = 0;
-		}
-
-		void begin()
-		{
-			building = true;
-			data = 0;
-		}
-
-		void end()
-		{
-			building = false;
-		}
-
-		bool building;
-		volatile int reference;
-		volatile unsigned int data;
-	};
-
-	struct DrawData
-	{
-		const void *constants;
-
-		const void *input[16];
-		unsigned int stride[16];
-		Texture mipmap[16 + 4];
-		const void *indices;
-
-		struct VS
-		{
-			float4 c[256 + 1];   // One extra for indices out of range, c[256] = {0, 0, 0, 0}
-			int4 i[16];
-			bool b[16];
-		};
-
-		struct PS
-		{
-			word4 cW[8][4];
-			float4 c[224];
-			int4 i[16];
-			bool b[16];
-		};
-
-		union
-		{
-			VS vs;
-			VertexProcessor::FixedFunction ff;
-		};
-
-		PS ps;
-
-		VertexProcessor::PointSprite point;
-
-		PixelProcessor::Stencil stencil[2];   // clockwise, counterclockwise
-		PixelProcessor::Stencil stencilCCW;
-		PixelProcessor::Fog fog;
-		PixelProcessor::Factor factor;
-		unsigned int occlusion[16];   // Number of pixels passing depth test
-
-		#if PERF_PROFILE
-			int64_t cycles[PERF_TIMERS][16];
-		#endif
-
-		TextureStage::Uniforms textureStage[8];
-
-		float4 WWWWx16;
-		float4 HHHHx16;
-		float4 LLLLx16;
-		float4 TTTTx16;
-		float4 ZZZZ;
-		float4 XXXX;
-		float4 YYYY;
-		float4 offX;
-		float4 offY;
-		float4 posScale;
-		float4 posOffset;
-		float viewportHeight;
-		float slopeDepthBias;
-		float depthRange;
-		float depthNear;
-		Plane clipPlane[6];
-
-		unsigned int *colorBuffer[4];
-		int colorPitchB[4];
-		int colorSliceB[4];
-		float *depthBuffer;
-		int depthPitchB;
-		int depthSliceB;
-		unsigned char *stencilBuffer;
-		int stencilPitchB;
-		int stencilSliceB;
-
-		float4 a2c0;
-		float4 a2c1;
-		float4 a2c2;
-		float4 a2c3;
-	};
-
-	struct DrawCall
-	{
-		DrawCall();
-
-		~DrawCall();
-
-		Context::DrawType drawType;
-		int batchSize;
-
-		Routine *vertexRoutine;
-		Routine *setupRoutine;
-		Routine *pixelRoutine;
-
-		VertexProcessor::RoutinePointer vertexPointer;
-		SetupProcessor::RoutinePointer setupPointer;
-		PixelProcessor::RoutinePointer pixelPointer;
-
-		int (*setupPrimitives)(Renderer *renderer, int batch, int count);
-		SetupProcessor::State setupState;
-
-		Resource *vertexStream[16];
-		Resource *indexBuffer;
-		Surface *renderTarget[4];
-		Surface *depthStencil;
-		Resource *texture[16 + 4];
-
-		int vsDirtyConstF;
-		int vsDirtyConstI;
-		int vsDirtyConstB;
-
-		int psDirtyConstF;
-		int psDirtyConstI;
-		int psDirtyConstB;
-
-		std::list<Query*> *queries;
-
-		int clipFlags;
-
-		volatile int primitive;    // Current primitive to enter pipeline
-		volatile int count;        // Number of primitives to render
-		volatile int references;   // Remaining references to this draw call, 0 when done drawing, -1 when resources unlocked and slot is free
-
-		DrawData *data;
-	};
-
-	class Renderer : public VertexProcessor, public PixelProcessor, public SetupProcessor
-	{
-		struct Task
-		{
-			enum Type
-			{
-				PRIMITIVES,
-				PIXELS,
-
-				RESUME,
-				SUSPEND
-			};
-
-			volatile Type type;
-			volatile int primitiveUnit;
-			volatile int pixelCluster;
-		};
-
-		struct PrimitiveProgress
-		{
-			void init()
-			{
-				drawCall = 0;
-				firstPrimitive = 0;
-				primitiveCount = 0;
-				visible = 0;
-				references = 0;
-			}
-
-			volatile int drawCall;
-			volatile int firstPrimitive;
-			volatile int primitiveCount;
-			volatile int visible;
-			volatile int references;
-		};
-
-		struct PixelProgress
-		{
-			void init()
-			{
-				drawCall = 0;
-				processedPrimitives = 0;
-				executing = false;
-			}
-
-			volatile int drawCall;
-			volatile int processedPrimitives;
-			volatile bool executing;
-		};
-
-	public:
-		Renderer(Context *context, Surface *renderTarget = 0);
-
-		virtual ~Renderer();
-
-		virtual void blit(Surface *source, const Rect &sRect, Surface *dest, const Rect &dRect, bool filter);
-		virtual void draw(Context::DrawType drawType, unsigned int indexOffset, unsigned int count, bool update = true);
-
-		virtual void setIndexBuffer(Resource *indexBuffer);
-
-		virtual void setMultiSampleMask(unsigned int mask);
-		virtual void setTransparencyAntialiasing(Context::TransparencyAntialiasing transparencyAntialiasing);
-
-		virtual void setTextureResource(unsigned int sampler, Resource *resource);
-		virtual void setTextureLevel(unsigned int sampler, unsigned int face, unsigned int level, Surface *surface, TextureType type);
-
-		virtual void setTextureFilter(SamplerType type, int sampler, FilterType textureFilter);
-		virtual void setMipmapFilter(SamplerType type, int sampler, MipmapType mipmapFilter);
-		virtual void setGatherEnable(SamplerType type, int sampler, bool enable);
-		virtual void setAddressingModeU(SamplerType type, int sampler, AddressingMode addressingMode);
-		virtual void setAddressingModeV(SamplerType type, int sampler, AddressingMode addressingMode);
-		virtual void setAddressingModeW(SamplerType type, int sampler, AddressingMode addressingMode);
-		virtual void setReadSRGB(SamplerType type, int sampler, bool sRGB);
-		virtual void setMipmapLOD(SamplerType type, int sampler, float bias);
-		virtual void setBorderColor(SamplerType type, int sampler, const Color<float> &borderColor);
-		virtual void setMaxAnisotropy(SamplerType type, int sampler, unsigned int maxAnisotropy);
-		
-		virtual void setPointSpriteEnable(bool pointSpriteEnable);
-		virtual void setPointScaleEnable(bool pointScaleEnable);
-
-		virtual void setDepthBias(float bias);
-		virtual void setSlopeDepthBias(float slopeBias);
-
-		// Programmable pipelines
-		virtual void setPixelShader(const PixelShader *shader);
-		virtual void setVertexShader(const VertexShader *shader);
-
-		virtual void setPixelShaderConstantF(int index, const float value[4], int count = 1);
-		virtual void setPixelShaderConstantI(int index, const int value[4], int count = 1);
-		virtual void setPixelShaderConstantB(int index, const int *boolean, int count = 1);
-
-		virtual void setVertexShaderConstantF(int index, const float value[4], int count = 1);
-		virtual void setVertexShaderConstantI(int index, const int value[4], int count = 1);
-		virtual void setVertexShaderConstantB(int index, const int *boolean, int count = 1);
-
-		// Viewport & Clipper
-		virtual void setViewport(const Viewport &viewport);
-		virtual void setClipFlags(int flags);
-		virtual void setClipPlane(unsigned int index, const float plane[4]);
-
-		// Partial transform
-		virtual void setModelMatrix(const Matrix &M, int i = 0);
-		virtual void setViewMatrix(const Matrix &V);
-		virtual void setBaseMatrix(const Matrix &B);
-		virtual void setProjectionMatrix(const Matrix &P);
-
-		virtual void setPostTransformEnable(bool enable);
-
-		virtual void setPosScale(float x, float y);
-		virtual void setPosOffset(float x, float y);
-
-		virtual void addQuery(Query *query);
-		virtual void removeQuery(Query *query);
-
-		#if PERF_HUD
-			// Performance timers
-			int getThreadCount();
-			int64_t getVertexTime(int thread);
-			int64_t getSetupTime(int thread);
-			int64_t getPixelTime(int thread);
-			void resetTimers();
-		#endif
-
-	private:
-		static void threadFunction(void *parameters);
-		void threadLoop(int threadIndex);
-		void taskLoop(int threadIndex);
-		void findAvailableTasks();
-		void scheduleTask(int threadIndex);
-		void executeTask(int threadIndex);
-		void finishRendering(Task &pixelTask);
-
-		void processPrimitiveVertices(int unit, unsigned int start, unsigned int count, unsigned int loop, int thread);
-
-		static int setupSolidTriangles(Renderer *renderer, int batch, int count);
-		static int setupWireframeTriangle(Renderer *renderer, int batch, int count);
-		static int setupVertexTriangle(Renderer *renderer, int batch, int count);
-		static int setupLines(Renderer *renderer, int batch, int count);
-		static int setupPoints(Renderer *renderer, int batch, int count);
-
-		static bool setupLine(Renderer *renderer, Primitive &primitive, Triangle &triangle, const DrawCall &draw);
-		static bool setupPoint(Renderer *renderer, Primitive &primitive, Triangle &triangle, const DrawCall &draw);
-
-		bool isReadWriteTexture(int sampler);
-		void updateClipper();
-		void updateConfiguration(bool initialUpdate = false);
-		void startupConfiguration();
-		static unsigned int computeClipFlags(const float4 &v, const DrawData &data);
-		void initializeThreads(int threadCount);
-		void terminateThreads();
-		void deleteBatches();
-
-		void loadConstants(const VertexShader *vertexShader);
-		void loadConstants(const PixelShader *pixelShader);
-
-		Context *context;
-		Clipper *clipper;
-		Viewport viewport;
-		float4 posScale;
-		float4 posOffset;
-		int clipFlags;
-
-		Triangle *triangleBatch[16];
-		Primitive *primitiveBatch[16];
-
-		// User-defined clipping planes
-		Plane userPlane[6];
-		Plane clipPlane[6];   // Tranformed to clip space
-		bool updateClipPlanes;
-
-		volatile bool exitThreads;
-		volatile int threadsAwake;
-		Thread *worker[16];
-		Event *resume[16];         // Events for resuming threads
-		Event *suspend[16];        // Events for suspending threads
-		Event *resumeApp;          // Event for resuming the application thread
-
-		PrimitiveProgress primitiveProgress[16];
-		PixelProgress pixelProgress[16];
-		Task task[16];   // Current tasks for threads
-
-		enum {DRAW_COUNT = 16};   // Number of draw calls buffered
-		DrawCall *drawCall[DRAW_COUNT];
-		DrawCall *drawList[DRAW_COUNT];
-
-		volatile int currentDraw;
-		volatile int nextDraw;
-
-		Task taskQueue[32];
-		unsigned int qHead;
-		unsigned int qSize;
-
-		BackoffLock mutex;
-
-		#if PERF_HUD
-			int64_t vertexTime[16];
-			int64_t setupTime[16];
-			int64_t pixelTime[16];
-		#endif
-
-		VertexTask *vertexTask[16];
-
-		SwiftConfig *swiftConfig;
-
-		std::list<Query*> queries;
-
-		VertexProcessor::State vertexState;
-		SetupProcessor::State setupState;
-		PixelProcessor::State pixelState;
-		int (*setupPrimitives)(Renderer *renderer, int batch, int count);
-
-		Routine *vertexRoutine;
-		Routine *setupRoutine;
-		Routine *pixelRoutine;
-
-		Blitter blitter;
-	};
-}
-
-#endif   // sw_Renderer_hpp
+// SwiftShader Software Renderer

+//

+// Copyright(c) 2005-2012 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 sw_Renderer_hpp

+#define sw_Renderer_hpp

+

+#include "VertexProcessor.hpp"

+#include "PixelProcessor.hpp"

+#include "SetupProcessor.hpp"

+#include "Plane.hpp"

+#include "Blitter.hpp"

+#include "Common/MutexLock.hpp"

+#include "Common/Thread.hpp"

+#include "Main/Config.hpp"

+

+#include <list>

+

+namespace sw

+{

+	class Clipper;

+	class PixelShader;

+	class VertexShader;

+	class SwiftConfig;

+	struct Task;

+	class Resource;

+	class Renderer;

+

+	extern int batchSize;

+	extern int threadCount;

+	extern int unitCount;

+	extern int clusterCount;

+

+	enum TranscendentalPrecision

+	{

+		APPROXIMATE,

+		PARTIAL,	// 2^-10

+		ACCURATE,

+		WHQL,		// 2^-21

+		IEEE		// 2^-23

+	};

+

+	extern TranscendentalPrecision logPrecision;

+	extern TranscendentalPrecision expPrecision;

+	extern TranscendentalPrecision rcpPrecision;

+	extern TranscendentalPrecision rsqPrecision;

+	extern bool perspectiveCorrection;

+

+	struct Query

+	{

+		Query()

+		{

+			building = false;

+			reference = 0;

+			data = 0;

+		}

+

+		void begin()

+		{

+			building = true;

+			data = 0;

+		}

+

+		void end()

+		{

+			building = false;

+		}

+

+		bool building;

+		volatile int reference;

+		volatile unsigned int data;

+	};

+

+	struct DrawData

+	{

+		const void *constants;

+

+		const void *input[16];

+		unsigned int stride[16];

+		Texture mipmap[16 + 4];

+		const void *indices;

+

+		struct VS

+		{

+			float4 c[256 + 1];   // One extra for indices out of range, c[256] = {0, 0, 0, 0}

+			int4 i[16];

+			bool b[16];

+		};

+

+		struct PS

+		{

+			word4 cW[8][4];

+			float4 c[224];

+			int4 i[16];

+			bool b[16];

+		};

+

+		union

+		{

+			VS vs;

+			VertexProcessor::FixedFunction ff;

+		};

+

+		PS ps;

+

+		VertexProcessor::PointSprite point;

+

+		PixelProcessor::Stencil stencil[2];   // clockwise, counterclockwise

+		PixelProcessor::Stencil stencilCCW;

+		PixelProcessor::Fog fog;

+		PixelProcessor::Factor factor;

+		unsigned int occlusion[16];   // Number of pixels passing depth test

+

+		#if PERF_PROFILE

+			int64_t cycles[PERF_TIMERS][16];

+		#endif

+

+		TextureStage::Uniforms textureStage[8];

+

+		float4 Wx16;

+		float4 Hx16;

+		float4 X0x16;

+		float4 Y0x16;

+		float4 XXXX;

+		float4 YYYY;

+		float4 halfPixelX;

+		float4 halfPixelY;

+		float viewportHeight;

+		float slopeDepthBias;

+		float depthRange;

+		float depthNear;

+		Plane clipPlane[6];

+

+		unsigned int *colorBuffer[4];

+		int colorPitchB[4];

+		int colorSliceB[4];

+		float *depthBuffer;

+		int depthPitchB;

+		int depthSliceB;

+		unsigned char *stencilBuffer;

+		int stencilPitchB;

+		int stencilSliceB;

+

+		int scissorX0;

+		int scissorX1;

+		int scissorY0;

+		int scissorY1;

+

+		float4 a2c0;

+		float4 a2c1;

+		float4 a2c2;

+		float4 a2c3;

+	};

+

+	struct DrawCall

+	{

+		DrawCall();

+

+		~DrawCall();

+

+		Context::DrawType drawType;

+		int batchSize;

+

+		Routine *vertexRoutine;

+		Routine *setupRoutine;

+		Routine *pixelRoutine;

+

+		VertexProcessor::RoutinePointer vertexPointer;

+		SetupProcessor::RoutinePointer setupPointer;

+		PixelProcessor::RoutinePointer pixelPointer;

+

+		int (*setupPrimitives)(Renderer *renderer, int batch, int count);

+		SetupProcessor::State setupState;

+

+		Resource *vertexStream[16];

+		Resource *indexBuffer;

+		Surface *renderTarget[4];

+		Surface *depthStencil;

+		Resource *texture[16 + 4];

+

+		int vsDirtyConstF;

+		int vsDirtyConstI;

+		int vsDirtyConstB;

+

+		int psDirtyConstF;

+		int psDirtyConstI;

+		int psDirtyConstB;

+

+		std::list<Query*> *queries;

+

+		int clipFlags;

+

+		volatile int primitive;    // Current primitive to enter pipeline

+		volatile int count;        // Number of primitives to render

+		volatile int references;   // Remaining references to this draw call, 0 when done drawing, -1 when resources unlocked and slot is free

+

+		DrawData *data;

+	};

+

+	struct Viewport

+	{

+		float x0;

+		float y0;

+		float width;

+		float height;

+		float minZ;

+		float maxZ;

+	};

+

+	class Renderer : public VertexProcessor, public PixelProcessor, public SetupProcessor

+	{

+		struct Task

+		{

+			enum Type

+			{

+				PRIMITIVES,

+				PIXELS,

+

+				RESUME,

+				SUSPEND

+			};

+

+			volatile Type type;

+			volatile int primitiveUnit;

+			volatile int pixelCluster;

+		};

+

+		struct PrimitiveProgress

+		{

+			void init()

+			{

+				drawCall = 0;

+				firstPrimitive = 0;

+				primitiveCount = 0;

+				visible = 0;

+				references = 0;

+			}

+

+			volatile int drawCall;

+			volatile int firstPrimitive;

+			volatile int primitiveCount;

+			volatile int visible;

+			volatile int references;

+		};

+

+		struct PixelProgress

+		{

+			void init()

+			{

+				drawCall = 0;

+				processedPrimitives = 0;

+				executing = false;

+			}

+

+			volatile int drawCall;

+			volatile int processedPrimitives;

+			volatile bool executing;

+		};

+

+	public:

+		Renderer(Context *context, bool halfIntegerCoordinates, bool symmetricNormalizedDepth, bool booleanFaceRegister, bool fullPixelPositionRegister, bool exactColorRounding);

+

+		virtual ~Renderer();

+

+		virtual void blit(Surface *source, const Rect &sRect, Surface *dest, const Rect &dRect, bool filter);

+		virtual void draw(Context::DrawType drawType, unsigned int indexOffset, unsigned int count, bool update = true);

+

+		virtual void setIndexBuffer(Resource *indexBuffer);

+

+		virtual void setMultiSampleMask(unsigned int mask);

+		virtual void setTransparencyAntialiasing(Context::TransparencyAntialiasing transparencyAntialiasing);

+

+		virtual void setTextureResource(unsigned int sampler, Resource *resource);

+		virtual void setTextureLevel(unsigned int sampler, unsigned int face, unsigned int level, Surface *surface, TextureType type);

+

+		virtual void setTextureFilter(SamplerType type, int sampler, FilterType textureFilter);

+		virtual void setMipmapFilter(SamplerType type, int sampler, MipmapType mipmapFilter);

+		virtual void setGatherEnable(SamplerType type, int sampler, bool enable);

+		virtual void setAddressingModeU(SamplerType type, int sampler, AddressingMode addressingMode);

+		virtual void setAddressingModeV(SamplerType type, int sampler, AddressingMode addressingMode);

+		virtual void setAddressingModeW(SamplerType type, int sampler, AddressingMode addressingMode);

+		virtual void setReadSRGB(SamplerType type, int sampler, bool sRGB);

+		virtual void setMipmapLOD(SamplerType type, int sampler, float bias);

+		virtual void setBorderColor(SamplerType type, int sampler, const Color<float> &borderColor);

+		virtual void setMaxAnisotropy(SamplerType type, int sampler, unsigned int maxAnisotropy);

+		

+		virtual void setPointSpriteEnable(bool pointSpriteEnable);

+		virtual void setPointScaleEnable(bool pointScaleEnable);

+

+		virtual void setDepthBias(float bias);

+		virtual void setSlopeDepthBias(float slopeBias);

+

+		// Programmable pipelines

+		virtual void setPixelShader(const PixelShader *shader);

+		virtual void setVertexShader(const VertexShader *shader);

+

+		virtual void setPixelShaderConstantF(int index, const float value[4], int count = 1);

+		virtual void setPixelShaderConstantI(int index, const int value[4], int count = 1);

+		virtual void setPixelShaderConstantB(int index, const int *boolean, int count = 1);

+

+		virtual void setVertexShaderConstantF(int index, const float value[4], int count = 1);

+		virtual void setVertexShaderConstantI(int index, const int value[4], int count = 1);

+		virtual void setVertexShaderConstantB(int index, const int *boolean, int count = 1);

+

+		// Viewport & Clipper

+		virtual void setViewport(const Viewport &viewport);

+		virtual void setScissor(const Rect &scissor);

+		virtual void setClipFlags(int flags);

+		virtual void setClipPlane(unsigned int index, const float plane[4]);

+

+		// Partial transform

+		virtual void setModelMatrix(const Matrix &M, int i = 0);

+		virtual void setViewMatrix(const Matrix &V);

+		virtual void setBaseMatrix(const Matrix &B);

+		virtual void setProjectionMatrix(const Matrix &P);

+

+		virtual void addQuery(Query *query);

+		virtual void removeQuery(Query *query);

+

+		void synchronize();

+

+		#if PERF_HUD

+			// Performance timers

+			int getThreadCount();

+			int64_t getVertexTime(int thread);

+			int64_t getSetupTime(int thread);

+			int64_t getPixelTime(int thread);

+			void resetTimers();

+		#endif

+

+	private:

+		static void threadFunction(void *parameters);

+		void threadLoop(int threadIndex);

+		void taskLoop(int threadIndex);

+		void findAvailableTasks();

+		void scheduleTask(int threadIndex);

+		void executeTask(int threadIndex);

+		void finishRendering(Task &pixelTask);

+

+		void processPrimitiveVertices(int unit, unsigned int start, unsigned int count, unsigned int loop, int thread);

+

+		static int setupSolidTriangles(Renderer *renderer, int batch, int count);

+		static int setupWireframeTriangle(Renderer *renderer, int batch, int count);

+		static int setupVertexTriangle(Renderer *renderer, int batch, int count);

+		static int setupLines(Renderer *renderer, int batch, int count);

+		static int setupPoints(Renderer *renderer, int batch, int count);

+

+		static bool setupLine(Renderer *renderer, Primitive &primitive, Triangle &triangle, const DrawCall &draw);

+		static bool setupPoint(Renderer *renderer, Primitive &primitive, Triangle &triangle, const DrawCall &draw);

+

+		bool isReadWriteTexture(int sampler);

+		void updateClipper();

+		void updateConfiguration(bool initialUpdate = false);

+		static unsigned int computeClipFlags(const float4 &v, const DrawData &data);

+		void initializeThreads(int threadCount);

+		void terminateThreads();

+		void deleteBatches();

+

+		void loadConstants(const VertexShader *vertexShader);

+		void loadConstants(const PixelShader *pixelShader);

+

+		Context *context;

+		Clipper *clipper;

+		Viewport viewport;

+		Rect scissor;

+		int clipFlags;

+

+		Triangle *triangleBatch[16];

+		Primitive *primitiveBatch[16];

+

+		// User-defined clipping planes

+		Plane userPlane[6];

+		Plane clipPlane[6];   // Tranformed to clip space

+		bool updateClipPlanes;

+

+		volatile bool exitThreads;

+		volatile int threadsAwake;

+		Thread *worker[16];

+		Event *resume[16];         // Events for resuming threads

+		Event *suspend[16];        // Events for suspending threads

+		Event *resumeApp;          // Event for resuming the application thread

+

+		PrimitiveProgress primitiveProgress[16];

+		PixelProgress pixelProgress[16];

+		Task task[16];   // Current tasks for threads

+

+		enum {DRAW_COUNT = 16};   // Number of draw calls buffered

+		DrawCall *drawCall[DRAW_COUNT];

+		DrawCall *drawList[DRAW_COUNT];

+

+		volatile int currentDraw;

+		volatile int nextDraw;

+

+		Task taskQueue[32];

+		unsigned int qHead;

+		unsigned int qSize;

+

+		BackoffLock mutex;

+

+		#if PERF_HUD

+			int64_t vertexTime[16];

+			int64_t setupTime[16];

+			int64_t pixelTime[16];

+		#endif

+

+		VertexTask *vertexTask[16];

+

+		SwiftConfig *swiftConfig;

+

+		std::list<Query*> queries;

+		Resource *sync;

+

+		VertexProcessor::State vertexState;

+		SetupProcessor::State setupState;

+		PixelProcessor::State pixelState;

+		int (*setupPrimitives)(Renderer *renderer, int batch, int count);

+

+		Routine *vertexRoutine;

+		Routine *setupRoutine;

+		Routine *pixelRoutine;

+

+		Blitter blitter;

+	};

+}

+

+#endif   // sw_Renderer_hpp

diff --git a/src/Renderer/Sampler.cpp b/src/Renderer/Sampler.cpp
index 1b7c651..a292267 100644
--- a/src/Renderer/Sampler.cpp
+++ b/src/Renderer/Sampler.cpp
@@ -1,6 +1,6 @@
 // SwiftShader Software Renderer
 //
-// Copyright(c) 2005-2011 TransGaming Inc.
+// Copyright(c) 2005-2012 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
@@ -343,6 +343,11 @@
 			return false;
 		}
 
+		if(texture.mipmap[0].width[0] != texture.mipmap[0].onePitchP[1])
+		{
+			return true;   // Shifting of the texture coordinates doesn't yield the correct address, so using multiply by pitch
+		}
+
 		return !isPow2(texture.mipmap[0].width[0]) || !isPow2(texture.mipmap[0].height[0]) || !isPow2(texture.mipmap[0].depth[0]);
 	}
 
diff --git a/src/Renderer/Sampler.hpp b/src/Renderer/Sampler.hpp
index 2132a06..14d0487 100644
--- a/src/Renderer/Sampler.hpp
+++ b/src/Renderer/Sampler.hpp
@@ -1,195 +1,195 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2011 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 sw_Sampler_hpp
-#define sw_Sampler_hpp
-
-#include "Main/Config.hpp"
-#include "Renderer/Surface.hpp"
-
-namespace sw
-{
-	struct Mipmap
-	{
-		void *buffer[6];
-
-		union
-		{
-			struct
-			{
-				int64_t uInt;
-				int64_t vInt;
-				int64_t wInt;
-				int64_t uFrac;
-				int64_t vFrac;
-				int64_t wFrac;
-			};
-
-			struct
-			{
-				float4 fWidth;
-				float4 fHeight;
-				float4 fDepth;
-			};
-		};
-
-		short uHalf[4];
-		short vHalf[4];
-		short wHalf[4];
-		short width[4];
-		short height[4];
-		short depth[4];
-		short onePitchP[4];
-		int sliceP[2];
-	};
-
-	struct Texture
-	{
-		Mipmap mipmap[MIPMAP_LEVELS];
-
-		float LOD;
-		float4 widthHeightLOD;
-		float4 widthLOD;
-		float4 heightLOD;
-		float4 depthLOD;
-
-		word4 borderColor4[4];
-		float4 borderColorF[4];
-		float maxAnisotropy;
-	};
-
-	enum SamplerType
-	{
-		SAMPLER_PIXEL,
-		SAMPLER_VERTEX
-	};
-
-	enum TextureType
-	{
-		TEXTURE_NULL,
-		TEXTURE_2D,
-		TEXTURE_CUBE,
-		TEXTURE_3D,
-
-		TEXTURE_LAST = TEXTURE_3D
-	};
-
-	enum FilterType
-	{
-		FILTER_POINT,
-		FILTER_GATHER,
-		FILTER_LINEAR,
-		FILTER_ANISOTROPIC,
-
-		FILTER_LAST = FILTER_ANISOTROPIC
-	};
-
-	enum MipmapType
-	{
-		MIPMAP_NONE,
-		MIPMAP_POINT,
-		MIPMAP_LINEAR,
-		
-		MIPMAP_LAST = MIPMAP_LINEAR
-	};
-
-	enum AddressingMode
-	{
-		ADDRESSING_WRAP,
-		ADDRESSING_CLAMP,
-		ADDRESSING_MIRROR,
-		ADDRESSING_MIRRORONCE,
-		ADDRESSING_BORDER,
-
-		ADDRESSING_LAST = ADDRESSING_BORDER
-	};
-
-	class Sampler
-	{
-	public:
-		struct State
-		{
-			State();
-
-			unsigned int textureType     : BITS(TEXTURE_LAST);
-			unsigned int textureFormat   : BITS(FORMAT_LAST);
-			unsigned int textureFilter   : BITS(FILTER_LAST);
-			unsigned int addressingModeU : BITS(ADDRESSING_LAST);
-			unsigned int addressingModeV : BITS(ADDRESSING_LAST);
-			unsigned int addressingModeW : BITS(ADDRESSING_LAST);
-			unsigned int mipmapFilter    : BITS(FILTER_LAST);
-			unsigned int hasNPOTTexture	 : 1;
-			unsigned int sRGB            : 1;
-
-			#if PERF_PROFILE
-			bool compressedFormat        : 1;
-			#endif
-		};
-
-		Sampler();
-
-		~Sampler();
-
-		State samplerState() const;
-
-		void setTextureLevel(int face, int level, Surface *surface, TextureType type);
-
-		void setTextureFilter(FilterType textureFilter);
-		void setMipmapFilter(MipmapType mipmapFilter);
-		void setGatherEnable(bool enable);
-		void setAddressingModeU(AddressingMode addressingMode);
-		void setAddressingModeV(AddressingMode addressingMode);
-		void setAddressingModeW(AddressingMode addressingMode);
-		void setReadSRGB(bool sRGB);
-		void setBorderColor(const Color<float> &borderColor);
-		void setMaxAnisotropy(unsigned int maxAnisotropy);
-
-		static void setFilterQuality(FilterType maximumFilterQuality);
-		static void setMipmapQuality(MipmapType maximumFilterQuality);
-		void setMipmapLOD(float lod);
-
-		bool hasTexture() const;
-		bool hasUnsignedTexture() const;
-		bool hasCubeTexture() const;
-		bool hasVolumeTexture() const;
-
-		const Texture &getTextureData();
-
-	private:
-		MipmapType mipmapFilter() const;
-		bool hasNPOTTexture() const;
-		TextureType getTextureType() const;
-		FilterType getTextureFilter() const;
-		AddressingMode getAddressingModeU() const;
-		AddressingMode getAddressingModeV() const;
-		AddressingMode getAddressingModeW() const;
-
-		Format externalTextureFormat;
-		Format internalTextureFormat;
-		TextureType textureType;
-
-		FilterType textureFilter;
-		AddressingMode addressingModeU;
-		AddressingMode addressingModeV;
-		AddressingMode addressingModeW;
-		MipmapType mipmapFilterState;
-		bool sRGB;
-		bool gather;
-
-		Texture texture;
-		float exp2LOD;
-
-		static FilterType maximumTextureFilterQuality;
-		static MipmapType maximumMipmapFilterQuality;
-	};
-}
-
-#endif   // sw_Sampler_hpp
+// SwiftShader Software Renderer

+//

+// Copyright(c) 2005-2011 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 sw_Sampler_hpp

+#define sw_Sampler_hpp

+

+#include "Main/Config.hpp"

+#include "Renderer/Surface.hpp"

+

+namespace sw

+{

+	struct Mipmap

+	{

+		void *buffer[6];

+

+		union

+		{

+			struct

+			{

+				int64_t uInt;

+				int64_t vInt;

+				int64_t wInt;

+				int64_t uFrac;

+				int64_t vFrac;

+				int64_t wFrac;

+			};

+

+			struct

+			{

+				float4 fWidth;

+				float4 fHeight;

+				float4 fDepth;

+			};

+		};

+

+		short uHalf[4];

+		short vHalf[4];

+		short wHalf[4];

+		short width[4];

+		short height[4];

+		short depth[4];

+		short onePitchP[4];

+		int sliceP[2];

+	};

+

+	struct Texture

+	{

+		Mipmap mipmap[MIPMAP_LEVELS];

+

+		float LOD;

+		float4 widthHeightLOD;

+		float4 widthLOD;

+		float4 heightLOD;

+		float4 depthLOD;

+

+		word4 borderColor4[4];

+		float4 borderColorF[4];

+		float maxAnisotropy;

+	};

+

+	enum SamplerType

+	{

+		SAMPLER_PIXEL,

+		SAMPLER_VERTEX

+	};

+

+	enum TextureType

+	{

+		TEXTURE_NULL,

+		TEXTURE_2D,

+		TEXTURE_CUBE,

+		TEXTURE_3D,

+

+		TEXTURE_LAST = TEXTURE_3D

+	};

+

+	enum FilterType

+	{

+		FILTER_POINT,

+		FILTER_GATHER,

+		FILTER_LINEAR,

+		FILTER_ANISOTROPIC,

+

+		FILTER_LAST = FILTER_ANISOTROPIC

+	};

+

+	enum MipmapType

+	{

+		MIPMAP_NONE,

+		MIPMAP_POINT,

+		MIPMAP_LINEAR,

+		

+		MIPMAP_LAST = MIPMAP_LINEAR

+	};

+

+	enum AddressingMode

+	{

+		ADDRESSING_WRAP,

+		ADDRESSING_CLAMP,

+		ADDRESSING_MIRROR,

+		ADDRESSING_MIRRORONCE,

+		ADDRESSING_BORDER,

+

+		ADDRESSING_LAST = ADDRESSING_BORDER

+	};

+

+	class Sampler

+	{

+	public:

+		struct State

+		{

+			State();

+

+			unsigned int textureType     : BITS(TEXTURE_LAST);

+			unsigned int textureFormat   : BITS(FORMAT_LAST);

+			unsigned int textureFilter   : BITS(FILTER_LAST);

+			unsigned int addressingModeU : BITS(ADDRESSING_LAST);

+			unsigned int addressingModeV : BITS(ADDRESSING_LAST);

+			unsigned int addressingModeW : BITS(ADDRESSING_LAST);

+			unsigned int mipmapFilter    : BITS(FILTER_LAST);

+			unsigned int hasNPOTTexture	 : 1;

+			unsigned int sRGB            : 1;

+

+			#if PERF_PROFILE

+			bool compressedFormat        : 1;

+			#endif

+		};

+

+		Sampler();

+

+		~Sampler();

+

+		State samplerState() const;

+

+		void setTextureLevel(int face, int level, Surface *surface, TextureType type);

+

+		void setTextureFilter(FilterType textureFilter);

+		void setMipmapFilter(MipmapType mipmapFilter);

+		void setGatherEnable(bool enable);

+		void setAddressingModeU(AddressingMode addressingMode);

+		void setAddressingModeV(AddressingMode addressingMode);

+		void setAddressingModeW(AddressingMode addressingMode);

+		void setReadSRGB(bool sRGB);

+		void setBorderColor(const Color<float> &borderColor);

+		void setMaxAnisotropy(unsigned int maxAnisotropy);

+

+		static void setFilterQuality(FilterType maximumFilterQuality);

+		static void setMipmapQuality(MipmapType maximumFilterQuality);

+		void setMipmapLOD(float lod);

+

+		bool hasTexture() const;

+		bool hasUnsignedTexture() const;

+		bool hasCubeTexture() const;

+		bool hasVolumeTexture() const;

+

+		const Texture &getTextureData();

+

+	private:

+		MipmapType mipmapFilter() const;

+		bool hasNPOTTexture() const;

+		TextureType getTextureType() const;

+		FilterType getTextureFilter() const;

+		AddressingMode getAddressingModeU() const;

+		AddressingMode getAddressingModeV() const;

+		AddressingMode getAddressingModeW() const;

+

+		Format externalTextureFormat;

+		Format internalTextureFormat;

+		TextureType textureType;

+

+		FilterType textureFilter;

+		AddressingMode addressingModeU;

+		AddressingMode addressingModeV;

+		AddressingMode addressingModeW;

+		MipmapType mipmapFilterState;

+		bool sRGB;

+		bool gather;

+

+		Texture texture;

+		float exp2LOD;

+

+		static FilterType maximumTextureFilterQuality;

+		static MipmapType maximumMipmapFilterQuality;

+	};

+}

+

+#endif   // sw_Sampler_hpp

diff --git a/src/Renderer/SetupProcessor.cpp b/src/Renderer/SetupProcessor.cpp
index 1e737a4..775564e 100644
--- a/src/Renderer/SetupProcessor.cpp
+++ b/src/Renderer/SetupProcessor.cpp
@@ -1,6 +1,6 @@
 // SwiftShader Software Renderer
 //
-// Copyright(c) 2005-2011 TransGaming Inc.
+// Copyright(c) 2005-2012 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
@@ -14,7 +14,6 @@
 #include "SetupRoutine.hpp"
 #include "Primitive.hpp"
 #include "Polygon.hpp"
-#include "Viewport.hpp"
 #include "Context.hpp"
 #include "Renderer.hpp"
 #include "Constants.hpp"
@@ -23,6 +22,7 @@
 namespace sw
 {
 	extern bool complementaryDepthBuffer;
+	extern bool fullPixelPositionRegister;
 
 	unsigned int SetupProcessor::States::computeHash()
 	{
@@ -54,6 +54,7 @@
 
 	SetupProcessor::SetupProcessor(Context *context) : context(context)
 	{
+		precacheDLL = 0;
 		routineCache = 0;
 		setRoutineCacheSize(1024);
 	}
@@ -68,11 +69,14 @@
 	{
 		State state;
 
+		bool vPosZW = (context->pixelShader && context->pixelShader->vPosDeclared && fullPixelPositionRegister);
+
 		state.isDrawPoint = context->isDrawPoint(true);
 		state.isDrawLine = context->isDrawLine(true);
 		state.isDrawTriangle = context->isDrawTriangle(false);
 		state.isDrawSolidTriangle = context->isDrawTriangle(true);
-		state.interpolateDepth = context->depthBufferActive() || context->pixelFogActive() != Context::FOG_NONE;
+		state.interpolateZ = context->depthBufferActive() || context->pixelFogActive() != Context::FOG_NONE || vPosZW;
+		state.interpolateW = context->perspectiveActive() || vPosZW;
 		state.perspective = context->perspectiveActive();
 		state.pointSprite = context->pointSpriteActive();
 		state.cullMode = context->cullMode;
@@ -135,8 +139,8 @@
 
 						switch(context->pixelShader->semantic[interpolant][component - project].usage)
 						{
-						case ShaderOperation::USAGE_TEXCOORD: flat = point && !sprite; break;
-						case ShaderOperation::USAGE_COLOR:    flat = flatShading;      break;
+						case Shader::USAGE_TEXCOORD: flat = point && !sprite; break;
+						case Shader::USAGE_COLOR:    flat = flatShading;      break;
 						}
 
 						state.gradient[interpolant][component].attribute = input;
@@ -157,11 +161,11 @@
 					{
 					case 0xFF:
 						break;
-					case ShaderOperation::USAGE_TEXCOORD:
+					case Shader::USAGE_TEXCOORD:
 						state.gradient[interpolant][component].attribute = T0 + index;
 						state.gradient[interpolant][component].flat = point && !sprite;
 						break;
-					case ShaderOperation::USAGE_COLOR:
+					case Shader::USAGE_COLOR:
 						state.gradient[interpolant][component].attribute = D0 + index;
 						state.gradient[interpolant][component].flat = flatShading;
 						break;
diff --git a/src/Renderer/SetupProcessor.hpp b/src/Renderer/SetupProcessor.hpp
index 13adf87..0537057 100644
--- a/src/Renderer/SetupProcessor.hpp
+++ b/src/Renderer/SetupProcessor.hpp
@@ -1,6 +1,6 @@
 // SwiftShader Software Renderer

 //

-// Copyright(c) 2005-2011 TransGaming Inc.

+// Copyright(c) 2005-2012 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

@@ -24,7 +24,6 @@
 	struct Triangle;

 	struct Polygon;

 	struct Vertex;

-	class Viewport;

 	class Routine;

 	struct DrawCall;

 	struct DrawData;

@@ -36,21 +35,21 @@
 		{

 			unsigned int computeHash();

 

-			unsigned int isDrawPoint			: 1;

-			unsigned int isDrawLine				: 1;

-			unsigned int isDrawTriangle			: 1;

-			unsigned int isDrawSolidTriangle	: 1;

-			unsigned int interpolateDepth		: 1;

-			unsigned int perspective			: 1;

-			unsigned int pointSprite			: 1;

-			unsigned int positionRegister		: 4;

-			unsigned int pointSizeRegister		: 4;

-			unsigned int cullMode				: BITS(Context::CULL_LAST);

-			unsigned int twoSidedStencil		: 1;

-			unsigned int slopeDepthBias			: 1;

-			unsigned int vFace					: 1;

-

-			unsigned int multiSample			: 3;   // 1, 2 or 4

+			unsigned int isDrawPoint         : 1;

+			unsigned int isDrawLine          : 1;

+			unsigned int isDrawTriangle      : 1;

+			unsigned int isDrawSolidTriangle : 1;

+			unsigned int interpolateZ        : 1;

+			unsigned int interpolateW        : 1;

+			unsigned int perspective         : 1;

+			unsigned int pointSprite         : 1;

+			unsigned int positionRegister    : 4;

+			unsigned int pointSizeRegister   : 4;

+			unsigned int cullMode            : BITS(Context::CULL_LAST);

+			unsigned int twoSidedStencil     : 1;

+			unsigned int slopeDepthBias      : 1;

+			unsigned int vFace               : 1;

+			unsigned int multiSample         : 3;   // 1, 2 or 4

 

 			struct Gradient

 			{

@@ -100,6 +99,7 @@
 		Context *const context;

 

 		LRUCache<State, Routine> *routineCache;

+		HMODULE precacheDLL;

 	};

 }

 

diff --git a/src/Renderer/Stream.hpp b/src/Renderer/Stream.hpp
index 395f244..b038a99 100644
--- a/src/Renderer/Stream.hpp
+++ b/src/Renderer/Stream.hpp
@@ -1,98 +1,98 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2011 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 sw_Stream_hpp
-#define sw_Stream_hpp
-
-#include "Common/Types.hpp"
-
-namespace sw
-{
-	class Resource;
-
-	enum StreamType
-	{
-		STREAMTYPE_COLOR,     // 4 normalized unsigned bytes, ZYXW order
-		STREAMTYPE_UDEC3,     // 3 unsigned 10-bit fields
-		STREAMTYPE_DEC3N,     // 3 normalized signed 10-bit fields
-		STREAMTYPE_INDICES,   // 4 unsigned bytes, stored unconverted into X component
-		STREAMTYPE_FLOAT,     // Normalization ignored
-		STREAMTYPE_BYTE,
-		STREAMTYPE_SBYTE,
-		STREAMTYPE_SHORT,
-		STREAMTYPE_USHORT,
-		STREAMTYPE_FIXED,     // Normalization ignored (16.16 format)
-		STREAMTYPE_HALF,      // Normalization ignored
-
-		STREAMTYPE_LAST = STREAMTYPE_HALF
-	};
-
-	struct StreamResource
-	{
-		Resource *resource;
-		const void *buffer;
-		unsigned int stride;
-	};
-
-	struct Stream : public StreamResource
-	{
-		Stream(Resource *resource = 0, const void *buffer = 0, unsigned int stride = 0)
-		{
-			this->resource = resource;
-			this->buffer = buffer;
-			this->stride = stride;
-		}
-
-		Stream &define(StreamType type, unsigned int count, bool normalized = false)
-		{
-			this->type = type;
-			this->count = count;
-			this->normalized = normalized;
-
-			return *this;
-		}
-
-		Stream &define(const void *buffer, StreamType type, unsigned int count, bool normalized = false)
-		{
-			this->buffer = buffer;
-			this->type = type;
-			this->count = count;
-			this->normalized = normalized;
-
-			return *this;
-		}
-
-		Stream &defaults()
-		{
-			static const float4 null = {0, 0, 0, 1};
-	
-			resource = 0;
-			buffer = &null;
-			stride = 0;
-			type = STREAMTYPE_FLOAT;
-			count = 0;
-			normalized = false;
-
-			return *this;
-		}
-
-		operator bool() const   // Returns true if stream contains data
-		{
-			return count != 0;
-		}
-
-		StreamType type;
-		unsigned int count;
-		bool normalized;
-	};
-}
-
-#endif   // sw_Stream_hpp
+// SwiftShader Software Renderer

+//

+// Copyright(c) 2005-2012 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 sw_Stream_hpp

+#define sw_Stream_hpp

+

+#include "Common/Types.hpp"

+

+namespace sw

+{

+	class Resource;

+

+	enum StreamType

+	{

+		STREAMTYPE_COLOR,     // 4 normalized unsigned bytes, ZYXW order

+		STREAMTYPE_UDEC3,     // 3 unsigned 10-bit fields

+		STREAMTYPE_DEC3N,     // 3 normalized signed 10-bit fields

+		STREAMTYPE_INDICES,   // 4 unsigned bytes, stored unconverted into X component

+		STREAMTYPE_FLOAT,     // Normalization ignored

+		STREAMTYPE_BYTE,

+		STREAMTYPE_SBYTE,

+		STREAMTYPE_SHORT,

+		STREAMTYPE_USHORT,

+		STREAMTYPE_FIXED,     // Normalization ignored (16.16 format)

+		STREAMTYPE_HALF,      // Normalization ignored

+

+		STREAMTYPE_LAST = STREAMTYPE_HALF

+	};

+

+	struct StreamResource

+	{

+		Resource *resource;

+		const void *buffer;

+		unsigned int stride;

+	};

+

+	struct Stream : public StreamResource

+	{

+		Stream(Resource *resource = 0, const void *buffer = 0, unsigned int stride = 0)

+		{

+			this->resource = resource;

+			this->buffer = buffer;

+			this->stride = stride;

+		}

+

+		Stream &define(StreamType type, unsigned int count, bool normalized = false)

+		{

+			this->type = type;

+			this->count = count;

+			this->normalized = normalized;

+

+			return *this;

+		}

+

+		Stream &define(const void *buffer, StreamType type, unsigned int count, bool normalized = false)

+		{

+			this->buffer = buffer;

+			this->type = type;

+			this->count = count;

+			this->normalized = normalized;

+

+			return *this;

+		}

+

+		Stream &defaults()

+		{

+			static const float4 null = {0, 0, 0, 1};

+	

+			resource = 0;

+			buffer = &null;

+			stride = 0;

+			type = STREAMTYPE_FLOAT;

+			count = 0;

+			normalized = false;

+

+			return *this;

+		}

+

+		operator bool() const   // Returns true if stream contains data

+		{

+			return count != 0;

+		}

+

+		StreamType type;

+		unsigned char count;

+		bool normalized;

+	};

+}

+

+#endif   // sw_Stream_hpp

diff --git a/src/Renderer/Surface.cpp b/src/Renderer/Surface.cpp
index d072a15..3767123 100644
--- a/src/Renderer/Surface.cpp
+++ b/src/Renderer/Surface.cpp
@@ -1,6 +1,6 @@
 // SwiftShader Software Renderer
 //
-// Copyright(c) 2005-2011 TransGaming Inc.
+// Copyright(c) 2005-2012 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
@@ -13,12 +13,13 @@
 
 #include "Color.hpp"
 #include "Context.hpp"
+#include "Renderer.hpp"
 #include "Common/Half.hpp"
 #include "Common/Memory.hpp"
 #include "Common/CPUID.hpp"
 #include "Common/Resource.hpp"
 #include "Common/Debug.hpp"
-#include "Reactor/Shell.hpp"
+#include "Reactor/Reactor.hpp"
 
 #include <xmmintrin.h>
 #include <emmintrin.h>
@@ -35,6 +36,14 @@
 	unsigned int *Surface::palette = 0;
 	unsigned int Surface::paletteID = 0;
 
+	void Rect::clip(int minX, int minY, int maxX, int maxY)
+	{
+		x0 = sw::clamp(x0, minX, maxX);
+		y0 = sw::clamp(y0, minY, maxY);
+		x1 = sw::clamp(x1, minX, maxX);
+		y1 = sw::clamp(y1, minY, maxY);
+	}
+
 	void Surface::Buffer::write(int x, int y, int z, const Color<float> &color)
 	{
 		void *element = (unsigned char*)buffer + x * bytes + y * pitchB + z * sliceB;
@@ -624,7 +633,7 @@
 		return c00 + c10 + c01 + c11;
 	}
 
-	void *Surface::Buffer::lockRect(int left, int top, int front, Lock lock)
+	void *Surface::Buffer::lockRect(int x, int y, int z, Lock lock)
 	{
 		this->lock = lock;
 
@@ -647,14 +656,14 @@
 		#if S3TC_SUPPORT
 		case FORMAT_DXT1:
 		case FORMAT_ATI1:
-			return (unsigned char*)buffer + 8 * (left / 4) + (top / 4) * pitchB + front * sliceB;
+			return (unsigned char*)buffer + 8 * (x / 4) + (y / 4) * pitchB + z * sliceB;
 		case FORMAT_DXT3:
 		case FORMAT_DXT5:
 		case FORMAT_ATI2:
-			return (unsigned char*)buffer + 16 * (left / 4) + (top / 4) * pitchB + front * sliceB;
+			return (unsigned char*)buffer + 16 * (x / 4) + (y / 4) * pitchB + z * sliceB;
 		#endif
 		default:
-			return (unsigned char*)buffer + left * bytes + top * pitchB + front * sliceB;
+			return (unsigned char*)buffer + x * bytes + y * pitchB + z * sliceB;
 		}
 
 		return 0;
@@ -668,7 +677,7 @@
 	Surface::Surface(Resource *texture, int width, int height, int depth, Format format, bool lockable, bool renderTarget) : lockable(lockable), renderTarget(renderTarget)
 	{
 		resource = texture ? texture : new Resource(0);
-		hasParent = texture;
+		hasParent = texture != 0;
 		depth = max(1, depth);
 
 		external.buffer = 0;
@@ -720,6 +729,9 @@
 	{
 		if(!hasParent)
 		{
+			// Synchronize so we can deallocate the buffers below
+			resource->lock(DESTRUCT);
+			resource->unlock();
 			resource->destruct();
 		}
 
@@ -737,7 +749,7 @@
 		stencil.buffer = 0;
 	}
 
-	void *Surface::lockExternal(int left, int top, int front, Lock lock, Accessor client)
+	void *Surface::lockExternal(int x, int y, int z, Lock lock, Accessor client)
 	{
 		resource->lock(client);
 
@@ -774,7 +786,7 @@
 			ASSERT(false);
 		}
 
-		return external.lockRect(left, top, front, lock);
+		return external.lockRect(x, y, z, lock);
 	}
 
 	void Surface::unlockExternal()
@@ -784,7 +796,7 @@
 		external.unlockRect();
 	}
 
-	void *Surface::lockInternal(int left, int top, int front, Lock lock, Accessor client)
+	void *Surface::lockInternal(int x, int y, int z, Lock lock, Accessor client)
 	{
 		if(lock != LOCK_UNLOCKED)
 		{
@@ -860,7 +872,7 @@
 			resolve();
 		}
 
-		return internal.lockRect(left, top, front, lock);
+		return internal.lockRect(x, y, z, lock);
 	}
 
 	void Surface::unlockInternal()
@@ -2066,9 +2078,7 @@
 		int width4 = (width + 3) & ~3;
 		int height4 = (height + 3) & ~3;
 
-		void *buffer = allocate(size(width4, height4, depth, format));
-
-		return buffer;
+		return allocate(size(width4, height4, depth, format));
 	}
 
 	void Surface::memfill(void *buffer, int pattern, int bytes)
@@ -2199,7 +2209,7 @@
 					case FORMAT_A8R8G8B8:
 				//	case FORMAT_X8G8R8B8Q:   // FIXME
 				//	case FORMAT_A8G8R8B8Q:   // FIXME
-						if(rgbaMask == 0xF || (internal.format == FORMAT_X8R8G8B8 && rgbaMask == 0xF))
+						if(rgbaMask == 0xF || (internal.format == FORMAT_X8R8G8B8 && rgbaMask == 0x7))
 						{
 							memfill(target, color, 4 * (x1 - x0));
 						}
diff --git a/src/Renderer/Surface.hpp b/src/Renderer/Surface.hpp
index 9e46a9a..a50b1c3 100644
--- a/src/Renderer/Surface.hpp
+++ b/src/Renderer/Surface.hpp
@@ -1,6 +1,6 @@
 // SwiftShader Software Renderer

 //

-// Copyright(c) 2005-2011 TransGaming Inc.

+// Copyright(c) 2005-2012 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

@@ -20,12 +20,14 @@
 {

 	class Resource;

 

-	struct Rect   // Top-left coordinate system

+	struct Rect

 	{

-		union {int left;   int x1;};

-		union {int top;    int y1;};

-		union {int right;  int x2;};

-		union {int bottom; int y2;};

+		void clip(int minX, int minY, int maxX, int maxY);

+

+		int x0;   // Inclusive

+		int y0;   // Inclusive

+		int x1;   // Exclusive

+		int y1;   // Exclusive

 	};

 

 	enum Format

@@ -129,7 +131,7 @@
 			Color<float> sample(float x, float y, float z) const;

 			Color<float> sample(float x, float y) const;

 

-			void *lockRect(int left, int top, int front, Lock lock);

+			void *lockRect(int x, int y, int z, Lock lock);

 			void unlockRect();

 

 			void *buffer;

@@ -153,7 +155,7 @@
 		

 		virtual ~Surface();

 

-		void *lockExternal(int left, int top, int front, Lock lock, Accessor client);

+		void *lockExternal(int x, int y, int z, Lock lock, Accessor client);

 		void unlockExternal();

 		inline int getExternalWidth() const;

 		inline int getExternalHeight() const;

@@ -164,7 +166,7 @@
 		inline int getExternalSliceB() const;

 		inline int getExternalSliceP() const;

 

-		virtual void *lockInternal(int left, int top, int front, Lock lock, Accessor client);

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

 		virtual void unlockInternal();

 		inline int getInternalWidth() const;

 		inline int getInternalHeight() const;

@@ -327,7 +329,6 @@
 		static void decodeDXT1(Buffer &internal, const Buffer &external);

 		static void decodeDXT3(Buffer &internal, const Buffer &external);

 		static void decodeDXT5(Buffer &internal, const Buffer &external);

-

 		static void decodeATI1(Buffer &internal, const Buffer &external);

 		static void decodeATI2(Buffer &internal, const Buffer &external);

 		#endif

diff --git a/src/Renderer/Vector.hpp b/src/Renderer/Vector.hpp
index 2ff1713..4c32d9e 100644
--- a/src/Renderer/Vector.hpp
+++ b/src/Renderer/Vector.hpp
@@ -1,150 +1,150 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2011 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 Vector_hpp
-#define Vector_hpp
-
-namespace sw
-{
-	struct Point;
-	struct Matrix;
-	struct Plane;
-
-	struct Vector
-	{
-		Vector();
-		Vector(const int i);
-		Vector(const Vector &v);
-		Vector(const Point &p);
-		Vector(float v_x, float v_y, float v_z);
-
-		Vector &operator=(const Vector &v);
-
-		union
-		{
-			float v[3];
-
-			struct
-			{
-				float x;
-				float y;
-				float z;
-			};
-		};
-
-		float &operator[](int i);
-		float &operator()(int i);
-
-		const float &operator[](int i) const;
-		const float &operator()(int i) const;
-
-		Vector operator+() const;
-		Vector operator-() const;
-
-		Vector &operator+=(const Vector &v);
-		Vector &operator-=(const Vector &v);
-		Vector &operator*=(float s);
-		Vector &operator/=(float s);
-
-		friend bool operator==(const Vector &u, const Vector &v);
-		friend bool operator!=(const Vector &u, const Vector &v);
-
-		friend Vector operator+(const Vector &u, const Vector &v);
-		friend Vector operator-(const Vector &u, const Vector &v);
-		friend float operator*(const Vector &u, const Vector &v);   // Dot product
-		friend Vector operator*(float s, const Vector &v);
-		friend Vector operator*(const Vector &v, float s);
-		friend Vector operator/(const Vector &v, float s);
-		friend float operator^(const Vector &u, const Vector &v);   // Angle between vectors
-		friend Vector operator%(const Vector &u, const Vector &v);   // Cross product
-
-		friend Vector operator*(const Matrix &M, const Vector& v);
-		friend Vector operator*(const Vector &v, const Matrix &M);
-		friend Vector &operator*=(Vector &v, const Matrix &M);
-
-		static float N(const Vector &v);   // Norm
-		static float N2(const Vector &v);   // Squared norm
-
-		static Vector mirror(const Vector &v, const Plane &p);
-		static Vector reflect(const Vector &v, const Plane &p);
-		static Vector lerp(const Vector &u, const Vector &v, float t);
-	};
-}
-
-#include "Point.hpp"
-
-namespace sw
-{
-	inline Vector::Vector()
-	{
-	}
-
-	inline Vector::Vector(const int i)
-	{
-		const float s = (float)i;
-
-		x = s;
-		y = s;
-		z = s;
-	}
-
-	inline Vector::Vector(const Vector &v)
-	{
-		x = v.x;
-		y = v.y;
-		z = v.z;
-	}
-
-	inline Vector::Vector(const Point &P)
-	{
-		x = P.x;
-		y = P.y;
-		z = P.z;
-	}
-
-	inline Vector::Vector(float v_x, float v_y, float v_z)
-	{
-		x = v_x;
-		y = v_y;
-		z = v_z;
-	}
-
-	inline Vector &Vector::operator=(const Vector &v)
-	{
-		x = v.x;
-		y = v.y;
-		z = v.z;
-
-		return *this;
-	}
-
-	inline float &Vector::operator()(int i)
-	{
-		return v[i];
-	}
-
-	inline float &Vector::operator[](int i)
-	{
-		return v[i];
-	}
-
-	inline const float &Vector::operator()(int i) const
-	{
-		return v[i];
-	}
-
-	inline const float &Vector::operator[](int i) const
-	{
-		return v[i];
-	}
-}
-
-#endif   // Vector_hpp
+// SwiftShader Software Renderer

+//

+// Copyright(c) 2005-2011 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 Vector_hpp

+#define Vector_hpp

+

+namespace sw

+{

+	struct Point;

+	struct Matrix;

+	struct Plane;

+

+	struct Vector

+	{

+		Vector();

+		Vector(const int i);

+		Vector(const Vector &v);

+		Vector(const Point &p);

+		Vector(float v_x, float v_y, float v_z);

+

+		Vector &operator=(const Vector &v);

+

+		union

+		{

+			float v[3];

+

+			struct

+			{

+				float x;

+				float y;

+				float z;

+			};

+		};

+

+		float &operator[](int i);

+		float &operator()(int i);

+

+		const float &operator[](int i) const;

+		const float &operator()(int i) const;

+

+		Vector operator+() const;

+		Vector operator-() const;

+

+		Vector &operator+=(const Vector &v);

+		Vector &operator-=(const Vector &v);

+		Vector &operator*=(float s);

+		Vector &operator/=(float s);

+

+		friend bool operator==(const Vector &u, const Vector &v);

+		friend bool operator!=(const Vector &u, const Vector &v);

+

+		friend Vector operator+(const Vector &u, const Vector &v);

+		friend Vector operator-(const Vector &u, const Vector &v);

+		friend float operator*(const Vector &u, const Vector &v);   // Dot product

+		friend Vector operator*(float s, const Vector &v);

+		friend Vector operator*(const Vector &v, float s);

+		friend Vector operator/(const Vector &v, float s);

+		friend float operator^(const Vector &u, const Vector &v);   // Angle between vectors

+		friend Vector operator%(const Vector &u, const Vector &v);   // Cross product

+

+		friend Vector operator*(const Matrix &M, const Vector& v);

+		friend Vector operator*(const Vector &v, const Matrix &M);

+		friend Vector &operator*=(Vector &v, const Matrix &M);

+

+		static float N(const Vector &v);   // Norm

+		static float N2(const Vector &v);   // Squared norm

+

+		static Vector mirror(const Vector &v, const Plane &p);

+		static Vector reflect(const Vector &v, const Plane &p);

+		static Vector lerp(const Vector &u, const Vector &v, float t);

+	};

+}

+

+#include "Point.hpp"

+

+namespace sw

+{

+	inline Vector::Vector()

+	{

+	}

+

+	inline Vector::Vector(const int i)

+	{

+		const float s = (float)i;

+

+		x = s;

+		y = s;

+		z = s;

+	}

+

+	inline Vector::Vector(const Vector &v)

+	{

+		x = v.x;

+		y = v.y;

+		z = v.z;

+	}

+

+	inline Vector::Vector(const Point &P)

+	{

+		x = P.x;

+		y = P.y;

+		z = P.z;

+	}

+

+	inline Vector::Vector(float v_x, float v_y, float v_z)

+	{

+		x = v_x;

+		y = v_y;

+		z = v_z;

+	}

+

+	inline Vector &Vector::operator=(const Vector &v)

+	{

+		x = v.x;

+		y = v.y;

+		z = v.z;

+

+		return *this;

+	}

+

+	inline float &Vector::operator()(int i)

+	{

+		return v[i];

+	}

+

+	inline float &Vector::operator[](int i)

+	{

+		return v[i];

+	}

+

+	inline const float &Vector::operator()(int i) const

+	{

+		return v[i];

+	}

+

+	inline const float &Vector::operator[](int i) const

+	{

+		return v[i];

+	}

+}

+

+#endif   // Vector_hpp

diff --git a/src/Renderer/Vertex.hpp b/src/Renderer/Vertex.hpp
index b1f77c5..0b593a7 100644
--- a/src/Renderer/Vertex.hpp
+++ b/src/Renderer/Vertex.hpp
@@ -1,99 +1,99 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2011 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 Vertex_hpp
-#define Vertex_hpp
-
-#include "Color.hpp"
-#include "Common/MetaMacro.hpp"
-#include "Common/Types.hpp"
-
-namespace sw
-{
-	enum Out   // Default vertex attribute semantic
-	{
-		Pos = 0,
-		D0 = 1,
-		D1 = 2,
-		T0 = 3,
-		T1 = 4,
-		T2 = 5,
-		T3 = 6,
-		T4 = 7,
-		T5 = 8,
-		T6 = 9,
-		T7 = 10,
-		Fog = 11,   // x component
-		Pts = Fog   // y component
-	};
-
-	struct UVWQ
-	{
-		float u;
-		float v;
-		float w;
-		float q;
-
-		float &operator[](int i)
-		{
-			return (&u)[i];
-		}
-	};
-
-	ALIGN(16, struct Vertex
-	{
-		union
-		{
-			struct   // Fixed semantics
-			{
-				union   // Position
-				{
-					struct
-					{
-						float x;
-						float y;
-						float z;
-						float w;
-					};
-
-					struct
-					{
-						float4 P;
-					};
-				};
-
-				Color<float> C[2];   // Diffuse and specular color
-
-				UVWQ T[8];           // Texture coordinates
-
-				float f;             // Fog
-				float pSize;         // Point size
-				unsigned char padding0[4];
-				unsigned char clipFlags;
-				unsigned char padding1[3];
-			};
-
-			float4 v[12];   // Generic components using semantic declaration
-		};
-
-		struct   // Projected coordinates
-		{
-			int X;
-			int Y;
-			float Z;
-			float W;
-		};
-	});
-
-	META_ASSERT((sizeof(Vertex) & 0x0000000F) == 0);
-}
-
-#endif   // Vertex_hpp
+// SwiftShader Software Renderer

+//

+// Copyright(c) 2005-2011 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 Vertex_hpp

+#define Vertex_hpp

+

+#include "Color.hpp"

+#include "Common/MetaMacro.hpp"

+#include "Common/Types.hpp"

+

+namespace sw

+{

+	enum Out   // Default vertex attribute semantic

+	{

+		Pos = 0,

+		D0 = 1,

+		D1 = 2,

+		T0 = 3,

+		T1 = 4,

+		T2 = 5,

+		T3 = 6,

+		T4 = 7,

+		T5 = 8,

+		T6 = 9,

+		T7 = 10,

+		Fog = 11,   // x component

+		Pts = Fog   // y component

+	};

+

+	struct UVWQ

+	{

+		float u;

+		float v;

+		float w;

+		float q;

+

+		float &operator[](int i)

+		{

+			return (&u)[i];

+		}

+	};

+

+	ALIGN(16, struct Vertex

+	{

+		union

+		{

+			struct   // Fixed semantics

+			{

+				union   // Position

+				{

+					struct

+					{

+						float x;

+						float y;

+						float z;

+						float w;

+					};

+

+					struct

+					{

+						float4 P;

+					};

+				};

+

+				Color<float> C[2];   // Diffuse and specular color

+

+				UVWQ T[8];           // Texture coordinates

+

+				float f;             // Fog

+				float pSize;         // Point size

+				unsigned char padding0[4];

+				unsigned char clipFlags;

+				unsigned char padding1[3];

+			};

+

+			float4 v[12];   // Generic components using semantic declaration

+		};

+

+		struct   // Projected coordinates

+		{

+			int X;

+			int Y;

+			float Z;

+			float W;

+		};

+	});

+

+	META_ASSERT((sizeof(Vertex) & 0x0000000F) == 0);

+}

+

+#endif   // Vertex_hpp

diff --git a/src/Renderer/VertexProcessor.cpp b/src/Renderer/VertexProcessor.cpp
index 6f23be7..c660ef6 100644
--- a/src/Renderer/VertexProcessor.cpp
+++ b/src/Renderer/VertexProcessor.cpp
@@ -1,6 +1,6 @@
 // SwiftShader Software Renderer
 //
-// Copyright(c) 2005-2011 TransGaming Inc.
+// Copyright(c) 2005-2012 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
@@ -11,7 +11,6 @@
 
 #include "VertexProcessor.hpp"
 
-#include "Viewport.hpp"
 #include "Math.hpp"
 #include "VertexPipeline.hpp"
 #include "VertexProgram.hpp"
@@ -98,6 +97,7 @@
 			updateModelMatrix[i] = true;
 		}
 
+		precacheDLL = 0;
 		routineCache = 0;
 		setRoutineCacheSize(1024);
 	}
@@ -795,11 +795,11 @@
 
 		if(context->vertexShader)
 		{
-			state.shaderHash = context->vertexShader->getHash();
+			state.shaderID = context->vertexShader->getSerialID();
 		}
 		else
 		{
-			state.shaderHash = 0;
+			state.shaderID = 0;
 		}
 
 		state.fixedFunction = !context->vertexShader && context->pixelShaderVersion() < 0x0300;
@@ -837,7 +837,6 @@
 		state.pointScaleActive = context->pointScaleActive();
 
 		state.preTransformed = context->preTransformed;
-		state.postTransform = context->postTransform;
 		state.superSampling = context->renderTarget[0]->getSuperSampleCount() > 1;
 		state.multiSampling = context->renderTarget[0]->getMultiSampleCount() > 1;
 
@@ -895,10 +894,10 @@
 
 			for(int stage = 0; stage < 8; stage++)
 			{
-				if(context->vertexTextureActive(stage, 0)) state.output[T0 + stage].write |= 0x01;
-				if(context->vertexTextureActive(stage, 1)) state.output[T0 + stage].write |= 0x02;
-				if(context->vertexTextureActive(stage, 2)) state.output[T0 + stage].write |= 0x04;
-				if(context->vertexTextureActive(stage, 3)) state.output[T0 + stage].write |= 0x08;
+				if(context->texCoordActive(stage, 0)) state.output[T0 + stage].write |= 0x01;
+				if(context->texCoordActive(stage, 1)) state.output[T0 + stage].write |= 0x02;
+				if(context->texCoordActive(stage, 2)) state.output[T0 + stage].write |= 0x04;
+				if(context->texCoordActive(stage, 3)) state.output[T0 + stage].write |= 0x08;
 			}
 
 			if(context->fogActive())
diff --git a/src/Renderer/VertexProcessor.hpp b/src/Renderer/VertexProcessor.hpp
index 6738dca..5e3ff96 100644
--- a/src/Renderer/VertexProcessor.hpp
+++ b/src/Renderer/VertexProcessor.hpp
@@ -1,313 +1,312 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2011 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 sw_VertexProcessor_hpp
-#define sw_VertexProcessor_hpp
-
-#include "Matrix.hpp"
-#include "Context.hpp"
-#include "LRUCache.hpp"
-
-namespace sw
-{
-	class Viewport;
-	class Routine;
-	struct DrawData;
-
-	struct VertexCache   // FIXME: Variable size
-	{
-		void clear();
-
-		Vertex vertex[16][4];
-		unsigned int tag[16];
-
-		int drawCall;
-	};
-
-	struct VertexTask
-	{
-		unsigned int count;
-		VertexCache vertexCache;
-	};
-
-	class VertexProcessor
-	{
-	public:
-		struct States
-		{
-			unsigned int computeHash();
-
-			uint64_t shaderHash;
-
-			unsigned int fixedFunction						: 1;
-			unsigned int shaderContainsTexldl				: 1;
-			unsigned int positionRegister					: 4;
-			unsigned int pointSizeRegister					: 4;   // 0xF signifies no vertex point size
-				
-			unsigned int vertexBlendMatrixCount				: 3;
-			unsigned int indexedVertexBlendEnable			: 1;
-			unsigned int vertexNormalActive					: 1;
-			unsigned int normalizeNormals					: 1;
-			unsigned int vertexLightingActive				: 1;
-			unsigned int diffuseActive						: 1;
-			unsigned int specularActive						: 1;
-			unsigned int vertexSpecularActive				: 1;
-			unsigned int vertexLightActive					: 8;
-			unsigned int vertexDiffuseMaterialSourceActive	: BITS(Context::MATERIAL_LAST);
-			unsigned int vertexSpecularMaterialSourceActive	: BITS(Context::MATERIAL_LAST);
-			unsigned int vertexAmbientMaterialSourceActive	: BITS(Context::MATERIAL_LAST);
-			unsigned int vertexEmissiveMaterialSourceActive	: BITS(Context::MATERIAL_LAST);
-			unsigned int fogActive							: 1;
-			unsigned int vertexFogMode						: BITS(Context::FOG_LAST);
-			unsigned int rangeFogActive						: 1;
-			unsigned int localViewerActive					: 1;
-			unsigned int pointSizeActive					: 1;
-			unsigned int pointScaleActive					: 1;
-
-			unsigned int preTransformed						: 1;
-			unsigned int postTransform						: 1;
-			unsigned int superSampling						: 1;
-			unsigned int multiSampling						: 1;
-
-			struct TextureState
-			{
-				unsigned char texGenActive : BITS(Context::TEXGEN_LAST);
-				unsigned char textureTransformCountActive : 3;
-				unsigned char texCoordIndexActive : 3;
-			};
-
-			TextureState textureState[8];
-
-			Sampler::State samplerState[4];
-
-			struct Input
-			{
-				operator bool() const   // Returns true if stream contains data
-				{
-					return count != 0;
-				}
-
-				unsigned int type       : BITS(STREAMTYPE_LAST);
-				unsigned int count      : 3;
-				unsigned int normalized : 1;
-			};
-
-			struct Output
-			{
-				union
-				{
-					unsigned char write : 4;
-
-					struct
-					{
-						unsigned char xWrite : 1;
-						unsigned char yWrite : 1;
-						unsigned char zWrite : 1;
-						unsigned char wWrite : 1;
-					};
-				};
-
-				union
-				{
-					unsigned char clamp : 4;
-					
-					struct
-					{
-						unsigned char xClamp : 1;
-						unsigned char yClamp : 1;
-						unsigned char zClamp : 1;
-						unsigned char wClamp : 1;
-					};
-				};
-			};
-
-			Input input[16];
-			Output output[12];
-		};
-
-		struct State : States
-		{
-			State();
-
-			bool operator==(const State &state) const;
-
-			unsigned int hash;
-		};
-
-		struct FixedFunction
-		{
-			float4 transformT[12][4];
-			float4 cameraTransformT[12][4];
-			float4 normalTransformT[12][4];
-			float4 textureTransform[8][4];
-			
-			float4 lightPosition[8];
-			float4 lightAmbient[8];
-			float4 lightSpecular[8];
-			float4 lightDiffuse[8];
-			float4 attenuationConstant[8];
-			float4 attenuationLinear[8];
-			float4 attenuationQuadratic[8];
-			float lightRange[8];
-			float4 materialDiffuse;
-			float4 materialSpecular;
-			float materialShininess;
-			float4 globalAmbient;
-			float4 materialEmission;
-			float4 materialAmbient;
-		};
-
-		struct PointSprite
-		{
-			float4 pointSize;
-			float pointSizeMin;
-			float pointSizeMax;
-			float pointScaleA;
-			float pointScaleB;
-			float pointScaleC;
-		};
-
-		typedef void (__cdecl *RoutinePointer)(Vertex *output, unsigned int *batch, VertexTask *vertexTask, DrawData *draw);
-
-		VertexProcessor(Context *context);
-
-		virtual ~VertexProcessor();
-
-		virtual void setInputStream(int index, const Stream &stream);
-
-		virtual void setInputPositionStream(const Stream &stream);
-		virtual void setInputBlendWeightStream(const Stream &stream);
-		virtual void setInputBlendIndicesStream(const Stream &stream);
-		virtual void setInputNormalStream(const Stream &stream);
-		virtual void setInputPSizeStream(const Stream &stream);
-		virtual void setInputTexCoordStream(const Stream &stream, int index);
-		virtual void setInputPositiontStream(const Stream &stream);
-		virtual void setInputColorStream(const Stream &stream, int index);
-
-		virtual void resetInputStreams(bool preTransformed);
-
-		virtual void setFloatConstant(unsigned int index, const float value[4]);
-		virtual void setIntegerConstant(unsigned int index, const int integer[4]);
-		virtual void setBooleanConstant(unsigned int index, int boolean);
-
-		// Transformations
-		virtual void setModelMatrix(const Matrix &M, int i = 0);
-		virtual void setViewMatrix(const Matrix &V);
-		virtual void setBaseMatrix(const Matrix &B);
-		virtual void setProjectionMatrix(const Matrix &P);
-
-		// Lighting
-		virtual void setLightingEnable(bool lightingEnable);
-		virtual void setLightEnable(unsigned int light, bool lightEnable);
-		virtual void setSpecularEnable(bool specularEnable);
-
-		virtual void setGlobalAmbient(const Color<float> &globalAmbient);
-		virtual void setLightPosition(unsigned int light, const Point &lightPosition);
-		virtual void setLightViewPosition(unsigned int light, const Point &lightPosition);
-		virtual void setLightDiffuse(unsigned int light, const Color<float> &lightDiffuse);
-		virtual void setLightSpecular(unsigned int light, const Color<float> &lightSpecular);
-		virtual void setLightAmbient(unsigned int light, const Color<float> &lightAmbient);
-		virtual void setLightAttenuation(unsigned int light, float constant, float linear, float quadratic);
-		virtual void setLightRange(unsigned int light, float lightRange);
-
-		virtual void setFogEnable(bool fogEnable);
-		virtual void setVertexFogMode(Context::FogMode fogMode);
-		virtual void setRangeFogEnable(bool enable);
-
-		virtual void setColorVertexEnable(bool colorVertexEnable);
-		virtual void setDiffuseMaterialSource(Context::MaterialSource diffuseMaterialSource);
-		virtual void setSpecularMaterialSource(Context::MaterialSource specularMaterialSource);
-		virtual void setAmbientMaterialSource(Context::MaterialSource ambientMaterialSource);
-		virtual void setEmissiveMaterialSource(Context::MaterialSource emissiveMaterialSource);
-
-		virtual void setMaterialEmission(const Color<float> &emission);
-		virtual void setMaterialAmbient(const Color<float> &materialAmbient);
-		virtual void setMaterialDiffuse(const Color<float> &diffuseColor);
-		virtual void setMaterialSpecular(const Color<float> &specularColor);
-		virtual void setMaterialShininess(float specularPower);
-
-		virtual void setIndexedVertexBlendEnable(bool indexedVertexBlendEnable);
-		virtual void setVertexBlendMatrixCount(unsigned int vertexBlendMatrixCount);
-
-		virtual void setTextureWrap(unsigned int stage, int mask);
-		virtual void setTexGen(unsigned int stage, Context::TexGen texGen);
-		virtual void setLocalViewer(bool localViewer);
-		virtual void setNormalizeNormals(bool normalizeNormals);
-		virtual void setTextureMatrix(int stage, const Matrix &T);
-		virtual void setTextureTransform(int stage, int count, bool project);
-
-		virtual void setTextureFilter(unsigned int sampler, FilterType textureFilter);
-		virtual void setMipmapFilter(unsigned int sampler, MipmapType mipmapFilter);
-		virtual void setGatherEnable(unsigned int sampler, bool enable);
-		virtual void setAddressingModeU(unsigned int sampler, AddressingMode addressingMode);
-		virtual void setAddressingModeV(unsigned int sampler, AddressingMode addressingMode);
-		virtual void setAddressingModeW(unsigned int sampler, AddressingMode addressingMode);
-		virtual void setReadSRGB(unsigned int sampler, bool sRGB);
-		virtual void setMipmapLOD(unsigned int sampler, float bias);
-		virtual void setBorderColor(unsigned int sampler, const Color<float> &borderColor);
-		virtual void setMaxAnisotropy(unsigned int stage, unsigned int maxAnisotropy);
-
-		virtual void setPointSize(float pointSize);
-		virtual void setPointSizeMin(float pointSizeMin);
-		virtual void setPointSizeMax(float pointSizeMax);
-		virtual void setPointScaleA(float pointScaleA);
-		virtual void setPointScaleB(float pointScaleB);
-		virtual void setPointScaleC(float pointScaleC);
-
-	protected:
-		const Matrix &getModelTransform(int i);
-		const Matrix &getViewTransform();
-
-		const State update();
-		Routine *routine(const State &state);
-
-		bool isFixedFunction();
-		void setRoutineCacheSize(int cacheSize);
-
-		// Shader constants
-		float4 c[256 + 1];   // One extra for indices out of range, c[256] = {0, 0, 0, 0}
-		int4 i[16];
-		bool b[16];
-
-		PointSprite point;
-		FixedFunction ff;
-
-	private:
-		void updateTransform();
-
-		void setTransform(const Matrix &M, int i);
-		void setCameraTransform(const Matrix &M, int i);
-		void setNormalTransform(const Matrix &M, int i);
-
-		Context *const context;
-
-		LRUCache<State, Routine> *routineCache;
-
-	protected:
-		Matrix M[12];      // Model/Geometry/World matrix
-		Matrix V;          // View/Camera/Eye matrix
-		Matrix B;          // Base matrix
-		Matrix P;          // Projection matrix
-		Matrix PB;         // P * B
-		Matrix PBV;        // P * B * V
-		Matrix PBVM[12];   // P * B * V * M
-
-		// Update hierarchy
-		bool updateMatrix;
-		bool updateModelMatrix[12];
-		bool updateViewMatrix;
-		bool updateBaseMatrix;
-		bool updateProjectionMatrix;
-		bool updateLighting;
-	};
-}
-
-#endif   // sw_VertexProcessor_hpp
+// SwiftShader Software Renderer

+//

+// Copyright(c) 2005-2012 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 sw_VertexProcessor_hpp

+#define sw_VertexProcessor_hpp

+

+#include "Matrix.hpp"

+#include "Context.hpp"

+#include "LRUCache.hpp"

+

+namespace sw

+{

+	class Routine;

+	struct DrawData;

+

+	struct VertexCache   // FIXME: Variable size

+	{

+		void clear();

+

+		Vertex vertex[16][4];

+		unsigned int tag[16];

+

+		int drawCall;

+	};

+

+	struct VertexTask

+	{

+		unsigned int count;

+		VertexCache vertexCache;

+	};

+

+	class VertexProcessor

+	{

+	public:

+		struct States

+		{

+			unsigned int computeHash();

+

+			uint64_t shaderID;

+

+			unsigned int fixedFunction						: 1;

+			unsigned int shaderContainsTexldl				: 1;

+			unsigned int positionRegister					: 4;

+			unsigned int pointSizeRegister					: 4;   // 0xF signifies no vertex point size

+				

+			unsigned int vertexBlendMatrixCount				: 3;

+			unsigned int indexedVertexBlendEnable			: 1;

+			unsigned int vertexNormalActive					: 1;

+			unsigned int normalizeNormals					: 1;

+			unsigned int vertexLightingActive				: 1;

+			unsigned int diffuseActive						: 1;

+			unsigned int specularActive						: 1;

+			unsigned int vertexSpecularActive				: 1;

+			unsigned int vertexLightActive					: 8;

+			unsigned int vertexDiffuseMaterialSourceActive	: BITS(Context::MATERIAL_LAST);

+			unsigned int vertexSpecularMaterialSourceActive	: BITS(Context::MATERIAL_LAST);

+			unsigned int vertexAmbientMaterialSourceActive	: BITS(Context::MATERIAL_LAST);

+			unsigned int vertexEmissiveMaterialSourceActive	: BITS(Context::MATERIAL_LAST);

+			unsigned int fogActive							: 1;

+			unsigned int vertexFogMode						: BITS(Context::FOG_LAST);

+			unsigned int rangeFogActive						: 1;

+			unsigned int localViewerActive					: 1;

+			unsigned int pointSizeActive					: 1;

+			unsigned int pointScaleActive					: 1;

+

+			unsigned int preTransformed						: 1;

+			unsigned int superSampling						: 1;

+			unsigned int multiSampling						: 1;

+

+			struct TextureState

+			{

+				unsigned char texGenActive : BITS(Context::TEXGEN_LAST);

+				unsigned char textureTransformCountActive : 3;

+				unsigned char texCoordIndexActive : 3;

+			};

+

+			TextureState textureState[8];

+

+			Sampler::State samplerState[4];

+

+			struct Input

+			{

+				operator bool() const   // Returns true if stream contains data

+				{

+					return count != 0;

+				}

+

+				unsigned int type       : BITS(STREAMTYPE_LAST);

+				unsigned int count      : 3;

+				unsigned int normalized : 1;

+			};

+

+			struct Output

+			{

+				union

+				{

+					unsigned char write : 4;

+

+					struct

+					{

+						unsigned char xWrite : 1;

+						unsigned char yWrite : 1;

+						unsigned char zWrite : 1;

+						unsigned char wWrite : 1;

+					};

+				};

+

+				union

+				{

+					unsigned char clamp : 4;

+					

+					struct

+					{

+						unsigned char xClamp : 1;

+						unsigned char yClamp : 1;

+						unsigned char zClamp : 1;

+						unsigned char wClamp : 1;

+					};

+				};

+			};

+

+			Input input[16];

+			Output output[12];

+		};

+

+		struct State : States

+		{

+			State();

+

+			bool operator==(const State &state) const;

+

+			unsigned int hash;

+		};

+

+		struct FixedFunction

+		{

+			float4 transformT[12][4];

+			float4 cameraTransformT[12][4];

+			float4 normalTransformT[12][4];

+			float4 textureTransform[8][4];

+			

+			float4 lightPosition[8];

+			float4 lightAmbient[8];

+			float4 lightSpecular[8];

+			float4 lightDiffuse[8];

+			float4 attenuationConstant[8];

+			float4 attenuationLinear[8];

+			float4 attenuationQuadratic[8];

+			float lightRange[8];

+			float4 materialDiffuse;

+			float4 materialSpecular;

+			float materialShininess;

+			float4 globalAmbient;

+			float4 materialEmission;

+			float4 materialAmbient;

+		};

+

+		struct PointSprite

+		{

+			float4 pointSize;

+			float pointSizeMin;

+			float pointSizeMax;

+			float pointScaleA;

+			float pointScaleB;

+			float pointScaleC;

+		};

+

+		typedef void (__cdecl *RoutinePointer)(Vertex *output, unsigned int *batch, VertexTask *vertexTask, DrawData *draw);

+

+		VertexProcessor(Context *context);

+

+		virtual ~VertexProcessor();

+

+		virtual void setInputStream(int index, const Stream &stream);

+

+		virtual void setInputPositionStream(const Stream &stream);

+		virtual void setInputBlendWeightStream(const Stream &stream);

+		virtual void setInputBlendIndicesStream(const Stream &stream);

+		virtual void setInputNormalStream(const Stream &stream);

+		virtual void setInputPSizeStream(const Stream &stream);

+		virtual void setInputTexCoordStream(const Stream &stream, int index);

+		virtual void setInputPositiontStream(const Stream &stream);

+		virtual void setInputColorStream(const Stream &stream, int index);

+

+		virtual void resetInputStreams(bool preTransformed);

+

+		virtual void setFloatConstant(unsigned int index, const float value[4]);

+		virtual void setIntegerConstant(unsigned int index, const int integer[4]);

+		virtual void setBooleanConstant(unsigned int index, int boolean);

+

+		// Transformations

+		virtual void setModelMatrix(const Matrix &M, int i = 0);

+		virtual void setViewMatrix(const Matrix &V);

+		virtual void setBaseMatrix(const Matrix &B);

+		virtual void setProjectionMatrix(const Matrix &P);

+

+		// Lighting

+		virtual void setLightingEnable(bool lightingEnable);

+		virtual void setLightEnable(unsigned int light, bool lightEnable);

+		virtual void setSpecularEnable(bool specularEnable);

+

+		virtual void setGlobalAmbient(const Color<float> &globalAmbient);

+		virtual void setLightPosition(unsigned int light, const Point &lightPosition);

+		virtual void setLightViewPosition(unsigned int light, const Point &lightPosition);

+		virtual void setLightDiffuse(unsigned int light, const Color<float> &lightDiffuse);

+		virtual void setLightSpecular(unsigned int light, const Color<float> &lightSpecular);

+		virtual void setLightAmbient(unsigned int light, const Color<float> &lightAmbient);

+		virtual void setLightAttenuation(unsigned int light, float constant, float linear, float quadratic);

+		virtual void setLightRange(unsigned int light, float lightRange);

+

+		virtual void setFogEnable(bool fogEnable);

+		virtual void setVertexFogMode(Context::FogMode fogMode);

+		virtual void setRangeFogEnable(bool enable);

+

+		virtual void setColorVertexEnable(bool colorVertexEnable);

+		virtual void setDiffuseMaterialSource(Context::MaterialSource diffuseMaterialSource);

+		virtual void setSpecularMaterialSource(Context::MaterialSource specularMaterialSource);

+		virtual void setAmbientMaterialSource(Context::MaterialSource ambientMaterialSource);

+		virtual void setEmissiveMaterialSource(Context::MaterialSource emissiveMaterialSource);

+

+		virtual void setMaterialEmission(const Color<float> &emission);

+		virtual void setMaterialAmbient(const Color<float> &materialAmbient);

+		virtual void setMaterialDiffuse(const Color<float> &diffuseColor);

+		virtual void setMaterialSpecular(const Color<float> &specularColor);

+		virtual void setMaterialShininess(float specularPower);

+

+		virtual void setIndexedVertexBlendEnable(bool indexedVertexBlendEnable);

+		virtual void setVertexBlendMatrixCount(unsigned int vertexBlendMatrixCount);

+

+		virtual void setTextureWrap(unsigned int stage, int mask);

+		virtual void setTexGen(unsigned int stage, Context::TexGen texGen);

+		virtual void setLocalViewer(bool localViewer);

+		virtual void setNormalizeNormals(bool normalizeNormals);

+		virtual void setTextureMatrix(int stage, const Matrix &T);

+		virtual void setTextureTransform(int stage, int count, bool project);

+

+		virtual void setTextureFilter(unsigned int sampler, FilterType textureFilter);

+		virtual void setMipmapFilter(unsigned int sampler, MipmapType mipmapFilter);

+		virtual void setGatherEnable(unsigned int sampler, bool enable);

+		virtual void setAddressingModeU(unsigned int sampler, AddressingMode addressingMode);

+		virtual void setAddressingModeV(unsigned int sampler, AddressingMode addressingMode);

+		virtual void setAddressingModeW(unsigned int sampler, AddressingMode addressingMode);

+		virtual void setReadSRGB(unsigned int sampler, bool sRGB);

+		virtual void setMipmapLOD(unsigned int sampler, float bias);

+		virtual void setBorderColor(unsigned int sampler, const Color<float> &borderColor);

+		virtual void setMaxAnisotropy(unsigned int stage, unsigned int maxAnisotropy);

+

+		virtual void setPointSize(float pointSize);

+		virtual void setPointSizeMin(float pointSizeMin);

+		virtual void setPointSizeMax(float pointSizeMax);

+		virtual void setPointScaleA(float pointScaleA);

+		virtual void setPointScaleB(float pointScaleB);

+		virtual void setPointScaleC(float pointScaleC);

+

+	protected:

+		const Matrix &getModelTransform(int i);

+		const Matrix &getViewTransform();

+

+		const State update();

+		Routine *routine(const State &state);

+

+		bool isFixedFunction();

+		void setRoutineCacheSize(int cacheSize);

+

+		// Shader constants

+		float4 c[256 + 1];   // One extra for indices out of range, c[256] = {0, 0, 0, 0}

+		int4 i[16];

+		bool b[16];

+

+		PointSprite point;

+		FixedFunction ff;

+

+	private:

+		void updateTransform();

+

+		void setTransform(const Matrix &M, int i);

+		void setCameraTransform(const Matrix &M, int i);

+		void setNormalTransform(const Matrix &M, int i);

+

+		Context *const context;

+

+		LRUCache<State, Routine> *routineCache;

+		HMODULE precacheDLL;

+

+	protected:

+		Matrix M[12];      // Model/Geometry/World matrix

+		Matrix V;          // View/Camera/Eye matrix

+		Matrix B;          // Base matrix

+		Matrix P;          // Projection matrix

+		Matrix PB;         // P * B

+		Matrix PBV;        // P * B * V

+		Matrix PBVM[12];   // P * B * V * M

+

+		// Update hierarchy

+		bool updateMatrix;

+		bool updateModelMatrix[12];

+		bool updateViewMatrix;

+		bool updateBaseMatrix;

+		bool updateProjectionMatrix;

+		bool updateLighting;

+	};

+}

+

+#endif   // sw_VertexProcessor_hpp

diff --git a/src/Renderer/Viewport.hpp b/src/Renderer/Viewport.hpp
index 010d921..a946c69 100644
--- a/src/Renderer/Viewport.hpp
+++ b/src/Renderer/Viewport.hpp
@@ -1,48 +1,48 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2011 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 sw_Viewport_hpp
-#define sw_Viewport_hpp
-
-namespace sw
-{
-	class Viewport
-	{
-	public:
-		Viewport();
-
-		~Viewport();
-
-		void setLeft(float l);
-		void setTop(float t);
-		void setWidth(float w);
-		void setHeight(float h);
-		void setNear(float n);
-		void setFar(float f);
-
-		float getLeft() const;
-		float getTop() const;
-		float getWidth() const;
-		float getHeight() const;
-		float getNear() const;
-		float getFar() const;
-
-	private:
-		float left;     // Leftmost pixel column
-		float top;      // Highest pixel row
-		float width;    // Width in pixels
-		float height;   // Height in pixels
-		float min;
-		float max;
-	};
-}
-
-#endif   // sw_Viewport_hpp
+// SwiftShader Software Renderer

+//

+// Copyright(c) 2005-2011 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 sw_Viewport_hpp

+#define sw_Viewport_hpp

+

+namespace sw

+{

+	class Viewport

+	{

+	public:

+		Viewport();

+

+		~Viewport();

+

+		void setLeft(float l);

+		void setTop(float t);

+		void setWidth(float w);

+		void setHeight(float h);

+		void setNear(float n);

+		void setFar(float f);

+

+		float getLeft() const;

+		float getTop() const;

+		float getWidth() const;

+		float getHeight() const;

+		float getNear() const;

+		float getFar() const;

+

+	private:

+		float left;     // Leftmost pixel column

+		float top;      // Highest pixel row

+		float width;    // Width in pixels

+		float height;   // Height in pixels

+		float min;

+		float max;

+	};

+}

+

+#endif   // sw_Viewport_hpp