text:
'use strict';
goog.provide('functional.gles3.es3fTextureFormatTests');
goog.require('framework.common.tcuCompressedTexture');
goog.require('framework.common.tcuSurface');
goog.require('framework.common.tcuTestCase');
goog.require('framework.common.tcuTexture');
goog.require('framework.common.tcuTextureUtil');
goog.require('framework.delibs.debase.deMath');
goog.require('framework.delibs.debase.deRandom');
goog.require('framework.opengl.gluShaderUtil');
goog.require('framework.opengl.gluStrUtil');
goog.require('framework.opengl.gluTexture');
goog.require('framework.opengl.gluTextureUtil');
goog.require('modules.shared.glsTextureTestUtil');

goog.scope(function() {

var es3fTextureFormatTests = functional.gles3.es3fTextureFormatTests;
var gluShaderUtil = framework.opengl.gluShaderUtil;
var deRandom = framework.delibs.debase.deRandom;
var tcuTestCase = framework.common.tcuTestCase;
var tcuSurface = framework.common.tcuSurface;
var gluTexture = framework.opengl.gluTexture;
var gluTextureUtil = framework.opengl.gluTextureUtil;
var tcuTexture = framework.common.tcuTexture;
var glsTextureTestUtil = modules.shared.glsTextureTestUtil;
var tcuTextureUtil = framework.common.tcuTextureUtil;
var gluStrUtil = framework.opengl.gluStrUtil;
var deMath = framework.delibs.debase.deMath;
var tcuCompressedTexture = framework.common.tcuCompressedTexture;

/** @type {WebGL2RenderingContext} */ var gl;
es3fTextureFormatTests.GLU_EXPECT_NO_ERROR = function(error, message) {
    assertMsgOptions(error === gl.NONE, message, false, true);
};

var DE_ASSERT = function(x) {
    if (!x)
        throw new Error('Assert failed');
};

es3fTextureFormatTests.version = '300 es';

es3fTextureFormatTests.testDescription = function() {
    var test = tcuTestCase.runner.currentTest;
    return test.description;
};

es3fTextureFormatTests.setParentClass = function(child, parent) {
    child.prototype = Object.create(parent.prototype);
    child.prototype.constructor = child;
};

/**
 * @constructor
 * @extends {tcuTestCase.DeqpTest}
 */
es3fTextureFormatTests.Texture2DFormatCase = function(descriptor) {
    tcuTestCase.DeqpTest.call(this, descriptor.name, descriptor.description);
    this.m_format = descriptor.format;
    this.m_dataType = descriptor.dataType;
    this.m_width = descriptor.width;
    this.m_height = descriptor.height;
    this.m_renderer = new glsTextureTestUtil.TextureRenderer(es3fTextureFormatTests.version, gluShaderUtil.precision.PRECISION_HIGHP);
};

es3fTextureFormatTests.setParentClass(es3fTextureFormatTests.Texture2DFormatCase, tcuTestCase.DeqpTest);

es3fTextureFormatTests.Texture2DFormatCase.prototype.init = function() {
    /*tcu::TextureFormat*/ var fmt = this.m_dataType ? gluTextureUtil.mapGLTransferFormat(this.m_format, this.m_dataType) : gluTextureUtil.mapGLInternalFormat(this.m_format);
    /*tcu::TextureFormatInfo*/ var spec = tcuTextureUtil.getTextureFormatInfo(fmt);
    /* TODO : Port

    std::ostringstream fmtName;

    if (m_dataType)
        fmtName << glu::getPixelFormatStr(m_format) << ", " << glu::getTypeStr(m_dataType);
    else
        fmtName << glu::getPixelFormatStr(m_format);

    log << TestLog::Message << "2D texture, " << fmtName.str() << ", " << m_width << "x" << m_height
                            << ",\n fill with " << formatGradient(&spec.valueMin, &spec.valueMax) << " gradient"
        << TestLog::EndMessage;
    */

    this.m_texture = this.m_dataType ?
              gluTexture.texture2DFromFormat(gl, this.m_format, this.m_dataType, this.m_width, this.m_height) : // Implicit internal format.
              gluTexture.texture2DFromInternalFormat(gl, this.m_format, this.m_width, this.m_height); // Explicit internal format.

    // Fill level 0.
    this.m_texture.getRefTexture().allocLevel(0);
    tcuTextureUtil.fillWithComponentGradients(this.m_texture.getRefTexture().getLevel(0), spec.valueMin, spec.valueMax);
};

es3fTextureFormatTests.Texture2DFormatCase.prototype.deinit = function() {
    /* TODO: Implement */
};

es3fTextureFormatTests.Texture2DFormatCase.prototype.iterate = function() {
    /* TODO: Implement */

    var viewport = new glsTextureTestUtil.RandomViewport(document.getElementById('canvas'), this.m_width, this.m_height/*, deStringHash(getName())*/);

    /* tcu::Surface */ var renderedFrame = new tcuSurface.Surface(viewport.width, viewport.height);
    /* tcu::Surface */ var referenceFrame = new tcuSurface.Surface(viewport.width, viewport.height);
    /* TODO: Implement
    // tcu::RGBA threshold = m_renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(1,1,1,1);
    */
    var threshold = [3, 3, 3, 3];
    var renderParams = new glsTextureTestUtil.ReferenceParams(glsTextureTestUtil.textureType.TEXTURETYPE_2D);

    /* tcu::TextureFormatInfo*/ var spec = tcuTextureUtil.getTextureFormatInfo(this.m_texture.getRefTexture().getFormat());
    /** @const */ var wrapS = gl.CLAMP_TO_EDGE;
    /** @const */ var wrapT = gl.CLAMP_TO_EDGE;
    /** @const */ var minFilter = gl.NEAREST;
    /** @const */ var magFilter = gl.NEAREST;

    renderParams.flags.log_programs = true;
    renderParams.flags.log_uniforms = true;

    renderParams.samplerType = glsTextureTestUtil.getSamplerType(this.m_texture.getRefTexture().getFormat());
    renderParams.sampler = new tcuTexture.Sampler(tcuTexture.WrapMode.CLAMP_TO_EDGE, tcuTexture.WrapMode.CLAMP_TO_EDGE, tcuTexture.WrapMode.CLAMP_TO_EDGE,
     tcuTexture.FilterMode.NEAREST, tcuTexture.FilterMode.NEAREST);
    renderParams.colorScale = spec.lookupScale;
    renderParams.colorBias = spec.lookupBias;

    var texCoord = glsTextureTestUtil.computeQuadTexCoord2D([0, 0], [1, 1]);

    // log << TestLog::Message << "Texture parameters:"
    // << "\n WRAP_S = " << glu::getTextureParameterValueStr(gl.TEXTURE_WRAP_S, wrapS)
    // << "\n WRAP_T = " << glu::getTextureParameterValueStr(gl.TEXTURE_WRAP_T, wrapT)
    // << "\n MIN_FILTER = " << glu::getTextureParameterValueStr(gl.TEXTURE_MIN_FILTER, minFilter)
    // << "\n MAG_FILTER = " << glu::getTextureParameterValueStr(gl.TEXTURE_MAG_FILTER, magFilter)
    // << TestLog::EndMessage;

    // Setup base viewport.
    gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);

    // Upload texture data to GL.
    this.m_texture.upload();

    // Bind to unit 0.
    gl.activeTexture(gl.TEXTURE0);
    gl.bindTexture(gl.TEXTURE_2D, this.m_texture.getGLTexture());

    // Setup nearest neighbor filtering and clamp-to-edge.
    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapS);
    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrapT);
    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);
    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);

    es3fTextureFormatTests.GLU_EXPECT_NO_ERROR(gl.getError(), 'Set texturing state');

    // // Draw.
    this.m_renderer.renderQuad(0, texCoord, renderParams);
    gl.readPixels(viewport.x, viewport.y, viewport.width, viewport.height, gl.RGBA, gl.UNSIGNED_BYTE, renderedFrame.getAccess().getDataPtr());

    es3fTextureFormatTests.GLU_EXPECT_NO_ERROR(gl.getError(), 'glReadPixels()');

    // // Compute reference.
    glsTextureTestUtil.sampleTexture2D(new glsTextureTestUtil.SurfaceAccess(referenceFrame, undefined /*m_renderCtx.getRenderTarget().getPixelFormat()*/),
        this.m_texture.getRefTexture(), texCoord, renderParams);

    // Compare and log.
    var isOk = glsTextureTestUtil.compareImages(referenceFrame, renderedFrame, threshold);

    assertMsgOptions(isOk, es3fTextureFormatTests.testDescription(), true, true);
    return tcuTestCase.IterateResult.STOP;
};

/**
 * @constructor
 * @extends {tcuTestCase.DeqpTest}
 */
es3fTextureFormatTests.TextureCubeFormatCase = function(descriptor) {
    tcuTestCase.DeqpTest.call(this, descriptor.name, descriptor.description);
    this.m_format = descriptor.format;
    this.m_dataType = descriptor.dataType;
    this.m_width = descriptor.width;
    this.m_height = descriptor.height;
    this.m_renderer = new glsTextureTestUtil.TextureRenderer(es3fTextureFormatTests.version, gluShaderUtil.precision.PRECISION_HIGHP);
    DE_ASSERT(this.m_width == this.m_height);
};

es3fTextureFormatTests.setParentClass(es3fTextureFormatTests.TextureCubeFormatCase, tcuTestCase.DeqpTest);

es3fTextureFormatTests.TextureCubeFormatCase.prototype.init = function() {
    /*tcu::TextureFormat*/ var fmt = this.m_dataType ? gluTextureUtil.mapGLTransferFormat(this.m_format, this.m_dataType) : gluTextureUtil.mapGLInternalFormat(this.m_format);
    /*tcu::TextureFormatInfo*/ var spec = tcuTextureUtil.getTextureFormatInfo(fmt);
    /* TODO : Port

    std::ostringstream fmtName;

    if (m_dataType)
        fmtName << glu::getPixelFormatStr(m_format) << ", " << glu::getTypeStr(m_dataType);
    else
        fmtName << glu::getPixelFormatStr(m_format);

    log << TestLog::Message << "2D texture, " << fmtName.str() << ", " << m_width << "x" << m_height
                            << ",\n fill with " << formatGradient(&spec.valueMin, &spec.valueMax) << " gradient"
        << TestLog::EndMessage;
    */

    this.m_texture = this.m_dataType ?
              gluTexture.cubeFromFormat(gl, this.m_format, this.m_dataType, this.m_width) : // Implicit internal format.
              gluTexture.cubeFromInternalFormat(gl, this.m_format, this.m_width); // Explicit internal format.

    // Fill level 0.
    for (var face in tcuTexture.CubeFace) {
        var gMin = null;
        var gMax = null;

        switch (tcuTexture.CubeFace[face]) {
            case 0: gMin = deMath.swizzle(spec.valueMin, [0, 1, 2, 3]); gMax = deMath.swizzle(spec.valueMax, [0, 1, 2, 3]); break;
            case 1: gMin = deMath.swizzle(spec.valueMin, [2, 1, 0, 3]); gMax = deMath.swizzle(spec.valueMax, [2, 1, 0, 3]); break;
            case 2: gMin = deMath.swizzle(spec.valueMin, [1, 2, 0, 3]); gMax = deMath.swizzle(spec.valueMax, [1, 2, 0, 3]); break;
            case 3: gMin = deMath.swizzle(spec.valueMax, [0, 1, 2, 3]); gMax = deMath.swizzle(spec.valueMin, [0, 1, 2, 3]); break;
            case 4: gMin = deMath.swizzle(spec.valueMax, [2, 1, 0, 3]); gMax = deMath.swizzle(spec.valueMin, [2, 1, 0, 3]); break;
            case 5: gMin = deMath.swizzle(spec.valueMax, [1, 2, 0, 3]); gMax = deMath.swizzle(spec.valueMin, [1, 2, 0, 3]); break;
            default:
                DE_ASSERT(false);
        }

        this.m_texture.getRefTexture().allocLevel(tcuTexture.CubeFace[face], 0);
        tcuTextureUtil.fillWithComponentGradients(this.m_texture.getRefTexture().getLevelFace(0, tcuTexture.CubeFace[face]), gMin, gMax);
    }

    this.m_texture.upload();
    this.m_curFace = 0;
    this.m_isOk = true;
};

es3fTextureFormatTests.TextureCubeFormatCase.prototype.testFace = function(face) {
    /* TODO: Implement */

    var viewport = new glsTextureTestUtil.RandomViewport(document.getElementById('canvas'), this.m_width, this.m_height/*, deStringHash(getName())*/);

    /* tcu::Surface */ var renderedFrame = new tcuSurface.Surface(viewport.width, viewport.height);
    /* tcu::Surface */ var referenceFrame = new tcuSurface.Surface(viewport.width, viewport.height);
    /* TODO: Implement
    // tcu::RGBA threshold = m_renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(1,1,1,1);
    */
    var threshold = [3, 3, 3, 3];
    var renderParams = new glsTextureTestUtil.ReferenceParams(glsTextureTestUtil.textureType.TEXTURETYPE_CUBE);

    /* tcu::TextureFormatInfo*/ var spec = tcuTextureUtil.getTextureFormatInfo(this.m_texture.getRefTexture().getFormat());
    /** @const */ var wrapS = gl.CLAMP_TO_EDGE;
    /** @const */ var wrapT = gl.CLAMP_TO_EDGE;
    /** @const */ var minFilter = gl.NEAREST;
    /** @const */ var magFilter = gl.NEAREST;

    renderParams.flags.log_programs = true;
    renderParams.flags.log_uniforms = true;

    renderParams.samplerType = glsTextureTestUtil.getSamplerType(this.m_texture.getRefTexture().getFormat());
    renderParams.sampler = new tcuTexture.Sampler(tcuTexture.WrapMode.CLAMP_TO_EDGE, tcuTexture.WrapMode.CLAMP_TO_EDGE, tcuTexture.WrapMode.CLAMP_TO_EDGE,
     tcuTexture.FilterMode.NEAREST, tcuTexture.FilterMode.NEAREST);
    renderParams.colorScale = spec.lookupScale;
    renderParams.colorBias = spec.lookupBias;

    // Log render info on first face.
    if (face === tcuTexture.CubeFace.CUBEFACE_NEGATIVE_X) {
        renderParams.flags.log_programs = true;
        renderParams.flags.log_uniforms = true;
    }

    var texCoord = glsTextureTestUtil.computeQuadTexCoordCube(face);

    // log << TestLog::Message << "Texture parameters:"
    // << "\n WRAP_S = " << glu::getTextureParameterValueStr(gl.TEXTURE_WRAP_S, wrapS)
    // << "\n WRAP_T = " << glu::getTextureParameterValueStr(gl.TEXTURE_WRAP_T, wrapT)
    // << "\n MIN_FILTER = " << glu::getTextureParameterValueStr(gl.TEXTURE_MIN_FILTER, minFilter)
    // << "\n MAG_FILTER = " << glu::getTextureParameterValueStr(gl.TEXTURE_MAG_FILTER, magFilter)
    // << TestLog::EndMessage;

    // Setup base viewport.
    gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);

    // Bind to unit 0.
    gl.activeTexture(gl.TEXTURE0);
    gl.bindTexture(gl.TEXTURE_CUBE_MAP, this.m_texture.getGLTexture());

    // Setup nearest neighbor filtering and clamp-to-edge.
    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, wrapS);
    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, wrapT);
    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, minFilter);
    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, magFilter);

    es3fTextureFormatTests.GLU_EXPECT_NO_ERROR(gl.getError(), 'Set texturing state');

    // // Draw.
    this.m_renderer.renderQuad(0, texCoord, renderParams);
    gl.readPixels(viewport.x, viewport.y, viewport.width, viewport.height, gl.RGBA, gl.UNSIGNED_BYTE, renderedFrame.getAccess().getDataPtr());

    es3fTextureFormatTests.GLU_EXPECT_NO_ERROR(gl.getError(), 'glReadPixels()');

    // // Compute reference.
    glsTextureTestUtil.sampleTextureCube(new glsTextureTestUtil.SurfaceAccess(referenceFrame, undefined /*m_renderCtx.getRenderTarget().getPixelFormat()*/),
        this.m_texture.getRefTexture(), texCoord, renderParams);

    // Compare and log.
    var isOk = glsTextureTestUtil.compareImages(referenceFrame, renderedFrame, threshold);

    assertMsgOptions(isOk, 'Face: ' + this.m_curFace + ' ' + es3fTextureFormatTests.testDescription(), true, true);
    return isOk;
};

es3fTextureFormatTests.TextureCubeFormatCase.prototype.iterate = function() {
    debug('Testing face ' + this.m_curFace);
    // Execute test for all faces.
    if (!this.testFace(this.m_curFace))
        this.m_isOk = false;

    this.m_curFace += 1;

    if (this.m_curFace < Object.keys(tcuTexture.CubeFace).length)
        return tcuTestCase.IterateResult.CONTINUE;
    else
        return tcuTestCase.IterateResult.STOP;
};

/**
 * @constructor
 * @extends {tcuTestCase.DeqpTest}
 */
es3fTextureFormatTests.Texture2DArrayFormatCase = function(descriptor) {
    tcuTestCase.DeqpTest.call(this, descriptor.name, descriptor.description);
    this.m_format = descriptor.format;
    this.m_dataType = descriptor.dataType;
    this.m_width = descriptor.width;
    this.m_height = descriptor.height;
    this.m_numLayers = descriptor.numLayers;
    this.m_renderer = new glsTextureTestUtil.TextureRenderer(es3fTextureFormatTests.version, gluShaderUtil.precision.PRECISION_HIGHP);
};

es3fTextureFormatTests.setParentClass(es3fTextureFormatTests.Texture2DArrayFormatCase, tcuTestCase.DeqpTest);

es3fTextureFormatTests.Texture2DArrayFormatCase.prototype.init = function() {
    /*tcu::TextureFormat*/ var fmt = this.m_dataType ? gluTextureUtil.mapGLTransferFormat(this.m_format, this.m_dataType) : gluTextureUtil.mapGLInternalFormat(this.m_format);
    /*tcu::TextureFormatInfo*/ var spec = tcuTextureUtil.getTextureFormatInfo(fmt);
    /* TODO : Port

    std::ostringstream fmtName;

    if (m_dataType)
        fmtName << glu::getPixelFormatStr(m_format) << ", " << glu::getTypeStr(m_dataType);
    else
        fmtName << glu::getPixelFormatStr(m_format);

    log << TestLog::Message << "2D texture, " << fmtName.str() << ", " << m_width << "x" << m_height
                            << ",\n fill with " << formatGradient(&spec.valueMin, &spec.valueMax) << " gradient"
        << TestLog::EndMessage;
    */

    this.m_texture = this.m_dataType ?
              gluTexture.texture2DArrayFromFormat(gl, this.m_format, this.m_dataType, this.m_width, this.m_height, this.m_numLayers) : // Implicit internal format.
              gluTexture.texture2DArrayFromInternalFormat(gl, this.m_format, this.m_width, this.m_height, this.m_numLayers); // Explicit internal format.

    this.m_texture.getRefTexture().allocLevel(0);
    tcuTextureUtil.fillWithComponentGradients(this.m_texture.getRefTexture().getLevel(0), spec.valueMin, spec.valueMax);

    this.m_curLayer = 0;
    this.m_isOk = true;
};

