2010-11-12 17:16:15 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
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
|
|
|
|
|
|
|
#include "CCPlatformConfig.h"
|
|
|
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
|
|
|
|
|
|
|
#include "CCGLView.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
#include "CCDirector.h"
|
|
|
|
#include "ccMacros.h"
|
|
|
|
#include "jni/IMEJni.h"
|
2012-09-08 08:23:04 +08:00
|
|
|
#include "jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h"
|
2012-06-19 16:20:46 +08:00
|
|
|
#include "CCGL.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <android/log.h>
|
2012-06-19 16:20:46 +08:00
|
|
|
|
2012-05-05 10:06:41 +08:00
|
|
|
|
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;
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
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-01-31 12:16:40 +08:00
|
|
|
GLView* GLView::createWithRect(const std::string& viewName, Rect rect, float frameZoomFactor)
|
2014-01-24 07:36:55 +08:00
|
|
|
{
|
2014-01-31 08:51:43 +08:00
|
|
|
auto ret = new GLView;
|
2014-01-31 12:16:40 +08:00
|
|
|
if(ret && ret->initWithRect(viewName, rect, frameZoomFactor)) {
|
2014-01-24 07:36:55 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-01-31 08:51:43 +08:00
|
|
|
GLView* GLView::create(const std::string& viewName)
|
2014-01-24 07:36:55 +08:00
|
|
|
{
|
2014-01-31 08:51:43 +08:00
|
|
|
auto ret = new GLView;
|
2014-01-31 12:16:40 +08:00
|
|
|
if(ret && ret->initWithFullScreen(viewName)) {
|
2014-01-24 07:36:55 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-01-31 08:51:43 +08:00
|
|
|
GLView* GLView::createWithFullScreen(const std::string& viewName)
|
2014-01-24 07:36:55 +08:00
|
|
|
{
|
2014-01-31 08:51:43 +08:00
|
|
|
auto ret = new GLView();
|
2014-01-24 07:36:55 +08:00
|
|
|
if(ret && ret->initWithFullScreen(viewName)) {
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-01-31 08:51:43 +08:00
|
|
|
GLView::GLView()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
initExtensions();
|
2010-11-12 17:16:15 +08:00
|
|
|
}
|
|
|
|
|
2014-01-31 08:51:43 +08:00
|
|
|
GLView::~GLView()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-01-31 12:16:40 +08:00
|
|
|
bool GLView::initWithRect(const std::string& viewName, Rect rect, float frameZoomFactor)
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
2014-01-24 07:36:55 +08:00
|
|
|
return true;
|
2012-04-23 15:40:46 +08:00
|
|
|
}
|
2010-11-12 17:16:15 +08:00
|
|
|
|
2014-01-31 08:51:43 +08:00
|
|
|
bool GLView::initWithFullScreen(const std::string& viewName)
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
2014-01-24 07:36:55 +08:00
|
|
|
return true;
|
2010-11-12 17:16:15 +08:00
|
|
|
}
|
|
|
|
|
2014-01-24 07:36:55 +08:00
|
|
|
|
2014-01-31 08:51:43 +08:00
|
|
|
bool GLView::isOpenGLReady()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
2014-01-24 07:36:55 +08:00
|
|
|
return (_screenSize.width != 0 && _screenSize.height != 0);
|
2011-02-23 18:22:05 +08:00
|
|
|
}
|
|
|
|
|
2014-01-31 08:51:43 +08:00
|
|
|
void GLView::end()
|
2011-02-23 18:22:05 +08:00
|
|
|
{
|
2014-01-24 07:36:55 +08:00
|
|
|
terminateProcessJNI();
|
2011-02-23 18:22:05 +08:00
|
|
|
}
|
2010-11-12 17:16:15 +08:00
|
|
|
|
2014-01-31 08:51:43 +08:00
|
|
|
void GLView::swapBuffers()
|
2013-07-12 06:24:23 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-01-31 08:51:43 +08:00
|
|
|
void GLView::setIMEKeyboardState(bool bOpen)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
setKeyboardStateJNI((int)bOpen);
|
|
|
|
}
|
|
|
|
|
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
|