Merge remote branch 'origin/gallium-0.2' into gallium-0.2
[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 "main/imports.h"
34 #include "main/api_noop.h"
35 #include "main/vtxfmt.h"
36 #include "main/simple_list.h"
37 #include "shader/shader_api.h"
38
39 #include "brw_context.h"
40 #include "brw_defines.h"
41 #include "brw_draw.h"
42 #include "brw_vs.h"
43 #include "intel_tex.h"
44 #include "intel_blit.h"
45 #include "intel_batchbuffer.h"
46 #include "intel_pixel.h"
47 #include "intel_span.h"
48 #include "tnl/t_pipeline.h"
49
50 #include "utils.h"
51
52
53 /***************************************
54 * Mesa's Driver Functions
55 ***************************************/
56
57 static void brwUseProgram(GLcontext *ctx, GLuint program)
58 {
59 _mesa_use_program(ctx, program);
60 }
61
62 static void brwInitProgFuncs( struct dd_function_table *functions )
63 {
64 functions->UseProgram = brwUseProgram;
65 }
66 static void brwInitDriverFunctions( struct dd_function_table *functions )
67 {
68 intelInitDriverFunctions( functions );
69
70 brwInitFragProgFuncs( functions );
71 brwInitProgFuncs( functions );
72 brw_init_queryobj_functions(functions);
73 }
74
75
76 static void brw_init_attribs( struct brw_context *brw )
77 {
78 GLcontext *ctx = &brw->intel.ctx;
79
80 brw->attribs.Color = &ctx->Color;
81 brw->attribs.Depth = &ctx->Depth;
82 brw->attribs.Fog = &ctx->Fog;
83 brw->attribs.Hint = &ctx->Hint;
84 brw->attribs.Light = &ctx->Light;
85 brw->attribs.Line = &ctx->Line;
86 brw->attribs.Point = &ctx->Point;
87 brw->attribs.Polygon = &ctx->Polygon;
88 brw->attribs.Scissor = &ctx->Scissor;
89 brw->attribs.Stencil = &ctx->Stencil;
90 brw->attribs.Texture = &ctx->Texture;
91 brw->attribs.Transform = &ctx->Transform;
92 brw->attribs.Viewport = &ctx->Viewport;
93 brw->attribs.VertexProgram = &ctx->VertexProgram;
94 brw->attribs.FragmentProgram = &ctx->FragmentProgram;
95 brw->attribs.PolygonStipple = &ctx->PolygonStipple[0];
96 }
97
98
99 GLboolean brwCreateContext( const __GLcontextModes *mesaVis,
100 __DRIcontextPrivate *driContextPriv,
101 void *sharedContextPrivate)
102 {
103 struct dd_function_table functions;
104 struct brw_context *brw = (struct brw_context *) CALLOC_STRUCT(brw_context);
105 struct intel_context *intel = &brw->intel;
106 GLcontext *ctx = &intel->ctx;
107
108 if (!brw) {
109 _mesa_printf("%s: failed to alloc context\n", __FUNCTION__);
110 return GL_FALSE;
111 }
112
113 brwInitVtbl( brw );
114 brwInitDriverFunctions( &functions );
115
116 if (!intelInitContext( intel, mesaVis, driContextPriv,
117 sharedContextPrivate, &functions )) {
118 _mesa_printf("%s: failed to init intel context\n", __FUNCTION__);
119 FREE(brw);
120 return GL_FALSE;
121 }
122
123 /* Initialize swrast, tnl driver tables: */
124 intelInitSpanFuncs(ctx);
125
126 TNL_CONTEXT(ctx)->Driver.RunPipeline = _tnl_run_pipeline;
127
128 ctx->Const.MaxTextureUnits = BRW_MAX_TEX_UNIT;
129 ctx->Const.MaxTextureImageUnits = BRW_MAX_TEX_UNIT;
130 ctx->Const.MaxTextureCoordUnits = BRW_MAX_TEX_UNIT;
131 ctx->Const.MaxVertexTextureImageUnits = 0; /* no vertex shader textures */
132
133 /* Advertise the full hardware capabilities. The new memory
134 * manager should cope much better with overload situations:
135 */
136 ctx->Const.MaxTextureLevels = 12;
137 ctx->Const.Max3DTextureLevels = 9;
138 ctx->Const.MaxCubeTextureLevels = 12;
139 ctx->Const.MaxTextureRectSize = (1<<11);
140
141 /* ctx->Const.MaxNativeVertexProgramTemps = 32; */
142
143 brw_init_attribs( brw );
144 brw_init_metaops( brw );
145 brw_init_state( brw );
146
147 brw->state.dirty.mesa = ~0;
148 brw->state.dirty.brw = ~0;
149
150 brw->emit_state_always = 0;
151
152 ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
153 ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
154
155 make_empty_list(&brw->query.active_head);
156
157 brw_draw_init( brw );
158
159 return GL_TRUE;
160 }
161