CCGLViewImpl-android.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /****************************************************************************
  2. Copyright (c) 2010-2012 cocos2d-x.org
  3. Copyright (c) 2013-2016 Chukong Technologies Inc.
  4. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  5. http://www.cocos2d-x.org
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. ****************************************************************************/
  22. #include "platform/CCPlatformConfig.h"
  23. #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
  24. #include "platform/android/CCGLViewImpl-android.h"
  25. #include "base/CCDirector.h"
  26. #include "base/ccMacros.h"
  27. #include "platform/android/jni/JniHelper.h"
  28. #include "CCGL.h"
  29. #include <stdlib.h>
  30. #include <android/log.h>
  31. // <EGL/egl.h> exists since android 2.3
  32. #include <EGL/egl.h>
  33. PFNGLGENVERTEXARRAYSOESPROC glGenVertexArraysOESEXT = 0;
  34. PFNGLBINDVERTEXARRAYOESPROC glBindVertexArrayOESEXT = 0;
  35. PFNGLDELETEVERTEXARRAYSOESPROC glDeleteVertexArraysOESEXT = 0;
  36. void initExtensions() {
  37. glGenVertexArraysOESEXT = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress("glGenVertexArraysOES");
  38. glBindVertexArrayOESEXT = (PFNGLBINDVERTEXARRAYOESPROC)eglGetProcAddress("glBindVertexArrayOES");
  39. glDeleteVertexArraysOESEXT = (PFNGLDELETEVERTEXARRAYSOESPROC)eglGetProcAddress("glDeleteVertexArraysOES");
  40. }
  41. NS_CC_BEGIN
  42. GLViewImpl* GLViewImpl::createWithRect(const std::string& viewName, Rect rect, float frameZoomFactor)
  43. {
  44. auto ret = new GLViewImpl;
  45. if(ret && ret->initWithRect(viewName, rect, frameZoomFactor)) {
  46. ret->autorelease();
  47. return ret;
  48. }
  49. CC_SAFE_DELETE(ret);
  50. return nullptr;
  51. }
  52. GLViewImpl* GLViewImpl::create(const std::string& viewName)
  53. {
  54. auto ret = new GLViewImpl;
  55. if(ret && ret->initWithFullScreen(viewName)) {
  56. ret->autorelease();
  57. return ret;
  58. }
  59. CC_SAFE_DELETE(ret);
  60. return nullptr;
  61. }
  62. GLViewImpl* GLViewImpl::createWithFullScreen(const std::string& viewName)
  63. {
  64. auto ret = new GLViewImpl();
  65. if(ret && ret->initWithFullScreen(viewName)) {
  66. ret->autorelease();
  67. return ret;
  68. }
  69. CC_SAFE_DELETE(ret);
  70. return nullptr;
  71. }
  72. GLViewImpl::GLViewImpl()
  73. {
  74. initExtensions();
  75. }
  76. GLViewImpl::~GLViewImpl()
  77. {
  78. }
  79. bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float frameZoomFactor)
  80. {
  81. return true;
  82. }
  83. bool GLViewImpl::initWithFullScreen(const std::string& viewName)
  84. {
  85. return true;
  86. }
  87. bool GLViewImpl::isOpenGLReady()
  88. {
  89. return (_screenSize.width != 0 && _screenSize.height != 0);
  90. }
  91. void GLViewImpl::end()
  92. {
  93. JniHelper::callStaticVoidMethod("org/cocos2dx/lib/Cocos2dxHelper", "terminateProcess");
  94. }
  95. void GLViewImpl::swapBuffers()
  96. {
  97. }
  98. void GLViewImpl::setIMEKeyboardState(bool bOpen)
  99. {
  100. if (bOpen) {
  101. JniHelper::callStaticVoidMethod("org/cocos2dx/lib/Cocos2dxGLSurfaceView", "openIMEKeyboard");
  102. } else {
  103. JniHelper::callStaticVoidMethod("org/cocos2dx/lib/Cocos2dxGLSurfaceView", "closeIMEKeyboard");
  104. }
  105. }
  106. NS_CC_END
  107. #endif // CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID