2016-03-25 36 views
0

我有一個關於GL_LUMINANCE與uint16數據的小問題。我有一些OpenGL的代碼,我想帶給WebGL的/ three.js所:DataTexture與LuminanceFormat UnsignedShort無法渲染

glTexImage2D(GL_TEXTURE_2D, 0, myColor, (ushort)width, 
      (ushort)height, 0, GL_LUMINANCE, GL_UNSIGNED_SHORT, imageData); 

當運行這個基本示例代碼我得到的錯誤

texture bound to texture unit 0 is not renderable. 
It maybe non-power-of-2 and have incompatible texture filtering. 

我不是專家,所以也許這並根本不工作? 所以,這就是基本的樣本:

<!DOCTYPE html> 
<html> 
    <head> 
    <meta http-equiv="Pragma" content="no-cache"> 
    <meta http-equiv="Expires" content="-1"> 

    <script type="text/javascript" src="js/three.js"></script>  
    </head> 
    <body> 
     <canvas id="c" width="800" height="800" style="border:1px solid">No canvas functionality</canvas> 
     <script> 
      var canvas = document.getElementById("c"); 
      var scene = new THREE.Scene(); 
      var camera = new THREE.PerspectiveCamera(75, canvas.width/canvas.height, 0.1, 1000); 
      var renderer = new THREE.WebGLRenderer({ canvas: canvas }); 

      var test = new Uint16Array(2048 * 2048); 
      for(var i = 0; i < test.length; i++) { 
       test[i] = Math.floor((Math.random() * 0xFFFF) + 1); 
      } 

      var geometry = new THREE.PlaneGeometry(1, 1); 
      var tex = new THREE.DataTexture(test, 2048, 2048, THREE.LuminanceFormat, THREE.UnsignedShortType); 
      var material = new THREE.MeshBasicMaterial({ map: tex }); 
      var mesh = new THREE.Mesh(geometry, this.material); 
      material.map.needsUpdate = true; 
      scene.add(mesh); 

      var bbox = new THREE.BoundingBoxHelper(mesh, 0xFF0000); 
      bbox.update(); 
      scene.add(bbox); 

      camera.position.z = 1; 

      function render() { 
      renderer.render(scene, camera); 
     } 

      requestAnimationFrame(render); 
     </script> 
    </body> 
</html> 

在此先感謝

+0

不是一個答案,但你的榜樣使用'THREE.LuminanceFormat','Uint8Array'和'THREE.UnsignedByteType'。檢查WebGL規範的限制。 – WestLangley

回答

0

經過一番挖掘在網上我發現這個論壇條目:

There is no such thing as gl.SHORT or gl.UNSIGNED_SHORT for textures in OpenGL ES 2.0 nor WebGL

有沒有這樣的事情gl.SHORT或gl.UNSIGNED_SHORT在OpenGL ES 2.0或WebGL中的紋理

從OpenGL ES 2.0的規格只有這些格式都支持

RGBA UNSIGNED_BYTE 
RGB UNSIGNED_BYTE 
RGBA UNSIGNED_SHORT_4_4_4_4 
RGBA UNSIGNED_SHORT_5_5_5_1 
RGB UNSIGNED_SHORT_5_6_5 
LUMINANCE_ALPHA UNSIGNED_BYTE 
LUMINANCE UNSIGNED_BYTE 
ALPHA UNSIGNED_BYTE 

OES_texture_float增加

RGBA FLOAT 
RGB FLOAT 
LUMINANCE_ALPHA FLOAT 
LUMINANCE FLOAT 
ALPHA FLOAT 

因此,這解決了對我來說:)