Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

all methods are implemented for triangle.js, not rendering anything t…

…hough
  • Loading branch information...
commit d573cac41a45a0154e3d3cad140c576ee1914b99 1 parent b890792
Elijah Insua authored

Showing 3 changed files with 291 additions and 101 deletions. Show diff stats Hide diff stats

  1. +16 46 example/js/main.cc
  2. +43 47 example/triangle.js
  3. +232 8 src/js/spidermonkey.cc
62 example/js/main.cc
@@ -21,14 +21,23 @@ static JSClass global_class = {
21 21
22 22
23 23 /* JSAPI variables. */
24   -JSRuntime *rt;
25   -JSContext *cx;
26   -JSObject *global;
  24 +JSRuntime *rt = NULL;
  25 +JSContext *cx = NULL;
  26 +JSObject *global = NULL;
27 27
28 28 void c_exit(int code) {
29   - JS_DestroyContext(cx);
30   - JS_DestroyRuntime(rt);
31   - JS_ShutDown();
  29 + if (cx != NULL) {
  30 + JS_DestroyContext(cx);
  31 + }
  32 +
  33 + if (rt != NULL) {
  34 + JS_DestroyRuntime(rt);
  35 + }
  36 +
  37 + if (global != NULL) {
  38 + JS_ShutDown();
  39 + }
  40 +
32 41 exit(code);
33 42 }
34 43
@@ -90,9 +99,7 @@ static JSFunctionSpec module_global_functions[] = {
90 99 JS_FS("webgl_rendering_context_blendEquationSeparate", webgl_rendering_context_blendEquationSeparate, 2 /* GLenum modeRGB, GLenum modeAlpha */, 0),
91 100 JS_FS("webgl_rendering_context_blendFunc", webgl_rendering_context_blendFunc, 2 /* GLenum sfactor, GLenum dfactor */, 0),
92 101 JS_FS("webgl_rendering_context_blendFuncSeparate", webgl_rendering_context_blendFuncSeparate, 4 /* GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha */, 0),
93   - JS_FS("webgl_rendering_context_bufferData", webgl_rendering_context_bufferData, 3 /* GLenum target, GLsizeiptr size, GLenum usage */, 0),
94   - JS_FS("webgl_rendering_context_bufferData", webgl_rendering_context_bufferData, 3 /* GLenum target, ArrayBufferView data, GLenum usage */, 0),
95   - JS_FS("webgl_rendering_context_bufferData", webgl_rendering_context_bufferData, 3 /* GLenum target, ArrayBuffer data, GLenum usage */, 0),
  102 + JS_FS("webgl_rendering_context_bufferData", webgl_rendering_context_bufferData, 3, 0),
96 103 JS_FS("webgl_rendering_context_bufferSubData", webgl_rendering_context_bufferSubData, 3 /* GLenum target, GLintptr offset, ArrayBufferView data */, 0),
97 104 JS_FS("webgl_rendering_context_bufferSubData", webgl_rendering_context_bufferSubData, 3 /* GLenum target, GLintptr offset, ArrayBuffer data */, 0),
98 105 JS_FS("webgl_rendering_context_checkFramebufferStatus", webgl_rendering_context_checkFramebufferStatus, 1 /* GLenum target */, 0),
@@ -256,33 +263,6 @@ void setupGlobals(JSContext *cx, JSObject *global) {
256 263 }
257 264 }
258 265
259   -
260   -
261   -
262   -
263   -JSBool printer_construct(JSContext *cx, uintN argc, jsval *argv)
264   -{
265   - cout << "constructed!" << endl;
266   - return JS_TRUE;
267   -}
268   -
269   -void printer_finalize(JSContext *cx, JSObject *obj)
270   -{
271   -}
272   -
273   -static JSClass printer_class = {
274   - "Printer",
275   - JSCLASS_HAS_PRIVATE | JSCLASS_CONSTRUCT_PROTOTYPE,
276   - JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
277   - JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, printer_finalize,
278   - JSCLASS_NO_OPTIONAL_MEMBERS
279   -};
280   -
281   -void render() {
282   - glFlush();
283   -}
284   -
285   -
286 266 int main(int argc, char **argv)
287 267 {
288 268 if (argc < 2) {
@@ -290,8 +270,6 @@ int main(int argc, char **argv)
290 270 c_exit(EXIT_FAILURE);
291 271 }
292 272
293   -
294   -
295 273 const char* filename = argv[1];
296 274 char *script = getFileContents(filename);
297 275
@@ -305,10 +283,6 @@ int main(int argc, char **argv)
305 283 if (cx == NULL)
306 284 c_exit(EXIT_FAILURE);
307 285
308   -
309   -
310   -
311   -
312 286 JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT);
313 287 JS_SetVersion(cx, JSVERSION_LATEST);
314 288 JS_SetErrorReporter(cx, reportError);
@@ -321,10 +295,6 @@ int main(int argc, char **argv)
321 295 if (!JS_InitStandardClasses(cx, global))
322 296 c_exit(EXIT_FAILURE);
323 297
324   -
325   - // SET UP CUSTOM CLASS
326   - JS_InitClass(cx, global, NULL, &printer_class, printer_construct, 0, NULL, NULL, NULL, NULL);
327   -
328 298 jsval rval;
329 299 JSString *str;
330 300 JSBool ok;
90 example/triangle.js
... ... @@ -1,64 +1,60 @@
1   -var WebGLRenderingContext = require('../lib/webgl.js');
  1 +var webgl = require('../lib/webgl.js');
  2 +var vertices = [
  3 + 0.75, 0.75, 0.0, 1.0,
  4 + 0.75, -0.75, 0.0, 1.0,
  5 + -0.75, -0.75, 0.0, 1.0,
  6 +];
  7 +
  8 +function e(name, result) {
  9 + var e = ctx.getError()
  10 + if (e) {
  11 + console.log(name, 'failed!', e);
  12 + fail();
  13 + } else {
  14 + console.log(name, 'passed!');
  15 + }
  16 + return result;
  17 +}
2 18
3   -var ctx = new WebGLRenderingContext();
4   -var program = ctx.createProgram();
  19 +var ctx = new webgl.WebGLRenderingContext();
  20 +var program = e('create program', ctx.createProgram());
5 21 var shaders = {
6 22 vertex : "attribute vec3 pos;\nvoid main() {\n gl_Position = vec4(pos, 1.0);\n}",
7 23 frag : "void main() {\n gl_FragColor = vec4(1.0, 0, 1, 1.0);\n}"
8 24 };
9 25
10   -var vertexShader = ctx.createShader(ctx.VERTEX_SHADER);
11   -var fragShader = ctx.createShader(ctx.FRAGMENT_SHADER);
  26 +var vertexShader = e('create shader', ctx.createShader(ctx.VERTEX_SHADER));
  27 +var fragShader = e('create shader', ctx.createShader(ctx.FRAGMENT_SHADER));
12 28
13   -ctx.shaderSource(vertexShader, shaders.vertex);
14   -ctx.shaderSource(fragShader, shaders.frag);
15   -
16   -ctx.compileShader(vertexShader);
17   -ctx.compileShader(fragShader);
18   -
19   -ctx.attachShader(program, vertexShader);
20   -ctx.attachShader(program, fragShader);
21   -ctx.linkProgram(program);
  29 +e('shader source', ctx.shaderSource(vertexShader, shaders.vertex));
  30 +e('shader source', ctx.shaderSource(fragShader, shaders.frag));
  31 +e('compile shader', ctx.compileShader(vertexShader));
  32 +e('compile shader', ctx.compileShader(fragShader));
  33 +e('attach shader', ctx.attachShader(program, vertexShader));
  34 +e('attach shader', ctx.attachShader(program, fragShader));
  35 +e('link program', ctx.linkProgram(program));
22 36
23 37 if (!ctx.getProgramParameter(program, ctx.LINK_STATUS)) {
24   - console.log("Could not link program");
  38 + console.log("Could not link program.\n Error:", ctx.getError());
  39 + console.log(ctx.getProgramInfoLog(program));
25 40 fail();
26 41 }
27 42
28   -ctx.useProgram(program);
29   -var attr = ctx.getAttribLocation(program, "pos");
30   -var vertexBuffer = ctx.createBuffer();
31   -
32   -vertexBuffer.itemSize = 3;
33   -vertexBuffer.numItems = 3;
  43 +e('use program', ctx.useProgram(program));
  44 +var attr = e('attribute location', ctx.getAttribLocation(program, "pos"));
  45 +var vertexBuffer = e('create buffer', ctx.createBuffer());
34 46
35   -/*
36   - const float vertexPositions[] = {
37   - 0.75f, 0.75f, 0.0f, 1.0f,
38   - 0.75f, -0.75f, 0.0f, 1.0f,
39   - -0.75f, -0.75f, 0.0f, 1.0f,
40   - };
41   -*/
42   -
43   -var vertices = [
44   - 0.0, 1.0, 0.0,
45   - -1.0, -1.0, 0.0,
46   - 1.0, -1.0, 0.0
47   -];
48   -
49   -ctx.bindBuffer(ctx.ARRAY_BUFFER, vertexBuffer);
50   -ctx.bufferData(ctx.ARRAY_BUFFER, new Float32Array(vertexBuffer));
  47 +e('bind buffer', ctx.bindBuffer(ctx.ARRAY_BUFFER, vertexBuffer));
  48 +e('buffer data', ctx.bufferData(ctx.ARRAY_BUFFER, new Float32Array(vertexBuffer)));
51 49
52 50 var a = 10000;
53 51 while(a--) {
54   -
55   - ctx.clearColor(0.5, 0.5, 0.5, 1);
56   - ctx.clear(ctx.COLOR_BUFFER_BIT, ctx.DEPTH_BUFFER_BIT);
57   - ctx.bindBuffer(ctx.ARRAY_BUFFER, vertexBuffer);
58   - ctx.enableVertexAttribArray(attr);
59   - ctx.vertexAttribPointer(attr, vertexBuffer.itemSize, ctx.FLOAT, false, 0, 0);
60   - ctx.drawArrays(ctx.TRIANGLES, 0, 3);
61   - ctx.flush();
  52 + e('clear color', ctx.clearColor(0.5, 0.5, 0.5, 1));
  53 + e('clear', ctx.clear(ctx.COLOR_BUFFER_BIT | ctx.DEPTH_BUFFER_BIT));
  54 + e('bind buffer', ctx.bindBuffer(ctx.ARRAY_BUFFER, vertexBuffer));
  55 + e('enable vertex attrib array', ctx.enableVertexAttribArray(attr));
  56 + e('vertex pointer', ctx.vertexAttribPointer(attr, 3, ctx.FLOAT, false, 0, 0));
  57 + e('draw arrays', ctx.drawArrays(ctx.TRIANGLES, 0, 3));
  58 + e('flush', ctx.flush());
62 59 }
63   -
64   -fail();
  60 +console.log("DONE");
240 src/js/spidermonkey.cc
@@ -30,6 +30,15 @@ JSBool webgl_rendering_context_activeTexture(JSContext *cx, uintN argc, jsval *a
30 30
31 31 JSBool webgl_rendering_context_attachShader(JSContext *cx, uintN argc, jsval *argv) {
32 32
  33 + int program;
  34 + int shader;
  35 +
  36 + if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, argv), "ii", &program, &shader)) {
  37 + return JS_FALSE;
  38 + }
  39 +
  40 + glAttachShader(program, shader);
  41 +
