1 /**************************************************************************
3 * Copyright 2003 VMware, Inc.
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 VMWARE 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 **************************************************************************/
31 #include "main/mtypes.h"
32 #include "pipe/p_state.h"
33 #include "state_tracker/st_api.h"
34 #include "main/fbobject.h"
35 #include "state_tracker/st_atom.h"
44 struct dd_function_table
;
47 struct gen_mipmap_state
;
49 struct st_fragment_program
;
50 struct st_perf_monitor_group
;
54 /** For drawing quads for glClear, glDraw/CopyPixels, glBitmap, etc. */
65 struct st_context_iface iface
;
67 struct gl_context
*ctx
;
69 struct pipe_context
*pipe
;
71 struct u_upload_mgr
*uploader
, *indexbuf_uploader
, *constbuf_uploader
;
73 struct draw_context
*draw
; /**< For selection/feedback/rastpos only */
74 struct draw_stage
*feedback_stage
; /**< For GL_FEEDBACK rendermode */
75 struct draw_stage
*selection_stage
; /**< For GL_SELECT rendermode */
76 struct draw_stage
*rastpos_stage
; /**< For glRasterPos */
77 GLboolean clamp_frag_color_in_shader
;
78 GLboolean clamp_vert_color_in_shader
;
79 boolean has_stencil_export
; /**< can do shader stencil export? */
80 boolean has_time_elapsed
;
81 boolean has_shader_model3
;
84 boolean prefer_blit_based_texture_transfer
;
85 boolean force_persample_in_shader
;
86 boolean has_shareable_shaders
;
87 boolean has_half_float_packing
;
88 boolean has_multi_draw_indirect
;
91 * If a shader can be created when we get its source.
92 * This means it has only 1 variant, not counting glBitmap and
95 boolean shader_has_one_variant
[MESA_SHADER_STAGES
];
97 boolean needs_texcoord_semantic
;
98 boolean apply_texture_swizzle_to_border_color
;
100 /* On old libGL's for linux we need to invalidate the drawables
101 * on glViewpport calls, this is set via a option.
103 boolean invalidate_on_gl_viewport
;
105 boolean vertex_array_out_of_memory
;
107 /* Some state is contained in constant objects.
108 * Other state is just parameter values.
111 struct pipe_blend_state blend
;
112 struct pipe_depth_stencil_alpha_state depth_stencil
;
113 struct pipe_rasterizer_state rasterizer
;
114 struct pipe_sampler_state samplers
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
115 GLuint num_samplers
[PIPE_SHADER_TYPES
];
116 struct pipe_sampler_view
*sampler_views
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
117 GLuint num_sampler_views
[PIPE_SHADER_TYPES
];
118 struct pipe_clip_state clip
;
122 } constants
[PIPE_SHADER_TYPES
];
123 struct pipe_framebuffer_state framebuffer
;
124 struct pipe_scissor_state scissor
[PIPE_MAX_VIEWPORTS
];
125 struct pipe_viewport_state viewport
[PIPE_MAX_VIEWPORTS
];
129 struct pipe_scissor_state rects
[PIPE_MAX_WINDOW_RECTANGLES
];
131 unsigned sample_mask
;
133 GLuint poly_stipple
[32]; /**< In OpenGL's bottom-to-top order */
135 GLuint fb_orientation
;
141 uint64_t dirty
; /**< dirty states */
143 /** This masks out unused shader resources. Only valid in draw calls. */
144 uint64_t active_states
;
146 /* If true, further analysis of states is required to know if something
147 * has changed. Used mainly for shaders.
149 bool gfx_shaders_may_be_dirty
;
150 bool compute_shader_may_be_dirty
;
152 GLboolean vertdata_edgeflags
;
153 GLboolean edgeflag_culls_prims
;
155 /** Mapping from VARYING_SLOT_x to post-transformed vertex slot */
156 const GLuint
*vertex_result_to_slot
;
158 struct st_vertex_program
*vp
; /**< Currently bound vertex program */
159 struct st_fragment_program
*fp
; /**< Currently bound fragment program */
160 struct st_geometry_program
*gp
; /**< Currently bound geometry program */
161 struct st_tessctrl_program
*tcp
; /**< Currently bound tess control program */
162 struct st_tesseval_program
*tep
; /**< Currently bound tess eval program */
163 struct st_compute_program
*cp
; /**< Currently bound compute program */
165 struct st_vp_variant
*vp_variant
;
166 struct st_fp_variant
*fp_variant
;
167 struct st_basic_variant
*gp_variant
;
168 struct st_basic_variant
*tcp_variant
;
169 struct st_basic_variant
*tep_variant
;
170 struct st_basic_variant
*cp_variant
;
173 struct pipe_resource
*pixelmap_texture
;
174 struct pipe_sampler_view
*pixelmap_sampler_view
;
179 struct pipe_rasterizer_state rasterizer
;
180 struct pipe_sampler_state sampler
;
181 struct pipe_sampler_state atlas_sampler
;
182 enum pipe_format tex_format
;
184 struct bitmap_cache
*cache
;
187 /** for glDraw/CopyPixels */
190 void *vert_shaders
[2]; /**< ureg shaders */
194 GLsizei width
, height
;
196 const void *user_pointer
; /**< Last user 'pixels' pointer */
197 void *image
; /**< Copy of the glDrawPixels image data */
198 struct pipe_resource
*texture
;
201 /** for glReadPixels */
203 struct pipe_resource
*src
;
204 struct pipe_resource
*cache
;
205 enum pipe_format dst_format
;
213 struct pipe_rasterizer_state raster
;
214 struct pipe_viewport_state viewport
;
221 /* For gl(Compressed)Tex(Sub)Image */
223 struct pipe_rasterizer_state raster
;
224 struct pipe_blend_state upload_blend
;
228 void *download_fs
[PIPE_MAX_TEXTURE_TYPES
];
230 bool download_enabled
;
236 /** for drawing with st_util_vertex */
237 struct pipe_vertex_element util_velems
[3];
239 void *passthrough_fs
; /**< simple pass-through frag shader */
241 enum pipe_texture_target internal_target
;
243 struct cso_context
*cso_context
;
245 void *winsys_drawable_handle
;
247 /* The number of vertex buffers from the last call of validate_arrays. */
248 unsigned last_num_vbuffers
;
253 struct st_config_options options
;
255 struct st_perf_monitor_group
*perfmon
;
257 enum pipe_reset_status reset_status
;
261 /* Need this so that we can implement Mesa callbacks in this module.
263 static inline struct st_context
*st_context(struct gl_context
*ctx
)
270 * Wrapper for struct gl_framebuffer.
271 * This is an opaque type to the outside world.
273 struct st_framebuffer
275 struct gl_framebuffer Base
;
278 struct st_framebuffer_iface
*iface
;
279 enum st_attachment_type statts
[ST_ATTACHMENT_COUNT
];
286 extern void st_init_driver_functions(struct pipe_screen
*screen
,
287 struct dd_function_table
*functions
);
289 void st_invalidate_state(struct gl_context
* ctx
, GLbitfield new_state
);
291 void st_invalidate_readpix_cache(struct st_context
*st
);
298 st_fb_orientation(const struct gl_framebuffer
*fb
)
300 if (fb
&& _mesa_is_winsys_fbo(fb
)) {
301 /* Drawing into a window (on-screen buffer).
303 * Negate Y scale to flip image vertically.
304 * The NDC Y coords prior to viewport transformation are in the range
305 * [y=-1=bottom, y=1=top]
306 * Hardware window coords are in the range [y=0=top, y=H-1=bottom] where
307 * H is the window height.
308 * Use the viewport transformation to invert Y.
313 /* Drawing into user-created FBO (very likely a texture).
315 * For textures, T=0=Bottom, so by extension Y=0=Bottom for rendering.
322 static inline enum pipe_shader_type
323 st_shader_stage_to_ptarget(gl_shader_stage stage
)
326 case MESA_SHADER_VERTEX
:
327 return PIPE_SHADER_VERTEX
;
328 case MESA_SHADER_FRAGMENT
:
329 return PIPE_SHADER_FRAGMENT
;
330 case MESA_SHADER_GEOMETRY
:
331 return PIPE_SHADER_GEOMETRY
;
332 case MESA_SHADER_TESS_CTRL
:
333 return PIPE_SHADER_TESS_CTRL
;
334 case MESA_SHADER_TESS_EVAL
:
335 return PIPE_SHADER_TESS_EVAL
;
336 case MESA_SHADER_COMPUTE
:
337 return PIPE_SHADER_COMPUTE
;
340 assert(!"should not be reached");
341 return PIPE_SHADER_VERTEX
;
345 st_user_clip_planes_enabled(struct gl_context
*ctx
)
347 return (ctx
->API
== API_OPENGL_COMPAT
||
348 ctx
->API
== API_OPENGLES
) && /* only ES 1.x */
349 ctx
->Transform
.ClipPlanesEnabled
;
352 /** clear-alloc a struct-sized object, with casting */
353 #define ST_CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T))
356 extern struct st_context
*
357 st_create_context(gl_api api
, struct pipe_context
*pipe
,
358 const struct gl_config
*visual
,
359 struct st_context
*share
,
360 const struct st_config_options
*options
);
363 st_destroy_context(struct st_context
*st
);
366 st_get_active_states(struct gl_context
*ctx
);