mrautio / duktape-webgl

Duktape WebGL 2.0 bindings

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status Build and test

duktape-webgl

WebGL 2.0 bindings for Duktape embeddable Javascript engine

  • duktape-webgl implements fairly many WebGL 1.0 and 2.0 methods and constants.
    • *_WEBGL constants and methods not available in core OpenGL are missing.
    • duktape-webgl runs desktop OpenGL Core Profile beneath, not OpenGL ES to which WebGL is based.
  • If you're looking for OpenGL 1.x legacy bindings, check duktape-opengl project.

License

Zlib

Setup

  • Include dukwebgl.h to your Duktape & OpenGL project.

C initialization example

/* Applicable OpenGL header needs to be included before dukwebgl */
#include <GL/glcorearb.h>

/* Duktape needs to be included before dukwebgl */
#include "duktape.h"

/* DUKWEBGL_IMPLEMENTATION needs to be defined in *one* source file to create the implementation. */
#define DUKWEBGL_IMPLEMENTATION 
#include "dukwebgl.h"

...
    /* duktape-webgl bindings will be added to the global object */
    dukwebgl_bind(ctx);
...

JS initialization example

var gl = new WebGL2RenderingContext();
// now you should be able to call WebGL methods as you wish

API general design

  • JS API should resemble to WebGL specifications as much as possible
    • Contradicting / differing OpenGL call logic should be in favor of WebGL specifications
  • C API should be minimal, yet allowing some flexibility for power-users
  • Comply to intersection of OpenGL core C API headers and WebGL 1.x - 2.x APIs
    • Only support WebGL constants defined in the C API
    • Users should have possibility to restrict API imports based on OpenGL core version, i.e. via define/undef
  • Performance over validity
    • Does not validate input
      • Duktape context is assumed to be valid
      • Variables passed from JS are assumed to be valid for intended OpenGL API calls
    • Will attempt to pass calls to underlying OpenGL C API functions with low overhead.

What about GLSL?

  • This API does not transpile GLSL versions.
  • If your program does not support GLSL ES directly, then you should write shaders in a cross-platform manner or do transpiling yourself.

About

Duktape WebGL 2.0 bindings

License:zlib License


Languages

Language:JavaScript 51.8%Language:C 46.6%Language:Dockerfile 1.1%Language:Shell 0.5%