i965: Get a ralloc context into brw_compile.
[mesa.git] / src / mesa / drivers / common / driverfuncs.c
index f2e36b78452007af89b4a492843cc0495d5f29bf..0dbc7c3e8535f4e25e1aa769588219f284efa296 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5
+ * Version:  7.1
  *
- * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
  */
 
 
-#include "glheader.h"
-#include "imports.h"
-#include "buffers.h"
-#include "context.h"
-#include "framebuffer.h"
-#include "occlude.h"
-#include "program.h"
-#include "renderbuffer.h"
-#include "texcompress.h"
-#include "texformat.h"
-#include "teximage.h"
-#include "texobj.h"
-#include "texstore.h"
-#if FEATURE_ARB_vertex_buffer_object
-#include "bufferobj.h"
-#endif
-#if FEATURE_EXT_framebuffer_object
-#include "fbobject.h"
-#include "texrender.h"
-#endif
+#include "main/glheader.h"
+#include "main/imports.h"
+#include "main/arrayobj.h"
+#include "main/context.h"
+#include "main/framebuffer.h"
+#include "main/mipmap.h"
+#include "main/queryobj.h"
+#include "main/renderbuffer.h"
+#include "main/shaderobj.h"
+#include "main/texcompress.h"
+#include "main/texformat.h"
+#include "main/texgetimage.h"
+#include "main/teximage.h"
+#include "main/texobj.h"
+#include "main/texstore.h"
+#include "main/bufferobj.h"
+#include "main/fbobject.h"
+#include "main/texrender.h"
+#include "main/samplerobj.h"
+#include "main/syncobj.h"
+#include "main/texturebarrier.h"
+#include "main/transformfeedback.h"
 
-#include "driverfuncs.h"
+#include "program/program.h"
+#include "tnl/tnl.h"
 #include "swrast/swrast.h"
 
+#include "driverfuncs.h"
+#include "meta.h"
+
 
 
 /**
@@ -61,7 +67,7 @@
 void
 _mesa_init_driver_functions(struct dd_function_table *driver)
 {
-   _mesa_bzero(driver, sizeof(*driver));
+   memset(driver, 0, sizeof(*driver));
 
    driver->GetString = NULL;  /* REQUIRED! */
    driver->UpdateState = NULL;  /* REQUIRED! */
@@ -75,6 +81,7 @@ _mesa_init_driver_functions(struct dd_function_table *driver)
    /* framebuffer/image functions */
    driver->Clear = _swrast_Clear;
    driver->Accum = _swrast_Accum;
+   driver->RasterPos = _tnl_RasterPos;
    driver->DrawPixels = _swrast_DrawPixels;
    driver->ReadPixels = _swrast_ReadPixels;
    driver->CopyPixels = _swrast_CopyPixels;
@@ -89,11 +96,12 @@ _mesa_init_driver_functions(struct dd_function_table *driver)
    driver->TexSubImage2D = _mesa_store_texsubimage2d;
    driver->TexSubImage3D = _mesa_store_texsubimage3d;
    driver->GetTexImage = _mesa_get_teximage;
-   driver->CopyTexImage1D = _swrast_copy_teximage1d;
-   driver->CopyTexImage2D = _swrast_copy_teximage2d;
-   driver->CopyTexSubImage1D = _swrast_copy_texsubimage1d;
-   driver->CopyTexSubImage2D = _swrast_copy_texsubimage2d;
-   driver->CopyTexSubImage3D = _swrast_copy_texsubimage3d;
+   driver->CopyTexImage1D = _mesa_meta_CopyTexImage1D;
+   driver->CopyTexImage2D = _mesa_meta_CopyTexImage2D;
+   driver->CopyTexSubImage1D = _mesa_meta_CopyTexSubImage1D;
+   driver->CopyTexSubImage2D = _mesa_meta_CopyTexSubImage2D;
+   driver->CopyTexSubImage3D = _mesa_meta_CopyTexSubImage3D;
+   driver->GenerateMipmap = _mesa_meta_GenerateMipmap;
    driver->TestProxyTexImage = _mesa_test_proxy_teximage;
    driver->CompressedTexImage1D = _mesa_store_compressed_teximage1d;
    driver->CompressedTexImage2D = _mesa_store_compressed_teximage2d;
@@ -102,23 +110,20 @@ _mesa_init_driver_functions(struct dd_function_table *driver)
    driver->CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d;
    driver->CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d;
    driver->GetCompressedTexImage = _mesa_get_compressed_teximage;
