Fixed off by one errors in clipping.
[mesa.git] / src / mesa / drivers / dri / i915 / i915_context.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * 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
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 #include "i915_context.h"
29 #include "imports.h"
30 #include "intel_tex.h"
31 #include "intel_tris.h"
32 #include "tnl/t_context.h"
33 #include "tnl/t_pipeline.h"
34 #include "tnl/t_vertex.h"
35
36 #include "swrast/swrast.h"
37 #include "swrast_setup/swrast_setup.h"
38 #include "tnl/tnl.h"
39 #include "array_cache/acache.h"
40
41 #include "utils.h"
42 #include "i915_reg.h"
43
44 /***************************************
45 * Mesa's Driver Functions
46 ***************************************/
47
48 static const char * const card_extensions[] =
49 {
50 "GL_ARB_fragment_program",
51 NULL
52 };
53
54 /* Override intel default.
55 */
56 static void i915InvalidateState( GLcontext *ctx, GLuint new_state )
57 {
58 _swrast_InvalidateState( ctx, new_state );
59 _swsetup_InvalidateState( ctx, new_state );
60 _ac_InvalidateState( ctx, new_state );
61 _tnl_InvalidateState( ctx, new_state );
62 _tnl_invalidate_vertex_state( ctx, new_state );
63 INTEL_CONTEXT(ctx)->NewGLState |= new_state;
64
65 /* Todo: gather state values under which tracked parameters become
66 * invalidated, add callbacks for things like
67 * ProgramLocalParameters, etc.
68 */
69 {
70 struct i915_fragment_program *p =
71 (struct i915_fragment_program *)ctx->FragmentProgram.Current;
72 if (p->nr_params)
73 p->params_uptodate = 0;
74 }
75
76 }
77
78 /* This is the extension list explicitly enabled by the client and
79 * excludes functionality available in Mesa and also excludes legacy
80 * extensions. It is recognized that in an open source driver, those
81 * extensions will probably be re-enabled.
82 */
83 static const GLubyte *i915GetString( GLcontext *ctx, GLenum name )
84 {
85 if (name == GL_EXTENSIONS)
86 return
87 "GL_ARB_fragment_program "
88 "GL_ARB_multitexture "
89 "GL_ARB_point_parameters "
90 "GL_ARB_texture_border_clamp "
91 "GL_ARB_texture_compression "
92 "GL_ARB_texture_cube_map "
93 "GL_ARB_texture_env_add "
94 "GL_ARB_texture_env_combine "
95 "GL_ARB_texture_env_dot3 "
96 "GL_ARB_texture_mirrored_repeat "
97 "GL_ARB_transpose_matrix "
98 "GL_ARB_vertex_buffer_object "
99 "GL_ARB_vertex_program "
100 "GL_ARB_window_pos "
101 "GL_EXT_abgr "
102 "GL_EXT_bgra "
103 "GL_EXT_blend_color "
104 "GL_EXT_blend_func_separate "
105 "GL_EXT_blend_minmax "
106 "GL_EXT_blend_subtract "
107 "GL_EXT_clip_volume_hint "
108 "GL_EXT_compiled_vertex_array "
109 "GL_EXT_draw_range_elements "
110 "GL_EXT_fog_coord "
111 "GL_EXT_multi_draw_arrays "
112 "GL_EXT_packed_pixels "
113 "GL_EXT_rescale_normal "
114 "GL_EXT_secondary_color "
115 "GL_EXT_separate_specular_color "
116 "GL_EXT_stencil_wrap "
117 "GL_EXT_texture3D "
118 "GL_EXT_texture_env_add "
119 "GL_EXT_texture_env_combine "
120 "GL_EXT_texture_filter_anisotropic "
121 "GL_IBM_texture_mirrored_repeat "
122 "GL_MESA_ycbcr_texture "
123 "GL_MESA_window_pos "
124 "GL_NV_texgen_reflection "
125 "GL_SGIS_generate_mipmap";
126
127 return intelGetString( ctx, name );
128 }
129
130
131 static void i915InitDriverFunctions( struct dd_function_table *functions )
132 {
133 intelInitDriverFunctions( functions );
134 i915InitStateFunctions( functions );
135 i915InitTextureFuncs( functions );
136 i915InitFragProgFuncs( functions );
137 functions->UpdateState = i915InvalidateState;
138 functions->GetString = i915GetString;
139 }
140
141
142
143 GLboolean i915CreateContext( const __GLcontextModes *mesaVis,
144 __DRIcontextPrivate *driContextPriv,
145 void *sharedContextPrivate)
146 {
147 struct dd_function_table functions;
148 i915ContextPtr i915 = (i915ContextPtr) CALLOC_STRUCT(i915_context);
149 intelContextPtr intel = &i915->intel;
150 GLcontext *ctx = &intel->ctx;
151
152 if (!i915) return GL_FALSE;
153
154 i915InitVtbl( i915 );
155
156 i915InitDriverFunctions( &functions );
157
158 if (!intelInitContext( intel, mesaVis, driContextPriv,
159 sharedContextPrivate, &functions )) {
160 FREE(i915);
161 return GL_FALSE;
162 }
163
164 ctx->Const.MaxTextureUnits = I915_TEX_UNITS;
165 ctx->Const.MaxTextureImageUnits = I915_TEX_UNITS;
166 ctx->Const.MaxTextureCoordUnits = I915_TEX_UNITS;
167
168 intel->nr_heaps = 1;
169 intel->texture_heaps[0] =
170 driCreateTextureHeap( 0, intel,
171 intel->intelScreen->textureSize,
172 12,
173 I830_NR_TEX_REGIONS,
174 intel->sarea->texList,
175 & intel->sarea->texAge,
176 & intel->swapped,
177 sizeof( struct i915_texture_object ),
178 (destroy_texture_object_t *)intelDestroyTexObj );
179
180 /* FIXME: driCalculateMaxTextureLevels assumes that mipmaps are tightly
181 * FIXME: packed, but they're not in Intel graphics hardware.
182 */
183 ctx->Const.MaxTextureUnits = 1;
184 driCalculateMaxTextureLevels( intel->texture_heaps,
185 intel->nr_heaps,
186 &intel->ctx.Const,
187 4,
188 11, /* max 2D texture size is 2048x2048 */
189 8, /* 3D texture */
190 11, /* cube texture. */
191 11, /* rect texture */
192 12,
193 GL_FALSE );
194 ctx->Const.MaxTextureUnits = I915_TEX_UNITS;
195
196 /* GL_ARB_fragment_program limits - don't think Mesa actually
197 * validates programs against these, and in any case one ARB
198 * instruction can translate to more than one HW instruction, so
199 * we'll still have to check and fallback each time.
200 */
201
202 ctx->Const.MaxFragmentProgramTemps = I915_MAX_TEMPORARY;
203 ctx->Const.MaxFragmentProgramAttribs = 11; /* 8 tex, 2 color, fog */
204 ctx->Const.MaxFragmentProgramLocalParams = I915_MAX_CONSTANT;
205 ctx->Const.MaxFragmentProgramEnvParams = I915_MAX_CONSTANT;
206 ctx->Const.MaxFragmentProgramAluInstructions = I915_MAX_ALU_INSN;
207 ctx->Const.MaxFragmentProgramTexInstructions = I915_MAX_TEX_INSN;
208 ctx->Const.MaxFragmentProgramInstructions = (I915_MAX_ALU_INSN +
209 I915_MAX_TEX_INSN);
210 ctx->Const.MaxFragmentProgramTexIndirections = I915_MAX_TEX_INDIRECT;
211 ctx->Const.MaxFragmentProgramAddressRegs = 0; /* I don't think we have one */
212
213
214 driInitExtensions( ctx, card_extensions, GL_FALSE );
215
216
217 _tnl_init_vertices( ctx, ctx->Const.MaxArrayLockSize + 12,
218 36 * sizeof(GLfloat) );
219
220 intel->verts = TNL_CONTEXT(ctx)->clipspace.vertex_buf;
221
222 i915InitState( i915 );
223
224 return GL_TRUE;
225 }
226