Merge branch 'lp-offset-twoside'
[mesa.git] / src / gallium / targets / graw-null / graw_util.c
1
2 #include "pipe/p_compiler.h"
3 #include "pipe/p_context.h"
4 #include "pipe/p_state.h"
5 #include "tgsi/tgsi_text.h"
6 #include "util/u_debug.h"
7 #include "util/u_memory.h"
8 #include "state_tracker/graw.h"
9
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 state.tokens = tokens;
24 return pipe->create_gs_state(pipe, &state);
25 }
26
27 PUBLIC void *
28 graw_parse_vertex_shader(struct pipe_context *pipe,
29 const char *text)
30 {
31 struct tgsi_token tokens[1024];
32 struct pipe_shader_state state;
33
34 if (!tgsi_text_translate(text, tokens, Elements(tokens)))
35 return NULL;
36
37 state.tokens = tokens;
38 return pipe->create_vs_state(pipe, &state);
39 }
40
41 PUBLIC void *
42 graw_parse_fragment_shader(struct pipe_context *pipe,
43 const char *text)
44 {
45 struct tgsi_token tokens[1024];
46 struct pipe_shader_state state;
47
48 if (!tgsi_text_translate(text, tokens, Elements(tokens)))
49 return NULL;
50
51 state.tokens = tokens;
52 return pipe->create_fs_state(pipe, &state);
53 }
54
55 static char out_filename[256] = "";
56
57 PUBLIC boolean
58 graw_parse_args(int *argi,
59 int argc,
60 char *argv[])
61 {
62 if (strcmp(argv[*argi], "-o") == 0) {
63 if (*argi + 1 >= argc) {
64 return FALSE;
65 }
66
67 strncpy(out_filename, argv[*argi + 1], sizeof(out_filename) - 1);
68 out_filename[sizeof(out_filename) - 1] = '\0';
69 *argi += 2;
70 return TRUE;
71 }
72
73 return FALSE;
74 }
75
76 PUBLIC boolean
77 graw_save_surface_to_file(struct pipe_context *pipe,
78 struct pipe_surface *surface,
79 const char *filename)
80 {
81 if (!filename || !*filename) {
82 filename = out_filename;
83 if (!filename || !*filename) {
84 return FALSE;
85 }
86 }
87
88 /* XXX: Make that working in release builds.
89 */
90 debug_dump_surface_bmp(pipe, filename, surface);
91 return TRUE;
92 }