Backed out using pixel texture coordinates, it had weird visual side effects
authorSam Lantinga <slouken@libsdl.org>
Sat, 09 Dec 2017 19:48:38 -0800
changeset 11755e9a1b9ea8da0
parent 11754 09f7bead4e7c
child 11756 2f67d059ac64
Backed out using pixel texture coordinates, it had weird visual side effects
src/render/metal/SDL_render_metal.m
src/render/metal/SDL_shaders_metal.metal
src/render/metal/SDL_shaders_metal_ios.h
src/render/metal/SDL_shaders_metal_osx.h
     1.1 --- a/src/render/metal/SDL_render_metal.m	Sat Dec 09 19:41:08 2017 -0800
     1.2 +++ b/src/render/metal/SDL_render_metal.m	Sat Dec 09 19:48:38 2017 -0800
     1.3 @@ -597,6 +597,14 @@
     1.4      return (((val - 0.5f) / len) * 2.0f) - 1.0f;
     1.5  }
     1.6  
     1.7 +// normalize a value from 0.0f to len into 0.0f to 1.0f.
     1.8 +static inline float
     1.9 +normtex(const float _val, const float len)
    1.10 +{
    1.11 +    const float val = (_val < 0.0f) ? 0.0f : (_val > len) ? len : _val;
    1.12 +    return ((val + 0.5f) / len);
    1.13 +}
    1.14 +
    1.15  static int
    1.16  DrawVerts(SDL_Renderer * renderer, const SDL_FPoint * points, int count,
    1.17            const MTLPrimitiveType primtype)
    1.18 @@ -700,11 +708,11 @@
    1.19      };
    1.20  
    1.21      const float uv[] = {
    1.22 -        srcrect->x, srcrect->y + srcrect->h,
    1.23 -        srcrect->x, srcrect->y,
    1.24 -        srcrect->x + srcrect->w, srcrect->y,
    1.25 -        srcrect->x, srcrect->y + srcrect->h,
    1.26 -        srcrect->x + srcrect->w, srcrect->y + srcrect->h
    1.27 +        normtex(srcrect->x, texw), normtex(srcrect->y + srcrect->h, texh),
    1.28 +        normtex(srcrect->x, texw), normtex(srcrect->y, texh),
    1.29 +        normtex(srcrect->x + srcrect->w, texw), normtex(srcrect->y, texh),
    1.30 +        normtex(srcrect->x, texw), normtex(srcrect->y + srcrect->h, texh),
    1.31 +        normtex(srcrect->x + srcrect->w, texw), normtex(srcrect->y + srcrect->h, texh)
    1.32      };
    1.33  
    1.34      float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
     2.1 --- a/src/render/metal/SDL_shaders_metal.metal	Sat Dec 09 19:41:08 2017 -0800
     2.2 +++ b/src/render/metal/SDL_shaders_metal.metal	Sat Dec 09 19:48:38 2017 -0800
     2.3 @@ -37,13 +37,13 @@
     2.4  
     2.5  fragment float4 SDL_Copy_fragment_nearest(CopyVertex vert [[stage_in]], constant float4 &col [[buffer(0)]], texture2d<float> tex [[texture(0)]])
     2.6  {
     2.7 -    constexpr sampler s(coord::pixel, address::clamp_to_edge, filter::nearest);
     2.8 +    constexpr sampler s(coord::normalized, address::clamp_to_edge, filter::nearest);
     2.9      return tex.sample(s, vert.texcoord) * col;
    2.10  }
    2.11  
    2.12  fragment float4 SDL_Copy_fragment_linear(CopyVertex vert [[stage_in]], constant float4 &col [[buffer(0)]], texture2d<float> tex [[texture(0)]])
    2.13  {
    2.14 -    constexpr sampler s(coord::pixel, address::clamp_to_edge, filter::linear);
    2.15 +    constexpr sampler s(coord::normalized, address::clamp_to_edge, filter::linear);
    2.16      return tex.sample(s, vert.texcoord) * col;
    2.17  }
    2.18  
     3.1 --- a/src/render/metal/SDL_shaders_metal_ios.h	Sat Dec 09 19:41:08 2017 -0800
     3.2 +++ b/src/render/metal/SDL_shaders_metal_ios.h	Sat Dec 09 19:48:38 2017 -0800
     3.3 @@ -40,10 +40,10 @@
     3.4    0x00, 0x4e, 0x41, 0x4d, 0x45, 0x1a, 0x00, 0x53, 0x44, 0x4c, 0x5f, 0x43,
     3.5    0x6f, 0x70, 0x79, 0x5f, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74,
     3.6    0x5f, 0x6e, 0x65, 0x61, 0x72, 0x65, 0x73, 0x74, 0x00, 0x54, 0x59, 0x50,
     3.7 -  0x45, 0x01, 0x00, 0x01, 0x48, 0x41, 0x53, 0x48, 0x20, 0x00, 0xef, 0x6a,
     3.8 -  0x0f, 0x39, 0xf2, 0x56, 0x54, 0x13, 0xc0, 0x2c, 0xd2, 0x94, 0x21, 0x23,
     3.9 -  0xea, 0x5f, 0xdf, 0xcd, 0x64, 0x3a, 0x6a, 0xb0, 0xc2, 0x01, 0xed, 0xe9,
    3.10 -  0xbc, 0xfe, 0xdc, 0xc7, 0x4e, 0x78, 0x4f, 0x46, 0x46, 0x54, 0x18, 0x00,
    3.11 +  0x45, 0x01, 0x00, 0x01, 0x48, 0x41, 0x53, 0x48, 0x20, 0x00, 0x91, 0xe7,
    3.12 +  0x15, 0xc9, 0xbd, 0x36, 0x0d, 0x0b, 0x4c, 0x9f, 0x3f, 0xc3, 0x30, 0x30,
    3.13 +  0x16, 0xf2, 0x81, 0xff, 0x84, 0x2d, 0x09, 0x96, 0x37, 0xc5, 0x87, 0x01,
    3.14 +  0xf5, 0xa7, 0x03, 0x13, 0x3c, 0x1a, 0x4f, 0x46, 0x46, 0x54, 0x18, 0x00,
    3.15    0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
    3.16    0x00, 0x00, 0x00, 0x00, 0x50, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    3.17    0x56, 0x45, 0x52, 0x53, 0x08, 0x00, 0x01, 0x00, 0x08, 0x00, 0x01, 0x00,
    3.18 @@ -51,10 +51,10 @@
    3.19    0x4d, 0x45, 0x19, 0x00, 0x53, 0x44, 0x4c, 0x5f, 0x43, 0x6f, 0x70, 0x79,
    3.20    0x5f, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x6c, 0x69,
    3.21    0x6e, 0x65, 0x61, 0x72, 0x00, 0x54, 0x59, 0x50, 0x45, 0x01, 0x00, 0x01,
    3.22 -  0x48, 0x41, 0x53, 0x48, 0x20, 0x00, 0xd3, 0xa8, 0x76, 0x2b, 0x4d, 0x23,
    3.23 -  0xcc, 0x19, 0xd8, 0xd7, 0x8f, 0xbc, 0x91, 0xdd, 0x2f, 0x81, 0xdc, 0x04,
    3.24 -  0x66, 0x9e, 0xcc, 0x76, 0x01, 0xad, 0xb7, 0xff, 0xed, 0x0f, 0x01, 0x67,
    3.25 -  0xdc, 0x5d, 0x4f, 0x46, 0x46, 0x54, 0x18, 0x00, 0x20, 0x00, 0x00, 0x00,
    3.26 +  0x48, 0x41, 0x53, 0x48, 0x20, 0x00, 0x19, 0xe0, 0xf9, 0x60, 0xfe, 0xee,
    3.27 +  0xd6, 0xfe, 0xf4, 0x5e, 0x73, 0xda, 0xd6, 0xd4, 0x16, 0x65, 0x96, 0x45,
    3.28 +  0xf2, 0xbe, 0x64, 0x8f, 0x7b, 0x82, 0xa6, 0x1a, 0xc1, 0xc7, 0xfc, 0xfa,
    3.29 +  0x34, 0x02, 0x4f, 0x46, 0x46, 0x54, 0x18, 0x00, 0x20, 0x00, 0x00, 0x00,
    3.30    0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    3.31    0xa0, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x45, 0x52, 0x53,
    3.32    0x08, 0x00, 0x01, 0x00, 0x08, 0x00, 0x01, 0x00, 0x01, 0x00, 0x45, 0x4e,
    3.33 @@ -862,7 +862,7 @@
    3.34    0xc4, 0x3f, 0x11, 0xd7, 0x44, 0x45, 0xc4, 0x6f, 0x0f, 0x7e, 0x85, 0x17,
    3.35    0xb7, 0x0d, 0x61, 0x20, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x04,
    3.36    0x41, 0x2c, 0x10, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0xeb,
    3.37 -  0xdd, 0x7f, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x80, 0xd8, 0x08,
    3.38 +  0xdd, 0xff, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x80, 0xd8, 0x08,
    3.39    0x00, 0xa9, 0x1a, 0x18, 0x01, 0xa0, 0x64, 0x0a, 0x1b, 0x08, 0x8c, 0x00,
    3.40    0x00, 0x00, 0x23, 0x06, 0x8a, 0x10, 0x48, 0x87, 0x90, 0x10, 0xc5, 0x10,
    3.41    0x50, 0x52, 0x2c, 0x10, 0xe4, 0x93, 0x41, 0x40, 0x0c, 0x00, 0x02, 0x00,
    3.42 @@ -1082,7 +1082,7 @@
    3.43    0xd8, 0x5f, 0x44, 0x80, 0xc1, 0x10, 0xcd, 0xf4, 0x2f, 0x48, 0x43, 0x00,
    3.44    0x11, 0x00, 0x61, 0x20, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x04,
    3.45    0x41, 0x2c, 0x10, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0xeb,
    3.46 -  0xdd, 0x7a, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x80, 0xd8, 0x08,
    3.47 +  0xdd, 0xfa, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x80, 0xd8, 0x08,
    3.48    0x00, 0xa9, 0x1a, 0x18, 0x01, 0xa0, 0x64, 0x0a, 0x1b, 0x08, 0x8c, 0x00,
    3.49    0x00, 0x00, 0x23, 0x06, 0x8a, 0x10, 0x48, 0x87, 0x90, 0x10, 0xc5, 0x10,
    3.50    0x50, 0x52, 0x2c, 0x10, 0xe4, 0x93, 0x41, 0x40, 0x0c, 0x00, 0x02, 0x00,
     4.1 --- a/src/render/metal/SDL_shaders_metal_osx.h	Sat Dec 09 19:41:08 2017 -0800
     4.2 +++ b/src/render/metal/SDL_shaders_metal_osx.h	Sat Dec 09 19:48:38 2017 -0800
     4.3 @@ -40,10 +40,10 @@
     4.4    0x00, 0x4e, 0x41, 0x4d, 0x45, 0x1a, 0x00, 0x53, 0x44, 0x4c, 0x5f, 0x43,
     4.5    0x6f, 0x70, 0x79, 0x5f, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74,
     4.6    0x5f, 0x6e, 0x65, 0x61, 0x72, 0x65, 0x73, 0x74, 0x00, 0x54, 0x59, 0x50,
     4.7 -  0x45, 0x01, 0x00, 0x01, 0x48, 0x41, 0x53, 0x48, 0x20, 0x00, 0x35, 0x04,
     4.8 -  0x75, 0x32, 0xf3, 0x3b, 0x10, 0x7f, 0x21, 0x81, 0xca, 0xf4, 0xe5, 0xda,
     4.9 -  0xbd, 0xa9, 0x01, 0x9c, 0x95, 0xf2, 0xeb, 0xd1, 0x85, 0x5b, 0xb1, 0x88,
    4.10 -  0x08, 0x8b, 0x3e, 0x03, 0xb3, 0xc2, 0x4f, 0x46, 0x46, 0x54, 0x18, 0x00,
    4.11 +  0x45, 0x01, 0x00, 0x01, 0x48, 0x41, 0x53, 0x48, 0x20, 0x00, 0x1a, 0xcd,
    4.12 +  0xc9, 0x51, 0xc4, 0x9c, 0x69, 0x4c, 0x35, 0x81, 0x89, 0x37, 0x6f, 0x90,
    4.13 +  0x27, 0xe8, 0x83, 0x1e, 0x2b, 0x28, 0xc5, 0x03, 0x60, 0xdd, 0x80, 0x89,
    4.14 +  0xe7, 0x3e, 0x21, 0xe0, 0x73, 0xe0, 0x4f, 0x46, 0x46, 0x54, 0x18, 0x00,
    4.15    0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
    4.16    0x00, 0x00, 0x00, 0x00, 0x60, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    4.17    0x56, 0x45, 0x52, 0x53, 0x08, 0x00, 0x01, 0x00, 0x08, 0x00, 0x01, 0x00,
    4.18 @@ -51,10 +51,10 @@
    4.19    0x4d, 0x45, 0x19, 0x00, 0x53, 0x44, 0x4c, 0x5f, 0x43, 0x6f, 0x70, 0x79,
    4.20    0x5f, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x6c, 0x69,
    4.21    0x6e, 0x65, 0x61, 0x72, 0x00, 0x54, 0x59, 0x50, 0x45, 0x01, 0x00, 0x01,
    4.22 -  0x48, 0x41, 0x53, 0x48, 0x20, 0x00, 0x2c, 0xda, 0x9b, 0x1f, 0x12, 0xa6,
    4.23 -  0x94, 0x15, 0xd3, 0x95, 0x98, 0xee, 0x7e, 0x09, 0xd7, 0x54, 0x47, 0xd6,
    4.24 -  0x7c, 0xe0, 0x6d, 0xc0, 0x83, 0xc8, 0x90, 0x9b, 0x8e, 0xb7, 0xc8, 0xb2,
    4.25 -  0xf4, 0xbe, 0x4f, 0x46, 0x46, 0x54, 0x18, 0x00, 0x20, 0x00, 0x00, 0x00,
    4.26 +  0x48, 0x41, 0x53, 0x48, 0x20, 0x00, 0x4e, 0x03, 0xfc, 0x68, 0xd2, 0xb4,
    4.27 +  0xd0, 0x9a, 0xf1, 0x46, 0xed, 0x3f, 0x64, 0x34, 0xae, 0x1b, 0x24, 0x25,
    4.28 +  0x3f, 0xa5, 0x86, 0x18, 0x28, 0xab, 0x3c, 0xf2, 0x2c, 0x7d, 0xce, 0xdf,
    4.29 +  0x93, 0x73, 0x4f, 0x46, 0x46, 0x54, 0x18, 0x00, 0x20, 0x00, 0x00, 0x00,
    4.30    0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    4.31    0xc0, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x45, 0x52, 0x53,
    4.32    0x08, 0x00, 0x01, 0x00, 0x08, 0x00, 0x01, 0x00, 0x01, 0x00, 0x45, 0x4e,
    4.33 @@ -864,7 +864,7 @@
    4.34    0xc4, 0x3f, 0x11, 0xd7, 0x44, 0x45, 0xc4, 0x6f, 0x0f, 0x7e, 0x85, 0x17,
    4.35    0xb7, 0x0d, 0x61, 0x20, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x04,
    4.36    0x41, 0x2c, 0x10, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0xeb,
    4.37 -  0xdd, 0x7f, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x80, 0xd8, 0x08,
    4.38 +  0xdd, 0xff, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x80, 0xd8, 0x08,
    4.39    0x00, 0xa9, 0x1a, 0x18, 0x01, 0xa0, 0x64, 0x0a, 0x1b, 0x08, 0x8c, 0x00,
    4.40    0x00, 0x00, 0x23, 0x06, 0x8a, 0x10, 0x48, 0x87, 0x90, 0x10, 0xc5, 0x10,
    4.41    0x50, 0x52, 0x2c, 0x10, 0xe4, 0x93, 0x41, 0x40, 0x0c, 0x00, 0x02, 0x00,
    4.42 @@ -1085,7 +1085,7 @@
    4.43    0x95, 0x3f, 0xe7, 0x3c, 0xd8, 0x5f, 0x44, 0x80, 0xc1, 0x10, 0xcd, 0xf4,
    4.44    0x2f, 0x48, 0x43, 0x00, 0x11, 0x00, 0x61, 0x20, 0x00, 0x00, 0x13, 0x00,
    4.45    0x00, 0x00, 0x13, 0x04, 0x41, 0x2c, 0x10, 0x00, 0x00, 0x00, 0x07, 0x00,
    4.46 -  0x00, 0x00, 0x04, 0xeb, 0xdd, 0x7a, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff,
    4.47 +  0x00, 0x00, 0x04, 0xeb, 0xdd, 0xfa, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff,
    4.48    0x3f, 0x80, 0xd8, 0x08, 0x00, 0xa9, 0x1a, 0x18, 0x01, 0xa0, 0x64, 0x0a,
    4.49    0x1b, 0x08, 0x8c, 0x00, 0x00, 0x00, 0x23, 0x06, 0x8a, 0x10, 0x48, 0x87,
    4.50    0x90, 0x10, 0xc5, 0x10, 0x50, 0x52, 0x2c, 0x10, 0xe4, 0x93, 0x41, 0x40,