Merge branch 'master' of git+ssh://keithw@git.freedesktop.org/git/mesa/mesa into...
[mesa.git] / src / mesa / drivers / dri / i965 / brw_context.c
1 /*
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a 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, sublicense, 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
16 portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **********************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 */
31
32
33 #include "brw_context.h"
34 #include "brw_aub.h"
35 #include "brw_defines.h"
36 #include "brw_draw.h"
37 #include "brw_vs.h"
38 #include "imports.h"
39 #include "intel_tex.h"
40 #include "intel_blit.h"
41 #include "intel_batchbuffer.h"
42
43 #include "utils.h"
44 #include "api_noop.h"
45 #include "vtxfmt.h"
46
47 /***************************************
48 * Mesa's Driver Functions
49 ***************************************/
50
51 static const struct dri_extension brw_extensions[] =
52 {
53 { "GL_ARB_depth_texture", NULL },
54 { "GL_ARB_fragment_program", NULL },
55 { "GL_ARB_shadow", NULL },
56 { "GL_EXT_shadow_funcs", NULL },
57 /* ARB extn won't work if not enabled */
58 { "GL_SGIX_depth_texture", NULL },
59 { "GL_ARB_texture_env_crossbar", NULL },
60 { NULL, NULL }
61 };
62
63
64 static void brwInitDriverFunctions( struct dd_function_table *functions )
65 {
66 intelInitDriverFunctions( functions );
67 brwInitTextureFuncs( functions );
68 brwInitFragProgFuncs( functions );
69 }
70
71
72 static void brw_init_attribs( struct brw_context *brw )
73 {
74 GLcontext *ctx = &brw->intel.ctx;
75
76 brw->attribs.Color = &ctx->Color;
77 brw->attribs.Depth = &ctx->Depth;
78 brw->attribs.Fog = &ctx->Fog;
79 brw->attribs.Hint = &ctx->Hint;
80 brw->attribs.Light = &ctx->Light;
81 brw->attribs.Line = &ctx->Line;
82 brw->attribs.Point = &ctx->Point;
83 brw->attribs.Polygon = &ctx->Polygon;
84 brw->attribs.Scissor = &ctx->Scissor;
85 brw->attribs.Stencil = &ctx->Stencil;
86 brw->attribs.Texture = &ctx->Texture;
87 brw->attribs.Transform = &ctx->Transform;
88 brw->attribs.Viewport = &ctx->Viewport;
89 brw->attribs.VertexProgram = &ctx->VertexProgram;
90 brw->attribs.FragmentProgram = &ctx->FragmentProgram;
91 brw->attribs.PolygonStipple = &ctx->PolygonStipple[0];
92 }
93
94
95 GLboolean brwCreateContext( const __GLcontextModes *mesaVis,
96 __DRIcontextPrivate *driContextPriv,
97 void *sharedContextPrivate)
98 {
99 struct dd_function_table functions;
100 struct brw_context *brw = (struct brw_context *) CALLOC_STRUCT(brw_context);
101 struct intel_context *intel = &brw->intel;
102 GLcontext *ctx = &intel->ctx;
103
104 if (!brw) {
105 _mesa_printf("%s: failed to alloc context\n", __FUNCTION__);
106 return GL_FALSE;
107 }
108
109 brwInitVtbl( brw );
110 brwInitDriverFunctions( &functions );
111
112 if (!intelInitContext( intel, mesaVis, driContextPriv,
113 sharedContextPrivate, &functions )) {
114 _mesa_printf("%s: failed to init intel context\n", __FUNCTION__);
115 FREE(brw);
116 return GL_FALSE;
117 }
118
119 ctx->Const.MaxTextureUnits = BRW_MAX_TEX_UNIT;
120 ctx->Const.MaxTextureImageUnits = BRW_MAX_TEX_UNIT;
121 ctx->Const.MaxTextureCoordUnits = BRW_MAX_TEX_UNIT;
122
123
124 /* Advertise the full hardware capabilities. The new memory
125 * manager should cope much better with overload situations:
126 */
127 ctx->Const.MaxTextureLevels = 12;
128 ctx->Const.Max3DTextureLevels = 9;
129 ctx->Const.MaxCubeTextureLevels = 12;
130 ctx->Const.MaxTextureRectSize = (1<<11);
131 ctx->Const.MaxTextureUnits = BRW_MAX_TEX_UNIT;
132
133 /* ctx->Const.MaxNativeVertexProgramTemps = 32; */
134
135
136 driInitExtensions( ctx, brw_extensions, GL_FALSE );
137
138 brw_aub_init( brw );
139
140 brw_init_attribs( brw );
141 brw_init_metaops( brw );
142 brw_init_state( brw );
143
144 brw->state.dirty.mesa = ~0;
145 brw->state.dirty.brw = ~0;
146
147 memset(&brw->wm.bind, ~0, sizeof(brw->wm.bind));
148
149 brw->emit_state_always = 0;
150
151 ctx->_MaintainTexEnvProgram = 1;
152
153 brw_draw_init( brw );
154
155 brw_ProgramCacheInit( ctx );
156
157 brw_FrameBufferTexInit( brw );
158
159 {
160 const char *filename = getenv("INTEL_REPLAY");
161 if (filename) {
162 brw_playback_aubfile(brw, filename);
163 exit(0);
164 }
165 }
166
167 return GL_TRUE;
168 }
169