Commits

vrld committed 06e20ce

Fix #435 (for real this time). Unfixes #324.

Add a extern vec2 love_ScreenSize to the pixel effects that will
be (re)set upon PixelEffect::loadVolatile() and is used to flip
the fragment coordinate.

Unfixes #324 because canvases can have different dimensions than
the screen.

  • Participants
  • Parent commits 3c6206d

Comments (0)

Files changed (7)

src/modules/graphics/Quad.h

 	virtual void flip(bool x, bool y) = 0;
 
 	/**
-	 * Mirror texture coordinates around 0.5
-	 */
-	virtual void mirror(bool x, bool y) = 0;
-
-	/**
 	 * Gets a pointer to the vertices.
 	 **/
 	virtual const vertex *getVertices() const = 0;

src/modules/graphics/opengl/Canvas.cpp

 
 	// world coordinates
 	vertices[0].x = 0;
-	vertices[0].y = 0;
+	vertices[0].y = h;
 	vertices[1].x = 0;
-	vertices[1].y = h;
+	vertices[1].y = 0;
 	vertices[2].x = w;
-	vertices[2].y = h;
+	vertices[2].y = 0;
 	vertices[3].x = w;
-	vertices[3].y = 0;
+	vertices[3].y = h;
 
 	// texture coordinates
 	vertices[0].s = 0;
 	glLoadIdentity();
 
 	// Set up orthographic view (no depth)
-	glOrtho(0.0, width, height, 0.0, -1.0, 1.0);
+	glOrtho(0.0, width, 0.0, height, -1.0, 1.0);
 
 	// Switch back to modelview matrix
 	glMatrixMode(GL_MODELVIEW);
 void Canvas::drawq(love::graphics::Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
 {
 	static Matrix t;
-	quad->mirror(false, true);
 	const vertex *v = quad->getVertices();
 
 	t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
 	drawv(t, v);
-	quad->mirror(false, true);
 }
 
 love::image::ImageData *Canvas::getImageData(love::image::Image *image)
 	int row = 4 * width;
 	int size = row * height;
 	GLubyte *pixels = new GLubyte[size];
-	GLubyte *screenshot = new GLubyte[size];
 
 	strategy->bindFBO(fbo);
 	glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
 	else
 		strategy->bindFBO(0);
 
-	GLubyte *src = pixels - row;  // second line of source image
-	GLubyte *dst = screenshot + size;  // last row of destination image
+	love::image::ImageData *img = image->newImageData(width, height, (void *)pixels);
 
-	for (int i = 0; i < height; ++i)
-		memcpy(dst -= row, src += row, row);
-
-	love::image::ImageData *img = image->newImageData(width, height, (void *)screenshot);
-
-	delete[] screenshot;
 	delete[] pixels;
 
 	return img;

src/modules/graphics/opengl/PixelEffect.cpp

 
 #include "PixelEffect.h"
 #include "GLee.h"
+#include "Graphics.h"
 
 namespace
 {
 	}
 
 	glDeleteShader(shader);
+
+	Graphics *instance = (Graphics*)Module::getInstance("love.graphics.opengl");
+	GLfloat screenSize[2] = {(float)instance->getWidth(), (float)instance->getHeight()};
+	sendFloat("love_ScreenSize", 2, screenSize, 1);
+
 	return true;
 }
 

src/modules/graphics/opengl/Quad.cpp

 	}
 }
 
