utils/availableprofiles.c
author Ethan Lee <flibitijibibo@flibitijibibo.com>
Tue, 07 Jul 2020 17:44:32 -0400
changeset 1278 be0f548f321f
parent 1134 be31bd0ee0a2
permissions -rw-r--r--
spirv: Fix bogus detection of PSIZE0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
423
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/**
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * MojoShader; generate shader programs from bytecode of compiled
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *  Direct3D shaders.
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 *
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 * Please see the file LICENSE.txt in the source's root directory.
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 *  This file written by Ryan C. Gordon.
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
 */
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#include <stdio.h>
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
#include "mojoshader.h"
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#include "SDL.h"
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
904
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
    14
static void *lookup(const char *fnname, void *unused)
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
    15
{
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
    16
    (void) unused;
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
    17
    return SDL_GL_GetProcAddress(fnname);
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
    18
} // lookup
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
    19
423
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
static int check_available(void)
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
{
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
    const char **avail = NULL;
1117
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 904
diff changeset
    23
    int total = MOJOSHADER_glAvailableProfiles(lookup, NULL, NULL, 0, NULL, NULL, NULL);
423
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
    if (total > 0)
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
    {
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
        avail = (const char **) alloca(sizeof (const char *) * total);
1117
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 904
diff changeset
    27
        total = MOJOSHADER_glAvailableProfiles(lookup, NULL, avail, total, NULL, NULL, NULL);
423
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
    } // if
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
    if (total <= 0)
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
        fprintf(stderr, "No profiles available.\n");
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
    else
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
    {
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
        int i;
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
        for (i = 0; i < total; i++)
458
b91904879798 Added MOJOSHADER_maxShaderModel().
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    36
        {
b91904879798 Added MOJOSHADER_maxShaderModel().
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    37
            printf("%s (Shader Model %d)\n", avail[i],
b91904879798 Added MOJOSHADER_maxShaderModel().
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    38
                   MOJOSHADER_maxShaderModel(avail[i]));
b91904879798 Added MOJOSHADER_maxShaderModel().
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    39
        } // for
423
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
    } // else
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
    return 0;
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
} // check_available
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
int main(int argc, char **argv)
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
{
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
    int retval = 1;
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
    #if 0
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
    printf("MojoShader availableprofile\n");
901
a9f799b93150 Report changeset, not version.
Ryan C. Gordon <icculus@icculus.org>
parents: 588
diff changeset
    52
    printf("Compiled against changeset %s\n", MOJOSHADER_CHANGESET);
a9f799b93150 Report changeset, not version.
Ryan C. Gordon <icculus@icculus.org>
parents: 588
diff changeset
    53
    printf("Linked against changeset %s\n", MOJOSHADER_changeset());
423
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
    printf("\n");
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
    #endif
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
1134
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    57
    SDL_Window *sdlwindow = NULL;
423
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
    if (SDL_Init(SDL_INIT_VIDEO) == -1)
1134
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    59
        fprintf(stderr, "SDL_Init() error: %s\n", SDL_GetError());
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    60
    else if (SDL_GL_LoadLibrary(NULL) == -1)
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    61
        fprintf(stderr, "SDL_GL_LoadLibrary() error: %s\n", SDL_GetError());
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    62
    else if ((sdlwindow = SDL_CreateWindow(argv[0], SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_OPENGL)) == NULL)
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    63
        fprintf(stderr, "SDL_CreateWindow() error: %s\n", SDL_GetError());
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    64
    else if (SDL_GL_CreateContext(sdlwindow) == NULL)
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    65
        fprintf(stderr, "SDL_GL_CreateContext() error: %s\n", SDL_GetError());
423
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
    else
1134
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    67
        retval = check_available();
423
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
1134
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    69
    SDL_Quit();
423
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
    return retval;
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
} // main
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
// end of availableprofiles.c ...
ee393c1cf3b4 Added availableprofiles.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74