Files
cocos4/native/cocos/scripting/js-bindings/manual/jsb_opengl_node.cpp
T
Jare Guo d9bd3d763c update license (#1089)
* updating license

* update license
2018-02-01 15:20:01 +08:00

130 lines
4.9 KiB
C++

/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
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 "jsb_opengl_node.hpp"
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
#include "cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp"
#include "cocos/scripting/js-bindings/manual/jsb_conversions.hpp"
#include "cocos/scripting/js-bindings/manual/jsb_global.h"
#include "scripting/js-bindings/manual/jsb_opengl_functions.hpp"
USING_NS_CC;
void JSB_GLNode::draw(Renderer *renderer, const Mat4& transform, uint32_t flags)
{
_customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(JSB_GLNode::onDraw, this, transform, flags);
renderer->addCommand(&_customCommand);
}
void JSB_GLNode::onDraw(Mat4 &transform, uint32_t flags)
{
se::ScriptEngine::getInstance()->clearException();
se::AutoHandleScope hs;
auto iter = se::NativePtrToObjectMap::find(this);
if (iter != se::NativePtrToObjectMap::end())
{
se::Object* jsObj = iter->second;
se::Value funcVal;
if (jsObj->getProperty("draw", &funcVal) && funcVal.isObject() && funcVal.toObject()->isFunction())
{
auto director = Director::getInstance();
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
funcVal.toObject()->call(se::EmptyValueArray, jsObj);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
}
}
static se::Class* __jsb_cocos2dx_GLNode_class = nullptr;
static se::Object* __jsb_cocos2dx_GLNode_proto = nullptr;
static bool js_cocos2dx_GLNode_finalize(se::State& s)
{
CCLOGINFO("jsbindings: finalizing JS object %p (JSB_GLNode)", s.nativeThisObject());
JSB_GLNode* cobj = (JSB_GLNode*)s.nativeThisObject();
if (cobj->getReferenceCount() == 1)
cobj->autorelease();
else
cobj->release();
return true;
}
SE_BIND_FINALIZE_FUNC(js_cocos2dx_GLNode_finalize)
static bool js_cocos2dx_GLNode_constructor(se::State& s)
{
JSB_GLNode* cobj = new (std::nothrow) JSB_GLNode();
s.thisObject()->setPrivateData(cobj);
return true;
}
SE_BIND_CTOR(js_cocos2dx_GLNode_constructor, __jsb_cocos2dx_GLNode_class, js_cocos2dx_GLNode_finalize)
static bool js_cocos2dx_GLNode_ctor(se::State& s)
{
JSB_GLNode* cobj = new (std::nothrow) JSB_GLNode();
s.thisObject()->setPrivateData(cobj);
return true;
}
SE_BIND_SUB_CLS_CTOR(js_cocos2dx_GLNode_ctor, __jsb_cocos2dx_GLNode_class, js_cocos2dx_GLNode_finalize)
static bool js_cocos2dx_GLNode_create(se::State& s)
{
const auto& args = s.args();
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc == 0) {
auto result = new (std::nothrow) JSB_GLNode();
auto obj = se::Object::createObjectWithClass(__jsb_cocos2dx_GLNode_class);
obj->setPrivateData(result);
s.rval().setObject(obj);
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
return false;
}
SE_BIND_FUNC(js_cocos2dx_GLNode_create)
bool js_register_cocos2dx_GLNode(se::Object* obj)
{
auto cls = se::Class::create("GLNode", obj, __jsb_cocos2d_Node_proto, _SE(js_cocos2dx_GLNode_constructor));
cls->defineFunction("ctor", _SE(js_cocos2dx_GLNode_ctor));
cls->defineStaticFunction("create", _SE(js_cocos2dx_GLNode_create));
cls->defineFinalizeFunction(_SE(js_cocos2dx_GLNode_finalize));
cls->install();
JSBClassType::registerClass<JSB_GLNode>(cls);
__jsb_cocos2dx_GLNode_proto = cls->getProto();
__jsb_cocos2dx_GLNode_class = cls;
jsb_set_extend_property("cc", "GLNode");
se::ScriptEngine::getInstance()->clearException();
return true;
}