我用uint16数据提出了一个关于GL_LUMINANCE的小问题。我有一些OpenGL代码,我想带到WebGL / three.js:
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 :(得分: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
所以这解决了我:)