-   driver->CompressedTextureSize = _mesa_compressed_texture_size;
    driver->BindTexture = NULL;
    driver->NewTextureObject = _mesa_new_texture_object;
    driver->DeleteTexture = _mesa_delete_texture_object;
    driver->NewTextureImage = _mesa_new_texture_image;
    driver->FreeTexImageData = _mesa_free_texture_image_data; 
-   driver->TextureMemCpy = _mesa_memcpy; 
+   driver->MapTexture = NULL;
+   driver->UnmapTexture = NULL;
+   driver->TextureMemCpy = memcpy;
    driver->IsTextureResident = NULL;
-   driver->PrioritizeTexture = NULL;
-   driver->ActiveTexture = NULL;
    driver->UpdateTexturePalette = NULL;
 
    /* imaging */
-   driver->CopyColorTable = _swrast_CopyColorTable;
-   driver->CopyColorSubTable = _swrast_CopyColorSubTable;
-   driver->CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
-   driver->CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
+   driver->CopyColorTable = _mesa_meta_CopyColorTable;
+   driver->CopyColorSubTable = _mesa_meta_CopyColorSubTable;
 
    /* Vertex/fragment programs */
    driver->BindProgram = NULL;
@@ -132,14 +137,13 @@ _mesa_init_driver_functions(struct dd_function_table *driver)
    driver->BlendFuncSeparate = NULL;
    driver->ClearColor = NULL;
    driver->ClearDepth = NULL;
-   driver->ClearIndex = NULL;
    driver->ClearStencil = NULL;
    driver->ClipPlane = NULL;
    driver->ColorMask = NULL;
    driver->ColorMaterial = NULL;
    driver->CullFace = NULL;
-   driver->DrawBuffer = _swrast_DrawBuffer;
-   driver->DrawBuffers = NULL; /***_swrast_DrawBuffers;***/
+   driver->DrawBuffer = NULL;
+   driver->DrawBuffers = NULL;
    driver->FrontFace = NULL;
    driver->DepthFunc = NULL;
    driver->DepthMask = NULL;
@@ -147,7 +151,6 @@ _mesa_init_driver_functions(struct dd_function_table *driver)
    driver->Enable = NULL;
    driver->Fogfv = NULL;
    driver->Hint = NULL;
-   driver->IndexMask = NULL;
    driver->Lightfv = NULL;
    driver->LightModelfv = NULL;
    driver->LineStipple = NULL;
@@ -162,58 +165,43 @@ _mesa_init_driver_functions(struct dd_function_table *driver)
    driver->RenderMode = NULL;
    driver->Scissor = NULL;
    driver->ShadeModel = NULL;
-   driver->StencilFunc = NULL;
-   driver->StencilMask = NULL;
-   driver->StencilOp = NULL;
-   driver->ActiveStencilFace = NULL;
+   driver->StencilFuncSeparate = NULL;
+   driver->StencilOpSeparate = NULL;
+   driver->StencilMaskSeparate = NULL;
    driver->TexGen = NULL;
    driver->TexEnv = NULL;
    driver->TexParameter = NULL;
-   driver->TextureMatrix = NULL;
    driver->Viewport = NULL;
 
-   /* vertex arrays */
-   driver->VertexPointer = NULL;
-   driver->NormalPointer = NULL;
-   driver->ColorPointer = NULL;
-   driver->FogCoordPointer = NULL;
-   driver->IndexPointer = NULL;
-   driver->SecondaryColorPointer = NULL;
-   driver->TexCoordPointer = NULL;
-   driver->EdgeFlagPointer = NULL;
-   driver->VertexAttribPointer = NULL;
-   driver->LockArraysEXT = NULL;
-   driver->UnlockArraysEXT = NULL;
-
-   /* state queries */
-   driver->GetBooleanv = NULL;
-   driver->GetDoublev = NULL;
-   driver->GetFloatv = NULL;
-   driver->GetIntegerv = NULL;
-   driver->GetPointerv = NULL;
-   
-#if FEATURE_ARB_vertex_buffer_object
-   driver->NewBufferObject = _mesa_new_buffer_object;
-   driver->DeleteBuffer = _mesa_delete_buffer_object;
-   driver->BindBuffer = NULL;
-   driver->BufferData = _mesa_buffer_data;
-   driver->BufferSubData = _mesa_buffer_subdata;
-   driver->GetBufferSubData = _mesa_buffer_get_subdata;
-   driver->MapBuffer = _mesa_buffer_map;
-   driver->UnmapBuffer = _mesa_buffer_unmap;
-#endif
-
-#if FEATURE_EXT_framebuffer_object
+   /* buffer objects */
+   _mesa_init_buffer_object_functions(driver);
+
+   /* query objects */
+   _mesa_init_query_object_functions(driver);
+
+   _mesa_init_sync_object_functions(driver);
+
    driver->NewFramebuffer = _mesa_new_framebuffer;
    driver->NewRenderbuffer = _mesa_new_soft_renderbuffer;
