brw_context.c revision 3e05902d304e71493d05edef4c31c6ed1a22bf17
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_exec.h"
38#include "brw_save.h"
39#include "brw_vs.h"
40#include "imports.h"
41#include "intel_tex.h"
42#include "intel_blit.h"
43#include "intel_batchbuffer.h"
44
45#include "utils.h"
46#include "api_noop.h"
47#include "vtxfmt.h"
48
49/***************************************
50 * Mesa's Driver Functions
51 ***************************************/
52
53static 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
66static void brwInitDriverFunctions( struct dd_function_table *functions )
67{
68   intelInitDriverFunctions( functions );
69   brwInitTextureFuncs( functions );
70   brwInitFragProgFuncs( functions );
71}
72
73
74static void brw_init_attribs( struct brw_context *brw )
75{
76   GLcontext *ctx = &brw->intel.ctx;
77
78   brw->attribs.Color = &ctx->Color;
79   brw->attribs.Depth = &ctx->Depth;
80   brw->attribs.Fog = &ctx->Fog;
81   brw->attribs.Hint = &ctx->Hint;
82   brw->attribs.Light = &ctx->Light;
83   brw->attribs.Line = &ctx->Line;
84   brw->attribs.Point = &ctx->Point;
85   brw->attribs.Polygon = &ctx->Polygon;
86   brw->attribs.Scissor = &ctx->Scissor;
87   brw->attribs.Stencil = &ctx->Stencil;
88   brw->attribs.Texture = &ctx->Texture;
89   brw->attribs.Transform = &ctx->Transform;
90   brw->attribs.Viewport = &ctx->Viewport;
91   brw->attribs.VertexProgram = &ctx->VertexProgram;
92   brw->attribs.FragmentProgram = &ctx->FragmentProgram;
93   brw->attribs.PolygonStipple = &ctx->PolygonStipple[0];
94}
95
96
97GLboolean brwCreateContext( const __GLcontextModes *mesaVis,
98			    __DRIcontextPrivate *driContextPriv,
99			    void *sharedContextPrivate)
100{
101   struct dd_function_table functions;
102   struct brw_context *brw = (struct brw_context *) CALLOC_STRUCT(brw_context);
103   struct intel_context *intel = &brw->intel;
104   GLcontext *ctx = &intel->ctx;
105
106   if (!brw) {
107      _mesa_printf("%s: failed to alloc context\n", __FUNCTION__);
108      return GL_FALSE;
109   }
110
111   brwInitVtbl( brw );
112   brwInitDriverFunctions( &functions );
113
114   if (!intelInitContext( intel, mesaVis, driContextPriv,
115			  sharedContextPrivate, &functions )) {
116      _mesa_printf("%s: failed to init intel context\n", __FUNCTION__);
117      FREE(brw);
118      return GL_FALSE;
119   }
120
121   ctx->Const.MaxTextureUnits = BRW_MAX_TEX_UNIT;
122   ctx->Const.MaxTextureImageUnits = BRW_MAX_TEX_UNIT;
123   ctx->Const.MaxTextureCoordUnits = BRW_MAX_TEX_UNIT;
124
125
126   /* Advertise the full hardware capabilities.  The new memory
127    * manager should cope much better with overload situations:
128    */
129   ctx->Const.MaxTextureLevels = 12;
130   ctx->Const.Max3DTextureLevels = 9;
131   ctx->Const.MaxCubeTextureLevels = 12;
132   ctx->Const.MaxTextureRectSize = (1<<11);
133   ctx->Const.MaxTextureUnits = BRW_MAX_TEX_UNIT;
134
135/*    ctx->Const.MaxNativeVertexProgramTemps = 32; */
136
137
138   driInitExtensions( ctx, brw_extensions, GL_FALSE );
139
140   brw_aub_init( brw );
141
142   brw_init_attribs( brw );
143   brw_init_metaops( brw );
144   brw_init_state( brw );
145
146   brw->state.dirty.mesa = ~0;
147   brw->state.dirty.brw = ~0;
148
149   memset(&brw->wm.bind, ~0, sizeof(brw->wm.bind));
150
151   brw->emit_state_always = 0;
152
153   ctx->_MaintainTexEnvProgram = 1;
154
155   brw_draw_init( brw );
156
157   brw_ProgramCacheInit( ctx );
158
159   /* Hook our functions into exec and compile dispatch tables.  Only
160    * fallback on out-of-memory situations.
161    */
162   brw_exec_init( ctx );
163   brw_save_init( ctx );
164
165   return GL_TRUE;
166}
167
168