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