add setImage method to set texture image directly from buffer
This commit is contained in:
@@ -76,10 +76,22 @@ class FFITexture extends Texture {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future setImage(
|
Future setImage(int level, Uint8List buffer, int width, int height,
|
||||||
int level, Uint8List buffer, PixelDataFormat format, PixelDataType type) {
|
int channels, PixelDataFormat format, PixelDataType type) async {
|
||||||
// TODO: implement setImage
|
final success = Texture_setImage(
|
||||||
throw UnimplementedError();
|
_engine,
|
||||||
|
pointer,
|
||||||
|
level,
|
||||||
|
buffer.address,
|
||||||
|
buffer.lengthInBytes,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
channels,
|
||||||
|
format.index,
|
||||||
|
type.index);
|
||||||
|
if (!success) {
|
||||||
|
throw Exception("Failed to set image");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -192,6 +192,18 @@ enum TPixelDataType {
|
|||||||
};
|
};
|
||||||
|
|
||||||
EMSCRIPTEN_KEEPALIVE bool Texture_loadImage(TEngine *tEngine, TTexture *tTexture, TLinearImage *tImage, TPixelDataFormat bufferFormat, TPixelDataType pixelDataType);
|
EMSCRIPTEN_KEEPALIVE bool Texture_loadImage(TEngine *tEngine, TTexture *tTexture, TLinearImage *tImage, TPixelDataFormat bufferFormat, TPixelDataType pixelDataType);
|
||||||
|
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 bufferFormat,
|
||||||
|
uint32_t pixelDataType
|
||||||
|
);
|
||||||
EMSCRIPTEN_KEEPALIVE TLinearImage *Image_createEmpty(uint32_t width,uint32_t height,uint32_t channel);
|
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 TLinearImage *Image_decode(uint8_t* data, size_t length, const char* name = "image");
|
||||||
EMSCRIPTEN_KEEPALIVE float *Image_getBytes(TLinearImage *tLinearImage);
|
EMSCRIPTEN_KEEPALIVE float *Image_getBytes(TLinearImage *tLinearImage);
|
||||||
|
|||||||
@@ -105,6 +105,55 @@ namespace thermion
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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:
|
||||||
|
if(size != width * height * channels * sizeof(float)) {
|
||||||
|
Log("Size mismatch");
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
filament::Texture::PixelBufferDescriptor buffer(
|
||||||
|
data,
|
||||||
|
size,
|
||||||
|
bufferFormat,
|
||||||
|
pixelDataType);
|
||||||
|
|
||||||
|
texture->setImage(*engine, level, std::move(buffer));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
EMSCRIPTEN_KEEPALIVE TLinearImage *Image_createEmpty(uint32_t width,uint32_t height,uint32_t channel) {
|
EMSCRIPTEN_KEEPALIVE TLinearImage *Image_createEmpty(uint32_t width,uint32_t height,uint32_t channel) {
|
||||||
auto *image = new ::image::LinearImage(width, height, channel);
|
auto *image = new ::image::LinearImage(width, height, channel);
|
||||||
|
|||||||
Reference in New Issue
Block a user