Skip to content
Permalink
Browse files

Backed out using pixel texture coordinates, it had weird visual side …

…effects
  • Loading branch information
slouken committed Dec 10, 2017
1 parent 8aad492 commit c2cc9c166cd3658aebc1a5d97c4cf3e2a185f75c
@@ -597,6 +597,14 @@ static void METAL_ActivateRenderer(SDL_Renderer * renderer)
return (((val - 0.5f) / len) * 2.0f) - 1.0f;
}

// normalize a value from 0.0f to len into 0.0f to 1.0f.
static inline float
normtex(const float _val, const float len)
{
const float val = (_val < 0.0f) ? 0.0f : (_val > len) ? len : _val;
return ((val + 0.5f) / len);
}

static int
DrawVerts(SDL_Renderer * renderer, const SDL_FPoint * points, int count,
const MTLPrimitiveType primtype)
@@ -700,11 +708,11 @@ static void METAL_ActivateRenderer(SDL_Renderer * renderer)
};

const float uv[] = {
srcrect->x, srcrect->y + srcrect->h,
srcrect->x, srcrect->y,
srcrect->x + srcrect->w, srcrect->y,
srcrect->x, srcrect->y + srcrect->h,
srcrect->x + srcrect->w, srcrect->y + srcrect->h
normtex(srcrect->x, texw), normtex(srcrect->y + srcrect->h, texh),
normtex(srcrect->x, texw), normtex(srcrect->y, texh),
normtex(srcrect->x + srcrect->w, texw), normtex(srcrect->y, texh),
normtex(srcrect->x, texw), normtex(srcrect->y + srcrect->h, texh),
normtex(srcrect->x + srcrect->w, texw), normtex(srcrect->y + srcrect->h, texh)
};