33 42 return JS_TRUE;
34 43 }
35 44
@@ -40,6 +49,15 @@ JSBool webgl_rendering_context_bindAttribLocation(JSContext *cx, uintN argc, jsv
40 49
41 50 JSBool webgl_rendering_context_bindBuffer(JSContext *cx, uintN argc, jsval *argv) {
42 51
  52 + int target;
  53 + int buffer;
  54 +
  55 + if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, argv), "ii", &target, &buffer)) {
  56 + return JS_FALSE;
  57 + }
  58 +
  59 + glBindBuffer(target, buffer);
  60 +
43 61 return JS_TRUE;
44 62 }
45 63
@@ -86,6 +104,28 @@ JSBool webgl_rendering_context_blendFuncSeparate(JSContext *cx, uintN argc, jsva
86 104
87 105 JSBool webgl_rendering_context_bufferData(JSContext *cx, uintN argc, jsval *argv) {
88 106
  107 +
  108 + int target;
  109 + JSObject *array;
  110 + int usage;
  111 +
  112 + if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, argv), "ioi", &target, &array, &usage)) {
  113 + return JS_FALSE;
  114 + }
  115 +
  116 + // TODO: convert it into a typed array?
  117 + if (!js_IsTypedArray(array)) {
  118 + return JS_FALSE;
  119 + }
  120 +
  121 + js::TypedArray *tarray = js::TypedArray::fromJSObject(array);
  122 + JS_ASSERT(tarray);
  123 +
  124 + cout << "data " << tarray->data << " type:" << tarray->type << endl;
  125 + uintN srclen = tarray->length;
  126 +
  127 + glBufferData(target, srclen, tarray->data, usage);
  128 +
