summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/js/tests/gl-enum-tests.js
blob: 32d451f7a2ccf91131e24816534821ddb42f9c5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
Copyright (c) 2019 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
*/

// This test relies on the surrounding web page defining a variable
// "contextVersion" which indicates what version of WebGL it's running
// on -- 1 for WebGL 1.0, 2 for WebGL 2.0, etc.

"use strict";
description("This test ensures various WebGL functions fail when passed invalid OpenGL ES enums.");

debug("");
debug("Canvas.getContext");

var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("canvas", undefined, contextVersion);
if (!gl) {
  testFailed("context does not exist");
} else {
  testPassed("context exists");

  debug("");
  debug("Checking gl enums.");

  var buffer = new ArrayBuffer(2);
  var buf = new Uint16Array(buffer);
  var tex = gl.createTexture();
  var program = wtu.createProgram(gl, wtu.loadStandardVertexShader(gl), wtu.loadStandardFragmentShader(gl));
  gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
  wtu.glErrorShouldBe(gl, gl.NO_ERROR);

  var tests = [
    "gl.disable(desktopGL['CLIP_PLANE0'])",
    "gl.disable(desktopGL['POINT_SPRITE'])",
    "gl.getBufferParameter(gl.ARRAY_BUFFER, desktopGL['PIXEL_PACK_BUFFER'])",
    "gl.hint(desktopGL['PERSPECTIVE_CORRECTION_HINT'], gl.FASTEST)",
    "gl.isEnabled(desktopGL['CLIP_PLANE0'])",
    "gl.isEnabled(desktopGL['POINT_SPRITE'])",
    "gl.pixelStorei(desktopGL['PACK_SWAP_BYTES'], 1)",
    "gl.getParameter(desktopGL['NUM_COMPRESSED_TEXTURE_FORMATS'])",
    "gl.getParameter(desktopGL['EXTENSIONS'])",
    "gl.getParameter(desktopGL['SHADER_COMPILER'])",
    "gl.getParameter(desktopGL['SHADER_BINARY_FORMATS'])",
    "gl.getParameter(desktopGL['NUM_SHADER_BINARY_FORMATS'])",
  ];

  if (contextVersion < 2) {
    tests = tests.concat([
      "gl.blendEquation(desktopGL['MIN'])",
      "gl.blendEquation(desktopGL['MAX'])",
      "gl.blendEquationSeparate(desktopGL['MIN'], gl.FUNC_ADD)",
      "gl.blendEquationSeparate(desktopGL['MAX'], gl.FUNC_ADD)",
      "gl.blendEquationSeparate(gl.FUNC_ADD, desktopGL['MIN'])",
      "gl.blendEquationSeparate(gl.FUNC_ADD, desktopGL['MAX'])",
      "gl.bufferData(gl.ARRAY_BUFFER, 16, desktopGL['STREAM_READ'])",
      "gl.bufferData(gl.ARRAY_BUFFER, 16, desktopGL['STREAM_COPY'])",
      "gl.bufferData(gl.ARRAY_BUFFER, 16, desktopGL['STATIC_READ'])",
      "gl.bufferData(gl.ARRAY_BUFFER, 16, desktopGL['STATIC_COPY'])",
      "gl.bufferData(gl.ARRAY_BUFFER, 16, desktopGL['DYNAMIC_READ'])",
      "gl.bufferData(gl.ARRAY_BUFFER, 16, desktopGL['DYNAMIC_COPY'])",
      "gl.bindTexture(desktopGL['TEXTURE_2D_ARRAY'], tex)",
      "gl.bindTexture(desktopGL['TEXTURE_3D'], tex)",
    ]);
  } else {
    tests = tests.concat([
      "gl.bindTexture(desktopGL['TEXTURE_RECTANGLE_EXT'], tex)",
      "gl.enable(desktopGL['PRIMITIVE_RESTART_FIXED_INDEX'])",
      "gl.getActiveUniforms(program, [0], desktopGL['UNIFORM_NAME_LENGTH'])",
      "gl.getProgramParameter(program, desktopGL['ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH'])",
      "gl.getProgramParameter(program, desktopGL['TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH'])",
      "gl.getProgramParameter(program, desktopGL['PROGRAM_BINARY_RETRIEVABLE_HINT'])",
      "gl.getProgramParameter(program, desktopGL['PROGRAM_BINARY_LENGTH'])",
      "gl.getParameter(program, desktopGL['NUM_PROGRAM_BINARY_FORMATS'])",
    ]);
  }

  for (var ii = 0; ii < tests.length; ++ii) {
    TestEval(tests[ii]);
    wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, tests[ii] + " should return INVALID_ENUM.");
  }

  gl.bindTexture(gl.TEXTURE_2D, tex);
  wtu.glErrorShouldBe(gl, gl.NO_ERROR);

  tests = [
    "gl.getTexParameter(gl.TEXTURE_2D, desktopGL['GENERATE_MIPMAP'])",
    "gl.texParameteri(gl.TEXTURE_2D, desktopGL['GENERATE_MIPMAP'], 1)",
    "gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, desktopGL['CLAMP_TO_BORDER'])",
  ];

  if (contextVersion < 2) {
    tests = tests.concat([
      "gl.texParameteri(desktopGL['TEXTURE_2D_ARRAY'], gl.TEXTURE_MAG_FILTER, gl.NEAREST)",
      "gl.texParameteri(desktopGL['TEXTURE_3D'], gl.TEXTURE_MAG_FILTER, gl.NEAREST)",
    ]);
  } else {
    tests = tests.concat([
      "gl.texParameteri(desktopGL['TEXTURE_2D'], desktopGL['TEXTURE_SWIZZLE_R_EXT'], gl.RED)",
      "gl.texParameteri(desktopGL['TEXTURE_2D'], desktopGL['TEXTURE_SWIZZLE_G_EXT'], gl.RED)",
      "gl.texParameteri(desktopGL['TEXTURE_2D'], desktopGL['TEXTURE_SWIZZLE_B_EXT'], gl.RED)",
      "gl.texParameteri(desktopGL['TEXTURE_2D'], desktopGL['TEXTURE_SWIZZLE_A_EXT'], gl.RED)",
      "gl.texParameteri(desktopGL['TEXTURE_2D'], gl.TEXTURE_WRAP_R, desktopGL['CLAMP_TO_BORDER'])",
    ]);
  }

  for (var ii = 0; ii < tests.length; ++ii) {
    TestEval(tests[ii]);
    wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, tests[ii] + " should return INVALID_ENUM.");
  }
  if (contextVersion >= 2) {
    var uniformBlockProgram = wtu.loadUniformBlockProgram(gl);
    gl.linkProgram(uniformBlockProgram);
    shouldBe('gl.getProgramParameter(uniformBlockProgram, gl.LINK_STATUS)', 'true');
    shouldBe('gl.getError()', 'gl.NO_ERROR');
    gl.getActiveUniformBlockParameter(uniformBlockProgram, 0, desktopGL['UNIFORM_BLOCK_NAME_LENGTH']);
    shouldBe('gl.getError()', 'gl.INVALID_ENUM');
  }
}

debug("");
var successfullyParsed = true;