| 45 | } |
| 46 | |
| 47 | int main() { |
| 48 | EmscriptenWebGLContextAttributes attr; |
| 49 | emscripten_webgl_init_context_attributes(&attr); |
| 50 | #ifdef EXPLICIT_SWAP |
| 51 | attr.explicitSwapControl = 1; |
| 52 | #endif |
| 53 | #ifdef DRAW_FROM_CLIENT_MEMORY |
| 54 | // This test verifies that drawing from client-side memory when enableExtensionsByDefault==false works. |
| 55 | attr.enableExtensionsByDefault = 0; |
| 56 | #endif |
| 57 | |
| 58 | EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context("#canvas", &attr); |
| 59 | emscripten_webgl_make_context_current(ctx); |
| 60 | |
| 61 | static const char vertex_shader[] = |
| 62 | "attribute vec4 apos;" |
| 63 | "attribute vec4 acolor;" |
| 64 | "varying vec4 color;" |
| 65 | "void main() {" |
| 66 | "color = acolor;" |
| 67 | "gl_Position = apos;" |
| 68 | "}"; |
| 69 | GLuint vs = compile_shader(GL_VERTEX_SHADER, vertex_shader); |
| 70 | |
| 71 | static const char fragment_shader[] = |
| 72 | "precision lowp float;" |
| 73 | "varying vec4 color;" |
| 74 | "void main() {" |
| 75 | "gl_FragColor = color;" |
| 76 | "}"; |
| 77 | GLuint fs = compile_shader(GL_FRAGMENT_SHADER, fragment_shader); |
| 78 | |
| 79 | GLuint program = create_program(vs, fs); |
| 80 | glUseProgram(program); |
| 81 | |
| 82 | static const float pos_and_color[] = { |
| 83 | // x, y, r, g, b |
| 84 | -0.6f, -0.6f, 1, 0, 0, |
| 85 | 0.6f, -0.6f, 0, 1, 0, |
| 86 | 0.f, 0.6f, 0, 0, 1, |
| 87 | }; |
| 88 | |
| 89 | #ifdef DRAW_FROM_CLIENT_MEMORY |
| 90 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 20, pos_and_color); |
| 91 | glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 20, (void*)(pos_and_color+2)); |
| 92 | #else |
| 93 | GLuint vbo; |
| 94 | glGenBuffers(1, &vbo); |
| 95 | glBindBuffer(GL_ARRAY_BUFFER, vbo); |
| 96 | glBufferData(GL_ARRAY_BUFFER, sizeof(pos_and_color), pos_and_color, GL_STATIC_DRAW); |
| 97 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 20, 0); |
| 98 | glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 20, (void*)8); |
| 99 | #endif |
| 100 | glEnableVertexAttribArray(0); |
| 101 | glEnableVertexAttribArray(1); |
| 102 | |
| 103 | glClearColor(0.3f,0.3f,0.3f,1); |
| 104 | glClear(GL_COLOR_BUFFER_BIT); |
nothing calls this directly
no test coverage detected