Skip to content

Commit

Permalink
optimize webgl and canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding committed Sep 22, 2022
1 parent 2395826 commit 517853b
Show file tree
Hide file tree
Showing 3 changed files with 2,737 additions and 6,682 deletions.
16 changes: 11 additions & 5 deletions components/home/globe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ interface MarkerProps {
size: number;
}

// Maybe dynamic based on device type?
const DPR = 1;

export default function Globe({ hostname }: { hostname?: string }) {
const { data: markers } = useSWR<MarkerProps[]>(
`/api/edge/coordinates${hostname ? `?hostname=${hostname}` : ""}`,
Expand Down Expand Up @@ -40,9 +43,12 @@ export default function Globe({ hostname }: { hostname?: string }) {
window.addEventListener("resize", onResize);
onResize();
const globe = createGlobe(canvasRef.current, {
devicePixelRatio: 2,
width: width * 2,
height: width * 2,
context: {
antialias: false,
},
devicePixelRatio: DPR,
width: width * DPR,
height: width * DPR,
phi: 0,
theta: 0.3,
dark: 0,
Expand All @@ -59,8 +65,8 @@ export default function Globe({ hostname }: { hostname?: string }) {
// `state` will be an empty object, return updated params.
phi += 0.002;
state.phi = phi + r.get();
state.width = width * 2;
state.height = width * 2;
state.width = width * DPR;
state.height = width * DPR;
},
});
setTimeout(() => (canvasRef.current.style.opacity = "1"));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@visx/responsive": "^2.10.0",
"@visx/shape": "^2.12.2",
"@visx/tooltip": "^2.10.0",
"cobe": "^0.6.1",
"cobe": "^0.6.2",
"framer-motion": "^7.2.1",
"i": "^0.3.7",
"ms": "^2.1.3",
Expand Down
Loading

0 comments on commit 517853b

Please sign in to comment.