blob: 1e55db0e07ffe061e36c73a14d78d7de5f751938 [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
Andy McFadden6ef57d72014-03-05 15:06:53 -080025#include <WindowSurface.h>
26#include <EGLUtils.h>
Mathias Agopian653870d2009-08-06 16:25:37 -070027
28using namespace android;
29
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080030int main(int argc, char** argv)
31{
Mathias Agopian653870d2009-08-06 16:25:37 -070032 EGLint configAttribs[] = {
33 EGL_DEPTH_SIZE, 0,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080034 EGL_NONE
35 };
36
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037 EGLint majorVersion;
38 EGLint minorVersion;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080039 EGLContext context;
Mathias Agopian653870d2009-08-06 16:25:37 -070040 EGLConfig config;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080041 EGLSurface surface;
42 EGLint w, h;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043 EGLDisplay dpy;
44
Andy McFadden6ef57d72014-03-05 15:06:53 -080045 WindowSurface windowSurface;
46 EGLNativeWindowType window = windowSurface.getSurface();
Mathias Agopian1d3bcd62009-08-10 16:48:22 -070047
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048 dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
49 eglInitialize(dpy, &majorVersion, &minorVersion);
Mathias Agopian653870d2009-08-06 16:25:37 -070050
Mathias Agopian653870d2009-08-06 16:25:37 -070051 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;
Mathias Agopian591018a2009-08-04 13:43:35 -070056 }
Mathias Agopian653870d2009-08-06 16:25:37 -070057
58 surface = eglCreateWindowSurface(dpy, config, window, NULL);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080059 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 uint16_t t5551[] = {
91 0x0000, 0xFFFF, 0x0000, 0xFFFF,
92 0xFFFF, 0x0000, 0xFFFF, 0x0000,
93 0x0000, 0xFFFF, 0x0000, 0xFFFF,
94 0xFFFF, 0x0000, 0xFFFF, 0x0000 };
95
96 uint32_t t32[] = {
97 0xFF000000, 0xFF0000FF, 0xFF00FF00, 0xFFFF0000,
98 0xFF00FF00, 0xFFFF0000, 0xFF000000, 0xFF0000FF,
99 0xFF00FFFF, 0xFF00FF00, 0x00FF00FF, 0xFFFFFF00,
100 0xFF000000, 0xFFFF00FF, 0xFF00FFFF, 0xFFFFFFFF
101 };
102
103
104 glClear(GL_COLOR_BUFFER_BIT);
105 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 4, 4, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, t8);
106 glDrawTexiOES(0, 0, 0, dim/2, dim/2);
107
108 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 4, 4, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, t16);
109 glDrawTexiOES(dim/2, 0, 0, dim/2, dim/2);
110
111 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, t16);
112 glDrawTexiOES(0, dim/2, 0, dim/2, dim/2);
113
114 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, t32);
115 glDrawTexiOES(dim/2, dim/2, 0, dim/2, dim/2);
116
117 eglSwapBuffers(dpy, surface);
Andy McFadden6ef57d72014-03-05 15:06:53 -0800118
119 sleep(2); // so you have a chance to admire it
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800120 return 0;
121}