-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzglAndroidNativeDevice.cpp
executable file
·145 lines (115 loc) · 3.08 KB
/
zglAndroidNativeDevice.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* Copyright (C) 2010 ZiiLABS Pte Ltd
* All Rights Reserved.
*
* This software and its associated documentation may contain some
* proprietary, confidential and trade secret information of
* ZiiLABS Pte Ltd and except as provided by written agreement with
* ZiiLABS Pte Ltd
*
* a) no part may be disclosed, distributed, reproduced, transmitted,
* transcribed, stored in a retrieval system, adapted or translated
* in any form or by any means electronic, mechanical, magnetic,
* optical, chemical, manual or otherwise,
*
* and
*
* b) the recipient is not entitled to discover through reverse
* engineering or reverse compiling or other such techniques or
* processes the trade secrets contained therein or in the
* documentation.
*/
#include <stdlib.h>
#include <unistd.h>
#include "zglDevice.h"
#include "zglAndroidNativeDevice.h"
#ifdef _ANDROID_NATIVE_
#include <android/log.h>
#include "zglCore.h"
#include "zglEngine.h"
using namespace android;
static zglEngine * glEngine = (zglEngine *)NULL;
static zglDevice * glDevice = (zglDevice *)NULL;
//!< static interface for the zglDevice::getDevice
zglDevice * zglDevice::getDevice()
{
if(glDevice == NULL)
{
glDevice = new zglAndroidNativeDevice();
}
return glDevice;
}
void zglDevice::destroyDevice()
{
if(glDevice != NULL)
{
delete glDevice;
glDevice = (zglDevice *)0;
}
}
//!< Implement of the zglAndroidNativeDevice
//!< GL/EGL attributes.
static EGLint configAttribs[] =
{
EGL_DEPTH_SIZE, 0,
EGL_NONE
};
bool zglAndroidNativeDevice::init(int width, int height, const char * title)
{
__android_log_print(ANDROID_LOG_INFO, "zglDemo", "zglAndroidNativeDevice::init()");
EGLNativeWindowType window = android_createDisplaySurface();
dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(dpy, &majorVersion, &minorVersion);
status_t err = EGLUtils::selectConfigForNativeWindow(
dpy, configAttribs, window, &config);
if (err)
{
fprintf(stderr, "couldn't find an EGLConfig matching the screen format\n");
return 0;
}
surface = eglCreateWindowSurface(dpy, config, window, NULL);
context = eglCreateContext(dpy, config, NULL, NULL);
eglMakeCurrent(dpy, surface, surface, context);
eglQuerySurface(dpy, surface, EGL_WIDTH, &m_width);
eglQuerySurface(dpy, surface, EGL_HEIGHT, &m_height);
//post initial
glEngine = zglEngine::getEngine();
glEngine->setSize(m_width, m_height);
glEngine->setViewport(0, 0, m_width, m_height);
zglCore::reset();
return true;
}
bool zglAndroidNativeDevice::fini()
{
eglMakeCurrent (dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroySurface (dpy, surface);
eglDestroyContext (dpy, context);
eglTerminate (dpy);
zglEngine::destroyEngine();
return true;
}
bool zglAndroidNativeDevice::run()
{
int loop = 0;
while(loop < 65536)
{
if(glEngine->update())
{
//glEngine->postUpdate();
glEngine->renderScreen();
flipScreen();
}
//usleep(20000);
}
fini();
return true;
}
long zglAndroidNativeDevice::getTickTime()
{
return 0l;
}
void zglAndroidNativeDevice::flipScreen()
{
eglSwapBuffers(dpy, surface);
}
#endif