mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-07 03:51:50 +00:00
upgraded/improved LuaCanvas::clear method
This commit is contained in:
parent
0d641fa82f
commit
67da57d870
1 changed files with 5 additions and 12 deletions
|
|
@ -161,18 +161,11 @@ static LuaCanvas& require_canvas(State* L, int idx) {
|
|||
static int l_clear(State* L) {
|
||||
auto& canvas = require_canvas(L, 1);
|
||||
auto& image = canvas.getData();
|
||||
ubyte* data = image.getData();
|
||||
RGBA rgba {};
|
||||
if (gettop(L) == 1) {
|
||||
std::fill(data, data + image.getDataSize(), 0);
|
||||
return 0;
|
||||
}
|
||||
rgba = get_rgba(L, 2);
|
||||
size_t pixels = image.getWidth() * image.getHeight();
|
||||
const size_t channels = 4;
|
||||
for (size_t i = 0; i < pixels * channels; i++) {
|
||||
data[i] = rgba.arr[i % channels];
|
||||
}
|
||||
size_t pixelscount = image.getWidth() * image.getHeight();
|
||||
uint32_t* data = reinterpret_cast<uint32_t*>(image.getData());
|
||||
|
||||
if (gettop(L) == 1) std::fill(data, data + pixelscount, 0);
|
||||
else std::fill(data, data + pixelscount, get_rgba(L, 2).rgba);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue