From d6abf975fc6ddbdc2f4962727d72ed43ec2a4310 Mon Sep 17 00:00:00 2001 From: Ed Mackey Date: Sun, 4 Jun 2017 17:12:40 -0400 Subject: [PATCH] Tolerate lack of sRGB extension. --- main.js | 9 +++++---- scene.js | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/main.js b/main.js index 702079f8..b8380945 100644 --- a/main.js +++ b/main.js @@ -58,7 +58,7 @@ function loadCubeMap(gl, envMap, type, state) { gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture); gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false); // todo: should this be srgb? or rgba? what's the HDR scale on this? - gl.texImage2D(face, j, gl.hasSRGBExt.SRGB_EXT, gl.hasSRGBExt.SRGB_EXT, gl.UNSIGNED_BYTE, image); + gl.texImage2D(face, j, state.sRGBifAvailable, state.sRGBifAvailable, gl.UNSIGNED_BYTE, image); } }(texture, face, image, j); image.src = faces[i][0]; @@ -139,14 +139,15 @@ function init(vertSource, fragSource) { // Load extensions gl.hasLodExt = gl.getExtension('EXT_shader_texture_lod'); gl.hasDerivativesExt = gl.getExtension('OES_standard_derivatives'); - gl.hasSRGBExt = gl.getExtension('EXT_SRGB'); + var hasSRGBExt = gl.getExtension('EXT_SRGB'); glState = { uniforms: {}, attributes: {}, vertSource: vertSource, fragSource: fragSource, - scene: null + scene: null, + sRGBifAvailable: (hasSRGBExt ? hasSRGBExt.SRGB_EXT : gl.RGBA) }; var projectionMatrix = mat4.create(); @@ -438,7 +439,7 @@ function handleMouseMove(ev, redraw) { var wheelSpeed = 1.04; function handleWheel(ev, redraw) { ev.preventDefault(); - if (ev.wheelDelta > 0) { + if (ev.deltaY > 0) { translate *= wheelSpeed; } else { diff --git a/scene.js b/scene.js index b78a7c66..ed17d338 100644 --- a/scene.js +++ b/scene.js @@ -19,7 +19,8 @@ class Mesh { uniformLocations: {}, attributes: {}, vertSource: globalState.vertSource, - fragSource: globalState.fragSource + fragSource: globalState.fragSource, + sRGBifAvailable : globalState.sRGBifAvailable }; var primitives = gltf.meshes[meshIdx].primitives; @@ -227,7 +228,7 @@ class Mesh { if (pbrMat && pbrMat.baseColorTexture && gltf.textures.length > pbrMat.baseColorTexture.index) { var baseColorTexInfo = gltf.textures[pbrMat.baseColorTexture.index]; var baseColorSrc = this.modelPath + gltf.images[baseColorTexInfo.source].uri; - imageInfos['baseColor'] = { 'uri': baseColorSrc, 'samplerIndex': samplerIndex, 'colorSpace': gl.hasSRGBExt.SRGB_EXT }; // colorSpace, samplerindex, uri + imageInfos['baseColor'] = { 'uri': baseColorSrc, 'samplerIndex': samplerIndex, 'colorSpace': this.glState.sRGBifAvailable }; // colorSpace, samplerindex, uri this.glState.uniforms['u_BaseColorSampler'] = { 'funcName': 'uniform1i', 'vals': [samplerIndex] }; samplerIndex++; this.defines.HAS_BASECOLORMAP = 1; @@ -287,7 +288,7 @@ class Mesh { if (this.material && this.material.emissiveTexture) { var emissiveTexInfo = gltf.textures[this.material.emissiveTexture.index]; var emissiveSrc = this.modelPath + gltf.images[emissiveTexInfo.source].uri; - imageInfos['emissive'] = { 'uri': emissiveSrc, 'samplerIndex': samplerIndex, 'colorSpace': gl.hasSRGBExt.SRGB_EXT }; // colorSpace, samplerindex, uri + imageInfos['emissive'] = { 'uri': emissiveSrc, 'samplerIndex': samplerIndex, 'colorSpace': this.glState.sRGBifAvailable }; // colorSpace, samplerindex, uri this.glState.uniforms['u_EmissiveSampler'] = { 'funcName': 'uniform1i', 'vals': [samplerIndex] }; samplerIndex++; this.defines.HAS_EMISSIVEMAP = 1;