Subversion Repositories Kolibri OS

Rev

Rev 3770 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. #include "pipe/p_compiler.h"
  3. #include "pipe/p_context.h"
  4. #include "pipe/p_shader_tokens.h"
  5. #include "pipe/p_state.h"
  6. #include "tgsi/tgsi_text.h"
  7. #include "util/u_debug.h"
  8. #include "util/u_memory.h"
  9. #include "state_tracker/graw.h"
  10.  
  11. /* Helper functions.  These are the same for all graw implementations.
  12.  */
  13. PUBLIC void *
  14. graw_parse_geometry_shader(struct pipe_context *pipe,
  15.                            const char *text)
  16. {
  17.    struct tgsi_token tokens[1024];
  18.    struct pipe_shader_state state;
  19.  
  20.    if (!tgsi_text_translate(text, tokens, Elements(tokens)))
  21.       return NULL;
  22.  
  23.    memset(&state, 0, sizeof state);
  24.    state.tokens = tokens;
  25.    return pipe->create_gs_state(pipe, &state);
  26. }
  27.  
  28. PUBLIC void *
  29. graw_parse_vertex_shader(struct pipe_context *pipe,
  30.                          const char *text)
  31. {
  32.    struct tgsi_token tokens[1024];
  33.    struct pipe_shader_state state;
  34.  
  35.    if (!tgsi_text_translate(text, tokens, Elements(tokens)))
  36.       return NULL;
  37.  
  38.    memset(&state, 0, sizeof state);
  39.    state.tokens = tokens;
  40.    return pipe->create_vs_state(pipe, &state);
  41. }
  42.  
  43. PUBLIC void *
  44. graw_parse_fragment_shader(struct pipe_context *pipe,
  45.                            const char *text)
  46. {
  47.    struct tgsi_token tokens[1024];
  48.    struct pipe_shader_state state;
  49.  
  50.    if (!tgsi_text_translate(text, tokens, Elements(tokens)))
  51.       return NULL;
  52.  
  53.    memset(&state, 0, sizeof state);
  54.    state.tokens = tokens;
  55.    return pipe->create_fs_state(pipe, &state);
  56. }
  57.  
  58. static char out_filename[256] = "";
  59.  
  60. PUBLIC boolean
  61. graw_parse_args(int *argi,
  62.                 int argc,
  63.                 char *argv[])
  64. {
  65.    if (strcmp(argv[*argi], "-o") == 0) {
  66.       if (*argi + 1 >= argc) {
  67.          return FALSE;
  68.       }
  69.  
  70.       strncpy(out_filename, argv[*argi + 1], sizeof(out_filename) - 1);
  71.       out_filename[sizeof(out_filename) - 1] = '\0';
  72.       *argi += 2;
  73.       return TRUE;
  74.    }
  75.  
  76.    return FALSE;
  77. }
  78.  
  79. PUBLIC boolean
  80. graw_save_surface_to_file(struct pipe_context *pipe,
  81.                           struct pipe_surface *surface,
  82.                           const char *filename)
  83. {
  84.    if (!filename || !*filename) {
  85.       filename = out_filename;
  86.       if (!filename || !*filename) {
  87.          return FALSE;
  88.       }
  89.    }
  90.  
  91.    /* XXX: Make that working in release builds.
  92.     */
  93. //   debug_dump_surface_bmp(pipe, filename, surface);
  94.    return TRUE;
  95. }
  96.