es3fTextureFormatTests.Texture2DArrayFormatCase.prototype.testLayer = function(layerNdx) {
    /* TODO: Implement */

    var viewport = new glsTextureTestUtil.RandomViewport(document.getElementById('canvas'), this.m_width, this.m_height/*, deStringHash(getName())*/);

    /* tcu::Surface */ var renderedFrame = new tcuSurface.Surface(viewport.width, viewport.height);
    /* tcu::Surface */ var referenceFrame = new tcuSurface.Surface(viewport.width, viewport.height);
    /* TODO: Implement
    // tcu::RGBA threshold = m_renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(1,1,1,1);
    */
    var threshold = [3, 3, 3, 3];
    var renderParams = new glsTextureTestUtil.ReferenceParams(glsTextureTestUtil.textureType.TEXTURETYPE_2D_ARRAY);

    /* tcu::TextureFormatInfo*/ var spec = tcuTextureUtil.getTextureFormatInfo(this.m_texture.getRefTexture().getFormat());
    /** @const */ var wrapS = gl.CLAMP_TO_EDGE;
    /** @const */ var wrapT = gl.CLAMP_TO_EDGE;
    /** @const */ var minFilter = gl.NEAREST;
    /** @const */ var magFilter = gl.NEAREST;

    renderParams.flags.log_programs = true;
    renderParams.flags.log_uniforms = true;

    renderParams.samplerType = glsTextureTestUtil.getSamplerType(this.m_texture.getRefTexture().getFormat());
    renderParams.sampler = new tcuTexture.Sampler(tcuTexture.WrapMode.CLAMP_TO_EDGE, tcuTexture.WrapMode.CLAMP_TO_EDGE, tcuTexture.WrapMode.CLAMP_TO_EDGE,
     tcuTexture.FilterMode.NEAREST, tcuTexture.FilterMode.NEAREST);
    renderParams.colorScale = spec.lookupScale;
    renderParams.colorBias = spec.lookupBias;

    var texCoord = glsTextureTestUtil.computeQuadTexCoord2DArray(layerNdx, [0, 0], [1, 1]);

    // log << TestLog::Message << "Texture parameters:"
    // << "\n WRAP_S = " << glu::getTextureParameterValueStr(gl.TEXTURE_WRAP_S, wrapS)
    // << "\n WRAP_T = " << glu::getTextureParameterValueStr(gl.TEXTURE_WRAP_T, wrapT)
    // << "\n MIN_FILTER = " << glu::getTextureParameterValueStr(gl.TEXTURE_MIN_FILTER, minFilter)
    // << "\n MAG_FILTER = " << glu::getTextureParameterValueStr(gl.TEXTURE_MAG_FILTER, magFilter)
    // << TestLog::EndMessage;

    // Setup base viewport.
    gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);

    this.m_texture.upload();

    // Bind to unit 0.
    gl.activeTexture(gl.TEXTURE0);
    gl.bindTexture(gl.TEXTURE_2D_ARRAY, this.m_texture.getGLTexture());

    // Setup nearest neighbor filtering and clamp-to-edge.
    gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_WRAP_S, wrapS);
    gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_WRAP_T, wrapT);
    gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, minFilter);
    gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, magFilter);

    es3fTextureFormatTests.GLU_EXPECT_NO_ERROR(gl.getError(), 'Set texturing state');

    // // Draw.
    this.m_renderer.renderQuad(0, texCoord, renderParams);
    gl.readPixels(viewport.x, viewport.y, viewport.width, viewport.height, gl.RGBA, gl.UNSIGNED_BYTE, renderedFrame.getAccess().getDataPtr());

    es3fTextureFormatTests.GLU_EXPECT_NO_ERROR(gl.getError(), 'glReadPixels()');

    // // Compute reference.
    glsTextureTestUtil.sampleTexture2DArray(new glsTextureTestUtil.SurfaceAccess(referenceFrame, undefined /*m_renderCtx.getRenderTarget().getPixelFormat()*/),
        this.m_texture.getRefTexture(), texCoord, renderParams);

    // Compare and log.
    var isOk = glsTextureTestUtil.compareImages(referenceFrame, renderedFrame, threshold);

    assertMsgOptions(isOk, 'Layer: ' + this.m_curLayer + ' ' + es3fTextureFormatTests.testDescription(), true, true);
    return isOk;
};

es3fTextureFormatTests.Texture2DArrayFormatCase.prototype.iterate = function() {
    debug('Testing layer ' + this.m_curLayer);
    // Execute test for all layers.
    if (!this.testLayer(this.m_curLayer))
        this.m_isOk = false;

    this.m_curLayer += 1;

    if (this.m_curLayer == this.m_numLayers)
        return tcuTestCase.IterateResult.STOP;
    else
        return tcuTestCase.IterateResult.CONTINUE;
};

/**
 * @constructor
 * @extends {tcuTestCase.DeqpTest}
 */
es3fTextureFormatTests.Texture3DFormatCase = function(descriptor) {
    tcuTestCase.DeqpTest.call(this, descriptor.name, descriptor.description);
    this.m_format = descriptor.format;
    this.m_dataType = descriptor.dataType;
    this.m_width = descriptor.width;
    this.m_height = descriptor.height;
    this.m_depth = descriptor.depth;
    this.m_renderer = new glsTextureTestUtil.TextureRenderer(es3fTextureFormatTests.version, gluShaderUtil.precision.PRECISION_HIGHP);
};

es3fTextureFormatTests.setParentClass(es3fTextureFormatTests.Texture3DFormatCase, tcuTestCase.DeqpTest);

es3fTextureFormatTests.Texture3DFormatCase.prototype.init = function() {
    /*tcu::TextureFormat*/ var fmt = this.m_dataType ? gluTextureUtil.mapGLTransferFormat(this.m_format, this.m_dataType) : gluTextureUtil.mapGLInternalFormat(this.m_format);
    /*tcu::TextureFormatInfo*/ var spec = tcuTextureUtil.getTextureFormatInfo(fmt);
    /* TODO : Port

    std::ostringstream fmtName;

    if (m_dataType)
        fmtName << glu::getPixelFormatStr(m_format) << ", " << glu::getTypeStr(m_dataType);
    else
        fmtName << glu::getPixelFormatStr(m_format);

    log << TestLog::Message << "2D texture, " << fmtName.str() << ", " << m_width << "x" << m_height
                            << ",\n fill with " << formatGradient(&spec.valueMin, &spec.valueMax) << " gradient"
        << TestLog::EndMessage;
    */

    this.m_texture = this.m_dataType ?
              gluTexture.texture3DFromFormat(gl, this.m_format, this.m_dataType, this.m_width, this.m_height, this.m_depth) : // Implicit internal format.
              gluTexture.texture3DFromInternalFormat(gl, this.m_format, this.m_width, this.m_height, this.m_depth); // Explicit internal format.

    this.m_texture.getRefTexture().allocLevel(0);
    tcuTextureUtil.fillWithComponentGradients(this.m_texture.getRefTexture().getLevel(0), spec.valueMin, spec.valueMax);

    this.m_curSlice = 0;
    this.m_isOk = true;
};

es3fTextureFormatTests.Texture3DFormatCase.prototype.testSlice = function(sliceNdx) {
    /* TODO: Implement */

    var viewport = new glsTextureTestUtil.RandomViewport(document.getElementById('canvas'), this.m_width, this.m_height/*, deStringHash(getName())*/);

    /* tcu::Surface */ var renderedFrame = new tcuSurface.Surface(viewport.width, viewport.height);
    /* tcu::Surface */ var referenceFrame = new tcuSurface.Surface(viewport.width, viewport.height);
    /* TODO: Implement
    // tcu::RGBA threshold = m_renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(1,1,1,1);
    */
    var threshold = [3, 3, 3, 3];
    var renderParams = new glsTextureTestUtil.ReferenceParams(glsTextureTestUtil.textureType.TEXTURETYPE_3D);

    /* tcu::TextureFormatInfo*/ var spec = tcuTextureUtil.getTextureFormatInfo(this.m_texture.getRefTexture().getFormat());
    var r = (sliceNdx + 0.5) / this.m_depth;
    /** @const */ var wrapS = gl.CLAMP_TO_EDGE;
    /** @const */ var wrapT = gl.CLAMP_TO_EDGE;
    /** @const */ var minFilter = gl.NEAREST;
    /** @const */ var magFilter = gl.NEAREST;

    renderParams.flags.log_programs = true;
    renderParams.flags.log_uniforms = true;

    renderParams.samplerType = glsTextureTestUtil.getSamplerType(this.m_texture.getRefTexture().getFormat());
    renderParams.sampler = new tcuTexture.Sampler(tcuTexture.WrapMode.CLAMP_TO_EDGE, tcuTexture.WrapMode.CLAMP_TO_EDGE, tcuTexture.WrapMode.CLAMP_TO_EDGE,
     tcuTexture.FilterMode.NEAREST, tcuTexture.FilterMode.NEAREST);
    renderParams.colorScale = spec.lookupScale;
    renderParams.colorBias = spec.lookupBias;

    var texCoord = glsTextureTestUtil.computeQuadTexCoord3D([0, 0, r], [1, 1, r], [0, 1, 2]);

    // log << TestLog::Message << "Texture parameters:"
    // << "\n WRAP_S = " << glu::getTextureParameterValueStr(gl.TEXTURE_WRAP_S, wrapS)
    // << "\n WRAP_T = " << glu::getTextureParameterValueStr(gl.TEXTURE_WRAP_T, wrapT)
    // << "\n MIN_FILTER = " << glu::getTextureParameterValueStr(gl.TEXTURE_MIN_FILTER, minFilter)
    // << "\n MAG_FILTER = " << glu::getTextureParameterValueStr(gl.TEXTURE_MAG_FILTER, magFilter)
    // << TestLog::EndMessage;

    // Setup base viewport.
    gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);

    this.m_texture.upload();

    // Bind to unit 0.
    gl.activeTexture(gl.TEXTURE0);
    gl.bindTexture(gl.TEXTURE_3D, this.m_texture.getGLTexture());

    // Setup nearest neighbor filtering and clamp-to-edge.
    gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_WRAP_S, wrapS);
    gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_WRAP_T, wrapT);
    gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_MIN_FILTER, minFilter);
    gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_MAG_FILTER, magFilter);

    es3fTextureFormatTests.GLU_EXPECT_NO_ERROR(gl.getError(), 'Set texturing state');

    // // Draw.
    this.m_renderer.renderQuad(0, texCoord, renderParams);
    gl.readPixels(viewport.x, viewport.y, viewport.width, viewport.height, gl.RGBA, gl.UNSIGNED_BYTE, renderedFrame.getAccess().getDataPtr());

    es3fTextureFormatTests.GLU_EXPECT_NO_ERROR(gl.getError(), 'glReadPixels()');

    // // Compute reference.
    glsTextureTestUtil.sampleTexture3D(new glsTextureTestUtil.SurfaceAccess(referenceFrame, undefined /*m_renderCtx.getRenderTarget().getPixelFormat()*/),
        this.m_texture.getRefTexture(), texCoord, renderParams);

    // Compare and log.
    var isOk = glsTextureTestUtil.compareImages(referenceFrame, renderedFrame, threshold);

    assertMsgOptions(isOk, 'Slice: ' + this.m_curSlice + ' ' + es3fTextureFormatTests.testDescription(), true, true);
    return isOk;
};

