meta: Move the meta structures to the meta header.
[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 /**\}*/
62
63 /**
64 * State which we may save/restore across meta ops.
65 * XXX this may be incomplete...
66 */
67 struct save_state
68 {
69 GLbitfield SavedState; /**< bitmask of MESA_META_* flags */
70
71 /** MESA_META_CLEAR (and others?) */
72 struct gl_query_object *CurrentOcclusionObject;
73
74 /** MESA_META_ALPHA_TEST */
75 GLboolean AlphaEnabled;
76 GLenum AlphaFunc;
77 GLclampf AlphaRef;
78
79 /** MESA_META_BLEND */
80 GLbitfield BlendEnabled;
81 GLboolean ColorLogicOpEnabled;
82
83 /** MESA_META_COLOR_MASK */
84 GLubyte ColorMask[MAX_DRAW_BUFFERS][4];
85
86 /** MESA_META_DEPTH_TEST */
87 struct gl_depthbuffer_attrib Depth;
88
89 /** MESA_META_FOG */
90 GLboolean Fog;
91
92 /** MESA_META_PIXEL_STORE */
93 struct gl_pixelstore_attrib Pack, Unpack;
94
95 /** MESA_META_PIXEL_TRANSFER */
96 GLfloat RedBias, RedScale;
97 GLfloat GreenBias, GreenScale;
98 GLfloat BlueBias, BlueScale;
99 GLfloat AlphaBias, AlphaScale;
100 GLfloat DepthBias, DepthScale;
101 GLboolean MapColorFlag;
102
103 /** MESA_META_RASTERIZATION */
104 GLenum FrontPolygonMode, BackPolygonMode;
105 GLboolean PolygonOffset;
106 GLboolean PolygonSmooth;
107 GLboolean PolygonStipple;
108 GLboolean PolygonCull;
109
110 /** MESA_META_SCISSOR */
111 struct gl_scissor_attrib Scissor;
112
113 /** MESA_META_SHADER */
114 GLboolean VertexProgramEnabled;
115 struct gl_vertex_program *VertexProgram;
116 GLboolean FragmentProgramEnabled;
117 struct gl_fragment_program *FragmentProgram;
118 GLboolean ATIFragmentShaderEnabled;
119 struct gl_shader_program *Shader[MESA_SHADER_STAGES];
120 struct gl_shader_program *ActiveShader;
121
122 /** MESA_META_STENCIL_TEST */
123 struct gl_stencil_attrib Stencil;
124
125 /** MESA_META_TRANSFORM */
126 GLenum MatrixMode;
127 GLfloat ModelviewMatrix[16];
128 GLfloat ProjectionMatrix[16];
129 GLfloat TextureMatrix[16];
130
131 /** MESA_META_CLIP */
132 GLbitfield ClipPlanesEnabled;
133
134 /** MESA_META_TEXTURE */
135 GLuint ActiveUnit;
136 GLuint ClientActiveUnit;
137 /** for unit[0] only */
138 struct gl_texture_object *CurrentTexture[NUM_TEXTURE_TARGETS];
139 /** mask of TEXTURE_2D_BIT, etc */
140 GLbitfield TexEnabled[MAX_TEXTURE_UNITS];
141 GLbitfield TexGenEnabled[MAX_TEXTURE_UNITS];
142 GLuint EnvMode; /* unit[0] only */
143
144 /** MESA_META_VERTEX */
145 struct gl_vertex_array_object *VAO;
146 struct gl_buffer_object *ArrayBufferObj;
147
148 /** MESA_META_VIEWPORT */
149 GLfloat ViewportX, ViewportY, ViewportW, ViewportH;
150 GLclampd DepthNear, DepthFar;
151
152 /** MESA_META_CLAMP_FRAGMENT_COLOR */
153 GLenum ClampFragmentColor;
154
155 /** MESA_META_CLAMP_VERTEX_COLOR */
156 GLenum ClampVertexColor;
157
158 /** MESA_META_CONDITIONAL_RENDER */
159 struct gl_query_object *CondRenderQuery;
160 GLenum CondRenderMode;
161
162 /** MESA_META_SELECT_FEEDBACK */
163 GLenum RenderMode;
164 struct gl_selection Select;
165 struct gl_feedback Feedback;
166
167 /** MESA_META_MULTISAMPLE */
168 GLboolean MultisampleEnabled;
169
170 /** MESA_META_FRAMEBUFFER_SRGB */
171 GLboolean sRGBEnabled;
172
173 /** Miscellaneous (always disabled) */
174 GLboolean Lighting;
175 GLboolean RasterDiscard;
176 GLboolean TransformFeedbackNeedsResume;
177 };
178
179 /**
180 * Temporary texture used for glBlitFramebuffer, glDrawPixels, etc.
181 * This is currently shared by all the meta ops. But we could create a
182 * separate one for each of glDrawPixel, glBlitFramebuffer, glCopyPixels, etc.
183 */
184 struct temp_texture
185 {
186 GLuint TexObj;
187 GLenum Target; /**< GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE */
188 GLsizei MinSize; /**< Min texture size to allocate */
189 GLsizei MaxSize; /**< Max possible texture size */
190 GLboolean NPOT; /**< Non-power of two size OK? */
191 GLsizei Width, Height; /**< Current texture size */
192 GLenum IntFormat;
193 GLfloat Sright, Ttop; /**< right, top texcoords */
194 };
195
196 /**
197 * State for GLSL texture sampler which is used to generate fragment
198 * shader in _mesa_meta_generate_mipmap().
199 */
200 struct blit_shader {
201 const char *type;
202 const char *func;
203 const char *texcoords;
204 GLuint shader_prog;
205 };
206
207 /**
208 * Table of all sampler types and shaders for accessing them.
209 */
210 struct blit_shader_table {
211 struct blit_shader sampler_1d;
212 struct blit_shader sampler_2d;
213 struct blit_shader sampler_3d;
214 struct blit_shader sampler_rect;
215 struct blit_shader sampler_cubemap;
216 struct blit_shader sampler_1d_array;
217 struct blit_shader sampler_2d_array;
218 struct blit_shader sampler_cubemap_array;
219 };
220
221 /**
222 * State for glBlitFramebufer()
223 */
224 struct blit_state
225 {
226 GLuint VAO;
227 GLuint VBO;
228 GLuint DepthFP;
229 struct blit_shader_table shaders;
230 struct temp_texture depthTex;
231 };
232
233
234 /**
235 * State for glClear()
236 */
237 struct clear_state
238 {
239 GLuint VAO;
240 GLuint VBO;
241 GLuint ShaderProg;
242 GLint ColorLocation;
243 GLint LayerLocation;
244
245 GLuint IntegerShaderProg;
246 GLint IntegerColorLocation;
247 GLint IntegerLayerLocation;
248 };
249
250
251 /**
252 * State for glCopyPixels()
253 */
254 struct copypix_state
255 {
256 GLuint VAO;
257 GLuint VBO;
258 };
259
260
261 /**
262 * State for glDrawPixels()
263 */
264 struct drawpix_state
265 {
266 GLuint VAO;
267 GLuint VBO;
268
269 GLuint StencilFP; /**< Fragment program for drawing stencil images */
270 GLuint DepthFP; /**< Fragment program for drawing depth images */
271 };
272
273
274 /**
275 * State for glBitmap()
276 */
277 struct bitmap_state
278 {
279 GLuint VAO;
280 GLuint VBO;
281 struct temp_texture Tex; /**< separate texture from other meta ops */
282 };
283
284 /**
285 * State for _mesa_meta_generate_mipmap()
286 */
287 struct gen_mipmap_state
288 {
289 GLuint VAO;
290 GLuint VBO;
291 GLuint FBO;
292 GLuint Sampler;
293
294 struct blit_shader_table shaders;
295 };
296
297 /**
298 * State for texture decompression
299 */
300 struct decompress_state
301 {
302 GLuint VAO;
303 GLuint VBO, FBO, RBO, Sampler;
304 GLint Width, Height;
305
306 struct blit_shader_table shaders;
307 };
308
309 /**
310 * State for glDrawTex()
311 */
312 struct drawtex_state
313 {
314 GLuint VAO;
315 GLuint VBO;
316 };
317
318 #define MAX_META_OPS_DEPTH 8
319 /**
320 * All per-context meta state.
321 */
322 struct gl_meta_state
323 {
324 /** Stack of state saved during meta-ops */
325 struct save_state Save[MAX_META_OPS_DEPTH];
326 /** Save stack depth */
327 GLuint SaveStackDepth;
328
329 struct temp_texture TempTex;
330
331 struct blit_state Blit; /**< For _mesa_meta_BlitFramebuffer() */
332 struct clear_state Clear; /**< For _mesa_meta_Clear() */
333 struct copypix_state CopyPix; /**< For _mesa_meta_CopyPixels() */
334 struct drawpix_state DrawPix; /**< For _mesa_meta_DrawPixels() */
335 struct bitmap_state Bitmap; /**< For _mesa_meta_Bitmap() */
336 struct gen_mipmap_state Mipmap; /**< For _mesa_meta_GenerateMipmap() */
337 struct decompress_state Decompress; /**< For texture decompression */
338 struct drawtex_state DrawTex; /**< For _mesa_meta_DrawTex() */
339 };
340
341 struct vertex {
342 GLfloat x, y, z, tex[4];
343 GLfloat r, g, b, a;
344 };
345
346 extern void
347 _mesa_meta_init(struct gl_context *ctx);
348
349 extern void
350 _mesa_meta_free(struct gl_context *ctx);
351
352 extern void
353 _mesa_meta_begin(struct gl_context *ctx, GLbitfield state);
354
355 extern void
356 _mesa_meta_end(struct gl_context *ctx);
357
358 extern GLboolean
359 _mesa_meta_in_progress(struct gl_context *ctx);
360
361 extern void
362 _mesa_meta_BlitFramebuffer(struct gl_context *ctx,
363 GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
364 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
365 GLbitfield mask, GLenum filter);
366
367 extern void
368 _mesa_meta_Clear(struct gl_context *ctx, GLbitfield buffers);
369
370 extern void
371 _mesa_meta_glsl_Clear(struct gl_context *ctx, GLbitfield buffers);
372
373 extern void
374 _mesa_meta_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
375 GLsizei width, GLsizei height,
376 GLint dstx, GLint dsty, GLenum type);
377
378 extern void
379 _mesa_meta_DrawPixels(struct gl_context *ctx,
380 GLint x, GLint y, GLsizei width, GLsizei height,
381 GLenum format, GLenum type,
382 const struct gl_pixelstore_attrib *unpack,
383 const GLvoid *pixels);
384
385 extern void
386 _mesa_meta_Bitmap(struct gl_context *ctx,
387 GLint x, GLint y, GLsizei width, GLsizei height,
388 const struct gl_pixelstore_attrib *unpack,
389 const GLubyte *bitmap);
390
391 extern GLboolean
392 _mesa_meta_check_generate_mipmap_fallback(struct gl_context *ctx, GLenum target,
393 struct gl_texture_object *texObj);
394
395 extern void
396 _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
397 struct gl_texture_object *texObj);
398
399 extern void
400 _mesa_meta_CopyTexSubImage(struct gl_context *ctx, GLuint dims,
401 struct gl_texture_image *texImage,
402 GLint xoffset, GLint yoffset, GLint slice,
403 struct gl_renderbuffer *rb,
404 GLint x, GLint y,
405 GLsizei width, GLsizei height);
406
407 extern void
408 _mesa_meta_GetTexImage(struct gl_context *ctx,
409 GLenum format, GLenum type, GLvoid *pixels,
410 struct gl_texture_image *texImage);
411
412 extern void
413 _mesa_meta_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
414 GLfloat width, GLfloat height);
415
416 #endif /* META_H */