Replacing numbers by constants

In order to be able to easily modify
values in between OpenGL ES versions,
some constants were added to replace
hardcoded numbers.

Change-Id: Ic35bf8e45341addf5315acaa9ffac01095b8907c
Reviewed-on: https://swiftshader-review.googlesource.com/2761
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/Main/Config.hpp b/src/Main/Config.hpp
index b23500b..a5bc115 100644
--- a/src/Main/Config.hpp
+++ b/src/Main/Config.hpp
@@ -67,7 +67,15 @@
 enum

 {

 	OUTLINE_RESOLUTION = 4096,   // Maximum vertical resolution of the render target

-	MIPMAP_LEVELS = 14

+	MIPMAP_LEVELS = 14,

+	TEXTURE_IMAGE_UNITS = 16,

+	VERTEX_TEXTURE_IMAGE_UNITS = 4,

+	TOTAL_IMAGE_UNITS = TEXTURE_IMAGE_UNITS + VERTEX_TEXTURE_IMAGE_UNITS,

+	FRAGMENT_UNIFORM_VECTORS = 224,

+	VERTEX_UNIFORM_VECTORS = 256,

+	MAX_UNIFORM_BLOCKS_COMPONENTS = 49152,

+	MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS = MAX_UNIFORM_BLOCKS_COMPONENTS + 4 * FRAGMENT_UNIFORM_VECTORS,

+	MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS = MAX_UNIFORM_BLOCKS_COMPONENTS + 4 * VERTEX_UNIFORM_VECTORS,

 };

 

 #endif   // sw_Config_hpp