-   driver->RenderbufferTexture = _mesa_renderbuffer_texture;
+   driver->RenderTexture = _mesa_render_texture;
+   driver->FinishRenderTexture = _mesa_finish_render_texture;
    driver->FramebufferRenderbuffer = _mesa_framebuffer_renderbuffer;
-#endif
+   driver->ValidateFramebuffer = _mesa_validate_framebuffer;
 
-   /* query objects */
-   driver->NewQueryObject = _mesa_new_query_object;
-   driver->BeginQuery = NULL;
-   driver->EndQuery = NULL;
+   driver->BlitFramebuffer = _swrast_BlitFramebuffer;
+
+   _mesa_init_texture_barrier_functions(driver);
+
+   /* APPLE_vertex_array_object */
+   driver->NewArrayObject = _mesa_new_array_object;
+   driver->DeleteArrayObject = _mesa_delete_array_object;
+   driver->BindArrayObject = NULL;
+
+   _mesa_init_shader_object_functions(driver);
+
+   _mesa_init_transform_feedback_functions(driver);
+
+   _mesa_init_sampler_object_functions(driver);
 
    /* T&L stuff */
    driver->NeedValidate = GL_FALSE;
@@ -223,11 +211,11 @@ _mesa_init_driver_functions(struct dd_function_table *driver)
    driver->NeedFlush = 0;
    driver->SaveNeedFlush = 0;
 
+   driver->ProgramStringNotify = _tnl_program_string;
    driver->FlushVertices = NULL;
    driver->SaveFlushVertices = NULL;
    driver->NotifySaveBegin = NULL;
    driver->LightingSpaceChange = NULL;
-   driver->MakeCurrent = NULL;
 
    /* display list */
    driver->NewList = NULL;
@@ -235,3 +223,110 @@ _mesa_init_driver_functions(struct dd_function_table *driver)
    driver->BeginCallList = NULL;
    driver->EndCallList = NULL;
 }
