diff --git a/AUTHORS b/AUTHORS index cfa5742269..25146236e4 100644 --- a/AUTHORS +++ b/AUTHORS @@ -106,6 +106,7 @@ Developers: Rohan Kuruvilla (rohankuruvilla, Zynga) Improvements to JS Bindings. Synchronizing CCBReader to version 5. + Adding OpenGL Bindings to Javascript. Jianfeng Zou (NetDragon Inc) contributes CCListView and CCTextureWatcher. diff --git a/samples/Javascript/Shared b/samples/Javascript/Shared index 999fabb306..975bbe4772 160000 --- a/samples/Javascript/Shared +++ b/samples/Javascript/Shared @@ -1 +1 @@ -Subproject commit 999fabb306cddffd0c043ee1cff6e8627ac0df24 +Subproject commit 975bbe4772eebe9c7d970ab9508312bb24cfab5d diff --git a/samples/Javascript/TestJavascript/Classes/AppDelegate.cpp b/samples/Javascript/TestJavascript/Classes/AppDelegate.cpp index 5c82c478a1..30d8dd7692 100644 --- a/samples/Javascript/TestJavascript/Classes/AppDelegate.cpp +++ b/samples/Javascript/TestJavascript/Classes/AppDelegate.cpp @@ -9,6 +9,7 @@ #include "cocos2d_specifics.hpp" #include "js_bindings_chipmunk_registration.h" #include "js_bindings_system_registration.h" +#include "jsb_opengl_registration.h" USING_NS_CC; using namespace CocosDenshion; @@ -40,6 +41,7 @@ bool AppDelegate::applicationDidFinishLaunching() sc->addRegisterCallback(register_cocos2dx_js_extensions); sc->addRegisterCallback(register_all_cocos2dx_extension_manual); sc->addRegisterCallback(jsb_register_chipmunk); + sc->addRegisterCallback(JSB_register_opengl); sc->addRegisterCallback(jsb_register_system); sc->start(); diff --git a/samples/Javascript/TestJavascript/game.js.REMOVED.git-id b/samples/Javascript/TestJavascript/game.js.REMOVED.git-id index 989e347537..8f22324e2a 100644 --- a/samples/Javascript/TestJavascript/game.js.REMOVED.git-id +++ b/samples/Javascript/TestJavascript/game.js.REMOVED.git-id @@ -1 +1 @@ -e1f03e3925993f54e478def7760c0c849140f5d3 \ No newline at end of file +1188862a29d02a39835ba2f3567c4213decf3038 \ No newline at end of file diff --git a/samples/Javascript/TestJavascript/obfuscate.xml b/samples/Javascript/TestJavascript/obfuscate.xml index 3be4846e46..8c16f77347 100644 --- a/samples/Javascript/TestJavascript/obfuscate.xml +++ b/samples/Javascript/TestJavascript/obfuscate.xml @@ -43,6 +43,7 @@ + diff --git a/samples/Javascript/TestJavascript/proj.ios/TestJavascript.xcodeproj/project.pbxproj.REMOVED.git-id b/samples/Javascript/TestJavascript/proj.ios/TestJavascript.xcodeproj/project.pbxproj.REMOVED.git-id index 5fc75e26b9..01a58f5ea0 100644 --- a/samples/Javascript/TestJavascript/proj.ios/TestJavascript.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/samples/Javascript/TestJavascript/proj.ios/TestJavascript.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -0b29dbaef87c1e7f69eea235667a2e278bec0062 \ No newline at end of file +fd1fb139a7505d087883dc9eff612594905edb6c \ No newline at end of file diff --git a/scripting/javascript/bindings/Android.mk b/scripting/javascript/bindings/Android.mk index b2ebbc38b0..5f4bb947bd 100644 --- a/scripting/javascript/bindings/Android.mk +++ b/scripting/javascript/bindings/Android.mk @@ -19,6 +19,10 @@ LOCAL_SRC_FILES := ScriptingCore.cpp \ js_bindings_system_registration.cpp \ js_bindings_ccbreader.cpp \ js_bindings_core.cpp \ + js_bindings_opengl.cpp \ + jsb_opengl_functions.cpp \ + jsb_opengl_manual.cpp \ + jsb_opengl_registration.cpp \ generated/jsb_cocos2dx_auto.cpp \ generated/jsb_cocos2dx_extension_auto.cpp diff --git a/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id b/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id index 1215cbca04..789b08ad0c 100644 --- a/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id +++ b/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id @@ -1 +1 @@ -f90e21c07782c14bf38e748ec3e254e318d505ab \ No newline at end of file +158877faeea5c5d8bf8b8e51dc69aa902c382d32 \ No newline at end of file diff --git a/scripting/javascript/bindings/generated b/scripting/javascript/bindings/generated index 2f59a8dbc5..f446eaff18 160000 --- a/scripting/javascript/bindings/generated +++ b/scripting/javascript/bindings/generated @@ -1 +1 @@ -Subproject commit 2f59a8dbc553ea2ef966dc595684f027a6d56931 +Subproject commit f446eaff18a58982ab29058b3159c75a0119a3c7 diff --git a/scripting/javascript/bindings/js/jsb_cocos2d.js b/scripting/javascript/bindings/js/jsb_cocos2d.js index 32e718ff0c..f5bee11969 100644 --- a/scripting/javascript/bindings/js/jsb_cocos2d.js +++ b/scripting/javascript/bindings/js/jsb_cocos2d.js @@ -500,6 +500,7 @@ cc.Class.extend = function (prop) { }; cc.Node.prototype.ctor = function() {}; +cc.GLNode.extend = cc.Class.extend; cc.Node.extend = cc.Class.extend; cc.Layer.extend = cc.Class.extend; cc.LayerGradient.extend = cc.Class.extend; diff --git a/scripting/javascript/bindings/js/jsb_opengl.js b/scripting/javascript/bindings/js/jsb_opengl.js index da7d6b7afd..95d3cc7531 100644 --- a/scripting/javascript/bindings/js/jsb_opengl.js +++ b/scripting/javascript/bindings/js/jsb_opengl.js @@ -1,24 +1,373 @@ -// -// OpenGL defines -// +/* + OpenGL ES 2.0 / WebGL helper functions + */ + +/* + * According to the WebGL specification ( For further info see:s http://www.khronos.org/registry/webgl/specs/latest/webgl.idl ), + * the API should work with objects like WebGLTexture, WebGLBuffer, WebGLRenderBuffer, WebGLFramebuffer, WebGLProgram, WebGLShader. + * OpenGL ES 2.0 doesn't have "objects" concepts: Instead it uses ids (GLints). So, these objects are emulated in this thin wrapper. + */ + var gl = gl || {}; -gl.NEAREST = 0x2600; -gl.LINEAR = 0x2601; -gl.REPEAT = 0x2901; -gl.CLAMP_TO_EDGE = 0x812F; -gl.CLAMP_TO_BORDER = 0x812D; -gl.LINEAR_MIPMAP_NEAREST = 0x2701; -gl.NEAREST_MIPMAP_NEAREST = 0x2700; -gl.ZERO = 0; -gl.ONE = 1; -gl.SRC_COLOR = 0x0300; -gl.ONE_MINUS_SRC_COLOR = 0x0301; -gl.SRC_ALPHA = 0x0302; -gl.ONE_MINUS_SRC_ALPHA = 0x0303; -gl.DST_ALPHA = 0x0304; -gl.ONE_MINUS_DST_ALPHA = 0x0305; -gl.DST_COLOR = 0x0306; -gl.ONE_MINUS_DST_COLOR = 0x0307; -gl.SRC_ALPHA_SATURATE = 0x0308; +// +// Create functions +// +gl.createTexture = function() { + // Returns a "WebGLTexture" object + var ret = gl._createTexture(); + return { texture_id:ret }; +}; + +gl.createBuffer = function() { + // Returns a "WebGLBuffer" object + var ret = gl._createBuffer(); + return { buffer_id:ret }; +}; + +gl.createRenderbuffer = function() { + // Returns a "WebGLRenderBuffer" object + var ret = gl._createRenderuffer(); + return { renderbuffer_id:ret}; +}; + +gl.createFramebuffer = function() { + // Returns a "WebGLFramebuffer" object + var ret = gl._createFramebuffer(); + return {framebuffer_id:ret}; +}; + +gl.createProgram = function() { + // Returns a "WebGLProgram" object + var ret = gl._createProgram(); + return {program_id:ret}; +}; + +gl.createShader = function(shaderType) { + // Returns a "WebGLShader" object + var ret = gl._createShader(shaderType); + return {shader_id:ret}; +}; + +// +// Delete Functions +// +gl.deleteTexture = function(texture) { + var texture_id = texture.texture_id; + // Accept numbers too. eg: gl.deleteTexture(0) + if( typeof texture === 'number' ) + texture_id = texture; + + gl._deleteTexture(texture_id); +}; + +gl.deleteBuffer = function(bufer) { + var buffer_id = buffer.buffer_id; + // Accept numbers too. eg: gl.deleteBuffer(0) + if( typeof buffer === 'number' ) + buffer_id = buffer; + + gl._deleteBuffer(buffer_id); +}; + +gl.deleteRenderbuffer = function(bufer) { + var buffer_id = buffer.renderbuffer_id; + // Accept numbers too. eg: gl.deleteRenderbuffer(0) + if( typeof buffer === 'number' ) + buffer_id = buffer; + + gl._deleteRenderbuffer(renderbuffer_id); +}; + +gl.deleteFramebuffer = function(bufer) { + var buffer_id = buffer.framebuffer_id; + // Accept numbers too. eg: gl.deleteFramebuffer(0) + if( typeof buffer === 'number' ) + buffer_id = buffer; + + gl._deleteFramebuffer(buffer_id); +}; + +gl.deleteProgram = function(program) { + var program_id = program.program_id; + // Accept numbers too. eg: gl.deleteShader(0) + if( typeof program === 'number' ) + program_id = program; + + gl._deleteProgram(program_id); +}; + +gl.deleteShader = function(shader) { + var shader_id = shader.shader_id; + // Accept numbers too. eg: gl.deleteShader(0) + if( typeof shader === 'number' ) + shader_id = shader; + + gl._deleteShader(shader_id); +}; + +// +// Bind Related +// +// void bindTexture(GLenum target, WebGLTexture? texture); +gl.bindTexture = function(target, texture) { + + var texture_id; + // Accept numbers too. eg: gl.bindTexture(0) + if( typeof texture === 'number' ) + texture_id = texture; + else if( texture === null ) + texture_id = 0; + else + texture_id = texture.texture_id; + + gl._bindTexture( target, texture_id ); +}; + +// void bindBuffer(GLenum target, WebGLBuffer? buffer); +gl.bindBuffer = function(target, buffer) { + var buffer_id; + // Accept numbers too. eg: gl.bindBuffer(0) + if( typeof buffer === 'number' ) + buffer_id = buffer; + else if( buffer === null ) + buffer_id = 0; + else + buffer_id = buffer.buffer_id; + + gl._bindBuffer(target, buffer_id); +}; + +// void bindRenderbuffer(GLenum target, WebGLRenderbuffer? renderbuffer); +gl.bindRenderBuffer = function(target, buffer) { + var buffer_id; + + // Accept numbers too. eg: gl.bindRenderbuffer(0) + if( typeof buffer === 'number' ) + buffer_id = buffer; + else if( buffer === null ) + buffer_id = 0; + else + buffer_id = buffer.buffer_id; + + gl._bindRenderbuffer(target, buffer_id); +}; + +// void bindFramebuffer(GLenum target, WebGLFramebuffer? framebuffer); +gl.bindFramebuffer = function(target, buffer) { + var buffer_id; + + // Accept numbers too. eg: gl.bindFramebuffer(0) + if( typeof buffer === 'number' ) + buffer_id = buffer; + else if( buffer === null ) + buffer_id = 0; + else + buffer_id = buffer.buffer_id; + + gl._bindFramebuffer(target, buffer_id); +}; + +// +// Uniform related +// +// any getUniform(WebGLProgram? program, WebGLUniformLocation? location); +gl.getUniform = function(program, location) { + var program_id; + var location_id; + + // Accept numbers too. eg: gl.bindFramebuffer(0) + if( typeof program === 'number' ) + program_id = program; + else + program_id = program.program_id; + + if( typeof location === 'number' ) + location_id = location; + else + location_id = location.location_id; + + return gl._getUniform(program_id, location_id); +}; + +// gl.uniformMatrix2fv = function(location, bool, matrix) { +// gl._uniformMatrix2fv(program.program_id, bool, matrix); +// }; + +// gl.uniformMatrix3fv = function(program, bool, matrix) { +// gl._uniformMatrix3fv(program.program_id, bool, matrix); +// }; + +// gl.uniformMatrix4fv = function(program, bool, matrix) { +// gl._uniformMatrix4fv(program.program_id, bool, matrix); +// }; + + +// +// Shader related +// +// void compileShader(WebGLShader? shader); +gl.compileShader = function(shader) { + gl._compileShader( shader.shader_id); +}; + +// void shaderSource(WebGLShader? shader, DOMString source); +gl.shaderSource = function(shader, source) { + gl._shaderSource(shader.shader_id, source); +}; + +// any getShaderParameter(WebGLShader? shader, GLenum pname); +gl.getShaderParameter = function(shader, e) { + return gl._getShaderParameter(shader.shader_id,e); +}; + +// DOMString? getShaderInfoLog(WebGLShader? shader); +gl.getShaderInfoLog = function(shader) { + return gl._getShaderInfoLog(shader.shader_id); +}; + +// +// program related +// +// void attachShader(WebGLProgram? program, WebGLShader? shader); +gl.attachShader = function(program, shader) { + var program_id = program.program_id; + // Accept numbers too. eg: gl.attachShader(17) + if( typeof program === 'number' ) + program_id = program; + + gl._attachShader(program_id, shader.shader_id); +}; + +// void linkProgram(WebGLProgram? program); +gl.linkProgram = function(program) { + var program_id = program.program_id; + // Accept numbers too. eg: gl.linkProgram(17) + if( typeof program === 'number' ) + program_id = program; + + gl._linkProgram(program_id); +}; + + +// any getProgramParameter(WebGLProgram? program, GLenum pname); +gl.getProgramParameter = function(program, e) { + var program_id = program.program_id; + // Accept numbers too. eg: gl.getProgramParameter(17) + if( typeof program === 'number' ) + program_id = program; + + return gl._getProgramParameter(program_id, e); +}; + +// void useProgram(WebGLProgram? program); +gl.useProgram = function(program) { + var program_id; + // Accept numbers too. eg: gl.useProgram(17) + if( typeof program === 'number' ) + program_id = program; + else + program_id = program.program_id; + + gl._useProgram (program_id); +}; + + +// [WebGLHandlesContextLoss] GLint getAttribLocation(WebGLProgram? program, DOMString name); +gl.getAttribLocation = function(program, name) { + var program_id = program.program_id; + // Accept numbers too. eg: gl.getAttribLocation(17) + if( typeof program === 'number' ) + program_id = program; + + return gl._getAttribLocation(program_id, name); +}; + +// WebGLUniformLocation? getUniformLocation(WebGLProgram? program, DOMString name); +gl.getUniformLocation = function(program, name) { + var program_id = program.program_id; + // Accept numbers too. eg: gl.getUniformLocation(17) + if( typeof program === 'number' ) + program_id = program; + + // XXX: it should return an object, not an integer + return gl._getUniformLocation(program_id,name); +}; + + +// WebGLActiveInfo? getActiveAttrib(WebGLProgram? program, GLuint index); +gl.getActiveAttrib = function(program, index) { + var program_id = program.program_id; + // Accept numbers too. eg: gl.getActiveAttrib(17) + if( typeof program === 'number' ) + program_id = program; + + return gl._getActiveAttrib(program_id, index); +}; + +// WebGLActiveInfo? getActiveUniform(WebGLProgram? program, GLuint index); +gl.getActiveUniform = function(program, index) { + var program_id = program.program_id; + // Accept numbers too. eg: gl.getActiveUniform(17) + if( typeof program === 'number' ) + program_id = program; + + return gl._getActiveUniform(program_id, index); +}; + +// sequence? getAttachedShaders(WebGLProgram? program); +gl.getAttachedShaders = function(program) { + var program_id = program.program_id; + // Accept numbers too. eg: gl.getAttachedShaders(17) + if( typeof program === 'number' ) + program_id = program; + + return gl._getAttachedShaders(program_id); +}; + +// +// Texture functions +// + +// XXX: Currently only the 1st one is supported +// void texImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, ArrayBufferView? pixels); +// void texImage2D(GLenum target, GLint level, GLenum internalformat, GLenum format, GLenum type, ImageData? pixels); +// void texImage2D(GLenum target, GLint level, GLenum internalformat, GLenum format, GLenum type, HTMLImageElement image); // May throw DOMException +// void texImage2D(GLenum target, GLint level, GLenum internalformat, GLenum format, GLenum type, HTMLCanvasElement canvas); // May throw DOMException +// void texImage2D(GLenum target, GLint level, GLenum internalformat, GLenum format, GLenum type, HTMLVideoElement video); // May throw DOMException +gl.texImage2D = function() { + if( arguments.length != 9) + throw "texImage2D: Unsupported number of parameters:" + arguments.length; + + gl._texImage2D.apply(this, arguments); +}; + +// XXX: Currently only the 1st one is supported +// void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, ArrayBufferView? pixels); +// void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLenum format, GLenum type, ImageData? pixels); +// void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLenum format, GLenum type, HTMLImageElement image); // May throw DOMException +// void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLenum format, GLenum type, HTMLCanvasElement canvas); // May throw DOMException +// void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLenum format, GLenum type, HTMLVideoElement video); // May throw DOMException +gl.texSubImage2D = function() { + if( arguments.length != 9) + throw "texImage2D: Unsupported number of parameters"; + + gl._texSubImage2D.apply(this, arguments); +}; + +// +// Extensions +// +// From the WebGL spec: +// Returns an object if, and only if, name is an ASCII case-insensitive match [HTML] for one of the names returned from getSupportedExtensions; +// otherwise, returns null. The object returned from getExtension contains any constants or functions provided by the extension. +// A returned object may have no constants or functions if the extension does not define any, but a unique object must still be returned. +// That object is used to indicate that the extension has been enabled. +// XXX: The returned object must return the functions and constants. +gl.getExtension = function(extension) { + var extensions = gl.getSupportedExtensions(); + if( extensions.indexOf(extension) > -1 ) + return {}; + return null; +}; diff --git a/scripting/javascript/bindings/js/jsb_opengl_constants.js b/scripting/javascript/bindings/js/jsb_opengl_constants.js index 4b2a310a9c..dfb6734a66 100644 --- a/scripting/javascript/bindings/js/jsb_opengl_constants.js +++ b/scripting/javascript/bindings/js/jsb_opengl_constants.js @@ -1,6 +1,6 @@ /* * AUTOGENERATED FILE. DO NOT EDIT IT -* Generated by "generate_jsb.py -c opengl_jsb.ini" on 2013-03-05 +* Generated by "generate_jsb.py -c opengl_jsb.ini" on 2013-03-18 * Script version: v0.6 */ diff --git a/scripting/javascript/bindings/js_bindings_config.h b/scripting/javascript/bindings/js_bindings_config.h index 4dfbd855b8..b5450b2d80 100644 --- a/scripting/javascript/bindings/js_bindings_config.h +++ b/scripting/javascript/bindings/js_bindings_config.h @@ -161,4 +161,11 @@ JSAutoCompartment ac(cx, obj) #define JSB_INCLUDE_SYSTEM 1 #endif // JSB_INCLUDE_SYSTEM +/** @def JSB_INCLUDE_OPENGL + Whether or not it should include bindings for WebGL / OpenGL ES 2.0 + */ +#ifndef JSB_INCLUDE_OPENGL +#define JSB_INCLUDE_OPENGL 1 +#endif // JSB_INCLUDE_OPENGL + #endif // __JS_BINDINGS_CONFIG_H diff --git a/scripting/javascript/bindings/js_bindings_opengl.cpp b/scripting/javascript/bindings/js_bindings_opengl.cpp new file mode 100644 index 0000000000..acd2a78882 --- /dev/null +++ b/scripting/javascript/bindings/js_bindings_opengl.cpp @@ -0,0 +1,133 @@ +#include "js_bindings_opengl.h" + +void GLNode::draw() { + js_proxy_t* proxy = NULL; + JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); + proxy = js_get_or_create_proxy(cx, this); + + //JSB_CCNode *proxy = objc_getAssociatedObject(self, &JSB_association_proxy_key); + if( proxy ) { + JSObject *jsObj = proxy->obj; + if (jsObj) { + JSBool found; + JSB_ENSURE_AUTOCOMPARTMENT(cx, jsObj); + JS_HasProperty(cx, jsObj, "draw", &found); + if (found == JS_TRUE) { + jsval rval, fval; + jsval *argv = NULL; unsigned argc=0; + + JS_GetProperty(cx, jsObj, "draw", &fval); + JS_CallFunctionValue(cx, jsObj, fval, argc, argv, &rval); + } + } + } +} + + +JSClass *js_cocos2dx_GLNode_class; +JSObject *js_cocos2dx_GLNode_prototype; + +JSBool js_cocos2dx_GLNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + + if (argc == 0) { + GLNode* cobj = new GLNode(); +#ifdef COCOS2D_JAVASCRIPT + cocos2d::CCObject *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } +#endif + TypeTest t; + js_type_class_t *typeClass; + uint32_t typeId = t.s_id(); + HASH_FIND_INT(_js_global_type_ht, &typeId, typeClass); + assert(typeClass); + JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t *p; + JS_NEW_PROXY(p, cobj, obj); +#ifdef COCOS2D_JAVASCRIPT + JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::GLNode"); +#endif + return JS_TRUE; + } + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0); + return JS_FALSE; +} + +void js_cocos2dx_GLNode_finalize(JSFreeOp *fop, JSObject *obj) { +} + +JSBool js_cocos2dx_GLNode_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + GLNode* ret = new GLNode(); + jsval jsret; + do { + if (ret) { + js_proxy_t *proxy = js_get_or_create_proxy(cx, ret); + jsret = OBJECT_TO_JSVAL(proxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + JS_SET_RVAL(cx, vp, jsret); + return JS_TRUE; +} + +extern JSObject* jsb_CCNode_prototype; + +void js_register_cocos2dx_GLNode(JSContext *cx, JSObject *global) { + js_cocos2dx_GLNode_class = (JSClass *)calloc(1, sizeof(JSClass)); + js_cocos2dx_GLNode_class->name = "GLNode"; + js_cocos2dx_GLNode_class->addProperty = JS_PropertyStub; + js_cocos2dx_GLNode_class->delProperty = JS_PropertyStub; + js_cocos2dx_GLNode_class->getProperty = JS_PropertyStub; + js_cocos2dx_GLNode_class->setProperty = JS_StrictPropertyStub; + js_cocos2dx_GLNode_class->enumerate = JS_EnumerateStub; + js_cocos2dx_GLNode_class->resolve = JS_ResolveStub; + js_cocos2dx_GLNode_class->convert = JS_ConvertStub; + js_cocos2dx_GLNode_class->finalize = js_cocos2dx_GLNode_finalize; + js_cocos2dx_GLNode_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + {0, 0, 0, 0, 0} + }; + + static JSFunctionSpec funcs[] = { + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_GLNode_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + js_cocos2dx_GLNode_prototype = JS_InitClass( + cx, global, + jsb_CCNode_prototype, + js_cocos2dx_GLNode_class, + js_cocos2dx_GLNode_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace + JSBool found; + JS_SetPropertyAttributes(cx, global, "GLNode", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + uint32_t typeId = t.s_id(); + HASH_FIND_INT(_js_global_type_ht, &typeId, p); + if (!p) { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->type = typeId; + p->jsclass = js_cocos2dx_GLNode_class; + p->proto = js_cocos2dx_GLNode_prototype; + p->parentProto = jsb_CCNode_prototype; + HASH_ADD_INT(_js_global_type_ht, type, p); + } +} diff --git a/scripting/javascript/bindings/js_bindings_opengl.h b/scripting/javascript/bindings/js_bindings_opengl.h new file mode 100644 index 0000000000..2288051b9d --- /dev/null +++ b/scripting/javascript/bindings/js_bindings_opengl.h @@ -0,0 +1,10 @@ +#include "cocos2d.h" +#include "ScriptingCore.h" +#include "cocos2d_specifics.hpp" + +class GLNode : public cocos2d::CCNode { + public: + void draw(); +}; + +void js_register_cocos2dx_GLNode(JSContext *cx, JSObject *global); \ No newline at end of file diff --git a/scripting/javascript/bindings/js_manual_conversions.cpp b/scripting/javascript/bindings/js_manual_conversions.cpp index bc2b42f650..b5db7d60cb 100644 --- a/scripting/javascript/bindings/js_manual_conversions.cpp +++ b/scripting/javascript/bindings/js_manual_conversions.cpp @@ -148,6 +148,43 @@ JSBool jsval_to_uint( JSContext *cx, jsval vp, unsigned int *ret ) return jsval_to_int32(cx, vp, (int32_t*)ret); } + +JSBool JSB_jsval_to_int32( JSContext *cx, jsval vp, int32_t *outval ) +{ + JSBool ret = JS_FALSE; + double dp; + if( (ret=JS_ValueToNumber(cx, vp, &dp)) ) { + if( isnan(dp)) + return JS_FALSE; + *outval = (int32_t)dp; + } + return ret; +} + +JSBool JSB_jsval_to_uint32( JSContext *cx, jsval vp, uint32_t *outval ) +{ + JSBool ret = JS_FALSE; + double dp; + if( (ret=JS_ValueToNumber(cx, vp, &dp)) ) { + if( isnan(dp)) + return JS_FALSE; + *outval = (uint32_t)dp; + } + return ret; +} + +JSBool JSB_jsval_to_uint16( JSContext *cx, jsval vp, uint16_t *outval ) +{ + JSBool ret = JS_FALSE; + double dp; + if( (ret=JS_ValueToNumber(cx, vp, &dp)) ) { + if( isnan(dp)) + return JS_FALSE; + *outval = (uint16_t)dp; + } + return ret; +} + jsval int_to_jsval( JSContext *cx, int number ) { return INT_TO_JSVAL(number); @@ -217,3 +254,96 @@ jsval charptr_to_jsval( JSContext *cx, const char *str) return STRING_TO_JSVAL(ret_obj); } + + +JSBool JSB_jsval_typedarray_to_dataptr( JSContext *cx, jsval vp, GLsizei *count, void **data, JSArrayBufferViewType t) +{ + JSObject *jsobj; + JSBool ok = JS_ValueToObject( cx, vp, &jsobj ); + JSB_PRECONDITION2( ok && jsobj, cx, JS_FALSE, "Error converting value to object"); + + // WebGL supports TypedArray and sequences for some of its APIs. So when converting a TypedArray, we should + // also check for a possible non-Typed Array JS object, like a JS Array. + + if( JS_IsTypedArrayObject( jsobj ) ) { + + *count = JS_GetTypedArrayLength(jsobj); + JSArrayBufferViewType type = JS_GetArrayBufferViewType(jsobj); + JSB_PRECONDITION2(t==type, cx, JS_FALSE, "TypedArray type different than expected type"); + + switch (t) { + case js::ArrayBufferView::TYPE_INT8: + case js::ArrayBufferView::TYPE_UINT8: + *data = JS_GetUint8ArrayData(jsobj); + break; + + case js::ArrayBufferView::TYPE_INT16: + case js::ArrayBufferView::TYPE_UINT16: + *data = JS_GetUint16ArrayData(jsobj); + break; + + case js::ArrayBufferView::TYPE_INT32: + case js::ArrayBufferView::TYPE_UINT32: + *data = JS_GetUint32ArrayData(jsobj); + break; + + case js::ArrayBufferView::TYPE_FLOAT32: + *data = JS_GetFloat32ArrayData(jsobj); + break; + + default: + JSB_PRECONDITION2(false, cx, JS_FALSE, "Unsupported typedarray type"); + break; + } + } else if( JS_IsArrayObject(cx, jsobj)) { + // Slow... avoid it. Use TypedArray instead, but the spec says that it can receive + // Sequence<> as well. + uint32_t length; + JS_GetArrayLength(cx, jsobj, &length); + + for( uint32_t i=0; i? getAttachedShaders(WebGLProgram? program); +JSBool JSB_glGetAttachedShaders(JSContext *cx, uint32_t argc, jsval *vp) +{ + JSB_PRECONDITION2( argc == 1, cx, JS_FALSE, "Invalid number of arguments" ); + jsval *argvp = JS_ARGV(cx,vp); + JSBool ok = JS_TRUE; + uint32_t arg0; + + ok &= jsval_to_uint( cx, *argvp++, &arg0 ); + JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments"); + + GLsizei length; + glGetProgramiv(arg0, GL_ATTACHED_SHADERS, &length); + GLuint* buffer = new GLuint[length]; + memset(buffer, 0, length * sizeof(GLuint)); + glGetAttachedShaders(arg0, length, NULL, buffer); + + JSObject *jsobj = JS_NewArrayObject(cx, length, NULL); + JSB_PRECONDITION2(jsobj, cx, JS_FALSE, "Error creating JS Object"); + + for( int i=0; i? getSupportedExtensions(); +JSBool JSB_glGetSupportedExtensions(JSContext *cx, uint32_t argc, jsval *vp) +{ + JSB_PRECONDITION2( argc == 0, cx, JS_FALSE, "Invalid number of arguments" ); + + const GLubyte *extensions = glGetString(GL_EXTENSIONS); + + JSObject *jsobj = JS_NewArrayObject(cx, 0, NULL); + JSB_PRECONDITION2(jsobj, cx, JS_FALSE, "Error creating JS Object"); + + // copy, to be able to add '\0' + size_t len = strlen((char*)extensions); + GLubyte* copy = new GLubyte[len+1]; + strncpy((char*)copy, (const char*)extensions, len ); + + int start_extension=0; + int element=0; + for( int i=0; i +#include "jsapi.h" + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + +// compatible with iOS +#define glClearDepthf glClearDepth +#define glDepthRangef glDepthRange +#define glReleaseShaderCompiler() + +#endif // __MAC_OS_X_VERSION_MAX_ALLOWED + +// forward declaration of new functions +JSBool JSB_glGetSupportedExtensions(JSContext *cx, uint32_t argc, jsval *vp); + + +#endif // JSB_INCLUDE_OPENGL + +#endif // __jsb_opengl_manual diff --git a/scripting/javascript/bindings/jsb_opengl_registration.cpp b/scripting/javascript/bindings/jsb_opengl_registration.cpp new file mode 100644 index 0000000000..434737f24b --- /dev/null +++ b/scripting/javascript/bindings/jsb_opengl_registration.cpp @@ -0,0 +1,188 @@ +/* + * JS Bindings: https://github.com/zynga/jsbindings + * + * Copyright (c) 2012 Zynga Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "js_bindings_config.h" +#include "js_bindings_core.h" +#include "jsfriendapi.h" +#include "jsb_opengl_manual.h" +#include "js_bindings_opengl.h" + +//#include "jsb_opengl_functions_registration.h" + +// system +#include "jsb_opengl_functions.h" + +void JSB_register_opengl(JSContext *_cx, JSObject *object) +{ + // + // gl + // + JSObject *opengl = JS_NewObject(_cx, NULL, NULL, NULL); + jsval openglVal = OBJECT_TO_JSVAL(opengl); + JS_SetProperty(_cx, object, "gl", &openglVal); + + jsval nsval; + JSObject *ccns; + JS_GetProperty(_cx, object, "cc", &nsval); + if (nsval == JSVAL_VOID) { + ccns = JS_NewObject(_cx, NULL, NULL, NULL); + nsval = OBJECT_TO_JSVAL(ccns); + JS_SetProperty(_cx, object, "cc", &nsval); + } else { + JS_ValueToObject(_cx, nsval, &ccns); + } + + js_register_cocos2dx_GLNode(_cx, ccns); + + // New WebGL functions, not present on OpenGL ES 2.0 + JS_DefineFunction(_cx, opengl, "getSupportedExtensions", JSB_glGetSupportedExtensions, 0, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "activeTexture", JSB_glActiveTexture, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_attachShader", JSB_glAttachShader, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_bindAttribLocation", JSB_glBindAttribLocation, 3, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_bindBuffer", JSB_glBindBuffer, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_bindFramebuffer", JSB_glBindFramebuffer, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_bindRenderbuffer", JSB_glBindRenderbuffer, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_bindTexture", JSB_glBindTexture, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "blendColor", JSB_glBlendColor, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "blendEquation", JSB_glBlendEquation, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "blendEquationSeparate", JSB_glBlendEquationSeparate, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "blendFunc", JSB_glBlendFunc, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "blendFuncSeparate", JSB_glBlendFuncSeparate, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "bufferData", JSB_glBufferData, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "bufferSubData", JSB_glBufferSubData, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "checkFramebufferStatus", JSB_glCheckFramebufferStatus, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "clear", JSB_glClear, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "clearColor", JSB_glClearColor, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "clearDepthf", JSB_glClearDepthf, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "clearStencil", JSB_glClearStencil, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "colorMask", JSB_glColorMask, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_compileShader", JSB_glCompileShader, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "compressedTexImage2D", JSB_glCompressedTexImage2D, 8, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "compressedTexSubImage2D", JSB_glCompressedTexSubImage2D, 9, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "copyTexImage2D", JSB_glCopyTexImage2D, 8, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "copyTexSubImage2D", JSB_glCopyTexSubImage2D, 8, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_createProgram", JSB_glCreateProgram, 0, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_createShader", JSB_glCreateShader, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "cullFace", JSB_glCullFace, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_deleteBuffer", JSB_glDeleteBuffers, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_deleteFramebuffer", JSB_glDeleteFramebuffers, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_deleteProgram", JSB_glDeleteProgram, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_deleteRenderbuffer", JSB_glDeleteRenderbuffers, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_deleteShader", JSB_glDeleteShader, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_deleteTexture", JSB_glDeleteTextures, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "depthFunc", JSB_glDepthFunc, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "depthMask", JSB_glDepthMask, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "depthRangef", JSB_glDepthRangef, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "detachShader", JSB_glDetachShader, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "disable", JSB_glDisable, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "disableVertexAttribArray", JSB_glDisableVertexAttribArray, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "drawArrays", JSB_glDrawArrays, 3, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "drawElements", JSB_glDrawElements, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "enable", JSB_glEnable, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "enableVertexAttribArray", JSB_glEnableVertexAttribArray, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "finish", JSB_glFinish, 0, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "flush", JSB_glFlush, 0, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "framebufferRenderbuffer", JSB_glFramebufferRenderbuffer, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "framebufferTexture2D", JSB_glFramebufferTexture2D, 5, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "frontFace", JSB_glFrontFace, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_createBuffer", JSB_glGenBuffers, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_createFramebuffer", JSB_glGenFramebuffers, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_createRenderbuffer", JSB_glGenRenderbuffers, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_createTexture", JSB_glGenTextures, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "generateMipmap", JSB_glGenerateMipmap, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_getActiveAttrib", JSB_glGetActiveAttrib, 7, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_getActiveUniform", JSB_glGetActiveUniform, 7, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_getAttachedShaders", JSB_glGetAttachedShaders, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_getAttribLocation", JSB_glGetAttribLocation, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "getError", JSB_glGetError, 0, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_getProgramInfoLog", JSB_glGetProgramInfoLog, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_getProgramParameter", JSB_glGetProgramiv, 3, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_getShaderInfoLog", JSB_glGetShaderInfoLog, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_getShaderSource", JSB_glGetShaderSource, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_getShaderParameter", JSB_glGetShaderiv, 3, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "getTexParameter", JSB_glGetTexParameterfv, 3, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_getUniformLocation", JSB_glGetUniformLocation, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_getUniform", JSB_glGetUniformfv, 3, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "hint", JSB_glHint, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "isBuffer", JSB_glIsBuffer, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "isEnabled", JSB_glIsEnabled, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "isFramebuffer", JSB_glIsFramebuffer, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "isProgram", JSB_glIsProgram, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "isRenderbuffer", JSB_glIsRenderbuffer, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "isShader", JSB_glIsShader, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "isTexture", JSB_glIsTexture, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "lineWidth", JSB_glLineWidth, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_linkProgram", JSB_glLinkProgram, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "pixelStorei", JSB_glPixelStorei, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "polygonOffset", JSB_glPolygonOffset, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "readPixels", JSB_glReadPixels, 7, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "releaseShaderCompiler", JSB_glReleaseShaderCompiler, 0, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "renderbufferStorage", JSB_glRenderbufferStorage, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "sampleCoverage", JSB_glSampleCoverage, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "scissor", JSB_glScissor, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_shaderSource", JSB_glShaderSource, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "stencilFunc", JSB_glStencilFunc, 3, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "stencilFuncSeparate", JSB_glStencilFuncSeparate, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "stencilMask", JSB_glStencilMask, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "stencilMaskSeparate", JSB_glStencilMaskSeparate, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "stencilOp", JSB_glStencilOp, 3, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "stencilOpSeparate", JSB_glStencilOpSeparate, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_texImage2D", JSB_glTexImage2D, 9, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "texParameterf", JSB_glTexParameterf, 3, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "texParameteri", JSB_glTexParameteri, 3, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_texSubImage2D", JSB_glTexSubImage2D, 9, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "uniform1f", JSB_glUniform1f, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "uniform1fv", JSB_glUniform1fv, 3, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "uniform1i", JSB_glUniform1i, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "uniform1iv", JSB_glUniform1iv, 3, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "uniform2f", JSB_glUniform2f, 3, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "uniform2fv", JSB_glUniform2fv, 3, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "uniform2i", JSB_glUniform2i, 3, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "uniform2iv", JSB_glUniform2iv, 3, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "uniform3f", JSB_glUniform3f, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "uniform3fv", JSB_glUniform3fv, 3, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "uniform3i", JSB_glUniform3i, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "uniform3iv", JSB_glUniform3iv, 3, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "uniform4f", JSB_glUniform4f, 5, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "uniform4fv", JSB_glUniform4fv, 3, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "uniform4i", JSB_glUniform4i, 5, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "uniform4iv", JSB_glUniform4iv, 3, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "uniformMatrix2fv", JSB_glUniformMatrix2fv, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "uniformMatrix3fv", JSB_glUniformMatrix3fv, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "uniformMatrix4fv", JSB_glUniformMatrix4fv, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_useProgram", JSB_glUseProgram, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "_validateProgram", JSB_glValidateProgram, 1, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "vertexAttrib1f", JSB_glVertexAttrib1f, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "vertexAttrib1fv", JSB_glVertexAttrib1fv, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "vertexAttrib2f", JSB_glVertexAttrib2f, 3, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "vertexAttrib2fv", JSB_glVertexAttrib2fv, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "vertexAttrib3f", JSB_glVertexAttrib3f, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "vertexAttrib3fv", JSB_glVertexAttrib3fv, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "vertexAttrib4f", JSB_glVertexAttrib4f, 5, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "vertexAttrib4fv", JSB_glVertexAttrib4fv, 2, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "vertexAttribPointer", JSB_glVertexAttribPointer, 6, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + JS_DefineFunction(_cx, opengl, "viewport", JSB_glViewport, 4, JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE ); + +} + diff --git a/scripting/javascript/bindings/jsb_opengl_registration.h b/scripting/javascript/bindings/jsb_opengl_registration.h new file mode 100644 index 0000000000..1351c240a9 --- /dev/null +++ b/scripting/javascript/bindings/jsb_opengl_registration.h @@ -0,0 +1,32 @@ +/* + * JS Bindings: https://github.com/zynga/jsbindings + * + * Copyright (c) 2012 Zynga Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +#ifndef __JSB_OPENGL_REGISTRATION +#define __JSB_OPENGL_REGISTRATION +#include "jsb_opengl_functions.h" + +void JSB_register_opengl( JSContext *globalC, JSObject *globalO); + +#endif // __JSB_OPENGL_REGISTRATION diff --git a/scripting/javascript/bindings/obfuscate/obfuscate_exclude_cocos2d.js.REMOVED.git-id b/scripting/javascript/bindings/obfuscate/obfuscate_exclude_cocos2d.js.REMOVED.git-id index 1f98f8f036..b8d21c1eac 100644 --- a/scripting/javascript/bindings/obfuscate/obfuscate_exclude_cocos2d.js.REMOVED.git-id +++ b/scripting/javascript/bindings/obfuscate/obfuscate_exclude_cocos2d.js.REMOVED.git-id @@ -1 +1 @@ -f92eb40bc776570519509464d3f3ba6e9d93d3a9 \ No newline at end of file +6ddddf80e821ca5ff218502a76a75d5eba5bb254 \ No newline at end of file diff --git a/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj b/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj index e0d07f6137..d425a659f8 100644 --- a/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj +++ b/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj @@ -16,12 +16,16 @@ + + + + @@ -33,6 +37,9 @@ + + + @@ -42,6 +49,7 @@ + diff --git a/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj.filters b/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj.filters index 17f920d148..f45738ddca 100644 --- a/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj.filters +++ b/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj.filters @@ -59,6 +59,18 @@ manual + + manual + + + manual + + + manual + + + manual + @@ -121,6 +133,18 @@ manual + + manual + + + manual + + + manual + + + manual + diff --git a/tools/tojs/cocos2dx.ini b/tools/tojs/cocos2dx.ini index d52325ca38..ff71bb924b 100644 --- a/tools/tojs/cocos2dx.ini +++ b/tools/tojs/cocos2dx.ini @@ -26,7 +26,7 @@ headers = %(cocosdir)s/cocos2dx/include/cocos2d.h %(cocosdir)s/CocosDenshion/inc # what classes to produce code for. You can use regular expressions here. When testing the regular # expression, it will be enclosed in "^$", like this: "^CCMenu*$". -classes = CCSprite.* CCScene CCNode.* CCDirector CCLayer.* CCMenu.* CCTouch CC.*Action.* CCMove.* CCRotate.* CCBlink.* CCTint.* CCSequence CCRepeat.* CCFade.* CCEase.* CCScale.* CCTransition.* CCSpawn CCAnimat.* CCFlip.* CCDelay.* CCSkew.* CCJump.* CCPlace.* CCShow.* CCProgress.* CCPointArray CCToggleVisibility.* CCHide CCParticle.* CCLabel.* CCAtlas.* CCTextureCache.* CCTexture2D CCCardinal.* CCCatmullRom.* CCParallaxNode CCTileMap.* CCTMX.* CCCallFunc CCRenderTexture CCGridAction CCGrid3DAction CCGridBase$ CCShaky3D CCWaves3D CCFlipX3D CCFlipY3D CCSpeed CCActionManager CCSet SimpleAudioEngine CCScheduler CCTimer CCOrbit.* CCFollow.* CCBezier.* CCCardinalSpline.* CCCamera.* CCDrawNode CC.*3D$ CCLiquid$ CCWaves$ CCShuffleTiles$ CCTurnOffTiles$ CCSplit.* CCTwirl$ CCFileUtils$ +classes = CCSprite.* CCScene CCNode.* CCDirector CCLayer.* CCMenu.* CCTouch CC.*Action.* CCMove.* CCRotate.* CCBlink.* CCTint.* CCSequence CCRepeat.* CCFade.* CCEase.* CCScale.* CCTransition.* CCSpawn CCAnimat.* CCFlip.* CCDelay.* CCSkew.* CCJump.* CCPlace.* CCShow.* CCProgress.* CCPointArray CCToggleVisibility.* CCHide CCParticle.* CCLabel.* CCAtlas.* CCTextureCache.* CCTexture2D CCCardinal.* CCCatmullRom.* CCParallaxNode CCTileMap.* CCTMX.* CCCallFunc CCRenderTexture CCGridAction CCGrid3DAction CCGridBase$ CCShaky3D CCWaves3D CCFlipX3D CCFlipY3D CCSpeed CCActionManager CCSet SimpleAudioEngine CCScheduler CCTimer CCOrbit.* CCFollow.* CCBezier.* CCCardinalSpline.* CCCamera.* CCDrawNode CC.*3D$ CCLiquid$ CCWaves$ CCShuffleTiles$ CCTurnOffTiles$ CCSplit.* CCTwirl$ CCFileUtils$ CCGLProgram CCShaderCache # what should we skip? in the format ClassName::[function function] # ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also @@ -35,7 +35,7 @@ classes = CCSprite.* CCScene CCNode.* CCDirector CCLayer.* CCMenu.* CCTouch CC.* # will apply to all class names. This is a convenience wildcard to be able to skip similar named # functions from all classes. -skip = CCNode::[.*Transform convertToWindowSpace ^setPosition$ getGrid setGLServerState description getShaderProgram getUserObject .*UserData getGLServerState .*schedule], +skip = CCNode::[.*Transform convertToWindowSpace ^setPosition$ getGrid setGLServerState description getUserObject .*UserData getGLServerState .*schedule], CCSprite::[getQuad displayFrame getBlendFunc ^setPosition$ setBlendFunc setSpriteBatchNode getSpriteBatchNode], CCSpriteBatchNode::[getBlendFunc setBlendFunc], CCMotionStreak::[getBlendFunc setBlendFunc], @@ -83,6 +83,7 @@ skip = CCNode::[.*Transform convertToWindowSpace ^setPosition$ getGrid setGLServ CCSequence::[create], CCSpawn::[create], CCAnimation::[create], + CCGLProgram::[getProgram setUniformLocationWith2f.* setUniformLocationWith1f.* setUniformLocationWith3f.* setUniformLocationWith4f.*], CCGrid3DAction::[create actionWith.*], CCTiledGrid3DAction::[create actionWith.*], CCTMXMapInfo::[startElement endElement textHandler], @@ -107,6 +108,7 @@ rename_functions = CCDirector::[sharedDirector=getInstance], CCAnimationCache::[sharedAnimationCache=getInstance addAnimationsWithFile=addAnimations animationByName=getAnimation removeAnimationByName=removeAnimation], CCLayerGradient::[initWithColor=init], CCLayerColor::[initWithColor=init], + CCGLProgram::[fragmentShaderLog=getFragmentShaderLog initWithVertexShaderByteArray=initWithString initWithVertexShaderFilename=init programLog=getProgramLog setUniformLocationWith1i=setUniformLocationI32 vertexShaderLog=getVertexShaderLog], CCNode::[boundingBox=getBoundingBox removeFromParentAndCleanup=removeFromParent removeAllChildrenWithCleanup=removeAllChildren], CCLabelAtlas::[create=_create], CCTMXLayer::[tileAt=getTileAt tileGIDAt=getTileGIDAt propertyNamed=getProperty], @@ -118,6 +120,7 @@ rename_functions = CCDirector::[sharedDirector=getInstance], CCCamera::[setUpXYZ=setUp getUpXYZ=getUp setEyeXYZ=setEye getEyeXYZ=getEye setCenterXYZ=setCenter getCenterXYZ=getCenter], CCTMXTiledMap::[layerNamed=getLayer objectGroupNamed=getObjectGroup propertyNamed=getProperty], CCTexture2D::[defaultAlphaPixelFormat=getDefaultAlphaPixelFormat], + CCShaderCache::[programForKey=getProgram sharedShaderCache=getInstance], CCFileUtils::[sharedFileUtils=getInstance loadFilenameLookupDictionaryFromFile=loadFilenameLookup] rename_classes = CCParticleSystemQuad::CCParticleSystem,