1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #ifndef PIPE_CONTEXT_H
29 #define PIPE_CONTEXT_H
32 #include "p_compiler.h"
34 struct pipe_state_cache
;
36 * Software pipeline rendering context. Basically a collection of
37 * state setting functions, plus VBO drawing entrypoint.
40 struct pipe_winsys
*winsys
;
42 void (*destroy
)( struct pipe_context
* );
47 const unsigned *(*supported_formats
)(struct pipe_context
*pipe
,
48 unsigned *numFormats
);
50 void (*max_texture_size
)(struct pipe_context
*pipe
,
51 unsigned textureType
, /* PIPE_TEXTURE_x */
56 const char *(*get_name
)( struct pipe_context
*pipe
);
58 const char *(*get_vendor
)( struct pipe_context
*pipe
);
60 int (*get_param
)( struct pipe_context
*pipe
, int param
);
65 * Return false on fallbacks (temporary??)
67 boolean (*draw_arrays
)( struct pipe_context
*pipe
,
68 unsigned mode
, unsigned start
, unsigned count
);
70 boolean (*draw_elements
)( struct pipe_context
*pipe
,
71 struct pipe_buffer_handle
*indexBuffer
,
73 unsigned mode
, unsigned start
, unsigned count
);
75 /** Clear a surface to given value (no scissor; clear whole surface) */
76 void (*clear
)(struct pipe_context
*pipe
, struct pipe_surface
*ps
,
82 void (*begin_query
)(struct pipe_context
*pipe
, struct pipe_query_object
*q
);
83 void (*end_query
)(struct pipe_context
*pipe
, struct pipe_query_object
*q
);
84 void (*wait_query
)(struct pipe_context
*pipe
, struct pipe_query_object
*q
);
89 void * (*create_blend_state
)(struct pipe_context
*,
90 const struct pipe_blend_state
*);
91 void (*bind_blend_state
)(struct pipe_context
*, void *);
92 void (*delete_blend_state
)(struct pipe_context
*, void *);
94 const struct pipe_sampler_state
* (*create_sampler_state
)(
95 struct pipe_context
*,
96 const struct pipe_sampler_state
*);
97 void (*bind_sampler_state
)(struct pipe_context
*,
99 const struct pipe_sampler_state
*);
100 void (*delete_sampler_state
)(struct pipe_context
*,
101 const struct pipe_sampler_state
*);
103 void *(*create_rasterizer_state
)(struct pipe_context
*,
104 const struct pipe_rasterizer_state
*);
105 void (*bind_rasterizer_state
)(struct pipe_context
*, void *);
106 void (*delete_rasterizer_state
)(struct pipe_context
*, void *);
108 const struct pipe_depth_stencil_state
* (*create_depth_stencil_state
)(
109 struct pipe_context
*,
110 const struct pipe_depth_stencil_state
*);
111 void (*bind_depth_stencil_state
)(struct pipe_context
*,
112 const struct pipe_depth_stencil_state
*);
113 void (*delete_depth_stencil_state
)(struct pipe_context
*,
114 const struct pipe_depth_stencil_state
*);
116 const struct pipe_shader_state
* (*create_fs_state
)(
117 struct pipe_context
*,
118 const struct pipe_shader_state
*);
119 void (*bind_fs_state
)(struct pipe_context
*,
120 const struct pipe_shader_state
*);
121 void (*delete_fs_state
)(struct pipe_context
*,
122 const struct pipe_shader_state
*);
123 const struct pipe_shader_state
* (*create_vs_state
)(
124 struct pipe_context
*,
125 const struct pipe_shader_state
*);
126 void (*bind_vs_state
)(struct pipe_context
*,
127 const struct pipe_shader_state
*);
128 void (*delete_vs_state
)(struct pipe_context
*,
129 const struct pipe_shader_state
*);
131 void (*set_alpha_test_state
)( struct pipe_context
*,
132 const struct pipe_alpha_test_state
* );
134 void (*set_blend_color
)( struct pipe_context
*,
135 const struct pipe_blend_color
* );
137 void (*set_clip_state
)( struct pipe_context
*,
138 const struct pipe_clip_state
* );
140 void (*set_clear_color_state
)( struct pipe_context
*,
141 const struct pipe_clear_color_state
* );
143 void (*set_constant_buffer
)( struct pipe_context
*,
144 uint shader
, uint index
,
145 const struct pipe_constant_buffer
*buf
);
147 void (*set_feedback_state
)( struct pipe_context
*,
148 const struct pipe_feedback_state
*);
150 void (*set_framebuffer_state
)( struct pipe_context
*,
151 const struct pipe_framebuffer_state
* );
153 void (*set_polygon_stipple
)( struct pipe_context
*,
154 const struct pipe_poly_stipple
* );
156 void (*set_scissor_state
)( struct pipe_context
*,
157 const struct pipe_scissor_state
* );
159 void (*set_texture_state
)( struct pipe_context
*,
161 struct pipe_mipmap_tree
* );
163 void (*set_viewport_state
)( struct pipe_context
*,
164 const struct pipe_viewport_state
* );
169 void (*set_vertex_buffer
)( struct pipe_context
*,
171 const struct pipe_vertex_buffer
* );
173 void (*set_vertex_element
)( struct pipe_context
*,
175 const struct pipe_vertex_element
* );
180 void (*set_feedback_buffer
)(struct pipe_context
*,
182 const struct pipe_feedback_buffer
*);
186 * This might go away...
188 struct pipe_surface
*(*surface_alloc
)(struct pipe_context
*pipe
,
191 struct pipe_surface
*(*get_tex_surface
)(struct pipe_context
*pipe
,
192 struct pipe_mipmap_tree
*texture
,
193 unsigned face
, unsigned level
,
197 * Memory region functions
198 * Some of these may go away...
200 struct pipe_region
*(*region_alloc
)(struct pipe_context
*pipe
,
201 unsigned cpp
, unsigned width
, unsigned height
,
204 void (*region_release
)(struct pipe_context
*pipe
, struct pipe_region
**r
);
206 ubyte
*(*region_map
)(struct pipe_context
*pipe
, struct pipe_region
*r
);
208 void (*region_unmap
)(struct pipe_context
*pipe
, struct pipe_region
*r
);
210 void (*region_data
)(struct pipe_context
*pipe
,
211 struct pipe_region
*dest
,
212 unsigned dest_offset
,
213 unsigned destx
, unsigned desty
,
214 const void *src
, unsigned src_stride
,
215 unsigned srcx
, unsigned srcy
, unsigned width
, unsigned height
);
217 void (*region_copy
)(struct pipe_context
*pipe
,
218 struct pipe_region
*dest
,
219 unsigned dest_offset
,
220 unsigned destx
, unsigned desty
,
221 struct pipe_region
*src
, /* don't make this const -
224 unsigned srcx
, unsigned srcy
, unsigned width
, unsigned height
);
226 void (*region_fill
)(struct pipe_context
*pipe
,
227 struct pipe_region
*dst
,
229 unsigned dstx
, unsigned dsty
,
230 unsigned width
, unsigned height
,
237 boolean (*mipmap_tree_layout
)( struct pipe_context
*pipe
,
238 struct pipe_mipmap_tree
*mt
);
243 void (*flush
)( struct pipe_context
*pipe
,
249 * Set 'ptr' to point to 'region' and update reference counting.
250 * The old thing pointed to, if any, will be unreferenced first.
251 * 'region' may be NULL.
254 pipe_region_reference(struct pipe_region
**ptr
, struct pipe_region
*region
)
258 /* unreference the old thing */
259 struct pipe_region
*oldReg
= *ptr
;
261 assert(oldReg
->refcount
>= 0);
262 if (oldReg
->refcount
== 0) {
263 /* free the old region */
264 assert(oldReg
->map_refcount
== 0);
265 /* XXX dereference the region->buffer */
271 /* reference the new thing */
279 * \sa pipe_region_reference
282 pipe_surface_reference(struct pipe_surface
**ptr
, struct pipe_surface
*surf
)
286 /* unreference the old thing */
287 struct pipe_surface
*oldSurf
= *ptr
;
289 assert(oldSurf
->refcount
>= 0);
290 if (oldSurf
->refcount
== 0) {
291 /* free the old region */
292 pipe_region_reference(&oldSurf
->region
, NULL
);
298 /* reference the new thing */
305 #endif /* PIPE_CONTEXT_H */