The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2006, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include <stdlib.h> |
| 19 | #include <stdio.h> |
| 20 | |
| 21 | #include <EGL/egl.h> |
| 22 | #include <GLES/gl.h> |
| 23 | #include <GLES/glext.h> |
| 24 | |
Mathias Agopian | a1f6eff | 2009-08-06 16:25:37 -0700 | [diff] [blame] | 25 | #include <ui/FramebufferNativeWindow.h> |
| 26 | #include <ui/EGLUtils.h> |
| 27 | |
| 28 | using namespace android; |
| 29 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | int main(int argc, char** argv) |
| 31 | { |
Mathias Agopian | a1f6eff | 2009-08-06 16:25:37 -0700 | [diff] [blame] | 32 | EGLint configAttribs[] = { |
| 33 | EGL_DEPTH_SIZE, 0, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | EGL_NONE |
| 35 | }; |
| 36 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | EGLint majorVersion; |
| 38 | EGLint minorVersion; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | EGLContext context; |
Mathias Agopian | a1f6eff | 2009-08-06 16:25:37 -0700 | [diff] [blame] | 40 | EGLConfig config; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | EGLSurface surface; |
| 42 | EGLint w, h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | EGLDisplay dpy; |
| 44 | |
Mathias Agopian | e6f0f5c | 2009-08-10 16:48:22 -0700 | [diff] [blame] | 45 | EGLNativeWindowType window = android_createDisplaySurface(); |
| 46 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 48 | eglInitialize(dpy, &majorVersion, &minorVersion); |
Mathias Agopian | a1f6eff | 2009-08-06 16:25:37 -0700 | [diff] [blame] | 49 | |
Mathias Agopian | a1f6eff | 2009-08-06 16:25:37 -0700 | [diff] [blame] | 50 | status_t err = EGLUtils::selectConfigForNativeWindow( |
| 51 | dpy, configAttribs, window, &config); |
| 52 | if (err) { |
| 53 | fprintf(stderr, "couldn't find an EGLConfig matching the screen format\n"); |
| 54 | return 0; |
Mathias Agopian | 429c521 | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 55 | } |
Mathias Agopian | a1f6eff | 2009-08-06 16:25:37 -0700 | [diff] [blame] | 56 | |
| 57 | surface = eglCreateWindowSurface(dpy, config, window, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | context = eglCreateContext(dpy, config, NULL, NULL); |
| 59 | eglMakeCurrent(dpy, surface, surface, context); |
| 60 | eglQuerySurface(dpy, surface, EGL_WIDTH, &w); |
| 61 | eglQuerySurface(dpy, surface, EGL_HEIGHT, &h); |
| 62 | GLint dim = w<h ? w : h; |
| 63 | |
| 64 | |
| 65 | GLint crop[4] = { 0, 4, 4, -4 }; |
| 66 | glBindTexture(GL_TEXTURE_2D, 0); |
| 67 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 68 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 69 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 70 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 71 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 72 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 73 | glEnable(GL_TEXTURE_2D); |
| 74 | glColor4f(1,1,1,1); |
| 75 | |
| 76 | // packing is always 4 |
| 77 | uint8_t t8[] = { |
| 78 | 0x00, 0x55, 0x00, 0x55, |
| 79 | 0xAA, 0xFF, 0xAA, 0xFF, |
| 80 | 0x00, 0x55, 0x00, 0x55, |
| 81 | 0xAA, 0xFF, 0xAA, 0xFF }; |
| 82 | |
| 83 | uint16_t t16[] = { |
| 84 | 0x0000, 0x5555, 0x0000, 0x5555, |
| 85 | 0xAAAA, 0xFFFF, 0xAAAA, 0xFFFF, |
| 86 | 0x0000, 0x5555, 0x0000, 0x5555, |
| 87 | 0xAAAA, 0xFFFF, 0xAAAA, 0xFFFF }; |
| 88 | |
| 89 | uint16_t t5551[] = { |
| 90 | 0x0000, 0xFFFF, 0x0000, 0xFFFF, |
| 91 | 0xFFFF, 0x0000, 0xFFFF, 0x0000, |
| 92 | 0x0000, 0xFFFF, 0x0000, 0xFFFF, |
| 93 | 0xFFFF, 0x0000, 0xFFFF, 0x0000 }; |
| 94 | |
| 95 | uint32_t t32[] = { |
| 96 | 0xFF000000, 0xFF0000FF, 0xFF00FF00, 0xFFFF0000, |
| 97 | 0xFF00FF00, 0xFFFF0000, 0xFF000000, 0xFF0000FF, |
| 98 | 0xFF00FFFF, 0xFF00FF00, 0x00FF00FF, 0xFFFFFF00, |
| 99 | 0xFF000000, 0xFFFF00FF, 0xFF00FFFF, 0xFFFFFFFF |
| 100 | }; |
| 101 | |
| 102 | |
| 103 | glClear(GL_COLOR_BUFFER_BIT); |
| 104 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 4, 4, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, t8); |
| 105 | glDrawTexiOES(0, 0, 0, dim/2, dim/2); |
| 106 | |
| 107 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 4, 4, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, t16); |
| 108 | glDrawTexiOES(dim/2, 0, 0, dim/2, dim/2); |
| 109 | |
| 110 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, t16); |
| 111 | glDrawTexiOES(0, dim/2, 0, dim/2, dim/2); |
| 112 | |
| 113 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, t32); |
| 114 | glDrawTexiOES(dim/2, dim/2, 0, dim/2, dim/2); |
| 115 | |
| 116 | eglSwapBuffers(dpy, surface); |
| 117 | return 0; |
| 118 | } |