texelFetch implementation

Passes all texelFetch and texelFetchOffset tests in dEQP.

Change-Id: Ic212d326d1c062f1947696e6963fef300b7737f1
Reviewed-on: https://swiftshader-review.googlesource.com/5512
Tested-by: Meng-Lin Wu <marleymoo@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/Renderer/Sampler.cpp b/src/Renderer/Sampler.cpp
index 93cca30..c6cec5e 100644
--- a/src/Renderer/Sampler.cpp
+++ b/src/Renderer/Sampler.cpp
@@ -76,8 +76,8 @@
 
 		texture.baseLevel = 0;
 		texture.maxLevel = 1000;
-		texture.maxLod = 1000;
-		texture.minLod = -1000;
+		texture.maxLod = MIPMAP_LEVELS - 2;	// Trilinear accesses lod+1
+		texture.minLod = 0;
 	}
 
 	Sampler::~Sampler()
@@ -351,12 +351,12 @@
 
 	void Sampler::setMinLod(float minLod)
 	{
-		texture.minLod = minLod;
+		texture.minLod = clamp(minLod, 0.0f, (float)(MIPMAP_LEVELS - 2));
 	}
 
 	void Sampler::setMaxLod(float maxLod)
 	{
-		texture.maxLod = maxLod;
+		texture.maxLod = clamp(maxLod, 0.0f, (float)(MIPMAP_LEVELS - 2));
 	}
 
 	void Sampler::setFilterQuality(FilterType maximumFilterQuality)