utils/bestprofile.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:
406
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/**
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * MojoShader; generate shader programs from bytecode of compiled
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *  Direct3D shaders.
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 *
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 * Please see the file LICENSE.txt in the source's root directory.
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 *  This file written by Ryan C. Gordon.
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
 */
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#include <stdio.h>
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
#include "mojoshader.h"
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#include "SDL.h"
682e9073a9cf Added bestprofile program.
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
406
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
int main(int argc, char **argv)
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
{
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
    int retval = 1;
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
    #if 0
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
    printf("MojoShader bestprofile\n");
901
a9f799b93150 Report changeset, not version.
Ryan C. Gordon <icculus@icculus.org>
parents: 588
diff changeset
    26
    printf("Compiled against changeset %s\n", MOJOSHADER_CHANGESET);
a9f799b93150 Report changeset, not version.
Ryan C. Gordon <icculus@icculus.org>
parents: 588
diff changeset
    27
    printf("Linked against changeset %s\n", MOJOSHADER_changeset());
406
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
    printf("\n");
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
    #endif
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
1134
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    31
    SDL_Window *sdlwindow = NULL;
406
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
    if (SDL_Init(SDL_INIT_VIDEO) == -1)
1134
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    33
        fprintf(stderr, "SDL_Init() error: %s\n", SDL_GetError());
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    34
    else if (SDL_GL_LoadLibrary(NULL) == -1)
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    35
        fprintf(stderr, "SDL_GL_LoadLibrary() error: %s\n", SDL_GetError());
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    36
    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
    37
        fprintf(stderr, "SDL_CreateWindow() error: %s\n", SDL_GetError());
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    38
    else if (SDL_GL_CreateContext(sdlwindow) == NULL)
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    39
        fprintf(stderr, "SDL_GL_CreateContext() error: %s\n", SDL_GetError());
406
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
    else
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
    {
1134
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    42
        const char *best = MOJOSHADER_glBestProfile(lookup, NULL, NULL, NULL, NULL);
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    43
        MOJOSHADER_glContext *ctx = MOJOSHADER_glCreateContext(best, lookup, 0, 0, 0, 0);
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    44
        if (ctx == NULL)
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    45
            printf("MOJOSHADER_glCreateContext() fail: %s\n", MOJOSHADER_glGetError());
406
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
        else
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
        {
1134
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    48
            printf("%s\n", best);
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    49
            retval = 0;  // success.
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    50
            MOJOSHADER_glDestroyContext(ctx);
406
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
        } // else
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
    } // else
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
1134
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
    54
    SDL_Quit();
406
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
    return retval;
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
} // main
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
// end of bestprofile.c ...
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59