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