fix GL_BACK color material bug
[mesa.git] / src / mesa / drivers / glide / fxdrv.h
index f5ef5763383b8fda5ee126bd391b24d576ddbb9b..c85c73d8e23efe12e92624947f8508c249e49713 100644 (file)
@@ -1,27 +1,48 @@
-/* -*- mode: C; tab-width:8;  -*-
-
-             fxdrv.h - 3Dfx VooDoo driver types
-*/
+/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */
 
 /*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * Mesa 3-D graphics library
+ * Version:  3.3
+ *
+ * Copyright (C) 1999-2000  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"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * 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.
  *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the
+ * terms stated above.
  *
- * See the file fxapi.c for more informations about authors
+ * Thank you for your contribution, David!
  *
+ * Please make note of the above copyright/license statement.  If you
+ * contributed code or bug fixes to this code under the previous (GNU
+ * Library) license and object to the new license, your code will be
+ * removed at your request.  Please see the Mesa docs/COPYRIGHT file
+ * for more information.
+ *
+ * Additional Mesa/3Dfx driver developers:
+ *   Daryll Strauss <daryll@precisioninsight.com>
+ *   Keith Whitwell <keith@precisioninsight.com>
+ *
+ * See fxapi.h for more revision/author details.
  */
 
+
 #ifndef FXDRV_H
 #define FXDRV_H
 
  * you turn debugging on/off from the debugger.
  */
 
-#ifndef XFree86Server
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <assert.h>
-#else 
+#ifdef XFree86Server
 #include "GL/xf86glx.h"
+#else 
+#include "glheader.h"
 #endif
 
 
@@ -47,6 +64,7 @@
 #include "context.h"
 #include "macros.h"
 #include "matrix.h"
+#include "mem.h"
 #include "texture.h"
 #include "types.h"
 #include "vb.h"
 #include "clip.h"
 #include "vbrender.h"
 
+#ifdef XF86DRI
+typedef struct tfxMesaContext *fxMesaContext;
+#else
 #include "GL/fxmesa.h"
+#endif
 #include "fxglidew.h"
 /* use gl/gl.h GLAPI/GLAPIENTRY/GLCALLBACK in place of WINGDIAPI/APIENTRY/CALLBACK, */
 /* these are defined in mesa gl/gl.h - tjump@spgs.com */
 
 
 
-#if defined(MESA_DEBUG) && 0
 extern void fx_sanity_triangle( GrVertex *, GrVertex *, GrVertex * );
+#if defined(MESA_DEBUG) && 0
 #define grDrawTriangle fx_sanity_triangle
 #endif
 
@@ -140,17 +162,17 @@ typedef struct {
 #endif
 #endif
 
-#define FX_VB_COLOR(fxm, color)                        \
-do {                                           \
-  if (sizeof(GLint) == 4*sizeof(GLubyte)) {    \
-     if (fxm->constColor != *(GLuint*)color) { \
-       fxm->constColor = *(GLuint*)color;      \
-       grConstantColorValue(FXCOLOR4(color));  \
-     }                                         \
-  } else {                                     \
-     grConstantColorValue(FXCOLOR4(color));    \
-  }                                            \
-} while (0)
+#define FX_VB_COLOR(fxm, color)                                \
+  do {                                                 \
+    if (sizeof(GLint) == 4*sizeof(GLubyte)) {          \
+      if (fxm->constColor != *(GLuint*)color) {                \
+       fxm->constColor = *(GLuint*)color;              \
+       FX_grConstantColorValue(FXCOLOR4(color));       \
+      }                                                        \
+    } else {                                           \
+      FX_grConstantColorValue(FXCOLOR4(color));                \
+    }                                                  \
+  } while (0)
 
 #define GOURAUD(x) {                                   \
   GLubyte *col = VB->ColorPtr->data[(x)];              \
@@ -161,9 +183,9 @@ do {                                                \
 }
 
 #if FX_USE_PARGB
-#define GOURAUD2(v, c) {                                                                                                                               \
-  GLubyte *col = c;                                                                                                                                    \
-  v->argb=MESACOLOR2PARGB(col);                                                                                                                        \
+#define GOURAUD2(v, c) {                       \
+  GLubyte *col = c;                            \
+  v->argb=MESACOLOR2PARGB(col);                        \
 }
 #else
 #define GOURAUD2(v, c) {                       \
