removed obsolete _mesa_pack_rgba_span_chan()
[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-2006 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->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
136 _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
137 "glClear(incomplete framebuffer)");
138 return;
139 }
140
141 if (ctx->RenderMode == GL_RENDER) {
142 const GLint x = ctx->DrawBuffer->_Xmin;
143 const GLint y = ctx->DrawBuffer->_Ymin;
144 const GLint height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
145 const GLint width = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
146 GLbitfield bufferMask;
147
148 /* don't clear depth buffer if depth writing disabled */
149 if (!ctx->Depth.Mask)
150 mask &= ~GL_DEPTH_BUFFER_BIT;
151
152 /* Build the bitmask to send to device driver's Clear function.
153 * Note that the GL_COLOR_BUFFER_BIT flag will expand to 0, 1, 2 or 4
154 * of the BUFFER_BIT_FRONT/BACK_LEFT/RIGHT flags, or one of the
155 * BUFFER_BIT_COLORn flags.
156 */
157 bufferMask = 0;
158 if (mask & GL_COLOR_BUFFER_BIT) {
159 bufferMask |= ctx->DrawBuffer->_ColorDrawBufferMask[0];
160 }
161
162 if ((mask & GL_DEPTH_BUFFER_BIT)
163 && ctx->DrawBuffer->Visual.haveDepthBuffer) {
164 bufferMask |= BUFFER_BIT_DEPTH;
165 }
166
167 if ((mask & GL_STENCIL_BUFFER_BIT)
168 && ctx->DrawBuffer->Visual.haveStencilBuffer) {
169 bufferMask |= BUFFER_BIT_STENCIL;
170 }
171
172 if ((mask & GL_ACCUM_BUFFER_BIT)
173 && ctx->DrawBuffer->Visual.haveAccumBuffer) {
174 bufferMask |= BUFFER_BIT_ACCUM;
175 }
176
177 ASSERT(ctx->Driver.Clear);
178 ctx->Driver.Clear( ctx, bufferMask, (GLboolean) !ctx->Scissor.Enabled,
179 x, y, width, height );
180 }
181 }
182
183
184
185 /**
186 * Return bitmask of BUFFER_BIT_* flags indicating which color buffers are
187 * available to the rendering context.
188 * This depends on the framebuffer we're writing to. For window system
189 * framebuffers we look at the framebuffer's visual. But for user-
190 * create framebuffers we look at the number of supported color attachments.
191 */
192 static GLbitfield
193 supported_buffer_bitmask(const GLcontext *ctx, GLuint framebufferID)
194 {
195 GLbitfield mask = 0x0;
196
197 if (framebufferID > 0) {
198 /* A user-created renderbuffer */
199 GLuint i;
200 ASSERT(ctx->Extensions.EXT_framebuffer_object);
201 for (i = 0; i < ctx->Const.MaxColorAttachments; i++) {
202 mask |= (BUFFER_BIT_COLOR0 << i);
203 }
204 }
205 else {
206 /* A window system renderbuffer */
207 GLint i;
208 mask = BUFFER_BIT_FRONT_LEFT; /* always have this */
209 if (ctx->Visual.stereoMode) {
210 mask |= BUFFER_BIT_FRONT_RIGHT;
211 if (ctx->Visual.doubleBufferMode) {
212 mask |= BUFFER_BIT_BACK_LEFT | BUFFER_BIT_BACK_RIGHT;
213 }
214 }
215 else if (ctx->Visual.doubleBufferMode) {
216 mask |= BUFFER_BIT_BACK_LEFT;
217 }
218
219 for (i = 0; i < ctx->Visual.numAuxBuffers; i++) {
220 mask |= (BUFFER_BIT_AUX0 << i);
221 }
222 }
223
224 return mask;
225 }
226
227
228 /**
229 * Helper routine used by glDrawBuffer and glDrawBuffersARB.
230 * Given a GLenum naming one or more color buffers (such as
231 * GL_FRONT_AND_BACK), return the corresponding bitmask of BUFFER_BIT_* flags.
232 */
233 static GLbitfield
234 draw_buffer_enum_to_bitmask(GLenum buffer)
235 {
236 switch (buffer) {
237 case GL_NONE:
238 return 0;
239 case GL_FRONT:
240 return BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_FRONT_RIGHT;
241 case GL_BACK:
242 return BUFFER_BIT_BACK_LEFT | BUFFER_BIT_BACK_RIGHT;
243 case GL_RIGHT:
244 return BUFFER_BIT_FRONT_RIGHT | BUFFER_BIT_BACK_RIGHT;
245 case GL_FRONT_RIGHT:
246 return BUFFER_BIT_FRONT_RIGHT;
247 case GL_BACK_RIGHT:
248 return BUFFER_BIT_BACK_RIGHT;
249 case GL_BACK_LEFT:
250 return BUFFER_BIT_BACK_LEFT;
251 case GL_FRONT_AND_BACK:
252 return BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT
253 | BUFFER_BIT_FRONT_RIGHT | BUFFER_BIT_BACK_RIGHT;
254 case GL_LEFT:
255 return BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT;
256 case GL_FRONT_LEFT:
257 return BUFFER_BIT_FRONT_LEFT;
258 case GL_AUX0:
259 return BUFFER_BIT_AUX0;
260 case GL_AUX1:
261 return BUFFER_BIT_AUX1;
262 case GL_AUX2:
263 return BUFFER_BIT_AUX2;
264 case GL_AUX3:
265 return BUFFER_BIT_AUX3;
266 case GL_COLOR_ATTACHMENT0_EXT:
267 return BUFFER_BIT_COLOR0;
268 case GL_COLOR_ATTACHMENT1_EXT:
269 return BUFFER_BIT_COLOR1;
270 case GL_COLOR_ATTACHMENT2_EXT:
271 return BUFFER_BIT_COLOR2;
272 case GL_COLOR_ATTACHMENT3_EXT:
273 return BUFFER_BIT_COLOR3;
274 default:
275 /* error */
276 return BAD_MASK;
277 }
278 }
279
280
281 /**
282 * Helper routine used by glReadBuffer.
283 * Given a GLenum naming a color buffer, return the index of the corresponding
284 * renderbuffer (a BUFFER_* value).
285 * return -1 for an invalid buffer.
286 */
287 static GLint
288 read_buffer_enum_to_index(GLenum buffer)
289 {
290 switch (buffer) {
291 case GL_FRONT:
292 return BUFFER_FRONT_LEFT;
293 case GL_BACK:
294 return BUFFER_BACK_LEFT;
295 case GL_RIGHT:
296 return BUFFER_FRONT_RIGHT;
297 case GL_FRONT_RIGHT:
298 return BUFFER_FRONT_RIGHT;
299 case GL_BACK_RIGHT:
300 return BUFFER_BACK_RIGHT;
301 case GL_BACK_LEFT:
302 return BUFFER_BACK_LEFT;
303 case GL_LEFT:
304 return BUFFER_FRONT_LEFT;
305 case GL_FRONT_LEFT:
306 return BUFFER_FRONT_LEFT;
307 case GL_AUX0:
308 return BUFFER_AUX0;
309 case GL_AUX1:
310 return BUFFER_AUX1;
311 case GL_AUX2:
312 return BUFFER_AUX2;
313 case GL_AUX3:
314 return BUFFER_AUX3;
315 case GL_COLOR_ATTACHMENT0_EXT:
316 return BUFFER_COLOR0;
317 case GL_COLOR_ATTACHMENT1_EXT:
318 return BUFFER_COLOR1;
319 case GL_COLOR_ATTACHMENT2_EXT:
320 return BUFFER_COLOR2;
321 case GL_COLOR_ATTACHMENT3_EXT:
322 return BUFFER_COLOR3;
323 default:
324 /* error */
325 return -1;
326 }
327 }
328
329
330 /**
331 * Called by glDrawBuffer().
332 * Specify which renderbuffer(s) to draw into for the first color output.
333 * <buffer> can name zero, one, two or four renderbuffers!
334 * \sa _mesa_DrawBuffersARB
335 *
336 * \param buffer buffer token such as GL_LEFT or GL_FRONT_AND_BACK, etc.
337 */
338 void GLAPIENTRY
339 _mesa_DrawBuffer(GLenum buffer)
340 {
341 GLuint bufferID;
342 GLbitfield destMask;
343 GET_CURRENT_CONTEXT(ctx);
344 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex... */
345
346 if (MESA_VERBOSE & VERBOSE_API) {
347 _mesa_debug(ctx, "glDrawBuffer %s\n", _mesa_lookup_enum_by_nr(buffer));
348 }
349
350 bufferID = ctx->DrawBuffer->Name;
351
352 if (buffer == GL_NONE) {
353 destMask = 0x0;
354 }
355 else {
356 const GLbitfield supportedMask = supported_buffer_bitmask(ctx, bufferID);
357 destMask = draw_buffer_enum_to_bitmask(buffer);
358 if (destMask == BAD_MASK) {
359 /* totally bogus buffer */
360 _mesa_error(ctx, GL_INVALID_ENUM, "glDrawBuffer(buffer)");
361 return;
362 }
363 destMask &= supportedMask;
364 if (destMask == 0x0) {
365 /* none of the named color buffers exist! */
366 _mesa_error(ctx, GL_INVALID_OPERATION, "glDrawBuffer(buffer)");
367 return;
368 }
369 }
370
371 /* if we get here, there's no error so set new state */
372 _mesa_drawbuffers(ctx, 1, &buffer, &destMask);
373 }
374
375
376 /**
377 * Called by glDrawBuffersARB; specifies the destination color renderbuffers
378 * for N fragment program color outputs.
379 * \sa _mesa_DrawBuffer
380 * \param n number of outputs
381 * \param buffers array [n] of renderbuffer names. Unlike glDrawBuffer, the
382 * names cannot specify more than one buffer. For example,
383 * GL_FRONT_AND_BACK is illegal.
384 */
385 void GLAPIENTRY
386 _mesa_DrawBuffersARB(GLsizei n, const GLenum *buffers)
387 {
388 GLint output;
389 GLuint bufferID;
390 GLbitfield usedBufferMask, supportedMask;
391 GLbitfield destMask[MAX_DRAW_BUFFERS];
392 GET_CURRENT_CONTEXT(ctx);
393 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
394
395 if (!ctx->Extensions.ARB_draw_buffers) {
396 _mesa_error(ctx, GL_INVALID_OPERATION, "glDrawBuffersARB");
397 return;
398 }
399 if (n < 1 || n > (GLsizei) ctx->Const.MaxDrawBuffers) {
400 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawBuffersARB(n)");
401 return;
402 }
403
404 bufferID = ctx->DrawBuffer->Name;
405
406 supportedMask = supported_buffer_bitmask(ctx, bufferID);
407 usedBufferMask = 0x0;
408
409 /* complicated error checking... */
410 for (output = 0; output < n; output++) {
411 if (buffers[output] == GL_NONE) {
412 destMask[output] = 0x0;
413 }
414 else {
415 destMask[output] = draw_buffer_enum_to_bitmask(buffers[output]);
416 if (destMask[output] == BAD_MASK
417 || _mesa_bitcount(destMask[output]) > 1) {
418 _mesa_error(ctx, GL_INVALID_ENUM, "glDrawBuffersARB(buffer)");
419 return;
420 }
421 destMask[output] &= supportedMask;
422 if (destMask[output] == 0) {
423 _mesa_error(ctx, GL_INVALID_OPERATION,
424 "glDrawBuffersARB(unsupported buffer)");
425 return;
426 }
427 if (destMask[output] & usedBufferMask) {
428 /* can't specify a dest buffer more than once! */
429 _mesa_error(ctx, GL_INVALID_OPERATION,
430 "glDrawBuffersARB(duplicated buffer)");
431 return;
432 }
433
434 /* update bitmask */
435 usedBufferMask |= destMask[output];
436 }
437 }
438
439 /* OK, if we get here, there were no errors so set the new state */
440 _mesa_drawbuffers(ctx, n, buffers, destMask);
441 }
442
443
444 /**
445 * Set color output state. Traditionally, there was only one color
446 * output, but fragment programs can now have several distinct color
447 * outputs (see GL_ARB_draw_buffers). This function sets the state
448 * for one such color output.
449 * \param ctx current context
450 * \param output which fragment program output
451 * \param buffer buffer to write to (like GL_LEFT)
452 * \param destMask BUFFER_* bitmask
453 * (like BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT).
454 */
455 static void
456 set_color_output(GLcontext *ctx, GLuint output, GLenum buffer,
457 GLbitfield destMask)
458 {
459 struct gl_framebuffer *fb = ctx->DrawBuffer;
460
461 ASSERT(output < ctx->Const.MaxDrawBuffers);
462
463 /* Set per-FBO state */
464 fb->ColorDrawBuffer[output] = buffer;
465 fb->_ColorDrawBufferMask[output] = destMask;
466 /* not really needed, will be set later */
467 fb->_NumColorDrawBuffers[output] = 0;
468
469 /* Set traditional state var */
470 ctx->Color.DrawBuffer[output] = buffer;
471 }
472
473
474 /**
475 * Helper routine used by _mesa_DrawBuffer, _mesa_DrawBuffersARB and
476 * _mesa_PopAttrib to set drawbuffer state.
477 * All error checking will have been done prior to calling this function
478 * so nothing should go wrong at this point.
479 * \param ctx current context
480 * \param n number of color outputs to set
481 * \param buffers array[n] of colorbuffer names, like GL_LEFT.
482 * \param destMask array[n] of BUFFER_* bitmasks which correspond to the
483 * colorbuffer names. (i.e. GL_FRONT_AND_BACK =>
484 * BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT).
485 */
486 void
487 _mesa_drawbuffers(GLcontext *ctx, GLuint n, const GLenum *buffers,
488 const GLbitfield *destMask)
489 {
490 GLbitfield mask[MAX_DRAW_BUFFERS];
491 GLuint output;
492
493 if (!destMask) {
494 /* compute destMask values now */
495 const GLuint bufferID = ctx->DrawBuffer->Name;
496 const GLbitfield supportedMask = supported_buffer_bitmask(ctx, bufferID);
497 for (output = 0; output < n; output++) {
498 mask[output] = draw_buffer_enum_to_bitmask(buffers[output]);
499 ASSERT(mask[output] != BAD_MASK);
500 mask[output] &= supportedMask;
501 }
502 destMask = mask;
503 }
504
505 for (output = 0; output < n; output++) {
506 set_color_output(ctx, output, buffers[output], destMask[output]);
507 }
508
509 /* set remaining color outputs to NONE */
510 for (output = n; output < ctx->Const.MaxDrawBuffers; output++) {
511 set_color_output(ctx, output, GL_NONE, 0x0);
512 }
513
514 ctx->NewState |= _NEW_COLOR;
515
516 /*
517 * Call device driver function.
518 */
519 if (ctx->Driver.DrawBuffers)
520 ctx->Driver.DrawBuffers(ctx, n, buffers);
521 else if (ctx->Driver.DrawBuffer)
522 ctx->Driver.DrawBuffer(ctx, buffers[0]);
523 }
524
525
526
527 /**
528 * Called by glReadBuffer to set the source renderbuffer for reading pixels.
529 * \param mode color buffer such as GL_FRONT, GL_BACK, etc.
530 */
531 void GLAPIENTRY
532 _mesa_ReadBuffer(GLenum buffer)
533 {
534 struct gl_framebuffer *fb;
535 GLbitfield supportedMask;
536 GLint srcBuffer;
537 GLuint bufferID;
538 GET_CURRENT_CONTEXT(ctx);
539 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
540
541 fb = ctx->ReadBuffer;
542 bufferID = fb->Name;
543
544 if (MESA_VERBOSE & VERBOSE_API)
545 _mesa_debug(ctx, "glReadBuffer %s\n", _mesa_lookup_enum_by_nr(buffer));
546
547 if (bufferID > 0 && buffer == GL_NONE) {
548 /* This is legal for user-created framebuffer objects */
549 srcBuffer = -1;
550 }
551 else {
552 /* general case / window-system framebuffer */
553 srcBuffer = read_buffer_enum_to_index(buffer);
554 if (srcBuffer == -1) {
555 _mesa_error(ctx, GL_INVALID_ENUM, "glReadBuffer(buffer=0x%x)", buffer);
556 return;
557 }
558 supportedMask = supported_buffer_bitmask(ctx, bufferID);
559 if (((1 << srcBuffer) & supportedMask) == 0) {
560 _mesa_error(ctx, GL_INVALID_OPERATION, "glReadBuffer(buffer=0x%x)", buffer);
561 return;
562 }
563 }
564
565 if (bufferID == 0) {
566 ctx->Pixel.ReadBuffer = buffer;
567 }
568 fb->ColorReadBuffer = buffer;
569 fb->_ColorReadBufferIndex = srcBuffer;
570
571 ctx->NewState |= _NEW_PIXEL;
572
573 /*
574 * Call device driver function.
575 */
576 if (ctx->Driver.ReadBuffer)
577 (*ctx->Driver.ReadBuffer)(ctx, buffer);
578 }
579
580
581 #if _HAVE_FULL_GL
582
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->WinSysDrawBuffer) {
603 GLuint newWidth, newHeight;
604 GLframebuffer *buffer = ctx->WinSysDrawBuffer;
605
606 assert(buffer->Name == 0);
607
608 /* ask device driver for size of output buffer */
609 ctx->Driver.GetBufferSize( buffer, &newWidth, &newHeight );
610
611 /* see if size of device driver's color buffer (window) has changed */
612 if (buffer->Width != newWidth || buffer->Height != newHeight) {
613 if (ctx->Driver.ResizeBuffers)
614 ctx->Driver.ResizeBuffers(ctx, buffer, newWidth, newHeight );
615 }
616 }
617
618 if (ctx->WinSysReadBuffer
619 && ctx->WinSysReadBuffer != ctx->WinSysDrawBuffer) {
620 GLuint newWidth, newHeight;
621 GLframebuffer *buffer = ctx->WinSysReadBuffer;
622
623 assert(buffer->Name == 0);
624
625 /* ask device driver for size of read buffer */
626 ctx->Driver.GetBufferSize( buffer, &newWidth, &newHeight );
627
628 /* see if size of device driver's color buffer (window) has changed */
629 if (buffer->Width != newWidth || buffer->Height != newHeight) {
630 if (ctx->Driver.ResizeBuffers)
631 ctx->Driver.ResizeBuffers(ctx, buffer, newWidth, newHeight );
632 }
633 }
634
635 ctx->NewState |= _NEW_BUFFERS; /* to update scissor / window bounds */
636 }
637
638 void GLAPIENTRY
639 _mesa_ResizeBuffersMESA( void )
640 {
641 GET_CURRENT_CONTEXT(ctx);
642
643 _mesa_resizebuffers( ctx );
644 }
645
646
647 /*
648 * XXX move somewhere else someday?
649 */
650 void GLAPIENTRY
651 _mesa_SampleCoverageARB(GLclampf value, GLboolean invert)
652 {
653 GET_CURRENT_CONTEXT(ctx);
654
655 if (!ctx->Extensions.ARB_multisample) {
656 _mesa_error(ctx, GL_INVALID_OPERATION, "glSampleCoverageARB");
657 return;
658 }
659
660 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx );
661 ctx->Multisample.SampleCoverageValue = (GLfloat) CLAMP(value, 0.0, 1.0);
662 ctx->Multisample.SampleCoverageInvert = invert;
663 ctx->NewState |= _NEW_MULTISAMPLE;
664 }
665
666 #endif /* _HAVE_FULL_GL */
667
668
669
670 /**
671 * Define the scissor box.
672 *
673 * \param x, y coordinates of the scissor box lower-left corner.
674 * \param width width of the scissor box.
675 * \param height height of the scissor box.
676 *
677 * \sa glScissor().
678 *
679 * Verifies the parameters and updates __GLcontextRec::Scissor. On a
680 * change flushes the vertices and notifies the driver via
681 * the dd_function_table::Scissor callback.
682 */
683 void
684 _mesa_set_scissor(GLcontext *ctx,
685 GLint x, GLint y, GLsizei width, GLsizei height)
686 {
687 if (x == ctx->Scissor.X &&
688 y == ctx->Scissor.Y &&
689 width == ctx->Scissor.Width &&
690 height == ctx->Scissor.Height)
691 return;
692
693 FLUSH_VERTICES(ctx, _NEW_SCISSOR);
694 ctx->Scissor.X = x;
695 ctx->Scissor.Y = y;
696 ctx->Scissor.Width = width;
697 ctx->Scissor.Height = height;
698
699 if (ctx->Driver.Scissor)
700 ctx->Driver.Scissor( ctx, x, y, width, height );
701 }
702
703
704 void GLAPIENTRY
705 _mesa_Scissor( GLint x, GLint y, GLsizei width, GLsizei height )
706 {
707 GET_CURRENT_CONTEXT(ctx);
708 ASSERT_OUTSIDE_BEGIN_END(ctx);
709
710 if (width < 0 || height < 0) {
711 _mesa_error( ctx, GL_INVALID_VALUE, "glScissor" );
712 return;
713 }
714
715 if (MESA_VERBOSE & VERBOSE_API)
716 _mesa_debug(ctx, "glScissor %d %d %d %d\n", x, y, width, height);
717
718 _mesa_set_scissor(ctx, x, y, width, height);
719 }
720
721
722
723 /**********************************************************************/
724 /** \name Initialization */
725 /*@{*/
726
727 /**
728 * Initialize the context's scissor state.
729 * \param ctx the GL context.
730 */
731 void
732 _mesa_init_scissor(GLcontext *ctx)
733 {
734 /* Scissor group */
735 ctx->Scissor.Enabled = GL_FALSE;
736 ctx->Scissor.X = 0;
737 ctx->Scissor.Y = 0;
738 ctx->Scissor.Width = 0;
739 ctx->Scissor.Height = 0;
740 }
741
742
743 /**
744 * Initialize the context's multisample state.
745 * \param ctx the GL context.
746 */
747 void
748 _mesa_init_multisample(GLcontext *ctx)
749 {
750 ctx->Multisample.Enabled = GL_FALSE;
751 ctx->Multisample.SampleAlphaToCoverage = GL_FALSE;
752 ctx->Multisample.SampleAlphaToOne = GL_FALSE;
753 ctx->Multisample.SampleCoverage = GL_FALSE;
754 ctx->Multisample.SampleCoverageValue = 1.0;
755 ctx->Multisample.SampleCoverageInvert = GL_FALSE;
756 }
757
758 /*@}*/