Skip to content

Commit

Permalink
Merge pull request #6 from KhronosGroup/optional-srgb
Browse files Browse the repository at this point in the history
Tolerate lack of sRGB extension.
  • Loading branch information
emackey authored Jun 4, 2017
2 parents 3141c45 + d6abf97 commit ec09d0b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 5 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ec09d0b

Please sign in to comment.