brw_context.c revision de1e9880f8b239768293f7f434a9117dfab20162
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 55static void brwUseProgram(GLcontext *ctx, GLuint program) 56{ 57 _mesa_use_program(ctx, program); 58} 59 60static void brwInitProgFuncs( struct dd_function_table *functions ) 61{ 62 functions->UseProgram = brwUseProgram; 63} 64static void brwInitDriverFunctions( struct dd_function_table *functions ) 65{ 66 intelInitDriverFunctions( functions ); 67 68 /* CopyPixels can be accelerated even with the current memory 69 * manager: 70 */ 71 if (!getenv("INTEL_NO_BLIT")) { 72 functions->CopyPixels = intelCopyPixels; 73 functions->Bitmap = intelBitmap; 74 } 75 76 brwInitFragProgFuncs( functions ); 77 brwInitProgFuncs( functions ); 78} 79 80 81static void brw_init_attribs( struct brw_context *brw ) 82{ 83 GLcontext *ctx = &brw->intel.ctx; 84 85 brw->attribs.Color = &ctx->Color; 86 brw->attribs.Depth = &ctx->Depth; 87 brw->attribs.Fog = &ctx->Fog; 88 brw->attribs.Hint = &ctx->Hint; 89 brw->attribs.Light = &ctx->Light; 90 brw->attribs.Line = &ctx->Line; 91 brw->attribs.Point = &ctx->Point; 92 brw->attribs.Polygon = &ctx->Polygon; 93 brw->attribs.Scissor = &ctx->Scissor; 94 brw->attribs.Stencil = &ctx->Stencil; 95 brw->attribs.Texture = &ctx->Texture; 96 brw->attribs.Transform = &ctx->Transform; 97 brw->attribs.Viewport = &ctx->Viewport; 98 brw->attribs.VertexProgram = &ctx->VertexProgram; 99 brw->attribs.FragmentProgram = &ctx->FragmentProgram; 100 brw->attribs.PolygonStipple = &ctx->PolygonStipple[0]; 101} 102 103 104GLboolean brwCreateContext( const __GLcontextModes *mesaVis, 105 __DRIcontextPrivate *driContextPriv, 106 void *sharedContextPrivate) 107{ 108 struct dd_function_table functions; 109 struct brw_context *brw = (struct brw_context *) CALLOC_STRUCT(brw_context); 110 struct intel_context *intel = &brw->intel; 111 GLcontext *ctx = &intel->ctx; 112 113 if (!brw) { 114 _mesa_printf("%s: failed to alloc context\n", __FUNCTION__); 115 return GL_FALSE; 116 } 117 118 brwInitVtbl( brw ); 119 brwInitDriverFunctions( &functions ); 120 121 if (!intelInitContext( intel, mesaVis, driContextPriv, 122 sharedContextPrivate, &functions )) { 123 _mesa_printf("%s: failed to init intel context\n", __FUNCTION__); 124 FREE(brw); 125 return GL_FALSE; 126 } 127 128 /* Initialize swrast, tnl driver tables: */ 129 intelInitSpanFuncs(ctx); 130 131 TNL_CONTEXT(ctx)->Driver.RunPipeline = _tnl_run_pipeline; 132 133 ctx->Const.MaxTextureUnits = BRW_MAX_TEX_UNIT; 134 ctx->Const.MaxTextureImageUnits = BRW_MAX_TEX_UNIT; 135 ctx->Const.MaxTextureCoordUnits = BRW_MAX_TEX_UNIT; 136 137 138 /* Advertise the full hardware capabilities. The new memory 139 * manager should cope much better with overload situations: 140 */ 141 ctx->Const.MaxTextureLevels = 12; 142 ctx->Const.Max3DTextureLevels = 9; 143 ctx->Const.MaxCubeTextureLevels = 12; 144 ctx->Const.MaxTextureRectSize = (1<<11); 145 ctx->Const.MaxTextureUnits = BRW_MAX_TEX_UNIT; 146 147/* ctx->Const.MaxNativeVertexProgramTemps = 32; */ 148 149 brw_init_attribs( brw ); 150 brw_init_metaops( brw ); 151 brw_init_state( brw ); 152 153 brw->state.dirty.mesa = ~0; 154 brw->state.dirty.brw = ~0; 155 156 brw->emit_state_always = 0; 157 158 ctx->FragmentProgram._MaintainTexEnvProgram = 1; 159 160 brw_draw_init( brw ); 161 162 brw_ProgramCacheInit( ctx ); 163 164 return GL_TRUE; 165} 166 167