src/render/metal/SDL_shaders_metal.metal
changeset 11789 01f9851b2c9d
parent 11755 e9a1b9ea8da0
child 11799 cecf6b192ced
     1.1 --- a/src/render/metal/SDL_shaders_metal.metal	Sat Dec 30 18:48:07 2017 -0400
     1.2 +++ b/src/render/metal/SDL_shaders_metal.metal	Sat Dec 30 20:32:22 2017 -0400
     1.3 @@ -1,17 +1,20 @@
     1.4  #include <metal_texture>
     1.5 +#include <metal_matrix>
     1.6  
     1.7  using namespace metal;
     1.8  
     1.9 -struct SolidVertex
    1.10 +struct SolidVertexOutput
    1.11  {
    1.12  	float4 position [[position]];
    1.13  	float pointSize [[point_size]];
    1.14  };
    1.15  
    1.16 -vertex SolidVertex SDL_Solid_vertex(constant float2 *position [[buffer(0)]], uint vid [[vertex_id]])
    1.17 +vertex SolidVertexOutput SDL_Solid_vertex(const device float2 *position [[buffer(0)]],
    1.18 +                                          constant float4x4 &projection [[buffer(2)]],
    1.19 +                                          uint vid [[vertex_id]])
    1.20  {
    1.21 -    SolidVertex v;
    1.22 -	v.position = float4(position[vid].x, position[vid].y, 0.0f, 1.0f);
    1.23 +    SolidVertexOutput v;
    1.24 +	v.position = projection * float4(position[vid].x, position[vid].y, 0.0f, 1.0f);
    1.25  	v.pointSize = 0.5f;
    1.26  	return v;
    1.27  }
    1.28 @@ -21,27 +24,34 @@
    1.29      return col;
    1.30  }
    1.31  
    1.32 -struct CopyVertex
    1.33 +struct CopyVertexOutput
    1.34  {
    1.35      float4 position [[position]];
    1.36      float2 texcoord;
    1.37  };
    1.38  
    1.39 -vertex CopyVertex SDL_Copy_vertex(constant float2 *position [[buffer(0)]], constant float2 *texcoords [[buffer(1)]], uint vid [[vertex_id]])
    1.40 +vertex CopyVertexOutput SDL_Copy_vertex(const device float2 *position [[buffer(0)]],
    1.41 +                                        const device float2 *texcoords [[buffer(1)]],
    1.42 +                                        constant float4x4 &projection [[buffer(2)]],
    1.43 +                                        uint vid [[vertex_id]])
    1.44  {
    1.45 -    CopyVertex v;
    1.46 -    v.position = float4(position[vid].x, position[vid].y, 0.0f, 1.0f);
    1.47 +    CopyVertexOutput v;
    1.48 +    v.position = projection * float4(position[vid].x, position[vid].y, 0.0f, 1.0f);
    1.49      v.texcoord = texcoords[vid];
    1.50      return v;
    1.51  }
    1.52  
    1.53 -fragment float4 SDL_Copy_fragment_nearest(CopyVertex vert [[stage_in]], constant float4 &col [[buffer(0)]], texture2d<float> tex [[texture(0)]])
    1.54 +fragment float4 SDL_Copy_fragment_nearest(CopyVertexOutput vert [[stage_in]],
    1.55 +                                          constant float4 &col [[buffer(0)]],
    1.56 +                                          texture2d<float> tex [[texture(0)]])
    1.57  {
    1.58      constexpr sampler s(coord::normalized, address::clamp_to_edge, filter::nearest);
    1.59      return tex.sample(s, vert.texcoord) * col;
    1.60  }
    1.61  
    1.62 -fragment float4 SDL_Copy_fragment_linear(CopyVertex vert [[stage_in]], constant float4 &col [[buffer(0)]], texture2d<float> tex [[texture(0)]])
    1.63 +fragment float4 SDL_Copy_fragment_linear(CopyVertexOutput vert [[stage_in]],
    1.64 +                                         constant float4 &col [[buffer(0)]],
    1.65 +                                         texture2d<float> tex [[texture(0)]])
    1.66  {
    1.67      constexpr sampler s(coord::normalized, address::clamp_to_edge, filter::linear);
    1.68      return tex.sample(s, vert.texcoord) * col;