Skip to main content
New Participant
March 13, 2025
Solved

How to update contents of SceneTexture in SpatialSDK?

  • March 13, 2025
  • 1 reply
  • 525 views

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.
    Best answer by PointyLlama5273

    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
    March 14, 2025

    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)