I need a way to know when the texture has been completely uploaded to the GPU so that I can run a callback function.
My question is essentially: How do I know when the create3DFromRaw function has finished transferring information to the GPU?
Thanks
publicAPI.create3DFromRaw = (
width,
height,
depth,
numComps,
dataType,
data
) => {
// Permit OpenGLDataType to be half float, if applicable, for 3D
publicAPI.getOpenGLDataType(dataType);
// Now determine the texture parameters using the arguments.
publicAPI.getInternalFormat(dataType, numComps);
publicAPI.getFormat(dataType, numComps);
if (!model.internalFormat || !model.format || !model.openGLDataType) {
vtkErrorMacro('Failed to determine texture parameters.');
return false;
}
model.target = model.context.TEXTURE_3D;
model.components = numComps;
model.width = width;
model.height = height;
model.depth = depth;
model.numberOfDimensions = 3;
model._openGLRenderWindow.activateTexture(publicAPI);
publicAPI.createTexture();
publicAPI.bind();
// Create an array of texture with one texture
const dataArray = [data];
const is3DArray = true;
const pixData = updateArrayDataType(dataType, dataArray, is3DArray);
const scaledData = scaleTextureToHighestPowerOfTwo(pixData);
// Source texture data from the PBO.
// model.context.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
model.context.pixelStorei(model.context.UNPACK_ALIGNMENT, 1);
// openGLDataType
if (useTexStorage(dataType)) {
model.context.texStorage3D(
model.target,
1,
model.internalFormat,
model.width,
model.height,
model.depth
);
if (scaledData[0] != null) {
model.context.texSubImage3D(
model.target,
0,
0,
0,
0,
model.width,
model.height,
model.depth,
model.format,
model.openGLDataType,
scaledData[0]
);
}
} else {
model.context.texImage3D(
model.target,
0,
model.internalFormat,
model.width,
model.height,
model.depth,
0,
model.format,
model.openGLDataType,
scaledData[0]
);
}
if (model.generateMipmap) {
model.context.generateMipmap(model.target);
}
model.allocatedGPUMemoryInBytes =
model.width *
model.height *
model.depth *
model.components *
model._openGLRenderWindow.getDefaultTextureByteSize(
dataType,
model.oglNorm16Ext,
model.useHalfFloat
);
publicAPI.deactivate();
return true;
};