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 "state_tracker/st_api.h"
33 #include "main/fbobject.h"
34 #include "state_tracker/st_atom.h"
35 #include "util/u_inlines.h"
36 #include "util/list.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. */
62 struct st_bitmap_cache
64 /** Window pos to render the cached image */
66 /** Bounds of region used in window coords */
67 GLint xmin
, ymin
, xmax
, ymax
;
71 /** Bitmap's Z position */
74 struct pipe_resource
*texture
;
75 struct pipe_transfer
*trans
;
79 /** An I8 texture image: */
83 struct st_bound_handles
91 struct st_context_iface iface
;
93 struct gl_context
*ctx
;
95 struct pipe_context
*pipe
;
97 struct draw_context
*draw
; /**< For selection/feedback/rastpos only */
98 struct draw_stage
*feedback_stage
; /**< For GL_FEEDBACK rendermode */
99 struct draw_stage
*selection_stage
; /**< For GL_SELECT rendermode */
100 struct draw_stage
*rastpos_stage
; /**< For glRasterPos */
101 GLboolean clamp_frag_color_in_shader
;
102 GLboolean clamp_vert_color_in_shader
;
103 boolean has_stencil_export
; /**< can do shader stencil export? */
104 boolean has_time_elapsed
;
105 boolean has_shader_model3
;
108 boolean prefer_blit_based_texture_transfer
;
109 boolean force_persample_in_shader
;
110 boolean has_shareable_shaders
;
111 boolean has_half_float_packing
;
112 boolean has_multi_draw_indirect
;
113 boolean has_user_constbuf
;
114 boolean can_bind_const_buffer_as_vertex
;
117 * If a shader can be created when we get its source.
118 * This means it has only 1 variant, not counting glBitmap and
121 boolean shader_has_one_variant
[MESA_SHADER_STAGES
];
123 boolean needs_texcoord_semantic
;
124 boolean apply_texture_swizzle_to_border_color
;
126 /* On old libGL's for linux we need to invalidate the drawables
127 * on glViewpport calls, this is set via a option.
129 boolean invalidate_on_gl_viewport
;
130 boolean draw_needs_minmax_index
;
131 boolean vertex_array_out_of_memory
;
133 /* Some state is contained in constant objects.
134 * Other state is just parameter values.
137 struct pipe_blend_state blend
;
138 struct pipe_depth_stencil_alpha_state depth_stencil
;
139 struct pipe_rasterizer_state rasterizer
;
140 struct pipe_sampler_state samplers
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
141 GLuint num_samplers
[PIPE_SHADER_TYPES
];
142 struct pipe_sampler_view
*sampler_views
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
143 GLuint num_sampler_views
[PIPE_SHADER_TYPES
];
144 struct pipe_clip_state clip
;
148 } constants
[PIPE_SHADER_TYPES
];
151 unsigned fb_num_samples
;
152 unsigned fb_num_layers
;
153 unsigned num_viewports
;
154 struct pipe_scissor_state scissor
[PIPE_MAX_VIEWPORTS
];
155 struct pipe_viewport_state viewport
[PIPE_MAX_VIEWPORTS
];
159 struct pipe_scissor_state rects
[PIPE_MAX_WINDOW_RECTANGLES
];
162 GLuint poly_stipple
[32]; /**< In OpenGL's bottom-to-top order */
164 GLuint fb_orientation
;
167 uint64_t dirty
; /**< dirty states */
169 /** This masks out unused shader resources. Only valid in draw calls. */
170 uint64_t active_states
;
172 /* If true, further analysis of states is required to know if something
173 * has changed. Used mainly for shaders.
175 bool gfx_shaders_may_be_dirty
;
176 bool compute_shader_may_be_dirty
;
178 GLboolean vertdata_edgeflags
;
179 GLboolean edgeflag_culls_prims
;
181 struct st_vertex_program
*vp
; /**< Currently bound vertex program */
182 struct st_fragment_program
*fp
; /**< Currently bound fragment program */
183 struct st_common_program
*gp
; /**< Currently bound geometry program */
184 struct st_common_program
*tcp
; /**< Currently bound tess control program */
185 struct st_common_program
*tep
; /**< Currently bound tess eval program */
186 struct st_compute_program
*cp
; /**< Currently bound compute program */
188 struct st_vp_variant
*vp_variant
;
191 struct pipe_resource
*pixelmap_texture
;
192 struct pipe_sampler_view
*pixelmap_sampler_view
;
197 struct pipe_rasterizer_state rasterizer
;
198 struct pipe_sampler_state sampler
;
199 struct pipe_sampler_state atlas_sampler
;
200 enum pipe_format tex_format
;
202 struct st_bitmap_cache cache
;
205 /** for glDraw/CopyPixels */
208 void *vert_shaders
[2]; /**< ureg shaders */
212 GLsizei width
, height
;
214 const void *user_pointer
; /**< Last user 'pixels' pointer */
215 void *image
; /**< Copy of the glDrawPixels image data */
216 struct pipe_resource
*texture
;
219 /** for glReadPixels */
221 struct pipe_resource
*src
;
222 struct pipe_resource
*cache
;
223 enum pipe_format dst_format
;
231 struct pipe_rasterizer_state raster
;
232 struct pipe_viewport_state viewport
;
239 /* For gl(Compressed)Tex(Sub)Image */
241 struct pipe_rasterizer_state raster
;
242 struct pipe_blend_state upload_blend
;
246 void *download_fs
[3][PIPE_MAX_TEXTURE_TYPES
];
248 bool download_enabled
;
254 /** for drawing with st_util_vertex */
255 struct pipe_vertex_element util_velems
[3];
257 void *passthrough_fs
; /**< simple pass-through frag shader */
259 enum pipe_texture_target internal_target
;
261 struct cso_context
*cso_context
;
263 void *winsys_drawable_handle
;
265 /* The number of vertex buffers from the last call of validate_arrays. */
266 unsigned last_num_vbuffers
;
271 struct st_config_options options
;
273 struct st_perf_monitor_group
*perfmon
;
275 enum pipe_reset_status reset_status
;
277 /* Array of bound texture/image handles which are resident in the context.
279 struct st_bound_handles bound_texture_handles
[PIPE_SHADER_TYPES
];
280 struct st_bound_handles bound_image_handles
[PIPE_SHADER_TYPES
];
283 struct list_head winsys_buffers
;
287 /* Need this so that we can implement Mesa callbacks in this module.
289 static inline struct st_context
*st_context(struct gl_context
*ctx
)
296 * Wrapper for struct gl_framebuffer.
297 * This is an opaque type to the outside world.
299 struct st_framebuffer
301 struct gl_framebuffer Base
;
303 struct st_framebuffer_iface
*iface
;
304 enum st_attachment_type statts
[ST_ATTACHMENT_COUNT
];
310 /* list of framebuffer objects */
311 struct list_head head
;
315 extern void st_init_driver_functions(struct pipe_screen
*screen
,
316 struct dd_function_table
*functions
);
319 st_invalidate_buffers(struct st_context
*st
);
321 /* Invalidate the readpixels cache to ensure we don't read stale data.
324 st_invalidate_readpix_cache(struct st_context
*st
)
326 if (unlikely(st
->readpix_cache
.src
)) {
327 pipe_resource_reference(&st
->readpix_cache
.src
, NULL
);
328 pipe_resource_reference(&st
->readpix_cache
.cache
, NULL
);
337 st_fb_orientation(const struct gl_framebuffer
*fb
)
339 if (fb
&& _mesa_is_winsys_fbo(fb
)) {
340 /* Drawing into a window (on-screen buffer).
342 * Negate Y scale to flip image vertically.
343 * The NDC Y coords prior to viewport transformation are in the range
344 * [y=-1=bottom, y=1=top]
345 * Hardware window coords are in the range [y=0=top, y=H-1=bottom] where
346 * H is the window height.
347 * Use the viewport transformation to invert Y.
352 /* Drawing into user-created FBO (very likely a texture).
354 * For textures, T=0=Bottom, so by extension Y=0=Bottom for rendering.
362 st_user_clip_planes_enabled(struct gl_context
*ctx
)
364 return (ctx
->API
== API_OPENGL_COMPAT
||
365 ctx
->API
== API_OPENGLES
) && /* only ES 1.x */
366 ctx
->Transform
.ClipPlanesEnabled
;
369 /** clear-alloc a struct-sized object, with casting */
370 #define ST_CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T))
373 extern struct st_context
*
374 st_create_context(gl_api api
, struct pipe_context
*pipe
,
375 const struct gl_config
*visual
,
376 struct st_context
*share
,
377 const struct st_config_options
*options
,
381 st_destroy_context(struct st_context
*st
);
384 st_get_active_states(struct gl_context
*ctx
);