Skip to content

Commit

Permalink
Support Threejs attributes on Graphics initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
fedegratti committed May 19, 2023
1 parent f0676d7 commit 962f639
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v10.2.1
v10.3.0
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ohzi-core",
"version": "10.2.1",
"version": "10.3.0",
"description": "OHZI Core Library",
"source": "src/index.js",
"module": "build/index.module.js",
Expand Down
37 changes: 24 additions & 13 deletions src/Graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { WebGLRenderer } from 'three';

class Graphics
{
init(canvas, context_attributes)
init(canvas, core_attributes, context_attributes, threejs_attributes)
{
this._renderer = undefined;
this.blitter = undefined;
Expand All @@ -36,23 +36,34 @@ class Graphics
this.canvas_context = undefined;
this.context_attributes = undefined;

this.core_attributes = {
force_webgl2: true,
xr_enabled: false
};

this.context_attributes = {
alpha: true,
antialias: false,
depth: true,
desynchronized: false,
stencil: false,
antialias: false,
failIfMajorPerformanceCaveat: false,
powerPreference: 'high-performance',
premultipliedAlpha: true,
preserveDrawingBuffer: true,
powerPreference: 'high-performance',
logarithmicDepthBuffer: false,
force_webgl2: true,
xr_enabled: false
stencil: false
};

this.threejs_attributes = {
logarithmicDepthBuffer: false
};

Object.assign(this.core_attributes, core_attributes);
Object.assign(this.context_attributes, context_attributes);

if (this.context_attributes.force_webgl2)
Object.assign(this.threejs_attributes, this.context_attributes);
Object.assign(this.threejs_attributes, threejs_attributes);

if (this.core_attributes.force_webgl2)
{
this.canvas_context = canvas.getContext('webgl2', this.context_attributes) ||
canvas.getContext('webgl', this.context_attributes) ||
Expand All @@ -68,12 +79,12 @@ class Graphics

// console.log(`Using WebGL ${this.is_webgl2 ? 2 : 1}`);

this._renderer = new WebGLRenderer({
canvas: canvas,
context: this.canvas_context
});
this.threejs_attributes.canvas = canvas;
this.threejs_attributes.context = this.canvas_context;

this._renderer = new WebGLRenderer(this.threejs_attributes);

if (this.context_attributes.xr_enabled)
if (this.core_attributes.xr_enabled)
{
this._renderer.xr.enabled = true;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Initializer
{
}

init(canvas, context_attributes, input)
init(input)
{
CameraManager.init();
CameraUtilities.init(input);
Expand All @@ -39,7 +39,6 @@ class Initializer
Time.init();
UI.init(input);

Graphics.init(canvas, context_attributes);
Debug.init();
}

Expand Down
2 changes: 1 addition & 1 deletion types/Initializer.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { initializer as Initializer };
declare const initializer: Initializer;
declare class Initializer {
init(canvas: any, context_attributes: any, input: any): void;
init(input: any): void;
dispose(render_loop: any): void;
}

0 comments on commit 962f639

Please sign in to comment.