summaryrefslogtreecommitdiffstats
path: root/src/gallium/targets/graw-null/graw_util.c
blob: e5cf526d33a02b49ea5823a4c265e8b1df5c1cad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

#include "pipe/p_compiler.h"
#include "pipe/p_context.h"
#include "pipe/p_state.h"
#include "tgsi/tgsi_text.h"
#include "util/u_debug.h"
#include "util/u_memory.h"
#include "state_tracker/graw.h"


/* Helper functions.  These are the same for all graw implementations.
 */
PUBLIC void *
graw_parse_geometry_shader(struct pipe_context *pipe,
                           const char *text)
{
   struct tgsi_token tokens[1024];
   struct pipe_shader_state state;

   if (!tgsi_text_translate(text, tokens, Elements(tokens)))
      return NULL;

   state.tokens = tokens;
   return pipe->create_gs_state(pipe, &state);
}

PUBLIC void *
graw_parse_vertex_shader(struct pipe_context *pipe,
                         const char *text)
{
   struct tgsi_token tokens[1024];
   struct pipe_shader_state state;

   if (!tgsi_text_translate(text, tokens, Elements(tokens)))
      return NULL;

   state.tokens = tokens;
   return pipe->create_vs_state(pipe, &state);
}

PUBLIC void *
graw_parse_fragment_shader(struct pipe_context *pipe,
                           const char *text)
{
   struct tgsi_token tokens[1024];
   struct pipe_shader_state state;

   if (!tgsi_text_translate(text, tokens, Elements(tokens)))
      return NULL;

   state.tokens = tokens;
   return pipe->create_fs_state(pipe, &state);
}

static char out_filename[256] = "";

PUBLIC boolean
graw_parse_args(int *argi,
                int argc,
                char *argv[])
{
   if (strcmp(argv[*argi], "-o") == 0) {
      if (*argi + 1 >= argc) {
         return FALSE;
      }

      strncpy(out_filename, argv[*argi + 1], sizeof(out_filename) - 1);
      out_filename[sizeof(out_filename) - 1] = '\0';
      *argi += 2;
      return TRUE;
   }

   return FALSE;
}

PUBLIC boolean
graw_save_surface_to_file(struct pipe_context *pipe,
                          struct pipe_surface *surface,
                          const char *filename)
{
   if (!filename || !*filename) {
      filename = out_filename;
      if (!filename || !*filename) {
         return FALSE;
      }
   }

   /* XXX: Make that working in release builds.
    */
   debug_dump_surface_bmp(pipe, filename, surface);
   return TRUE;
}