-void Quad::mirror(bool x, bool y)
-{
-	for (size_t i = 0; i < NUM_VERTICES; ++i)
-	{
-		if (x)
-			vertices[i].s = 1.0f - vertices[i].s;
-		if (y)
-			vertices[i].t = 1.0f - vertices[i].t;
-	}
-}
-
 const vertex *Quad::getVertices() const
 {
 	return vertices;

src/modules/graphics/opengl/Quad.h

 	Viewport getViewport() const;
 
 	void flip(bool x, bool y);
-	void mirror(bool x, bool y);
 
 	/**
 	 * Gets a pointer to the vertices.

src/scripts/graphics.lua

 		#define Image sampler2D
 		#define extern uniform
 		#define Texel texture2D
-		layout(origin_upper_left) in vec4 gl_FragCoord;
-		uniform sampler2D _tex0_;]]
+		uniform sampler2D _tex0_;
+		uniform vec2 love_ScreenSize;]]
 		local footer = [[void main() {
 			// fix weird crashing issue in OSX when _tex0_ is unused within effect()
 			float dummy = texture2D(_tex0_, vec2(.5)).r;
-			gl_FragColor = effect(gl_Color, _tex0_, gl_TexCoord[0].xy, gl_FragCoord.xy);
+			gl_FragColor = effect(gl_Color, _tex0_, gl_TexCoord[0].xy, love_ScreenSize - gl_FragCoord.xy);
 		}]]
 
-		local function include(quoted_path) return (love.filesystem.read(quoted_path:sub(2,-2))) end
-		code = code:gsub("#include (%b'')", include)
-		code = code:gsub('#include (%b"")', include)
-
 		return table.concat{header, "\n", code, footer}
 	end
 
 				linenumber, what, message = l:match("^%w+: 0:(%d+):%s*(%w+)%([^%)]+%)%s*(.+)$")
 			end
 			if linenumber and what and message then
-				lines[#lines+1] = ("Line %d: %s: %s"):format(linenumber - 5, what, message)
+				lines[#lines+1] = ("Line %d: %s: %s"):format(linenumber - 7, what, message)
 			end
 		end
 		-- did not match any known error messages

src/scripts/graphics.lua.h

 	0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x0a,
 	0x09, 0x09, 0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x54, 0x65, 0x78, 0x65, 0x6c, 0x20, 0x74, 0x65, 
 	0x78, 0x74, 0x75, 0x72, 0x65, 0x32, 0x44, 0x0a,
-	0x09, 0x09, 0x6c, 0x61, 0x79, 0x6f, 0x75, 0x74, 0x28, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x5f, 0x75, 0x70, 
-	0x70, 0x65, 0x72, 0x5f, 0x6c, 0x65, 0x66, 0x74, 0x29, 0x20, 0x69, 0x6e, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 
-	0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x3b, 0x0a,
 	0x09, 0x09, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x32, 
-	0x44, 0x20, 0x5f, 0x74, 0x65, 0x78, 0x30, 0x5f, 0x3b, 0x5d, 0x5d, 0x0a,
+	0x44, 0x20, 0x5f, 0x74, 0x65, 0x78, 0x30, 0x5f, 0x3b, 0x0a,
+	0x09, 0x09, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x6c, 0x6f, 0x76, 
+	0x65, 0x5f, 0x53, 0x63, 0x72, 0x65, 0x65, 0x6e, 0x53, 0x69, 0x7a, 0x65, 0x3b, 0x5d, 0x5d, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x6f, 0x6f, 0x74, 0x65, 0x72, 0x20, 0x3d, 0x20, 0x5b, 
 	0x5b, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x28, 0x29, 0x20, 0x7b, 0x0a,
 	0x09, 0x09, 0x09, 0x2f, 0x2f, 0x20, 0x66, 0x69, 0x78, 0x20, 0x77, 0x65, 0x69, 0x72, 0x64, 0x20, 0x63, 0x72, 
 	0x09, 0x09, 0x09, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 
 	0x65, 0x66, 0x66, 0x65, 0x63, 0x74, 0x28, 0x67, 0x6c, 0x5f, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x2c, 0x20, 0x5f, 
 	0x74, 0x65, 0x78, 0x30, 0x5f, 0x2c, 0x20, 0x67, 0x6c, 0x5f, 0x54, 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 
-	0x5b, 0x30, 0x5d, 0x2e, 0x78, 0x79, 0x2c, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6f, 
+	0x5b, 0x30, 0x5d, 0x2e, 0x78, 0x79, 0x2c, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x5f, 0x53, 0x63, 0x72, 0x65, 0x65, 
+	0x6e, 0x53, 0x69, 0x7a, 0x65, 0x20, 0x2d, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6f, 
 	0x72, 0x64, 0x2e, 0x78, 0x79, 0x29, 0x3b, 0x0a,
 	0x09, 0x09, 0x7d, 0x5d, 0x5d, 0x0a,
-	0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, 
-	0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x28, 0x71, 0x75, 0x6f, 0x74, 0x65, 0x64, 0x5f, 0x70, 0x61, 0x74, 0x68, 
-	0x29, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x28, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6c, 
-	0x65, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x72, 0x65, 0x61, 0x64, 0x28, 0x71, 0x75, 0x6f, 0x74, 0x65, 
-	0x64, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x3a, 0x73, 0x75, 0x62, 0x28, 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x29, 0x29, 
-	0x20, 0x65, 0x6e, 0x64, 0x0a,
-	0x09, 0x09, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x3a, 0x67, 0x73, 0x75, 0x62, 
-	0x28, 0x22, 0x23, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x28, 0x25, 0x62, 0x27, 0x27, 0x29, 0x22, 
-	0x2c, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x29, 0x0a,
-	0x09, 0x09, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x3a, 0x67, 0x73, 0x75, 0x62, 
-	0x28, 0x27, 0x23, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x28, 0x25, 0x62, 0x22, 0x22, 0x29, 0x27, 
-	0x2c, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x29, 0x0a,
 	0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6e, 
 	0x63, 0x61, 0x74, 0x7b, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x2c, 0x20, 0x22, 0x5c, 0x6e, 0x22, 0x2c, 0x20, 
 	0x63, 0x6f, 0x64, 0x65, 0x2c, 0x20, 0x66, 0x6f, 0x6f, 0x74, 0x65, 0x72, 0x7d, 0x0a,
 	0x09, 0x09, 0x09, 0x09, 0x6c, 0x69, 0x6e, 0x65, 0x73, 0x5b, 0x23, 0x6c, 0x69, 0x6e, 0x65, 0x73, 0x2b, 0x31, 
 	0x5d, 0x20, 0x3d, 0x20, 0x28, 0x22, 0x4c, 0x69, 0x6e, 0x65, 0x20, 0x25, 0x64, 0x3a, 0x20, 0x25, 0x73, 0x3a, 
 	0x20, 0x25, 0x73, 0x22, 0x29, 0x3a, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x6e, 
-	0x75, 0x6d, 0x62, 0x65, 0x72, 0x20, 0x2d, 0x20, 0x35, 0x2c, 0x20, 0x77, 0x68, 0x61, 0x74, 0x2c, 0x20, 0x6d, 
+	0x75, 0x6d, 0x62, 0x65, 0x72, 0x20, 0x2d, 0x20, 0x37, 0x2c, 0x20, 0x77, 0x68, 0x61, 0x74, 0x2c, 0x20, 0x6d, 
 	0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x29, 0x0a,
 	0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
 	0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,