From 04623e3be44cd2756d56ae059c08938aecb61df4 Mon Sep 17 00:00:00 2001 From: James Gray Date: Thu, 11 Jun 2015 13:54:49 -0500 Subject: [PATCH] console: always use Image of type DATA At least until we start introducing mechanisms to reduce memory footprint, like platform-specific texture compression. --- lime/graphics/Image.hx | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/lime/graphics/Image.hx b/lime/graphics/Image.hx index b8a863003..92a1fece6 100644 --- a/lime/graphics/Image.hx +++ b/lime/graphics/Image.hx @@ -1017,15 +1017,42 @@ class Image { #if lime_console - var texdata = TextureData.fromFile (path); + var td = TextureData.fromFile (path); - if (texdata.valid) { + if (td.valid) { - buffer = new ImageBuffer (null, texdata.width, texdata.height); - buffer.src = texdata; - // TODO(james4k): call texdata.release() in a finalizer or - // somewhere.. or don't manage texture resources this way. - // we shall see. + var w = td.width; + var h = td.height; + var data = new Array (); + + #if 1 + + cpp.NativeArray.setSize (data, w*h*4); + { + var dest:cpp.Pointer = cast cpp.Pointer.arrayElem (data, 0); + var src:cpp.Pointer = cast td.pointer; + var n = w * h; + for (i in 0...n) { + dest[i] = src[i]; + } + } + td.release (); + + #else + + // TODO(james4k): caveats here with every image + // pointing to the same piece of memory, and things may + // change with compressed textures. but, may be worth + // considering if game is hitting memory constraints. + // can we do this safely somehow? copy on write? + // probably too many people writing directly to the + // buffer... + cpp.NativeArray.setUnmanagedData (data, td.pointer, w*h*4); + + #end + + var array = new UInt8Array (ByteArray.fromBytes (Bytes.ofData (cast data))); + buffer = new ImageBuffer (array, w, h); }