Skip to main content
New Participant
Mar 13, 2025 8:24 PM UTC
Solved

How to update contents of SceneTexture in SpatialSDK?

I'm working with a SceneTexture instance passed to a shader for rendering in this fashion:

    val videoTexture = SceneTexture(Color.valueOf(0f, 0f, 1f, 1f))
    videoMaterial = SceneMaterial.custom("myShader", arrayOf(
      SceneMaterialAttribute("videoTexture", SceneMaterialDataType.Texture2D)
    )).apply {
      setTexture("videoTexture", videoTexture)
    }
Is there any way to update the videoTexture without creating a new SceneTexture instance? I've tried the following:
frame?.copyPixelsToBuffer(copyBuffer!!)
videoTexture.update(copyBuffer!!, frame!!.width, frame.height, 4)
videoMaterial!!.setTexture("videoTexture", videoTexture)

where frame is a Bitmap with a per pixel byte count of 4 (format ARGB_8888). It results in no visible changes to the texture, even if copyBuffer is empty. It's hard to tell if this is the correct usage or if this update function even does anything at all considering the the lack of information on the official documentation. I've also tried looking through the official samples, but found no mentions of this function. 

    This topic has been closed for replies.
    New Participant
    Mar 14, 2025 2:28 AM UTC

    Figured it out.

    Turns out the strideInBytes parameter refers the number of bytes between rows in a bitmap, so the correct version would look like this:

    videoTexture?.update(copyBuffer!!, frame.width, frame.height, frame.rowBytes)

     

    1 reply

    PointyLlama5273AuthorAnswer
    New Participant
    Mar 14, 2025 2:28 AM UTC

    Figured it out.

    Turns out the strideInBytes parameter refers the number of bytes between rows in a bitmap, so the correct version would look like this:

    videoTexture?.update(copyBuffer!!, frame.width, frame.height, frame.rowBytes)