es3fTextureFormatTests.Texture3DFormatCase.prototype.iterate = function() {
    debug('Testing slice ' + this.m_curSlice);
    // Execute test for all layers.
    if (!this.testSlice(this.m_curSlice))
        this.m_isOk = false;

    this.m_curSlice += 1;

    if (this.m_curSlice >= this.m_depth)
        return tcuTestCase.IterateResult.STOP;
    else
        return tcuTestCase.IterateResult.CONTINUE;
};

/**
 * @constructor
 * @extends {tcuTestCase.DeqpTest}
 */
es3fTextureFormatTests.Compressed2DFormatCase = function(descriptor) {
    tcuTestCase.DeqpTest.call(this, descriptor.name, descriptor.description);
    this.m_format = descriptor.format;
    this.m_dataType = descriptor.dataType;
    this.m_width = descriptor.width;
    this.m_height = descriptor.height;
    this.m_renderer = new glsTextureTestUtil.TextureRenderer(es3fTextureFormatTests.version, gluShaderUtil.precision.PRECISION_HIGHP);
};

es3fTextureFormatTests.setParentClass(es3fTextureFormatTests.Compressed2DFormatCase, tcuTestCase.DeqpTest);

es3fTextureFormatTests.Compressed2DFormatCase.prototype.init = function() {
    var compressed = new tcuCompressedTexture.CompressedTexture(this.m_format, this.m_width, this.m_height);
    var rand = new deRandom.Random(0);
    for (var i = 0; i < compressed.m_data.length; i++) {
        compressed.m_data[i] = rand.getInt(0, 255);
    }
    this.m_texture = gluTexture.compressed2DFromInternalFormat(gl, this.m_format, this.m_width, this.m_height, compressed);
};

es3fTextureFormatTests.Compressed2DFormatCase.prototype.deinit = function() {
    /* TODO: Implement */
};

es3fTextureFormatTests.Compressed2DFormatCase.prototype.iterate = function() {
    /* TODO: Implement */

    var viewport = new glsTextureTestUtil.RandomViewport(document.getElementById('canvas'), this.m_width, this.m_height/*, deStringHash(getName())*/);

    /* tcu::Surface */ var renderedFrame = new tcuSurface.Surface(viewport.width, viewport.height);
    /* tcu::Surface */ var referenceFrame = new tcuSurface.Surface(viewport.width, viewport.height);
    /* TODO: Implement
    // tcu::RGBA threshold = m_renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(1,1,1,1);
    */
    var threshold = [3, 3, 3, 3];
    var renderParams = new glsTextureTestUtil.ReferenceParams(glsTextureTestUtil.textureType.TEXTURETYPE_2D);

    /* tcu::TextureFormatInfo*/ var spec = tcuTextureUtil.getTextureFormatInfo(this.m_texture.getRefTexture().getFormat());
    /** @const */ var wrapS = gl.CLAMP_TO_EDGE;
    /** @const */ var wrapT = gl.CLAMP_TO_EDGE;
    /** @const */ var minFilter = gl.NEAREST;
    /** @const */ var magFilter = gl.NEAREST;

    renderParams.flags.log_programs = true;
    renderParams.flags.log_uniforms = true;

    renderParams.samplerType = glsTextureTestUtil.getSamplerType(this.m_texture.getRefTexture().getFormat());
    renderParams.sampler = new tcuTexture.Sampler(tcuTexture.WrapMode.CLAMP_TO_EDGE, tcuTexture.WrapMode.CLAMP_TO_EDGE, tcuTexture.WrapMode.CLAMP_TO_EDGE,
     tcuTexture.FilterMode.NEAREST, tcuTexture.FilterMode.NEAREST);
    renderParams.colorScale = spec.lookupScale;
    renderParams.colorBias = spec.lookupBias;

    var texCoord = glsTextureTestUtil.computeQuadTexCoord2D([0, 0], [1, 1]);

    // log << TestLog::Message << "Texture parameters:"
    // << "\n WRAP_S = " << glu::getTextureParameterValueStr(gl.TEXTURE_WRAP_S, wrapS)
    // << "\n WRAP_T = " << glu::getTextureParameterValueStr(gl.TEXTURE_WRAP_T, wrapT)
    // << "\n MIN_FILTER = " << glu::getTextureParameterValueStr(gl.TEXTURE_MIN_FILTER, minFilter)
    // << "\n MAG_FILTER = " << glu::getTextureParameterValueStr(gl.TEXTURE_MAG_FILTER, magFilter)
    // << TestLog::EndMessage;

    // Setup base viewport.
    gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);

    // Bind to unit 0.
    gl.activeTexture(gl.TEXTURE0);
    gl.bindTexture(gl.TEXTURE_2D, this.m_texture.getGLTexture());

    // Setup nearest neighbor filtering and clamp-to-edge.
    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapS);
    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrapT);
    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);
    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);

    es3fTextureFormatTests.GLU_EXPECT_NO_ERROR(gl.getError(), 'Set texturing state');

    // // Draw.
    this.m_renderer.renderQuad(0, texCoord, renderParams);
    es3fTextureFormatTests.GLU_EXPECT_NO_ERROR(gl.getError(), 'Render');
    gl.readPixels(viewport.x, viewport.y, viewport.width, viewport.height, gl.RGBA, gl.UNSIGNED_BYTE, renderedFrame.getAccess().getDataPtr());

    es3fTextureFormatTests.GLU_EXPECT_NO_ERROR(gl.getError(), 'glReadPixels()');

    // // Compute reference.
    glsTextureTestUtil.sampleTexture2D(new glsTextureTestUtil.SurfaceAccess(referenceFrame, undefined /*m_renderCtx.getRenderTarget().getPixelFormat()*/),
        this.m_texture.getRefTexture(), texCoord, renderParams);

    // Compare and log.
    var isOk = glsTextureTestUtil.compareImages(referenceFrame, renderedFrame, threshold);

    assertMsgOptions(isOk, es3fTextureFormatTests.testDescription(), true, true);
    return tcuTestCase.IterateResult.STOP;
};

/**
 * @constructor
 * @extends {tcuTestCase.DeqpTest}
 */
es3fTextureFormatTests.CompressedCubeFormatCase = function(descriptor) {
    tcuTestCase.DeqpTest.call(this, descriptor.name, descriptor.description);
    this.m_format = descriptor.format;
    this.m_dataType = descriptor.dataType;
    this.m_width = descriptor.width;
    this.m_height = descriptor.height;
    this.m_renderer = new glsTextureTestUtil.TextureRenderer(es3fTextureFormatTests.version, gluShaderUtil.precision.PRECISION_HIGHP);
    this.m_curFace = 0;
    this.m_isOk = true;
    DE_ASSERT(this.m_width == this.m_height);
};

es3fTextureFormatTests.setParentClass(es3fTextureFormatTests.CompressedCubeFormatCase, tcuTestCase.DeqpTest);

es3fTextureFormatTests.CompressedCubeFormatCase.prototype.init = function() {
    var compressed = new tcuCompressedTexture.CompressedTexture(this.m_format, this.m_width, this.m_height);
    var rand = new deRandom.Random(0);
    for (var i = 0; i < compressed.m_data.length; i++) {
        compressed.m_data[i] = rand.getInt(0, 255);
    }
    this.m_texture = gluTexture.compressedCubeFromInternalFormat(gl, this.m_format, this.m_width, compressed);
};

