GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — GaiaMod-Render/src/BitmapSkin.js at develop · GaiaMod-Main/GaiaMod-Render Expand file tree/ Copy pathBitmapSkin.jsMore file actions 133 lines (114 loc) · 3.92 KB / Copy pathBitmapSkin.jsFile metadata and controls133 lines (114 loc) · 3.92 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 const twgl = require("twgl.js"); const Skin = require("./Skin"); class BitmapSkin extends Skin { /** * Create a new Bitmap Skin. * @extends Skin * @param {!int} id - The ID for this Skin. * @param {!RenderWebGL} renderer - The renderer which will use this skin. */ constructor(id, renderer) { super(id, renderer); /** @type {!int} */ this._costumeResolution = 1; /** @type {Array<int>} */ this._textureSize = [0, 0]; } /** * Dispose of this object. Do not use it after calling this method. */ dispose() { if (this._texture) { this._renderer.gl.deleteTexture(this._texture); this._texture = null; } super.dispose(); } /** * @return {Array<number>} the "native" size, in texels, of this skin. */ get size() { return [ this._textureSize[0] / this._costumeResolution, this._textureSize[1] / this._costumeResolution, ]; } /** * @param {Array<number>} scale - The scaling factors to be used. * @return {WebGLTexture} The GL texture representation of this skin when drawing at the given scale. */ // eslint-disable-next-line no-unused-vars getTexture(scale) { return this._texture || super.getTexture(); } /** * Set the contents of this skin to a snapshot of the provided bitmap data. * @param {ImageData|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} bitmapData - new contents for this skin. * @param {int} [costumeResolution=1] - The resolution to use for this bitmap. * @param {Array<number>} [rotationCenter] - Optional rotation center for the bitmap. If not supplied, it will be * calculated from the bounding box * @fires Skin.event:WasAltered */ setBitmap(bitmapData, costumeResolution, rotationCenter) { if (!bitmapData.width || !bitmapData.height) { super.setEmptyImageData(); return; } const gl = this._renderer.gl; // TW: We want to use <canvas> as-is because reading ImageData wastes memory. // However, vanilla LLK/scratch-vm will reuse any canvas that we get here for other costumes, // which will cause bugs when Silhouette lazily reads the canvas data. // Turbo Warp/scratch-vm does not reuse canvases and will set canvas.reusable = false. let textureData = bitmapData; if ( bitmapData instanceof HTMLCanvasElement && bitmapData.reusable !== false ) { const context = bitmapData.getContext("2d", { willReadFrequently: true }); textureData = context.getImageData( 0, 0, bitmapData.width, bitmapData.height, ); } if (this._texture === null) { const textureOptions = { auto: false, wrap: gl.CLAMP_TO_EDGE, }; this._texture = twgl.createTexture(gl, textureOptions); } this._setTexture(textureData); // Do these last in case any of the above throws an exception this._costumeResolution = costumeResolution || 2; this._textureSize = BitmapSkin._getBitmapSize(bitmapData); if (typeof rotationCenter === "undefined") rotationCenter = this.calculateRotationCenter(); this._rotationCenter[0] = rotationCenter[0]; this._rotationCenter[1] = rotationCenter[1]; this.emitWasAltered(); } /** * @param {ImageData|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} bitmapData - bitmap data to inspect. * @returns {Array<int>} the width and height of the bitmap data, in pixels. * @private */ static _getBitmapSize(bitmapData) { if (bitmapData instanceof HTMLImageElement) { return [ bitmapData.naturalWidth || bitmapData.width, bitmapData.naturalHeight || bitmapData.height, ]; } if (bitmapData instanceof HTMLVideoElement) { return [ bitmapData.videoWidth || bitmapData.width, bitmapData.videoHeight || bitmapData.height, ]; } // ImageData or HTMLCanvasElement return [bitmapData.width, bitmapData.height]; } } module.exports = BitmapSkin; |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |