meta: Add a state flag for the GL_DITHER
[mesa.git] / src / mesa / drivers / common / meta.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2009 VMware, Inc. 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 "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 #ifndef META_H
27 #define META_H
28
29 #include "main/mtypes.h"
30
31 /**
32 * \name Flags for meta operations
33 * \{
34 *
35 * These flags are passed to _mesa_meta_begin().
36 */
37 #define MESA_META_ALL ~0x0
38 #define MESA_META_ALPHA_TEST 0x1
39 #define MESA_META_BLEND 0x2 /**< includes logicop */
40 #define MESA_META_COLOR_MASK 0x4
41 #define MESA_META_DEPTH_TEST 0x8
42 #define MESA_META_FOG 0x10
43 #define MESA_META_PIXEL_STORE 0x20
44 #define MESA_META_PIXEL_TRANSFER 0x40
45 #define MESA_META_RASTERIZATION 0x80
46 #define MESA_META_SCISSOR 0x100
47 #define MESA_META_SHADER 0x200
48 #define MESA_META_STENCIL_TEST 0x400
49 #define MESA_META_TRANSFORM 0x800 /**< modelview/projection matrix state */
50 #define MESA_META_TEXTURE 0x1000
51 #define MESA_META_VERTEX 0x2000
52 #define MESA_META_VIEWPORT 0x4000
53 #define MESA_META_CLAMP_FRAGMENT_COLOR 0x8000
54 #define MESA_META_CLAMP_VERTEX_COLOR 0x10000
55 #define MESA_META_CONDITIONAL_RENDER 0x20000
56 #define MESA_META_CLIP 0x40000
57 #define MESA_META_SELECT_FEEDBACK 0x80000
58 #define MESA_META_MULTISAMPLE 0x100000
59 #define MESA_META_FRAMEBUFFER_SRGB 0x200000
60 #define MESA_META_OCCLUSION_QUERY 0x400000
61 #define MESA_META_DRAW_BUFFERS 0x800000
62 #define MESA_META_DITHER 0x1000000
63 /**\}*/
64
65 /**
66 * State which we may save/restore across meta ops.
67 * XXX this may be incomplete...
68 */
69 struct save_state
70 {
71 GLbitfield SavedState; /**< bitmask of MESA_META_* flags */
72
73 /* Always saved/restored with meta. */
74 gl_api API;
75
76 /** MESA_META_CLEAR (and others?) */
77 struct gl_query_object *CurrentOcclusionObject;
78
79 /** MESA_META_ALPHA_TEST */
80 GLboolean AlphaEnabled;
81 GLenum AlphaFunc;
82 GLclampf AlphaRef;
83
84 /** MESA_META_BLEND */
85 GLbitfield BlendEnabled;
86 GLboolean ColorLogicOpEnabled;
87
88 /** MESA_META_DITHER */
89 GLboolean DitherFlag;
90
91 /** MESA_META_COLOR_MASK */
92 GLubyte ColorMask[MAX_DRAW_BUFFERS][4];
93
94 /** MESA_META_DEPTH_TEST */
95 struct gl_depthbuffer_attrib Depth;
96
97 /** MESA_META_FOG */
98 GLboolean Fog;
99
100 /** MESA_META_PIXEL_STORE */
101 struct gl_pixelstore_attrib Pack, Unpack;
102
103 /** MESA_META_PIXEL_TRANSFER */
104 GLfloat RedBias, RedScale;
105 GLfloat GreenBias, GreenScale;
106 GLfloat BlueBias, BlueScale;
107 GLfloat AlphaBias, AlphaScale;
108 GLfloat DepthBias, DepthScale;
109 GLboolean MapColorFlag;
110
111 /** MESA_META_RASTERIZATION */
112 GLenum FrontPolygonMode, BackPolygonMode;
113 GLboolean PolygonOffset;
114 GLboolean PolygonSmooth;
115 GLboolean PolygonStipple;
116 GLboolean PolygonCull;
117
118 /** MESA_META_SCISSOR */
119 struct gl_scissor_attrib Scissor;
120
121 /** MESA_META_SHADER */
122 GLboolean VertexProgramEnabled;
123 struct gl_vertex_program *VertexProgram;
124 GLboolean FragmentProgramEnabled;
125 struct gl_fragment_program *FragmentProgram;
126 GLboolean ATIFragmentShaderEnabled;
127 struct gl_shader_program *Shader[MESA_SHADER_STAGES];
128 struct gl_shader_program *ActiveShader;
129 struct gl_pipeline_object *Pipeline;
130
131 /** MESA_META_STENCIL_TEST */
132 struct gl_stencil_attrib Stencil;
133
134 /** MESA_META_TRANSFORM */
135 GLenum MatrixMode;
136 GLfloat ModelviewMatrix[16];
137 GLfloat ProjectionMatrix[16];
138 GLfloat TextureMatrix[16];
139
140 /** MESA_META_CLIP */
141 GLbitfield ClipPlanesEnabled;
142
143 /** MESA_META_TEXTURE */
144 GLuint ActiveUnit;
145 GLuint ClientActiveUnit;
146 /** for unit[0] only */
147 struct gl_texture_object *CurrentTexture[NUM_TEXTURE_TARGETS];
148 /** mask of TEXTURE_2D_BIT, etc */
149 GLbitfield TexEnabled[MAX_TEXTURE_UNITS];
150 GLbitfield TexGenEnabled[MAX_TEXTURE_UNITS];
151 GLuint EnvMode; /* unit[0] only */
152
153 /** MESA_META_VERTEX */
154 struct gl_vertex_array_object *VAO;
155 struct gl_buffer_object *ArrayBufferObj;
156
157 /** MESA_META_VIEWPORT */
158 GLfloat ViewportX, ViewportY, ViewportW, ViewportH;
159 GLclampd DepthNear, DepthFar;
160
161 /** MESA_META_CLAMP_FRAGMENT_COLOR */
162 GLenum ClampFragmentColor;
163
164 /** MESA_META_CLAMP_VERTEX_COLOR */
165 GLenum ClampVertexColor;
166
167 /** MESA_META_CONDITIONAL_RENDER */
168 struct gl_query_object *CondRenderQuery;
169 GLenum CondRenderMode;
170
171 /** MESA_META_SELECT_FEEDBACK */
172 GLenum RenderMode;
173 struct gl_selection Select;
174 struct gl_feedback Feedback;
175
176 /** MESA_META_MULTISAMPLE */
177 struct gl_multisample_attrib Multisample;
178
179 /** MESA_META_FRAMEBUFFER_SRGB */
180 GLboolean sRGBEnabled;
181
182 /** Miscellaneous (always disabled) */
183 GLboolean Lighting;
184 GLboolean RasterDiscard;
185 GLboolean TransformFeedbackNeedsResume;
186
187 GLuint DrawBufferName, ReadBufferName, RenderbufferName;
188
189 /** MESA_META_DRAW_BUFFERS */
190 GLenum ColorDrawBuffers[MAX_DRAW_BUFFERS];
191 };
192
193 /**
194 * Temporary texture used for glBlitFramebuffer, glDrawPixels, etc.
195 * This is currently shared by all the meta ops. But we could create a
196 * separate one for each of glDrawPixel, glBlitFramebuffer, glCopyPixels, etc.
197 */
198 struct temp_texture
199 {
200 GLuint TexObj;
201 GLenum Target; /**< GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE */
202 GLsizei MinSize; /**< Min texture size to allocate */
203 GLsizei MaxSize; /**< Max possible texture size */
204 GLboolean NPOT; /**< Non-power of two size OK? */
205 GLsizei Width, Height; /**< Current texture size */
206 GLenum IntFormat;
207 GLfloat Sright, Ttop; /**< right, top texcoords */
208 };
209
210 /**
211 * State for GLSL texture sampler which is used to generate fragment
212 * shader in _mesa_meta_generate_mipmap().
213 */
214 struct blit_shader {
215 const char *type;
216 const char *func;
217 const char *texcoords;
218 GLuint shader_prog;
219 };
220
221 /**
222 * Table of all sampler types and shaders for accessing them.
223 */
224 struct blit_shader_table {
225 struct blit_shader sampler_1d;
226 struct blit_shader sampler_2d;
227 struct blit_shader sampler_3d;
228 struct blit_shader sampler_rect;
229 struct blit_shader sampler_cubemap;
230 struct blit_shader sampler_1d_array;
231 struct blit_shader sampler_2d_array;
232 struct blit_shader sampler_cubemap_array;
233 };
234
235 /**
236 * Indices in the blit_state->msaa_shaders[] array
237 *
238 * Note that setup_glsl_msaa_blit_shader() assumes that the _INT enums are one
239 * more than the non-_INT version and _UINT is one beyond that.
240 */
241 enum blit_msaa_shader {
242 BLIT_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE,
243 BLIT_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_INT,
244 BLIT_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_UINT,
245 BLIT_MSAA_SHADER_2D_MULTISAMPLE_COPY,
246 BLIT_MSAA_SHADER_2D_MULTISAMPLE_COPY_INT,
247 BLIT_MSAA_SHADER_2D_MULTISAMPLE_COPY_UINT,
248 BLIT_MSAA_SHADER_2D_MULTISAMPLE_DEPTH_RESOLVE,
249 BLIT_MSAA_SHADER_2D_MULTISAMPLE_DEPTH_COPY,
250 BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE,
251 BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_INT,
252 BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_UINT,
253 BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_COPY,
254 BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_COPY_INT,
255 BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_COPY_UINT,
256 BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_DEPTH_RESOLVE,
257 BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_DEPTH_COPY,
258 BLIT_MSAA_SHADER_COUNT,
259 };
260
261 /**
262 * State for glBlitFramebufer()
263 */
264 struct blit_state
265 {
266 GLuint VAO;
267 GLuint VBO;
268 struct blit_shader_table shaders;
269 GLuint msaa_shaders[BLIT_MSAA_SHADER_COUNT];
270 struct temp_texture depthTex;
271 bool no_ctsi_fallback;
272 };
273
274 struct fb_tex_blit_state
275 {
276 GLint baseLevelSave, maxLevelSave;
277 GLuint sampler, samplerSave, stencilSamplingSave;
278 GLuint tempTex;
279 };
280
281
282 /**
283 * State for glClear()
284 */
285 struct clear_state
286 {
287 GLuint VAO;
288 GLuint VBO;
289 GLuint ShaderProg;
290 GLint ColorLocation;
291 GLint LayerLocation;
292
293 GLuint IntegerShaderProg;
294 GLint IntegerColorLocation;
295 GLint IntegerLayerLocation;
296 };
297
298
299 /**
300 * State for glCopyPixels()
301 */
302 struct copypix_state
303 {
304 GLuint VAO;
305 GLuint VBO;
306 };
307
308
309 /**
310 * State for glDrawPixels()
311 */
312 struct drawpix_state
313 {
314 GLuint VAO;
315 GLuint VBO;
316
317 GLuint StencilFP; /**< Fragment program for drawing stencil images */
318 GLuint DepthFP; /**< Fragment program for drawing depth images */
319 };
320
321
322 /**
323 * State for glBitmap()
324 */
325 struct bitmap_state
326 {
327 GLuint VAO;
328 GLuint VBO;
329 struct temp_texture Tex; /**< separate texture from other meta ops */
330 };
331
332 /**
333 * State for _mesa_meta_generate_mipmap()
334 */
335 struct gen_mipmap_state
336 {
337 GLuint VAO;
338 GLuint VBO;
339 GLuint FBO;
340 GLuint Sampler;
341
342 struct blit_shader_table shaders;
343 };
344
345 /**
346 * State for texture decompression
347 */
348 struct decompress_state
349 {
350 GLuint VAO;
351 GLuint VBO, FBO, RBO, Sampler;
352 GLint Width, Height;
353
354 struct blit_shader_table shaders;
355 };
356
357 /**
358 * State for glDrawTex()
359 */
360 struct drawtex_state
361 {
362 GLuint VAO;
363 GLuint VBO;
364 };
365
366 #define MAX_META_OPS_DEPTH 8
367 /**
368 * All per-context meta state.
369 */
370 struct gl_meta_state
371 {
372 /** Stack of state saved during meta-ops */
373 struct save_state Save[MAX_META_OPS_DEPTH];
374 /** Save stack depth */
375 GLuint SaveStackDepth;
376
377 struct temp_texture TempTex;
378
379 struct blit_state Blit; /**< For _mesa_meta_BlitFramebuffer() */
380 struct clear_state Clear; /**< For _mesa_meta_Clear() */
381 struct copypix_state CopyPix; /**< For _mesa_meta_CopyPixels() */
382 struct drawpix_state DrawPix; /**< For _mesa_meta_DrawPixels() */
383 struct bitmap_state Bitmap; /**< For _mesa_meta_Bitmap() */
384 struct gen_mipmap_state Mipmap; /**< For _mesa_meta_GenerateMipmap() */
385 struct decompress_state Decompress; /**< For texture decompression */
386 struct drawtex_state DrawTex; /**< For _mesa_meta_DrawTex() */
387 };
388
389 struct vertex {
390 GLfloat x, y, z, tex[4];
391 GLfloat r, g, b, a;
392 };
393
394 extern void
395 _mesa_meta_init(struct gl_context *ctx);
396
397 extern void
398 _mesa_meta_free(struct gl_context *ctx);
399
400 extern void
401 _mesa_meta_begin(struct gl_context *ctx, GLbitfield state);
402
403 extern void
404 _mesa_meta_end(struct gl_context *ctx);
405
406 extern GLboolean
407 _mesa_meta_in_progress(struct gl_context *ctx);
408
409 extern void
410 _mesa_meta_fb_tex_blit_begin(const struct gl_context *ctx,
411 struct fb_tex_blit_state *blit);
412
413 extern void
414 _mesa_meta_fb_tex_blit_end(struct gl_context *ctx, GLenum target,
415 struct fb_tex_blit_state *blit);
416
417 extern GLboolean
418 _mesa_meta_bind_rb_as_tex_image(struct gl_context *ctx,
419 struct gl_renderbuffer *rb,
420 GLuint *tex,
421 struct gl_texture_object **texObj,
422 GLenum *target);
423
424 GLuint
425 _mesa_meta_setup_sampler(struct gl_context *ctx,
426 const struct gl_texture_object *texObj,
427 GLenum target, GLenum filter, GLuint srcLevel);
428
429 extern GLbitfield
430 _mesa_meta_BlitFramebuffer(struct gl_context *ctx,
431 GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
432 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
433 GLbitfield mask, GLenum filter);
434
435 extern void
436 _mesa_meta_and_swrast_BlitFramebuffer(struct gl_context *ctx,
437 GLint srcX0, GLint srcY0,
438 GLint srcX1, GLint srcY1,
439 GLint dstX0, GLint dstY0,
440 GLint dstX1, GLint dstY1,
441 GLbitfield mask, GLenum filter);
442
443 extern void
444 _mesa_meta_Clear(struct gl_context *ctx, GLbitfield buffers);
445
446 extern void
447 _mesa_meta_glsl_Clear(struct gl_context *ctx, GLbitfield buffers);
448
449 extern void
450 _mesa_meta_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
451 GLsizei width, GLsizei height,
452 GLint dstx, GLint dsty, GLenum type);
453
454 extern void
455 _mesa_meta_DrawPixels(struct gl_context *ctx,
456 GLint x, GLint y, GLsizei width, GLsizei height,
457 GLenum format, GLenum type,
458 const struct gl_pixelstore_attrib *unpack,
459 const GLvoid *pixels);
460
461 extern void
462 _mesa_meta_Bitmap(struct gl_context *ctx,
463 GLint x, GLint y, GLsizei width, GLsizei height,
464 const struct gl_pixelstore_attrib *unpack,
465 const GLubyte *bitmap);
466
467 extern void
468 _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
469 struct gl_texture_object *texObj);
470
471 extern void
472 _mesa_meta_CopyTexSubImage(struct gl_context *ctx, GLuint dims,
473 struct gl_texture_image *texImage,
474 GLint xoffset, GLint yoffset, GLint slice,
475 struct gl_renderbuffer *rb,
476 GLint x, GLint y,
477 GLsizei width, GLsizei height);
478
479 extern void
480 _mesa_meta_GetTexImage(struct gl_context *ctx,
481 GLenum format, GLenum type, GLvoid *pixels,
482 struct gl_texture_image *texImage);
483
484 extern void
485 _mesa_meta_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
486 GLfloat width, GLfloat height);
487
488 /* meta-internal functions */
489 GLuint
490 _mesa_meta_compile_shader_with_debug(struct gl_context *ctx, GLenum target,
491 const GLcharARB *source);
492
493
494 GLuint
495 _mesa_meta_link_program_with_debug(struct gl_context *ctx, GLuint program);
496
497 void
498 _mesa_meta_compile_and_link_program(struct gl_context *ctx,
499 const char *vs_source,
500 const char *fs_source,
501 const char *name,
502 GLuint *program);
503
504 GLboolean
505 _mesa_meta_alloc_texture(struct temp_texture *tex,
506 GLsizei width, GLsizei height, GLenum intFormat);
507
508 void
509 _mesa_meta_setup_texture_coords(GLenum faceTarget,
510 GLint slice,
511 GLint width,
512 GLint height,
513 GLint depth,
514 GLfloat coords0[4],
515 GLfloat coords1[4],
516 GLfloat coords2[4],
517 GLfloat coords3[4]);
518
519 struct temp_texture *
520 _mesa_meta_get_temp_texture(struct gl_context *ctx);
521
522 struct temp_texture *
523 _mesa_meta_get_temp_depth_texture(struct gl_context *ctx);
524
525 void
526 _mesa_meta_setup_vertex_objects(GLuint *VAO, GLuint *VBO,
527 bool use_generic_attributes,
528 unsigned vertex_size, unsigned texcoord_size,
529 unsigned color_size);
530
531 void
532 _mesa_meta_setup_ff_tnl_for_blit(GLuint *VAO, GLuint *VBO,
533 unsigned texcoord_size);
534
535 void
536 _mesa_meta_setup_drawpix_texture(struct gl_context *ctx,
537 struct temp_texture *tex,
538 GLboolean newTex,
539 GLsizei width, GLsizei height,
540 GLenum format, GLenum type,
541 const GLvoid *pixels);
542
543 void
544 _mesa_meta_setup_copypix_texture(struct gl_context *ctx,
545 struct temp_texture *tex,
546 GLint srcX, GLint srcY,
547 GLsizei width, GLsizei height,
548 GLenum intFormat,
549 GLenum filter);
550
551 void
552 _mesa_meta_setup_blit_shader(struct gl_context *ctx,
553 GLenum target,
554 struct blit_shader_table *table);
555
556 void
557 _mesa_meta_glsl_blit_cleanup(struct blit_state *blit);
558
559 void
560 _mesa_meta_blit_shader_table_cleanup(struct blit_shader_table *table);
561
562 void
563 _mesa_meta_glsl_generate_mipmap_cleanup(struct gen_mipmap_state *mipmap);
564
565 void
566 _mesa_meta_bind_fbo_image(GLenum attachment,
567 struct gl_texture_image *texImage, GLuint layer);
568
569 #endif /* META_H */