utils/bestprofile.c
author Ryan C. Gordon <icculus@icculus.org>
Mon, 23 Apr 2012 02:03:02 -0400
changeset 1102 0af2fb8af7fc
parent 904 5989f0d4185a
child 1117 f6712bf72c19
permissions -rw-r--r--
GLSL and ARB1: Implemented TEXM3X3 opcode.
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
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
    if (SDL_Init(SDL_INIT_VIDEO) == -1)
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
        fprintf(stderr, "SDL_Init(SDL_INIT_VIDEO) error: %s\n", SDL_GetError());
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
    else
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
    {
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
        SDL_GL_LoadLibrary(NULL);
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
        if (SDL_SetVideoMode(640, 480, 0, SDL_OPENGL) == NULL)
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
            fprintf(stderr, "SDL_SetVideoMode() error: %s\n", SDL_GetError());
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
        else
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
        {
904
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
    40
            const char *best = MOJOSHADER_glBestProfile(lookup, NULL);
406
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
            MOJOSHADER_glContext *ctx;
904
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
    42
            ctx = MOJOSHADER_glCreateContext(best, lookup, 0, 0, 0, 0);
406
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
            if (ctx == NULL)
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
                printf("MOJOSHADER_glCreateContext() fail: %s\n", MOJOSHADER_glGetError());
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
            else
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
            {
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
                printf("%s\n", best);
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
                retval = 0;  // success.
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
                MOJOSHADER_glDestroyContext(ctx);
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
            } // else
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
        SDL_Quit();
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
    } // else
682e9073a9cf Added bestprofile program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
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