89 129 return JS_TRUE;
90 130 }
91 131
@@ -102,18 +142,40 @@ JSBool webgl_rendering_context_checkFramebufferStatus(JSContext *cx, uintN argc,
102 142
103 143 JSBool webgl_rendering_context_clear(JSContext *cx, uintN argc, jsval *argv) {
104 144
  145 + int bits;
  146 +
  147 + if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, argv), "i", &bits)) {
  148 + return JS_FALSE;
  149 + }
105 150
106   - glClear(GL_DEPTH);
  151 + glClear(bits);
107 152 return JS_TRUE;
108 153 }
109 154
110 155 JSBool webgl_rendering_context_clearColor(JSContext *cx, uintN argc, jsval *argv) {
111   - glClearColor(0,0,0,1);
  156 +
  157 + jsdouble r;
  158 + jsdouble g;
  159 + jsdouble b;
  160 + jsdouble a;
  161 + if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, argv), "dddd", &r, &g, &b, &a)) {
  162 + return JS_FALSE;
  163 + }
  164 +
  165 + glClearColor(r,g,b,a);
  166 +
112 167 return JS_TRUE;
113 168 }
114 169
115 170 JSBool webgl_rendering_context_clearDepth(JSContext *cx, uintN argc, jsval *argv) {
116 171
  172 + jsdouble clampd;
  173 + if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, argv), "d", &clampd)) {
  174 + return JS_FALSE;
  175 + }
  176 +
  177 + glClearDepth(clampd);
  178 +
