test/testgles.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 24 Mar 2009 10:33:12 +0000
changeset 3099 82e60908fab1
parent 2765 f55c87ae336b
child 3110 e6c21c14ce3a
permissions -rw-r--r--
Date: Mon, 23 Mar 2009 09:17:24 +0200
From: "Mike Gorchak"
Subject: New QNX patches

Please apply patch qnx4.diff, which is attached. What has been done:
1)Added back OpenGL ES renderer for QNX target. Added few corrections to
OpenGL ES renderer to let it work under QNX. OpenGL ES renderer do not
support textures under QNX, so I think some additional work must be done.
2) Added GL_OES_query_matrix extension to SDL_opengles.h header file, which
required by OpenGL ES 1.1 specification.
3) Added attribute clearing at the entrance of function
SDL_GL_GetAttribure(). Added error checking into the function
SDL_GL_GetAttribure(), because some attributes can't be obtained in OpenGL
ES 1.0.
4) Porting testdyngles to OpenGL ES 1.0 (1.1 has glColor4ub() and
glColor4f() functions, but 1.0 has glColor4f() only).
5) Added error checking after obtaining attributes using
SDL_GL_GetAttribute() function to the testgl2 and testgles.
6) Small correction to testmultiaudio with printing errors.
7) Added software and accelerated OpenGL ES 1.0 support into the QNX GF
driver.

Please remove ./src/audio/nto directory - it will not be used anymore.
Please create ./src/audio/qsa directory and add content of the archive
qsa.tar.gz into this directory. I rewrote some sound code, added support for
multiple audio cards, enumeration, etc. Added initial support for capture.

As far as I can understand SDL 1.3 is not supporting audio capture right now
? Sam, Am I right ? Or audio capture must be supported through the
PlayDevice routine ?

