Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tolerate lack of sRGB extension. #6

Merged
merged 1 commit into from
Jun 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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