gl2_basic.cpp revision 493220dcb8d2f5d9633c157b41e1e27c6613b21d
1/* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#include <stdlib.h> 18#include <stdio.h> 19#include <time.h> 20#include <sched.h> 21#include <sys/resource.h> 22 23#include <EGL/egl.h> 24#include <GLES/gl.h> 25#include <GLES/glext.h> 26 27#include <utils/Timers.h> 28 29#include <ui/FramebufferNativeWindow.h> 30#include <ui/EGLUtils.h> 31 32using namespace android; 33 34static void printGLString(const char *name, GLenum s) 35{ 36 const char *v = (const char *)glGetString(s); 37 if (v) 38 printf("GL %s = %s\n", name, v); 39 else 40 printf("GL %s = (null)\n", name); 41} 42 43int main(int argc, char** argv) 44{ 45 EGLint s_configAttribs[] = { 46 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 47 EGL_RED_SIZE, 5, 48 EGL_GREEN_SIZE, 6, 49 EGL_BLUE_SIZE, 5, 50 EGL_NONE 51 }; 52 53 EGLint numConfigs = -1; 54 EGLint majorVersion; 55 EGLint minorVersion; 56 EGLConfig config; 57 EGLContext context; 58 EGLSurface surface; 59 EGLint w, h; 60 61 EGLDisplay dpy; 62 63 EGLNativeWindowType window = 0; 64 window = android_createDisplaySurface(); 65 66 dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); 67 eglInitialize(dpy, &majorVersion, &minorVersion); 68 EGLUtils::selectConfigForNativeWindow(dpy, s_configAttribs, window, &config); 69 surface = eglCreateWindowSurface(dpy, config, window, NULL); 70 71 EGLint gl2_0Attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE}; 72 73 context = eglCreateContext(dpy, config, NULL, gl2_0Attribs); 74 eglMakeCurrent(dpy, surface, surface, context); 75 eglQuerySurface(dpy, surface, EGL_WIDTH, &w); 76 eglQuerySurface(dpy, surface, EGL_HEIGHT, &h); 77 GLint dim = w<h ? w : h; 78 79 printGLString("Version", GL_VERSION); 80 printGLString("Vendor", GL_VENDOR); 81 printGLString("Renderer", GL_RENDERER); 82 printGLString("Extensions", GL_EXTENSIONS); 83 84 return 0; 85} 86