And last, please put file SDL_gf_opengles.c to the ./src/video/qnxgf
directory. It is OpenGL ES 1.1 emulation layer for some functions, which are
not supported by OpenGL ES 1.0.
     1 #include <stdlib.h>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <math.h>
     5 
     6 #include "common.h"
     7 
     8 #ifdef __IPHONEOS__
     9 #define HAVE_OPENGLES
    10 #endif
    11 
    12 #ifdef HAVE_OPENGLES
    13 
    14 #include "SDL_opengles.h"
    15 
    16 static CommonState *state;
    17 static SDL_GLContext context;
    18 
    19 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    20 static void
    21 quit(int rc)
    22 {
    23     if (context) {
    24         /* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */
    25         SDL_GL_DeleteContext(context);
    26     }
    27     CommonQuit(state);
    28     exit(rc);
    29 }
    30 
    31 static void
    32 Render()
    33 {
    34     static GLubyte color[8][4] = { {255, 0, 0, 0},
    35     {255, 0, 0, 255},
    36     {0, 255, 0, 255},
    37     {0, 255, 0, 255},
    38     {0, 255, 0, 255},
    39     {255, 255, 255, 255},
    40     {255, 0, 255, 255},
    41     {0, 0, 255, 255}
    42     };
    43     static GLfloat cube[8][3] = { {0.5, 0.5, -0.5},
    44     {0.5f, -0.5f, -0.5f},
    45     {-0.5f, -0.5f, -0.5f},
    46     {-0.5f, 0.5f, -0.5f},
    47     {-0.5f, 0.5f, 0.5f},
    48     {0.5f, 0.5f, 0.5f},
    49     {0.5f, -0.5f, 0.5f},
    50     {-0.5f, -0.5f, 0.5f}
    51     };
    52     static GLubyte indices[36] = { 0, 3, 4,
    53         4, 5, 0,
    54         0, 5, 6,
    55         6, 1, 0,
    56         6, 7, 2,
    57         2, 1, 6,
    58         7, 4, 3,
    59         3, 2, 7,
    60         5, 4, 7,
    61         7, 6, 5,
    62         2, 3, 1,
    63         3, 0, 1
    64     };
    65 
    66 
    67     /* Do our drawing, too. */
    68     glClearColor(0.0, 0.0, 0.0, 1.0);
    69     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    70 
    71     /* Draw the cube */
    72     glColorPointer(4, GL_UNSIGNED_BYTE, 0, color);
    73     glEnableClientState(GL_COLOR_ARRAY);
    74     glVertexPointer(3, GL_FLOAT, 0, cube);
    75     glEnableClientState(GL_VERTEX_ARRAY);
    76     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, indices);
    77 
    78     glMatrixMode(GL_MODELVIEW);
    79     glRotatef(5.0, 1.0, 1.0, 1.0);
    80 }
    81 
    82 int
    83 main(int argc, char *argv[])
    84 {
    85     int fsaa, accel;
    86     int value;
    87     int i, done;
    88     SDL_DisplayMode mode;
    89     SDL_Event event;
    90     Uint32 then, now, frames;
    91     int status;
    92 
    93     /* Initialize parameters */
    94     fsaa = 0;
    95     accel = 0;
    96 
    97     /* Initialize test framework */
    98     state = CommonCreateState(argv, SDL_INIT_VIDEO);
    99     if (!state) {
   100         return 1;
   101     }
   102     for (i = 1; i < argc;) {
   103         int consumed;
   104 
   105         consumed = CommonArg(state, i);
   106         if (consumed == 0) {
   107             if (SDL_strcasecmp(argv[i], "--fsaa") == 0) {
   108                 ++fsaa;
   109                 consumed = 1;
   110             } else if (SDL_strcasecmp(argv[i], "--accel") == 0) {
   111                 ++accel;
   112                 consumed = 1;
   113             } else {
   114                 consumed = -1;
   115             }
   116         }
   117         if (consumed < 0) {
   118             fprintf(stderr, "Usage: %s %s [--fsaa] [--accel]\n", argv[0],
   119                     CommonUsage(state));
   120             quit(1);
   121         }
   122         i += consumed;
   123     }
   124 
   125     /* Set OpenGL parameters */
   126     state->window_flags |= SDL_WINDOW_OPENGL;
   127     SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
   128     SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
   129     SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
   130     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
   131     if (fsaa) {
   132         SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
   133         SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa);
   134     }
   135     if (accel) {
   136         SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
   137     }
   138     if (!CommonInit(state)) {
   139         quit(2);
   140     }
   141 
   142     /* Create OpenGL context */
   143     context = SDL_GL_CreateContext(state->windows[0]);
   144     if (!context) {
   145         fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
   146         quit(2);
   147     }
   148 
   149     if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
   150         SDL_GL_SetSwapInterval(1);
   151     } else {
   152         SDL_GL_SetSwapInterval(0);
   153     }
   154 
   155     SDL_GetCurrentDisplayMode(&mode);
   156     printf("Screen BPP: %d\n", SDL_BITSPERPIXEL(mode.format));
   157     printf("\n");
   158     printf("Vendor     : %s\n", glGetString(GL_VENDOR));
   159     printf("Renderer   : %s\n", glGetString(GL_RENDERER));
   160     printf("Version    : %s\n", glGetString(GL_VERSION));
   161     printf("Extensions : %s\n", glGetString(GL_EXTENSIONS));
   162     printf("\n");
   163 
   164     status=SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
   165     if (!status) {
   166         printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
   167     } else {
   168         printf("Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError());
   169     }
   170     status=SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
   171     if (!status) {
   172         printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
   173     } else {
   174         printf("Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError());
   175     }
   176     status=SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
   177     if (!status) {
   178         printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
   179     } else {
   180         printf("Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError());
   181     }
   182     status=SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
   183     if (!status) {
   184         printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
   185     } else {
   186         printf("Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError());
   187     }
   188     if (fsaa) {
   189         status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
   190         if (!status) {
   191             printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
   192         } else {
   193             printf("Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_GetError());
   194         }
   195         status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
   196         if (!status) {
   197             printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value);
   198         } else {
   199             printf("Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", SDL_GetError());
   200         }
   201     }
   202     if (accel) {
   203         status=SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
   204         if (!status)
   205         {
   206             printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
   207         } else {
   208             printf("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", SDL_GetError());
   209         }
   210     }
   211 
   212     /* Set rendering settings */
   213     glMatrixMode(GL_PROJECTION);
   214     glLoadIdentity();
   215     glOrthof(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
   216     glMatrixMode(GL_MODELVIEW);
   217     glLoadIdentity();
   218     glEnable(GL_DEPTH_TEST);
   219     glDepthFunc(GL_LESS);
   220     glShadeModel(GL_SMOOTH);
   221 
   222     /* Main render loop */
   223     frames = 0;
   224     then = SDL_GetTicks();
   225     done = 0;
   226     while (!done) {
   227         /* Check for events */
   228         ++frames;
   229         while (SDL_PollEvent(&event)) {
   230             CommonEvent(state, &event, &done);
   231         }
   232         for (i = 0; i < state->num_windows; ++i) {
   233             int w, h;
   234             SDL_GL_MakeCurrent(state->windows[i], context);
   235             SDL_GetWindowSize(state->windows[i], &w, &h);
   236             glViewport(0, 0, w, h);
   237             Render();
   238             SDL_GL_SwapWindow(state->windows[i]);
   239         }
   240     }
   241 
   242     /* Print out some timing information */
   243     now = SDL_GetTicks();
   244     if (now > then) {
   245         printf("%2.2f frames per second\n",
   246                ((double) frames * 1000) / (now - then));
   247     }
   248     quit(0);
   249     return 0;
   250 }
   251 
   252 #else /* HAVE_OPENGLES */
   253 
   254 int
   255 main(int argc, char *argv[])
   256 {
   257     printf("No OpenGL ES support on this system\n");
   258     return 1;
   259 }
   260 
   261 #endif /* HAVE_OPENGLES */