@@ -204,13 +226,13 @@ do {                                              \
 #define FX_UM_E0_MODULATE           0x00000002
 #define FX_UM_E0_DECAL              0x00000004
 #define FX_UM_E0_BLEND              0x00000008
-#define FX_UM_E0_ADD                           0x00000010
+#define FX_UM_E0_ADD               0x00000010
 
 #define FX_UM_E1_REPLACE            0x00000020
 #define FX_UM_E1_MODULATE           0x00000040
 #define FX_UM_E1_DECAL              0x00000080
 #define FX_UM_E1_BLEND              0x00000100
-#define FX_UM_E1_ADD                           0x00000200
+#define FX_UM_E1_ADD               0x00000200
 
 #define FX_UM_E_ENVMODE             0x000003ff
 
@@ -230,45 +252,38 @@ do {                                              \
 
 #define FX_UM_E_IFMT                0x00fff000
 
-#define FX_UM_COLOR_ITERATED        0x00100000
-#define FX_UM_COLOR_CONSTANT        0x00200000
-#define FX_UM_ALPHA_ITERATED        0x00400000
-#define FX_UM_ALPHA_CONSTANT        0x00800000
+#define FX_UM_COLOR_ITERATED        0x01000000
+#define FX_UM_COLOR_CONSTANT        0x02000000
+#define FX_UM_ALPHA_ITERATED        0x04000000
+#define FX_UM_ALPHA_CONSTANT        0x08000000
 
 typedef void (*tfxRenderVBFunc)(GLcontext *);
 
-typedef struct tfxTMFreeListNode {
-  struct tfxTMFreeListNode *next;
-  FxU32 startAddress, endAddress;
-} tfxTMFreeNode;
-
-typedef struct tfxTMAllocListNode {
-  struct tfxTMAllocListNode *next;
-  FxU32 startAddress, endAddress;
-  struct gl_texture_object *tObj;
-} tfxTMAllocNode;
+/*
+  Memory range from startAddr to endAddr-1
+*/
+typedef struct MemRange_t {
+  struct MemRange_t *next;
+  FxU32 startAddr, endAddr;
+} MemRange;
 
 typedef struct {
-  GLsizei width, height;
-  GLint glideFormat;
-
-  unsigned short *data;
-  GLboolean translated, used;
+  GLsizei width, height;              /* image size */
+  GrTextureFormat_t glideFormat;      /* Glide image format */
+  unsigned short *data;               /* Glide-formated texture image */
 } tfxMipMapLevel;
 
-typedef struct {
-  GLuint lastTimeUsed;
+typedef struct tfxTexInfo_t {
+  struct tfxTexInfo *next;
+  struct gl_texture_object *tObj;
 
+  GLuint lastTimeUsed;
   FxU32 whichTMU;
-
-  tfxTMAllocNode *tm[FX_NUM_TMU];
+  GLboolean isInTM;
 
   tfxMipMapLevel mipmapLevel[MAX_TEXTURE_LEVELS];
-  GLboolean isInTM;
-} tfxTMInfo;
 
-typedef struct {
-  tfxTMInfo tmi;
+  MemRange *tm[FX_NUM_TMU];
 
   GLint minLevel, maxLevel;
   GLint baseLevelInternalFormat;
@@ -384,35 +399,51 @@ struct tfxMesaVertexBuffer {
 
 #define FX_DRIVER_DATA(vb) ((struct tfxMesaVertexBuffer *)((vb)->driver_data))
 #define FX_CONTEXT(ctx) ((fxMesaContext)((ctx)->DriverCtx))
-#define FX_TEXTURE_DATA(t) ((tfxTexInfo *) ((t)->Current->DriverData))
+#define FX_TEXTURE_DATA(t) fxTMGetTexInfo((t)->Current)
 
 #if defined(XFree86Server) || defined(GLX_DIRECT_RENDERING)
 #include "tdfx_init.h"
 #else
 #define DRI_FX_CONTEXT
+#define BEGIN_BOARD_LOCK()
+#define END_BOARD_LOCK()
+#define BEGIN_CLIP_LOOP()
+#define END_CLIP_LOOP()
 #endif
 
+
+/* These lookup table are used to extract RGB values in [0,255] from
+ * 16-bit pixel values.
+ */
+extern GLubyte FX_PixelToR[0x10000];
+extern GLubyte FX_PixelToG[0x10000];
+extern GLubyte FX_PixelToB[0x10000];
+
+
 struct tfxMesaContext {
   GuTexPalette glbPalette;
 
   GLcontext *glCtx;              /* the core Mesa context */
+#if !defined(XFree86Server) && !defined(GLX_DIRECT_RENDERING)
   GLvisual *glVis;               /* describes the color buffer */
   GLframebuffer *glBuffer;       /* the ancillary buffers */
+#endif
 
   GLint board;                   /* the board used for this context */
   GLint width, height;           /* size of color buffer */
 
   GrBuffer_t currentFB;
 
+  GLboolean bgrOrder;
   GrColor_t color;
   GrColor_t clearC;
   GrAlpha_t clearA;
   GLuint constColor;
+  GrCullMode_t cullMode;
 
   tfxUnitsState unitsState;
   tfxUnitsState restoreUnitsState; /* saved during multipass */
 
-
   GLuint tmu_source[FX_NUM_TMU];
   GLuint tex_dest[MAX_TEXTURE_UNITS];
   GLuint setupindex;
@@ -438,12 +469,14 @@ struct tfxMesaContext {
   GLint tmuSrc;
   GLuint lastUnitsMode;
   GLuint freeTexMem[FX_NUM_TMU];
-  tfxTMFreeNode *tmFree[FX_NUM_TMU];
-  tfxTMAllocNode *tmAlloc[FX_NUM_TMU];
+  MemRange *tmPool;
+  MemRange *tmFree[FX_NUM_TMU];
 
   GLenum fogTableMode;
   GLfloat fogDensity;
+  GLfloat fogStart, fogEnd;
   GrFog_t *fogTable;
+  GLint textureAlign;
 
   /* Acc. functions */
 
@@ -477,8 +510,19 @@ struct tfxMesaContext {
   
   FX_GrContext_t glideContext;
 
-  DRI_FX_CONTEXT
+  int x_offset;
+  int y_offset;
+  int y_delta;
+  int screen_width;
+  int screen_height;
+  int initDone;
+  int clipMinX;
+  int clipMaxX;
+  int clipMinY;
+  int clipMaxY;
+  int needClip;
 
+  DRI_FX_CONTEXT
 };
 
 typedef void (*tfxSetupFunc)(struct vertex_buffer *, GLuint, GLuint);
@@ -486,6 +530,7 @@ typedef void (*tfxSetupFunc)(struct vertex_buffer *, GLuint, GLuint);
 extern GrHwConfiguration glbHWConfig;
 extern int glbCurrentBoard;
 
+extern void fxPrintSetupFlags( const char *msg, GLuint flags );
 extern void fxSetupFXUnits(GLcontext *);
 extern void fxSetupDDPointers(GLcontext *);
 extern void fxDDSetNearFar(GLcontext *, GLfloat, GLfloat);
@@ -518,19 +563,30 @@ extern void fxDDClipInit(void);
 extern void fxUpdateDDSpanPointers(GLcontext *);
 extern void fxSetupDDSpanPointers(GLcontext *);
 
-extern void fxDDBufferSize(GLcontext *, GLuint *, GLuint *);
-
-extern void fxDDTexEnv(GLcontext *, GLenum, const GLfloat *);
-extern void fxDDTexImg(GLcontext *, GLenum, struct gl_texture_object *,
-                      GLint, GLint, const struct gl_texture_image *);
+extern void fxPrintTextureData(tfxTexInfo *ti);
+extern GLboolean fxDDTexImage2D(GLcontext *ctx, GLenum target, GLint level,
+                              GLenum format, GLenum type, const GLvoid *pixels,
+                              const struct gl_pixelstore_attrib *packing,
+                              struct gl_texture_object *texObj,
+                              struct gl_texture_image *texImage,
+                              GLboolean *retainInternalCopy);
+extern GLboolean fxDDTexSubImage2D(GLcontext *ctx, GLenum target, GLint level,
+                              GLint xoffset, GLint yoffset,
+                              GLsizei width, GLsizei height,
+                              GLenum format, GLenum type, const GLvoid *pixels,
+                              const struct gl_pixelstore_attrib *packing,
+                              struct gl_texture_object *texObj,
+                              struct gl_texture_image *texImage);
+extern GLvoid *fxDDGetTexImage(GLcontext *ctx, GLenum target, GLint level,
+                               const struct gl_texture_object *texObj,
+                               GLenum *formatOut, GLenum *typeOut,
+                               GLboolean *freeImageOut );
+extern void fxDDTexEnv(GLcontext *, GLenum, GLenum, const GLfloat *);
 extern void fxDDTexParam(GLcontext *, GLenum, struct gl_texture_object *,
                         GLenum, const GLfloat *);
 extern void fxDDTexBind(GLcontext *, GLenum, struct gl_texture_object *);
 extern void fxDDTexDel(GLcontext *, struct gl_texture_object *);
 extern void fxDDTexPalette(GLcontext *, struct gl_texture_object *);
-extern void fxDDTexuseGlbPalette(GLcontext *, GLboolean);
-extern void fxDDTexSubImg(GLcontext *, GLenum, struct gl_texture_object *, GLint,
-                         GLint, GLint, GLint, GLint, GLint, const struct gl_texture_image *);
 extern void fxDDTexUseGlbPalette(GLcontext *, GLboolean);
 
 extern void fxDDEnable(GLcontext *, GLenum, GLboolean);
@@ -569,10 +625,13 @@ extern void fxDDRenderVBIndirectDirect( struct vertex_buffer *VB );
 
 extern void fxDDInitExtensions( GLcontext *ctx );
 
+#define fxTMGetTexInfo(o) ((tfxTexInfo*)((o)->DriverData))
 extern void fxTMInit(fxMesaContext ctx);
 extern void fxTMClose(fxMesaContext ctx);
+extern void fxTMRestoreTextures_NoLock(fxMesaContext ctx);
 extern void fxTMMoveInTM(fxMesaContext, struct gl_texture_object *, GLint);
 extern void fxTMMoveOutTM(fxMesaContext, struct gl_texture_object *);
+#define fxTMMoveOutTM_NoLock fxTMMoveOutTM
 extern void fxTMFreeTexture(fxMesaContext, struct gl_texture_object *);
 extern void fxTMReloadMipMapLevel(fxMesaContext, struct gl_texture_object *, GLint);
 extern void fxTMReloadSubMipMapLevel(fxMesaContext, struct gl_texture_object *,
@@ -589,22 +648,19 @@ extern GLboolean fxDDColorMask(GLcontext *ctx,
                               GLboolean r, GLboolean g, 
                               GLboolean b, GLboolean a );
 
-extern GLuint fxDDDepthTestSpanGeneric(GLcontext *ctx,
-                                       GLuint n, GLint x, GLint y, 
-                                      const GLdepth z[],
-                                       GLubyte mask[]);
-
-extern void fxDDDepthTestPixelsGeneric(GLcontext* ctx,
-                                       GLuint n, 
-                                      const GLint x[], const GLint y[],
-                                       const GLdepth z[], GLubyte mask[]);
+extern void fxDDWriteDepthSpan(GLcontext *ctx, GLuint n, GLint x, GLint y,
+                               const GLdepth depth[], const GLubyte mask[]);
 
-extern void fxDDReadDepthSpanFloat(GLcontext *ctx,
-                                  GLuint n, GLint x, GLint y, GLfloat depth[]);
+extern void fxDDReadDepthSpan(GLcontext *ctx, GLuint n, GLint x, GLint y,
+                              GLdepth depth[]);
 
-extern void fxDDReadDepthSpanInt(GLcontext *ctx,
-                                GLuint n, GLint x, GLint y, GLdepth depth[]);
+extern void fxDDWriteDepthPixels(GLcontext *ctx, GLuint n,
+                                 const GLint x[], const GLint y[],
+                                 const GLdepth depth[], const GLubyte mask[]);
 
+extern void fxDDReadDepthPixels(GLcontext *ctx, GLuint n,
+                                const GLint x[], const GLint y[],
+                                GLdepth depth[]);
 
 extern void fxDDFastPath( struct vertex_buffer *VB );
 
@@ -620,4 +676,11 @@ extern void fxDDDoRenderVB( struct vertex_buffer *VB );
 
 extern int fxDDInitFxMesaContext( fxMesaContext fxMesa );
 
+
+extern void fxSetScissorValues(GLcontext *ctx);
+extern void fxTMMoveInTM_NoLock(fxMesaContext fxMesa, 
+                               struct gl_texture_object *tObj, 
+                               GLint where);
+extern void fxInitPixelTables(fxMesaContext fxMesa, GLboolean bgrOrder);
+
 #endif