Jump to content

Doubt about the buffer in Texture Constructor


JCPalmer
 Share

Recommended Posts

I am expanding my read ahead to include textures in addition to .js files with in-line geometry.  It is going to split the fetch of the file from the creation of the texture.  When a TOB generated .js file is dynamically loaded, it will call a function matReadAhead() in the file.  It will create a QI.TextureBuffer's for each texture.  When the scene asks for the materials, the applyWhenReady() will be called.  Hopefully, the fetch of the image file has already been performed when the .js was being fetched in advance as well.

Once the fetch is complete, I will be executing a BABYLON.Texture constructor() passing the buffer QI.TextureBuffer got. Texture passes the buffer to Engine.createTexture(), but it looks like it is only actually used when fromData is an Array.  Isn't this test wrong?

Link to comment
Share on other sites

Looking further, I see the static in Texture, LoadFromString

Seems like I could just add a "data:" on my url like it does.  Then fromData would be a 'true'.  fromData would still not be an Array though.  For un-compressed textures, I think the test just needs to be changed to:

if (!(buffer instanceof Array)) {
      do load file
}else {
    callback(buffer);
}

For images calling looks like it the buffer never gets called, so LoadFromString should not work.  I was also not actually passing an Array. I have already called LoadImage, so I am passing a HTMLImageElement.  Maybe the tests should be:

if (!buffer)
    Tools.LoadImage(url, onload, onerror, scene.database);
else if (buffer instanceof Array)
    Tools.LoadImage(buffer, onload, onerror, scene.database); // using LoadDataFromString
else
    callback(buffer); // passing a HTMLImageElement from previous Tools.LoadImage

 

Link to comment
Share on other sites

I have moved beyond whether this is a bug.  I am going to do a PR in this area anyway to:

  • remove ATC as a compressed texture format
  • depreciate .DDS in favor of DXT inside of a .KTX
  • have a more flexible default internal format where extensions of '.jpg' can be RGB instead of RGBA to save GPU memory

I will also expand buffer parameter to be either an arraybuffer or HTMLImageElement.  The whole beginning of this function will be refactored to clean up & make more clear.  Here is the documentation.  Is this right?

/**
 * Usually called from BABYLON.Texture.ts.  Passed information to create a WebGLTexture.
 * @param {string} urlArg- This contains one of the following:
 *                         1. A conventional http URL, e.g. 'http://...' or 'file://...'
 *                         2. A base64 string of in-line texture data, e.g. 'data:image/jpg;base64,/ ... //Z'
 *                         3. A indicator that data being passed using the buffer parameter, e.g. 'data:mytexture.jpg'
 *
 * @param {boolean} noMipmap- When true, no mipmaps shall be generated.  Ignored for compressed textures.  They must be in the file.
 * @param {boolean} invertY- When true, image is flipped when loaded.  You probably want true. Ignored for compressed textures.  Must be flipped in the file.
 * @param {Scene} scene- Needed for loading to the correct scene.
 * @param {number} samplingMode- Mode with should be used sample / access the texture.  Default: TRILINEAR
 * @param {callback} onLoad- Optional callback to be called upon successful completion.
 * @param {callback} onError- Optional callback to be called upon failure.
 * @param {ArrayBuffer | HTMLImageElement} buffer- A source of a file previously fetched as either an ArrayBuffer (compressed or image format) or HTMLImageElement (image format)
 * @param {WebGLTexture} fallback- An internal argument in case the function must be called again, due to etc1 not having alpha capabilities.
 * @param {number} format-  Internal format.  Default: RGB when extension is '.jpg' else RGBA.  Ignored for compressed textures.
 */

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...