diff --git a/Sources/Krom.hx b/Sources/Krom.hx index 0ea1132b..9c73c6c0 100644 --- a/Sources/Krom.hx +++ b/Sources/Krom.hx @@ -194,7 +194,7 @@ extern class Krom { static function delayIdleSleep(): Void; static function raytraceSupported(): Bool; static function raytraceInit(shader: js.lib.ArrayBuffer, vb: Dynamic, ib: Dynamic, scale: Float): Void; - static function raytraceSetTextures(tex0: Dynamic, tex1: Dynamic, tex2: Dynamic, texenv: Dynamic, tex_sobol: Dynamic, tex_scramble: Dynamic, tex_rank: Dynamic): Void; + static function raytraceSetTextures(tex0: kha.Image, tex1: kha.Image, tex2: kha.Image, texenv: Dynamic, tex_sobol: Dynamic, tex_scramble: Dynamic, tex_rank: Dynamic): Void; static function raytraceDispatchRays(target: Dynamic, cb: js.lib.ArrayBuffer): Void; static function vrBegin(): Void; static function vrBeginRender(eye: Int): Void; diff --git a/Sources/main.cpp b/Sources/main.cpp index 490ca4ce..1583db86 100644 --- a/Sources/main.cpp +++ b/Sources/main.cpp @@ -3699,14 +3699,60 @@ namespace { void krom_raytrace_set_textures(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); - Local rtfield0 = Local::Cast(args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_g4_render_target_t *texpaint0 = (kinc_g4_render_target_t *)rtfield0->Value(); + kinc_g4_render_target_t *texpaint0; + kinc_g4_render_target_t *texpaint1; + kinc_g4_render_target_t *texpaint2; - Local rtfield1 = Local::Cast(args[1]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_g4_render_target_t *texpaint1 = (kinc_g4_render_target_t *)rtfield1->Value(); + Local texpaint0_image = args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked(); + Local texpaint0_tex = texpaint0_image->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "texture_").ToLocalChecked()).ToLocalChecked(); + Local texpaint0_rt = texpaint0_image->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "renderTarget_").ToLocalChecked()).ToLocalChecked(); - Local rtfield2 = Local::Cast(args[2]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_g4_render_target_t *texpaint2 = (kinc_g4_render_target_t *)rtfield2->Value(); + if (texpaint0_tex->IsObject()) { + #ifdef KORE_DIRECT3D12 + Local texfield = Local::Cast(texpaint0_tex->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); + kinc_g4_texture_t *texture = (kinc_g4_texture_t *)texfield->Value(); + texpaint0 = (kinc_g4_render_target_t *)malloc(sizeof(kinc_g4_render_target_t)); + texpaint0->impl._renderTarget.impl.srvDescriptorHeap = texture->impl._texture.impl.srvDescriptorHeap; + #endif + } + else { + Local rtfield = Local::Cast(texpaint0_rt->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); + texpaint0 = (kinc_g4_render_target_t *)rtfield->Value(); + } + + Local texpaint1_image = args[1]->ToObject(isolate->GetCurrentContext()).ToLocalChecked(); + Local texpaint1_tex = texpaint1_image->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "texture_").ToLocalChecked()).ToLocalChecked(); + Local texpaint1_rt = texpaint1_image->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "renderTarget_").ToLocalChecked()).ToLocalChecked(); + + if (texpaint1_tex->IsObject()) { + #ifdef KORE_DIRECT3D12 + Local texfield = Local::Cast(texpaint1_tex->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); + kinc_g4_texture_t *texture = (kinc_g4_texture_t *)texfield->Value(); + texpaint1 = (kinc_g4_render_target_t *)malloc(sizeof(kinc_g4_render_target_t)); + texpaint1->impl._renderTarget.impl.srvDescriptorHeap = texture->impl._texture.impl.srvDescriptorHeap; + #endif + } + else { + Local rtfield = Local::Cast(texpaint1_rt->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); + texpaint1 = (kinc_g4_render_target_t *)rtfield->Value(); + } + + Local texpaint2_image = args[2]->ToObject(isolate->GetCurrentContext()).ToLocalChecked(); + Local texpaint2_tex = texpaint2_image->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "texture_").ToLocalChecked()).ToLocalChecked(); + Local texpaint2_rt = texpaint2_image->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "renderTarget_").ToLocalChecked()).ToLocalChecked(); + + if (texpaint2_tex->IsObject()) { + #ifdef KORE_DIRECT3D12 + Local texfield = Local::Cast(texpaint2_tex->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); + kinc_g4_texture_t *texture = (kinc_g4_texture_t *)texfield->Value(); + texpaint2 = (kinc_g4_render_target_t *)malloc(sizeof(kinc_g4_render_target_t)); + texpaint2->impl._renderTarget.impl.srvDescriptorHeap = texture->impl._texture.impl.srvDescriptorHeap; + #endif + } + else { + Local rtfield = Local::Cast(texpaint2_rt->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); + texpaint2 = (kinc_g4_render_target_t *)rtfield->Value(); + } Local envfield = Local::Cast(args[3]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); kinc_g4_texture_t *texenv = (kinc_g4_texture_t *)envfield->Value(); @@ -3738,6 +3784,18 @@ namespace { } kinc_raytrace_set_textures(&texpaint0->impl._renderTarget, &texpaint1->impl._renderTarget, &texpaint2->impl._renderTarget, &texenv->impl._texture, &texsobol->impl._texture, &texscramble->impl._texture, &texrank->impl._texture); + + if (texpaint0_tex->IsObject()) { + free(texpaint0); + } + + if (texpaint1_tex->IsObject()) { + free(texpaint1); + } + + if (texpaint2_tex->IsObject()) { + free(texpaint2); + } } void krom_raytrace_dispatch_rays(const FunctionCallbackInfo &args) {