rnc-archive / react-native-webgl

DEPRECATED: use expo-gl – Implements WebGL for react-native
296 stars 73 forks source link

iOS >= 100% cpu usage when textureLoad #61

Closed dominicrico closed 4 years ago

dominicrico commented 6 years ago

Hi there,

I'm building a panorama image viewer for iOS at the moment. My problem is that when I load an panorama image my cpu usage jumps from ~5% to over 100% and never drops down.

I'm using this to load the image and create the sphere:

import THREE from './three'

export const loadThreeJSTexture = async (gl, src, texture, renderer) => {
  var properties = renderer.properties.get(texture)
  await gl.getExtension('RN')
    .loadTexture({ yflip: false, image: src })
    .then(({ texture }) => {
      properties.__webglTexture = texture
      properties.__webglInit = true
      texture.needsUpdate = true
      gl.flush()
      gl.getExtension('RN').endFrame()
    })
}

export const loadTexture = async (gl, src, renderer) => {
  const texture = new THREE.Texture()
  const material = new THREE.MeshBasicMaterial({map: texture, overdraw: 0.5})
  await loadThreeJSTexture(gl, src, texture, renderer)
  return material
}

export const createSphere = async (gl, pano, renderer) => {
  const geometry = new THREE.SphereBufferGeometry(500, 60, 40)

  const material = await loadTexture(gl, pano, renderer)
  const mesh = new THREE.Mesh(geometry, material)

  mesh.rotation.z = Math.PI

  return mesh
}

any ideas why my cpu usage is so high? Thank you in advance!