es3fTextureFormatTests.CompressedCubeFormatCase.prototype.testFace = function(face) {
    /* TODO: Implement */

    var viewport = new glsTextureTestUtil.RandomViewport(document.getElementById('canvas'), this.m_width, this.m_height/*, deStringHash(getName())*/);

    /* tcu::Surface */ var renderedFrame = new tcuSurface.Surface(viewport.width, viewport.height);
    /* tcu::Surface */ var referenceFrame = new tcuSurface.Surface(viewport.width, viewport.height);
    /* TODO: Implement
    // tcu::RGBA threshold = m_renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(1,1,1,1);
    */
    var threshold = [3, 3, 3, 3];
    var renderParams = new glsTextureTestUtil.ReferenceParams(glsTextureTestUtil.textureType.TEXTURETYPE_CUBE);

    /** @const */ var wrapS = gl.CLAMP_TO_EDGE;
    /** @const */ var wrapT = gl.CLAMP_TO_EDGE;
    /** @const */ var minFilter = gl.NEAREST;
    /** @const */ var magFilter = gl.NEAREST;

    renderParams.flags.log_programs = true;
    renderParams.flags.log_uniforms = true;

    renderParams.samplerType = glsTextureTestUtil.getSamplerType(this.m_texture.getRefTexture().getFormat());
    renderParams.sampler = new tcuTexture.Sampler(tcuTexture.WrapMode.CLAMP_TO_EDGE, tcuTexture.WrapMode.CLAMP_TO_EDGE, tcuTexture.WrapMode.CLAMP_TO_EDGE,
     tcuTexture.FilterMode.NEAREST, tcuTexture.FilterMode.NEAREST);

    // Log render info on first face.
    if (face === tcuTexture.CubeFace.CUBEFACE_NEGATIVE_X) {
        renderParams.flags.log_programs = true;
        renderParams.flags.log_uniforms = true;
    }

    var texCoord = glsTextureTestUtil.computeQuadTexCoordCube(face);

    // log << TestLog::Message << "Texture parameters:"
    // << "\n WRAP_S = " << glu::getTextureParameterValueStr(gl.TEXTURE_WRAP_S, wrapS)
    // << "\n WRAP_T = " << glu::getTextureParameterValueStr(gl.TEXTURE_WRAP_T, wrapT)
    // << "\n MIN_FILTER = " << glu::getTextureParameterValueStr(gl.TEXTURE_MIN_FILTER, minFilter)
    // << "\n MAG_FILTER = " << glu::getTextureParameterValueStr(gl.TEXTURE_MAG_FILTER, magFilter)
    // << TestLog::EndMessage;

    // Setup base viewport.
    gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);

    // Bind to unit 0.
    gl.activeTexture(gl.TEXTURE0);
    gl.bindTexture(gl.TEXTURE_CUBE_MAP, this.m_texture.getGLTexture());

    // Setup nearest neighbor filtering and clamp-to-edge.
    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, wrapS);
    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, wrapT);
    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, minFilter);
    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, magFilter);

    es3fTextureFormatTests.GLU_EXPECT_NO_ERROR(gl.getError(), 'Set texturing state');

    // // Draw.
    this.m_renderer.renderQuad(0, texCoord, renderParams);
    gl.readPixels(viewport.x, viewport.y, viewport.width, viewport.height, gl.RGBA, gl.UNSIGNED_BYTE, renderedFrame.getAccess().getDataPtr());

    es3fTextureFormatTests.GLU_EXPECT_NO_ERROR(gl.getError(), 'glReadPixels()');

    // // Compute reference.
    glsTextureTestUtil.sampleTextureCube(new glsTextureTestUtil.SurfaceAccess(referenceFrame, undefined /*m_renderCtx.getRenderTarget().getPixelFormat()*/),
        this.m_texture.getRefTexture(), texCoord, renderParams);

    // Compare and log.
    var isOk = glsTextureTestUtil.compareImages(referenceFrame, renderedFrame, threshold);

    assertMsgOptions(isOk, 'Face: ' + this.m_curFace + ' ' + es3fTextureFormatTests.testDescription(), true, true);
    return isOk;
};

es3fTextureFormatTests.CompressedCubeFormatCase.prototype.iterate = function() {
    debug('Testing face ' + this.m_curFace);
    // Execute test for all faces.
    if (!this.testFace(this.m_curFace))
        this.m_isOk = false;

    this.m_curFace += 1;

    if (this.m_curFace < Object.keys(tcuTexture.CubeFace).length)
        return tcuTestCase.IterateResult.CONTINUE;
    else
        return tcuTestCase.IterateResult.STOP;
};

