mirror of https://github.com/axmolengine/axmol.git
Merge pull request #5172 from dumganhar/use-unified-cceglview
Using unified 'desktop/CCEGLView.h/cpp' for Windows platform too.
This commit is contained in:
commit
aba15dfc2d
|
@ -175,7 +175,7 @@ THE SOFTWARE.
|
|||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
#include "platform/win32/CCApplication.h"
|
||||
#include "platform/win32/CCEGLView.h"
|
||||
#include "platform/desktop/CCEGLView.h"
|
||||
#include "platform/win32/CCGL.h"
|
||||
#include "platform/win32/CCStdC.h"
|
||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||
|
|
|
@ -308,10 +308,10 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
|||
<ClCompile Include="platform\CCFileUtils.cpp" />
|
||||
<ClCompile Include="platform\CCSAXParser.cpp" />
|
||||
<ClCompile Include="platform\CCThread.cpp" />
|
||||
<ClCompile Include="platform\desktop\CCEGLView.cpp" />
|
||||
<ClCompile Include="platform\win32\CCApplication.cpp" />
|
||||
<ClCompile Include="platform\win32\CCCommon.cpp" />
|
||||
<ClCompile Include="platform\win32\CCDevice.cpp" />
|
||||
<ClCompile Include="platform\win32\CCEGLView.cpp" />
|
||||
<ClCompile Include="platform\win32\CCFileUtilsWin32.cpp" />
|
||||
<ClCompile Include="platform\win32\CCImage.cpp" />
|
||||
<ClCompile Include="platform\win32\CCStdC.cpp" />
|
||||
|
@ -511,8 +511,8 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
|||
<ClInclude Include="platform\CCImageCommon_cpp.h" />
|
||||
<ClInclude Include="platform\CCSAXParser.h" />
|
||||
<ClInclude Include="platform\CCThread.h" />
|
||||
<ClInclude Include="platform\desktop\CCEGLView.h" />
|
||||
<ClInclude Include="platform\win32\CCApplication.h" />
|
||||
<ClInclude Include="platform\win32\CCEGLView.h" />
|
||||
<ClInclude Include="platform\win32\CCFileUtilsWin32.h" />
|
||||
<ClInclude Include="platform\win32\CCGL.h" />
|
||||
<ClInclude Include="platform\win32\CCPlatformDefine.h" />
|
||||
|
|
|
@ -112,6 +112,9 @@
|
|||
<Filter Include="renderer">
|
||||
<UniqueIdentifier>{cba0f362-878c-438b-ad0f-43d287516357}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="platform\desktop">
|
||||
<UniqueIdentifier>{32373f63-2c2d-4eab-bc4a-21745ba0b3fb}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\physics\CCPhysicsBody.cpp">
|
||||
|
@ -351,9 +354,6 @@
|
|||
<ClCompile Include="platform\win32\CCDevice.cpp">
|
||||
<Filter>platform\win32</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="platform\win32\CCEGLView.cpp">
|
||||
<Filter>platform\win32</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="platform\win32\CCFileUtilsWin32.cpp">
|
||||
<Filter>platform\win32</Filter>
|
||||
</ClCompile>
|
||||
|
@ -595,6 +595,9 @@
|
|||
<ClCompile Include="CCFontCharMap.cpp">
|
||||
<Filter>label_nodes</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="platform\desktop\CCEGLView.cpp">
|
||||
<Filter>platform\desktop</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\physics\CCPhysicsBody.h">
|
||||
|
@ -852,9 +855,6 @@
|
|||
<ClInclude Include="platform\win32\CCApplication.h">
|
||||
<Filter>platform\win32</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="platform\win32\CCEGLView.h">
|
||||
<Filter>platform\win32</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="platform\win32\CCFileUtilsWin32.h">
|
||||
<Filter>platform\win32</Filter>
|
||||
</ClInclude>
|
||||
|
@ -1198,5 +1198,8 @@
|
|||
<ClInclude Include="CCFontCharMap.h">
|
||||
<Filter>label_nodes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="platform\desktop\CCEGLView.h">
|
||||
<Filter>platform\desktop</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -7,7 +7,7 @@
|
|||
<PropertyGroup />
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>$(EngineRoot)cocos\2d;$(EngineRoot)cocos\2d\renderer;$(EngineRoot)cocos\gui;$(EngineRoot)cocos\base;$(EngineRoot)cocos\physics;$(EngineRoot)cocos\math\kazmath\include;$(EngineRoot)cocos\2d\platform\win32;$(EngineRoot)external\glfw3\include\win32;$(EngineRoot)external\win32-specific\gles\include\OGLES</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(EngineRoot)cocos\2d;$(EngineRoot)cocos\2d\renderer;$(EngineRoot)cocos\gui;$(EngineRoot)cocos\base;$(EngineRoot)cocos\physics;$(EngineRoot)cocos\math\kazmath\include;$(EngineRoot)cocos\2d\platform\win32;$(EngineRoot)cocos\2d\platform\desktop;$(EngineRoot)external\glfw3\include\win32;$(EngineRoot)external\win32-specific\gles\include\OGLES</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_VARIADIC_MAX=10;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
|
|
|
@ -37,8 +37,15 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
struct keyCodeItem
|
||||
{
|
||||
int glfwKeyCode;
|
||||
EventKeyboard::KeyCode keyCode;
|
||||
};
|
||||
|
||||
static std::unordered_map<int, EventKeyboard::KeyCode> g_keyCodeMap = {
|
||||
static std::unordered_map<int, EventKeyboard::KeyCode> g_keyCodeMap;
|
||||
|
||||
static keyCodeItem g_keyCodeStructArray[] = {
|
||||
/* The unknown key */
|
||||
{ GLFW_KEY_UNKNOWN , EventKeyboard::KeyCode::KEY_NONE },
|
||||
|
||||
|
@ -346,6 +353,11 @@ EGLView::EGLView()
|
|||
CCASSERT(nullptr == s_pEglView, "EGLView is singleton, Should be inited only one time\n");
|
||||
_viewName = "cocos2dx";
|
||||
s_pEglView = this;
|
||||
g_keyCodeMap.clear();
|
||||
for (auto& item : g_keyCodeStructArray)
|
||||
{
|
||||
g_keyCodeMap[item.glfwKeyCode] = item.keyCode;
|
||||
}
|
||||
glfwSetErrorCallback(EGLViewEventHandler::onGLFWError);
|
||||
glfwInit();
|
||||
}
|
||||
|
@ -493,10 +505,74 @@ EGLView* EGLView::sharedOpenGLView()
|
|||
return EGLView::getInstance();
|
||||
}
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
static bool glew_dynamic_binding()
|
||||
{
|
||||
const char *gl_extensions = (const char*)glGetString(GL_EXTENSIONS);
|
||||
|
||||
// If the current opengl driver doesn't have framebuffers methods, check if an extension exists
|
||||
if (glGenFramebuffers == NULL)
|
||||
{
|
||||
log("OpenGL: glGenFramebuffers is NULL, try to detect an extension");
|
||||
if (strstr(gl_extensions, "ARB_framebuffer_object"))
|
||||
{
|
||||
log("OpenGL: ARB_framebuffer_object is supported");
|
||||
|
||||
glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC) wglGetProcAddress("glIsRenderbuffer");
|
||||
glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC) wglGetProcAddress("glBindRenderbuffer");
|
||||
glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC) wglGetProcAddress("glDeleteRenderbuffers");
|
||||
glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC) wglGetProcAddress("glGenRenderbuffers");
|
||||
glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC) wglGetProcAddress("glRenderbufferStorage");
|
||||
glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC) wglGetProcAddress("glGetRenderbufferParameteriv");
|
||||
glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC) wglGetProcAddress("glIsFramebuffer");
|
||||
glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC) wglGetProcAddress("glBindFramebuffer");
|
||||
glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC) wglGetProcAddress("glDeleteFramebuffers");
|
||||
glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC) wglGetProcAddress("glGenFramebuffers");
|
||||
glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC) wglGetProcAddress("glCheckFramebufferStatus");
|
||||
glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC) wglGetProcAddress("glFramebufferTexture1D");
|
||||
glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC) wglGetProcAddress("glFramebufferTexture2D");
|
||||
glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC) wglGetProcAddress("glFramebufferTexture3D");
|
||||
glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC) wglGetProcAddress("glFramebufferRenderbuffer");
|
||||
glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) wglGetProcAddress("glGetFramebufferAttachmentParameteriv");
|
||||
glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC) wglGetProcAddress("glGenerateMipmap");
|
||||
}
|
||||
else
|
||||
if (strstr(gl_extensions, "EXT_framebuffer_object"))
|
||||
{
|
||||
log("OpenGL: EXT_framebuffer_object is supported");
|
||||
glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC) wglGetProcAddress("glIsRenderbufferEXT");
|
||||
glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC) wglGetProcAddress("glBindRenderbufferEXT");
|
||||
glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC) wglGetProcAddress("glDeleteRenderbuffersEXT");
|
||||
glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC) wglGetProcAddress("glGenRenderbuffersEXT");
|
||||
glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC) wglGetProcAddress("glRenderbufferStorageEXT");
|
||||
glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC) wglGetProcAddress("glGetRenderbufferParameterivEXT");
|
||||
glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC) wglGetProcAddress("glIsFramebufferEXT");
|
||||
glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC) wglGetProcAddress("glBindFramebufferEXT");
|
||||
glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC) wglGetProcAddress("glDeleteFramebuffersEXT");
|
||||
glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC) wglGetProcAddress("glGenFramebuffersEXT");
|
||||
glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC) wglGetProcAddress("glCheckFramebufferStatusEXT");
|
||||
glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC) wglGetProcAddress("glFramebufferTexture1DEXT");
|
||||
glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC) wglGetProcAddress("glFramebufferTexture2DEXT");
|
||||
glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC) wglGetProcAddress("glFramebufferTexture3DEXT");
|
||||
glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC) wglGetProcAddress("glFramebufferRenderbufferEXT");
|
||||
glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) wglGetProcAddress("glGetFramebufferAttachmentParameterivEXT");
|
||||
glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC) wglGetProcAddress("glGenerateMipmapEXT");
|
||||
}
|
||||
else
|
||||
{
|
||||
log("OpenGL: No framebuffers extension is supported");
|
||||
log("OpenGL: Any call to Fbo will crash!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
// helper
|
||||
bool EGLView::initGlew()
|
||||
{
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_LINUX
|
||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_MAC)
|
||||
GLenum GlewInitResult = glewInit();
|
||||
if (GLEW_OK != GlewInitResult)
|
||||
{
|
||||
|
@ -522,13 +598,18 @@ bool EGLView::initGlew()
|
|||
log("OpenGL 2.0 not supported");
|
||||
}
|
||||
|
||||
// if(glew_dynamic_binding() == false)
|
||||
// {
|
||||
// MessageBox("No OpenGL framebuffer support. Please upgrade the driver of your video card.", "OpenGL error");
|
||||
// return false;
|
||||
// }
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
if(glew_dynamic_binding() == false)
|
||||
{
|
||||
MessageBox("No OpenGL framebuffer support. Please upgrade the driver of your video card.", "OpenGL error");
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif // Linux
|
||||
// Enable point size by default on windows.
|
||||
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
#endif
|
||||
|
||||
#endif // (CC_TARGET_PLATFORM != CC_PLATFORM_MAC)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_EGLVIEW_MAC_H__
|
||||
#define __CC_EGLVIEW_MAC_H__
|
||||
#ifndef __CC_EGLVIEW_DESKTOP_H__
|
||||
#define __CC_EGLVIEW_DESKTOP_H__
|
||||
|
||||
#include "platform/CCCommon.h"
|
||||
#include "platform/CCEGLViewProtocol.h"
|
||||
|
@ -100,4 +100,4 @@ protected:
|
|||
|
||||
NS_CC_END // end of namespace cocos2d
|
||||
|
||||
#endif // end of __CC_EGLVIEW_MAC_H__
|
||||
#endif // end of __CC_EGLVIEW_DESKTOP_H__
|
||||
|
|
|
@ -1,591 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
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 "CCEGLView.h"
|
||||
#include "CCSet.h"
|
||||
#include "ccMacros.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCIMEDispatcher.h"
|
||||
#include "CCApplication.h"
|
||||
#include "CCTouch.h"
|
||||
#include "CCEventDispatcher.h"
|
||||
#include "CCEventKeyboard.h"
|
||||
#include "CCEventMouse.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
struct keyCodeItem
|
||||
{
|
||||
int glfwKeyCode;
|
||||
EventKeyboard::KeyCode keyCode;
|
||||
};
|
||||
|
||||
static std::map<int, EventKeyboard::KeyCode> g_keyCodeMap;
|
||||
|
||||
static keyCodeItem g_keyCodeStructArray[] = {
|
||||
/* The unknown key */
|
||||
{ GLFW_KEY_UNKNOWN , EventKeyboard::KeyCode::KEY_NONE },
|
||||
|
||||
/* Printable keys */
|
||||
|
||||
{ GLFW_KEY_SPACE , EventKeyboard::KeyCode::KEY_SPACE },
|
||||
{ GLFW_KEY_APOSTROPHE , EventKeyboard::KeyCode::KEY_APOSTROPHE },
|
||||
{ GLFW_KEY_COMMA , EventKeyboard::KeyCode::KEY_COMMA },
|
||||
{ GLFW_KEY_MINUS , EventKeyboard::KeyCode::KEY_MINUS },
|
||||
{ GLFW_KEY_PERIOD , EventKeyboard::KeyCode::KEY_PERIOD },
|
||||
{ GLFW_KEY_SLASH , EventKeyboard::KeyCode::KEY_SLASH },
|
||||
{ GLFW_KEY_0 , EventKeyboard::KeyCode::KEY_0 },
|
||||
{ GLFW_KEY_1 , EventKeyboard::KeyCode::KEY_1 },
|
||||
{ GLFW_KEY_2 , EventKeyboard::KeyCode::KEY_2 },
|
||||
{ GLFW_KEY_3 , EventKeyboard::KeyCode::KEY_3 },
|
||||
{ GLFW_KEY_4 , EventKeyboard::KeyCode::KEY_4 },
|
||||
{ GLFW_KEY_5 , EventKeyboard::KeyCode::KEY_5 },
|
||||
{ GLFW_KEY_6 , EventKeyboard::KeyCode::KEY_6 },
|
||||
{ GLFW_KEY_7 , EventKeyboard::KeyCode::KEY_7 },
|
||||
{ GLFW_KEY_8 , EventKeyboard::KeyCode::KEY_8 },
|
||||
{ GLFW_KEY_9 , EventKeyboard::KeyCode::KEY_9 },
|
||||
{ GLFW_KEY_SEMICOLON , EventKeyboard::KeyCode::KEY_SEMICOLON },
|
||||
{ GLFW_KEY_EQUAL , EventKeyboard::KeyCode::KEY_EQUAL },
|
||||
{ GLFW_KEY_A , EventKeyboard::KeyCode::KEY_A },
|
||||
{ GLFW_KEY_B , EventKeyboard::KeyCode::KEY_B },
|
||||
{ GLFW_KEY_C , EventKeyboard::KeyCode::KEY_C },
|
||||
{ GLFW_KEY_D , EventKeyboard::KeyCode::KEY_D },
|
||||
{ GLFW_KEY_E , EventKeyboard::KeyCode::KEY_E },
|
||||
{ GLFW_KEY_F , EventKeyboard::KeyCode::KEY_F },
|
||||
{ GLFW_KEY_G , EventKeyboard::KeyCode::KEY_G },
|
||||
{ GLFW_KEY_H , EventKeyboard::KeyCode::KEY_H },
|
||||
{ GLFW_KEY_I , EventKeyboard::KeyCode::KEY_I },
|
||||
{ GLFW_KEY_J , EventKeyboard::KeyCode::KEY_J },
|
||||
{ GLFW_KEY_K , EventKeyboard::KeyCode::KEY_K },
|
||||
{ GLFW_KEY_L , EventKeyboard::KeyCode::KEY_L },
|
||||
{ GLFW_KEY_M , EventKeyboard::KeyCode::KEY_M },
|
||||
{ GLFW_KEY_N , EventKeyboard::KeyCode::KEY_N },
|
||||
{ GLFW_KEY_O , EventKeyboard::KeyCode::KEY_O },
|
||||
{ GLFW_KEY_P , EventKeyboard::KeyCode::KEY_P },
|
||||
{ GLFW_KEY_Q , EventKeyboard::KeyCode::KEY_Q },
|
||||
{ GLFW_KEY_R , EventKeyboard::KeyCode::KEY_R },
|
||||
{ GLFW_KEY_S , EventKeyboard::KeyCode::KEY_S },
|
||||
{ GLFW_KEY_T , EventKeyboard::KeyCode::KEY_T },
|
||||
{ GLFW_KEY_U , EventKeyboard::KeyCode::KEY_U },
|
||||
{ GLFW_KEY_V , EventKeyboard::KeyCode::KEY_V },
|
||||
{ GLFW_KEY_W , EventKeyboard::KeyCode::KEY_W },
|
||||
{ GLFW_KEY_X , EventKeyboard::KeyCode::KEY_X },
|
||||
{ GLFW_KEY_Y , EventKeyboard::KeyCode::KEY_Y },
|
||||
{ GLFW_KEY_Z , EventKeyboard::KeyCode::KEY_Z },
|
||||
{ GLFW_KEY_LEFT_BRACKET , EventKeyboard::KeyCode::KEY_LEFT_BRACKET },
|
||||
{ GLFW_KEY_BACKSLASH , EventKeyboard::KeyCode::KEY_BACK_SLASH },
|
||||
{ GLFW_KEY_RIGHT_BRACKET , EventKeyboard::KeyCode::KEY_RIGHT_BRACKET },
|
||||
{ GLFW_KEY_GRAVE_ACCENT , EventKeyboard::KeyCode::KEY_GRAVE },
|
||||
{ GLFW_KEY_WORLD_1 , EventKeyboard::KeyCode::KEY_GRAVE },
|
||||
{ GLFW_KEY_WORLD_2 , EventKeyboard::KeyCode::KEY_NONE },
|
||||
|
||||
/* Function keys */
|
||||
{ GLFW_KEY_ESCAPE , EventKeyboard::KeyCode::KEY_ESCAPE },
|
||||
{ GLFW_KEY_ENTER , EventKeyboard::KeyCode::KEY_KP_ENTER },
|
||||
{ GLFW_KEY_TAB , EventKeyboard::KeyCode::KEY_TAB },
|
||||
{ GLFW_KEY_BACKSPACE , EventKeyboard::KeyCode::KEY_BACKSPACE },
|
||||
{ GLFW_KEY_INSERT , EventKeyboard::KeyCode::KEY_INSERT },
|
||||
{ GLFW_KEY_DELETE , EventKeyboard::KeyCode::KEY_DELETE },
|
||||
{ GLFW_KEY_RIGHT , EventKeyboard::KeyCode::KEY_RIGHT_ARROW },
|
||||
{ GLFW_KEY_LEFT , EventKeyboard::KeyCode::KEY_LEFT_ARROW },
|
||||
{ GLFW_KEY_DOWN , EventKeyboard::KeyCode::KEY_DOWN_ARROW },
|
||||
{ GLFW_KEY_UP , EventKeyboard::KeyCode::KEY_UP_ARROW },
|
||||
{ GLFW_KEY_PAGE_UP , EventKeyboard::KeyCode::KEY_KP_PG_UP },
|
||||
{ GLFW_KEY_PAGE_DOWN , EventKeyboard::KeyCode::KEY_KP_PG_DOWN },
|
||||
{ GLFW_KEY_HOME , EventKeyboard::KeyCode::KEY_KP_HOME },
|
||||
{ GLFW_KEY_END , EventKeyboard::KeyCode::KEY_END },
|
||||
{ GLFW_KEY_CAPS_LOCK , EventKeyboard::KeyCode::KEY_CAPS_LOCK },
|
||||
{ GLFW_KEY_SCROLL_LOCK , EventKeyboard::KeyCode::KEY_SCROLL_LOCK },
|
||||
{ GLFW_KEY_NUM_LOCK , EventKeyboard::KeyCode::KEY_NUM_LOCK },
|
||||
{ GLFW_KEY_PRINT_SCREEN , EventKeyboard::KeyCode::KEY_PRINT },
|
||||
{ GLFW_KEY_PAUSE , EventKeyboard::KeyCode::KEY_PAUSE },
|
||||
{ GLFW_KEY_F1 , EventKeyboard::KeyCode::KEY_F1 },
|
||||
{ GLFW_KEY_F2 , EventKeyboard::KeyCode::KEY_F2 },
|
||||
{ GLFW_KEY_F3 , EventKeyboard::KeyCode::KEY_F3 },
|
||||
{ GLFW_KEY_F4 , EventKeyboard::KeyCode::KEY_F4 },
|
||||
{ GLFW_KEY_F5 , EventKeyboard::KeyCode::KEY_F5 },
|
||||
{ GLFW_KEY_F6 , EventKeyboard::KeyCode::KEY_F6 },
|
||||
{ GLFW_KEY_F7 , EventKeyboard::KeyCode::KEY_F7 },
|
||||
{ GLFW_KEY_F8 , EventKeyboard::KeyCode::KEY_F8 },
|
||||
{ GLFW_KEY_F9 , EventKeyboard::KeyCode::KEY_F9 },
|
||||
{ GLFW_KEY_F10 , EventKeyboard::KeyCode::KEY_F10 },
|
||||
{ GLFW_KEY_F11 , EventKeyboard::KeyCode::KEY_F11 },
|
||||
{ GLFW_KEY_F12 , EventKeyboard::KeyCode::KEY_F12 },
|
||||
{ GLFW_KEY_F13 , EventKeyboard::KeyCode::KEY_NONE },
|
||||
{ GLFW_KEY_F14 , EventKeyboard::KeyCode::KEY_NONE },
|
||||
{ GLFW_KEY_F15 , EventKeyboard::KeyCode::KEY_NONE },
|
||||
{ GLFW_KEY_F16 , EventKeyboard::KeyCode::KEY_NONE },
|
||||
{ GLFW_KEY_F17 , EventKeyboard::KeyCode::KEY_NONE },
|
||||
{ GLFW_KEY_F18 , EventKeyboard::KeyCode::KEY_NONE },
|
||||
{ GLFW_KEY_F19 , EventKeyboard::KeyCode::KEY_NONE },
|
||||
{ GLFW_KEY_F20 , EventKeyboard::KeyCode::KEY_NONE },
|
||||
{ GLFW_KEY_F21 , EventKeyboard::KeyCode::KEY_NONE },
|
||||
{ GLFW_KEY_F22 , EventKeyboard::KeyCode::KEY_NONE },
|
||||
{ GLFW_KEY_F23 , EventKeyboard::KeyCode::KEY_NONE },
|
||||
{ GLFW_KEY_F24 , EventKeyboard::KeyCode::KEY_NONE },
|
||||
{ GLFW_KEY_F25 , EventKeyboard::KeyCode::KEY_NONE },
|
||||
{ GLFW_KEY_KP_0 , EventKeyboard::KeyCode::KEY_0 },
|
||||
{ GLFW_KEY_KP_1 , EventKeyboard::KeyCode::KEY_1 },
|
||||
{ GLFW_KEY_KP_2 , EventKeyboard::KeyCode::KEY_2 },
|
||||
{ GLFW_KEY_KP_3 , EventKeyboard::KeyCode::KEY_3 },
|
||||
{ GLFW_KEY_KP_4 , EventKeyboard::KeyCode::KEY_4 },
|
||||
{ GLFW_KEY_KP_5 , EventKeyboard::KeyCode::KEY_5 },
|
||||
{ GLFW_KEY_KP_6 , EventKeyboard::KeyCode::KEY_6 },
|
||||
{ GLFW_KEY_KP_7 , EventKeyboard::KeyCode::KEY_7 },
|
||||
{ GLFW_KEY_KP_8 , EventKeyboard::KeyCode::KEY_8 },
|
||||
{ GLFW_KEY_KP_9 , EventKeyboard::KeyCode::KEY_9 },
|
||||
{ GLFW_KEY_KP_DECIMAL , EventKeyboard::KeyCode::KEY_PERIOD },
|
||||
{ GLFW_KEY_KP_DIVIDE , EventKeyboard::KeyCode::KEY_KP_DIVIDE },
|
||||
{ GLFW_KEY_KP_MULTIPLY , EventKeyboard::KeyCode::KEY_KP_MULTIPLY },
|
||||
{ GLFW_KEY_KP_SUBTRACT , EventKeyboard::KeyCode::KEY_KP_MINUS },
|
||||
{ GLFW_KEY_KP_ADD , EventKeyboard::KeyCode::KEY_KP_PLUS },
|
||||
{ GLFW_KEY_KP_ENTER , EventKeyboard::KeyCode::KEY_KP_ENTER },
|
||||
{ GLFW_KEY_KP_EQUAL , EventKeyboard::KeyCode::KEY_EQUAL },
|
||||
{ GLFW_KEY_LEFT_SHIFT , EventKeyboard::KeyCode::KEY_SHIFT },
|
||||
{ GLFW_KEY_LEFT_CONTROL , EventKeyboard::KeyCode::KEY_CTRL },
|
||||
{ GLFW_KEY_LEFT_ALT , EventKeyboard::KeyCode::KEY_ALT },
|
||||
{ GLFW_KEY_LEFT_SUPER , EventKeyboard::KeyCode::KEY_HYPER },
|
||||
{ GLFW_KEY_RIGHT_SHIFT , EventKeyboard::KeyCode::KEY_SHIFT },
|
||||
{ GLFW_KEY_RIGHT_CONTROL , EventKeyboard::KeyCode::KEY_CTRL },
|
||||
{ GLFW_KEY_RIGHT_ALT , EventKeyboard::KeyCode::KEY_ALT },
|
||||
{ GLFW_KEY_RIGHT_SUPER , EventKeyboard::KeyCode::KEY_HYPER },
|
||||
{ GLFW_KEY_MENU , EventKeyboard::KeyCode::KEY_MENU },
|
||||
{ GLFW_KEY_LAST , EventKeyboard::KeyCode::KEY_NONE }
|
||||
};
|
||||
|
||||
#if(_MSC_VER >= 1600) // Visual Studio 2010 or higher version.
|
||||
// Windows Touch define
|
||||
#define MOUSEEVENTF_FROMTOUCH 0xFF515700
|
||||
|
||||
// Windows Touch functions
|
||||
// Workaround to be able tu run app on Windows XP
|
||||
typedef WINUSERAPI BOOL (WINAPI *RegisterTouchWindowFn)(_In_ HWND hwnd, _In_ ULONG ulFlags);
|
||||
typedef WINUSERAPI BOOL (WINAPI *UnregisterTouchWindowFn)(_In_ HWND hwnd);
|
||||
typedef WINUSERAPI LPARAM (WINAPI *GetMessageExtraInfoFn)(VOID);
|
||||
typedef WINUSERAPI BOOL (WINAPI *GetTouchInputInfoFn)(_In_ HTOUCHINPUT hTouchInput, _In_ UINT cInputs, __out_ecount(cInputs) PTOUCHINPUT pInputs, _In_ int cbSize);
|
||||
typedef WINUSERAPI BOOL (WINAPI *CloseTouchInputHandleFn)(_In_ HTOUCHINPUT hTouchInput);
|
||||
|
||||
static RegisterTouchWindowFn s_pfRegisterTouchWindowFunction = NULL;
|
||||
static UnregisterTouchWindowFn s_pfUnregisterTouchWindowFunction = NULL;
|
||||
static GetMessageExtraInfoFn s_pfGetMessageExtraInfoFunction = NULL;
|
||||
static GetTouchInputInfoFn s_pfGetTouchInputInfoFunction = NULL;
|
||||
static CloseTouchInputHandleFn s_pfCloseTouchInputHandleFunction = NULL;
|
||||
|
||||
static bool CheckTouchSupport()
|
||||
{
|
||||
s_pfRegisterTouchWindowFunction = (RegisterTouchWindowFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "RegisterTouchWindow");
|
||||
s_pfUnregisterTouchWindowFunction = (UnregisterTouchWindowFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "UnregisterTouchWindow");
|
||||
s_pfGetMessageExtraInfoFunction = (GetMessageExtraInfoFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "GetMessageExtraInfo");
|
||||
s_pfGetTouchInputInfoFunction = (GetTouchInputInfoFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "GetTouchInputInfo");
|
||||
s_pfCloseTouchInputHandleFunction = (CloseTouchInputHandleFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "CloseTouchInputHandle");
|
||||
|
||||
return (s_pfRegisterTouchWindowFunction && s_pfUnregisterTouchWindowFunction && s_pfGetMessageExtraInfoFunction && s_pfGetTouchInputInfoFunction && s_pfCloseTouchInputHandleFunction);
|
||||
}
|
||||
|
||||
#endif /* #if(_MSC_VER >= 1600) */
|
||||
|
||||
static bool glew_dynamic_binding()
|
||||
{
|
||||
const char *gl_extensions = (const char*)glGetString(GL_EXTENSIONS);
|
||||
|
||||
// If the current opengl driver doesn't have framebuffers methods, check if an extension exists
|
||||
if (glGenFramebuffers == NULL)
|
||||
{
|
||||
log("OpenGL: glGenFramebuffers is NULL, try to detect an extension");
|
||||
if (strstr(gl_extensions, "ARB_framebuffer_object"))
|
||||
{
|
||||
log("OpenGL: ARB_framebuffer_object is supported");
|
||||
|
||||
glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC) wglGetProcAddress("glIsRenderbuffer");
|
||||
glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC) wglGetProcAddress("glBindRenderbuffer");
|
||||
glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC) wglGetProcAddress("glDeleteRenderbuffers");
|
||||
glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC) wglGetProcAddress("glGenRenderbuffers");
|
||||
glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC) wglGetProcAddress("glRenderbufferStorage");
|
||||
glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC) wglGetProcAddress("glGetRenderbufferParameteriv");
|
||||
glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC) wglGetProcAddress("glIsFramebuffer");
|
||||
glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC) wglGetProcAddress("glBindFramebuffer");
|
||||
glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC) wglGetProcAddress("glDeleteFramebuffers");
|
||||
glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC) wglGetProcAddress("glGenFramebuffers");
|
||||
glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC) wglGetProcAddress("glCheckFramebufferStatus");
|
||||
glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC) wglGetProcAddress("glFramebufferTexture1D");
|
||||
glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC) wglGetProcAddress("glFramebufferTexture2D");
|
||||
glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC) wglGetProcAddress("glFramebufferTexture3D");
|
||||
glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC) wglGetProcAddress("glFramebufferRenderbuffer");
|
||||
glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) wglGetProcAddress("glGetFramebufferAttachmentParameteriv");
|
||||
glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC) wglGetProcAddress("glGenerateMipmap");
|
||||
}
|
||||
else
|
||||
if (strstr(gl_extensions, "EXT_framebuffer_object"))
|
||||
{
|
||||
log("OpenGL: EXT_framebuffer_object is supported");
|
||||
glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC) wglGetProcAddress("glIsRenderbufferEXT");
|
||||
glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC) wglGetProcAddress("glBindRenderbufferEXT");
|
||||
glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC) wglGetProcAddress("glDeleteRenderbuffersEXT");
|
||||
glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC) wglGetProcAddress("glGenRenderbuffersEXT");
|
||||
glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC) wglGetProcAddress("glRenderbufferStorageEXT");
|
||||
glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC) wglGetProcAddress("glGetRenderbufferParameterivEXT");
|
||||
glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC) wglGetProcAddress("glIsFramebufferEXT");
|
||||
glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC) wglGetProcAddress("glBindFramebufferEXT");
|
||||
glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC) wglGetProcAddress("glDeleteFramebuffersEXT");
|
||||
glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC) wglGetProcAddress("glGenFramebuffersEXT");
|
||||
glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC) wglGetProcAddress("glCheckFramebufferStatusEXT");
|
||||
glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC) wglGetProcAddress("glFramebufferTexture1DEXT");
|
||||
glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC) wglGetProcAddress("glFramebufferTexture2DEXT");
|
||||
glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC) wglGetProcAddress("glFramebufferTexture3DEXT");
|
||||
glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC) wglGetProcAddress("glFramebufferRenderbufferEXT");
|
||||
glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) wglGetProcAddress("glGetFramebufferAttachmentParameterivEXT");
|
||||
glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC) wglGetProcAddress("glGenerateMipmapEXT");
|
||||
}
|
||||
else
|
||||
{
|
||||
log("OpenGL: No framebuffers extension is supported");
|
||||
log("OpenGL: Any call to Fbo will crash!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//begin EGLViewEventHandler
|
||||
class EGLViewEventHandler
|
||||
{
|
||||
public:
|
||||
static bool s_captured;
|
||||
static float s_mouseX;
|
||||
static float s_mouseY;
|
||||
|
||||
static void OnGLFWError(int errorID, const char* errorDesc);
|
||||
static void OnGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify);
|
||||
static void OnGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y);
|
||||
static void OnGLFWMouseScrollCallback(GLFWwindow* window, double x, double y);
|
||||
static void OnGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||
static void OnGLFWCharCallback(GLFWwindow* window, unsigned int character);
|
||||
static void OnGLFWWindowPosCallback(GLFWwindow* windows, int x, int y);
|
||||
};
|
||||
|
||||
bool EGLViewEventHandler::s_captured = false;
|
||||
float EGLViewEventHandler::s_mouseX = 0;
|
||||
float EGLViewEventHandler::s_mouseY = 0;
|
||||
|
||||
void EGLViewEventHandler::OnGLFWError(int errorID, const char* errorDesc)
|
||||
{
|
||||
CCLOGERROR("GLFWError #%d Happen, %s\n", errorID, errorDesc);
|
||||
}
|
||||
|
||||
void EGLViewEventHandler::OnGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify)
|
||||
{
|
||||
EGLView* eglView = EGLView::getInstance();
|
||||
if(nullptr == eglView) return;
|
||||
if(GLFW_MOUSE_BUTTON_LEFT == button)
|
||||
{
|
||||
if(GLFW_PRESS == action)
|
||||
{
|
||||
s_captured = true;
|
||||
if (eglView->getViewPortRect().equals(Rect::ZERO) || eglView->getViewPortRect().containsPoint(Point(s_mouseX,s_mouseY)))
|
||||
{
|
||||
int id = 0;
|
||||
eglView->handleTouchesBegin(1, &id, &s_mouseX, &s_mouseY);
|
||||
}
|
||||
}
|
||||
else if(GLFW_RELEASE == action)
|
||||
{
|
||||
s_captured = false;
|
||||
if (eglView->getViewPortRect().equals(Rect::ZERO) || eglView->getViewPortRect().containsPoint(Point(s_mouseX,s_mouseY)))
|
||||
{
|
||||
int id = 0;
|
||||
eglView->handleTouchesEnd(1, &id, &s_mouseX, &s_mouseY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(GLFW_PRESS == action)
|
||||
{
|
||||
EventMouse event(EventMouse::MouseEventType::MOUSE_DOWN);
|
||||
event.setCursorPosition(s_mouseX, eglView->getViewPortRect().size.height - s_mouseY);
|
||||
event.setMouseButton(button);
|
||||
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
||||
}
|
||||
else if(GLFW_RELEASE == action)
|
||||
{
|
||||
EventMouse event(EventMouse::MouseEventType::MOUSE_UP);
|
||||
event.setCursorPosition(s_mouseX, eglView->getViewPortRect().size.height - s_mouseY);
|
||||
event.setMouseButton(button);
|
||||
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
||||
}
|
||||
}
|
||||
|
||||
void EGLViewEventHandler::OnGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y)
|
||||
{
|
||||
s_mouseX = (float)x;
|
||||
s_mouseY = (float)y;
|
||||
EGLView* eglView = EGLView::getInstance();
|
||||
if(nullptr == eglView) return;
|
||||
|
||||
s_mouseX /= eglView->getFrameZoomFactor();
|
||||
s_mouseY /= eglView->getFrameZoomFactor();
|
||||
|
||||
if(s_captured)
|
||||
{
|
||||
if (eglView->getViewPortRect().equals(Rect::ZERO) || eglView->getViewPortRect().containsPoint(Point(s_mouseX,eglView->getFrameSize().height - s_mouseY)))
|
||||
{
|
||||
int id = 0;
|
||||
eglView->handleTouchesMove(1, &id, &s_mouseX, &s_mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
EventMouse event(EventMouse::MouseEventType::MOUSE_MOVE);
|
||||
//Because OpenGL use upper left as origin point, we need to revert the mouse y coordinate here
|
||||
event.setCursorPosition(s_mouseX, eglView->getViewPortRect().size.height - s_mouseY);
|
||||
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
||||
}
|
||||
|
||||
void EGLViewEventHandler::OnGLFWMouseScrollCallback(GLFWwindow* window, double x, double y)
|
||||
{
|
||||
EGLView* eglView = EGLView::getInstance();
|
||||
if(nullptr == eglView) return;
|
||||
|
||||
EventMouse event(EventMouse::MouseEventType::MOUSE_SCROLL);
|
||||
//Because OpenGL use upper left as origin point, we need to revert the mouse y coordinate here
|
||||
event.setScrollData((float)x, -(float)y);
|
||||
event.setCursorPosition(s_mouseX, eglView->getViewPortRect().size.height - s_mouseY);
|
||||
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
||||
}
|
||||
|
||||
void EGLViewEventHandler::OnGLFWKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (GLFW_REPEAT != action)
|
||||
{
|
||||
EventKeyboard event(g_keyCodeMap[key], GLFW_PRESS == action);
|
||||
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
||||
dispatcher->dispatchEvent(&event);
|
||||
}
|
||||
}
|
||||
|
||||
void EGLViewEventHandler::OnGLFWCharCallback(GLFWwindow *window, unsigned int character)
|
||||
{
|
||||
IMEDispatcher::sharedDispatcher()->dispatchInsertText((const char*) &character, 1);
|
||||
}
|
||||
|
||||
void EGLViewEventHandler::OnGLFWWindowPosCallback(GLFWwindow *windows, int x, int y)
|
||||
{
|
||||
if(Director::getInstance())
|
||||
{
|
||||
Director::getInstance()->setViewport();
|
||||
}
|
||||
}
|
||||
|
||||
//end EGLViewEventHandler
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// impliment EGLView
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
EGLView* EGLView::s_pEglView = nullptr;
|
||||
|
||||
EGLView::EGLView()
|
||||
: _captured(false)
|
||||
, _lpfnAccelerometerKeyHook(NULL)
|
||||
, _frameZoomFactor(1.0f)
|
||||
, _supportTouch(false)
|
||||
, _mainWindow(nullptr)
|
||||
{
|
||||
CCASSERT(nullptr == s_pEglView, "EGLView is singleton, Should be inited only one time\n");
|
||||
s_pEglView = this;
|
||||
g_keyCodeMap.clear();
|
||||
for (auto& item : g_keyCodeStructArray)
|
||||
{
|
||||
g_keyCodeMap.insert(std::make_pair(item.glfwKeyCode, item.keyCode));
|
||||
}
|
||||
_viewName = "Cocos2dxWin32";
|
||||
glfwSetErrorCallback(EGLViewEventHandler::OnGLFWError);
|
||||
glfwInit();
|
||||
}
|
||||
|
||||
EGLView::~EGLView()
|
||||
{
|
||||
glfwTerminate();
|
||||
s_pEglView = nullptr;
|
||||
}
|
||||
|
||||
bool EGLView::init(const char* viewName, float width, float height, float frameZoomFactor)
|
||||
{
|
||||
if(nullptr != _mainWindow) return true;
|
||||
|
||||
setViewName(viewName);
|
||||
setFrameSize(width, height);
|
||||
setFrameZoomFactor(frameZoomFactor);
|
||||
|
||||
glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
|
||||
_mainWindow = glfwCreateWindow(_screenSize.width * _frameZoomFactor, _screenSize.height * _frameZoomFactor, _viewName.c_str(), nullptr, nullptr);
|
||||
glfwMakeContextCurrent(_mainWindow);
|
||||
|
||||
glfwGetFramebufferSize(_mainWindow, &_frameBufferSize[0], &_frameBufferSize[1]);
|
||||
glfwSetMouseButtonCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseCallBack);
|
||||
glfwSetCursorPosCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseMoveCallBack);
|
||||
glfwSetScrollCallback(_mainWindow, EGLViewEventHandler::OnGLFWMouseScrollCallback);
|
||||
glfwSetCharCallback(_mainWindow, EGLViewEventHandler::OnGLFWCharCallback);
|
||||
glfwSetKeyCallback(_mainWindow, EGLViewEventHandler::OnGLFWKeyCallback);
|
||||
glfwSetWindowPosCallback(_mainWindow, EGLViewEventHandler::OnGLFWWindowPosCallback);
|
||||
|
||||
// check OpenGL version at first
|
||||
const GLubyte* glVersion = glGetString(GL_VERSION);
|
||||
CCLOG("OpenGL version = %s", glVersion);
|
||||
|
||||
if ( atof((const char*)glVersion) < 1.5 )
|
||||
{
|
||||
char strComplain[256] = {0};
|
||||
sprintf(strComplain,
|
||||
"OpenGL 1.5 or higher is required (your version is %s). Please upgrade the driver of your video card.",
|
||||
glVersion);
|
||||
MessageBox(strComplain, "OpenGL version too old");
|
||||
return false;
|
||||
}
|
||||
|
||||
GLenum GlewInitResult = glewInit();
|
||||
if (GLEW_OK != GlewInitResult)
|
||||
{
|
||||
MessageBox((char *)glewGetErrorString(GlewInitResult), "OpenGL error");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)
|
||||
{
|
||||
log("Ready for GLSL");
|
||||
}
|
||||
else
|
||||
{
|
||||
log("Not totally ready :(");
|
||||
}
|
||||
|
||||
if (glewIsSupported("GL_VERSION_2_0"))
|
||||
{
|
||||
log("Ready for OpenGL 2.0");
|
||||
}
|
||||
else
|
||||
{
|
||||
log("OpenGL 2.0 not supported");
|
||||
}
|
||||
|
||||
if(glew_dynamic_binding() == false)
|
||||
{
|
||||
MessageBox("No OpenGL framebuffer support. Please upgrade the driver of your video card.", "OpenGL error");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enable point size by default on windows.
|
||||
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void EGLView::setAccelerometerKeyHook( LPFN_ACCELEROMETER_KEYHOOK lpfnAccelerometerKeyHook )
|
||||
{
|
||||
_lpfnAccelerometerKeyHook=lpfnAccelerometerKeyHook;
|
||||
}
|
||||
|
||||
|
||||
bool EGLView::isOpenGLReady()
|
||||
{
|
||||
return nullptr != _mainWindow;
|
||||
}
|
||||
|
||||
void EGLView::end()
|
||||
{
|
||||
if(_mainWindow)
|
||||
glfwSetWindowShouldClose(_mainWindow,1);
|
||||
}
|
||||
|
||||
void EGLView::swapBuffers()
|
||||
{
|
||||
if(_mainWindow)
|
||||
glfwSwapBuffers(_mainWindow);
|
||||
}
|
||||
|
||||
bool EGLView::windowShouldClose()
|
||||
{
|
||||
if(_mainWindow)
|
||||
return glfwWindowShouldClose(_mainWindow) != 0;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
void EGLView::pollEvents()
|
||||
{
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
void EGLView::setIMEKeyboardState(bool /*bOpen*/)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void EGLView::setFrameZoomFactor(float fZoomFactor)
|
||||
{
|
||||
_frameZoomFactor = fZoomFactor;
|
||||
Director::getInstance()->setProjection(Director::getInstance()->getProjection());
|
||||
}
|
||||
|
||||
float EGLView::getFrameZoomFactor()
|
||||
{
|
||||
return _frameZoomFactor;
|
||||
}
|
||||
|
||||
void EGLView::setFrameSize(float width, float height)
|
||||
{
|
||||
EGLViewProtocol::setFrameSize(width, height);
|
||||
}
|
||||
|
||||
void EGLView::setViewPortInPoints(float x , float y , float w , float h)
|
||||
{
|
||||
float frameZoomFactorX = _frameBufferSize[0]/_screenSize.width;
|
||||
float frameZoomFactorY = _frameBufferSize[1]/_screenSize.height;
|
||||
glViewport((GLint)(x * _scaleX * frameZoomFactorX + _viewPortRect.origin.x * frameZoomFactorX),
|
||||
(GLint)(y * _scaleY * frameZoomFactorY + _viewPortRect.origin.y * frameZoomFactorY),
|
||||
(GLsizei)(w * _scaleX * frameZoomFactorX),
|
||||
(GLsizei)(h * _scaleY * frameZoomFactorY));
|
||||
}
|
||||
|
||||
void EGLView::setScissorInPoints(float x , float y , float w , float h)
|
||||
{
|
||||
float frameZoomFactorX = _frameBufferSize[0]/_screenSize.width;
|
||||
float frameZoomFactorY = _frameBufferSize[1]/_screenSize.height;
|
||||
glScissor((GLint)(x * _scaleX * frameZoomFactorX + _viewPortRect.origin.x * frameZoomFactorX),
|
||||
(GLint)(y * _scaleY * frameZoomFactorY + _viewPortRect.origin.y * frameZoomFactorY),
|
||||
(GLsizei)(w * _scaleX * frameZoomFactorX),
|
||||
(GLsizei)(h * _scaleY * frameZoomFactorY));
|
||||
}
|
||||
|
||||
EGLView* EGLView::getInstance()
|
||||
{
|
||||
CCASSERT(nullptr != s_pEglView, "EGL singleton should not be null");
|
||||
return s_pEglView;
|
||||
}
|
||||
|
||||
// XXX: deprecated
|
||||
EGLView* EGLView::sharedOpenGLView()
|
||||
{
|
||||
return EGLView::getInstance();
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -1,107 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_EGLVIEW_WIN32_H__
|
||||
#define __CC_EGLVIEW_WIN32_H__
|
||||
|
||||
#include "CCStdC.h"
|
||||
#include "platform/CCCommon.h"
|
||||
#include "CCGeometry.h"
|
||||
#include "platform/CCEGLViewProtocol.h"
|
||||
|
||||
#include "glfw3.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class EGL;
|
||||
|
||||
class CC_DLL EGLView : public EGLViewProtocol
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @js ctor
|
||||
*/
|
||||
EGLView();
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual ~EGLView();
|
||||
|
||||
/* override functions */
|
||||
virtual bool isOpenGLReady();
|
||||
virtual void end();
|
||||
virtual void swapBuffers();
|
||||
virtual void setFrameSize(float width, float height);
|
||||
virtual void setIMEKeyboardState(bool bOpen);
|
||||
/*
|
||||
*frameZoomFactor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
||||
*/
|
||||
bool init(const char* viewName, float width, float height, float frameZoomFactor = 1.0f);
|
||||
public:
|
||||
|
||||
//void resize(int width, int height);
|
||||
float getFrameZoomFactor();
|
||||
//void centerWindow();
|
||||
|
||||
typedef void (*LPFN_ACCELEROMETER_KEYHOOK)( UINT message,WPARAM wParam, LPARAM lParam );
|
||||
void setAccelerometerKeyHook( LPFN_ACCELEROMETER_KEYHOOK lpfnAccelerometerKeyHook );
|
||||
|
||||
virtual void setViewPortInPoints(float x , float y , float w , float h);
|
||||
virtual void setScissorInPoints(float x , float y , float w , float h);
|
||||
|
||||
// static function
|
||||
/**
|
||||
@brief get the shared main open gl window
|
||||
*/
|
||||
static EGLView* getInstance();
|
||||
|
||||
/** @deprecated Use getInstance() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE static EGLView* sharedOpenGLView();
|
||||
protected:
|
||||
/*
|
||||
* Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
||||
*/
|
||||
void setFrameZoomFactor(float fZoomFactor);
|
||||
private:
|
||||
bool _captured;
|
||||
LPFN_ACCELEROMETER_KEYHOOK _lpfnAccelerometerKeyHook;
|
||||
bool _supportTouch;
|
||||
|
||||
int _frameBufferSize[2];
|
||||
float _frameZoomFactor;
|
||||
static EGLView* s_pEglView;
|
||||
public:
|
||||
bool windowShouldClose();
|
||||
|
||||
void pollEvents();
|
||||
GLFWwindow* getWindow() const { return _mainWindow; }
|
||||
private:
|
||||
GLFWwindow* _mainWindow;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // end of __CC_EGLVIEW_WIN32_H__
|
|
@ -54,6 +54,7 @@ include_directories(
|
|||
${COCOS2D_ROOT}/cocos/2d
|
||||
${COCOS2D_ROOT}/cocos/2d/renderer
|
||||
${COCOS2D_ROOT}/cocos/2d/platform
|
||||
${COCOS2D_ROOT}/cocos/2d/platform/desktop
|
||||
${COCOS2D_ROOT}/cocos/2d/platform/linux
|
||||
${COCOS2D_ROOT}/cocos/base
|
||||
${COCOS2D_ROOT}/cocos/physics
|
||||
|
|
|
@ -57,6 +57,7 @@ include_directories(
|
|||
${COCOS2D_ROOT}/cocos/2d
|
||||
${COCOS2D_ROOT}/cocos/2d/renderer
|
||||
${COCOS2D_ROOT}/cocos/2d/platform
|
||||
${COCOS2D_ROOT}/cocos/2d/platform/desktop
|
||||
${COCOS2D_ROOT}/cocos/2d/platform/linux
|
||||
${COCOS2D_ROOT}/cocos/base
|
||||
${COCOS2D_ROOT}/cocos/physics
|
||||
|
|
|
@ -1 +1 @@
|
|||
094fab5984d8776b4addab57e40089288aedbe91
|
||||
f2d904a11c3d04415a453ab06821282d09dd88f2
|
Loading…
Reference in New Issue