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

performance, use webgl2 as default context #878

Merged
merged 4 commits into from
Aug 12, 2021
Merged
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
31 changes: 29 additions & 2 deletions packages/web/src/ui/views/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const viewer = (state, i18n) => {

if (!render) {
const options = setup(el)
if (options.error) return html`<b style="color:red; background:white; position:fixed; z-index:10; top:50%">${options.error}</b>`
viewerOptions = options.viewerOptions
camera = options.camera
render = prepareRender(viewerOptions)
Expand Down Expand Up @@ -191,13 +192,32 @@ const viewer = (state, i18n) => {
return el
}

const createContext = (canvas, contextAttributes) => {
const get = (type) => {
try {
return { gl: canvas.getContext(type, contextAttributes), type }
} catch (e) {
return null
}
}
return (
get('webgl2') ||
get('webgl') ||
get('experimental-webgl') ||
get('webgl-experimental')
)
}

const setup = (element) => {
// prepare the camera
let error
const camera = Object.assign({}, perspectiveCamera.defaults)
camera.position = [150, -180, 233]

const { gl, type } = createContext(element)

const viewerOptions = {
glOptions: { canvas: element },
glOptions: { gl },
camera,
drawCommands: {
// draw commands bootstrap themselves the first time they are run
Expand All @@ -209,7 +229,14 @@ const setup = (element) => {
// data
entities: []
}
return { viewerOptions, camera }
if (type === 'webgl') {
if (!gl.getExtension('OES_element_index_uint')) {
error = 'Your browser uses an old version of WebGL without OES_element_index_uint. Please upgrade your browser to use this application'
}

viewerOptions.glOptions.optionalExtensions = ['oes_element_index_uint']
}
return { viewerOptions, camera, error }
}

const resize = (viewerElement) => {
Expand Down