Update Files

This commit is contained in:
2025-01-22 16:18:30 +01:00
parent ed4603cf95
commit a36294b518
16718 changed files with 2960346 additions and 0 deletions

View 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;
}
}

View 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);
}
}

View 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);
}
}

View 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;
}
}

View 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;
}
}

View 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 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);
}
}

View 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 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);
}
}

View 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;
}
}

View 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);
}
}