+
+
+/**
+ * Call the ctx->Driver.* state functions with current values to initialize
+ * driver state.
+ * Only the Intel drivers use this so far.
+ */
+void
+_mesa_init_driver_state(struct gl_context *ctx)
+{
+   ctx->Driver.AlphaFunc(ctx, ctx->Color.AlphaFunc, ctx->Color.AlphaRef);
+
+   ctx->Driver.BlendColor(ctx, ctx->Color.BlendColor);
+
+   ctx->Driver.BlendEquationSeparate(ctx,
+                                     ctx->Color.Blend[0].EquationRGB,
+                                     ctx->Color.Blend[0].EquationA);
+
+   ctx->Driver.BlendFuncSeparate(ctx,
+                                 ctx->Color.Blend[0].SrcRGB,
+                                 ctx->Color.Blend[0].DstRGB,
+                                 ctx->Color.Blend[0].SrcA,
+                                 ctx->Color.Blend[0].DstA);
+
+   if (ctx->Driver.ColorMaskIndexed) {
+      GLuint i;
+      for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
+         ctx->Driver.ColorMaskIndexed(ctx, i,
+                                      ctx->Color.ColorMask[0][RCOMP],
+                                      ctx->Color.ColorMask[0][GCOMP],
+                                      ctx->Color.ColorMask[0][BCOMP],
+                                      ctx->Color.ColorMask[0][ACOMP]);
+      }
+   }
+   else {
+      ctx->Driver.ColorMask(ctx,
+                            ctx->Color.ColorMask[0][RCOMP],
+                            ctx->Color.ColorMask[0][GCOMP],
+                            ctx->Color.ColorMask[0][BCOMP],
+                            ctx->Color.ColorMask[0][ACOMP]);
+   }
+
+   ctx->Driver.CullFace(ctx, ctx->Polygon.CullFaceMode);
+   ctx->Driver.DepthFunc(ctx, ctx->Depth.Func);
+   ctx->Driver.DepthMask(ctx, ctx->Depth.Mask);
+
+   ctx->Driver.Enable(ctx, GL_ALPHA_TEST, ctx->Color.AlphaEnabled);
+   ctx->Driver.Enable(ctx, GL_BLEND, ctx->Color.BlendEnabled);
+   ctx->Driver.Enable(ctx, GL_COLOR_LOGIC_OP, ctx->Color.ColorLogicOpEnabled);
+   ctx->Driver.Enable(ctx, GL_COLOR_SUM, ctx->Fog.ColorSumEnabled);
+   ctx->Driver.Enable(ctx, GL_CULL_FACE, ctx->Polygon.CullFlag);
+   ctx->Driver.Enable(ctx, GL_DEPTH_TEST, ctx->Depth.Test);
+   ctx->Driver.Enable(ctx, GL_DITHER, ctx->Color.DitherFlag);
+   ctx->Driver.Enable(ctx, GL_FOG, ctx->Fog.Enabled);
+   ctx->Driver.Enable(ctx, GL_LIGHTING, ctx->Light.Enabled);
+   ctx->Driver.Enable(ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag);
+   ctx->Driver.Enable(ctx, GL_POLYGON_STIPPLE, ctx->Polygon.StippleFlag);
+   ctx->Driver.Enable(ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled);
+   ctx->Driver.Enable(ctx, GL_STENCIL_TEST, ctx->Stencil._Enabled);
+   ctx->Driver.Enable(ctx, GL_TEXTURE_1D, GL_FALSE);
+   ctx->Driver.Enable(ctx, GL_TEXTURE_2D, GL_FALSE);
+   ctx->Driver.Enable(ctx, GL_TEXTURE_RECTANGLE_NV, GL_FALSE);
+   ctx->Driver.Enable(ctx, GL_TEXTURE_3D, GL_FALSE);
+   ctx->Driver.Enable(ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE);
+
+   ctx->Driver.Fogfv(ctx, GL_FOG_COLOR, ctx->Fog.Color);
+   ctx->Driver.Fogfv(ctx, GL_FOG_MODE, 0);
+   ctx->Driver.Fogfv(ctx, GL_FOG_DENSITY, &ctx->Fog.Density);
+   ctx->Driver.Fogfv(ctx, GL_FOG_START, &ctx->Fog.Start);
+   ctx->Driver.Fogfv(ctx, GL_FOG_END, &ctx->Fog.End);
+
+   ctx->Driver.FrontFace(ctx, ctx->Polygon.FrontFace);
+
+   {
+      GLfloat f = (GLfloat) ctx->Light.Model.ColorControl;
+      ctx->Driver.LightModelfv(ctx, GL_LIGHT_MODEL_COLOR_CONTROL, &f);
+   }
+
+   ctx->Driver.LineWidth(ctx, ctx->Line.Width);
+   ctx->Driver.LogicOpcode(ctx, ctx->Color.LogicOp);
+   ctx->Driver.PointSize(ctx, ctx->Point.Size);
+   ctx->Driver.PolygonStipple(ctx, (const GLubyte *) ctx->PolygonStipple);
+   ctx->Driver.Scissor(ctx, ctx->Scissor.X, ctx->Scissor.Y,
+                       ctx->Scissor.Width, ctx->Scissor.Height);
+   ctx->Driver.ShadeModel(ctx, ctx->Light.ShadeModel);
+   ctx->Driver.StencilFuncSeparate(ctx, GL_FRONT,
+                                   ctx->Stencil.Function[0],
+                                   ctx->Stencil.Ref[0],
+                                   ctx->Stencil.ValueMask[0]);
+   ctx->Driver.StencilFuncSeparate(ctx, GL_BACK,
+                                   ctx->Stencil.Function[1],
+                                   ctx->Stencil.Ref[1],
+                                   ctx->Stencil.ValueMask[1]);
+   ctx->Driver.StencilMaskSeparate(ctx, GL_FRONT, ctx->Stencil.WriteMask[0]);
+   ctx->Driver.StencilMaskSeparate(ctx, GL_BACK, ctx->Stencil.WriteMask[1]);
+   ctx->Driver.StencilOpSeparate(ctx, GL_FRONT,
+                                 ctx->Stencil.FailFunc[0],
+                                 ctx->Stencil.ZFailFunc[0],
+                                 ctx->Stencil.ZPassFunc[0]);
+   ctx->Driver.StencilOpSeparate(ctx, GL_BACK,
+                                 ctx->Stencil.FailFunc[1],
+                                 ctx->Stencil.ZFailFunc[1],
+                                 ctx->Stencil.ZPassFunc[1]);
+
+
+   ctx->Driver.DrawBuffer(ctx, ctx->Color.DrawBuffer[0]);
+}