132216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian/* 232216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** 332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** Copyright 2006, The Android Open Source Project 432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** 532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** Licensed under the Apache License, Version 2.0 (the "License"); 632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** you may not use this file except in compliance with the License. 732216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** You may obtain a copy of the License at 832216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** 932216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** http://www.apache.org/licenses/LICENSE-2.0 1032216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** 1132216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** Unless required by applicable law or agreed to in writing, software 1232216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** distributed under the License is distributed on an "AS IS" BASIS, 1332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** See the License for the specific language governing permissions and 1532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian** limitations under the License. 1632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian*/ 1732216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 1832216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian#include <unistd.h> 1932216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian#include <stdlib.h> 2032216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian#include <stdio.h> 2132216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 2232216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian#include <EGL/egl.h> 2332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian#include <GLES/gl.h> 2432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian#include <GLES/glext.h> 2532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 2632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian#include <utils/StopWatch.h> 276ef57d7b368ebbac5f2b27c36a9032fee1cda8b1Andy McFadden#include <WindowSurface.h> 286ef57d7b368ebbac5f2b27c36a9032fee1cda8b1Andy McFadden#include <EGLUtils.h> 2932216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 3032216166f127d7d30765b08d219f2c4ffd754080Mathias Agopianusing namespace android; 3132216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 3232216166f127d7d30765b08d219f2c4ffd754080Mathias Agopianint main(int argc, char** argv) 3332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian{ 3432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian EGLint configAttribs[] = { 3532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian EGL_DEPTH_SIZE, 0, 3632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian EGL_NONE 3732216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian }; 3832216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 3932216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian EGLint majorVersion; 4032216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian EGLint minorVersion; 4132216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian EGLContext context; 4232216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian EGLConfig config; 4332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian EGLSurface surface; 4432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian EGLint w, h; 4532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian EGLDisplay dpy; 4632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 476ef57d7b368ebbac5f2b27c36a9032fee1cda8b1Andy McFadden WindowSurface windowSurface; 486ef57d7b368ebbac5f2b27c36a9032fee1cda8b1Andy McFadden EGLNativeWindowType window = windowSurface.getSurface(); 4932216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 5032216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); 5132216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian eglInitialize(dpy, &majorVersion, &minorVersion); 5232216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 5332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian status_t err = EGLUtils::selectConfigForNativeWindow( 5432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian dpy, configAttribs, window, &config); 5532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian if (err) { 5632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian fprintf(stderr, "couldn't find an EGLConfig matching the screen format\n"); 5732216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian return 0; 5832216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian } 5932216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 6032216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian surface = eglCreateWindowSurface(dpy, config, window, NULL); 6132216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian context = eglCreateContext(dpy, config, NULL, NULL); 6232216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian eglMakeCurrent(dpy, surface, surface, context); 6332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian eglQuerySurface(dpy, surface, EGL_WIDTH, &w); 6432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian eglQuerySurface(dpy, surface, EGL_HEIGHT, &h); 6532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 6632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian printf("w=%d, h=%d\n", w, h); 6732216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 6832216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian glBindTexture(GL_TEXTURE_2D, 0); 6932216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 706c7d04b1d038318a9fe3ba59ce2a748bd00578ebMathias Agopian glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 713810c2b6c6216211a67f6240a8c520b1de4e409dMathias Agopian glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 723810c2b6c6216211a67f6240a8c520b1de4e409dMathias Agopian glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 7332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 7432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian glDisable(GL_DITHER); 7532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian glDisable(GL_BLEND); 7632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian glEnable(GL_TEXTURE_2D); 7732216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian glColor4f(1,1,1,1); 7832216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 796c7d04b1d038318a9fe3ba59ce2a748bd00578ebMathias Agopian 806c7d04b1d038318a9fe3ba59ce2a748bd00578ebMathias Agopian // default pack-alignment is 4 816c7d04b1d038318a9fe3ba59ce2a748bd00578ebMathias Agopian const uint16_t t16[64] = { 0xFFFF, 0, 0xF800, 0, 0x07E0, 0, 0x001F, 0 }; 8232216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 8332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian const GLfloat vertices[4][2] = { 843810c2b6c6216211a67f6240a8c520b1de4e409dMathias Agopian { w/2, 0 }, 853810c2b6c6216211a67f6240a8c520b1de4e409dMathias Agopian { w/2, h } 8632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian }; 8732216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 8832216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian const GLfloat texCoords[4][2] = { 8932216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian { 0, 0 }, 903810c2b6c6216211a67f6240a8c520b1de4e409dMathias Agopian { 1, 1 } 9132216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian }; 9232216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 933810c2b6c6216211a67f6240a8c520b1de4e409dMathias Agopian glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 4, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, t16); 9432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 9532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian glViewport(0, 0, w, h); 9632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian glMatrixMode(GL_PROJECTION); 9732216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian glLoadIdentity(); 9832216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian glOrthof(0, w, 0, h, 0, 1); 9932216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 10032216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian glEnableClientState(GL_VERTEX_ARRAY); 10132216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian glEnableClientState(GL_TEXTURE_COORD_ARRAY); 10232216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian glVertexPointer(2, GL_FLOAT, 0, vertices); 10332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian glTexCoordPointer(2, GL_FLOAT, 0, texCoords); 10432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 10532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian glClearColor(0,0,0,0); 10632216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian glClear(GL_COLOR_BUFFER_BIT); 10732216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian glDrawArrays(GL_LINES, 0, 2); 10832216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian eglSwapBuffers(dpy, surface); 10932216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 11032216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian usleep(5*1000000); 11132216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 11232216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian eglTerminate(dpy); 11332216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian 11432216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian return 0; 11532216166f127d7d30765b08d219f2c4ffd754080Mathias Agopian} 116