forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
3
Kha/Backends/HTML5-Worker/kha/Blob.hx
Normal file
3
Kha/Backends/HTML5-Worker/kha/Blob.hx
Normal file
@ -0,0 +1,3 @@
|
||||
package kha;
|
||||
|
||||
typedef Blob = kha.internal.BytesBlob;
|
77
Kha/Backends/HTML5-Worker/kha/Display.hx
Normal file
77
Kha/Backends/HTML5-Worker/kha/Display.hx
Normal file
@ -0,0 +1,77 @@
|
||||
package kha;
|
||||
|
||||
import js.Browser;
|
||||
|
||||
class Display {
|
||||
static var instance: Display = new Display();
|
||||
|
||||
function new() {}
|
||||
|
||||
public static function init(): Void {}
|
||||
|
||||
public static var primary(get, never): Display;
|
||||
|
||||
static function get_primary(): Display {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static var all(get, never): Array<Display>;
|
||||
|
||||
static function get_all(): Array<Display> {
|
||||
return [primary];
|
||||
}
|
||||
|
||||
public var available(get, never): Bool;
|
||||
|
||||
function get_available(): Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public var name(get, never): String;
|
||||
|
||||
function get_name(): String {
|
||||
return "Display";
|
||||
}
|
||||
|
||||
public var x(get, never): Int;
|
||||
|
||||
function get_x(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public var y(get, never): Int;
|
||||
|
||||
function get_y(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public var width(get, never): Int;
|
||||
|
||||
function get_width(): Int {
|
||||
return 800;
|
||||
}
|
||||
|
||||
public var height(get, never): Int;
|
||||
|
||||
function get_height(): Int {
|
||||
return 600;
|
||||
}
|
||||
|
||||
public var frequency(get, never): Int;
|
||||
|
||||
function get_frequency(): Int {
|
||||
return 60;
|
||||
}
|
||||
|
||||
public var pixelsPerInch(get, never): Int;
|
||||
|
||||
function get_pixelsPerInch(): Int {
|
||||
return 96;
|
||||
}
|
||||
|
||||
public var modes(get, never): Array<DisplayMode>;
|
||||
|
||||
function get_modes(): Array<DisplayMode> {
|
||||
return [];
|
||||
}
|
||||
}
|
3
Kha/Backends/HTML5-Worker/kha/Font.hx
Normal file
3
Kha/Backends/HTML5-Worker/kha/Font.hx
Normal file
@ -0,0 +1,3 @@
|
||||
package kha;
|
||||
|
||||
typedef Font = kha.Kravur;
|
222
Kha/Backends/HTML5-Worker/kha/Image.hx
Normal file
222
Kha/Backends/HTML5-Worker/kha/Image.hx
Normal file
@ -0,0 +1,222 @@
|
||||
package kha;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
import kha.graphics4.Graphics;
|
||||
import kha.graphics4.DepthStencilFormat;
|
||||
import kha.graphics4.TextureFormat;
|
||||
import kha.graphics4.Usage;
|
||||
|
||||
class Image implements Canvas implements Resource {
|
||||
public var id: Int;
|
||||
public var _rtid: Int;
|
||||
|
||||
public static var _lastId: Int = -1;
|
||||
static var lastRtId: Int = -1;
|
||||
|
||||
var w: Int;
|
||||
var h: Int;
|
||||
var rw: Int;
|
||||
var rh: Int;
|
||||
var myFormat: TextureFormat;
|
||||
var bytes: Bytes = null;
|
||||
|
||||
public function new(id: Int, rtid: Int, width: Int, height: Int, realWidth: Int, realHeight: Int, format: TextureFormat) {
|
||||
this.id = id;
|
||||
this._rtid = rtid;
|
||||
w = width;
|
||||
h = height;
|
||||
rw = realWidth;
|
||||
rh = realHeight;
|
||||
myFormat = format;
|
||||
}
|
||||
|
||||
public static function create(width: Int, height: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
|
||||
if (format == null)
|
||||
format = TextureFormat.RGBA32;
|
||||
if (usage == null)
|
||||
usage = Usage.StaticUsage;
|
||||
var id = ++_lastId;
|
||||
Worker.postMessage({
|
||||
command: 'createImage',
|
||||
id: id,
|
||||
width: width,
|
||||
height: height,
|
||||
format: format,
|
||||
usage: usage
|
||||
});
|
||||
return new Image(id, -1, width, height, width, height, format);
|
||||
}
|
||||
|
||||
public static function create3D(width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function createRenderTarget(width: Int, height: Int, format: TextureFormat = null,
|
||||
depthStencil: DepthStencilFormat = DepthStencilFormat.NoDepthAndStencil, antiAliasingSamples: Int = 1): Image {
|
||||
if (format == null)
|
||||
format = TextureFormat.RGBA32;
|
||||
var rtid = ++lastRtId;
|
||||
Worker.postMessage({
|
||||
command: 'createRenderTarget',
|
||||
id: rtid,
|
||||
width: width,
|
||||
height: height
|
||||
});
|
||||
return new Image(-1, rtid, width, height, width, height, format);
|
||||
}
|
||||
|
||||
public static function fromBytes(bytes: Bytes, width: Int, height: Int, format: TextureFormat = null, usage: Usage = null, readable: Bool = false): Image {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function fromBytes3D(bytes: Bytes, width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null,
|
||||
readable: Bool = false): Image {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static var maxSize(get, never): Int;
|
||||
|
||||
static function get_maxSize(): Int {
|
||||
return 1024 * 4;
|
||||
}
|
||||
|
||||
public static var nonPow2Supported(get, never): Bool;
|
||||
|
||||
static function get_nonPow2Supported(): Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function renderTargetsInvertedY(): Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isOpaque(x: Int, y: Int): Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function unload(): Void {}
|
||||
|
||||
public function lock(level: Int = 0): Bytes {
|
||||
if (bytes == null) {
|
||||
switch (myFormat) {
|
||||
case RGBA32:
|
||||
bytes = Bytes.alloc(4 * width * height);
|
||||
case L8:
|
||||
bytes = Bytes.alloc(width * height);
|
||||
case RGBA128:
|
||||
bytes = Bytes.alloc(16 * width * height);
|
||||
case DEPTH16:
|
||||
bytes = Bytes.alloc(2 * width * height);
|
||||
case RGBA64:
|
||||
bytes = Bytes.alloc(8 * width * height);
|
||||
case A32:
|
||||
bytes = Bytes.alloc(4 * width * height);
|
||||
case A16:
|
||||
bytes = Bytes.alloc(2 * width * height);
|
||||
}
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public function unlock(): Void {
|
||||
Worker.postMessage({command: 'unlockImage', id: id, bytes: bytes.getData()});
|
||||
}
|
||||
|
||||
public function getPixels(): Bytes {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function generateMipmaps(levels: Int): Void {}
|
||||
|
||||
public function setMipmaps(mipmaps: Array<Image>): Void {}
|
||||
|
||||
public function setDepthStencilFrom(image: Image): Void {}
|
||||
|
||||
public function clear(x: Int, y: Int, z: Int, width: Int, height: Int, depth: Int, color: Color): Void {}
|
||||
|
||||
public var width(get, never): Int;
|
||||
|
||||
function get_width(): Int {
|
||||
return w;
|
||||
}
|
||||
|
||||
public var height(get, never): Int;
|
||||
|
||||
function get_height(): Int {
|
||||
return h;
|
||||
}
|
||||
|
||||
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 rw;
|
||||
}
|
||||
|
||||
public var realHeight(get, never): Int;
|
||||
|
||||
function get_realHeight(): Int {
|
||||
return rh;
|
||||
}
|
||||
|
||||
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 var stride(get, never): Int;
|
||||
|
||||
function get_stride(): Int {
|
||||
return formatByteSize(myFormat) * width;
|
||||
}
|
||||
|
||||
var graphics1: kha.graphics1.Graphics;
|
||||
var graphics2: kha.graphics2.Graphics;
|
||||
var graphics4: kha.graphics4.Graphics;
|
||||
|
||||
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.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.html5worker.Graphics(this);
|
||||
}
|
||||
return graphics4;
|
||||
}
|
||||
}
|
80
Kha/Backends/HTML5-Worker/kha/LoaderImpl.hx
Normal file
80
Kha/Backends/HTML5-Worker/kha/LoaderImpl.hx
Normal file
@ -0,0 +1,80 @@
|
||||
package kha;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
import kha.graphics4.TextureFormat;
|
||||
|
||||
class LoaderImpl {
|
||||
static var loadingImages: Map<Int, Image->Void> = new Map();
|
||||
static var loadingSounds: Map<Int, Sound->Void> = new Map();
|
||||
static var soundId = -1;
|
||||
static var loadingVideos: Map<Int, Video->Void> = new Map();
|
||||
static var videoId = -1;
|
||||
static var loadingBlobs: Map<Int, Blob->Void> = new Map();
|
||||
static var blobId = -1;
|
||||
static var sounds: Map<Int, Sound> = new Map();
|
||||
|
||||
public static function getImageFormats(): Array<String> {
|
||||
return ["png", "jpg", "hdr"];
|
||||
}
|
||||
|
||||
public static function loadImageFromDescription(desc: Dynamic, done: kha.Image->Void, failed: AssetError->Void) {
|
||||
++kha.Image._lastId;
|
||||
loadingImages[kha.Image._lastId] = done;
|
||||
Worker.postMessage({command: 'loadImage', file: desc.files[0], id: kha.Image._lastId});
|
||||
}
|
||||
|
||||
public static function _loadedImage(value: Dynamic) {
|
||||
var image = new Image(value.id, -1, value.width, value.height, value.realWidth, value.realHeight, TextureFormat.RGBA32);
|
||||
loadingImages[value.id](image);
|
||||
loadingImages.remove(value.id);
|
||||
}
|
||||
|
||||
public static function getSoundFormats(): Array<String> {
|
||||
return ["mp4"];
|
||||
}
|
||||
|
||||
public static function loadSoundFromDescription(desc: Dynamic, done: kha.Sound->Void, failed: AssetError->Void) {
|
||||
++soundId;
|
||||
loadingSounds[soundId] = done;
|
||||
Worker.postMessage({command: 'loadSound', file: desc.files[0], id: soundId});
|
||||
}
|
||||
|
||||
public static function _loadedSound(value: Dynamic) {
|
||||
var sound = new kha.html5worker.Sound(value.id);
|
||||
loadingSounds[value.id](sound);
|
||||
loadingSounds.remove(value.id);
|
||||
sounds.set(value.id, sound);
|
||||
}
|
||||
|
||||
public static function _uncompressedSound(value: Dynamic): Void {
|
||||
cast(sounds[value.id], kha.html5worker.Sound)._callback();
|
||||
}
|
||||
|
||||
public static function getVideoFormats(): Array<String> {
|
||||
return ["mp4"];
|
||||
}
|
||||
|
||||
public static function loadVideoFromDescription(desc: Dynamic, done: kha.Video->Void, failed: AssetError->Void): Void {
|
||||
++videoId;
|
||||
loadingVideos[videoId] = done;
|
||||
Worker.postMessage({command: 'loadVideo', file: desc.files[0], id: videoId});
|
||||
}
|
||||
|
||||
public static function loadBlobFromDescription(desc: Dynamic, done: Blob->Void, failed: AssetError->Void) {
|
||||
++blobId;
|
||||
loadingBlobs[blobId] = done;
|
||||
Worker.postMessage({command: 'loadBlob', file: desc.files[0], id: blobId});
|
||||
}
|
||||
|
||||
public static function _loadedBlob(value: Dynamic) {
|
||||
var blob = new Blob(Bytes.ofData(value.data));
|
||||
loadingBlobs[value.id](blob);
|
||||
loadingBlobs.remove(value.id);
|
||||
}
|
||||
|
||||
public static function loadFontFromDescription(desc: Dynamic, done: Font->Void, failed: AssetError->Void): Void {
|
||||
loadBlobFromDescription(desc, function(blob: Blob) {
|
||||
done(new Kravur(blob));
|
||||
}, failed);
|
||||
}
|
||||
}
|
89
Kha/Backends/HTML5-Worker/kha/Starter.hx
Normal file
89
Kha/Backends/HTML5-Worker/kha/Starter.hx
Normal file
@ -0,0 +1,89 @@
|
||||
package kha;
|
||||
|
||||
import kha.Game;
|
||||
import kha.input.Gamepad;
|
||||
import kha.input.Keyboard;
|
||||
import kha.js.WorkerGraphics;
|
||||
import kha.Key;
|
||||
import kha.Loader;
|
||||
|
||||
class Starter {
|
||||
var gameToStart: Game;
|
||||
|
||||
static var frame: Framebuffer = null;
|
||||
static var keyboard: Keyboard;
|
||||
static var mouse: kha.input.Mouse;
|
||||
static var gamepad: Gamepad;
|
||||
|
||||
public static var mouseX: Int;
|
||||
public static var mouseY: Int;
|
||||
|
||||
public function new() {
|
||||
Worker.handleMessages(messageHandler);
|
||||
keyboard = new Keyboard();
|
||||
mouse = new kha.input.Mouse();
|
||||
gamepad = new Gamepad();
|
||||
|
||||
Loader.init(new kha.js.Loader());
|
||||
Scheduler.init();
|
||||
}
|
||||
|
||||
public function start(game: Game): Void {
|
||||
gameToStart = game;
|
||||
Configuration.setScreen(new EmptyScreen(Color.fromBytes(0, 0, 0)));
|
||||
Loader.the.loadProject(loadFinished);
|
||||
}
|
||||
|
||||
public function loadFinished() {
|
||||
Loader.the.initProject();
|
||||
|
||||
gameToStart.width = Loader.the.width;
|
||||
gameToStart.height = Loader.the.height;
|
||||
|
||||
Sys.init(gameToStart.width, gameToStart.height);
|
||||
frame = new Framebuffer(new WorkerGraphics(gameToStart.width, gameToStart.height), null);
|
||||
Scheduler.start();
|
||||
|
||||
Configuration.setScreen(gameToStart);
|
||||
|
||||
gameToStart.loadFinished();
|
||||
}
|
||||
|
||||
public function lockMouse(): Void {}
|
||||
|
||||
public function unlockMouse(): Void {}
|
||||
|
||||
public function canLockMouse(): Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isMouseLocked(): Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function notifyOfMouseLockChange(func: Void->Void, error: Void->Void): Void {}
|
||||
|
||||
public function removeFromMouseLockChange(func: Void->Void, error: Void->Void): Void {}
|
||||
|
||||
function messageHandler(value: Dynamic): Void {
|
||||
switch (value.data.command) {
|
||||
case 'loadedBlob':
|
||||
cast(Loader.the, kha.js.Loader).loadedBlob(value.data);
|
||||
case 'loadedImage':
|
||||
cast(Loader.the, kha.js.Loader).loadedImage(value.data);
|
||||
case 'loadedSound':
|
||||
cast(Loader.the, kha.js.Loader).loadedSound(value.data);
|
||||
case 'loadedMusic':
|
||||
cast(Loader.the, kha.js.Loader).loadedMusic(value.data);
|
||||
case 'frame':
|
||||
if (frame != null) {
|
||||
Scheduler.executeFrame();
|
||||
Configuration.screen().render(frame);
|
||||
}
|
||||
case 'keyDown':
|
||||
Configuration.screen().keyDown(Key.createByIndex(value.data.key), value.data.char);
|
||||
case 'keyUp':
|
||||
Configuration.screen().keyUp(Key.createByIndex(value.data.key), value.data.char);
|
||||
}
|
||||
}
|
||||
}
|
15
Kha/Backends/HTML5-Worker/kha/Storage.hx
Normal file
15
Kha/Backends/HTML5-Worker/kha/Storage.hx
Normal file
@ -0,0 +1,15 @@
|
||||
package kha;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
import haxe.io.BytesData;
|
||||
import js.lib.ArrayBuffer;
|
||||
|
||||
class Storage {
|
||||
public static function namedFile(name: String): StorageFile {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function defaultFile(): StorageFile {
|
||||
return namedFile("default.kha");
|
||||
}
|
||||
}
|
241
Kha/Backends/HTML5-Worker/kha/SystemImpl.hx
Normal file
241
Kha/Backends/HTML5-Worker/kha/SystemImpl.hx
Normal file
@ -0,0 +1,241 @@
|
||||
package kha;
|
||||
|
||||
import kha.input.Gamepad;
|
||||
import kha.input.Keyboard;
|
||||
import kha.input.KeyCode;
|
||||
import kha.input.Mouse;
|
||||
import kha.input.Surface;
|
||||
import kha.System;
|
||||
|
||||
class GamepadStates {
|
||||
public var axes: Array<Float>;
|
||||
public var buttons: Array<Float>;
|
||||
|
||||
public function new() {
|
||||
axes = new Array<Float>();
|
||||
buttons = new Array<Float>();
|
||||
}
|
||||
}
|
||||
|
||||
class SystemImpl {
|
||||
static var options: SystemOptions;
|
||||
@:allow(kha.Window)
|
||||
static var width: Int = 800;
|
||||
@:allow(kha.Window)
|
||||
static var height: Int = 600;
|
||||
static var dpi: Int = 96;
|
||||
static inline var maxGamepads: Int = 4;
|
||||
static var frame: Framebuffer;
|
||||
static var keyboard: Keyboard = null;
|
||||
static var mouse: kha.input.Mouse;
|
||||
static var surface: Surface;
|
||||
static var gamepads: Array<Gamepad>;
|
||||
|
||||
public static function init(options: SystemOptions, callback: Window->Void) {
|
||||
Worker.handleMessages(messageHandler);
|
||||
|
||||
Shaders.init();
|
||||
var shaders = new Array<Dynamic>();
|
||||
for (field in Reflect.fields(Shaders)) {
|
||||
if (field != "init" && field != "__name__" && field.substr(field.length - 5, 4) != "Data") {
|
||||
var shader = Reflect.field(Shaders, field);
|
||||
shaders.push({
|
||||
name: field,
|
||||
files: shader.files,
|
||||
sources: shader.sources
|
||||
});
|
||||
}
|
||||
}
|
||||
Worker.postMessage({command: 'setShaders', shaders: shaders});
|
||||
|
||||
SystemImpl.options = options;
|
||||
|
||||
// haxe.Log.trace = untyped js.Boot.__trace; // Hack for JS trace problems
|
||||
|
||||
keyboard = new Keyboard();
|
||||
mouse = new Mouse();
|
||||
surface = new Surface();
|
||||
gamepads = new Array<Gamepad>();
|
||||
for (i in 0...maxGamepads) {
|
||||
gamepads[i] = new Gamepad(i);
|
||||
}
|
||||
var window = new Window();
|
||||
|
||||
var g4 = new kha.html5worker.Graphics();
|
||||
frame = new Framebuffer(0, null, null, g4);
|
||||
frame.init(new kha.graphics2.Graphics1(frame), new kha.graphics4.Graphics2(frame), g4);
|
||||
|
||||
Scheduler.init();
|
||||
Scheduler.start();
|
||||
|
||||
callback(window);
|
||||
}
|
||||
|
||||
public static function windowWidth(windowId: Int = 0): Int {
|
||||
return Window.get(0).width;
|
||||
}
|
||||
|
||||
public static function windowHeight(windowId: Int = 0): Int {
|
||||
return Window.get(0).height;
|
||||
}
|
||||
|
||||
public static function screenDpi(): Int {
|
||||
return dpi;
|
||||
}
|
||||
|
||||
public static function getScreenRotation(): ScreenRotation {
|
||||
return ScreenRotation.RotationNone;
|
||||
}
|
||||
|
||||
public static function getTime(): Float {
|
||||
return js.Syntax.code("Date.now()") / 1000;
|
||||
}
|
||||
|
||||
public static function getVsync(): Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getRefreshRate(): Int {
|
||||
return 60;
|
||||
}
|
||||
|
||||
public static function getSystemId(): String {
|
||||
return "HTML5-Worker";
|
||||
}
|
||||
|
||||
public static function vibrate(ms: Int): Void {
|
||||
js.Browser.navigator.vibrate(ms);
|
||||
}
|
||||
|
||||
public static function getLanguage(): String {
|
||||
final lang = js.Browser.navigator.language;
|
||||
return lang.substr(0, 2).toLowerCase();
|
||||
}
|
||||
|
||||
public static function requestShutdown(): Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getMouse(num: Int): Mouse {
|
||||
if (num != 0)
|
||||
return null;
|
||||
return mouse;
|
||||
}
|
||||
|
||||
public static function getKeyboard(num: Int): Keyboard {
|
||||
if (num != 0)
|
||||
return null;
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
public static function lockMouse(): Void {}
|
||||
|
||||
public static function unlockMouse(): Void {}
|
||||
|
||||
public static function canLockMouse(): Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function isMouseLocked(): Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function notifyOfMouseLockChange(func: Void->Void, error: Void->Void): Void {}
|
||||
|
||||
public static function removeFromMouseLockChange(func: Void->Void, error: Void->Void): Void {}
|
||||
|
||||
static function unload(_): Void {}
|
||||
|
||||
public static function canSwitchFullscreen(): Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function isFullscreen(): Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function requestFullscreen(): Void {}
|
||||
|
||||
public static function exitFullscreen(): Void {}
|
||||
|
||||
public static function notifyOfFullscreenChange(func: Void->Void, error: Void->Void): Void {}
|
||||
|
||||
public static function removeFromFullscreenChange(func: Void->Void, error: Void->Void): Void {}
|
||||
|
||||
public static function changeResolution(width: Int, height: Int): Void {}
|
||||
|
||||
public static function setKeepScreenOn(on: Bool): Void {}
|
||||
|
||||
public static function loadUrl(url: String): Void {}
|
||||
|
||||
public static function getGamepadId(index: Int): String {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
public static function getGamepadVendor(index: Int): String {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
public static function setGamepadRumble(index: Int, leftAmount: Float, rightAmount: Float) {}
|
||||
|
||||
static function messageHandler(value: Dynamic): Void {
|
||||
switch (value.data.command) {
|
||||
case 'patch':
|
||||
js.Lib.eval(value.data.source);
|
||||
case 'loadedImage':
|
||||
LoaderImpl._loadedImage(value.data);
|
||||
case 'loadedSound':
|
||||
LoaderImpl._loadedSound(value.data);
|
||||
case 'loadedBlob':
|
||||
LoaderImpl._loadedBlob(value.data);
|
||||
case 'uncompressedSound':
|
||||
LoaderImpl._uncompressedSound(value.data);
|
||||
case 'frame':
|
||||
if (frame != null) {
|
||||
Scheduler.executeFrame();
|
||||
Worker.postMessage({command: 'beginFrame'});
|
||||
System.render([frame]);
|
||||
Worker.postMessage({command: 'endFrame'});
|
||||
}
|
||||
case 'setWindowSize':
|
||||
width = value.data.width;
|
||||
height = value.data.height;
|
||||
case 'keyDown':
|
||||
keyboard.sendDownEvent(cast value.data.key);
|
||||
case 'keyUp':
|
||||
keyboard.sendUpEvent(cast value.data.key);
|
||||
case 'keyPress':
|
||||
keyboard.sendPressEvent(value.data.character);
|
||||
case 'mouseDown':
|
||||
mouse.sendDownEvent(0, value.data.button, value.data.x, value.data.y);
|
||||
case 'mouseUp':
|
||||
mouse.sendUpEvent(0, value.data.button, value.data.x, value.data.y);
|
||||
case 'mouseMove':
|
||||
mouse.sendMoveEvent(0, value.data.x, value.data.y, value.data.mx, value.data.my);
|
||||
case 'mouseWheel':
|
||||
mouse.sendWheelEvent(0, value.data.delta);
|
||||
}
|
||||
}
|
||||
|
||||
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 {}
|
||||
}
|
119
Kha/Backends/HTML5-Worker/kha/Window.hx
Normal file
119
Kha/Backends/HTML5-Worker/kha/Window.hx
Normal file
@ -0,0 +1,119 @@
|
||||
package kha;
|
||||
|
||||
class Window {
|
||||
static var instance: Window;
|
||||
|
||||
@:allow(kha.SystemImpl)
|
||||
function new() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public static function create(win: WindowOptions = null, frame: FramebufferOptions = null): Window {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function destroy(window: Window): Void {}
|
||||
|
||||
public static function get(index: Int): Window {
|
||||
if (index == 0) {
|
||||
return instance;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static var all(get, never): Array<Window>;
|
||||
|
||||
static function get_all(): Array<Window> {
|
||||
return [instance];
|
||||
}
|
||||
|
||||
public function resize(width: Int, height: Int): Void {}
|
||||
|
||||
public function move(x: Int, y: Int): Void {}
|
||||
|
||||
public function changeWindowFeatures(features: Int): Void {}
|
||||
|
||||
public function changeFramebuffer(frame: FramebufferOptions): Void {}
|
||||
|
||||
public var x(get, set): Int;
|
||||
|
||||
function get_x(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
function set_x(value: Int): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public var y(get, set): Int;
|
||||
|
||||
function get_y(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
function set_y(value: Int): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public var width(get, set): Int;
|
||||
|
||||
function get_width(): Int {
|
||||
return SystemImpl.width;
|
||||
}
|
||||
|
||||
function set_width(value: Int): Int {
|
||||
return SystemImpl.width;
|
||||
}
|
||||
|
||||
public var height(get, set): Int;
|
||||
|
||||
function get_height(): Int {
|
||||
return SystemImpl.height;
|
||||
}
|
||||
|
||||
function set_height(value: Int): Int {
|
||||
return SystemImpl.height;
|
||||
}
|
||||
|
||||
public var mode(get, set): WindowMode;
|
||||
|
||||
function get_mode(): WindowMode {
|
||||
return Windowed;
|
||||
}
|
||||
|
||||
function set_mode(value: WindowMode): WindowMode {
|
||||
return Windowed;
|
||||
}
|
||||
|
||||
public var visible(get, set): Bool;
|
||||
|
||||
function get_visible(): Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
function set_visible(value: Bool): Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public var title(get, set): String;
|
||||
|
||||
function get_title(): String {
|
||||
return "Kha";
|
||||
}
|
||||
|
||||
function set_title(value: String): String {
|
||||
return "Kha";
|
||||
}
|
||||
|
||||
public function notifyOnResize(callback: Int->Int->Void): Void {}
|
||||
|
||||
public function notifyOnPpiChange(callback: Int->Void): Void {}
|
||||
|
||||
public var vSynced(get, never): Bool;
|
||||
|
||||
function get_vSynced(): Bool {
|
||||
return true;
|
||||
}
|
||||
}
|
16
Kha/Backends/HTML5-Worker/kha/Worker.hx
Normal file
16
Kha/Backends/HTML5-Worker/kha/Worker.hx
Normal file
@ -0,0 +1,16 @@
|
||||
package kha;
|
||||
|
||||
class Worker {
|
||||
public static function postMessage(m: Dynamic): Void {
|
||||
try {
|
||||
js.Syntax.code("self.postMessage(m)");
|
||||
}
|
||||
catch (e:Dynamic) {
|
||||
trace(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static function handleMessages(messageHandler: Dynamic->Void) {
|
||||
untyped js.Syntax.code("self.onmessage = messageHandler");
|
||||
}
|
||||
}
|
187
Kha/Backends/HTML5-Worker/kha/arrays/ByteArray.hx
Normal file
187
Kha/Backends/HTML5-Worker/kha/arrays/ByteArray.hx
Normal file
@ -0,0 +1,187 @@
|
||||
package kha.arrays;
|
||||
|
||||
import js.lib.DataView;
|
||||
import kha.FastFloat;
|
||||
|
||||
@:forward
|
||||
abstract ByteArray(DataView) to DataView {
|
||||
static final LITTLE_ENDIAN: Bool = js.Syntax.code("new Uint8Array(new Uint32Array([0x12345678]).buffer)[0] === 0x78");
|
||||
|
||||
public var buffer(get, never): ByteBuffer;
|
||||
|
||||
inline function get_buffer(): ByteBuffer {
|
||||
return cast this.buffer;
|
||||
}
|
||||
|
||||
public function new(buffer: ByteBuffer, ?byteOffset: Int, ?byteLength: Int) {
|
||||
this = new DataView(buffer, byteOffset, byteLength);
|
||||
}
|
||||
|
||||
static public function make(byteLength: Int): ByteArray {
|
||||
return new ByteArray(ByteBuffer.create(byteLength));
|
||||
}
|
||||
|
||||
public inline function getInt8(byteOffset: Int): Int {
|
||||
return this.getInt8(byteOffset);
|
||||
}
|
||||
|
||||
public inline function getUint8(byteOffset: Int): Int {
|
||||
return this.getUint8(byteOffset);
|
||||
}
|
||||
|
||||
public inline function getInt16(byteOffset: Int): Int {
|
||||
return this.getInt16(byteOffset, LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
public inline function getUint16(byteOffset: Int): Int {
|
||||
return this.getUint16(byteOffset, LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
public inline function getInt32(byteOffset: Int): Int {
|
||||
return this.getInt32(byteOffset, LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
public inline function getUint32(byteOffset: Int): Int {
|
||||
return this.getUint32(byteOffset, LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
public inline function getFloat32(byteOffset: Int): FastFloat {
|
||||
return this.getFloat32(byteOffset, LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
public inline function getFloat64(byteOffset: Int): Float {
|
||||
return this.getFloat64(byteOffset, LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
public inline function setInt8(byteOffset: Int, value: Int): Void {
|
||||
this.setInt8(byteOffset, value);
|
||||
}
|
||||
|
||||
public inline function setUint8(byteOffset: Int, value: Int): Void {
|
||||
this.setUint8(byteOffset, value);
|
||||
}
|
||||
|
||||
public inline function setInt16(byteOffset: Int, value: Int): Void {
|
||||
this.setInt16(byteOffset, value, LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
public inline function setUint16(byteOffset: Int, value: Int): Void {
|
||||
this.setUint16(byteOffset, value, LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
public inline function setInt32(byteOffset: Int, value: Int): Void {
|
||||
this.setInt32(byteOffset, value, LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
public inline function setUint32(byteOffset: Int, value: Int): Void {
|
||||
this.setUint32(byteOffset, value, LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
public inline function setFloat32(byteOffset: Int, value: FastFloat): Void {
|
||||
this.setFloat32(byteOffset, value, true);
|
||||
}
|
||||
|
||||
public inline function setFloat64(byteOffset: Int, value: Float): Void {
|
||||
this.setFloat64(byteOffset, value, LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
public inline function getInt16LE(byteOffset: Int): Int {
|
||||
return this.getInt16(byteOffset, true);
|
||||
}
|
||||
|
||||
public inline function getUint16LE(byteOffset: Int): Int {
|
||||
return this.getUint16(byteOffset, true);
|
||||
}
|
||||
|
||||
public inline function getInt32LE(byteOffset: Int): Int {
|
||||
return this.getInt32(byteOffset, true);
|
||||
}
|
||||
|
||||
public inline function getUint32LE(byteOffset: Int): Int {
|
||||
return this.getUint32(byteOffset, true);
|
||||
}
|
||||
|
||||
public inline function getFloat32LE(byteOffset: Int): FastFloat {
|
||||
return this.getFloat32(byteOffset, true);
|
||||
}
|
||||
|
||||
public inline function getFloat64LE(byteOffset: Int): Float {
|
||||
return this.getFloat64(byteOffset, true);
|
||||
}
|
||||
|
||||
public inline function setInt16LE(byteOffset: Int, value: Int): Void {
|
||||
this.setInt16(byteOffset, value, true);
|
||||
}
|
||||
|
||||
public inline function setUint16LE(byteOffset: Int, value: Int): Void {
|
||||
this.setUint16(byteOffset, value, true);
|
||||
}
|
||||
|
||||
public inline function setInt32LE(byteOffset: Int, value: Int): Void {
|
||||
this.setInt32(byteOffset, value, true);
|
||||
}
|
||||
|
||||
public inline function setUint32LE(byteOffset: Int, value: Int): Void {
|
||||
this.setUint32(byteOffset, value, true);
|
||||
}
|
||||
|
||||
public inline function setFloat32LE(byteOffset: Int, value: FastFloat): Void {
|
||||
this.setFloat32(byteOffset, value, true);
|
||||
}
|
||||
|
||||
public inline function setFloat64LE(byteOffset: Int, value: Float): Void {
|
||||
this.setFloat64(byteOffset, value, true);
|
||||
}
|
||||
|
||||
public inline function getInt16BE(byteOffset: Int): Int {
|
||||
return this.getInt16(byteOffset);
|
||||
}
|
||||
|
||||
public inline function getUint16BE(byteOffset: Int): Int {
|
||||
return this.getUint16(byteOffset);
|
||||
}
|
||||
|
||||
public inline function getInt32BE(byteOffset: Int): Int {
|
||||
return this.getInt32(byteOffset);
|
||||
}
|
||||
|
||||
public inline function getUint32BE(byteOffset: Int): Int {
|
||||
return this.getUint32(byteOffset);
|
||||
}
|
||||
|
||||
public inline function getFloat32BE(byteOffset: Int): FastFloat {
|
||||
return this.getFloat32(byteOffset);
|
||||
}
|
||||
|
||||
public inline function getFloat64BE(byteOffset: Int): Float {
|
||||
return this.getFloat64(byteOffset);
|
||||
}
|
||||
|
||||
public inline function setInt16BE(byteOffset: Int, value: Int): Void {
|
||||
this.setInt16(byteOffset, value);
|
||||
}
|
||||
|
||||
public inline function setUint16BE(byteOffset: Int, value: Int): Void {
|
||||
this.setUint16(byteOffset, value);
|
||||
}
|
||||
|
||||
public inline function setInt32BE(byteOffset: Int, value: Int): Void {
|
||||
this.setInt32(byteOffset, value);
|
||||
}
|
||||
|
||||
public inline function setUint32BE(byteOffset: Int, value: Int): Void {
|
||||
this.setUint32(byteOffset, value);
|
||||
}
|
||||
|
||||
public inline function setFloat32BE(byteOffset: Int, value: FastFloat): Void {
|
||||
this.setFloat32(byteOffset, value);
|
||||
}
|
||||
|
||||
public inline function setFloat64BE(byteOffset: Int, value: Float): Void {
|
||||
this.setFloat64(byteOffset, value);
|
||||
}
|
||||
|
||||
public inline function subarray(start: Int, ?end: Int): ByteArray {
|
||||
return new ByteArray(buffer, start, end != null ? end - start : null);
|
||||
}
|
||||
}
|
14
Kha/Backends/HTML5-Worker/kha/arrays/ByteBuffer.hx
Normal file
14
Kha/Backends/HTML5-Worker/kha/arrays/ByteBuffer.hx
Normal file
@ -0,0 +1,14 @@
|
||||
package kha.arrays;
|
||||
|
||||
import js.lib.ArrayBuffer;
|
||||
|
||||
@:forward
|
||||
abstract ByteBuffer(ArrayBuffer) from ArrayBuffer to ArrayBuffer {
|
||||
public static function create(length: Int): ByteBuffer {
|
||||
return new ByteBuffer(length);
|
||||
}
|
||||
|
||||
function new(length: Int) {
|
||||
this = new ArrayBuffer(length);
|
||||
}
|
||||
}
|
13
Kha/Backends/HTML5-Worker/kha/audio1/Audio.hx
Normal file
13
Kha/Backends/HTML5-Worker/kha/audio1/Audio.hx
Normal file
@ -0,0 +1,13 @@
|
||||
package kha.audio1;
|
||||
|
||||
class Audio {
|
||||
public static function play(sound: Sound, loop: Bool = false): kha.audio1.AudioChannel {
|
||||
Worker.postMessage({command: 'playSound', id: cast(sound, kha.html5worker.Sound)._id, loop: loop});
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function stream(sound: Sound, loop: Bool = false): kha.audio1.AudioChannel {
|
||||
Worker.postMessage({command: 'streamSound', id: cast(sound, kha.html5worker.Sound)._id, loop: loop});
|
||||
return null;
|
||||
}
|
||||
}
|
13
Kha/Backends/HTML5-Worker/kha/audio2/Audio.hx
Normal file
13
Kha/Backends/HTML5-Worker/kha/audio2/Audio.hx
Normal file
@ -0,0 +1,13 @@
|
||||
package kha.audio2;
|
||||
|
||||
import kha.Sound;
|
||||
|
||||
class Audio {
|
||||
public static var disableGcInteractions = false;
|
||||
public static var samplesPerSecond: Int;
|
||||
public static var audioCallback: Int->Buffer->Void;
|
||||
|
||||
public static function stream(sound: Sound, loop: Bool = false): kha.audio1.AudioChannel {
|
||||
return null;
|
||||
}
|
||||
}
|
44
Kha/Backends/HTML5-Worker/kha/graphics4/CubeMap.hx
Normal file
44
Kha/Backends/HTML5-Worker/kha/graphics4/CubeMap.hx
Normal file
@ -0,0 +1,44 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
|
||||
class CubeMap implements Canvas implements Resource {
|
||||
public static function createRenderTarget(size: Int, format: TextureFormat, depthStencil: DepthStencilFormat = NoDepthAndStencil): CubeMap {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function unload(): Void {}
|
||||
|
||||
public function lock(level: Int = 0): Bytes {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function unlock(): Void {}
|
||||
|
||||
public var width(get, never): Int;
|
||||
public var height(get, never): Int;
|
||||
|
||||
function get_width(): Int {
|
||||
return 512;
|
||||
}
|
||||
|
||||
function get_height(): Int {
|
||||
return 512;
|
||||
}
|
||||
|
||||
public var g1(get, never): kha.graphics1.Graphics;
|
||||
public var g2(get, never): kha.graphics2.Graphics;
|
||||
public var g4(get, never): kha.graphics4.Graphics;
|
||||
|
||||
function get_g1(): kha.graphics1.Graphics {
|
||||
return null;
|
||||
}
|
||||
|
||||
function get_g2(): kha.graphics2.Graphics {
|
||||
return null;
|
||||
}
|
||||
|
||||
function get_g4(): kha.graphics4.Graphics {
|
||||
return null;
|
||||
}
|
||||
}
|
27
Kha/Backends/HTML5-Worker/kha/graphics4/FragmentShader.hx
Normal file
27
Kha/Backends/HTML5-Worker/kha/graphics4/FragmentShader.hx
Normal file
@ -0,0 +1,27 @@
|
||||
package kha.graphics4;
|
||||
|
||||
class FragmentShader {
|
||||
public var sources: Array<String>;
|
||||
public var shader: Dynamic;
|
||||
public var files: Array<String>;
|
||||
|
||||
public function new(sources: Array<Blob>, files: Array<String>) {
|
||||
this.sources = [];
|
||||
for (source in sources) {
|
||||
this.sources.push(source.toString());
|
||||
}
|
||||
this.shader = null;
|
||||
this.files = files;
|
||||
}
|
||||
|
||||
public static function fromSource(source: String): FragmentShader {
|
||||
var shader = new FragmentShader([], ["runtime-string"]);
|
||||
shader.sources.push(source);
|
||||
return shader;
|
||||
}
|
||||
|
||||
public function delete(): Void {
|
||||
shader = null;
|
||||
sources = null;
|
||||
}
|
||||
}
|
51
Kha/Backends/HTML5-Worker/kha/graphics4/IndexBuffer.hx
Normal file
51
Kha/Backends/HTML5-Worker/kha/graphics4/IndexBuffer.hx
Normal file
@ -0,0 +1,51 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import kha.arrays.Uint32Array;
|
||||
import kha.graphics4.Usage;
|
||||
|
||||
class IndexBuffer {
|
||||
static var lastId: Int = -1;
|
||||
|
||||
public var _id: Int;
|
||||
public var _data: Uint32Array;
|
||||
|
||||
var mySize: Int;
|
||||
var usage: Usage;
|
||||
var lockStart: Int = 0;
|
||||
var lockEnd: Int = 0;
|
||||
|
||||
public function new(indexCount: Int, usage: Usage, canRead: Bool = false) {
|
||||
this.usage = usage;
|
||||
mySize = indexCount;
|
||||
_data = new Uint32Array(indexCount);
|
||||
_id = ++lastId;
|
||||
Worker.postMessage({
|
||||
command: 'createIndexBuffer',
|
||||
id: _id,
|
||||
size: indexCount,
|
||||
usage: usage
|
||||
});
|
||||
}
|
||||
|
||||
public function delete(): Void {
|
||||
_data = null;
|
||||
}
|
||||
|
||||
public function lock(?start: Int, ?count: Int): Uint32Array {
|
||||
lockStart = start != null ? start : 0;
|
||||
lockEnd = count != null ? start + count : mySize;
|
||||
return _data.subarray(lockStart, lockEnd);
|
||||
}
|
||||
|
||||
public function unlock(?count: Int): Void {
|
||||
if (count != null)
|
||||
lockEnd = lockStart + count;
|
||||
Worker.postMessage({command: 'updateIndexBuffer', id: _id, data: _data.subarray(lockStart, lockEnd).buffer});
|
||||
}
|
||||
|
||||
public function set(): Void {}
|
||||
|
||||
public function count(): Int {
|
||||
return mySize;
|
||||
}
|
||||
}
|
117
Kha/Backends/HTML5-Worker/kha/graphics4/PipelineState.hx
Normal file
117
Kha/Backends/HTML5-Worker/kha/graphics4/PipelineState.hx
Normal file
@ -0,0 +1,117 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import kha.graphics4.FragmentShader;
|
||||
import kha.graphics4.VertexData;
|
||||
import kha.graphics4.VertexShader;
|
||||
import kha.graphics4.VertexStructure;
|
||||
|
||||
class PipelineState extends PipelineStateBase {
|
||||
static var lastId: Int = -1;
|
||||
|
||||
public var _id: Int;
|
||||
|
||||
var textures: Array<String>;
|
||||
var textureValues: Array<Dynamic>;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
_id = ++lastId;
|
||||
textures = new Array<String>();
|
||||
textureValues = new Array<Dynamic>();
|
||||
}
|
||||
|
||||
public function delete(): Void {}
|
||||
|
||||
public function compile(): Void {
|
||||
var index = 0;
|
||||
for (structure in inputLayout) {
|
||||
for (element in structure.elements) {
|
||||
if (element.data == VertexData.Float4x4) {
|
||||
index += 4;
|
||||
}
|
||||
else {
|
||||
++index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var layout = new Array<Dynamic>();
|
||||
for (input in inputLayout) {
|
||||
var elements = new Array<Dynamic>();
|
||||
for (element in input.elements) {
|
||||
elements.push({
|
||||
name: element.name,
|
||||
data: element.data
|
||||
});
|
||||
}
|
||||
layout.push({
|
||||
elements: elements
|
||||
});
|
||||
}
|
||||
|
||||
var stencilValue = -1;
|
||||
switch (stencilReferenceValue) {
|
||||
case Static(value):
|
||||
stencilValue = value;
|
||||
case Dynamic:
|
||||
stencilValue = -1;
|
||||
}
|
||||
|
||||
var state = {
|
||||
cullMode: cullMode,
|
||||
depthWrite: depthWrite,
|
||||
depthMode: depthMode,
|
||||
stencilFrontMode: stencilFrontMode,
|
||||
stencilFrontBothPass: stencilFrontBothPass,
|
||||
stencilFrontDepthFail: stencilFrontDepthFail,
|
||||
stencilFrontFail: stencilFrontFail,
|
||||
stencilBackMode: stencilBackMode,
|
||||
stencilBackBothPass: stencilBackBothPass,
|
||||
stencilBackDepthFail: stencilBackDepthFail,
|
||||
stencilBackFail: stencilBackFail,
|
||||
stencilReferenceValue: stencilValue,
|
||||
stencilReadMask: stencilReadMask,
|
||||
stencilWriteMask: stencilWriteMask,
|
||||
blendSource: blendSource,
|
||||
blendDestination: blendDestination,
|
||||
alphaBlendSource: alphaBlendSource,
|
||||
alphaBlendDestination: alphaBlendDestination,
|
||||
colorWriteMaskRed: colorWriteMaskRed,
|
||||
colorWriteMaskGreen: colorWriteMaskGreen,
|
||||
colorWriteMaskBlue: colorWriteMaskBlue,
|
||||
colorWriteMaskAlpha: colorWriteMaskAlpha,
|
||||
conservativeRasterization: conservativeRasterization
|
||||
};
|
||||
|
||||
Worker.postMessage({
|
||||
command: 'compilePipeline',
|
||||
id: _id,
|
||||
frag: fragmentShader.files[0],
|
||||
vert: vertexShader.files[0],
|
||||
layout: layout,
|
||||
state: state
|
||||
});
|
||||
}
|
||||
|
||||
public function getConstantLocation(name: String): kha.graphics4.ConstantLocation {
|
||||
var loc = new kha.html5worker.ConstantLocation();
|
||||
Worker.postMessage({
|
||||
command: 'createConstantLocation',
|
||||
id: loc._id,
|
||||
name: name,
|
||||
pipeline: _id
|
||||
});
|
||||
return loc;
|
||||
}
|
||||
|
||||
public function getTextureUnit(name: String): kha.graphics4.TextureUnit {
|
||||
var unit = new kha.html5worker.TextureUnit();
|
||||
Worker.postMessage({
|
||||
command: 'createTextureUnit',
|
||||
id: unit._id,
|
||||
name: name,
|
||||
pipeline: _id
|
||||
});
|
||||
return unit;
|
||||
}
|
||||
}
|
115
Kha/Backends/HTML5-Worker/kha/graphics4/VertexBuffer.hx
Normal file
115
Kha/Backends/HTML5-Worker/kha/graphics4/VertexBuffer.hx
Normal file
@ -0,0 +1,115 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import kha.arrays.Float32Array;
|
||||
import kha.graphics4.Usage;
|
||||
import kha.graphics4.VertexStructure;
|
||||
import kha.graphics4.VertexData;
|
||||
|
||||
class VertexBuffer {
|
||||
static var lastId: Int = -1;
|
||||
|
||||
public var _id: Int;
|
||||
public var _data: Float32Array;
|
||||
|
||||
var mySize: Int;
|
||||
var myStride: Int;
|
||||
var sizes: Array<Int>;
|
||||
var offsets: Array<Int>;
|
||||
var usage: Usage;
|
||||
var instanceDataStepRate: Int;
|
||||
var lockStart: Int = 0;
|
||||
var lockCount: Int = 0;
|
||||
|
||||
public function new(vertexCount: Int, structure: VertexStructure, usage: Usage, instanceDataStepRate: Int = 0, canRead: Bool = false) {
|
||||
this.usage = usage;
|
||||
this.instanceDataStepRate = instanceDataStepRate;
|
||||
mySize = vertexCount;
|
||||
myStride = 0;
|
||||
for (element in structure.elements) {
|
||||
myStride += VertexStructure.dataByteSize(element.data);
|
||||
}
|
||||
|
||||
_data = new Float32Array(Std.int(vertexCount * myStride / 4));
|
||||
|
||||
sizes = new Array<Int>();
|
||||
offsets = new Array<Int>();
|
||||
sizes[structure.elements.length - 1] = 0;
|
||||
offsets[structure.elements.length - 1] = 0;
|
||||
|
||||
var offset = 0;
|
||||
var index = 0;
|
||||
for (element in structure.elements) {
|
||||
var size = 0;
|
||||
size += Std.int(VertexStructure.dataByteSize(element.data) / 4);
|
||||
sizes[index] = size;
|
||||
offsets[index] = offset;
|
||||
offset += VertexStructure.dataByteSize(element.data);
|
||||
++index;
|
||||
}
|
||||
|
||||
_id = ++lastId;
|
||||
var elements = new Array<Dynamic>();
|
||||
for (element in structure.elements) {
|
||||
elements.push({
|
||||
name: element.name,
|
||||
data: element.data
|
||||
});
|
||||
}
|
||||
Worker.postMessage({
|
||||
command: 'createVertexBuffer',
|
||||
id: _id,
|
||||
size: vertexCount,
|
||||
structure: {elements: elements},
|
||||
usage: usage
|
||||
});
|
||||
}
|
||||
|
||||
public function delete(): Void {
|
||||
_data = null;
|
||||
}
|
||||
|
||||
public function lock(?start: Int, ?count: Int): Float32Array {
|
||||
lockStart = start != null ? start : 0;
|
||||
lockCount = count != null ? count : mySize;
|
||||
return _data.subarray(Std.int(lockStart * stride() / 4), Std.int((lockStart + lockCount) * stride() / 4));
|
||||
}
|
||||
|
||||
public function unlock(?count: Int): Void {
|
||||
if (count != null)
|
||||
lockCount = count;
|
||||
Worker.postMessage({
|
||||
command: 'updateVertexBuffer',
|
||||
id: _id,
|
||||
data: _data.subarray(Std.int(lockStart * stride() / 4), Std.int((lockStart + lockCount) * stride() / 4)).buffer,
|
||||
start: lockStart,
|
||||
count: lockCount
|
||||
});
|
||||
}
|
||||
|
||||
public function stride(): Int {
|
||||
return myStride;
|
||||
}
|
||||
|
||||
public function count(): Int {
|
||||
return mySize;
|
||||
}
|
||||
|
||||
public function set(offset: Int): Int {
|
||||
var attributesOffset = 0;
|
||||
for (i in 0...sizes.length) {
|
||||
if (sizes[i] > 4) {
|
||||
var size = sizes[i];
|
||||
var addonOffset = 0;
|
||||
while (size > 0) {
|
||||
size -= 4;
|
||||
addonOffset += 4 * 4;
|
||||
++attributesOffset;
|
||||
}
|
||||
}
|
||||
else {
|
||||
++attributesOffset;
|
||||
}
|
||||
}
|
||||
return attributesOffset;
|
||||
}
|
||||
}
|
27
Kha/Backends/HTML5-Worker/kha/graphics4/VertexShader.hx
Normal file
27
Kha/Backends/HTML5-Worker/kha/graphics4/VertexShader.hx
Normal file
@ -0,0 +1,27 @@
|
||||
package kha.graphics4;
|
||||
|
||||
class VertexShader {
|
||||
public var sources: Array<String>;
|
||||
public var shader: Dynamic;
|
||||
public var files: Array<String>;
|
||||
|
||||
public function new(sources: Array<Blob>, files: Array<String>) {
|
||||
this.sources = [];
|
||||
for (source in sources) {
|
||||
this.sources.push(source.toString());
|
||||
}
|
||||
this.shader = null;
|
||||
this.files = files;
|
||||
}
|
||||
|
||||
public static function fromSource(source: String): VertexShader {
|
||||
var shader = new VertexShader([], ["runtime-string"]);
|
||||
shader.sources.push(source);
|
||||
return shader;
|
||||
}
|
||||
|
||||
public function delete(): Void {
|
||||
shader = null;
|
||||
sources = null;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package kha.html5worker;
|
||||
|
||||
class ConstantLocation implements kha.graphics4.ConstantLocation {
|
||||
static var lastId: Int = -1;
|
||||
|
||||
public var _id: Int;
|
||||
|
||||
public function new() {
|
||||
_id = ++lastId;
|
||||
}
|
||||
}
|
345
Kha/Backends/HTML5-Worker/kha/html5worker/Graphics.hx
Normal file
345
Kha/Backends/HTML5-Worker/kha/html5worker/Graphics.hx
Normal file
@ -0,0 +1,345 @@
|
||||
package kha.html5worker;
|
||||
|
||||
import kha.arrays.Float32Array;
|
||||
import kha.Canvas;
|
||||
import kha.graphics4.IndexBuffer;
|
||||
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.graphics4.VertexStructure;
|
||||
import kha.math.FastMatrix3;
|
||||
import kha.math.FastMatrix4;
|
||||
import kha.math.FastVector2;
|
||||
import kha.math.FastVector3;
|
||||
import kha.math.FastVector4;
|
||||
|
||||
class Graphics implements kha.graphics4.Graphics {
|
||||
var renderTarget: Image;
|
||||
|
||||
public function new(renderTarget: Canvas = null) {
|
||||
if (Std.isOfType(renderTarget, Image)) {
|
||||
this.renderTarget = cast renderTarget;
|
||||
}
|
||||
}
|
||||
|
||||
public function begin(additionalRenderTargets: Array<Canvas> = null): Void {
|
||||
Worker.postMessage({command: 'begin', renderTarget: renderTarget == null ? -1 : renderTarget._rtid});
|
||||
}
|
||||
|
||||
public function beginFace(face: Int): Void {}
|
||||
|
||||
public function beginEye(eye: Int): Void {}
|
||||
|
||||
public function end(): Void {
|
||||
Worker.postMessage({command: 'end'});
|
||||
}
|
||||
|
||||
public function flush(): Void {}
|
||||
|
||||
public function vsynced(): Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function refreshRate(): Int {
|
||||
return 60;
|
||||
}
|
||||
|
||||
public function clear(?color: Color, ?depth: Float, ?stencil: Int): Void {
|
||||
Worker.postMessage({
|
||||
command: 'clear',
|
||||
color: color == null ? null : color.value,
|
||||
hasDepth: depth != null,
|
||||
depth: depth,
|
||||
hasStencil: stencil != null,
|
||||
stencil: stencil
|
||||
});
|
||||
}
|
||||
|
||||
public function viewport(x: Int, y: Int, width: Int, height: Int): Void {
|
||||
Worker.postMessage({
|
||||
command: 'viewport',
|
||||
x: x,
|
||||
y: y,
|
||||
width: width,
|
||||
height: height
|
||||
});
|
||||
}
|
||||
|
||||
public function createVertexBuffer(vertexCount: Int, structure: VertexStructure, usage: Usage, canRead: Bool = false): kha.graphics4.VertexBuffer {
|
||||
return new VertexBuffer(vertexCount, structure, usage);
|
||||
}
|
||||
|
||||
public function setVertexBuffer(vertexBuffer: kha.graphics4.VertexBuffer): Void {
|
||||
Worker.postMessage({command: 'setVertexBuffer', id: vertexBuffer._id});
|
||||
}
|
||||
|
||||
public function setVertexBuffers(vertexBuffers: Array<kha.graphics4.VertexBuffer>): Void {
|
||||
var ids = new Array<Int>();
|
||||
for (buffer in vertexBuffers) {
|
||||
ids.push(buffer._id);
|
||||
}
|
||||
Worker.postMessage({command: 'setVertexBuffers', ids: ids});
|
||||
}
|
||||
|
||||
public function createIndexBuffer(indexCount: Int, usage: Usage, canRead: Bool = false): kha.graphics4.IndexBuffer {
|
||||
return new IndexBuffer(indexCount, usage);
|
||||
}
|
||||
|
||||
public function setIndexBuffer(indexBuffer: kha.graphics4.IndexBuffer): Void {
|
||||
Worker.postMessage({command: 'setIndexBuffer', id: indexBuffer._id});
|
||||
}
|
||||
|
||||
public function setTexture(stage: kha.graphics4.TextureUnit, texture: kha.Image): Void {
|
||||
Worker.postMessage({
|
||||
command: 'setTexture',
|
||||
stage: cast(stage, kha.html5worker.TextureUnit)._id,
|
||||
texture: texture == null ? -1 : texture.id,
|
||||
renderTarget: texture == null ? -1 : texture._rtid
|
||||
});
|
||||
}
|
||||
|
||||
public function setTextureDepth(stage: kha.graphics4.TextureUnit, texture: kha.Image): Void {}
|
||||
|
||||
public function setTextureArray(unit: kha.graphics4.TextureUnit, texture: kha.Image): Void {}
|
||||
|
||||
public function setVideoTexture(unit: kha.graphics4.TextureUnit, texture: kha.Video): Void {}
|
||||
|
||||
public function setImageTexture(unit: kha.graphics4.TextureUnit, texture: kha.Image): Void {}
|
||||
|
||||
public function setTextureParameters(texunit: kha.graphics4.TextureUnit, uAddressing: TextureAddressing, vAddressing: TextureAddressing,
|
||||
minificationFilter: TextureFilter, magnificationFilter: TextureFilter, mipmapFilter: MipMapFilter): Void {
|
||||
Worker.postMessage({
|
||||
command: 'setTextureParameters',
|
||||
id: cast(texunit, kha.html5worker.TextureUnit)._id,
|
||||
uAddressing: uAddressing,
|
||||
vAddressing: vAddressing,
|
||||
minificationFilter: minificationFilter,
|
||||
magnificationFilter: magnificationFilter,
|
||||
mipmapFilter: mipmapFilter
|
||||
});
|
||||
}
|
||||
|
||||
public function setTexture3DParameters(texunit: kha.graphics4.TextureUnit, uAddressing: TextureAddressing, vAddressing: TextureAddressing,
|
||||
wAddressing: TextureAddressing, minificationFilter: TextureFilter, magnificationFilter: TextureFilter, mipmapFilter: MipMapFilter): Void {}
|
||||
|
||||
public function setTextureCompareMode(texunit: kha.graphics4.TextureUnit, enabled: Bool): Void {}
|
||||
|
||||
public function setCubeMapCompareMode(texunit: kha.graphics4.TextureUnit, enabled: Bool): Void {}
|
||||
|
||||
public function setCubeMap(stage: kha.graphics4.TextureUnit, cubeMap: kha.graphics4.CubeMap): Void {}
|
||||
|
||||
public function setCubeMapDepth(stage: kha.graphics4.TextureUnit, cubeMap: kha.graphics4.CubeMap): Void {}
|
||||
|
||||
public function setPipeline(pipe: PipelineState): Void {
|
||||
Worker.postMessage({command: 'setPipeline', id: pipe._id});
|
||||
}
|
||||
|
||||
public function setStencilReferenceValue(value: Int): Void {}
|
||||
|
||||
public function setBool(location: kha.graphics4.ConstantLocation, value: Bool): Void {
|
||||
Worker.postMessage({
|
||||
command: 'setBool',
|
||||
location: cast(location, kha.html5worker.ConstantLocation)._id,
|
||||
value: value
|
||||
});
|
||||
}
|
||||
|
||||
public function setInt(location: kha.graphics4.ConstantLocation, value: Int): Void {
|
||||
Worker.postMessage({
|
||||
command: 'setInt',
|
||||
location: cast(location, kha.html5worker.ConstantLocation)._id,
|
||||
value: value
|
||||
});
|
||||
}
|
||||
|
||||
public function setInt2(location: kha.graphics4.ConstantLocation, value1: Int, value2: Int): Void {
|
||||
Worker.postMessage({
|
||||
command: 'setInt2',
|
||||
location: cast(location, kha.html5worker.ConstantLocation)._id,
|
||||
_0: value1,
|
||||
_1: value2
|
||||
});
|
||||
}
|
||||
|
||||
public function setInt3(location: kha.graphics4.ConstantLocation, value1: Int, value2: Int, value3: Int): Void {
|
||||
Worker.postMessage({
|
||||
command: 'setInt3',
|
||||
location: cast(location, kha.html5worker.ConstantLocation)._id,
|
||||
_0: value1,
|
||||
_1: value2,
|
||||
_2: value3
|
||||
});
|
||||
}
|
||||
|
||||
public function setInt4(location: kha.graphics4.ConstantLocation, value1: Int, value2: Int, value3: Int, value4: Int): Void {
|
||||
Worker.postMessage({
|
||||
command: 'setInt4',
|
||||
location: cast(location, kha.html5worker.ConstantLocation)._id,
|
||||
_0: value1,
|
||||
_1: value2,
|
||||
_2: value3,
|
||||
_3: value4
|
||||
});
|
||||
}
|
||||
|
||||
public function setInts(location: kha.graphics4.ConstantLocation, values: kha.arrays.Int32Array): Void {
|
||||
Worker.postMessage({
|
||||
command: 'setInts',
|
||||
location: cast(location, kha.html5worker.ConstantLocation)._id,
|
||||
values: values
|
||||
});
|
||||
}
|
||||
|
||||
public function setFloat(location: kha.graphics4.ConstantLocation, value: FastFloat): Void {
|
||||
Worker.postMessage({
|
||||
command: 'setFloat',
|
||||
location: cast(location, kha.html5worker.ConstantLocation)._id,
|
||||
value: value
|
||||
});
|
||||
}
|
||||
|
||||
public function setFloat2(location: kha.graphics4.ConstantLocation, value1: FastFloat, value2: FastFloat): Void {
|
||||
Worker.postMessage({
|
||||
command: 'setFloat2',
|
||||
location: cast(location, kha.html5worker.ConstantLocation)._id,
|
||||
_0: value1,
|
||||
_1: value2
|
||||
});
|
||||
}
|
||||
|
||||
public function setFloat3(location: kha.graphics4.ConstantLocation, value1: FastFloat, value2: FastFloat, value3: FastFloat): Void {
|
||||
Worker.postMessage({
|
||||
command: 'setFloat3',
|
||||
location: cast(location, kha.html5worker.ConstantLocation)._id,
|
||||
_0: value1,
|
||||
_1: value2,
|
||||
_2: value3
|
||||
});
|
||||
}
|
||||
|
||||
public function setFloat4(location: kha.graphics4.ConstantLocation, value1: FastFloat, value2: FastFloat, value3: FastFloat, value4: FastFloat): Void {
|
||||
Worker.postMessage({
|
||||
command: 'setFloat4',
|
||||
location: cast(location, kha.html5worker.ConstantLocation)._id,
|
||||
_0: value1,
|
||||
_1: value2,
|
||||
_2: value3,
|
||||
_3: value4
|
||||
});
|
||||
}
|
||||
|
||||
public function setFloats(location: kha.graphics4.ConstantLocation, values: Float32Array): Void {
|
||||
Worker.postMessage({
|
||||
command: 'setFloats',
|
||||
location: cast(location, kha.html5worker.ConstantLocation)._id,
|
||||
values: values
|
||||
});
|
||||
}
|
||||
|
||||
public function setVector2(location: kha.graphics4.ConstantLocation, value: FastVector2): Void {
|
||||
Worker.postMessage({
|
||||
command: 'setVector2',
|
||||
location: cast(location, kha.html5worker.ConstantLocation)._id,
|
||||
x: value.x,
|
||||
y: value.y
|
||||
});
|
||||
}
|
||||
|
||||
public function setVector3(location: kha.graphics4.ConstantLocation, value: FastVector3): Void {
|
||||
Worker.postMessage({
|
||||
command: 'setVector3',
|
||||
location: cast(location, kha.html5worker.ConstantLocation)._id,
|
||||
x: value.x,
|
||||
y: value.y,
|
||||
z: value.z
|
||||
});
|
||||
}
|
||||
|
||||
public function setVector4(location: kha.graphics4.ConstantLocation, value: FastVector4): Void {
|
||||
Worker.postMessage({
|
||||
command: 'setVector4',
|
||||
location: cast(location, kha.html5worker.ConstantLocation)._id,
|
||||
x: value.x,
|
||||
y: value.y,
|
||||
z: value.z,
|
||||
w: value.w
|
||||
});
|
||||
}
|
||||
|
||||
public inline function setMatrix(location: kha.graphics4.ConstantLocation, matrix: FastMatrix4): Void {
|
||||
Worker.postMessage({
|
||||
command: 'setMatrix4',
|
||||
location: cast(location, kha.html5worker.ConstantLocation)._id,
|
||||
_00: matrix._00,
|
||||
_01: matrix._01,
|
||||
_02: matrix._02,
|
||||
_03: matrix._03,
|
||||
_10: matrix._10,
|
||||
_11: matrix._11,
|
||||
_12: matrix._12,
|
||||
_13: matrix._13,
|
||||
_20: matrix._20,
|
||||
_21: matrix._21,
|
||||
_22: matrix._22,
|
||||
_23: matrix._23,
|
||||
_30: matrix._30,
|
||||
_31: matrix._31,
|
||||
_32: matrix._32,
|
||||
_33: matrix._33
|
||||
});
|
||||
}
|
||||
|
||||
public inline function setMatrix3(location: kha.graphics4.ConstantLocation, matrix: FastMatrix3): Void {
|
||||
Worker.postMessage({
|
||||
command: 'setMatrix3',
|
||||
location: cast(location, kha.html5worker.ConstantLocation)._id,
|
||||
_00: matrix._00,
|
||||
_01: matrix._01,
|
||||
_02: matrix._02,
|
||||
_10: matrix._10,
|
||||
_11: matrix._11,
|
||||
_12: matrix._12,
|
||||
_20: matrix._20,
|
||||
_21: matrix._21,
|
||||
_22: matrix._22
|
||||
});
|
||||
}
|
||||
|
||||
public function drawIndexedVertices(start: Int = 0, count: Int = -1): Void {
|
||||
Worker.postMessage({command: 'drawIndexedVertices', start: start, count: count});
|
||||
}
|
||||
|
||||
public function scissor(x: Int, y: Int, width: Int, height: Int): Void {
|
||||
Worker.postMessage({
|
||||
command: 'scissor',
|
||||
x: x,
|
||||
y: y,
|
||||
width: width,
|
||||
height: height
|
||||
});
|
||||
}
|
||||
|
||||
public function disableScissor(): Void {
|
||||
Worker.postMessage({command: 'disableScissor'});
|
||||
}
|
||||
|
||||
public function drawIndexedVerticesInstanced(instanceCount: Int, start: Int = 0, count: Int = -1) {
|
||||
Worker.postMessage({
|
||||
command: 'drawIndexedVerticesInstanced',
|
||||
instanceCount: instanceCount,
|
||||
start: start,
|
||||
count: count
|
||||
});
|
||||
}
|
||||
|
||||
public function instancedRenderingAvailable(): Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function maxBoundTextures(): Int {
|
||||
return 16;
|
||||
}
|
||||
}
|
25
Kha/Backends/HTML5-Worker/kha/html5worker/Sound.hx
Normal file
25
Kha/Backends/HTML5-Worker/kha/html5worker/Sound.hx
Normal file
@ -0,0 +1,25 @@
|
||||
package kha.html5worker;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
import haxe.ds.Vector;
|
||||
|
||||
class Sound extends kha.Sound {
|
||||
public var _id: Int;
|
||||
public var _callback: Void->Void;
|
||||
|
||||
public function new(id: Int) {
|
||||
super();
|
||||
this._id = id;
|
||||
}
|
||||
|
||||
override public function uncompress(done: Void->Void): Void {
|
||||
compressedData = null;
|
||||
Worker.postMessage({command: 'uncompressSound', id: _id});
|
||||
_callback = done;
|
||||
}
|
||||
|
||||
override public function unload() {
|
||||
compressedData = null;
|
||||
uncompressedData = null;
|
||||
}
|
||||
}
|
11
Kha/Backends/HTML5-Worker/kha/html5worker/TextureUnit.hx
Normal file
11
Kha/Backends/HTML5-Worker/kha/html5worker/TextureUnit.hx
Normal file
@ -0,0 +1,11 @@
|
||||
package kha.html5worker;
|
||||
|
||||
class TextureUnit implements kha.graphics4.TextureUnit {
|
||||
static var lastId: Int = -1;
|
||||
|
||||
public var _id: Int;
|
||||
|
||||
public function new() {
|
||||
_id = ++lastId;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user