void LLPostProcess::initialize(unsigned int width, unsigned int height) { destroyGL(); mScreenWidth = width; mScreenHeight = height; createScreenTextures(); createNoiseTexture(); //Setup our VBO. { mVBO = new LLVertexBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_TEXCOORD1,3); mVBO->allocateBuffer(4,0,TRUE); LLStrider<LLVector3> v; LLStrider<LLVector2> uv1; LLStrider<LLVector2> uv2; mVBO->getVertexStrider(v); mVBO->getTexCoord0Strider(uv1); mVBO->getTexCoord1Strider(uv2); v[0] = LLVector3( uv2[0] = uv1[0] = LLVector2(0, 0) ); v[1] = LLVector3( uv2[1] = uv1[1] = LLVector2(0, mScreenHeight) ); v[2] = LLVector3( uv2[2] = uv1[2] = LLVector2(mScreenWidth, 0) ); v[3] = LLVector3( uv2[3] = uv1[3] = LLVector2(mScreenWidth, mScreenHeight) ); mVBO->flush(); } stop_glerror(); }
void GLWindow::createGLWindow(bool togglefullscreen) { if(togglefullscreen) { isFullscreen = !isFullscreen; destroyGL(); } RECT WindowRect; int width = isFullscreen?videoModes[fullscreenMode].width:videoModes[windowedMode].width; int height = isFullscreen?videoModes[fullscreenMode].height:videoModes[windowedMode].height; int bits = isFullscreen?videoModes[fullscreenMode].bpp:videoModes[windowedMode].bpp; windowPosition = Point(nativeMode.dmPelsWidth/2 - width/2, nativeMode.dmPelsHeight/2 - height/2); int x = isFullscreen?0:windowPosition.x; int y = isFullscreen?0:windowPosition.y; WindowRect.left = (long) x; WindowRect.right = (long) x + width; WindowRect.top = (long) y; WindowRect.bottom = (long) y + height; if(isFullscreen) { SetWindowLongPtr(hWnd, GWL_EXSTYLE, WS_EX_APPWINDOW ); SetWindowLongPtr(hWnd, GWL_STYLE, WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE); SetWindowPos(hWnd,HWND_TOP, 0, 0, width, height, SWP_SHOWWINDOW); DEVMODE dm; dm.dmSize = sizeof(DEVMODE); dm.dmPelsWidth = width; dm.dmPelsHeight = height; dm.dmBitsPerPel = bits; dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; ChangeDisplaySettings(&dm,CDS_FULLSCREEN); } else { if(currentMode() == 0) SystemParametersInfo( SPI_GETWORKAREA, 0, &WindowRect, 0 ); DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; DWORD dwStyle = WS_OVERLAPPEDWINDOW | WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE; SetWindowLongPtr(hWnd, GWL_EXSTYLE, dwExStyle); SetWindowLongPtr(hWnd, GWL_STYLE, dwStyle); AdjustWindowRectEx(&WindowRect, dwStyle, false, dwExStyle); SetWindowPos(hWnd,HWND_TOP, WindowRect.left, WindowRect.top, WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top, SWP_SHOWWINDOW); if(togglefullscreen) ChangeDisplaySettings(NULL, 0); } if(togglefullscreen) initGL(bits); }
void Mesh::doRebuild() { // We could do some fancy things here, like checking to see if GL resources // have already been built, and just updating them. Let's just be lazy and // force a complete rebuild instead. destroyGL(); initGL(); }
void EGLView::CreateView(HWND hwnd, int left, int top, int width, int height ) { HINSTANCE hInstance = GetModuleHandle( NULL ); WNDCLASS wc; // Windows Class Structure // Redraw On Size, And Own DC For Window. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = _WindowProc; // WndProc Handles Messages wc.cbClsExtra = 0; // No Extra Window Data wc.cbWndExtra = 0; // No Extra Window Data wc.hInstance = hInstance; // Set The Instance wc.hIcon = LoadIcon( NULL, IDI_WINLOGO ); // Load The Default Icon wc.hCursor = LoadCursor( NULL, IDC_ARROW ); // Load The Arrow Pointer wc.hbrBackground = NULL; // No Background Required For GL wc.lpszMenuName = NULL; // wc.lpszClassName = L"Raster"; // Set The Class Name RegisterClass(&wc); // center window position RECT rcDesktop; GetWindowRect(GetDesktopWindow(), &rcDesktop); // create window m_hWnd = CreateWindowEx( WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, // Extended Style For The Window L"Raster", // Class Name L"Raster", // Window Title //WS_CAPTION | WS_POPUPWINDOW | WS_MINIMIZEBOX, // Defined Window Style WS_CHILD, // Defined Window Style 0, 0, // Window Position //TODO: Initializing width with a large value to avoid getting a wrong client area by 'GetClientRect' function. width, // Window Width height, // Window Height hwnd, // No Parent Window NULL, // No Menu hInstance, // Instance NULL ); bool bRet = initGL(); if(!bRet) destroyGL(); ShowWindow( m_hWnd, true ); s_pMainWindow = this; //CCEGLViewProtocol::setFrameSize( width, height ); m_obDesignResolutionSize = m_obScreenSize = CCSizeMake(width, height); resize( width, height); SetWindowPos(m_hWnd, 0, left, top, width, height, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_NOZORDER); //RasterGL::sharedRasterGL()->SetWinSize( width, height ); return; }
bool EGLView::CreateGL(HWND hwnd ) { m_hWnd = hwnd; bool bRet = false; bRet = initGL(); if(!bRet) destroyGL(); return bRet; }
void GLWindow::destroyGLWindow() { destroyGL(); ShowTaskBar(true); if ( hDC) { ReleaseDC( hWnd, hDC); hDC = NULL; } if ( hWnd) { DestroyWindow( hWnd); hWnd = NULL; } UnregisterClass(__TEXT("OGL"),hInstance); hInstance = NULL; }
LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { BOOL bProcessed = FALSE; switch (message) { case WM_LBUTTONDOWN: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (m_pDelegate && MK_LBUTTON == wParam) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; CCPoint pt(point.x, point.y); pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp)) { m_bCaptured = true; SetCapture(m_hWnd); int id = 0; handleTouchesBegin(1, &id, &pt.x, &pt.y); } } break; case WM_MOUSEMOVE: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (MK_LBUTTON == wParam && m_bCaptured) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; CCPoint pt(point.x, point.y); int id = 0; pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; handleTouchesMove(1, &id, &pt.x, &pt.y); } break; case WM_LBUTTONUP: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (m_bCaptured) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; CCPoint pt(point.x, point.y); int id = 0; pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; handleTouchesEnd(1, &id, &pt.x, &pt.y); ReleaseCapture(); m_bCaptured = false; } break; #if(_MSC_VER >= 1600) case WM_TOUCH: { BOOL bHandled = FALSE; UINT cInputs = LOWORD(wParam); PTOUCHINPUT pInputs = new TOUCHINPUT[cInputs]; if (pInputs) { if (s_pfGetTouchInputInfoFunction((HTOUCHINPUT)lParam, cInputs, pInputs, sizeof(TOUCHINPUT))) { for (UINT i=0; i < cInputs; i++) { TOUCHINPUT ti = pInputs[i]; POINT input; input.x = TOUCH_COORD_TO_PIXEL(ti.x); input.y = TOUCH_COORD_TO_PIXEL(ti.y); ScreenToClient(m_hWnd, &input); CCPoint pt(input.x, input.y); CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp)) { pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; if (ti.dwFlags & TOUCHEVENTF_DOWN) handleTouchesBegin(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y); else if (ti.dwFlags & TOUCHEVENTF_MOVE) handleTouchesMove(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y); else if (ti.dwFlags & TOUCHEVENTF_UP) handleTouchesEnd(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y); } } bHandled = TRUE; } delete [] pInputs; } if (bHandled) { s_pfCloseTouchInputHandleFunction((HTOUCHINPUT)lParam); } } break; #endif /* #if(_MSC_VER >= 1600) */ case WM_SIZE: switch (wParam) { case SIZE_RESTORED: CCApplication::sharedApplication()->applicationWillEnterForeground(); break; case SIZE_MINIMIZED: CCApplication::sharedApplication()->applicationDidEnterBackground(); break; } break; case WM_KEYDOWN: if (wParam == VK_F1 || wParam == VK_F2) { CCDirector* pDirector = CCDirector::sharedDirector(); if (GetKeyState(VK_LSHIFT) < 0 || GetKeyState(VK_RSHIFT) < 0 || GetKeyState(VK_SHIFT) < 0) pDirector->getKeypadDispatcher()->dispatchKeypadMSG(wParam == VK_F1 ? kTypeBackClicked : kTypeMenuClicked); } if ( m_lpfnAccelerometerKeyHook!=NULL ) { (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam ); } break; case WM_KEYUP: if ( m_lpfnAccelerometerKeyHook!=NULL ) { (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam ); } break; case WM_CHAR: { if (wParam < 0x20) { if (VK_BACK == wParam) { CCIMEDispatcher::sharedDispatcher()->dispatchDeleteBackward(); } else if (VK_RETURN == wParam) { CCIMEDispatcher::sharedDispatcher()->dispatchInsertText("\n", 1); } else if (VK_TAB == wParam) { // tab input } else if (VK_ESCAPE == wParam) { // ESC input //CCDirector::sharedDirector()->end(); } } else if (wParam < 128) { // ascii char CCIMEDispatcher::sharedDispatcher()->dispatchInsertText((const char *)&wParam, 1); } else { char szUtf8[8] = {0}; int nLen = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)&wParam, 1, szUtf8, sizeof(szUtf8), NULL, NULL); CCIMEDispatcher::sharedDispatcher()->dispatchInsertText(szUtf8, nLen); } if ( m_lpfnAccelerometerKeyHook!=NULL ) { (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam ); } } break; case WM_PAINT: PAINTSTRUCT ps; BeginPaint(m_hWnd, &ps); EndPaint(m_hWnd, &ps); break; case WM_CLOSE: CCDirector::sharedDirector()->end(); break; case WM_DESTROY: destroyGL(); PostQuitMessage(0); break; default: if (m_wndproc) { m_wndproc(message, wParam, lParam, &bProcessed); if (bProcessed) break; } return DefWindowProc(m_hWnd, message, wParam, lParam); } if (m_wndproc && !bProcessed) { m_wndproc(message, wParam, lParam, &bProcessed); } return 0; }
bool CCEGLView::Create() { bool bRet = false; do { CC_BREAK_IF(m_hWnd); HINSTANCE hInstance = GetModuleHandle( NULL ); WNDCLASS wc; // Windows Class Structure // Redraw On Size, And Own DC For Window. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = _WindowProc; // WndProc Handles Messages wc.cbClsExtra = 0; // No Extra Window Data wc.cbWndExtra = 0; // No Extra Window Data wc.hInstance = hInstance; // Set The Instance wc.hIcon = LoadIcon( NULL, IDI_WINLOGO ); // Load The Default Icon wc.hCursor = LoadCursor( NULL, IDC_ARROW ); // Load The Arrow Pointer wc.hbrBackground = NULL; // No Background Required For GL wc.lpszMenuName = m_menu; // wc.lpszClassName = kWindowClassName; // Set The Class Name CC_BREAK_IF(! RegisterClass(&wc) && 1410 != GetLastError()); // center window position RECT rcDesktop; GetWindowRect(GetDesktopWindow(), &rcDesktop); WCHAR wszBuf[50] = {0}; MultiByteToWideChar(CP_UTF8, 0, m_szViewName, -1, wszBuf, sizeof(wszBuf)); // create window m_hWnd = CreateWindowEx( WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, // Extended Style For The Window kWindowClassName, // Class Name wszBuf, // Window Title WS_CAPTION | WS_POPUPWINDOW | WS_MINIMIZEBOX, // Defined Window Style 0, 0, // Window Position //TODO: Initializing width with a large value to avoid getting a wrong client area by 'GetClientRect' function. 1000, // Window Width 1000, // Window Height NULL, // No Parent Window NULL, // No Menu hInstance, // Instance NULL ); CC_BREAK_IF(! m_hWnd); bRet = initGL(); if(!bRet) destroyGL(); CC_BREAK_IF(!bRet); s_pMainWindow = this; bRet = true; } while (0); #if(_MSC_VER >= 1600) m_bSupportTouch = CheckTouchSupport(); if(m_bSupportTouch) { m_bSupportTouch = (s_pfRegisterTouchWindowFunction(m_hWnd, 0) != 0); } #endif /* #if(_MSC_VER >= 1600) */ return bRet; }
VertexBuffer::~VertexBuffer() { destroyGL(); // Dangerous if GL components not already freed and we're not in the GL context thread. delete[] _data; }
Mesh::~Mesh() { removeFromQueue(kQueueNewTexture); // In case the mesh is destroyed while waiting to be initialised. destroyGL(); }
EGLWindow::~EGLWindow() { destroyGL(); }
bool EGLWindow::initializeGL(OSWindow *osWindow) { PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT = reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(eglGetProcAddress("eglGetPlatformDisplayEXT")); if (!eglGetPlatformDisplayEXT) { return false; } std::vector<EGLint> displayAttributes; displayAttributes.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE); displayAttributes.push_back(mPlatform.renderer); displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE); displayAttributes.push_back(mPlatform.majorVersion); displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE); displayAttributes.push_back(mPlatform.minorVersion); if (mPlatform.deviceType != EGL_DONT_CARE) { displayAttributes.push_back(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE); displayAttributes.push_back(mPlatform.deviceType); } displayAttributes.push_back(EGL_NONE); mDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, osWindow->getNativeDisplay(), &displayAttributes[0]); if (mDisplay == EGL_NO_DISPLAY) { destroyGL(); return false; } EGLint majorVersion, minorVersion; if (eglInitialize(mDisplay, &majorVersion, &minorVersion) == EGL_FALSE) { destroyGL(); return false; } eglBindAPI(EGL_OPENGL_ES_API); if (eglGetError() != EGL_SUCCESS) { destroyGL(); return false; } const EGLint configAttributes[] = { EGL_RED_SIZE, (mRedBits >= 0) ? mRedBits : EGL_DONT_CARE, EGL_GREEN_SIZE, (mGreenBits >= 0) ? mGreenBits : EGL_DONT_CARE, EGL_BLUE_SIZE, (mBlueBits >= 0) ? mBlueBits : EGL_DONT_CARE, EGL_ALPHA_SIZE, (mAlphaBits >= 0) ? mAlphaBits : EGL_DONT_CARE, EGL_DEPTH_SIZE, (mDepthBits >= 0) ? mDepthBits : EGL_DONT_CARE, EGL_STENCIL_SIZE, (mStencilBits >= 0) ? mStencilBits : EGL_DONT_CARE, EGL_SAMPLE_BUFFERS, mMultisample ? 1 : 0, EGL_NONE }; EGLint configCount; if (!eglChooseConfig(mDisplay, configAttributes, &mConfig, 1, &configCount) || (configCount != 1)) { destroyGL(); return false; } eglGetConfigAttrib(mDisplay, mConfig, EGL_RED_SIZE, &mRedBits); eglGetConfigAttrib(mDisplay, mConfig, EGL_GREEN_SIZE, &mGreenBits); eglGetConfigAttrib(mDisplay, mConfig, EGL_BLUE_SIZE, &mBlueBits); eglGetConfigAttrib(mDisplay, mConfig, EGL_ALPHA_SIZE, &mBlueBits); eglGetConfigAttrib(mDisplay, mConfig, EGL_DEPTH_SIZE, &mDepthBits); eglGetConfigAttrib(mDisplay, mConfig, EGL_STENCIL_SIZE, &mStencilBits); std::vector<EGLint> surfaceAttributes; if (strstr(eglQueryString(mDisplay, EGL_EXTENSIONS), "EGL_NV_post_sub_buffer") != nullptr) { surfaceAttributes.push_back(EGL_POST_SUB_BUFFER_SUPPORTED_NV); surfaceAttributes.push_back(EGL_TRUE); } surfaceAttributes.push_back(EGL_NONE); mSurface = eglCreateWindowSurface(mDisplay, mConfig, osWindow->getNativeWindow(), &surfaceAttributes[0]); if (eglGetError() != EGL_SUCCESS) { destroyGL(); return false; } ASSERT(mSurface != EGL_NO_SURFACE); EGLint contextAttibutes[] = { EGL_CONTEXT_CLIENT_VERSION, mClientVersion, EGL_NONE }; mContext = eglCreateContext(mDisplay, mConfig, NULL, contextAttibutes); if (eglGetError() != EGL_SUCCESS) { destroyGL(); return false; } eglMakeCurrent(mDisplay, mSurface, mSurface, mContext); if (eglGetError() != EGL_SUCCESS) { destroyGL(); return false; } if (mSwapInterval != -1) { eglSwapInterval(mDisplay, mSwapInterval); } return true; }
LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { BOOL bProcessed = FALSE; switch (message) { case WM_LBUTTONDOWN: if (m_pDelegate && MK_LBUTTON == wParam) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR()); CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp)) { m_bCaptured = true; SetCapture(m_hWnd); int id = 0; pt.x *= m_windowTouchScaleX; pt.y *= m_windowTouchScaleY; handleTouchesBegin(1, &id, &pt.x, &pt.y); } } break; case WM_MOUSEMOVE: if (MK_LBUTTON == wParam && m_bCaptured) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR()); int id = 0; pt.x *= m_windowTouchScaleX; pt.y *= m_windowTouchScaleY; handleTouchesMove(1, &id, &pt.x, &pt.y); } break; case WM_LBUTTONUP: if (m_bCaptured) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR()); int id = 0; pt.x *= m_windowTouchScaleX; pt.y *= m_windowTouchScaleY; handleTouchesEnd(1, &id, &pt.x, &pt.y); ReleaseCapture(); m_bCaptured = false; } break; case WM_SIZE: switch (wParam) { case SIZE_RESTORED: CCApplication::sharedApplication()->applicationWillEnterForeground(); break; case SIZE_MINIMIZED: CCApplication::sharedApplication()->applicationDidEnterBackground(); break; } break; case WM_KEYDOWN: if (wParam == VK_F1 || wParam == VK_F2) { CCDirector* pDirector = CCDirector::sharedDirector(); if (GetKeyState(VK_LSHIFT) < 0 || GetKeyState(VK_RSHIFT) < 0 || GetKeyState(VK_SHIFT) < 0) pDirector->getKeypadDispatcher()->dispatchKeypadMSG(wParam == VK_F1 ? kTypeBackClicked : kTypeMenuClicked); } if ( m_lpfnAccelerometerKeyHook!=NULL ) { (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam ); } break; case WM_KEYUP: if ( m_lpfnAccelerometerKeyHook!=NULL ) { (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam ); } break; case WM_CHAR: { if (wParam < 0x20) { if (VK_BACK == wParam) { CCIMEDispatcher::sharedDispatcher()->dispatchDeleteBackward(); } else if (VK_RETURN == wParam) { CCIMEDispatcher::sharedDispatcher()->dispatchInsertText("\n", 1); } else if (VK_TAB == wParam) { // tab input } else if (VK_ESCAPE == wParam) { // ESC input //CCDirector::sharedDirector()->end(); } } else if (wParam < 128) { // ascii char CCIMEDispatcher::sharedDispatcher()->dispatchInsertText((const char *)&wParam, 1); } else { char szUtf8[8] = {0}; int nLen = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)&wParam, 1, szUtf8, sizeof(szUtf8), NULL, NULL); CCIMEDispatcher::sharedDispatcher()->dispatchInsertText(szUtf8, nLen); } if ( m_lpfnAccelerometerKeyHook!=NULL ) { (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam ); } } break; case WM_PAINT: PAINTSTRUCT ps; BeginPaint(m_hWnd, &ps); EndPaint(m_hWnd, &ps); break; case WM_CLOSE: CCDirector::sharedDirector()->end(); break; case WM_DESTROY: destroyGL(); PostQuitMessage(0); break; default: if (m_wndproc) { m_wndproc(message, wParam, lParam, &bProcessed); if (bProcessed) break; } return DefWindowProc(m_hWnd, message, wParam, lParam); } if (m_wndproc && !bProcessed) { m_wndproc(message, wParam, lParam, &bProcessed); } return 0; }
IndexBuffer::~IndexBuffer() { destroyGL(); delete[] _data; }
LLPostProcess::~LLPostProcess(void) { destroyGL() ; }
void Mesh::doDestroy() { destroyGL(); }
LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { BOOL bProcessed = FALSE; //CCLog("wParam:%d", wParam); switch (message) { case WM_MOUSEWHEEL: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (m_pDelegate) { POINT point = { (short)LOWORD(lParam), (short)HIWORD(lParam) }; ScreenToClient(m_hWnd, &point); DPoint pt(point.x, point.y); pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; DPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); float zDelta = (short)HIWORD(wParam); if (m_obViewPortRect.equals(DRectZero) || m_obViewPortRect.containsPoint(tmp)) { m_bCaptured = true; SetCapture(m_hWnd); CrossApp::CAEvent* event = new CrossApp::CAEvent(); event->setEventType(CrossApp::EventType::middleMouseEvent); handleScrollWheel(pt.x, pt.y, 0, zDelta, event); event->release(); } } break; case WM_MOUSEMOVE: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (MK_LBUTTON == wParam && m_bCaptured) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; DPoint pt(point.x, point.y); int id = 0; pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; CrossApp::CAEvent* event = new CrossApp::CAEvent(); event->setEventType(CrossApp::EventType::leftMouseEvent); handleTouchesMove(1, &id, &pt.x, &pt.y, event); event->release(); event = new CrossApp::CAEvent(); event->setEventType(CrossApp::EventType::movedMouseEvent); handleMouseMoved(pt.x, pt.y, event); event->release(); } break; case WM_MBUTTONDOWN: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (m_pDelegate && MK_MBUTTON == wParam) { POINT point = { (short)LOWORD(lParam), (short)HIWORD(lParam) }; DPoint pt(point.x, point.y); pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; DPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(DRectZero) || m_obViewPortRect.containsPoint(tmp)) { m_bCaptured = true; SetCapture(m_hWnd); int id = 0; CrossApp::CAEvent* event = new CrossApp::CAEvent(); event->setEventType(CrossApp::EventType::middleMouseEvent); handleOtherMouseDown(1, &id, &pt.x, &pt.y, event); event->release(); } } break; case WM_MBUTTONUP: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (m_pDelegate) { POINT point = { (short)LOWORD(lParam), (short)HIWORD(lParam) }; DPoint pt(point.x, point.y); pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; DPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(DRectZero) || m_obViewPortRect.containsPoint(tmp)) { m_bCaptured = true; SetCapture(m_hWnd); int id = 0; CrossApp::CAEvent* event = new CrossApp::CAEvent(); event->setEventType(CrossApp::EventType::middleMouseEvent); handleOtherMouseUp(1,&id, &pt.x, &pt.y, event); event->release(); } } break; case WM_LBUTTONDOWN: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (m_pDelegate && MK_LBUTTON == wParam) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; DPoint pt(point.x, point.y); pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; DPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(DRectZero) || m_obViewPortRect.containsPoint(tmp)) { m_bCaptured = true; SetCapture(m_hWnd); int id = 0; CrossApp::CAEvent* event = new CrossApp::CAEvent(); event->setEventType(CrossApp::EventType::leftMouseEvent); handleTouchesBegin(1, &id, &pt.x, &pt.y, event); event->release(); } } break; case WM_LBUTTONUP: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (m_bCaptured) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; DPoint pt(point.x, point.y); int id = 0; pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; CrossApp::CAEvent* event = new CrossApp::CAEvent(); event->setEventType(CrossApp::EventType::leftMouseEvent); handleTouchesEnd(1, &id, &pt.x, &pt.y, event); event->release(); ReleaseCapture(); m_bCaptured = false; } break; case WM_RBUTTONDOWN: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (m_pDelegate && MK_RBUTTON == wParam) { POINT point = { (short)LOWORD(lParam), (short)HIWORD(lParam) }; DPoint pt(point.x, point.y); pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; DPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(DRectZero) || m_obViewPortRect.containsPoint(tmp)) { m_bCaptured = true; SetCapture(m_hWnd); int id = 0; CrossApp::CAEvent* event = new CrossApp::CAEvent(); event->setEventType(CrossApp::EventType::rightMouseEvent); handleTouchesBegin(1, &id, &pt.x, &pt.y, event); event->release(); } } break; case WM_RBUTTONUP: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (m_bCaptured) { POINT point = { (short)LOWORD(lParam), (short)HIWORD(lParam) }; DPoint pt(point.x, point.y); int id = 0; pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; CrossApp::CAEvent* event = new CrossApp::CAEvent(); event->setEventType(CrossApp::EventType::rightMouseEvent); handleTouchesEnd(1, &id, &pt.x, &pt.y, event); event->release(); ReleaseCapture(); m_bCaptured = false; } break; #if(_MSC_VER >= 1600) case WM_TOUCH: { BOOL bHandled = FALSE; UINT cInputs = LOWORD(wParam); PTOUCHINPUT pInputs = new TOUCHINPUT[cInputs]; if (pInputs) { if (s_pfGetTouchInputInfoFunction((HTOUCHINPUT)lParam, cInputs, pInputs, sizeof(TOUCHINPUT))) { for (UINT i=0; i < cInputs; i++) { TOUCHINPUT ti = pInputs[i]; POINT input; input.x = TOUCH_COORD_TO_PIXEL(ti.x); input.y = TOUCH_COORD_TO_PIXEL(ti.y); ScreenToClient(m_hWnd, &input); DPoint pt(input.x, input.y); DPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(DRectZero) || m_obViewPortRect.containsPoint(tmp)) { pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; CrossApp::CAEvent* event = new CrossApp::CAEvent(); event->setEventType(CrossApp::EventType::leftMouseEvent); if (ti.dwFlags & TOUCHEVENTF_DOWN) handleTouchesBegin(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y, event); else if (ti.dwFlags & TOUCHEVENTF_MOVE) handleTouchesMove(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y, event); else if (ti.dwFlags & TOUCHEVENTF_UP) handleTouchesEnd(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y, event); event->release(); } } bHandled = TRUE; } delete [] pInputs; } if (bHandled) { s_pfCloseTouchInputHandleFunction((HTOUCHINPUT)lParam); } } break; #endif /* #if(_MSC_VER >= 1600) */ case WM_SIZE: { static int oldWidth = 0, oldHeight = 0, windowState = 0; switch (wParam) { case SIZE_RESTORED: { if (windowState == 2) { CCApplication::sharedApplication()->applicationWillEnterForeground(); } else if (windowState == 1) { this->setFrameSize(oldWidth, oldHeight); CCApplication::sharedApplication()->applicationDidExitFullScreen(); } windowState = 0; } break; case SIZE_MAXIMIZED: { if (windowState == 2) { CCApplication::sharedApplication()->applicationWillEnterForeground(); } else if (windowState == 0) { oldWidth = m_obScreenSize.width * 2; oldHeight = m_obScreenSize.height * 2; RECT rt; SystemParametersInfo(SPI_GETWORKAREA, 0, &rt, 0); // 获得工作区大小 int w = (rt.right - rt.left) * 2; int h = (rt.bottom - rt.top - 24) * 2; this->setFrameSize(w, h); CCApplication::sharedApplication()->applicationDidToggleFullScreen(); } windowState = 1; } break; case SIZE_MINIMIZED: { CCApplication::sharedApplication()->applicationDidEnterBackground(); windowState = 2; } break; } } break; case WM_KEYDOWN: switch (wParam) { case VK_F1: if (GetKeyState(VK_LSHIFT) < 0 || GetKeyState(VK_RSHIFT) < 0 || GetKeyState(VK_SHIFT) < 0) CAApplication::getApplication()->getKeypadDispatcher()->dispatchKeypadMSG(kTypeBackClicked); break; case VK_F2: if (GetKeyState(VK_LSHIFT) < 0 || GetKeyState(VK_RSHIFT) < 0 || GetKeyState(VK_SHIFT) < 0) CAApplication::getApplication()->getKeypadDispatcher()->dispatchKeypadMSG(kTypeMenuClicked); break; case VK_ESCAPE: CAApplication::getApplication()->getKeypadDispatcher()->dispatchKeypadMSG(kTypeBackClicked); break; case VK_LEFT: CAIMEDispatcher::sharedDispatcher()->dispatchCursorMoveBackward(); break; case VK_RIGHT: CAIMEDispatcher::sharedDispatcher()->dispatchCursorMoveForward(); break; case VK_UP: CAIMEDispatcher::sharedDispatcher()->dispatchCursorMoveUp(); break; case VK_DOWN: CAIMEDispatcher::sharedDispatcher()->dispatchCursorMoveDown(); break; case 'C': case 'X': if (GetKeyState(VK_CONTROL) < 0) { if (wParam == 'C') { CAIMEDispatcher::sharedDispatcher()->dispatchCopyToClipboard(); } else { CAIMEDispatcher::sharedDispatcher()->dispatchCutToClipboard(); } } break; case 'V': if (GetKeyState(VK_CONTROL) < 0) { CAIMEDispatcher::sharedDispatcher()->dispatchPasteFromClipboard(); } break; case 'A': if (GetKeyState(VK_CONTROL) < 0) { CAIMEDispatcher::sharedDispatcher()->dispatchSelectAll(); } break; default: break; } if ( m_lpfnAccelerometerKeyHook!=NULL ) { (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam ); } break; case WM_KEYUP: if ( m_lpfnAccelerometerKeyHook!=NULL ) { (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam ); } break; case WM_CHAR: { if (wParam < 0x20) { if (VK_BACK == wParam) { CAIMEDispatcher::sharedDispatcher()->dispatchDeleteBackward(); } else if (VK_RETURN == wParam) { CAIMEDispatcher::sharedDispatcher()->dispatchInsertText("\n", 1); } else if (VK_TAB == wParam) { // tab input } else if (VK_ESCAPE == wParam) { // ESC input //CCDirector::sharedDirector()->end(); } } else if (wParam < 128) { // ascii char CAIMEDispatcher::sharedDispatcher()->dispatchInsertText((const char *)&wParam, 1); } else { char szUtf8[8] = {0}; int nLen = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)&wParam, 1, szUtf8, sizeof(szUtf8), NULL, NULL); CAIMEDispatcher::sharedDispatcher()->dispatchInsertText(szUtf8, nLen); } if ( m_lpfnAccelerometerKeyHook!=NULL ) { (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam ); } } break; case WM_PAINT: PAINTSTRUCT ps; BeginPaint(m_hWnd, &ps); EndPaint(m_hWnd, &ps); break; case WM_CLOSE: CAApplication::getApplication()->end(); break; case WM_DESTROY: destroyGL(); PostQuitMessage(0); break; default: if (m_wndproc) { m_wndproc(message, wParam, lParam, &bProcessed); if (bProcessed) break; } return DefWindowProc(m_hWnd, message, wParam, lParam); } if (m_wndproc && !bProcessed) { m_wndproc(message, wParam, lParam, &bProcessed); } return 0; }