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 eglSwapBuffers() native "EGLSwapBuffers"; | |
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 glDepthBufferBit() native "GLDepthBufferBit"; | |
65 int glFloat() native "GLFloat"; | |
66 int glFragmentShader() native "GLFragmentShader"; | |
67 int glLinkStatus() native "GLLinkStatus"; | |
68 int glStaticDraw() native "GLStaticDraw"; | |
69 int glTriangleStrip() native "GLTriangleStrip"; | |
70 int glTriangles() native "GLTriangles"; | |
71 int glTrue() native "GLTrue"; | |
72 int glVertexShader() native "GLVertexShader"; | |
73 | |
74 String glGetShaderInfoLog(int shader) native "GLGetShaderInfoLog"; | |
75 String glGetProgramInfoLog(int program) native "GLGetProgramInfoLog"; | |
76 | |
77 class WebGLRenderingContext { | |
78 WebGLRenderingContext(); | |
79 | |
80 static get ARRAY_BUFFER => glArrayBuffer(); | |
81 static get COLOR_BUFFER_BIT => glColorBufferBit(); | |
82 static get COMPILE_STATUS => glCompileStatus(); | |
83 static get DEPTH_BUFFER_BIT => glDepthBufferBit(); | |
84 static get FLOAT => glFloat(); | |
85 static get FRAGMENT_SHADER => glFragmentShader(); | |
86 static get LINK_STATUS => glLinkStatus(); | |
87 static get VERTEX_SHADER => glVertexShader(); | |
88 static get STATIC_DRAW => glStaticDraw(); | |
89 static get TRUE => glTrue(); | |
90 static get TRIANGLE_STRIP => glTriangleStrip(); | |
91 static get TRIANGLES => glTriangles(); | |
92 | |
93 attachShader(program, shader) => glAttachShader(program, shader); | |
94 bindBuffer(target, buffer) => glBindBuffer(target, buffer); | |
95 bufferData(target, data, usage) => glBufferData(target, data, usage); | |
96 clearColor(r, g, b, alpha) => glClearColor(r, g, b, alpha); | |
97 clearDepth(depth) => glClearDepth(depth); | |
98 clear(mask) => glClear(mask); | |
99 compileShader(shader) => glCompileShader(shader); | |
100 createBuffer() => glCreateBuffer(); | |
101 createProgram() => glCreateProgram(); | |
102 createShader(shaderType) => glCreateShader(shaderType); | |
103 drawArrays(mode, first, count) => glDrawArrays(mode, first, count); | |
104 enableVertexAttribArray(index) => glEnableVertexAttribArray(index); | |
105 getAttribLocation(program, name) => glGetAttribLocation(program, name); | |
106 getError() => glGetError(); | |
107 getProgramParameter(program, name) => glGetProgramParameter(program, name); | |
108 getShaderParameter(shader, name) => glGetShaderParameter(shader, name); | |
109 getUniformLocation(program, name) => glGetUniformLocation(program, name); | |
110 linkProgram(program) => glLinkProgram(program); | |
111 shaderSource(shader, source) => glShaderSource(shader, source); | |
112 uniform1f(location, v0) => glUniform1f(location, v0); | |
113 uniform2f(location, v0, v1) => glUniform2f(location, v0, v1); | |
114 uniform3f(location, v0, v1, v2) => glUniform3f(location, v0, v1, v2); | |
115 uniform4f(location, v0, v1, v2, v3) => glUniform4f(location, v0, v1, v2, v3); | |
116 uniform1i(location, v0) => glUniform1i(location, v0); | |
117 uniform2i(location, v0, v1) => glUniform2i(location, v0, v1); | |
118 uniform3i(location, v0, v1, v2) => glUniform3i(location, v0, v1, v2); | |
119 uniform4i(location, v0, v1, v2, v3) => glUniform4i(location, v0, v1, v2, v3); | |
120 uniform1fv(location, values) => glUniform1fv(location, values); | |
121 uniform2fv(location, values) => glUniform2fv(location, values); | |
122 uniform3fv(location, values) => glUniform3fv(location, values); | |
123 uniform4fv(location, values) => glUniform4fv(location, values); | |
124 uniform1iv(location, values) => glUniform1iv(location, values); | |
125 uniform2iv(location, values) => glUniform2iv(location, values); | |
126 uniform3iv(location, values) => glUniform3iv(location, values); | |
127 uniform4iv(location, values) => glUniform4iv(location, values); | |
128 useProgram(program) => glUseProgram(program); | |
129 vertexAttribPointer(index, size, type, normalized, stride, pointer) => | |
130 glVertexAttribPointer(index, size, type, normalized, stride, pointer); | |
131 viewport(x, y, width, height) => glViewport(x, y, width, height); | |
132 getShaderInfoLog(shader) => glGetShaderInfoLog(shader); | |
133 getProgramInfoLog(program) => glGetProgramInfoLog(program); | |
134 | |
135 // TODO(vsm): Kill. | |
136 noSuchMethod(invocation) { | |
137 throw new Exception('Unimplemented ${invocation.memberName}'); | |
138 } | |
139 } | |
140 | |
141 var gl = new WebGLRenderingContext(); | |
142 | |
143 //------------------------------------------------------------------ | |
144 // Simple audio support. | |
145 | |
146 void playBackground(String path) native "PlayBackground"; | |
147 void stopBackground() native "StopBackground"; | |
148 | |
OLD | NEW |