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,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

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

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

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

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

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

View 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

View 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

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

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

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