|
| 1 | +#include <emscripten/html5_webgl.h> |
| 2 | +#include <emscripten/html5.h> |
| 3 | +#include <webgl/webgl2.h> |
| 4 | +#include <stdlib.h> |
| 5 | +#include <assert.h> |
| 6 | +#include <stdio.h> |
| 7 | +#include <string.h> |
| 8 | + |
| 9 | +void test(const char *src) |
| 10 | +{ |
| 11 | + GLuint shader = glCreateShader(GL_VERTEX_SHADER); |
| 12 | + glShaderSource(shader, 1, &src, NULL); |
| 13 | + glCompileShader(shader); |
| 14 | + printf("%s\n", emscripten_webgl_get_shader_info_log_utf8(shader)); |
| 15 | + assert(emscripten_webgl_get_shader_parameter_d(shader, GL_COMPILE_STATUS) == 1); |
| 16 | +} |
| 17 | + |
| 18 | +int main() |
| 19 | +{ |
| 20 | + EmscriptenWebGLContextAttributes attrs; |
| 21 | + emscripten_webgl_init_context_attributes(&attrs); |
| 22 | + attrs.majorVersion = WEBGL_VERSION; |
| 23 | + EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context("#canvas", &attrs); |
| 24 | + emscripten_webgl_make_context_current(context); |
| 25 | + |
| 26 | + // Test the presence of GL_FRAGMENT_PRECISION_HIGH built-in preprocessor |
| 27 | + test("#ifdef GL_FRAGMENT_PRECISION_HIGH\n" |
| 28 | + "void main() {}\n" |
| 29 | + "#endif"); |
| 30 | + test("#if GL_FRAGMENT_PRECISION_HIGH == 1\n" |
| 31 | + "void main() {}\n" |
| 32 | + "#endif"); |
| 33 | + |
| 34 | + // Test GL_ES built-in preprocessor directive |
| 35 | + test("#ifdef GL_ES\n" |
| 36 | + "void main() {}\n" |
| 37 | + "#endif"); |
| 38 | + test("#if GL_ES == 1\n" |
| 39 | + "void main() {}\n" |
| 40 | + "#endif"); |
| 41 | + test("#if GL_ES != 1\n" // Also check negation, i.e. that #if is not tautologically true |
| 42 | + "error!\n" |
| 43 | + "#else\n" |
| 44 | + "void main() {}\n" |
| 45 | + "#endif"); |
| 46 | + |
| 47 | + // Test __VERSION__ built-in preprocessor directive. |
| 48 | + // Note that when WebGL 2 contexts are created, shaders |
| 49 | + // still default to #version 100, unless explicit |
| 50 | + // "#version 300 es" is specified. |
| 51 | + test("#ifdef __VERSION__\n" |
| 52 | + "void main() {}\n" |
| 53 | + "#endif"); |
| 54 | + test("#if __VERSION__ == 100\n" |
| 55 | + "void main() {}\n" |
| 56 | + "#endif"); |
| 57 | + test("#if defined(GL_ES) && __VERSION__ < 300\n" |
| 58 | + "void main() {}\n" |
| 59 | + "#endif"); |
| 60 | + test("#if !defined(GL_ES) || __VERSION__ >= 300\n" // for good measure, check via negation |
| 61 | + "error!\n" |
| 62 | + "#else\n" |
| 63 | + "void main() {}\n" |
| 64 | + "#endif"); |
| 65 | + |
| 66 | +#if WEBGL_VERSION >= 2 |
| 67 | + test("#version 100\n" |
| 68 | + "#if __VERSION__ == 300\n" |
| 69 | + "error!\n" |
| 70 | + "#endif\n" |
| 71 | + "void main() {}"); |
| 72 | + test("#version 300 es\n" |
| 73 | + "#if __VERSION__ == 300\n" |
| 74 | + "void main() {}\n" |
| 75 | + "#endif"); |
| 76 | +#endif |
| 77 | + |
| 78 | + return 0; |
| 79 | +} |
0 commit comments