From dc20cb816488df3b273cef6538c8a80e57eb13d1 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 2 Mar 2018 11:04:21 +0800 Subject: [PATCH] Adds opengl utils. --- .../js-bindings/manual/jsb_opengl_utils.cpp | 25 +++++++++ .../js-bindings/manual/jsb_opengl_utils.hpp | 54 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 native/cocos/scripting/js-bindings/manual/jsb_opengl_utils.cpp create mode 100644 native/cocos/scripting/js-bindings/manual/jsb_opengl_utils.hpp diff --git a/native/cocos/scripting/js-bindings/manual/jsb_opengl_utils.cpp b/native/cocos/scripting/js-bindings/manual/jsb_opengl_utils.cpp new file mode 100644 index 0000000000..1feaa3a558 --- /dev/null +++ b/native/cocos/scripting/js-bindings/manual/jsb_opengl_utils.cpp @@ -0,0 +1,25 @@ +/**************************************************************************** + Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos2d-x.org + + 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 "jsb_opengl_utils.hpp" diff --git a/native/cocos/scripting/js-bindings/manual/jsb_opengl_utils.hpp b/native/cocos/scripting/js-bindings/manual/jsb_opengl_utils.hpp new file mode 100644 index 0000000000..95b4af34c4 --- /dev/null +++ b/native/cocos/scripting/js-bindings/manual/jsb_opengl_utils.hpp @@ -0,0 +1,54 @@ + +/**************************************************************************** + Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos2d-x.org + + 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. + ****************************************************************************/ + +#pragma once + +#include "cocos/renderer/gfx/GFXUtils.h" + +#define _JSB_GL_CHECK(_call) \ + do { \ + _call; \ + GLenum gl_err = glGetError(); \ + if (0 != gl_err) { \ + SE_REPORT_ERROR(#_call "; GL error 0x%x: %s", gl_err, glEnumName(gl_err)); \ + return false; \ + } \ + } while(false) + + +#if COCOS2D_DEBUG > 0 +# define JSB_GL_CHECK(_call) _JSB_GL_CHECK(_call) +# define JSB_GL_CHECK_ERROR() \ + do { \ + GLenum gl_err = glGetError(); \ + if (0 != gl_err) { \ + SE_REPORT_ERROR("line: %d: GL error 0x%x: %s", __LINE__, gl_err, glEnumName(gl_err)); \ + return false; \ + } \ + } while(false) +#else +# define JSB_GL_CHECK(_call) _call +# define JSB_GL_CHECK_ERROR() +#endif // BRENDERER_CONFIG_DEBUG