2 * Mesa 3-D graphics library
4 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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.
28 * glViewport and glDepthRange functions.
38 set_viewport_no_notify(struct gl_context
*ctx
, unsigned idx
, GLint x
, GLint y
,
39 GLsizei width
, GLsizei height
)
41 /* clamp width and height to the implementation dependent range */
42 width
= MIN2(width
, (GLsizei
) ctx
->Const
.MaxViewportWidth
);
43 height
= MIN2(height
, (GLsizei
) ctx
->Const
.MaxViewportHeight
);
45 ctx
->ViewportArray
[idx
].X
= x
;
46 ctx
->ViewportArray
[idx
].Width
= width
;
47 ctx
->ViewportArray
[idx
].Y
= y
;
48 ctx
->ViewportArray
[idx
].Height
= height
;
49 ctx
->NewState
|= _NEW_VIEWPORT
;
52 /* XXX remove this someday. Currently the DRI drivers rely on
53 * the WindowMap matrix being up to date in the driver's Viewport
54 * and DepthRange functions.
56 _math_matrix_viewport(&ctx
->ViewportArray
[idx
]._WindowMap
,
57 ctx
->ViewportArray
[idx
].X
,
58 ctx
->ViewportArray
[idx
].Y
,
59 ctx
->ViewportArray
[idx
].Width
,
60 ctx
->ViewportArray
[idx
].Height
,
61 ctx
->ViewportArray
[idx
].Near
,
62 ctx
->ViewportArray
[idx
].Far
,
63 ctx
->DrawBuffer
->_DepthMaxF
);
69 * \sa Called via glViewport() or display list execution.
71 * Flushes the vertices and calls _mesa_set_viewport() with the given
75 _mesa_Viewport(GLint x
, GLint y
, GLsizei width
, GLsizei height
)
77 GET_CURRENT_CONTEXT(ctx
);
78 FLUSH_VERTICES(ctx
, 0);
80 if (MESA_VERBOSE
& VERBOSE_API
)
81 _mesa_debug(ctx
, "glViewport %d %d %d %d\n", x
, y
, width
, height
);
83 if (width
< 0 || height
< 0) {
84 _mesa_error(ctx
, GL_INVALID_VALUE
,
85 "glViewport(%d, %d, %d, %d)", x
, y
, width
, height
);
89 set_viewport_no_notify(ctx
, 0, x
, y
, width
, height
);
91 if (ctx
->Driver
.Viewport
) {
92 /* Many drivers will use this call to check for window size changes
93 * and reallocate the z/stencil/accum/etc buffers if needed.
95 ctx
->Driver
.Viewport(ctx
);
101 * Set new viewport parameters and update derived state (the _WindowMap
102 * matrix). Usually called from _mesa_Viewport().
104 * \param ctx GL context.
105 * \param idx Index of the viewport to be updated.
106 * \param x, y coordinates of the lower left corner of the viewport rectangle.
107 * \param width width of the viewport rectangle.
108 * \param height height of the viewport rectangle.
111 _mesa_set_viewport(struct gl_context
*ctx
, unsigned idx
, GLint x
, GLint y
,
112 GLsizei width
, GLsizei height
)
114 set_viewport_no_notify(ctx
, idx
, x
, y
, width
, height
);
116 if (ctx
->Driver
.Viewport
) {
117 /* Many drivers will use this call to check for window size changes
118 * and reallocate the z/stencil/accum/etc buffers if needed.
120 ctx
->Driver
.Viewport(ctx
);
125 set_depth_range_no_notify(struct gl_context
*ctx
, unsigned idx
,
126 GLclampd nearval
, GLclampd farval
)
128 if (ctx
->ViewportArray
[idx
].Near
== nearval
&&
129 ctx
->ViewportArray
[idx
].Far
== farval
)
132 ctx
->ViewportArray
[idx
].Near
= CLAMP(nearval
, 0.0, 1.0);
133 ctx
->ViewportArray
[idx
].Far
= CLAMP(farval
, 0.0, 1.0);
134 ctx
->NewState
|= _NEW_VIEWPORT
;
137 /* XXX remove this someday. Currently the DRI drivers rely on
138 * the WindowMap matrix being up to date in the driver's Viewport
139 * and DepthRange functions.
141 _math_matrix_viewport(&ctx
->ViewportArray
[idx
]._WindowMap
,
142 ctx
->ViewportArray
[idx
].X
,
143 ctx
->ViewportArray
[idx
].Y
,
144 ctx
->ViewportArray
[idx
].Width
,
145 ctx
->ViewportArray
[idx
].Height
,
146 ctx
->ViewportArray
[idx
].Near
,
147 ctx
->ViewportArray
[idx
].Far
,
148 ctx
->DrawBuffer
->_DepthMaxF
);
153 _mesa_set_depth_range(struct gl_context
*ctx
, unsigned idx
,
154 GLclampd nearval
, GLclampd farval
)
156 set_depth_range_no_notify(ctx
, idx
, nearval
, farval
);
158 if (ctx
->Driver
.DepthRange
)
159 ctx
->Driver
.DepthRange(ctx
);
163 * Called by glDepthRange
165 * \param nearval specifies the Z buffer value which should correspond to
166 * the near clip plane
167 * \param farval specifies the Z buffer value which should correspond to
171 _mesa_DepthRange(GLclampd nearval
, GLclampd farval
)
173 GET_CURRENT_CONTEXT(ctx
);
175 FLUSH_VERTICES(ctx
, 0);
177 if (MESA_VERBOSE
&VERBOSE_API
)
178 _mesa_debug(ctx
, "glDepthRange %f %f\n", nearval
, farval
);
180 set_depth_range_no_notify(ctx
, 0, nearval
, farval
);
182 if (ctx
->Driver
.DepthRange
) {
183 ctx
->Driver
.DepthRange(ctx
);
188 _mesa_DepthRangef(GLclampf nearval
, GLclampf farval
)
190 _mesa_DepthRange(nearval
, farval
);
194 * Initialize the context viewport attribute group.
195 * \param ctx the GL context.
197 void _mesa_init_viewport(struct gl_context
*ctx
)
199 GLfloat depthMax
= 65535.0F
; /* sorf of arbitrary */
202 /* Note: ctx->Const.MaxViewports may not have been set by the driver yet,
203 * so just initialize all of them.
205 for (i
= 0; i
< MAX_VIEWPORTS
; i
++) {
207 ctx
->ViewportArray
[i
].X
= 0;
208 ctx
->ViewportArray
[i
].Y
= 0;
209 ctx
->ViewportArray
[i
].Width
= 0;
210 ctx
->ViewportArray
[i
].Height
= 0;
211 ctx
->ViewportArray
[i
].Near
= 0.0;
212 ctx
->ViewportArray
[i
].Far
= 1.0;
213 _math_matrix_ctr(&ctx
->ViewportArray
[i
]._WindowMap
);
215 _math_matrix_viewport(&ctx
->ViewportArray
[i
]._WindowMap
, 0, 0, 0, 0,
216 0.0F
, 1.0F
, depthMax
);
222 * Free the context viewport attribute group data.
223 * \param ctx the GL context.
225 void _mesa_free_viewport_data(struct gl_context
*ctx
)
229 for (i
= 0; i
< MAX_VIEWPORTS
; i
++)
230 _math_matrix_dtr(&ctx
->ViewportArray
[i
]._WindowMap
);