Use glReadPixels for Bitmap::getRaw

This commit is contained in:
Inori 2019-09-06 16:18:09 -04:00 committed by Inori
parent 3b714579a8
commit f17ab86ac2
3 changed files with 12 additions and 11 deletions

View file

@ -422,14 +422,12 @@ RB_METHOD(bitmapGetRawData)
RB_UNUSED_PARAM;
Bitmap *b = getPrivateData<Bitmap>(self);
int size = b->width()*b->height()*4;
VALUE ret = rb_str_new(0, size);
GUARD_EXC ( b->getRaw(RSTRING_PTR(ret), size); );
char *pixels{};
int size{};
GUARD_EXC( pixels = (char*)b->getRaw(); );
GUARD_EXC( size = b->width()*b->height()*4; );
return rb_str_new(pixels, size);
return ret;
}
RB_METHOD(bitmapSetRawData)
@ -437,7 +435,7 @@ RB_METHOD(bitmapSetRawData)
RB_UNUSED_PARAM;
VALUE str;
rb_get_args(argc, argv, "1", &str);
rb_scan_args(argc, argv, "1", &str);
SafeStringValue(str);
Bitmap *b = getPrivateData<Bitmap>(self);

View file

@ -883,13 +883,16 @@ void Bitmap::setPixel(int x, int y, const Color &color)
p->onModified(false);
}
void *Bitmap::getRaw()
void Bitmap::getRaw(void *output, int output_size)
{
if (output_size != width()*height()*4) return;
guardDisposed();
GUARD_MEGA;
return p->surface->pixels;
FBO::bind(p->gl.fbo);
glReadPixels(0,0,width(),height(),GL_BGRA,GL_UNSIGNED_BYTE,output);
}
void Bitmap::replaceRaw(void *pixel_data, int size)

View file

@ -82,7 +82,7 @@ public:
Color getPixel(int x, int y) const;
void setPixel(int x, int y, const Color &color);
void *getRaw();
void getRaw(void *output, int output_size);
void replaceRaw(void *pixel_data, int size);
void hueChange(int hue);