diff --git a/src/OpenGL/libGL/Device.cpp b/src/OpenGL/libGL/Device.cpp
index 7e78042..062c4fe 100644
--- a/src/OpenGL/libGL/Device.cpp
+++ b/src/OpenGL/libGL/Device.cpp
@@ -426,7 +426,7 @@
 

 	void Device::setPixelShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count)

 	{

-		for(unsigned int i = 0; i < count && startRegister + i < 224; i++)

+		for(unsigned int i = 0; i < count && startRegister + i < FRAGMENT_UNIFORM_VECTORS; i++)

 		{

 			pixelShaderConstantF[startRegister + i][0] = constantData[i * 4 + 0];

 			pixelShaderConstantF[startRegister + i][1] = constantData[i * 4 + 1];

@@ -473,7 +473,7 @@
 

 	void Device::setVertexShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count)

 	{

-		for(unsigned int i = 0; i < count && startRegister + i < 256; i++)

+		for(unsigned int i = 0; i < count && startRegister + i < VERTEX_UNIFORM_VECTORS; i++)

 		{

 			vertexShaderConstantF[startRegister + i][0] = constantData[i * 4 + 0];

 			vertexShaderConstantF[startRegister + i][1] = constantData[i * 4 + 1];

diff --git a/src/OpenGL/libGL/Device.hpp b/src/OpenGL/libGL/Device.hpp
index 09c566e..dec8dfb 100644
--- a/src/OpenGL/libGL/Device.hpp
+++ b/src/OpenGL/libGL/Device.hpp
@@ -89,8 +89,8 @@
 		bool vertexShaderDirty;

 		unsigned int vertexShaderConstantsFDirty;

 

-		float pixelShaderConstantF[224][4];

-		float vertexShaderConstantF[256][4];

+		float pixelShaderConstantF[FRAGMENT_UNIFORM_VECTORS][4];

+		float vertexShaderConstantF[VERTEX_UNIFORM_VECTORS][4];

 

 		Image *renderTarget;

 		Image *depthStencil;

diff --git a/src/OpenGL/libGLESv2/Context.cpp b/src/OpenGL/libGLESv2/Context.cpp
index 0fdb24a..34e5ee3 100644
--- a/src/OpenGL/libGLESv2/Context.cpp
+++ b/src/OpenGL/libGLESv2/Context.cpp
@@ -1587,21 +1587,21 @@
 		UNIMPLEMENTED();

 		*params = IMPLEMENTATION_MAX_COLOR_ATTACHMENTS;

 		break;

-	case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS: // integer, at least 1

+	case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS: // integer, at least 50048

 		UNIMPLEMENTED();

-		*params = 1;

+		*params = MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS;

 		break;

 	case GL_MAX_COMBINED_UNIFORM_BLOCKS: // integer, at least 70

 		UNIMPLEMENTED();

 		*params = 70;

 		break;

-	case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS: // integer, at least 1

+	case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS: // integer, at least 50176

 		UNIMPLEMENTED();

-		*params = 1;

+		*params = MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS;

 		break;

 	case GL_MAX_DRAW_BUFFERS: // integer, at least 8

 		UNIMPLEMENTED();

-		*params = 8;

+		*params = IMPLEMENTATION_MAX_DRAW_BUFFERS;

 		break;

 	case GL_MAX_ELEMENT_INDEX: // integer, at least 16777215

 		UNIMPLEMENTED();

@@ -1645,7 +1645,7 @@
 		break;

 	case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS: // integer, at least 4

 		UNIMPLEMENTED();

-		*params = 4;

+		*params = IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS;

 		break;

 	case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS: // integer, at least 4

 		UNIMPLEMENTED();

@@ -1657,7 +1657,7 @@
 		break;

 	case GL_MAX_UNIFORM_BUFFER_BINDINGS: // integer, at least 36

 		UNIMPLEMENTED();

-		*params = 36;

+		*params = IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS;

 		break;

 	case GL_MAX_VARYING_COMPONENTS: // integer, at least 60

 		UNIMPLEMENTED();

@@ -1729,7 +1729,7 @@
 		break;

 	case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT: // integer, defaults to 1

 		UNIMPLEMENTED();

-		*params = 1;

+		*params = IMPLEMENTATION_UNIFORM_BUFFER_OFFSET_ALIGNMENT;

 		break;

 	case GL_UNIFORM_BUFFER_SIZE: // indexed[n] 64-bit integer, initially 0

 		UNIMPLEMENTED();

diff --git a/src/OpenGL/libGLESv2/Context.h b/src/OpenGL/libGLESv2/Context.h
index 3a7801e..5a3af6e 100644
--- a/src/OpenGL/libGLESv2/Context.h
+++ b/src/OpenGL/libGLESv2/Context.h
@@ -70,12 +70,12 @@
 {

     MAX_VERTEX_ATTRIBS = 16,

 	MAX_UNIFORM_VECTORS = 256,   // Device limit

-    MAX_VERTEX_UNIFORM_VECTORS = 256 - 3,   // Reserve space for gl_DepthRange

+    MAX_VERTEX_UNIFORM_VECTORS = VERTEX_UNIFORM_VECTORS - 3,   // Reserve space for gl_DepthRange

     MAX_VARYING_VECTORS = 10,

-    MAX_TEXTURE_IMAGE_UNITS = 16,

-    MAX_VERTEX_TEXTURE_IMAGE_UNITS = 4,

+    MAX_TEXTURE_IMAGE_UNITS = TEXTURE_IMAGE_UNITS,

+    MAX_VERTEX_TEXTURE_IMAGE_UNITS = VERTEX_TEXTURE_IMAGE_UNITS,

     MAX_COMBINED_TEXTURE_IMAGE_UNITS = MAX_TEXTURE_IMAGE_UNITS + MAX_VERTEX_TEXTURE_IMAGE_UNITS,

-    MAX_FRAGMENT_UNIFORM_VECTORS = 224 - 3,    // Reserve space for gl_DepthRange

+    MAX_FRAGMENT_UNIFORM_VECTORS = FRAGMENT_UNIFORM_VECTORS - 3,    // Reserve space for gl_DepthRange

     MAX_DRAW_BUFFERS = 1,

 };

 

diff --git a/src/OpenGL/libGLESv2/Device.cpp b/src/OpenGL/libGLESv2/Device.cpp
index e9d8fbe..0f5f7b9 100644
--- a/src/OpenGL/libGLESv2/Device.cpp
+++ b/src/OpenGL/libGLESv2/Device.cpp
@@ -406,7 +406,7 @@
 

 	void Device::setPixelShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count)

 	{

-		for(unsigned int i = 0; i < count && startRegister + i < 224; i++)

+		for(unsigned int i = 0; i < count && startRegister + i < FRAGMENT_UNIFORM_VECTORS; i++)

 		{

 			pixelShaderConstantF[startRegister + i][0] = constantData[i * 4 + 0];

 			pixelShaderConstantF[startRegister + i][1] = constantData[i * 4 + 1];

@@ -453,7 +453,7 @@
 

 	void Device::setVertexShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count)

 	{

-		for(unsigned int i = 0; i < count && startRegister + i < 256; i++)

+		for(unsigned int i = 0; i < count && startRegister + i < VERTEX_UNIFORM_VECTORS; i++)

 		{

 			vertexShaderConstantF[startRegister + i][0] = constantData[i * 4 + 0];

 			vertexShaderConstantF[startRegister + i][1] = constantData[i * 4 + 1];

diff --git a/src/OpenGL/libGLESv2/Device.hpp b/src/OpenGL/libGLESv2/Device.hpp
index cbdb8bb..cc3ea10 100644
--- a/src/OpenGL/libGLESv2/Device.hpp
+++ b/src/OpenGL/libGLESv2/Device.hpp
@@ -95,8 +95,8 @@
 		bool vertexShaderDirty;

 		unsigned int vertexShaderConstantsFDirty;

 

-		float pixelShaderConstantF[224][4];

-		float vertexShaderConstantF[256][4];

+		float pixelShaderConstantF[FRAGMENT_UNIFORM_VECTORS][4];

+		float vertexShaderConstantF[VERTEX_UNIFORM_VECTORS][4];

 

 		egl::Image *renderTarget;

 		egl::Image *depthStencil;

diff --git a/src/OpenGL/libGLESv2/Texture.h b/src/OpenGL/libGLESv2/Texture.h
index f0e41d5..cfe70dc 100644
--- a/src/OpenGL/libGLESv2/Texture.h
+++ b/src/OpenGL/libGLESv2/Texture.h
@@ -47,6 +47,8 @@
 	IMPLEMENTATION_MAX_COLOR_ATTACHMENTS = 8,

 	IMPLEMENTATION_MAX_DRAW_BUFFERS = 8,

 	IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS = 4,

+	IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS = 36,

+	IMPLEMENTATION_UNIFORM_BUFFER_OFFSET_ALIGNMENT = 1,

 };

 

 class Texture : public egl::Texture

diff --git a/src/Radiance/libRAD/Device.cpp b/src/Radiance/libRAD/Device.cpp
index 60f3b94..1692f00 100644
--- a/src/Radiance/libRAD/Device.cpp
+++ b/src/Radiance/libRAD/Device.cpp
@@ -406,7 +406,7 @@
 

 	void Device::setPixelShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count)

 	{

-		for(unsigned int i = 0; i < count && startRegister + i < 224; i++)

+		for(unsigned int i = 0; i < count && startRegister + i < FRAGMENT_UNIFORM_VECTORS; i++)

 		{

 			pixelShaderConstantF[startRegister + i][0] = constantData[i * 4 + 0];

 			pixelShaderConstantF[startRegister + i][1] = constantData[i * 4 + 1];

@@ -453,7 +453,7 @@
 

 	void Device::setVertexShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count)

 	{

-		for(unsigned int i = 0; i < count && startRegister + i < 256; i++)

+		for(unsigned int i = 0; i < count && startRegister + i < VERTEX_UNIFORM_VECTORS; i++)

 		{

 			vertexShaderConstantF[startRegister + i][0] = constantData[i * 4 + 0];

 			vertexShaderConstantF[startRegister + i][1] = constantData[i * 4 + 1];

diff --git a/src/Radiance/libRAD/Device.hpp b/src/Radiance/libRAD/Device.hpp
index 4dbe2e5..68d3064 100644
--- a/src/Radiance/libRAD/Device.hpp
+++ b/src/Radiance/libRAD/Device.hpp
@@ -93,8 +93,8 @@
 		bool vertexShaderDirty;

 		unsigned int vertexShaderConstantsFDirty;

 

-		float pixelShaderConstantF[224][4];

-		float vertexShaderConstantF[256][4];

+		float pixelShaderConstantF[FRAGMENT_UNIFORM_VECTORS][4];

+		float vertexShaderConstantF[VERTEX_UNIFORM_VECTORS][4];

 

 		egl::Image *renderTarget;

 		egl::Image *depthStencil;

diff --git a/src/Renderer/Context.cpp b/src/Renderer/Context.cpp
index 7fd3292..9bff6f6 100644
--- a/src/Renderer/Context.cpp
+++ b/src/Renderer/Context.cpp
@@ -200,7 +200,7 @@
 		}
 
 		// Set vertex streams to null stream
-		for(int i = 0; i < 16; i++)
+		for(int i = 0; i < TEXTURE_IMAGE_UNITS; i++)
 		{
 			input[i].defaults();
 		}
@@ -208,7 +208,7 @@
 		fogStart = 0.0f;
 		fogEnd = 1.0f;
 
-		for(int i = 0; i < 16; i++) textureWrap[i] = 0;
+		for(int i = 0; i < TEXTURE_IMAGE_UNITS; i++) textureWrap[i] = 0;
 		for(int i = 0; i < 8; i++) texGen[i] = TEXGEN_PASSTHRU;
 		for(int i = 0; i < 8; i++) textureTransformCount[i] = 0;
 		for(int i = 0; i < 8; i++) textureTransformProject[i] = false;
diff --git a/src/Renderer/Context.hpp b/src/Renderer/Context.hpp
index 208b8f3..9ab3e85 100644
--- a/src/Renderer/Context.hpp
+++ b/src/Renderer/Context.hpp
@@ -395,15 +395,15 @@
 		int alphaReference;

 		

 		TextureStage textureStage[8];

-		Sampler sampler[16 + 4];

+		Sampler sampler[TOTAL_IMAGE_UNITS];

 

 		Format renderTargetInternalFormat(int index);

 		int colorWriteActive();

 		int colorWriteActive(int index);

 		bool colorUsed();

 

-		Resource *texture[16 + 4];

-		Stream input[16];

+		Resource *texture[TOTAL_IMAGE_UNITS];

+		Stream input[TEXTURE_IMAGE_UNITS];

 		Resource *indexBuffer;

 

 		bool preTransformed;   // FIXME: Private

@@ -414,7 +414,7 @@
 		void computeIllumination();

 

 		bool textureWrapActive;

-		unsigned char textureWrap[16];

+		unsigned char textureWrap[TEXTURE_IMAGE_UNITS];

 		TexGen texGen[8];

 		bool localViewer;

 		bool normalizeNormals;

diff --git a/src/Renderer/PixelProcessor.cpp b/src/Renderer/PixelProcessor.cpp
index 132f692..cae5f4d 100644
--- a/src/Renderer/PixelProcessor.cpp
+++ b/src/Renderer/PixelProcessor.cpp
@@ -327,7 +327,7 @@
 
 	void PixelProcessor::setTextureFilter(unsigned int sampler, FilterType textureFilter)
 	{
-		if(sampler < 16)
+		if(sampler < TEXTURE_IMAGE_UNITS)
 		{
 			context->sampler[sampler].setTextureFilter(textureFilter);
 		}
@@ -336,7 +336,7 @@
 
 	void PixelProcessor::setMipmapFilter(unsigned int sampler, MipmapType mipmapFilter)
 	{
-		if(sampler < 16)
+		if(sampler < TEXTURE_IMAGE_UNITS)
 		{
 			context->sampler[sampler].setMipmapFilter(mipmapFilter);
 		}
@@ -345,7 +345,7 @@
 
 	void PixelProcessor::setGatherEnable(unsigned int sampler, bool enable)
 	{
-		if(sampler < 16)
+		if(sampler < TEXTURE_IMAGE_UNITS)
 		{
 			context->sampler[sampler].setGatherEnable(enable);
 		}
@@ -354,7 +354,7 @@
 
 	void PixelProcessor::setAddressingModeU(unsigned int sampler, AddressingMode addressMode)
 	{
-		if(sampler < 16)
+		if(sampler < TEXTURE_IMAGE_UNITS)
 		{
 			context->sampler[sampler].setAddressingModeU(addressMode);
 		}
@@ -363,7 +363,7 @@
 
 	void PixelProcessor::setAddressingModeV(unsigned int sampler, AddressingMode addressMode)
 	{
-		if(sampler < 16)
+		if(sampler < TEXTURE_IMAGE_UNITS)
 		{
 			context->sampler[sampler].setAddressingModeV(addressMode);
 		}
@@ -372,7 +372,7 @@
 
 	void PixelProcessor::setAddressingModeW(unsigned int sampler, AddressingMode addressMode)
 	{
-		if(sampler < 16)
+		if(sampler < TEXTURE_IMAGE_UNITS)
 		{
 			context->sampler[sampler].setAddressingModeW(addressMode);
 		}
@@ -381,7 +381,7 @@
 
 	void PixelProcessor::setReadSRGB(unsigned int sampler, bool sRGB)
 	{
-		if(sampler < 16)
+		if(sampler < TEXTURE_IMAGE_UNITS)
 		{
 			context->sampler[sampler].setReadSRGB(sRGB);
 		}
@@ -390,7 +390,7 @@
 
 	void PixelProcessor::setMipmapLOD(unsigned int sampler, float bias)
 	{
-		if(sampler < 16)
+		if(sampler < TEXTURE_IMAGE_UNITS)
 		{
 			context->sampler[sampler].setMipmapLOD(bias);
 		}
@@ -399,7 +399,7 @@
 
 	void PixelProcessor::setBorderColor(unsigned int sampler, const Color<float> &borderColor)
 	{
-		if(sampler < 16)
+		if(sampler < TEXTURE_IMAGE_UNITS)
 		{
 			context->sampler[sampler].setBorderColor(borderColor);
 		}
@@ -408,7 +408,7 @@
 
 	void PixelProcessor::setMaxAnisotropy(unsigned int sampler, float maxAnisotropy)
 	{
-		if(sampler < 16)
+		if(sampler < TEXTURE_IMAGE_UNITS)
 		{
 			context->sampler[sampler].setMaxAnisotropy(maxAnisotropy);
 		}
diff --git a/src/Renderer/PixelProcessor.hpp b/src/Renderer/PixelProcessor.hpp
index d68d051..2c8a2f6 100644
--- a/src/Renderer/PixelProcessor.hpp
+++ b/src/Renderer/PixelProcessor.hpp
@@ -80,7 +80,7 @@
 			TransparencyAntialiasing transparencyAntialiasing : BITS(TRANSPARENCY_LAST);

 			bool centroid                                     : 1;

 

-			Sampler::State sampler[16];

+			Sampler::State sampler[TEXTURE_IMAGE_UNITS];

 			TextureStage::State textureStage[8];

 

 			struct Interpolant

@@ -287,7 +287,7 @@
 

 		// Shader constants

 		word4 cW[8][4];

-		float4 c[224];

+		float4 c[FRAGMENT_UNIFORM_VECTORS];

 		int4 i[16];

 		bool b[16];

 

diff --git a/src/Renderer/Renderer.cpp b/src/Renderer/Renderer.cpp
index 1cc97d8..3fd13bb 100644
--- a/src/Renderer/Renderer.cpp
+++ b/src/Renderer/Renderer.cpp
@@ -341,12 +341,12 @@
 
 			draw->indexBuffer = context->indexBuffer;
 
-			for(int sampler = 0; sampler < 20; sampler++)
+			for(int sampler = 0; sampler < TOTAL_IMAGE_UNITS; sampler++)
 			{
 				draw->texture[sampler] = 0;
 			}
 
-			for(int sampler = 0; sampler < 16; sampler++)
+			for(int sampler = 0; sampler < TEXTURE_IMAGE_UNITS; sampler++)
 			{
 				if(pixelState.sampler[sampler].textureType != TEXTURE_NULL)
 				{
@@ -395,14 +395,14 @@
 			{
 				if(context->vertexShader->getVersion() >= 0x0300)
 				{
-					for(int sampler = 0; sampler < 4; sampler++)
+					for(int sampler = 0; sampler < VERTEX_TEXTURE_IMAGE_UNITS; sampler++)
 					{
 						if(vertexState.samplerState[sampler].textureType != TEXTURE_NULL)
 						{
-							draw->texture[16 + sampler] = context->texture[16 + sampler];
-							draw->texture[16 + sampler]->lock(PUBLIC, PRIVATE);
+							draw->texture[TEXTURE_IMAGE_UNITS + sampler] = context->texture[TEXTURE_IMAGE_UNITS + sampler];
+							draw->texture[TEXTURE_IMAGE_UNITS + sampler]->lock(PUBLIC, PRIVATE);
 
-							data->mipmap[16 + sampler] = context->sampler[16 + sampler].getTextureData();
+							data->mipmap[TEXTURE_IMAGE_UNITS + sampler] = context->sampler[TEXTURE_IMAGE_UNITS + sampler].getTextureData();
 						}
 					}
 				}
@@ -913,7 +913,7 @@
 					draw.depthStencil->unlockStencil();
 				}
 
-				for(int i = 0; i < 16 + 4; i++)
+				for(int i = 0; i < TOTAL_IMAGE_UNITS; i++)
 				{
 					if(draw.texture[i])
 					{
@@ -921,7 +921,7 @@
 					}
 				}
 
-				for(int i = 0; i < 16; i++)
+				for(int i = 0; i < TEXTURE_IMAGE_UNITS; i++)
 				{
 					if(draw.vertexStream[i])
 					{
@@ -2085,14 +2085,14 @@
 
 	void Renderer::setTextureResource(unsigned int sampler, Resource *resource)
 	{
-		ASSERT(sampler < (16 + 4));
+		ASSERT(sampler < TOTAL_IMAGE_UNITS);
 
 		context->texture[sampler] = resource;
 	}
 
 	void Renderer::setTextureLevel(unsigned int sampler, unsigned int face, unsigned int level, Surface *surface, TextureType type)
 	{
-		ASSERT(sampler < (16 + 4) && face < 6 && level < MIPMAP_LEVELS);
+		ASSERT(sampler < TOTAL_IMAGE_UNITS && face < 6 && level < MIPMAP_LEVELS);
 		
 		context->sampler[sampler].setTextureLevel(face, level, surface, type);
 	}
diff --git a/src/Renderer/Renderer.hpp b/src/Renderer/Renderer.hpp
index 3408ab5..6fbbfa9 100644
--- a/src/Renderer/Renderer.hpp
+++ b/src/Renderer/Renderer.hpp
@@ -82,9 +82,9 @@
 	{
 		const void *constants;
 
-		const void *input[16];
-		unsigned int stride[16];
-		Texture mipmap[16 + 4];
+		const void *input[TEXTURE_IMAGE_UNITS];
+		unsigned int stride[TEXTURE_IMAGE_UNITS];
+		Texture mipmap[TOTAL_IMAGE_UNITS];
 		const void *indices;
 
 		struct VS
@@ -97,7 +97,7 @@
 		struct PS
 		{
 			word4 cW[8][4];
-			float4 c[224];
+			float4 c[FRAGMENT_UNIFORM_VECTORS];
 			int4 i[16];
 			bool b[16];
 		};
@@ -180,11 +180,11 @@
 		int (*setupPrimitives)(Renderer *renderer, int batch, int count);
 		SetupProcessor::State setupState;
 
-		Resource *vertexStream[16];
+		Resource *vertexStream[TEXTURE_IMAGE_UNITS];
 		Resource *indexBuffer;
 		Surface *renderTarget[4];
 		Surface *depthStencil;
-		Resource *texture[16 + 4];
+		Resource *texture[TOTAL_IMAGE_UNITS];
 
 		int vsDirtyConstF;
 		int vsDirtyConstI;
diff --git a/src/Renderer/VertexProcessor.cpp b/src/Renderer/VertexProcessor.cpp
index 46518fe..b4500a5 100644
--- a/src/Renderer/VertexProcessor.cpp
+++ b/src/Renderer/VertexProcessor.cpp
@@ -116,7 +116,7 @@
 
 	void VertexProcessor::resetInputStreams(bool preTransformed)
 	{
-		for(int i = 0; i < 16; i++)
+		for(int i = 0; i < TEXTURE_IMAGE_UNITS; i++)
 		{
 			context->input[i].defaults();
 		}
@@ -400,7 +400,7 @@
 
 	void VertexProcessor::setTextureWrap(unsigned int stage, int mask)
 	{
-		if(stage < 16)
+		if(stage < TEXTURE_IMAGE_UNITS)
 		{
 			context->textureWrap[stage] = mask;
 		}
@@ -408,7 +408,7 @@
 
 		context->textureWrapActive = false;
 
-		for(int i = 0; i < 16; i++)
+		for(int i = 0; i < TEXTURE_IMAGE_UNITS; i++)
 		{
 			context->textureWrapActive |= (context->textureWrap[i] != 0x00);
 		}
@@ -452,90 +452,90 @@
 
 	void VertexProcessor::setTextureFilter(unsigned int sampler, FilterType textureFilter)
 	{
-		if(sampler < 4)
+		if(sampler < VERTEX_TEXTURE_IMAGE_UNITS)
 		{
-			context->sampler[16 + sampler].setTextureFilter(textureFilter);
+			context->sampler[TEXTURE_IMAGE_UNITS + sampler].setTextureFilter(textureFilter);
 		}
 		else ASSERT(false);
 	}
 
 	void VertexProcessor::setMipmapFilter(unsigned int sampler, MipmapType mipmapFilter)
 	{
-		if(sampler < 4)
+		if(sampler < VERTEX_TEXTURE_IMAGE_UNITS)
 		{
-			context->sampler[16 + sampler].setMipmapFilter(mipmapFilter);
+			context->sampler[TEXTURE_IMAGE_UNITS + sampler].setMipmapFilter(mipmapFilter);
 		}
 		else ASSERT(false);
 	}
 
 	void VertexProcessor::setGatherEnable(unsigned int sampler, bool enable)
 	{
-		if(sampler < 4)
+		if(sampler < VERTEX_TEXTURE_IMAGE_UNITS)
 		{
-			context->sampler[16 + sampler].setGatherEnable(enable);
+			context->sampler[TEXTURE_IMAGE_UNITS + sampler].setGatherEnable(enable);
 		}
 		else ASSERT(false);
 	}
 
 	void VertexProcessor::setAddressingModeU(unsigned int sampler, AddressingMode addressMode)
 	{
-		if(sampler < 4)
+		if(sampler < VERTEX_TEXTURE_IMAGE_UNITS)
 		{
-			context->sampler[16 + sampler].setAddressingModeU(addressMode);
+			context->sampler[TEXTURE_IMAGE_UNITS + sampler].setAddressingModeU(addressMode);
 		}
 		else ASSERT(false);
 	}
 
 	void VertexProcessor::setAddressingModeV(unsigned int sampler, AddressingMode addressMode)
 	{
-		if(sampler < 4)
+		if(sampler < VERTEX_TEXTURE_IMAGE_UNITS)
 		{
-			context->sampler[16 + sampler].setAddressingModeV(addressMode);
+			context->sampler[TEXTURE_IMAGE_UNITS + sampler].setAddressingModeV(addressMode);
 		}
 		else ASSERT(false);
 	}
 
 	void VertexProcessor::setAddressingModeW(unsigned int sampler, AddressingMode addressMode)
 	{
-		if(sampler < 4)
+		if(sampler < VERTEX_TEXTURE_IMAGE_UNITS)
 		{
-			context->sampler[16 + sampler].setAddressingModeW(addressMode);
+			context->sampler[TEXTURE_IMAGE_UNITS + sampler].setAddressingModeW(addressMode);
 		}
 		else ASSERT(false);
 	}
 
 	void VertexProcessor::setReadSRGB(unsigned int sampler, bool sRGB)
 	{
-		if(sampler < 4)
+		if(sampler < VERTEX_TEXTURE_IMAGE_UNITS)
 		{
-			context->sampler[16 + sampler].setReadSRGB(sRGB);
+			context->sampler[TEXTURE_IMAGE_UNITS + sampler].setReadSRGB(sRGB);
 		}
 		else ASSERT(false);
 	}
 
 	void VertexProcessor::setMipmapLOD(unsigned int sampler, float bias)
 	{
-		if(sampler < 4)
+		if(sampler < VERTEX_TEXTURE_IMAGE_UNITS)
 		{
-			context->sampler[16 + sampler].setMipmapLOD(bias);
+			context->sampler[TEXTURE_IMAGE_UNITS + sampler].setMipmapLOD(bias);
 		}
 		else ASSERT(false);
 	}
 
 	void VertexProcessor::setBorderColor(unsigned int sampler, const Color<float> &borderColor)
 	{
-		if(sampler < 4)
+		if(sampler < VERTEX_TEXTURE_IMAGE_UNITS)
 		{
-			context->sampler[16 + sampler].setBorderColor(borderColor);
+			context->sampler[TEXTURE_IMAGE_UNITS + sampler].setBorderColor(borderColor);
 		}
 		else ASSERT(false);
 	}
 
 	void VertexProcessor::setMaxAnisotropy(unsigned int sampler, float maxAnisotropy)
 	{
-		if(sampler < 4)
+		if(sampler < VERTEX_TEXTURE_IMAGE_UNITS)
 		{
-			context->sampler[16 + sampler].setMaxAnisotropy(maxAnisotropy);
+			context->sampler[TEXTURE_IMAGE_UNITS + sampler].setMaxAnisotropy(maxAnisotropy);
 		}
 		else ASSERT(false);
 	}
@@ -801,7 +801,7 @@
 		state.superSampling = context->getSuperSampleCount() > 1;
 		state.multiSampling = context->getMultiSampleCount() > 1;
 
-		for(int i = 0; i < 16; i++)
+		for(int i = 0; i < TEXTURE_IMAGE_UNITS; i++)
 		{
 			state.input[i].type = context->input[i].type;
 			state.input[i].count = context->input[i].count;
@@ -820,11 +820,11 @@
 		}
 		else
 		{
-			for(unsigned int i = 0; i < 4; i++)
+			for(unsigned int i = 0; i < VERTEX_TEXTURE_IMAGE_UNITS; i++)
 			{
 				if(context->vertexShader->usesSampler(i))
 				{
-					state.samplerState[i] = context->sampler[16 + i].samplerState();
+					state.samplerState[i] = context->sampler[TEXTURE_IMAGE_UNITS + i].samplerState();
 				}
 			}
 		}
diff --git a/src/Renderer/VertexProcessor.hpp b/src/Renderer/VertexProcessor.hpp
index 4f665af..04d7ade 100644
--- a/src/Renderer/VertexProcessor.hpp
+++ b/src/Renderer/VertexProcessor.hpp
@@ -83,7 +83,7 @@
 

 			TextureState textureState[8];

 

-			Sampler::State samplerState[4];

+			Sampler::State samplerState[VERTEX_TEXTURE_IMAGE_UNITS];

 

 			struct Input

 			{

@@ -126,7 +126,7 @@
 				};

 			};

 

-			Input input[16];

+			Input input[TEXTURE_IMAGE_UNITS];

 			Output output[12];

 		};

 

diff --git a/src/Shader/PixelRoutine.cpp b/src/Shader/PixelRoutine.cpp
index 45b614f..7c0f931 100644
--- a/src/Shader/PixelRoutine.cpp
+++ b/src/Shader/PixelRoutine.cpp
@@ -53,7 +53,7 @@
 
 	PixelRoutine::~PixelRoutine()
 	{
-		for(int i = 0; i < 16; i++)
+		for(int i = 0; i < TEXTURE_IMAGE_UNITS; i++)
 		{
 			delete sampler[i];
 		}
@@ -65,7 +65,7 @@
 			Long pipeTime = Ticks();
 		#endif
 
-		for(int i = 0; i < 16; i++)
+		for(int i = 0; i < TEXTURE_IMAGE_UNITS; i++)
 		{
 			sampler[i] = new SamplerCore(r.constants, state.sampler[i]);
 		}
@@ -2078,7 +2078,7 @@
 		{
 			Int index = As<Int>(Float(reg(r, sampler).x.x));
 
-			for(int i = 0; i < 16; i++)
+			for(int i = 0; i < TEXTURE_IMAGE_UNITS; i++)
 			{
 				if(shader->usesSampler(i))
 				{
diff --git a/src/Shader/PixelRoutine.hpp b/src/Shader/PixelRoutine.hpp
index e6dd8fb..8e89b09 100644
--- a/src/Shader/PixelRoutine.hpp
+++ b/src/Shader/PixelRoutine.hpp
@@ -296,7 +296,7 @@
 		const PixelShader *const shader;
 
 	private:
-		SamplerCore *sampler[16];
+		SamplerCore *sampler[TEXTURE_IMAGE_UNITS];
 
 		bool perturbate;
 		bool luminance;
diff --git a/src/Shader/VertexProgram.cpp b/src/Shader/VertexProgram.cpp
index a12083f..7cd1daa 100644
--- a/src/Shader/VertexProgram.cpp
+++ b/src/Shader/VertexProgram.cpp
@@ -38,7 +38,7 @@
 
 	VertexProgram::~VertexProgram()
 	{
-		for(int i = 0; i < 4; i++)
+		for(int i = 0; i < VERTEX_TEXTURE_IMAGE_UNITS; i++)
 		{
 			delete sampler[i];
 		}
@@ -46,7 +46,7 @@
 
 	void VertexProgram::pipeline(Registers &r)
 	{
-		for(int i = 0; i < 4; i++)
+		for(int i = 0; i < VERTEX_TEXTURE_IMAGE_UNITS; i++)
 		{
 			sampler[i] = new SamplerCore(r.constants, state.samplerState[i]);
 		}
diff --git a/src/Shader/VertexProgram.hpp b/src/Shader/VertexProgram.hpp
index 902cf75..097f90c 100644
--- a/src/Shader/VertexProgram.hpp
+++ b/src/Shader/VertexProgram.hpp
@@ -82,7 +82,7 @@
 
 		void sampleTexture(Registers &r, Vector4f &c, const Src &s, Float4 &u, Float4 &v, Float4 &w, Float4 &q);
 
-		SamplerCore *sampler[4];
+		SamplerCore *sampler[VERTEX_TEXTURE_IMAGE_UNITS];
 
 		int ifDepth;
 		int loopRepDepth;
diff --git a/src/Shader/VertexRoutine.cpp b/src/Shader/VertexRoutine.cpp
index f8d9e11..94bbdeb 100644
--- a/src/Shader/VertexRoutine.cpp
+++ b/src/Shader/VertexRoutine.cpp
@@ -95,7 +95,7 @@
 
 	void VertexRoutine::readInput(Registers &r, UInt &index)
 	{
-		for(int i = 0; i < 16; i++)
+		for(int i = 0; i < TEXTURE_IMAGE_UNITS; i++)
 		{
 			Pointer<Byte> input = *Pointer<Pointer<Byte> >(r.data + OFFSET(DrawData,input) + sizeof(void*) * i);
 			UInt stride = *Pointer<UInt>(r.data + OFFSET(DrawData,stride) + sizeof(unsigned int) * i);