Skip to content

Commit

Permalink
Provide more opportunities to make images readable
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Oct 31, 2022
1 parent dab3660 commit aaebc16
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 40 deletions.
8 changes: 4 additions & 4 deletions Backends/HTML5-Worker/kha/Image.hx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Image implements Canvas implements Resource {
myFormat = format;
}

public static function create(width: Int, height: Int, format: TextureFormat = null, usage: Usage = null): Image {
public static function create(width: Int, height: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
if (format == null)
format = TextureFormat.RGBA32;
if (usage == null)
Expand All @@ -47,7 +47,7 @@ class Image implements Canvas implements Resource {
return new Image(id, -1, width, height, width, height, format);
}

public static function create3D(width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null): Image {
public static function create3D(width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
return null;
}

Expand All @@ -65,11 +65,11 @@ class Image implements Canvas implements Resource {
return new Image(-1, rtid, width, height, width, height, format);
}

public static function fromBytes(bytes: Bytes, width: Int, height: Int, format: TextureFormat = null, usage: Usage = null): Image {
public static function fromBytes(bytes: Bytes, width: Int, height: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
return null;
}

public static function fromBytes3D(bytes: Bytes, width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null): Image {
public static function fromBytes3D(bytes: Bytes, width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
return null;
}

Expand Down
12 changes: 6 additions & 6 deletions Backends/HTML5/kha/Image.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import kha.graphics4.DepthStencilFormat;
import kha.graphics4.Usage;

class Image implements Canvas implements Resource {
public static function create(width: Int, height: Int, format: TextureFormat = null, usage: Usage = null): Image {
public static function create(width: Int, height: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
if (format == null)
format = TextureFormat.RGBA32;
if (usage == null)
usage = Usage.StaticUsage;
if (SystemImpl.gl == null)
return new CanvasImage(width, height, format, false);
else
return new WebGLImage(width, height, format, false, DepthStencilFormat.NoDepthAndStencil, 1, false);
return new WebGLImage(width, height, format, false, DepthStencilFormat.NoDepthAndStencil, 1, readable);
}

public static function create3D(width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null): Image {
public static function create3D(width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
return null;
}

Expand Down Expand Up @@ -64,13 +64,13 @@ class Image implements Canvas implements Resource {
}
}

public static function fromBytes(bytes: Bytes, width: Int, height: Int, format: TextureFormat = null, usage: Usage = null): Image {
public static function fromBytes(bytes: Bytes, width: Int, height: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
if (format == null)
format = TextureFormat.RGBA32;
if (usage == null)
usage = Usage.StaticUsage;
if (SystemImpl.gl != null) {
var img = new WebGLImage(width, height, format, false, DepthStencilFormat.NoDepthAndStencil, 1, false);
var img = new WebGLImage(width, height, format, false, DepthStencilFormat.NoDepthAndStencil, 1, readable);
img.image = img.bytesToArray(bytes);
img.createTexture();
return img;
Expand All @@ -83,7 +83,7 @@ class Image implements Canvas implements Resource {
return img;
}

public static function fromBytes3D(bytes: Bytes, width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null): Image {
public static function fromBytes3D(bytes: Bytes, width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
return null;
}

Expand Down
14 changes: 6 additions & 8 deletions Backends/Kinc-HL/kha/Image.hx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class Image implements Canvas implements Resource {
return image;
}

public static function create(width: Int, height: Int, format: TextureFormat = null, usage: Usage = null): Image {
return create2(width, height, format == null ? TextureFormat.RGBA32 : format, false, false, NoDepthAndStencil);
public static function create(width: Int, height: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
return create2(width, height, format == null ? TextureFormat.RGBA32 : format, readable, false, NoDepthAndStencil);
}

public static function create3D(width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null): Image {
return create3(width, height, depth, format == null ? TextureFormat.RGBA32 : format, false, 0);
public static function create3D(width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
return create3(width, height, depth, format == null ? TextureFormat.RGBA32 : format, readable, 0);
}

public static function createRenderTarget(width: Int, height: Int, format: TextureFormat = null, depthStencil: DepthStencilFormat = NoDepthAndStencil,
Expand All @@ -47,8 +47,7 @@ class Image implements Canvas implements Resource {
// return image;
// }

public static function fromBytes(bytes: Bytes, width: Int, height: Int, format: TextureFormat = null, usage: Usage = null): Image {
var readable = true;
public static function fromBytes(bytes: Bytes, width: Int, height: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
var image = new Image(readable);
image.myFormat = format;
image.initFromBytes(bytes.getData(), width, height, getTextureFormat(format));
Expand All @@ -59,8 +58,7 @@ class Image implements Canvas implements Resource {
_texture = kinc_texture_from_bytes(bytes.bytes, width, height, format, readable);
}

public static function fromBytes3D(bytes: Bytes, width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null): Image {
var readable = true;
public static function fromBytes3D(bytes: Bytes, width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
var image = new Image(readable);
image.myFormat = format;
image.initFromBytes3D(bytes.getData(), width, height, depth, getTextureFormat(format));
Expand Down
14 changes: 6 additions & 8 deletions Backends/Kinc-hxcpp/kha/Image.hx
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ class Image implements Canvas implements Resource {
return image;
}

public static function create(width: Int, height: Int, format: TextureFormat = null, usage: Usage = null): Image {
return _create2(width, height, format == null ? TextureFormat.RGBA32 : format, false, false, NoDepthAndStencil, 0);
public static function create(width: Int, height: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
return _create2(width, height, format == null ? TextureFormat.RGBA32 : format, readable, false, NoDepthAndStencil, 0);
}

public static function create3D(width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null): Image {
return _create3(width, height, depth, format == null ? TextureFormat.RGBA32 : format, false, 0);
public static function create3D(width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
return _create3(width, height, depth, format == null ? TextureFormat.RGBA32 : format, readable, 0);
}

public static function createRenderTarget(width: Int, height: Int, format: TextureFormat = null, depthStencil: DepthStencilFormat = NoDepthAndStencil,
Expand Down Expand Up @@ -83,8 +83,7 @@ class Image implements Canvas implements Resource {
")
static function initArrayTexture(source: Image, images: Array<Image>): Void {}

public static function fromBytes(bytes: Bytes, width: Int, height: Int, format: TextureFormat = null, usage: Usage = null): Image {
var readable = true;
public static function fromBytes(bytes: Bytes, width: Int, height: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
var image = new Image(readable);
image.myFormat = format;
image.initFromBytes(bytes.getData(), width, height, getTextureFormat(format));
Expand All @@ -105,8 +104,7 @@ class Image implements Canvas implements Resource {
")
function initFromBytes(bytes: BytesData, width: Int, height: Int, format: Int): Void {}

public static function fromBytes3D(bytes: Bytes, width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null): Image {
var readable = true;
public static function fromBytes3D(bytes: Bytes, width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
var image = new Image(readable);
image.myFormat = format;
image.initFromBytes3D(bytes.getData(), width, height, depth, getTextureFormat(format));
Expand Down
10 changes: 4 additions & 6 deletions Backends/Krom/kha/Image.hx
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,18 @@ class Image implements Canvas implements Resource {
return new Image(texture);
}

public static function fromBytes(bytes: Bytes, width: Int, height: Int, format: TextureFormat = null, usage: Usage = null): Image {
public static function fromBytes(bytes: Bytes, width: Int, height: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
if (format == null)
format = TextureFormat.RGBA32;
var readable = true;
var image = new Image(null);
image.myFormat = format;
image.texture_ = Krom.createTextureFromBytes(bytes.getData(), width, height, getTextureFormat(format), readable);
return image;
}

public static function fromBytes3D(bytes: Bytes, width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null): Image {
public static function fromBytes3D(bytes: Bytes, width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
if (format == null)
format = TextureFormat.RGBA32;
var readable = true;
var image = new Image(null);
image.myFormat = format;
image.texture_ = Krom.createTextureFromBytes3D(bytes.getData(), width, height, depth, getTextureFormat(format), readable);
Expand All @@ -111,7 +109,7 @@ class Image implements Canvas implements Resource {
doneCallback(image);
}

public static function create(width: Int, height: Int, format: TextureFormat = null, usage: Usage = null): Image {
public static function create(width: Int, height: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
if (format == null)
format = TextureFormat.RGBA32;
var image = new Image(null);
Expand All @@ -120,7 +118,7 @@ class Image implements Canvas implements Resource {
return image;
}

public static function create3D(width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null): Image {
public static function create3D(width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
if (format == null)
format = TextureFormat.RGBA32;
var image = new Image(null);
Expand Down
8 changes: 4 additions & 4 deletions Backends/Node/kha/Image.hx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class Image implements Canvas implements Resource {
graphics4 = new EmptyGraphics4(w, h);
}

public static function create(width: Int, height: Int, format: TextureFormat = null, usage: Usage = null): Image {
public static function create(width: Int, height: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
return new Image(width, height, format);
}

public static function create3D(width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null): Image {
public static function create3D(width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
return null;
}

Expand All @@ -43,11 +43,11 @@ class Image implements Canvas implements Resource {
return new Image(width, height, format);
}

public static function fromBytes(bytes: Bytes, width: Int, height: Int, format: TextureFormat = null, usage: Usage = null): Image {
public static function fromBytes(bytes: Bytes, width: Int, height: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
return null;
}

public static function fromBytes3D(bytes: Bytes, width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null): Image {
public static function fromBytes3D(bytes: Bytes, width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
return null;
}

Expand Down
9 changes: 5 additions & 4 deletions Sources/kha/Image.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import kha.graphics4.TextureFormat;
import kha.graphics4.Usage;

extern class Image implements Canvas implements Resource {
public static function create(width: Int, height: Int, format: TextureFormat = TextureFormat.RGBA32, usage: Usage = Usage.StaticUsage): Image;
public static function create(width: Int, height: Int, format: TextureFormat = TextureFormat.RGBA32, usage: Usage = Usage.StaticUsage,
readable: Bool = false): Image;

public static function create3D(width: Int, height: Int, depth: Int, format: TextureFormat = TextureFormat.RGBA32,
usage: Usage = Usage.StaticUsage): Image;
usage: Usage = Usage.StaticUsage, readable: Bool = false): Image;

public static function fromBytes(bytes: Bytes, width: Int, height: Int, format: TextureFormat = TextureFormat.RGBA32,
usage: Usage = Usage.StaticUsage): Image;
usage: Usage = Usage.StaticUsage, readable: Bool = false): Image;

public static function fromBytes3D(bytes: Bytes, width: Int, height: Int, depth: Int, format: TextureFormat = TextureFormat.RGBA32,
usage: Usage = Usage.StaticUsage): Image;
usage: Usage = Usage.StaticUsage, readable: Bool = false): Image;

public static function fromEncodedBytes(bytes: Bytes, fileExtention: String, doneCallback: Image->Void, errorCallback: String->Void,
readable: Bool = false): Void;
Expand Down

0 comments on commit aaebc16

Please sign in to comment.