es3fTextureFormatTests.genTestCases = function() {
    var state = tcuTestCase.runner;
    state.setRoot(tcuTestCase.newTest('texture_format', 'Top level'));
    var unsizedGroup = tcuTestCase.newTest('unsized', 'Unsized formats');
    var sizedGroup = tcuTestCase.newTest('sized', 'Sized formats');
    var sized2DGroup = tcuTestCase.newTest('2d', 'Sized formats (2D)');
    var sizedCubeGroup = tcuTestCase.newTest('cube', 'Sized formats (Cubemap)');
    var sized2DArrayGroup = tcuTestCase.newTest('2d_array', 'Sized formats (2D Array)');
    var sized3DGroup = tcuTestCase.newTest('3d', 'Sized formats (3D)');
    var compressedGroup = tcuTestCase.newTest('compressed', 'Compressed formats');

    sizedGroup.addChild(sized2DGroup);
    sizedGroup.addChild(sizedCubeGroup);
    sizedGroup.addChild(sized2DArrayGroup);
    sizedGroup.addChild(sized3DGroup);

    var texFormats = [
        ['alpha', gl.ALPHA, gl.UNSIGNED_BYTE],
        ['luminance', gl.LUMINANCE, gl.UNSIGNED_BYTE],
        ['luminance_alpha', gl.LUMINANCE_ALPHA, gl.UNSIGNED_BYTE],
        ['rgb_unsigned_short_5_6_5', gl.RGB, gl.UNSIGNED_SHORT_5_6_5],
        ['rgb_unsigned_byte', gl.RGB, gl.UNSIGNED_BYTE],
        ['rgba_unsigned_short_4_4_4_4', gl.RGBA, gl.UNSIGNED_SHORT_4_4_4_4],
        ['rgba_unsigned_short_5_5_5_1', gl.RGBA, gl.UNSIGNED_SHORT_5_5_5_1],
        ['rgba_unsigned_byte', gl.RGBA, gl.UNSIGNED_BYTE]
    ];
    texFormats.forEach(function(elem) {
        var format = elem[1];
        var dataType = elem[2];
        var nameBase = elem[0];
        var descriptionBase = gluStrUtil.getPixelFormatName(format) + ', ' + gluStrUtil.getTypeName(dataType);
        unsizedGroup.addChild(new es3fTextureFormatTests.Texture2DFormatCase({
                                    name: nameBase + '_2d_pot',
                                    description: descriptionBase + ' gl.TEXTURE_2D',
                                    format: format,
                                    dataType: dataType,
                                    width: 128,
                                    height: 128
                                })
        );
        unsizedGroup.addChild(new es3fTextureFormatTests.Texture2DFormatCase({
                                                name: nameBase + '_2d_npot',
                                                description: descriptionBase + ' gl.TEXTURE_2D',
                                                        format: format,
                                                        dataType: dataType,
                                                        width: 63,
                                                        height: 112
                                                    })
        );
        unsizedGroup.addChild(new es3fTextureFormatTests.TextureCubeFormatCase({
                                                name: nameBase + '_cube_pot',
                                                description: descriptionBase + ' gl.TEXTURE_CUBE_MAP',
                                                        format: format,
                                                        dataType: dataType,
                                                        width: 64,
                                                        height: 64
                                                    })
        );
        unsizedGroup.addChild(new es3fTextureFormatTests.TextureCubeFormatCase({name: nameBase + '_cube_npot',
                                                description: descriptionBase + ' gl.TEXTURE_CUBE_MAP',
                                                        format: format,
                                                        dataType: dataType,
                                                        width: 57,
                                                        height: 57
                                                    })
        );
        unsizedGroup.addChild(new es3fTextureFormatTests.Texture2DArrayFormatCase({name: nameBase + '_2d_array_pot',
                                                description: descriptionBase + ' gl.TEXTURE_2D_ARRAY',
                                                        format: format,
                                                        dataType: dataType,
                                                        width: 64,
                                                        height: 64,
                                                        numLayers: 8
                                                    })
        );
        unsizedGroup.addChild(new es3fTextureFormatTests.Texture2DArrayFormatCase({name: nameBase + '_2d_array_npot',
                                                description: descriptionBase + ' gl.TEXTURE_2D_ARRAY',
                                                        format: format,
                                                        dataType: dataType,
                                                        width: 63,
                                                        height: 57,
                                                        numLayers: 7
                                                    })
        );
        unsizedGroup.addChild(new es3fTextureFormatTests.Texture3DFormatCase({name: nameBase + '_3d_pot',
                                                description: descriptionBase + ' gl.TEXTURE_3D',
                                                        format: format,
                                                        dataType: dataType,
                                                        width: 8,
                                                        height: 32,
                                                        depth: 16
                                                    })
        );
        unsizedGroup.addChild(new es3fTextureFormatTests.Texture3DFormatCase({name: nameBase + '_3d_npot',
                                                description: descriptionBase + ' gl.TEXTURE_3D',
                                                        format: format,
                                                        dataType: dataType,
                                                        width: 11,
                                                        height: 31,
                                                        depth: 7
                                                    })
        );
    });

    var sizedColorFormats = [
        ['rgba32f', gl.RGBA32F],
        ['rgba32i', gl.RGBA32I],
        ['rgba32ui', gl.RGBA32UI],
        ['rgba16f', gl.RGBA16F],
        ['rgba16i', gl.RGBA16I],
        ['rgba16ui', gl.RGBA16UI],
        ['rgba8', gl.RGBA8],
        ['rgba8i', gl.RGBA8I],
        ['rgba8ui', gl.RGBA8UI],
        ['srgb8_alpha8', gl.SRGB8_ALPHA8],
        ['rgb10_a2', gl.RGB10_A2],
        ['rgb10_a2ui', gl.RGB10_A2UI],
        ['rgba4', gl.RGBA4],
        ['rgb5_a1', gl.RGB5_A1],
        ['rgba8_snorm', gl.RGBA8_SNORM],
        ['rgb8', gl.RGB8],
        ['rgb565', gl.RGB565],
        ['r11f_g11f_b10f', gl.R11F_G11F_B10F],
        ['rgb32f', gl.RGB32F],
        ['rgb32i', gl.RGB32I],
        ['rgb32ui', gl.RGB32UI],
        ['rgb16f', gl.RGB16F],
        ['rgb16i', gl.RGB16I],
        ['rgb16ui', gl.RGB16UI],
        ['rgb8_snorm', gl.RGB8_SNORM],
        ['rgb8i', gl.RGB8I],
        ['rgb8ui', gl.RGB8UI],
        ['srgb8', gl.SRGB8],
        ['rgb9_e5', gl.RGB9_E5],
        ['rg32f', gl.RG32F],
        ['rg32i', gl.RG32I],
        ['rg32ui', gl.RG32UI],
        ['rg16f', gl.RG16F],
        ['rg16i', gl.RG16I],
        ['rg16ui', gl.RG16UI],
        ['rg8', gl.RG8],
        ['rg8i', gl.RG8I],
        ['rg8ui', gl.RG8UI],
        ['rg8_snorm', gl.RG8_SNORM],
        ['r32f', gl.R32F],
        ['r32i', gl.R32I],
        ['r32ui', gl.R32UI],
        ['r16f', gl.R16F],
        ['r16i', gl.R16I],
        ['r16ui', gl.R16UI],
        ['r8', gl.R8],
        ['r8i', gl.R8I],
        ['r8ui', gl.R8UI],
        ['r8_snorm', gl.R8_SNORM]
    ];

    sizedColorFormats.forEach(function(elem) {
        var internalFormat = elem[1];
        var nameBase = elem[0];
        var descriptionBase = gluStrUtil.getPixelFormatName(internalFormat);
        sized2DGroup.addChild(new es3fTextureFormatTests.Texture2DFormatCase({name: nameBase + '_pot',
                                                description: descriptionBase + ' gl.TEXTURE_2D',
                                                        format: internalFormat,
                                                        width: 128,
                                                        height: 128
                                                    })
        );
        sized2DGroup.addChild(new es3fTextureFormatTests.Texture2DFormatCase({name: nameBase + '_npot',
                                                description: descriptionBase + ' gl.TEXTURE_2D',
                                                        format: internalFormat,
                                                        width: 63,
                                                        height: 112
                                                    })
        );
        sizedCubeGroup.addChild(new es3fTextureFormatTests.TextureCubeFormatCase({name: nameBase + '_pot',
                                                description: descriptionBase + ' gl.TEXTURE_CUBE_MAP',
                                                        format: internalFormat,
                                                        width: 64,
                                                        height: 64
                                                    })
        );
        sizedCubeGroup.addChild(new es3fTextureFormatTests.TextureCubeFormatCase({name: nameBase + '_npot',
                                                description: descriptionBase + ' gl.TEXTURE_CUBE_MAP',
                                                        format: internalFormat,
                                                        width: 57,
                                                        height: 57
                                                    })
        );
        sized2DArrayGroup.addChild(new es3fTextureFormatTests.Texture2DArrayFormatCase({name: nameBase + '_pot',
                                                description: descriptionBase + ' gl.TEXTURE_2D_ARRAY',
                                                        format: internalFormat,
                                                        width: 64,
                                                        height: 64,
                                                        numLayers: 8
                                                    })
        );
        sized2DArrayGroup.addChild(new es3fTextureFormatTests.Texture2DArrayFormatCase({name: nameBase + '_npot',
                                                description: descriptionBase + ' gl.TEXTURE_2D_ARRAY',
                                                        format: internalFormat,
                                                        width: 63,
                                                        height: 57,
                                                        numLayers: 7
                                                    })
        );
        sized3DGroup.addChild(new es3fTextureFormatTests.Texture3DFormatCase({name: nameBase + '_pot',
                                                description: descriptionBase + ' gl.TEXTURE_3D',
                                                        format: internalFormat,
                                                        width: 8,
                                                        height: 32,
                                                        depth: 16
                                                    })
        );
        sized3DGroup.addChild(new es3fTextureFormatTests.Texture3DFormatCase({name: nameBase + '_npot',
                                                description: descriptionBase + ' gl.TEXTURE_3D',
                                                        format: internalFormat,
                                                        width: 11,
                                                        height: 31,
                                                        depth: 7
                                                    })
        );
    });

    var sizedDepthStencilFormats = [
        // Depth and stencil formats
        ['depth_component32f', gl.DEPTH_COMPONENT32F],
        ['depth_component24', gl.DEPTH_COMPONENT24],
        ['depth_component16', gl.DEPTH_COMPONENT16],
        ['depth32f_stencil8', gl.DEPTH32F_STENCIL8],
        ['depth24_stencil8', gl.DEPTH24_STENCIL8]
    ];
    sizedDepthStencilFormats.forEach(function(elem) {
        var internalFormat = elem[1];
        var nameBase = elem[0];
        var descriptionBase = gluStrUtil.getPixelFormatName(internalFormat);
        sized2DGroup.addChild(new es3fTextureFormatTests.Texture2DFormatCase({name: nameBase + '_pot',
                                                description: descriptionBase + ' gl.TEXTURE_2D',
                                                        format: internalFormat,
                                                        width: 128,
                                                        height: 128
                                                    })
        );
        sized2DGroup.addChild(new es3fTextureFormatTests.Texture2DFormatCase({name: nameBase + '_npot',
                                                description: descriptionBase + ' gl.TEXTURE_2D',
                                                        format: internalFormat,
                                                        width: 63,
                                                        height: 112
                                                    })
        );
        sizedCubeGroup.addChild(new es3fTextureFormatTests.TextureCubeFormatCase({name: nameBase + '_pot',
                                                description: descriptionBase + ' gl.TEXTURE_CUBE_MAP',
                                                        format: internalFormat,
                                                        width: 64,
                                                        height: 64
                                                    })
        );
        sizedCubeGroup.addChild(new es3fTextureFormatTests.TextureCubeFormatCase({name: nameBase + '_npot',
                                                description: descriptionBase + ' gl.TEXTURE_CUBE_MAP',
                                                        format: internalFormat,
                                                        width: 57,
                                                        height: 57
                                                    })
        );
        sized2DArrayGroup.addChild(new es3fTextureFormatTests.Texture2DArrayFormatCase({name: nameBase + '_pot',
                                                description: descriptionBase + ' gl.TEXTURE_2D_ARRAY',
                                                        format: internalFormat,
                                                        width: 64,
                                                        height: 64,
                                                        numLayers: 8
                                                    })
        );
        sized2DArrayGroup.addChild(new es3fTextureFormatTests.Texture2DArrayFormatCase({name: nameBase + '_npot',
                                                description: descriptionBase + ' gl.TEXTURE_2D_ARRAY',
                                                        format: internalFormat,
                                                        width: 63,
                                                        height: 57,
                                                        numLayers: 7
                                                    })
        );
    });

    var etc2Formats = [
        ['gl.COMPRESSED_R11_EAC', 'eac_r11', tcuCompressedTexture.Format.EAC_R11],
        ['gl.COMPRESSED_SIGNED_R11_EAC', 'eac_signed_r11', tcuCompressedTexture.Format.EAC_SIGNED_R11],
        ['gl.COMPRESSED_RG11_EAC', 'eac_rg11', tcuCompressedTexture.Format.EAC_RG11],
        ['gl.COMPRESSED_SIGNED_RG11_EAC', 'eac_signed_rg11', tcuCompressedTexture.Format.EAC_SIGNED_RG11],
        ['gl.COMPRESSED_RGB8_ETC2', 'etc2_rgb8', tcuCompressedTexture.Format.ETC2_RGB8],
        ['gl.COMPRESSED_SRGB8_ETC2', 'etc2_srgb8', tcuCompressedTexture.Format.ETC2_SRGB8],
        ['gl.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2', 'etc2_rgb8_punchthrough_alpha1', tcuCompressedTexture.Format.ETC2_RGB8_PUNCHTHROUGH_ALPHA1],
        ['gl.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2', 'etc2_srgb8_punchthrough_alpha1', tcuCompressedTexture.Format.ETC2_SRGB8_PUNCHTHROUGH_ALPHA1],
        ['gl.COMPRESSED_RGBA8_ETC2_EAC', 'etc2_eac_rgba8', tcuCompressedTexture.Format.ETC2_EAC_RGBA8],
        ['gl.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC', 'etc2_eac_srgb8_alpha8', tcuCompressedTexture.Format.ETC2_EAC_SRGB8_ALPHA8]
    ];
    etc2Formats.forEach(function(elem) {
        var nameBase = elem[1];
        var descriptionBase = elem[0];
        var format = elem[2];
        compressedGroup.addChild(new es3fTextureFormatTests.Compressed2DFormatCase({name: nameBase + '_2d_pot', description: descriptionBase + ', gl.TEXTURE_2D',
                                                format: format,
                                                width: 128,
                                                height: 64
                                            })
                                );
        compressedGroup.addChild(new es3fTextureFormatTests.CompressedCubeFormatCase({name: nameBase + '_cube_pot', description: descriptionBase + ', gl.TEXTURE_CUBE_MAP',
                                                format: format,
                                                width: 64,
                                                height: 64
                                            })
                                );
        compressedGroup.addChild(new es3fTextureFormatTests.Compressed2DFormatCase({name: nameBase + '_2d_pot', description: descriptionBase + ', gl.TEXTURE_2D',
                                                format: format,
                                                width: 128,
                                                height: 64
                                            })
                                );
        compressedGroup.addChild(new es3fTextureFormatTests.CompressedCubeFormatCase({name: nameBase + '_cube_npot', description: descriptionBase + ', gl.TEXTURE_CUBE_MAP',
                                                format: format,
                                                width: 51,
                                                height: 51
                                            })
                                );
    });

    state.testCases.addChild(unsizedGroup);
    state.testCases.addChild(sizedGroup);
    state.testCases.addChild(compressedGroup);
};

