Skip to content

Commit

Permalink
Prefix private methods with _
Browse files Browse the repository at this point in the history
  • Loading branch information
1chandu committed Sep 6, 2019
1 parent 523791f commit a7d2a50
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 90 deletions.
48 changes: 23 additions & 25 deletions modules/core/src/lib/transform/buffer-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export default class BufferTransform {

this.resources = {}; // resources to be deleted

this.initialize(props);
this._initialize(props);
Object.seal(this);
}

setupResources(opts) {
for (const binding of this.bindings) {
this.setupTransformFeedback(binding, opts);
this._setupTransformFeedback(binding, opts);
}
}

Expand All @@ -36,7 +36,7 @@ export default class BufferTransform {

swap() {
if (this.feedbackMap) {
this.currentIndex = (this.currentIndex + 1) % 2;
this.currentIndex = this._getNextIndex();
return true;
}
return false;
Expand Down Expand Up @@ -74,7 +74,7 @@ export default class BufferTransform {

// Private

initialize(props = {}) {
_initialize(props = {}) {
this._setupBuffers(props);
this.varyings = props.varyings || Object.keys(this.bindings[this.currentIndex].feedbackBuffers);
if (this.varyings.length > 0) {
Expand All @@ -83,17 +83,8 @@ export default class BufferTransform {
}
}

_setupBuffers(props = {}) {
const {sourceBuffers = null} = props;
Object.assign(this.feedbackMap, props.feedbackMap);
// if (sourceBuffers || props.feedbackBuffers) {
const feedbackBuffers = this.getFeedbackBuffers(props);
this.updateBindings({sourceBuffers, feedbackBuffers});
// }
}

// auto create feedback buffers if requested
getFeedbackBuffers(props) {
_getFeedbackBuffers(props) {
const {sourceBuffers} = props;
const feedbackBuffers = {};
if (this.bindings[this.currentIndex]) {
Expand All @@ -115,7 +106,7 @@ export default class BufferTransform {
// Create new buffer with same layout and settings as source buffer
const sourceBuffer = sourceBuffers[bufferOrRef];
const {byteLength, usage, accessor} = sourceBuffer;
feedbackBuffers[bufferName] = this.createNewBuffer(bufferName, {
feedbackBuffers[bufferName] = this._createNewBuffer(bufferName, {
byteLength,
usage,
accessor
Expand All @@ -126,27 +117,34 @@ export default class BufferTransform {
return feedbackBuffers;
}

setupTransformFeedback(binding, {model}) {
_setupBuffers(props = {}) {
const {sourceBuffers = null} = props;
Object.assign(this.feedbackMap, props.feedbackMap);
const feedbackBuffers = this._getFeedbackBuffers(props);
this._updateBindings({sourceBuffers, feedbackBuffers});
}

_setupTransformFeedback(binding, {model}) {
const {program} = model;
binding.transformFeedback = new TransformFeedback(this.gl, {
program,
buffers: binding.feedbackBuffers
});
}

updateBindings(opts) {
this.bindings[this.currentIndex] = this.updateBinding(this.bindings[this.currentIndex], opts);
_updateBindings(opts) {
this.bindings[this.currentIndex] = this._updateBinding(this.bindings[this.currentIndex], opts);
if (this.feedbackMap) {
const {sourceBuffers, feedbackBuffers} = this.swapBuffers(this.bindings[this.currentIndex]);
const nextIndex = this.getNextIndex();
this.bindings[nextIndex] = this.updateBinding(this.bindings[nextIndex], {
const {sourceBuffers, feedbackBuffers} = this._swapBuffers(this.bindings[this.currentIndex]);
const nextIndex = this._getNextIndex();
this.bindings[nextIndex] = this._updateBinding(this.bindings[nextIndex], {
sourceBuffers,
feedbackBuffers
});
}
}

updateBinding(binding, opts) {
_updateBinding(binding, opts) {
if (!binding) {
return {
sourceBuffers: Object.assign({}, opts.sourceBuffers),
Expand All @@ -161,7 +159,7 @@ export default class BufferTransform {
return binding;
}

swapBuffers(opts) {
_swapBuffers(opts) {
if (!this.feedbackMap) {
return null;
}
Expand All @@ -179,7 +177,7 @@ export default class BufferTransform {
}

// Create a buffer and add to list of buffers to be deleted.
createNewBuffer(name, opts) {
_createNewBuffer(name, opts) {
const buffer = new Buffer(this.gl, opts);
if (this.resources[name]) {
this.resources[name].delete();
Expand All @@ -188,7 +186,7 @@ export default class BufferTransform {
return buffer;
}

getNextIndex() {
_getNextIndex() {
return (this.currentIndex + 1) % 2;
}
}
66 changes: 33 additions & 33 deletions modules/core/src/lib/transform/texture-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ export default class TextureTransform {

this.resources = {}; // resources to be deleted

this.initialize(props);
this._initialize(props);
Object.seal(this);
}

getModelProps(props = {}) {
const updatedModelProps = this.processVertexShader(props);
const updatedModelProps = this._processVertexShader(props);
return Object.assign({}, props, updatedModelProps);
}

Expand All @@ -61,7 +61,7 @@ export default class TextureTransform {
const textureName = this.samplerTextureMap[sampler];
uniforms[sampler] = sourceTextures[textureName];
}
this.setSourceTextureParameters();
this._setSourceTextureParameters();
// get texture size uniforms
const sizeUniforms = getSizeUniforms({
sourceTextureMap: sourceTextures,
Expand All @@ -81,7 +81,7 @@ export default class TextureTransform {

swap() {
if (this._swapTexture) {
this.currentIndex = (this.currentIndex + 1) % 2;
this.currentIndex = this._getNextIndex();
return true;
}
return false;
Expand All @@ -92,20 +92,6 @@ export default class TextureTransform {
this._setupTextures(opts);
}

_setupTextures(props = {}) {
const {_sourceTextures = {}, _targetTexture} = props;
const targetTexture = this.createTargetTexture({
sourceTextures: _sourceTextures,
textureOrReference: _targetTexture
});
this.hasSourceTextures =
this.hasSourceTextures || (_sourceTextures && Object.keys(_sourceTextures).length > 0);
this.updateBindings({sourceTextures: _sourceTextures, targetTexture});
if ('elementCount' in props) {
this.updateElementIDBuffer(props.elementCount);
}
}

// returns current target texture
getTargetTexture() {
const {targetTexture} = this.bindings[this.currentIndex];
Expand Down Expand Up @@ -153,7 +139,7 @@ export default class TextureTransform {

// Private

initialize(props = {}) {
_initialize(props = {}) {
const {_targetTextureVarying, _swapTexture} = props;
this._swapTexture = _swapTexture;
this.targetTextureVarying = _targetTextureVarying;
Expand All @@ -162,7 +148,7 @@ export default class TextureTransform {
}

// auto create target texture if requested
createTargetTexture(props) {
_createTargetTexture(props) {
const {sourceTextures, textureOrReference} = props;
if (textureOrReference instanceof Texture2D) {
return textureOrReference;
Expand All @@ -177,10 +163,24 @@ export default class TextureTransform {
// we also update target texture.
this._targetRefTexName = textureOrReference;

return this.createNewTexture(refTexture);
return this._createNewTexture(refTexture);
}

_setupTextures(props = {}) {
const {_sourceTextures = {}, _targetTexture} = props;
const targetTexture = this._createTargetTexture({
sourceTextures: _sourceTextures,
textureOrReference: _targetTexture
});
this.hasSourceTextures =
this.hasSourceTextures || (_sourceTextures && Object.keys(_sourceTextures).length > 0);
this._updateBindings({sourceTextures: _sourceTextures, targetTexture});
if ('elementCount' in props) {
this._updateElementIDBuffer(props.elementCount);
}
}

updateElementIDBuffer(elementCount) {
_updateElementIDBuffer(elementCount) {
if (typeof elementCount !== 'number' || this.elementCount >= elementCount) {
return;
}
Expand All @@ -200,19 +200,19 @@ export default class TextureTransform {
this.elementCount = elementCount;
}

updateBindings(opts) {
this.bindings[this.currentIndex] = this.updateBinding(this.bindings[this.currentIndex], opts);
_updateBindings(opts) {
this.bindings[this.currentIndex] = this._updateBinding(this.bindings[this.currentIndex], opts);
if (this._swapTexture) {
const {sourceTextures, targetTexture} = this.swapTextures(this.bindings[this.currentIndex]);
const nextIndex = this.getNextIndex();
this.bindings[nextIndex] = this.updateBinding(this.bindings[nextIndex], {
const {sourceTextures, targetTexture} = this._swapTextures(this.bindings[this.currentIndex]);
const nextIndex = this._getNextIndex();
this.bindings[nextIndex] = this._updateBinding(this.bindings[nextIndex], {
sourceTextures,
targetTexture
});
}
}

updateBinding(binding, opts) {
_updateBinding(binding, opts) {
const {sourceTextures, targetTexture} = opts;
if (!binding) {
binding = {
Expand Down Expand Up @@ -249,15 +249,15 @@ export default class TextureTransform {
}

// set texture filtering parameters on source textures.
setSourceTextureParameters() {
_setSourceTextureParameters() {
const index = this.currentIndex;
const {sourceTextures} = this.bindings[index];
for (const name in sourceTextures) {
sourceTextures[name].setParameters(SRC_TEX_PARAMETER_OVERRIDES);
}
}

swapTextures(opts) {
_swapTextures(opts) {
if (!this._swapTexture) {
return null;
}
Expand All @@ -270,7 +270,7 @@ export default class TextureTransform {
}

// Create a buffer and add to list of buffers to be deleted.
createNewTexture(refTexture) {
_createNewTexture(refTexture) {
const texture = cloneTextureFrom(refTexture, {
parameters: {
[GL.TEXTURE_MIN_FILTER]: GL.NEAREST,
Expand All @@ -292,12 +292,12 @@ export default class TextureTransform {
return texture;
}

getNextIndex() {
_getNextIndex() {
return (this.currentIndex + 1) % 2;
}

// build and return shader releated parameters
processVertexShader(props = {}) {
_processVertexShader(props = {}) {
const {sourceTextures, targetTexture} = this.bindings[this.currentIndex];
const {vs, uniforms, targetTextureType, inject, samplerTextureMap} = updateForTextures({
vs: props.vs,
Expand Down

0 comments on commit a7d2a50

Please sign in to comment.