src/render/metal/SDL_render_metal.m
changeset 11751 f5a8e41ac249
parent 11750 e2a349c9dd30
child 11753 963b438b949f
     1.1 --- a/src/render/metal/SDL_render_metal.m	Sat Dec 09 03:28:23 2017 -0500
     1.2 +++ b/src/render/metal/SDL_render_metal.m	Sat Dec 09 12:58:41 2017 -0800
     1.3 @@ -96,8 +96,12 @@
     1.4       // (the weakest GPU supported by Metal on iOS has 4k texture max, and
     1.5       //  other models might be 2x or 4x more. On macOS, it's 16k across the
     1.6       //  board right now.)
     1.7 -     4096,
     1.8 -     4096}
     1.9 +#ifdef __MACOSX__
    1.10 +     16384, 16384
    1.11 +#else
    1.12 +     4096, 4096
    1.13 +#endif
    1.14 +    }
    1.15  };
    1.16  
    1.17  @interface METAL_RenderData : NSObject
    1.18 @@ -305,7 +309,7 @@
    1.19      data.mtllibrary.label = @"SDL Metal renderer shader library";
    1.20  
    1.21      data.mtlpipelineprims = [[NSMutableArray alloc] init];
    1.22 -    MakePipelineStates(data, data.mtlpipelineprims, @"SDL primitives pipeline", @"SDL_Simple_vertex", @"SDL_Simple_fragment");
    1.23 +    MakePipelineStates(data, data.mtlpipelineprims, @"SDL primitives pipeline", @"SDL_Solid_vertex", @"SDL_Solid_fragment");
    1.24      data.mtlpipelinecopy = [[NSMutableArray alloc] init];
    1.25      MakePipelineStates(data, data.mtlpipelinecopy, @"SDL_RenderCopy pipeline", @"SDL_Copy_vertex", @"SDL_Copy_fragment");
    1.26  
    1.27 @@ -559,17 +563,18 @@
    1.28  
    1.29  // normalize a value from 0.0f to len into -1.0f to 1.0f.
    1.30  static inline float
    1.31 -norm(const float _val, const float len)
    1.32 +normx(const float _val, const float len)
    1.33  {
    1.34      const float val = (_val < 0.0f) ? 0.0f : (_val > len) ? len : _val;
    1.35 -    return ((val / len) * 2.0f) - 1.0f;  // !!! FIXME: is this right?
    1.36 +    return (((val + 0.5f) / len) * 2.0f) - 1.0f;
    1.37  }
    1.38  
    1.39  // normalize a value from 0.0f to len into -1.0f to 1.0f.
    1.40  static inline float
    1.41  normy(const float _val, const float len)
    1.42  {
    1.43 -    return norm(len - ((_val < 0.0f) ? 0.0f : (_val > len) ? len : _val), len);
    1.44 +    const float val = (_val <= 0.0f) ? len : (_val >= len) ? 0.0f : (len - _val);
    1.45 +    return (((val - 0.5f) / len) * 2.0f) - 1.0f;
    1.46  }
    1.47  
    1.48  // normalize a value from 0.0f to len into 0.0f to 1.0f.
    1.49 @@ -577,7 +582,7 @@
    1.50  normtex(const float _val, const float len)
    1.51  {
    1.52      const float val = (_val < 0.0f) ? 0.0f : (_val > len) ? len : _val;
    1.53 -    return (val / len);
    1.54 +    return ((val + 0.5f) / len);
    1.55  }
    1.56  
    1.57  static int
    1.58 @@ -606,7 +611,7 @@
    1.59      // !!! FIXME: we can convert this in the shader. This will save the malloc and for-loop, but we still need to upload.
    1.60      float *ptr = verts;
    1.61      for (int i = 0; i < count; i++, points++) {
    1.62 -        *ptr = norm(points->x, w); ptr++;
    1.63 +        *ptr = normx(points->x, w); ptr++;
    1.64          *ptr = normy(points->y, h); ptr++;
    1.65      }
    1.66  
    1.67 @@ -648,11 +653,11 @@
    1.68          if ((rects->w <= 0.0f) || (rects->h <= 0.0f)) continue;
    1.69  
    1.70          const float verts[] = {
    1.71 -            norm(rects->x, w), normy(rects->y + rects->h, h),
    1.72 -            norm(rects->x, w), normy(rects->y, h),
    1.73 -            norm(rects->x + rects->w, w), normy(rects->y, h),
    1.74 -            norm(rects->x, w), normy(rects->y + rects->h, h),
    1.75 -            norm(rects->x + rects->w, w), normy(rects->y + rects->h, h)
    1.76 +            normx(rects->x, w), normy(rects->y + rects->h, h),
    1.77 +            normx(rects->x, w), normy(rects->y, h),
    1.78 +            normx(rects->x + rects->w, w), normy(rects->y, h),
    1.79 +            normx(rects->x, w), normy(rects->y + rects->h, h),
    1.80 +            normx(rects->x + rects->w, w), normy(rects->y + rects->h, h)
    1.81          };
    1.82  
    1.83          [data.mtlcmdencoder setVertexBytes:verts length:sizeof(verts) atIndex:0];
    1.84 @@ -675,11 +680,11 @@
    1.85      const float texh = (float) mtltexture.height;
    1.86  
    1.87      const float xy[] = {
    1.88 -        norm(dstrect->x, w), normy(dstrect->y + dstrect->h, h),
    1.89 -        norm(dstrect->x, w), normy(dstrect->y, h),
    1.90 -        norm(dstrect->x + dstrect->w, w), normy(dstrect->y, h),
    1.91 -        norm(dstrect->x, w), normy(dstrect->y + dstrect->h, h),
    1.92 -        norm(dstrect->x + dstrect->w, w), normy(dstrect->y + dstrect->h, h)
    1.93 +        normx(dstrect->x, w), normy(dstrect->y + dstrect->h, h),
    1.94 +        normx(dstrect->x, w), normy(dstrect->y, h),
    1.95 +        normx(dstrect->x + dstrect->w, w), normy(dstrect->y, h),
    1.96 +        normx(dstrect->x, w), normy(dstrect->y + dstrect->h, h),
    1.97 +        normx(dstrect->x + dstrect->w, w), normy(dstrect->y + dstrect->h, h)
    1.98      };
    1.99  
   1.100      const float uv[] = {
   1.101 @@ -768,7 +773,9 @@
   1.102  METAL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   1.103  { @autoreleasepool {
   1.104      id<MTLTexture> mtltexture = CFBridgingRelease(texture->driverdata);
   1.105 -#if !__has_feature(objc_arc)
   1.106 +#if __has_feature(objc_arc)
   1.107 +    mtltexture = nil;
   1.108 +#else
   1.109      [mtltexture release];
   1.110  #endif
   1.111      texture->driverdata = NULL;