Forum Discussion

PointyLlama5273's avatar
4 months ago
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. 

  • 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

  • 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)