Replace gl_framebuffer's _ColorReadBufferMask with _ColorReadBufferIndex,
[mesa.git] / src / mesa / main / buffers.c
1 /**
2 * \file buffers.c
3 * Frame buffer management.
4 */
5
6 /*
7 * Mesa 3-D graphics library
8 * Version: 6.5
9 *
10 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included
20 * in all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 */
29
30
31 #include "glheader.h"
32 #include "buffers.h"
33 #include "colormac.h"
34 #include "context.h"
35 #include "enums.h"
36 #include "fbobject.h"
37 #include "state.h"
38
39
40 #define BAD_MASK ~0u
41
42
43 #if _HAVE_FULL_GL
44 void GLAPIENTRY
45 _mesa_ClearIndex( GLfloat c )
46 {
47 GET_CURRENT_CONTEXT(ctx);
48 ASSERT_OUTSIDE_BEGIN_END(ctx);
49
50 if (ctx->Color.ClearIndex == (GLuint) c)
51 return;
52
53 FLUSH_VERTICES(ctx, _NEW_COLOR);
54 ctx->Color.ClearIndex = (GLuint) c;
55
56 if (!ctx->Visual.rgbMode && ctx->Driver.ClearIndex) {
57 /* it's OK to call glClearIndex in RGBA mode but it should be a NOP */
58 (*ctx->Driver.ClearIndex)( ctx, ctx->Color.ClearIndex );
59 }
60 }
61 #endif
62
63
64 /**
65 * Specify the clear values for the color buffers.
66 *
67 * \param red red color component.
68 * \param green green color component.
69 * \param blue blue color component.
70 * \param alpha alpha component.
71 *
72 * \sa glClearColor().
73 *
74 * Clamps the parameters and updates gl_colorbuffer_attrib::ClearColor. On a
75 * change, flushes the vertices and notifies the driver via the
76 * dd_function_table::ClearColor callback.
77 */
78 void GLAPIENTRY
79 _mesa_ClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
80 {
81 GLfloat tmp[4];
82 GET_CURRENT_CONTEXT(ctx);
83 ASSERT_OUTSIDE_BEGIN_END(ctx);
84
85 tmp[0] = CLAMP(red, 0.0F, 1.0F);
86 tmp[1] = CLAMP(green, 0.0F, 1.0F);
87 tmp[2] = CLAMP(blue, 0.0F, 1.0F);
88 tmp[3] = CLAMP(alpha, 0.0F, 1.0F);
89
90 if (TEST_EQ_4V(tmp, ctx->Color.ClearColor))
91 return; /* no change */
92
93 FLUSH_VERTICES(ctx, _NEW_COLOR);
94 COPY_4V(ctx->Color.ClearColor, tmp);
95
96 if (ctx->Visual.rgbMode && ctx->Driver.ClearColor) {
97 /* it's OK to call glClearColor in CI mode but it should be a NOP */
98 (*ctx->Driver.ClearColor)(ctx, ctx->Color.ClearColor);
99 }
100 }
101
102
103 /**
104 * Clear buffers.
105 *
106 * \param mask bit-mask indicating the buffers to be cleared.
107 *
108 * Flushes the vertices and verifies the parameter. If __GLcontextRec::NewState
109 * is set then calls _mesa_update_state() to update gl_frame_buffer::_Xmin,
110 * etc. If the rasterization mode is set to GL_RENDER then requests the driver
111 * to clear the buffers, via the dd_function_table::Clear callback.
112 */
113 void GLAPIENTRY
114 _mesa_Clear( GLbitfield mask )
115 {
116 GET_CURRENT_CONTEXT(ctx);
117 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
118
119 if (MESA_VERBOSE & VERBOSE_API)
120 _mesa_debug(ctx, "glClear 0x%x\n", mask);
121
122 if (mask & ~(GL_COLOR_BUFFER_BIT |
123 GL_DEPTH_BUFFER_BIT |
124 GL_STENCIL_BUFFER_BIT |
125 GL_ACCUM_BUFFER_BIT)) {
126 /* invalid bit set */
127 _mesa_error( ctx, GL_INVALID_VALUE, "glClear(0x%x)", mask);
128 return;
129 }
130
131 if (ctx->NewState) {
132 _mesa_update_state( ctx ); /* update _Xmin, etc */
133 }
134
135 if (ctx->RenderMode == GL_RENDER) {
136 const GLint x = ctx->DrawBuffer->_Xmin;
137 const GLint y = ctx->DrawBuffer->_Ymin;
138 const GLint height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
139 const GLint width = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
140 GLbitfield bufferMask;
141
142 /* don't clear depth buffer if depth writing disabled */
143 if (!ctx->Depth.Mask)
144 mask &= ~GL_DEPTH_BUFFER_BIT;
145
146 /* Build the bitmask to send to device driver's Clear function.
147 * Note that the GL_COLOR_BUFFER_BIT flag will expand to 0, 1, 2 or 4
148 * of the BUFFER_BIT_FRONT/BACK_LEFT/RIGHT flags, or one of the
149 * BUFFER_BIT_COLORn flags.
150 */
151 bufferMask = 0;
152 if (mask & GL_COLOR_BUFFER_BIT) {
153 bufferMask |= ctx->DrawBuffer->_ColorDrawBufferMask[0];
154 }
155
156 if ((mask & GL_DEPTH_BUFFER_BIT)
157 && ctx->DrawBuffer->Visual.haveDepthBuffer) {
158 bufferMask |= BUFFER_BIT_DEPTH;
159 }
160
161 if ((mask & GL_STENCIL_BUFFER_BIT)
162 && ctx->DrawBuffer->Visual.haveStencilBuffer) {
163 bufferMask |= BUFFER_BIT_STENCIL;
164 }
165
166 if ((mask & GL_ACCUM_BUFFER_BIT)
167 && ctx->DrawBuffer->Visual.haveAccumBuffer) {
168 bufferMask |= BUFFER_BIT_ACCUM;
169 }
170
171 ASSERT(ctx->Driver.Clear);
172 ctx->Driver.Clear( ctx, bufferMask, (GLboolean) !ctx->Scissor.Enabled,
173 x, y, width, height );
174 }
175 }
176
177
178
179 /**
180 * Return bitmask of BUFFER_BIT_* flags indicating which color buffers are
181 * available to the rendering context.
182 * This depends on the framebuffer we're writing to. For window system
183 * framebuffers we look at the framebuffer's visual. But for user-
184 * create framebuffers we look at the number of supported color attachments.
185 */
186 static GLbitfield
187 supported_buffer_bitmask(const GLcontext *ctx, GLuint framebufferID)
188 {
189 GLbitfield mask = 0x0;
190 GLint i;
191
192 if (framebufferID > 0) {
193 /* A user-created renderbuffer */
194 ASSERT(ctx->Extensions.EXT_framebuffer_object);
195 for (i = 0; i < ctx->Const.MaxColorAttachments; i++) {
196 mask |= (BUFFER_BIT_COLOR0 << i);
197 }
198 }
199 else {
200 /* A window system renderbuffer */
201 mask = BUFFER_BIT_FRONT_LEFT; /* always have this */
202 if (ctx->Visual.stereoMode) {
203 mask |= BUFFER_BIT_FRONT_RIGHT;
204 if (ctx->Visual.doubleBufferMode) {
205 mask |= BUFFER_BIT_BACK_LEFT | BUFFER_BIT_BACK_RIGHT;
206 }
207 }
208 else if (ctx->Visual.doubleBufferMode) {
209 mask |= BUFFER_BIT_BACK_LEFT;
210 }
211
212 for (i = 0; i < ctx->Visual.numAuxBuffers; i++) {
213 mask |= (BUFFER_BIT_AUX0 << i);
214 }
215 }
216
217 return mask;
218 }
219
220
221 /**
222 * Helper routine used by glDrawBuffer and glDrawBuffersARB.
223 * Given a GLenum naming one or more color buffers (such as
224 * GL_FRONT_AND_BACK), return the corresponding bitmask of BUFFER_BIT_* flags.
225 */
226 static GLbitfield
227 draw_buffer_enum_to_bitmask(GLenum buffer)
228 {
229 switch (buffer) {
230 case GL_NONE:
231 return 0;
232 case GL_FRONT:
233 return BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_FRONT_RIGHT;
234 case GL_BACK:
235 return BUFFER_BIT_BACK_LEFT | BUFFER_BIT_BACK_RIGHT;
236 case GL_RIGHT:
237 return BUFFER_BIT_FRONT_RIGHT | BUFFER_BIT_BACK_RIGHT;
238 case GL_FRONT_RIGHT:
239 return BUFFER_BIT_FRONT_RIGHT;
240 case GL_BACK_RIGHT:
241 return BUFFER_BIT_BACK_RIGHT;
242 case GL_BACK_LEFT:
243 return BUFFER_BIT_BACK_LEFT;
244 case GL_FRONT_AND_BACK:
245 return BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT
246 | BUFFER_BIT_FRONT_RIGHT | BUFFER_BIT_BACK_RIGHT;
247 case GL_LEFT:
248 return BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT;
249 case GL_FRONT_LEFT:
250 return BUFFER_BIT_FRONT_LEFT;
251 case GL_AUX0:
252 return BUFFER_BIT_AUX0;
253 case GL_AUX1:
254 return BUFFER_BIT_AUX1;
255 case GL_AUX2:
256 return BUFFER_BIT_AUX2;
257 case GL_AUX3:
258 return BUFFER_BIT_AUX3;
259 case GL_COLOR_ATTACHMENT0_EXT:
260 return BUFFER_BIT_COLOR0;
261 case GL_COLOR_ATTACHMENT1_EXT:
262 return BUFFER_BIT_COLOR1;
263 case GL_COLOR_ATTACHMENT2_EXT:
264 return BUFFER_BIT_COLOR2;
265 case GL_COLOR_ATTACHMENT3_EXT:
266 return BUFFER_BIT_COLOR3;
267 default:
268 /* error */
269 return BAD_MASK;
270 }
271 }
272
273
274 /**
275 * Helper routine used by glReadBuffer.
276 * Given a GLenum naming a color buffer, return the index of the corresponding
277 * renderbuffer (a BUFFER_* value).
278 * return -1 for an invalid buffer.
279 */
280 static GLint
281 read_buffer_enum_to_index(GLenum buffer)
282 {
283 switch (buffer) {
284 case GL_FRONT:
285 return BUFFER_FRONT_LEFT;
286 case GL_BACK:
287 return BUFFER_BACK_LEFT;
288 case GL_RIGHT:
289 return BUFFER_FRONT_RIGHT;
290 case GL_FRONT_RIGHT:
291 return BUFFER_FRONT_RIGHT;
292 case GL_BACK_RIGHT:
293 return BUFFER_BACK_RIGHT;
294 case GL_BACK_LEFT:
295 return BUFFER_BACK_LEFT;
296 case GL_LEFT:
297 return BUFFER_FRONT_LEFT;
298 case GL_FRONT_LEFT:
299 return BUFFER_FRONT_LEFT;
300 case GL_AUX0:
301 return BUFFER_AUX0;
302 case GL_AUX1:
303 return BUFFER_AUX1;
304 case GL_AUX2:
305 return BUFFER_AUX2;
306 case GL_AUX3:
307 return BUFFER_AUX3;
308 case GL_COLOR_ATTACHMENT0_EXT:
309 return BUFFER_COLOR0;
310 case GL_COLOR_ATTACHMENT1_EXT:
311 return BUFFER_COLOR1;
312 case GL_COLOR_ATTACHMENT2_EXT:
313 return BUFFER_COLOR2;
314 case GL_COLOR_ATTACHMENT3_EXT:
315 return BUFFER_COLOR3;
316 default:
317 /* error */
318 return -1;
319 }
320 }
321
322
323 /**
324 * Called by glDrawBuffer().
325 * Specify which renderbuffer(s) to draw into for the first color output.
326 * <buffer> can name zero, one, two or four renderbuffers!
327 * \sa _mesa_DrawBuffersARB
328 *
329 * \param buffer buffer token such as GL_LEFT or GL_FRONT_AND_BACK, etc.
330 */
331 void GLAPIENTRY
332 _mesa_DrawBuffer(GLenum buffer)
333 {
334 GLuint bufferID;
335 GLbitfield destMask;
336 GET_CURRENT_CONTEXT(ctx);
337 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex... */
338
339 if (MESA_VERBOSE & VERBOSE_API) {
340 _mesa_debug(ctx, "glDrawBuffer %s\n", _mesa_lookup_enum_by_nr(buffer));
341 }
342
343 bufferID = ctx->DrawBuffer->Name;
344
345 if (buffer == GL_NONE) {
346 destMask = 0x0;
347 }
348 else {
349 const GLbitfield supportedMask = supported_buffer_bitmask(ctx, bufferID);
350 destMask = draw_buffer_enum_to_bitmask(buffer);
351 if (destMask == BAD_MASK) {
352 /* totally bogus buffer */
353 _mesa_error(ctx, GL_INVALID_ENUM, "glDrawBuffer(buffer)");
354 return;
355 }
356 destMask &= supportedMask;
357 if (destMask == 0x0) {
358 /* none of the named color buffers exist! */
359 _mesa_error(ctx, GL_INVALID_OPERATION, "glDrawBuffer(buffer)");
360 return;
361 }
362 }
363
364 /* if we get here, there's no error so set new state */
365 _mesa_drawbuffers(ctx, 1, &buffer, &destMask);
366 }
367
368
369 /**
370 * Called by glDrawBuffersARB; specifies the destination color renderbuffers
371 * for N fragment program color outputs.
372 * \sa _mesa_DrawBuffer
373 * \param n number of outputs
374 * \param buffers array [n] of renderbuffer names. Unlike glDrawBuffer, the
375 * names cannot specify more than one buffer. For example,
376 * GL_FRONT_AND_BACK is illegal.
377 */
378 void GLAPIENTRY
379 _mesa_DrawBuffersARB(GLsizei n, const GLenum *buffers)
380 {
381 GLint output;
382 GLuint bufferID;
383 GLbitfield usedBufferMask, supportedMask;
384 GLbitfield destMask[MAX_DRAW_BUFFERS];
385 GET_CURRENT_CONTEXT(ctx);
386 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
387
388 if (!ctx->Extensions.ARB_draw_buffers) {
389 _mesa_error(ctx, GL_INVALID_OPERATION, "glDrawBuffersARB");
390 return;
391 }
392 if (n < 1 || n > (GLsizei) ctx->Const.MaxDrawBuffers) {
393 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawBuffersARB(n)");
394 return;
395 }
396
397 bufferID = ctx->DrawBuffer->Name;
398
399 supportedMask = supported_buffer_bitmask(ctx, bufferID);
400 usedBufferMask = 0x0;
401
402 /* complicated error checking... */
403 for (output = 0; output < n; output++) {
404 if (buffers[output] == GL_NONE) {
405 destMask[output] = 0x0;
406 }
407 else {
408 destMask[output] = draw_buffer_enum_to_bitmask(buffers[output]);
409 if (destMask[output] == BAD_MASK
410 || _mesa_bitcount(destMask[output]) > 1) {
411 _mesa_error(ctx, GL_INVALID_ENUM, "glDrawBuffersARB(buffer)");
412 return;
413 }
414 destMask[output] &= supportedMask;
415 if (destMask[output] == 0) {
416 _mesa_error(ctx, GL_INVALID_OPERATION,
417 "glDrawBuffersARB(unsupported buffer)");
418 return;
419 }
420 if (destMask[output] & usedBufferMask) {
421 /* can't specify a dest buffer more than once! */
422 _mesa_error(ctx, GL_INVALID_OPERATION,
423 "glDrawBuffersARB(duplicated buffer)");
424 return;
425 }
426
427 /* update bitmask */
428 usedBufferMask |= destMask[output];
429 }
430 }
431
432 /* OK, if we get here, there were no errors so set the new state */
433 _mesa_drawbuffers(ctx, n, buffers, destMask);
434 }
435
436
437 /**
438 * Set color output state. Traditionally, there was only one color
439 * output, but fragment programs can now have several distinct color
440 * outputs (see GL_ARB_draw_buffers). This function sets the state
441 * for one such color output.
442 * \param ctx current context
443 * \param output which fragment program output
444 * \param buffer buffer to write to (like GL_LEFT)
445 * \param destMask BUFFER_* bitmask
446 * (like BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT).
447 */
448 static void
449 set_color_output(GLcontext *ctx, GLuint output, GLenum buffer,
450 GLbitfield destMask)
451 {
452 struct gl_framebuffer *fb = ctx->DrawBuffer;
453
454 ASSERT(output < ctx->Const.MaxDrawBuffers);
455
456 fb->ColorDrawBuffer[output] = buffer;
457 fb->_ColorDrawBufferMask[output] = destMask;
458
459 if (fb->Name == 0) {
460 /* Set traditional state var */
461 ctx->Color.DrawBuffer[output] = buffer;
462 }
463
464 /* not really needed, will be set later */
465 fb->_NumColorDrawBuffers[output] = 0;
466 }
467
468
469 /**
470 * Helper routine used by _mesa_DrawBuffer, _mesa_DrawBuffersARB and
471 * _mesa_PopAttrib to set drawbuffer state.
472 * All error checking will have been done prior to calling this function
473 * so nothing should go wrong at this point.
474 * \param ctx current context
475 * \param n number of color outputs to set
476 * \param buffers array[n] of colorbuffer names, like GL_LEFT.
477 * \param destMask array[n] of BUFFER_* bitmasks which correspond to the
478 * colorbuffer names. (i.e. GL_FRONT_AND_BACK =>
479 * BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT).
480 */
481 void
482 _mesa_drawbuffers(GLcontext *ctx, GLsizei n, const GLenum *buffers,
483 const GLbitfield *destMask)
484 {
485 GLbitfield mask[MAX_DRAW_BUFFERS];
486 GLint output;
487
488 if (!destMask) {
489 /* compute destMask values now */
490 const GLuint bufferID = ctx->DrawBuffer->Name;
491 const GLbitfield supportedMask = supported_buffer_bitmask(ctx, bufferID);
492 for (output = 0; output < n; output++) {
493 mask[output] = draw_buffer_enum_to_bitmask(buffers[output]);
494 ASSERT(mask[output] != BAD_MASK);
495 mask[output] &= supportedMask;
496 }
497 destMask = mask;
498 }
499
500 for (output = 0; output < n; output++) {
501 set_color_output(ctx, output, buffers[output], destMask[output]);
502 }
503
504 /* set remaining color outputs to NONE */
505 for (output = n; output < ctx->Const.MaxDrawBuffers; output++) {
506 set_color_output(ctx, output, GL_NONE, 0x0);
507 }
508
509 ctx->NewState |= _NEW_COLOR;
510
511 /*
512 * Call device driver function.
513 */
514 if (ctx->Driver.DrawBuffers)
515 ctx->Driver.DrawBuffers(ctx, n, buffers);
516 else if (ctx->Driver.DrawBuffer)
517 ctx->Driver.DrawBuffer(ctx, buffers[0]);
518 }
519
520
521
522 /**
523 * Called by glReadBuffer to set the source renderbuffer for reading pixels.
524 * \param mode color buffer such as GL_FRONT, GL_BACK, etc.
525 */
526 void GLAPIENTRY
527 _mesa_ReadBuffer(GLenum buffer)
528 {
529 struct gl_framebuffer *fb;
530 GLbitfield supportedMask;
531 GLint srcBuffer;
532 GLuint bufferID;
533 GET_CURRENT_CONTEXT(ctx);
534 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
535
536 fb = ctx->ReadBuffer;
537 bufferID = fb->Name;
538
539 if (MESA_VERBOSE & VERBOSE_API)
540 _mesa_debug(ctx, "glReadBuffer %s\n", _mesa_lookup_enum_by_nr(buffer));
541
542 if (bufferID > 0 && buffer == GL_NONE) {
543 /* This is legal for user-created framebuffer objects */
544 srcBuffer = -1;
545 }
546 else {
547 /* general case / window-system framebuffer */
548 srcBuffer = read_buffer_enum_to_index(buffer);
549 if (srcBuffer == -1) {
550 _mesa_error(ctx, GL_INVALID_ENUM, "glReadBuffer(buffer)");
551 return;
552 }
553 supportedMask = supported_buffer_bitmask(ctx, bufferID);
554 if (((1 << srcBuffer) & supportedMask) == 0) {
555 _mesa_error(ctx, GL_INVALID_OPERATION, "glReadBuffer(buffer)");
556 return;
557 }
558 }
559
560 if (bufferID == 0) {
561 ctx->Pixel.ReadBuffer = buffer;
562 }
563 fb->ColorReadBuffer = buffer;
564 fb->_ColorReadBufferIndex = srcBuffer;
565
566 ctx->NewState |= _NEW_PIXEL;
567
568 /*
569 * Call device driver function.
570 */
571 if (ctx->Driver.ReadBuffer)
572 (*ctx->Driver.ReadBuffer)(ctx, buffer);
573 }
574
575
576 #if _HAVE_FULL_GL
577
578 /**
579 * GL_MESA_resize_buffers extension.
580 *
581 * When this function is called, we'll ask the window system how large
582 * the current window is. If it's a new size, we'll call the driver's
583 * ResizeBuffers function. The driver will then resize its color buffers
584 * as needed, and maybe call the swrast's routine for reallocating
585 * swrast-managed depth/stencil/accum/etc buffers.
586 * \note This function should only be called through the GL API, not
587 * from device drivers (as was done in the past).
588 */
589 void GLAPIENTRY
590 _mesa_ResizeBuffersMESA( void )
591 {
592 GET_CURRENT_CONTEXT(ctx);
593
594 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx );
595
596 if (MESA_VERBOSE & VERBOSE_API)
597 _mesa_debug(ctx, "glResizeBuffersMESA\n");
598
599 if (ctx->WinSysDrawBuffer) {
600 GLuint newWidth, newHeight;
601 GLframebuffer *buffer = ctx->WinSysDrawBuffer;
602
603 assert(buffer->Name == 0);
604
605 /* ask device driver for size of output buffer */
606 ctx->Driver.GetBufferSize( buffer, &newWidth, &newHeight );
607
608 /* see if size of device driver's color buffer (window) has changed */
609 if (buffer->Width != newWidth || buffer->Height != newHeight) {
610 if (ctx->Driver.ResizeBuffers)
611 ctx->Driver.ResizeBuffers(ctx, buffer, newWidth, newHeight );
612 }
613 }
614
615 if (ctx->WinSysReadBuffer
616 && ctx->WinSysReadBuffer != ctx->WinSysDrawBuffer) {
617 GLuint newWidth, newHeight;
618 GLframebuffer *buffer = ctx->WinSysReadBuffer;
619
620 assert(buffer->Name == 0);
621
622 /* ask device driver for size of read buffer */
623 ctx->Driver.GetBufferSize( buffer, &newWidth, &newHeight );
624
625 /* see if size of device driver's color buffer (window) has changed */
626 if (buffer->Width != newWidth || buffer->Height != newHeight) {
627 if (ctx->Driver.ResizeBuffers)
628 ctx->Driver.ResizeBuffers(ctx, buffer, newWidth, newHeight );
629 }
630 }
631
632 ctx->NewState |= _NEW_BUFFERS; /* to update scissor / window bounds */
633 }
634
635
636 /*
637 * XXX move somewhere else someday?
638 */
639 void GLAPIENTRY
640 _mesa_SampleCoverageARB(GLclampf value, GLboolean invert)
641 {
642 GET_CURRENT_CONTEXT(ctx);
643
644 if (!ctx->Extensions.ARB_multisample) {
645 _mesa_error(ctx, GL_INVALID_OPERATION, "glSampleCoverageARB");
646 return;
647 }
648
649 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx );
650 ctx->Multisample.SampleCoverageValue = (GLfloat) CLAMP(value, 0.0, 1.0);
651 ctx->Multisample.SampleCoverageInvert = invert;
652 ctx->NewState |= _NEW_MULTISAMPLE;
653 }
654
655 #endif /* _HAVE_FULL_GL */
656
657
658
659 /**
660 * Define the scissor box.
661 *
662 * \param x, y coordinates of the scissor box lower-left corner.
663 * \param width width of the scissor box.
664 * \param height height of the scissor box.
665 *
666 * \sa glScissor().
667 *
668 * Verifies the parameters and updates __GLcontextRec::Scissor. On a
669 * change flushes the vertices and notifies the driver via
670 * the dd_function_table::Scissor callback.
671 */
672 void GLAPIENTRY
673 _mesa_Scissor( GLint x, GLint y, GLsizei width, GLsizei height )
674 {
675 GET_CURRENT_CONTEXT(ctx);
676 ASSERT_OUTSIDE_BEGIN_END(ctx);
677
678 if (width < 0 || height < 0) {
679 _mesa_error( ctx, GL_INVALID_VALUE, "glScissor" );
680 return;
681 }
682
683 if (MESA_VERBOSE & VERBOSE_API)
684 _mesa_debug(ctx, "glScissor %d %d %d %d\n", x, y, width, height);
685
686 if (x == ctx->Scissor.X &&
687 y == ctx->Scissor.Y &&
688 width == ctx->Scissor.Width &&
689 height == ctx->Scissor.Height)
690 return;
691
692 FLUSH_VERTICES(ctx, _NEW_SCISSOR);
693 ctx->Scissor.X = x;
694 ctx->Scissor.Y = y;
695 ctx->Scissor.Width = width;
696 ctx->Scissor.Height = height;
697
698 if (ctx->Driver.Scissor)
699 ctx->Driver.Scissor( ctx, x, y, width, height );
700 }
701
702
703
704 /**********************************************************************/
705 /** \name Initialization */
706 /*@{*/
707
708 /**
709 * Initialize the context's scissor state.
710 * \param ctx the GL context.
711 */
712 void
713 _mesa_init_scissor(GLcontext *ctx)
714 {
715 /* Scissor group */
716 ctx->Scissor.Enabled = GL_FALSE;
717 ctx->Scissor.X = 0;
718 ctx->Scissor.Y = 0;
719 ctx->Scissor.Width = 0;
720 ctx->Scissor.Height = 0;
721 }
722
723
724 /**
725 * Initialize the context's multisample state.
726 * \param ctx the GL context.
727 */
728 void
729 _mesa_init_multisample(GLcontext *ctx)
730 {
731 ctx->Multisample.Enabled = GL_FALSE;
732 ctx->Multisample.SampleAlphaToCoverage = GL_FALSE;
733 ctx->Multisample.SampleAlphaToOne = GL_FALSE;
734 ctx->Multisample.SampleCoverage = GL_FALSE;
735 ctx->Multisample.SampleCoverageValue = 1.0;
736 ctx->Multisample.SampleCoverageInvert = GL_FALSE;
737 }
738
739 /*@}*/