Added few more stubs so that control reaches to DestroyDevice().
[mesa.git] / src / mesa / tnl / t_context.h
index ebaae6335b942d906bacce86ae0dc9ac08d21a50..a5bcdb80dbba1d01edadeaa8f9fee7c8563a6e33 100644 (file)
@@ -1,6 +1,5 @@
 /*
  * mesa 3-D graphics library
- * Version:  6.5
  *
  * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 /**
 #define _T_CONTEXT_H
 
 #include "main/glheader.h"
-#include "main/bitset.h"
+
 #include "main/mtypes.h"
 
-#include "math/m_matrix.h"
 #include "math/m_vector.h"
-#include "math/m_xform.h"
 
 #include "vbo/vbo.h"
 
+#include "tnl.h"
+
 #define MAX_PIPELINE_STAGES     30
 
 /*
  * attribs want (16).
  */
 enum {
-       _TNL_ATTRIB_POS = 0,
-       _TNL_ATTRIB_WEIGHT = 1,
-       _TNL_ATTRIB_NORMAL = 2,
-       _TNL_ATTRIB_COLOR0 = 3,
-       _TNL_ATTRIB_COLOR1 = 4,
-       _TNL_ATTRIB_FOG = 5,
-       _TNL_ATTRIB_COLOR_INDEX = 6,
-       _TNL_ATTRIB_EDGEFLAG = 7,
-       _TNL_ATTRIB_TEX0 = 8,
-       _TNL_ATTRIB_TEX1 = 9,
-       _TNL_ATTRIB_TEX2 = 10,
-       _TNL_ATTRIB_TEX3 = 11,
-       _TNL_ATTRIB_TEX4 = 12,
-       _TNL_ATTRIB_TEX5 = 13,
-       _TNL_ATTRIB_TEX6 = 14,
-       _TNL_ATTRIB_TEX7 = 15,
-
-       _TNL_ATTRIB_GENERIC0 = 16, /* doesn't really exist! */
-       _TNL_ATTRIB_GENERIC1 = 17,
-       _TNL_ATTRIB_GENERIC2 = 18,
-       _TNL_ATTRIB_GENERIC3 = 19,
-       _TNL_ATTRIB_GENERIC4 = 20,
-       _TNL_ATTRIB_GENERIC5 = 21,
-       _TNL_ATTRIB_GENERIC6 = 22,
-       _TNL_ATTRIB_GENERIC7 = 23,
-       _TNL_ATTRIB_GENERIC8 = 24,
-       _TNL_ATTRIB_GENERIC9 = 25,
-       _TNL_ATTRIB_GENERIC10 = 26,
-       _TNL_ATTRIB_GENERIC11 = 27,
-       _TNL_ATTRIB_GENERIC12 = 28,
-       _TNL_ATTRIB_GENERIC13 = 29,
-       _TNL_ATTRIB_GENERIC14 = 30,
-       _TNL_ATTRIB_GENERIC15 = 31,
+       _TNL_ATTRIB_POS,
+       _TNL_ATTRIB_NORMAL,
+       _TNL_ATTRIB_COLOR0,
+       _TNL_ATTRIB_COLOR1,
+       _TNL_ATTRIB_FOG,
+       _TNL_ATTRIB_COLOR_INDEX,
+       _TNL_ATTRIB_EDGEFLAG,
+       _TNL_ATTRIB_TEX0,
+       _TNL_ATTRIB_TEX1,
+       _TNL_ATTRIB_TEX2,
+       _TNL_ATTRIB_TEX3,
+       _TNL_ATTRIB_TEX4,
+       _TNL_ATTRIB_TEX5,
+       _TNL_ATTRIB_TEX6,
+       _TNL_ATTRIB_TEX7,
+
+       /* This is really a VARYING_SLOT, not an attrib.  Need to fix
+        * tnl to understand the difference.
+        */
+       _TNL_ATTRIB_POINTSIZE,
+
+       _TNL_ATTRIB_GENERIC0, /* doesn't really exist! */
+       _TNL_ATTRIB_GENERIC1,
+       _TNL_ATTRIB_GENERIC2,
+       _TNL_ATTRIB_GENERIC3,
+       _TNL_ATTRIB_GENERIC4,
+       _TNL_ATTRIB_GENERIC5,
+       _TNL_ATTRIB_GENERIC6,
+       _TNL_ATTRIB_GENERIC7,
+       _TNL_ATTRIB_GENERIC8,
+       _TNL_ATTRIB_GENERIC9,
+       _TNL_ATTRIB_GENERIC10,
+       _TNL_ATTRIB_GENERIC11,
+       _TNL_ATTRIB_GENERIC12,
+       _TNL_ATTRIB_GENERIC13,
+       _TNL_ATTRIB_GENERIC14,
+       _TNL_ATTRIB_GENERIC15,
+
+       _TNL_ATTRIB_MAX,
 
        /* These alias with the generics, but they are not active
         * concurrently, so it's not a problem.  The TNL module
@@ -122,26 +128,19 @@ enum {
         * generic attribute in order to pick up per-vertex material
         * data.
         */
-       _TNL_ATTRIB_MAT_FRONT_AMBIENT = 16,
-       _TNL_ATTRIB_MAT_BACK_AMBIENT = 17,
-       _TNL_ATTRIB_MAT_FRONT_DIFFUSE = 18,
-       _TNL_ATTRIB_MAT_BACK_DIFFUSE = 19,
-       _TNL_ATTRIB_MAT_FRONT_SPECULAR = 20,
-       _TNL_ATTRIB_MAT_BACK_SPECULAR = 21,
-       _TNL_ATTRIB_MAT_FRONT_EMISSION = 22,
-       _TNL_ATTRIB_MAT_BACK_EMISSION = 23,
-       _TNL_ATTRIB_MAT_FRONT_SHININESS = 24,
-       _TNL_ATTRIB_MAT_BACK_SHININESS = 25,
-       _TNL_ATTRIB_MAT_FRONT_INDEXES = 26,
-       _TNL_ATTRIB_MAT_BACK_INDEXES = 27,
-
-       /* This is really a VERT_RESULT, not an attrib.  Need to fix
-        * tnl to understand the difference.
-        */
-       _TNL_ATTRIB_POINTSIZE = 16,
-
-       _TNL_ATTRIB_MAX = 32
-} ;
+       _TNL_ATTRIB_MAT_FRONT_AMBIENT=VERT_ATTRIB_MAT(MAT_ATTRIB_FRONT_AMBIENT),
+       _TNL_ATTRIB_MAT_BACK_AMBIENT,
+       _TNL_ATTRIB_MAT_FRONT_DIFFUSE,
+       _TNL_ATTRIB_MAT_BACK_DIFFUSE,
+       _TNL_ATTRIB_MAT_FRONT_SPECULAR,
+       _TNL_ATTRIB_MAT_BACK_SPECULAR,
+       _TNL_ATTRIB_MAT_FRONT_EMISSION,
+       _TNL_ATTRIB_MAT_BACK_EMISSION,
+       _TNL_ATTRIB_MAT_FRONT_SHININESS,
+       _TNL_ATTRIB_MAT_BACK_SHININESS,
+       _TNL_ATTRIB_MAT_FRONT_INDEXES,
+       _TNL_ATTRIB_MAT_BACK_INDEXES,
+};
 
 #define _TNL_ATTRIB_TEX(u)       (_TNL_ATTRIB_TEX0 + (u))
 #define _TNL_ATTRIB_GENERIC(n) (_TNL_ATTRIB_GENERIC0 + (n))
