mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +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;
|
||||
|
||||
/**
|
||||
* Mirror texture coordinates around 0.5
|
||||
*/
|
||||
virtual void mirror(bool x, bool y) = 0;
|
||||
|
||||
/**
|
||||
* Gets a pointer to the vertices.
|
||||
**/
|
||||
|
||||
@@ -197,13 +197,13 @@ Canvas::Canvas(int width, int height)
|
||||
|
||||
// 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;
|
||||
@@ -262,7 +262,7 @@ void Canvas::startGrab()
|
||||
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);
|
||||
@@ -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
|
||||
{
|
||||
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)
|
||||
@@ -325,7 +323,6 @@ 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);
|
||||
@@ -334,15 +331,8 @@ love::image::ImageData *Canvas::getImageData(love::image::Image *image)
|
||||
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;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "PixelEffect.h"
|
||||
#include "GLee.h"
|
||||
#include "Graphics.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -134,6 +135,11 @@ bool PixelEffect::loadVolatile()
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
return vertices;
|
||||
|
||||
@@ -54,7 +54,6 @@ public:
|
||||
Viewport getViewport() const;
|
||||
|
||||
void flip(bool x, bool y);
|
||||
void mirror(bool x, bool y);
|
||||
|
||||
/**
|
||||
* Gets a pointer to the vertices.
|
||||
|
||||
Reference in New Issue
Block a user