mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-08-03 21:45:32 +02:00
Use glReadPixels for Bitmap::getRaw
This commit is contained in:
parent
3b714579a8
commit
f17ab86ac2
3 changed files with 12 additions and 11 deletions
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue