Skip to content

Commit

Permalink
Revert use of js #private as it breaks the integration with unmigrate…
Browse files Browse the repository at this point in the history
…d code
  • Loading branch information
DanielJoyce committed Mar 3, 2024
1 parent 64dbe65 commit 8f22346
Show file tree
Hide file tree
Showing 11 changed files with 857 additions and 857 deletions.
98 changes: 49 additions & 49 deletions src/drawables/Background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,46 @@ import Enums from '../misc/Enums';
class Background {

/** WebGL Context */
#gl;
_gl;
/** Owning scene */
#main;
_main;
/** VertexBuffer */
#vertexBuffer;
_vertexBuffer;
/** Texture coordinates buffer */
#texCoordBuffer;
_texCoordBuffer;
/** Should canvas be filled by background @type {boolean} */
#fill;
_fill;
/** One pixel texture used as background if no other is supplied */
#monoTex;
_monoTex;
/** Background texture ( if one is provided ) */
#texture;
_texture;
/** Height of the texture */
#texWidth;
_texWidth;
/** Width of the texture */
#texHeight;
_texHeight;
/** Texture type, 0: fixed grey, 1 env spec, 2 env ambient */
#type;
_type;
/** Should the texture be blurred @type {boolean} */
#blur;
_blur;

constructor(gl, main) {
this.#gl = gl;
this.#main = main;
this.#vertexBuffer = new Buffer(gl, gl.ARRAY_BUFFER, gl.STATIC_DRAW);
this.#texCoordBuffer = new Buffer(gl, gl.ARRAY_BUFFER, gl.STATIC_DRAW);
this.#fill = true;
this.#monoTex = null;
this.#texture = null;
this.#texWidth = 1;
this.#texHeight = 1;
this.#type = 0;
this.#blur = 0.0;
this._gl = gl;
this._main = main;
this._vertexBuffer = new Buffer(gl, gl.ARRAY_BUFFER, gl.STATIC_DRAW);
this._texCoordBuffer = new Buffer(gl, gl.ARRAY_BUFFER, gl.STATIC_DRAW);
this._fill = true;
this._monoTex = null;
this._texture = null;
this._texWidth = 1;
this._texHeight = 1;
this._type = 0;
this._blur = 0.0;
this.init();
}

init() {
this.#texCoordBuffer.update(new Float32Array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0]));
this.#monoTex = this.createOnePixelTexture(50, 50, 50, 255);
this._texCoordBuffer.update(new Float32Array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0]));
this._monoTex = this.createOnePixelTexture(50, 50, 50, 255);
let element = document
.getElementById('backgroundopen');
if (element != null) {
Expand Down Expand Up @@ -76,7 +76,7 @@ class Background {
}
bg.onload = function () {

var canvas = self.#main.getCanvas();
var canvas = self._main.getCanvas();
self.loadBackgroundTexture(bg);
self.onResize(canvas.width, canvas.height);
self.main.render();
Expand All @@ -91,53 +91,53 @@ class Background {
}

get gl() {
return this.#gl;
return this._gl;
}

get main() {
return this.#main;
return this._main;
}

get blur() {
return this.#blur;
return this._blur;
}

get vertexBuffer() {
return this.#vertexBuffer;
return this._vertexBuffer;
}

get texCoordBuffer() {
return this.#texCoordBuffer;
return this._texCoordBuffer;
}

release() {
this.deleteTexture();
this.#vertexBuffer().release();
this.#texCoordBuffer().release();
this._vertexBuffer().release();
this._texCoordBuffer().release();
}

get type() {
return this.#type;
return this._type;
}

set type(val) {
this.#type = val;
this._type = val;
}

onResize(width, height) {
var ratio = (width / height) / (this.#texWidth / this.#texHeight);
var comp = this.#fill || this.#type !== 0 ? 1.0 / ratio : ratio;
var ratio = (width / height) / (this._texWidth / this._texHeight);
var comp = this._fill || this._type !== 0 ? 1.0 / ratio : ratio;
var x = comp < 1.0 ? 1.0 : 1.0 / ratio;
var y = comp < 1.0 ? ratio : 1.0;
this.#vertexBuffer.update(new Float32Array([-x, -y, x, -y, -x, y, x, y]));
this._vertexBuffer.update(new Float32Array([-x, -y, x, -y, -x, y, x, y]));
}

getTexture() {
return this.#texture ? this.#texture : this.#monoTex;
return this._texture ? this._texture : this._monoTex;
}

createOnePixelTexture(r, g, b, a) {
var gl = this.#gl;
var gl = this._gl;
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texImage2D(
Expand All @@ -158,14 +158,14 @@ class Background {
}

loadBackgroundTexture(tex) {
var gl = this.#gl;
var gl = this._gl;
this.deleteTexture();

this.#texWidth = tex.width;
this.#texHeight = tex.height;
this.#texture = gl.createTexture();
this._texWidth = tex.width;
this._texHeight = tex.height;
this._texture = gl.createTexture();

gl.bindTexture(gl.TEXTURE_2D, this.#texture);
gl.bindTexture(gl.TEXTURE_2D, this._texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, tex);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
Expand All @@ -174,15 +174,15 @@ class Background {
}

deleteTexture() {
if (this.#texture) {
this.#texWidth = this.#texHeight = 1;
this.#gl.deleteTexture(this.#texture);
this.#texture = null;
if (this._texture) {
this._texWidth = this._texHeight = 1;
this._gl.deleteTexture(this._texture);
this._texture = null;
}
}

render() {
Shader[Enums.Shader.BACKGROUND].getOrCreate(this.#gl).draw(this);
Shader[Enums.Shader.BACKGROUND].getOrCreate(this._gl).draw(this);
}
}

Expand Down
80 changes: 40 additions & 40 deletions src/drawables/Rtt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,118 +9,118 @@ var singletonBuffer;
*/
class Rtt {

#gl;
#texture;
#depth;
#framebuffer;
#shaderType;
inverseSize;
#vertexBuffer;
#type;
#wrapRepeat;
#filterNearest;
_gl;
_texture;
_depth;
_framebuffer;
_shaderType;
inverseSize;
_vertexBuffer;
_type;
_wrapRepeat;
_filterNearest;

constructor(gl, shaderName = null, depth = gl.createRenderbuffer(), halfFloat = false) {
this.#gl = gl; // webgl context
this._gl = gl; // webgl context

this.#texture = gl.createTexture();
this.#depth = depth;
this.#framebuffer = gl.createFramebuffer();
this._texture = gl.createTexture();
this._depth = depth;
this._framebuffer = gl.createFramebuffer();

this.#shaderType = shaderName;
this._shaderType = shaderName;
this.inverseSize = new Float32Array(2);
this.#vertexBuffer = null;
this._vertexBuffer = null;

if (halfFloat && WebGLCaps.hasRTTHalfFloat()) this.#type = WebGLCaps.HALF_FLOAT_OES;
else if (halfFloat && WebGLCaps.hasRTTFloat()) this.#type = gl.FLOAT;
else this.#type = gl.UNSIGNED_BYTE;
if (halfFloat && WebGLCaps.hasRTTHalfFloat()) this._type = WebGLCaps.HALF_FLOAT_OES;
else if (halfFloat && WebGLCaps.hasRTTFloat()) this._type = gl.FLOAT;
else this._type = gl.UNSIGNED_BYTE;

this.setWrapRepeat(false);
this.setFilterNearest(false);
this.init();
}

getGL() {
return this.#gl;
return this._gl;
}

getVertexBuffer() {
return this.#vertexBuffer;
return this._vertexBuffer;
}

getFramebuffer() {
return this.#framebuffer;
return this._framebuffer;
}

getTexture() {
return this.#texture;
return this._texture;
}

getDepth() {
return this.#depth;
return this._depth;
}

getInverseSize() {
return this.inverseSize;
}

init() {
var gl = this.#gl;
var gl = this._gl;

if (!singletonBuffer) {
singletonBuffer = new Buffer(gl, gl.ARRAY_BUFFER, gl.STATIC_DRAW);
singletonBuffer.update(new Float32Array([-1.0, -1.0, 4.0, -1.0, -1.0, 4.0]));
}

this.#vertexBuffer = singletonBuffer;
this._vertexBuffer = singletonBuffer;
}

setWrapRepeat(bool) {
this.#wrapRepeat = bool;
this._wrapRepeat = bool;
}

setFilterNearest(bool) {
this.#filterNearest = bool;
this._filterNearest = bool;
}

onResize(width, height) {
var gl = this.#gl;
var gl = this._gl;

this.inverseSize[0] = 1.0 / width;
this.inverseSize[1] = 1.0 / height;

gl.bindTexture(gl.TEXTURE_2D, this.#texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, this.#type, null);
gl.bindTexture(gl.TEXTURE_2D, this._texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, this._type, null);

var filter = this.#filterNearest ? gl.NEAREST : gl.LINEAR;
var filter = this._filterNearest ? gl.NEAREST : gl.LINEAR;
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filter);

var wrap = this.#wrapRepeat ? gl.REPEAT : gl.CLAMP_TO_EDGE;
var wrap = this._wrapRepeat ? gl.REPEAT : gl.CLAMP_TO_EDGE;
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrap);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrap);

if (this.#depth) {
gl.bindRenderbuffer(gl.RENDERBUFFER, this.#depth);
if (this._depth) {
gl.bindRenderbuffer(gl.RENDERBUFFER, this._depth);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height);
}

gl.bindFramebuffer(gl.FRAMEBUFFER, this.#framebuffer);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.#texture, 0);
gl.bindFramebuffer(gl.FRAMEBUFFER, this._framebuffer);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._texture, 0);
gl.framebufferRenderbuffer(
gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this.#depth
gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this._depth
);

gl.bindTexture(gl.TEXTURE_2D, null);
}

release() {
if (this.#texture) this.#gl.deleteTexture(this.#texture);
if (this._texture) this._gl.deleteTexture(this._texture);
this.getVertexBuffer().release();
}

render(main) {
Shader[this.#shaderType].getOrCreate(this.#gl).draw(this, main);
Shader[this._shaderType].getOrCreate(this._gl).draw(this, main);
}
}

Expand Down
Loading

0 comments on commit 8f22346

Please sign in to comment.