Implement renderer.readPixels when not using SDL_Renderer
This commit is contained in:
@@ -135,20 +135,65 @@ class NativeRenderer {
|
||||
|
||||
var imageBuffer:ImageBuffer = null;
|
||||
|
||||
#if (!macro && lime_cffi)
|
||||
#if !cs
|
||||
imageBuffer = NativeCFFI.lime_renderer_read_pixels (handle, rect, new ImageBuffer (new UInt8Array (Bytes.alloc (0))));
|
||||
#else
|
||||
var data:Dynamic = NativeCFFI.lime_renderer_read_pixels (handle, rect, null);
|
||||
if (data != null) {
|
||||
imageBuffer = new ImageBuffer (new UInt8Array (@:privateAccess new Bytes (data.data.length, data.data.b)), data.width, data.height, data.bitsPerPixel);
|
||||
switch (parent.context) {
|
||||
|
||||
case OPENGL (gl):
|
||||
|
||||
var windowWidth = parent.window.__width * parent.window.__scale;
|
||||
var windowHeight = parent.window.__height * parent.window.__scale;
|
||||
|
||||
var x = Std.int (rect.x);
|
||||
var y = Std.int ((windowHeight - rect.y) - rect.height);
|
||||
var width = Std.int (rect.width);
|
||||
var height = Std.int (rect.height);
|
||||
|
||||
var buffer = Bytes.alloc (width * height * 4);
|
||||
|
||||
gl.readPixels (x, y, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buffer);
|
||||
|
||||
var rowLength = width * 4;
|
||||
var srcPosition = (height - 1) * rowLength;
|
||||
var destPosition = 0;
|
||||
|
||||
var temp = Bytes.alloc (rowLength);
|
||||
var rows = Std.int (height / 2);
|
||||
|
||||
while (rows-- > 0) {
|
||||
|
||||
temp.blit (0, buffer, destPosition, rowLength);
|
||||
buffer.blit (destPosition, buffer, srcPosition, rowLength);
|
||||
buffer.blit (srcPosition, temp, 0, rowLength);
|
||||
|
||||
destPosition += rowLength;
|
||||
srcPosition -= rowLength;
|
||||
|
||||
}
|
||||
|
||||
imageBuffer = new ImageBuffer (new UInt8Array (buffer), width, height, 32, RGBA32);
|
||||
|
||||
default:
|
||||
|
||||
#if (!macro && lime_cffi)
|
||||
#if !cs
|
||||
imageBuffer = NativeCFFI.lime_renderer_read_pixels (handle, rect, new ImageBuffer (new UInt8Array (Bytes.alloc (0))));
|
||||
#else
|
||||
var data:Dynamic = NativeCFFI.lime_renderer_read_pixels (handle, rect, null);
|
||||
if (data != null) {
|
||||
imageBuffer = new ImageBuffer (new UInt8Array (@:privateAccess new Bytes (data.data.length, data.data.b)), data.width, data.height, data.bitsPerPixel);
|
||||
}
|
||||
#end
|
||||
#end
|
||||
|
||||
if (imageBuffer != null) {
|
||||
|
||||
imageBuffer.format = RGBA32;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#end
|
||||
#end
|
||||
|
||||
if (imageBuffer != null) {
|
||||
|
||||
imageBuffer.format = RGBA32;
|
||||
return new Image (imageBuffer);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user