mesa: move gl_texture_image::FetchTexel fields to swrast
[mesa.git] / src / mesa / swrast / s_context.h
index dfe311a40bcc7c1efd39e2ff897e913731450d99..8357483a27f6b73dfe0bde59f1d06d6c1305f98a 100644 (file)
 #ifndef S_CONTEXT_H
 #define S_CONTEXT_H
 
-#include "mtypes.h"
+#include "main/compiler.h"
+#include "main/mtypes.h"
+#include "program/prog_execute.h"
 #include "swrast.h"
 #include "s_span.h"
-#include "prog_execute.h"
 
 
-typedef void (*texture_sample_func)(GLcontext *ctx,
+typedef void (*texture_sample_func)(struct gl_context *ctx,
                                     const struct gl_texture_object *tObj,
                                     GLuint n, const GLfloat texcoords[][4],
-                                    const GLfloat lambda[], GLchan rgba[][4]);
+                                    const GLfloat lambda[], GLfloat rgba[][4]);
 
-typedef void (_ASMAPIP blend_func)( GLcontext *ctx, GLuint n,
+typedef void (_ASMAPIP blend_func)( struct gl_context *ctx, GLuint n,
                                     const GLubyte mask[],
                                     GLvoid *src, const GLvoid *dst,
                                     GLenum chanType);
 
-typedef void (*swrast_point_func)( GLcontext *ctx, const SWvertex *);
+typedef void (*swrast_point_func)( struct gl_context *ctx, const SWvertex *);
 
-typedef void (*swrast_line_func)( GLcontext *ctx,
+typedef void (*swrast_line_func)( struct gl_context *ctx,
                                   const SWvertex *, const SWvertex *);
 
-typedef void (*swrast_tri_func)( GLcontext *ctx, const SWvertex *,
+typedef void (*swrast_tri_func)( struct gl_context *ctx, const SWvertex *,
                                  const SWvertex *, const SWvertex *);
 
 
-typedef void (*validate_texture_image_func)(GLcontext *ctx,
+typedef void (*validate_texture_image_func)(struct gl_context *ctx,
                                             struct gl_texture_object *texObj,
                                             GLuint face, GLuint level);
 
@@ -108,6 +109,73 @@ typedef void (*validate_texture_image_func)(GLcontext *ctx,
                                _NEW_DEPTH)
 
 
+struct swrast_texture_image;
+
+
+typedef void (*FetchTexelFuncC)(const struct swrast_texture_image *texImage,
+                                GLint col, GLint row, GLint img,
+                                GLchan *texelOut);
+
+/**
+ * As above, but returns floats.
+ * Used for depth component images and for upcoming signed/float
+ * texture images.
+ */
+typedef void (*FetchTexelFuncF)(const struct swrast_texture_image *texImage,
+                                GLint col, GLint row, GLint img,
+                                GLfloat *texelOut);
+
+
+typedef void (*StoreTexelFunc)(struct swrast_texture_image *texImage,
+                               GLint col, GLint row, GLint img,
+                               const void *texel);
+
+/**
+ * Subclass of gl_texture_image.
+ * We need extra fields/info to keep tracking of mapped texture buffers,
+ * strides and Fetch/Store functions.
+ */
+struct swrast_texture_image
+{
+   struct gl_texture_image Base;
+
+#if 0
+   /** used for mipmap LOD computation */
+   GLfloat WidthScale, HeightScale, DepthScale;
+   GLboolean _IsPowerOfTwo;  /**< Are all dimensions powers of two? */
+
+   GLubyte *Data;    /**< The actual texture data in malloc'd memory */
+
+   GLint TexelSize;  /**< bytes per texel block */
+#endif
+
+   FetchTexelFuncC FetchTexelc;
+   FetchTexelFuncF FetchTexelf;
+   StoreTexelFunc Store;
+
+#if 0
+   /** These fields only valid when texture memory is mapped */
+   GLubyte **SliceMaps;  /**< points to OneMap or a malloc'd array */
+   GLint RowStride;  /**< bytes per row of blocks */
+#endif
+};
+
+
+/** cast wrapper */
+static INLINE struct swrast_texture_image *
+swrast_texture_image(struct gl_texture_image *img)
+{
+   return (struct swrast_texture_image *) img;
+}
+
+/** cast wrapper */
+static INLINE const struct swrast_texture_image *
+swrast_texture_image_const(const struct gl_texture_image *img)
+{
+   return (const struct swrast_texture_image *) img;
+}
+
+
 /**
  * \struct SWcontext
  * \brief  Per-context state that's private to the software rasterizer module.
@@ -128,22 +196,21 @@ typedef struct
     * _swrast_validate_derived():
     */
    GLbitfield _RasterMask;
-   GLfloat _BackfaceSign;
+   GLfloat _BackfaceSign;      /** +1 or -1 */
+   GLfloat _BackfaceCullSign;  /** +1, 0, or -1 */
    GLboolean _PreferPixelFog;    /* Compute fog blend factor per fragment? */
-   GLboolean _AnyTextureCombine;
+   GLboolean _TextureCombinePrimary;
    GLboolean _FogEnabled;
-   GLenum _FogMode;  /* either GL_FOG_MODE or fragment program's fog mode */
+   GLboolean _DeferredTexture;
 
-   /** Multiple render targets */
-   GLbitfield _ColorOutputsMask;
-   GLuint _NumColorOutputs;
-
-   /** Fragment attributes to compute during rasterization.
-    * Mask of FRAG_BIT_* flags.
-    */
-   GLbitfield _FragmentAttribs;
-   GLuint _MinFragmentAttrib;  /**< Lowest bit set in _FragmentAttribs */
-   GLuint _MaxFragmentAttrib;  /**< Highest bit set in _FragmentAttribs + 1 */
+   /** List/array of the fragment attributes to interpolate */
+   GLuint _ActiveAttribs[FRAG_ATTRIB_MAX];
+   /** Same info, but as a bitmask */
+   GLbitfield _ActiveAttribMask;
+   /** Number of fragment attributes to interpolate */
+   GLuint _NumActiveAttribs;
+   /** Indicates how each attrib is to be interpolated (lines/tris) */
+   GLenum _InterpMode[FRAG_ATTRIB_MAX]; /* GL_FLAT or GL_SMOOTH (for now) */
 
    /* Accum buffer temporaries.
     */
@@ -153,11 +220,13 @@ typedef struct
    /* Working values:
     */
    GLuint StippleCounter;    /**< Line stipple counter */
+   GLuint PointLineFacing;
    GLbitfield NewState;
    GLuint StateChanges;
    GLenum Primitive;    /* current primitive being drawn (ala glBegin) */
+   GLboolean SpecularVertexAdd; /**< Add specular/secondary color per vertex */
 
-   void (*InvalidateState)( GLcontext *ctx, GLbitfield new_state );
+   void (*InvalidateState)( struct gl_context *ctx, GLbitfield new_state );
 
    /**
     * When the NewState mask intersects these masks, we invalidate the
@@ -174,9 +243,9 @@ typedef struct
     * Will be called when the GL state change mask intersects the above masks.
     */
    /*@{*/
-   void (*choose_point)( GLcontext * );
-   void (*choose_line)( GLcontext * );
-   void (*choose_triangle)( GLcontext * );
+   void (*choose_point)( struct gl_context * );
+   void (*choose_line)( struct gl_context * );
+   void (*choose_triangle)( struct gl_context * );
    /*@}*/
 
    /**
@@ -205,6 +274,7 @@ typedef struct
     * on some systems.
     */
    SWspanarrays *SpanArrays;
+   SWspanarrays *ZoomedArrays;  /**< For pixel zooming */
 
    /**
     * Used to buffer N GL_POINTS, instead of rendering one by one.
@@ -219,7 +289,7 @@ typedef struct
    /** Buffer for saving the sampled texture colors.
     * Needed for GL_ARB_texture_env_crossbar implementation.
     */
-   GLchan *TexelBuffer;
+   GLfloat *TexelBuffer;
 
    validate_texture_image_func ValidateTextureImage;
 
@@ -230,27 +300,49 @@ typedef struct
 
 
 extern void
-_swrast_validate_derived( GLcontext *ctx );
+_swrast_validate_derived( struct gl_context *ctx );
 
 extern void
-_swrast_update_texture_samplers(GLcontext *ctx);
+_swrast_update_texture_samplers(struct gl_context *ctx);
 
 
-#define SWRAST_CONTEXT(ctx) ((SWcontext *)ctx->swrast_context)
+/** Return SWcontext for the given struct gl_context */
+static INLINE SWcontext *
+SWRAST_CONTEXT(struct gl_context *ctx)
+{
+   return (SWcontext *) ctx->swrast_context;
+}
 
-#define RENDER_START(SWctx, GLctx)                     \
-   do {                                                        \
-      if ((SWctx)->Driver.SpanRenderStart) {           \
-         (*(SWctx)->Driver.SpanRenderStart)(GLctx);    \
-      }                                                        \
-   } while (0)
+/** const version of above */
+static INLINE const SWcontext *
+CONST_SWRAST_CONTEXT(const struct gl_context *ctx)
+{
+   return (const SWcontext *) ctx->swrast_context;
+}
 
-#define RENDER_FINISH(SWctx, GLctx)                    \
-   do {                                                        \
-      if ((SWctx)->Driver.SpanRenderFinish) {          \
-         (*(SWctx)->Driver.SpanRenderFinish)(GLctx);   \
-      }                                                        \
-   } while (0)
+
+/**
+ * Called prior to framebuffer reading/writing.
+ * For drivers that rely on swrast for fallback rendering, this is the
+ * driver's opportunity to map renderbuffers and textures.
+ */
+static INLINE void
+swrast_render_start(struct gl_context *ctx)
+{
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
+   if (swrast->Driver.SpanRenderStart)
+      swrast->Driver.SpanRenderStart(ctx);
+}
+
+
+/** Called after framebuffer reading/writing */
+static INLINE void
+swrast_render_finish(struct gl_context *ctx)
+{
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
+   if (swrast->Driver.SpanRenderFinish)
+      swrast->Driver.SpanRenderFinish(ctx);
+}
 
 
 
@@ -264,6 +356,34 @@ _swrast_update_texture_samplers(GLcontext *ctx);
 
 
 
+/*
+ * Fixed point arithmetic macros
+ */
+#ifndef FIXED_FRAC_BITS
+#define FIXED_FRAC_BITS 11
+#endif
+
+#define FIXED_SHIFT     FIXED_FRAC_BITS
+#define FIXED_ONE       (1 << FIXED_SHIFT)
+#define FIXED_HALF      (1 << (FIXED_SHIFT-1))
+#define FIXED_FRAC_MASK (FIXED_ONE - 1)
+#define FIXED_INT_MASK  (~FIXED_FRAC_MASK)
+#define FIXED_EPSILON   1
+#define FIXED_SCALE     ((float) FIXED_ONE)
+#define FIXED_DBL_SCALE ((double) FIXED_ONE)
+#define FloatToFixed(X) (IROUND((X) * FIXED_SCALE))
+#define FixedToDouble(X) ((X) * (1.0 / FIXED_DBL_SCALE))
+#define IntToFixed(I)   ((I) << FIXED_SHIFT)
+#define FixedToInt(X)   ((X) >> FIXED_SHIFT)
+#define FixedToUns(X)   (((unsigned int)(X)) >> FIXED_SHIFT)
+#define FixedCeil(X)    (((X) + FIXED_ONE - FIXED_EPSILON) & FIXED_INT_MASK)
+#define FixedFloor(X)   ((X) & FIXED_INT_MASK)
+#define FixedToFloat(X) ((X) * (1.0F / FIXED_SCALE))
+#define PosFloatToFixed(X)      FloatToFixed(X)
+#define SignedFloatToFixed(X)   FloatToFixed(X)
+
+
+
 /*
  * XXX these macros are just bandages for now in order to make
  * CHAN_BITS==32 compile cleanly.
@@ -277,4 +397,19 @@ _swrast_update_texture_samplers(GLcontext *ctx);
 #define FixedToChan(X)  FixedToInt(X)
 #endif
 
+
+/**
+ * For looping over fragment attributes in the pointe, line
+ * triangle rasterizers.
+ */
+#define ATTRIB_LOOP_BEGIN                                \
+   {                                                     \
+      GLuint a;                                          \
+      for (a = 0; a < swrast->_NumActiveAttribs; a++) {  \
+         const GLuint attr = swrast->_ActiveAttribs[a];
+
+#define ATTRIB_LOOP_END } }
+
+
+
 #endif