2 * Mesa 3-D graphics library
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
29 * glViewport and glDepthRange functions.
41 * \sa Called via glViewport() or display list execution.
43 * Flushes the vertices and calls _mesa_set_viewport() with the given
47 _mesa_Viewport(GLint x
, GLint y
, GLsizei width
, GLsizei height
)
49 GET_CURRENT_CONTEXT(ctx
);
50 FLUSH_VERTICES(ctx
, 0);
51 _mesa_set_viewport(ctx
, x
, y
, width
, height
);
56 * Set new viewport parameters and update derived state (the _WindowMap
57 * matrix). Usually called from _mesa_Viewport().
59 * \param ctx GL context.
60 * \param x, y coordinates of the lower left corner of the viewport rectangle.
61 * \param width width of the viewport rectangle.
62 * \param height height of the viewport rectangle.
65 _mesa_set_viewport(struct gl_context
*ctx
, GLint x
, GLint y
,
66 GLsizei width
, GLsizei height
)
68 if (MESA_VERBOSE
& VERBOSE_API
)
69 _mesa_debug(ctx
, "glViewport %d %d %d %d\n", x
, y
, width
, height
);
71 if (width
< 0 || height
< 0) {
72 _mesa_error(ctx
, GL_INVALID_VALUE
,
73 "glViewport(%d, %d, %d, %d)", x
, y
, width
, height
);
77 /* clamp width and height to the implementation dependent range */
78 width
= MIN2(width
, (GLsizei
) ctx
->Const
.MaxViewportWidth
);
79 height
= MIN2(height
, (GLsizei
) ctx
->Const
.MaxViewportHeight
);
82 ctx
->Viewport
.Width
= width
;
84 ctx
->Viewport
.Height
= height
;
85 ctx
->NewState
|= _NEW_VIEWPORT
;
88 /* XXX remove this someday. Currently the DRI drivers rely on
89 * the WindowMap matrix being up to date in the driver's Viewport
90 * and DepthRange functions.
92 _math_matrix_viewport(&ctx
->Viewport
._WindowMap
,
93 ctx
->Viewport
.X
, ctx
->Viewport
.Y
,
94 ctx
->Viewport
.Width
, ctx
->Viewport
.Height
,
95 ctx
->Viewport
.Near
, ctx
->Viewport
.Far
,
96 ctx
->DrawBuffer
->_DepthMaxF
);
99 if (ctx
->Driver
.Viewport
) {
100 /* Many drivers will use this call to check for window size changes
101 * and reallocate the z/stencil/accum/etc buffers if needed.
103 ctx
->Driver
.Viewport(ctx
, x
, y
, width
, height
);
109 * Called by glDepthRange
111 * \param nearval specifies the Z buffer value which should correspond to
112 * the near clip plane
113 * \param farval specifies the Z buffer value which should correspond to
117 _mesa_DepthRange(GLclampd nearval
, GLclampd farval
)
119 GET_CURRENT_CONTEXT(ctx
);
121 FLUSH_VERTICES(ctx
, 0);
123 if (MESA_VERBOSE
&VERBOSE_API
)
124 _mesa_debug(ctx
, "glDepthRange %f %f\n", nearval
, farval
);
126 if (ctx
->Viewport
.Near
== nearval
&&
127 ctx
->Viewport
.Far
== farval
)
130 ctx
->Viewport
.Near
= (GLfloat
) CLAMP(nearval
, 0.0, 1.0);
131 ctx
->Viewport
.Far
= (GLfloat
) CLAMP(farval
, 0.0, 1.0);
132 ctx
->NewState
|= _NEW_VIEWPORT
;
135 /* XXX remove this someday. Currently the DRI drivers rely on
136 * the WindowMap matrix being up to date in the driver's Viewport
137 * and DepthRange functions.
139 _math_matrix_viewport(&ctx
->Viewport
._WindowMap
,
140 ctx
->Viewport
.X
, ctx
->Viewport
.Y
,
141 ctx
->Viewport
.Width
, ctx
->Viewport
.Height
,
142 ctx
->Viewport
.Near
, ctx
->Viewport
.Far
,
143 ctx
->DrawBuffer
->_DepthMaxF
);
146 if (ctx
->Driver
.DepthRange
) {
147 ctx
->Driver
.DepthRange(ctx
, nearval
, farval
);
152 _mesa_DepthRangef(GLclampf nearval
, GLclampf farval
)
154 _mesa_DepthRange(nearval
, farval
);
158 * Initialize the context viewport attribute group.
159 * \param ctx the GL context.
161 void _mesa_init_viewport(struct gl_context
*ctx
)
163 GLfloat depthMax
= 65535.0F
; /* sorf of arbitrary */
168 ctx
->Viewport
.Width
= 0;
169 ctx
->Viewport
.Height
= 0;
170 ctx
->Viewport
.Near
= 0.0;
171 ctx
->Viewport
.Far
= 1.0;
172 _math_matrix_ctr(&ctx
->Viewport
._WindowMap
);
174 _math_matrix_viewport(&ctx
->Viewport
._WindowMap
, 0, 0, 0, 0,
175 0.0F
, 1.0F
, depthMax
);
180 * Free the context viewport attribute group data.
181 * \param ctx the GL context.
183 void _mesa_free_viewport_data(struct gl_context
*ctx
)
185 _math_matrix_dtr(&ctx
->Viewport
._WindowMap
);