From 6110809d23ffef845d5070576f8ddfac719706af Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Fri, 25 Jan 2019 17:04:05 -0800 Subject: [PATCH] JNI fix for badly-sized PixelBufferDescriptors. (!) Amazingly, the size field in PixelBufferDescriptor was often totally incorrect for Java-based clients. The reason we did not notice: OpenGL often consumes a pointer to image data without consuming a byte count (e.g. glTexImage2D). OpenGL infers size from dimensions + format, but Vulkan does not. This caused texture corruption with Vulkan on Android. This fix follows a pattern used in other places such as FRenderer::readPixels. --- android/filament-android/src/main/cpp/Texture.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/android/filament-android/src/main/cpp/Texture.cpp b/android/filament-android/src/main/cpp/Texture.cpp index 969a8b5bb4..65c8d4b7e5 100644 --- a/android/filament-android/src/main/cpp/Texture.cpp +++ b/android/filament-android/src/main/cpp/Texture.cpp @@ -36,8 +36,10 @@ using namespace driver; static size_t getTextureDataSize(const Texture *texture, size_t level, Texture::Format format, Texture::Type type, size_t stride, size_t alignment) { + // Zero stride implies tight row-to-row packing. + stride = stride == 0 ? texture->getWidth(level) : std::max(size_t(1), stride >> level); return Texture::computeTextureDataSize(format, type, - std::max(size_t(1), stride >> level), texture->getHeight(level), alignment); + stride, texture->getHeight(level), alignment); } extern "C" JNIEXPORT jboolean JNICALL