forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
3
Kha/Backends/Kinc-hxcpp/kha/Blob.hx
Normal file
3
Kha/Backends/Kinc-hxcpp/kha/Blob.hx
Normal file
@ -0,0 +1,3 @@
|
||||
package kha;
|
||||
|
||||
typedef Blob = kha.internal.BytesBlob;
|
150
Kha/Backends/Kinc-hxcpp/kha/Display.hx
Normal file
150
Kha/Backends/Kinc-hxcpp/kha/Display.hx
Normal file
@ -0,0 +1,150 @@
|
||||
package kha;
|
||||
|
||||
@:headerCode("
|
||||
#include <kinc/display.h>
|
||||
")
|
||||
class Display {
|
||||
var num: Int;
|
||||
|
||||
static var displays: Array<Display> = null;
|
||||
|
||||
function new(num: Int) {
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
@:functionCode("return kinc_count_displays();")
|
||||
static function count(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:functionCode("kinc_display_init();")
|
||||
static function initKoreDisplay(): Void {}
|
||||
|
||||
public static function init() {
|
||||
if (displays == null) {
|
||||
initKoreDisplay();
|
||||
displays = [];
|
||||
for (i in 0...count()) {
|
||||
displays.push(new Display(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@:functionCode("return kinc_primary_display();")
|
||||
static function primaryId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static var primary(get, never): Display;
|
||||
|
||||
static function get_primary(): Display {
|
||||
init();
|
||||
return displays[primaryId()];
|
||||
}
|
||||
|
||||
public static var all(get, never): Array<Display>;
|
||||
|
||||
static function get_all(): Array<Display> {
|
||||
init();
|
||||
return displays;
|
||||
}
|
||||
|
||||
public var available(get, never): Bool;
|
||||
|
||||
@:functionCode("return kinc_display_available(num);")
|
||||
function get_available(): Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public var name(get, never): String;
|
||||
|
||||
@:functionCode("return ::String(kinc_display_name(num));")
|
||||
function get_name(): String {
|
||||
return "Display";
|
||||
}
|
||||
|
||||
public var x(get, never): Int;
|
||||
|
||||
@:functionCode("return kinc_display_current_mode(num).x;")
|
||||
function get_x(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public var y(get, never): Int;
|
||||
|
||||
@:functionCode("return kinc_display_current_mode(num).y;")
|
||||
function get_y(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public var width(get, never): Int;
|
||||
|
||||
@:functionCode("return kinc_display_current_mode(num).width;")
|
||||
function get_width(): Int {
|
||||
return 800;
|
||||
}
|
||||
|
||||
public var height(get, never): Int;
|
||||
|
||||
@:functionCode("return kinc_display_current_mode(num).height;")
|
||||
function get_height(): Int {
|
||||
return 600;
|
||||
}
|
||||
|
||||
public var frequency(get, never): Int;
|
||||
|
||||
@:functionCode("return kinc_display_current_mode(num).frequency;")
|
||||
function get_frequency(): Int {
|
||||
return 60;
|
||||
}
|
||||
|
||||
public var pixelsPerInch(get, never): Int;
|
||||
|
||||
@:functionCode("return kinc_display_current_mode(num).pixels_per_inch;")
|
||||
function get_pixelsPerInch(): Int {
|
||||
return 72;
|
||||
}
|
||||
|
||||
public var modes(get, never): Array<DisplayMode>;
|
||||
|
||||
var allModes: Array<DisplayMode> = null;
|
||||
|
||||
@:functionCode("return kinc_display_count_available_modes(num);")
|
||||
function modeCount(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:functionCode("return kinc_display_available_mode(num, modeIndex).width;")
|
||||
function getModeWidth(modeIndex: Int) {
|
||||
return 800;
|
||||
}
|
||||
|
||||
@:functionCode("return kinc_display_available_mode(num, modeIndex).height;")
|
||||
function getModeHeight(modeIndex: Int) {
|
||||
return 600;
|
||||
}
|
||||
|
||||
@:functionCode("return kinc_display_available_mode(num, modeIndex).frequency;")
|
||||
function getModeFrequency(modeIndex: Int) {
|
||||
return 60;
|
||||
}
|
||||
|
||||
@:functionCode("return kinc_display_available_mode(num, modeIndex).bits_per_pixel;")
|
||||
function getModeBitsPerPixel(modeIndex: Int) {
|
||||
return 32;
|
||||
}
|
||||
|
||||
function initModes() {
|
||||
if (allModes == null) {
|
||||
allModes = [];
|
||||
for (i in 0...modeCount()) {
|
||||
allModes.push(new DisplayMode(getModeWidth(i), getModeHeight(i), getModeFrequency(i), getModeBitsPerPixel(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function get_modes(): Array<DisplayMode> {
|
||||
initModes();
|
||||
return allModes;
|
||||
}
|
||||
}
|
3
Kha/Backends/Kinc-hxcpp/kha/Font.hx
Normal file
3
Kha/Backends/Kinc-hxcpp/kha/Font.hx
Normal file
@ -0,0 +1,3 @@
|
||||
package kha;
|
||||
|
||||
typedef Font = kha.Kravur;
|
559
Kha/Backends/Kinc-hxcpp/kha/Image.hx
Normal file
559
Kha/Backends/Kinc-hxcpp/kha/Image.hx
Normal file
@ -0,0 +1,559 @@
|
||||
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;
|
||||
}
|
||||
}
|
220
Kha/Backends/Kinc-hxcpp/kha/LoaderImpl.hx
Normal file
220
Kha/Backends/Kinc-hxcpp/kha/LoaderImpl.hx
Normal file
@ -0,0 +1,220 @@
|
||||
package kha;
|
||||
|
||||
import kha.arrays.Float32Array;
|
||||
import haxe.io.Bytes;
|
||||
import haxe.io.BytesData;
|
||||
|
||||
@:headerCode("
|
||||
#include <kinc/input/keyboard.h>
|
||||
#include <kinc/system.h>
|
||||
#include <kinc/video.h>
|
||||
#include <khalib/loader.h>
|
||||
")
|
||||
class BlobCallback {
|
||||
public var success: Blob->Void;
|
||||
public var error: AssetError->Void;
|
||||
|
||||
public function new(success: Blob->Void, error: AssetError->Void) {
|
||||
this.success = success;
|
||||
this.error = error;
|
||||
}
|
||||
}
|
||||
|
||||
class ImageCallback {
|
||||
public var success: Image->Void;
|
||||
public var error: AssetError->Void;
|
||||
|
||||
public function new(success: Image->Void, error: AssetError->Void) {
|
||||
this.success = success;
|
||||
this.error = error;
|
||||
}
|
||||
}
|
||||
|
||||
class SoundCallback {
|
||||
public var success: Sound->Void;
|
||||
public var error: AssetError->Void;
|
||||
|
||||
public function new(success: Sound->Void, error: AssetError->Void) {
|
||||
this.success = success;
|
||||
this.error = error;
|
||||
}
|
||||
}
|
||||
|
||||
class LoaderImpl {
|
||||
static var blobCallbacks = new Map<haxe.Int64, BlobCallback>();
|
||||
static var imageCallbacks = new Map<haxe.Int64, ImageCallback>();
|
||||
static var soundCallbacks = new Map<haxe.Int64, SoundCallback>();
|
||||
|
||||
public static function loadSoundFromDescription(desc: Dynamic, done: kha.Sound->Void, failed: AssetError->Void) {
|
||||
soundCallbacks[loadSound(desc.files[0])] = new SoundCallback(done, failed);
|
||||
}
|
||||
|
||||
@:functionCode("return kha_loader_load_sound(filename);")
|
||||
static function loadSound(filename: String): haxe.Int64 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function getSoundFormats(): Array<String> {
|
||||
return ["wav", "ogg"];
|
||||
}
|
||||
|
||||
public static function loadImageFromDescription(desc: Dynamic, done: kha.Image->Void, failed: AssetError->Void) {
|
||||
var readable = Reflect.hasField(desc, "readable") ? desc.readable : false;
|
||||
// done(kha.Image.fromFile(desc.files[0], readable));
|
||||
imageCallbacks[loadImage(desc.files[0], readable)] = new ImageCallback(done, failed);
|
||||
}
|
||||
|
||||
@:functionCode("return kha_loader_load_image(filename, readable);")
|
||||
static function loadImage(filename: String, readable: Bool): haxe.Int64 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function getImageFormats(): Array<String> {
|
||||
return ["png", "jpg", "hdr"];
|
||||
}
|
||||
|
||||
public static function loadBlobFromDescription(desc: Dynamic, done: Blob->Void, failed: AssetError->Void) {
|
||||
blobCallbacks[loadBlob(desc.files[0])] = new BlobCallback(done, failed);
|
||||
}
|
||||
|
||||
@:functionCode("return kha_loader_load_blob(filename);")
|
||||
static function loadBlob(filename: String): haxe.Int64 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function loadFontFromDescription(desc: Dynamic, done: Font->Void, failed: AssetError->Void): Void {
|
||||
loadBlobFromDescription(desc, function(blob: Blob) {
|
||||
done(new Kravur(blob));
|
||||
}, failed);
|
||||
}
|
||||
|
||||
public static function loadVideoFromDescription(desc: Dynamic, done: Video->Void, failed: AssetError->Void) {
|
||||
done(new kha.kore.Video(desc.files[0]));
|
||||
}
|
||||
|
||||
@:functionCode("return ::String(kinc_video_formats()[0]);")
|
||||
static function videoFormat(): String {
|
||||
return "";
|
||||
}
|
||||
|
||||
public static function getVideoFormats(): Array<String> {
|
||||
return [videoFormat()];
|
||||
}
|
||||
|
||||
@:functionCode("kinc_keyboard_show();")
|
||||
public static function showKeyboard(): Void {}
|
||||
|
||||
@:functionCode("kinc_keyboard_hide();")
|
||||
public static function hideKeyboard(): Void {}
|
||||
|
||||
@:functionCode("kinc_load_url(url);")
|
||||
public static function loadURL(url: String): Void {}
|
||||
|
||||
@:keep static function blobLoaded(index: haxe.Int64, bytes: BytesData) {
|
||||
blobCallbacks[index].success(new Blob(Bytes.ofData(bytes)));
|
||||
}
|
||||
|
||||
@:keep static function blobErrored(index: haxe.Int64, filename: String) {
|
||||
blobCallbacks[index].error({url: filename});
|
||||
}
|
||||
|
||||
@:keep static function soundLoadedCompressed(index: haxe.Int64, bytes: BytesData) {
|
||||
var sound = new Sound();
|
||||
sound.compressedData = Bytes.ofData(bytes);
|
||||
sound.uncompressedData = null;
|
||||
sound.channels = 0;
|
||||
sound.sampleRate = 0;
|
||||
sound.length = 0;
|
||||
soundCallbacks[index].success(sound);
|
||||
}
|
||||
|
||||
@:keep static function soundLoadedUncompressed(index: haxe.Int64, samples: Float32Array, channels: Int, sampleRate: Int, length: Float) {
|
||||
var sound = new Sound();
|
||||
sound.compressedData = null;
|
||||
sound.uncompressedData = samples;
|
||||
sound.channels = channels;
|
||||
sound.sampleRate = sampleRate;
|
||||
sound.length = length;
|
||||
soundCallbacks[index].success(sound);
|
||||
}
|
||||
|
||||
@:keep static function soundErrored(index: haxe.Int64, filename: String) {
|
||||
soundCallbacks[index].error({url: filename});
|
||||
}
|
||||
|
||||
@:keep static function createFloat32Array() {
|
||||
return new Float32Array(0);
|
||||
}
|
||||
|
||||
@:keep static function createEmptyImage(readable: Bool, floatFormat: Bool) {
|
||||
return Image.createEmpty(readable, floatFormat);
|
||||
}
|
||||
|
||||
@:keep static function imageLoaded(index: haxe.Int64, image: Image) {
|
||||
imageCallbacks[index].success(image);
|
||||
}
|
||||
|
||||
@:keep static function imageErrored(index: haxe.Int64, filename: String) {
|
||||
imageCallbacks[index].error({url: filename});
|
||||
}
|
||||
|
||||
@:functionCode("
|
||||
kha_file_reference_t file = kha_loader_get_file();
|
||||
while (file.index != 0) {
|
||||
switch (file.type) {
|
||||
case KHA_FILE_TYPE_BLOB:
|
||||
if (file.error) {
|
||||
blobErrored(file.index, file.name);
|
||||
}
|
||||
else {
|
||||
Array<unsigned char> buffer = Array_obj<unsigned char>::fromData(file.data.blob.bytes, file.data.blob.size);
|
||||
blobLoaded(file.index, buffer);
|
||||
kha_loader_cleanup_blob(file.data.blob);
|
||||
}
|
||||
break;
|
||||
case KHA_FILE_TYPE_IMAGE:
|
||||
if (file.error) {
|
||||
imageErrored(file.index, file.name);
|
||||
}
|
||||
else {
|
||||
::kha::Image image = createEmptyImage(file.data.image.readable, file.data.image.image.format == KINC_IMAGE_FORMAT_RGBA128);
|
||||
kinc_image_t kincImage;
|
||||
kinc_image_init(&kincImage, file.data.image.image.data, file.data.image.image.width, file.data.image.image.height, (kinc_image_format_t)file.data.image.image.format);
|
||||
kinc_g4_texture_init_from_image(&image->texture, &kincImage);
|
||||
if (file.data.image.readable) {
|
||||
image->imageData = (uint8_t*)kincImage.data;
|
||||
}
|
||||
else {
|
||||
free(file.data.image.image.data);
|
||||
}
|
||||
kinc_image_destroy(&kincImage);
|
||||
image->imageType = KhaImageTypeTexture;
|
||||
image->originalWidth = file.data.image.image.width;
|
||||
image->originalHeight = file.data.image.image.height;
|
||||
imageLoaded(file.index, image);
|
||||
}
|
||||
break;
|
||||
case KHA_FILE_TYPE_SOUND:
|
||||
if (file.error) {
|
||||
soundErrored(file.index, file.name);
|
||||
}
|
||||
else if (file.data.sound.samples != NULL) {
|
||||
::kha::arrays::ByteArrayPrivate buffer = createFloat32Array();
|
||||
buffer->self.data = (uint8_t*)file.data.sound.samples;
|
||||
buffer->byteArrayLength = file.data.sound.size * 4;
|
||||
buffer->byteArrayOffset = 0;
|
||||
soundLoadedUncompressed(file.index, buffer, file.data.sound.channels, file.data.sound.sample_rate, file.data.sound.length);
|
||||
}
|
||||
else {
|
||||
Array<unsigned char> buffer = Array_obj<unsigned char>::fromData(file.data.sound.compressed_samples, file.data.sound.size);
|
||||
soundLoadedCompressed(file.index, buffer);
|
||||
kha_loader_cleanup_sound(file.data.sound);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
file = kha_loader_get_file();
|
||||
}
|
||||
")
|
||||
public static function tick(): Void {}
|
||||
}
|
65
Kha/Backends/Kinc-hxcpp/kha/Storage.hx
Normal file
65
Kha/Backends/Kinc-hxcpp/kha/Storage.hx
Normal file
@ -0,0 +1,65 @@
|
||||
package kha;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
|
||||
using StringTools;
|
||||
|
||||
@:headerCode("
|
||||
#include <kinc/io/filereader.h>
|
||||
#include <kinc/io/filewriter.h>
|
||||
")
|
||||
@:ifFeature("kha.Storage.*")
|
||||
class KoreStorageFile extends StorageFile {
|
||||
var name: String;
|
||||
|
||||
public function new(name: String) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@:functionCode("
|
||||
kinc_file_reader_t file;
|
||||
if (!kinc_file_reader_open(&file, name, KINC_FILE_TYPE_SAVE)) return null();
|
||||
::kha::internal::BytesBlob blob = createBlob(kinc_file_reader_size(&file));
|
||||
kinc_file_reader_read(&file, blob->bytes->b->Pointer(), kinc_file_reader_size(&file));
|
||||
kinc_file_reader_close(&file);
|
||||
return blob;
|
||||
")
|
||||
override public function read(): Blob {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:functionCode("
|
||||
kinc_file_writer_t file;
|
||||
if (!kinc_file_writer_open(&file, name)) return;
|
||||
kinc_file_writer_write(&file, data->bytes->b->Pointer(), data->get_length());
|
||||
kinc_file_writer_close(&file);
|
||||
")
|
||||
function writeInternal(data: Blob): Void {}
|
||||
|
||||
override public function write(data: Blob): Void {
|
||||
if (data != null) {
|
||||
writeInternal(data);
|
||||
}
|
||||
}
|
||||
|
||||
@:keep
|
||||
static function createBlob(size: Int): Blob {
|
||||
return Blob.alloc(size);
|
||||
}
|
||||
|
||||
static function unused(): Void {
|
||||
Bytes.alloc(0);
|
||||
}
|
||||
}
|
||||
|
||||
class Storage {
|
||||
public static function namedFile(name: String): StorageFile {
|
||||
name = name.replace("\\", ".");
|
||||
name = name.replace("/", ".");
|
||||
return new KoreStorageFile(name);
|
||||
}
|
||||
|
||||
public static function defaultFile(): StorageFile {
|
||||
return namedFile("default.kha");
|
||||
}
|
||||
}
|
519
Kha/Backends/Kinc-hxcpp/kha/SystemImpl.hx
Normal file
519
Kha/Backends/Kinc-hxcpp/kha/SystemImpl.hx
Normal file
@ -0,0 +1,519 @@
|
||||
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)");
|
||||
}
|
||||
}
|
251
Kha/Backends/Kinc-hxcpp/kha/Window.hx
Normal file
251
Kha/Backends/Kinc-hxcpp/kha/Window.hx
Normal file
@ -0,0 +1,251 @@
|
||||
package kha;
|
||||
|
||||
@:headerCode("
|
||||
#include <kinc/window.h>
|
||||
")
|
||||
@:cppFileCode("
|
||||
namespace {
|
||||
char windowTitles[10][256];
|
||||
int titleIndex = 0;
|
||||
|
||||
void resizeCallback(int width, int height, void* data) {
|
||||
::kha::Window_obj::callResizeCallbacks(*((int*)&data), width, height);
|
||||
}
|
||||
|
||||
void ppiCallback(int ppi, void* data) {
|
||||
::kha::Window_obj::callPpiCallbacks(*((int*)&data), ppi);
|
||||
}
|
||||
}
|
||||
|
||||
kinc_window_options_t convertWindowOptions(::kha::WindowOptions win) {
|
||||
kinc_window_options_t window;
|
||||
strcpy(windowTitles[titleIndex], win->title.c_str());
|
||||
window.title = windowTitles[titleIndex];
|
||||
++titleIndex;
|
||||
window.x = win->x;
|
||||
window.y = win->y;
|
||||
window.width = win->width;
|
||||
window.height = win->height;
|
||||
window.display_index = win->display;
|
||||
window.visible = win->visible;
|
||||
window.window_features = win->windowFeatures;
|
||||
window.mode = (kinc_window_mode_t)win->mode;
|
||||
return window;
|
||||
}
|
||||
|
||||
kinc_framebuffer_options_t convertFramebufferOptions(::kha::FramebufferOptions frame) {
|
||||
kinc_framebuffer_options_t framebuffer;
|
||||
framebuffer.frequency = frame->frequency;
|
||||
framebuffer.vertical_sync = frame->verticalSync;
|
||||
framebuffer.color_bits = frame->colorBufferBits;
|
||||
framebuffer.depth_bits = frame->depthBufferBits;
|
||||
framebuffer.stencil_bits = frame->stencilBufferBits;
|
||||
framebuffer.samples_per_pixel = frame->samplesPerPixel;
|
||||
return framebuffer;
|
||||
}
|
||||
")
|
||||
class Window {
|
||||
static var windows: Array<Window> = [];
|
||||
static var resizeCallbacks: Array<Array<Int->Int->Void>> = [];
|
||||
static var ppiCallbacks: Array<Array<Int->Void>> = [];
|
||||
|
||||
var num: Int;
|
||||
var visibility: Bool;
|
||||
var windowTitle: String;
|
||||
|
||||
@:noCompletion
|
||||
@:noDoc
|
||||
public function new(num: Int, win: WindowOptions) {
|
||||
this.num = num;
|
||||
visibility = win != null && win.visible;
|
||||
windowTitle = win == null ? "Kha" : (win.title == null ? "Kha" : win.title);
|
||||
resizeCallbacks[num] = [];
|
||||
ppiCallbacks[num] = [];
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
@:noDoc
|
||||
@:keep
|
||||
static function unused(): Void {
|
||||
Display.primary.x;
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
@:noDoc
|
||||
public static function _init(win: WindowOptions = null, frame: FramebufferOptions = null): Void {
|
||||
var window = new Window(windows.length, win);
|
||||
windows.push(window);
|
||||
}
|
||||
|
||||
@:access(kha.SystemImpl)
|
||||
public static function create(win: WindowOptions = null, frame: FramebufferOptions = null): Window {
|
||||
koreCreate(win == null ? {} : win, frame == null ? {} : frame);
|
||||
var window = new Window(windows.length, win);
|
||||
var index = windows.push(window) - 1;
|
||||
kha.SystemImpl.onWindowCreated(index);
|
||||
return window;
|
||||
}
|
||||
|
||||
@:functionCode("
|
||||
kinc_window_options_t window = convertWindowOptions(win);
|
||||
kinc_framebuffer_options_t framebuffer = convertFramebufferOptions(frame);
|
||||
kinc_window_create(&window, &framebuffer);
|
||||
")
|
||||
static function koreCreate(win: WindowOptions, frame: FramebufferOptions) {}
|
||||
|
||||
public static function destroy(window: Window): Void {
|
||||
koreDestroy(window.num);
|
||||
windows.remove(window);
|
||||
}
|
||||
|
||||
@:functionCode("kinc_window_destroy(num);")
|
||||
static function koreDestroy(num: Int) {}
|
||||
|
||||
public static function get(index: Int): Window {
|
||||
return windows[index];
|
||||
}
|
||||
|
||||
public static var all(get, never): Array<Window>;
|
||||
|
||||
static function get_all(): Array<Window> {
|
||||
return windows;
|
||||
}
|
||||
|
||||
@:functionCode("kinc_window_resize(num, width, height);")
|
||||
public function resize(width: Int, height: Int): Void {}
|
||||
|
||||
@:functionCode("kinc_window_move(num, x, y);")
|
||||
public function move(x: Int, y: Int): Void {}
|
||||
|
||||
@:functionCode("kinc_window_change_features(num, features);")
|
||||
public function changeWindowFeatures(features: Int): Void {}
|
||||
|
||||
@:functionCode("
|
||||
kinc_framebuffer_options_t framebuffer = convertFramebufferOptions(frame);
|
||||
kinc_window_change_framebuffer(num, &framebuffer);
|
||||
")
|
||||
public function changeFramebuffer(frame: FramebufferOptions): Void {}
|
||||
|
||||
public var x(get, set): Int;
|
||||
|
||||
@:functionCode("return kinc_window_x(num);")
|
||||
function get_x(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:functionCode("int y = kinc_window_y(num); kinc_window_move(num, value, y);")
|
||||
function set_x(value: Int): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public var y(get, set): Int;
|
||||
|
||||
@:functionCode("return kinc_window_y(num);")
|
||||
function get_y(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:functionCode("int x = kinc_window_x(num); kinc_window_move(num, x, value);")
|
||||
function set_y(value: Int): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public var width(get, set): Int;
|
||||
|
||||
@:functionCode("return kinc_window_width(num);")
|
||||
function get_width(): Int {
|
||||
return 800;
|
||||
}
|
||||
|
||||
@:functionCode("int height = kinc_window_height(num); kinc_window_resize(num, value, height);")
|
||||
function set_width(value: Int): Int {
|
||||
return 800;
|
||||
}
|
||||
|
||||
public var height(get, set): Int;
|
||||
|
||||
@:functionCode("return kinc_window_height(num);")
|
||||
function get_height(): Int {
|
||||
return 600;
|
||||
}
|
||||
|
||||
@:functionCode("int width = kinc_window_width(num); kinc_window_move(num, width, value);")
|
||||
function set_height(value: Int): Int {
|
||||
return 600;
|
||||
}
|
||||
|
||||
public var mode(get, set): WindowMode;
|
||||
|
||||
function get_mode(): WindowMode {
|
||||
return cast getKincMode();
|
||||
}
|
||||
|
||||
@:functionCode("return kinc_window_get_mode(num);")
|
||||
function getKincMode(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:functionCode("kinc_window_change_mode(num, (kinc_window_mode_t)mode); return mode;")
|
||||
function set_mode(mode: WindowMode): WindowMode {
|
||||
return mode;
|
||||
}
|
||||
|
||||
public var visible(get, set): Bool;
|
||||
|
||||
function get_visible(): Bool {
|
||||
return visibility;
|
||||
}
|
||||
|
||||
@:functionCode("if (value) kinc_window_show(num); else kinc_window_hide(num);")
|
||||
function set_visible(value: Bool): Bool {
|
||||
visibility = value;
|
||||
return value;
|
||||
}
|
||||
|
||||
public var title(get, set): String;
|
||||
|
||||
function get_title(): String {
|
||||
return windowTitle;
|
||||
}
|
||||
|
||||
@:functionCode("kinc_window_set_title(num, value.c_str());")
|
||||
function set_title(value: String): String {
|
||||
windowTitle = value;
|
||||
return windowTitle;
|
||||
}
|
||||
|
||||
@:functionCode("kinc_window_set_resize_callback(num, resizeCallback, (void*)this->num);")
|
||||
public function notifyOnResize(callback: Int->Int->Void): Void {
|
||||
resizeCallbacks[num].push(callback);
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
@:noDoc
|
||||
@:keep
|
||||
public static function callResizeCallbacks(num: Int, width: Int, height: Int) {
|
||||
for (callback in resizeCallbacks[num]) {
|
||||
callback(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
@:functionCode("kinc_window_set_ppi_changed_callback(num, ppiCallback, (void*)this->num);")
|
||||
public function notifyOnPpiChange(callback: Int->Void): Void {
|
||||
ppiCallbacks[num].push(callback);
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
@:noDoc
|
||||
@:keep
|
||||
public static function callPpiCallbacks(num: Int, ppi: Int) {
|
||||
for (callback in ppiCallbacks[num]) {
|
||||
callback(ppi);
|
||||
}
|
||||
}
|
||||
|
||||
public var vSynced(get, never): Bool;
|
||||
|
||||
@:functionCode("return kinc_window_vsynced(num);")
|
||||
function get_vSynced(): Bool {
|
||||
return true;
|
||||
}
|
||||
}
|
366
Kha/Backends/Kinc-hxcpp/kha/arrays/ByteArray.hx
Normal file
366
Kha/Backends/Kinc-hxcpp/kha/arrays/ByteArray.hx
Normal file
@ -0,0 +1,366 @@
|
||||
package kha.arrays;
|
||||
|
||||
import cpp.vm.Gc;
|
||||
|
||||
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;
|
||||
|
||||
Gc.setFinalizer(this, cpp.Function.fromStaticFunction(finalize));
|
||||
}
|
||||
|
||||
@:void static function finalize(arr: ByteArrayPrivate): Void {
|
||||
arr.self.subRef();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
this.self.addRef();
|
||||
}
|
||||
|
||||
public static inline function make(byteLength: Int): ByteArray {
|
||||
var buffer = ByteBuffer.create();
|
||||
if (byteLength > 0) {
|
||||
buffer.alloc(byteLength);
|
||||
}
|
||||
return new ByteArray(buffer, 0, byteLength);
|
||||
}
|
||||
|
||||
public inline function getInt8(byteOffset: Int): Int {
|
||||
return untyped __cpp__("*(int8_t *)&{0}.data[{1} + {2}]", this.self, this.byteArrayOffset, byteOffset);
|
||||
}
|
||||
|
||||
public inline function getUint8(byteOffset: Int): Int {
|
||||
return untyped __cpp__("*(uint8_t *)&{0}.data[{1} + {2}]", this.self, this.byteArrayOffset, byteOffset);
|
||||
}
|
||||
|
||||
public inline function getInt16(byteOffset: Int): Int {
|
||||
return untyped __cpp__("*(int16_t *)&{0}.data[{1} + {2}]", this.self, this.byteArrayOffset, byteOffset);
|
||||
}
|
||||
|
||||
public inline function getUint16(byteOffset: Int): Int {
|
||||
return untyped __cpp__("*(uint16_t *)&{0}.data[{1} + {2}]", this.self, this.byteArrayOffset, byteOffset);
|
||||
}
|
||||
|
||||
public inline function getInt32(byteOffset: Int): Int {
|
||||
return untyped __cpp__("*(int32_t *)&{0}.data[{1} + {2}]", this.self, this.byteArrayOffset, byteOffset);
|
||||
}
|
||||
|
||||
public inline function getUint32(byteOffset: Int): Int {
|
||||
return untyped __cpp__("*(uint32_t *)&{0}.data[{1} + {2}]", this.self, this.byteArrayOffset, byteOffset);
|
||||
}
|
||||
|
||||
public inline function getFloat32(byteOffset: Int): FastFloat {
|
||||
return untyped __cpp__("*(float *)&{0}.data[{1} + {2}]", this.self, this.byteArrayOffset, byteOffset);
|
||||
}
|
||||
|
||||
public inline function getFloat64(byteOffset: Int): Float {
|
||||
return untyped __cpp__("*(double *)&{0}.data[{1} + {2}]", this.self, this.byteArrayOffset, byteOffset);
|
||||
}
|
||||
|
||||
public inline function setInt8(byteOffset: Int, value: Int): Void {
|
||||
untyped __cpp__("*((int8_t *)&{0}.data[{1} + {2}]) = {3}", this.self, this.byteArrayOffset, byteOffset, value);
|
||||
}
|
||||
|
||||
public inline function setUint8(byteOffset: Int, value: Int): Void {
|
||||
untyped __cpp__("*((uint8_t *)&{0}.data[{1} + {2}]) = {3}", this.self, this.byteArrayOffset, byteOffset, value);
|
||||
}
|
||||
|
||||
public inline function setInt16(byteOffset: Int, value: Int): Void {
|
||||
untyped __cpp__("*((int16_t *)&{0}.data[{1} + {2}]) = {3}", this.self, this.byteArrayOffset, byteOffset, value);
|
||||
}
|
||||
|
||||
public inline function setUint16(byteOffset: Int, value: Int): Void {
|
||||
untyped __cpp__("*((uint16_t *)&{0}.data[{1} + {2}]) = {3}", this.self, this.byteArrayOffset, byteOffset, value);
|
||||
}
|
||||
|
||||
public inline function setInt32(byteOffset: Int, value: Int): Void {
|
||||
untyped __cpp__("*((int32_t *)&{0}.data[{1} + {2}]) = {3}", this.self, this.byteArrayOffset, byteOffset, value);
|
||||
}
|
||||
|
||||
public inline function setUint32(byteOffset: Int, value: Int): Void {
|
||||
untyped __cpp__("*((uint32_t *)&{0}.data[{1} + {2}]) = {3}", this.self, this.byteArrayOffset, byteOffset, value);
|
||||
}
|
||||
|
||||
public inline function setFloat32(byteOffset: Int, value: FastFloat): Void {
|
||||
untyped __cpp__("*((float *)&{0}.data[{1} + {2}]) = {3}", this.self, this.byteArrayOffset, byteOffset, value);
|
||||
}
|
||||
|
||||
public inline function setFloat64(byteOffset: Int, value: Float): Void {
|
||||
untyped __cpp__("*((double *)&{0}.data[{1} + {2}]) = {3}", this.self, this.byteArrayOffset, byteOffset, value);
|
||||
}
|
||||
|
||||
public inline function getInt16LE(byteOffset: Int): Int {
|
||||
#if !sys_bigendian
|
||||
return untyped __cpp__("*(int16_t *)&{0}.data[{1} + {2}]", this.self, this.byteArrayOffset, byteOffset);
|
||||
#else
|
||||
return untyped __cpp__("({0}.data[{1} + {2} + 0] << 0) | ({0}.data[{1} + {2} + 1] << 8)", this.self, this.byteArrayOffset, byteOffset);
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function getUint16LE(byteOffset: Int): Int {
|
||||
#if !sys_bigendian
|
||||
return untyped __cpp__("*(uint16_t *)&{0}.data[{1} + {2}]", this.self, this.byteArrayOffset, byteOffset);
|
||||
#else
|
||||
return untyped __cpp__("({0}.data[{1} + {2} + 0] << 0) | ({0}.data[{1} + {2} + 1] << 8)", this.self, this.byteArrayOffset, byteOffset);
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function getInt32LE(byteOffset: Int): Int {
|
||||
#if !sys_bigendian
|
||||
return untyped __cpp__("*(int32_t *)&{0}.data[{1} + {2}]", this.self, this.byteArrayOffset, byteOffset);
|
||||
#else
|
||||
return
|
||||
untyped __cpp__("({0}.data[{1} + {2} + 0] << 0) | ({0}.data[{1} + {2} + 1] << 8) | ({0}.data[{1} + {2} + 2] << 16) | ({0}.data[{1} + {2} + 3] << 24)",
|
||||
this.self,
|
||||
this.byteArrayOffset, byteOffset);
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function getUint32LE(byteOffset: Int): Int {
|
||||
#if !sys_bigendian
|
||||
return untyped __cpp__("*(uint32_t *)&{0}.data[{1} + {2}]", this.self, this.byteArrayOffset, byteOffset);
|
||||
#else
|
||||
return
|
||||
untyped __cpp__("({0}.data[{1} + {2} + 0] << 0) | ({0}.data[{1} + {2} + 1] << 8) | ({0}.data[{1} + {2} + 2] << 16) | ({0}.data[{1} + {2} + 3] << 24)",
|
||||
this.self,
|
||||
this.byteArrayOffset, byteOffset);
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function getFloat32LE(byteOffset: Int): FastFloat {
|
||||
#if !sys_bigendian
|
||||
return untyped __cpp__("*(float *)&{0}.data[{1} + {2}]", this.self, this.byteArrayOffset, byteOffset);
|
||||
#else
|
||||
untyped __cpp__("int32_t i = ({0}.data[{1} + {2} + 0] << 0) | ({0}.data[{1} + {2} + 1] << 8) | ({0}.data[{1} + {2} + 2] << 16) | ({0}.data[{1} + {2} + 3] << 24)",
|
||||
this.self, this.byteArrayOffset, byteOffset);
|
||||
return untyped __cpp__("*(float *)&i");
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function getFloat64LE(byteOffset: Int): Float {
|
||||
#if !sys_bigendian
|
||||
return untyped __cpp__("*(double *)&{0}.data[{1} + {2}]", this.self, this.byteArrayOffset, byteOffset);
|
||||
#else
|
||||
untyped __cpp__("int64_t i = ((int64_t){0}.data[{1} + {2} + 0] << 0) | ((int64_t){0}.data[{1} + {2} + 1] << 8) | ((int64_t){0}.data[{1} + {2} + 2] << 16) | ((int64_t){0}.data[{1} + {2} + 3] << 24) | ((int64_t){0}.data[{1} + {2} + 4] << 32) | ((int64_t){0}.data[{1} + {2} + 5] << 40) | ((int64_t){0}.data[{1} + {2} + 6] << 48) | ((int64_t){0}.data[{1} + {2} + 7] << 56)",
|
||||
this.self, this.byteArrayOffset, byteOffset);
|
||||
return untyped __cpp__("*(double *)&i");
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function setInt16LE(byteOffset: Int, value: Int): Void {
|
||||
#if !sys_bigendian
|
||||
untyped __cpp__("*(int16_t *)&{0}.data[{1} + {2}] = {3}", this.self, this.byteArrayOffset, byteOffset, value);
|
||||
#else
|
||||
untyped __cpp__("int8_t * data = (int8_t *)&{0}", value);
|
||||
untyped __cpp__("int16_t levalue = data[0] << 8 | data[1] << 0");
|
||||
untyped __cpp__("*(int16_t *)&{0}.data[{1} + {2}] = levalue", this.self, this.byteArrayOffset, byteOffset);
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function setUint16LE(byteOffset: Int, value: Int): Void {
|
||||
#if !sys_bigendian
|
||||
untyped __cpp__("*(uint16_t *)&{0}.data[{1} + {2}] = {3}", this.self, this.byteArrayOffset, byteOffset, value);
|
||||
#else
|
||||
untyped __cpp__("int8_t * data = (int8_t *)&{0}", value);
|
||||
untyped __cpp__("uint16_t levalue = data[0] << 8 | data[1] << 0");
|
||||
untyped __cpp__("*(uint16_t *)&{0}.data[{1} + {2}] = levalue", this.self, this.byteArrayOffset, byteOffset);
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function setInt32LE(byteOffset: Int, value: Int): Void {
|
||||
#if !sys_bigendian
|
||||
untyped __cpp__("*(int32_t *)&{0}.data[{1} + {2}] = {3}", this.self, this.byteArrayOffset, byteOffset, value);
|
||||
#else
|
||||
untyped __cpp__("int8_t * data = (int8_t *)&{0}", value);
|
||||
untyped __cpp__("int32_t levalue = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3] << 0");
|
||||
untyped __cpp__("*(int32_t *)&{0}.data[{1} + {2}] = levalue", this.self, this.byteArrayOffset, byteOffset);
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function setUint32LE(byteOffset: Int, value: Int): Void {
|
||||
#if !sys_bigendian
|
||||
untyped __cpp__("*(uint32_t *)&{0}.data[{1} + {2}] = {3}", this.self, this.byteArrayOffset, byteOffset, value);
|
||||
#else
|
||||
untyped __cpp__("int8_t * data = (int8_t *)&{0}", value);
|
||||
untyped __cpp__("uint32_t levalue = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3] << 0");
|
||||
untyped __cpp__("*(uint32_t *)&{0}.data[{1} + {2}] = levalue", this.self, this.byteArrayOffset, byteOffset);
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function setFloat32LE(byteOffset: Int, value: FastFloat): Void {
|
||||
#if !sys_bigendian
|
||||
untyped __cpp__("*(float *)&{0}.data[{1} + {2}] = {3}", this.self, this.byteArrayOffset, byteOffset, value);
|
||||
#else
|
||||
untyped __cpp__("int8_t * data = (int8_t *)&{0}", value);
|
||||
untyped __cpp__("int32_t levalue = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3] << 0");
|
||||
untyped __cpp__("float lefloat = *(float*)&levalue");
|
||||
untyped __cpp__("*(float *)&{0}.data[{1} + {2}] = lefloat", this.self, this.byteArrayOffset, byteOffset);
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function setFloat64LE(byteOffset: Int, value: Float): Void {
|
||||
#if !sys_bigendian
|
||||
untyped __cpp__("*(double *)&{0}.data[{1} + {2}] = {3}", this.self, this.byteArrayOffset, byteOffset, value);
|
||||
#else
|
||||
untyped __cpp__("int8_t * data = (int8_t *)&{0}", value);
|
||||
untyped __cpp__("int64_t levalue = (int64_t)data[0] << 56 | (int64_t)data[1] << 48 | (int64_t)data[2] << 40 | (int64_t)data[3] << 32 | (int64_t)data[4] << 24 | (int64_t)data[5] << 16 | (int64_t)data[6] << 8 | (int64_t)data[7] << 0");
|
||||
untyped __cpp__("double lefloat = *(double*)&levalue");
|
||||
untyped __cpp__("*(double *)&{0}.data[{1} + {2}] = lefloat", this.self, this.byteArrayOffset, byteOffset);
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function getInt16BE(byteOffset: Int): Int {
|
||||
#if sys_bigendian
|
||||
return untyped __cpp__("*(int16_t *)&{0}.data[{1} + {2}]", this.self, this.byteArrayOffset, byteOffset);
|
||||
#else
|
||||
untyped __cpp__("int i = ({0}.data[{1} + {2} + 1] << 0) | ({0}.data[{1} + {2} + 0] << 8)", this.self, this.byteArrayOffset, byteOffset);
|
||||
return untyped __cpp__("*(float *)&i;");
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function getUint16BE(byteOffset: Int): Int {
|
||||
#if sys_bigendian
|
||||
return untyped __cpp__("*(uint16_t *)&{0}.data[{1} + {2}]", this.self, this.byteArrayOffset, byteOffset);
|
||||
#else
|
||||
untyped __cpp__("int i = ({0}.data[{1} + {2} + 1] << 0) | ({0}.data[{1} + {2} + 0] << 8)", this.self, this.byteArrayOffset, byteOffset);
|
||||
return untyped __cpp__("*(float *)&i;");
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function getInt32BE(byteOffset: Int): Int {
|
||||
#if sys_bigendian
|
||||
return untyped __cpp__("*(int32_t *)&{0}.data[{1} + {2}]", this.self, this.byteArrayOffset, byteOffset);
|
||||
#else
|
||||
return
|
||||
untyped __cpp__("({0}.data[{1} + {2} + 3] << 0) | ({0}.data[{1} + {2} + 2] << 8) | ({0}.data[{1} + {2} + 1] << 16) | ({0}.data[{1} + {2} + 0] << 24)",
|
||||
this.self,
|
||||
this.byteArrayOffset, byteOffset);
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function getUint32BE(byteOffset: Int): Int {
|
||||
#if sys_bigendian
|
||||
return untyped __cpp__("*(uint32_t *)&{0}.data[{1} + {2}]", this.self, this.byteArrayOffset, byteOffset);
|
||||
#else
|
||||
return
|
||||
untyped __cpp__("({0}.data[{1} + {2} + 3] << 0) | ({0}.data[{1} + {2} + 2] << 8) | ({0}.data[{1} + {2} + 1] << 16) | ({0}.data[{1} + {2} + 0] << 24)",
|
||||
this.self,
|
||||
this.byteArrayOffset, byteOffset);
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function getFloat32BE(byteOffset: Int): FastFloat {
|
||||
#if sys_bigendian
|
||||
return untyped __cpp__("*(float *)&{0}.data[{1} + {2}]", this.self, this.byteArrayOffset, byteOffset);
|
||||
#else
|
||||
untyped __cpp__("int32_t i = ({0}.data[{1} + {2} + 3] << 0) | ({0}.data[{1} + {2} + 2] << 8) | ({0}.data[{1} + {2} + 1] << 16) | ({0}.data[{1} + {2} + 0] << 24)",
|
||||
this.self, this.byteArrayOffset, byteOffset);
|
||||
return untyped __cpp__("*(float *)&i;");
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function getFloat64BE(byteOffset: Int): Float {
|
||||
#if sys_bigendian
|
||||
return untyped __cpp__("*(double *)&{0}.data[{1} + {2}]", this.self, this.byteArrayOffset, byteOffset);
|
||||
#else
|
||||
untyped __cpp__("int64_t i = ((int64_t){0}.data[{1} + {2} + 7] << 0) | ((int64_t){0}.data[{1} + {2} + 6] << 8) | ((int64_t){0}.data[{1} + {2} + 5] << 16) | ((int64_t){0}.data[{1} + {2} + 4] << 24) | ((int64_t){0}.data[{1} + {2} + 3] << 32) | ((int64_t){0}.data[{1} + {2} + 2] << 40) | ((int64_t){0}.data[{1} + {2} + 1] << 48) | ((int64_t){0}.data[{1} + {2} + 0] << 56)",
|
||||
this.self, this.byteArrayOffset, byteOffset);
|
||||
return untyped __cpp__("*(double *)&i;");
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function setInt16BE(byteOffset: Int, value: Int): Void {
|
||||
#if sys_bigendian
|
||||
untyped __cpp__("*(int16_t *)&{0}.data[{1} + {2}] = {3}", this.self, this.byteArrayOffset, byteOffset, value);
|
||||
#else
|
||||
untyped __cpp__("int8_t * data = (int8_t *)&{0}", value);
|
||||
untyped __cpp__("int16_t levalue = data[0] << 8 | data[1] << 0");
|
||||
untyped __cpp__("*(int16_t *)&{0}.data[{1} + {2}] = levalue", this.self, this.byteArrayOffset, byteOffset);
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function setUint16BE(byteOffset: Int, value: Int): Void {
|
||||
#if sys_bigendian
|
||||
untyped __cpp__("*(uint16_t *)&{0}.data[{1} + {2}] = {3}", this.self, this.byteArrayOffset, byteOffset, value);
|
||||
#else
|
||||
untyped __cpp__("int8_t * data = (int8_t *)&{0}", value);
|
||||
untyped __cpp__("uint16_t levalue = data[0] << 8 | data[1] << 0");
|
||||
untyped __cpp__("*(uint16_t *)&{0}.data[{1} + {2}] = levalue", this.self, this.byteArrayOffset, byteOffset);
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function setInt32BE(byteOffset: Int, value: Int): Void {
|
||||
#if sys_bigendian
|
||||
untyped __cpp__("*(int32_t *)&{0}.data[{1} + {2}] = {3}", this.self, this.byteArrayOffset, byteOffset, value);
|
||||
#else
|
||||
untyped __cpp__("int8_t * data = (int8_t *)&{0}", value);
|
||||
untyped __cpp__("int32_t levalue = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3] << 0");
|
||||
untyped __cpp__("*(int32_t *)&{0}.data[{1} + {2}] = levalue", this.self, this.byteArrayOffset, byteOffset);
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function setUint32BE(byteOffset: Int, value: Int): Void {
|
||||
#if sys_bigendian
|
||||
untyped __cpp__("*(uint32_t *)&{0}.data[{1} + {2}] = {3}", this.self, this.byteArrayOffset, byteOffset, value);
|
||||
#else
|
||||
untyped __cpp__("int8_t * data = (int8_t *)&{0}", value);
|
||||
untyped __cpp__("uint32_t levalue = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3] << 0");
|
||||
untyped __cpp__("*(uint32_t *)&{0}.data[{1} + {2}] = levalue", this.self, this.byteArrayOffset, byteOffset);
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function setFloat32BE(byteOffset: Int, value: FastFloat): Void {
|
||||
#if sys_bigendian
|
||||
untyped __cpp__("*(float *)&{0}.data[{1} + {2}] = {3}", this.self, this.byteArrayOffset, byteOffset, value);
|
||||
#else
|
||||
untyped __cpp__("int8_t * data = (int8_t *)&{0}", value);
|
||||
untyped __cpp__("int32_t levalue = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3] << 0");
|
||||
untyped __cpp__("float lefloat = *(float*)&levalue");
|
||||
untyped __cpp__("*(float *)&{0}.data[{1} + {2}] = lefloat", this.self, this.byteArrayOffset, byteOffset);
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function setFloat64BE(byteOffset: Int, value: Float): Void {
|
||||
#if sys_bigendian
|
||||
untyped __cpp__("*(double *)&{0}.data[{1} + {2}] = {3}", this.self, this.byteArrayOffset, byteOffset, value);
|
||||
#else
|
||||
untyped __cpp__("int8_t * data = (int8_t *)&{0}", value);
|
||||
untyped __cpp__("int64_t levalue = (int64_t)data[0] << 56 | (int64_t)data[1] << 48 | (int64_t)data[2] << 40 | (int64_t)data[3] << 32 | (int64_t)data[4] << 24 | (int64_t)data[5] << 16 | (int64_t)data[6] << 8 | (int64_t)data[7] << 0");
|
||||
untyped __cpp__("double lefloat = *(double*)&levalue");
|
||||
untyped __cpp__("*(double *)&{0}.data[{1} + {2}] = lefloat", this.self, this.byteArrayOffset, byteOffset);
|
||||
#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);
|
||||
}
|
||||
}
|
20
Kha/Backends/Kinc-hxcpp/kha/arrays/ByteBuffer.hx
Normal file
20
Kha/Backends/Kinc-hxcpp/kha/arrays/ByteBuffer.hx
Normal file
@ -0,0 +1,20 @@
|
||||
package kha.arrays;
|
||||
|
||||
@:unreflective
|
||||
@:structAccess
|
||||
@:include("cpp_bytearray.h")
|
||||
@:native("bytearray")
|
||||
extern class ByteBuffer {
|
||||
@:native("bytearray")
|
||||
public static function create(): ByteBuffer;
|
||||
|
||||
public function alloc(length: Int): Void;
|
||||
|
||||
public function addRef(): Void;
|
||||
|
||||
public function subRef(): Void;
|
||||
|
||||
public function get(index: Int): FastFloat;
|
||||
|
||||
public function set(index: Int, value: FastFloat): FastFloat;
|
||||
}
|
3
Kha/Backends/Kinc-hxcpp/kha/audio1/Audio.hx
Normal file
3
Kha/Backends/Kinc-hxcpp/kha/audio1/Audio.hx
Normal file
@ -0,0 +1,3 @@
|
||||
package kha.audio1;
|
||||
|
||||
typedef Audio = kha.audio2.Audio1;
|
58
Kha/Backends/Kinc-hxcpp/kha/audio2/Audio.hx
Normal file
58
Kha/Backends/Kinc-hxcpp/kha/audio2/Audio.hx
Normal file
@ -0,0 +1,58 @@
|
||||
package kha.audio2;
|
||||
|
||||
import kha.Sound;
|
||||
import kha.internal.IntBox;
|
||||
|
||||
@:keep
|
||||
class Audio {
|
||||
static var buffer: Buffer;
|
||||
static var intBox: IntBox = new IntBox(0);
|
||||
|
||||
@:noCompletion
|
||||
public static function _init() {
|
||||
var bufferSize = 1024 * 2;
|
||||
buffer = new Buffer(bufferSize * 4, 2, 44100);
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
public static function _callCallback(samples: Int, sampleRate: Int): Void {
|
||||
if (buffer == null)
|
||||
return;
|
||||
buffer.samplesPerSecond = sampleRate;
|
||||
if (audioCallback != null) {
|
||||
intBox.value = samples;
|
||||
audioCallback(intBox, buffer);
|
||||
}
|
||||
else {
|
||||
for (i in 0...samples) {
|
||||
buffer.data.set(buffer.writeLocation, 0);
|
||||
buffer.writeLocation += 1;
|
||||
if (buffer.writeLocation >= buffer.size) {
|
||||
buffer.writeLocation = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
public static function _readSample(): Float {
|
||||
if (buffer == null)
|
||||
return 0;
|
||||
var value = buffer.data.get(buffer.readLocation);
|
||||
++buffer.readLocation;
|
||||
if (buffer.readLocation >= buffer.size) {
|
||||
buffer.readLocation = 0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static var disableGcInteractions = false;
|
||||
|
||||
public static var samplesPerSecond: Int;
|
||||
|
||||
public static var audioCallback: IntBox->Buffer->Void;
|
||||
|
||||
public static function stream(sound: Sound, loop: Bool = false): kha.audio1.AudioChannel {
|
||||
return null;
|
||||
}
|
||||
}
|
108
Kha/Backends/Kinc-hxcpp/kha/audio2/StreamChannel.hx
Normal file
108
Kha/Backends/Kinc-hxcpp/kha/audio2/StreamChannel.hx
Normal file
@ -0,0 +1,108 @@
|
||||
package kha.audio2;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
|
||||
@:headerCode("#define STB_VORBIS_HEADER_ONLY\n#include <kinc/libs/stb_vorbis.c>")
|
||||
@:headerClassCode("stb_vorbis* vorbis;")
|
||||
class StreamChannel implements kha.audio1.AudioChannel {
|
||||
var atend: Bool = false;
|
||||
@:keep var loop: Bool;
|
||||
var myVolume: Float;
|
||||
var paused: Bool = false;
|
||||
|
||||
public function new(data: Bytes, loop: Bool) {
|
||||
myVolume = 1;
|
||||
this.loop = loop;
|
||||
initVorbis(data);
|
||||
}
|
||||
|
||||
@:functionCode("vorbis = stb_vorbis_open_memory(data->b->Pointer(), data->length, NULL, NULL);")
|
||||
function initVorbis(data: Bytes): Void {}
|
||||
|
||||
@:functionCode("
|
||||
int read = stb_vorbis_get_samples_float_interleaved(vorbis, 2, (float*)samples->self.data, length);
|
||||
if (read < length / 2) {
|
||||
if (loop) {
|
||||
stb_vorbis_seek_start(vorbis);
|
||||
}
|
||||
else {
|
||||
atend = true;
|
||||
}
|
||||
for (int i = read * 2; i < length; ++i) {
|
||||
samples->self.data[i] = 0;
|
||||
}
|
||||
}
|
||||
")
|
||||
function nextVorbisSamples(samples: kha.arrays.Float32Array, length: Int): Void {}
|
||||
|
||||
public function nextSamples(samples: kha.arrays.Float32Array, length: Int, sampleRate: Int): Void {
|
||||
if (paused) {
|
||||
for (i in 0...length) {
|
||||
samples[i] = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
nextVorbisSamples(samples, length);
|
||||
}
|
||||
|
||||
public function play(): Void {
|
||||
paused = false;
|
||||
}
|
||||
|
||||
public function pause(): Void {
|
||||
paused = true;
|
||||
}
|
||||
|
||||
public function stop(): Void {
|
||||
atend = true;
|
||||
}
|
||||
|
||||
public var length(get, never): Float; // Seconds
|
||||
|
||||
@:functionCode("
|
||||
if (vorbis == NULL) return 0;
|
||||
return stb_vorbis_stream_length_in_seconds(vorbis);
|
||||
")
|
||||
function get_length(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public var position(get, set): Float; // Seconds
|
||||
|
||||
@:functionCode("
|
||||
if (vorbis == NULL) return 0;
|
||||
return stb_vorbis_get_sample_offset(vorbis) /
|
||||
(float)stb_vorbis_stream_length_in_samples(vorbis) *
|
||||
stb_vorbis_stream_length_in_seconds(vorbis);
|
||||
")
|
||||
function get_position(): Float {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:functionCode("
|
||||
if (vorbis == NULL) return value;
|
||||
unsigned int rate = stb_vorbis_get_info(vorbis).sample_rate;
|
||||
stb_vorbis_seek_frame(vorbis, rate * value);
|
||||
return value;
|
||||
")
|
||||
function set_position(value: Float): Float {
|
||||
return value;
|
||||
}
|
||||
|
||||
public var volume(get, set): Float;
|
||||
|
||||
function get_volume(): Float {
|
||||
return myVolume;
|
||||
}
|
||||
|
||||
function set_volume(value: Float): Float {
|
||||
return myVolume = value;
|
||||
}
|
||||
|
||||
public var finished(get, never): Bool;
|
||||
|
||||
function get_finished(): Bool {
|
||||
return atend;
|
||||
}
|
||||
}
|
11
Kha/Backends/Kinc-hxcpp/kha/capture/AudioCapture.hx
Normal file
11
Kha/Backends/Kinc-hxcpp/kha/capture/AudioCapture.hx
Normal file
@ -0,0 +1,11 @@
|
||||
package kha.capture;
|
||||
|
||||
import kha.audio2.Buffer;
|
||||
|
||||
class AudioCapture {
|
||||
public static var audioCallback: Int->Buffer->Void;
|
||||
|
||||
public static function init(initialized: Void->Void, error: Void->Void): Void {
|
||||
error();
|
||||
}
|
||||
}
|
176
Kha/Backends/Kinc-hxcpp/kha/compute/Compute.hx
Normal file
176
Kha/Backends/Kinc-hxcpp/kha/compute/Compute.hx
Normal file
@ -0,0 +1,176 @@
|
||||
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);");
|
||||
}
|
||||
}
|
9
Kha/Backends/Kinc-hxcpp/kha/compute/ConstantLocation.hx
Normal file
9
Kha/Backends/Kinc-hxcpp/kha/compute/ConstantLocation.hx
Normal file
@ -0,0 +1,9 @@
|
||||
package kha.compute;
|
||||
|
||||
@:headerCode("
|
||||
#include <kinc/compute/compute.h>
|
||||
")
|
||||
@:headerClassCode("kinc_compute_constant_location location;")
|
||||
class ConstantLocation {
|
||||
public function new() {}
|
||||
}
|
45
Kha/Backends/Kinc-hxcpp/kha/compute/Shader.hx
Normal file
45
Kha/Backends/Kinc-hxcpp/kha/compute/Shader.hx
Normal file
@ -0,0 +1,45 @@
|
||||
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);
|
||||
}
|
||||
}
|
77
Kha/Backends/Kinc-hxcpp/kha/compute/ShaderStorageBuffer.hx
Normal file
77
Kha/Backends/Kinc-hxcpp/kha/compute/ShaderStorageBuffer.hx
Normal file
@ -0,0 +1,77 @@
|
||||
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;
|
||||
}
|
||||
}
|
9
Kha/Backends/Kinc-hxcpp/kha/compute/TextureUnit.hx
Normal file
9
Kha/Backends/Kinc-hxcpp/kha/compute/TextureUnit.hx
Normal file
@ -0,0 +1,9 @@
|
||||
package kha.compute;
|
||||
|
||||
@:headerCode("
|
||||
#include <kinc/compute/compute.h>
|
||||
")
|
||||
@:headerClassCode("kinc_compute_texture_unit unit;")
|
||||
class TextureUnit {
|
||||
public function new() {}
|
||||
}
|
123
Kha/Backends/Kinc-hxcpp/kha/graphics4/CubeMap.hx
Normal file
123
Kha/Backends/Kinc-hxcpp/kha/graphics4/CubeMap.hx
Normal file
@ -0,0 +1,123 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
|
||||
@:headerCode("
|
||||
#include <kinc/graphics4/rendertarget.h>
|
||||
")
|
||||
@:headerClassCode("kinc_g4_render_target_t renderTarget;")
|
||||
class CubeMap implements Canvas implements Resource {
|
||||
var format: TextureFormat;
|
||||
var graphics4: kha.graphics4.Graphics;
|
||||
|
||||
function new() {}
|
||||
|
||||
public static function createRenderTarget(size: Int, format: TextureFormat = null, depthStencil: DepthStencilFormat = null): CubeMap {
|
||||
return create2(size, format == null ? TextureFormat.RGBA32 : format, false, true, depthStencil);
|
||||
}
|
||||
|
||||
public static function create2(size: Int, format: TextureFormat, readable: Bool, renderTarget: Bool, depthStencil: DepthStencilFormat): CubeMap {
|
||||
var cubeMap = new CubeMap();
|
||||
cubeMap.format = format;
|
||||
if (renderTarget)
|
||||
cubeMap.initRenderTarget(size, getRenderTargetFormat(format), getDepthBufferBits(depthStencil), getStencilBufferBits(depthStencil));
|
||||
return cubeMap;
|
||||
}
|
||||
|
||||
@:functionCode("kinc_g4_render_target_init_cube(&renderTarget, cubeMapSize, (kinc_g4_render_target_format_t)format, depthBufferBits, stencilBufferBits);")
|
||||
function initRenderTarget(cubeMapSize: Int, format: Int, depthBufferBits: Int, stencilBufferBits: Int): Void {}
|
||||
|
||||
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;
|
||||
default:
|
||||
return 1; // Grey 8
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@:functionCode("return renderTarget.width;")
|
||||
function get_width(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:functionCode("return renderTarget.height;")
|
||||
function get_height(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public var g1(get, never): kha.graphics1.Graphics;
|
||||
|
||||
function get_g1(): kha.graphics1.Graphics {
|
||||
return null;
|
||||
}
|
||||
|
||||
public var g2(get, never): kha.graphics2.Graphics;
|
||||
|
||||
function get_g2(): kha.graphics2.Graphics {
|
||||
return null;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
35
Kha/Backends/Kinc-hxcpp/kha/graphics4/FragmentShader.hx
Normal file
35
Kha/Backends/Kinc-hxcpp/kha/graphics4/FragmentShader.hx
Normal file
@ -0,0 +1,35 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
import kha.Blob;
|
||||
|
||||
@:headerCode("
|
||||
#include <kinc/graphics4/shader.h>
|
||||
")
|
||||
@:headerClassCode("kinc_g4_shader_t shader;")
|
||||
class FragmentShader {
|
||||
public function new(sources: Array<Blob>, files: Array<String>) {
|
||||
if (sources != null) {
|
||||
init(sources[0], files[0]);
|
||||
}
|
||||
}
|
||||
|
||||
function init(source: Blob, file: String): Void {
|
||||
untyped __cpp__("kinc_g4_shader_init(&shader, source->bytes->b->Pointer(), source->get_length(), KINC_G4_SHADER_TYPE_FRAGMENT);");
|
||||
}
|
||||
|
||||
public static function fromSource(source: String): FragmentShader {
|
||||
var fragmentShader = new FragmentShader(null, null);
|
||||
untyped __cpp__("kinc_g4_shader_init_from_source(&fragmentShader->shader, source, KINC_G4_SHADER_TYPE_FRAGMENT);");
|
||||
return fragmentShader;
|
||||
}
|
||||
|
||||
public function delete(): Void {
|
||||
untyped __cpp__("kinc_g4_shader_destroy(&shader);");
|
||||
}
|
||||
|
||||
@:keep
|
||||
function _forceInclude(): Void {
|
||||
Bytes.alloc(0);
|
||||
}
|
||||
}
|
27
Kha/Backends/Kinc-hxcpp/kha/graphics4/GeometryShader.hx
Normal file
27
Kha/Backends/Kinc-hxcpp/kha/graphics4/GeometryShader.hx
Normal file
@ -0,0 +1,27 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
import kha.Blob;
|
||||
|
||||
@:headerCode("
|
||||
#include <kinc/graphics4/shader.h>
|
||||
")
|
||||
@:headerClassCode("kinc_g4_shader_t shader;")
|
||||
class GeometryShader {
|
||||
public function new(sources: Array<Blob>, files: Array<String>) {
|
||||
init(sources[0], files[0]);
|
||||
}
|
||||
|
||||
function init(source: Blob, file: String): Void {
|
||||
untyped __cpp__("kinc_g4_shader_init(&shader, source->bytes->b->Pointer(), source->get_length(), KINC_G4_SHADER_TYPE_GEOMETRY);");
|
||||
}
|
||||
|
||||
public function delete(): Void {
|
||||
untyped __cpp__("kinc_g4_shader_destroy(&shader);");
|
||||
}
|
||||
|
||||
@:keep
|
||||
function _forceInclude(): Void {
|
||||
Bytes.alloc(0);
|
||||
}
|
||||
}
|
53
Kha/Backends/Kinc-hxcpp/kha/graphics4/IndexBuffer.hx
Normal file
53
Kha/Backends/Kinc-hxcpp/kha/graphics4/IndexBuffer.hx
Normal file
@ -0,0 +1,53 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import kha.arrays.Uint32Array;
|
||||
|
||||
@:headerCode("
|
||||
#include <kinc/graphics4/indexbuffer.h>
|
||||
")
|
||||
@:headerClassCode("kinc_g4_index_buffer_t buffer;")
|
||||
class IndexBuffer {
|
||||
var data: Uint32Array;
|
||||
var myCount: Int;
|
||||
|
||||
public function new(indexCount: Int, usage: Usage, canRead: Bool = false) {
|
||||
myCount = indexCount;
|
||||
data = new Uint32Array(0);
|
||||
untyped __cpp__("kinc_g4_index_buffer_init(&buffer, indexCount, KINC_G4_INDEX_BUFFER_FORMAT_32BIT, (kinc_g4_usage_t)usage);");
|
||||
}
|
||||
|
||||
public function delete(): Void {
|
||||
untyped __cpp__("kinc_g4_index_buffer_destroy(&buffer);");
|
||||
}
|
||||
|
||||
@:functionCode("
|
||||
data->self.data = (uint8_t*)kinc_g4_index_buffer_lock(&buffer, start, count);
|
||||
data->byteArrayLength = count * 4;
|
||||
data->byteArrayOffset = 0;
|
||||
return data;
|
||||
")
|
||||
function lockPrivate(start: Int, count: Int): Uint32Array {
|
||||
return data;
|
||||
}
|
||||
|
||||
public function lock(?start: Int, ?count: Int): Uint32Array {
|
||||
if (start == null)
|
||||
start = 0;
|
||||
if (count == null)
|
||||
count = this.count();
|
||||
return lockPrivate(start, count);
|
||||
}
|
||||
|
||||
@:functionCode("kinc_g4_index_buffer_unlock(&buffer, count); data->self.data = nullptr;")
|
||||
public function unlockPrivate(count: Int): Void {}
|
||||
|
||||
public function unlock(?count: Int): Void {
|
||||
if (count == null)
|
||||
count = this.count();
|
||||
unlockPrivate(count);
|
||||
}
|
||||
|
||||
public function count(): Int {
|
||||
return myCount;
|
||||
}
|
||||
}
|
313
Kha/Backends/Kinc-hxcpp/kha/graphics4/PipelineState.hx
Normal file
313
Kha/Backends/Kinc-hxcpp/kha/graphics4/PipelineState.hx
Normal file
@ -0,0 +1,313 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import kha.graphics4.FragmentShader;
|
||||
import kha.graphics4.VertexData;
|
||||
import kha.graphics4.VertexElement;
|
||||
import kha.graphics4.VertexShader;
|
||||
import kha.graphics4.VertexStructure;
|
||||
|
||||
@:headerCode("
|
||||
#include <kinc/graphics4/graphics.h>
|
||||
#include <kinc/graphics4/pipeline.h>
|
||||
#include <kinc/graphics4/vertexstructure.h>
|
||||
#include <khalib/g4.h>
|
||||
")
|
||||
@:cppFileCode("
|
||||
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;
|
||||
}
|
||||
}
|
||||
")
|
||||
@:headerClassCode("kinc_g4_pipeline_t pipeline;")
|
||||
@:keep
|
||||
class PipelineState extends PipelineStateBase {
|
||||
public function new() {
|
||||
super();
|
||||
untyped __cpp__("kinc_g4_pipeline_init(&pipeline);");
|
||||
}
|
||||
|
||||
public function delete(): Void {
|
||||
untyped __cpp__("kinc_g4_pipeline_destroy(&pipeline);");
|
||||
}
|
||||
|
||||
@:functionCode("
|
||||
pipeline.vertex_shader = &vertexShader->shader;
|
||||
pipeline.fragment_shader = &fragmentShader->shader;
|
||||
if (geometryShader != null()) pipeline.geometry_shader = &geometryShader->shader;
|
||||
if (tessellationControlShader != null()) pipeline.tessellation_control_shader = &tessellationControlShader->shader;
|
||||
if (tessellationEvaluationShader != null()) pipeline.tessellation_evaluation_shader = &tessellationEvaluationShader->shader;
|
||||
kinc_g4_vertex_structure_t s0, s1, s2, s3;
|
||||
kinc_g4_vertex_structure_t* structures2[4] = { &s0, &s1, &s2, &s3 };
|
||||
::kha::graphics4::VertexStructure* structures[4] = { &structure0, &structure1, &structure2, &structure3 };
|
||||
for (int i1 = 0; i1 < size; ++i1) {
|
||||
kinc_g4_vertex_structure_init(structures2[i1]);
|
||||
structures2[i1]->instanced = (*structures[i1])->instanced;
|
||||
for (int i2 = 0; i2 < (*structures[i1])->size(); ++i2) {
|
||||
kinc_g4_vertex_data_t data = kha_convert_vertex_data((*structures[i1])->get(i2)->data);
|
||||
pipeline.input_layout[i1] = structures2[i1];
|
||||
kinc_g4_vertex_structure_add(pipeline.input_layout[i1], (*structures[i1])->get(i2)->name, data);
|
||||
}
|
||||
}
|
||||
for (int i = size; i < 16; ++i) {
|
||||
pipeline.input_layout[i] = nullptr;
|
||||
}
|
||||
kinc_g4_pipeline_compile(&pipeline);
|
||||
")
|
||||
function linkWithStructures2(structure0: VertexStructure, structure1: VertexStructure, structure2: VertexStructure, structure3: VertexStructure,
|
||||
size: Int): Void {}
|
||||
|
||||
static function getDepthBufferBits(depthAndStencil: DepthStencilFormat): Int {
|
||||
return switch (depthAndStencil) {
|
||||
case NoDepthAndStencil: 0;
|
||||
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: 0;
|
||||
case DepthOnly: 0;
|
||||
case DepthAutoStencilAuto: 8;
|
||||
case Depth24Stencil8: 8;
|
||||
case Depth32Stencil8: 8;
|
||||
case Depth16: 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function compile(): Void {
|
||||
var stencilReferenceValue = switch (this.stencilReferenceValue) {
|
||||
case Static(value): value;
|
||||
default: 0;
|
||||
}
|
||||
setStates(cullMode, depthMode, stencilFrontMode, stencilFrontBothPass, stencilFrontDepthFail, stencilFrontFail, stencilBackMode, stencilBackBothPass,
|
||||
stencilBackDepthFail, stencilBackFail, depthWrite, stencilReferenceValue, getBlendFactor(blendSource), getBlendFactor(blendDestination),
|
||||
getBlendOperation(blendOperation), getBlendFactor(alphaBlendSource), getBlendFactor(alphaBlendDestination),
|
||||
getBlendOperation(alphaBlendOperation), getDepthBufferBits(depthStencilAttachment), getStencilBufferBits(depthStencilAttachment));
|
||||
linkWithStructures2(inputLayout.length > 0 ? inputLayout[0] : null, inputLayout.length > 1 ? inputLayout[1] : null,
|
||||
inputLayout.length > 2 ? inputLayout[2] : null, inputLayout.length > 3 ? inputLayout[3] : null, inputLayout.length);
|
||||
}
|
||||
|
||||
public function getConstantLocation(name: String): kha.graphics4.ConstantLocation {
|
||||
var location = new kha.kore.graphics4.ConstantLocation();
|
||||
initConstantLocation(location, name);
|
||||
return location;
|
||||
}
|
||||
|
||||
@:functionCode("location->location = kinc_g4_pipeline_get_constant_location(&pipeline, name.c_str());")
|
||||
function initConstantLocation(location: kha.kore.graphics4.ConstantLocation, name: String): Void {}
|
||||
|
||||
public function getTextureUnit(name: String): kha.graphics4.TextureUnit {
|
||||
var unit = new kha.kore.graphics4.TextureUnit();
|
||||
initTextureUnit(unit, name);
|
||||
return unit;
|
||||
}
|
||||
|
||||
@:functionCode("unit->unit = kinc_g4_pipeline_get_texture_unit(&pipeline, name.c_str());")
|
||||
function initTextureUnit(unit: kha.kore.graphics4.TextureUnit, name: String): Void {}
|
||||
|
||||
static function getBlendFactor(factor: BlendingFactor): Int {
|
||||
switch (factor) {
|
||||
case BlendOne, Undefined:
|
||||
return 0;
|
||||
case BlendZero:
|
||||
return 1;
|
||||
case SourceAlpha:
|
||||
return 2;
|
||||
case DestinationAlpha:
|
||||
return 3;
|
||||
case InverseSourceAlpha:
|
||||
return 4;
|
||||
case InverseDestinationAlpha:
|
||||
return 5;
|
||||
case SourceColor:
|
||||
return 6;
|
||||
case DestinationColor:
|
||||
return 7;
|
||||
case InverseSourceColor:
|
||||
return 8;
|
||||
case InverseDestinationColor:
|
||||
return 9;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static function getBlendOperation(factor: BlendingOperation): Int {
|
||||
switch (factor) {
|
||||
case Add:
|
||||
return 0;
|
||||
case Subtract:
|
||||
return 1;
|
||||
case ReverseSubtract:
|
||||
return 2;
|
||||
case Min:
|
||||
return 3;
|
||||
case Max:
|
||||
return 4;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@:functionCode("
|
||||
switch (cullMode) {
|
||||
case 0:
|
||||
pipeline.cull_mode = KINC_G4_CULL_CLOCKWISE;
|
||||
break;
|
||||
case 1:
|
||||
pipeline.cull_mode = KINC_G4_CULL_COUNTER_CLOCKWISE;
|
||||
break;
|
||||
case 2:
|
||||
pipeline.cull_mode = KINC_G4_CULL_NOTHING;
|
||||
break;
|
||||
}
|
||||
|
||||
pipeline.depth_mode = convertCompareMode(depthMode);
|
||||
pipeline.depth_write = depthWrite;
|
||||
|
||||
pipeline.stencil_front_mode = convertCompareMode(stencilFrontMode);
|
||||
pipeline.stencil_front_both_pass = convertStencilAction(stencilFrontBothPass);
|
||||
pipeline.stencil_front_depth_fail = convertStencilAction(stencilFrontDepthFail);
|
||||
pipeline.stencil_front_fail = convertStencilAction(stencilFrontFail);
|
||||
pipeline.stencil_back_mode = convertCompareMode(stencilBackMode);
|
||||
pipeline.stencil_back_both_pass = convertStencilAction(stencilBackBothPass);
|
||||
pipeline.stencil_back_depth_fail = convertStencilAction(stencilBackDepthFail);
|
||||
pipeline.stencil_back_fail = convertStencilAction(stencilBackFail);
|
||||
pipeline.stencil_reference_value = stencilReferenceValue;
|
||||
pipeline.stencil_read_mask = stencilReadMask;
|
||||
pipeline.stencil_write_mask = stencilWriteMask;
|
||||
|
||||
pipeline.blend_source = (kinc_g4_blending_factor_t)blendSource;
|
||||
pipeline.blend_destination = (kinc_g4_blending_factor_t)blendDestination;
|
||||
pipeline.blend_operation = (kinc_g4_blending_operation_t)blendOperation;
|
||||
pipeline.alpha_blend_source = (kinc_g4_blending_factor_t)alphaBlendSource;
|
||||
pipeline.alpha_blend_destination = (kinc_g4_blending_factor_t)alphaBlendDestination;
|
||||
pipeline.alpha_blend_operation = (kinc_g4_blending_operation_t)alphaBlendOperation;
|
||||
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
pipeline.color_write_mask_red[i] = colorWriteMasksRed[i];
|
||||
pipeline.color_write_mask_green[i] = colorWriteMasksGreen[i];
|
||||
pipeline.color_write_mask_blue[i] = colorWriteMasksBlue[i];
|
||||
pipeline.color_write_mask_alpha[i] = colorWriteMasksAlpha[i];
|
||||
}
|
||||
|
||||
pipeline.color_attachment_count = colorAttachmentCount;
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
pipeline.color_attachment[i] = convertColorAttachment(colorAttachments[i]);
|
||||
}
|
||||
|
||||
pipeline.depth_attachment_bits = depthAttachmentBits;
|
||||
pipeline.stencil_attachment_bits = stencilAttachmentBits;
|
||||
|
||||
pipeline.conservative_rasterization = conservativeRasterization;
|
||||
")
|
||||
function setStates(cullMode: Int, depthMode: Int, stencilFrontMode: Int, stencilFrontBothPass: Int, stencilFrontDepthFail: Int, stencilFrontFail: Int,
|
||||
stencilBackMode: Int, stencilBackBothPass: Int, stencilBackDepthFail: Int, stencilBackFail: Int, depthWrite: Bool, stencilReferenceValue: Int,
|
||||
blendSource: Int, blendDestination: Int, blendOperation: Int, alphaBlendSource: Int, alphaBlendDestination: Int, alphaBlendOperation: Int,
|
||||
depthAttachmentBits: Int, stencilAttachmentBits: Int): Void {}
|
||||
|
||||
@:functionCode("kinc_g4_set_pipeline(&pipeline);")
|
||||
function set2(): Void {}
|
||||
|
||||
public function set(): Void {
|
||||
set2();
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
public static function _unused1(): VertexElement {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
public static function _unused2(): VertexData {
|
||||
return VertexData.Float32_1X;
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
public static function _unused3(): VertexShader {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
public static function _unused4(): FragmentShader {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
public static function _unused5(): GeometryShader {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
public static function _unused6(): TessellationControlShader {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
public static function _unused7(): TessellationEvaluationShader {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
import kha.Blob;
|
||||
|
||||
@:headerCode("
|
||||
#include <kinc/graphics4/shader.h>
|
||||
")
|
||||
@:headerClassCode("kinc_g4_shader_t shader;")
|
||||
class TessellationControlShader {
|
||||
public function new(sources: Array<Blob>, files: Array<String>) {
|
||||
init(sources[0], files[0]);
|
||||
}
|
||||
|
||||
function init(source: Blob, file: String): Void {
|
||||
untyped __cpp__("kinc_g4_shader_init(&shader, source->bytes->b->Pointer(), source->get_length(), KINC_G4_SHADER_TYPE_TESSELLATION_CONTROL);");
|
||||
}
|
||||
|
||||
public function delete(): Void {
|
||||
untyped __cpp__("kinc_g4_shader_destroy(&shader);");
|
||||
}
|
||||
|
||||
@:keep
|
||||
function _forceInclude(): Void {
|
||||
Bytes.alloc(0);
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
import kha.Blob;
|
||||
|
||||
@:headerCode("
|
||||
#include <kinc/graphics4/shader.h>
|
||||
")
|
||||
@:headerClassCode("kinc_g4_shader_t shader;")
|
||||
class TessellationEvaluationShader {
|
||||
public function new(sources: Array<Blob>, files: Array<String>) {
|
||||
init(sources[0], files[0]);
|
||||
}
|
||||
|
||||
function init(source: Blob, file: String): Void {
|
||||
untyped __cpp__("kinc_g4_shader_init(&shader, source->bytes->b->Pointer(), source->get_length(), KINC_G4_SHADER_TYPE_TESSELLATION_EVALUATION);");
|
||||
}
|
||||
|
||||
public function delete(): Void {
|
||||
untyped __cpp__("kinc_g4_shader_destroy(&shader);");
|
||||
}
|
||||
|
||||
@:keep
|
||||
function _forceInclude(): Void {
|
||||
Bytes.alloc(0);
|
||||
}
|
||||
}
|
108
Kha/Backends/Kinc-hxcpp/kha/graphics4/VertexBuffer.hx
Normal file
108
Kha/Backends/Kinc-hxcpp/kha/graphics4/VertexBuffer.hx
Normal file
@ -0,0 +1,108 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import kha.arrays.Float32Array;
|
||||
import kha.arrays.Int16Array;
|
||||
import kha.graphics4.VertexData;
|
||||
import kha.graphics4.VertexElement;
|
||||
import kha.graphics4.VertexStructure;
|
||||
|
||||
@:headerCode("
|
||||
#include <kinc/graphics4/vertexbuffer.h>
|
||||
#include <khalib/g4.h>
|
||||
")
|
||||
@:headerClassCode("kinc_g4_vertex_buffer_t buffer;")
|
||||
class VertexBuffer {
|
||||
var data: Float32Array;
|
||||
@:keep var dataInt16: Int16Array;
|
||||
|
||||
public function new(vertexCount: Int, structure: VertexStructure, usage: Usage, instanceDataStepRate: Int = 0, canRead: Bool = false) {
|
||||
init(vertexCount, structure, usage, instanceDataStepRate);
|
||||
data = new Float32Array(0);
|
||||
}
|
||||
|
||||
public function delete(): Void {
|
||||
untyped __cpp__("kinc_g4_vertex_buffer_destroy(&buffer);");
|
||||
}
|
||||
|
||||
@:functionCode("
|
||||
kinc_g4_vertex_structure_t structure2;
|
||||
kinc_g4_vertex_structure_init(&structure2);
|
||||
for (int i = 0; i < structure->size(); ++i) {
|
||||
kinc_g4_vertex_data_t data = kha_convert_vertex_data(structure->get(i)->data);
|
||||
kinc_g4_vertex_structure_add(&structure2, structure->get(i)->name, data);
|
||||
}
|
||||
kinc_g4_vertex_buffer_init(&buffer, vertexCount, &structure2, (kinc_g4_usage_t)usage, instanceDataStepRate);
|
||||
")
|
||||
function init(vertexCount: Int, structure: VertexStructure, usage: Int, instanceDataStepRate: Int) {}
|
||||
|
||||
@:functionCode("
|
||||
data->self.data = (uint8_t*)kinc_g4_vertex_buffer_lock(&buffer, start, count);
|
||||
data->byteArrayLength = count * kinc_g4_vertex_buffer_stride(&buffer);
|
||||
data->byteArrayOffset = 0;
|
||||
return data;
|
||||
")
|
||||
function lockPrivate(start: Int, count: Int): Float32Array {
|
||||
return data;
|
||||
}
|
||||
|
||||
var lastLockCount: Int = 0;
|
||||
|
||||
public function lock(?start: Int, ?count: Int): Float32Array {
|
||||
if (start == null)
|
||||
start = 0;
|
||||
if (count == null)
|
||||
count = this.count() - start;
|
||||
lastLockCount = count;
|
||||
return lockPrivate(start, count);
|
||||
}
|
||||
|
||||
@:functionCode("
|
||||
dataInt16->self.data = (uint8_t*)kinc_g4_vertex_buffer_lock(&buffer, start, count);
|
||||
dataInt16->byteArrayLength = count * kinc_g4_vertex_buffer_stride(&buffer);
|
||||
dataInt16->byteArrayOffset = 0;
|
||||
return dataInt16;
|
||||
")
|
||||
function lockInt16Private(start: Int, count: Int): Int16Array {
|
||||
return dataInt16;
|
||||
}
|
||||
|
||||
public function lockInt16(?start: Int, ?count: Int): Int16Array {
|
||||
if (start == null)
|
||||
start = 0;
|
||||
if (count == null)
|
||||
count = this.count();
|
||||
lastLockCount = count;
|
||||
if (dataInt16 == null)
|
||||
dataInt16 = new Int16Array(0);
|
||||
return lockInt16Private(start, count);
|
||||
}
|
||||
|
||||
@:functionCode("kinc_g4_vertex_buffer_unlock(&buffer, count); data->self.data = nullptr; if (!hx::IsNull(dataInt16)) dataInt16->self.data = nullptr;")
|
||||
function unlockPrivate(count: Int): Void {}
|
||||
|
||||
public function unlock(?count: Int): Void {
|
||||
unlockPrivate(count == null ? lastLockCount : count);
|
||||
}
|
||||
|
||||
@:functionCode("return kinc_g4_vertex_buffer_stride(&buffer);")
|
||||
public function stride(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:functionCode("return kinc_g4_vertex_buffer_count(&buffer);")
|
||||
public function count(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
@:keep
|
||||
public static function _unused1(): VertexElement {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
@:keep
|
||||
public static function _unused2(): VertexData {
|
||||
return VertexData.Float32_1X;
|
||||
}
|
||||
}
|
35
Kha/Backends/Kinc-hxcpp/kha/graphics4/VertexShader.hx
Normal file
35
Kha/Backends/Kinc-hxcpp/kha/graphics4/VertexShader.hx
Normal file
@ -0,0 +1,35 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
import kha.Blob;
|
||||
|
||||
@:headerCode("
|
||||
#include <kinc/graphics4/shader.h>
|
||||
")
|
||||
@:headerClassCode("kinc_g4_shader_t shader;")
|
||||
class VertexShader {
|
||||
public function new(sources: Array<Blob>, files: Array<String>) {
|
||||
if (sources != null) {
|
||||
init(sources[0], files[0]);
|
||||
}
|
||||
}
|
||||
|
||||
function init(source: Blob, file: String): Void {
|
||||
untyped __cpp__("kinc_g4_shader_init(&shader, source->bytes->b->Pointer(), source->get_length(), KINC_G4_SHADER_TYPE_VERTEX);");
|
||||
}
|
||||
|
||||
public static function fromSource(source: String): VertexShader {
|
||||
var vertexShader = new VertexShader(null, null);
|
||||
untyped __cpp__("kinc_g4_shader_init_from_source(&vertexShader->shader, source, KINC_G4_SHADER_TYPE_VERTEX);");
|
||||
return vertexShader;
|
||||
}
|
||||
|
||||
public function delete(): Void {
|
||||
untyped __cpp__("kinc_g4_shader_destroy(&shader);");
|
||||
}
|
||||
|
||||
@:keep
|
||||
function _forceInclude(): Void {
|
||||
Bytes.alloc(0);
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package kha.graphics5;
|
||||
|
||||
#if kha_dxr
|
||||
@:headerCode('
|
||||
#include <Kore/Graphics5/RayTrace.h>
|
||||
')
|
||||
@:headerClassCode("Kore::Graphics5::AccelerationStructure* accel;")
|
||||
class AccelerationStructure {
|
||||
public function new(commandList: CommandList, vb: VertexBuffer, ib: IndexBuffer) {
|
||||
init(commandList, vb, ib);
|
||||
}
|
||||
|
||||
function init(commandList: CommandList, vb: VertexBuffer, ib: IndexBuffer) {
|
||||
untyped __cpp__("accel = new Kore::Graphics5::AccelerationStructure(commandList->commandList, vb->buffer, ib->buffer);");
|
||||
}
|
||||
}
|
||||
#end
|
71
Kha/Backends/Kinc-hxcpp/kha/graphics5_/CommandList.hx
Normal file
71
Kha/Backends/Kinc-hxcpp/kha/graphics5_/CommandList.hx
Normal file
@ -0,0 +1,71 @@
|
||||
package kha.graphics5;
|
||||
|
||||
@:headerCode('
|
||||
#include <Kore/Graphics5/CommandList.h>
|
||||
')
|
||||
@:headerClassCode("Kore::Graphics5::CommandList* commandList;")
|
||||
class CommandList {
|
||||
public function new() {
|
||||
init();
|
||||
}
|
||||
|
||||
@:functionCode('commandList = new Kore::Graphics5::CommandList();')
|
||||
private function init(): Void {}
|
||||
|
||||
public function begin(): Void {
|
||||
untyped __cpp__("commandList->begin();");
|
||||
}
|
||||
|
||||
public function end(): Void {
|
||||
untyped __cpp__("commandList->end();");
|
||||
}
|
||||
|
||||
public function renderTargetToFramebufferBarrier(renderTarget: RenderTarget): Void {
|
||||
untyped __cpp__("commandList->renderTargetToFramebufferBarrier(renderTarget->renderTarget);");
|
||||
}
|
||||
|
||||
public function framebufferToRenderTargetBarrier(renderTarget: RenderTarget): Void {
|
||||
untyped __cpp__("commandList->framebufferToRenderTargetBarrier(renderTarget->renderTarget);");
|
||||
}
|
||||
|
||||
public function setRenderTargets(targets: Array<RenderTarget>): Void {
|
||||
var len = targets.length;
|
||||
var image1 = targets[0];
|
||||
var image2 = targets[1];
|
||||
var image3 = targets[2];
|
||||
var image4 = targets[3];
|
||||
var image5 = targets[4];
|
||||
var image6 = targets[5];
|
||||
var image7 = targets[6];
|
||||
untyped __cpp__("Kore::Graphics5::RenderTarget* renderTargets[8] = { image1 == null() ? nullptr : image1->renderTarget, image2 == null() ? nullptr : image2->renderTarget, image3 == null() ? nullptr : image3->renderTarget, image4 == null() ? nullptr : image4->renderTarget, image5 == null() ? nullptr : image5->renderTarget, image6 == null() ? nullptr : image6->renderTarget, image7 == null() ? nullptr : image7->renderTarget }; commandList->setRenderTargets(renderTargets, len);");
|
||||
}
|
||||
|
||||
public function drawIndexedVertices(start: Int = 0, count: Int = -1): Void {
|
||||
untyped __cpp__("commandList->drawIndexedVertices();");
|
||||
}
|
||||
|
||||
public function setIndexBuffer(indexBuffer: IndexBuffer): Void {
|
||||
untyped __cpp__("commandList->setIndexBuffer(*indexBuffer->buffer);");
|
||||
}
|
||||
|
||||
public function setVertexBuffers(vertexBuffers: Array<VertexBuffer>, offsets: Array<Int>): Void {
|
||||
var vb = vertexBuffers[0];
|
||||
untyped __cpp__("int offs[1] = { 0 }; Kore::Graphics5::VertexBuffer* buffers[1] = { vb->buffer }; commandList->setVertexBuffers(buffers, offs, 1);");
|
||||
}
|
||||
|
||||
public function setPipelineLayout(): Void {
|
||||
untyped __cpp__("commandList->setPipelineLayout();");
|
||||
}
|
||||
|
||||
public function setPipeline(pipeline: PipelineState): Void {
|
||||
untyped __cpp__("commandList->setPipeline(pipeline->pipeline);");
|
||||
}
|
||||
|
||||
public function clear(target: RenderTarget, ?color: Color, ?depth: Float, ?stencil: Int): Void {
|
||||
untyped __cpp__("commandList->clear(target->renderTarget, Kore::Graphics5::ClearColorFlag);");
|
||||
}
|
||||
|
||||
public function upload(indexBuffer: IndexBuffer): Void {
|
||||
untyped __cpp__("commandList->upload(indexBuffer->buffer);");
|
||||
}
|
||||
}
|
27
Kha/Backends/Kinc-hxcpp/kha/graphics5_/ConstantBuffer.hx
Normal file
27
Kha/Backends/Kinc-hxcpp/kha/graphics5_/ConstantBuffer.hx
Normal file
@ -0,0 +1,27 @@
|
||||
package kha.graphics5;
|
||||
|
||||
@:headerCode('
|
||||
#include <Kore/Graphics5/ConstantBuffer.h>
|
||||
')
|
||||
@:headerClassCode("Kore::Graphics5::ConstantBuffer* buffer;")
|
||||
class ConstantBuffer {
|
||||
public function new(size: Int) {
|
||||
init(size);
|
||||
}
|
||||
|
||||
function init(size: Int) {
|
||||
untyped __cpp__("buffer = new Kore::Graphics5::ConstantBuffer(size)");
|
||||
}
|
||||
|
||||
public function lock(): Void {
|
||||
untyped __cpp__("buffer->lock()");
|
||||
}
|
||||
|
||||
public function unlock(): Void {
|
||||
untyped __cpp__("buffer->unlock()");
|
||||
}
|
||||
|
||||
public function setFloat(offset: Int, value: FastFloat): Void {
|
||||
untyped __cpp__("buffer->setFloat(offset, value)");
|
||||
}
|
||||
}
|
35
Kha/Backends/Kinc-hxcpp/kha/graphics5_/FragmentShader.hx
Normal file
35
Kha/Backends/Kinc-hxcpp/kha/graphics5_/FragmentShader.hx
Normal file
@ -0,0 +1,35 @@
|
||||
package kha.graphics5;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
import kha.Blob;
|
||||
|
||||
@:headerCode('
|
||||
#include <Kore/Graphics5/Graphics.h>
|
||||
')
|
||||
@:headerClassCode("Kore::Graphics5::Shader* shader;")
|
||||
class FragmentShader {
|
||||
public function new(sources: Array<Blob>, files: Array<String>) {
|
||||
if (sources != null) {
|
||||
init(sources[0], files[0]);
|
||||
}
|
||||
}
|
||||
|
||||
private function init(source: Blob, file: String): Void {
|
||||
untyped __cpp__('shader = new Kore::Graphics5::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::Graphics5::FragmentShader);');
|
||||
}
|
||||
|
||||
// public static function fromSource(source: String): FragmentShader {
|
||||
// var fragmentShader = new FragmentShader(null, null);
|
||||
// untyped __cpp__('fragmentShader->shader = new Kore::Graphics5::Shader(source, Kore::Graphics5::FragmentShader);');
|
||||
// return fragmentShader;
|
||||
// }
|
||||
|
||||
public function delete(): Void {
|
||||
untyped __cpp__('delete shader; shader = nullptr;');
|
||||
}
|
||||
|
||||
@:keep
|
||||
function _forceInclude(): Void {
|
||||
Bytes.alloc(0);
|
||||
}
|
||||
}
|
46
Kha/Backends/Kinc-hxcpp/kha/graphics5_/IndexBuffer.hx
Normal file
46
Kha/Backends/Kinc-hxcpp/kha/graphics5_/IndexBuffer.hx
Normal file
@ -0,0 +1,46 @@
|
||||
package kha.graphics5;
|
||||
|
||||
import kha.arrays.Uint32Array;
|
||||
|
||||
@:headerCode('
|
||||
#include <Kore/Graphics5/Graphics.h>
|
||||
')
|
||||
@:headerClassCode("Kore::Graphics5::IndexBuffer* buffer;")
|
||||
class IndexBuffer {
|
||||
private var data: Uint32Array;
|
||||
private var myCount: Int;
|
||||
|
||||
public function new(indexCount: Int, usage: Usage, canRead: Bool = false) {
|
||||
myCount = indexCount;
|
||||
data = new Uint32Array();
|
||||
untyped __cpp__('buffer = new Kore::Graphics5::IndexBuffer(indexCount, true);');
|
||||
}
|
||||
|
||||
public function delete(): Void {
|
||||
untyped __cpp__('delete buffer; buffer = nullptr;');
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
data->self.data = (unsigned int*)buffer->lock() + start;
|
||||
data->self.myLength = count;
|
||||
return data;
|
||||
')
|
||||
private function lock2(start: Int, count: Int): Uint32Array {
|
||||
return data;
|
||||
}
|
||||
|
||||
public function lock(?start: Int, ?count: Int): Uint32Array {
|
||||
if (start == null)
|
||||
start = 0;
|
||||
if (count == null)
|
||||
count = this.count();
|
||||
return lock2(start, count);
|
||||
}
|
||||
|
||||
@:functionCode('buffer->unlock();')
|
||||
public function unlock(): Void {}
|
||||
|
||||
public function count(): Int {
|
||||
return myCount;
|
||||
}
|
||||
}
|
277
Kha/Backends/Kinc-hxcpp/kha/graphics5_/PipelineState.hx
Normal file
277
Kha/Backends/Kinc-hxcpp/kha/graphics5_/PipelineState.hx
Normal file
@ -0,0 +1,277 @@
|
||||
package kha.graphics5;
|
||||
|
||||
import kha.graphics5.FragmentShader;
|
||||
import kha.graphics5.VertexData;
|
||||
import kha.graphics5.VertexElement;
|
||||
import kha.graphics5.VertexShader;
|
||||
import kha.graphics5.VertexStructure;
|
||||
|
||||
@:headerCode('
|
||||
#include <Kore/Graphics5/Graphics.h>
|
||||
#include <Kore/Graphics5/PipelineState.h>
|
||||
')
|
||||
@:cppFileCode('
|
||||
static Kore::Graphics5::ZCompareMode convertCompareMode(int mode) {
|
||||
switch (mode) {
|
||||
case 0:
|
||||
return Kore::Graphics5::ZCompareAlways;
|
||||
case 1:
|
||||
return Kore::Graphics5::ZCompareNever;
|
||||
case 2:
|
||||
return Kore::Graphics5::ZCompareEqual;
|
||||
case 3:
|
||||
return Kore::Graphics5::ZCompareNotEqual;
|
||||
case 4:
|
||||
return Kore::Graphics5::ZCompareLess;
|
||||
case 5:
|
||||
return Kore::Graphics5::ZCompareLessEqual;
|
||||
case 6:
|
||||
return Kore::Graphics5::ZCompareGreater;
|
||||
case 7:
|
||||
default:
|
||||
return Kore::Graphics5::ZCompareGreaterEqual;
|
||||
}
|
||||
}
|
||||
|
||||
static Kore::Graphics5::StencilAction convertStencilAction(int action) {
|
||||
switch (action) {
|
||||
case 0:
|
||||
return Kore::Graphics5::Keep;
|
||||
case 1:
|
||||
return Kore::Graphics5::Zero;
|
||||
case 2:
|
||||
return Kore::Graphics5::Replace;
|
||||
case 3:
|
||||
return Kore::Graphics5::Increment;
|
||||
case 4:
|
||||
return Kore::Graphics5::IncrementWrap;
|
||||
case 5:
|
||||
return Kore::Graphics5::Decrement;
|
||||
case 6:
|
||||
return Kore::Graphics5::DecrementWrap;
|
||||
case 7:
|
||||
default:
|
||||
return Kore::Graphics5::Invert;
|
||||
}
|
||||
}
|
||||
')
|
||||
@:headerClassCode("Kore::Graphics5::PipelineState* pipeline;")
|
||||
@:keep
|
||||
class PipelineState extends PipelineStateBase {
|
||||
public function new() {
|
||||
super();
|
||||
untyped __cpp__('pipeline = new Kore::Graphics5::PipelineState;');
|
||||
}
|
||||
|
||||
public function delete(): Void {
|
||||
untyped __cpp__('delete pipeline; pipeline = nullptr;');
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
pipeline->vertexShader = vertexShader->shader;
|
||||
pipeline->fragmentShader = fragmentShader->shader;
|
||||
// if (geometryShader != null()) pipeline->geometryShader = geometryShader->shader;
|
||||
// if (tessellationControlShader != null()) pipeline->tessellationControlShader = tessellationControlShader->shader;
|
||||
// if (tessellationEvaluationShader != null()) pipeline->tessellationEvaluationShader = tessellationEvaluationShader->shader;
|
||||
Kore::Graphics4::VertexStructure s0, s1, s2, s3;
|
||||
Kore::Graphics4::VertexStructure* structures2[4] = { &s0, &s1, &s2, &s3 };
|
||||
::kha::graphics4::VertexStructure* structures[4] = { &structure0, &structure1, &structure2, &structure3 };
|
||||
for (int i1 = 0; i1 < size; ++i1) {
|
||||
structures2[i1]->instanced = (*structures[i1])->instanced;
|
||||
for (int i2 = 0; i2 < (*structures[i1])->size(); ++i2) {
|
||||
Kore::Graphics4::VertexData data;
|
||||
switch ((*structures[i1])->get(i2)->data) {
|
||||
case 0:
|
||||
data = Kore::Graphics4::Float1VertexData;
|
||||
break;
|
||||
case 1:
|
||||
data = Kore::Graphics4::Float2VertexData;
|
||||
break;
|
||||
case 2:
|
||||
data = Kore::Graphics4::Float3VertexData;
|
||||
break;
|
||||
case 3:
|
||||
data = Kore::Graphics4::Float4VertexData;
|
||||
break;
|
||||
case 4:
|
||||
data = Kore::Graphics4::Float4x4VertexData;
|
||||
break;
|
||||
case 5:
|
||||
data = Kore::Graphics4::Short2NormVertexData;
|
||||
break;
|
||||
case 6:
|
||||
data = Kore::Graphics4::Short4NormVertexData;
|
||||
break;
|
||||
}
|
||||
pipeline->inputLayout[i1] = structures2[i1];
|
||||
pipeline->inputLayout[i1]->add((*structures[i1])->get(i2)->name, data);
|
||||
}
|
||||
}
|
||||
for (int i = size; i < 16; ++i) {
|
||||
pipeline->inputLayout[i] = nullptr;
|
||||
}
|
||||
pipeline->compile();
|
||||
')
|
||||
private function linkWithStructures2(structure0: VertexStructure, structure1: VertexStructure, structure2: VertexStructure, structure3: VertexStructure,
|
||||
size: Int): Void {}
|
||||
|
||||
public function compile(): Void {
|
||||
setStates(cullMode, depthMode, stencilMode, stencilBothPass, stencilDepthFail, stencilFail, getBlendFunc(blendSource), getBlendFunc(blendDestination),
|
||||
getBlendFunc(alphaBlendSource), getBlendFunc(alphaBlendDestination));
|
||||
linkWithStructures2(inputLayout.length > 0 ? inputLayout[0] : null, inputLayout.length > 1 ? inputLayout[1] : null,
|
||||
inputLayout.length > 2 ? inputLayout[2] : null, inputLayout.length > 3 ? inputLayout[3] : null, inputLayout.length);
|
||||
}
|
||||
|
||||
public function getConstantLocation(name: String): kha.graphics4.ConstantLocation {
|
||||
var location = new kha.kore.graphics4.ConstantLocation();
|
||||
initConstantLocation(location, name);
|
||||
return location;
|
||||
}
|
||||
|
||||
// @:functionCode('location->location = pipeline->getConstantLocation(name.c_str());')
|
||||
private function initConstantLocation(location: kha.kore.graphics4.ConstantLocation, name: String): Void {}
|
||||
|
||||
public function getTextureUnit(name: String): kha.graphics4.TextureUnit {
|
||||
var unit = new kha.kore.graphics4.TextureUnit();
|
||||
initTextureUnit(unit, name);
|
||||
return unit;
|
||||
}
|
||||
|
||||
// @:functionCode('unit->unit = pipeline->getTextureUnit(name.c_str());')
|
||||
private function initTextureUnit(unit: kha.kore.graphics4.TextureUnit, name: String): Void {}
|
||||
|
||||
private static function getBlendFunc(factor: BlendingFactor): Int {
|
||||
switch (factor) {
|
||||
case BlendOne, Undefined:
|
||||
return 0;
|
||||
case BlendZero:
|
||||
return 1;
|
||||
case SourceAlpha:
|
||||
return 2;
|
||||
case DestinationAlpha:
|
||||
return 3;
|
||||
case InverseSourceAlpha:
|
||||
return 4;
|
||||
case InverseDestinationAlpha:
|
||||
return 5;
|
||||
case SourceColor:
|
||||
return 6;
|
||||
case DestinationColor:
|
||||
return 7;
|
||||
case InverseSourceColor:
|
||||
return 8;
|
||||
case InverseDestinationColor:
|
||||
return 9;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
switch (cullMode) {
|
||||
case 0:
|
||||
pipeline->cullMode = Kore::Graphics5::Clockwise;
|
||||
break;
|
||||
case 1:
|
||||
pipeline->cullMode = Kore::Graphics5::CounterClockwise;
|
||||
break;
|
||||
case 2:
|
||||
pipeline->cullMode = Kore::Graphics5::NoCulling;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (depthMode) {
|
||||
case 0:
|
||||
pipeline->depthMode = Kore::Graphics5::ZCompareAlways;
|
||||
break;
|
||||
case 1:
|
||||
pipeline->depthMode = Kore::Graphics5::ZCompareNever;
|
||||
break;
|
||||
case 2:
|
||||
pipeline->depthMode = Kore::Graphics5::ZCompareEqual;
|
||||
break;
|
||||
case 3:
|
||||
pipeline->depthMode = Kore::Graphics5::ZCompareNotEqual;
|
||||
break;
|
||||
case 4:
|
||||
pipeline->depthMode = Kore::Graphics5::ZCompareLess;
|
||||
break;
|
||||
case 5:
|
||||
pipeline->depthMode = Kore::Graphics5::ZCompareLessEqual;
|
||||
break;
|
||||
case 6:
|
||||
pipeline->depthMode = Kore::Graphics5::ZCompareGreater;
|
||||
break;
|
||||
case 7:
|
||||
pipeline->depthMode = Kore::Graphics5::ZCompareGreaterEqual;
|
||||
break;
|
||||
}
|
||||
pipeline->depthWrite = depthWrite;
|
||||
|
||||
pipeline->stencilMode = convertCompareMode(stencilMode);
|
||||
pipeline->stencilBothPass = convertStencilAction(stencilBothPass);
|
||||
pipeline->stencilDepthFail = convertStencilAction(stencilDepthFail);
|
||||
pipeline->stencilFail = convertStencilAction(stencilFail);
|
||||
pipeline->stencilReferenceValue = stencilReferenceValue;
|
||||
pipeline->stencilReadMask = stencilReadMask;
|
||||
pipeline->stencilWriteMask = stencilWriteMask;
|
||||
|
||||
pipeline->blendSource = (Kore::Graphics5::BlendingOperation)blendSource;
|
||||
pipeline->blendDestination = (Kore::Graphics5::BlendingOperation)blendDestination;
|
||||
pipeline->alphaBlendSource = (Kore::Graphics5::BlendingOperation)alphaBlendSource;
|
||||
pipeline->alphaBlendDestination = (Kore::Graphics5::BlendingOperation)alphaBlendDestination;
|
||||
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
pipeline->colorWriteMaskRed[i] = colorWriteMasksRed[i];
|
||||
pipeline->colorWriteMaskGreen[i] = colorWriteMasksGreen[i];
|
||||
pipeline->colorWriteMaskBlue[i] = colorWriteMasksBlue[i];
|
||||
pipeline->colorWriteMaskAlpha[i] = colorWriteMasksAlpha[i];
|
||||
}
|
||||
|
||||
pipeline->conservativeRasterization = conservativeRasterization;
|
||||
')
|
||||
private function setStates(cullMode: Int, depthMode: Int, stencilMode: Int, stencilBothPass: Int, stencilDepthFail: Int, stencilFail: Int,
|
||||
blendSource: Int, blendDestination: Int, alphaBlendSource: Int, alphaBlendDestination: Int): Void {}
|
||||
|
||||
// @:functionCode('Kore::Graphics4::setPipeline(pipeline);')
|
||||
// private function set2(): Void {
|
||||
// }
|
||||
// public function set(): Void {
|
||||
// set2();
|
||||
// }
|
||||
|
||||
@:noCompletion
|
||||
public static function _unused1(): VertexElement {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
public static function _unused2(): VertexData {
|
||||
return Float1;
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
public static function _unused3(): VertexShader {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
public static function _unused4(): FragmentShader {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
public static function _unused5(): GeometryShader {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
public static function _unused6(): TessellationControlShader {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
public static function _unused7(): TessellationEvaluationShader {
|
||||
return null;
|
||||
}
|
||||
}
|
18
Kha/Backends/Kinc-hxcpp/kha/graphics5_/RayTracePipeline.hx
Normal file
18
Kha/Backends/Kinc-hxcpp/kha/graphics5_/RayTracePipeline.hx
Normal file
@ -0,0 +1,18 @@
|
||||
package kha.graphics5;
|
||||
|
||||
#if kha_dxr
|
||||
@:headerCode('
|
||||
#include <Kore/Graphics5/RayTrace.h>
|
||||
')
|
||||
@:headerClassCode("Kore::Graphics5::RayTracePipeline* pipeline;")
|
||||
class RayTracePipeline {
|
||||
public function new(commandList: CommandList, rayTraceShader: kha.Blob, constantBuffer: ConstantBuffer) {
|
||||
untyped __cpp__("pipeline = new Kore::Graphics5::RayTracePipeline(commandList->commandList, rayTraceShader->bytes->b->Pointer(), rayTraceShader->get_length(), constantBuffer->buffer);");
|
||||
}
|
||||
|
||||
@:keep
|
||||
function _forceInclude(): Void {
|
||||
haxe.io.Bytes.alloc(0);
|
||||
}
|
||||
}
|
||||
#end
|
17
Kha/Backends/Kinc-hxcpp/kha/graphics5_/RayTraceTarget.hx
Normal file
17
Kha/Backends/Kinc-hxcpp/kha/graphics5_/RayTraceTarget.hx
Normal file
@ -0,0 +1,17 @@
|
||||
package kha.graphics5;
|
||||
|
||||
#if kha_dxr
|
||||
@:headerCode('
|
||||
#include <Kore/Graphics5/RayTrace.h>
|
||||
')
|
||||
@:headerClassCode("Kore::Graphics5::RayTraceTarget* target;")
|
||||
class RayTraceTarget {
|
||||
public function new(width: Int, height: Int) {
|
||||
init(width, height);
|
||||
}
|
||||
|
||||
function init(width: Int, height: Int) {
|
||||
untyped __cpp__("target = new Kore::Graphics5::RayTraceTarget(width, height);");
|
||||
}
|
||||
}
|
||||
#end
|
35
Kha/Backends/Kinc-hxcpp/kha/graphics5_/RenderTarget.hx
Normal file
35
Kha/Backends/Kinc-hxcpp/kha/graphics5_/RenderTarget.hx
Normal file
@ -0,0 +1,35 @@
|
||||
package kha.graphics5;
|
||||
|
||||
@:headerCode('
|
||||
#include <Kore/Graphics5/Graphics.h>
|
||||
')
|
||||
@:headerClassCode("Kore::Graphics5::RenderTarget* renderTarget;")
|
||||
class RenderTarget {
|
||||
public function new(width: Int, height: Int, depthBufferBits: Int, antialiasing: Bool, format: TextureFormat, stencilBufferBits: Int, contextId: Int) {
|
||||
init(width, height, depthBufferBits, antialiasing, getRenderTargetFormat(format), stencilBufferBits, contextId);
|
||||
}
|
||||
|
||||
@:functionCode('renderTarget = new Kore::Graphics5::RenderTarget(width, height, depthBufferBits, antialiasing, (Kore::Graphics5::RenderTargetFormat)format, stencilBufferBits, contextId);')
|
||||
private function init(width: Int, height: Int, depthBufferBits: Int, antialiasing: Bool, format: Int, stencilBufferBits: Int, contextId: Int): Void {}
|
||||
|
||||
private 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;
|
||||
}
|
||||
}
|
||||
}
|
92
Kha/Backends/Kinc-hxcpp/kha/graphics5_/VertexBuffer.hx
Normal file
92
Kha/Backends/Kinc-hxcpp/kha/graphics5_/VertexBuffer.hx
Normal file
@ -0,0 +1,92 @@
|
||||
package kha.graphics5;
|
||||
|
||||
import kha.arrays.Float32Array;
|
||||
import kha.graphics5.VertexData;
|
||||
import kha.graphics5.VertexElement;
|
||||
import kha.graphics5.VertexStructure;
|
||||
|
||||
@:headerCode('
|
||||
#include <Kore/Graphics5/Graphics.h>
|
||||
')
|
||||
@:headerClassCode("Kore::Graphics5::VertexBuffer* buffer;")
|
||||
class VertexBuffer {
|
||||
private var data: Float32Array;
|
||||
|
||||
public function new(vertexCount: Int, structure: VertexStructure, usage: Usage, instanceDataStepRate: Int = 0, canRead: Bool = false) {
|
||||
init(vertexCount, structure, usage, instanceDataStepRate);
|
||||
data = new Float32Array();
|
||||
}
|
||||
|
||||
public function delete(): Void {
|
||||
untyped __cpp__('delete buffer; buffer = nullptr;');
|
||||
}
|
||||
|
||||
@:functionCode("
|
||||
Kore::Graphics4::VertexStructure structure2;
|
||||
for (int i = 0; i < structure->size(); ++i) {
|
||||
Kore::Graphics4::VertexData data;
|
||||
switch (structure->get(i)->data) {
|
||||
case 0:
|
||||
data = Kore::Graphics4::Float1VertexData;
|
||||
break;
|
||||
case 1:
|
||||
data = Kore::Graphics4::Float2VertexData;
|
||||
break;
|
||||
case 2:
|
||||
data = Kore::Graphics4::Float3VertexData;
|
||||
break;
|
||||
case 3:
|
||||
data = Kore::Graphics4::Float4VertexData;
|
||||
break;
|
||||
case 4:
|
||||
data = Kore::Graphics4::Float4x4VertexData;
|
||||
break;
|
||||
}
|
||||
structure2.add(structure->get(i)->name, data);
|
||||
}
|
||||
buffer = new Kore::Graphics5::VertexBuffer(vertexCount, structure2, false);
|
||||
")
|
||||
private function init(vertexCount: Int, structure: VertexStructure, usage: Int, instanceDataStepRate: Int) {}
|
||||
|
||||
@:functionCode('
|
||||
data->self.data = buffer->lock() + start * buffer->stride() / 4;
|
||||
data->self.myLength = count * buffer->stride() / 4;
|
||||
return data;
|
||||
')
|
||||
private function lock2(start: Int, count: Int): Float32Array {
|
||||
return data;
|
||||
}
|
||||
|
||||
public function lock(?start: Int, ?count: Int): Float32Array {
|
||||
if (start == null)
|
||||
start = 0;
|
||||
if (count == null)
|
||||
count = this.count();
|
||||
return lock2(start, count);
|
||||
}
|
||||
|
||||
@:functionCode('buffer->unlock();')
|
||||
public function unlock(): Void {}
|
||||
|
||||
@:functionCode("return buffer->stride();")
|
||||
public function stride(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:functionCode("return buffer->count();")
|
||||
public function count(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
@:keep
|
||||
public static function _unused1(): VertexElement {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
@:keep
|
||||
public static function _unused2(): VertexData {
|
||||
return Float1;
|
||||
}
|
||||
}
|
35
Kha/Backends/Kinc-hxcpp/kha/graphics5_/VertexShader.hx
Normal file
35
Kha/Backends/Kinc-hxcpp/kha/graphics5_/VertexShader.hx
Normal file
@ -0,0 +1,35 @@
|
||||
package kha.graphics5;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
import kha.Blob;
|
||||
|
||||
@:headerCode('
|
||||
#include <Kore/Graphics5/Graphics.h>
|
||||
')
|
||||
@:headerClassCode("Kore::Graphics5::Shader* shader;")
|
||||
class VertexShader {
|
||||
public function new(sources: Array<Blob>, files: Array<String>) {
|
||||
if (sources != null) {
|
||||
init(sources[0], files[0]);
|
||||
}
|
||||
}
|
||||
|
||||
private function init(source: Blob, file: String): Void {
|
||||
untyped __cpp__('shader = new Kore::Graphics5::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::Graphics5::VertexShader);');
|
||||
}
|
||||
|
||||
// public static function fromSource(source: String): VertexShader {
|
||||
// var vertexShader = new VertexShader(null, null);
|
||||
// untyped __cpp__('vertexShader->shader = new Kore::Graphics5::Shader(source, Kore::Graphics5::VertexShader);');
|
||||
// return vertexShader;
|
||||
// }
|
||||
|
||||
public function delete(): Void {
|
||||
untyped __cpp__('delete shader; shader = nullptr;');
|
||||
}
|
||||
|
||||
@:keep
|
||||
function _forceInclude(): Void {
|
||||
Bytes.alloc(0);
|
||||
}
|
||||
}
|
46
Kha/Backends/Kinc-hxcpp/kha/input/MouseImpl.hx
Normal file
46
Kha/Backends/Kinc-hxcpp/kha/input/MouseImpl.hx
Normal file
@ -0,0 +1,46 @@
|
||||
package kha.input;
|
||||
|
||||
import kha.SystemImpl;
|
||||
import kha.input.Mouse;
|
||||
|
||||
class MouseImpl extends kha.input.Mouse {
|
||||
public function new() {
|
||||
super();
|
||||
}
|
||||
|
||||
override public function lock(): Void {
|
||||
SystemImpl.lockMouse();
|
||||
}
|
||||
|
||||
override public function unlock(): Void {
|
||||
SystemImpl.unlockMouse();
|
||||
}
|
||||
|
||||
override public function canLock(): Bool {
|
||||
return SystemImpl.canLockMouse();
|
||||
}
|
||||
|
||||
override public function isLocked(): Bool {
|
||||
return SystemImpl.isMouseLocked();
|
||||
}
|
||||
|
||||
override public function notifyOnLockChange(func: Void->Void, error: Void->Void): Void {
|
||||
SystemImpl.notifyOfMouseLockChange(func, error);
|
||||
}
|
||||
|
||||
override public function removeFromLockChange(func: Void->Void, error: Void->Void): Void {
|
||||
SystemImpl.removeFromMouseLockChange(func, error);
|
||||
}
|
||||
|
||||
override public function hideSystemCursor(): Void {
|
||||
SystemImpl.hideSystemCursor();
|
||||
}
|
||||
|
||||
override public function showSystemCursor(): Void {
|
||||
SystemImpl.showSystemCursor();
|
||||
}
|
||||
|
||||
override public function setSystemCursor(cursor: MouseCursor): Void {
|
||||
SystemImpl.setSystemCursor(cursor.getIndex());
|
||||
}
|
||||
}
|
31
Kha/Backends/Kinc-hxcpp/kha/input/Sensor.hx
Normal file
31
Kha/Backends/Kinc-hxcpp/kha/input/Sensor.hx
Normal file
@ -0,0 +1,31 @@
|
||||
package kha.input;
|
||||
|
||||
@:keep
|
||||
class Sensor {
|
||||
static var accelerometer: Sensor = new Sensor();
|
||||
static var gyroscope: Sensor = new Sensor();
|
||||
|
||||
var listeners: Array<Float->Float->Float->Void> = new Array();
|
||||
|
||||
public static function get(type: SensorType): Sensor {
|
||||
switch (type) {
|
||||
case Accelerometer:
|
||||
return accelerometer;
|
||||
case Gyroscope:
|
||||
return gyroscope;
|
||||
}
|
||||
}
|
||||
|
||||
public function notify(listener: Float->Float->Float->Void): Void {
|
||||
listeners.push(listener);
|
||||
}
|
||||
|
||||
function new() {}
|
||||
|
||||
public static function _changed(type: Int, x: Float, y: Float, z: Float): Void {
|
||||
var sensor = get(type == 0 ? SensorType.Accelerometer : SensorType.Gyroscope);
|
||||
for (listener in sensor.listeners) {
|
||||
listener(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
17
Kha/Backends/Kinc-hxcpp/kha/kore/Keyboard.hx
Normal file
17
Kha/Backends/Kinc-hxcpp/kha/kore/Keyboard.hx
Normal file
@ -0,0 +1,17 @@
|
||||
package kha.kore;
|
||||
|
||||
@:headerCode("
|
||||
#include <kinc/input/keyboard.h>
|
||||
")
|
||||
@:allow(kha.SystemImpl)
|
||||
class Keyboard extends kha.input.Keyboard {
|
||||
function new() {
|
||||
super();
|
||||
}
|
||||
|
||||
@:functionCode("kinc_keyboard_show();")
|
||||
override public function show(): Void {}
|
||||
|
||||
@:functionCode("kinc_keyboard_hide();")
|
||||
override public function hide(): Void {}
|
||||
}
|
62
Kha/Backends/Kinc-hxcpp/kha/kore/Video.hx
Normal file
62
Kha/Backends/Kinc-hxcpp/kha/kore/Video.hx
Normal file
@ -0,0 +1,62 @@
|
||||
package kha.kore;
|
||||
|
||||
@:headerCode("
|
||||
#include <kinc/video.h>
|
||||
")
|
||||
@:headerClassCode("kinc_video_t video;")
|
||||
class Video extends kha.Video {
|
||||
public function new(filename: String) {
|
||||
super();
|
||||
init(filename);
|
||||
}
|
||||
|
||||
@:functionCode("kinc_video_init(&video, filename.c_str());")
|
||||
function init(filename: String) {}
|
||||
|
||||
@:functionCode("kinc_video_play(&video, loop);")
|
||||
override public function play(loop: Bool = false): Void {}
|
||||
|
||||
@:functionCode("kinc_video_pause(&video);")
|
||||
override public function pause(): Void {}
|
||||
|
||||
@:functionCode("kinc_video_stop(&video);")
|
||||
override public function stop(): Void {}
|
||||
|
||||
override function update(time: Float) {
|
||||
untyped __cpp__('kinc_video_update(&video, time)');
|
||||
}
|
||||
|
||||
// @:functionCode("return static_cast<int>(video->duration * 1000.0);")
|
||||
override public function getLength(): Int { // Miliseconds
|
||||
return 0;
|
||||
}
|
||||
|
||||
// @:functionCode("return static_cast<int>(video->position * 1000.0);")
|
||||
override public function getCurrentPos(): Int { // Miliseconds
|
||||
return 0;
|
||||
}
|
||||
|
||||
override function get_position(): Int {
|
||||
return getCurrentPos();
|
||||
}
|
||||
|
||||
// @:functionCode("video->update(value / 1000.0); return value;")
|
||||
override function set_position(value: Int): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
override public function isFinished(): Bool {
|
||||
return untyped __cpp__("kinc_video_finished(&video)");
|
||||
}
|
||||
|
||||
override public function width(): Int {
|
||||
return untyped __cpp__("kinc_video_width(&video)");
|
||||
}
|
||||
|
||||
override public function height(): Int {
|
||||
return untyped __cpp__("kinc_video_height(&video)");
|
||||
}
|
||||
|
||||
@:functionCode("kinc_video_destroy(&video);")
|
||||
override public function unload(): Void {}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package kha.kore.graphics4;
|
||||
|
||||
@:headerCode("
|
||||
#include <kinc/graphics4/constantlocation.h>
|
||||
")
|
||||
@:headerClassCode("kinc_g4_constant_location_t location;")
|
||||
class ConstantLocation implements kha.graphics4.ConstantLocation {
|
||||
public function new() {}
|
||||
}
|
503
Kha/Backends/Kinc-hxcpp/kha/kore/graphics4/Graphics.hx
Normal file
503
Kha/Backends/Kinc-hxcpp/kha/kore/graphics4/Graphics.hx
Normal file
@ -0,0 +1,503 @@
|
||||
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 {}
|
||||
}
|
11
Kha/Backends/Kinc-hxcpp/kha/kore/graphics4/Graphics2.hx
Normal file
11
Kha/Backends/Kinc-hxcpp/kha/kore/graphics4/Graphics2.hx
Normal file
@ -0,0 +1,11 @@
|
||||
package kha.kore.graphics4;
|
||||
|
||||
class Graphics2 extends kha.graphics4.Graphics2 {
|
||||
override public function drawVideoInternal(video: kha.Video, x: Float, y: Float, width: Float, height: Float): Void {
|
||||
// color = Color.Blue;
|
||||
// fillRect(x, y, width, height);
|
||||
|
||||
color = Color.White;
|
||||
drawScaledSubImage(Image.fromVideo(video), 0, 0, video.width(), video.height() * 0.66, x, y, width, height);
|
||||
}
|
||||
}
|
6
Kha/Backends/Kinc-hxcpp/kha/kore/graphics4/ShaderType.hx
Normal file
6
Kha/Backends/Kinc-hxcpp/kha/kore/graphics4/ShaderType.hx
Normal file
@ -0,0 +1,6 @@
|
||||
package kha.kore.graphics4;
|
||||
|
||||
enum abstract ShaderType(Int) {
|
||||
var FragmentShader;
|
||||
var VertexShader;
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package kha.kore.graphics4;
|
||||
|
||||
@:headerCode("
|
||||
#include <kinc/graphics4/textureunit.h>
|
||||
")
|
||||
@:headerClassCode("kinc_g4_texture_unit_t unit;")
|
||||
class TextureUnit implements kha.graphics4.TextureUnit {
|
||||
public function new() {}
|
||||
}
|
55
Kha/Backends/Kinc-hxcpp/kha/kore/graphics5_/Graphics.hx
Normal file
55
Kha/Backends/Kinc-hxcpp/kha/kore/graphics5_/Graphics.hx
Normal file
@ -0,0 +1,55 @@
|
||||
package kha.kore.graphics5;
|
||||
|
||||
import kha.graphics5.RenderTarget;
|
||||
import kha.graphics5.CommandList;
|
||||
#if kha_dxr
|
||||
import kha.graphics5.AccelerationStructure;
|
||||
import kha.graphics5.RayTraceTarget;
|
||||
import kha.graphics5.RayTracePipeline;
|
||||
#end
|
||||
|
||||
@:headerCode('
|
||||
#include <Kore/Graphics5/Graphics.h>
|
||||
#include <Kore/Graphics5/RayTrace.h>
|
||||
')
|
||||
class Graphics implements kha.graphics5.Graphics {
|
||||
private var target: Canvas;
|
||||
|
||||
public function new(target: Canvas = null) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public function begin(target: RenderTarget): Void {
|
||||
untyped __cpp__("Kore::Graphics5::begin(target->renderTarget);");
|
||||
}
|
||||
|
||||
public function end(): Void {
|
||||
untyped __cpp__("Kore::Graphics5::end();");
|
||||
}
|
||||
|
||||
public function swapBuffers(): Void {
|
||||
untyped __cpp__("Kore::Graphics5::swapBuffers();");
|
||||
}
|
||||
|
||||
#if kha_dxr
|
||||
public function setAccelerationStructure(accel: AccelerationStructure): Void {
|
||||
untyped __cpp__("Kore::Graphics5::setAccelerationStructure(accel->accel);");
|
||||
}
|
||||
|
||||
public function setRayTracePipeline(pipe: RayTracePipeline): Void {
|
||||
untyped __cpp__("Kore::Graphics5::setRayTracePipeline(pipe->pipeline);");
|
||||
}
|
||||
|
||||
public function setRayTraceTarget(target: RayTraceTarget): Void {
|
||||
untyped __cpp__("Kore::Graphics5::setRayTraceTarget(target->target);");
|
||||
}
|
||||
|
||||
public function dispatchRays(commandList: CommandList): Void {
|
||||
untyped __cpp__("Kore::Graphics5::dispatchRays(commandList->commandList);");
|
||||
}
|
||||
|
||||
public function copyRayTraceTarget(commandList: CommandList, renderTarget: RenderTarget, output: RayTraceTarget): Void {
|
||||
untyped __cpp__("Kore::Graphics5::copyRayTraceTarget(commandList->commandList, renderTarget->renderTarget, output->target);");
|
||||
}
|
||||
#end
|
||||
}
|
186
Kha/Backends/Kinc-hxcpp/kha/kore/vr/CardboardVrInterface.hx
Normal file
186
Kha/Backends/Kinc-hxcpp/kha/kore/vr/CardboardVrInterface.hx
Normal file
@ -0,0 +1,186 @@
|
||||
package kha.kore.vr;
|
||||
|
||||
import kha.graphics4.FragmentShader;
|
||||
import kha.graphics4.Graphics;
|
||||
import kha.graphics4.ConstantLocation;
|
||||
import kha.graphics4.TextureUnit;
|
||||
import kha.Framebuffer;
|
||||
import kha.graphics4.IndexBuffer;
|
||||
import kha.graphics4.Program;
|
||||
import kha.graphics4.Usage;
|
||||
import kha.graphics4.VertexBuffer;
|
||||
import kha.graphics4.VertexData;
|
||||
import kha.graphics4.VertexShader;
|
||||
import kha.graphics4.VertexStructure;
|
||||
import kha.graphics4.TextureFormat;
|
||||
import kha.graphics4.CullMode;
|
||||
import kha.graphics4.BlendingOperation;
|
||||
import kha.Image;
|
||||
import kha.math.Matrix4;
|
||||
import kha.math.Quaternion;
|
||||
import kha.math.Vector2;
|
||||
import kha.math.Vector3;
|
||||
import kha.math.Vector4;
|
||||
import kha.vr.Pose;
|
||||
import kha.vr.PoseState;
|
||||
import kha.vr.SensorState;
|
||||
import kha.vr.TimeWarpParms;
|
||||
import kha.Loader;
|
||||
|
||||
#if ANDROID
|
||||
@:headerCode('
|
||||
#include <Kore/Vr/VrInterface.h>
|
||||
')
|
||||
#end
|
||||
#if VR_CARDBOARD
|
||||
class CardboardVrInterfaceTest extends kha.vr.VrInterface {
|
||||
// We draw directly to the screen
|
||||
public var framebuffer: Framebuffer;
|
||||
|
||||
private var image: Image;
|
||||
|
||||
@:functionCode('
|
||||
return Kore::VrInterface::getGaze();
|
||||
')
|
||||
private function GetGaze(): Quaternion {
|
||||
return null;
|
||||
}
|
||||
|
||||
public override function GetSensorState(): SensorState {
|
||||
// Return from cardboard api
|
||||
|
||||
var s: SensorState = new SensorState();
|
||||
s.Predicted = s.Recorded = new PoseState();
|
||||
s.Predicted.Pose = new Pose();
|
||||
s.Predicted.Pose.Orientation = GetGaze();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public override function GetPredictedSensorState(time: Float): SensorState {
|
||||
// Return using cardboard api
|
||||
return GetSensorState();
|
||||
}
|
||||
|
||||
public override function WarpSwapBlack(): Void {
|
||||
// Oculus-specific
|
||||
}
|
||||
|
||||
public override function WarpSwapLoadingIcon(): Void {
|
||||
// Oculus-specific
|
||||
}
|
||||
|
||||
public override function WarpSwap(parms: TimeWarpParms): Void {
|
||||
// Draw the two images, side-by-side
|
||||
// parms.LeftImage.Image = Loader.the.getImage("use.png");
|
||||
|
||||
if (image == null) {
|
||||
image = Image.createRenderTarget(Sys.pixelWidth, Sys.pixelHeight, TextureFormat.RGBA32);
|
||||
}
|
||||
|
||||
var g: Graphics = image.g4;
|
||||
g.begin();
|
||||
|
||||
g.clear(Color.Orange);
|
||||
|
||||
g.setCullMode(CullMode.None);
|
||||
// g.setBlendingMode(BlendingOperation.BlendOne, BlendingOperation.BlendZero);
|
||||
|
||||
g.setProgram(program);
|
||||
g.setVertexBuffer(vb);
|
||||
g.setIndexBuffer(ib);
|
||||
|
||||
var texture: TextureUnit = program.getTextureUnit("tex");
|
||||
var matrixLocation: ConstantLocation = program.getConstantLocation("projectionMatrix");
|
||||
|
||||
var t: Matrix4 = Matrix4.translation(-0.5, 0, 0);
|
||||
var s: Matrix4 = Matrix4.scale(0.5, 1, 1);
|
||||
var m: Matrix4 = s.multmat(t);
|
||||
g.setMatrix(matrixLocation, m);
|
||||
|
||||
g.setTexture(texture, parms.LeftImage.Image);
|
||||
g.drawIndexedVertices();
|
||||
|
||||
t = Matrix4.translation(0.5, 0, 0);
|
||||
m = s.multmat(t);
|
||||
|
||||
g.setMatrix(matrixLocation, m);
|
||||
|
||||
g.setTexture(texture, parms.RightImage.Image);
|
||||
g.drawIndexedVertices();
|
||||
|
||||
g.end();
|
||||
|
||||
framebuffer.g4.begin();
|
||||
SendTextureToDistortion(image);
|
||||
|
||||
framebuffer.g4.end();
|
||||
}
|
||||
|
||||
@:functionCode('Kore::VrInterface::DistortTexture(image.mPtr);')
|
||||
private function SendTextureToDistortion(image: Image) {
|
||||
// TODO: Add a function to CPP VrInterface
|
||||
// TODO: Check how large the texture should be
|
||||
}
|
||||
|
||||
public override function GetTimeInSeconds(): Float {
|
||||
return Sys.getTime();
|
||||
}
|
||||
|
||||
var vb: VertexBuffer;
|
||||
var ib: IndexBuffer;
|
||||
|
||||
var program: Program;
|
||||
|
||||
private function setVertex(a: Array<Float>, index: Int, pos: Vector3, uv: Vector2, color: Vector4) {
|
||||
var base: Int = index * 9;
|
||||
a[base + 0] = pos.x;
|
||||
a[base + 1] = pos.y;
|
||||
a[base + 2] = pos.z;
|
||||
base += 3;
|
||||
a[base + 0] = uv.x;
|
||||
a[base + 1] = uv.y;
|
||||
base += 2;
|
||||
for (i in 0...4) {
|
||||
a[base + i] = color.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
|
||||
var structure: VertexStructure = new VertexStructure();
|
||||
structure.add("vertexPosition", VertexData.Float3);
|
||||
structure.add("vertexUV", VertexData.Float2);
|
||||
structure.add("vertexColor", VertexData.Float4);
|
||||
|
||||
vb = new VertexBuffer(4, structure, Usage.StaticUsage);
|
||||
var verts: Array<Float> = vb.lock();
|
||||
|
||||
setVertex(verts, 0, new Vector3(-1, -1, 0), new Vector2(0, 0), new Vector4(1, 1, 1, 1));
|
||||
setVertex(verts, 1, new Vector3(-1, 1, 0), new Vector2(0, 1), new Vector4(1, 1, 1, 1));
|
||||
setVertex(verts, 2, new Vector3(1, -1, 0), new Vector2(1, 0), new Vector4(1, 1, 1, 1));
|
||||
setVertex(verts, 3, new Vector3(1, 1, 0), new Vector2(1, 1), new Vector4(1, 1, 1, 1));
|
||||
|
||||
vb.unlock();
|
||||
|
||||
ib = new IndexBuffer(6, Usage.StaticUsage);
|
||||
var indices: Array<Int> = ib.lock();
|
||||
|
||||
indices[0] = 0;
|
||||
indices[1] = 1;
|
||||
indices[2] = 2;
|
||||
indices[3] = 1;
|
||||
indices[4] = 3;
|
||||
indices[5] = 2;
|
||||
|
||||
ib.unlock();
|
||||
|
||||
program = new Program();
|
||||
|
||||
program.setVertexShader(new VertexShader(Loader.the.getShader("painter-image.vert")));
|
||||
program.setFragmentShader(new FragmentShader(Loader.the.getShader("painter-image.frag")));
|
||||
program.link(structure);
|
||||
}
|
||||
}
|
||||
#end
|
75
Kha/Backends/Kinc-hxcpp/kha/kore/vr/VrInterface.hx
Normal file
75
Kha/Backends/Kinc-hxcpp/kha/kore/vr/VrInterface.hx
Normal file
@ -0,0 +1,75 @@
|
||||
package kha.kore.vr;
|
||||
|
||||
import kha.vr.SensorState;
|
||||
import kha.vr.TimeWarpParms;
|
||||
|
||||
#if ANDROID
|
||||
@:headerCode('
|
||||
#include <Kore/Vr/VrInterface.h>
|
||||
')
|
||||
#end
|
||||
class VrInterface extends kha.vr.VrInterface {
|
||||
#if ANDROID
|
||||
// Returns the current sensor state
|
||||
// Returns the predicted sensor state at the specified time
|
||||
@:functionCode('return Kore::VrInterface::GetSensorState();')
|
||||
public override function GetSensorState(): SensorState {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Returns the predicted sensor state at the specified time
|
||||
|
||||
@:functionCode('return Kore::VrInterface::GetPredictedSensorState(time);')
|
||||
public override function GetPredictedSensorState(time: Float): SensorState {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Sends a black image to the warp swap thread
|
||||
|
||||
@:functionCode('Kore::VrInterface::WarpSwapBlack();')
|
||||
public override function WarpSwapBlack(): Void {}
|
||||
|
||||
// Sends the Oculus loading symbol to the warp swap thread
|
||||
|
||||
@:functionCode('Kore::VrInterface::WarpSwapLoadingIcon();')
|
||||
public override function WarpSwapLoadingIcon(): Void {}
|
||||
|
||||
// Sends the set of images to the warp swap thread
|
||||
|
||||
@:functionCode('Kore::VrInterface::WarpSwap(parms.mPtr);')
|
||||
public override function WarpSwap(parms: TimeWarpParms): Void {}
|
||||
|
||||
@:functionCode('return Kore::VrInterface::GetTimeInSeconds();')
|
||||
public override function GetTimeInSeconds(): Float {
|
||||
return 0.0;
|
||||
}
|
||||
#else
|
||||
// Returns the current sensor state
|
||||
// Returns the predicted sensor state at the specified time
|
||||
public override function GetSensorState(): SensorState {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Returns the predicted sensor state at the specified time
|
||||
public override function GetPredictedSensorState(time: Float): SensorState {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Sends a black image to the warp swap thread
|
||||
public override function WarpSwapBlack(): Void {}
|
||||
|
||||
// Sends the Oculus loading symbol to the warp swap thread
|
||||
public override function WarpSwapLoadingIcon(): Void {}
|
||||
|
||||
// Sends the set of images to the warp swap thread
|
||||
public override function WarpSwap(parms: TimeWarpParms): Void {}
|
||||
|
||||
public override function GetTimeInSeconds(): Float {
|
||||
return 0.0;
|
||||
}
|
||||
#end
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
}
|
||||
}
|
62
Kha/Backends/Kinc-hxcpp/kha/kore/vr/VrInterfaceRift.hx
Normal file
62
Kha/Backends/Kinc-hxcpp/kha/kore/vr/VrInterfaceRift.hx
Normal file
@ -0,0 +1,62 @@
|
||||
package kha.kore.vr;
|
||||
|
||||
import kha.math.Quaternion;
|
||||
import kha.math.Vector3;
|
||||
import kha.vr.Pose;
|
||||
import kha.vr.PoseState;
|
||||
import kha.vr.SensorState;
|
||||
import kha.vr.TimeWarpParms;
|
||||
|
||||
@:headerCode('
|
||||
#include <Kore/Vr/VrInterface.h>
|
||||
')
|
||||
/**
|
||||
* ...
|
||||
* @author Florian Mehm
|
||||
*/
|
||||
class VrInterfaceRift extends VrInterface {
|
||||
// Returns the current sensor state
|
||||
#if VR_RIFT
|
||||
@:functionCode('
|
||||
return Kore::VrInterface::GetSensorState();
|
||||
')
|
||||
#end
|
||||
public override function GetSensorState(): SensorState {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Returns the predicted sensor state at the specified time
|
||||
public override function GetPredictedSensorState(time: Float): SensorState {
|
||||
return GetSensorState();
|
||||
}
|
||||
|
||||
// Sends a black image to the warp swap thread
|
||||
public override function WarpSwapBlack(): Void {
|
||||
return;
|
||||
}
|
||||
|
||||
// Sends the Oculus loading symbol to the warp swap thread
|
||||
public override function WarpSwapLoadingIcon(): Void {
|
||||
return;
|
||||
}
|
||||
|
||||
// Sends the set of images to the warp swap thread
|
||||
#if VR_RIFT
|
||||
@:functionCode('
|
||||
Kore::VrInterface::WarpSwap(parms.mPtr);
|
||||
')
|
||||
#end
|
||||
public override function WarpSwap(parms: TimeWarpParms): Void {
|
||||
return;
|
||||
}
|
||||
|
||||
// This returns the time that the TimeWarp thread uses
|
||||
// Since it is created from the library's vsync counting code, we should use this
|
||||
public override function GetTimeInSeconds(): Float {
|
||||
return System.time;
|
||||
}
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
}
|
||||
}
|
77
Kha/Backends/Kinc-hxcpp/kha/netsync/Network.hx
Normal file
77
Kha/Backends/Kinc-hxcpp/kha/netsync/Network.hx
Normal file
@ -0,0 +1,77 @@
|
||||
package kha.netsync;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
|
||||
@:headerCode("
|
||||
#include <kinc/network/socket.h>
|
||||
")
|
||||
@:headerClassCode("kinc_socket_t socket;")
|
||||
class Network {
|
||||
var url: String;
|
||||
var port: Int;
|
||||
var bufferPos: Int;
|
||||
var buffer: Bytes;
|
||||
var tempBuffer: Bytes;
|
||||
var listener: Bytes->Void;
|
||||
|
||||
public function new(url: String, port: Int, errorCallback: Void->Void, closeCallback: Void->Void) {
|
||||
this.url = url;
|
||||
this.port = port + 1; // TODO: This is somewhat ugly, but necessary to maintain both websocket and UPD connections at the same time (see also Server.hx)
|
||||
bufferPos = 0;
|
||||
buffer = Bytes.alloc(256); // TODO: Size
|
||||
tempBuffer = Bytes.alloc(256); // TODO: Size
|
||||
init(url, port);
|
||||
kha.Scheduler.addFrameTask(update, 0);
|
||||
}
|
||||
|
||||
@:functionCode("
|
||||
kinc_socket_init(&socket);
|
||||
kinc_socket_options options;
|
||||
kinc_socket_options_set_defaults(&options);
|
||||
kinc_socket_set(&socket, \"127.0.0.1\", port, KINC_SOCKET_FAMILY_IP4, KINC_SOCKET_PROTOCOL_UDP);
|
||||
kinc_socket_open(&socket, &options);
|
||||
")
|
||||
public function init(url: String, port: Int) {
|
||||
send(Bytes.ofString("JOIN"), true); // TODO: Discuss, dependency with Server.hx
|
||||
}
|
||||
|
||||
@:functionCode("
|
||||
// TODO: mandatory
|
||||
kinc_socket_send_url(&socket, url, port, (const unsigned char*)bytes->b->getBase(), bytes->length);
|
||||
")
|
||||
public function send(bytes: Bytes, mandatory: Bool): Void {}
|
||||
|
||||
public function listen(listener: Bytes->Void): Void {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
function update() {
|
||||
var received = getBytesFromSocket(tempBuffer);
|
||||
buffer.blit(bufferPos, tempBuffer, 0, received);
|
||||
bufferPos += received;
|
||||
// if (received > 0) trace("received " + received + " bytes");
|
||||
|
||||
// TODO: Handle partial packets, don't choke on garbage
|
||||
if (listener != null && bufferPos > 0) {
|
||||
var result = Bytes.alloc(bufferPos);
|
||||
result.blit(0, buffer, 0, bufferPos);
|
||||
listener(result);
|
||||
bufferPos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@:functionCode("
|
||||
unsigned int recAddr;
|
||||
unsigned int recPort;
|
||||
int size = kinc_socket_receive(&socket, (unsigned char*)inBuffer->b->getBase(), inBuffer->length, &recAddr, &recPort);
|
||||
if (size >= 0) {
|
||||
return size;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
")
|
||||
function getBytesFromSocket(inBuffer: Bytes): Int {
|
||||
return 0;
|
||||
}
|
||||
}
|
45
Kha/Backends/Kinc-hxcpp/kha/network/Http.hx
Normal file
45
Kha/Backends/Kinc-hxcpp/kha/network/Http.hx
Normal file
@ -0,0 +1,45 @@
|
||||
package kha.network;
|
||||
|
||||
@:headerCode("
|
||||
#include <kinc/network/http.h>
|
||||
")
|
||||
@:headerClassCode("
|
||||
static void internalCallback(int error, int response, const char* body, void* data) {
|
||||
int callbackindex = (int)(intptr_t)data;
|
||||
if (error == 0) {
|
||||
size_t length = strlen(body);
|
||||
HX_CHAR* chars = hx::NewString(length);
|
||||
for (int i = 0; i < length; ++i) {
|
||||
chars[i] = body[i];
|
||||
}
|
||||
internalCallback2(error, response, String(chars, length), callbackindex);
|
||||
}
|
||||
else {
|
||||
internalCallback2(error, response, null(), callbackindex);
|
||||
}
|
||||
}
|
||||
")
|
||||
class Http {
|
||||
static var callbacks: Array<Int->Int->String->Void>;
|
||||
|
||||
@:functionCode("kinc_http_request(url, path, data, port, secure, method, header, internalCallback, (void*)callbackindex);")
|
||||
static function request2(url: String, path: String, data: String, port: Int, secure: Bool, method: Int, header: String, callbackindex: Int): Void {}
|
||||
|
||||
static function internalCallback2(error: Int, response: Int, body: String, callbackindex: Int): Void {
|
||||
callbacks[callbackindex](error, response, body);
|
||||
}
|
||||
|
||||
public static function request(url: String, path: String, data: String, port: Int, secure: Bool, method: HttpMethod, headers: Map<String, String>,
|
||||
callback: Int->Int->String->Void /*error, response, body*/): Void {
|
||||
if (callbacks == null) {
|
||||
callbacks = new Array<Int->Int->String->Void>();
|
||||
}
|
||||
var index = callbacks.length;
|
||||
callbacks.push(callback);
|
||||
var header = "";
|
||||
for (key in headers.keys()) {
|
||||
header += key + ": " + headers[key] + "\r\n";
|
||||
}
|
||||
request2(url, path, data, port, secure, method, header, index);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user