| 62 | } |
| 63 | |
| 64 | int main() { |
| 65 | EmscriptenWebGLContextAttributes attrs; |
| 66 | emscripten_webgl_init_context_attributes(&attrs); |
| 67 | |
| 68 | attrs.enableExtensionsByDefault = 1; |
| 69 | attrs.majorVersion = 2; |
| 70 | attrs.minorVersion = 0; |
| 71 | |
| 72 | /* Skip WebGL 2 tests if not supported */ |
| 73 | EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context("#canvas", &attrs); |
| 74 | if (!context) { |
| 75 | printf("Skipped: WebGL 2 is not supported.\n"); |
| 76 | return 0; |
| 77 | } |
| 78 | emscripten_webgl_make_context_current(context); |
| 79 | |
| 80 | /* Generate a query */ |
| 81 | GL_CALL(glGenQueries(2, &sampleQuery)); |
| 82 | assert(sampleQuery); |
| 83 | |
| 84 | /* Begin it */ |
| 85 | GL_CALL(glBeginQuery(GL_ANY_SAMPLES_PASSED, sampleQuery)); |
| 86 | |
| 87 | /* Now, `sampleQuery` should be a query */ |
| 88 | bool isQuery = false; |
| 89 | GL_CALL(isQuery = glIsQuery(sampleQuery)); |
| 90 | assert(isQuery); |
| 91 | |
| 92 | /* Do a draw to actually have something in the queue */ |
| 93 | GLuint vert = compile_shader(GL_VERTEX_SHADER, |
| 94 | "#version 300 es\n" |
| 95 | "in vec4 position;\n" |
| 96 | "void main() {\n" |
| 97 | " gl_Position = position;\n" |
| 98 | "}\n"); |
| 99 | GLuint frag = compile_shader(GL_FRAGMENT_SHADER, |
| 100 | "#version 300 es\n" |
| 101 | "precision lowp float;\n" |
| 102 | "out vec4 color;\n" |
| 103 | "void main() {\n" |
| 104 | " color = vec4(1.0, 0.3, 0.1, 1.0);\n" |
| 105 | "}\n"); |
| 106 | GLuint program = create_program(vert, frag); |
| 107 | GL_CALL(glUseProgram(program)); |
| 108 | const float positions[] = { |
| 109 | -0.5f, -0.5f, 0.0f, |
| 110 | 0.5f, -0.5f, 0.0f, |
| 111 | 0.0f, 0.5f, 0.0f |
| 112 | }; |
| 113 | GLuint vertices; |
| 114 | GL_CALL(glGenBuffers(1, &vertices)); |
| 115 | GL_CALL(glBindBuffer(GL_ARRAY_BUFFER, vertices)); |
| 116 | GL_CALL(glBufferData(GL_ARRAY_BUFFER, sizeof(positions), positions, GL_STATIC_DRAW)); |
| 117 | GL_CALL(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 12, 0)); |
| 118 | GL_CALL(glEnableVertexAttribArray(0)); |
| 119 | GL_CALL(glClearColor(0.5f, 0.7f, 0.9f, 1.0f)); |
| 120 | GL_CALL(glClear(GL_COLOR_BUFFER_BIT)); |
| 121 | GL_CALL(glDrawArrays(GL_TRIANGLES, 0, 3)); |
nothing calls this directly
no test coverage detected