mirror of
https://github.com/love2d/love.git
synced 2026-08-20 04:30:09 +02:00
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.
This commit is contained in:
@@ -50,11 +50,6 @@ public:
|
|||||||
|
|
||||||
virtual void flip(bool x, bool y) = 0;
|
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.
|
* Gets a pointer to the vertices.
|
||||||
**/
|
**/
|
||||||
|
|||||||
@@ -197,13 +197,13 @@ Canvas::Canvas(int width, int height)
|
|||||||
|
|
||||||
// world coordinates
|
// world coordinates
|
||||||
vertices[0].x = 0;
|
vertices[0].x = 0;
|
||||||
vertices[0].y = 0;
|
vertices[0].y = h;
|
||||||
vertices[1].x = 0;
|
vertices[1].x = 0;
|
||||||
vertices[1].y = h;
|
vertices[1].y = 0;
|
||||||
vertices[2].x = w;
|
vertices[2].x = w;
|
||||||
vertices[2].y = h;
|
vertices[2].y = 0;
|
||||||
vertices[3].x = w;
|
vertices[3].x = w;
|
||||||
vertices[3].y = 0;
|
vertices[3].y = h;
|
||||||
|
|
||||||
// texture coordinates
|
// texture coordinates
|
||||||
vertices[0].s = 0;
|
vertices[0].s = 0;
|
||||||
@@ -262,7 +262,7 @@ void Canvas::startGrab()
|
|||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
// Set up orthographic view (no depth)
|
// 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
|
// Switch back to modelview matrix
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
@@ -312,12 +312,10 @@ void Canvas::draw(float x, float y, float angle, float sx, float sy, float ox, f
|
|||||||
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
|
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;
|
static Matrix t;
|
||||||
quad->mirror(false, true);
|
|
||||||
const vertex *v = quad->getVertices();
|
const vertex *v = quad->getVertices();
|
||||||
|
|
||||||
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
|
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||||
drawv(t, v);
|
drawv(t, v);
|
||||||
quad->mirror(false, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
love::image::ImageData *Canvas::getImageData(love::image::Image *image)
|
love::image::ImageData *Canvas::getImageData(love::image::Image *image)
|
||||||
@@ -325,7 +323,6 @@ love::image::ImageData *Canvas::getImageData(love::image::Image *image)
|
|||||||
int row = 4 * width;
|
int row = 4 * width;
|
||||||
int size = row * height;
|
int size = row * height;
|
||||||
GLubyte *pixels = new GLubyte[size];
|
GLubyte *pixels = new GLubyte[size];
|
||||||
GLubyte *screenshot = new GLubyte[size];
|
|
||||||
|
|
||||||
strategy->bindFBO(fbo);
|
strategy->bindFBO(fbo);
|
||||||
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||||
@@ -334,15 +331,8 @@ love::image::ImageData *Canvas::getImageData(love::image::Image *image)
|
|||||||
else
|
else
|
||||||
strategy->bindFBO(0);
|
strategy->bindFBO(0);
|
||||||
|
|
||||||
GLubyte *src = pixels - row; // second line of source image
|
love::image::ImageData *img = image->newImageData(width, height, (void *)pixels);
|
||||||
GLubyte *dst = screenshot + size; // last row of destination image
|
|
||||||
|
|
||||||
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;
|
delete[] pixels;
|
||||||
|
|
||||||
return img;
|
return img;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "PixelEffect.h"
|
#include "PixelEffect.h"
|
||||||
#include "GLee.h"
|
#include "GLee.h"
|
||||||
|
#include "Graphics.h"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@@ -134,6 +135,11 @@ bool PixelEffect::loadVolatile()
|
|||||||
}
|
}
|
||||||
|
|
||||||
glDeleteShader(shader);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -113,17 +113,6 @@ void Quad::flip(bool x, bool y)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
const vertex *Quad::getVertices() const
|
||||||
{
|
{
|
||||||
return vertices;
|
return vertices;
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ public:
|
|||||||
Viewport getViewport() const;
|
Viewport getViewport() const;
|
||||||
|
|
||||||
void flip(bool x, bool y);
|
void flip(bool x, bool y);
|
||||||
void mirror(bool x, bool y);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a pointer to the vertices.
|
* Gets a pointer to the vertices.
|
||||||
|
|||||||
@@ -1290,18 +1290,14 @@ do
|
|||||||
#define Image sampler2D
|
#define Image sampler2D
|
||||||
#define extern uniform
|
#define extern uniform
|
||||||
#define Texel texture2D
|
#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() {
|
local footer = [[void main() {
|
||||||
// fix weird crashing issue in OSX when _tex0_ is unused within effect()
|
// fix weird crashing issue in OSX when _tex0_ is unused within effect()
|
||||||
float dummy = texture2D(_tex0_, vec2(.5)).r;
|
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}
|
return table.concat{header, "\n", code, footer}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1318,7 +1314,7 @@ do
|
|||||||
linenumber, what, message = l:match("^%w+: 0:(%d+):%s*(%w+)%([^%)]+%)%s*(.+)$")
|
linenumber, what, message = l:match("^%w+: 0:(%d+):%s*(%w+)%([^%)]+%)%s*(.+)$")
|
||||||
end
|
end
|
||||||
if linenumber and what and message then
|
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
|
||||||
end
|
end
|
||||||
-- did not match any known error messages
|
-- did not match any known error messages
|
||||||
|
|||||||
@@ -6273,11 +6273,10 @@ const unsigned char graphics_lua[] =
|
|||||||
0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x0a,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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, 0x2f, 0x2f, 0x20, 0x66, 0x69, 0x78, 0x20, 0x77, 0x65, 0x69, 0x72, 0x64, 0x20, 0x63, 0x72,
|
||||||
@@ -6291,21 +6290,10 @@ const unsigned char graphics_lua[] =
|
|||||||
0x09, 0x09, 0x09, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20,
|
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,
|
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,
|
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,
|
0x72, 0x64, 0x2e, 0x78, 0x79, 0x29, 0x3b, 0x0a,
|
||||||
0x09, 0x09, 0x7d, 0x5d, 0x5d, 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,
|
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, 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,
|
0x63, 0x6f, 0x64, 0x65, 0x2c, 0x20, 0x66, 0x6f, 0x6f, 0x74, 0x65, 0x72, 0x7d, 0x0a,
|
||||||
@@ -6356,7 +6344,7 @@ const unsigned char graphics_lua[] =
|
|||||||
0x09, 0x09, 0x09, 0x09, 0x6c, 0x69, 0x6e, 0x65, 0x73, 0x5b, 0x23, 0x6c, 0x69, 0x6e, 0x65, 0x73, 0x2b, 0x31,
|
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,
|
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,
|
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,
|
0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x29, 0x0a,
|
||||||
0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
|
0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
|
||||||
0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
|
0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
|
||||||
|
|||||||
Reference in New Issue
Block a user