當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript OneDimensionalTextureAccessHelper.setupTextureLayout方法代碼示例

本文整理匯總了TypeScript中neuroglancer/webgl/one_dimensional_texture_access.OneDimensionalTextureAccessHelper.setupTextureLayout方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript OneDimensionalTextureAccessHelper.setupTextureLayout方法的具體用法?TypeScript OneDimensionalTextureAccessHelper.setupTextureLayout怎麽用?TypeScript OneDimensionalTextureAccessHelper.setupTextureLayout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在neuroglancer/webgl/one_dimensional_texture_access.OneDimensionalTextureAccessHelper的用法示例。


在下文中一共展示了OneDimensionalTextureAccessHelper.setupTextureLayout方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: setupTextureLayout

 /**
  * Called each time textureLayout changes while drawing chunks.
  */
 setupTextureLayout(gl: GL, shader: ShaderProgram, textureLayout: TextureLayout) {
   if (this.numChannels > 1) {
     gl.uniform1f(shader.uniform('uChannelStride'), textureLayout.channelStride);
   }
   this.textureAccessHelper.setupTextureLayout(gl, shader, textureLayout);
 }
開發者ID:funkey,項目名稱:neuroglancer,代碼行數:9,代碼來源:uncompressed_chunk_format.ts

示例2: setupTextureLayout

 /**
  * Called each time textureLayout changes while drawing chunks.
  */
 setupTextureLayout(gl: GL, shader: ShaderProgram, textureLayout: TextureLayout) {
   gl.uniform3fv(shader.uniform('uSubchunkGridSize'), textureLayout.subchunkGridSize);
   this.textureAccessHelper.setupTextureLayout(gl, shader, textureLayout);
 }
開發者ID:funkey,項目名稱:neuroglancer,代碼行數:7,代碼來源:chunk_format.ts

示例3: fragmentShaderTest

  fragmentShaderTest(6, tester => {
    let {gl, builder} = tester;
    const dataType = DataType.UINT32;
    const numComponents = 1;
    const format = new OneDimensionalTextureFormat();
    const layout = new OneDimensionalTextureLayout();
    compute1dTextureFormat(format, dataType, numComponents);

    const data = new Uint32Array(dataLength);
    for (let i = 0; i < data.length; ++i) {
      data[i] = i;
    }

    setLayout(layout, gl, format.texelsPerElement);

    const accessHelper = new OneDimensionalTextureAccessHelper('textureAccess');
    const textureUnitSymbol = Symbol('textureUnit');
    accessHelper.defineShader(builder);
    builder.addUniform('highp float', 'uOffset');
    builder.addUniform('highp vec4', 'uExpected');
    builder.addTextureSampler2D('uSampler', textureUnitSymbol);
    builder.addFragmentCode(
        accessHelper.getAccessor('readValue', 'uSampler', dataType, numComponents));
    builder.addFragmentCode(glsl_unnormalizeUint8);
    builder.addFragmentCode(glsl_uintleToFloat);
    builder.addOutputBuffer('vec4', 'v4f_fragData0', 0);
    builder.addOutputBuffer('vec4', 'v4f_fragData1', 1);
    builder.addOutputBuffer('vec4', 'v4f_fragData2', 2);
    builder.addOutputBuffer('vec4', 'v4f_fragData3', 3);
    builder.addOutputBuffer('vec4', 'v4f_fragData4', 4);
    builder.addOutputBuffer('vec4', 'v4f_fragData5', 5);
    builder.setFragmentMain(`
uint32_t value = readValue(uOffset);
v4f_fragData4 = packFloatIntoVec4(uintleToFloat(value.value.xyz));
v4f_fragData5 = packFloatIntoVec4(all(equal(value.value, uExpected)) ? 1.0 : 0.0);
value.value = unnormalizeUint8(value.value);
v4f_fragData0 = packFloatIntoVec4(value.value.x);
v4f_fragData1 = packFloatIntoVec4(value.value.y);
v4f_fragData2 = packFloatIntoVec4(value.value.z);
v4f_fragData3 = packFloatIntoVec4(value.value.w);
`);

    tester.build();
    let {shader} = tester;
    shader.bind();

    accessHelper.setupTextureLayout(gl, shader, layout);

    const textureUnit = shader.textureUnit(textureUnitSymbol);
    let texture = gl.createTexture();
    tester.registerDisposer(() => {
      gl.deleteTexture(texture);
    });
    gl.bindTexture(gl.TEXTURE_2D, texture);
    setOneDimensionalTextureData(gl, layout, format, data);
    gl.bindTexture(gl.TEXTURE_2D, null);

    function testOffset(x: number) {
      let value = data[x];
      gl.uniform1f(shader.uniform('uOffset'), x);
      gl.uniform4fv(shader.uniform('uExpected'), setVec4FromUint32(new Float32Array(4), value));

      gl.activeTexture(gl.TEXTURE0 + textureUnit);
      gl.bindTexture(gl.TEXTURE_2D, texture);
      tester.execute();
      gl.bindTexture(gl.TEXTURE_2D, null);

      let actual = new Float32Array(4);
      let expected = new Float32Array(4);
      for (let i = 0; i < 4; ++i) {
        actual[i] = tester.readFloat(i);
        expected[i] = (value >>> (8 * i)) & 0xFF;
      }
      for (let i = 0; i < 4; ++i) {
        expect(actual[i]).toBe(
            expected[i],
            `offset = ${x}, value = ${x}, actual = ${Array.from(actual)}, expected = ${
                Array.from(expected)}`);
      }
      expect(tester.readFloat(4))
          .toBe(value, `uint24le value != expected, offset = ${x}, value = ${x}`);
      expect(tester.readFloat(5))
          .toBe(1.0, `uExpected != value in shader, offset = ${x}, value = ${x}`);
    }

    testOffset(255 /*+ 256 * 256 * 9*/);
    for (let i = 0; i < 100; ++i) {
      testOffset(i);
    }

    const COUNT = 100;
    for (let i = 0; i < COUNT; ++i) {
      let offset = Math.floor(Math.random() * data.length);
      testOffset(offset);
    }
  });
開發者ID:stephenplaza,項目名稱:neuroglancer,代碼行數:96,代碼來源:one_dimensional_texture_access.spec.ts


注:本文中的neuroglancer/webgl/one_dimensional_texture_access.OneDimensionalTextureAccessHelper.setupTextureLayout方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。