~ubuntu-branches/ubuntu/oneiric/mesa-demos/oneiric

« back to all changes in this revision

Viewing changes to src/egl/opengl/demo1.c

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers
  • Date: 2010-09-27 16:18:27 UTC
  • Revision ID: james.westby@ubuntu.com-20100927161827-1yfgolc1oy9sjhi8
Tags: upstream-8.0.1
ImportĀ upstreamĀ versionĀ 8.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Exercise EGL API functions
 
3
 */
 
4
 
 
5
#define EGL_EGLEXT_PROTOTYPES
 
6
 
 
7
#include <EGL/egl.h>
 
8
#include <EGL/eglext.h>
 
9
#include <assert.h>
 
10
#include <stdio.h>
 
11
#include <stdlib.h>
 
12
#include <string.h>
 
13
 
 
14
 
 
15
/**
 
16
 * Test EGL_MESA_screen_surface functions
 
17
 */
 
18
static void
 
19
TestScreens(EGLDisplay dpy)
 
20
{
 
21
#define MAX 8
 
22
   EGLScreenMESA screens[MAX];
 
23
   EGLint numScreens;
 
24
   EGLint i;
 
25
 
 
26
   eglGetScreensMESA(dpy, screens, MAX, &numScreens);
 
27
   printf("Found %d screens\n", numScreens);
 
28
   for (i = 0; i < numScreens; i++) {
 
29
      printf(" Screen %d handle: %d\n", i, (int) screens[i]);
 
30
   }
 
31
}
 
32
 
 
33
/**
 
34
 * Print table of all available configurations.
 
35
 */
 
36
static void
 
37
PrintConfigs(EGLDisplay d, EGLConfig *configs, EGLint numConfigs)
 
38
{
 
39
   EGLint i;
 
40
 
 
41
   printf("Configurations:\n");
 
42
   printf("     bf lv d st colorbuffer dp st   supported \n");
 
43
   printf("  id sz  l b ro  r  g  b  a th cl   surfaces  \n");
 
44
   printf("----------------------------------------------\n");
 
45
   for (i = 0; i < numConfigs; i++) {
 
46
      EGLint id, size, level;
 
47
      EGLint red, green, blue, alpha;
 
48
      EGLint depth, stencil;
 
49
      EGLint surfaces;
 
50
      EGLint doubleBuf = 1, stereo = 0;
 
51
      char surfString[100] = "";
 
52
 
 
53
      eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id);
 
54
      eglGetConfigAttrib(d, configs[i], EGL_BUFFER_SIZE, &size);
 
55
      eglGetConfigAttrib(d, configs[i], EGL_LEVEL, &level);
 
56
 
 
57
      eglGetConfigAttrib(d, configs[i], EGL_RED_SIZE, &red);
 
58
      eglGetConfigAttrib(d, configs[i], EGL_GREEN_SIZE, &green);
 
59
      eglGetConfigAttrib(d, configs[i], EGL_BLUE_SIZE, &blue);
 
60
      eglGetConfigAttrib(d, configs[i], EGL_ALPHA_SIZE, &alpha);
 
61
      eglGetConfigAttrib(d, configs[i], EGL_DEPTH_SIZE, &depth);
 
62
      eglGetConfigAttrib(d, configs[i], EGL_STENCIL_SIZE, &stencil);
 
63
      eglGetConfigAttrib(d, configs[i], EGL_SURFACE_TYPE, &surfaces);
 
64
 
 
65
      if (surfaces & EGL_WINDOW_BIT)
 
66
         strcat(surfString, "win,");
 
67
      if (surfaces & EGL_PBUFFER_BIT)
 
68
         strcat(surfString, "pb,");
 
69
      if (surfaces & EGL_PIXMAP_BIT)
 
70
         strcat(surfString, "pix,");
 
71
      if (strlen(surfString) > 0)
 
72
         surfString[strlen(surfString) - 1] = 0;
 
73
 
 
74
      printf("0x%02x %2d %2d %c  %c %2d %2d %2d %2d %2d %2d   %-12s\n",
 
75
             id, size, level,
 
76
             doubleBuf ? 'y' : '.',
 
77
             stereo ? 'y' : '.',
 
78
             red, green, blue, alpha,
 
79
             depth, stencil, surfString);
 
80
   }
 
81
}
 
82
 
 
83
 
 
84
 
 
85
int
 
86
main(int argc, char *argv[])
 
87
{
 
88
   int maj, min;
 
89
   EGLContext ctx;
 
90
   EGLSurface pbuffer;
 
91
   EGLConfig *configs;
 
92
   EGLint numConfigs;
 
93
   EGLBoolean b;
 
94
   const EGLint pbufAttribs[] = {
 
95
      EGL_WIDTH, 500,
 
96
      EGL_HEIGHT, 500,
 
97
      EGL_NONE
 
98
   };
 
99
 
 
100
   EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
 
101
   assert(d);
 
102
 
 
103
   if (!eglInitialize(d, &maj, &min)) {
 
104
      printf("demo: eglInitialize failed\n");
 
105
      exit(1);
 
106
   }
 
107
 
 
108
   printf("EGL version = %d.%d\n", maj, min);
 
109
   printf("EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR));
 
110
 
 
111
   eglGetConfigs(d, NULL, 0, &numConfigs);
 
112
   configs = malloc(sizeof(*configs) *numConfigs);
 
113
   eglGetConfigs(d, configs, numConfigs, &numConfigs);
 
114
 
 
115
   PrintConfigs(d, configs, numConfigs);
 
116
 
 
117
   eglBindAPI(EGL_OPENGL_API);
 
118
   ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL);
 
119
   if (ctx == EGL_NO_CONTEXT) {
 
120
      printf("failed to create context\n");
 
121
      return 0;
 
122
   }
 
123
 
 
124
   pbuffer = eglCreatePbufferSurface(d, configs[0], pbufAttribs);
 
125
   if (pbuffer == EGL_NO_SURFACE) {
 
126
      printf("failed to create pbuffer\n");
 
127
      return 0;
 
128
   }
 
129
 
 
130
   free(configs);
 
131
 
 
132
   b = eglMakeCurrent(d, pbuffer, pbuffer, ctx);
 
133
   if (!b) {
 
134
      printf("make current failed\n");
 
135
      return 0;
 
136
   }
 
137
 
 
138
   b = eglMakeCurrent(d, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
 
139
 
 
140
   TestScreens(d);
 
141
 
 
142
   eglDestroySurface(d, pbuffer);
 
143
   eglDestroyContext(d, ctx);
 
144
   eglTerminate(d);
 
145
 
 
146
   return 0;
 
147
}