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,119 @@
package kha.graphics4;
import haxe.io.Bytes;
class CubeMap implements Canvas implements Resource {
public var texture_: Dynamic;
public var renderTarget_: Dynamic;
var format: TextureFormat;
var graphics4: kha.graphics4.Graphics;
function new(texture: Dynamic) {
texture_ = texture;
}
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; // Grey8
}
}
public static function createRenderTarget(size: Int, format: TextureFormat = null, depthStencil: DepthStencilFormat = NoDepthAndStencil): CubeMap {
if (format == null)
format = TextureFormat.RGBA32;
var cubeMap = new CubeMap(null);
cubeMap.format = format;
cubeMap.renderTarget_ = Krom.createRenderTargetCubeMap(size, getRenderTargetFormat(format), getDepthBufferBits(depthStencil),
getStencilBufferBits(depthStencil));
return cubeMap;
}
public function unload(): Void {}
public function lock(level: Int = 0): Bytes {
return null;
}
public function unlock(): Void {}
public var width(get, never): Int;
function get_width(): Int {
return texture_ == null ? renderTarget_.width : texture_.width;
}
public var height(get, never): Int;
function get_height(): Int {
return texture_ == null ? renderTarget_.height : texture_.height;
}
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.krom.Graphics(this);
}
return graphics4;
}
}

View File

@ -0,0 +1,22 @@
package kha.graphics4;
class FragmentShader {
public var shader: Dynamic;
public function new(sources: Array<Blob>, names: Array<String>) {
if (sources != null) {
shader = Krom.createFragmentShader(sources[0].bytes.getData(), names[0]);
}
}
public static function fromSource(source: String): FragmentShader {
var shader = new FragmentShader(null, null);
shader.shader = Krom.createFragmentShaderFromSource(source);
return shader;
}
public function delete() {
Krom.deleteShader(shader);
shader = null;
}
}

View File

@ -0,0 +1,14 @@
package kha.graphics4;
class GeometryShader {
public var shader: Dynamic;
public function new(sources: Array<Blob>, names: Array<String>) {
shader = Krom.createGeometryShader(sources[0].bytes.getData(), names[0]);
}
public function delete() {
Krom.deleteShader(shader);
shader = null;
}
}

View File

@ -0,0 +1,42 @@
package kha.graphics4;
import kha.arrays.Uint32Array;
import kha.graphics4.Usage;
class IndexBuffer {
public var _data: Uint32Array;
var buffer: Dynamic;
var indexCount: Int;
public function new(indexCount: Int, usage: Usage, canRead: Bool = false) {
this.indexCount = indexCount;
buffer = Krom.createIndexBuffer(indexCount);
}
public function delete() {
Krom.deleteIndexBuffer(buffer);
buffer = null;
}
public function lock(?start: Int, ?count: Int): Uint32Array {
_data = Krom.lockIndexBuffer(buffer);
if (start == null)
start = 0;
if (count == null)
count = indexCount;
return _data.subarray(start, start + count);
}
public function unlock(?count: Int): Void {
Krom.unlockIndexBuffer(buffer);
}
public function set(): Void {
Krom.setIndexBuffer(buffer);
}
public function count(): Int {
return indexCount;
}
}

View File

