Compare commits

...

39 Commits

Author SHA1 Message Date
e2b63c9a1a Merge pull request 'main' (#3) from Gorochu/LNXSDK:main into main
Reviewed-on: #3
2026-05-31 05:25:04 +00:00
c467b54dd0 Update 2026-05-30 22:14:11 -07:00
a428fb684d Update Kha/Backends/Kore-HL/kfile.js 2026-05-30 19:16:41 +00:00
f2076e5568 merge upstream 2026-05-30 18:52:54 +00:00
c3ce85887a Update leenkx/blender/lnx/props_renderpath.py 2026-05-30 02:39:42 +00:00
09b1e513a0 Update leenkx/Sources/leenkx/trait/internal/DebugConsole.hx 2026-05-30 02:35:42 +00:00
ca3e6beca1 Update leenkx/blender/lnx/utils.py 2026-05-29 22:31:30 +00:00
bef25f6a1a Update leenkx/blender/lnx/props_exporter.py 2026-05-29 22:27:11 +00:00
89e6beeed2 Update leenkx/blender/lnx/make.py 2026-05-29 22:25:11 +00:00
c3c8dc2dce Update leenkx/blender/lnx/make.py 2026-05-29 22:23:38 +00:00
5aec4c9c30 Update leenkx/blender/lnx/assets.py 2026-05-29 22:12:50 +00:00
eb5b73a163 Update 2026-05-22 13:06:40 -07:00
b47ea35fe4 Update 2026-05-22 11:54:15 -07:00
05f197c291 Update 2026-05-22 11:48:42 -07:00
0a5075319f Update 2026-05-22 01:09:33 -07:00
c0f390d015 Update 2026-05-22 00:04:16 -07:00
966c915a93 merge upstream 2026-05-22 06:48:44 +00:00
59562de23a Update 2026-05-21 23:44:37 -07:00
877a69d844 Update 2026-05-21 23:40:20 -07:00
9a69764479 Merge pull request 'main' (#124) from Onek8/LNXSDK:main into main
Reviewed-on: LeenkxTeam/LNXSDK#124
2026-05-22 05:04:08 +00:00
3e2915dff7 merge upstream 2026-05-22 05:03:04 +00:00
5b91100d0c Update 2026-05-21 20:21:34 -07:00
add4d4cc87 Update 2026-05-21 20:15:16 -07:00
051ce0b99f Merge pull request 'main' (#123) from Onek8/LNXSDK:main into main
Reviewed-on: LeenkxTeam/LNXSDK#123
2026-05-18 09:21:13 +00:00
fe8bd1e307 merge upstream 2026-05-18 09:20:44 +00:00
d529d8c036 Update 2026-05-18 02:19:41 -07:00
4e0d270abc Merge pull request 'Update' (#122) from Onek8/LNXSDK:main into main
Reviewed-on: LeenkxTeam/LNXSDK#122
2026-05-18 08:03:21 +00:00
6416f0908c Update 2026-05-18 01:02:36 -07:00
b018f7a9b1 Merge pull request 'Update' (#121) from Onek8/LNXSDK:main into main
Reviewed-on: LeenkxTeam/LNXSDK#121
2026-05-18 07:33:03 +00:00
7f9c767bcb Update 2026-05-18 00:31:40 -07:00
5346cbc238 Merge pull request 'main' (#120) from Onek8/LNXSDK:main into main
Reviewed-on: LeenkxTeam/LNXSDK#120
2026-05-18 01:29:39 +00:00
dfca8eb660 merge upstream 2026-05-18 01:29:01 +00:00
acc0d62321 Update 2026-05-17 18:28:03 -07:00
48536e9e80 Merge pull request 'Update' (#119) from Onek8/LNXSDK:main into main
Reviewed-on: LeenkxTeam/LNXSDK#119
2026-05-17 18:10:39 +00:00
8b65973bff Update 2026-05-17 11:09:44 -07:00
c5918926d8 Merge pull request 'main' (#118) from Onek8/LNXSDK:main into main
Reviewed-on: LeenkxTeam/LNXSDK#118
2026-05-17 17:55:02 +00:00
edec5e56fb Update 2026-05-17 10:53:44 -07:00
857e0f1e62 Merge branch 'main' of https://dev.leenkx.com/Onek8/LNXSDK 2026-05-16 18:08:31 -07:00
6a4f995daf Update 2026-05-16 18:08:13 -07:00
8757 changed files with 303943 additions and 71912 deletions

View File

@ -0,0 +1,22 @@
package kha.graphics4;
import haxe.io.Bytes;
import kha.Blob;
class ComputeShader {
public function new(sources: Array<Blob>, files: Array<String>) {
}
public function delete(): Void {
}
public function getConstantLocation(name: String): ConstantLocation {
return null;
}
public function getTextureUnit(name: String): TextureUnit {
return null;
}
}

View File

@ -0,0 +1,24 @@
package kha.graphics4;
class ShaderStorageBuffer {
var data: Array<Int>;
var myCount: Int;
public function new(indexCount: Int, type: VertexData) {
myCount = indexCount;
data = new Array<Int>();
data[myCount - 1] = 0;
}
public function delete(): Void {}
public function lock(): Array<Int> {
return data;
}
public function unlock(): Void {}
public function count(): Int {
return myCount;
}
}

View File

@ -0,0 +1,22 @@
package kha.graphics4;
import haxe.io.Bytes;
import kha.Blob;
class ComputeShader {
public function new(sources: Array<Blob>, files: Array<String>) {
}
public function delete(): Void {
}
public function getConstantLocation(name: String): ConstantLocation {
return null;
}
public function getTextureUnit(name: String): TextureUnit {
return null;
}
}

View File

@ -0,0 +1,24 @@
package kha.graphics4;
class ShaderStorageBuffer {
var data: Array<Int>;
var myCount: Int;
public function new(indexCount: Int, type: VertexData) {
myCount = indexCount;
data = new Array<Int>();
data[myCount - 1] = 0;
}
public function delete(): Void {}
public function lock(): Array<Int> {
return data;
}
public function unlock(): Void {}
public function count(): Int {
return myCount;
}
}

View File

@ -2,9 +2,11 @@ package kha.html5worker;
import kha.arrays.Float32Array; import kha.arrays.Float32Array;
import kha.Canvas; import kha.Canvas;
import kha.graphics4.ComputeShader;
import kha.graphics4.IndexBuffer; import kha.graphics4.IndexBuffer;
import kha.graphics4.MipMapFilter; import kha.graphics4.MipMapFilter;
import kha.graphics4.PipelineState; import kha.graphics4.PipelineState;
import kha.graphics4.ShaderStorageBuffer;
import kha.graphics4.TextureAddressing; import kha.graphics4.TextureAddressing;
import kha.graphics4.TextureFilter; import kha.graphics4.TextureFilter;
import kha.graphics4.Usage; import kha.graphics4.Usage;
@ -342,4 +344,16 @@ class Graphics implements kha.graphics4.Graphics {
public function maxBoundTextures(): Int { public function maxBoundTextures(): Int {
return 16; return 16;
} }
public function setShaderStorageBuffer(buffer: ShaderStorageBuffer, index: Int) {
}
public function setComputeShader(shader: ComputeShader) {
}
public function compute(x: Int, y: Int, z: Int) {
}
} }

View File

@ -27,7 +27,7 @@ class CanvasImage extends Image {
var g2canvas: CanvasGraphics = null; var g2canvas: CanvasGraphics = null;
public static function init() { public static function init() {
var canvas: Dynamic = Browser.document.createElement("canvas"); final canvas = Browser.document.createCanvasElement();
if (canvas != null) { if (canvas != null) {
context = canvas.getContext("2d"); context = canvas.getContext("2d");
canvas.width = 2048; canvas.width = 2048;
@ -56,7 +56,7 @@ class CanvasImage extends Image {
override function get_g2(): kha.graphics2.Graphics { override function get_g2(): kha.graphics2.Graphics {
if (g2canvas == null) { if (g2canvas == null) {
var canvas: Dynamic = Browser.document.createElement("canvas"); final canvas = Browser.document.createCanvasElement();
image = canvas; image = canvas;
var context = canvas.getContext("2d"); var context = canvas.getContext("2d");
canvas.width = width; canvas.width = width;

View File

@ -66,7 +66,7 @@ class Display {
public var pixelsPerInch(get, never): Int; public var pixelsPerInch(get, never): Int;
function get_pixelsPerInch(): Int { function get_pixelsPerInch(): Int {
var dpiElement = Browser.document.createElement("div"); final dpiElement = Browser.document.createDivElement();
dpiElement.style.position = "absolute"; dpiElement.style.position = "absolute";
dpiElement.style.width = "1in"; dpiElement.style.width = "1in";
dpiElement.style.height = "1in"; dpiElement.style.height = "1in";

View File

@ -1,5 +1,6 @@
package kha; package kha;
import js.html.FileReader;
import haxe.io.Bytes; import haxe.io.Bytes;
import js.html.ImageElement; import js.html.ImageElement;
import js.html.CanvasElement; import js.html.CanvasElement;
@ -90,11 +91,29 @@ class Image implements Canvas implements Resource {
public static function fromEncodedBytes(bytes: Bytes, fileExtention: String, doneCallback: Image->Void, errorCallback: String->Void, public static function fromEncodedBytes(bytes: Bytes, fileExtention: String, doneCallback: Image->Void, errorCallback: String->Void,
readable: Bool = false): Void { readable: Bool = false): Void {
var dataUrl = "data:image;base64," + haxe.crypto.Base64.encode(bytes); final mime = switch fileExtention {
var imageElement = cast(js.Browser.document.createElement("img"), ImageElement); case "jpg": 'image/jpeg';
imageElement.onload = function() doneCallback(fromImage(imageElement, readable)); case ext: 'image/$ext';
imageElement.onerror = function() errorCallback("Image was not created"); }
imageElement.src = dataUrl; bufferToBase64(cast bytes.getData(), dataUrl -> {
final imageElement = js.Browser.document.createImageElement();
imageElement.onload = () -> doneCallback(fromImage(imageElement, readable));
imageElement.onerror = () -> errorCallback("Image was not created");
imageElement.src = 'data:$mime;base64,$dataUrl';
}, () -> {
errorCallback("Image was not created");
});
}
static function bufferToBase64(buffer:js.lib.Uint8Array, onLoad:(base64:String)->Void, onError:()->Void) {
final reader = new FileReader();
reader.onload = () -> {
final result:String = reader.result;
// remove the `data:application/octet-stream;base64,` part from the start
onLoad(result.substr(result.indexOf(',') + 1));
}
reader.onerror = () -> onError();
reader.readAsDataURL(new js.html.Blob([buffer]));
} }
public static function fromVideo(video: kha.Video): Image { public static function fromVideo(video: kha.Video): Image {

View File

@ -32,7 +32,7 @@ class LoaderImpl {
}, failed); }, failed);
} }
else { else {
var img: ImageElement = cast Browser.document.createElement("img"); final img = Browser.document.createImageElement();
img.onerror = function(event: Dynamic) failed({url: desc.files[0], error: event}); img.onerror = function(event: Dynamic) failed({url: desc.files[0], error: event});
img.onload = function(event: Dynamic) done(Image.fromImage(img, readable)); img.onload = function(event: Dynamic) done(Image.fromImage(img, readable));
img.crossOrigin = ""; img.crossOrigin = "";
@ -159,9 +159,9 @@ class LoaderImpl {
} }
public static function loadRemote(desc: Dynamic, done: Blob->Void, failed: AssetError->Void) { public static function loadRemote(desc: Dynamic, done: Blob->Void, failed: AssetError->Void) {
var request = untyped new XMLHttpRequest(); var request = new XMLHttpRequest();
request.open("GET", desc.files[0], true); request.open("GET", desc.files[0], true);
request.responseType = "arraybuffer"; request.responseType = ARRAYBUFFER;
request.onreadystatechange = function() { request.onreadystatechange = function() {
if (request.readyState != 4) if (request.readyState != 4)
@ -174,12 +174,6 @@ class LoaderImpl {
var byteArray: Dynamic = Syntax.code("new Uint8Array(arrayBuffer)"); var byteArray: Dynamic = Syntax.code("new Uint8Array(arrayBuffer)");
bytes = Bytes.ofData(byteArray); bytes = Bytes.ofData(byteArray);
} }
else if (request.responseBody != null) {
var data: Dynamic = untyped Syntax.code("VBArray(request.responseBody).toArray()");
bytes = Bytes.alloc(data.length);
for (i in 0...data.length)
bytes.set(i, data[i]);
}
else { else {
failed({url: desc.files[0]}); failed({url: desc.files[0]});
return; return;

View File

@ -6,8 +6,10 @@ import js.html.CanvasElement;
import js.html.ClipboardEvent; import js.html.ClipboardEvent;
import js.html.DeviceMotionEvent; import js.html.DeviceMotionEvent;
import js.html.DeviceOrientationEvent; import js.html.DeviceOrientationEvent;
import js.html.DragEvent;
import js.html.KeyboardEvent; import js.html.KeyboardEvent;
import js.html.MouseEvent; import js.html.MouseEvent;
import js.html.PointerEvent;
import js.html.Touch; import js.html.Touch;
import js.html.TouchEvent; import js.html.TouchEvent;
import js.html.WebSocket; import js.html.WebSocket;
@ -213,6 +215,7 @@ class SystemImpl {
} }
public static function vibrate(ms: Int): Void { public static function vibrate(ms: Int): Void {
if (Browser.navigator.vibrate == null) return;
Browser.navigator.vibrate(ms); Browser.navigator.vibrate(ms);
} }
@ -227,7 +230,7 @@ class SystemImpl {
} }
static inline var maxGamepads: Int = 4; static inline var maxGamepads: Int = 4;
public static var frame: Framebuffer; static var frame: Framebuffer;
static var keyboard: Keyboard = null; static var keyboard: Keyboard = null;
static var mouse: kha.input.Mouse; static var mouse: kha.input.Mouse;
static var surface: Surface; static var surface: Surface;
@ -311,14 +314,14 @@ class SystemImpl {
} }
public static function copyToClipboard(text: String) { public static function copyToClipboard(text: String) {
var textArea = Browser.document.createElement("textarea"); var textArea = Browser.document.createTextAreaElement();
untyped textArea.value = text; textArea.value = text;
textArea.style.top = "0"; textArea.style.top = "0";
textArea.style.left = "0"; textArea.style.left = "0";
textArea.style.position = "fixed"; textArea.style.position = "fixed";
Browser.document.body.appendChild(textArea); Browser.document.body.appendChild(textArea);
textArea.focus(); textArea.focus();
untyped textArea.select(); textArea.select();
try { try {
Browser.document.execCommand("copy"); Browser.document.execCommand("copy");
} }
@ -388,8 +391,7 @@ class SystemImpl {
{ {
alpha: false, alpha: false,
antialias: options.framebuffer.samplesPerPixel > 1, antialias: options.framebuffer.samplesPerPixel > 1,
stencil: true, stencil: true
xrCompatible: true
}); // preserveDrawingBuffer: true } ); Warning: preserveDrawingBuffer can cause huge performance issues on mobile browsers }); // preserveDrawingBuffer: true } ); Warning: preserveDrawingBuffer can cause huge performance issues on mobile browsers
SystemImpl.gl.pixelStorei(GL.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1); SystemImpl.gl.pixelStorei(GL.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1);
@ -418,8 +420,7 @@ class SystemImpl {
{ {
alpha: false, alpha: false,
antialias: options.framebuffer.samplesPerPixel > 1, antialias: options.framebuffer.samplesPerPixel > 1,
stencil: true, stencil: true
xrCompatible: true
}); // preserveDrawingBuffer: true } ); WARNING: preserveDrawingBuffer causes huge performance issues (on mobile browser)! }); // preserveDrawingBuffer: true } ); WARNING: preserveDrawingBuffer causes huge performance issues (on mobile browser)!
SystemImpl.gl.pixelStorei(GL.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1); SystemImpl.gl.pixelStorei(GL.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1);
SystemImpl.gl.getExtension("OES_texture_float"); SystemImpl.gl.getExtension("OES_texture_float");
@ -462,7 +463,7 @@ class SystemImpl {
} }
// canvas.getContext("2d").scale(transform, transform); // canvas.getContext("2d").scale(transform, transform);
if (!mobile && kha.audio2.Audio._init()) { if ((!mobile || options.audio.allowMobileWebAudio) && kha.audio2.Audio._init()) {
SystemImpl._hasWebAudio = true; SystemImpl._hasWebAudio = true;
kha.audio2.Audio1._init(); kha.audio2.Audio1._init();
} }
@ -482,7 +483,7 @@ class SystemImpl {
canvas.focus(); canvas.focus();
#if kha_disable_context_menu #if kha_disable_context_menu
canvas.oncontextmenu = function(event: Dynamic) { canvas.oncontextmenu = function(event: PointerEvent) {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
} }
@ -505,12 +506,12 @@ class SystemImpl {
canvas.addEventListener("touchend", touchUp, false); canvas.addEventListener("touchend", touchUp, false);
canvas.addEventListener("touchmove", touchMove, false); canvas.addEventListener("touchmove", touchMove, false);
canvas.addEventListener("touchcancel", touchCancel, false); canvas.addEventListener("touchcancel", touchCancel, false);
// prevent dragging canvas like images in Firefox
canvas.addEventListener("dragstart", (e: DragEvent) -> e.preventDefault());
// prevent dropping local files on page and replacing page with them
Browser.document.addEventListener("dragover", (e: DragEvent) -> e.preventDefault());
Browser.document.addEventListener("dragover", function(event) { Browser.document.addEventListener("drop", function(event: DragEvent) {
event.preventDefault();
});
Browser.document.addEventListener("drop", function(event: js.html.DragEvent) {
event.preventDefault(); event.preventDefault();
if (event.dataTransfer != null && event.dataTransfer.files != null) { if (event.dataTransfer != null && event.dataTransfer.files != null) {
for (file in event.dataTransfer.files) { for (file in event.dataTransfer.files) {
@ -531,14 +532,7 @@ class SystemImpl {
static function initAnimate(callback: Window->Void) { static function initAnimate(callback: Window->Void) {
var canvas: CanvasElement = getCanvasElement(); var canvas: CanvasElement = getCanvasElement();
var window: Dynamic = Browser.window; final window = Browser.window;
var requestAnimationFrame = window.requestAnimationFrame;
if (requestAnimationFrame == null)
requestAnimationFrame = window.mozRequestAnimationFrame;
if (requestAnimationFrame == null)
requestAnimationFrame = window.webkitRequestAnimationFrame;
if (requestAnimationFrame == null)
requestAnimationFrame = window.msRequestAnimationFrame;
var isRefreshRateDetectionActive = false; var isRefreshRateDetectionActive = false;
var lastTimestamp = 0.0; var lastTimestamp = 0.0;
@ -549,16 +543,7 @@ class SystemImpl {
]; ];
function animate(timestamp) { function animate(timestamp) {
if (untyped Browser.window._khaSkipWindowRender == true) { window.requestAnimationFrame(animate);
if (requestAnimationFrame != null)
requestAnimationFrame(animate);
return;
}
if (requestAnimationFrame == null)
Browser.window.setTimeout(animate, 1000.0 / 60.0);
else
requestAnimationFrame(animate);
var sysGamepads = getGamepads(); var sysGamepads = getGamepads();
if (sysGamepads != null) { if (sysGamepads != null) {
@ -639,64 +624,38 @@ class SystemImpl {
}, 500); }, 500);
Scheduler.start(); Scheduler.start();
requestAnimationFrame(animate); window.requestAnimationFrame(animate);
callback(SystemImpl.window); callback(SystemImpl.window);
} }
public static function lockMouse(): Void { public static function lockMouse(): Void {
untyped if (SystemImpl.khanvas.requestPointerLock) { if (SystemImpl.khanvas.requestPointerLock != null) {
SystemImpl.khanvas.requestPointerLock(); SystemImpl.khanvas.requestPointerLock();
} }
else if (SystemImpl.khanvas.mozRequestPointerLock) {
SystemImpl.khanvas.mozRequestPointerLock();
}
else if (SystemImpl.khanvas.webkitRequestPointerLock) {
SystemImpl.khanvas.webkitRequestPointerLock();
}
} }
public static function unlockMouse(): Void { public static function unlockMouse(): Void {
untyped if (document.exitPointerLock) { if (Browser.document.exitPointerLock != null) {
document.exitPointerLock(); Browser.document.exitPointerLock();
}
else if (document.mozExitPointerLock) {
document.mozExitPointerLock();
}
else if (document.webkitExitPointerLock) {
document.webkitExitPointerLock();
} }
} }
public static function canLockMouse(): Bool { public static function canLockMouse(): Bool {
return Syntax.code("'pointerLockElement' in document || return Syntax.code("'pointerLockElement' in document");
'mozPointerLockElement' in document ||
'webkitPointerLockElement' in document");
} }
public static function isMouseLocked(): Bool { public static function isMouseLocked(): Bool {
return Syntax.code("document.pointerLockElement === kha_SystemImpl.khanvas || return Syntax.code("document.pointerLockElement === kha_SystemImpl.khanvas");
document.mozPointerLockElement === kha_SystemImpl.khanvas ||
document.webkitPointerLockElement === kha_SystemImpl.khanvas");
} }
public static function notifyOfMouseLockChange(func: Void->Void, error: Void->Void): Void { public static function notifyOfMouseLockChange(func: Void->Void, error: Void->Void): Void {
js.Browser.document.addEventListener("pointerlockchange", func, false); js.Browser.document.addEventListener("pointerlockchange", func, false);
js.Browser.document.addEventListener("mozpointerlockchange", func, false);
js.Browser.document.addEventListener("webkitpointerlockchange", func, false);
js.Browser.document.addEventListener("pointerlockerror", error, false); js.Browser.document.addEventListener("pointerlockerror", error, false);
js.Browser.document.addEventListener("mozpointerlockerror", error, false);
js.Browser.document.addEventListener("webkitpointerlockerror", error, false);
} }
public static function removeFromMouseLockChange(func: Void->Void, error: Void->Void): Void { public static function removeFromMouseLockChange(func: Void->Void, error: Void->Void): Void {
js.Browser.document.removeEventListener("pointerlockchange", func, false); js.Browser.document.removeEventListener("pointerlockchange", func, false);
js.Browser.document.removeEventListener("mozpointerlockchange", func, false);
js.Browser.document.removeEventListener("webkitpointerlockchange", func, false);
js.Browser.document.removeEventListener("pointerlockerror", error, false); js.Browser.document.removeEventListener("pointerlockerror", error, false);
js.Browser.document.removeEventListener("mozpointerlockerror", error, false);
js.Browser.document.removeEventListener("webkitpointerlockerror", error, false);
} }
static function setMouseXY(event: MouseEvent): Void { static function setMouseXY(event: MouseEvent): Void {
@ -902,13 +861,6 @@ class SystemImpl {
var movementX = event.movementX; var movementX = event.movementX;
var movementY = event.movementY; var movementY = event.movementY;
if (event.movementX == null) {
movementX = (untyped event.mozMovementX != null) ? untyped event.mozMovementX : ((untyped event.webkitMovementX != null) ? untyped event.webkitMovementX : (mouseX
- lastMouseX));
movementY = (untyped event.mozMovementY != null) ? untyped event.mozMovementY : ((untyped event.webkitMovementY != null) ? untyped event.webkitMovementY : (mouseY
- lastMouseY));
}
// this ensures same behaviour across browser until they fix it // this ensures same behaviour across browser until they fix it
if (firefox) { if (firefox) {
movementX = Std.int(movementX * Browser.window.devicePixelRatio); movementX = Std.int(movementX * Browser.window.devicePixelRatio);
@ -956,7 +908,9 @@ class SystemImpl {
} }
setTouchXY(touch); setTouchXY(touch);
mouse.sendDownEvent(0, 0, touchX, touchY); if (!Surface.listenedEventsBefore) {
mouse.sendDownEvent(0, 0, touchX, touchY);
}
surface.sendTouchStartEvent(id, touchX, touchY); surface.sendTouchStartEvent(id, touchX, touchY);
if (index == 0) { if (index == 0) {
lastFirstTouchX = touchX; lastFirstTouchX = touchX;
@ -979,7 +933,9 @@ class SystemImpl {
} }
setTouchXY(touch); setTouchXY(touch);
mouse.sendUpEvent(0, 0, touchX, touchY); if (!Surface.listenedEventsBefore) {
mouse.sendUpEvent(0, 0, touchX, touchY);
}
surface.sendTouchEndEvent(id, touchX, touchY); surface.sendTouchEndEvent(id, touchX, touchY);
} }
insideInputEvent = false; insideInputEvent = false;
@ -998,7 +954,9 @@ class SystemImpl {
lastFirstTouchX = touchX; lastFirstTouchX = touchX;
lastFirstTouchY = touchY; lastFirstTouchY = touchY;
mouse.sendMoveEvent(0, touchX, touchY, movementX, movementY); if (!Surface.listenedEventsBefore) {
mouse.sendMoveEvent(0, touchX, touchY, movementX, movementY);
}
} }
var id = touch.identifier; var id = touch.identifier;
if (ios) if (ios)
@ -1020,7 +978,9 @@ class SystemImpl {
id = iosTouchs.indexOf(id); id = iosTouchs.indexOf(id);
setTouchXY(touch); setTouchXY(touch);
mouse.sendUpEvent(0, 0, touchX, touchY); if (!Surface.listenedEventsBefore) {
mouse.sendUpEvent(0, 0, touchX, touchY);
}
surface.sendTouchEndEvent(id, touchX, touchY); surface.sendTouchEndEvent(id, touchX, touchY);
} }
iosTouchs = []; iosTouchs = [];
@ -1311,15 +1271,45 @@ class SystemImpl {
return "unknown"; return "unknown";
} }
public static function setGamepadRumble(index: Int, leftAmount: Float, rightAmount: Float) {} public static function setGamepadRumble(index: Int, leftAmount: Float, rightAmount: Float): Void {
final sysGamepads = getGamepads();
if (sysGamepads == null || sysGamepads[index] == null) {
return;
}
final gamepad = sysGamepads[index];
final duration = 10000; // 10 seconds
if (untyped gamepad.vibrationActuator) {
if (leftAmount == 0 && rightAmount == 0) {
untyped gamepad.vibrationActuator.reset();
}
else {
untyped gamepad.vibrationActuator.playEffect('dual-rumble', {
duration: duration,
strongMagnitude: leftAmount,
weakMagnitude: rightAmount
});
}
}
else if (untyped gamepad.hapticActuators && untyped gamepad.hapticActuators.length > 0) {
final hapticActuator = untyped gamepad.hapticActuators[0];
if (leftAmount == 0 && rightAmount == 0) {
untyped gamepad.hapticActuators[0].pulse(0, 0);
}
else {
untyped gamepad.hapticActuators[0].pulse(leftAmount, duration);
}
}
}
static function getGamepads(): Array<js.html.Gamepad> { static function getGamepads(): Array<js.html.Gamepad> {
if (chrome && kha.vr.VrInterface.instance != null && kha.vr.VrInterface.instance.IsVrEnabled()) { if (chrome && kha.vr.VrInterface.instance != null && kha.vr.VrInterface.instance.IsVrEnabled()) {
return null; // Chrome crashes if navigator.getGamepads() is called when using VR return null; // Chrome crashes if navigator.getGamepads() is called when using VR
} }
if (untyped navigator.getGamepads) { if (Browser.navigator.getGamepads != null) {
return js.Browser.navigator.getGamepads(); return Browser.navigator.getGamepads();
} }
else { else {
return null; return null;

View File

@ -21,7 +21,6 @@ class Window {
this.defaultHeight = defaultHeight; this.defaultHeight = defaultHeight;
windows.push(this); windows.push(this);
resizeCallbacks[num] = []; resizeCallbacks[num] = [];
windows.push(this);
final observer: MutationObserver = new MutationObserver(function(mutations: Array<js.html.MutationRecord>, observer: MutationObserver) { final observer: MutationObserver = new MutationObserver(function(mutations: Array<js.html.MutationRecord>, observer: MutationObserver) {
var isResize = false; var isResize = false;
for (mutation in mutations) { for (mutation in mutations) {

View File

@ -1,14 +1,14 @@
package kha.audio2; package kha.audio2;
import js.Syntax;
import js.Browser; import js.Browser;
import js.Syntax;
import js.html.URL; import js.html.URL;
import js.html.audio.AudioContext; import js.html.audio.AudioContext;
import js.html.audio.AudioProcessingEvent; import js.html.audio.AudioProcessingEvent;
import js.html.audio.ScriptProcessorNode; import js.html.audio.ScriptProcessorNode;
import kha.Sound;
import kha.internal.IntBox; import kha.internal.IntBox;
import kha.js.AEAudioChannel; import kha.js.AEAudioChannel;
import kha.Sound;
class Audio { class Audio {
public static var disableGcInteractions = false; public static var disableGcInteractions = false;
@ -70,7 +70,7 @@ class Audio {
public static var samplesPerSecond: Int; public static var samplesPerSecond: Int;
public static var audioCallback: kha.internal.IntBox->Buffer->Void; public static var audioCallback: (outputBufferLength: IntBox, buffer: Buffer) -> Void;
static var virtualChannels: Array<VirtualStreamChannel> = []; static var virtualChannels: Array<VirtualStreamChannel> = [];

View File

@ -1,5 +1,6 @@
package kha.capture; package kha.capture;
import js.Browser.navigator;
import js.html.audio.AudioProcessingEvent; import js.html.audio.AudioProcessingEvent;
import kha.audio2.Buffer; import kha.audio2.Buffer;
@ -16,8 +17,8 @@ class AudioCapture {
return; return;
} }
var getUserMedia = untyped __js__("navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia"); final getUserMedia = (navigator : Dynamic).getUserMedia;
getUserMedia.call(js.Browser.navigator, {audio: true}, function(stream: Dynamic) { getUserMedia.call(navigator, {audio: true}, function(stream: Dynamic) {
input = kha.audio2.Audio._context.createMediaStreamSource(stream); input = kha.audio2.Audio._context.createMediaStreamSource(stream);
var bufferSize = 1024 * 2; var bufferSize = 1024 * 2;

View File

@ -1,12 +1,13 @@
package kha.capture; package kha.capture;
import js.Browser.navigator;
import js.Browser; import js.Browser;
class VideoCapture { class VideoCapture {
public static function init(initialized: kha.Video->Void, error: Void->Void): Void { public static function init(initialized: kha.Video->Void, error: Void->Void): Void {
var getUserMedia = untyped __js__("navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia"); final getUserMedia = (navigator : Dynamic).getUserMedia;
getUserMedia.call(js.Browser.navigator, {audio: true, video: true}, function(stream: Dynamic) { getUserMedia.call(navigator, {audio: true, video: true}, function(stream: Dynamic) {
var element: js.html.VideoElement = cast Browser.document.createElement("video"); final element = Browser.document.createVideoElement();
element.srcObject = stream; element.srcObject = stream;
element.onloadedmetadata = function(e) { element.onloadedmetadata = function(e) {
initialized(kha.js.Video.fromElement(element)); initialized(kha.js.Video.fromElement(element));

View File

@ -0,0 +1,22 @@
package kha.graphics4;
import haxe.io.Bytes;
import kha.Blob;
class ComputeShader {
public function new(sources: Array<Blob>, files: Array<String>) {
}
public function delete(): Void {
}
public function getConstantLocation(name: String): ConstantLocation {
return null;
}
public function getTextureUnit(name: String): TextureUnit {
return null;
}
}

View File

@ -0,0 +1,24 @@
package kha.graphics4;
class ShaderStorageBuffer {
var data: Array<Int>;
var myCount: Int;
public function new(indexCount: Int, type: VertexData) {
myCount = indexCount;
data = new Array<Int>();
data[myCount - 1] = 0;
}
public function delete(): Void {}
public function lock(): Array<Int> {
return data;
}
public function unlock(): Void {}
public function count(): Int {
return myCount;
}
}

View File

@ -105,18 +105,7 @@ class CanvasGraphics extends Graphics {
} }
override function set_imageScaleQuality(value: ImageScaleQuality): ImageScaleQuality { override function set_imageScaleQuality(value: ImageScaleQuality): ImageScaleQuality {
if (value == ImageScaleQuality.Low) { canvas.imageSmoothingEnabled = value == ImageScaleQuality.High;
untyped canvas.mozImageSmoothingEnabled = false;
untyped canvas.webkitImageSmoothingEnabled = false;
untyped canvas.msImageSmoothingEnabled = false;
canvas.imageSmoothingEnabled = false;
}
else {
untyped canvas.mozImageSmoothingEnabled = true;
untyped canvas.webkitImageSmoothingEnabled = true;
untyped canvas.msImageSmoothingEnabled = true;
canvas.imageSmoothingEnabled = true;
}
return scaleQuality = value; return scaleQuality = value;
} }

View File

@ -0,0 +1,28 @@
package kha.js;
import js.html.MessageChannel;
class Microtask {
static var messageChannel: MessageChannel;
static final callbacks: Array<() -> Void> = [];
static function init(): Void {
if (messageChannel != null) {
return;
}
messageChannel = new MessageChannel();
messageChannel.port1.onmessage = _ -> {
final copy = callbacks.copy();
callbacks.resize(0);
for (callback in copy) {
callback();
}
};
}
public static function queueMicrotask(callback: () -> Void): Void {
init();
callbacks.push(callback);
messageChannel.port2.postMessage(js.Lib.undefined);
}
}

View File

@ -32,7 +32,7 @@ class Video extends kha.Video {
video.done = done; video.done = done;
video.element = cast Browser.document.createElement("video"); video.element = Browser.document.createVideoElement();
video.filenames = []; video.filenames = [];
for (filename in filenames) { for (filename in filenames) {

View File

@ -16,7 +16,7 @@ import kha.audio2.Audio;
super(); super();
this.offset = 0; this.offset = 0;
this.buffer = buffer; this.buffer = buffer;
this.startTime = Audio._context.currentTime; this.startTime = Audio._context.currentTime;
this.source = Audio._context.createBufferSource(); this.source = Audio._context.createBufferSource();
this.source.buffer = this.buffer; this.source.buffer = this.buffer;
this.source.connect(Audio._context.destination); this.source.connect(Audio._context.destination);
@ -91,7 +91,7 @@ class WebAudioSound extends kha.Sound {
var i = 0; var i = 0;
final lidx = len * 2; final lidx = len * 2;
function uncompressInner() { function uncompressInner() {
var chk_len = idx + 11025; var chk_len = idx + 44100;
var next_chk = chk_len > lidx ? lidx : chk_len; var next_chk = chk_len > lidx ? lidx : chk_len;
while (idx < next_chk) { while (idx < next_chk) {
uncompressedData[idx] = ch0[i]; uncompressedData[idx] = ch0[i];
@ -100,7 +100,7 @@ class WebAudioSound extends kha.Sound {
++i; ++i;
} }
if (idx < lidx) if (idx < lidx)
js.Browser.window.setTimeout(uncompressInner, 0); Microtask.queueMicrotask(uncompressInner);
else { else {
compressedData = null; compressedData = null;
done(); done();

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,22 @@
package kha.graphics4;
import haxe.io.Bytes;
import kha.Blob;
class ComputeShader {
public function new(sources: Array<Blob>, files: Array<String>) {
}
public function delete(): Void {
}
public function getConstantLocation(name: String): ConstantLocation {
return null;
}
public function getTextureUnit(name: String): TextureUnit {
return null;
}
}

View File

@ -0,0 +1,24 @@
package kha.graphics4;
class ShaderStorageBuffer {
var data: Array<Int>;
var myCount: Int;
public function new(indexCount: Int, type: VertexData) {
myCount = indexCount;
data = new Array<Int>();
data[myCount - 1] = 0;
}
public function delete(): Void {}
public function lock(): Array<Int> {
return data;
}
public function unlock(): Void {}
public function count(): Int {
return myCount;
}
}

View File

@ -1,31 +0,0 @@
let project = new Project('Kha', __dirname);
project.addFiles('kinc-bridge/**', 'hl/include/**', 'hl/src/std/**', 'hl/src/gc.c', 'hl/src/hl.h', 'hl/src/hlc.h', 'hl/src/hlmodule.h', 'hl/src/opcodes.h');
project.addExcludes('hl/src/std/unicase.c', 'hl/src/std/debug.c', 'hl/include/pcre/pcre2_jit_match.c', 'hl/include/pcre/pcre2_jit_misc.c');
project.addIncludeDirs('hl/src', 'hl/include/pcre', 'hl/include/mbedtls/include', 'hl/include/zlib');
project.addFiles('hl/include/mbedtls/library/**', 'hl/include/zlib/**', 'hl/libs/fmt/fmt.c', 'hl/libs/fmt/sha1.c', 'hl/libs/ssl/ssl.c');
if (platform == Platform.OSX) project.addDefine('KORE_DEBUGDIR="osx-hl"');
if (platform == Platform.iOS) project.addDefine('KORE_DEBUGDIR="ios-hl"');
if (platform !== Platform.Windows || audio !== AudioApi.DirectSound) {
project.addDefine('KORE_MULTITHREADED_AUDIO');
project.addDefine('KINC_MULTITHREADED_AUDIO');
}
project.addDefine('KORE');
project.addDefine('KOREC');
project.addDefine('ROTATE90');
project.addDefine('LIBHL_STATIC');
project.addDefine('PCRE2_CODE_UNIT_WIDTH=16');
project.addDefine('HAVE_CONFIG_H');
project.cStd = 'c11';
if (platform === Platform.Windows || platform === Platform.WindowsApp) {
project.addDefine('_WINSOCK_DEPRECATED_NO_WARNINGS');
}
if (platform === Platform.Windows) {
project.addLib('ws2_32');
project.addLib('Crypt32'); // SSL
}
resolve(project);

View File

@ -1,463 +0,0 @@
package kha;
import haxe.io.Bytes;
import haxe.io.BytesData;
import kha.korehl.graphics4.TextureUnit;
import kha.graphics4.TextureFormat;
import kha.graphics4.DepthStencilFormat;
import kha.graphics4.Usage;
class Image implements Canvas implements Resource {
public var _texture: Pointer;
public var _renderTarget: Pointer;
public var _textureArray: Pointer;
public var _textureArrayTextures: Pointer;
var myFormat: TextureFormat;
var readable: Bool;
var graphics1: kha.graphics1.Graphics;
var graphics2: kha.graphics2.Graphics;
var graphics4: kha.graphics4.Graphics;
public static function fromVideo(video: Video): Image {
var image = new Image(false);
image.myFormat = TextureFormat.RGBA32;
image.initVideo(cast(video, kha.korehl.Video));
return image;
}
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, 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,
antiAliasingSamples: Int = 1): Image {
return create2(width, height, format == null ? TextureFormat.RGBA32 : format, false, true, depthStencil);
}
// public static function createArray(images: Array<Image>, format: TextureFormat = null): Image {
// var image = new Image(false);
// image.myFormat = (format == null) ? TextureFormat.RGBA32 : format;
// initArrayTexture(image, images);
// return image;
// }
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));
return image;
}
function initFromBytes(bytes: BytesData, width: Int, height: Int, format: Int): Void {
_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,
readable: Bool = false): Image {
var image = new Image(readable);
image.myFormat = format;
image.initFromBytes3D(bytes.getData(), width, height, depth, getTextureFormat(format));
return image;
}
function initFromBytes3D(bytes: BytesData, width: Int, height: Int, depth: Int, format: Int): Void {
_texture = kinc_texture_from_bytes3d(bytes.bytes, width, height, depth, format, readable);
}
public static function fromEncodedBytes(bytes: Bytes, format: String, doneCallback: Image->Void, errorCallback: String->Void,
readable: Bool = false): Void {
var image = new Image(readable);
var isFloat = format == "hdr" || format == "HDR";
image.myFormat = isFloat ? TextureFormat.RGBA128 : TextureFormat.RGBA32;
image.initFromEncodedBytes(bytes.getData(), format);
doneCallback(image);
}
function initFromEncodedBytes(bytes: BytesData, format: String): Void {
_texture = kinc_texture_from_encoded_bytes(bytes.bytes, bytes.length, StringHelper.convert(format), readable);
}
function new(readable: Bool) {
this.readable = readable;
}
static function getRenderTargetFormat(format: TextureFormat): Int {
switch (format) {
case RGBA32: // Target32Bit
return 0;
case RGBA64: // Target64BitFloat
return 1;
case RGBA128: // Target128BitFloat
return 3;
case DEPTH16: // Target16BitDepth
return 4;
default:
return 0;
}
}
static function getDepthBufferBits(depthAndStencil: DepthStencilFormat): Int {
return switch (depthAndStencil) {
case NoDepthAndStencil: -1;
case DepthOnly: 24;
case DepthAutoStencilAuto: 24;
case Depth24Stencil8: 24;
case Depth32Stencil8: 32;
case Depth16: 16;
}
}
static function getStencilBufferBits(depthAndStencil: DepthStencilFormat): Int {
return switch (depthAndStencil) {
case NoDepthAndStencil: -1;
case DepthOnly: -1;
case DepthAutoStencilAuto: 8;
case Depth24Stencil8: 8;
case Depth32Stencil8: 8;
case Depth16: 0;
}
}
static function getTextureFormat(format: TextureFormat): Int {
switch (format) {
case RGBA32:
return 0;
case RGBA128:
return 3;
case RGBA64:
return 4;
case A32:
return 5;
case A16:
return 7;
default:
return 1; // Grey8
}
}
public static function create2(width: Int, height: Int, format: TextureFormat, readable: Bool, renderTarget: Bool,
depthStencil: DepthStencilFormat): Image {
var image = new Image(readable);
image.myFormat = format;
if (renderTarget)
image.initRenderTarget(width, height, getDepthBufferBits(depthStencil), getRenderTargetFormat(format), getStencilBufferBits(depthStencil));
else
image.init(width, height, format);
return image;
}
public static function create3(width: Int, height: Int, depth: Int, format: TextureFormat, readable: Bool, contextId: Int): Image {
var image = new Image(readable);
image.myFormat = format;
image.init3D(width, height, depth, getTextureFormat(format));
return image;
}
function initRenderTarget(width: Int, height: Int, depthBufferBits: Int, format: Int, stencilBufferBits: Int): Void {
_renderTarget = kinc_render_target_create(width, height, depthBufferBits, format, stencilBufferBits);
_texture = null;
}
function init(width: Int, height: Int, format: Int): Void {
_texture = kinc_texture_create(width, height, format, readable);
_renderTarget = null;
}
function init3D(width: Int, height: Int, depth: Int, format: Int): Void {
_texture = kinc_texture_create3d(width, height, depth, format, readable);
_renderTarget = null;
}
function initVideo(video: kha.korehl.Video): Void {
_texture = kinc_video_get_current_image(video._video);
_renderTarget = null;
}
public static function fromFile(filename: String, readable: Bool): Image {
var image = new Image(readable);
var isFloat = StringTools.endsWith(filename, ".hdr");
image.myFormat = isFloat ? TextureFormat.RGBA128 : TextureFormat.RGBA32;
image.initFromFile(filename);
if (image._texture == null) {
return null;
}
return image;
}
function initFromFile(filename: String): Void {
_texture = kinc_texture_create_from_file(StringHelper.convert(filename), readable);
_renderTarget = null;
}
public var g1(get, never): kha.graphics1.Graphics;
function get_g1(): kha.graphics1.Graphics {
if (graphics1 == null) {
graphics1 = new kha.graphics2.Graphics1(this);
}
return graphics1;
}
public var g2(get, never): kha.graphics2.Graphics;
function get_g2(): kha.graphics2.Graphics {
if (graphics2 == null) {
graphics2 = new kha.korehl.graphics4.Graphics2(this);
}
return graphics2;
}
public var g4(get, never): kha.graphics4.Graphics;
function get_g4(): kha.graphics4.Graphics {
if (graphics4 == null) {
graphics4 = new kha.korehl.graphics4.Graphics(this);
}
return graphics4;
}
public static var maxSize(get, never): Int;
static function get_maxSize(): Int {
return 4096;
}
public static var nonPow2Supported(get, never): Bool;
static function get_nonPow2Supported(): Bool {
return kinc_non_pow2_textures_supported();
}
public static function renderTargetsInvertedY(): Bool {
return kinc_graphics_render_targets_inverted_y();
}
public var width(get, never): Int;
function get_width(): Int {
return _texture != null ? kinc_texture_get_width(_texture) : kinc_render_target_get_width(_renderTarget);
}
public var height(get, never): Int;
function get_height(): Int {
return _texture != null ? kinc_texture_get_height(_texture) : kinc_render_target_get_height(_renderTarget);
}
public var depth(get, never): Int;
function get_depth(): Int {
return 1;
}
public var format(get, never): TextureFormat;
function get_format(): TextureFormat {
return myFormat;
}
public var realWidth(get, never): Int;
function get_realWidth(): Int {
return _texture != null ? kinc_texture_get_real_width(_texture) : kinc_render_target_get_real_width(_renderTarget);
}
public var realHeight(get, never): Int;
function get_realHeight(): Int {
return _texture != null ? kinc_texture_get_real_height(_texture) : kinc_render_target_get_real_height(_renderTarget);
}
public var stride(get, never): Int;
function get_stride(): Int {
return _texture != null ? kinc_texture_get_stride(_texture) : (formatByteSize(myFormat) * width);
}
public function isOpaque(x: Int, y: Int): Bool {
return atInternal(x, y) & 0xff != 0;
}
function atInternal(x: Int, y: Int): Int {
return kinc_texture_at(_texture, x, y);
}
public inline function at(x: Int, y: Int): Color {
return Color.fromValue(atInternal(x, y));
}
public function unload(): Void {
_texture != null ? kinc_texture_unload(_texture) : kinc_render_target_unload(_renderTarget);
}
var bytes: Bytes = null;
public function lock(level: Int = 0): Bytes {
bytes = Bytes.alloc(formatByteSize(myFormat) * width * height);
return bytes;
}
public function unlock(): Void {
kinc_texture_unlock(_texture, bytes.getData().bytes);
bytes = null;
}
var pixels: Bytes = null;
public function getPixels(): Bytes {
if (_renderTarget == null)
return null;
if (pixels == null) {
var size = formatByteSize(myFormat) * width * height;
pixels = Bytes.alloc(size);
}
kinc_render_target_get_pixels(_renderTarget, pixels.getData().bytes);
return pixels;
}
static function formatByteSize(format: TextureFormat): Int {
return switch (format) {
case RGBA32: 4;
case L8: 1;
case RGBA128: 16;
case DEPTH16: 2;
case RGBA64: 8;
case A32: 4;
case A16: 2;
default: 4;
}
}
public function generateMipmaps(levels: Int): Void {
_texture != null ? kinc_generate_mipmaps_texture(_texture, levels) : kinc_generate_mipmaps_target(_renderTarget, levels);
}
public function setMipmaps(mipmaps: Array<Image>): Void {
for (i in 0...mipmaps.length) {
var image = mipmaps[i];
var level = i + 1;
kinc_set_mipmap_texture(_texture, image._texture, level);
}
}
public function setDepthStencilFrom(image: Image): Void {
kinc_render_target_set_depth_stencil_from(_renderTarget, image._renderTarget);
}
public function clear(x: Int, y: Int, z: Int, width: Int, height: Int, depth: Int, color: Color): Void {
kinc_texture_clear(_texture, x, y, z, width, height, depth, color);
}
@:hlNative("std", "kinc_texture_create") static function kinc_texture_create(width: Int, height: Int, format: Int, readable: Bool): Pointer {
return null;
}
@:hlNative("std", "kinc_texture_create_from_file") static function kinc_texture_create_from_file(filename: hl.Bytes, readable: Bool): Pointer {
return null;
}
@:hlNative("std", "kinc_texture_create3d") static function kinc_texture_create3d(width: Int, height: Int, depth: Int, format: Int,
readable: Bool): Pointer {
return null;
}
@:hlNative("std", "kinc_video_get_current_image") static function kinc_video_get_current_image(video: Pointer): Pointer {
return null;
}
@:hlNative("std", "kinc_texture_from_bytes") static function kinc_texture_from_bytes(bytes: Pointer, width: Int, height: Int, format: Int,
readable: Bool): Pointer {
return null;
}
@:hlNative("std", "kinc_texture_from_bytes3d") static function kinc_texture_from_bytes3d(bytes: Pointer, width: Int, height: Int, depth: Int, format: Int,
readable: Bool): Pointer {
return null;
}
@:hlNative("std", "kinc_texture_from_encoded_bytes") static function kinc_texture_from_encoded_bytes(bytes: Pointer, length: Int, format: hl.Bytes,
readable: Bool): Pointer {
return null;
}
@:hlNative("std", "kinc_non_pow2_textures_supported") static function kinc_non_pow2_textures_supported(): Bool {
return false;
}
@:hlNative("std", "kinc_graphics_render_targets_inverted_y") static function kinc_graphics_render_targets_inverted_y(): Bool {
return false;
}
@:hlNative("std", "kinc_texture_get_width") static function kinc_texture_get_width(texture: Pointer): Int {
return 0;
}
@:hlNative("std", "kinc_texture_get_height") static function kinc_texture_get_height(texture: Pointer): Int {
return 0;
}
@:hlNative("std", "kinc_texture_get_real_width") static function kinc_texture_get_real_width(texture: Pointer): Int {
return 0;
}
@:hlNative("std", "kinc_texture_get_real_height") static function kinc_texture_get_real_height(texture: Pointer): Int {
return 0;
}
@:hlNative("std", "kinc_texture_get_stride") static function kinc_texture_get_stride(texture: Pointer): Int {
return 0;
}
@:hlNative("std", "kinc_texture_at") static function kinc_texture_at(texture: Pointer, x: Int, y: Int): Int {
return 0;
}
@:hlNative("std", "kinc_texture_unload") static function kinc_texture_unload(texture: Pointer): Void {}
@:hlNative("std", "kinc_render_target_unload") static function kinc_render_target_unload(renderTarget: Pointer): Void {}
@:hlNative("std", "kinc_render_target_create") static function kinc_render_target_create(width: Int, height: Int, depthBufferBits: Int, format: Int,
stencilBufferBits: Int): Pointer {
return null;
}
@:hlNative("std", "kinc_render_target_get_width") static function kinc_render_target_get_width(renderTarget: Pointer): Int {
return 0;
}
@:hlNative("std", "kinc_render_target_get_height") static function kinc_render_target_get_height(renderTarget: Pointer): Int {
return 0;
}
@:hlNative("std", "kinc_render_target_get_real_width") static function kinc_render_target_get_real_width(renderTarget: Pointer): Int {
return 0;
}
@:hlNative("std", "kinc_render_target_get_real_height") static function kinc_render_target_get_real_height(renderTarget: Pointer): Int {
return 0;
}
@:hlNative("std", "kinc_texture_unlock") static function kinc_texture_unlock(texture: Pointer, bytes: Pointer): Void {}
@:hlNative("std", "kinc_render_target_get_pixels") static function kinc_render_target_get_pixels(renderTarget: Pointer, pixels: Pointer): Void {}
@:hlNative("std", "kinc_generate_mipmaps_texture") static function kinc_generate_mipmaps_texture(texture: Pointer, levels: Int): Void {}
@:hlNative("std", "kinc_generate_mipmaps_target") static function kinc_generate_mipmaps_target(renderTarget: Pointer, levels: Int): Void {}
@:hlNative("std", "kinc_set_mipmap_texture") static function kinc_set_mipmap_texture(texture: Pointer, mipmap: Pointer, level: Int): Void {}
@:hlNative("std", "kinc_render_target_set_depth_stencil_from") static function kinc_render_target_set_depth_stencil_from(renderTarget: Pointer,
from: Pointer): Int {
return 0;
}
@:hlNative("std", "kinc_texture_clear") static function kinc_texture_clear(texture: Pointer, x: Int, y: Int, z: Int, width: Int, height: Int, depth: Int,
color: Color): Void {}
}

View File

@ -1,496 +0,0 @@
package kha;
import kha.graphics4.TextureFormat;
import kha.input.Gamepad;
import kha.input.KeyCode;
import kha.input.Keyboard;
import kha.input.Mouse;
import kha.input.MouseImpl;
import kha.input.Pen;
import kha.input.Surface;
import kha.System;
class SystemImpl {
static var framebuffer: Framebuffer;
static var keyboard: Keyboard;
static var mouse: kha.input.Mouse;
static var pen: kha.input.Pen;
static var gamepads: Array<Gamepad>;
static var surface: Surface;
static var mouseLockListeners: Array<Void->Void>;
public static function init(options: SystemOptions, callback: Window->Void): Void {
haxe.Log.trace = function(v: Dynamic, ?infos: haxe.PosInfos) {
var message = infos != null ? infos.className + ":" + infos.lineNumber + ": " + v : Std.string(v);
kinc_log(StringHelper.convert(message));
};
init_kore(StringHelper.convert(options.title), options.width, options.height, options.framebuffer.samplesPerPixel, options.framebuffer.verticalSync,
cast options.window.mode, options.window.windowFeatures);
new Window(0);
Scheduler.init();
Shaders.init();
var g4 = new kha.korehl.graphics4.Graphics();
framebuffer = new Framebuffer(0, null, null, g4);
framebuffer.init(new kha.graphics2.Graphics1(framebuffer), new kha.korehl.graphics4.Graphics2(framebuffer), g4);
final samplesRef: hl.Ref<Int> = kha.audio2.Audio.samplesPerSecond;
kinc_init_audio(kha.audio2.Audio._callCallback, kha.audio2.Audio._readSample, samplesRef);
kha.audio2.Audio.samplesPerSecond = samplesRef.get();
kha.audio1.Audio._init();
kha.audio2.Audio._init();
keyboard = new kha.input.Keyboard();
mouse = new kha.input.MouseImpl();
pen = new kha.input.Pen();
gamepads = new Array<Gamepad>();
for (i in 0...4) {
gamepads[i] = new kha.input.Gamepad(i);
gamepads[i].connected = kinc_gamepad_connected(i);
}
surface = new kha.input.Surface();
mouseLockListeners = new Array();
kinc_register_keyboard(keyDown, keyUp, keyPress);
kinc_register_mouse(mouseDown, mouseUp, mouseMove, mouseWheel);
kinc_register_pen(penDown, penUp, penMove);
kinc_register_gamepad(gamepadAxis, gamepadButton);
kinc_register_surface(touchStart, touchEnd, touchMove);
kinc_register_sensor(kha.input.Sensor._accelerometerChanged, kha.input.Sensor._gyroscopeChanged);
kinc_register_callbacks(foreground, resume, pause, background, shutdown);
kinc_register_dropfiles(dropFiles);
kinc_register_copycutpaste(copy, cut, paste);
Scheduler.start();
callback(Window.get(0));
run_kore();
}
public static function initEx(title: String, options: Array<WindowOptions>, windowCallback: Int->Void, callback: Void->Void): Void {}
@:keep
public static function frame(): Void {
Scheduler.executeFrame();
System.render([framebuffer]);
for (i in 0...4) {
if (gamepads[i].connected && !kinc_gamepad_connected(i)) {
Gamepad.sendDisconnectEvent(i);
}
else if (!gamepads[i].connected && kinc_gamepad_connected(i)) {
Gamepad.sendConnectEvent(i);
}
}
}
public static function getTime(): Float {
return kinc_get_time();
}
public static function windowWidth(windowId: Int): Int {
return kinc_get_window_width(windowId);
}
public static function windowHeight(windowId: Int): Int {
return kinc_get_window_height(windowId);
}
public static function getScreenRotation(): ScreenRotation {
return ScreenRotation.RotationNone;
}
public static function getSystemId(): String {
final b: hl.Bytes = kinc_get_system_id();
return @:privateAccess String.fromUTF8(b);
}
public static function vibrate(ms: Int): Void {
kinc_vibrate(ms);
}
public static function getLanguage(): String {
final b: hl.Bytes = kinc_get_language();
return @:privateAccess String.fromUTF8(b);
}
public static function requestShutdown(): Bool {
kinc_request_shutdown();
return true;
}
public static function getMouse(num: Int): Mouse {
if (num != 0)
return null;
return mouse;
}
public static function getPen(num: Int): Pen {
if (num != 0)
return null;
return pen;
}
public static function getKeyboard(num: Int): Keyboard {
if (num != 0)
return null;
return keyboard;
}
public static function lockMouse(windowId: Int = 0): Void {
if (!isMouseLocked()) {
kinc_mouse_lock(windowId);
for (listener in mouseLockListeners) {
listener();
}
}
}
public static function unlockMouse(windowId: Int = 0): Void {
if (isMouseLocked()) {
kinc_mouse_unlock(windowId);
for (listener in mouseLockListeners) {
listener();
}
}
}
public static function canLockMouse(windowId: Int = 0): Bool {
return kinc_can_lock_mouse(windowId);
}
public static function isMouseLocked(windowId: Int = 0): Bool {
return kinc_is_mouse_locked(windowId);
}
public static function notifyOfMouseLockChange(func: Void->Void, error: Void->Void): Void {
if (canLockMouse(0) && func != null) {
mouseLockListeners.push(func);
}
}
public static function removeFromMouseLockChange(func: Void->Void, error: Void->Void): Void {
if (canLockMouse(0) && func != null) {
mouseLockListeners.remove(func);
}
}
public static function hideSystemCursor(): Void {
kinc_show_mouse(false);
}
public static function showSystemCursor(): Void {
kinc_show_mouse(true);
}
public static function keyDown(code: KeyCode): Void {
keyboard.sendDownEvent(code);
}
public static function keyUp(code: KeyCode): Void {
keyboard.sendUpEvent(code);
}
public static function keyPress(char: Int): Void {
keyboard.sendPressEvent(String.fromCharCode(char));
}
public static function mouseDown(windowId: Int, button: Int, x: Int, y: Int): Void {
mouse.sendDownEvent(windowId, button, x, y);
}
public static function mouseUp(windowId: Int, button: Int, x: Int, y: Int): Void {
mouse.sendUpEvent(windowId, button, x, y);
}
public static function mouseMove(windowId: Int, x: Int, y: Int, movementX: Int, movementY: Int): Void {
mouse.sendMoveEvent(windowId, x, y, movementX, movementY);
}
public static function mouseWheel(windowId: Int, delta: Int): Void {
mouse.sendWheelEvent(windowId, delta);
}
public static function mouseLeave(windowId: Int): Void {
mouse.sendLeaveEvent(windowId);
}
public static function penDown(windowId: Int, x: Int, y: Int, pressure: Float): Void {
pen.sendDownEvent(windowId, x, y, pressure);
}
public static function penUp(windowId: Int, x: Int, y: Int, pressure: Float): Void {
pen.sendUpEvent(windowId, x, y, pressure);
}
public static function penMove(windowId: Int, x: Int, y: Int, pressure: Float): Void {
pen.sendMoveEvent(windowId, x, y, pressure);
}
public static function gamepadAxis(gamepad: Int, axis: Int, value: FastFloat): Void {
gamepads[gamepad].sendAxisEvent(axis, value);
}
public static function gamepadButton(gamepad: Int, button: Int, value: FastFloat): Void {
gamepads[gamepad].sendButtonEvent(button, value);
}
public static function touchStart(index: Int, x: Int, y: Int): Void {
surface.sendTouchStartEvent(index, x, y);
}
public static function touchEnd(index: Int, x: Int, y: Int): Void {
surface.sendTouchEndEvent(index, x, y);
}
public static function touchMove(index: Int, x: Int, y: Int): Void {
surface.sendMoveEvent(index, x, y);
}
public static function foreground(): Void {
System.foreground();
}
public static function resume(): Void {
System.resume();
}
public static function pause(): Void {
System.pause();
}
public static function background(): Void {
System.background();
}
public static function shutdown(): Void {
System.shutdown();
}
public static function dropFiles(filePath: String): Void {
System.dropFiles(filePath);
}
public static function copy(): hl.Bytes {
if (System.copyListener != null) {
final text = System.copyListener();
if (text == null)
return null;
return StringHelper.convert(text);
}
else {
return null;
}
}
public static function cut(): hl.Bytes {
if (System.cutListener != null) {
final text = System.cutListener();
if (text == null)
return null;
return StringHelper.convert(text);
}
else {
return null;
}
}
public static function paste(data: hl.Bytes): Void {
final text = @:privateAccess String.fromUTF8(data);
if (System.pasteListener != null) {
System.pasteListener(text);
}
}
static var fullscreenListeners: Array<Void->Void> = new Array();
static var previousWidth: Int = 0;
static var previousHeight: Int = 0;
public static function canSwitchFullscreen(): Bool {
return true;
}
public static function isFullscreen(): Bool {
return kinc_system_is_fullscreen();
}
public static function requestFullscreen(): Void {
if (!isFullscreen()) {
previousWidth = kinc_get_window_width(0);
previousHeight = kinc_get_window_height(0);
kinc_system_request_fullscreen();
for (listener in fullscreenListeners) {
listener();
}
}
}
public static function exitFullscreen(): Void {
if (isFullscreen()) {
if (previousWidth == 0 || previousHeight == 0) {
previousWidth = kinc_get_window_width(0);
previousHeight = kinc_get_window_height(0);
}
kinc_system_exit_fullscreen(previousWidth, previousHeight);
for (listener in fullscreenListeners) {
listener();
}
}
}
public static function notifyOfFullscreenChange(func: Void->Void, error: Void->Void): Void {
if (canSwitchFullscreen() && func != null) {
fullscreenListeners.push(func);
}
}
public static function removeFromFullscreenChange(func: Void->Void, error: Void->Void): Void {
if (canSwitchFullscreen() && func != null) {
fullscreenListeners.remove(func);
}
}
public static function changeResolution(width: Int, height: Int): Void {
kinc_system_change_resolution(width, height);
}
public static function setKeepScreenOn(on: Bool): Void {
kinc_system_set_keepscreenon(on);
}
public static function loadUrl(url: String): Void {
kinc_system_load_url(StringHelper.convert(url));
}
public static function getGamepadId(index: Int): String {
final b: hl.Bytes = kinc_get_gamepad_id(index);
return @:privateAccess String.fromUTF8(b);
}
public static function getGamepadVendor(index: Int): String {
final b: hl.Bytes = kinc_get_gamepad_vendor(index);
return @:privateAccess String.fromUTF8(b);
}
public static function setGamepadRumble(index: Int, leftAmount: Float, rightAmount: Float) {}
public static function safeZone(): Float {
return 1.0;
}
public static function login(): Void {}
public static function automaticSafeZone(): Bool {
return true;
}
public static function setSafeZone(value: Float): Void {}
public static function unlockAchievement(id: Int): Void {}
public static function waitingForLogin(): Bool {
return false;
}
public static function disallowUserChange(): Void {}
public static function allowUserChange(): Void {}
@:hlNative("std", "init_kore") static function init_kore(title: hl.Bytes, width: Int, height: Int, samplesPerPixel: Int, vSync: Bool, windowMode: Int,
windowFeatures: Int): Void {}
@:hlNative("std", "run_kore") static function run_kore(): Void {}
@:hlNative("std", "kinc_init_audio") static function kinc_init_audio(callCallback: Int->Void, readSample: Void->FastFloat,
outSamplesPerSecond: hl.Ref<Int>): Void {}
@:hlNative("std", "kinc_log") static function kinc_log(v: hl.Bytes): Void {}
@:hlNative("std", "kinc_get_time") static function kinc_get_time(): Float {
return 0;
}
@:hlNative("std", "kinc_get_window_width") static function kinc_get_window_width(window: Int): Int {
return 0;
}
@:hlNative("std", "kinc_get_window_height") static function kinc_get_window_height(window: Int): Int {
return 0;
}
@:hlNative("std", "kinc_get_system_id") static function kinc_get_system_id(): hl.Bytes {
return null;
}
@:hlNative("std", "kinc_vibrate") static function kinc_vibrate(ms: Int): Void {}
@:hlNative("std", "kinc_get_language") static function kinc_get_language(): hl.Bytes {
return null;
}
@:hlNative("std", "kinc_request_shutdown") static function kinc_request_shutdown(): Void {}
@:hlNative("std", "kinc_mouse_lock") static function kinc_mouse_lock(windowId: Int): Void {}
@:hlNative("std", "kinc_mouse_unlock") static function kinc_mouse_unlock(windowId: Int): Void {}
@:hlNative("std", "kinc_can_lock_mouse") static function kinc_can_lock_mouse(windowId: Int): Bool {
return false;
}
@:hlNative("std", "kinc_is_mouse_locked") static function kinc_is_mouse_locked(windowId: Int): Bool {
return false;
}
@:hlNative("std", "kinc_show_mouse") static function kinc_show_mouse(show: Bool): Void {}
@:hlNative("std", "kinc_system_is_fullscreen") static function kinc_system_is_fullscreen(): Bool {
return false;
}
@:hlNative("std", "kinc_system_request_fullscreen") static function kinc_system_request_fullscreen(): Void {}
@:hlNative("std", "kinc_system_exit_fullscreen") static function kinc_system_exit_fullscreen(previousWidth: Int, previousHeight: Int): Void {}
@:hlNative("std", "kinc_register_keyboard") static function kinc_register_keyboard(keyDown: KeyCode->Void, keyUp: KeyCode->Void,
keyPress: Int->Void): Void {}
@:hlNative("std", "kinc_register_mouse") static function kinc_register_mouse(mouseDown: Int->Int->Int->Int->Void, mouseUp: Int->Int->Int->Int->Void,
mouseMove: Int->Int->Int->Int->Int->Void, mouseWheel: Int->Int->Void): Void {}
@:hlNative("std", "kinc_register_pen") static function kinc_register_pen(penDown: Int->Int->Int->Float->Void, penUp: Int->Int->Int->Float->Void,
penMove: Int->Int->Int->Float->Void): Void {}
@:hlNative("std", "kinc_register_gamepad") static function kinc_register_gamepad(gamepadAxis: Int->Int->FastFloat->Void,
gamepadButton: Int->Int->FastFloat->Void): Void {}
@:hlNative("std", "kinc_register_surface") static function kinc_register_surface(touchStart: Int->Int->Int->Void, touchEnd: Int->Int->Int->Void,
touchMove: Int->Int->Int->Void): Void {}
@:hlNative("std", "kinc_register_sensor") static function kinc_register_sensor(accelerometerChanged: Float->Float->Float->Void,
gyroscopeChanged: Float->Float->Float->Void): Void {}
@:hlNative("std", "kinc_register_callbacks") static function kinc_register_callbacks(foreground: Void->Void, resume: Void->Void, pause: Void->Void,
background: Void->Void, shutdown: Void->Void): Void {}
@:hlNative("std", "kinc_register_dropfiles") static function kinc_register_dropfiles(dropFiles: String->Void): Void {}
@:hlNative("std", "kinc_register_copycutpaste") static function kinc_register_copycutpaste(copy: Void->hl.Bytes, cut: Void->hl.Bytes,
paste: hl.Bytes->Void): Void {}
@:hlNative("std", "kinc_system_change_resolution") static function kinc_system_change_resolution(width: Int, height: Int): Void {}
@:hlNative("std", "kinc_system_set_keepscreenon") static function kinc_system_set_keepscreenon(on: Bool): Void {}
@:hlNative("std", "kinc_system_load_url") static function kinc_system_load_url(url: hl.Bytes): Void {}
@:hlNative("std", "kinc_get_gamepad_id") static function kinc_get_gamepad_id(index: Int): hl.Bytes {
return null;
}
@:hlNative("std", "kinc_get_gamepad_vendor") static function kinc_get_gamepad_vendor(index: Int): hl.Bytes {
return null;
}
@:hlNative("std", "kinc_gamepad_connected") static function kinc_gamepad_connected(index: Int): Bool {
return false;
}
}

View File

@ -1,448 +0,0 @@
package kha.arrays;
class ByteArrayPrivate {
public var self: ByteBuffer;
public var byteArrayOffset: Int;
public var byteArrayLength: Int;
public inline function new(offset: Int, length: Int) {
this.byteArrayOffset = offset;
this.byteArrayLength = length;
}
}
abstract ByteArray(ByteArrayPrivate) {
public var buffer(get, never): ByteBuffer;
inline function get_buffer(): ByteBuffer {
return this.self;
}
public var byteLength(get, never): Int;
inline function get_byteLength(): Int {
return this.byteArrayLength;
}
public var byteOffset(get, never): Int;
inline function get_byteOffset(): Int {
return this.byteArrayOffset;
}
public inline function new(buffer: ByteBuffer, byteOffset: Int, byteLength: Int): Void {
this = new ByteArrayPrivate(byteOffset, byteLength);
this.self = buffer;
}
public static inline function make(byteLength: Int): ByteArray {
var buffer = ByteBuffer.create(byteLength);
return new ByteArray(buffer, 0, byteLength);
}
public inline function free() {
this.self.free();
}
public inline function getData(): Pointer {
return this.self;
}
// Get
public inline function getInt8(byteOffset: Int): Int {
return kinc_bytearray_getint8(this.self, this.byteArrayOffset + byteOffset);
}
public inline function getUint8(byteOffset: Int): Int {
return kinc_bytearray_getuint8(this.self, this.byteArrayOffset + byteOffset);
}
public inline function getInt16(byteOffset: Int): Int {
return kinc_bytearray_getint16(this.self, this.byteArrayOffset + byteOffset);
}
public inline function getUint16(byteOffset: Int): Int {
return kinc_bytearray_getuint16(this.self, this.byteArrayOffset + byteOffset);
}
public inline function getInt32(byteOffset: Int): Int {
return kinc_bytearray_getint32(this.self, this.byteArrayOffset + byteOffset);
}
public inline function getUint32(byteOffset: Int): Int {
return kinc_bytearray_getuint32(this.self, this.byteArrayOffset + byteOffset);
}
public inline function getFloat32(byteOffset: Int): FastFloat {
return kinc_bytearray_getfloat32(this.self, this.byteArrayOffset + byteOffset);
}
public inline function getFloat64(byteOffset: Int): Float {
return kinc_bytearray_getfloat64(this.self, this.byteArrayOffset + byteOffset);
}
// Set
public inline function setInt8(byteOffset: Int, value: Int): Void {
kinc_bytearray_setint8(this.self, this.byteArrayOffset + byteOffset, value);
}
public inline function setUint8(byteOffset: Int, value: Int): Void {
kinc_bytearray_setuint8(this.self, this.byteArrayOffset + byteOffset, value);
}
public inline function setInt16(byteOffset: Int, value: Int): Void {
kinc_bytearray_setint16(this.self, this.byteArrayOffset + byteOffset, value);
}
public inline function setUint16(byteOffset: Int, value: Int): Void {
kinc_bytearray_setuint16(this.self, this.byteArrayOffset + byteOffset, value);
}
public inline function setInt32(byteOffset: Int, value: Int): Void {
kinc_bytearray_setint32(this.self, this.byteArrayOffset + byteOffset, value);
}
public inline function setUint32(byteOffset: Int, value: hl.I64): Void {
kinc_bytearray_setuint32(this.self, this.byteArrayOffset + byteOffset, value);
}
public inline function setFloat32(byteOffset: Int, value: FastFloat): Void {
kinc_bytearray_setfloat32(this.self, this.byteArrayOffset + byteOffset, value);
}
public inline function setFloat64(byteOffset: Int, value: Float): Void {
kinc_bytearray_setfloat64(this.self, this.byteArrayOffset + byteOffset, value);
}
// Get (little endian)
public inline function getInt16LE(byteOffset: Int): Int {
#if !sys_bigendian
return getInt16(byteOffset);
#else
return kinc_bytearray_getint16_le(this.self, this.byteArrayOffset + byteOffset);
#end
}
public inline function getUint16LE(byteOffset: Int): Int {
#if !sys_bigendian
return getUint16(byteOffset);
#else
return kinc_bytearray_getuint16_le(this.self, this.byteArrayOffset + byteOffset);
#end
}
public inline function getInt32LE(byteOffset: Int): Int {
#if !sys_bigendian
return getInt32(byteOffset);
#else
return kinc_bytearray_getint32_le(this.self, this.byteArrayOffset + byteOffset);
#end
}
public inline function getUint32LE(byteOffset: Int): hl.I64 {
#if !sys_bigendian
return getUint32(byteOffset);
#else
return kinc_bytearray_getuint32_le(this.self, this.byteArrayOffset + byteOffset);
#end
}
public inline function getFloat32LE(byteOffset: Int): FastFloat {
#if !sys_bigendian
return getFloat32(byteOffset);
#else
return kinc_bytearray_getfloat32_le(this.self, this.byteArrayOffset + byteOffset);
#end
}
public inline function getFloat64LE(byteOffset: Int): Float {
#if !sys_bigendian
return getFloat64(byteOffset);
#else
return kinc_bytearray_getfloat64_le(this.self, this.byteArrayOffset + byteOffset);
#end
}
// Set (little endian)
public inline function setInt16LE(byteOffset: Int, value: Int): Void {
#if !sys_bigendian
setInt16(byteOffset, value);
#else
kinc_bytearray_setint16_le(this.self, this.byteArrayOffset + byteOffset, value);
#end
}
public inline function setUint16LE(byteOffset: Int, value: Int): Void {
#if !sys_bigendian
setUint16(byteOffset, value);
#else
kinc_bytearray_setuint16_le(this.self, this.byteArrayOffset + byteOffset, value);
#end
}
public inline function setInt32LE(byteOffset: Int, value: Int): Void {
#if !sys_bigendian
setInt32(byteOffset, value);
#else
kinc_bytearray_setint32_le(this.self, this.byteArrayOffset + byteOffset, value);
#end
}
public inline function setUint32LE(byteOffset: Int, value: hl.I64): Void {
#if !sys_bigendian
setUint32(byteOffset, value);
#else
kinc_bytearray_setuint32_le(this.self, this.byteArrayOffset + byteOffset, value);
#end
}
public inline function setFloat32LE(byteOffset: Int, value: FastFloat): Void {
#if !sys_bigendian
setFloat32(byteOffset, value);
#else
kinc_bytearray_setfloat32_le(this.self, this.byteArrayOffset + byteOffset, value);
#end
}
public inline function setFloat64LE(byteOffset: Int, value: Float): Void {
#if !sys_bigendian
setFloat64(byteOffset, value);
#else
kinc_bytearray_setfloat64_le(this.self, this.byteArrayOffset + byteOffset, value);
#end
}
// Get (big endian)
public inline function getInt16BE(byteOffset: Int): Int {
#if sys_bigendian
return getInt16(byteOffset);
#else
return kinc_bytearray_getint16_be(this.self, this.byteArrayOffset + byteOffset);
#end
}
public inline function getUint16BE(byteOffset: Int): Int {
#if sys_bigendian
return getUint16(byteOffset);
#else
return kinc_bytearray_getuint16_be(this.self, this.byteArrayOffset + byteOffset);
#end
}
public inline function getInt32BE(byteOffset: Int): Int {
#if sys_bigendian
return getInt32(byteOffset);
#else
return kinc_bytearray_getint32_be(this.self, this.byteArrayOffset + byteOffset);
#end
}
public inline function getUint32BE(byteOffset: Int): hl.I64 {
#if sys_bigendian
return getUint32(byteOffset);
#else
return kinc_bytearray_getuint32_be(this.self, this.byteArrayOffset + byteOffset);
#end
}
public inline function getFloat32BE(byteOffset: Int): FastFloat {
#if sys_bigendian
return getFloat32(byteOffset);
#else
return kinc_bytearray_getfloat32_be(this.self, this.byteArrayOffset + byteOffset);
#end
}
public inline function getFloat64BE(byteOffset: Int): Float {
#if sys_bigendian
return getFloat64(byteOffset);
#else
return kinc_bytearray_getfloat64_be(this.self, this.byteArrayOffset + byteOffset);
#end
}
// Set (big endian)
public inline function setInt16BE(byteOffset: Int, value: Int): Void {
#if sys_bigendian
setInt16(byteOffset, value);
#else
kinc_bytearray_setint16_be(this.self, this.byteArrayOffset + byteOffset, value);
#end
}
public inline function setUint16BE(byteOffset: Int, value: Int): Void {
#if sys_bigendian
setUint16(byteOffset, value);
#else
kinc_bytearray_setuint16_be(this.self, this.byteArrayOffset + byteOffset, value);
#end
}
public inline function setInt32BE(byteOffset: Int, value: Int): Void {
#if sys_bigendian
setInt32(byteOffset, value);
#else
kinc_bytearray_setint32_be(this.self, this.byteArrayOffset + byteOffset, value);
#end
}
public inline function setUint32BE(byteOffset: Int, value: hl.I64): Void {
#if sys_bigendian
setUint32(byteOffset, value);
#else
kinc_bytearray_setuint32_be(this.self, this.byteArrayOffset + byteOffset, value);
#end
}
public inline function setFloat32BE(byteOffset: Int, value: FastFloat): Void {
#if sys_bigendian
setFloat32(byteOffset, value);
#else
kinc_bytearray_setfloat32_be(this.self, this.byteArrayOffset + byteOffset, value);
#end
}
public inline function setFloat64BE(byteOffset: Int, value: Float): Void {
#if sys_bigendian
setFloat64(byteOffset, value);
#else
kinc_bytearray_setfloat64_be(this.self, this.byteArrayOffset + byteOffset, value);
#end
}
public function subarray(start: Int, ?end: Int): ByteArray {
var offset: Int = this.byteArrayOffset + start;
var length: Int = end == null ? this.byteArrayLength - start : end - start;
return new ByteArray(this.self, offset, length);
}
@:hlNative("std", "kinc_bytearray_getint8") static function kinc_bytearray_getint8(bytearray: Pointer, byteOffset: Int): Int {
return 0;
}
@:hlNative("std", "kinc_bytearray_getuint8") static function kinc_bytearray_getuint8(bytearray: Pointer, byteOffset: Int): Int {
return 0;
}
@:hlNative("std", "kinc_bytearray_getint16") static function kinc_bytearray_getint16(bytearray: Pointer, byteOffset: Int): Int {
return 0;
}
@:hlNative("std", "kinc_bytearray_getuint16") static function kinc_bytearray_getuint16(bytearray: Pointer, byteOffset: Int): Int {
return 0;
}
@:hlNative("std", "kinc_bytearray_getint32") static function kinc_bytearray_getint32(bytearray: Pointer, byteOffset: Int): Int {
return 0;
}
@:hlNative("std", "kinc_bytearray_getuint32") static function kinc_bytearray_getuint32(bytearray: Pointer, byteOffset: Int): hl.I64 {
return 0;
}
@:hlNative("std", "kinc_bytearray_getfloat32") static function kinc_bytearray_getfloat32(bytearray: Pointer, byteOffset: Int): FastFloat {
return 0;
}
@:hlNative("std", "kinc_bytearray_getfloat64") static function kinc_bytearray_getfloat64(bytearray: Pointer, byteOffset: Int): Float {
return 0;
}
@:hlNative("std", "kinc_bytearray_setint8") static function kinc_bytearray_setint8(bytearray: Pointer, byteOffset: Int, value: Int) {}
@:hlNative("std", "kinc_bytearray_setuint8") static function kinc_bytearray_setuint8(bytearray: Pointer, byteOffset: Int, value: Int) {}
@:hlNative("std", "kinc_bytearray_setint16") static function kinc_bytearray_setint16(bytearray: Pointer, byteOffset: Int, value: Int) {}
@:hlNative("std", "kinc_bytearray_setuint16") static function kinc_bytearray_setuint16(bytearray: Pointer, byteOffset: Int, value: Int) {}
@:hlNative("std", "kinc_bytearray_setint32") static function kinc_bytearray_setint32(bytearray: Pointer, byteOffset: Int, value: Int) {}
@:hlNative("std", "kinc_bytearray_setuint32") static function kinc_bytearray_setuint32(bytearray: Pointer, byteOffset: Int, value: hl.I64) {}
@:hlNative("std", "kinc_bytearray_setfloat32") static function kinc_bytearray_setfloat32(bytearray: Pointer, byteOffset: Int, value: FastFloat) {}
@:hlNative("std", "kinc_bytearray_setfloat64") static function kinc_bytearray_setfloat64(bytearray: Pointer, byteOffset: Int, value: Float) {}
// Variants for little endian on big endian system
@:hlNative("std", "kinc_bytearray_getint16_le") static function kinc_bytearray_getint16_le(bytearray: Pointer, byteOffset: Int): Int {
return 0;
}
@:hlNative("std", "kinc_bytearray_getuint16_le") static function kinc_bytearray_getuint16_le(bytearray: Pointer, byteOffset: Int): Int {
return 0;
}
@:hlNative("std", "kinc_bytearray_getint32_le") static function kinc_bytearray_getint32_le(bytearray: Pointer, byteOffset: Int): Int {
return 0;
}
@:hlNative("std", "kinc_bytearray_getuint32_le") static function kinc_bytearray_getuint32_le(bytearray: Pointer, byteOffset: Int): hl.I64 {
return 0;
}
@:hlNative("std", "kinc_bytearray_getfloat32_le") static function kinc_bytearray_getfloat32_le(bytearray: Pointer, byteOffset: Int): FastFloat {
return 0;
}
@:hlNative("std", "kinc_bytearray_getfloat64_le") static function kinc_bytearray_getfloat64_le(bytearray: Pointer, byteOffset: Int): Float {
return 0;
}
@:hlNative("std", "kinc_bytearray_setint16_le") static function kinc_bytearray_setint16_le(bytearray: Pointer, byteOffset: Int, value: Int) {}
@:hlNative("std", "kinc_bytearray_setuint16_le") static function kinc_bytearray_setuint16_le(bytearray: Pointer, byteOffset: Int, value: Int) {}
@:hlNative("std", "kinc_bytearray_setint32_le") static function kinc_bytearray_setint32_le(bytearray: Pointer, byteOffset: Int, value: Int) {}
@:hlNative("std", "kinc_bytearray_setuint32_le") static function kinc_bytearray_setuint32_le(bytearray: Pointer, byteOffset: Int, value: hl.I64) {}
@:hlNative("std", "kinc_bytearray_setfloat32_le") static function kinc_bytearray_setfloat32_le(bytearray: Pointer, byteOffset: Int, value: FastFloat) {}
@:hlNative("std", "kinc_bytearray_setfloat64_le") static function kinc_bytearray_setfloat64_le(bytearray: Pointer, byteOffset: Int, value: Float) {}
// Variants for big endian on little endian system
@:hlNative("std", "kinc_bytearray_getint16_be") static function kinc_bytearray_getint16_be(bytearray: Pointer, byteOffset: Int): Int {
return 0;
}
@:hlNative("std", "kinc_bytearray_getuint16_be") static function kinc_bytearray_getuint16_be(bytearray: Pointer, byteOffset: Int): Int {
return 0;
}
@:hlNative("std", "kinc_bytearray_getint32_be") static function kinc_bytearray_getint32_be(bytearray: Pointer, byteOffset: Int): Int {
return 0;
}
@:hlNative("std", "kinc_bytearray_getuint32_be") static function kinc_bytearray_getuint32_be(bytearray: Pointer, byteOffset: Int): hl.I64 {
return 0;
}
@:hlNative("std", "kinc_bytearray_getfloat32_be") static function kinc_bytearray_getfloat32_be(bytearray: Pointer, byteOffset: Int): FastFloat {
return 0;
}
@:hlNative("std", "kinc_bytearray_getfloat64_be") static function kinc_bytearray_getfloat64_be(bytearray: Pointer, byteOffset: Int): Float {
return 0;
}
@:hlNative("std", "kinc_bytearray_setint16_be") static function kinc_bytearray_setint16_be(bytearray: Pointer, byteOffset: Int, value: Int) {}
@:hlNative("std", "kinc_bytearray_setuint16_be") static function kinc_bytearray_setuint16_be(bytearray: Pointer, byteOffset: Int, value: Int) {}
@:hlNative("std", "kinc_bytearray_setint32_be") static function kinc_bytearray_setint32_be(bytearray: Pointer, byteOffset: Int, value: Int) {}
@:hlNative("std", "kinc_bytearray_setuint32_be") static function kinc_bytearray_setuint32_be(bytearray: Pointer, byteOffset: Int, value: hl.I64) {}
@:hlNative("std", "kinc_bytearray_setfloat32_be") static function kinc_bytearray_setfloat32_be(bytearray: Pointer, byteOffset: Int, value: FastFloat) {}
@:hlNative("std", "kinc_bytearray_setfloat64_be") static function kinc_bytearray_setfloat64_be(bytearray: Pointer, byteOffset: Int, value: Float) {}
}

View File

@ -1,171 +0,0 @@
package kha.compute;
import kha.arrays.Float32Array;
import kha.Image;
import kha.FastFloat;
import kha.math.FastMatrix3;
import kha.math.FastMatrix4;
import kha.math.FastVector2;
import kha.math.FastVector3;
import kha.math.FastVector4;
import kha.graphics4.CubeMap;
import kha.graphics4.TextureAddressing;
import kha.graphics4.TextureFilter;
import kha.graphics4.MipMapFilter;
class Compute {
public static function setBool(location: kha.compute.ConstantLocation, value: Bool): Void {
kinc_compute_set_bool(location._location, value);
}
public static function setInt(location: kha.compute.ConstantLocation, value: Int): Void {
kinc_compute_set_int(location._location, value);
}
public static function setFloat(location: kha.compute.ConstantLocation, value: FastFloat): Void {
kinc_compute_set_float(location._location, value);
}
public static function setFloat2(location: kha.compute.ConstantLocation, value1: FastFloat, value2: FastFloat): Void {
kinc_compute_set_float2(location._location, value1, value2);
}
public static function setFloat3(location: kha.compute.ConstantLocation, value1: FastFloat, value2: FastFloat, value3: FastFloat): Void {
kinc_compute_set_float3(location._location, value1, value2, value3);
}
public static function setFloat4(location: kha.compute.ConstantLocation, value1: FastFloat, value2: FastFloat, value3: FastFloat,
value4: FastFloat): Void {
kinc_compute_set_float4(location._location, value1, value2, value3, value4);
}
public static function setVector2(location: kha.compute.ConstantLocation, value: FastVector2): Void {
kinc_compute_set_float2(location._location, value.x, value.y);
}
public static function setVector3(location: kha.compute.ConstantLocation, value: FastVector3): Void {
kinc_compute_set_float3(location._location, value.x, value.y, value.z);
}
public static function setVector4(location: kha.compute.ConstantLocation, value: FastVector4): Void {
kinc_compute_set_float4(location._location, value.x, value.y, value.z, value.w);
}
public static function setFloats(location: kha.compute.ConstantLocation, values: Float32Array): Void {
kinc_compute_set_floats(location._location, values.getData(), values.length);
}
public static function setMatrix(location: kha.compute.ConstantLocation, matrix: FastMatrix4): Void {
kinc_compute_set_matrix(location._location, matrix._00, matrix._10, matrix._20, matrix._30, matrix._01, matrix._11, matrix._21, matrix._31,
matrix._02, matrix._12, matrix._22, matrix._32, matrix._03, matrix._13, matrix._23, matrix._33);
}
public static function setMatrix3(location: kha.compute.ConstantLocation, matrix: FastMatrix3): Void {
kinc_compute_set_matrix3(location._location, matrix._00, matrix._10, matrix._20, matrix._01, matrix._11, matrix._21, matrix._02, matrix._12,
matrix._22);
}
public static function setBuffer(buffer: ShaderStorageBuffer, index: Int) {
// Kore::Compute::setBuffer(buffer->buffer, index);
}
public static function setTexture(unit: TextureUnit, texture: Image, access: Access) {
if (texture._texture != null)
kinc_compute_set_texture(unit._unit, texture._texture, access);
else
kinc_compute_set_target(unit._unit, texture._renderTarget, access);
}
public static function setSampledTexture(unit: TextureUnit, texture: Image) {
if (texture._texture != null)
kinc_compute_set_sampled_texture(unit._unit, texture._texture);
else
kinc_compute_set_sampled_target(unit._unit, texture._renderTarget);
}
public static function setSampledDepthTexture(unit: TextureUnit, texture: Image) {
kinc_compute_set_sampled_depth_target(unit._unit, texture._renderTarget);
}
public static function setSampledCubeMap(unit: TextureUnit, cubeMap: CubeMap) {
if (cubeMap._texture != null)
kinc_compute_set_sampled_cubemap_texture(unit._unit, cubeMap._texture);
else
kinc_compute_set_sampled_cubemap_target(unit._unit, cubeMap._renderTarget);
}
public static function setSampledDepthCubeMap(unit: TextureUnit, cubeMap: CubeMap) {
kinc_compute_set_sampled_cubemap_depth_target(unit._unit, cubeMap._renderTarget);
}
public static function setTextureParameters(unit: TextureUnit, uAddressing: TextureAddressing, vAddressing: TextureAddressing,
minificationFilter: TextureFilter, magnificationFilter: TextureFilter, mipmapFilter: MipMapFilter): Void {
kinc_compute_set_texture_parameters(unit._unit, uAddressing, vAddressing, minificationFilter, magnificationFilter, mipmapFilter);
}
public static function setTexture3DParameters(unit: TextureUnit, uAddressing: TextureAddressing, vAddressing: TextureAddressing,
wAddressing: TextureAddressing, minificationFilter: TextureFilter, magnificationFilter: TextureFilter, mipmapFilter: MipMapFilter): Void {
kinc_compute_set_texture3d_parameters(unit._unit, uAddressing, vAddressing, wAddressing, minificationFilter, magnificationFilter, mipmapFilter);
}
public static function setShader(shader: Shader) {
kinc_compute_set_shader(shader._shader);
}
public static function compute(x: Int, y: Int, z: Int) {
kinc_compute_compute(x, y, z);
}
@:hlNative("std", "kinc_compute_set_bool") static function kinc_compute_set_bool(location: Pointer, value: Bool): Void {}
@:hlNative("std", "kinc_compute_set_int") static function kinc_compute_set_int(location: Pointer, value: Int): Void {}
@:hlNative("std", "kinc_compute_set_float") static function kinc_compute_set_float(location: Pointer, value: FastFloat): Void {}
@:hlNative("std", "kinc_compute_set_float2") static function kinc_compute_set_float2(location: Pointer, value1: FastFloat, value2: FastFloat): Void {}
@:hlNative("std", "kinc_compute_set_float3") static function kinc_compute_set_float3(location: Pointer, value1: FastFloat, value2: FastFloat,
value3: FastFloat): Void {}
@:hlNative("std", "kinc_compute_set_float4") static function kinc_compute_set_float4(location: Pointer, value1: FastFloat, value2: FastFloat,
value3: FastFloat, value4: FastFloat): Void {}
@:hlNative("std", "kinc_compute_set_floats") static function kinc_compute_set_floats(location: Pointer, values: Pointer, count: Int): Void {}
@:hlNative("std", "kinc_compute_set_matrix") static function kinc_compute_set_matrix(location: Pointer, _00: FastFloat, _10: FastFloat, _20: FastFloat,
_30: FastFloat, _01: FastFloat, _11: FastFloat, _21: FastFloat, _31: FastFloat, _02: FastFloat, _12: FastFloat, _22: FastFloat, _32: FastFloat,
_03: FastFloat, _13: FastFloat, _23: FastFloat, _33: FastFloat): Void {}
@:hlNative("std", "kinc_compute_set_matrix3") static function kinc_compute_set_matrix3(location: Pointer, _00: FastFloat, _10: FastFloat, _20: FastFloat,
_01: FastFloat, _11: FastFloat, _21: FastFloat, _02: FastFloat, _12: FastFloat, _22: FastFloat): Void {}
@:hlNative("std", "kinc_compute_set_texture") static function kinc_compute_set_texture(unit: Pointer, texture: Pointer, access: Int): Void {}
@:hlNative("std", "kinc_compute_set_target") static function kinc_compute_set_target(unit: Pointer, renderTarget: Pointer, access: Int): Void {}
@:hlNative("std", "kinc_compute_set_sampled_texture") static function kinc_compute_set_sampled_texture(unit: Pointer, texture: Pointer): Void {}
@:hlNative("std", "kinc_compute_set_sampled_target") static function kinc_compute_set_sampled_target(unit: Pointer, renderTarget: Pointer): Void {}
@:hlNative("std", "kinc_compute_set_sampled_depth_target") static function kinc_compute_set_sampled_depth_target(unit: Pointer,
renderTarget: Pointer): Void {}
@:hlNative("std", "kinc_compute_set_sampled_cubemap_texture") static function kinc_compute_set_sampled_cubemap_texture(unit: Pointer,
texture: Pointer): Void {}
@:hlNative("std", "kinc_compute_set_sampled_cubemap_target") static function kinc_compute_set_sampled_cubemap_target(unit: Pointer,
renderTarget: Pointer): Void {}
@:hlNative("std", "kinc_compute_set_sampled_cubemap_depth_target") static function kinc_compute_set_sampled_cubemap_depth_target(unit: Pointer,
renderTarget: Pointer): Void {}
@:hlNative("std", "kinc_compute_set_texture_parameters") static function kinc_compute_set_texture_parameters(unit: Pointer, uAddressing: Int,
vAddressing: Int, minificationFilter: Int, magnificationFilter: Int, mipmapFilter: Int): Void {}
@:hlNative("std", "kinc_compute_set_texture3d_parameters") static function kinc_compute_set_texture3d_parameters(unit: Pointer, uAddressing: Int,
vAddressing: Int, wAddressing: Int, minificationFilter: Int, magnificationFilter: Int, mipmapFilter: Int): Void {}
@:hlNative("std", "kinc_compute_set_shader") static function kinc_compute_set_shader(shader: Pointer): Void {}
@:hlNative("std", "kinc_compute_compute") static function kinc_compute_compute(x: Int, y: Int, z: Int): Void {}
}

View File

@ -1,9 +0,0 @@
package kha.compute;
class ConstantLocation {
public var _location: Pointer;
public function new(location: Pointer) {
_location = location;
}
}

View File

@ -1,37 +0,0 @@
package kha.compute;
import kha.Blob;
class Shader {
public var _shader: Pointer;
public function new(sources: Array<Blob>, files: Array<String>) {
_shader = kinc_compute_create_shader(sources[0].bytes.getData(), sources[0].bytes.getData().length);
}
public function delete(): Void {
kinc_compute_delete_shader(_shader);
}
public function getConstantLocation(name: String): ConstantLocation {
return new ConstantLocation(kinc_compute_get_constantlocation(_shader, StringHelper.convert(name)));
}
public function getTextureUnit(name: String): TextureUnit {
return new TextureUnit(kinc_compute_get_textureunit(_shader, StringHelper.convert(name)));
}
@:hlNative("std", "kinc_compute_create_shader") static function kinc_compute_create_shader(data: hl.Bytes, length: Int): Pointer {
return null;
}
@:hlNative("std", "kinc_compute_delete_shader") static function kinc_compute_delete_shader(shader: Pointer): Void {}
@:hlNative("std", "kinc_compute_get_constantlocation") static function kinc_compute_get_constantlocation(shader: Pointer, name: hl.Bytes): Pointer {
return null;
}
@:hlNative("std", "kinc_compute_get_textureunit") static function kinc_compute_get_textureunit(shader: Pointer, name: hl.Bytes): Pointer {
return null;
}
}

View File

@ -1,26 +0,0 @@
package kha.compute;
import kha.graphics4.VertexData;
class ShaderStorageBuffer {
public var _buffer: Pointer;
var data: Array<Int>;
var myCount: Int;
public function new(indexCount: Int, type: VertexData) {}
function init(indexCount: Int, type: VertexData) {}
public function delete(): Void {}
public function lock(): Array<Int> {
return data;
}
public function unlock(): Void {}
public function count(): Int {
return myCount;
}
}

View File

@ -1,9 +0,0 @@
package kha.compute;
class TextureUnit {
public var _unit: Pointer;
public function new(unit: Pointer) {
_unit = unit;
}
}

View File

@ -1,70 +0,0 @@
package kha.graphics4;
using StringTools;
import kha.Blob;
class FragmentShader {
public var _shader: Pointer;
public function new(sources: Array<Blob>, files: Array<String>) {
//initShader(sources[0]);
var shaderBlob: Blob = null;
var shaderFile: String = null;
#if kha_opengl
final expectedExtension = ".glsl";
#elseif kha_direct3d11
final expectedExtension = ".d3d11";
#elseif kha_direct3d12
final expectedExtension = ".d3d12";
#elseif kha_metal
final expectedExtension = ".metal";
#elseif kha_vulkan
final expectedExtension = ".spirv";
#else
final expectedExtension = ".glsl";
#end
if (sources != null && files != null) {
for (i in 0...files.length) {
if (files[i].endsWith(expectedExtension)) {
shaderBlob = sources[i];
shaderFile = files[i];
break;
}
}
}
if (shaderBlob == null && sources != null && sources.length > 0) {
trace('Warning: Could not find shader with extension ${expectedExtension}. Falling back to sources[0]: ${files != null && files.length > 0 ? files[0] : "Unknown"}');
shaderBlob = sources[0];
}
if (shaderBlob != null) {
initShader(shaderBlob);
} else {
trace('Error: No suitable fragment shader source found!');
}
}
function initShader(source: Blob): Void {
//_shader = kinc_create_fragmentshader(source.bytes.getData(), source.bytes.getData().length);
_shader = kinc_create_fragmentshader(source.bytes.getData(), source.length); // Use source.length here
}
public static function fromSource(source: String): FragmentShader {
var sh = new FragmentShader(null, null);
sh._shader = kinc_fragmentshader_from_source(StringHelper.convert(source));
return sh;
}
public function delete(): Void {}
@:hlNative("std", "kinc_create_fragmentshader") static function kinc_create_fragmentshader(data: hl.Bytes, length: Int): Pointer {
return null;
}
@:hlNative("std", "kinc_fragmentshader_from_source") static function kinc_fragmentshader_from_source(source: hl.Bytes): Pointer {
return null;
}
}

View File

@ -1,379 +0,0 @@
package kha.korehl.graphics4;
import kha.arrays.Float32Array;
import kha.graphics4.CubeMap;
import kha.graphics4.MipMapFilter;
import kha.graphics4.PipelineState;
import kha.graphics4.TextureAddressing;
import kha.graphics4.TextureFilter;
import kha.graphics4.Usage;
import kha.graphics4.VertexBuffer;
import kha.math.FastMatrix3;
import kha.math.FastMatrix4;
import kha.math.FastVector2;
import kha.math.FastVector3;
import kha.math.FastVector4;
import kha.Canvas;
import kha.Image;
import kha.Video;
import kha.Color;
class Graphics implements kha.graphics4.Graphics {
var target: Canvas;
public function new(target: Canvas = null) {
this.target = target;
}
public function vsynced(): Bool {
return kinc_graphics_vsynced();
}
public function refreshRate(): Int {
return kinc_graphics_refreshrate();
}
public function clear(?color: Color, ?z: FastFloat, ?stencil: Int): Void {
var flags: Int = 0;
if (color != null)
flags |= 1;
if (z != null)
flags |= 2;
if (stencil != null)
flags |= 4;
kinc_graphics_clear(flags, color == null ? 0 : color.value, z, stencil);
}
public function viewport(x: Int, y: Int, width: Int, height: Int): Void {
kinc_graphics_viewport(x, y, width, height);
}
public function setVertexBuffer(vertexBuffer: kha.graphics4.VertexBuffer): Void {
kinc_graphics_set_vertexbuffer(vertexBuffer._buffer);
}
public function setVertexBuffers(vertexBuffers: Array<kha.graphics4.VertexBuffer>): Void {
kinc_graphics_set_vertexbuffers(vertexBuffers.length > 0 ? vertexBuffers[0]._buffer : null,
vertexBuffers.length > 1 ? vertexBuffers[1]._buffer : null, vertexBuffers.length > 2 ? vertexBuffers[2]._buffer : null,
vertexBuffers.length > 3 ? vertexBuffers[3]._buffer : null, vertexBuffers.length);
}
public function setIndexBuffer(indexBuffer: kha.graphics4.IndexBuffer): Void {
kinc_graphics_set_indexbuffer(indexBuffer._buffer);
}
public function maxTextureSize(): Int {
return 4096;
}
public function supportsNonPow2Textures(): Bool {
return false;
}
public function setCubeMap(unit: kha.graphics4.TextureUnit, cubeMap: kha.graphics4.CubeMap): Void {
if (cubeMap == null)
return;
if (cubeMap._texture != null)
kinc_graphics_set_cubemap_texture(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, cubeMap._texture);
else
kinc_graphics_set_cubemap_target(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, cubeMap._renderTarget);
}
public function setCubeMapDepth(unit: kha.graphics4.TextureUnit, cubeMap: kha.graphics4.CubeMap): Void {
if (cubeMap == null)
return;
kinc_graphics_set_cubemap_depth(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, cubeMap._renderTarget);
}
public function scissor(x: Int, y: Int, width: Int, height: Int): Void {
kinc_graphics_scissor(x, y, width, height);
}
public function disableScissor(): Void {
kinc_graphics_disable_scissor();
}
public function instancedRenderingAvailable(): Bool {
return true;
}
public function setTextureParameters(unit: kha.graphics4.TextureUnit, uAddressing: TextureAddressing, vAddressing: TextureAddressing,
minificationFilter: TextureFilter, magnificationFilter: TextureFilter, mipmapFilter: MipMapFilter): Void {
kinc_graphics_set_texture_parameters(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, uAddressing, vAddressing, minificationFilter,
magnificationFilter, mipmapFilter);
}
public function setTexture3DParameters(unit: kha.graphics4.TextureUnit, uAddressing: TextureAddressing, vAddressing: TextureAddressing,
wAddressing: TextureAddressing, minificationFilter: TextureFilter, magnificationFilter: TextureFilter, mipmapFilter: MipMapFilter): Void {
kinc_graphics_set_texture3d_parameters(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, uAddressing, vAddressing, wAddressing, minificationFilter,
magnificationFilter, mipmapFilter);
}
public function setTextureCompareMode(unit: kha.graphics4.TextureUnit, enabled: Bool) {
kinc_graphics_set_texture_compare_mode(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, enabled);
}
public function setCubeMapCompareMode(unit: kha.graphics4.TextureUnit, enabled: Bool) {
kinc_graphics_set_cube_map_compare_mode(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, enabled);
}
public function setTexture(unit: kha.graphics4.TextureUnit, texture: kha.Image): Void {
if (texture == null)
return;
if (texture._texture != null)
kinc_graphics_set_texture(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, texture._texture);
else
kinc_graphics_set_render_target(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, texture._renderTarget);
}
public function setTextureArray(unit: kha.graphics4.TextureUnit, texture: kha.Image): Void {
if (texture == null)
return;
kinc_graphics_set_texture_array(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, texture._textureArray);
}
public function setTextureDepth(unit: kha.graphics4.TextureUnit, texture: kha.Image): Void {
if (texture == null)
return;
kinc_graphics_set_texture_depth(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, texture._renderTarget);
}
public function setVideoTexture(unit: kha.graphics4.TextureUnit, texture: kha.Video): Void {
if (texture == null)
return;
kinc_graphics_set_texture(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, Image.fromVideo(texture)._texture);
}
public function setImageTexture(unit: kha.graphics4.TextureUnit, texture: kha.Image): Void {
kinc_graphics_set_image_texture(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, texture._texture);
}
public function maxBoundTextures(): Int {
return 8;
}
public function setPipeline(pipe: PipelineState): Void {
pipe.set();
}
public function setStencilReferenceValue(value: Int): Void {}
public function setBool(location: kha.graphics4.ConstantLocation, value: Bool): Void {
kinc_graphics_set_bool(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value);
}
public function setInt(location: kha.graphics4.ConstantLocation, value: Int): Void {
kinc_graphics_set_int(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value);
}
public function setInt2(location: kha.graphics4.ConstantLocation, value1: Int, value2: Int): Void {
kinc_graphics_set_int2(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value1, value2);
}
public function setInt3(location: kha.graphics4.ConstantLocation, value1: Int, value2: Int, value3: Int): Void {
kinc_graphics_set_int3(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value1, value2, value3);
}
public function setInt4(location: kha.graphics4.ConstantLocation, value1: Int, value2: Int, value3: Int, value4: Int): Void {
kinc_graphics_set_int4(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value1, value2, value3, value4);
}
public function setInts(location: kha.graphics4.ConstantLocation, values: kha.arrays.Int32Array): Void {
kinc_graphics_set_ints(cast(location, kha.korehl.graphics4.ConstantLocation)._location, values.getData(), values.length);
}
public function setFloat(location: kha.graphics4.ConstantLocation, value: FastFloat): Void {
kinc_graphics_set_float(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value);
}
public function setFloat2(location: kha.graphics4.ConstantLocation, value1: FastFloat, value2: FastFloat): Void {
kinc_graphics_set_float2(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value1, value2);
}
public function setFloat3(location: kha.graphics4.ConstantLocation, value1: FastFloat, value2: FastFloat, value3: FastFloat): Void {
kinc_graphics_set_float3(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value1, value2, value3);
}
public function setFloat4(location: kha.graphics4.ConstantLocation, value1: FastFloat, value2: FastFloat, value3: FastFloat, value4: FastFloat): Void {
kinc_graphics_set_float4(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value1, value2, value3, value4);
}
public function setVector2(location: kha.graphics4.ConstantLocation, value: FastVector2): Void {
kinc_graphics_set_float2(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value.x, value.y);
}
public function setVector3(location: kha.graphics4.ConstantLocation, value: FastVector3): Void {
kinc_graphics_set_float3(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value.x, value.y, value.z);
}
public function setVector4(location: kha.graphics4.ConstantLocation, value: FastVector4): Void {
kinc_graphics_set_float4(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value.x, value.y, value.z, value.w);
}
public function setFloats(location: kha.graphics4.ConstantLocation, values: Float32Array): Void {
kinc_graphics_set_floats(cast(location, kha.korehl.graphics4.ConstantLocation)._location, values.getData(), values.length);
}
public inline function setMatrix(location: kha.graphics4.ConstantLocation, matrix: FastMatrix4): Void {
kinc_graphics_set_matrix(cast(location, kha.korehl.graphics4.ConstantLocation)._location, matrix._00, matrix._10, matrix._20, matrix._30, matrix._01,
matrix._11, matrix._21, matrix._31, matrix._02, matrix._12, matrix._22, matrix._32, matrix._03, matrix._13, matrix._23, matrix._33);
}
public inline function setMatrix3(location: kha.graphics4.ConstantLocation, matrix: FastMatrix3): Void {
kinc_graphics_set_matrix3(cast(location, kha.korehl.graphics4.ConstantLocation)._location, matrix._00, matrix._10, matrix._20, matrix._01, matrix._11,
matrix._21, matrix._02, matrix._12, matrix._22);
}
public function drawIndexedVertices(start: Int = 0, count: Int = -1): Void {
if (count < 0)
kinc_graphics_draw_all_indexed_vertices();
else
kinc_graphics_draw_indexed_vertices(start, count);
}
public function drawIndexedVerticesInstanced(instanceCount: Int, start: Int = 0, count: Int = -1): Void {
if (count < 0)
kinc_graphics_draw_all_indexed_vertices_instanced(instanceCount);
else
kinc_graphics_draw_indexed_vertices_instanced(instanceCount, start, count);
}
function renderToTexture(additionalRenderTargets: Array<Canvas>): Void {
if (additionalRenderTargets != null) {
var len = additionalRenderTargets.length;
var rt0 = cast(target, Image)._renderTarget;
var rt1 = len > 0 ? cast(additionalRenderTargets[0], Image)._renderTarget : null;
var rt2 = len > 1 ? cast(additionalRenderTargets[1], Image)._renderTarget : null;
var rt3 = len > 2 ? cast(additionalRenderTargets[2], Image)._renderTarget : null;
var rt4 = len > 3 ? cast(additionalRenderTargets[3], Image)._renderTarget : null;
var rt5 = len > 4 ? cast(additionalRenderTargets[4], Image)._renderTarget : null;
var rt6 = len > 5 ? cast(additionalRenderTargets[5], Image)._renderTarget : null;
var rt7 = len > 6 ? cast(additionalRenderTargets[6], Image)._renderTarget : null;
kinc_graphics_render_to_textures(rt0, rt1, rt2, rt3, rt4, rt5, rt6, rt7, len + 1);
}
else {
kinc_graphics_render_to_texture(cast(target, Image)._renderTarget);
}
}
public function begin(additionalRenderTargets: Array<Canvas> = null): Void {
if (target == null)
kinc_graphics_restore_render_target();
else
renderToTexture(additionalRenderTargets);
}
public function beginFace(face: Int): Void {
kinc_graphics_render_to_face(cast(target, CubeMap)._renderTarget, face);
}
public function beginEye(eye: Int): Void {}
public function end(): Void {}
public function flush(): Void {
kinc_graphics_flush();
}
@:hlNative("std", "kinc_graphics_clear") static function kinc_graphics_clear(flags: Int, color: Int, z: FastFloat, stencil: Int): Void {}
@:hlNative("std", "kinc_graphics_vsynced") static function kinc_graphics_vsynced(): Bool {
return false;
}
@:hlNative("std", "kinc_graphics_refreshrate") static function kinc_graphics_refreshrate(): Int {
return 0;
}
@:hlNative("std", "kinc_graphics_viewport") static function kinc_graphics_viewport(x: Int, y: Int, width: Int, height: Int): Void {}
@:hlNative("std", "kinc_graphics_set_vertexbuffer") static function kinc_graphics_set_vertexbuffer(buffer: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_vertexbuffers") static function kinc_graphics_set_vertexbuffers(b0: Pointer, b1: Pointer, b2: Pointer, b3: Pointer,
count: Int): Void {}
@:hlNative("std", "kinc_graphics_set_indexbuffer") static function kinc_graphics_set_indexbuffer(buffer: Pointer): Void {}
@:hlNative("std", "kinc_graphics_scissor") static function kinc_graphics_scissor(x: Int, y: Int, width: Int, height: Int): Void {}
@:hlNative("std", "kinc_graphics_disable_scissor") static function kinc_graphics_disable_scissor(): Void {}
@:hlNative("std", "kinc_graphics_set_texture_parameters") static function kinc_graphics_set_texture_parameters(unit: Pointer, uAddressing: Int,
vAddressing: Int, minificationFilter: Int, magnificationFilter: Int, mipmapFilter: Int): Void {}
@:hlNative("std", "kinc_graphics_set_texture3d_parameters") static function kinc_graphics_set_texture3d_parameters(unit: Pointer, uAddressing: Int,
vAddressing: Int, wAddressing: Int, minificationFilter: Int, magnificationFilter: Int, mipmapFilter: Int): Void {}
@:hlNative("std", "kinc_graphics_set_texture_compare_mode") static function kinc_graphics_set_texture_compare_mode(unit: Pointer, enabled: Bool): Void {}
@:hlNative("std", "kinc_graphics_set_cube_map_compare_mode") static function kinc_graphics_set_cube_map_compare_mode(unit: Pointer, enabled: Bool): Void {}
@:hlNative("std", "kinc_graphics_set_texture") static function kinc_graphics_set_texture(unit: Pointer, texture: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_texture_depth") static function kinc_graphics_set_texture_depth(unit: Pointer, renderTarget: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_texture_array") static function kinc_graphics_set_texture_array(unit: Pointer, textureArray: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_render_target") static function kinc_graphics_set_render_target(unit: Pointer, renderTarget: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_cubemap_texture") static function kinc_graphics_set_cubemap_texture(unit: Pointer, texture: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_cubemap_target") static function kinc_graphics_set_cubemap_target(unit: Pointer, renderTarget: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_cubemap_depth") static function kinc_graphics_set_cubemap_depth(unit: Pointer, renderTarget: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_image_texture") static function kinc_graphics_set_image_texture(unit: Pointer, texture: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_bool") static function kinc_graphics_set_bool(location: Pointer, value: Bool): Void {}
@:hlNative("std", "kinc_graphics_set_int") static function kinc_graphics_set_int(location: Pointer, value: Int): Void {}
@:hlNative("std", "kinc_graphics_set_int2") static function kinc_graphics_set_int2(location: Pointer, value1: Int, value2: Int): Void {}
@:hlNative("std", "kinc_graphics_set_int3") static function kinc_graphics_set_int3(location: Pointer, value1: Int, value2: Int, value3: Int): Void {}
@:hlNative("std", "kinc_graphics_set_int4") static function kinc_graphics_set_int4(location: Pointer, value1: Int, value2: Int, value3: Int,
value4: Int): Void {}
@:hlNative("std", "kinc_graphics_set_ints") static function kinc_graphics_set_ints(location: Pointer, values: Pointer, count: Int): Void {}
@:hlNative("std", "kinc_graphics_set_float") static function kinc_graphics_set_float(location: Pointer, value: FastFloat): Void {}
@:hlNative("std", "kinc_graphics_set_float2") static function kinc_graphics_set_float2(location: Pointer, value1: FastFloat, value2: FastFloat): Void {}
@:hlNative("std", "kinc_graphics_set_float3") static function kinc_graphics_set_float3(location: Pointer, value1: FastFloat, value2: FastFloat,
value3: FastFloat): Void {}
@:hlNative("std", "kinc_graphics_set_float4") static function kinc_graphics_set_float4(location: Pointer, value1: FastFloat, value2: FastFloat,
value3: FastFloat, value4: FastFloat): Void {}
@:hlNative("std", "kinc_graphics_set_floats") static function kinc_graphics_set_floats(location: Pointer, values: Pointer, count: Int): Void {}
@:hlNative("std", "kinc_graphics_set_matrix") static function kinc_graphics_set_matrix(location: Pointer, _00: FastFloat, _10: FastFloat, _20: FastFloat,
_30: FastFloat, _01: FastFloat, _11: FastFloat, _21: FastFloat, _31: FastFloat, _02: FastFloat, _12: FastFloat, _22: FastFloat, _32: FastFloat,
_03: FastFloat, _13: FastFloat, _23: FastFloat, _33: FastFloat): Void {}
@:hlNative("std", "kinc_graphics_set_matrix3") static function kinc_graphics_set_matrix3(location: Pointer, _00: FastFloat, _10: FastFloat,
_20: FastFloat, _01: FastFloat, _11: FastFloat, _21: FastFloat, _02: FastFloat, _12: FastFloat, _22: FastFloat): Void {}
@:hlNative("std", "kinc_graphics_draw_all_indexed_vertices") static function kinc_graphics_draw_all_indexed_vertices(): Void {}
@:hlNative("std", "kinc_graphics_draw_indexed_vertices") static function kinc_graphics_draw_indexed_vertices(start: Int, count: Int): Void {}
@:hlNative("std",
"kinc_graphics_draw_all_indexed_vertices_instanced") static function kinc_graphics_draw_all_indexed_vertices_instanced(instanceCount: Int): Void {}
@:hlNative("std", "kinc_graphics_draw_indexed_vertices_instanced") static function kinc_graphics_draw_indexed_vertices_instanced(instanceCount: Int,
start: Int, count: Int): Void {}
@:hlNative("std", "kinc_graphics_restore_render_target") static function kinc_graphics_restore_render_target(): Void {}
@:hlNative("std", "kinc_graphics_render_to_texture") static function kinc_graphics_render_to_texture(renderTarget: Pointer): Void {}
@:hlNative("std", "kinc_graphics_render_to_textures") static function kinc_graphics_render_to_textures(rt0: Pointer, rt1: Pointer, rt2: Pointer,
rt3: Pointer, rt4: Pointer, rt5: Pointer, rt6: Pointer, rt7: Pointer, count: Int): Void {}
@:hlNative("std", "kinc_graphics_render_to_face") static function kinc_graphics_render_to_face(renderTarget: Pointer, face: Int): Void {}
@:hlNative("std", "kinc_graphics_flush") static function kinc_graphics_flush(): Void {}
}

View File

@ -1,38 +0,0 @@
#include <kinc/graphics4/compute.h>
#include <kinc/graphics4/texture.h>
#include <hl.h>
vbyte *hl_kinc_compute_create_shader(vbyte *data, int length) {
kinc_g4_compute_shader *shader = (kinc_g4_compute_shader *)malloc(sizeof(kinc_g4_compute_shader));
kinc_g4_compute_shader_init(shader, data, length);
return (vbyte *)shader;
}
void hl_kinc_compute_delete_shader(vbyte *shader) {
kinc_g4_compute_shader *sh = (kinc_g4_compute_shader *)shader;
kinc_g4_compute_shader_destroy(sh);
free(sh);
}
vbyte *hl_kinc_compute_get_constantlocation(vbyte *shader, vbyte *name) {
kinc_g4_compute_shader *sh = (kinc_g4_compute_shader *)shader;
kinc_g4_constant_location_t *location = (kinc_g4_constant_location_t *)malloc(sizeof(kinc_g4_constant_location_t));
*location = kinc_g4_compute_shader_get_constant_location(sh, (char *)name);
return (vbyte *)location;
}
vbyte *hl_kinc_compute_get_textureunit(vbyte *shader, vbyte *name) {
kinc_g4_compute_shader *sh = (kinc_g4_compute_shader *)shader;
kinc_g4_texture_unit_t *unit = (kinc_g4_texture_unit_t *)malloc(sizeof(kinc_g4_texture_unit_t));
*unit = kinc_g4_compute_shader_get_texture_unit(sh, (char *)name);
return (vbyte *)unit;
}
void hl_kinc_set_compute_shader(vbyte *shader) {
kinc_g4_set_compute_shader((kinc_g4_compute_shader *)shader);
}
void hl_kinc_compute(int x, int y, int z) {
kinc_g4_compute(x, y, z);
}

View File

@ -1,265 +0,0 @@
#include <kinc/graphics4/graphics.h>
#include <kinc/graphics4/pipeline.h>
#include <kinc/graphics4/shader.h>
#include <kinc/graphics4/vertexstructure.h>
#include <hl.h>
static kinc_g4_compare_mode_t convertCompareMode(int mode) {
switch (mode) {
case 0:
return KINC_G4_COMPARE_ALWAYS;
case 1:
return KINC_G4_COMPARE_NEVER;
case 2:
return KINC_G4_COMPARE_EQUAL;
case 3:
return KINC_G4_COMPARE_NOT_EQUAL;
case 4:
return KINC_G4_COMPARE_LESS;
case 5:
return KINC_G4_COMPARE_LESS_EQUAL;
case 6:
return KINC_G4_COMPARE_GREATER;
case 7:
default:
return KINC_G4_COMPARE_GREATER_EQUAL;
}
}
static kinc_g4_stencil_action_t convertStencilAction(int action) {
switch (action) {
case 0:
return KINC_G4_STENCIL_KEEP;
case 1:
return KINC_G4_STENCIL_ZERO;
case 2:
return KINC_G4_STENCIL_REPLACE;
case 3:
return KINC_G4_STENCIL_INCREMENT;
case 4:
return KINC_G4_STENCIL_INCREMENT_WRAP;
case 5:
return KINC_G4_STENCIL_DECREMENT;
case 6:
return KINC_G4_STENCIL_DECREMENT_WRAP;
case 7:
default:
return KINC_G4_STENCIL_INVERT;
}
}
static kinc_g4_render_target_format_t convertColorAttachment(int format) {
switch (format) {
case 0:
return KINC_G4_RENDER_TARGET_FORMAT_32BIT;
case 1:
return KINC_G4_RENDER_TARGET_FORMAT_8BIT_RED;
case 2:
return KINC_G4_RENDER_TARGET_FORMAT_128BIT_FLOAT;
case 3:
return KINC_G4_RENDER_TARGET_FORMAT_16BIT_DEPTH;
case 4:
return KINC_G4_RENDER_TARGET_FORMAT_64BIT_FLOAT;
case 5:
return KINC_G4_RENDER_TARGET_FORMAT_32BIT_RED_FLOAT;
case 6:
default:
return KINC_G4_RENDER_TARGET_FORMAT_16BIT_RED_FLOAT;
}
}
vbyte *hl_kinc_create_vertexshader(vbyte *data, int length) {
kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t));
kinc_g4_shader_init(shader, data, length, KINC_G4_SHADER_TYPE_VERTEX);
return (vbyte *)shader;
}
vbyte *hl_kinc_create_fragmentshader(vbyte *data, int length) {
kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t));
kinc_g4_shader_init(shader, data, length, KINC_G4_SHADER_TYPE_FRAGMENT);
return (vbyte *)shader;
}
vbyte *hl_kinc_create_geometryshader(vbyte *data, int length) {
kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t));
kinc_g4_shader_init(shader, data, length, KINC_G4_SHADER_TYPE_GEOMETRY);
return (vbyte *)shader;
}
vbyte *hl_kinc_create_tesscontrolshader(vbyte *data, int length) {
kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t));
kinc_g4_shader_init(shader, data, length, KINC_G4_SHADER_TYPE_TESSELLATION_CONTROL);
return (vbyte *)shader;
}
vbyte *hl_kinc_create_tessevalshader(vbyte *data, int length) {
kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t));
kinc_g4_shader_init(shader, data, length, KINC_G4_SHADER_TYPE_TESSELLATION_EVALUATION);
return (vbyte *)shader;
}
vbyte *hl_kinc_vertexshader_from_source(vbyte *source) {
kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t));
kinc_g4_shader_init_from_source(shader, (char *)source, KINC_G4_SHADER_TYPE_VERTEX);
return (vbyte *)shader;
}
vbyte *hl_kinc_fragmentshader_from_source(vbyte *source) {
kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t));
kinc_g4_shader_init_from_source(shader, (char *)source, KINC_G4_SHADER_TYPE_FRAGMENT);
return (vbyte *)shader;
}
vbyte *hl_kinc_geometryshader_from_source(vbyte *source) {
kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t));
kinc_g4_shader_init_from_source(shader, (char *)source, KINC_G4_SHADER_TYPE_GEOMETRY);
return (vbyte *)shader;
}
vbyte *hl_kinc_tesscontrolshader_from_source(vbyte *source) {
kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t));
kinc_g4_shader_init_from_source(shader, (char *)source, KINC_G4_SHADER_TYPE_TESSELLATION_CONTROL);
return (vbyte *)shader;
}
vbyte *hl_kinc_tessevalshader_from_source(vbyte *source) {
kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t));
kinc_g4_shader_init_from_source(shader, (char *)source, KINC_G4_SHADER_TYPE_TESSELLATION_EVALUATION);
return (vbyte *)shader;
}
vbyte *hl_kinc_create_pipeline() {
kinc_g4_pipeline_t *pipeline = (kinc_g4_pipeline_t *)malloc(sizeof(kinc_g4_pipeline_t));
kinc_g4_pipeline_init(pipeline);
return (vbyte *)pipeline;
}
void hl_kinc_delete_pipeline(vbyte *pipeline) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
kinc_g4_pipeline_destroy(pipe);
free(pipe);
}
void hl_kinc_pipeline_set_vertex_shader(vbyte *pipeline, vbyte *shader) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
kinc_g4_shader_t *sh = (kinc_g4_shader_t *)shader;
pipe->vertex_shader = sh;
}
void hl_kinc_pipeline_set_fragment_shader(vbyte *pipeline, vbyte *shader) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
kinc_g4_shader_t *sh = (kinc_g4_shader_t *)shader;
pipe->fragment_shader = sh;
}
void hl_kinc_pipeline_set_geometry_shader(vbyte *pipeline, vbyte *shader) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
kinc_g4_shader_t *sh = (kinc_g4_shader_t *)shader;
pipe->geometry_shader = sh;
}
void hl_kinc_pipeline_set_tesscontrol_shader(vbyte *pipeline, vbyte *shader) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
kinc_g4_shader_t *sh = (kinc_g4_shader_t *)shader;
pipe->tessellation_control_shader = sh;
}
void hl_kinc_pipeline_set_tesseval_shader(vbyte *pipeline, vbyte *shader) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
kinc_g4_shader_t *sh = (kinc_g4_shader_t *)shader;
pipe->tessellation_evaluation_shader = sh;
}
void hl_kinc_pipeline_compile(vbyte *pipeline, vbyte *structure0, vbyte *structure1, vbyte *structure2, vbyte *structure3) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
pipe->input_layout[0] = (kinc_g4_vertex_structure_t *)structure0;
pipe->input_layout[1] = (kinc_g4_vertex_structure_t *)structure1;
pipe->input_layout[2] = (kinc_g4_vertex_structure_t *)structure2;
pipe->input_layout[3] = (kinc_g4_vertex_structure_t *)structure3;
pipe->input_layout[4] = NULL;
kinc_g4_pipeline_compile(pipe);
}
void hl_kinc_pipeline_set_states(vbyte *pipeline, int cullMode, int depthMode, int stencilFrontMode, int stencilFrontBothPass, int stencilFrontDepthFail,
int stencilFrontFail, int stencilBackMode, int stencilBackBothPass, int stencilBackDepthFail, int stencilBackFail,
int blendSource, int blendDestination, int alphaBlendSource, int alphaBlendDestination, bool depthWrite,
int stencilReferenceValue, int stencilReadMask, int stencilWriteMask, bool colorWriteMaskRed, bool colorWriteMaskGreen,
bool colorWriteMaskBlue, bool colorWriteMaskAlpha, int colorAttachmentCount, int colorAttachment0, int colorAttachment1,
int colorAttachment2, int colorAttachment3, int colorAttachment4, int colorAttachment5, int colorAttachment6,
int colorAttachment7, int depthAttachmentBits, int stencilAttachmentBits, bool conservativeRasterization) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
switch (cullMode) {
case 0:
pipe->cull_mode = KINC_G4_CULL_CLOCKWISE;
break;
case 1:
pipe->cull_mode = KINC_G4_CULL_COUNTER_CLOCKWISE;
break;
case 2:
pipe->cull_mode = KINC_G4_CULL_NOTHING;
break;
}
pipe->depth_mode = convertCompareMode(depthMode);
pipe->depth_write = depthWrite;
pipe->stencil_front_mode = convertCompareMode(stencilFrontMode);
pipe->stencil_front_both_pass = convertStencilAction(stencilFrontBothPass);
pipe->stencil_front_depth_fail = convertStencilAction(stencilFrontDepthFail);
pipe->stencil_front_fail = convertStencilAction(stencilFrontFail);
pipe->stencil_back_mode = convertCompareMode(stencilBackMode);
pipe->stencil_back_both_pass = convertStencilAction(stencilBackBothPass);
pipe->stencil_back_depth_fail = convertStencilAction(stencilBackDepthFail);
pipe->stencil_back_fail = convertStencilAction(stencilBackFail);
pipe->stencil_reference_value = stencilReferenceValue;
pipe->stencil_read_mask = stencilReadMask;
pipe->stencil_write_mask = stencilWriteMask;
pipe->blend_source = (kinc_g4_blending_factor_t)blendSource;
pipe->blend_destination = (kinc_g4_blending_factor_t)blendDestination;
pipe->alpha_blend_source = (kinc_g4_blending_factor_t)alphaBlendSource;
pipe->alpha_blend_destination = (kinc_g4_blending_factor_t)alphaBlendDestination;
pipe->color_write_mask_red[0] = colorWriteMaskRed;
pipe->color_write_mask_green[0] = colorWriteMaskGreen;
pipe->color_write_mask_blue[0] = colorWriteMaskBlue;
pipe->color_write_mask_alpha[0] = colorWriteMaskAlpha;
pipe->color_attachment_count = colorAttachmentCount;
pipe->color_attachment[0] = convertColorAttachment(colorAttachment0);
pipe->color_attachment[1] = convertColorAttachment(colorAttachment1);
pipe->color_attachment[2] = convertColorAttachment(colorAttachment2);
pipe->color_attachment[3] = convertColorAttachment(colorAttachment3);
pipe->color_attachment[4] = convertColorAttachment(colorAttachment4);
pipe->color_attachment[5] = convertColorAttachment(colorAttachment5);
pipe->color_attachment[6] = convertColorAttachment(colorAttachment6);
pipe->color_attachment[7] = convertColorAttachment(colorAttachment7);
pipe->depth_attachment_bits = depthAttachmentBits;
pipe->stencil_attachment_bits = stencilAttachmentBits;
pipe->conservative_rasterization = conservativeRasterization;
}
void hl_kinc_pipeline_set(vbyte *pipeline) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
kinc_g4_set_pipeline(pipe);
}
vbyte *hl_kinc_pipeline_get_constantlocation(vbyte *pipeline, vbyte *name) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
kinc_g4_constant_location_t *location = (kinc_g4_constant_location_t *)malloc(sizeof(kinc_g4_constant_location_t));
*location = kinc_g4_pipeline_get_constant_location(pipe, (char *)name);
return (vbyte *)location;
}
vbyte *hl_kinc_pipeline_get_textureunit(vbyte *pipeline, vbyte *name) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
kinc_g4_texture_unit_t *unit = (kinc_g4_texture_unit_t *)malloc(sizeof(kinc_g4_texture_unit_t));
*unit = kinc_g4_pipeline_get_texture_unit(pipe, (char *)name);
return (vbyte *)unit;
}

View File

@ -1,201 +0,0 @@
#include <kinc/input/acceleration.h>
#include <kinc/input/gamepad.h>
#include <kinc/input/keyboard.h>
#include <kinc/input/mouse.h>
#include <kinc/input/pen.h>
#include <kinc/input/rotation.h>
#include <kinc/input/surface.h>
#include <kinc/log.h>
#include <kinc/system.h>
#include <kinc/video.h>
#include <kinc/window.h>
#include <hl.h>
void hl_kinc_log(vbyte *v) {
kinc_log(KINC_LOG_LEVEL_INFO, (char *)v);
}
double hl_kinc_get_time(void) {
return kinc_time();
}
int hl_kinc_get_window_width(int window) {
return kinc_window_width(window);
}
int hl_kinc_get_window_height(int window) {
return kinc_window_height(window);
}
vbyte *hl_kinc_get_system_id(void) {
return (vbyte *)kinc_system_id();
}
void hl_kinc_vibrate(int ms) {
kinc_vibrate(ms);
}
vbyte *hl_kinc_get_language(void) {
return (vbyte *)kinc_language();
}
void hl_kinc_request_shutdown(void) {
kinc_stop();
}
void hl_kinc_mouse_lock(int windowId) {
kinc_mouse_lock(windowId);
}
void hl_kinc_mouse_unlock(void) {
kinc_mouse_unlock();
}
bool hl_kinc_can_lock_mouse(void) {
return kinc_mouse_can_lock();
}
bool hl_kinc_is_mouse_locked(void) {
return kinc_mouse_is_locked();
}
void hl_kinc_show_mouse(bool show) {
if (show) {
kinc_mouse_show();
}
else {
kinc_mouse_hide();
}
}
bool hl_kinc_system_is_fullscreen(void) {
return false; // kinc_is_fullscreen();
}
void hl_kinc_system_request_fullscreen(void) {
// kinc_change_resolution(display_width(), display_height(), true);
}
void hl_kinc_system_exit_fullscreen(int previousWidth, int previousHeight) {
// kinc_change_resolution(previousWidth, previousHeight, false);
}
void hl_kinc_system_change_resolution(int width, int height) {
// kinc_change_resolution(width, height, false);
}
void hl_kinc_system_set_keepscreenon(bool on) {
kinc_set_keep_screen_on(on);
}
void hl_kinc_system_load_url(vbyte *url) {
kinc_load_url((char *)url);
}
vbyte *hl_kinc_get_gamepad_id(int index) {
return (vbyte *)kinc_gamepad_product_name(index);
}
vbyte *hl_kinc_get_gamepad_vendor(int index) {
return (vbyte *)kinc_gamepad_vendor(index);
}
bool hl_kinc_gamepad_connected(int index) {
return kinc_gamepad_connected(index);
}
typedef void (*FN_KEY_DOWN)(int, void *);
typedef void (*FN_KEY_UP)(int, void *);
typedef void (*FN_KEY_PRESS)(unsigned int, void *);
void hl_kinc_register_keyboard(vclosure *keyDown, vclosure *keyUp, vclosure *keyPress) {
kinc_keyboard_set_key_down_callback(*((FN_KEY_DOWN *)(&keyDown->fun)), NULL);
kinc_keyboard_set_key_up_callback(*((FN_KEY_UP *)(&keyUp->fun)), NULL);
kinc_keyboard_set_key_press_callback(*((FN_KEY_PRESS *)(&keyPress->fun)), NULL);
}
typedef void (*FN_MOUSE_DOWN)(int, int, int, int, void *);
typedef void (*FN_MOUSE_UP)(int, int, int, int, void *);
typedef void (*FN_MOUSE_MOVE)(int, int, int, int, int, void *);
typedef void (*FN_MOUSE_WHEEL)(int, int, void *);
void hl_kinc_register_mouse(vclosure *mouseDown, vclosure *mouseUp, vclosure *mouseMove, vclosure *mouseWheel) {
kinc_mouse_set_press_callback(*((FN_MOUSE_DOWN *)(&mouseDown->fun)), NULL);
kinc_mouse_set_release_callback(*((FN_MOUSE_UP *)(&mouseUp->fun)), NULL);
kinc_mouse_set_move_callback(*((FN_MOUSE_MOVE *)(&mouseMove->fun)), NULL);
kinc_mouse_set_scroll_callback(*((FN_MOUSE_WHEEL *)(&mouseWheel->fun)), NULL);
}
typedef void (*FN_PEN_DOWN)(int, int, int, float);
typedef void (*FN_PEN_UP)(int, int, int, float);
typedef void (*FN_PEN_MOVE)(int, int, int, float);
void hl_kinc_register_pen(vclosure *penDown, vclosure *penUp, vclosure *penMove) {
kinc_pen_set_press_callback(*((FN_PEN_DOWN *)(&penDown->fun)));
kinc_pen_set_release_callback(*((FN_PEN_UP *)(&penUp->fun)));
kinc_pen_set_move_callback(*((FN_PEN_MOVE *)(&penMove->fun)));
}
typedef void (*FN_GAMEPAD_AXIS)(int, int, float, void *);
typedef void (*FN_GAMEPAD_BUTTON)(int, int, float, void *);
void hl_kinc_register_gamepad(vclosure *gamepadAxis, vclosure *gamepadButton) {
kinc_gamepad_set_axis_callback(*((FN_GAMEPAD_AXIS *)(&gamepadAxis->fun)), NULL);
kinc_gamepad_set_button_callback(*((FN_GAMEPAD_BUTTON *)(&gamepadButton->fun)), NULL);
}
typedef void (*FN_TOUCH_START)(int, int, int);
typedef void (*FN_TOUCH_END)(int, int, int);
typedef void (*FN_TOUCH_MOVE)(int, int, int);
void hl_kinc_register_surface(vclosure *touchStart, vclosure *touchEnd, vclosure *touchMove) {
kinc_surface_set_touch_start_callback(*((FN_TOUCH_START *)(&touchStart->fun)));
kinc_surface_set_touch_end_callback(*((FN_TOUCH_END *)(&touchEnd->fun)));
kinc_surface_set_move_callback(*((FN_TOUCH_MOVE *)(&touchMove->fun)));
}
typedef void (*FN_SENSOR_ACCELEROMETER)(float, float, float);
typedef void (*FN_SENSOR_GYROSCOPE)(float, float, float);
void hl_kinc_register_sensor(vclosure *accelerometerChanged, vclosure *gyroscopeChanged) {
kinc_acceleration_set_callback(*((FN_SENSOR_ACCELEROMETER *)(&accelerometerChanged->fun)));
kinc_rotation_set_callback(*((FN_SENSOR_GYROSCOPE *)(&gyroscopeChanged->fun)));
}
// typedef void(*FN_CB_ORIENTATION)(int);
typedef void (*FN_CB_FOREGROUND)(void *);
typedef void (*FN_CB_RESUME)(void *);
typedef void (*FN_CB_PAUSE)(void *);
typedef void (*FN_CB_BACKGROUND)(void *);
typedef void (*FN_CB_SHUTDOWN)(void *);
void hl_kinc_register_callbacks(vclosure *foreground, vclosure *resume, vclosure *pause, vclosure *background, vclosure *shutdown) {
// kinc_set_orientation_callback(orientation);
kinc_set_foreground_callback(*((FN_CB_FOREGROUND *)(&foreground->fun)), NULL);
kinc_set_resume_callback(*((FN_CB_RESUME *)(&resume->fun)), NULL);
kinc_set_pause_callback(*((FN_CB_PAUSE *)(&pause->fun)), NULL);
kinc_set_background_callback(*((FN_CB_BACKGROUND *)(&background->fun)), NULL);
kinc_set_shutdown_callback(*((FN_CB_SHUTDOWN *)(&shutdown->fun)), NULL);
}
typedef void (*FN_CB_DROPFILES)(wchar_t *);
void hl_kinc_register_dropfiles(vclosure *dropFiles) {
// todo: string convert
// kinc_set_drop_files_callback(*((FN_CB_DROPFILES*)(&dropFiles->fun)));
}
typedef char *(*FN_CB_COPY)(void *);
typedef char *(*FN_CB_CUT)(void *);
typedef void (*FN_CB_PASTE)(char *, void *);
void hl_kinc_register_copycutpaste(vclosure *copy, vclosure *cut, vclosure *paste) {
kinc_set_copy_callback(*((FN_CB_COPY *)(&copy->fun)), NULL);
kinc_set_cut_callback(*((FN_CB_CUT *)(&cut->fun)), NULL);
kinc_set_paste_callback(*((FN_CB_PASTE *)(&paste->fun)), NULL);
}
const char *hl_kinc_video_format(void) {
return kinc_video_formats()[0];
}

View File

@ -1,327 +0,0 @@
#include <kinc/graphics4/graphics.h>
#include <kinc/image.h>
#include <kinc/video.h>
#include <hl.h>
#include <assert.h>
typedef struct tex_and_data {
kinc_g4_texture_t texture;
int width, height;
void *data;
} tex_and_data_t;
static kinc_image_format_t convertImageFormat(int format) {
switch (format) {
default:
case 0:
return KINC_IMAGE_FORMAT_RGBA32;
case 1:
return KINC_IMAGE_FORMAT_GREY8;
case 2:
return KINC_IMAGE_FORMAT_RGBA128;
case 4:
return KINC_IMAGE_FORMAT_RGBA64;
case 5:
return KINC_IMAGE_FORMAT_A32;
case 6:
return KINC_IMAGE_FORMAT_A16;
}
}
static int sizeOf(kinc_image_format_t format) {
switch (format) {
case KINC_IMAGE_FORMAT_RGBA128:
return 16;
case KINC_IMAGE_FORMAT_RGBA32:
case KINC_IMAGE_FORMAT_BGRA32:
return 4;
case KINC_IMAGE_FORMAT_RGBA64:
return 8;
case KINC_IMAGE_FORMAT_A32:
return 4;
case KINC_IMAGE_FORMAT_A16:
return 2;
case KINC_IMAGE_FORMAT_GREY8:
return 1;
case KINC_IMAGE_FORMAT_RGB24:
return 3;
}
assert(false);
return 0;
}
vbyte *hl_kinc_texture_create(int width, int height, int format, bool readable) {
tex_and_data_t *texture = (tex_and_data_t *)malloc(sizeof(tex_and_data_t));
kinc_image_format_t f = convertImageFormat(format);
kinc_g4_texture_init(&texture->texture, width, height, f);
texture->width = width;
texture->height = height;
if (readable) {
texture->data = malloc(width * height * sizeOf(f));
}
else {
texture->data = NULL;
}
return (vbyte *)texture;
}
vbyte *hl_kinc_texture_create_from_file(vbyte *filename, bool readable) {
size_t size = kinc_image_size_from_file((char *)filename);
if (size > 0) {
tex_and_data_t *texture = (tex_and_data_t *)malloc(sizeof(tex_and_data_t));
texture->data = malloc(size);
kinc_image_t image;
if (kinc_image_init_from_file(&image, texture->data, (char *)filename) != 0) {
kinc_g4_texture_init_from_image(&texture->texture, &image);
texture->width = image.width;
texture->height = image.height;
if (!readable) {
free(texture->data);
texture->data = NULL;
}
kinc_image_destroy(&image);
return (vbyte *)texture;
}
kinc_image_destroy(&image);
free(texture->data);
texture->data = NULL;
free(texture);
}
return NULL;
}
vbyte *hl_kinc_texture_create3d(int width, int height, int depth, int format, bool readable) {
tex_and_data_t *texture = (tex_and_data_t *)malloc(sizeof(tex_and_data_t));
kinc_image_format_t f = convertImageFormat(format);
kinc_g4_texture_init(&texture->texture, width, height, f);
texture->width = width;
texture->height = height;
if (readable) {
texture->data = malloc(width * height * depth * sizeOf(f));
}
else {
texture->data = NULL;
}
return (vbyte *)texture;
}
vbyte *hl_kinc_video_get_current_image(vbyte *video) {
kinc_video_t *v = (kinc_video_t *)video;
return (vbyte *)kinc_video_current_image(v);
}
vbyte *hl_kinc_texture_from_bytes(vbyte *bytes, int width, int height, int format, bool readable) {
kinc_image_format_t f = convertImageFormat(format);
kinc_image_t image;
kinc_image_init(&image, bytes, width, height, f);
tex_and_data_t *texture = (tex_and_data_t *)malloc(sizeof(tex_and_data_t));
kinc_g4_texture_init_from_image(&texture->texture, &image);
texture->width = width;
texture->height = height;
kinc_image_destroy(&image);
if (readable) {
size_t size = width * height * sizeOf(f);
texture->data = malloc(size);
memcpy(texture->data, bytes, size);
}
else {
texture->data = NULL;
}
return (vbyte *)texture;
}
vbyte *hl_kinc_texture_from_bytes3d(vbyte *bytes, int width, int height, int depth, int format, bool readable) {
kinc_image_format_t f = convertImageFormat(format);
kinc_image_t image;
kinc_image_init3d(&image, bytes, width, height, depth, f);
tex_and_data_t *texture = (tex_and_data_t *)malloc(sizeof(tex_and_data_t));
kinc_g4_texture_init_from_image3d(&texture->texture, &image);
texture->width = width;
texture->height = height;
kinc_image_destroy(&image);
if (readable) {
size_t size = width * height * depth * sizeOf(f);
texture->data = malloc(size);
memcpy(texture->data, bytes, size);
}
else {
texture->data = NULL;
}
return (vbyte *)texture;
}
vbyte *hl_kinc_texture_from_encoded_bytes(vbyte *bytes, int length, vbyte *format, bool readable) {
tex_and_data_t *texture = (tex_and_data_t *)malloc(sizeof(tex_and_data_t));
size_t size = kinc_image_size_from_encoded_bytes(bytes, length, (char *)format);
texture->data = malloc(size);
kinc_image_t image;
kinc_image_init_from_encoded_bytes(&image, texture->data, bytes, length, (char *)format);
kinc_g4_texture_init_from_image(&texture->texture, &image);
texture->width = image.width;
texture->height = image.height;
kinc_image_destroy(&image);
if (!readable) {
free(texture->data);
texture->data = NULL;
}
return (vbyte *)texture;
}
bool hl_kinc_non_pow2_textures_supported(void) {
return kinc_g4_supports_non_pow2_textures();
}
int hl_kinc_texture_get_width(vbyte *texture) {
tex_and_data_t *tex = (tex_and_data_t *)texture;
return tex->width;
}
int hl_kinc_texture_get_height(vbyte *texture) {
tex_and_data_t *tex = (tex_and_data_t *)texture;
return tex->height;
}
int hl_kinc_texture_get_real_width(vbyte *texture) {
kinc_g4_texture_t *tex = (kinc_g4_texture_t *)texture;
return tex->tex_width;
}
int hl_kinc_texture_get_real_height(vbyte *texture) {
kinc_g4_texture_t *tex = (kinc_g4_texture_t *)texture;
return tex->tex_height;
}
int hl_kinc_texture_get_stride(vbyte *texture) {
kinc_g4_texture_t *tex = (kinc_g4_texture_t *)texture;
return kinc_g4_texture_stride(tex);
}
int hl_kinc_texture_at(vbyte *texture, int x, int y) {
tex_and_data_t *tex = (tex_and_data_t *)texture;
assert(tex->data != NULL);
return *(int *)&((uint8_t *)tex->data)[tex->width * sizeOf(tex->texture.format) * y + x * sizeOf(tex->texture.format)];
}
void hl_kinc_texture_unload(vbyte *texture) {
tex_and_data_t *tex = (tex_and_data_t *)texture;
if (tex->data != NULL) {
free(tex->data);
tex->data = NULL;
}
kinc_g4_texture_destroy(&tex->texture);
free(tex);
}
void hl_kinc_render_target_unload(vbyte *renderTarget) {
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
kinc_g4_render_target_destroy(rt);
free(rt);
}
vbyte *hl_kinc_render_target_create(int width, int height, int depthBufferBits, int format, int stencilBufferBits) {
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)malloc(sizeof(kinc_g4_render_target_t));
kinc_g4_render_target_init(rt, width, height, (kinc_g4_render_target_format_t)format, depthBufferBits, stencilBufferBits);
return (vbyte *)rt;
}
int hl_kinc_render_target_get_width(vbyte *renderTarget) {
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
return rt->width;
}
int hl_kinc_render_target_get_height(vbyte *renderTarget) {
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
return rt->height;
}
int hl_kinc_render_target_get_real_width(vbyte *renderTarget) {
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
return rt->texWidth;
}
int hl_kinc_render_target_get_real_height(vbyte *renderTarget) {
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
return rt->texHeight;
}
void hl_kinc_texture_unlock(vbyte *texture, vbyte *bytes) {
kinc_g4_texture_t *tex = (kinc_g4_texture_t *)texture;
uint8_t *b = (uint8_t *)bytes;
uint8_t *btex = kinc_g4_texture_lock(tex);
int size = sizeOf(tex->format);
int stride = kinc_g4_texture_stride(tex);
for (int y = 0; y < tex->tex_height; ++y) {
for (int x = 0; x < tex->tex_width; ++x) {
#ifdef KORE_DIRECT3D
if (tex->format == KINC_IMAGE_FORMAT_RGBA32) {
// RBGA->BGRA
btex[y * stride + x * size + 0] = b[(y * tex->tex_width + x) * size + 2];
btex[y * stride + x * size + 1] = b[(y * tex->tex_width + x) * size + 1];
btex[y * stride + x * size + 2] = b[(y * tex->tex_width + x) * size + 0];
btex[y * stride + x * size + 3] = b[(y * tex->tex_width + x) * size + 3];
}
else
#endif
{
for (int i = 0; i < size; ++i) {
btex[y * stride + x * size + i] = b[(y * tex->tex_width + x) * size + i];
}
}
}
}
kinc_g4_texture_unlock(tex);
}
void hl_kinc_render_target_get_pixels(vbyte *renderTarget, vbyte *pixels) {
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
kinc_g4_render_target_get_pixels(rt, pixels);
}
void hl_kinc_generate_mipmaps_texture(vbyte *texture, int levels) {
kinc_g4_texture_t *tex = (kinc_g4_texture_t *)texture;
kinc_g4_texture_generate_mipmaps(tex, levels);
}
void hl_kinc_generate_mipmaps_target(vbyte *renderTarget, int levels) {
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
kinc_g4_render_target_generate_mipmaps(rt, levels);
}
void hl_kinc_set_mipmap_texture(vbyte *texture, vbyte *mipmap, int level) {
kinc_g4_texture_t *tex = (kinc_g4_texture_t *)texture;
tex_and_data_t *miptex = (tex_and_data_t *)mipmap;
assert(miptex->data != NULL);
kinc_image_t mipimage;
kinc_image_init(&mipimage, miptex->data, miptex->width, miptex->height, miptex->texture.format);
kinc_g4_texture_set_mipmap(tex, &mipimage, level);
kinc_image_destroy(&mipimage);
}
void hl_kinc_render_target_set_depth_stencil_from(vbyte *renderTarget, vbyte *from) {
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
kinc_g4_render_target_t *rt2 = (kinc_g4_render_target_t *)from;
kinc_g4_render_target_set_depth_stencil_from(rt, rt2);
}
void hl_kinc_texture_clear(vbyte *texture, int x, int y, int z, int width, int height, int depth, int color) {
kinc_g4_texture_t *tex = (kinc_g4_texture_t *)texture;
kinc_g4_texture_clear(tex, x, y, z, width, height, depth, color);
}

View File

@ -1,154 +0,0 @@
let project = new Project('Kha');
const pcreVersion = '10.42';
const tlsVersion = '2.28.2';
const zlibVersion = '1.2.13';
project.addFiles('khacpp/src/**.h', 'khacpp/src/**.cpp', 'khacpp/include/**.h');
project.addFiles('khacpp/project/libs/common/**.h', 'khacpp/project/libs/common/**.cpp');
if (platform === Platform.Windows || platform === Platform.WindowsApp) project.addFiles('khacpp/project/libs/msvccompat/**.cpp');
if (platform === Platform.Linux) project.addFiles('khacpp/project/libs/linuxcompat/**.cpp');
project.addFiles('khacpp/project/libs/regexp/**.h', 'khacpp/project/libs/regexp/**.cpp', 'khacpp/project/libs/std/**.h', 'khacpp/project/libs/std/**.cpp');
project.addFiles('khacpp/project/thirdparty/pcre2-' + pcreVersion + '-8/src/**.h', 'khacpp/project/thirdparty/pcre2-' + pcreVersion + '-8/src/**.c');
project.addFiles('khacpp/project/thirdparty/pcre2-' + pcreVersion + '-16/src/**.h', 'khacpp/project/thirdparty/pcre2-' + pcreVersion + '-16/src/**.c');
const zlibFiles = [
'**.h',
'adler32.c',
'compress.c',
'crc32.c',
'gzio.c',
'uncompr.c',
'deflate.c',
'trees.c',
'zutil.c',
'inflate.c',
'infback.c',
'inftrees.c',
'inffast.c'
];
for (const file of zlibFiles) {
project.addFile('khacpp/project/thirdparty/zlib-' + zlibVersion + '/' + file);
}
project.addFiles('khacpp/project/thirdparty/mbedtls-' + tlsVersion + '/**');
project.addFiles('*.cpp', '*.c', 'Backends/Kore/*.h', '*.natvis');
project.addFiles('lib/**');
project.addIncludeDir('lib');
const pcreExcludes = [
'pcre2_dftables.c',
'pcre2_fuzzsupport.c',
'pcre2_printint.c',
'pcre2_jit_match.c',
'pcre2_jit_misc.c',
'pcre2_jit_test.c',
'pcre2_ucptables.c',
'pcre2demo.c',
'pcre2grep.c',
'pcre2posix.h',
'pcre2posix.c',
'pcre2posix_test.c',
'pcre2test.c',
'sljit/**'
];
for (const file of pcreExcludes) {
project.addExclude('khacpp/project/thirdparty/pcre2-' + pcreVersion + '-8/src/' + file);
project.addExclude('khacpp/project/thirdparty/pcre2-' + pcreVersion + '-16/src/' + file);
}
project.addExcludes('khacpp/src/ExampleMain.cpp', 'khacpp/src/hx/Scriptable.cpp', 'khacpp/src/hx/NoFiles.cpp', 'khacpp/src/hx/cppia/**');
project.addExcludes('khacpp/src/hx/Debugger.cpp', 'khacpp/src/hx/Profiler.cpp', 'khacpp/src/hx/Telemetry.cpp');
project.addExcludes('khacpp/src/hx/NekoAPI.cpp');
project.addExcludes('khacpp/src/hx/libs/sqlite/**');
project.addExcludes('khacpp/src/hx/libs/mysql/**');
project.addIncludeDirs('khacpp/include', 'khacpp/project/thirdparty/zlib-' + zlibVersion, 'khacpp/project/libs/nekoapi', 'khacpp/project/thirdparty/mbedtls-' + tlsVersion + '/include');
project.addIncludeDir('khacpp/src/hx/libs/ssl');
//if (options.vrApi == "rift") {
// out += "project.addIncludeDirs('C:/khaviar/LibOVRKernel/Src/');\n";
// out += "project.addIncludeDirs('C:/khaviar/LibOVR/Include/');\n";
//}
if (platform !== Platform.Android) {
project.addExcludes('khacpp/src/hx/AndroidCompat.cpp');
}
if (platform === Platform.Windows) {
project.addDefine('HX_WINDOWS');
project.addLib('Shlwapi');
project.addLib('Crypt32');
}
if (platform === Platform.WindowsApp) {
project.addDefine('HX_WINDOWS');
project.addDefine('HX_WINRT');
}
if (platform !== Platform.Windows || audio !== AudioApi.DirectSound) {
project.addDefine('KORE_MULTITHREADED_AUDIO');
}
if (platform === Platform.OSX) {
project.addDefine('HXCPP_M64');
project.addDefine('HX_MACOS');
}
if (platform === Platform.Linux) project.addDefine('HX_LINUX');
if (platform === Platform.iOS) {
project.addDefine('IPHONE');
project.addDefine('HX_IPHONE');
}
if (platform === Platform.tvOS) {
project.addDefine('APPLETV');
}
if (platform === Platform.Android) {
project.addDefine('ANDROID');
project.addDefine('_ANDROID');
project.addDefine('HX_ANDROID');
project.addDefine('HXCPP_ANDROID_PLATFORM=24');
}
if (platform === Platform.OSX) {
project.addDefine('KORE_DEBUGDIR="osx"');
project.addLib('Security');
}
if (platform === Platform.iOS) project.addDefine('KORE_DEBUGDIR="ios"');
// project:addDefine('HXCPP_SCRIPTABLE');
project.addDefine('STATIC_LINK');
project.addDefine('PCRE2_STATIC');
project.addDefine('HXCPP_VISIT_ALLOCS');
project.addDefine('KHA');
project.addDefine('KORE');
project.addDefine('ROTATE90');
project.addDefine('HAVE_CONFIG_H');
project.addDefine('SUPPORT_UTF');
project.addDefine('SUPPORT_UCP');
project.addDefine('SUPPORT_UNICODE');
project.addDefine('MBEDTLS_USER_CONFIG_FILE="mbedtls_config.h"');
project.addDefine('HX_SMART_STRINGS');
//if (Options.vrApi === "gearvr") {
// out += "project.addDefine('VR_GEAR_VR');\n";
//}
//else if (Options.vrApi === "cardboard") {
// out += "project.addDefine('VR_CARDBOARD');\n";
//}
//else if (Options.vrApi === "rift") {
// out += "project.addDefine('VR_RIFT');\n";
//}
//
//if (options.vrApi == "rift") {
// out += "project.addLib('C:/khaviar/LibOVRKernel/Lib/Windows/Win32/Release/VS2013/LibOVRKernel');\n";
// out += "project.addLib('C:/khaviar/LibOVR/Lib/Windows/Win32/Release/VS2013/LibOVR');\n";
//}
if (platform === Platform.Windows || platform === Platform.WindowsApp) {
project.addDefine('_WINSOCK_DEPRECATED_NO_WARNINGS');
}
if (platform === Platform.Windows) {
project.addLib('ws2_32');
}
resolve(project);

View File

@ -1,559 +0,0 @@
package kha;
import haxe.io.Bytes;
import haxe.io.BytesData;
import kha.kore.graphics4.TextureUnit;
import kha.graphics4.TextureFormat;
import kha.graphics4.DepthStencilFormat;
import kha.graphics4.Usage;
@:headerCode("
#include <kinc/graphics4/rendertarget.h>
#include <kinc/graphics4/texture.h>
#include <kinc/graphics4/texturearray.h>
#include <kinc/video.h>
#include <assert.h>
enum KhaImageType {
KhaImageTypeNone,
KhaImageTypeTexture,
KhaImageTypeRenderTarget,
KhaImageTypeTextureArray
};
")
@:headerClassCode("
KhaImageType imageType;
int originalWidth;
int originalHeight;
uint8_t *imageData;
bool ownsImageData;
kinc_g4_texture_t texture;
kinc_g4_render_target_t renderTarget;
kinc_g4_texture_array_t textureArray;
")
class Image implements Canvas implements Resource {
var myFormat: TextureFormat;
var readable: Bool;
var graphics1: kha.graphics1.Graphics;
var graphics2: kha.graphics2.Graphics;
var graphics4: kha.graphics4.Graphics;
public static function fromVideo(video: Video): Image {
var image = new Image(false, false);
image.myFormat = RGBA32;
image.initVideo(cast(video, kha.kore.Video));
return image;
}
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, 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,
antiAliasingSamples: Int = 1): Image {
return _create2(width, height, format == null ? TextureFormat.RGBA32 : format, false, true, depthStencil, antiAliasingSamples);
}
/**
* The provided images need to be readable.
*/
public static function createArray(images: Array<Image>, format: TextureFormat = null): Image {
var image = new Image(false);
image.myFormat = (format == null) ? TextureFormat.RGBA32 : format;
initArrayTexture(image, images);
return image;
}
@:functionCode("
kinc_image_t *kincImages = (kinc_image_t*)malloc(sizeof(kinc_image_t) * images->length);
for (unsigned i = 0; i < images->length; ++i) {
kinc_image_init(&kincImages[i], images->__get(i).StaticCast<::kha::Image>()->imageData, images->__get(i).StaticCast<::kha::Image>()->originalWidth, images->__get(i).StaticCast<::kha::Image>()->originalHeight, (kinc_image_format_t)getTextureFormat(images->__get(i).StaticCast<::kha::Image>()->myFormat));
}
kinc_g4_texture_array_init(&source->textureArray, kincImages, images->length);
for (unsigned i = 0; i < images->length; ++i) {
kinc_image_destroy(&kincImages[i]);
}
free(kincImages);
")
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, readable: Bool = false): Image {
var image = new Image(readable);
image.myFormat = format;
image.initFromBytes(bytes.getData(), width, height, getTextureFormat(format));
return image;
}
@:functionCode("
kinc_image_t image;
kinc_image_init(&image, bytes.GetPtr()->GetBase(), width, height, (kinc_image_format_t)format);
kinc_g4_texture_init_from_image(&texture, &image);
if (readable) {
imageData = (uint8_t*)image.data;
}
kinc_image_destroy(&image);
imageType = KhaImageTypeTexture;
originalWidth = width;
originalHeight = height;
")
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,
readable: Bool = false): Image {
var image = new Image(readable);
image.myFormat = format;
image.initFromBytes3D(bytes.getData(), width, height, depth, getTextureFormat(format));
return image;
}
@:functionCode("
kinc_image_t image;
kinc_image_init3d(&image, bytes.GetPtr()->GetBase(), width, height, depth, (kinc_image_format_t)format);
kinc_g4_texture_init_from_image3d(&texture, &image);
if (readable) {
imageData = (uint8_t*)image.data;
}
kinc_image_destroy(&image);
imageType = KhaImageTypeTexture;
originalWidth = width;
originalHeight = height;
")
function initFromBytes3D(bytes: BytesData, width: Int, height: Int, depth: Int, format: Int): Void {}
public static function fromEncodedBytes(bytes: Bytes, format: String, doneCallback: Image->Void, errorCallback: String->Void,
readable: Bool = false): Void {
var image = new Image(readable);
var isFloat = format == "hdr" || format == "HDR";
image.myFormat = isFloat ? TextureFormat.RGBA128 : TextureFormat.RGBA32;
image.initFromEncodedBytes(bytes.getData(), format);
doneCallback(image);
}
@:functionCode("
size_t size = kinc_image_size_from_encoded_bytes(bytes.GetPtr()->GetBase(), bytes.GetPtr()->length, format.c_str());
void* data = malloc(size);
kinc_image_t image;
kinc_image_init_from_encoded_bytes(&image, data, bytes.GetPtr()->GetBase(), bytes.GetPtr()->length, format.c_str());
originalWidth = image.width;
originalHeight = image.height;
kinc_g4_texture_init_from_image(&texture, &image);
if (readable) {
imageData = (uint8_t*)image.data;
}
kinc_image_destroy(&image);
if (!readable) {
free(data);
}
imageType = KhaImageTypeTexture;
")
function initFromEncodedBytes(bytes: BytesData, format: String): Void {}
function new(readable: Bool, ?dispose = true) {
this.readable = readable;
nullify();
if (dispose) {
cpp.vm.Gc.setFinalizer(this, cpp.Function.fromStaticFunction(finalize));
}
}
@:functionCode("
imageType = KhaImageTypeNone;
originalWidth = 0;
originalHeight = 0;
imageData = NULL;
ownsImageData = false;
")
function nullify() {}
@:functionCode("
if (image->imageType != KhaImageTypeNone) {
image->unload();
}
")
@:void static function finalize(image: Image): Void {}
static function getRenderTargetFormat(format: TextureFormat): Int {
switch (format) {
case RGBA32: // Target32Bit
return 0;
case RGBA64: // Target64BitFloat
return 1;
case A32: // Target32BitRedFloat
return 2;
case RGBA128: // Target128BitFloat
return 3;
case DEPTH16: // Target16BitDepth
return 4;
case L8:
return 5; // Target8BitRed
case A16:
return 6; // Target16BitRedFloat
default:
return 0;
}
}
static function getDepthBufferBits(depthAndStencil: DepthStencilFormat): Int {
return switch (depthAndStencil) {
case NoDepthAndStencil: -1;
case DepthOnly: 24;
case DepthAutoStencilAuto: 24;
case Depth24Stencil8: 24;
case Depth32Stencil8: 32;
case Depth16: 16;
}
}
static function getStencilBufferBits(depthAndStencil: DepthStencilFormat): Int {
return switch (depthAndStencil) {
case NoDepthAndStencil: -1;
case DepthOnly: -1;
case DepthAutoStencilAuto: 8;
case Depth24Stencil8: 8;
case Depth32Stencil8: 8;
case Depth16: 0;
}
}
static function getTextureFormat(format: TextureFormat): Int {
switch (format) {
case RGBA32:
return 0;
case RGBA128:
return 3;
case RGBA64:
return 4;
case A32:
return 5;
case A16:
return 7;
default:
return 1; // Grey8
}
}
@:noCompletion
public static function _create2(width: Int, height: Int, format: TextureFormat, readable: Bool, renderTarget: Bool, depthStencil: DepthStencilFormat,
samplesPerPixel: Int): Image {
var image = new Image(readable);
image.myFormat = format;
if (renderTarget)
image.initRenderTarget(width, height, getRenderTargetFormat(format), getDepthBufferBits(depthStencil), getStencilBufferBits(depthStencil),
samplesPerPixel);
else
image.init(width, height, getTextureFormat(format));
return image;
}
@:noCompletion
public static function _create3(width: Int, height: Int, depth: Int, format: TextureFormat, readable: Bool, contextId: Int): Image {
var image = new Image(readable);
image.myFormat = format;
image.init3D(width, height, depth, getTextureFormat(format));
return image;
}
@:functionCode("
kinc_g4_render_target_init_with_multisampling(&renderTarget, width, height, (kinc_g4_render_target_format_t)format, depthBufferBits, stencilBufferBits, samplesPerPixel);
imageType = KhaImageTypeRenderTarget;
originalWidth = width;
originalHeight = height;
")
function initRenderTarget(width: Int, height: Int, format: Int, depthBufferBits: Int, stencilBufferBits: Int, samplesPerPixel: Int): Void {}
@:functionCode("
kinc_g4_texture_init(&texture, width, height, (kinc_image_format_t)format);
imageType = KhaImageTypeTexture;
originalWidth = width;
originalHeight = height;
")
function init(width: Int, height: Int, format: Int): Void {}
@:functionCode("
kinc_g4_texture_init3d(&texture, width, height, depth, (kinc_image_format_t)format);
imageType = KhaImageTypeTexture;
originalWidth = width;
originalHeight = height;
")
function init3D(width: Int, height: Int, depth: Int, format: Int): Void {}
@:functionCode("
texture = *kinc_video_current_image(&video->video);
imageType = KhaImageTypeTexture;
")
function initVideo(video: kha.kore.Video): Void {}
public static function createEmpty(readable: Bool, floatFormat: Bool): Image {
var image = new Image(readable);
image.myFormat = floatFormat ? TextureFormat.RGBA128 : TextureFormat.RGBA32;
return image;
}
/*public static function fromFile(filename: String, readable: Bool): Image {
var image = new Image(readable);
var isFloat = StringTools.endsWith(filename, ".hdr");
image.format = isFloat ? TextureFormat.RGBA128 : TextureFormat.RGBA32;
image.initFromFile(filename);
return image;
}
@:functionCode('texture = new Kore::Graphics4::Texture(filename.c_str(), readable);')
private function initFromFile(filename: String): Void {
}*/
public var g1(get, never): kha.graphics1.Graphics;
function get_g1(): kha.graphics1.Graphics {
if (graphics1 == null) {
graphics1 = new kha.graphics2.Graphics1(this);
}
return graphics1;
}
public var g2(get, never): kha.graphics2.Graphics;
function get_g2(): kha.graphics2.Graphics {
if (graphics2 == null) {
graphics2 = new kha.kore.graphics4.Graphics2(this);
}
return graphics2;
}
public var g4(get, never): kha.graphics4.Graphics;
function get_g4(): kha.graphics4.Graphics {
if (graphics4 == null) {
graphics4 = new kha.kore.graphics4.Graphics(this);
}
return graphics4;
}
public static var maxSize(get, never): Int;
static function get_maxSize(): Int {
return 4096;
}
public static var nonPow2Supported(get, never): Bool;
@:functionCode("return kinc_g4_supports_non_pow2_textures();")
static function get_nonPow2Supported(): Bool {
return false;
}
@:functionCode("return kinc_g4_render_targets_inverted_y();")
public static function renderTargetsInvertedY(): Bool {
return false;
}
public var width(get, never): Int;
@:functionCode("return originalWidth;")
function get_width(): Int {
return 0;
}
public var height(get, never): Int;
@:functionCode("return originalHeight;")
function get_height(): Int {
return 0;
}
public var depth(get, never): Int;
@:functionCode("if (imageType == KhaImageTypeTexture) return texture.tex_depth; else return 0;")
function get_depth(): Int {
return 0;
}
public var format(get, never): TextureFormat;
@:functionCode("if (imageType == KhaImageTypeTexture) return texture.format; else return 0;")
function get_format(): TextureFormat {
return TextureFormat.RGBA32;
}
public var realWidth(get, never): Int;
@:functionCode("if (imageType == KhaImageTypeTexture) return texture.tex_width; else if (imageType == KhaImageTypeRenderTarget) return renderTarget.width; else return 0;")
function get_realWidth(): Int {
return 0;
}
public var realHeight(get, never): Int;
@:functionCode("if (imageType == KhaImageTypeTexture) return texture.tex_height; else if (imageType == KhaImageTypeRenderTarget) return renderTarget.height; else return 0;")
function get_realHeight(): Int {
return 0;
}
public function isOpaque(x: Int, y: Int): Bool {
return isOpaqueInternal(x, y, getTextureFormat(myFormat));
}
@:functionCode("
kinc_image_t image;
kinc_image_init(&image, imageData, originalWidth, originalHeight, (kinc_image_format_t)format);
bool opaque = (kinc_image_at(&image, x, y) & 0xff) != 0;
kinc_image_destroy(&image);
return opaque;
")
function isOpaqueInternal(x: Int, y: Int, format: Int): Bool {
return true;
}
public inline function at(x: Int, y: Int): Color {
return Color.fromValue(atInternal(x, y, getTextureFormat(myFormat)));
}
@:functionCode("
kinc_image_t image;
kinc_image_init(&image, imageData, originalWidth, originalHeight, (kinc_image_format_t)format);
int value = kinc_image_at(&image, x, y);
kinc_image_destroy(&image);
return value;
")
function atInternal(x: Int, y: Int, format: Int): Int {
return 0;
}
@:keep
@:functionCode("
if (imageType == KhaImageTypeTexture) {
kinc_g4_texture_destroy(&texture);
}
else if (imageType == KhaImageTypeRenderTarget) {
kinc_g4_render_target_destroy(&renderTarget);
}
else if (imageType == KhaImageTypeTextureArray) {
kinc_g4_texture_array_destroy(&textureArray);
}
else {
assert(false);
}
if (ownsImageData) {
free(imageData);
}
imageData = NULL;
imageType = KhaImageTypeNone;
")
public function unload(): Void {}
var bytes: Bytes = null;
@:functionCode("
int size = kinc_image_format_sizeof(texture.format) * originalWidth * originalHeight;
this->bytes = ::haxe::io::Bytes_obj::alloc(size);
return this->bytes;
")
public function lock(level: Int = 0): Bytes {
return null;
}
@:functionCode("
uint8_t *b = bytes->b->Pointer();
uint8_t *tex = kinc_g4_texture_lock(&texture);
int size = kinc_image_format_sizeof(texture.format);
int stride = kinc_g4_texture_stride(&texture);
for (int y = 0; y < texture.tex_height; ++y) {
for (int x = 0; x < texture.tex_width; ++x) {
#ifdef KORE_DIRECT3D
if (texture.format == KINC_IMAGE_FORMAT_RGBA32) {
//RBGA->BGRA
tex[y * stride + x * size + 0] = b[(y * originalWidth + x) * size + 2];
tex[y * stride + x * size + 1] = b[(y * originalWidth + x) * size + 1];
tex[y * stride + x * size + 2] = b[(y * originalWidth + x) * size + 0];
tex[y * stride + x * size + 3] = b[(y * originalWidth + x) * size + 3];
}
else
#endif
{
for (int i = 0; i < size; ++i) {
tex[y * stride + x * size + i] = b[(y * originalWidth + x) * size + i];
}
}
}
}
kinc_g4_texture_unlock(&texture);
")
public function unlock(): Void {
bytes = null;
}
@:ifFeature("kha.Image.getPixelsInternal")
var pixels: Bytes = null;
@:ifFeature("kha.Image.getPixelsInternal")
var pixelsAllocated: Bool = false;
@:functionCode("
if (imageType != KhaImageTypeRenderTarget) return NULL;
if (!this->pixelsAllocated) {
int size = formatSize * renderTarget.width * renderTarget.height;
this->pixels = ::haxe::io::Bytes_obj::alloc(size);
this->pixelsAllocated = true;
}
uint8_t *b = this->pixels->b->Pointer();
kinc_g4_render_target_get_pixels(&renderTarget, b);
return this->pixels;
")
function getPixelsInternal(formatSize: Int): Bytes {
return null;
}
public function getPixels(): Bytes {
return getPixelsInternal(formatByteSize(myFormat));
}
static function formatByteSize(format: TextureFormat): Int {
return switch (format) {
case RGBA32: 4;
case L8: 1;
case RGBA128: 16;
case DEPTH16: 2;
case RGBA64: 8;
case A32: 4;
case A16: 2;
default: 4;
}
}
public function generateMipmaps(levels: Int): Void {
untyped __cpp__("if (imageType == KhaImageTypeTexture) kinc_g4_texture_generate_mipmaps(&texture, levels); else if (imageType == KhaImageTypeRenderTarget) kinc_g4_render_target_generate_mipmaps(&renderTarget, levels)");
}
public function setMipmaps(mipmaps: Array<Image>): Void {
for (i in 0...mipmaps.length) {
var khaImage = mipmaps[i];
var level = i + 1;
var format = getTextureFormat(this.format);
untyped __cpp__("
kinc_image_t image;
kinc_image_init(&image, {0}->imageData, {0}->originalWidth, {0}->originalHeight, (kinc_image_format_t){2});
kinc_g4_texture_set_mipmap(&texture, &image, {1});
kinc_image_destroy(&image);
", khaImage, level, format);
}
}
public function setDepthStencilFrom(image: Image): Void {
untyped __cpp__("kinc_g4_render_target_set_depth_stencil_from(&renderTarget, &image->renderTarget)");
}
@:functionCode("if (imageType == KhaImageTypeTexture) kinc_g4_texture_clear(&texture, x, y, z, width, height, depth, color);")
public function clear(x: Int, y: Int, z: Int, width: Int, height: Int, depth: Int, color: Color): Void {}
public var stride(get, never): Int;
@:functionCode("if (imageType == KhaImageTypeTexture) return kinc_g4_texture_stride(&texture); else if (imageType == KhaImageTypeRenderTarget) return formatByteSize(myFormat) * renderTarget.width; else return 0;")
function get_stride(): Int {
return 0;
}
}

View File

@ -1,519 +0,0 @@
package kha;
import kha.input.Gamepad;
import kha.input.KeyCode;
import kha.input.Keyboard;
import kha.input.Mouse;
import kha.input.Pen;
import kha.input.Sensor;
import kha.input.SensorType;
import kha.input.Surface;
import kha.System;
import kha.graphics4.TextureFormat;
import kha.graphics4.DepthStencilFormat;
#if ANDROID
#if VR_CARDBOARD
import kha.kore.vr.CardboardVrInterface;
#end
#if !VR_CARDBOARD
import kha.kore.vr.VrInterface;
#end
#end
#if !ANDROID
#if VR_RIFT
import kha.kore.vr.VrInterfaceRift;
#end
#if !VR_RIFT
import kha.vr.VrInterfaceEmulated;
#end
#end
@:headerCode("
#include <kinc/system.h>
#include <kinc/input/gamepad.h>
#include <kinc/input/mouse.h>
#include <kinc/input/pen.h>
#include <kinc/display.h>
#include <kinc/window.h>
kinc_window_options_t convertWindowOptions(::kha::WindowOptions win);
kinc_framebuffer_options_t convertFramebufferOptions(::kha::FramebufferOptions frame);
void init_kinc(const char *name, int width, int height, kinc_window_options_t *win, kinc_framebuffer_options_t *frame);
void post_kinc_init();
void kha_kinc_init_audio(void);
void run_kinc();
const char *getGamepadId(int index);
const char *getGamepadVendor(int index);
void setGamepadRumble(int index, float left, float right);
")
@:keep
class SystemImpl {
public static var needs3d: Bool = false;
public static function getMouse(num: Int): Mouse {
if (num != 0)
return null;
return mouse;
}
public static function getPen(num: Int): Pen {
if (num != 0)
return null;
return pen;
}
public static function getKeyboard(num: Int): Keyboard {
if (num != 0)
return null;
return keyboard;
}
@:functionCode("return kinc_time();")
public static function getTime(): Float {
return 0;
}
public static function windowWidth(windowId: Int): Int {
return untyped __cpp__("kinc_window_width(windowId)");
}
public static function windowHeight(windowId: Int): Int {
return untyped __cpp__("kinc_window_height(windowId)");
}
public static function screenDpi(): Int {
return untyped __cpp__("kinc_display_current_mode(kinc_primary_display()).pixels_per_inch");
}
public static function getVsync(): Bool {
return true;
}
public static function getRefreshRate(): Int {
return 60;
}
public static function getScreenRotation(): ScreenRotation {
return ScreenRotation.RotationNone;
}
@:functionCode("return ::String(kinc_system_id());")
public static function getSystemId(): String {
return "";
}
public static function vibrate(ms: Int): Void {
untyped __cpp__("kinc_vibrate(ms)");
}
@:functionCode("return ::String(kinc_language());")
public static function getLanguage(): String {
return "en";
}
public static function requestShutdown(): Bool {
untyped __cpp__("kinc_stop()");
return true;
}
static var framebuffers: Array<Framebuffer> = new Array();
static var keyboard: Keyboard;
static var mouse: kha.input.Mouse;
static var pen: kha.input.Pen;
static var gamepads: Array<Gamepad>;
static var surface: Surface;
static var mouseLockListeners: Array<Void->Void>;
public static function init(options: SystemOptions, callback: Window->Void): Void {
initKinc(options.title, options.width, options.height, options.window, options.framebuffer);
Window._init();
kha.Worker._mainThread = sys.thread.Thread.current();
untyped __cpp__("post_kinc_init()");
Shaders.init();
#if (!VR_GEAR_VR && !VR_RIFT)
var g4 = new kha.kore.graphics4.Graphics();
g4.window = 0;
// var g5 = new kha.kore.graphics5.Graphics();
var framebuffer = new Framebuffer(0, null, null, g4 /*, g5*/);
framebuffer.init(new kha.graphics2.Graphics1(framebuffer), new kha.kore.graphics4.Graphics2(framebuffer), g4 /*, g5*/);
framebuffers.push(framebuffer);
#end
postInit(callback);
}
static function onWindowCreated(index: Int) {
var g4 = new kha.kore.graphics4.Graphics();
g4.window = index;
var framebuffer = new Framebuffer(index, null, null, g4);
framebuffer.init(new kha.graphics2.Graphics1(framebuffer), new kha.kore.graphics4.Graphics2(framebuffer), g4);
framebuffers.push(framebuffer);
}
static function postInit(callback: Window->Void) {
mouseLockListeners = new Array();
haxe.Timer.stamp();
Sensor.get(SensorType.Accelerometer); // force compilation
keyboard = new kha.kore.Keyboard();
mouse = new kha.input.MouseImpl();
pen = new kha.input.Pen();
gamepads = new Array<Gamepad>();
for (i in 0...4) {
gamepads[i] = new Gamepad(i);
gamepads[i].connected = checkGamepadConnected(i);
}
surface = new Surface();
kha.audio2.Audio._init();
kha.audio1.Audio._init();
untyped __cpp__("kha_kinc_init_audio()");
Scheduler.init();
loadFinished();
callback(Window.get(0));
untyped __cpp__("run_kinc()");
}
static function loadFinished() {
Scheduler.start();
/*
#if ANDROID
#if VR_GEAR_VR
kha.vr.VrInterface.instance = new kha.kore.vr.VrInterface();
#end
#if !VR_GEAR_VR
kha.vr.VrInterface.instance = new CardboardVrInterface();
#end
#end
#if !ANDROID
#if VR_RIFT
kha.vr.VrInterface.instance = new VrInterfaceRift();
#end
#if !VR_RIFT
kha.vr.VrInterface.instance = new kha.vr.VrInterfaceEmulated();
#end
#end
*/
// (DK) moved
/*Shaders.init();
#if (!VR_GEAR_VR && !VR_RIFT)
var g4 = new kha.kore.graphics4.Graphics();
framebuffers.push(new Framebuffer(null, null, g4));
framebuffers[0].init(new kha.graphics2.Graphics1(framebuffers[0]), new kha.kore.graphics4.Graphics2(framebuffers[0]), g4);
g4 = new kha.kore.graphics4.Graphics();
framebuffers.push(new Framebuffer(null, null, g4));
framebuffers[1].init(new kha.graphics2.Graphics1(framebuffers[1]), new kha.kore.graphics4.Graphics2(framebuffers[1]), g4);
#end
*/}
public static function lockMouse(windowId: Int = 0): Void {
if (!isMouseLocked()) {
untyped __cpp__("kinc_mouse_lock(windowId);");
for (listener in mouseLockListeners) {
listener();
}
}
}
public static function unlockMouse(windowId: Int = 0): Void {
if (isMouseLocked()) {
untyped __cpp__("kinc_mouse_unlock();");
for (listener in mouseLockListeners) {
listener();
}
}
}
public static function canLockMouse(windowId: Int = 0): Bool {
return untyped __cpp__("kinc_mouse_can_lock()");
}
public static function isMouseLocked(windowId: Int = 0): Bool {
return untyped __cpp__("kinc_mouse_is_locked()");
}
public static function notifyOfMouseLockChange(func: Void->Void, error: Void->Void, windowId: Int = 0): Void {
if (canLockMouse(windowId) && func != null) {
mouseLockListeners.push(func);
}
}
public static function removeFromMouseLockChange(func: Void->Void, error: Void->Void, windowId: Int = 0): Void {
if (canLockMouse(windowId) && func != null) {
mouseLockListeners.remove(func);
}
}
public static function hideSystemCursor(): Void {
untyped __cpp__("kinc_mouse_hide();");
}
public static function showSystemCursor(): Void {
untyped __cpp__("kinc_mouse_show();");
}
public static function setSystemCursor(cursor: Int): Void {
untyped __cpp__("kinc_mouse_set_cursor(cursor)");
}
public static function frame() {
/*
#if !ANDROID
#if !VR_RIFT
if (framebuffer == null) return;
var vrInterface: VrInterfaceEmulated = cast(VrInterface.instance, VrInterfaceEmulated);
vrInterface.framebuffer = framebuffer;
#end
#else
#if VR_CARDBOARD
var vrInterface: CardboardVrInterface = cast(VrInterface.instance, CardboardVrInterface);
vrInterface.framebuffer = framebuffer;
#end
#end
*/
LoaderImpl.tick();
Scheduler.executeFrame();
System.render(framebuffers);
if (kha.kore.graphics4.Graphics.lastWindow != -1) {
var win = kha.kore.graphics4.Graphics.lastWindow;
untyped __cpp__("kinc_g4_end({0})", win);
}
else {
untyped __cpp__("kinc_g4_begin(0)");
untyped __cpp__("kinc_g4_clear(KINC_G4_CLEAR_COLOR | KINC_G4_CLEAR_DEPTH | KINC_G4_CLEAR_STENCIL, 0, 0.0f, 0)");
untyped __cpp__("kinc_g4_end(0)");
}
kha.kore.graphics4.Graphics.lastWindow = -1;
for (i in 0...4) {
if (gamepads[i].connected && !checkGamepadConnected(i)) {
Gamepad.sendDisconnectEvent(i);
}
else if (!gamepads[i].connected && checkGamepadConnected(i)) {
Gamepad.sendConnectEvent(i);
}
}
}
@:functionCode("return kinc_gamepad_connected(i);")
static function checkGamepadConnected(i: Int): Bool {
return true;
}
public static function keyDown(code: KeyCode): Void {
keyboard.sendDownEvent(code);
}
public static function keyUp(code: KeyCode): Void {
keyboard.sendUpEvent(code);
}
public static function keyPress(char: Int): Void {
keyboard.sendPressEvent(String.fromCharCode(char));
}
public static var mouseX: Int;
public static var mouseY: Int;
public static function mouseDown(windowId: Int, button: Int, x: Int, y: Int): Void {
mouseX = x;
mouseY = y;
mouse.sendDownEvent(windowId, button, x, y);
}
public static function mouseUp(windowId: Int, button: Int, x: Int, y: Int): Void {
mouseX = x;
mouseY = y;
mouse.sendUpEvent(windowId, button, x, y);
}
public static function mouseMove(windowId: Int, x: Int, y: Int, movementX: Int, movementY: Int): Void {
// var movementX = x - mouseX;
// var movementY = y - mouseY;
mouseX = x;
mouseY = y;
mouse.sendMoveEvent(windowId, x, y, movementX, movementY);
}
public static function mouseWheel(windowId: Int, delta: Int): Void {
mouse.sendWheelEvent(windowId, delta);
}
public static function mouseLeave(windowId: Int): Void {
mouse.sendLeaveEvent(windowId);
}
public static function penDown(windowId: Int, x: Int, y: Int, pressure: Float): Void {
pen.sendDownEvent(windowId, x, y, pressure);
}
public static function penUp(windowId: Int, x: Int, y: Int, pressure: Float): Void {
pen.sendUpEvent(windowId, x, y, pressure);
}
public static function penMove(windowId: Int, x: Int, y: Int, pressure: Float): Void {
pen.sendMoveEvent(windowId, x, y, pressure);
}
public static function penEraserDown(windowId: Int, x: Int, y: Int, pressure: Float): Void {
pen.sendEraserDownEvent(windowId, x, y, pressure);
}
public static function penEraserUp(windowId: Int, x: Int, y: Int, pressure: Float): Void {
pen.sendEraserUpEvent(windowId, x, y, pressure);
}
public static function penEraserMove(windowId: Int, x: Int, y: Int, pressure: Float): Void {
pen.sendEraserMoveEvent(windowId, x, y, pressure);
}
public static function gamepadAxis(gamepad: Int, axis: Int, value: Float): Void {
gamepads[gamepad].sendAxisEvent(axis, value);
}
public static function gamepadButton(gamepad: Int, button: Int, value: Float): Void {
gamepads[gamepad].sendButtonEvent(button, value);
}
public static function touchStart(index: Int, x: Int, y: Int): Void {
surface.sendTouchStartEvent(index, x, y);
}
public static function touchEnd(index: Int, x: Int, y: Int): Void {
surface.sendTouchEndEvent(index, x, y);
}
public static function touchMove(index: Int, x: Int, y: Int): Void {
surface.sendMoveEvent(index, x, y);
}
public static function foreground(): Void {
System.foreground();
}
public static function resume(): Void {
System.resume();
}
public static function pause(): Void {
System.pause();
}
public static function background(): Void {
System.background();
}
public static function shutdown(): Void {
System.shutdown();
}
public static function dropFiles(filePath: String): Void {
System.dropFiles(filePath);
}
public static function copy(): String {
if (System.copyListener != null) {
return System.copyListener();
}
else {
return null;
}
}
public static function cut(): String {
if (System.cutListener != null) {
return System.cutListener();
}
else {
return null;
}
}
public static function paste(data: String): Void {
if (System.pasteListener != null) {
System.pasteListener(data);
}
}
@:functionCode("kinc_copy_to_clipboard(text.c_str());")
public static function copyToClipboard(text: String) {}
@:functionCode("kinc_login();")
public static function login(): Void {}
@:functionCode("return kinc_waiting_for_login();")
public static function waitingForLogin(): Bool {
return false;
}
@:functionCode("kinc_disallow_user_change();")
public static function disallowUserChange(): Void {}
@:functionCode("kinc_allow_user_change();")
public static function allowUserChange(): Void {}
public static function loginevent(): Void {
if (System.loginListener != null) {
System.loginListener();
}
}
public static function logoutevent(): Void {
if (System.logoutListener != null) {
System.logoutListener();
}
}
@:functionCode("
kinc_window_options_t window = convertWindowOptions(win);
kinc_framebuffer_options_t framebuffer = convertFramebufferOptions(frame);
init_kinc(name, width, height, &window, &framebuffer);
")
static function initKinc(name: String, width: Int, height: Int, win: WindowOptions, frame: FramebufferOptions): Void {}
public static function setKeepScreenOn(on: Bool): Void {
untyped __cpp__("kinc_set_keep_screen_on(on)");
}
public static function loadUrl(url: String): Void {
untyped __cpp__("kinc_load_url(url)");
}
@:functionCode("return ::String(::getGamepadId(index));")
public static function getGamepadId(index: Int): String {
return "unknown";
}
@:functionCode("return ::String(::getGamepadVendor(index));")
public static function getGamepadVendor(index: Int): String {
return "unknown";
}
public static function setGamepadRumble(index: Int, leftAmount: Float, rightAmount: Float): Void {
untyped __cpp__("::setGamepadRumble(index, leftAmount, rightAmount)");
}
public static function safeZone(): Float {
return untyped __cpp__("kinc_safe_zone()");
}
public static function automaticSafeZone(): Bool {
return untyped __cpp__("kinc_automatic_safe_zone()");
}
public static function setSafeZone(value: Float): Void {
untyped __cpp__("kinc_set_safe_zone(value)");
}
public static function unlockAchievement(id: Int): Void {
untyped __cpp__("kinc_unlock_achievement(id)");
}
}

View File

@ -1,176 +0,0 @@
package kha.compute;
import kha.arrays.Float32Array;
import kha.Image;
import kha.FastFloat;
import kha.math.FastMatrix3;
import kha.math.FastMatrix4;
import kha.math.FastVector2;
import kha.math.FastVector3;
import kha.math.FastVector4;
import kha.graphics4.CubeMap;
import kha.graphics4.TextureAddressing;
import kha.graphics4.TextureFilter;
import kha.graphics4.MipMapFilter;
@:headerCode("
#include <kinc/compute/compute.h>
")
class Compute {
public static function setBool(location: ConstantLocation, value: Bool) {
untyped __cpp__("kinc_compute_set_bool(location->location, value);");
}
public static function setInt(location: ConstantLocation, value: Int) {
untyped __cpp__("kinc_compute_set_int(location->location, value);");
}
public static function setFloat(location: ConstantLocation, value: FastFloat) {
untyped __cpp__("kinc_compute_set_float(location->location, value);");
}
public static function setFloat2(location: ConstantLocation, value1: FastFloat, value2: FastFloat) {
untyped __cpp__("kinc_compute_set_float2(location->location, value1, value2);");
}
public static function setFloat3(location: ConstantLocation, value1: FastFloat, value2: FastFloat, value3: FastFloat) {
untyped __cpp__("kinc_compute_set_float3(location->location, value1, value2, value3);");
}
public static function setFloat4(location: ConstantLocation, value1: FastFloat, value2: FastFloat, value3: FastFloat, value4: FastFloat) {
untyped __cpp__("kinc_compute_set_float4(location->location, value1, value2, value3, value4);");
}
public static function setFloats(location: ConstantLocation, values: Float32Array) {
untyped __cpp__("kinc_compute_set_floats(location->location, (float *)&values->self.data[values->byteArrayOffset], values->byteArrayLength);");
}
public static function setVector2(location: ConstantLocation, value: FastVector2): Void {
Compute.setFloat2(location, value.x, value.y);
}
public static function setVector3(location: ConstantLocation, value: FastVector3): Void {
Compute.setFloat3(location, value.x, value.y, value.z);
}
public static function setVector4(location: ConstantLocation, value: FastVector4): Void {
Compute.setFloat4(location, value.x, value.y, value.z, value.w);
}
public static function setMatrix(location: ConstantLocation, value: FastMatrix4): Void {
setMatrixPrivate(location, value);
}
public static function setMatrix3(location: ConstantLocation, value: FastMatrix3): Void {
setMatrix3Private(location, value);
}
@:functionCode("
kinc_matrix4x4_t value;
kinc_matrix4x4_set(&value, 0, 0, matrix->_00); kinc_matrix4x4_set(&value, 0, 1, matrix->_10); kinc_matrix4x4_set(&value, 0, 2, matrix->_20); kinc_matrix4x4_set(&value, 0, 3, matrix->_30);
kinc_matrix4x4_set(&value, 1, 0, matrix->_01); kinc_matrix4x4_set(&value, 1, 1, matrix->_11); kinc_matrix4x4_set(&value, 1, 2, matrix->_21); kinc_matrix4x4_set(&value, 1, 3, matrix->_31);
kinc_matrix4x4_set(&value, 2, 0, matrix->_02); kinc_matrix4x4_set(&value, 2, 1, matrix->_12); kinc_matrix4x4_set(&value, 2, 2, matrix->_22); kinc_matrix4x4_set(&value, 2, 3, matrix->_32);
kinc_matrix4x4_set(&value, 3, 0, matrix->_03); kinc_matrix4x4_set(&value, 3, 1, matrix->_13); kinc_matrix4x4_set(&value, 3, 2, matrix->_23); kinc_matrix4x4_set(&value, 3, 3, matrix->_33);
kinc_compute_set_matrix4(location->location, &value);
")
static function setMatrixPrivate(location: ConstantLocation, matrix: FastMatrix4): Void {}
@:functionCode("
kinc_matrix3x3_t value;
kinc_matrix3x3_set(&value, 0, 0, matrix->_00); kinc_matrix3x3_set(&value, 0, 1, matrix->_10); kinc_matrix3x3_set(&value, 0, 2, matrix->_20);
kinc_matrix3x3_set(&value, 1, 0, matrix->_01); kinc_matrix3x3_set(&value, 1, 1, matrix->_11); kinc_matrix3x3_set(&value, 1, 2, matrix->_21);
kinc_matrix3x3_set(&value, 2, 0, matrix->_02); kinc_matrix3x3_set(&value, 2, 1, matrix->_12); kinc_matrix3x3_set(&value, 2, 2, matrix->_22);
kinc_compute_set_matrix3(location->location, &value);
")
static function setMatrix3Private(location: ConstantLocation, matrix: FastMatrix3): Void {}
public static function setBuffer(buffer: ShaderStorageBuffer, index: Int) {
untyped __cpp__("
#ifdef KORE_OPENGL
kinc_compute_set_buffer(&buffer->buffer, index);
#endif
");
}
public static function setTexture(unit: TextureUnit, texture: Image, access: Access) {
setTexturePrivate(unit, texture, access);
}
@:functionCode("
if (texture->imageType == KhaImageTypeTexture) kinc_compute_set_texture(unit->unit, &texture->texture, (kinc_compute_access_t)access);
else if (texture->imageType == KhaImageTypeRenderTarget) kinc_compute_set_render_target(unit->unit, &texture->renderTarget, (kinc_compute_access_t)access);
")
static function setTexturePrivate(unit: TextureUnit, texture: Image, access: Int): Void {}
public static function setSampledTexture(unit: TextureUnit, texture: Image) {
setSampledTexturePrivate(unit, texture);
}
@:functionCode("
if (texture->imageType == KhaImageTypeTexture) kinc_compute_set_sampled_texture(unit->unit, &texture->texture);
else if (texture->imageType == KhaImageTypeRenderTarget) kinc_compute_set_sampled_render_target(unit->unit, &texture->renderTarget);
")
static function setSampledTexturePrivate(unit: TextureUnit, texture: Image): Void {}
public static function setSampledDepthTexture(unit: TextureUnit, texture: Image) {
untyped __cpp__("if (texture->imageType == KhaImageTypeRenderTarget) kinc_compute_set_sampled_depth_from_render_target(unit->unit, &texture->renderTarget);");
}
public static function setSampledCubeMap(unit: TextureUnit, cubeMap: CubeMap) {
setSampledCubeMapPrivate(unit, cubeMap);
}
@:functionCode("kinc_compute_set_sampled_render_target(unit->unit, &cubeMap->renderTarget);")
static function setSampledCubeMapPrivate(unit: TextureUnit, cubeMap: CubeMap): Void {}
public static function setSampledDepthCubeMap(unit: TextureUnit, cubeMap: CubeMap) {
untyped __cpp__("kinc_compute_set_sampled_depth_from_render_target(unit->unit, &cubeMap->renderTarget);");
}
@:functionCode("
kinc_compute_set_texture_addressing(unit->unit, KINC_G4_TEXTURE_DIRECTION_U, (kinc_g4_texture_addressing_t)uWrap);
kinc_compute_set_texture_addressing(unit->unit, KINC_G4_TEXTURE_DIRECTION_V, (kinc_g4_texture_addressing_t)vWrap);
")
static function setTextureWrapNative(unit: TextureUnit, uWrap: Int, vWrap: Int): Void {}
@:functionCode("
kinc_compute_set_texture3d_addressing(unit->unit, KINC_G4_TEXTURE_DIRECTION_U, (kinc_g4_texture_addressing_t)uWrap);
kinc_compute_set_texture3d_addressing(unit->unit, KINC_G4_TEXTURE_DIRECTION_V, (kinc_g4_texture_addressing_t)vWrap);
kinc_compute_set_texture3d_addressing(unit->unit, KINC_G4_TEXTURE_DIRECTION_W, (kinc_g4_texture_addressing_t)wWrap);
")
static function setTexture3DWrapNative(unit: TextureUnit, uWrap: Int, vWrap: Int, wWrap: Int): Void {}
@:functionCode("
kinc_compute_set_texture_minification_filter(unit->unit, (kinc_g4_texture_filter_t)minificationFilter);
kinc_compute_set_texture_magnification_filter(unit->unit, (kinc_g4_texture_filter_t)magnificationFilter);
kinc_compute_set_texture_mipmap_filter(unit->unit, (kinc_g4_mipmap_filter_t)mipMapFilter);
")
static function setTextureFiltersNative(unit: TextureUnit, minificationFilter: Int, magnificationFilter: Int, mipMapFilter: Int): Void {}
@:functionCode("
kinc_compute_set_texture3d_minification_filter(unit->unit, (kinc_g4_texture_filter_t)minificationFilter);
kinc_compute_set_texture3d_magnification_filter(unit->unit, (kinc_g4_texture_filter_t)magnificationFilter);
kinc_compute_set_texture3d_mipmap_filter(unit->unit, (kinc_g4_mipmap_filter_t)mipMapFilter);
")
static function setTexture3DFiltersNative(unit: TextureUnit, minificationFilter: Int, magnificationFilter: Int, mipMapFilter: Int): Void {}
public static function setTextureParameters(unit: TextureUnit, uAddressing: TextureAddressing, vAddressing: TextureAddressing,
minificationFilter: TextureFilter, magnificationFilter: TextureFilter, mipmapFilter: MipMapFilter): Void {
setTextureWrapNative(unit, uAddressing, vAddressing);
setTextureFiltersNative(unit, minificationFilter, magnificationFilter, mipmapFilter);
}
public static function setTexture3DParameters(unit: TextureUnit, uAddressing: TextureAddressing, vAddressing: TextureAddressing,
wAddressing: TextureAddressing, minificationFilter: TextureFilter, magnificationFilter: TextureFilter, mipmapFilter: MipMapFilter): Void {
setTexture3DWrapNative(unit, uAddressing, vAddressing, wAddressing);
setTexture3DFiltersNative(unit, minificationFilter, magnificationFilter, mipmapFilter);
}
public static function setShader(shader: Shader) {
untyped __cpp__("kinc_compute_set_shader(&shader->shader);");
}
public static function compute(x: Int, y: Int, z: Int) {
untyped __cpp__("kinc_compute(x, y, z);");
}
}

View File

@ -1,9 +0,0 @@
package kha.compute;
@:headerCode("
#include <kinc/compute/compute.h>
")
@:headerClassCode("kinc_compute_constant_location location;")
class ConstantLocation {
public function new() {}
}

View File

@ -1,45 +0,0 @@
package kha.compute;
import haxe.io.Bytes;
import kha.Blob;
@:headerCode("
#include <kinc/compute/compute.h>
")
@:headerClassCode("kinc_compute_shader shader;")
class Shader {
public function new(sources: Array<Blob>, files: Array<String>) {
init(sources[0], files[0]);
}
function init(source: Blob, file: String): Void {
untyped __cpp__("kinc_compute_shader_init(&shader, source->bytes->b->Pointer(), source->get_length());");
}
public function delete(): Void {
untyped __cpp__("kinc_compute_shader_destroy(&shader);");
}
public function getConstantLocation(name: String): ConstantLocation {
var location = new ConstantLocation();
initConstantLocation(location, name);
return location;
}
@:functionCode("location->location = kinc_compute_shader_get_constant_location(&shader, name.c_str());")
function initConstantLocation(location: ConstantLocation, name: String): Void {}
public function getTextureUnit(name: String): TextureUnit {
var unit = new TextureUnit();
initTextureUnit(unit, name);
return unit;
}
@:functionCode("unit->unit = kinc_compute_shader_get_texture_unit(&shader, name.c_str());")
function initTextureUnit(unit: TextureUnit, name: String): Void {}
@:keep
function _forceInclude(): Void {
Bytes.alloc(0);
}
}

View File

@ -1,77 +0,0 @@
package kha.compute;
import kha.graphics4.VertexData;
@:headerCode("
#include <kinc/compute/compute.h>
")
@:headerClassCode("
#ifdef KORE_OPENGL
kinc_shader_storage_buffer buffer;
#endif")
class ShaderStorageBuffer {
var data: Array<Int>;
var myCount: Int;
public function new(indexCount: Int, type: VertexData) {
myCount = indexCount;
data = new Array<Int>();
data[myCount - 1] = 0;
init(indexCount, type);
}
@:functionCode("
#ifdef KORE_OPENGL
kinc_g4_vertex_data type2;
switch (type) {
case 0:
type2 = KINC_G4_VERTEX_DATA_FLOAT1;
break;
case 1:
type2 = KINC_G4_VERTEX_DATA_FLOAT2;
break;
case 2:
type2 = KINC_G4_VERTEX_DATA_FLOAT3;
break;
case 3:
type2 = KINC_G4_VERTEX_DATA_FLOAT4;
break;
case 4:
type2 = KINC_G4_VERTEX_DATA_FLOAT4X4;
break;
}
kinc_shader_storage_buffer_init(&buffer, indexCount, type2);
#endif
")
function init(indexCount: Int, type: VertexData) {
myCount = indexCount;
data = new Array<Int>();
data[myCount - 1] = 0;
}
@:functionCode("
#ifdef KORE_OPENGL
kinc_shader_storage_buffer_destroy(&buffer);
#endif
")
public function delete(): Void {}
public function lock(): Array<Int> {
return data;
}
@:functionCode("
#ifdef KORE_OPENGL
int* indices = kinc_shader_storage_buffer_lock(&buffer);
for (int i = 0; i < myCount; ++i) {
indices[i] = data[i];
}
kinc_shader_storage_buffer_unlock(&buffer);
#endif
")
public function unlock(): Void {}
public function count(): Int {
return myCount;
}
}

View File

@ -1,9 +0,0 @@
package kha.compute;
@:headerCode("
#include <kinc/compute/compute.h>
")
@:headerClassCode("kinc_compute_texture_unit unit;")
class TextureUnit {
public function new() {}
}

View File

@ -1,503 +0,0 @@
package kha.kore.graphics4;
import kha.arrays.Float32Array;
import kha.Blob;
import kha.Canvas;
import kha.Color;
import kha.graphics4.CubeMap;
import kha.graphics4.CullMode;
import kha.graphics4.FragmentShader;
import kha.graphics4.BlendingFactor;
import kha.graphics4.BlendingOperation;
import kha.graphics4.CompareMode;
import kha.graphics4.MipMapFilter;
import kha.graphics4.PipelineState;
import kha.graphics4.StencilAction;
import kha.graphics4.TexDir;
import kha.graphics4.TextureAddressing;
import kha.graphics4.TextureFilter;
import kha.graphics4.TextureFormat;
import kha.graphics4.Usage;
import kha.graphics4.VertexBuffer;
import kha.graphics4.VertexShader;
import kha.graphics4.VertexStructure;
import kha.Image;
import kha.math.FastMatrix3;
import kha.math.FastMatrix4;
import kha.math.FastVector2;
import kha.math.FastVector3;
import kha.math.FastVector4;
import kha.math.Matrix4;
import kha.math.Vector2;
import kha.math.Vector3;
import kha.math.Vector4;
import kha.Video;
@:headerCode("
#include <kinc/display.h>
#include <kinc/graphics4/graphics.h>
#include <kinc/graphics4/rendertarget.h>
#include <kinc/window.h>
")
@:headerClassCode("kinc_g4_render_target_t *renderTarget = nullptr;")
class Graphics implements kha.graphics4.Graphics {
var target: Canvas;
public var window: Null<Int>;
public static var lastWindow: Int = -1;
static var current: Graphics = null;
public function new(target: Canvas = null) {
this.target = target;
init();
}
function init() {
if (target == null)
return;
if (Std.isOfType(target, CubeMap)) {
var cubeMap = cast(target, CubeMap);
untyped __cpp__("renderTarget = &{0}->renderTarget", cubeMap);
}
else {
var image = cast(target, Image);
untyped __cpp__("renderTarget = &{0}->renderTarget", image);
}
}
@:functionCode("return kinc_window_vsynced(0);")
public function vsynced(): Bool {
return true;
}
@:functionCode("return kinc_display_current_mode(kinc_primary_display()).frequency;")
public function refreshRate(): Int {
return 0;
}
public function clear(?color: Color, ?z: Float, ?stencil: Int): Void {
var flags: Int = 0;
if (color != null)
flags |= 1;
if (z != null)
flags |= 2;
if (stencil != null)
flags |= 4;
clear2(flags, color == null ? 0 : color.value, z, stencil);
}
@:functionCode("kinc_g4_viewport(x, y, width, height);")
public function viewport(x: Int, y: Int, width: Int, height: Int): Void {}
@:functionCode("kinc_g4_clear(flags, color, z, stencil);")
function clear2(flags: Int, color: Int, z: Float, stencil: Int): Void {}
// public function createVertexBuffer(vertexCount: Int, structure: VertexStructure, usage: Usage, canRead: Bool = false): kha.graphics4.VertexBuffer {
// return new VertexBuffer(vertexCount, structure);
// }
@:functionCode("kinc_g4_set_vertex_buffer(&vertexBuffer->buffer);")
public function setVertexBuffer(vertexBuffer: kha.graphics4.VertexBuffer): Void {}
@:functionCode("
kinc_g4_vertex_buffer_t* vertexBuffers[4] = {
vb0 == null() ? nullptr : &vb0->buffer,
vb1 == null() ? nullptr : &vb1->buffer,
vb2 == null() ? nullptr : &vb2->buffer,
vb3 == null() ? nullptr : &vb3->buffer
};
kinc_g4_set_vertex_buffers(vertexBuffers, count);
")
function setVertexBuffersInternal(vb0: VertexBuffer, vb1: VertexBuffer, vb2: VertexBuffer, vb3: VertexBuffer, count: Int): Void {}
public function setVertexBuffers(vertexBuffers: Array<kha.graphics4.VertexBuffer>): Void {
setVertexBuffersInternal(vertexBuffers.length > 0 ? vertexBuffers[0] : null, vertexBuffers.length > 1 ? vertexBuffers[1] : null,
vertexBuffers.length > 2 ? vertexBuffers[2] : null, vertexBuffers.length > 3 ? vertexBuffers[3] : null, vertexBuffers.length);
}
// public function createIndexBuffer(indexCount: Int, usage: Usage, canRead: Bool = false): kha.graphics.IndexBuffer {
// return new IndexBuffer(indexCount);
// }
@:functionCode("kinc_g4_set_index_buffer(&indexBuffer->buffer);")
public function setIndexBuffer(indexBuffer: kha.graphics4.IndexBuffer): Void {}
// public function createTexture(width: Int, height: Int, format: TextureFormat, usage: Usage, canRead: Bool = false, levels: Int = 1): Texture {
// return Image.create(width, height, format, canRead, false, false);
// }
// public function createRenderTargetTexture(width: Int, height: Int, format: TextureFormat, depthStencil: Bool, antiAliasingSamples: Int = 1): Texture {
// return Image.create(width, height, format, false, true, depthStencil);
// }
public function maxTextureSize(): Int {
return 4096;
}
public function supportsNonPow2Textures(): Bool {
return false;
}
public function setCubeMap(unit: kha.graphics4.TextureUnit, cubeMap: kha.graphics4.CubeMap): Void {
if (cubeMap == null)
return;
var koreUnit = cast(unit, kha.kore.graphics4.TextureUnit);
untyped __cpp__("kinc_g4_render_target_use_color_as_texture(&cubeMap->renderTarget, {0}->unit)", koreUnit);
}
public function setCubeMapDepth(unit: kha.graphics4.TextureUnit, cubeMap: kha.graphics4.CubeMap): Void {
if (cubeMap == null)
return;
var koreUnit = cast(unit, kha.kore.graphics4.TextureUnit);
untyped __cpp__("kinc_g4_render_target_use_depth_as_texture(&cubeMap->renderTarget, {0}->unit);", koreUnit);
}
@:functionCode("kinc_g4_scissor(x, y, width, height);")
public function scissor(x: Int, y: Int, width: Int, height: Int): Void {}
@:functionCode("kinc_g4_disable_scissor();")
public function disableScissor(): Void {}
public function instancedRenderingAvailable(): Bool {
return true;
}
@:functionCode("
kinc_g4_set_texture_addressing(unit->unit, KINC_G4_TEXTURE_DIRECTION_U, (kinc_g4_texture_addressing_t)uWrap);
kinc_g4_set_texture_addressing(unit->unit, KINC_G4_TEXTURE_DIRECTION_V, (kinc_g4_texture_addressing_t)vWrap);
")
function setTextureWrapNative(unit: TextureUnit, uWrap: Int, vWrap: Int): Void {}
@:functionCode("
kinc_g4_set_texture3d_addressing(unit->unit, KINC_G4_TEXTURE_DIRECTION_U, (kinc_g4_texture_addressing_t)uWrap);
kinc_g4_set_texture3d_addressing(unit->unit, KINC_G4_TEXTURE_DIRECTION_V, (kinc_g4_texture_addressing_t)vWrap);
kinc_g4_set_texture3d_addressing(unit->unit, KINC_G4_TEXTURE_DIRECTION_W, (kinc_g4_texture_addressing_t)wWrap);
")
function setTexture3DWrapNative(unit: TextureUnit, uWrap: Int, vWrap: Int, wWrap: Int): Void {}
@:functionCode("
kinc_g4_set_texture_minification_filter(unit->unit, (kinc_g4_texture_filter_t)minificationFilter);
kinc_g4_set_texture_magnification_filter(unit->unit, (kinc_g4_texture_filter_t)magnificationFilter);
kinc_g4_set_texture_mipmap_filter(unit->unit, (kinc_g4_mipmap_filter_t)mipMapFilter);
")
function setTextureFiltersNative(unit: TextureUnit, minificationFilter: Int, magnificationFilter: Int, mipMapFilter: Int): Void {}
@:functionCode("
kinc_g4_set_texture3d_minification_filter(unit->unit, (kinc_g4_texture_filter_t)minificationFilter);
kinc_g4_set_texture3d_magnification_filter(unit->unit, (kinc_g4_texture_filter_t)magnificationFilter);
kinc_g4_set_texture3d_mipmap_filter(unit->unit, (kinc_g4_mipmap_filter_t)mipMapFilter);
")
function setTexture3DFiltersNative(unit: TextureUnit, minificationFilter: Int, magnificationFilter: Int, mipMapFilter: Int): Void {}
public function setTextureParameters(texunit: kha.graphics4.TextureUnit, uAddressing: TextureAddressing, vAddressing: TextureAddressing,
minificationFilter: TextureFilter, magnificationFilter: TextureFilter, mipmapFilter: MipMapFilter): Void {
setTextureWrapNative(cast texunit, uAddressing, vAddressing);
setTextureFiltersNative(cast texunit, minificationFilter, magnificationFilter, mipmapFilter);
}
public function setTexture3DParameters(texunit: kha.graphics4.TextureUnit, uAddressing: TextureAddressing, vAddressing: TextureAddressing,
wAddressing: TextureAddressing, minificationFilter: TextureFilter, magnificationFilter: TextureFilter, mipmapFilter: MipMapFilter): Void {
setTexture3DWrapNative(cast texunit, uAddressing, vAddressing, wAddressing);
setTexture3DFiltersNative(cast texunit, minificationFilter, magnificationFilter, mipmapFilter);
}
public function setTextureCompareMode(texunit: kha.graphics4.TextureUnit, enabled: Bool) {
var koreUnit = cast(texunit, kha.kore.graphics4.TextureUnit);
untyped __cpp__("kinc_g4_set_texture_compare_mode({0}->unit, enabled);", koreUnit);
}
public function setCubeMapCompareMode(texunit: kha.graphics4.TextureUnit, enabled: Bool) {
var koreUnit = cast(texunit, kha.kore.graphics4.TextureUnit);
untyped __cpp__("kinc_g4_set_cubemap_compare_mode({0}->unit, enabled);", koreUnit);
}
@:functionCode("
if (texture->imageType == KhaImageTypeTexture) kinc_g4_set_texture(unit->unit, &texture->texture);
else if (texture->imageType == KhaImageTypeRenderTarget) kinc_g4_render_target_use_color_as_texture(&texture->renderTarget, unit->unit);
")
function setTextureInternal(unit: kha.kore.graphics4.TextureUnit, texture: kha.Image): Void {}
public function setTexture(unit: kha.graphics4.TextureUnit, texture: kha.Image): Void {
if (texture == null)
return;
setTextureInternal(cast unit, texture);
}
public function setTextureDepth(unit: kha.graphics4.TextureUnit, texture: kha.Image): Void {
if (texture == null)
return;
var koreUnit = cast(unit, kha.kore.graphics4.TextureUnit);
untyped __cpp__("kinc_g4_render_target_use_depth_as_texture(&texture->renderTarget, {0}->unit);", koreUnit);
}
public function setTextureArray(unit: kha.graphics4.TextureUnit, texture: kha.Image): Void {
if (texture == null)
return;
var koreUnit = cast(unit, kha.kore.graphics4.TextureUnit);
untyped __cpp__("if (texture->imageType == KhaImageTypeTextureArray) kinc_g4_set_texture_array({0}->unit, &texture->textureArray);", koreUnit);
}
public function setVideoTexture(unit: kha.graphics4.TextureUnit, texture: kha.Video): Void {
if (texture == null)
return;
setTextureInternal(cast unit, Image.fromVideo(texture));
}
@:functionCode("kinc_g4_set_image_texture(unit->unit, &texture->texture);")
function setImageTextureInternal(unit: kha.kore.graphics4.TextureUnit, texture: kha.Image): Void {}
public function setImageTexture(unit: kha.graphics4.TextureUnit, texture: kha.Image): Void {
if (texture == null)
return;
setImageTextureInternal(cast unit, texture);
}
@:functionCode("return kinc_g4_max_bound_textures();")
public function maxBoundTextures(): Int {
return 0;
}
// public function createVertexShader(source: Blob): VertexShader {
// return new Shader(source, ShaderType.VertexShader);
// }
// public function createFragmentShader(source: Blob): FragmentShader {
// return new Shader(source, ShaderType.FragmentShader);
// }
// public function createProgram(): kha.graphics4.Program {
// return new Program();
// }
public function setPipeline(pipe: PipelineState): Void {
pipe.set();
}
@:functionCode("kinc_g4_set_stencil_reference_value(value);")
public function setStencilReferenceValue(value: Int): Void {}
public function setBool(location: kha.graphics4.ConstantLocation, value: Bool): Void {
setBoolPrivate(cast location, value);
}
@:functionCode("kinc_g4_set_bool(location->location, value);")
function setBoolPrivate(location: kha.kore.graphics4.ConstantLocation, value: Bool): Void {}
public function setInt(location: kha.graphics4.ConstantLocation, value: Int): Void {
setIntPrivate(cast location, value);
}
@:functionCode("kinc_g4_set_int(location->location, value);")
function setIntPrivate(location: ConstantLocation, value: Int): Void {}
public function setInt2(location: kha.graphics4.ConstantLocation, value1: Int, value2: Int): Void {
setInt2Private(cast location, value1, value2);
}
@:functionCode("kinc_g4_set_int2(location->location, value1, value2);")
function setInt2Private(location: ConstantLocation, value1: Int, value2: Int): Void {}
public function setInt3(location: kha.graphics4.ConstantLocation, value1: Int, value2: Int, value3: Int): Void {
setInt3Private(cast location, value1, value2, value3);
}
@:functionCode("kinc_g4_set_int3(location->location, value1, value2, value3);")
function setInt3Private(location: ConstantLocation, value1: Int, value2: Int, value3: Int): Void {}
public function setInt4(location: kha.graphics4.ConstantLocation, value1: Int, value2: Int, value3: Int, value4: Int): Void {
setInt4Private(cast location, value1, value2, value3, value4);
}
@:functionCode("kinc_g4_set_int4(location->location, value1, value2, value3, value4);")
function setInt4Private(location: ConstantLocation, value1: Int, value2: Int, value3: Int, value4: Int): Void {}
public function setInts(location: kha.graphics4.ConstantLocation, values: kha.arrays.Int32Array): Void {
setIntsPrivate(cast location, values);
}
@:functionCode("kinc_g4_set_ints(location->location, (int*)values->self.data, values->byteArrayLength / 4);")
function setIntsPrivate(location: ConstantLocation, values: kha.arrays.Int32Array): Void {}
public function setFloat(location: kha.graphics4.ConstantLocation, value: FastFloat): Void {
setFloatPrivate(cast location, value);
}
@:functionCode("kinc_g4_set_float(location->location, value);")
function setFloatPrivate(location: ConstantLocation, value: FastFloat): Void {}
public function setFloat2(location: kha.graphics4.ConstantLocation, value1: FastFloat, value2: FastFloat): Void {
setFloat2Private(cast location, value1, value2);
}
@:functionCode("kinc_g4_set_float2(location->location, value1, value2);")
function setFloat2Private(location: ConstantLocation, value1: FastFloat, value2: FastFloat): Void {}
public function setFloat3(location: kha.graphics4.ConstantLocation, value1: FastFloat, value2: FastFloat, value3: FastFloat): Void {
setFloat3Private(cast location, value1, value2, value3);
}
@:functionCode("kinc_g4_set_float3(location->location, value1, value2, value3);")
function setFloat3Private(location: ConstantLocation, value1: FastFloat, value2: FastFloat, value3: FastFloat): Void {}
public function setFloat4(location: kha.graphics4.ConstantLocation, value1: FastFloat, value2: FastFloat, value3: FastFloat, value4: FastFloat): Void {
setFloat4Private(cast location, value1, value2, value3, value4);
}
@:functionCode("kinc_g4_set_float4(location->location, value1, value2, value3, value4);")
function setFloat4Private(location: ConstantLocation, value1: FastFloat, value2: FastFloat, value3: FastFloat, value4: FastFloat): Void {}
public function setVector2(location: kha.graphics4.ConstantLocation, value: FastVector2): Void {
setVector2Private(cast location, value.x, value.y);
}
@:functionCode("kinc_g4_set_float2(location->location, x, y);")
function setVector2Private(location: ConstantLocation, x: FastFloat, y: FastFloat): Void {}
public function setVector3(location: kha.graphics4.ConstantLocation, value: FastVector3): Void {
setVector3Private(cast location, value.x, value.y, value.z);
}
@:functionCode("kinc_g4_set_float3(location->location, x, y, z);")
function setVector3Private(location: ConstantLocation, x: FastFloat, y: FastFloat, z: FastFloat): Void {}
public function setVector4(location: kha.graphics4.ConstantLocation, value: FastVector4): Void {
setVector4Private(cast location, value.x, value.y, value.z, value.w);
}
@:functionCode("kinc_g4_set_float4(location->location, x, y, z, w);")
function setVector4Private(location: ConstantLocation, x: FastFloat, y: FastFloat, z: FastFloat, w: FastFloat): Void {}
public function setFloats(location: kha.graphics4.ConstantLocation, values: Float32Array): Void {
setFloatsPrivate(cast location, values);
}
@:functionCode("kinc_g4_set_floats(location->location, (float*)values->self.data, values->byteArrayLength / 4);")
function setFloatsPrivate(location: ConstantLocation, values: Float32Array): Void {}
public function setMatrix(location: kha.graphics4.ConstantLocation, matrix: FastMatrix4): Void {
setMatrixPrivate(cast location, matrix);
}
@:functionCode("
kinc_matrix4x4_t value;
kinc_matrix4x4_set(&value, 0, 0, matrix->_00); kinc_matrix4x4_set(&value, 1, 0, matrix->_10); kinc_matrix4x4_set(&value, 2, 0, matrix->_20); kinc_matrix4x4_set(&value, 3, 0, matrix->_30);
kinc_matrix4x4_set(&value, 0, 1, matrix->_01); kinc_matrix4x4_set(&value, 1, 1, matrix->_11); kinc_matrix4x4_set(&value, 2, 1, matrix->_21); kinc_matrix4x4_set(&value, 3, 1, matrix->_31);
kinc_matrix4x4_set(&value, 0, 2, matrix->_02); kinc_matrix4x4_set(&value, 1, 2, matrix->_12); kinc_matrix4x4_set(&value, 2, 2, matrix->_22); kinc_matrix4x4_set(&value, 3, 2, matrix->_32);
kinc_matrix4x4_set(&value, 0, 3, matrix->_03); kinc_matrix4x4_set(&value, 1, 3, matrix->_13); kinc_matrix4x4_set(&value, 2, 3, matrix->_23); kinc_matrix4x4_set(&value, 3, 3, matrix->_33);
kinc_g4_set_matrix4(location->location, &value);
")
function setMatrixPrivate(location: ConstantLocation, matrix: FastMatrix4): Void {}
public function setMatrix3(location: kha.graphics4.ConstantLocation, matrix: FastMatrix3): Void {
setMatrix3Private(cast location, matrix);
}
@:functionCode("
kinc_matrix3x3_t value;
kinc_matrix3x3_set(&value, 0, 0, matrix->_00); kinc_matrix3x3_set(&value, 1, 0, matrix->_10); kinc_matrix3x3_set(&value, 2, 0, matrix->_20);
kinc_matrix3x3_set(&value, 0, 1, matrix->_01); kinc_matrix3x3_set(&value, 1, 1, matrix->_11); kinc_matrix3x3_set(&value, 2, 1, matrix->_21);
kinc_matrix3x3_set(&value, 0, 2, matrix->_02); kinc_matrix3x3_set(&value, 1, 2, matrix->_12); kinc_matrix3x3_set(&value, 2, 2, matrix->_22);
kinc_g4_set_matrix3(location->location, &value);
")
function setMatrix3Private(location: ConstantLocation, matrix: FastMatrix3): Void {}
public function drawIndexedVertices(start: Int = 0, count: Int = -1): Void {
if (count < 0)
drawAllIndexedVertices();
else
drawSomeIndexedVertices(start, count);
}
@:functionCode("kinc_g4_draw_indexed_vertices();")
function drawAllIndexedVertices(): Void {}
@:functionCode("kinc_g4_draw_indexed_vertices_from_to(start, count);")
public function drawSomeIndexedVertices(start: Int, count: Int): Void {}
public function drawIndexedVerticesInstanced(instanceCount: Int, start: Int = 0, count: Int = -1): Void {
if (count < 0)
drawAllIndexedVerticesInstanced(instanceCount);
else
drawSomeIndexedVerticesInstanced(instanceCount, start, count);
}
@:functionCode("kinc_g4_draw_indexed_vertices_instanced(instanceCount);")
function drawAllIndexedVerticesInstanced(instanceCount: Int): Void {}
@:functionCode("kinc_g4_draw_indexed_vertices_instanced_from_to(instanceCount, start, count);")
function drawSomeIndexedVerticesInstanced(instanceCount: Int, start: Int, count: Int): Void {}
function renderToTexture(additionalRenderTargets: Array<Canvas>): Void {
if (additionalRenderTargets != null) {
var len = additionalRenderTargets.length;
var image1 = cast(additionalRenderTargets[0], Image);
var image2 = cast(additionalRenderTargets[1], Image);
var image3 = cast(additionalRenderTargets[2], Image);
var image4 = cast(additionalRenderTargets[3], Image);
var image5 = cast(additionalRenderTargets[4], Image);
var image6 = cast(additionalRenderTargets[5], Image);
var image7 = cast(additionalRenderTargets[6], Image);
untyped __cpp__("
kinc_g4_render_target_t *renderTargets[8] = { renderTarget, {1} == null() ? nullptr : &{1}->renderTarget, {2} == null() ? nullptr : &{2}->renderTarget, image3 == null() ? nullptr : &{3}->renderTarget, {4} == null() ? nullptr : &{4}->renderTarget, {5} == null() ? nullptr : &{5}->renderTarget, {6} == null() ? nullptr : &{6}->renderTarget, {7} == null() ? nullptr : &{7}->renderTarget };
kinc_g4_set_render_targets(renderTargets, {0} + 1);
", len, image1, image2, image3, image4, image5, image6, image7);
}
else {
untyped __cpp__("
kinc_g4_render_target_t *renderTargets[1] = { renderTarget };
kinc_g4_set_render_targets(renderTargets, 1)
");
}
}
@:functionCode("kinc_g4_restore_render_target();")
function renderToBackbuffer(): Void {}
public function begin(additionalRenderTargets: Array<Canvas> = null): Void {
if (current == null) {
current = this;
}
else {
throw "End before you begin";
}
var win: Int = window == null ? 0 : window;
if (win != lastWindow) {
if (lastWindow != -1) {
untyped __cpp__("kinc_g4_end(lastWindow);");
}
untyped __cpp__("kinc_g4_begin(win);");
lastWindow = win;
}
if (target == null) {
renderToBackbuffer();
}
else
renderToTexture(additionalRenderTargets);
}
public function beginFace(face: Int): Void {
if (current == null) {
current = this;
}
else {
throw "End before you begin";
}
untyped __cpp__("kinc_g4_set_render_target_face(renderTarget, face)");
}
public function beginEye(eye: Int): Void {}
public function end(): Void {
if (current == this) {
current = null;
}
else {
throw "Begin before you end";
}
}
@:functionCode("kinc_g4_flush();")
public function flush(): Void {}
}

View File

@ -1,28 +0,0 @@
#ifndef LIB_INCLUDE_INCLUDED
#define LIB_INCLUDE_INCLUDED
struct RGB
{
unsigned char r;
unsigned char g;
unsigned char b;
RGB(int inR=0, int inG=0, int inB=0) :
r(inR), g(inG), b(inB)
{
}
int getLuma();
int toInt();
};
struct Gradient
{
RGB colour0;
RGB colour1;
int steps;
};
#endif

View File

@ -1,5 +0,0 @@
#include "LibInclude.h"
int RGB::getLuma() { return (r+g+b)/3; }
int RGB::toInt() { return (r<<16) | (g<<8) | b; }

Some files were not shown because too many files have changed in this diff Show More