/**
 * Create and execute the test cases
 */
es3fTextureFormatTests.run = function(context) {
    gl = context;
    try {
        es3fTextureFormatTests.genTestCases();
        tcuTestCase.runner.runCallback(tcuTestCase.runTestCases);
    } catch (err) {
        bufferedLogToConsole(err);
        tcuTestCase.runner.terminate();
    }

};

});


text:
/*global module:false, require:false*/
var md = require('matchdep');

module.exports = function(grunt) {

	'use strict';

	var gruntfile = 'Gruntfile.js';
	var sources = ['src/<%= pkg.name %>.js'];

	md.filter('grunt-*').forEach(grunt.loadNpmTasks);

	// Project configuration.
	grunt.initConfig({
		pkg: grunt.file.readJSON('package.json'),
		meta: {
			banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
			'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
			'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
			'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author[0].name %> (<%= pkg.author[0].url %>);\n' +
			'* Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> http://deuxhuithuit.mit-license.org */\n'
		},
		concat: {
			options: {
				process: true,
				banner: '<%= meta.banner %>'
			},
			dist: {
				src: sources,
				dest: 'dist/<%= pkg.name %>.js'
			}
		},

		watch: {
			files: sources.concat(gruntfile),
			tasks: ['dev']
		},

		jshint: {
			files: sources.concat(gruntfile),
			options: {
				curly: true,
				eqeqeq: false, // allow ==
				immed: false, //
				latedef: false, // late definition
				newcap: false, // capitalize ctos
				nonew: true, // no new ..()
				noarg: true,
				sub: true,
				undef: true,
				//boss: true,
				eqnull: true, // relax
				browser: true,
				regexp: true,
				strict: true,
				trailing: false,
				smarttabs: true,
				lastsemic: true,
				globals: {
					console: true,
					jQuery: true,
					pd: true,
					_: true,
					Popcorn: true,
					DEBUG: true,
					CSS3: true,
					JSON: true
				}
			}
		},
		uglify: {
			prod: {
				files: {
					'dist/<%= pkg.name %>.min.js': '<%= concat.dist.dest %>'
				}
			},
			options: {
				banner: '<%= meta.banner %>',
				report: 'gzip',
				sourceMap: 'dist/<%= pkg.name %>.min.js.map',
				sourceMappingURL: '<%= pkg.name %>.min.js.map',
				sourceMapRoot: '../',
				mangle: true,
				compress: {
					global_defs: {
						DEBUG: false
					},
					dead_code: true,
					unused: true,
					warnings: true
				}
			}
		},

		complexity: {
			generic: {
				src: sources,
				options: {
					//jsLintXML: 'report.xml', // create XML JSLint-like report
					errorsOnly: false, // show only maintainability errors
					cyclomatic: 10, // 3
					halstead: 20, // 8
					maintainability: 95 //100
				}
			}
		}
	});

	// fix source map url
	grunt.registerTask('fix-source-map', 'Fix the wrong file path in the source map', function() {
		var sourceMapPath = grunt.template.process('<%= uglify.options.sourceMap %>');
		var sourceMapUrl = grunt.template.process('<%= uglify.options.sourceMappingURL %>');
		var diff = sourceMapPath.replace(sourceMapUrl, '');
		var sourceMap = grunt.file.readJSON(sourceMapPath);
		sourceMap.file = sourceMap.file.replace(diff, '');
		var newSources = [];
		sourceMap.sources.forEach(function (elem) {
			newSources.push(elem.replace(diff, ''));
		});
		sourceMap.sources = newSources;
		grunt.log.write(sourceMap.sources);
		grunt.file.write(sourceMapPath, JSON.stringify(sourceMap));
	});

	// Default tasks.
	grunt.registerTask('dev', ['jshint','complexity']);
	grunt.registerTask('build', ['concat','uglify','fix-source-map']);
	grunt.registerTask('default', ['dev','build']);
};

redpajama_set_name: RedPajamaGithub


text:
package DDG::Spice::RubyGems;
# ABSTRACT: Search for RubyGems

use strict;
use DDG::Spice;

triggers startend => 'rubygem', 'rubygems', 'ruby gems', 'ruby gem', 'gem install', 'gem';
spice to => 'https://rubygems.org/api/v1/search.json?query=$1';
spice wrap_jsonp_callback => 1;

handle remainder => sub {
    return $_ if length $_;
    return;
};

1;


text:
Plugin.define "phxEventManager" do
author "Brendan Coles <bcoles@gmail.com>" # 2012-03-03
version "0.1"
description "phxEventManager is an event resource calendar system designed to manage all aspects of an occasion."
website "http://phxeventmanager.com/"

# Google results as at 2012-03-03 #
# 114 for intext:"Powered by phxEventManager" -intext

# Dorks #
dorks [
'intext:"Powered by phxEventManager" -intext'
]

# Matches #
matches [

# div class="minicalmonth"
{ :text=>'
75, :text=>'' },

# Footer # Version Detection
{ :version=>/
\s+Copyright © 20[\d]{2}[^\n]+\s+Powered by phxEventManager ([^<]+)
/ },

]

end


text:
// Copyright 2014 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.build.lib.rules.java;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.packages.BuiltinProvider;
import com.google.devtools.build.lib.packages.NativeInfo;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization;
import com.google.devtools.build.lib.skylarkbuildapi.core.ProviderApi;
import com.google.devtools.build.lib.skylarkinterface.Param;
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.Location;
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.StarlarkThread;
import com.google.devtools.build.lib.syntax.StarlarkValue;
import java.util.List;
import javax.annotation.Nullable;

/** Marks configured targets that are able to supply message bundles to their dependents. */
@AutoCodec
@Immutable
public final class MessageBundleInfo extends NativeInfo implements StarlarkValue {

  public static final String SKYLARK_NAME = "MessageBundleInfo";

  /** Provider singleton constant. */
  public static final BuiltinProvider<MessageBundleInfo> PROVIDER = new Provider();

  /** Provider class for {@link MessageBundleInfo} objects. */
  @SkylarkModule(name = "Provider", documented = false, doc = "")
  public static class Provider extends BuiltinProvider<MessageBundleInfo> implements ProviderApi {
    private Provider() {
      super(SKYLARK_NAME, MessageBundleInfo.class);
    }

    @SkylarkCallable(
        name = "MessageBundleInfo",
        doc = "The MessageBundleInfo constructor.",
        documented = false,
        parameters = {
          @Param(name = "messages", positional = false, named = true, type = Sequence.class),
        },
        selfCall = true,
        useStarlarkThread = true)
    public MessageBundleInfo messageBundleInfo(Sequence<?> messages, StarlarkThread thread)
        throws EvalException {
      List<Artifact> messagesList = Sequence.castList(messages, Artifact.class, "messages");
      return new MessageBundleInfo(ImmutableList.copyOf(messagesList), thread.getCallerLocation());
    }
  }

  private final ImmutableList<Artifact> messages;

  public static MessageBundleInfo create(ImmutableList<Artifact> messages) {
    return new MessageBundleInfo(messages, null);
  }

  @VisibleForSerialization
  @AutoCodec.Instantiator
  MessageBundleInfo(ImmutableList<Artifact> messages, Location location) {
    super(PROVIDER, location);
    this.messages = Preconditions.checkNotNull(messages);
  }

  public ImmutableList<Artifact> getMessages() {
    return messages;
  }

  @Nullable
  public static ImmutableList<Artifact> getMessages(TransitiveInfoCollection info) {
    MessageBundleInfo messageBundleInfo =
        (MessageBundleInfo) info.get(MessageBundleInfo.PROVIDER.getKey());
    if (messageBundleInfo != null) {
      return messageBundleInfo.getMessages();
    }
    return null;
  }
}


text:
SYNONYM

#### According to
The Catalogue of Life, 3rd January 2011

#### Published in
Bull. Torrey bot. Club 33: 422 (1906)

#### Original name
Peridermium mexicanum Arthur & F. Kern, 1906

### Remarks
null


text:
IF EXISTS (
  SELECT * FROM INFORMATION_SCHEMA.ROUTINES
   WHERE SPECIFIC_SCHEMA = N'dbo'
     AND SPECIFIC_NAME = N'GetComment'
)
BEGIN
 PRINT N'Dropping Procedure dbo.GetComment'
 DROP PROCEDURE dbo.GetComment
END
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
-- GetComment 1

PRINT 'Creating Procedure dbo.GetComment'
GO

CREATE PROCEDURE GetComment
(
	@CommentID INT
)
AS

SET NOCOUNT ON

--TRUNCATION HACK
SET ANSI_WARNINGS OFF

SELECT Comment, CleanedComment
FROM Comment
WHERE CommentID = @CommentID