117 179 return JS_TRUE;
118 180 }
119 181
@@ -129,6 +191,13 @@ JSBool webgl_rendering_context_colorMask(JSContext *cx, uintN argc, jsval *argv)
129 191
130 192 JSBool webgl_rendering_context_compileShader(JSContext *cx, uintN argc, jsval *argv) {
131 193
  194 + int id;
  195 + if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, argv), "i", &id)) {
  196 + return JS_FALSE;
  197 + }
  198 +
  199 + glCompileShader(id);
  200 +
132 201 return JS_TRUE;
133 202 }
134 203
@@ -145,7 +214,9 @@ JSBool webgl_rendering_context_copyTexSubImage2D(JSContext *cx, uintN argc, jsva
145 214
146 215
147 216 JSBool webgl_rendering_context_createBuffer(JSContext *cx, uintN argc, jsval *argv) {
148   -
  217 + unsigned int buffer;
  218 + glGenBuffers(1, &buffer);
  219 + JS_SET_RVAL(cx, argv, INT_TO_JSVAL(buffer));
149 220 return JS_TRUE;
150 221 }
151 222
@@ -155,18 +226,32 @@ JSBool webgl_rendering_context_createFramebuffer(JSContext *cx, uintN argc, jsva
155 226 }
156 227
157 228 JSBool webgl_rendering_context_createProgram(JSContext *cx, uintN argc, jsval *argv) {
158   - GLenum program = glCreateProgram();
159   - JS_SET_RVAL(cx, argv, DOUBLE_TO_JSVAL(program));
  229 +
  230 + GLenum ret = glCreateProgram();
  231 + JS_SET_RVAL(cx, argv, INT_TO_JSVAL(ret));
  232 +
160 233 return JS_TRUE;
161 234 }
162 235
163 236 JSBool webgl_rendering_context_createRenderbuffer(JSContext *cx, uintN argc, jsval *argv) {
164 237
  238 + GLenum ret = glCreateProgram();
  239 + JS_SET_RVAL(cx, argv, INT_TO_JSVAL(ret));
  240 +
165 241 return JS_TRUE;
166 242 }
167 243
168 244 JSBool webgl_rendering_context_createShader(JSContext *cx, uintN argc, jsval *argv) {
169 245
  246 + int type;
  247 +
  248 + if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, argv), "i", &type)) {
  249 + return JS_FALSE;
  250 + }
  251 +
  252 + GLenum ret = glCreateShader(type);
  253 + JS_SET_RVAL(cx, argv, INT_TO_JSVAL(ret));
  254 +
170 255 return JS_TRUE;
171 256 }
172 257
@@ -240,6 +325,13 @@ JSBool webgl_rendering_context_disable(JSContext *cx, uintN argc, jsval *argv) {
240 325
241 326 JSBool webgl_rendering_context_disableVertexAttribArray(JSContext *cx, uintN argc, jsval *argv) {
242 327
  328 + int attr;
  329 + if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, argv), "i", &attr)) {
  330 + return JS_FALSE;
  331 + }
  332 +
  333 + glDisableVertexAttribArray(attr);
  334 +
