OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library android_extension; |
| 6 |
| 7 // The simplest way to call native code: top-level functions. |
| 8 int systemRand() native "SystemRand"; |
| 9 void systemSrand(int seed) native "SystemSrand"; |
| 10 void log(String what) native "Log"; |
| 11 |
| 12 // EGL functions. |
| 13 void glSwapBuffers() native "SwapBuffers"; |
| 14 |
| 15 // GL functions. |
| 16 void glAttachShader(int program, int shader) native "GLAttachShader"; |
| 17 void glBindBuffer(int target, int buffer) native "GLBindBuffer"; |
| 18 void glBufferData(int target, List data, int usage) native "GLBufferData"; |
| 19 void glClearColor(num r, num g, num b, num alpha) native "GLClearColor"; |
| 20 void glClearDepth(num depth) native "GLClearDepth"; |
| 21 void glClear(int mask) native "GLClear"; |
| 22 void glCompileShader(int shader) native "GLCompileShader"; |
| 23 int glCreateBuffer() native "GLCreateBuffer"; |
| 24 int glCreateProgram() native "GLCreateProgram"; |
| 25 int glCreateShader(int shaderType) native "GLCreateShader"; |
| 26 void glDrawArrays(int mode, int first, int count) native "GLDrawArrays"; |
| 27 void glEnableVertexAttribArray(int index) native "GLEnableVertexAttribArray"; |
| 28 int glGetAttribLocation(int program, String name) native "GLGetAttribLocation"; |
| 29 int glGetError() native "GLGetError"; |
| 30 int glGetProgramParameter(int program, int param) |
| 31 native "GLGetProgramParameter"; |
| 32 int glGetShaderParameter(int shader, int param) native "GLGetShaderParameter"; |
| 33 int glGetUniformLocation(int program, String name) |
| 34 native "GLGetUniformLocation"; |
| 35 void glLinkProgram(int program) native "GLLinkProgram"; |
| 36 void glShaderSource(int shader, String source) native "GLShaderSource"; |
| 37 void glUniform1f(int location, double v0) native "GLUniform1f"; |
| 38 void glUniform2f(int location, double v0, double v1) native "GLUniform2f"; |
| 39 void glUniform3f(int location, double v0, double v1, double v2) |
| 40 native "GLUniform3f"; |
| 41 void glUniform4f(int location, double v0, double v1, double v2, double v3) |
| 42 native "GLUniform4f"; |
| 43 void glUniform1i(int location, int v0) native "GLUniform1i"; |
| 44 void glUniform2i(int location, int v0, int v1) native "GLUniform2i"; |
| 45 void glUniform3i(int location, int v0, int v1, int v2) native "GLUniform3i"; |
| 46 void glUniform4i(int location, int v0, int v1, int v2, int v3) |
| 47 native "GLUniform4i"; |
| 48 void glUniform1fv(int location, List values) native "GLUniform1fv"; |
| 49 void glUniform2fv(int location, List values) native "GLUniform2fv"; |
| 50 void glUniform3fv(int location, List values) native "GLUniform3fv"; |
| 51 void glUniform4fv(int location, List values) native "GLUniform4fv"; |
| 52 void glUniform1iv(int location, List values) native "GLUniform1iv"; |
| 53 void glUniform2iv(int location, List values) native "GLUniform2iv"; |
| 54 void glUniform3iv(int location, List values) native "GLUniform3iv"; |
| 55 void glUniform4iv(int location, List values) native "GLUniform4iv"; |
| 56 void glUseProgram(int program) native "GLUseProgram"; |
| 57 void glVertexAttribPointer(int index, int size, int type, bool normalized, |
| 58 int stride, int pointer) native "GLVertexAttribPointer"; |
| 59 void glViewport(int x, int y, int width, int height) native "GLViewport"; |
| 60 |
| 61 int glArrayBuffer() native "GLArrayBuffer"; |
| 62 int glColorBufferBit() native "GLColorBufferBit"; |
| 63 int glCompileStatus() native "GLCompileStatus"; |
| 64 int glDeleteStatus() native "GLDeleteStatus"; |
| 65 int glDepthBufferBit() native "GLDepthBufferBit"; |
| 66 int glFloat() native "GLFloat"; |
| 67 int glFragmentShader() native "GLFragmentShader"; |
| 68 int glLinkStatus() native "GLLinkStatus"; |
| 69 int glStaticDraw() native "GLStaticDraw"; |
| 70 int glTriangleStrip() native "GLTriangleStrip"; |
| 71 int glTriangles() native "GLTriangles"; |
| 72 int glTrue() native "GLTrue"; |
| 73 int glValidateStatus() native "GLValidateStatus"; |
| 74 int glVertexShader() native "GLVertexShader"; |
| 75 |
| 76 String glGetShaderInfoLog(int shader) native "GLGetShaderInfoLog"; |
| 77 String glGetProgramInfoLog(int program) native "GLGetProgramInfoLog"; |
| 78 |
| 79 class WebGLRenderingContext { |
| 80 WebGLRenderingContext(); |
| 81 |
| 82 static get ARRAY_BUFFER => glArrayBuffer(); |
| 83 static get COLOR_BUFFER_BIT => glColorBufferBit(); |
| 84 static get COMPILE_STATUS => glCompileStatus(); |
| 85 static get DELETE_STATUS => glDeleteStatus(); |
| 86 static get DEPTH_BUFFER_BIT => glDepthBufferBit(); |
| 87 static get FLOAT => glFloat(); |
| 88 static get FRAGMENT_SHADER => glFragmentShader(); |
| 89 static get LINK_STATUS => glLinkStatus(); |
| 90 static get STATIC_DRAW => glStaticDraw(); |
| 91 static get TRUE => glTrue(); |
| 92 static get TRIANGLE_STRIP => glTriangleStrip(); |
| 93 static get TRIANGLES => glTriangles(); |
| 94 static get VALIDATE_STATUS => glValidateStatus(); |
| 95 static get VERTEX_SHADER => glVertexShader(); |
| 96 |
| 97 attachShader(program, shader) => glAttachShader(program, shader); |
| 98 bindBuffer(target, buffer) => glBindBuffer(target, buffer); |
| 99 bufferData(target, data, usage) => glBufferData(target, data, usage); |
| 100 clearColor(r, g, b, alpha) => glClearColor(r, g, b, alpha); |
| 101 clearDepth(depth) => glClearDepth(depth); |
| 102 clear(mask) => glClear(mask); |
| 103 compileShader(shader) => glCompileShader(shader); |
| 104 createBuffer() => glCreateBuffer(); |
| 105 createProgram() => glCreateProgram(); |
| 106 createShader(shaderType) => glCreateShader(shaderType); |
| 107 drawArrays(mode, first, count) => glDrawArrays(mode, first, count); |
| 108 enableVertexAttribArray(index) => glEnableVertexAttribArray(index); |
| 109 getAttribLocation(program, name) => glGetAttribLocation(program, name); |
| 110 getError() => glGetError(); |
| 111 getProgramParameter(program, name) { |
| 112 var rtn = glGetProgramParameter(program, name); |
| 113 if (name == DELETE_STATUS || |
| 114 name == LINK_STATUS || |
| 115 name == VALIDATE_STATUS) { |
| 116 return (rtn == 0) ? false : true; |
| 117 } |
| 118 return rtn; |
| 119 } |
| 120 getShaderParameter(shader, name) { |
| 121 var rtn = glGetShaderParameter(shader, name); |
| 122 if (name == DELETE_STATUS || name == COMPILE_STATUS) { |
| 123 return (rtn == 0) ? false : true; |
| 124 } |
| 125 return rtn; |
| 126 } |
| 127 getUniformLocation(program, name) => glGetUniformLocation(program, name); |
| 128 linkProgram(program) => glLinkProgram(program); |
| 129 shaderSource(shader, source) => glShaderSource(shader, source); |
| 130 uniform1f(location, v0) => glUniform1f(location, v0); |
| 131 uniform2f(location, v0, v1) => glUniform2f(location, v0, v1); |
| 132 uniform3f(location, v0, v1, v2) => glUniform3f(location, v0, v1, v2); |
| 133 uniform4f(location, v0, v1, v2, v3) => glUniform4f(location, v0, v1, v2, v3); |
| 134 uniform1i(location, v0) => glUniform1i(location, v0); |
| 135 uniform2i(location, v0, v1) => glUniform2i(location, v0, v1); |
| 136 uniform3i(location, v0, v1, v2) => glUniform3i(location, v0, v1, v2); |
| 137 uniform4i(location, v0, v1, v2, v3) => glUniform4i(location, v0, v1, v2, v3); |
| 138 uniform1fv(location, values) => glUniform1fv(location, values); |
| 139 uniform2fv(location, values) => glUniform2fv(location, values); |
| 140 uniform3fv(location, values) => glUniform3fv(location, values); |
| 141 uniform4fv(location, values) => glUniform4fv(location, values); |
| 142 uniform1iv(location, values) => glUniform1iv(location, values); |
| 143 uniform2iv(location, values) => glUniform2iv(location, values); |
| 144 uniform3iv(location, values) => glUniform3iv(location, values); |
| 145 uniform4iv(location, values) => glUniform4iv(location, values); |
| 146 useProgram(program) => glUseProgram(program); |
| 147 vertexAttribPointer(index, size, type, normalized, stride, pointer) => |
| 148 glVertexAttribPointer(index, size, type, normalized, stride, pointer); |
| 149 viewport(x, y, width, height) => glViewport(x, y, width, height); |
| 150 getShaderInfoLog(shader) => glGetShaderInfoLog(shader); |
| 151 getProgramInfoLog(program) => glGetProgramInfoLog(program); |
| 152 |
| 153 // TODO(vsm): Kill. |
| 154 noSuchMethod(invocation) { |
| 155 throw new Exception('Unimplemented ${invocation.memberName}'); |
| 156 } |
| 157 } |
| 158 |
| 159 var gl = new WebGLRenderingContext(); |
| 160 |
| 161 //------------------------------------------------------------------ |
| 162 // Simple audio support. |
| 163 |
| 164 void playBackground(String path) native "PlayBackground"; |
| 165 void stopBackground() native "StopBackground"; |
| 166 |
| 167 //------------------------------------------------------------------- |
| 168 // Set up print(). |
| 169 |
| 170 get _printClosure => (s) { |
| 171 try { |
| 172 log(s); |
| 173 } catch (_) { |
| 174 throw(s); |
| 175 } |
| 176 }; |
| 177 |
| 178 //------------------------------------------------------------------ |
| 179 // Temp hack for compat with WebGL. |
| 180 |
| 181 class Float32Array extends List<double> { |
| 182 Float32Array.fromList(List a) { |
| 183 addAll(a); |
| 184 } |
| 185 } |
| 186 |
OLD | NEW |