float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
@@ -37,13 +37,13 @@ vertex CopyVertex SDL_Copy_vertex(constant float2 *position [[buffer(0)]], const

fragment float4 SDL_Copy_fragment_nearest(CopyVertex vert [[stage_in]], constant float4 &col [[buffer(0)]], texture2d<float> tex [[texture(0)]])
{
constexpr sampler s(coord::pixel, address::clamp_to_edge, filter::nearest);
constexpr sampler s(coord::normalized, address::clamp_to_edge, filter::nearest);
return tex.sample(s, vert.texcoord) * col;
}

fragment float4 SDL_Copy_fragment_linear(CopyVertex vert [[stage_in]], constant float4 &col [[buffer(0)]], texture2d<float> tex [[texture(0)]])
{
constexpr sampler s(coord::pixel, address::clamp_to_edge, filter::linear);
constexpr sampler s(coord::normalized, address::clamp_to_edge, filter::linear);
return tex.sample(s, vert.texcoord) * col;
}

@@ -40,21 +40,21 @@ const unsigned char sdl_metallib[] = {
0x00, 0x4e, 0x41, 0x4d, 0x45, 0x1a, 0x00, 0x53, 0x44, 0x4c, 0x5f, 0x43,
0x6f, 0x70, 0x79, 0x5f, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74,
0x5f, 0x6e, 0x65, 0x61, 0x72, 0x65, 0x73, 0x74, 0x00, 0x54, 0x59, 0x50,
0x45, 0x01, 0x00, 0x01, 0x48, 0x41, 0x53, 0x48, 0x20, 0x00, 0xef, 0x6a,
0x0f, 0x39, 0xf2, 0x56, 0x54, 0x13, 0xc0, 0x2c, 0xd2, 0x94, 0x21, 0x23,
0xea, 0x5f, 0xdf, 0xcd, 0x64, 0x3a, 0x6a, 0xb0, 0xc2, 0x01, 0xed, 0xe9,
0xbc, 0xfe, 0xdc, 0xc7, 0x4e, 0x78, 0x4f, 0x46, 0x46, 0x54, 0x18, 0x00,
0x45, 0x01, 0x00, 0x01, 0x48, 0x41, 0x53, 0x48, 0x20, 0x00, 0x91, 0xe7,
0x15, 0xc9, 0xbd, 0x36, 0x0d, 0x0b, 0x4c, 0x9f, 0x3f, 0xc3, 0x30, 0x30,
0x16, 0xf2, 0x81, 0xff, 0x84, 0x2d, 0x09, 0x96, 0x37, 0xc5, 0x87, 0x01,
0xf5, 0xa7, 0x03, 0x13, 0x3c, 0x1a, 0x4f, 0x46, 0x46, 0x54, 0x18, 0x00,
0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x50, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x56, 0x45, 0x52, 0x53, 0x08, 0x00, 0x01, 0x00, 0x08, 0x00, 0x01, 0x00,
0x01, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x80, 0x00, 0x00, 0x00, 0x4e, 0x41,
0x4d, 0x45, 0x19, 0x00, 0x53, 0x44, 0x4c, 0x5f, 0x43, 0x6f, 0x70, 0x79,
0x5f, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x6c, 0x69,
0x6e, 0x65, 0x61, 0x72, 0x00, 0x54, 0x59, 0x50, 0x45, 0x01, 0x00, 0x01,
0x48, 0x41, 0x53, 0x48, 0x20, 0x00, 0xd3, 0xa8, 0x76, 0x2b, 0x4d, 0x23,
0xcc, 0x19, 0xd8, 0xd7, 0x8f, 0xbc, 0x91, 0xdd, 0x2f, 0x81, 0xdc, 0x04,
0x66, 0x9e, 0xcc, 0x76, 0x01, 0xad, 0xb7, 0xff, 0xed, 0x0f, 0x01, 0x67,
0xdc, 0x5d, 0x4f, 0x46, 0x46, 0x54, 0x18, 0x00, 0x20, 0x00, 0x00, 0x00,
0x48, 0x41, 0x53, 0x48, 0x20, 0x00, 0x19, 0xe0, 0xf9, 0x60, 0xfe, 0xee,
0xd6, 0xfe, 0xf4, 0x5e, 0x73, 0xda, 0xd6, 0xd4, 0x16, 0x65, 0x96, 0x45,
0xf2, 0xbe, 0x64, 0x8f, 0x7b, 0x82, 0xa6, 0x1a, 0xc1, 0xc7, 0xfc, 0xfa,
0x34, 0x02, 0x4f, 0x46, 0x46, 0x54, 0x18, 0x00, 0x20, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xa0, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x45, 0x52, 0x53,
0x08, 0x00, 0x01, 0x00, 0x08, 0x00, 0x01, 0x00, 0x01, 0x00, 0x45, 0x4e,
@@ -862,7 +862,7 @@ const unsigned char sdl_metallib[] = {
0xc4, 0x3f, 0x11, 0xd7, 0x44, 0x45, 0xc4, 0x6f, 0x0f, 0x7e, 0x85, 0x17,
0xb7, 0x0d, 0x61, 0x20, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x04,
0x41, 0x2c, 0x10, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0xeb,
0xdd, 0x7f, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x80, 0xd8, 0x08,
0xdd, 0xff, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x80, 0xd8, 0x08,
0x00, 0xa9, 0x1a, 0x18, 0x01, 0xa0, 0x64, 0x0a, 0x1b, 0x08, 0x8c, 0x00,
0x00, 0x00, 0x23, 0x06, 0x8a, 0x10, 0x48, 0x87, 0x90, 0x10, 0xc5, 0x10,
0x50, 0x52, 0x2c, 0x10, 0xe4, 0x93, 0x41, 0x40, 0x0c, 0x00, 0x02, 0x00,
@@ -1082,7 +1082,7 @@ const unsigned char sdl_metallib[] = {
0xd8, 0x5f, 0x44, 0x80, 0xc1, 0x10, 0xcd, 0xf4, 0x2f, 0x48, 0x43, 0x00,
0x11, 0x00, 0x61, 0x20, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x04,
0x41, 0x2c, 0x10, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0xeb,
0xdd, 0x7a, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x80, 0xd8, 0x08,
0xdd, 0xfa, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x80, 0xd8, 0x08,
0x00, 0xa9, 0x1a, 0x18, 0x01, 0xa0, 0x64, 0x0a, 0x1b, 0x08, 0x8c, 0x00,
0x00, 0x00, 0x23, 0x06, 0x8a, 0x10, 0x48, 0x87, 0x90, 0x10, 0xc5, 0x10,
0x50, 0x52, 0x2c, 0x10, 0xe4, 0x93, 0x41, 0x40, 0x0c, 0x00, 0x02, 0x00,
@@ -40,21 +40,21 @@ const unsigned char sdl_metallib[] = {
0x00, 0x4e, 0x41, 0x4d, 0x45, 0x1a, 0x00, 0x53, 0x44, 0x4c, 0x5f, 0x43,
0x6f, 0x70, 0x79, 0x5f, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74,
0x5f, 0x6e, 0x65, 0x61, 0x72, 0x65, 0x73, 0x74, 0x00, 0x54, 0x59, 0x50,
0x45, 0x01, 0x00, 0x01, 0x48, 0x41, 0x53, 0x48, 0x20, 0x00, 0x35, 0x04,
0x75, 0x32, 0xf3, 0x3b, 0x10, 0x7f, 0x21, 0x81, 0xca, 0xf4, 0xe5, 0xda,
0xbd, 0xa9, 0x01, 0x9c, 0x95, 0xf2, 0xeb, 0xd1, 0x85, 0x5b, 0xb1, 0x88,
0x08, 0x8b, 0x3e, 0x03, 0xb3, 0xc2, 0x4f, 0x46, 0x46, 0x54, 0x18, 0x00,
0x45, 0x01, 0x00, 0x01, 0x48, 0x41, 0x53, 0x48, 0x20, 0x00, 0x1a, 0xcd,
0xc9, 0x51, 0xc4, 0x9c, 0x69, 0x4c, 0x35, 0x81, 0x89, 0x37, 0x6f, 0x90,
0x27, 0xe8, 0x83, 0x1e, 0x2b, 0x28, 0xc5, 0x03, 0x60, 0xdd, 0x80, 0x89,
0xe7, 0x3e, 0x21, 0xe0, 0x73, 0xe0, 0x4f, 0x46, 0x46, 0x54, 0x18, 0x00,
0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x60, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x56, 0x45, 0x52, 0x53, 0x08, 0x00, 0x01, 0x00, 0x08, 0x00, 0x01, 0x00,
0x01, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x80, 0x00, 0x00, 0x00, 0x4e, 0x41,
0x4d, 0x45, 0x19, 0x00, 0x53, 0x44, 0x4c, 0x5f, 0x43, 0x6f, 0x70, 0x79,
0x5f, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x6c, 0x69,
0x6e, 0x65, 0x61, 0x72, 0x00, 0x54, 0x59, 0x50, 0x45, 0x01, 0x00, 0x01,
0x48, 0x41, 0x53, 0x48, 0x20, 0x00, 0x2c, 0xda, 0x9b, 0x1f, 0x12, 0xa6,
0x94, 0x15, 0xd3, 0x95, 0x98, 0xee, 0x7e, 0x09, 0xd7, 0x54, 0x47, 0xd6,
0x7c, 0xe0, 0x6d, 0xc0, 0x83, 0xc8, 0x90, 0x9b, 0x8e, 0xb7, 0xc8, 0xb2,
0xf4, 0xbe, 0x4f, 0x46, 0x46, 0x54, 0x18, 0x00, 0x20, 0x00, 0x00, 0x00,
0x48, 0x41, 0x53, 0x48, 0x20, 0x00, 0x4e, 0x03, 0xfc, 0x68, 0xd2, 0xb4,
0xd0, 0x9a, 0xf1, 0x46, 0xed, 0x3f, 0x64, 0x34, 0xae, 0x1b, 0x24, 0x25,
0x3f, 0xa5, 0x86, 0x18, 0x28, 0xab, 0x3c, 0xf2, 0x2c, 0x7d, 0xce, 0xdf,
0x93, 0x73, 0x4f, 0x46, 0x46, 0x54, 0x18, 0x00, 0x20, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xc0, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x45, 0x52, 0x53,
0x08, 0x00, 0x01, 0x00, 0x08, 0x00, 0x01, 0x00, 0x01, 0x00, 0x45, 0x4e,
@@ -864,7 +864,7 @@ const unsigned char sdl_metallib[] = {
0xc4, 0x3f, 0x11, 0xd7, 0x44, 0x45, 0xc4, 0x6f, 0x0f, 0x7e, 0x85, 0x17,
0xb7, 0x0d, 0x61, 0x20, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x04,
0x41, 0x2c, 0x10, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0xeb,
0xdd, 0x7f, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x80, 0xd8, 0x08,
0xdd, 0xff, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x80, 0xd8, 0x08,
0x00, 0xa9, 0x1a, 0x18, 0x01, 0xa0, 0x64, 0x0a, 0x1b, 0x08, 0x8c, 0x00,
0x00, 0x00, 0x23, 0x06, 0x8a, 0x10, 0x48, 0x87, 0x90, 0x10, 0xc5, 0x10,
0x50, 0x52, 0x2c, 0x10, 0xe4, 0x93, 0x41, 0x40, 0x0c, 0x00, 0x02, 0x00,
@@ -1085,7 +1085,7 @@ const unsigned char sdl_metallib[] = {
0x95, 0x3f, 0xe7, 0x3c, 0xd8, 0x5f, 0x44, 0x80, 0xc1, 0x10, 0xcd, 0xf4,
0x2f, 0x48, 0x43, 0x00, 0x11, 0x00, 0x61, 0x20, 0x00, 0x00, 0x13, 0x00,
0x00, 0x00, 0x13, 0x04, 0x41, 0x2c, 0x10, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x04, 0xeb, 0xdd, 0x7a, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0x04, 0xeb, 0xdd, 0xfa, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff,
0x3f, 0x80, 0xd8, 0x08, 0x00, 0xa9, 0x1a, 0x18, 0x01, 0xa0, 0x64, 0x0a,
0x1b, 0x08, 0x8c, 0x00, 0x00, 0x00, 0x23, 0x06, 0x8a, 0x10, 0x48, 0x87,
0x90, 0x10, 0xc5, 0x10, 0x50, 0x52, 0x2c, 0x10, 0xe4, 0x93, 0x41, 0x40,

0 comments on commit c2cc9c1

Please sign in to comment.