1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #include "intel_context.h"
29 #include "intel_buffers.h"
30 #include "intel_fbo.h"
31 #include "intel_mipmap_tree.h"
33 #include "main/fbobject.h"
34 #include "main/framebuffer.h"
35 #include "main/renderbuffer.h"
38 * Return pointer to current color drawing region, or NULL.
41 intel_drawbuf_region(struct intel_context
*intel
)
43 struct intel_renderbuffer
*irbColor
=
44 intel_renderbuffer(intel
->ctx
.DrawBuffer
->_ColorDrawBuffers
[0]);
45 if (irbColor
&& irbColor
->mt
)
46 return irbColor
->mt
->region
;
52 * Return pointer to current color reading region, or NULL.
55 intel_readbuf_region(struct intel_context
*intel
)
57 struct intel_renderbuffer
*irb
58 = intel_renderbuffer(intel
->ctx
.ReadBuffer
->_ColorReadBuffer
);
60 return irb
->mt
->region
;
66 * Check if we're about to draw into the front color buffer.
67 * If so, set the intel->front_buffer_dirty field to true.
70 intel_check_front_buffer_rendering(struct intel_context
*intel
)
72 const struct gl_framebuffer
*fb
= intel
->ctx
.DrawBuffer
;
73 if (_mesa_is_winsys_fbo(fb
)) {
74 /* drawing to window system buffer */
75 if (fb
->_NumColorDrawBuffers
> 0) {
76 if (fb
->_ColorDrawBufferIndexes
[0] == BUFFER_FRONT_LEFT
) {
77 intel
->front_buffer_dirty
= true;
84 intelDrawBuffer(struct gl_context
* ctx
, GLenum mode
)
86 if (ctx
->DrawBuffer
&& _mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
87 struct intel_context
*const intel
= intel_context(ctx
);
88 const bool was_front_buffer_rendering
=
89 intel
->is_front_buffer_rendering
;
91 intel
->is_front_buffer_rendering
= (mode
== GL_FRONT_LEFT
)
92 || (mode
== GL_FRONT
) || (mode
== GL_FRONT_AND_BACK
);
94 /* If we weren't front-buffer rendering before but we are now,
95 * invalidate our DRI drawable so we'll ask for new buffers
96 * (including the fake front) before we start rendering again.
98 if (!was_front_buffer_rendering
&& intel
->is_front_buffer_rendering
)
99 dri2InvalidateDrawable(intel
->driContext
->driDrawablePriv
);
102 intel_draw_buffer(ctx
);
107 intelReadBuffer(struct gl_context
* ctx
, GLenum mode
)
109 if (ctx
->DrawBuffer
&& _mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
110 struct intel_context
*const intel
= intel_context(ctx
);
111 const bool was_front_buffer_reading
=
112 intel
->is_front_buffer_reading
;
114 intel
->is_front_buffer_reading
= (mode
== GL_FRONT_LEFT
)
115 || (mode
== GL_FRONT
);
117 /* If we weren't front-buffer reading before but we are now,
118 * invalidate our DRI drawable so we'll ask for new buffers
119 * (including the fake front) before we start reading again.
121 if (!was_front_buffer_reading
&& intel
->is_front_buffer_reading
)
122 dri2InvalidateDrawable(intel
->driContext
->driReadablePriv
);
128 intelInitBufferFuncs(struct dd_function_table
*functions
)
130 functions
->DrawBuffer
= intelDrawBuffer
;
131 functions
->ReadBuffer
= intelReadBuffer
;