1 #ifndef GALLIUM_RAW_DL_H
2 #define GALLIUM_RAW_DL_H
4 /* This is an API for exercising gallium functionality in a
5 * platform-neutral fashion. Whatever platform integration is
6 * necessary to implement this interface is orchestrated by the
7 * individual target building this entity.
9 * For instance, the graw-xlib target includes code to implent these
10 * interfaces on top of the X window system.
12 * Programs using this interface may additionally benefit from some of
13 * the utilities currently in the libgallium.a library, especially
14 * those for parsing text representations of TGSI shaders.
18 #include "pipe/p_compiler.h"
19 #include "pipe/p_context.h"
20 #include "pipe/p_format.h"
21 #include "pipe/p_state.h"
22 #include "util/u_dl.h"
23 #include "tgsi/tgsi_text.h"
31 (*pfn_graw_create_window_and_screen_t
)( int x
,
35 enum pipe_format format
,
39 (*pfn_graw_set_display_func_t
)( void (*func
)( void ) );
42 (*pfn_graw_main_loop_t
)( void );
45 static pfn_graw_create_window_and_screen_t
46 pfn_graw_create_window_and_screen
= NULL
;
48 static pfn_graw_set_display_func_t
49 pfn_graw_set_display_func
= NULL
;
51 static pfn_graw_main_loop_t
52 pfn_graw_main_loop
= NULL
;
56 graw_create_window_and_screen( int x
,
60 enum pipe_format format
,
63 static struct util_dl_library
*lib
;
64 lib
= util_dl_open(UTIL_DL_PREFIX
"graw" UTIL_DL_EXT
);
67 pfn_graw_create_window_and_screen
= (pfn_graw_create_window_and_screen_t
)
68 util_dl_get_proc_address(lib
, "graw_create_window_and_screen");
69 if (!pfn_graw_create_window_and_screen
)
71 pfn_graw_set_display_func
= (pfn_graw_set_display_func_t
)
72 util_dl_get_proc_address(lib
, "graw_set_display_func");
73 if (!pfn_graw_set_display_func
)
75 pfn_graw_main_loop
= (pfn_graw_main_loop_t
)
76 util_dl_get_proc_address(lib
, "graw_main_loop");
77 if (!pfn_graw_main_loop
)
79 return pfn_graw_create_window_and_screen(x
, y
, width
, height
, format
, handle
);
81 fprintf(stderr
, "failed to open " UTIL_DL_PREFIX
"graw" UTIL_DL_EXT
"\n");
86 graw_set_display_func( void (*func
)( void ) )
88 if (!pfn_graw_set_display_func
)
90 pfn_graw_set_display_func(func
);
94 graw_main_loop( void )
96 if (!pfn_graw_main_loop
)
103 * Helper functions. These are the same for all graw implementations.
105 * XXX: These aren't graw related. If they are useful then should go somwhere
106 * inside auxiliary/util.
109 #define GRAW_MAX_NUM_TOKENS 1024
112 graw_parse_geometry_shader(struct pipe_context
*pipe
,
115 struct tgsi_token tokens
[GRAW_MAX_NUM_TOKENS
];
116 struct pipe_shader_state state
;
118 if (!tgsi_text_translate(text
, tokens
, GRAW_MAX_NUM_TOKENS
))
121 state
.tokens
= tokens
;
122 return pipe
->create_gs_state(pipe
, &state
);
126 graw_parse_vertex_shader(struct pipe_context
*pipe
,
129 struct tgsi_token tokens
[GRAW_MAX_NUM_TOKENS
];
130 struct pipe_shader_state state
;
132 if (!tgsi_text_translate(text
, tokens
, GRAW_MAX_NUM_TOKENS
))
135 state
.tokens
= tokens
;
136 return pipe
->create_vs_state(pipe
, &state
);
140 graw_parse_fragment_shader(struct pipe_context
*pipe
,
143 struct tgsi_token tokens
[GRAW_MAX_NUM_TOKENS
];
144 struct pipe_shader_state state
;
146 if (!tgsi_text_translate(text
, tokens
, GRAW_MAX_NUM_TOKENS
))
149 state
.tokens
= tokens
;
150 return pipe
->create_fs_state(pipe
, &state
);