Skip to content
Snippets Groups Projects
Commit 105218ee authored by Alexander Rose's avatar Alexander Rose
Browse files

better handle pixelRatio

parent 4db38ed6
No related branches found
No related tags found
No related merge requests found
...@@ -39,10 +39,6 @@ interface Renderer { ...@@ -39,10 +39,6 @@ interface Renderer {
dispose: () => void dispose: () => void
} }
function getPixelRatio() {
return (typeof window !== 'undefined') ? window.devicePixelRatio : 1
}
export const DefaultRendererProps = { export const DefaultRendererProps = {
clearColor: 0x000000 as Color, clearColor: 0x000000 as Color,
viewport: Viewport.create(0, 0, 0, 0) viewport: Viewport.create(0, 0, 0, 0)
...@@ -56,7 +52,6 @@ namespace Renderer { ...@@ -56,7 +52,6 @@ namespace Renderer {
const model = Mat4.identity() const model = Mat4.identity()
const viewport = Viewport.clone(_viewport) const viewport = Viewport.clone(_viewport)
const pixelRatio = getPixelRatio()
// const lightPosition = Vec3.create(0, 0, -100) // const lightPosition = Vec3.create(0, 0, -100)
const lightColor = Vec3.create(1.0, 1.0, 1.0) const lightColor = Vec3.create(1.0, 1.0, 1.0)
...@@ -73,7 +68,7 @@ namespace Renderer { ...@@ -73,7 +68,7 @@ namespace Renderer {
uView: ValueCell.create(Mat4.clone(camera.view)), uView: ValueCell.create(Mat4.clone(camera.view)),
uProjection: ValueCell.create(Mat4.clone(camera.projection)), uProjection: ValueCell.create(Mat4.clone(camera.projection)),
uPixelRatio: ValueCell.create(pixelRatio), uPixelRatio: ValueCell.create(ctx.pixelRatio),
uViewportHeight: ValueCell.create(viewport.height), uViewportHeight: ValueCell.create(viewport.height),
uLightColor: ValueCell.create(Vec3.clone(lightColor)), uLightColor: ValueCell.create(Vec3.clone(lightColor)),
......
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
import { createProgramCache, ProgramCache } from './program' import { createProgramCache, ProgramCache } from './program'
import { createShaderCache, ShaderCache } from './shader' import { createShaderCache, ShaderCache } from './shader'
function getPixelRatio() {
return (typeof window !== 'undefined') ? window.devicePixelRatio : 1
}
function unbindResources (gl: WebGLRenderingContext) { function unbindResources (gl: WebGLRenderingContext) {
// bind null to all texture units // bind null to all texture units
const maxTextureImageUnits = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS) const maxTextureImageUnits = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS)
...@@ -61,6 +65,7 @@ type Extensions = { ...@@ -61,6 +65,7 @@ type Extensions = {
export interface Context { export interface Context {
gl: WebGLRenderingContext gl: WebGLRenderingContext
extensions: Extensions extensions: Extensions
pixelRatio: number
shaderCache: ShaderCache shaderCache: ShaderCache
programCache: ProgramCache programCache: ProgramCache
...@@ -100,6 +105,7 @@ export function createContext(gl: WebGLRenderingContext): Context { ...@@ -100,6 +105,7 @@ export function createContext(gl: WebGLRenderingContext): Context {
return { return {
gl, gl,
extensions: { angleInstancedArrays, standardDerivatives, oesElementIndexUint, oesVertexArrayObject }, extensions: { angleInstancedArrays, standardDerivatives, oesElementIndexUint, oesVertexArrayObject },
pixelRatio: getPixelRatio(),
shaderCache, shaderCache,
programCache, programCache,
......
...@@ -179,9 +179,11 @@ namespace Viewer { ...@@ -179,9 +179,11 @@ namespace Viewer {
} }
function identify (x: number, y: number): PickingId { function identify (x: number, y: number): PickingId {
const buffer = new Uint8Array(4) x *= ctx.pixelRatio
y *= ctx.pixelRatio
y = canvas.height - y // flip y y = canvas.height - y // flip y
const buffer = new Uint8Array(4)
const xp = Math.round(x * pickScale) const xp = Math.round(x * pickScale)
const yp = Math.round(y * pickScale) const yp = Math.round(y * pickScale)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment