st_context.h revision 2b151bbb957284e7a1a272c1b5ec6c9307e6e623
1/************************************************************************** 2 * 3 * Copyright 2003 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 ST_CONTEXT_H 29#define ST_CONTEXT_H 30 31#include "main/mtypes.h" 32#include "pipe/p_state.h" 33#include "state_tracker/st_api.h" 34 35struct bitmap_cache; 36struct blit_state; 37struct dd_function_table; 38struct draw_context; 39struct draw_stage; 40struct gen_mipmap_state; 41struct st_context; 42struct st_fragment_program; 43struct u_upload_mgr; 44 45 46#define ST_NEW_MESA 0x1 /* Mesa state has changed */ 47#define ST_NEW_FRAGMENT_PROGRAM 0x2 48#define ST_NEW_VERTEX_PROGRAM 0x4 49#define ST_NEW_FRAMEBUFFER 0x8 50#define ST_NEW_EDGEFLAGS_DATA 0x10 51#define ST_NEW_GEOMETRY_PROGRAM 0x20 52 53 54struct st_state_flags { 55 GLuint mesa; 56 GLuint st; 57}; 58 59struct st_tracked_state { 60 const char *name; 61 struct st_state_flags dirty; 62 void (*update)( struct st_context *st ); 63}; 64 65 66 67struct st_context 68{ 69 struct st_context_iface iface; 70 71 struct gl_context *ctx; 72 73 struct pipe_context *pipe; 74 75 struct u_upload_mgr *uploader; 76 struct draw_context *draw; /**< For selection/feedback/rastpos only */ 77 struct draw_stage *feedback_stage; /**< For GL_FEEDBACK rendermode */ 78 struct draw_stage *selection_stage; /**< For GL_SELECT rendermode */ 79 struct draw_stage *rastpos_stage; /**< For glRasterPos */ 80 GLboolean sw_primitive_restart; 81 GLboolean clamp_frag_color_in_shader; 82 GLboolean clamp_vert_color_in_shader; 83 84 85 /* On old libGL's for linux we need to invalidate the drawables 86 * on glViewpport calls, this is set via a option. 87 */ 88 boolean invalidate_on_gl_viewport; 89 90 /* Some state is contained in constant objects. 91 * Other state is just parameter values. 92 */ 93 struct { 94 struct pipe_blend_state blend; 95 struct pipe_depth_stencil_alpha_state depth_stencil; 96 struct pipe_rasterizer_state rasterizer; 97 struct pipe_sampler_state samplers[PIPE_MAX_SAMPLERS]; 98 struct pipe_sampler_state vertex_samplers[PIPE_MAX_VERTEX_SAMPLERS]; 99 struct pipe_clip_state clip; 100 struct { 101 void *ptr; 102 unsigned size; 103 } constants[PIPE_SHADER_TYPES]; 104 struct pipe_framebuffer_state framebuffer; 105 struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; 106 struct pipe_sampler_view *sampler_vertex_views[PIPE_MAX_VERTEX_SAMPLERS]; 107 struct pipe_scissor_state scissor; 108 struct pipe_viewport_state viewport; 109 unsigned sample_mask; 110 111 GLuint num_samplers; 112 GLuint num_vertex_samplers; 113 GLuint num_textures; 114 GLuint num_vertex_textures; 115 116 GLuint poly_stipple[32]; /**< In OpenGL's bottom-to-top order */ 117 } state; 118 119 char vendor[100]; 120 char renderer[100]; 121 122 struct st_state_flags dirty; 123 124 GLboolean missing_textures; 125 GLboolean vertdata_edgeflags; 126 127 /** Mapping from VERT_RESULT_x to post-transformed vertex slot */ 128 const GLuint *vertex_result_to_slot; 129 130 struct st_vertex_program *vp; /**< Currently bound vertex program */ 131 struct st_fragment_program *fp; /**< Currently bound fragment program */ 132 struct st_geometry_program *gp; /**< Currently bound geometry program */ 133 134 struct st_vp_variant *vp_variant; 135 struct st_fp_variant *fp_variant; 136 struct st_gp_variant *gp_variant; 137 138 struct gl_texture_object *default_texture; 139 140 struct { 141 struct gl_program_cache *cache; 142 struct st_fragment_program *program; /**< cur pixel transfer prog */ 143 GLuint xfer_prog_sn; /**< pixel xfer program serial no. */ 144 GLuint user_prog_sn; /**< user fragment program serial no. */ 145 struct st_fragment_program *combined_prog; 146 GLuint combined_prog_sn; 147 struct pipe_resource *pixelmap_texture; 148 struct pipe_sampler_view *pixelmap_sampler_view; 149 boolean pixelmap_enabled; /**< use the pixelmap texture? */ 150 } pixel_xfer; 151 152 /** for glBitmap */ 153 struct { 154 struct pipe_rasterizer_state rasterizer; 155 struct pipe_sampler_state samplers[2]; 156 enum pipe_format tex_format; 157 void *vs; 158 struct bitmap_cache *cache; 159 } bitmap; 160 161 /** for glDraw/CopyPixels */ 162 struct { 163 struct gl_fragment_program *shaders[4]; 164 void *vert_shaders[2]; /**< ureg shaders */ 165 } drawpix; 166 167 /** for glClear */ 168 struct { 169 struct pipe_rasterizer_state raster; 170 struct pipe_viewport_state viewport; 171 void *vs; 172 void *fs; 173 float vertices[4][2][4]; /**< vertex pos + color */ 174 boolean enable_ds_separate; 175 } clear; 176 177 /** used for anything using util_draw_vertex_buffer */ 178 struct pipe_vertex_element velems_util_draw[3]; 179 180 void *passthrough_fs; /**< simple pass-through frag shader */ 181 182 enum pipe_texture_target internal_target; 183 struct gen_mipmap_state *gen_mipmap; 184 struct blit_state *blit; 185 186 struct cso_context *cso_context; 187 188 int force_msaa; 189 void *winsys_drawable_handle; 190 191 /* User vertex buffers. */ 192 struct { 193 struct pipe_resource *buffer; 194 195 /** Element size */ 196 GLuint element_size; 197 198 /** Attribute stride */ 199 GLsizei stride; 200 } user_attrib[PIPE_MAX_ATTRIBS]; 201 unsigned num_user_attribs; 202 203 /* Active render condition. */ 204 struct pipe_query *render_condition; 205 unsigned condition_mode; 206 207 int32_t draw_stamp; 208 int32_t read_stamp; 209}; 210 211 212/* Need this so that we can implement Mesa callbacks in this module. 213 */ 214static INLINE struct st_context *st_context(struct gl_context *ctx) 215{ 216 return ctx->st; 217} 218 219 220/** 221 * Wrapper for struct gl_framebuffer. 222 * This is an opaque type to the outside world. 223 */ 224struct st_framebuffer 225{ 226 struct gl_framebuffer Base; 227 void *Private; 228 229 struct st_framebuffer_iface *iface; 230 enum st_attachment_type statts[ST_ATTACHMENT_COUNT]; 231 unsigned num_statts; 232 int32_t stamp; 233 int32_t iface_stamp; 234}; 235 236 237extern void st_init_driver_functions(struct dd_function_table *functions); 238 239void st_invalidate_state(struct gl_context * ctx, GLuint new_state); 240 241 242 243#define Y_0_TOP 1 244#define Y_0_BOTTOM 2 245 246static INLINE GLuint 247st_fb_orientation(const struct gl_framebuffer *fb) 248{ 249 if (fb && fb->Name == 0) { 250 /* Drawing into a window (on-screen buffer). 251 * 252 * Negate Y scale to flip image vertically. 253 * The NDC Y coords prior to viewport transformation are in the range 254 * [y=-1=bottom, y=1=top] 255 * Hardware window coords are in the range [y=0=top, y=H-1=bottom] where 256 * H is the window height. 257 * Use the viewport transformation to invert Y. 258 */ 259 return Y_0_TOP; 260 } 261 else { 262 /* Drawing into user-created FBO (very likely a texture). 263 * 264 * For textures, T=0=Bottom, so by extension Y=0=Bottom for rendering. 265 */ 266 return Y_0_BOTTOM; 267 } 268} 269 270 271/** clear-alloc a struct-sized object, with casting */ 272#define ST_CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T)) 273 274 275extern int 276st_get_msaa(void); 277 278extern struct st_context * 279st_create_context(gl_api api, struct pipe_context *pipe, 280 const struct gl_config *visual, 281 struct st_context *share); 282 283extern void 284st_destroy_context(struct st_context *st); 285 286 287#endif 288