st/mesa: Fix glEGLImageTargetTexture2DOES.
[mesa.git] / src / gallium / include / state_tracker / graw_dl.h
1 #ifndef GALLIUM_RAW_DL_H
2 #define GALLIUM_RAW_DL_H
3
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.
8 *
9 * For instance, the graw-xlib target includes code to implent these
10 * interfaces on top of the X window system.
11 *
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.
15 */
16
17 #include <stdio.h>
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"
24
25
26 struct pipe_screen;
27 struct pipe_context;
28
29
30 typedef void *
31 (*pfn_graw_create_window_and_screen_t)( int x,
32 int y,
33 unsigned width,
34 unsigned height,
35 enum pipe_format format,
36 void **handle );
37
38 typedef void
39 (*pfn_graw_set_display_func_t)( void (*func)( void ) );
40
41 typedef void
42 (*pfn_graw_main_loop_t)( void );
43
44
45 static pfn_graw_create_window_and_screen_t
46 pfn_graw_create_window_and_screen = NULL;
47
48 static pfn_graw_set_display_func_t
49 pfn_graw_set_display_func = NULL;
50
51 static pfn_graw_main_loop_t
52 pfn_graw_main_loop = NULL;
53
54
55 static INLINE void *
56 graw_create_window_and_screen( int x,
57 int y,
58 unsigned width,
59 unsigned height,
60 enum pipe_format format,
61 void **handle )
62 {
63 static struct util_dl_library *lib;
64 lib = util_dl_open(UTIL_DL_PREFIX "graw" UTIL_DL_EXT);
65 if (!lib)
66 goto error;
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)
70 goto error;
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)
74 goto error;
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)
78 goto error;
79 return pfn_graw_create_window_and_screen(x, y, width, height, format, handle );
80 error:
81 fprintf(stderr, "failed to open " UTIL_DL_PREFIX "graw" UTIL_DL_EXT "\n");
82 return NULL;
83 }
84
85 static INLINE void
86 graw_set_display_func( void (*func)( void ) )
87 {
88 if (!pfn_graw_set_display_func)
89 return;
90 pfn_graw_set_display_func(func);
91 }
92
93 static INLINE void
94 graw_main_loop( void )
95 {
96 if (!pfn_graw_main_loop)
97 return;
98 pfn_graw_main_loop();
99 }
100
101
102 /*
103 * Helper functions. These are the same for all graw implementations.
104 *
105 * XXX: These aren't graw related. If they are useful then should go somwhere
106 * inside auxiliary/util.
107 */
108
109 #define GRAW_MAX_NUM_TOKENS 1024
110
111 static INLINE void *
112 graw_parse_geometry_shader(struct pipe_context *pipe,
113 const char *text)
114 {
115 struct tgsi_token tokens[GRAW_MAX_NUM_TOKENS];
116 struct pipe_shader_state state;
117
118 if (!tgsi_text_translate(text, tokens, GRAW_MAX_NUM_TOKENS))
119 return NULL;
120
121 state.tokens = tokens;
122 return pipe->create_gs_state(pipe, &state);
123 }
124
125 static INLINE void *
126 graw_parse_vertex_shader(struct pipe_context *pipe,
127 const char *text)
128 {
129 struct tgsi_token tokens[GRAW_MAX_NUM_TOKENS];
130 struct pipe_shader_state state;
131
132 if (!tgsi_text_translate(text, tokens, GRAW_MAX_NUM_TOKENS))
133 return NULL;
134
135 state.tokens = tokens;
136 return pipe->create_vs_state(pipe, &state);
137 }
138
139 static INLINE void *
140 graw_parse_fragment_shader(struct pipe_context *pipe,
141 const char *text)
142 {
143 struct tgsi_token tokens[GRAW_MAX_NUM_TOKENS];
144 struct pipe_shader_state state;
145
146 if (!tgsi_text_translate(text, tokens, GRAW_MAX_NUM_TOKENS))
147 return NULL;
148
149 state.tokens = tokens;
150 return pipe->create_fs_state(pipe, &state);
151 }
152
153 #endif