Skip to content

Commit 59fb322

Browse files
sedghifinetjul
authored andcommitted
refactor(OpenGLTexture): expose update array for opengl in texture
1 parent 5820f97 commit 59fb322

File tree

1 file changed

+25
-9
lines changed
  • Sources/Rendering/OpenGL/Texture

1 file changed

+25
-9
lines changed

Sources/Rendering/OpenGL/Texture/index.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -612,10 +612,19 @@ function vtkOpenGLTexture(publicAPI, model) {
612612
}
613613
};
614614

615-
//----------------------------------------------------------------------------
616-
function updateArrayDataType(dataType, data, depth = false) {
615+
/**
616+
* Updates the data array to match the required data type for OpenGL.
617+
*
618+
* This function takes the input data and converts it to the appropriate
619+
* format required by the OpenGL texture, based on the specified data type.
620+
*
621+
* @param {string} dataType - The original data type of the input data.
622+
* @param {Array} data - The input data array that needs to be updated.
623+
* @param {boolean} [depth=false] - Indicates whether the data is a 3D array.
624+
* @returns {Array} The updated data array that matches the OpenGL data type.
625+
*/
626+
publicAPI.updateArrayDataTypeForGL = (dataType, data, depth = false) => {
617627
const pixData = [];
618-
619628
let pixCount = model.width * model.height * model.components;
620629
if (depth) {
621630
pixCount *= model.depth;
@@ -693,7 +702,7 @@ function vtkOpenGLTexture(publicAPI, model) {
693702
}
694703

695704
return pixData;
696-
}
705+
};
697706

698707
//----------------------------------------------------------------------------
699708
function scaleTextureToHighestPowerOfTwo(data) {
@@ -856,7 +865,7 @@ function vtkOpenGLTexture(publicAPI, model) {
856865

857866
// Create an array of texture with one texture
858867
const dataArray = [data];
859-
const pixData = updateArrayDataType(dataType, dataArray);
868+
const pixData = publicAPI.updateArrayDataTypeForGL(dataType, dataArray);
860869
const scaledData = scaleTextureToHighestPowerOfTwo(pixData);
861870

862871
// Source texture data from the PBO.
@@ -944,7 +953,7 @@ function vtkOpenGLTexture(publicAPI, model) {
944953
publicAPI.createTexture();
945954
publicAPI.bind();
946955

947-
const pixData = updateArrayDataType(dataType, data);
956+
const pixData = publicAPI.updateArrayDataTypeForGL(dataType, data);
948957
const scaledData = scaleTextureToHighestPowerOfTwo(pixData);
949958

950959
// invert the data because opengl is messed up with cube maps
@@ -1364,7 +1373,7 @@ function vtkOpenGLTexture(publicAPI, model) {
13641373
publicAPI.create2DFromRaw(width, height, numComps, dataType, data);
13651374
};
13661375

1367-
publicAPI.updateVolumeScaleForOpenGL = (dataType, numComps) => {
1376+
publicAPI.updateVolumeInfoForGL = (dataType, numComps) => {
13681377
let isScalingApplied = false;
13691378

13701379
// Initialize volume info if it doesn't exist
@@ -1438,7 +1447,10 @@ function vtkOpenGLTexture(publicAPI, model) {
14381447
let dataTypeToUse = dataType;
14391448
let dataToUse = data;
14401449

1441-
if (!publicAPI.updateVolumeScaleForOpenGL(dataTypeToUse, numComps)) {
1450+
if (
1451+
!publicAPI.updateVolumeInfoForGL(dataTypeToUse, numComps) &&
1452+
dataToUse
1453+
) {
14421454
const numPixelsIn = width * height * depth;
14431455
const scaleOffsetsCopy = structuredClone(model.volumeInfo);
14441456
// otherwise convert to float
@@ -1484,7 +1496,11 @@ function vtkOpenGLTexture(publicAPI, model) {
14841496
// Create an array of texture with one texture
14851497
const dataArray = [dataToUse];
14861498
const is3DArray = true;
1487-
const pixData = updateArrayDataType(dataTypeToUse, dataArray, is3DArray);
1499+
const pixData = publicAPI.updateArrayDataTypeForGL(
1500+
dataTypeToUse,
1501+
dataArray,
1502+
is3DArray
1503+
);
14881504
const scaledData = scaleTextureToHighestPowerOfTwo(pixData);
14891505

14901506
// Source texture data from the PBO.

0 commit comments

Comments
 (0)