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

Utils: export createCanvasElement to public and use it for WebGPURenderer module #26601

Merged
merged 2 commits into from
Aug 21, 2023
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
12 changes: 2 additions & 10 deletions examples/jsm/renderers/common/Backend.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let vector2 = null;
let vector4 = null;

import { Vector2, Vector4, REVISION } from 'three';
import { Vector2, Vector4, REVISION, createCanvasElement } from 'three';

class Backend {

Expand Down Expand Up @@ -118,7 +118,7 @@ class Backend {

if ( domElement === null ) {

domElement = ( this.parameters.canvas !== undefined ) ? this.parameters.canvas : this.createCanvasElement();
domElement = ( this.parameters.canvas !== undefined ) ? this.parameters.canvas : createCanvasElement();

// OffscreenCanvas does not have setAttribute, see #22811
if ( 'setAttribute' in domElement ) domElement.setAttribute( 'data-engine', `three.js r${REVISION}` );
Expand All @@ -131,14 +131,6 @@ class Backend {

}

createCanvasElement() {

const canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
canvas.style.display = 'block';
return canvas;

}

// resource properties

get( object ) {
Expand Down
1 change: 1 addition & 0 deletions src/Three.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export { ImageUtils } from './extras/ImageUtils.js';
export { ShapeUtils } from './extras/ShapeUtils.js';
export { PMREMGenerator } from './extras/PMREMGenerator.js';
export { WebGLUtils } from './renderers/webgl/WebGLUtils.js';
export { createCanvasElement } from './utils.js';
export * from './constants.js';
export * from './Three.Legacy.js';

Expand Down
10 changes: 1 addition & 9 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,7 @@ import { WebGLUtils } from './webgl/WebGLUtils.js';
import { WebXRManager } from './webxr/WebXRManager.js';
import { WebGLMaterials } from './webgl/WebGLMaterials.js';
import { WebGLUniformsGroups } from './webgl/WebGLUniformsGroups.js';
import { createElementNS } from '../utils.js';

function createCanvasElement() {

const canvas = createElementNS( 'canvas' );
canvas.style.display = 'block';
return canvas;

}
import { createCanvasElement } from '../utils.js';

class WebGLRenderer {

Expand Down
10 changes: 9 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ function createElementNS( name ) {

}

function createCanvasElement() {

const canvas = createElementNS( 'canvas' );
canvas.style.display = 'block';
return canvas;

}

const _cache = {};

function warnOnce( message ) {
Expand All @@ -80,4 +88,4 @@ function warnOnce( message ) {

}

export { arrayMin, arrayMax, arrayNeedsUint32, getTypedArray, createElementNS, warnOnce };
export { arrayMin, arrayMax, arrayNeedsUint32, getTypedArray, createElementNS, createCanvasElement, warnOnce };