p_context.h revision 4528287e040415c2071012d02f20979ff995c754
1/**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28#ifndef PIPE_CONTEXT_H
29#define PIPE_CONTEXT_H
30
31#include "p_state.h"
32
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38
39struct pipe_screen;
40
41struct pipe_state_cache;
42
43/* Opaque driver handles:
44 */
45struct pipe_query;
46
47/**
48 * Gallium rendering context.  Basically:
49 *  - state setting functions
50 *  - VBO drawing functions
51 *  - surface functions
52 *  - device queries
53 */
54struct pipe_context {
55   struct pipe_winsys *winsys;
56   struct pipe_screen *screen;
57
58   void *priv;  /** context private data (for DRI for example) */
59   void *draw;  /** private, for draw module (temporary? */
60
61   void (*destroy)( struct pipe_context * );
62
63   /*
64    * Drawing.
65    * Return false on fallbacks (temporary??)
66    */
67   boolean (*draw_arrays)( struct pipe_context *pipe,
68			   unsigned mode, unsigned start, unsigned count);
69
70   boolean (*draw_elements)( struct pipe_context *pipe,
71			     struct pipe_buffer *indexBuffer,
72			     unsigned indexSize,
73			     unsigned mode, unsigned start, unsigned count);
74
75
76   /**
77    * Query objects
78    */
79   struct pipe_query *(*create_query)( struct pipe_context *pipe,
80                                              unsigned query_type );
81
82   void (*destroy_query)(struct pipe_context *pipe,
83                         struct pipe_query *q);
84
85   void (*begin_query)(struct pipe_context *pipe, struct pipe_query *q);
86   void (*end_query)(struct pipe_context *pipe, struct pipe_query *q);
87
88   boolean (*get_query_result)(struct pipe_context *pipe,
89                               struct pipe_query *q,
90                               boolean wait,
91                               uint64 *result);
92
93   /*
94    * State functions
95    */
96   void * (*create_blend_state)(struct pipe_context *,
97                                const struct pipe_blend_state *);
98   void   (*bind_blend_state)(struct pipe_context *, void *);
99   void   (*delete_blend_state)(struct pipe_context *, void  *);
100
101   void * (*create_sampler_state)(struct pipe_context *,
102                                  const struct pipe_sampler_state *);
103   void   (*bind_sampler_states)(struct pipe_context *, unsigned num, void **);
104   void   (*delete_sampler_state)(struct pipe_context *, void *);
105
106   void * (*create_rasterizer_state)(struct pipe_context *,
107                                     const struct pipe_rasterizer_state *);
108   void   (*bind_rasterizer_state)(struct pipe_context *, void *);
109   void   (*delete_rasterizer_state)(struct pipe_context *, void *);
110
111   void * (*create_depth_stencil_alpha_state)(struct pipe_context *,
112                                        const struct pipe_depth_stencil_alpha_state *);
113   void   (*bind_depth_stencil_alpha_state)(struct pipe_context *, void *);
114   void   (*delete_depth_stencil_alpha_state)(struct pipe_context *, void *);
115
116   void * (*create_fs_state)(struct pipe_context *,
117                             const struct pipe_shader_state *);
118   void   (*bind_fs_state)(struct pipe_context *, void *);
119   void   (*delete_fs_state)(struct pipe_context *, void *);
120
121   void * (*create_vs_state)(struct pipe_context *,
122                             const struct pipe_shader_state *);
123   void   (*bind_vs_state)(struct pipe_context *, void *);
124   void   (*delete_vs_state)(struct pipe_context *, void *);
125
126   /* The following look more properties than states.
127    * maybe combine a few of them into states or pass them
128    * in the bind calls to the state */
129   void (*set_blend_color)( struct pipe_context *,
130                            const struct pipe_blend_color * );
131
132   void (*set_clip_state)( struct pipe_context *,
133			   const struct pipe_clip_state * );
134
135   void (*set_constant_buffer)( struct pipe_context *,
136                                uint shader, uint index,
137                                const struct pipe_constant_buffer *buf );
138
139   void (*set_framebuffer_state)( struct pipe_context *,
140                                  const struct pipe_framebuffer_state * );
141
142   void (*set_polygon_stipple)( struct pipe_context *,
143				const struct pipe_poly_stipple * );
144
145   void (*set_scissor_state)( struct pipe_context *,
146                              const struct pipe_scissor_state * );
147
148
149   /* Currently a sampler is constrained to sample from a single texture:
150    */
151   void (*set_sampler_textures)( struct pipe_context *,
152                                 unsigned num,
153                                 struct pipe_texture ** );
154
155   void (*set_viewport_state)( struct pipe_context *,
156                               const struct pipe_viewport_state * );
157
158   /*
159    * Vertex arrays
160    */
161   void (*set_vertex_buffer)( struct pipe_context *,
162                              unsigned index,
163                              const struct pipe_vertex_buffer * );
164
165   void (*set_vertex_element)( struct pipe_context *,
166			       unsigned index,
167			       const struct pipe_vertex_element * );
168
169
170   /*
171    * Surface functions
172    */
173
174   void (*surface_copy)(struct pipe_context *pipe,
175                        unsigned do_flip,	/*<< flip surface contents vertically */
176			struct pipe_surface *dest,
177			unsigned destx, unsigned desty,
178			struct pipe_surface *src, /* don't make this const -
179						     need to map/unmap */
180			unsigned srcx, unsigned srcy,
181			unsigned width, unsigned height);
182
183   void (*surface_fill)(struct pipe_context *pipe,
184			struct pipe_surface *dst,
185			unsigned dstx, unsigned dsty,
186			unsigned width, unsigned height,
187			unsigned value);
188
189   void (*clear)(struct pipe_context *pipe,
190		 struct pipe_surface *ps,
191		 unsigned clearValue);
192
193   /**
194    * Called when texture data is changed.
195    * Note: we could pass some hints about which mip levels or cube faces
196    * have changed...
197    * XXX this may go away - could pass a 'write' flag to get_tex_surface()
198    */
199   void (*texture_update)(struct pipe_context *pipe,
200                          struct pipe_texture *texture);
201
202
203
204   /* Flush rendering:
205    */
206   void (*flush)( struct pipe_context *pipe,
207		  unsigned flags );
208};
209
210
211#ifdef __cplusplus
212}
213#endif
214
215#endif /* PIPE_CONTEXT_H */
216