Use ProgramStringNotify
[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 #include "shader/shader_api.h"
48
49 /***************************************
50 * Mesa's Driver Functions
51 ***************************************/
52
53 static const struct dri_extension brw_extensions[] =
54 {
55 { "GL_ARB_depth_texture", NULL },
56 { "GL_ARB_fragment_program", NULL },
57 { "GL_ARB_shadow", NULL },
58 { "GL_EXT_shadow_funcs", NULL },
59 /* ARB extn won't work if not enabled */
60 { "GL_SGIX_depth_texture", NULL },
61 { "GL_ARB_texture_env_crossbar", NULL },
62 { NULL, NULL }
63 };
64
65 static void brwUseProgram(GLcontext *ctx, GLuint program)
66 {
67 struct brw_context *brw = brw_context(ctx);
68 struct gl_shader_program *sh_prog;
69 _mesa_use_program(ctx, program);
70 sh_prog = ctx->Shader.CurrentProgram;
71 if (sh_prog) {
72 ctx->VertexProgram.Enabled = GL_TRUE;
73 ctx->FragmentProgram.Enabled = GL_TRUE;
74 brw->attribs.VertexProgram->Current = sh_prog->VertexProgram;
75 brw->attribs.FragmentProgram->Current = sh_prog->FragmentProgram;
76 }
77 }
78
79 static void brwInitProgFuncs( struct dd_function_table *functions )
80 {
81 functions->UseProgram = brwUseProgram;
82 }
83 static void brwInitDriverFunctions( struct dd_function_table *functions )
84 {
85 intelInitDriverFunctions( functions );
86 brwInitTextureFuncs( functions );
87 brwInitFragProgFuncs( functions );
88 brwInitProgFuncs( functions );
89 }
90
91
92 static void brw_init_attribs( struct brw_context *brw )
93 {
94 GLcontext *ctx = &brw->intel.ctx;
95
96 brw->attribs.Color = &ctx->Color;
97 brw->attribs.Depth = &ctx->Depth;
98 brw->attribs.Fog = &ctx->Fog;
99 brw->attribs.Hint = &ctx->Hint;
100 brw->attribs.Light = &ctx->Light;
101 brw->attribs.Line = &ctx->Line;
102 brw->attribs.Point = &ctx->Point;
103 brw->attribs.Polygon = &ctx->Polygon;
104 brw->attribs.Scissor = &ctx->Scissor;
105 brw->attribs.Stencil = &ctx->Stencil;
106 brw->attribs.Texture = &ctx->Texture;
107 brw->attribs.Transform = &ctx->Transform;
108 brw->attribs.Viewport = &ctx->Viewport;
109 brw->attribs.VertexProgram = &ctx->VertexProgram;
110 brw->attribs.FragmentProgram = &ctx->FragmentProgram;
111 brw->attribs.PolygonStipple = &ctx->PolygonStipple[0];
112 }
113
114
115 GLboolean brwCreateContext( const __GLcontextModes *mesaVis,
116 __DRIcontextPrivate *driContextPriv,
117 void *sharedContextPrivate)
118 {
119 struct dd_function_table functions;
120 struct brw_context *brw = (struct brw_context *) CALLOC_STRUCT(brw_context);
121 struct intel_context *intel = &brw->intel;
122 GLcontext *ctx = &intel->ctx;
123
124 if (!brw) {
125 _mesa_printf("%s: failed to alloc context\n", __FUNCTION__);
126 return GL_FALSE;
127 }
128
129 brwInitVtbl( brw );
130 brwInitDriverFunctions( &functions );
131
132 if (!intelInitContext( intel, mesaVis, driContextPriv,
133 sharedContextPrivate, &functions )) {
134 _mesa_printf("%s: failed to init intel context\n", __FUNCTION__);
135 FREE(brw);
136 return GL_FALSE;
137 }
138
139 ctx->Const.MaxTextureUnits = BRW_MAX_TEX_UNIT;
140 ctx->Const.MaxTextureImageUnits = BRW_MAX_TEX_UNIT;
141 ctx->Const.MaxTextureCoordUnits = BRW_MAX_TEX_UNIT;
142
143
144 /* Advertise the full hardware capabilities. The new memory
145 * manager should cope much better with overload situations:
146 */
147 ctx->Const.MaxTextureLevels = 12;
148 ctx->Const.Max3DTextureLevels = 9;
149 ctx->Const.MaxCubeTextureLevels = 12;
150 ctx->Const.MaxTextureRectSize = (1<<11);
151 ctx->Const.MaxTextureUnits = BRW_MAX_TEX_UNIT;
152
153 /* ctx->Const.MaxNativeVertexProgramTemps = 32; */
154
155
156 driInitExtensions( ctx, brw_extensions, GL_FALSE );
157
158 brw_aub_init( brw );
159
160 brw_init_attribs( brw );
161 brw_init_metaops( brw );
162 brw_init_state( brw );
163
164 brw->state.dirty.mesa = ~0;
165 brw->state.dirty.brw = ~0;
166
167 memset(&brw->wm.bind, ~0, sizeof(brw->wm.bind));
168
169 brw->emit_state_always = 0;
170
171 ctx->FragmentProgram._MaintainTexEnvProgram = 1;
172
173 brw_draw_init( brw );
174
175 brw_ProgramCacheInit( ctx );
176
177 brw_FrameBufferTexInit( brw );
178
179 {
180 const char *filename = getenv("INTEL_REPLAY");
181 if (filename) {
182 brw_playback_aubfile(brw, filename);
183 exit(0);
184 }
185 }
186
187 return GL_TRUE;
188 }
189