tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

gluObjectWrapper.js (3492B)


      1 /*-------------------------------------------------------------------------
      2 * drawElements Quality Program OpenGL ES Utilities
      3 * ------------------------------------------------
      4 *
      5 * Copyright 2014 The Android Open Source Project
      6 *
      7 * Licensed under the Apache License, Version 2.0 (the "License");
      8 * you may not use this file except in compliance with the License.
      9 * You may obtain a copy of the License at
     10 *
     11 *      http://www.apache.org/licenses/LICENSE-2.0
     12 *
     13 * Unless required by applicable law or agreed to in writing, software
     14 * distributed under the License is distributed on an "AS IS" BASIS,
     15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 * See the License for the specific language governing permissions and
     17 * limitations under the License.
     18 *
     19 */
     20 'use strict';
     21 
     22 goog.provide('framework.opengl.gluObjectWrapper');
     23 
     24 goog.scope(function() {
     25    var gluObjectWrapper = framework.opengl.gluObjectWrapper;
     26 
     27    /**
     28    * @typedef {function(this:WebGLRenderingContextBase): WebGLObject}
     29    */
     30    gluObjectWrapper.funcGenT;
     31 
     32    /**
     33    * @typedef {function(this:WebGLRenderingContextBase, WebGLObject)}
     34    */
     35    gluObjectWrapper.funcDelT;
     36 
     37    /**
     38    * @typedef {{name: string, funcGen: !gluObjectWrapper.funcGenT, funcDel: !gluObjectWrapper.funcDelT}}
     39    */
     40    gluObjectWrapper.traitsT;
     41 
     42    /**
     43    * Returns an object containing a configuration for an ObjectWrapper
     44    * @param {string} name
     45    * @param {gluObjectWrapper.funcGenT} funcGen
     46    * @param {gluObjectWrapper.funcDelT} funcDel
     47    * @return {gluObjectWrapper.traitsT}
     48    */
     49    gluObjectWrapper.traits = function(name, funcGen, funcDel) {
     50        return {
     51            name: name,
     52            funcGen: funcGen,
     53            funcDel: funcDel
     54        };
     55    };
     56 
     57    /**
     58    * @constructor
     59    * @param {WebGLRenderingContextBase} gl
     60    * @param {gluObjectWrapper.traitsT} traits
     61    */
     62    gluObjectWrapper.ObjectWrapper = function(gl, traits) {
     63        /**
     64        * @protected
     65        * @type {WebGLRenderingContextBase}
     66        */
     67        this.m_gl = gl;
     68 
     69        /**
     70        * @protected
     71        * @type {gluObjectWrapper.traitsT}
     72        */
     73        this.m_traits = traits;
     74 
     75        /**
     76        * @protected
     77        * @type {WebGLObject}
     78        */
     79        this.m_object = this.m_traits.funcGen.call(gl);
     80 
     81    };
     82 
     83    /**
     84    * Destorys the WebGLObject associated with this object.
     85    */
     86    gluObjectWrapper.ObjectWrapper.prototype.clear = function() {
     87        this.m_traits.funcDel.call(this.m_gl, this.m_object);
     88    };
     89 
     90    /**
     91    * Returns the WebGLObject associated with this object.
     92    * @return {WebGLObject}
     93    */
     94    gluObjectWrapper.ObjectWrapper.prototype.get = function() {
     95        return this.m_object;
     96    };
     97 
     98    /**
     99    * @constructor
    100    * @extends {gluObjectWrapper.ObjectWrapper}
    101    * @param {WebGLRenderingContextBase} gl
    102    */
    103    gluObjectWrapper.Framebuffer = function(gl) {
    104        gluObjectWrapper.ObjectWrapper.call(this, gl, gluObjectWrapper.traits(
    105            'framebuffer',
    106            /** @type {gluObjectWrapper.funcGenT} */(gl.createFramebuffer),
    107            /** @type {gluObjectWrapper.funcDelT} */(gl.deleteFramebuffer)
    108        ));
    109    };
    110    gluObjectWrapper.Framebuffer.prototype = Object.create(gluObjectWrapper.ObjectWrapper.prototype);
    111    gluObjectWrapper.Framebuffer.prototype.constructor = gluObjectWrapper.Framebuffer;
    112 
    113    /**
    114    * @return {WebGLFramebuffer}
    115    */
    116    gluObjectWrapper.Framebuffer.prototype.get;
    117 });