merge native setImage with setImageWithDepth
This commit is contained in:
@@ -532,62 +532,6 @@ namespace thermion
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE bool Texture_setImage(
|
||||
TEngine *tEngine,
|
||||
TTexture *tTexture,
|
||||
uint32_t level,
|
||||
uint8_t *data,
|
||||
size_t size,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t channels,
|
||||
uint32_t tBufferFormat,
|
||||
uint32_t tPixelDataType)
|
||||
{
|
||||
auto engine = reinterpret_cast<filament::Engine *>(tEngine);
|
||||
|
||||
auto texture = reinterpret_cast<filament::Texture *>(tTexture);
|
||||
auto bufferFormat = static_cast<PixelBufferDescriptor::PixelDataFormat>(tBufferFormat);
|
||||
auto pixelDataType = static_cast<PixelBufferDescriptor::PixelDataType>(tPixelDataType);
|
||||
|
||||
switch (bufferFormat)
|
||||
{
|
||||
case PixelBufferDescriptor::PixelDataFormat::RGB:
|
||||
case PixelBufferDescriptor::PixelDataFormat::RGBA:
|
||||
case PixelBufferDescriptor::PixelDataFormat::RGB_INTEGER:
|
||||
case PixelBufferDescriptor::PixelDataFormat::RGBA_INTEGER:
|
||||
break;
|
||||
default:
|
||||
Log("Unsupported buffer format type : %d", bufferFormat);
|
||||
return false;
|
||||
}
|
||||
|
||||
// the texture upload is async, so we need to copy the buffer
|
||||
auto *buffer = new std::vector<uint8_t>(size);
|
||||
std::copy(data, data + size, buffer->begin());
|
||||
|
||||
filament::Texture::PixelBufferDescriptor::Callback freeCallback = [](void *buf, size_t,
|
||||
void *data)
|
||||
{
|
||||
delete reinterpret_cast<std::vector<uint8_t> *>(data);
|
||||
};
|
||||
|
||||
filament::Texture::PixelBufferDescriptor pbd(
|
||||
buffer->data(),
|
||||
size,
|
||||
bufferFormat,
|
||||
pixelDataType,
|
||||
1, // alignment
|
||||
0, // left
|
||||
0, // top
|
||||
0, // stride
|
||||
freeCallback,
|
||||
buffer);
|
||||
|
||||
texture->setImage(*engine, level, std::move(pbd));
|
||||
return true;
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE bool Texture_setImageWithDepth(
|
||||
TEngine *tEngine,
|
||||
TTexture *tTexture,
|
||||
uint32_t level,
|
||||
@@ -598,7 +542,6 @@ namespace thermion
|
||||
uint32_t z_offset,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t channels,
|
||||
uint32_t depth,
|
||||
uint32_t tBufferFormat,
|
||||
uint32_t tPixelDataType)
|
||||
@@ -608,34 +551,18 @@ namespace thermion
|
||||
auto texture = reinterpret_cast<filament::Texture *>(tTexture);
|
||||
auto bufferFormat = static_cast<PixelBufferDescriptor::PixelDataFormat>(tBufferFormat);
|
||||
auto pixelDataType = static_cast<PixelBufferDescriptor::PixelDataType>(tPixelDataType);
|
||||
TRACE("Setting texture image (depth %d, %dx%dx%d (%d bytes, z_offset %d)", depth, width, height, channels, size, z_offset);
|
||||
TRACE("Setting texture image for level %d, offset %dx%dx%d, depth %d", level, x_offset, y_offset, z_offset, depth);
|
||||
|
||||
switch (bufferFormat)
|
||||
{
|
||||
case PixelBufferDescriptor::PixelDataFormat::RGB:
|
||||
case PixelBufferDescriptor::PixelDataFormat::RGBA:
|
||||
{
|
||||
size_t expectedSize = width * height * channels * sizeof(float);
|
||||
if (size != expectedSize)
|
||||
{
|
||||
Log("Size mismatch (expected %lu, got %lu)", expectedSize, size);
|
||||
case PixelBufferDescriptor::PixelDataFormat::RGB:
|
||||
case PixelBufferDescriptor::PixelDataFormat::RGBA:
|
||||
case PixelBufferDescriptor::PixelDataFormat::RGB_INTEGER:
|
||||
case PixelBufferDescriptor::PixelDataFormat::RGBA_INTEGER:
|
||||
break;
|
||||
default:
|
||||
Log("Unsupported buffer format type : %d", bufferFormat);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PixelBufferDescriptor::PixelDataFormat::RGB_INTEGER:
|
||||
case PixelBufferDescriptor::PixelDataFormat::RGBA_INTEGER:
|
||||
{
|
||||
if (size != width * height * channels * sizeof(uint8_t))
|
||||
{
|
||||
Log("Size mismatch");
|
||||
// return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
Log("Unsupported buffer format type : %d", bufferFormat);
|
||||
return false;
|
||||
}
|
||||
|
||||
// the texture upload is async, so we need to copy the buffer
|
||||
|
||||
@@ -937,29 +937,6 @@ extern "C"
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void Texture_setImageRenderThread(
|
||||
TEngine *tEngine,
|
||||
TTexture *tTexture,
|
||||
uint32_t level,
|
||||
uint8_t *data,
|
||||
size_t size,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t channels,
|
||||
uint32_t bufferFormat,
|
||||
uint32_t pixelDataType,
|
||||
void (*onComplete)(bool))
|
||||
{
|
||||
std::packaged_task<void()> lambda(
|
||||
[=]() mutable
|
||||
{
|
||||
bool result = Texture_setImage(tEngine, tTexture, level, data, size, width, height, channels,
|
||||
bufferFormat, pixelDataType);
|
||||
PROXY(onComplete(result));
|
||||
});
|
||||
auto fut = _renderThread->add_task(lambda);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void Texture_setImageWithDepthRenderThread(
|
||||
TEngine *tEngine,
|
||||
TTexture *tTexture,
|
||||
uint32_t level,
|
||||
@@ -970,7 +947,6 @@ extern "C"
|
||||
uint32_t z_offset,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t channels,
|
||||
uint32_t depth,
|
||||
uint32_t bufferFormat,
|
||||
uint32_t pixelDataType,
|
||||
@@ -979,7 +955,7 @@ extern "C"
|
||||
std::packaged_task<void()> lambda(
|
||||
[=]() mutable
|
||||
{
|
||||
bool result = Texture_setImageWithDepth(
|
||||
bool result = Texture_setImage(
|
||||
tEngine,
|
||||
tTexture,
|
||||
level,
|
||||
@@ -990,7 +966,6 @@ extern "C"
|
||||
z_offset,
|
||||
width,
|
||||
height,
|
||||
channels,
|
||||
depth,
|
||||
bufferFormat,
|
||||
pixelDataType);
|
||||
|
||||
Reference in New Issue
Block a user