243 335 return JS_TRUE;
244 336 }
245 337
@@ -250,6 +342,16 @@ JSBool webgl_rendering_context_drawArrays(JSContext *cx, uintN argc, jsval *argv
250 342
251 343 JSBool webgl_rendering_context_drawElements(JSContext *cx, uintN argc, jsval *argv) {
252 344
  345 + int mode;
  346 + int first;
  347 + int count;
  348 +
  349 + if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, argv), "iii", &mode, &first, &count)) {
  350 + return JS_FALSE;
  351 + }
  352 +
  353 + glDrawArrays(mode, first, count);
  354 +
253 355 return JS_TRUE;
254 356 }
255 357
@@ -261,6 +363,13 @@ JSBool webgl_rendering_context_enable(JSContext *cx, uintN argc, jsval *argv) {
261 363
262 364 JSBool webgl_rendering_context_enableVertexAttribArray(JSContext *cx, uintN argc, jsval *argv) {
263 365
  366 + int attr;
  367 + if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, argv), "i", &attr)) {
  368 + return JS_FALSE;
  369 + }
  370 +
  371 + glEnableVertexAttribArray(attr);
  372 +
264 373 return JS_TRUE;
265 374 }
266 375
@@ -316,6 +425,17 @@ JSBool webgl_rendering_context_getAttachedShaders(JSContext *cx, uintN argc, jsv
316 425
317 426 JSBool webgl_rendering_context_getAttribLocation(JSContext *cx, uintN argc, jsval *argv) {
318 427
  428 + int program;
  429 + JSString *js_attr;
  430 + if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, argv), "iS", &program, &js_attr)) {
  431 + return JS_FALSE;
  432 + }
  433 +
  434 + const char *attr = JS_EncodeString(cx, js_attr);
  435 + int ret = glGetAttribLocation(program, attr);
  436 +
  437 + JS_SET_RVAL(cx, argv, INT_TO_JSVAL(ret));
  438 +
319 439 return JS_TRUE;
320 440 }
321 441
@@ -332,7 +452,7 @@ JSBool webgl_rendering_context_getBufferParameter(JSContext *cx, uintN argc, jsv
332 452
333 453
334 454 JSBool webgl_rendering_context_getError(JSContext *cx, uintN argc, jsval *argv) {
335   -
  455 + JS_SET_RVAL(cx, argv, INT_TO_JSVAL(glGetError()));
336 456 return JS_TRUE;
337 457 }
338 458
@@ -344,11 +464,53 @@ JSBool webgl_rendering_context_getFramebufferAttachmentParameter(JSContext *cx,
344 464
345 465 JSBool webgl_rendering_context_getProgramParameter(JSContext *cx, uintN argc, jsval *argv) {
346 466
  467 + int param;
  468 + int program;
  469 +
  470 + if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, argv), "ii", &program, &param)) {
  471 + return JS_FALSE;
  472 + }
  473 +
  474 + int status;
  475 + glGetProgramiv(program, param, &status);
  476 +
  477 + bool b_status = (status == GL_TRUE) ? true : false;
  478 +
  479 + switch (param) {
  480 + case GL_DELETE_STATUS:
  481 + case GL_LINK_STATUS:
  482 + case GL_VALIDATE_STATUS:
  483 + JS_SET_RVAL(cx, argv, BOOLEAN_TO_JSVAL(status));
  484 + break;
  485 +
  486 + // all others are int return types
  487 + default:
  488 + JS_SET_RVAL(cx, argv, INT_TO_JSVAL(status));
  489 + break;
  490 + }
  491 +
347 492 return JS_TRUE;
348 493 }
349 494
350 495 JSBool webgl_rendering_context_getProgramInfoLog(JSContext *cx, uintN argc, jsval *argv) {
351 496
  497 + int program;
  498 +
  499 + if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, argv), "i", &program)) {
  500 + return JS_FALSE;
  501 + }
  502 +
  503 + int logLength = 0;
  504 + int maxLength;
  505 +
  506 + glGetProgramiv(program, GL_INFO_LOG_LENGTH, &maxLength);
  507 + char infoLog[maxLength];
  508 +
  509 + glGetProgramInfoLog(program, maxLength, &logLength, infoLog);
  510 +
  511 + JSString *jsLogString = JS_NewStringCopyN(cx, infoLog, logLength);
  512 + JS_SET_RVAL(cx, argv, STRING_TO_JSVAL(jsLogString));
  513 +
