blob: d877e740b40936fd7df507ebf2c080f538659bf5 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
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
25int main(int argc, char** argv)
26{
27 EGLint s_configAttribs[] = {
28 EGL_RED_SIZE, 5,
29 EGL_GREEN_SIZE, 6,
30 EGL_BLUE_SIZE, 5,
31 EGL_NONE
32 };
33
Mathias Agopian591018a2009-08-04 13:43:35 -070034 EGLint numConfigs = -1, n=0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035 EGLint majorVersion;
36 EGLint minorVersion;
37 EGLConfig config;
38 EGLContext context;
39 EGLSurface surface;
40 EGLint w, h;
41
42 EGLDisplay dpy;
43
44 dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
45 eglInitialize(dpy, &majorVersion, &minorVersion);
Mathias Agopian591018a2009-08-04 13:43:35 -070046
47 // Get all the "potential match" configs...
48 eglGetConfigs(dpy, NULL, 0, &numConfigs);
49 EGLConfig* const configs = malloc(sizeof(EGLConfig)*numConfigs);
50 eglChooseConfig(dpy, s_configAttribs, configs, numConfigs, &n);
51 config = configs[0];
52 if (n > 1) {
53 // if there is more than one candidate, go through the list
54 // and pick one that matches our framebuffer format
55 int fbSzA = 0; // should not hardcode
56 int fbSzR = 5; // should not hardcode
57 int fbSzG = 6; // should not hardcode
58 int fbSzB = 5; // should not hardcode
59 int i;
60 for (i=0 ; i<n ; i++) {
61 EGLint r,g,b,a;
62 eglGetConfigAttrib(dpy, configs[i], EGL_RED_SIZE, &r);
63 eglGetConfigAttrib(dpy, configs[i], EGL_GREEN_SIZE, &g);
64 eglGetConfigAttrib(dpy, configs[i], EGL_BLUE_SIZE, &b);
65 eglGetConfigAttrib(dpy, configs[i], EGL_ALPHA_SIZE, &a);
66 if (fbSzA == a && fbSzR == r && fbSzG == g && fbSzB == b) {
67 config = configs[i];
68 break;
69 }
70 }
71 }
72 free(configs);
73
74
75
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080076 surface = eglCreateWindowSurface(dpy, config,
77 android_createDisplaySurface(), NULL);
78 context = eglCreateContext(dpy, config, NULL, NULL);
79 eglMakeCurrent(dpy, surface, surface, context);
80 eglQuerySurface(dpy, surface, EGL_WIDTH, &w);
81 eglQuerySurface(dpy, surface, EGL_HEIGHT, &h);
82 GLint dim = w<h ? w : h;
83
84
85 GLint crop[4] = { 0, 4, 4, -4 };
86 glBindTexture(GL_TEXTURE_2D, 0);
87 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
88 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
89 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
90 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
91 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
92 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
93 glEnable(GL_TEXTURE_2D);
94 glColor4f(1,1,1,1);
95
96 // packing is always 4
97 uint8_t t8[] = {
98 0x00, 0x55, 0x00, 0x55,
99 0xAA, 0xFF, 0xAA, 0xFF,
100 0x00, 0x55, 0x00, 0x55,
101 0xAA, 0xFF, 0xAA, 0xFF };
102
103 uint16_t t16[] = {
104 0x0000, 0x5555, 0x0000, 0x5555,
105 0xAAAA, 0xFFFF, 0xAAAA, 0xFFFF,
106 0x0000, 0x5555, 0x0000, 0x5555,
107 0xAAAA, 0xFFFF, 0xAAAA, 0xFFFF };
108
109 uint16_t t5551[] = {
110 0x0000, 0xFFFF, 0x0000, 0xFFFF,
111 0xFFFF, 0x0000, 0xFFFF, 0x0000,
112 0x0000, 0xFFFF, 0x0000, 0xFFFF,
113 0xFFFF, 0x0000, 0xFFFF, 0x0000 };
114
115 uint32_t t32[] = {
116 0xFF000000, 0xFF0000FF, 0xFF00FF00, 0xFFFF0000,
117 0xFF00FF00, 0xFFFF0000, 0xFF000000, 0xFF0000FF,
118 0xFF00FFFF, 0xFF00FF00, 0x00FF00FF, 0xFFFFFF00,
119 0xFF000000, 0xFFFF00FF, 0xFF00FFFF, 0xFFFFFFFF
120 };
121
122
123 glClear(GL_COLOR_BUFFER_BIT);
124 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 4, 4, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, t8);
125 glDrawTexiOES(0, 0, 0, dim/2, dim/2);
126
127 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 4, 4, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, t16);
128 glDrawTexiOES(dim/2, 0, 0, dim/2, dim/2);
129
130 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, t16);
131 glDrawTexiOES(0, dim/2, 0, dim/2, dim/2);
132
133 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, t32);
134 glDrawTexiOES(dim/2, dim/2, 0, dim/2, dim/2);
135
136 eglSwapBuffers(dpy, surface);
137 return 0;
138}