forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
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() {}
|
||||
}
|
Reference in New Issue
Block a user