From a3b149820a93acf7fbf3833d7646bec807e1f163 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 3 Jul 2008 15:27:05 -0400 Subject: [PATCH] Added availableprofiles.c ... --HG-- branch : trunk --- .hgignore | 1 + CMakeLists.txt | 2 ++ availableprofiles.c | 64 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 availableprofiles.c diff --git a/.hgignore b/.hgignore index a2982373..c7cc941c 100644 --- a/.hgignore +++ b/.hgignore @@ -6,6 +6,7 @@ cmake_install.cmake testparse testoutput bestprofile +availableprofiles finderrors glcaps *.exe diff --git a/CMakeLists.txt b/CMakeLists.txt index 3383c518..2a9bc352 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,8 @@ IF(SDL_FOUND) TARGET_LINK_LIBRARIES(glcaps ${SDL_LIBRARY}) ADD_EXECUTABLE(bestprofile bestprofile.c) TARGET_LINK_LIBRARIES(bestprofile mojoshader ${SDL_LIBRARY}) + ADD_EXECUTABLE(availableprofiles availableprofiles.c) + TARGET_LINK_LIBRARIES(availableprofiles mojoshader ${SDL_LIBRARY}) ENDIF(SDL_FOUND) ADD_EXECUTABLE(testparse testparse.c) diff --git a/availableprofiles.c b/availableprofiles.c new file mode 100644 index 00000000..81b45bcd --- /dev/null +++ b/availableprofiles.c @@ -0,0 +1,64 @@ +/** + * MojoShader; generate shader programs from bytecode of compiled + * Direct3D shaders. + * + * Please see the file LICENSE.txt in the source's root directory. + * + * This file written by Ryan C. Gordon. + */ + +#include +#include "mojoshader.h" +#include "SDL.h" + +static int check_available(void) +{ + const char **avail = NULL; + int total = MOJOSHADER_glAvailableProfiles(SDL_GL_GetProcAddress, NULL, 0); + if (total > 0) + { + avail = (const char **) alloca(sizeof (const char *) * total); + total = MOJOSHADER_glAvailableProfiles(SDL_GL_GetProcAddress, avail, total); + } // if + + if (total <= 0) + fprintf(stderr, "No profiles available.\n"); + else + { + int i; + for (i = 0; i < total; i++) + printf("%s\n", avail[i]); + } // else + + return 0; +} // check_available + + +int main(int argc, char **argv) +{ + int retval = 1; + + #if 0 + printf("MojoShader availableprofile\n"); + printf("Compiled against version %d\n", MOJOSHADER_VERSION); + printf("Linked against version %d\n", MOJOSHADER_version()); + printf("\n"); + #endif + + if (SDL_Init(SDL_INIT_VIDEO) == -1) + fprintf(stderr, "SDL_Init(SDL_INIT_VIDEO) error: %s\n", SDL_GetError()); + else + { + SDL_GL_LoadLibrary(NULL); + if (SDL_SetVideoMode(640, 480, 0, SDL_OPENGL) == NULL) + fprintf(stderr, "SDL_SetVideoMode() error: %s\n", SDL_GetError()); + else + retval = check_available(); + SDL_Quit(); + } // else + + return retval; +} // main + +// end of availableprofiles.c ... +