@ -0,0 +1,95 @@
package kha.graphics4;
import kha.graphics4.FragmentShader;
import kha.graphics4.VertexData;
import kha.graphics4.VertexShader;
import kha.graphics4.VertexStructure;
class PipelineState extends PipelineStateBase {
var pipeline: Dynamic;
public function new() {
super();
pipeline = Krom.createPipeline();
}
public function delete() {
Krom.deletePipeline(pipeline);
pipeline = null;
}
public function compile(): Void {
var structure0 = inputLayout.length > 0 ? inputLayout[0] : null;
var structure1 = inputLayout.length > 1 ? inputLayout[1] : null;
var structure2 = inputLayout.length > 2 ? inputLayout[2] : null;
var structure3 = inputLayout.length > 3 ? inputLayout[3] : null;
var gs = geometryShader != null ? geometryShader.shader : null;
var tcs = tessellationControlShader != null ? tessellationControlShader.shader : null;
var tes = tessellationEvaluationShader != null ? tessellationEvaluationShader.shader : null;
var stencilReferenceValue = 0;
switch (this.stencilReferenceValue) {
case Static(value):
stencilReferenceValue = value;
default:
}
Krom.compilePipeline(pipeline, structure0, structure1, structure2, structure3, inputLayout.length, vertexShader.shader, fragmentShader.shader, gs,
tcs, tes, {
cullMode: cullMode,
depthWrite: this.depthWrite,
depthMode: depthMode,
stencilMode: stencilFrontMode,
stencilBothPass: stencilFrontBothPass,
stencilDepthFail: stencilFrontDepthFail,
stencilFail: stencilFrontFail,
stencilReferenceValue: stencilReferenceValue,
stencilReadMask: stencilReadMask,
stencilWriteMask: stencilWriteMask,
blendSource: convertBlendingFactor(blendSource),
blendDestination: convertBlendingFactor(blendDestination),
alphaBlendSource: convertBlendingFactor(alphaBlendSource),
alphaBlendDestination: convertBlendingFactor(alphaBlendDestination),
colorWriteMaskRed: colorWriteMasksRed,
colorWriteMaskGreen: colorWriteMasksGreen,
colorWriteMaskBlue: colorWriteMasksBlue,
colorWriteMaskAlpha: colorWriteMasksAlpha,
conservativeRasterization: conservativeRasterization
});
}
public function set(): Void {
Krom.setPipeline(pipeline);
}
public function getConstantLocation(name: String): kha.graphics4.ConstantLocation {
return Krom.getConstantLocation(pipeline, name);
}
public function getTextureUnit(name: String): kha.graphics4.TextureUnit {
return Krom.getTextureUnit(pipeline, name);
}
static function convertBlendingFactor(factor: BlendingFactor): Int {
switch (factor) {
case Undefined, BlendOne:
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;
}
}
}

View File

@ -0,0 +1,14 @@
package kha.graphics4;
class TessellationControlShader {
public var shader: Dynamic;
public function new(sources: Array<Blob>, names: Array<String>) {
shader = Krom.createTessellationControlShader(sources[0].bytes.getData(), names[0]);
}
public function delete() {
Krom.deleteShader(shader);
shader = null;
}
}

View File

@ -0,0 +1,14 @@
package kha.graphics4;
class TessellationEvaluationShader {
public var shader: Dynamic;
public function new(sources: Array<Blob>, names: Array<String>) {
shader = Krom.createTessellationEvaluationShader(sources[0].bytes.getData(), names[0]);
}
public function delete() {
Krom.deleteShader(shader);
shader = null;
}
}

View File

@ -0,0 +1,61 @@
package kha.graphics4;
import kha.arrays.Float32Array;
import kha.arrays.Int16Array;
import kha.graphics4.Usage;
import kha.graphics4.VertexStructure;
import kha.graphics4.VertexData;
class VertexBuffer {
public var buffer: Dynamic;
public var _data: Float32Array;
var vertexCount: Int;
var structure: VertexStructure;
var mySize: Int;
var lockStart: Int = 0;
var lockEnd: Int = 0;
public function new(vertexCount: Int, structure: VertexStructure, usage: Usage, instanceDataStepRate: Int = 0, canRead: Bool = false) {
this.vertexCount = vertexCount;
this.structure = structure;
mySize = vertexCount;
buffer = Krom.createVertexBuffer(vertexCount, structure.elements, usage, instanceDataStepRate);
}
public function delete() {
Krom.deleteVertexBuffer(buffer);
buffer = null;
}
public function lock(?start: Int, ?count: Int): Float32Array {
lockStart = start != null ? start : 0;
lockEnd = count != null ? start + count : mySize;
_data = new kha.arrays.ByteArray(Krom.lockVertexBuffer(buffer, lockStart, lockEnd));
return _data;
}
public function lockInt16(?start: Int, ?count: Int): Int16Array {
return new Int16Array(untyped lock(start, count).buffer);
}
public function unlock(?count: Int): Void {
if (count != null) {
lockEnd = lockStart + count;
}
Krom.unlockVertexBuffer(buffer, lockEnd);
}
public function stride(): Int {
return structure.byteSize();
}
public function count(): Int {
return vertexCount;
}
public function set(offset: Int): Int {
Krom.setVertexBuffer(buffer);
return 0;
}
}

View File

@ -0,0 +1,22 @@
package kha.graphics4;
class VertexShader {
public var shader: Dynamic;
public function new(sources: Array<Blob>, names: Array<String>) {
if (sources != null) {
shader = Krom.createVertexShader(sources[0].bytes.getData(), names[0]);
}
}
public static function fromSource(source: String): VertexShader {
var shader = new VertexShader(null, null);
shader.shader = Krom.createVertexShaderFromSource(source);
return shader;
}
public function delete() {
Krom.deleteShader(shader);
shader = null;
}
}