Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/pointer object #2

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5,394 changes: 5,394 additions & 0 deletions api/cmd.ts

Large diffs are not rendered by default.

2,107 changes: 2,107 additions & 0 deletions api/constant.ts

Large diffs are not rendered by default.

531 changes: 531 additions & 0 deletions api/def.ts

Large diffs are not rendered by default.

4,481 changes: 4,481 additions & 0 deletions api/enum.ts

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions api/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from "./constant.ts";
export * from "./enum.ts";
export * from "./def.ts";
export * from "./struct/common.ts";
export * from "./union.ts";
export * from "./cmd.ts";
export * from "./util.ts";
109 changes: 109 additions & 0 deletions api/struct/AabbPositionsKHR.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// deno-lint-ignore-file no-unused-vars
import {
AnyBuffer,
AnyPointer,
anyBuffer,
anyPointer,
BUFFER,
DATAVIEW,
LE,
BaseStruct,
pointerFromView,
notPointerObject,
} from "../util.ts";

export interface InitAabbPositionsKHR {
minX?: number;
minY?: number;
minZ?: number;
maxX?: number;
maxY?: number;
maxZ?: number;
}

export class AabbPositionsKHR implements BaseStruct {
static size = 24;

#data!: Uint8Array;
#view!: DataView;

get [BUFFER]() { return this.#data; }
get [DATAVIEW]() { return this.#view; }

constructor();
constructor(ptr: Deno.PointerValue);
constructor(init: InitAabbPositionsKHR);
constructor(data: Uint8Array);
constructor(data?: Deno.PointerValue | Uint8Array | InitAabbPositionsKHR) {
if (data === undefined || data === null) {
this.#data = new Uint8Array(AabbPositionsKHR.size);
this.#view = new DataView(this.#data.buffer, this.#data.byteOffset);
} else if (data instanceof Uint8Array) {
if (data.byteLength < AabbPositionsKHR.size) {
throw new Error("Data buffer too small");
}
this.#data = data;
this.#view = new DataView(data.buffer, data.byteOffset);
} else if(notPointerObject(data)) {
this.#data = new Uint8Array(AabbPositionsKHR.size);
this.#view = new DataView(this.#data.buffer, this.#data.byteOffset);
if (data.minX !== undefined) this.minX = data.minX;
if (data.minY !== undefined) this.minY = data.minY;
if (data.minZ !== undefined) this.minZ = data.minZ;
if (data.maxX !== undefined) this.maxX = data.maxX;
if (data.maxY !== undefined) this.maxY = data.maxY;
if (data.maxZ !== undefined) this.maxZ = data.maxZ;
} else {
this.#data = new Uint8Array(Deno.UnsafePointerView.getArrayBuffer(data, AabbPositionsKHR.size));
this.#view = new DataView(this.#data.buffer, this.#data.byteOffset);
}
}

get minX(): number {
return this.#view.getFloat32(0, LE);
}

set minX(value: number) {
this.#view.setFloat32(0, Number(value), LE);
}

get minY(): number {
return this.#view.getFloat32(4, LE);
}

set minY(value: number) {
this.#view.setFloat32(4, Number(value), LE);
}

get minZ(): number {
return this.#view.getFloat32(8, LE);
}

set minZ(value: number) {
this.#view.setFloat32(8, Number(value), LE);
}

get maxX(): number {
return this.#view.getFloat32(12, LE);
}

set maxX(value: number) {
this.#view.setFloat32(12, Number(value), LE);
}

get maxY(): number {
return this.#view.getFloat32(16, LE);
}

set maxY(value: number) {
this.#view.setFloat32(16, Number(value), LE);
}

get maxZ(): number {
return this.#view.getFloat32(20, LE);
}

set maxZ(value: number) {
this.#view.setFloat32(20, Number(value), LE);
}
}
2 changes: 2 additions & 0 deletions api/struct/AabbPositionsNV.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { AabbPositionsKHR } from "./AabbPositionsKHR.ts";
export type AabbPositionsNV = AabbPositionsKHR;
162 changes: 162 additions & 0 deletions api/struct/AccelerationStructureBuildGeometryInfoKHR.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
// deno-lint-ignore-file no-unused-vars
import {
AnyBuffer,
AnyPointer,
anyBuffer,
anyPointer,
BUFFER,
DATAVIEW,
LE,
BaseStruct,
pointerFromView,
notPointerObject,
} from "../util.ts";
import {AccelerationStructureGeometryKHR} from "./AccelerationStructureGeometryKHR.ts";
import { StructureType, AccelerationStructureTypeKHR, BuildAccelerationStructureModeKHR } from "../enum.ts";
import { BuildAccelerationStructureFlagsKHR, AccelerationStructureKHR } from "../def.ts";
import { DeviceOrHostAddressKHR } from "../union.ts";

export interface InitAccelerationStructureBuildGeometryInfoKHR {
pNext?: AnyPointer;
type?: AccelerationStructureTypeKHR;
flags?: BuildAccelerationStructureFlagsKHR;
mode?: BuildAccelerationStructureModeKHR;
srcAccelerationStructure?: AccelerationStructureKHR;
dstAccelerationStructure?: AccelerationStructureKHR;
geometryCount?: number;
pGeometries?: AnyPointer;
ppGeometries?: AnyPointer;
scratchData?: DeviceOrHostAddressKHR;
}

export class AccelerationStructureBuildGeometryInfoKHR implements BaseStruct {
static size = 80;

#data!: Uint8Array;
#view!: DataView;

get [BUFFER]() { return this.#data; }
get [DATAVIEW]() { return this.#view; }

constructor();
constructor(ptr: Deno.PointerValue);
constructor(init: InitAccelerationStructureBuildGeometryInfoKHR);
constructor(data: Uint8Array);
constructor(data?: Deno.PointerValue | Uint8Array | InitAccelerationStructureBuildGeometryInfoKHR) {
if (data === undefined || data === null) {
this.#data = new Uint8Array(AccelerationStructureBuildGeometryInfoKHR.size);
this.#view = new DataView(this.#data.buffer, this.#data.byteOffset);
} else if (data instanceof Uint8Array) {
if (data.byteLength < AccelerationStructureBuildGeometryInfoKHR.size) {
throw new Error("Data buffer too small");
}
this.#data = data;
this.#view = new DataView(data.buffer, data.byteOffset);
} else if(notPointerObject(data)) {
this.#data = new Uint8Array(AccelerationStructureBuildGeometryInfoKHR.size);
this.#view = new DataView(this.#data.buffer, this.#data.byteOffset);
if (data.pNext !== undefined) this.pNext = data.pNext;
if (data.type !== undefined) this.type = data.type;
if (data.flags !== undefined) this.flags = data.flags;
if (data.mode !== undefined) this.mode = data.mode;
if (data.srcAccelerationStructure !== undefined) this.srcAccelerationStructure = data.srcAccelerationStructure;
if (data.dstAccelerationStructure !== undefined) this.dstAccelerationStructure = data.dstAccelerationStructure;
if (data.geometryCount !== undefined) this.geometryCount = data.geometryCount;
if (data.pGeometries !== undefined) this.pGeometries = data.pGeometries;
if (data.ppGeometries !== undefined) this.ppGeometries = data.ppGeometries;
if (data.scratchData !== undefined) this.scratchData = data.scratchData;
} else {
this.#data = new Uint8Array(Deno.UnsafePointerView.getArrayBuffer(data, AccelerationStructureBuildGeometryInfoKHR.size));
this.#view = new DataView(this.#data.buffer, this.#data.byteOffset);
}
this.sType = StructureType.ACCELERATION_STRUCTURE_BUILD_GEOMETRY_INFO_KHR;
}

get sType(): number {
return this.#view.getUint32(0, LE);
}

set sType(value: StructureType) {
this.#view.setUint32(0, Number(value), LE);
}

get pNext(): Deno.PointerValue {
return pointerFromView(this.#view, 8, LE);
}

set pNext(value: AnyPointer) {
this.#view.setBigUint64(8, BigInt(anyPointer(value)), LE);
}

get type(): number {
return this.#view.getUint32(16, LE);
}

set type(value: AccelerationStructureTypeKHR) {
this.#view.setUint32(16, Number(value), LE);
}

get flags(): number {
return this.#view.getUint32(20, LE);
}

set flags(value: BuildAccelerationStructureFlagsKHR) {
this.#view.setUint32(20, Number(value), LE);
}

get mode(): number {
return this.#view.getUint32(24, LE);
}

set mode(value: BuildAccelerationStructureModeKHR) {
this.#view.setUint32(24, Number(value), LE);
}

get srcAccelerationStructure(): Deno.PointerValue {
return pointerFromView(this.#view, 32, LE);
}

set srcAccelerationStructure(value: AccelerationStructureKHR) {
this.#view.setBigUint64(32, BigInt(anyPointer(value)), LE);
}

get dstAccelerationStructure(): Deno.PointerValue {
return pointerFromView(this.#view, 40, LE);
}

set dstAccelerationStructure(value: AccelerationStructureKHR) {
this.#view.setBigUint64(40, BigInt(anyPointer(value)), LE);
}

get geometryCount(): number {
return this.#view.getUint32(48, LE);
}

set geometryCount(value: number) {
this.#view.setUint32(48, Number(value), LE);
}

get pGeometries(): Deno.PointerValue {
return pointerFromView(this.#view, 56, LE);
}

set pGeometries(value: AnyPointer) {
this.#view.setBigUint64(56, BigInt(anyPointer(value)), LE);
}

get ppGeometries(): Deno.PointerValue {
return pointerFromView(this.#view, 64, LE);
}

set ppGeometries(value: AnyPointer) {
this.#view.setBigUint64(64, BigInt(anyPointer(value)), LE);
}

get scratchData(): unknown {
throw new Error(`Unknown type: {"union":["u64","buffer"]}`);
}

set scratchData(value: DeviceOrHostAddressKHR) {
throw new Error(`Unknown type: {"union":["u64","buffer"]}`);
}
}
89 changes: 89 additions & 0 deletions api/struct/AccelerationStructureBuildRangeInfoKHR.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// deno-lint-ignore-file no-unused-vars
import {
AnyBuffer,
AnyPointer,
anyBuffer,
anyPointer,
BUFFER,
DATAVIEW,
LE,
BaseStruct,
pointerFromView,
notPointerObject,
} from "../util.ts";

export interface InitAccelerationStructureBuildRangeInfoKHR {
primitiveCount?: number;
primitiveOffset?: number;
firstVertex?: number;
transformOffset?: number;
}

export class AccelerationStructureBuildRangeInfoKHR implements BaseStruct {
static size = 16;

#data!: Uint8Array;
#view!: DataView;

get [BUFFER]() { return this.#data; }
get [DATAVIEW]() { return this.#view; }

constructor();
constructor(ptr: Deno.PointerValue);
constructor(init: InitAccelerationStructureBuildRangeInfoKHR);
constructor(data: Uint8Array);
constructor(data?: Deno.PointerValue | Uint8Array | InitAccelerationStructureBuildRangeInfoKHR) {
if (data === undefined || data === null) {
this.#data = new Uint8Array(AccelerationStructureBuildRangeInfoKHR.size);
this.#view = new DataView(this.#data.buffer, this.#data.byteOffset);
} else if (data instanceof Uint8Array) {
if (data.byteLength < AccelerationStructureBuildRangeInfoKHR.size) {
throw new Error("Data buffer too small");
}
this.#data = data;
this.#view = new DataView(data.buffer, data.byteOffset);
} else if(notPointerObject(data)) {
this.#data = new Uint8Array(AccelerationStructureBuildRangeInfoKHR.size);
this.#view = new DataView(this.#data.buffer, this.#data.byteOffset);
if (data.primitiveCount !== undefined) this.primitiveCount = data.primitiveCount;
if (data.primitiveOffset !== undefined) this.primitiveOffset = data.primitiveOffset;
if (data.firstVertex !== undefined) this.firstVertex = data.firstVertex;
if (data.transformOffset !== undefined) this.transformOffset = data.transformOffset;
} else {
this.#data = new Uint8Array(Deno.UnsafePointerView.getArrayBuffer(data, AccelerationStructureBuildRangeInfoKHR.size));
this.#view = new DataView(this.#data.buffer, this.#data.byteOffset);
}
}

get primitiveCount(): number {
return this.#view.getUint32(0, LE);
}

set primitiveCount(value: number) {
this.#view.setUint32(0, Number(value), LE);
}

get primitiveOffset(): number {
return this.#view.getUint32(4, LE);
}

set primitiveOffset(value: number) {
this.#view.setUint32(4, Number(value), LE);
}

get firstVertex(): number {
return this.#view.getUint32(8, LE);
}

set firstVertex(value: number) {
this.#view.setUint32(8, Number(value), LE);
}

get transformOffset(): number {
return this.#view.getUint32(12, LE);
}

set transformOffset(value: number) {
this.#view.setUint32(12, Number(value), LE);
}
}
Loading