Skip to content

Commit

Permalink
refactor: apply review
Browse files Browse the repository at this point in the history
  • Loading branch information
WoodNeck committed Nov 9, 2020
1 parent 3bfd6c3 commit f48be9b
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 68 deletions.
48 changes: 24 additions & 24 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ module.exports = config => {

webpack: {
devtool: "inline-source-map",
resolve: {
resolve: {
extensions: [".ts", ".js"]
},
},
mode: "none",
module: {
rules: [
Expand All @@ -50,20 +50,20 @@ module.exports = config => {
],
"plugins": [
"@babel/plugin-transform-modules-commonjs",
["@babel/plugin-proposal-class-properties", {"loose": true}],
["@babel/plugin-proposal-class-properties", {"loose": true}],
]
}
},
{
test: /\.ts$/,
exclude: /node_modules/,
use: {
loader: "ts-loader",
options: {
transpileOnly: true,
compilerOptions: {
module: "es5",
},
test: /\.ts$/,
exclude: /node_modules/,
use: {
loader: "ts-loader",
options: {
transpileOnly: true,
compilerOptions: {
module: "es5",
},
}
}
}
Expand Down Expand Up @@ -102,18 +102,18 @@ module.exports = config => {
karmaConfig.browsers.push(config.chrome ? "Chrome" : "ChromeHeadlessGL");

if (config.coverage) {
karmaConfig.reporters.push("coverage-istanbul");
karmaConfig.coverageIstanbulReporter = {
reports: ["text-summary", "html", "lcovonly"],
dir: "./coverage"
};
karmaConfig.webpack.module.rules.unshift({
test: /\.js$/,
exclude: /(node_modules|test)/,
loader: "istanbul-instrumenter-loader"
});
karmaConfig.singleRun = true;
}
karmaConfig.reporters.push("coverage-istanbul");
karmaConfig.coverageIstanbulReporter = {
reports: ["text-summary", "html", "lcovonly"],
dir: "./coverage"
};
karmaConfig.webpack.module.rules.unshift({
test: /\.js$/,
exclude: /(node_modules|test)/,
loader: "istanbul-instrumenter-loader"
});
karmaConfig.singleRun = true;
}

config.set(karmaConfig);
};
7 changes: 4 additions & 3 deletions src/PanoImageRenderer/WebGLUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ export default class WebGLUtils {

if (success) {
return shader;
} else {
// eslint-disable-next-line
console.error(gl.getShaderInfoLog(shader));
}

// eslint-disable-next-line
console.error(gl.getShaderInfoLog(shader));

return null;
}

Expand Down
10 changes: 5 additions & 5 deletions src/PanoImageRenderer/renderer/CubeRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Agent from "@egjs/agent";
import agent from "@egjs/agent";
import Renderer from "./Renderer";
import WebGLUtils from "../WebGLUtils";
import { util as mathUtil } from "../../utils/math-util";
Expand Down Expand Up @@ -217,11 +217,11 @@ void main(void) {
}

public getMaxCubeMapTextureSize(gl: WebGLRenderingContext, image: HTMLImageElement | HTMLVideoElement) {
const agent = Agent();
const agentInfo = agent();
const maxCubeMapTextureSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE);
let _imageWidth = this.getSourceTileSize(image);

if (agent.browser.name === "ie" && agent.browser.majorVersion === 11) {
if (agentInfo.browser.name === "ie" && agentInfo.browser.majorVersion === 11) {
if (!mathUtil.isPowerOfTwo(_imageWidth)) {
for (let i = 1; i < maxCubeMapTextureSize; i *= 2) {
if (i < _imageWidth) {
Expand All @@ -233,8 +233,8 @@ void main(void) {
}
}
}
if (agent.os.name === "ios") {
const majorVersion = agent.os.majorVersion;
if (agentInfo.os.name === "ios") {
const majorVersion = agentInfo.os.majorVersion;

// ios 9 의 경우 텍스쳐 최대사이즈는 1024 이다.
if (majorVersion === 9) {
Expand Down
6 changes: 3 additions & 3 deletions src/PanoImageRenderer/renderer/Renderer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Component from "@egjs/component";
import Agent from "@egjs/agent";
import agent from "@egjs/agent";
import { mat4 } from "gl-matrix";
import { CubemapConfig, TileConfig } from "../../types";

const agent = Agent();
const isIE11 = agent.browser.name === "ie" && agent.browser.majorVersion === 11;
const agentInfo = agent();
const isIE11 = agentInfo.browser.name === "ie" && agentInfo.browser.majorVersion === 11;

const EVENTS: {
ERROR: "error",
Expand Down
41 changes: 18 additions & 23 deletions src/PanoImageRenderer/vr/VRManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,29 +89,24 @@ class VRManager {
}

public requestPresent(canvas: HTMLCanvasElement) {
return new Promise((resolve, reject) => {
navigator.getVRDisplays().then(displays => {
const vrDisplay = displays.length && displays[0];

if (!vrDisplay) {
reject(new Error("No displays available."));
return;
}
if (!vrDisplay.capabilities.canPresent) {
reject(new Error("Display lacking capability to present."));
return;
}

vrDisplay.requestPresent([{source: canvas}]).then(() => {
const leftEye = vrDisplay.getEyeParameters(EYES.LEFT);
const rightEye = vrDisplay.getEyeParameters(EYES.RIGHT);

canvas.width = Math.max(leftEye.renderWidth, rightEye.renderWidth) * 2;
canvas.height = Math.max(leftEye.renderHeight, rightEye.renderHeight);

this._setDisplay(vrDisplay);
resolve();
});
return navigator.getVRDisplays().then(displays => {
const vrDisplay = displays.length && displays[0];

if (!vrDisplay) {
return Promise.reject(new Error("No displays available."));
}
if (!vrDisplay.capabilities.canPresent) {
return Promise.reject(new Error("Display lacking capability to present."));
}

vrDisplay.requestPresent([{source: canvas}]).then(() => {
const leftEye = vrDisplay.getEyeParameters(EYES.LEFT);
const rightEye = vrDisplay.getEyeParameters(EYES.RIGHT);

canvas.width = Math.max(leftEye.renderWidth, rightEye.renderWidth) * 2;
canvas.height = Math.max(leftEye.renderHeight, rightEye.renderHeight);

this._setDisplay(vrDisplay);
});
});
}
Expand Down
12 changes: 2 additions & 10 deletions src/PanoImageRenderer/vr/XRManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,11 @@ class XRManager {
}

public addEndCallback(callback: (evt?: Event) => any) {
const session = this._xrSession;

if (!session) return;

session.addEventListener("end", callback);
this._xrSession?.addEventListener("end", callback);
}

public removeEndCallback(callback: (evt?: Event) => any) {
const session = this._xrSession;

if (!session) return;

session.removeEventListener("end", callback);
this._xrSession?.removeEventListener("end", callback);
}

public requestPresent(canvas: HTMLCanvasElement, gl: WebGLRenderingContext) {
Expand Down

0 comments on commit f48be9b

Please sign in to comment.