GO

GRANT EXECUTE ON GetComment to public
GO


text:
/**
 * ENTRY SCRIPT
 */

// TODO: configure prod build
if (process.env.NODE_ENV === 'production') {
    console.log('PROD MODE!');
} else {
    require('babel-register');
    require('babel-polyfill');
    require('./server/server.js');
}


text:
ACCEPTED

#### According to
Index Fungorum

#### Published in
null

#### Original name
Eudarluca indica Ramakr. {?}

### Remarks
null


text:
import React from 'react';
import uriParser from '../util/uri-parser';
import Avatar from './avatar';
import TimeAgo from './time-ago';

const Post = ({ post }) => {
  const link = (post.url) ? uriParser(post.url).host : null;
  const title = (link) ? (

{post.title}

      {link} ↵

  ) : (

{post.title}

  );

  return (

{title}

        <Avatar user={post.user} />

          {post.user.name}
          <TimeAgo timestamp={post.created} />

  );
};

Post.propTypes = {
  post: React.PropTypes.shape({
    title: React.PropTypes.string.isRequired,
    body: React.PropTypes.string.isRequired,
    url: React.PropTypes.string,
    created: React.PropTypes.number.isRequired,
    user: React.PropTypes.shape({
      name: React.PropTypes.string.isRequired,
      color: React.PropTypes.string.isRequired,
    }),
  }),
};

export default Post;


text:
import numpy as np

from ray.rllib.models.modelv2 import ModelV2
from ray.rllib.models.preprocessors import get_preprocessor
from ray.rllib.models.tf.recurrent_net import RecurrentNetwork
from ray.rllib.models.torch.recurrent_net import RecurrentNetwork as TorchRNN
from ray.rllib.utils.annotations import override
from ray.rllib.utils.framework import try_import_tf, try_import_torch

tf1, tf, tfv = try_import_tf()
torch, nn = try_import_torch()

class RNNModel(RecurrentNetwork):
    """Example of using the Keras functional API to define a RNN model."""

    def __init__(self,
                 obs_space,
                 action_space,
                 num_outputs,
                 model_config,
                 name,
                 hiddens_size=256,
                 cell_size=64):
        super(RNNModel, self).__init__(obs_space, action_space, num_outputs,
                                       model_config, name)
        self.cell_size = cell_size

        # Define input layers
        input_layer = tf.keras.layers.Input(
            shape=(None, obs_space.shape[0]), name="inputs")
        state_in_h = tf.keras.layers.Input(shape=(cell_size, ), name="h")
        state_in_c = tf.keras.layers.Input(shape=(cell_size, ), name="c")
        seq_in = tf.keras.layers.Input(shape=(), name="seq_in", dtype=tf.int32)

        # Preprocess observation with a hidden layer and send to LSTM cell
        dense1 = tf.keras.layers.Dense(
            hiddens_size, activation=tf.nn.relu, name="dense1")(input_layer)
        lstm_out, state_h, state_c = tf.keras.layers.LSTM(
            cell_size, return_sequences=True, return_state=True, name="lstm")(
                inputs=dense1,
                mask=tf.sequence_mask(seq_in),
                initial_state=[state_in_h, state_in_c])

        # Postprocess LSTM output with another hidden layer and compute values
        logits = tf.keras.layers.Dense(
            self.num_outputs,
            activation=tf.keras.activations.linear,
            name="logits")(lstm_out)
        values = tf.keras.layers.Dense(
            1, activation=None, name="values")(lstm_out)

        # Create the RNN model
        self.rnn_model = tf.keras.Model(
            inputs=[input_layer, seq_in, state_in_h, state_in_c],
            outputs=[logits, values, state_h, state_c])
        self.rnn_model.summary()

    @override(RecurrentNetwork)
    def forward_rnn(self, inputs, state, seq_lens):
        model_out, self._value_out, h, c = self.rnn_model([inputs, seq_lens] +
                                                          state)
        return model_out, [h, c]

    @override(ModelV2)
    def get_initial_state(self):
        return [
            np.zeros(self.cell_size, np.float32),
            np.zeros(self.cell_size, np.float32),
        ]

    @override(ModelV2)
    def value_function(self):
        return tf.reshape(self._value_out, [-1])

class TorchRNNModel(TorchRNN, nn.Module):
    def __init__(self,
                 obs_space,
                 action_space,
                 num_outputs,
                 model_config,
                 name,
                 fc_size=64,
                 lstm_state_size=256):
        nn.Module.__init__(self)
        super().__init__(obs_space, action_space, num_outputs, model_config,
                         name)

        self.obs_size = get_preprocessor(obs_space)(obs_space).size
        self.fc_size = fc_size
        self.lstm_state_size = lstm_state_size

        # Build the Module from fc + LSTM + 2xfc (action + value outs).
        self.fc1 = nn.Linear(self.obs_size, self.fc_size)
        self.lstm = nn.LSTM(
            self.fc_size, self.lstm_state_size, batch_first=True)
        self.action_branch = nn.Linear(self.lstm_state_size, num_outputs)
        self.value_branch = nn.Linear(self.lstm_state_size, 1)
        # Holds the current "base" output (before logits layer).
        self._features = None

    @override(ModelV2)
    def get_initial_state(self):
        # TODO: (sven): Get rid of `get_initial_state` once Trajectory
        #  View API is supported across all of RLlib.
        # Place hidden states on same device as model.
        h = [
            self.fc1.weight.new(1, self.lstm_state_size).zero_().squeeze(0),
            self.fc1.weight.new(1, self.lstm_state_size).zero_().squeeze(0)
        ]
        return h

    @override(ModelV2)
    def value_function(self):
        assert self._features is not None, "must call forward() first"
        return torch.reshape(self.value_branch(self._features), [-1])

    @override(TorchRNN)
    def forward_rnn(self, inputs, state, seq_lens):
        """Feeds `inputs` (B x T x ..) through the Gru Unit.

        Returns the resulting outputs as a sequence (B x T x ...).
        Values are stored in self._cur_value in simple (B) shape (where B
        contains both the B and T dims!).

        Returns:
            NN Outputs (B x T x ...) as sequence.
            The state batches as a List of two items (c- and h-states).
        """
        x = nn.functional.relu(self.fc1(inputs))
        self._features, [h, c] = self.lstm(
            x, [torch.unsqueeze(state[0], 0),
                torch.unsqueeze(state[1], 0)])
        action_out = self.action_branch(self._features)
        return action_out, [torch.squeeze(h, 0), torch.squeeze(c, 0)]


text:
/*****************************************************************************/
/* Companies: Event Handlers */
/*****************************************************************************/
Template.Companies.events({
  'click .reactive-table tbody tr': function(event) {
    var company = this;
    Session.set('company', company);
  }
});

/*****************************************************************************/
/* Companies: Helpers */
/*****************************************************************************/
Template.Companies.helpers({
  companies: function() {
    return Companies.find({});
  },
  companiesCollction: function() {
    return Companies;
  },
  companiesTableSettings: function() {
    return {
      collection: Companies,
      rowsPerPage: 10,
      showFilter: true,
      fields: [{
        key: 'name',
        label: 'Company name'
      }]
    };
  },
  selectedCompany: function() {
    var company = Session.get('company');
    if (company) {
      return Companies.findOne({
        name: company.name
      })
    } else {
      Companies.findOne();
    }
  },
  tableSettings: function() {
    return {
      currentPage: Template.instance().currentPage
    };
  }
});

/*****************************************************************************/
/* Companies: Lifecycle Hooks */
/*****************************************************************************/
Template.Companies.onCreated(function() {
  var currentPage = new ReactiveVar(Session.get('current-page') || 0);
  this.currentPage = currentPage;
  this.autorun(function() {
    Session.set('current-page', currentPage.get());
  });
});

Template.Companies.onRendered(function() {});

Template.Companies.onDestroyed(function() {});

Template.companyNavItems.helpers({
  activeIfTemplateIs: function(template) {
    var currentRoute = Router.current();
    return currentRoute &&
      template === currentRoute.lookupTemplate() ? 'active' : '';
  }
});


text:
title: "camunda Modeler 2.3.0 released: Custom Tasks, Form Fields and better Subprocess Modeling"
date: "2013-12-05"
author: "Nico Rehwaldt"

categories:
  - "Execution"
tags:
  - "Camunda Modeler Eclipse Plug-in"
  - "Release Note"

aliases:
  - "/2013/12/camunda-Modeler-2-3-0-released.html"

---

We are happy to announce the new release of the camunda Modeler. This version adds the ability to extend the modeler with custom tasks. Furthermore it adds editing support for form fields that were recently re-introduced into the camunda BPM platform. Last but not least, it improves the handling of subprocesses.

Custom Task Plugins

Custom task plugins give you the ability to contribute self-made tasks to the camunda modeler.

{{
}}
A custom task is a task that may be reused across all of your diagrams. It can ship with a predefined configuration, can have a customized look and feel and integrates into the palette as well as the properties panel.

Check out our custom task example that show cases what is possible with custom tasks. Head over to the how to section if you want to build your own custom tasks right away.

Form Field Editing

You are now able to edit form fields for via the property panel. Check out Daniels introduction on generated forms to get more context on the topic.

Subprocess Improvements

For everyone modeling subprocesses out there, there is good news. You may now safely expand and collapse subprocesses. Internal layout of children will be retained. Import and export, work, too.

Do it

We fixed a number of bugs, too, including the sudden popup of error markers on BPMN 2.0 diagrams.

Checkout the complete list of issues solved in this release. And of course, try out the new modeler and tell us what you thing via our forums or on twitter.

Thanks go to Christian, Daniel and Michael for getting this Release through QA.