blob: 98e3be14406f47f28dbbcc567489ef363c543510 [file] [log] [blame]
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -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 <GLES/egl.h>
22
23int main(int argc, char** argv)
24{
25 EGLint s_configAttribs[] = {
26 EGL_RED_SIZE, 5,
27 EGL_GREEN_SIZE, 6,
28 EGL_BLUE_SIZE, 5,
29 EGL_NONE
30 };
31
32 EGLint numConfigs = -1;
33 EGLint majorVersion;
34 EGLint minorVersion;
35 EGLConfig config;
36 EGLContext context;
37 EGLSurface surface;
38 EGLint w, h;
39
40 EGLDisplay dpy;
41
42 dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
43 eglInitialize(dpy, &majorVersion, &minorVersion);
44 eglChooseConfig(dpy, s_configAttribs, &config, 1, &numConfigs);
45 surface = eglCreateWindowSurface(dpy, config,
46 android_createDisplaySurface(), NULL);
47 context = eglCreateContext(dpy, config, NULL, NULL);
48 eglMakeCurrent(dpy, surface, surface, context);
49 eglQuerySurface(dpy, surface, EGL_WIDTH, &w);
50 eglQuerySurface(dpy, surface, EGL_HEIGHT, &h);
51 GLint dim = w<h ? w : h;
52
53
54 GLint crop[4] = { 0, 4, 4, -4 };
55 glBindTexture(GL_TEXTURE_2D, 0);
56 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
57 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
58 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
59 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
60 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
61 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
62 glEnable(GL_TEXTURE_2D);
63 glColor4f(1,1,1,1);
64
65 // packing is always 4
66 uint8_t t8[] = {
67 0x00, 0x55, 0x00, 0x55,
68 0xAA, 0xFF, 0xAA, 0xFF,
69 0x00, 0x55, 0x00, 0x55,
70 0xAA, 0xFF, 0xAA, 0xFF };
71
72 uint16_t t16[] = {
73 0x0000, 0x5555, 0x0000, 0x5555,
74 0xAAAA, 0xFFFF, 0xAAAA, 0xFFFF,
75 0x0000, 0x5555, 0x0000, 0x5555,
76 0xAAAA, 0xFFFF, 0xAAAA, 0xFFFF };
77
78 uint16_t t5551[] = {
79 0x0000, 0xFFFF, 0x0000, 0xFFFF,
80 0xFFFF, 0x0000, 0xFFFF, 0x0000,
81 0x0000, 0xFFFF, 0x0000, 0xFFFF,
82 0xFFFF, 0x0000, 0xFFFF, 0x0000 };
83
84 uint32_t t32[] = {
85 0xFF000000, 0xFF0000FF, 0xFF00FF00, 0xFFFF0000,
86 0xFF00FF00, 0xFFFF0000, 0xFF000000, 0xFF0000FF,
87 0xFF00FFFF, 0xFF00FF00, 0x00FF00FF, 0xFFFFFF00,
88 0xFF000000, 0xFFFF00FF, 0xFF00FFFF, 0xFFFFFFFF
89 };
90
91
92 glClear(GL_COLOR_BUFFER_BIT);
93 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 4, 4, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, t8);
94 glDrawTexiOES(0, 0, 0, dim/2, dim/2);
95
96 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 4, 4, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, t16);
97 glDrawTexiOES(dim/2, 0, 0, dim/2, dim/2);
98
99 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, t16);
100 glDrawTexiOES(0, dim/2, 0, dim/2, dim/2);
101
102 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, t32);
103 glDrawTexiOES(dim/2, dim/2, 0, dim/2, dim/2);
104
105 eglSwapBuffers(dpy, surface);
106 return 0;
107}