Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4358 | Serge | 1 | /* |
2 | * Mesa 3-D graphics library |
||
3 | * |
||
4 | * Copyright (C) 2009 VMware, Inc. All Rights Reserved. |
||
5 | * |
||
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: |
||
12 | * |
||
13 | * The above copyright notice and this permission notice shall be included |
||
14 | * in all copies or substantial portions of the Software. |
||
15 | * |
||
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. |
||
23 | */ |
||
24 | |||
25 | |||
26 | /** |
||
27 | * \file viewport.c |
||
28 | * glViewport and glDepthRange functions. |
||
29 | */ |
||
30 | |||
31 | |||
32 | #include "context.h" |
||
33 | #include "macros.h" |
||
34 | #include "mtypes.h" |
||
35 | #include "viewport.h" |
||
36 | |||
37 | |||
38 | /** |
||
39 | * Set the viewport. |
||
40 | * \sa Called via glViewport() or display list execution. |
||
41 | * |
||
42 | * Flushes the vertices and calls _mesa_set_viewport() with the given |
||
43 | * parameters. |
||
44 | */ |
||
45 | void GLAPIENTRY |
||
46 | _mesa_Viewport(GLint x, GLint y, GLsizei width, GLsizei height) |
||
47 | { |
||
48 | GET_CURRENT_CONTEXT(ctx); |
||
49 | FLUSH_VERTICES(ctx, 0); |
||
50 | _mesa_set_viewport(ctx, x, y, width, height); |
||
51 | } |
||
52 | |||
53 | |||
54 | /** |
||
55 | * Set new viewport parameters and update derived state (the _WindowMap |
||
56 | * matrix). Usually called from _mesa_Viewport(). |
||
57 | * |
||
58 | * \param ctx GL context. |
||
59 | * \param x, y coordinates of the lower left corner of the viewport rectangle. |
||
60 | * \param width width of the viewport rectangle. |
||
61 | * \param height height of the viewport rectangle. |
||
62 | */ |
||
63 | void |
||
64 | _mesa_set_viewport(struct gl_context *ctx, GLint x, GLint y, |
||
65 | GLsizei width, GLsizei height) |
||
66 | { |
||
67 | if (MESA_VERBOSE & VERBOSE_API) |
||
68 | _mesa_debug(ctx, "glViewport %d %d %d %d\n", x, y, width, height); |
||
69 | |||
70 | if (width < 0 || height < 0) { |
||
71 | _mesa_error(ctx, GL_INVALID_VALUE, |
||
72 | "glViewport(%d, %d, %d, %d)", x, y, width, height); |
||
73 | return; |
||
74 | } |
||
75 | |||
76 | /* clamp width and height to the implementation dependent range */ |
||
77 | width = MIN2(width, (GLsizei) ctx->Const.MaxViewportWidth); |
||
78 | height = MIN2(height, (GLsizei) ctx->Const.MaxViewportHeight); |
||
79 | |||
80 | ctx->Viewport.X = x; |
||
81 | ctx->Viewport.Width = width; |
||
82 | ctx->Viewport.Y = y; |
||
83 | ctx->Viewport.Height = height; |
||
84 | ctx->NewState |= _NEW_VIEWPORT; |
||
85 | |||
86 | #if 1 |
||
87 | /* XXX remove this someday. Currently the DRI drivers rely on |
||
88 | * the WindowMap matrix being up to date in the driver's Viewport |
||
89 | * and DepthRange functions. |
||
90 | */ |
||
91 | _math_matrix_viewport(&ctx->Viewport._WindowMap, |
||
92 | ctx->Viewport.X, ctx->Viewport.Y, |
||
93 | ctx->Viewport.Width, ctx->Viewport.Height, |
||
94 | ctx->Viewport.Near, ctx->Viewport.Far, |
||
95 | ctx->DrawBuffer->_DepthMaxF); |
||
96 | #endif |
||
97 | |||
98 | if (ctx->Driver.Viewport) { |
||
99 | /* Many drivers will use this call to check for window size changes |
||
100 | * and reallocate the z/stencil/accum/etc buffers if needed. |
||
101 | */ |
||
102 | ctx->Driver.Viewport(ctx, x, y, width, height); |
||
103 | } |
||
104 | } |
||
105 | |||
106 | |||
107 | /** |
||
108 | * Called by glDepthRange |
||
109 | * |
||
110 | * \param nearval specifies the Z buffer value which should correspond to |
||
111 | * the near clip plane |
||
112 | * \param farval specifies the Z buffer value which should correspond to |
||
113 | * the far clip plane |
||
114 | */ |
||
115 | void GLAPIENTRY |
||
116 | _mesa_DepthRange(GLclampd nearval, GLclampd farval) |
||
117 | { |
||
118 | GET_CURRENT_CONTEXT(ctx); |
||
119 | |||
120 | FLUSH_VERTICES(ctx, 0); |
||
121 | |||
122 | if (MESA_VERBOSE&VERBOSE_API) |
||
123 | _mesa_debug(ctx, "glDepthRange %f %f\n", nearval, farval); |
||
124 | |||
125 | if (ctx->Viewport.Near == nearval && |
||
126 | ctx->Viewport.Far == farval) |
||
127 | return; |
||
128 | |||
129 | ctx->Viewport.Near = (GLfloat) CLAMP(nearval, 0.0, 1.0); |
||
130 | ctx->Viewport.Far = (GLfloat) CLAMP(farval, 0.0, 1.0); |
||
131 | ctx->NewState |= _NEW_VIEWPORT; |
||
132 | |||
133 | #if 1 |
||
134 | /* XXX remove this someday. Currently the DRI drivers rely on |
||
135 | * the WindowMap matrix being up to date in the driver's Viewport |
||
136 | * and DepthRange functions. |
||
137 | */ |
||
138 | _math_matrix_viewport(&ctx->Viewport._WindowMap, |
||
139 | ctx->Viewport.X, ctx->Viewport.Y, |
||
140 | ctx->Viewport.Width, ctx->Viewport.Height, |
||
141 | ctx->Viewport.Near, ctx->Viewport.Far, |
||
142 | ctx->DrawBuffer->_DepthMaxF); |
||
143 | #endif |
||
144 | |||
145 | if (ctx->Driver.DepthRange) { |
||
146 | ctx->Driver.DepthRange(ctx, nearval, farval); |
||
147 | } |
||
148 | } |
||
149 | |||
150 | void GLAPIENTRY |
||
151 | _mesa_DepthRangef(GLclampf nearval, GLclampf farval) |
||
152 | { |
||
153 | _mesa_DepthRange(nearval, farval); |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * Initialize the context viewport attribute group. |
||
158 | * \param ctx the GL context. |
||
159 | */ |
||
160 | void _mesa_init_viewport(struct gl_context *ctx) |
||
161 | { |
||
162 | GLfloat depthMax = 65535.0F; /* sorf of arbitrary */ |
||
163 | |||
164 | /* Viewport group */ |
||
165 | ctx->Viewport.X = 0; |
||
166 | ctx->Viewport.Y = 0; |
||
167 | ctx->Viewport.Width = 0; |
||
168 | ctx->Viewport.Height = 0; |
||
169 | ctx->Viewport.Near = 0.0; |
||
170 | ctx->Viewport.Far = 1.0; |
||
171 | _math_matrix_ctr(&ctx->Viewport._WindowMap); |
||
172 | |||
173 | _math_matrix_viewport(&ctx->Viewport._WindowMap, 0, 0, 0, 0, |
||
174 | 0.0F, 1.0F, depthMax); |
||
175 | } |
||
176 | |||
177 | |||
178 | /** |
||
179 | * Free the context viewport attribute group data. |
||
180 | * \param ctx the GL context. |
||
181 | */ |
||
182 | void _mesa_free_viewport_data(struct gl_context *ctx) |
||
183 | { |
||
184 | _math_matrix_dtr(&ctx->Viewport._WindowMap); |
||
185 | }>> |
||
186 |