Skip to content

Commit

Permalink
Revert "Merge branch 'playcanvas:main' into zone-component"
Browse files Browse the repository at this point in the history
This reverts commit 52a694e, reversing
changes made to e3d3067.
  • Loading branch information
MushAsterion committed Apr 13, 2023
1 parent 52a694e commit cc07f78
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 57 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2011-2023 PlayCanvas Ltd.
Copyright (c) 2011-2022 PlayCanvas Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
7 changes: 0 additions & 7 deletions src/core/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,3 @@ export const TRACEID_RENDERPIPELINE_ALLOC = 'RenderPipelineAlloc';
* @type {string}
*/
export const TRACEID_PIPELINELAYOUT_ALLOC = 'PipelineLayoutAlloc';

/**
* Logs the internal debug information for Elements.
*
* @type {string}
*/
export const TRACE_ID_ELEMENT = "Element";
41 changes: 31 additions & 10 deletions src/framework/components/element/component.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Debug } from '../../../core/debug.js';
import { TRACE_ID_ELEMENT } from '../../../core/constants.js';

import { Mat4 } from '../../../core/math/mat4.js';
import { Vec2 } from '../../../core/math/vec2.js';
Expand All @@ -20,6 +19,10 @@ import { ELEMENTTYPE_GROUP, ELEMENTTYPE_IMAGE, ELEMENTTYPE_TEXT, FITMODE_STRETCH
import { ImageElement } from './image-element.js';
import { TextElement } from './text-element.js';

// #if _DEBUG
const _debugLogging = false;
// #endif

const position = new Vec3();
const invParentWtm = new Mat4();

Expand Down Expand Up @@ -1204,7 +1207,9 @@ class ElementComponent extends Component {
this.system._prerender = [];
this.system.app.once('prerender', this._onPrerender, this);

Debug.trace(TRACE_ID_ELEMENT, 'register prerender');
// #if _DEBUG
if (_debugLogging) console.log('register prerender');
// #endif
}
const i = this.system._prerender.indexOf(this.entity);
if (i >= 0) {
Expand All @@ -1214,7 +1219,9 @@ class ElementComponent extends Component {
if (j < 0) {
this.system._prerender.push(current);
}
Debug.trace(TRACE_ID_ELEMENT, 'set prerender root to: ' + current.name);
// #if _DEBUG
if (_debugLogging) console.log('set prerender root to: ' + current.name);
// #endif
}

current = next;
Expand All @@ -1224,7 +1231,9 @@ class ElementComponent extends Component {
_onPrerender() {
for (let i = 0; i < this.system._prerender.length; i++) {
const mask = this.system._prerender[i];
Debug.trace(TRACE_ID_ELEMENT, 'prerender from: ' + mask.name);
// #if _DEBUG
if (_debugLogging) console.log('prerender from: ' + mask.name);
// #endif

// prevent call if element has been removed since being added
if (mask.element) {
Expand Down Expand Up @@ -1291,7 +1300,9 @@ class ElementComponent extends Component {

if (mask) {
const ref = mask.element._image._maskRef;
Debug.trace(TRACE_ID_ELEMENT, 'masking: ' + this.entity.name + ' with ' + ref);
// #if _DEBUG
if (_debugLogging) console.log('masking: ' + this.entity.name + ' with ' + ref);
// #endif

const sp = new StencilParameters({
ref: ref,
Expand All @@ -1305,7 +1316,9 @@ class ElementComponent extends Component {

this._maskedBy = mask;
} else {
Debug.trace(TRACE_ID_ELEMENT, 'no masking on: ' + this.entity.name);
// #if _DEBUG
if (_debugLogging) console.log('no masking on: ' + this.entity.name);
// #endif

// remove stencil params if this is image or text
if (renderableElement && renderableElement._setStencil) {
Expand Down Expand Up @@ -1335,8 +1348,12 @@ class ElementComponent extends Component {
// increment counter to count mask depth
depth++;

Debug.trace(TRACE_ID_ELEMENT, 'masking from: ' + this.entity.name + ' with ' + (sp.ref + 1));
Debug.trace(TRACE_ID_ELEMENT, 'depth++ to: ', depth);
// #if _DEBUG
if (_debugLogging) {
console.log('masking from: ' + this.entity.name + ' with ' + (sp.ref + 1));
console.log('depth++ to: ', depth);
}
// #endif

currentMask = this.entity;
}
Expand Down Expand Up @@ -1368,8 +1385,12 @@ class ElementComponent extends Component {
// increment mask counter to count depth of masks
depth++;

Debug.trace(TRACE_ID_ELEMENT, 'masking from: ' + this.entity.name + ' with ' + sp.ref);
Debug.trace(TRACE_ID_ELEMENT, 'depth++ to: ', depth);
// #if _DEBUG
if (_debugLogging) {
console.log('masking from: ' + this.entity.name + ' with ' + sp.ref);
console.log('depth++ to: ', depth);
}
// #endif

currentMask = this.entity;
}
Expand Down
18 changes: 11 additions & 7 deletions src/framework/components/element/image-element.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Debug } from '../../../core/debug.js';
import { TRACE_ID_ELEMENT } from '../../../core/constants.js';

import { math } from '../../../core/math/math.js';
import { Color } from '../../../core/math/color.js';
Expand Down Expand Up @@ -33,6 +32,10 @@ import { FITMODE_STRETCH, FITMODE_CONTAIN, FITMODE_COVER } from './constants.js'

import { Asset } from '../../asset/asset.js';

// #if _DEBUG
const _debugLogging = false;
// #endif

const _vertexFormatDeviceCache = new DeviceCache();

class ImageRenderable {
Expand Down Expand Up @@ -187,16 +190,17 @@ class ImageRenderable {
} else {
this.unmaskMeshInstance.drawOrder = this.meshInstance.drawOrder + this._element.getMaskOffset();
}
Debug.trace(TRACE_ID_ELEMENT, 'setDrawOrder: ', this.unmaskMeshInstance.name, this.unmaskMeshInstance.drawOrder);
// #if _DEBUG
if (_debugLogging) console.log('setDrawOrder: ', this.unmaskMeshInstance.name, this.unmaskMeshInstance.drawOrder);
// #endif
}
}

setDrawOrder(drawOrder) {
if (!this.meshInstance)
return;

Debug.trace(TRACE_ID_ELEMENT, 'setDrawOrder: ', this.meshInstance.name, drawOrder);

if (!this.meshInstance) return;
// #if _DEBUG
if (_debugLogging) console.log('setDrawOrder: ', this.meshInstance.name, drawOrder);
// #endif
this.meshInstance.drawOrder = drawOrder;
}

Expand Down
25 changes: 15 additions & 10 deletions src/framework/parsers/texture/img.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { path } from '../../../core/path.js';

import {
PIXELFORMAT_RGBA8, TEXHINT_ASSET
PIXELFORMAT_RGB8, PIXELFORMAT_RGBA8, TEXHINT_ASSET
} from '../../../platform/graphics/constants.js';
import { Texture } from '../../../platform/graphics/texture.js';
import { http } from '../../../platform/net/http.js';
Expand Down Expand Up @@ -28,7 +30,7 @@ class ImgParser {
if (hasContents) {
// ImageBitmap interface can load iage
if (this.device.supportsImageBitmap) {
this._loadImageBitmapFromBlob(new Blob([asset.file.contents]), callback);
this._loadImageBitmapFromData(asset.file.contents, callback);
return;
}
url = {
Expand Down Expand Up @@ -59,14 +61,16 @@ class ImgParser {
}

open(url, data, device) {
const ext = path.getExtension(url).toLowerCase();
const format = (ext === '.jpg' || ext === '.jpeg') ? PIXELFORMAT_RGB8 : PIXELFORMAT_RGBA8;
const texture = new Texture(device, {
name: url,
// #if _PROFILER
profilerHint: TEXHINT_ASSET,
// #endif
width: data.width,
height: data.height,
format: PIXELFORMAT_RGBA8
format: format
});
texture.setSource(data);
return texture;
Expand Down Expand Up @@ -120,20 +124,21 @@ class ImgParser {
retry: this.maxRetries > 0,
maxRetries: this.maxRetries
};
http.get(url, options, (err, blob) => {
http.get(url, options, function (err, blob) {
if (err) {
callback(err);
} else {
this._loadImageBitmapFromBlob(blob, callback);
createImageBitmap(blob, {
premultiplyAlpha: 'none'
})
.then(imageBitmap => callback(null, imageBitmap))
.catch(e => callback(e));
}
});
}

_loadImageBitmapFromBlob(blob, callback) {
createImageBitmap(blob, {
premultiplyAlpha: 'none',
colorSpaceConversion: 'none'
})
_loadImageBitmapFromData(data, callback) {
createImageBitmap(new Blob([data]), { premultiplyAlpha: 'none' })
.then(imageBitmap => callback(null, imageBitmap))
.catch(e => callback(e));
}
Expand Down
31 changes: 12 additions & 19 deletions src/platform/graphics/webgl/webgl-graphics-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,6 @@ class WebglGraphicsDevice extends GraphicsDevice {
* reduce the latency by desynchronizing the canvas paint cycle from the event loop.
* @param {boolean} [options.xrCompatible] - Boolean that hints to the user agent to use a
* compatible graphics adapter for an immersive XR device.
* @param {WebGLRenderingContext | WebGL2RenderingContext} [options.gl] - The rendering context
* to use. If not specified, a new context will be created.
*/
constructor(canvas, options = {}) {
super(canvas);
Expand Down Expand Up @@ -388,40 +386,35 @@ class WebglGraphicsDevice extends GraphicsDevice {
Debug.log("Antialiasing has been turned off due to rendering issues on AppleWebKit 15.4");
}

// Retrieve the WebGL context
const preferWebGl2 = (options.preferWebGl2 !== undefined) ? options.preferWebGl2 : true;

const names = preferWebGl2 ? ["webgl2", "webgl", "experimental-webgl"] : ["webgl", "experimental-webgl"];
let gl = null;
for (let i = 0; i < names.length; i++) {
gl = canvas.getContext(names[i], options);

// Retrieve the WebGL context
if (options.gl) {
gl = options.gl;
} else {
const preferWebGl2 = (options.preferWebGl2 !== undefined) ? options.preferWebGl2 : true;
const names = preferWebGl2 ? ["webgl2", "webgl", "experimental-webgl"] : ["webgl", "experimental-webgl"];
for (let i = 0; i < names.length; i++) {
gl = canvas.getContext(names[i], options);
if (gl) {
break;
}
if (gl) {
this.webgl2 = (names[i] === DEVICETYPE_WEBGL2);
this._deviceType = this.webgl2 ? DEVICETYPE_WEBGL2 : DEVICETYPE_WEBGL1;
break;
}
}
this.gl = gl;

if (!gl) {
throw new Error("WebGL not supported");
}

this.gl = gl;
this.webgl2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext;
this._deviceType = this.webgl2 ? DEVICETYPE_WEBGL2 : DEVICETYPE_WEBGL1;

// pixel format of the framebuffer
const alphaBits = gl.getParameter(gl.ALPHA_BITS);
this.framebufferFormat = alphaBits ? PIXELFORMAT_RGBA8 : PIXELFORMAT_RGB8;

const isChrome = platform.browser && !!window.chrome;
const isSafari = platform.browser && !!window.safari;
const isMac = platform.browser && navigator.appVersion.indexOf("Mac") !== -1;

// enable temporary texture unit workaround on desktop safari
this._tempEnableSafariTextureUnitWorkaround = isSafari;
this._tempEnableSafariTextureUnitWorkaround = platform.browser && !!window.safari;

// enable temporary workaround for glBlitFramebuffer failing on Mac Chrome (#2504)
this._tempMacChromeBlitFramebufferWorkaround = isMac && isChrome && !options.alpha;
Expand Down
4 changes: 1 addition & 3 deletions src/scene/materials/standard-material.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,7 @@ class StandardMaterial extends Material {
this._setParameter('material_sheenGloss', this.sheenGloss);
}

if (this.refractionIndex === 0.0) {
this._setParameter('material_f0', 1.0);
} else if (this.refractionIndex !== 1.0 / 1.5) {
if (this.refractionIndex !== 1.0 / 1.5) {
const oneOverRefractionIndex = 1.0 / this.refractionIndex;
const f0 = (oneOverRefractionIndex - 1) / (oneOverRefractionIndex + 1);
this._setParameter('material_f0', f0 * f0);
Expand Down

0 comments on commit cc07f78

Please sign in to comment.