Clone of mesa.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

egltri.c 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
  3. * Copyright (C) 2008 Brian Paul All Rights Reserved.
  4. * Copyright (C) 2008 Jakob Bornecrantz All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included
  14. * in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  20. * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. /*
  24. * This program is based on eglgears and xegl_tri.
  25. * Remixed by Jakob Bornecrantz
  26. *
  27. * No command line options.
  28. * Program runs for 5 seconds then exits, outputing framerate to console
  29. */
  30. #define EGL_EGLEXT_PROTOTYPES
  31. #include <assert.h>
  32. #include <math.h>
  33. #include <stdlib.h>
  34. #include <stdio.h>
  35. #include <string.h>
  36. #include <GL/gl.h>
  37. #include <EGL/egl.h>
  38. #include <EGL/eglext.h>
  39. #define MAX_CONFIGS 10
  40. #define MAX_MODES 100
  41. /* XXX this probably isn't very portable */
  42. #include <sys/time.h>
  43. #include <unistd.h>
  44. /* return current time (in seconds) */
  45. static double
  46. current_time(void)
  47. {
  48. struct timeval tv;
  49. #ifdef __VMS
  50. (void) gettimeofday(&tv, NULL );
  51. #else
  52. struct timezone tz;
  53. (void) gettimeofday(&tv, &tz);
  54. #endif
  55. return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
  56. }
  57. static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
  58. static void draw()
  59. {
  60. static const GLfloat verts[3][2] = {
  61. { -1, -1 },
  62. { 1, -1 },
  63. { 0, 1 }
  64. };
  65. static const GLfloat colors[3][3] = {
  66. { 1, 0, 0 },
  67. { 0, 1, 0 },
  68. { 0, 0, 1 }
  69. };
  70. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  71. glPushMatrix();
  72. glRotatef(view_rotx, 1, 0, 0);
  73. glRotatef(view_roty, 0, 1, 0);
  74. glRotatef(view_rotz, 0, 0, 1);
  75. {
  76. glVertexPointer(2, GL_FLOAT, 0, verts);
  77. glColorPointer(3, GL_FLOAT, 0, colors);
  78. glEnableClientState(GL_VERTEX_ARRAY);
  79. glEnableClientState(GL_COLOR_ARRAY);
  80. glDrawArrays(GL_TRIANGLES, 0, 3);
  81. glDisableClientState(GL_VERTEX_ARRAY);
  82. glDisableClientState(GL_COLOR_ARRAY);
  83. }
  84. glPopMatrix();
  85. }
  86. static void init()
  87. {
  88. glClearColor(0.4, 0.4, 0.4, 0.0);
  89. }
  90. /* new window size or exposure */
  91. static void reshape(int width, int height)
  92. {
  93. GLfloat ar = (GLfloat) width / (GLfloat) height;
  94. glViewport(0, 0, (GLint) width, (GLint) height);
  95. glMatrixMode(GL_PROJECTION);
  96. glLoadIdentity();
  97. glFrustum(-ar, ar, -1, 1, 5.0, 60.0);
  98. glMatrixMode(GL_MODELVIEW);
  99. glLoadIdentity();
  100. glTranslatef(0.0, 0.0, -10.0);
  101. }
  102. static void run(EGLDisplay dpy, EGLSurface surf, int ttr)
  103. {
  104. double st = current_time();
  105. double ct = st;
  106. int frames = 0;
  107. GLfloat seconds, fps;
  108. while (ct - st < ttr)
  109. {
  110. ct = current_time();
  111. draw();
  112. eglSwapBuffers(dpy, surf);
  113. frames++;
  114. }
  115. seconds = ct - st;
  116. fps = frames / seconds;
  117. printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, fps);
  118. }
  119. int main(int argc, char *argv[])
  120. {
  121. int maj, min;
  122. EGLContext ctx;
  123. EGLSurface screen_surf;
  124. EGLConfig configs[MAX_CONFIGS];
  125. EGLint numConfigs, i;
  126. EGLBoolean b;
  127. EGLDisplay d;
  128. EGLint screenAttribs[10];
  129. EGLModeMESA mode[MAX_MODES];
  130. EGLScreenMESA screen;
  131. EGLint count, chosenMode = 0;
  132. GLboolean printInfo = GL_FALSE;
  133. EGLint width = 0, height = 0;
  134. /* parse cmd line args */
  135. for (i = 1; i < argc; i++)
  136. {
  137. if (strcmp(argv[i], "-info") == 0)
  138. {
  139. printInfo = GL_TRUE;
  140. }
  141. else
  142. printf("Warning: unknown parameter: %s\n", argv[i]);
  143. }
  144. /* DBR : Create EGL context/surface etc */
  145. d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
  146. assert(d);
  147. if (!eglInitialize(d, &maj, &min)) {
  148. printf("egltri: eglInitialize failed\n");
  149. exit(1);
  150. }
  151. printf("egltri: EGL version = %d.%d\n", maj, min);
  152. printf("egltri: EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR));
  153. /* XXX use ChooseConfig */
  154. eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs);
  155. eglGetScreensMESA(d, &screen, 1, &count);
  156. if (!eglGetModesMESA(d, screen, mode, MAX_MODES, &count) || count == 0) {
  157. printf("egltri: eglGetModesMESA failed!\n");
  158. return 0;
  159. }
  160. /* Print list of modes, and find the one to use */
  161. printf("egltri: Found %d modes:\n", count);
  162. for (i = 0; i < count; i++) {
  163. EGLint w, h;
  164. eglGetModeAttribMESA(d, mode[i], EGL_WIDTH, &w);
  165. eglGetModeAttribMESA(d, mode[i], EGL_HEIGHT, &h);
  166. printf("%3d: %d x %d\n", i, w, h);
  167. if (w > width && h > height) {
  168. width = w;
  169. height = h;
  170. chosenMode = i;
  171. }
  172. }
  173. printf("egltri: Using screen mode/size %d: %d x %d\n", chosenMode, width, height);
  174. eglBindAPI(EGL_OPENGL_API);
  175. ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL);
  176. if (ctx == EGL_NO_CONTEXT) {
  177. printf("egltri: failed to create context\n");
  178. return 0;
  179. }
  180. /* build up screenAttribs array */
  181. i = 0;
  182. screenAttribs[i++] = EGL_WIDTH;
  183. screenAttribs[i++] = width;
  184. screenAttribs[i++] = EGL_HEIGHT;
  185. screenAttribs[i++] = height;
  186. screenAttribs[i++] = EGL_NONE;
  187. screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs);
  188. if (screen_surf == EGL_NO_SURFACE) {
  189. printf("egltri: failed to create screen surface\n");
  190. return 0;
  191. }
  192. b = eglShowScreenSurfaceMESA(d, screen, screen_surf, mode[chosenMode]);
  193. if (!b) {
  194. printf("egltri: show surface failed\n");
  195. return 0;
  196. }
  197. b = eglMakeCurrent(d, screen_surf, screen_surf, ctx);
  198. if (!b) {
  199. printf("egltri: make current failed\n");
  200. return 0;
  201. }
  202. if (printInfo)
  203. {
  204. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  205. printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  206. printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
  207. printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
  208. }
  209. init();
  210. reshape(width, height);
  211. glDrawBuffer( GL_BACK );
  212. run(d, screen_surf, 5.0);
  213. eglDestroySurface(d, screen_surf);
  214. eglDestroyContext(d, ctx);
  215. eglTerminate(d);
  216. return 0;
  217. }