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