tor-browser

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

rrShadingContext.js (3999B)


      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 
     21 'use strict';
     22 goog.provide('framework.referencerenderer.rrShadingContext');
     23 goog.require('framework.referencerenderer.rrFragmentOperations');
     24 goog.require('framework.delibs.debase.deMath');
     25 goog.require('framework.referencerenderer.rrDefs');
     26 goog.require('framework.referencerenderer.rrFragmentOperations');
     27 goog.require('framework.referencerenderer.rrGenericVector');
     28 
     29 goog.scope(function() {
     30 
     31    var rrShadingContext = framework.referencerenderer.rrShadingContext;
     32    var deMath = framework.delibs.debase.deMath;
     33    var rrDefs = framework.referencerenderer.rrDefs;
     34    var rrFragmentOperations = framework.referencerenderer.rrFragmentOperations;
     35    var rrGenericVector = framework.referencerenderer.rrGenericVector;
     36 
     37    var DE_ASSERT = function(x) {
     38        if (!x)
     39            throw new Error('Assert failed');
     40    };
     41 
     42    /**
     43     * Fragment shading context
     44     *
     45     * Contains per-primitive information used in fragment shading
     46     * @constructor
     47     * @param {Array<Array<number>>} varying0 (GenericVec4*)
     48     * @param {Array<Array<number>>} varying1 (GenericVec4*)
     49     * @param {Array<Array<number>>} varying2 (GenericVec4*)
     50     */
     51    rrShadingContext.FragmentShadingContext = function(varying0, varying1, varying2) {
     52        /** @type {Array<Array<Array<number>>>} */ this.varyings = [varying0, varying1, varying2]; //!< Vertex shader outputs. Pointer will be NULL if there is no such vertex.
     53        this.m_width = 0xFFFFFFFF;
     54        this.m_height = 0xFFFFFFFF;
     55    };
     56 
     57    /**
     58     * @param {number} width
     59     * @param {number} height
     60     */
     61    rrShadingContext.FragmentShadingContext.prototype.setSize = function(width, height) {
     62        this.m_width = width;
     63        this.m_height = height;
     64    };
     65 
     66    rrShadingContext.FragmentShadingContext.prototype.getWidth = function() {
     67        return this.m_width;
     68    };
     69 
     70    rrShadingContext.FragmentShadingContext.prototype.getHeight = function() {
     71        return this.m_height;
     72    };
     73 
     74    // Read Varying
     75 
     76    /**
     77     * @param {rrFragmentOperations.Fragment} packet
     78     * @param {rrShadingContext.FragmentShadingContext} context
     79     * @param {number} varyingLoc
     80     * @return {Array<number>} (Vector<T, 4>)
     81     */
     82    rrShadingContext.readTriangleVarying = function(packet, context, varyingLoc) {
     83        var result = deMath.scale(
     84            context.varyings[0][varyingLoc],
     85            packet.barycentric[0]
     86        );
     87 
     88        if (context.varyings[1])
     89            result = deMath.add(result, deMath.scale(
     90                context.varyings[1][varyingLoc],
     91                packet.barycentric[1]
     92            ));
     93 
     94        if (context.varyings[2])
     95            result = deMath.add(result, deMath.scale(
     96                context.varyings[2][varyingLoc],
     97                packet.barycentric[2]
     98            ));
     99 
    100        return result;
    101    };
    102 
    103    /**
    104     * @param {rrFragmentOperations.Fragment} packet
    105     * @param {rrShadingContext.FragmentShadingContext} context
    106     * @param {number} varyingLoc
    107     * @return {Array<number>} (Vector<T, 4>)
    108     */
    109    rrShadingContext.readVarying = function(packet, context, varyingLoc) {
    110        return rrShadingContext.readTriangleVarying(packet, context, varyingLoc);
    111    };
    112 
    113 });