From d86ff9011a4b304121ee75ed5f6352b426f9852a Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 21 Jun 2019 18:04:18 -0700 Subject: [PATCH] Update the postprocessing shader and vertex array for the Metal changes. Closes #201. --- renderer/src/gpu/renderer.rs | 4 ++-- resources/shaders/gl3/post.vs.glsl | 10 ++++++++-- resources/shaders/metal/post.vs.metal | 6 ++++-- shaders/post.vs.glsl | 10 ++++++++-- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/renderer/src/gpu/renderer.rs b/renderer/src/gpu/renderer.rs index 87565d36..f70f56d7 100644 --- a/renderer/src/gpu/renderer.rs +++ b/renderer/src/gpu/renderer.rs @@ -654,7 +654,7 @@ where } } - self.device.draw_arrays(4, &RenderState { + self.device.draw_elements(6, &RenderState { target: &self.dest_render_target(), program: &self.postprocess_program.program, vertex_array: &self.postprocess_vertex_array.vertex_array, @@ -1451,7 +1451,7 @@ where device.configure_vertex_attr(&vertex_array, &position_attr, &VertexAttrDescriptor { size: 2, class: VertexAttrClass::Int, - attr_type: VertexAttrType::U16, + attr_type: VertexAttrType::I16, stride: 4, offset: 0, divisor: 0, diff --git a/resources/shaders/gl3/post.vs.glsl b/resources/shaders/gl3/post.vs.glsl index b30dcf8d..a1d8effb 100644 --- a/resources/shaders/gl3/post.vs.glsl +++ b/resources/shaders/gl3/post.vs.glsl @@ -19,7 +19,13 @@ in ivec2 aPosition; out vec2 vTexCoord; void main(){ - vTexCoord = vec2(aPosition); - gl_Position = vec4(vec2(aPosition)* 2.0 - 1.0, 0.0, 1.0); + vec2 position = vec2(aPosition); + vTexCoord = position; + + + + + + gl_Position = vec4(vec2(position)* 2.0 - 1.0, 0.0, 1.0); } diff --git a/resources/shaders/metal/post.vs.metal b/resources/shaders/metal/post.vs.metal index 0fcc0bf6..f7385038 100644 --- a/resources/shaders/metal/post.vs.metal +++ b/resources/shaders/metal/post.vs.metal @@ -18,8 +18,10 @@ struct main0_in vertex main0_out main0(main0_in in [[stage_in]]) { main0_out out = {}; - out.vTexCoord = float2(in.aPosition); - out.gl_Position = float4((float2(in.aPosition) * 2.0) - float2(1.0), 0.0, 1.0); + float2 position = float2(in.aPosition); + out.vTexCoord = position; + position.y = 1.0 - position.y; + out.gl_Position = float4((float2(position) * 2.0) - float2(1.0), 0.0, 1.0); return out; } diff --git a/shaders/post.vs.glsl b/shaders/post.vs.glsl index 137cf388..52cf3eea 100644 --- a/shaders/post.vs.glsl +++ b/shaders/post.vs.glsl @@ -17,6 +17,12 @@ in ivec2 aPosition; out vec2 vTexCoord; void main() { - vTexCoord = vec2(aPosition); - gl_Position = vec4(vec2(aPosition) * 2.0 - 1.0, 0.0, 1.0); + vec2 position = vec2(aPosition); + vTexCoord = position; + +#ifdef PF_ORIGIN_UPPER_LEFT + // FIXME(pcwalton): This is wrong. + position.y = 1.0 - position.y; +#endif + gl_Position = vec4(vec2(position) * 2.0 - 1.0, 0.0, 1.0); }