axmol/cocos/platform/android/CCGLViewImpl-android.cpp

133 lines
3.9 KiB
C++
Raw Normal View History

2010-11-12 17:16:15 +08:00
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2010-11-12 17:16:15 +08:00
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.
****************************************************************************/
2014-01-31 08:51:43 +08:00
2014-09-10 08:41:49 +08:00
#include "platform/CCPlatformConfig.h"
2014-01-31 08:51:43 +08:00
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#include "platform/android/CCGLViewImpl-android.h"
2014-04-30 08:37:36 +08:00
#include "base/CCDirector.h"
#include "base/ccMacros.h"
2015-11-27 18:19:10 +08:00
#include "platform/android/jni/JniHelper.h"
#include "CCGL.h"
#include <stdlib.h>
#include <android/log.h>
2012-11-16 14:23:14 +08:00
// <EGL/egl.h> exists since android 2.3
#include <EGL/egl.h>
PFNGLGENVERTEXARRAYSOESPROC glGenVertexArraysOESEXT = 0;
PFNGLBINDVERTEXARRAYOESPROC glBindVertexArrayOESEXT = 0;
PFNGLDELETEVERTEXARRAYSOESPROC glDeleteVertexArraysOESEXT = 0;
void initExtensions() {
glGenVertexArraysOESEXT = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress("glGenVertexArraysOES");
glBindVertexArrayOESEXT = (PFNGLBINDVERTEXARRAYOESPROC)eglGetProcAddress("glBindVertexArrayOES");
glDeleteVertexArraysOESEXT = (PFNGLDELETEVERTEXARRAYSOESPROC)eglGetProcAddress("glDeleteVertexArraysOES");
}
2010-11-12 17:16:15 +08:00
2012-04-18 18:43:45 +08:00
NS_CC_BEGIN
2010-11-12 17:16:15 +08:00
2014-07-31 00:53:04 +08:00
GLViewImpl* GLViewImpl::createWithRect(const std::string& viewName, Rect rect, float frameZoomFactor)
{
2014-07-31 00:53:04 +08:00
auto ret = new GLViewImpl;
if(ret && ret->initWithRect(viewName, rect, frameZoomFactor)) {
ret->autorelease();
return ret;
}
2015-10-19 18:46:45 +08:00
CC_SAFE_DELETE(ret);
return nullptr;
}
2014-07-31 00:53:04 +08:00
GLViewImpl* GLViewImpl::create(const std::string& viewName)
{
2014-07-31 00:53:04 +08:00
auto ret = new GLViewImpl;
if(ret && ret->initWithFullScreen(viewName)) {
ret->autorelease();
return ret;
}
2015-10-19 18:46:45 +08:00
CC_SAFE_DELETE(ret);
return nullptr;
}
2014-07-31 00:53:04 +08:00
GLViewImpl* GLViewImpl::createWithFullScreen(const std::string& viewName)
{
2014-07-31 00:53:04 +08:00
auto ret = new GLViewImpl();
if(ret && ret->initWithFullScreen(viewName)) {
ret->autorelease();
return ret;
}
2015-10-19 18:46:45 +08:00
CC_SAFE_DELETE(ret);
return nullptr;
}
2014-07-31 00:53:04 +08:00
GLViewImpl::GLViewImpl()
2010-11-12 17:16:15 +08:00
{
initExtensions();
2010-11-12 17:16:15 +08:00
}
2014-07-31 00:53:04 +08:00
GLViewImpl::~GLViewImpl()
2010-11-12 17:16:15 +08:00
{
}
2014-07-31 00:53:04 +08:00
bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float frameZoomFactor)
2010-11-12 17:16:15 +08:00
{
return true;
}
2010-11-12 17:16:15 +08:00
2014-07-31 00:53:04 +08:00
bool GLViewImpl::initWithFullScreen(const std::string& viewName)
2010-11-12 17:16:15 +08:00
{
return true;
2010-11-12 17:16:15 +08:00
}
2014-07-31 00:53:04 +08:00
bool GLViewImpl::isOpenGLReady()
2010-11-12 17:16:15 +08:00
{
return (_screenSize.width != 0 && _screenSize.height != 0);
}
2014-07-31 00:53:04 +08:00
void GLViewImpl::end()
{
JniHelper::callStaticVoidMethod("org/cocos2dx/lib/Cocos2dxHelper", "terminateProcess");
}
2010-11-12 17:16:15 +08:00
2014-07-31 00:53:04 +08:00
void GLViewImpl::swapBuffers()
{
}
2014-07-31 00:53:04 +08:00
void GLViewImpl::setIMEKeyboardState(bool bOpen)
{
if (bOpen) {
JniHelper::callStaticVoidMethod("org/cocos2dx/lib/Cocos2dxGLSurfaceView", "openIMEKeyboard");
} else {
JniHelper::callStaticVoidMethod("org/cocos2dx/lib/Cocos2dxGLSurfaceView", "closeIMEKeyboard");
}
}
2012-04-18 18:43:45 +08:00
NS_CC_END
2014-01-31 08:51:43 +08:00
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID