code: def test_use_texture3D():
      """Test using a 3D texture"""
      vals = [0, 200, 100, 0, 255, 0, 100]
      d, h, w = len(vals), 3, 5
      data = np.zeros((d, h, w), np.float32)
  
      VERT_SHADER = """
      attribute vec2 a_pos;
      varying vec2 v_pos;
  
      void main (void)
      {
          v_pos = a_pos;
          gl_Position = vec4(a_pos, 0., 1.);
      }
      """
  
      FRAG_SHADER = """
      uniform sampler3D u_texture;
      varying vec2 v_pos;
      uniform float i;
      void main()
      {
          gl_FragColor = texture3D(u_texture,
                                   vec3((v_pos.y+1.)/2., (v_pos.x+1.)/2., i));
          gl_FragColor.a = 1.;
      }
      """
      # populate the depth "slices" with different gray colors in the bottom left
      for ii, val in enumerate(vals):
          data[ii, :2, :3] = val / 255.0
      with Canvas(size=(100, 100)) as c:
          if not has_pyopengl():
              t = Texture3D(data)
              assert_raises(
                  ImportError, t.glir.flush, c.context.shared.parser
              )
              return
          program = Program(VERT_SHADER, FRAG_SHADER)
          program["a_pos"] = [
              [-1.0, -1.0],
              [1.0, -1.0],
              [-1.0, 1.0],
              [1.0, 1.0],
          ]
          tex = Texture3D(data, interpolation="nearest")
          assert_equal(tex.width, w)
          assert_equal(tex.height, h)
          assert_equal(tex.depth, d)
          program["u_texture"] = tex
          for ii, val in enumerate(vals):
              set_viewport(0, 0, w, h)
              clear(color="black")
              iii = (ii + 0.5) / float(d)
              print(ii, iii)
              program["i"] = iii
              program.draw("triangle_strip")
              out = _screenshot()[:, :, 0].astype(int)[::-1]
              expected = np.zeros_like(out)
              expected[:2, :3] = val
              assert_allclose(out, expected, atol=1.0 / 255.0)
  
file_path: vispy/vispy/gloo/tests/test_use_gloo.py
imports: import sys
  import numpy
  from numpy.testing import assert_allclose
  import pytest
  from vispy.app import Canvas
  from vispy.gloo import Texture2D, Texture3D, Program, FrameBuffer, RenderBuffer, set_viewport, clear
  from vispy.gloo.util import draw_texture, _screenshot
  from vispy.testing import requires_application, has_pyopengl, run_tests_if_main, assert_raises, assert_equal, IS_TRAVIS_CI
label_desc: Use image node_id 3 for calling a global function with example usage: test_use_texture3D() without return types