2010-07-28 10:26:06 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-08-05 17:20:24 +08:00
|
|
|
// #define USE_EGL_UMU
|
|
|
|
|
|
|
|
#ifndef USE_EGL_UMU
|
|
|
|
// #define _EGL_SHOW_
|
2010-08-03 11:23:12 +08:00
|
|
|
#include <windows.h>
|
2010-08-05 17:20:24 +08:00
|
|
|
#endif
|
2010-07-28 10:26:06 +08:00
|
|
|
#include "CCXEGLView_uphone.h"
|
|
|
|
|
2010-08-03 18:11:37 +08:00
|
|
|
#include "TDC.h"
|
2010-08-05 17:20:24 +08:00
|
|
|
#undef GetNextWindow // this micro defined in winuser.h
|
|
|
|
#include "TApplication.h"
|
2010-08-03 18:11:37 +08:00
|
|
|
|
2010-07-29 16:05:14 +08:00
|
|
|
#include "EGL/egl.h"
|
2010-08-03 18:11:37 +08:00
|
|
|
#include "gles/gl.h"
|
2010-07-29 16:05:14 +08:00
|
|
|
|
|
|
|
#include "Cocos2dDefine.h"
|
2010-08-04 16:45:00 +08:00
|
|
|
#include "NSSet.h"
|
2010-08-05 12:02:55 +08:00
|
|
|
#include "CCDirector.h"
|
2010-08-25 10:19:20 +08:00
|
|
|
#include "CCTouch.h"
|
|
|
|
#include "CCTouchDispatcher.h"
|
2010-07-29 12:12:11 +08:00
|
|
|
|
2010-08-05 17:20:24 +08:00
|
|
|
#ifndef USE_EGL_UMU
|
2010-08-03 11:23:12 +08:00
|
|
|
#define WIN_CLASS_NAME "OpenGL"
|
|
|
|
|
2010-08-04 14:48:14 +08:00
|
|
|
static bool s_keys[256]; // Array Used For The Keyboard Routine
|
|
|
|
static bool s_active=TRUE; // Window Active Flag Set To TRUE By Default
|
2010-08-03 11:23:12 +08:00
|
|
|
|
|
|
|
EGLNativeWindowType _CreateWnd(int width, int height);
|
|
|
|
LRESULT CALLBACK _WndProc(HWND, UINT, WPARAM, LPARAM);
|
2010-08-05 17:20:24 +08:00
|
|
|
#endif
|
|
|
|
|
2010-08-03 11:23:12 +08:00
|
|
|
|
2010-07-28 10:26:06 +08:00
|
|
|
namespace cocos2d {
|
|
|
|
|
2010-07-29 16:05:14 +08:00
|
|
|
class CCXEGL
|
|
|
|
{
|
|
|
|
public:
|
2010-08-03 11:23:12 +08:00
|
|
|
~CCXEGL()
|
|
|
|
{
|
|
|
|
if (EGL_NO_DISPLAY != m_eglDisplay)
|
|
|
|
{
|
|
|
|
eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
|
|
eglTerminate(m_eglDisplay);
|
|
|
|
}
|
2010-08-05 17:20:24 +08:00
|
|
|
#ifndef USE_EGL_UMU
|
2010-08-03 11:23:12 +08:00
|
|
|
if (m_eglDC)
|
|
|
|
{
|
2010-08-31 16:53:25 +08:00
|
|
|
ReleaseDC( (HWND)m_eglWnd, (HDC)m_eglDC);
|
2010-08-03 11:23:12 +08:00
|
|
|
}
|
|
|
|
if (m_eglWnd)
|
|
|
|
{
|
2010-08-31 16:53:25 +08:00
|
|
|
DestroyWindow( (HWND)m_eglWnd);
|
2010-08-03 11:23:12 +08:00
|
|
|
}
|
|
|
|
UnregisterClass(WIN_CLASS_NAME, GetModuleHandle(NULL));
|
2010-08-05 17:20:24 +08:00
|
|
|
#endif
|
|
|
|
if (m_pBmp)
|
|
|
|
{
|
|
|
|
m_pBmp->Destroy();
|
|
|
|
}
|
2010-08-03 11:23:12 +08:00
|
|
|
}
|
|
|
|
|
2010-08-06 11:14:22 +08:00
|
|
|
static CCXEGL * create(TWindow * pWindow)
|
2010-08-03 11:23:12 +08:00
|
|
|
{
|
|
|
|
CCXEGL * pEGL = new CCXEGL;
|
|
|
|
Boolean bSuccess = FALSE;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
CCX_BREAK_IF(! pEGL);
|
|
|
|
|
|
|
|
TRectangle rc;
|
|
|
|
pWindow->GetClientBounds(&rc);
|
2010-08-04 14:48:14 +08:00
|
|
|
CCX_BREAK_IF(! (pEGL->m_pBmp = TBitmap::Create(rc.Width(), rc.Height(), 32)));
|
2010-08-05 17:20:24 +08:00
|
|
|
#ifdef USE_EGL_UMU
|
|
|
|
pEGL->m_eglWnd = pWindow;
|
|
|
|
TDC dc(pWindow);
|
|
|
|
pEGL->m_eglDC = &dc;
|
|
|
|
#else
|
|
|
|
CCX_BREAK_IF(! (pEGL->m_eglWnd = _CreateWnd(rc.Width(), rc.Height())));
|
2010-07-29 16:05:14 +08:00
|
|
|
|
2010-08-31 16:53:25 +08:00
|
|
|
pEGL->m_eglDC = GetDC( (HWND)(pEGL->m_eglWnd) );
|
2010-08-03 11:23:12 +08:00
|
|
|
CCX_BREAK_IF(! pEGL->m_eglDC);
|
2010-08-05 17:20:24 +08:00
|
|
|
#endif
|
2010-08-03 11:23:12 +08:00
|
|
|
EGLDisplay eglDisplay;
|
|
|
|
CCX_BREAK_IF(EGL_NO_DISPLAY == (eglDisplay = eglGetDisplay(pEGL->m_eglDC)));
|
|
|
|
|
|
|
|
EGLint nMajor, nMinor;
|
|
|
|
CCX_BREAK_IF(EGL_FALSE == eglInitialize(eglDisplay, &nMajor, &nMinor) || 1 != nMajor);
|
|
|
|
|
|
|
|
const EGLint aConfigAttribs[] =
|
|
|
|
{
|
|
|
|
EGL_LEVEL, 0,
|
|
|
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
|
|
EGL_NATIVE_RENDERABLE, EGL_FALSE,
|
|
|
|
EGL_DEPTH_SIZE, EGL_DONT_CARE,
|
|
|
|
EGL_NONE,
|
|
|
|
};
|
|
|
|
EGLint iConfigs;
|
|
|
|
EGLConfig eglConfig;
|
|
|
|
CCX_BREAK_IF(EGL_FALSE == eglChooseConfig(eglDisplay, aConfigAttribs, &eglConfig, 1, &iConfigs)
|
|
|
|
|| (iConfigs != 1));
|
|
|
|
|
|
|
|
EGLSurface eglSurface;
|
|
|
|
eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, pEGL->m_eglWnd, NULL);
|
|
|
|
CCX_BREAK_IF(EGL_NO_SURFACE == eglSurface);
|
|
|
|
|
|
|
|
EGLContext eglContext;
|
|
|
|
eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, NULL);
|
|
|
|
CCX_BREAK_IF(EGL_NO_CONTEXT == eglContext);
|
|
|
|
|
|
|
|
CCX_BREAK_IF(EGL_FALSE == eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext));
|
|
|
|
|
2010-08-03 18:11:37 +08:00
|
|
|
pEGL->m_pWnd = pWindow;
|
2010-08-03 11:23:12 +08:00
|
|
|
pEGL->m_eglDisplay = eglDisplay;
|
|
|
|
pEGL->m_eglSurface = eglSurface;
|
2010-08-06 11:14:22 +08:00
|
|
|
pEGL->m_eglConfig = eglConfig;
|
2010-08-03 11:23:12 +08:00
|
|
|
pEGL->m_eglContext = eglContext;
|
|
|
|
bSuccess = TRUE;
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
if (! bSuccess)
|
|
|
|
{
|
|
|
|
CCX_SAFE_DELETE(pEGL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pEGL;
|
|
|
|
}
|
|
|
|
|
2010-08-06 11:14:22 +08:00
|
|
|
void resizeSurface()
|
|
|
|
{
|
|
|
|
if (! m_pWnd || EGL_NO_DISPLAY == m_eglDisplay)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// release old surface
|
|
|
|
if (EGL_NO_SURFACE != m_eglSurface)
|
|
|
|
{
|
|
|
|
eglDestroySurface(m_eglDisplay, m_eglSurface);
|
|
|
|
m_eglSurface = EGL_NO_SURFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// resize eglWnd;
|
|
|
|
TRectangle rc;
|
|
|
|
m_pWnd->GetClientBounds(&rc);
|
|
|
|
RECT rcNew = {0, 0, rc.Width(), rc.Height(),};
|
|
|
|
AdjustWindowRectEx(&rcNew, WS_POPUPWINDOW, false, WS_EX_TOPMOST | WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
|
2010-08-31 16:53:25 +08:00
|
|
|
MoveWindow( (HWND)m_eglWnd, rcNew.left, rcNew.top, rcNew.right - rcNew.left, rcNew.bottom - rcNew.top, FALSE);
|
2010-08-06 11:14:22 +08:00
|
|
|
|
|
|
|
// create new surface and make current
|
|
|
|
m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, m_eglWnd, NULL);
|
|
|
|
eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
void swapBuffers()
|
2010-08-03 11:23:12 +08:00
|
|
|
{
|
|
|
|
if (EGL_NO_DISPLAY != m_eglDisplay)
|
|
|
|
{
|
2010-08-05 17:20:24 +08:00
|
|
|
TRectangle rc;
|
|
|
|
m_pWnd->GetClientBounds(&rc);
|
|
|
|
|
|
|
|
int nWidth = rc.Width();
|
|
|
|
int nHeight = rc.Height();
|
2010-08-03 18:11:37 +08:00
|
|
|
|
|
|
|
char *pData = new char[4 * nWidth * nHeight];
|
|
|
|
if (pData == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
glReadPixels(0, 0, nWidth, nHeight, GL_RGBA, GL_UNSIGNED_BYTE, pData);
|
|
|
|
|
2010-08-04 14:48:14 +08:00
|
|
|
char * pDst = (char *)m_pBmp->GetDataPtr();
|
2010-08-05 17:20:24 +08:00
|
|
|
int nPitch = m_pBmp->GetRowBytes();
|
2010-08-04 14:48:14 +08:00
|
|
|
char * pDstRow = NULL;
|
2010-08-05 17:20:24 +08:00
|
|
|
char * pSrc = pData;
|
2010-08-04 14:48:14 +08:00
|
|
|
|
2010-08-03 18:11:37 +08:00
|
|
|
for (int i = 0; i < nHeight; i++)
|
|
|
|
{
|
2010-08-04 16:08:43 +08:00
|
|
|
pDstRow = pDst + (nHeight - i - 1) * nPitch;
|
2010-08-03 18:11:37 +08:00
|
|
|
for (int j = 0; j < nWidth; j++)
|
|
|
|
{
|
2010-08-04 14:48:14 +08:00
|
|
|
*(int *)pDstRow = RGBA(pSrc[0], pSrc[1], pSrc[2], pSrc[3]);
|
|
|
|
pSrc += 4;
|
|
|
|
pDstRow += 4;
|
2010-08-03 18:11:37 +08:00
|
|
|
}
|
|
|
|
}
|
2010-08-04 14:48:14 +08:00
|
|
|
TDC dc(m_pWnd);
|
|
|
|
dc.DrawBitmap(m_pBmp, 0, 0);
|
2010-08-05 10:29:29 +08:00
|
|
|
#ifdef _EGL_SHOW_
|
|
|
|
eglSwapBuffers(m_eglDisplay, m_eglSurface);
|
|
|
|
#endif
|
2010-09-03 17:23:45 +08:00
|
|
|
delete[] pData;
|
2010-08-03 11:23:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
CCXEGL()
|
2010-08-03 18:11:37 +08:00
|
|
|
: m_pWnd(NULL)
|
2010-08-04 14:48:14 +08:00
|
|
|
, m_pBmp(NULL)
|
2010-08-03 18:11:37 +08:00
|
|
|
, m_eglWnd(NULL)
|
2010-08-05 17:20:24 +08:00
|
|
|
#ifndef USE_EGL_EMU
|
2010-08-03 11:23:12 +08:00
|
|
|
, m_eglDC(NULL)
|
2010-08-05 17:20:24 +08:00
|
|
|
#endif
|
2010-08-03 11:23:12 +08:00
|
|
|
, m_eglDisplay(EGL_NO_DISPLAY)
|
2010-08-06 11:14:22 +08:00
|
|
|
, m_eglConfig(0)
|
2010-08-03 11:23:12 +08:00
|
|
|
, m_eglSurface(EGL_NO_SURFACE)
|
2010-08-03 18:11:37 +08:00
|
|
|
, m_eglContext(EGL_NO_CONTEXT)
|
|
|
|
{}
|
2010-08-03 11:23:12 +08:00
|
|
|
|
2010-08-03 18:11:37 +08:00
|
|
|
TWindow * m_pWnd;
|
2010-08-04 14:48:14 +08:00
|
|
|
TBitmap * m_pBmp;
|
2010-08-03 11:23:12 +08:00
|
|
|
EGLNativeWindowType m_eglWnd;
|
|
|
|
EGLNativeDisplayType m_eglDC;
|
|
|
|
EGLDisplay m_eglDisplay;
|
2010-08-06 11:14:22 +08:00
|
|
|
EGLConfig m_eglConfig;
|
2010-08-03 11:23:12 +08:00
|
|
|
EGLSurface m_eglSurface;
|
|
|
|
EGLContext m_eglContext;
|
2010-07-29 16:05:14 +08:00
|
|
|
};
|
2010-07-28 10:26:06 +08:00
|
|
|
CCXEGLView::CCXEGLView(TApplication * pApp)
|
|
|
|
: TWindow(pApp)
|
2010-07-29 12:12:11 +08:00
|
|
|
, m_bCaptured(false)
|
2010-07-28 18:18:27 +08:00
|
|
|
, m_pDelegate(NULL)
|
2010-07-29 16:05:14 +08:00
|
|
|
, m_pEGL(NULL)
|
2010-07-28 10:26:06 +08:00
|
|
|
{
|
2010-07-29 12:12:11 +08:00
|
|
|
m_pTouch = new CCTouch;
|
|
|
|
m_pSet = new NSSet;
|
2010-07-28 10:26:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCXEGLView::~CCXEGLView()
|
|
|
|
{
|
2010-08-03 11:23:12 +08:00
|
|
|
delete m_pEGL;
|
2010-07-29 12:12:11 +08:00
|
|
|
delete m_pSet;
|
|
|
|
delete m_pTouch;
|
2010-07-28 10:26:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-03 11:23:12 +08:00
|
|
|
Boolean CCXEGLView::AfterCreate(void)
|
|
|
|
{
|
2010-08-06 11:14:22 +08:00
|
|
|
return (m_pEGL = CCXEGL::create(this)) ? TRUE : FALSE;
|
2010-08-03 11:23:12 +08:00
|
|
|
}
|
|
|
|
|
2010-07-28 10:26:06 +08:00
|
|
|
Boolean CCXEGLView::EventHandler(TApplication * pApp, EventType * pEvent)
|
|
|
|
{
|
2010-07-28 18:18:27 +08:00
|
|
|
Boolean bHandled = FALSE;
|
2010-07-29 16:05:14 +08:00
|
|
|
|
|
|
|
switch(pEvent->eType)
|
2010-07-28 18:18:27 +08:00
|
|
|
{
|
2010-08-05 17:20:24 +08:00
|
|
|
case EVENT_WinInit:
|
|
|
|
bHandled = TRUE;
|
|
|
|
break;
|
|
|
|
|
2010-08-05 12:02:55 +08:00
|
|
|
case EVENT_WinRotationChanged:
|
2010-08-06 11:14:22 +08:00
|
|
|
{
|
|
|
|
if (m_pEGL)
|
|
|
|
{
|
|
|
|
m_pEGL->resizeSurface();
|
|
|
|
UpdateWindow(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// CCX_SAFE_DELETE(m_pEGL);
|
|
|
|
// m_pEGL = CCXEGL::create(this);
|
2010-08-05 17:20:24 +08:00
|
|
|
bHandled = TRUE;
|
2010-08-05 10:29:29 +08:00
|
|
|
break;
|
|
|
|
|
2010-07-29 16:05:14 +08:00
|
|
|
case EVENT_WinPaint:
|
2010-08-05 17:20:24 +08:00
|
|
|
CCDirector::getSharedDirector()->preMainLoop();
|
|
|
|
bHandled = TRUE;
|
2010-07-29 16:05:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EVENT_PenDown:
|
2010-08-06 11:42:15 +08:00
|
|
|
if (m_bCaptured)
|
2010-07-29 16:05:14 +08:00
|
|
|
{
|
2010-08-06 11:42:15 +08:00
|
|
|
bHandled = TRUE;
|
|
|
|
}
|
2010-08-06 11:49:17 +08:00
|
|
|
else if (m_pDelegate && m_pTouch && m_pSet
|
|
|
|
&& ! PointInControl(pEvent->sParam1, pEvent->sParam2, NULL)
|
|
|
|
&& SetCaptureEx(-1, TRUE))
|
2010-08-06 11:42:15 +08:00
|
|
|
{
|
|
|
|
m_bCaptured = true;
|
|
|
|
m_nPenEventNum = pEvent->lParam5;
|
2010-08-06 10:15:54 +08:00
|
|
|
// SS_printf("PenDown: %4d, %4d\n", pEvent->sParam1, pEvent->sParam2);
|
2010-07-29 16:05:14 +08:00
|
|
|
m_pTouch->SetTouchInfo(0, (float)pEvent->sParam1, (float)pEvent->sParam2);
|
|
|
|
m_pSet->addObject(m_pTouch);
|
|
|
|
m_pDelegate->touchesBegan(m_pSet, NULL);
|
|
|
|
}
|
|
|
|
break;
|
2010-08-06 12:02:54 +08:00
|
|
|
|
2010-07-29 16:05:14 +08:00
|
|
|
case EVENT_PenMove:
|
2010-08-06 11:42:15 +08:00
|
|
|
if (m_pDelegate && m_pTouch && m_pSet && m_bCaptured && pEvent->lParam5 == m_nPenEventNum)
|
2010-07-29 16:05:14 +08:00
|
|
|
{
|
2010-08-06 10:15:54 +08:00
|
|
|
// SS_printf("PenMove: %4d, %4d\n", pEvent->sParam1, pEvent->sParam2);
|
2010-08-06 11:51:07 +08:00
|
|
|
m_pTouch->SetTouchInfo(0, (float)pEvent->sParam1, (float)pEvent->sParam2);
|
|
|
|
m_pDelegate->touchesMoved(m_pSet, NULL);
|
2010-07-28 18:18:27 +08:00
|
|
|
}
|
2010-07-29 16:05:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EVENT_PenUp:
|
2010-08-06 11:42:15 +08:00
|
|
|
if (m_pDelegate && m_pTouch && m_pSet && m_bCaptured && pEvent->lParam5 == m_nPenEventNum)
|
2010-07-29 16:05:14 +08:00
|
|
|
{
|
|
|
|
ReleaseCapture();
|
2010-08-06 10:15:54 +08:00
|
|
|
// SS_printf("PenUp: %4d, %4d\n", pEvent->sParam1, pEvent->sParam2);
|
2010-07-29 16:05:14 +08:00
|
|
|
m_pTouch->SetTouchInfo(0, (float)pEvent->sParam1, (float)pEvent->sParam2);
|
|
|
|
m_pDelegate->touchesEnded(m_pSet, NULL);
|
2010-08-19 16:45:18 +08:00
|
|
|
m_pSet->removeObject(m_pTouch);
|
2010-08-06 11:42:15 +08:00
|
|
|
m_bCaptured = false;
|
2010-07-29 16:05:14 +08:00
|
|
|
}
|
|
|
|
break;
|
2010-08-05 17:20:24 +08:00
|
|
|
|
|
|
|
case EVENT_WinClose:
|
|
|
|
// Stop the application since the main form has been closed
|
|
|
|
pApp->SendStopEvent();
|
|
|
|
break;
|
|
|
|
|
2010-07-28 18:18:27 +08:00
|
|
|
}
|
|
|
|
|
2010-08-03 11:23:12 +08:00
|
|
|
if (! bHandled)
|
2010-07-28 18:18:27 +08:00
|
|
|
{
|
|
|
|
return TWindow::EventHandler(pApp, pEvent);
|
|
|
|
}
|
2010-08-03 11:23:12 +08:00
|
|
|
return bHandled;
|
2010-07-28 10:26:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CGSize CCXEGLView::getSize()
|
|
|
|
{
|
2010-08-18 15:24:19 +08:00
|
|
|
Coord w, h;
|
|
|
|
TWindow::GetWindowExtent(&w, &h);
|
|
|
|
return CGSize((float)w, (float)h);
|
|
|
|
}
|
|
|
|
|
|
|
|
CGRect CCXEGLView::getFrame()
|
|
|
|
{
|
|
|
|
TRectangle rc;
|
|
|
|
GetClientBounds(&rc);
|
|
|
|
return (CGRect((float)rc.X(), (float)rc.Y(), (float)rc.Width(), (float)rc.Height()));
|
2010-07-28 10:26:06 +08:00
|
|
|
}
|
|
|
|
|
2010-07-28 18:18:27 +08:00
|
|
|
bool CCXEGLView::isOpenGLReady()
|
|
|
|
{
|
2010-07-29 16:05:14 +08:00
|
|
|
return (NULL != m_pEGL);
|
2010-07-28 18:18:27 +08:00
|
|
|
}
|
2010-07-28 10:26:06 +08:00
|
|
|
|
2010-07-28 18:18:27 +08:00
|
|
|
void CCXEGLView::release()
|
|
|
|
{
|
2010-08-03 11:23:12 +08:00
|
|
|
CCX_SAFE_DELETE(m_pEGL);
|
2010-07-28 18:18:27 +08:00
|
|
|
CloseWindow();
|
|
|
|
}
|
2010-07-28 10:26:06 +08:00
|
|
|
|
2010-07-28 18:18:27 +08:00
|
|
|
void CCXEGLView::setTouchDelegate(EGLTouchDelegate * pDelegate)
|
|
|
|
{
|
|
|
|
m_pDelegate = pDelegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCXEGLView::swapBuffers()
|
|
|
|
{
|
2010-07-29 16:05:14 +08:00
|
|
|
if (m_pEGL)
|
|
|
|
{
|
2010-08-06 11:14:22 +08:00
|
|
|
m_pEGL->swapBuffers();
|
2010-07-29 16:05:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-03 11:23:12 +08:00
|
|
|
} // end of namespace cocos2d
|
|
|
|
|
2010-07-29 16:05:14 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-08-03 11:23:12 +08:00
|
|
|
// static function
|
2010-07-29 16:05:14 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-08-05 17:20:24 +08:00
|
|
|
#ifndef USE_EGL_UMU
|
2010-08-03 11:23:12 +08:00
|
|
|
static EGLNativeWindowType _CreateWnd(int width, int height)
|
2010-07-29 16:05:14 +08:00
|
|
|
{
|
2010-08-03 11:23:12 +08:00
|
|
|
WNDCLASS wc; // Windows Class Structure
|
|
|
|
HINSTANCE hInstance;
|
|
|
|
EGLNativeWindowType hWnd = NULL;
|
|
|
|
|
|
|
|
hInstance = GetModuleHandle( NULL ); // Grab An Instance For Our Window
|
|
|
|
wc.style = CS_NOCLOSE | CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window.
|
|
|
|
wc.lpfnWndProc = WNDPROC( _WndProc ); // 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; // We Don't Want A Menu
|
|
|
|
wc.lpszClassName = WIN_CLASS_NAME; // Set The Class Name
|
|
|
|
|
|
|
|
RegisterClass(&wc); // Attempt To Register The Window Class
|
|
|
|
|
|
|
|
RECT rect = {0, 0, width, height};
|
|
|
|
AdjustWindowRectEx(&rect, WS_POPUPWINDOW, false, WS_EX_TOPMOST | WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
|
|
|
|
hWnd = CreateWindowEx(
|
|
|
|
WS_EX_TOPMOST | WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, // Extended Style For The Window
|
|
|
|
"OpenGL", // Class Name
|
|
|
|
"Effect Test App", // Window Title
|
|
|
|
WS_POPUPWINDOW/*WS_OVERLAPPEDWINDOW*/ | // Defined Window Style
|
|
|
|
WS_CLIPSIBLINGS | // Required Window Style
|
|
|
|
WS_CLIPCHILDREN, // Required Window Style
|
|
|
|
0, 0, // Window Position
|
|
|
|
rect.right - rect.left, // Window Width
|
|
|
|
rect.bottom - rect.top, // Window Height
|
|
|
|
NULL, // No Parent Window
|
|
|
|
NULL, // No Menu
|
|
|
|
hInstance, // Instance
|
|
|
|
NULL );
|
|
|
|
|
2010-08-05 10:29:29 +08:00
|
|
|
#ifdef _EGL_SHOW_
|
|
|
|
if (hWnd)
|
|
|
|
{
|
|
|
|
ShowWindow(hWnd, SW_SHOW);
|
|
|
|
}
|
|
|
|
#endif
|
2010-08-03 11:23:12 +08:00
|
|
|
return hWnd;
|
2010-07-29 16:05:14 +08:00
|
|
|
}
|
|
|
|
|
2010-08-03 11:23:12 +08:00
|
|
|
static LRESULT CALLBACK _WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
2010-07-29 16:05:14 +08:00
|
|
|
{
|
2010-08-03 11:23:12 +08:00
|
|
|
switch ( uMsg ) // Check For Windows Messages
|
2010-07-29 16:05:14 +08:00
|
|
|
{
|
2010-08-03 11:23:12 +08:00
|
|
|
case WM_ACTIVATE:
|
|
|
|
{
|
|
|
|
if ( ! HIWORD( wParam ) ) // Check Minimization State
|
|
|
|
{
|
2010-08-04 14:48:14 +08:00
|
|
|
s_active = TRUE;
|
2010-08-03 11:23:12 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-04 14:48:14 +08:00
|
|
|
s_active = FALSE;
|
2010-08-03 11:23:12 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2010-07-28 10:26:06 +08:00
|
|
|
|
2010-08-03 11:23:12 +08:00
|
|
|
case WM_SYSCOMMAND:
|
|
|
|
{
|
|
|
|
if ( ( wParam == SC_SCREENSAVE ) ||
|
|
|
|
( wParam == SC_MONITORPOWER ) )
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_CLOSE:
|
|
|
|
{
|
|
|
|
PostQuitMessage( 0 );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
{
|
2010-08-04 14:48:14 +08:00
|
|
|
s_keys[wParam] = TRUE;
|
2010-08-03 11:23:12 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_KEYUP:
|
|
|
|
{
|
2010-08-04 14:48:14 +08:00
|
|
|
s_keys[wParam] = FALSE;
|
2010-08-03 11:23:12 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_SIZE:
|
|
|
|
{
|
|
|
|
//ResizeScene( LOWORD( lParam ), HIWORD( lParam ) ); // LoWord=Width, HiWord=Height
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2010-07-28 10:26:06 +08:00
|
|
|
|
2010-08-03 11:23:12 +08:00
|
|
|
// Pass All Unhandled Messages To DefWindowProc
|
|
|
|
return DefWindowProc( hWnd, uMsg, wParam, lParam );
|
2010-07-28 10:26:06 +08:00
|
|
|
}
|
2010-08-05 17:20:24 +08:00
|
|
|
#endif
|