From 8e3ae3184e74a286deb593c6b0163a4183471120 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 29 Jun 2008 00:15:52 -0400 Subject: [PATCH] Added bestprofile program. --HG-- branch : trunk --- .hgignore | 1 + CMakeLists.txt | 2 ++ bestprofile.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 bestprofile.c diff --git a/.hgignore b/.hgignore index c11cacd3..54f47a14 100644 --- a/.hgignore +++ b/.hgignore @@ -5,6 +5,7 @@ Makefile cmake_install.cmake testparse testoutput +bestprofile finderrors glcaps *.exe diff --git a/CMakeLists.txt b/CMakeLists.txt index e3919877..35516e30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,8 @@ IF(SDL_FOUND) ADD_DEFINITIONS(-DFINDERRORS_COMPILE_SHADERS=1) ADD_EXECUTABLE(glcaps glcaps.c) TARGET_LINK_LIBRARIES(glcaps ${SDL_LIBRARY}) + ADD_EXECUTABLE(bestprofile bestprofile.c mojoshader.c mojoshader_opengl.c) + TARGET_LINK_LIBRARIES(bestprofile ${SDL_LIBRARY}) ENDIF(SDL_FOUND) ADD_EXECUTABLE(testparse testparse.c mojoshader.c) diff --git a/bestprofile.c b/bestprofile.c new file mode 100644 index 00000000..39370832 --- /dev/null +++ b/bestprofile.c @@ -0,0 +1,53 @@ +/** + * 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" + +int main(int argc, char **argv) +{ + int retval = 1; + + #if 0 + printf("MojoShader bestprofile\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 + { + const char *best = MOJOSHADER_glBestProfile(SDL_GL_GetProcAddress); + MOJOSHADER_glContext *ctx; + ctx = MOJOSHADER_glCreateContext(best, SDL_GL_GetProcAddress, 0, 0, 0); + if (ctx == NULL) + printf("MOJOSHADER_glCreateContext() fail: %s\n", MOJOSHADER_glGetError()); + else + { + printf("%s\n", best); + retval = 0; // success. + MOJOSHADER_glDestroyContext(ctx); + } // else + } // else + SDL_Quit(); + } // else + + return retval; +} // main + +// end of bestprofile.c ... +