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
25 #include <WindowSurface.h>
26 #include <EGLUtils.h>
27
28 using namespace android;
29
main(int,char **)30 int main(int /*argc*/, char** /*argv*/)
31 {
32 EGLint configAttribs[] = {
33 EGL_DEPTH_SIZE, 0,
34 EGL_NONE
35 };
36
37 EGLint majorVersion;
38 EGLint minorVersion;
39 EGLContext context;
40 EGLConfig config;
41 EGLSurface surface;
42 EGLint w, h;
43 EGLDisplay dpy;
44
45 WindowSurface windowSurface;
46 EGLNativeWindowType window = windowSurface.getSurface();
47
48 dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
49 eglInitialize(dpy, &majorVersion, &minorVersion);
50
51 status_t err = EGLUtils::selectConfigForNativeWindow(
52 dpy, configAttribs, window, &config);
53 if (err) {
54 fprintf(stderr, "couldn't find an EGLConfig matching the screen format\n");
55 return 0;
56 }
57
58 surface = eglCreateWindowSurface(dpy, config, window, NULL);
59 context = eglCreateContext(dpy, config, NULL, NULL);
60 eglMakeCurrent(dpy, surface, surface, context);
61 eglQuerySurface(dpy, surface, EGL_WIDTH, &w);
62 eglQuerySurface(dpy, surface, EGL_HEIGHT, &h);
63 GLint dim = w<h ? w : h;
64
65
66 GLint crop[4] = { 0, 4, 4, -4 };
67 glBindTexture(GL_TEXTURE_2D, 0);
68 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
69 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
70 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
71 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
72 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
73 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
74 glEnable(GL_TEXTURE_2D);
75 glColor4f(1,1,1,1);
76
77 // packing is always 4
78 uint8_t t8[] = {
79 0x00, 0x55, 0x00, 0x55,
80 0xAA, 0xFF, 0xAA, 0xFF,
81 0x00, 0x55, 0x00, 0x55,
82 0xAA, 0xFF, 0xAA, 0xFF };
83
84 uint16_t t16[] = {
85 0x0000, 0x5555, 0x0000, 0x5555,
86 0xAAAA, 0xFFFF, 0xAAAA, 0xFFFF,
87 0x0000, 0x5555, 0x0000, 0x5555,
88 0xAAAA, 0xFFFF, 0xAAAA, 0xFFFF };
89
90 uint32_t t32[] = {
91 0xFF000000, 0xFF0000FF, 0xFF00FF00, 0xFFFF0000,
92 0xFF00FF00, 0xFFFF0000, 0xFF000000, 0xFF0000FF,
93 0xFF00FFFF, 0xFF00FF00, 0x00FF00FF, 0xFFFFFF00,
94 0xFF000000, 0xFFFF00FF, 0xFF00FFFF, 0xFFFFFFFF
95 };
96
97
98 glClear(GL_COLOR_BUFFER_BIT);
99 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 4, 4, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, t8);
100 glDrawTexiOES(0, 0, 0, dim/2, dim/2);
101
102 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 4, 4, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, t16);
103 glDrawTexiOES(dim/2, 0, 0, dim/2, dim/2);
104
105 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, t16);
106 glDrawTexiOES(0, dim/2, 0, dim/2, dim/2);
107
108 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, t32);
109 glDrawTexiOES(dim/2, dim/2, 0, dim/2, dim/2);
110
111 eglSwapBuffers(dpy, surface);
112
113 sleep(2); // so you have a chance to admire it
114 return 0;
115 }
116