OSDN Git Service

Rectangle texture addressing fix
authorAlexis Hetu <sugoi@google.com>
Tue, 8 May 2018 18:25:40 +0000 (14:25 -0400)
committerAlexis Hétu <sugoi@google.com>
Wed, 9 May 2018 14:05:18 +0000 (14:05 +0000)
Texture rectangle coordinates were clamped in the [0, dim - 1] range,
but should have been sampled in the [0.5, dim - 0.5 range] according
to the spec (a related comment was added in the code).

Also, by having getAddressingModeW() return ADDRESSING_LAYER for
rectangle textures, the 3rd texture coordinate computation will be
skipped entirely, preventing the temporary variable 'fv' from being
overwritten.

Change-Id: I4bbc30b2a2b747eae2f2a1dfb710a986bff7849b
Reviewed-on: https://swiftshader-review.googlesource.com/18768
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
src/Renderer/Sampler.cpp
src/Shader/SamplerCore.cpp

index 85448b9..979079c 100644 (file)
@@ -478,7 +478,8 @@ namespace sw
        {
                if(textureType == TEXTURE_2D_ARRAY ||
                   textureType == TEXTURE_2D ||
-                  textureType == TEXTURE_CUBE)
+                  textureType == TEXTURE_CUBE ||
+                  textureType == TEXTURE_RECTANGLE)
                {
                        return ADDRESSING_LAYER;
                }
index 8fa378f..6ede6f1 100644 (file)
@@ -2370,7 +2370,12 @@ namespace sw
 
                        if(state.textureType == TEXTURE_RECTANGLE)
                        {
-                               coord = Min(Max(coord, Float4(0.0f)), Float4(dim - Int4(1)));
+                               // According to https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_texture_rectangle.txt
+                               // "CLAMP_TO_EDGE causes the s coordinate to be clamped to the range[0.5, wt - 0.5].
+                               //  CLAMP_TO_EDGE causes the t coordinate to be clamped to the range[0.5, ht - 0.5]."
+                               // Unless SwiftShader implements support for ADDRESSING_BORDER, other modes should be equivalent
+                               // to CLAMP_TO_EDGE. Rectangle textures have no support for any MIRROR or REPEAT modes.
+                               coord = Min(Max(coord, Float4(0.5f)), Float4(dim) - Float4(0.5f));
                        }
                        else
                        {