graw_dl.h 4.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#ifndef GALLIUM_RAW_DL_H
#define GALLIUM_RAW_DL_H

/* This is an API for exercising gallium functionality in a
 * platform-neutral fashion.  Whatever platform integration is
 * necessary to implement this interface is orchestrated by the
 * individual target building this entity.
 *
 * For instance, the graw-xlib target includes code to implent these
 * interfaces on top of the X window system.
 *
 * Programs using this interface may additionally benefit from some of
 * the utilities currently in the libgallium.a library, especially
 * those for parsing text representations of TGSI shaders.
 */

17
#include  <stdio.h>
18 19
#include "pipe/p_compiler.h"
#include "pipe/p_context.h"
20 21
#include "pipe/p_format.h"
#include "pipe/p_state.h"
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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
#include "util/u_dl.h"
#include "tgsi/tgsi_text.h"


struct pipe_screen;
struct pipe_context;


typedef void *
(*pfn_graw_create_window_and_screen_t)( int x,
                                        int y,
                                        unsigned width,
                                        unsigned height,
                                        enum pipe_format format,
			                void **handle );

typedef void
(*pfn_graw_set_display_func_t)( void (*func)( void ) );

typedef void
(*pfn_graw_main_loop_t)( void );


static pfn_graw_create_window_and_screen_t
pfn_graw_create_window_and_screen = NULL;

static pfn_graw_set_display_func_t
pfn_graw_set_display_func = NULL;

static pfn_graw_main_loop_t
pfn_graw_main_loop = NULL;


static INLINE void *
graw_create_window_and_screen( int x,
                               int y,
                               unsigned width,
                               unsigned height,
                               enum pipe_format format,
                               void **handle )
{
   static struct util_dl_library *lib;
   lib = util_dl_open(UTIL_DL_PREFIX "graw" UTIL_DL_EXT);
   if (!lib)
      goto error;
   pfn_graw_create_window_and_screen = (pfn_graw_create_window_and_screen_t)
      util_dl_get_proc_address(lib, "graw_create_window_and_screen");
   if (!pfn_graw_create_window_and_screen)
      goto error;
   pfn_graw_set_display_func = (pfn_graw_set_display_func_t)
      util_dl_get_proc_address(lib, "graw_set_display_func");
   if (!pfn_graw_set_display_func)
      goto error;
   pfn_graw_main_loop = (pfn_graw_main_loop_t)
      util_dl_get_proc_address(lib, "graw_main_loop");
   if (!pfn_graw_main_loop)
      goto error;
   return pfn_graw_create_window_and_screen(x, y, width, height, format, handle );
error:
   fprintf(stderr, "failed to open " UTIL_DL_PREFIX "graw" UTIL_DL_EXT "\n");
   return NULL;
}

static INLINE void 
graw_set_display_func( void (*func)( void ) )
{
   if (!pfn_graw_set_display_func)
      return;
   pfn_graw_set_display_func(func);
}

static INLINE void 
graw_main_loop( void )
{
   if (!pfn_graw_main_loop)
      return;
   pfn_graw_main_loop();
}


/* 
 * Helper functions.  These are the same for all graw implementations.
 *
 * XXX: These aren't graw related. If they are useful then should go somwhere
 * inside auxiliary/util.
 */

#define GRAW_MAX_NUM_TOKENS 1024

static INLINE void *
graw_parse_geometry_shader(struct pipe_context *pipe,
                           const char *text)
{
   struct tgsi_token tokens[GRAW_MAX_NUM_TOKENS];
   struct pipe_shader_state state;

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

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

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

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

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

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

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

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

#endif