@@ -152,7 +151,7 @@ enum {
 /**
  * Handy attribute ranges:
  */
-#define _TNL_FIRST_PROG      _TNL_ATTRIB_WEIGHT
+#define _TNL_FIRST_PROG      _TNL_ATTRIB_NORMAL
 #define _TNL_LAST_PROG       _TNL_ATTRIB_TEX7
 
 #define _TNL_FIRST_TEX       _TNL_ATTRIB_TEX0
@@ -161,8 +160,11 @@ enum {
 #define _TNL_FIRST_GENERIC _TNL_ATTRIB_GENERIC0
 #define _TNL_LAST_GENERIC  _TNL_ATTRIB_GENERIC15
 
-#define _TNL_FIRST_MAT       _TNL_ATTRIB_MAT_FRONT_AMBIENT /* GENERIC0 */
-#define _TNL_LAST_MAT        _TNL_ATTRIB_MAT_BACK_INDEXES  /* GENERIC11 */
+#define _TNL_FIRST_MAT       _TNL_ATTRIB_MAT_FRONT_AMBIENT /* GENERIC4 */
+#define _TNL_LAST_MAT        _TNL_ATTRIB_MAT_BACK_INDEXES  /* GENERIC15 */
+
+/* Number of available texture attributes */
+#define _TNL_NUM_TEX 8
 
 /* Number of available generic attributes */
 #define _TNL_NUM_GENERIC 16
@@ -175,7 +177,7 @@ enum {
 #define PRIM_END       0x20
 #define PRIM_MODE_MASK 0x0f
 
-static INLINE GLuint _tnl_translate_prim( const struct _mesa_prim *prim )
+static inline GLuint _tnl_translate_prim( const struct _mesa_prim *prim )
 {
    GLuint flag;
    flag = prim->mode;
@@ -203,7 +205,7 @@ struct vertex_buffer
     * such as backface color or eye-space coordinates, they are stored
     * here.
     */
-   GLuint      *Elts;                          
+   GLuint      *Elts;
    GLvector4f  *EyePtr;                                /* _TNL_BIT_POS */
    GLvector4f  *ClipPtr;                       /* _TNL_BIT_POS */
    GLvector4f  *NdcPtr;                         /* _TNL_BIT_POS */
@@ -216,11 +218,11 @@ struct vertex_buffer
    GLvector4f  *BackfaceColorPtr;
    GLvector4f  *BackfaceSecondaryColorPtr;
 
-   const struct _mesa_prim  *Primitive;                      
-   GLuint      PrimitiveCount;       
+   const struct _mesa_prim  *Primitive;
+   GLuint      PrimitiveCount;
 
    /* Inputs to the vertex program stage */
-   GLvector4f *AttribPtr[_TNL_ATTRIB_MAX];      /* GL_NV_vertex_program */
+   GLvector4f *AttribPtr[_TNL_ATTRIB_MAX];
 };
 
 
@@ -237,7 +239,7 @@ struct tnl_pipeline_stage
 
    /* Allocate private data
     */
-   GLboolean (*create)( GLcontext *ctx, struct tnl_pipeline_stage * );
+   GLboolean (*create)( struct gl_context *ctx, struct tnl_pipeline_stage * );
 
    /* Free private data.
     */
@@ -246,7 +248,7 @@ struct tnl_pipeline_stage
    /* Called on any statechange or input array size change or
     * input array change to/from zero stride.
     */
-   void (*validate)( GLcontext *ctx, struct tnl_pipeline_stage * );
+   void (*validate)( struct gl_context *ctx, struct tnl_pipeline_stage * );
 
    /* Called from _tnl_run_pipeline().  The stage.changed_inputs value
     * encodes all inputs to thee struct which have changed.  If
@@ -256,16 +258,16 @@ struct tnl_pipeline_stage
     * Return value: GL_TRUE - keep going
     *               GL_FALSE - finished pipeline
     */
-   GLboolean (*run)( GLcontext *ctx, struct tnl_pipeline_stage * );
+   GLboolean (*run)( struct gl_context *ctx, struct tnl_pipeline_stage * );
 };
 
 
 
 /** Contains the array of all pipeline stages.
- * The default values are defined at the end of t_pipeline.c 
+ * The default values are defined at the end of t_pipeline.c
  */
 struct tnl_pipeline {
-   
+
    GLuint last_attrib_stride[_TNL_ATTRIB_MAX];
    GLuint last_attrib_size[_TNL_ATTRIB_MAX];
    GLuint input_changes;
@@ -278,16 +280,16 @@ struct tnl_pipeline {
 struct tnl_clipspace;
 struct tnl_clipspace_attr;
 
-typedef void (*tnl_extract_func)( const struct tnl_clipspace_attr *a, 
-                                 GLfloat *out, 
+typedef void (*tnl_extract_func)( const struct tnl_clipspace_attr *a,
+                                 GLfloat *out,
                                  const GLubyte *v );
 
-typedef void (*tnl_insert_func)( const struct tnl_clipspace_attr *a, 
-                                GLubyte *v, 
+typedef void (*tnl_insert_func)( const struct tnl_clipspace_attr *a,
+                                GLubyte *v,
                                 const GLfloat *in );
 
-typedef void (*tnl_emit_func)( GLcontext *ctx, 
-                              GLuint count, 
+typedef void (*tnl_emit_func)( struct gl_context *ctx,
+                              GLuint count,
                               GLubyte *dest );
 
 
@@ -313,19 +315,19 @@ struct tnl_clipspace_attr
 
 
 
-typedef void (*tnl_points_func)( GLcontext *ctx, GLuint first, GLuint last );
-typedef void (*tnl_line_func)( GLcontext *ctx, GLuint v1, GLuint v2 );
-typedef void (*tnl_triangle_func)( GLcontext *ctx,
+typedef void (*tnl_points_func)( struct gl_context *ctx, GLuint first, GLuint last );
+typedef void (*tnl_line_func)( struct gl_context *ctx, GLuint v1, GLuint v2 );
+typedef void (*tnl_triangle_func)( struct gl_context *ctx,
                                   GLuint v1, GLuint v2, GLuint v3 );
-typedef void (*tnl_quad_func)( GLcontext *ctx, GLuint v1, GLuint v2,
+typedef void (*tnl_quad_func)( struct gl_context *ctx, GLuint v1, GLuint v2,
                               GLuint v3, GLuint v4 );
-typedef void (*tnl_render_func)( GLcontext *ctx, GLuint start, GLuint count,
+typedef void (*tnl_render_func)( struct gl_context *ctx, GLuint start, GLuint count,
                                 GLuint flags );
-typedef void (*tnl_interp_func)( GLcontext *ctx,
+typedef void (*tnl_interp_func)( struct gl_context *ctx,
                                 GLfloat t, GLuint dst, GLuint out, GLuint in,
                                 GLboolean force_boundary );
-typedef void (*tnl_copy_pv_func)( GLcontext *ctx, GLuint dst, GLuint src );
-typedef void (*tnl_setup_func)( GLcontext *ctx,
+typedef void (*tnl_copy_pv_func)( struct gl_context *ctx, GLuint dst, GLuint src );
+typedef void (*tnl_setup_func)( struct gl_context *ctx,
                                GLuint start, GLuint end,
                                GLuint new_inputs);
 
@@ -355,7 +357,7 @@ struct tnl_clipspace_fastpath {
 struct tnl_clipspace
 {
    GLboolean need_extras;
-   
+
    GLuint new_inputs;
 
    GLubyte *vertex_buf;
@@ -372,14 +374,28 @@ struct tnl_clipspace
    /* Parameters and constants for codegen:
     */
    GLboolean need_viewport;
-   GLfloat vp_scale[4];                
+   GLfloat vp_scale[4];
    GLfloat vp_xlate[4];
    GLfloat chan_scale[4];
    GLfloat identity[4];
 
    struct tnl_clipspace_fastpath *fastpath;
-   
-   void (*codegen_emit)( GLcontext *ctx );
+
+   void (*codegen_emit)( struct gl_context *ctx );
+};
+
+
+#define SHINE_TABLE_SIZE 256   /**< Material shininess lookup table sizes */
+
+/**
+ * Material shininess lookup table.
+ */
+struct tnl_shine_tab
+{
+   struct tnl_shine_tab *next, *prev;
+   GLfloat tab[SHINE_TABLE_SIZE+1];
+   GLfloat shininess;
+   GLuint refcount;
 };
 
 
@@ -389,13 +405,13 @@ struct tnl_device_driver
     *** TNL Pipeline
     ***/
 
-   void (*RunPipeline)(GLcontext *ctx);
+   void (*RunPipeline)(struct gl_context *ctx);
    /* Replaces PipelineStart/PipelineFinish -- intended to allow
     * drivers to wrap _tnl_run_pipeline() with code to validate state
-    * and grab/release hardware locks.  
+    * and grab/release hardware locks.
     */
 
-   void (*NotifyMaterialChange)(GLcontext *ctx);
+   void (*NotifyMaterialChange)(struct gl_context *ctx);
    /* Alert tnl-aware drivers of changes to material.
     */
 
@@ -404,14 +420,14 @@ struct tnl_device_driver
     ***/
    struct
    {
-      void (*Start)(GLcontext *ctx);
-      void (*Finish)(GLcontext *ctx);
+      void (*Start)(struct gl_context *ctx);
+      void (*Finish)(struct gl_context *ctx);
       /* Called before and after all rendering operations, including DrawPixels,
        * ReadPixels, Bitmap, span functions, and CopyTexImage, etc commands.
        * These are a suitable place for grabbing/releasing hardware locks.
        */
 
-      void (*PrimitiveNotify)(GLcontext *ctx, GLenum mode);
+      void (*PrimitiveNotify)(struct gl_context *ctx, GLenum mode);
       /* Called between RenderStart() and RenderFinish() to indicate the
        * type of primitive we're about to draw.  Mode will be one of the
        * modes accepted by glBegin().
@@ -429,12 +445,12 @@ struct tnl_device_driver
        * vertex attributes should be copied.
        */
 
-      void (*ClippedPolygon)( GLcontext *ctx, const GLuint *elts, GLuint n );
+      void (*ClippedPolygon)( struct gl_context *ctx, const GLuint *elts, GLuint n );
       /* Render a polygon with <n> vertices whose indexes are in the <elts>
        * array.
        */
 
-      void (*ClippedLine)( GLcontext *ctx, GLuint v0, GLuint v1 );
+      void (*ClippedLine)( struct gl_context *ctx, GLuint v0, GLuint v1 );
       /* Render a line between the two vertices given by indexes v0 and v1. */
 
       tnl_points_func           Points; /* must now respect vb->elts */
@@ -454,7 +470,7 @@ struct tnl_device_driver
        * vertices.
        */
 
-      void (*ResetLineStipple)( GLcontext *ctx );
+      void (*ResetLineStipple)( struct gl_context *ctx );
       /* Reset the hardware's line stipple counter.
        */
 
@@ -467,9 +483,9 @@ struct tnl_device_driver
        *
        * This function is called only from _tnl_render_stage in tnl/t_render.c.
        */
-      
 
-      GLboolean (*Multipass)( GLcontext *ctx, GLuint passno );
+
+      GLboolean (*Multipass)( struct gl_context *ctx, GLuint passno );
       /* Driver may request additional render passes by returning GL_TRUE
        * when this function is called.  This function will be called
        * after the first pass, and passes will be made until the function
@@ -482,17 +498,39 @@ struct tnl_device_driver
 };
 
 
-#define DECLARE_RENDERINPUTS(name) BITSET64_DECLARE(name, _TNL_ATTRIB_MAX)
-#define RENDERINPUTS_COPY BITSET64_COPY
-#define RENDERINPUTS_EQUAL BITSET64_EQUAL
-#define RENDERINPUTS_ZERO BITSET64_ZERO
-#define RENDERINPUTS_ONES BITSET64_ONES
-#define RENDERINPUTS_TEST BITSET64_TEST
-#define RENDERINPUTS_SET BITSET64_SET
-#define RENDERINPUTS_CLEAR BITSET64_CLEAR
-#define RENDERINPUTS_TEST_RANGE BITSET64_TEST_RANGE
-#define RENDERINPUTS_SET_RANGE BITSET64_SET_RANGE
-#define RENDERINPUTS_CLEAR_RANGE BITSET64_CLEAR_RANGE
+/**
+ * Utility that tracks and updates the current array entries.
+ */
+struct tnl_inputs
+{
+   /**
+    * Array of inputs to be set to the _DrawArrays pointer.
+    * The array contains pointers into the _DrawVAO and to the vbo modules
+    * current values. The array of pointers is updated incrementally
+    * based on the current and vertex_processing_mode values below.
+    */
+   struct tnl_vertex_array inputs[VERT_ATTRIB_MAX];
+   /** Those VERT_BIT_'s where the inputs array point to current values. */
+   GLbitfield current;
+   /** Store which aliasing current values - generics or materials - are set. */
+   gl_vertex_processing_mode vertex_processing_mode;
+};
+
+
+/**
+ * Initialize inputs.
+ */
+void
+_tnl_init_inputs(struct tnl_inputs *inputs);
+
+
+/**
+ * Update the tnl_vertex_array array inside the tnl_inputs structure
+ * provided the current _VPMode, the provided vao and
+ * the vao's enabled arrays filtered by the filter bitmask.
+ */
+void
+_tnl_update_inputs(struct gl_context *ctx, struct tnl_inputs *inputs);
 
 
 /**
@@ -512,6 +550,7 @@ typedef struct
    /* Clipspace/ndc/window vertex managment:
     */
    struct tnl_clipspace clipspace;
+   GLmatrix _WindowMap;
 
    /* Probably need a better configuration mechanism:
     */
@@ -520,15 +559,23 @@ typedef struct
    GLboolean AllowPixelFog;
    GLboolean _DoVertexFog;  /* eval fog function at each vertex? */
 
-   DECLARE_RENDERINPUTS(render_inputs_bitset);
+   GLbitfield64 render_inputs_bitset;
 
    GLvector4f tmp_inputs[VERT_ATTRIB_MAX];
 
-   /* Temp storage for t_draw.c: 
+   /* Temp storage for t_draw.c:
     */
    GLubyte *block[VERT_ATTRIB_MAX];
    GLuint nr_blocks;
 
+   GLuint CurInstance;
+
+   struct tnl_shine_tab *_ShineTable[2]; /**< Active shine tables */
+   struct tnl_shine_tab *_ShineTabList;  /**< MRU list of inactive shine tables */
+   /**@}*/
+
+   /* The list of tnl_vertex_array inputs. */
+   struct tnl_inputs draw_arrays;
 } TNLcontext;
 
 
@@ -541,7 +588,7 @@ typedef struct
 
 
 extern void
-tnl_clip_prepare(GLcontext *ctx);
+tnl_clip_prepare(struct gl_context *ctx);
 
 
 #endif