352 514 return JS_TRUE;
353 515 }
354 516
@@ -363,6 +525,22 @@ JSBool webgl_rendering_context_getShaderParameter(JSContext *cx, uintN argc, jsv
363 525 }
364 526
365 527 JSBool webgl_rendering_context_getShaderInfoLog(JSContext *cx, uintN argc, jsval *argv) {
  528 + int shader;
  529 +
  530 + if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, argv), "i", &shader)) {
  531 + return JS_FALSE;
  532 + }
  533 +
  534 + int logLength = 0;
  535 + int maxLength;
  536 +
  537 + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength);
  538 + char infoLog[maxLength];
  539 +
  540 + glGetShaderInfoLog(shader, maxLength, &logLength, infoLog);
  541 +
  542 + JSString *jsLogString = JS_NewStringCopyN(cx, infoLog, logLength);
  543 + JS_SET_RVAL(cx, argv, STRING_TO_JSVAL(jsLogString));
366 544
367 545 return JS_TRUE;
368 546 }
@@ -451,6 +629,13 @@ JSBool webgl_rendering_context_lineWidth(JSContext *cx, uintN argc, jsval *argv)
451 629
452 630 JSBool webgl_rendering_context_linkProgram(JSContext *cx, uintN argc, jsval *argv) {
453 631
  632 + int program;
  633 + if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, argv), "i", &program)) {
  634 + return JS_FALSE;
  635 + }
  636 +
  637 + glLinkProgram(program);
  638 +
454 639 return JS_TRUE;
455 640 }
456 641
@@ -489,6 +674,17 @@ JSBool webgl_rendering_context_scissor(JSContext *cx, uintN argc, jsval *argv) {
489 674
490 675 JSBool webgl_rendering_context_shaderSource(JSContext *cx, uintN argc, jsval *argv) {
491 676
  677 + int id;
  678 + JSString *js_source;
  679 + if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, argv), "iS", &id, &js_source)) {
  680 + return JS_FALSE;
  681 + }
  682 +
  683 + const char *source = JS_EncodeString(cx, js_source);
  684 +
  685 + int length = JS_GetStringLength(js_source);
  686 + glShaderSource(id, 1, &source, &length);
  687 +
492 688 return JS_TRUE;
493 689 }
494 690
@@ -644,6 +840,13 @@ JSBool webgl_rendering_context_uniformMatrix4fv(JSContext *cx, uintN argc, jsval
644 840
645 841 JSBool webgl_rendering_context_useProgram(JSContext *cx, uintN argc, jsval *argv) {
646 842
  843 + int program;
  844 + if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, argv), "i", &program)) {
  845 + return JS_FALSE;
  846 + }
  847 +
  848 + glUseProgram(program);
  849 +
647 850 return JS_TRUE;
648 851 }
649 852
@@ -696,13 +899,34 @@ JSBool webgl_rendering_context_vertexAttrib4fv(JSContext *cx, uintN argc, jsval
696 899
697 900 JSBool webgl_rendering_context_vertexAttribPointer(JSContext *cx, uintN argc, jsval *argv) {
698 901
  902 + unsigned int attr;
  903 + int size;
  904 + int type;
  905 + bool normalized;
  906 + int stride;
  907 + int offset;
  908 +
  909 + if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, argv), "iiibii", &attr, &size, &type, &normalized, &stride, &offset)) {
  910 + return JS_FALSE;
  911 + }
  912 +
  913 + glVertexAttribPointer(attr, size, type, normalized, stride, (void *)&offset);
  914 +
699 915 return JS_TRUE;
700 916 }
701 917
702 918
703 919 JSBool webgl_rendering_context_viewport(JSContext *cx, uintN argc, jsval *argv) {
704 920
705   - return JS_TRUE;
706   -}
  921 + int x;
  922 + int y;
  923 + int w;
  924 + int h;
707 925
  926 + if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, argv), "iiibii", &x, &y, &w, &h)) {
  927 + return JS_FALSE;
  928 + }
708 929
  930 + glViewport(x, y, w, h);
  931 + return JS_TRUE;
  932 +}

0 comments on commit d573cac

Please sign in to comment.
Something went wrong with that request. Please try again.