diff --git a/thermion_dart/native/include/c_api/TTexture.h b/thermion_dart/native/include/c_api/TTexture.h index ae74f1ef..a959e4b8 100644 --- a/thermion_dart/native/include/c_api/TTexture.h +++ b/thermion_dart/native/include/c_api/TTexture.h @@ -221,6 +221,10 @@ EMSCRIPTEN_KEEPALIVE bool Texture_setImageWithDepth( uint32_t bufferFormat, uint32_t pixelDataType ); +EMSCRIPTEN_KEEPALIVE uint32_t Texture_getWidth(TTexture *tTexture, uint32_t level); +EMSCRIPTEN_KEEPALIVE uint32_t Texture_getHeight(TTexture *tTexture, uint32_t level); +EMSCRIPTEN_KEEPALIVE uint32_t Texture_getDepth(TTexture *tTexture, uint32_t level); + EMSCRIPTEN_KEEPALIVE TLinearImage *Image_createEmpty(uint32_t width,uint32_t height,uint32_t channel); EMSCRIPTEN_KEEPALIVE TLinearImage *Image_decode(uint8_t* data, size_t length, const char* name = "image"); EMSCRIPTEN_KEEPALIVE float *Image_getBytes(TLinearImage *tLinearImage); @@ -229,6 +233,7 @@ EMSCRIPTEN_KEEPALIVE uint32_t Image_getWidth(TLinearImage *tLinearImage); EMSCRIPTEN_KEEPALIVE uint32_t Image_getHeight(TLinearImage *tLinearImage); EMSCRIPTEN_KEEPALIVE uint32_t Image_getChannels(TLinearImage *tLinearImage); EMSCRIPTEN_KEEPALIVE TTexture *RenderTarget_getColorTexture(TRenderTarget *tRenderTarget); +EMSCRIPTEN_KEEPALIVE TTexture *RenderTarget_getDepthTexture(TRenderTarget *tRenderTarget); // Texture Sampler related enums enum TSamplerWrapMode { diff --git a/thermion_dart/native/src/c_api/TTexture.cpp b/thermion_dart/native/src/c_api/TTexture.cpp index 13ad1670..9a8047b6 100644 --- a/thermion_dart/native/src/c_api/TTexture.cpp +++ b/thermion_dart/native/src/c_api/TTexture.cpp @@ -127,12 +127,15 @@ namespace thermion { case PixelBufferDescriptor::PixelDataFormat::RGB: case PixelBufferDescriptor::PixelDataFormat::RGBA: - if (size != width * height * channels * sizeof(float)) + { + size_t expectedSize = width * height * channels * sizeof(float); + if (size != expectedSize) { - Log("Size mismatch"); + Log("Size mismatch (expected %d, got %d)", expectedSize, size); return false; } break; + } case PixelBufferDescriptor::PixelDataFormat::RGB_INTEGER: case PixelBufferDescriptor::PixelDataFormat::RGBA_INTEGER: if (size != width * height * channels * sizeof(uint8_t)) @@ -260,6 +263,21 @@ namespace thermion return true; } + EMSCRIPTEN_KEEPALIVE uint32_t Texture_getWidth(TTexture *tTexture, uint32_t level) { + auto *texture = reinterpret_cast(tTexture); + return texture->getWidth(); + } + + EMSCRIPTEN_KEEPALIVE uint32_t Texture_getHeight(TTexture *tTexture, uint32_t level) { + auto *texture = reinterpret_cast(tTexture); + return texture->getHeight(); + } + + EMSCRIPTEN_KEEPALIVE uint32_t Texture_getDepth(TTexture *tTexture, uint32_t level) { + auto *texture = reinterpret_cast(tTexture); + return texture->getDepth(); + } + EMSCRIPTEN_KEEPALIVE TLinearImage *Image_createEmpty(uint32_t width, uint32_t height, uint32_t channel) { auto *image = new ::image::LinearImage(width, height, channel); @@ -268,7 +286,7 @@ namespace thermion EMSCRIPTEN_KEEPALIVE TTextureSampler *TextureSampler_create() { - auto *sampler = new filament::TextureSampler(); + auto *sampler = new filament::TextureSampler(filament::TextureSampler::CompareMode::COMPARE_TO_TEXTURE); return reinterpret_cast(sampler); } @@ -295,8 +313,19 @@ namespace thermion TSamplerCompareFunc compareFunc) { - filament::TextureSampler::CompareMode mode = static_cast(compareMode); - filament::TextureSampler::CompareFunc func = static_cast(compareFunc); + if(compareMode == COMPARE_MODE_NONE) { + TRACE("COMPARE MODE NONE"); + } else if(compareMode == COMPARE_MODE_COMPARE_TO_TEXTURE) { + TRACE("COMPARE MODE COMPARE TO TEXTURE"); + } else { + TRACE("UNKNWON COMPARE MODE"); + } + + + filament::TextureSampler::CompareMode mode = static_cast(static_cast(compareMode)); + filament::TextureSampler::CompareFunc func = static_cast(static_cast(compareFunc)); + + TRACE("Creating texture sampler with compare mode %d and compare func %d"); auto *sampler = new filament::TextureSampler(mode, func); return reinterpret_cast(sampler); @@ -401,6 +430,13 @@ namespace thermion return reinterpret_cast(texture); } + EMSCRIPTEN_KEEPALIVE TTexture *RenderTarget_getDepthTexture(TRenderTarget *tRenderTarget) + { + auto renderTarget = reinterpret_cast(tRenderTarget); + auto texture = renderTarget->getTexture(filament::RenderTarget::AttachmentPoint::DEPTH); + return reinterpret_cast(texture); + } + #ifdef __cplusplus } }