summaryrefslogtreecommitdiffstats
path: root/opengl/tests/gl2_basic
diff options
context:
space:
mode:
authorJack Palevich <jackpal@google.com>2009-09-17 10:59:23 -0700
committerJack Palevich <jackpal@google.com>2009-09-17 10:59:23 -0700
commitfc342cbbf71e29ed52996dee059655c83b95ab68 (patch)
treeb36e599ff589c64a5d0f540f31015425ba42f216 /opengl/tests/gl2_basic
parent113096d5d05c9c1739c9d427399f47a35cf6fd57 (diff)
downloadframeworks_base-fc342cbbf71e29ed52996dee059655c83b95ab68.zip
frameworks_base-fc342cbbf71e29ed52996dee059655c83b95ab68.tar.gz
frameworks_base-fc342cbbf71e29ed52996dee059655c83b95ab68.tar.bz2
Add additional error checking, exit early if errors occur.
Diffstat (limited to 'opengl/tests/gl2_basic')
-rw-r--r--opengl/tests/gl2_basic/gl2_basic.cpp77
1 files changed, 59 insertions, 18 deletions
diff --git a/opengl/tests/gl2_basic/gl2_basic.cpp b/opengl/tests/gl2_basic/gl2_basic.cpp
index f969a46..d4887ba 100644
--- a/opengl/tests/gl2_basic/gl2_basic.cpp
+++ b/opengl/tests/gl2_basic/gl2_basic.cpp
@@ -34,14 +34,16 @@ using namespace android;
static void printGLString(const char *name, GLenum s)
{
fprintf(stderr, "printGLString %s, %d\n", name, s);
+#if 0 // causes hangs
const char *v = (const char *)glGetString(s);
int error = glGetError();
fprintf(stderr, "glGetError() = %d, result of glGetString = %x\n", error,
(unsigned int)v);
- if ((v < (const char*) 0) || (v > (const char*) 0x1000))
+ if ((v < (const char*) 0) || (v > (const char*) 0x10000))
fprintf(stderr, "GL %s = %s\n", name, v);
else
- fprintf(stderr, "GL %s = (null)\n", name);
+ fprintf(stderr, "GL %s = (null) 0x%08x\n", name, (unsigned int) v);
+#endif
}
static const char* eglErrorToString[] = {
@@ -61,7 +63,11 @@ static const char* eglErrorToString[] = {
"EGL_BAD_SURFACE"
};
-static void checkEglError(const char* op) {
+static void checkEglError(const char* op, EGLBoolean returnVal = EGL_TRUE) {
+ if (returnVal != EGL_TRUE) {
+ fprintf(stderr, "%s() returned %d\n", op, returnVal);
+ }
+
for(EGLint error = eglGetError();
error != EGL_SUCCESS;
error = eglGetError()) {
@@ -69,25 +75,30 @@ static void checkEglError(const char* op) {
if (error >= EGL_SUCCESS && error <= EGL_BAD_SURFACE) {
errorString = eglErrorToString[error - EGL_SUCCESS];
}
- fprintf(stderr, "%s() returned eglError %s (0x%x)\n", op,
+ fprintf(stderr, "after %s() eglError %s (0x%x)\n", op,
errorString, error);
}
}
int main(int argc, char** argv)
{
+ EGLBoolean returnValue;
+ EGLConfig configs[2];
+ EGLint config_count;
+
+ EGLint context_attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
EGLint s_configAttribs[] = {
- EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
- EGL_RED_SIZE, 5,
- EGL_GREEN_SIZE, 6,
- EGL_BLUE_SIZE, 5,
- EGL_NONE
+ EGL_BUFFER_SIZE, EGL_DONT_CARE,
+ EGL_RED_SIZE, 5,
+ EGL_GREEN_SIZE, 6,
+ EGL_BLUE_SIZE, 5,
+ EGL_DEPTH_SIZE, 8,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+ EGL_NONE
};
- EGLint numConfigs = -1;
EGLint majorVersion;
EGLint minorVersion;
- EGLConfig config;
EGLContext context;
EGLSurface surface;
EGLint w, h;
@@ -100,20 +111,50 @@ int main(int argc, char** argv)
checkEglError("<init>");
dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
checkEglError("eglGetDisplay");
- eglInitialize(dpy, &majorVersion, &minorVersion);
- checkEglError("eglInitialize");
+ if (dpy == EGL_NO_DISPLAY) {
+ printf("eglGetDisplay returned EGL_NO_DISPLAY.\n");
+ return 0;
+ }
+ returnValue = eglInitialize(dpy, &majorVersion, &minorVersion);
+ checkEglError("eglInitialize", returnValue);
fprintf(stderr, "EGL version %d.%d\n", majorVersion, minorVersion);
- EGLUtils::selectConfigForNativeWindow(dpy, s_configAttribs, window, &config);
- fprintf(stderr, "Chosen config: 0x%08x\n", (unsigned long) config);
+ returnValue = eglGetConfigs (dpy, configs, 2, &config_count);
+ checkEglError("eglGetConfigs", returnValue);
+ fprintf(stderr, "Config count: %d\n", config_count);
+ for(int i = 0; i < config_count; i++) {
+ fprintf(stderr, "%d: 0x%08x\n", i, (unsigned int) configs[i]);
+ }
+#if 0
+ EGLConfig config;
+ EGLUtils::selectConfigForNativeWindow(dpy, s_configAttribs, window, &config);
checkEglError("EGLUtils::selectConfigForNativeWindow");
- surface = eglCreateWindowSurface(dpy, config, window, NULL);
- checkEglError("eglCreateWindowSurface");
+#else
+ int chooseConfigResult = eglChooseConfig(dpy, s_configAttribs, configs, 2, &config_count);
+ checkEglError("eglChooseConfig", chooseConfigResult);
+ if (chooseConfigResult != EGL_TRUE )
+ {
+ printf("eglChooseConfig failed\n");
+ return 0;
+ }
+#endif
+ surface = eglCreateWindowSurface(dpy, configs[0], window, NULL);
+ checkEglError("eglCreateWindowSurface");
+ if (surface == EGL_NO_SURFACE)
+ {
+ printf("gelCreateWindowSurface failed.\n");
+ return 0;
+ }
EGLint gl2_0Attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
- context = eglCreateContext(dpy, config, NULL, gl2_0Attribs);
+ context = eglCreateContext(dpy, configs[0], EGL_NO_CONTEXT, context_attribs);
checkEglError("eglCreateContext");
+ if (context == EGL_NO_CONTEXT)
+ {
+ printf("eglCreateContext failed\n");
+ return 0;
+ }
eglMakeCurrent(dpy, surface, surface, context);
checkEglError("eglMakeCurrent");
eglQuerySurface(dpy, surface, EGL_WIDTH, &w);