Skip to content

Commit

Permalink
Remove class SpeedyTextureUploader
Browse files Browse the repository at this point in the history
  • Loading branch information
alemart committed Jun 12, 2024
1 parent 69c0883 commit e27ea3c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 85 deletions.
8 changes: 1 addition & 7 deletions src/gpu/speedy-gpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { SpeedyGL } from './speedy-gl';
import { SpeedyTexture } from './speedy-texture';
import { SpeedyProgramCenter } from './speedy-program-center';
import { SpeedyTexturePool } from './speedy-texture-pool';
import { SpeedyTextureUploader } from './speedy-texture-uploader';
import { SpeedyMediaSource } from '../core/speedy-media-source';
import { SpeedyPromise } from '../core/speedy-promise';
import { Utils } from '../utils/utils';
Expand Down Expand Up @@ -51,9 +50,6 @@ export class SpeedyGPU extends Observable
/** @type {SpeedyTexturePool} texture pool */
this._texturePool = new SpeedyTexturePool(this);

/** @type {SpeedyTextureUploader} texture uploader */
this._textureUploader = new SpeedyTextureUploader(this);



// recreate the state if necessary
Expand Down Expand Up @@ -131,7 +127,7 @@ export class SpeedyGPU extends Observable
*/
upload(source, outputTexture)
{
return this._textureUploader.upload(source, outputTexture);
return outputTexture.upload(source.data, source.width, source.height);
}

/**
Expand All @@ -145,7 +141,6 @@ export class SpeedyGPU extends Observable
// release internal components
this._programs = this._programs.release();
this._texturePool = this._texturePool.release();
this._textureUploader = this._textureUploader.release();

// unsubscribe
this._speedyGL.unsubscribe(this._reset);
Expand Down Expand Up @@ -181,7 +176,6 @@ export class SpeedyGPU extends Observable

this._programs = new SpeedyProgramCenter(this);
this._texturePool = new SpeedyTexturePool(this);
this._textureUploader = new SpeedyTextureUploader(this);

this._notify();
}
Expand Down
75 changes: 0 additions & 75 deletions src/gpu/speedy-texture-uploader.js

This file was deleted.

19 changes: 16 additions & 3 deletions src/gpu/speedy-texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,26 @@ export class SpeedyTexture

/**
* Upload pixel data to the texture. The texture will be resized if needed.
* @param {TexImageSource} pixels
* @param {TexImageSource} data
* @param {number} [width] in pixels
* @param {number} [height] in pixels
* @return {SpeedyTexture} this
*/
upload(pixels, width = this._width, height = this._height)
upload(data, width = this._width, height = this._height)
{
const gl = this._gl;

// bugfix: if the media is a video, we can't really
// upload it to the GPU unless it's ready
if(data instanceof HTMLVideoElement) {
if(data.readyState < 2) {
// this may happen when the video loops (Firefox)
// keep the previously uploaded texture
//Utils.warning(`Trying to process a video that isn't ready yet`);
return this;
}
}

Utils.assert(width > 0 && height > 0);

this.discardMipmaps();
Expand All @@ -133,7 +145,7 @@ export class SpeedyTexture
this._format = gl.RGBA;
this._dataType = gl.UNSIGNED_BYTE;

SpeedyTexture._upload(gl, this._glTexture, this._width, this._height, pixels, 0, this._format, this._internalFormat, this._dataType);
SpeedyTexture._upload(gl, this._glTexture, this._width, this._height, data, 0, this._format, this._internalFormat, this._dataType);
return this;
}

Expand Down Expand Up @@ -356,6 +368,7 @@ export class SpeedyTexture
gl.bindTexture(gl.TEXTURE_2D, null);
return texture;
}

/**
* Upload pixel data to a WebGL texture
* @param {WebGL2RenderingContext} gl
Expand Down

0 comments on commit e27ea3c

Please sign in to comment.