1848b8605Smrg/*
2848b8605Smrg * Mesa 3-D graphics library
3848b8605Smrg *
4848b8605Smrg * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
5848b8605Smrg *
6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
7848b8605Smrg * copy of this software and associated documentation files (the "Software"),
8848b8605Smrg * to deal in the Software without restriction, including without limitation
9848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the
11848b8605Smrg * Software is furnished to do so, subject to the following conditions:
12848b8605Smrg *
13848b8605Smrg * The above copyright notice and this permission notice shall be included
14848b8605Smrg * in all copies or substantial portions of the Software.
15848b8605Smrg *
16848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20848b8605Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21848b8605Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22848b8605Smrg * OTHER DEALINGS IN THE SOFTWARE.
23848b8605Smrg */
24848b8605Smrg
25848b8605Smrg
26848b8605Smrg/**
27848b8605Smrg * \file swrast/s_context.h
28848b8605Smrg * \brief Software rasterization context and private types.
29848b8605Smrg * \author Keith Whitwell <keithw@vmware.com>
30848b8605Smrg */
31848b8605Smrg
32848b8605Smrg/**
33848b8605Smrg * \mainpage swrast module
34848b8605Smrg *
35848b8605Smrg * This module, software rasterization, contains the software fallback
36848b8605Smrg * routines for drawing points, lines, triangles, bitmaps and images.
37848b8605Smrg * All rendering boils down to writing spans (arrays) of pixels with
38848b8605Smrg * particular colors.  The span-writing routines must be implemented
39848b8605Smrg * by the device driver.
40848b8605Smrg */
41848b8605Smrg
42848b8605Smrg
43848b8605Smrg#ifndef S_CONTEXT_H
44848b8605Smrg#define S_CONTEXT_H
45848b8605Smrg
46848b8605Smrg#include "main/mtypes.h"
47848b8605Smrg#include "main/texcompress.h"
48848b8605Smrg#include "program/prog_execute.h"
49848b8605Smrg#include "swrast.h"
50848b8605Smrg#include "s_fragprog.h"
51848b8605Smrg#include "s_span.h"
52848b8605Smrg
53848b8605Smrg
54848b8605Smrgtypedef void (*texture_sample_func)(struct gl_context *ctx,
55848b8605Smrg                                    const struct gl_sampler_object *samp,
56848b8605Smrg                                    const struct gl_texture_object *tObj,
57848b8605Smrg                                    GLuint n, const GLfloat texcoords[][4],
58848b8605Smrg                                    const GLfloat lambda[], GLfloat rgba[][4]);
59848b8605Smrg
60b8e80941Smrgtypedef void (*blend_func)(struct gl_context *ctx, GLuint n,
61b8e80941Smrg                           const GLubyte mask[],
62b8e80941Smrg                           GLvoid *src, const GLvoid *dst,
63b8e80941Smrg                           GLenum chanType);
64848b8605Smrg
65848b8605Smrgtypedef void (*swrast_point_func)( struct gl_context *ctx, const SWvertex *);
66848b8605Smrg
67848b8605Smrgtypedef void (*swrast_line_func)( struct gl_context *ctx,
68848b8605Smrg                                  const SWvertex *, const SWvertex *);
69848b8605Smrg
70848b8605Smrgtypedef void (*swrast_tri_func)( struct gl_context *ctx, const SWvertex *,
71848b8605Smrg                                 const SWvertex *, const SWvertex *);
72848b8605Smrg
73848b8605Smrg
74848b8605Smrgtypedef void (*validate_texture_image_func)(struct gl_context *ctx,
75848b8605Smrg                                            struct gl_texture_object *texObj,
76848b8605Smrg                                            GLuint face, GLuint level);
77848b8605Smrg
78848b8605Smrg
79848b8605Smrg/**
80848b8605Smrg * \defgroup Bitmasks
81848b8605Smrg * Bitmasks to indicate which rasterization options are enabled
82848b8605Smrg * (RasterMask)
83848b8605Smrg */
84848b8605Smrg/*@{*/
85848b8605Smrg#define ALPHATEST_BIT		0x001	/**< Alpha-test pixels */
86848b8605Smrg#define BLEND_BIT		0x002	/**< Blend pixels */
87848b8605Smrg#define DEPTH_BIT		0x004	/**< Depth-test pixels */
88848b8605Smrg#define FOG_BIT			0x008	/**< Fog pixels */
89848b8605Smrg#define LOGIC_OP_BIT		0x010	/**< Apply logic op in software */
90848b8605Smrg#define CLIP_BIT		0x020	/**< Scissor or window clip pixels */
91848b8605Smrg#define STENCIL_BIT		0x040	/**< Stencil pixels */
92848b8605Smrg#define MASKING_BIT		0x080	/**< Do glColorMask or glIndexMask */
93848b8605Smrg#define MULTI_DRAW_BIT		0x400	/**< Write to more than one color- */
94848b8605Smrg                                        /**< buffer or no buffers. */
95848b8605Smrg#define OCCLUSION_BIT           0x800   /**< GL_HP_occlusion_test enabled */
96848b8605Smrg#define TEXTURE_BIT		0x1000	/**< Texturing really enabled */
97848b8605Smrg#define FRAGPROG_BIT            0x2000  /**< Fragment program enabled */
98848b8605Smrg#define ATIFRAGSHADER_BIT       0x4000  /**< ATI Fragment shader enabled */
99848b8605Smrg#define CLAMPING_BIT            0x8000  /**< Clamp colors to [0,1] */
100848b8605Smrg/*@}*/
101848b8605Smrg
102848b8605Smrg#define _SWRAST_NEW_RASTERMASK (_NEW_BUFFERS|	\
103848b8605Smrg			        _NEW_SCISSOR|	\
104848b8605Smrg			        _NEW_COLOR|	\
105848b8605Smrg			        _NEW_DEPTH|	\
106848b8605Smrg			        _NEW_FOG|	\
107848b8605Smrg                                _NEW_PROGRAM|   \
108848b8605Smrg			        _NEW_STENCIL|	\
109848b8605Smrg			        _NEW_TEXTURE|	\
110848b8605Smrg			        _NEW_VIEWPORT|	\
111848b8605Smrg			        _NEW_DEPTH)
112848b8605Smrg
113848b8605Smrg
114848b8605Smrgstruct swrast_texture_image;
115848b8605Smrg
116848b8605Smrg
117848b8605Smrg/**
118848b8605Smrg * Fetch a texel from texture image at given position.
119848b8605Smrg */
120848b8605Smrgtypedef void (*FetchTexelFunc)(const struct swrast_texture_image *texImage,
121848b8605Smrg                               GLint col, GLint row, GLint img,
122848b8605Smrg                               GLfloat *texelOut);
123848b8605Smrg
124848b8605Smrg
125848b8605Smrg/**
126848b8605Smrg * Subclass of gl_texture_image.
127848b8605Smrg * We need extra fields/info to keep tracking of mapped texture buffers,
128848b8605Smrg * strides and Fetch functions.
129848b8605Smrg */
130848b8605Smrgstruct swrast_texture_image
131848b8605Smrg{
132848b8605Smrg   struct gl_texture_image Base;
133848b8605Smrg
134848b8605Smrg   GLboolean _IsPowerOfTwo;  /**< Are all dimensions powers of two? */
135848b8605Smrg
136848b8605Smrg   /** used for mipmap LOD computation */
137848b8605Smrg   GLfloat WidthScale, HeightScale, DepthScale;
138848b8605Smrg
139848b8605Smrg   /**
140848b8605Smrg    * Byte stride between rows in ImageSlices.
141848b8605Smrg    *
142848b8605Smrg    * For compressed textures, this is the byte stride between one row of
143848b8605Smrg    * blocks and the next row of blocks.
144848b8605Smrg    *
145848b8605Smrg    * Only valid while one of the ImageSlices is mapped, and must be the same
146848b8605Smrg    * between all slices.
147848b8605Smrg    */
148848b8605Smrg   GLint RowStride;
149848b8605Smrg   /**
150848b8605Smrg    * When a texture image is mapped for swrast, this array contains pointers
151848b8605Smrg    * to the beginning of each slice.
152848b8605Smrg    *
153848b8605Smrg    * For swrast-allocated textures, these pointers will always stay
154848b8605Smrg    * initialized to point within Buffer.
155848b8605Smrg    */
156848b8605Smrg   void **ImageSlices;
157848b8605Smrg
158848b8605Smrg   /** Malloc'd texture memory */
159848b8605Smrg   GLubyte *Buffer;
160848b8605Smrg
161848b8605Smrg   FetchTexelFunc FetchTexel;
162848b8605Smrg
163848b8605Smrg   /** For fetching texels from compressed textures */
164848b8605Smrg   compressed_fetch_func FetchCompressedTexel;
165848b8605Smrg};
166848b8605Smrg
167848b8605Smrg
168848b8605Smrg/** cast wrapper */
169848b8605Smrgstatic inline struct swrast_texture_image *
170848b8605Smrgswrast_texture_image(struct gl_texture_image *img)
171848b8605Smrg{
172848b8605Smrg   return (struct swrast_texture_image *) img;
173848b8605Smrg}
174848b8605Smrg
175848b8605Smrg/** cast wrapper */
176848b8605Smrgstatic inline const struct swrast_texture_image *
177848b8605Smrgswrast_texture_image_const(const struct gl_texture_image *img)
178848b8605Smrg{
179848b8605Smrg   return (const struct swrast_texture_image *) img;
180848b8605Smrg}
181848b8605Smrg
182848b8605Smrg
183848b8605Smrg/**
184848b8605Smrg * Subclass of gl_renderbuffer with extra fields needed for software
185848b8605Smrg * rendering.
186848b8605Smrg */
187848b8605Smrgstruct swrast_renderbuffer
188848b8605Smrg{
189848b8605Smrg   struct gl_renderbuffer Base;
190848b8605Smrg
191848b8605Smrg   GLubyte *Buffer;     /**< The malloc'd memory for buffer */
192848b8605Smrg
193848b8605Smrg   /** These fields are only valid while buffer is mapped for rendering */
194848b8605Smrg   GLubyte *Map;
195848b8605Smrg   GLint RowStride;    /**< in bytes */
196848b8605Smrg
197848b8605Smrg   /** For span rendering */
198848b8605Smrg   GLenum ColorType;
199848b8605Smrg};
200848b8605Smrg
201848b8605Smrg
202848b8605Smrg/** cast wrapper */
203848b8605Smrgstatic inline struct swrast_renderbuffer *
204848b8605Smrgswrast_renderbuffer(struct gl_renderbuffer *img)
205848b8605Smrg{
206848b8605Smrg   return (struct swrast_renderbuffer *) img;
207848b8605Smrg}
208848b8605Smrg
209848b8605Smrg
210848b8605Smrg
211848b8605Smrg/**
212848b8605Smrg * \struct SWcontext
213848b8605Smrg * \brief  Per-context state that's private to the software rasterizer module.
214848b8605Smrg */
215848b8605Smrgtypedef struct
216848b8605Smrg{
217848b8605Smrg   /** Driver interface:
218848b8605Smrg    */
219848b8605Smrg   struct swrast_device_driver Driver;
220848b8605Smrg
221848b8605Smrg   /** Configuration mechanisms to make software rasterizer match
222848b8605Smrg    * characteristics of the hardware rasterizer (if present):
223848b8605Smrg    */
224848b8605Smrg   GLboolean AllowVertexFog;
225848b8605Smrg   GLboolean AllowPixelFog;
226848b8605Smrg
227848b8605Smrg   /** Derived values, invalidated on statechanges, updated from
228848b8605Smrg    * _swrast_validate_derived():
229848b8605Smrg    */
230848b8605Smrg   GLbitfield _RasterMask;
231848b8605Smrg   GLfloat _BackfaceSign;      /** +1 or -1 */
232848b8605Smrg   GLfloat _BackfaceCullSign;  /** +1, 0, or -1 */
233848b8605Smrg   GLboolean _PreferPixelFog;    /* Compute fog blend factor per fragment? */
234848b8605Smrg   GLboolean _TextureCombinePrimary;
235848b8605Smrg   GLboolean _FogEnabled;
236848b8605Smrg   GLboolean _DeferredTexture;
237848b8605Smrg
238848b8605Smrg   /** List/array of the fragment attributes to interpolate */
239848b8605Smrg   GLuint _ActiveAttribs[VARYING_SLOT_MAX];
240848b8605Smrg   /** Same info, but as a bitmask of VARYING_BIT_x bits */
241848b8605Smrg   GLbitfield64 _ActiveAttribMask;
242848b8605Smrg   /** Number of fragment attributes to interpolate */
243848b8605Smrg   GLuint _NumActiveAttribs;
244848b8605Smrg   /** Indicates how each attrib is to be interpolated (lines/tris) */
245848b8605Smrg   GLenum _InterpMode[VARYING_SLOT_MAX]; /* GL_FLAT or GL_SMOOTH (for now) */
246848b8605Smrg
247848b8605Smrg   /* Working values:
248848b8605Smrg    */
249848b8605Smrg   GLuint StippleCounter;    /**< Line stipple counter */
250848b8605Smrg   GLuint PointLineFacing;
251848b8605Smrg   GLbitfield NewState;
252848b8605Smrg   GLuint StateChanges;
253848b8605Smrg   GLenum Primitive;    /* current primitive being drawn (ala glBegin) */
254848b8605Smrg   GLboolean SpecularVertexAdd; /**< Add specular/secondary color per vertex */
255848b8605Smrg
256848b8605Smrg   void (*InvalidateState)( struct gl_context *ctx, GLbitfield new_state );
257848b8605Smrg
258848b8605Smrg   /**
259848b8605Smrg    * When the NewState mask intersects these masks, we invalidate the
260848b8605Smrg    * Point/Line/Triangle function pointers below.
261848b8605Smrg    */
262848b8605Smrg   /*@{*/
263848b8605Smrg   GLbitfield InvalidatePointMask;
264848b8605Smrg   GLbitfield InvalidateLineMask;
265848b8605Smrg   GLbitfield InvalidateTriangleMask;
266848b8605Smrg   /*@}*/
267848b8605Smrg
268848b8605Smrg   /**
269848b8605Smrg    * Device drivers plug in functions for these callbacks.
270848b8605Smrg    * Will be called when the GL state change mask intersects the above masks.
271848b8605Smrg    */
272848b8605Smrg   /*@{*/
273848b8605Smrg   void (*choose_point)( struct gl_context * );
274848b8605Smrg   void (*choose_line)( struct gl_context * );
275848b8605Smrg   void (*choose_triangle)( struct gl_context * );
276848b8605Smrg   /*@}*/
277848b8605Smrg
278848b8605Smrg   /**
279848b8605Smrg    * Current point, line and triangle drawing functions.
280848b8605Smrg    */
281848b8605Smrg   /*@{*/
282848b8605Smrg   swrast_point_func Point;
283848b8605Smrg   swrast_line_func Line;
284848b8605Smrg   swrast_tri_func Triangle;
285848b8605Smrg   /*@}*/
286848b8605Smrg
287848b8605Smrg   /**
288848b8605Smrg    * Placeholders for when separate specular (or secondary color) is
289848b8605Smrg    * enabled but texturing is not.
290848b8605Smrg    */
291848b8605Smrg   /*@{*/
292848b8605Smrg   swrast_point_func SpecPoint;
293848b8605Smrg   swrast_line_func SpecLine;
294848b8605Smrg   swrast_tri_func SpecTriangle;
295848b8605Smrg   /*@}*/
296848b8605Smrg
297848b8605Smrg   /**
298848b8605Smrg    * Typically, we'll allocate a sw_span structure as a local variable
299848b8605Smrg    * and set its 'array' pointer to point to this object.  The reason is
300848b8605Smrg    * this object is big and causes problems when allocated on the stack
301848b8605Smrg    * on some systems.
302848b8605Smrg    */
303848b8605Smrg   SWspanarrays *SpanArrays;
304848b8605Smrg   SWspanarrays *ZoomedArrays;  /**< For pixel zooming */
305848b8605Smrg
306848b8605Smrg   /**
307848b8605Smrg    * Used to buffer N GL_POINTS, instead of rendering one by one.
308848b8605Smrg    */
309848b8605Smrg   SWspan PointSpan;
310848b8605Smrg
311848b8605Smrg   /** Internal hooks, kept up to date by the same mechanism as above.
312848b8605Smrg    */
313848b8605Smrg   blend_func BlendFunc;
314848b8605Smrg   texture_sample_func TextureSample[MAX_COMBINED_TEXTURE_IMAGE_UNITS];
315848b8605Smrg
316848b8605Smrg   /** Buffer for saving the sampled texture colors.
317848b8605Smrg    * Needed for GL_ARB_texture_env_crossbar implementation.
318848b8605Smrg    */
319848b8605Smrg   GLfloat *TexelBuffer;
320848b8605Smrg
321848b8605Smrg   validate_texture_image_func ValidateTextureImage;
322848b8605Smrg
323848b8605Smrg   /** State used during execution of fragment programs */
324848b8605Smrg   struct gl_program_machine FragProgMachine;
325848b8605Smrg
326848b8605Smrg   /** Temporary arrays for stencil operations.  To avoid large stack
327848b8605Smrg    * allocations.
328848b8605Smrg    */
329848b8605Smrg   struct {
330848b8605Smrg      GLubyte *buf1, *buf2, *buf3, *buf4;
331848b8605Smrg   } stencil_temp;
332848b8605Smrg
333848b8605Smrg} SWcontext;
334848b8605Smrg
335848b8605Smrg
336848b8605Smrgextern void
337848b8605Smrg_swrast_validate_derived( struct gl_context *ctx );
338848b8605Smrg
339848b8605Smrgextern void
340848b8605Smrg_swrast_update_texture_samplers(struct gl_context *ctx);
341848b8605Smrg
342848b8605Smrg
343848b8605Smrg/** Return SWcontext for the given struct gl_context */
344848b8605Smrgstatic inline SWcontext *
345848b8605SmrgSWRAST_CONTEXT(struct gl_context *ctx)
346848b8605Smrg{
347848b8605Smrg   return (SWcontext *) ctx->swrast_context;
348848b8605Smrg}
349848b8605Smrg
350848b8605Smrg/** const version of above */
351848b8605Smrgstatic inline const SWcontext *
352848b8605SmrgCONST_SWRAST_CONTEXT(const struct gl_context *ctx)
353848b8605Smrg{
354848b8605Smrg   return (const SWcontext *) ctx->swrast_context;
355848b8605Smrg}
356848b8605Smrg
357848b8605Smrg
358848b8605Smrg/**
359848b8605Smrg * Called prior to framebuffer reading/writing.
360848b8605Smrg * For drivers that rely on swrast for fallback rendering, this is the
361848b8605Smrg * driver's opportunity to map renderbuffers and textures.
362848b8605Smrg */
363848b8605Smrgstatic inline void
364848b8605Smrgswrast_render_start(struct gl_context *ctx)
365848b8605Smrg{
366848b8605Smrg   SWcontext *swrast = SWRAST_CONTEXT(ctx);
367848b8605Smrg   if (swrast->Driver.SpanRenderStart)
368848b8605Smrg      swrast->Driver.SpanRenderStart(ctx);
369848b8605Smrg}
370848b8605Smrg
371848b8605Smrg
372848b8605Smrg/** Called after framebuffer reading/writing */
373848b8605Smrgstatic inline void
374848b8605Smrgswrast_render_finish(struct gl_context *ctx)
375848b8605Smrg{
376848b8605Smrg   SWcontext *swrast = SWRAST_CONTEXT(ctx);
377848b8605Smrg   if (swrast->Driver.SpanRenderFinish)
378848b8605Smrg      swrast->Driver.SpanRenderFinish(ctx);
379848b8605Smrg}
380848b8605Smrg
381848b8605Smrg
382848b8605Smrgextern void
383848b8605Smrg_swrast_span_render_start(struct gl_context *ctx);
384848b8605Smrg
385848b8605Smrgextern void
386848b8605Smrg_swrast_span_render_finish(struct gl_context *ctx);
387848b8605Smrg
388848b8605Smrgextern void
389848b8605Smrg_swrast_map_textures(struct gl_context *ctx);
390848b8605Smrg
391848b8605Smrgextern void
392848b8605Smrg_swrast_unmap_textures(struct gl_context *ctx);
393848b8605Smrg
394848b8605Smrgextern unsigned int
395848b8605Smrg_swrast_teximage_slice_height(struct gl_texture_image *texImage);
396848b8605Smrg
397848b8605Smrgextern void
398848b8605Smrg_swrast_map_texture(struct gl_context *ctx, struct gl_texture_object *texObj);
399848b8605Smrg
400848b8605Smrgextern void
401848b8605Smrg_swrast_unmap_texture(struct gl_context *ctx, struct gl_texture_object *texObj);
402848b8605Smrg
403848b8605Smrg
404848b8605Smrgextern void
405848b8605Smrg_swrast_map_renderbuffers(struct gl_context *ctx);
406848b8605Smrg
407848b8605Smrgextern void
408848b8605Smrg_swrast_unmap_renderbuffers(struct gl_context *ctx);
409848b8605Smrg
410848b8605Smrg
411848b8605Smrg/**
412848b8605Smrg * Size of an RGBA pixel, in bytes, for given datatype.
413848b8605Smrg */
414848b8605Smrg#define RGBA_PIXEL_SIZE(TYPE)                                     \
415848b8605Smrg         ((TYPE == GL_UNSIGNED_BYTE) ? 4 * sizeof(GLubyte) :      \
416848b8605Smrg          ((TYPE == GL_UNSIGNED_SHORT) ? 4 * sizeof(GLushort)     \
417848b8605Smrg           : 4 * sizeof(GLfloat)))
418848b8605Smrg
419848b8605Smrg
420848b8605Smrg
421848b8605Smrg/*
422848b8605Smrg * Fixed point arithmetic macros
423848b8605Smrg */
424848b8605Smrg#ifndef FIXED_FRAC_BITS
425848b8605Smrg#define FIXED_FRAC_BITS 11
426848b8605Smrg#endif
427848b8605Smrg
428848b8605Smrg#define FIXED_SHIFT     FIXED_FRAC_BITS
429848b8605Smrg#define FIXED_ONE       (1 << FIXED_SHIFT)
430848b8605Smrg#define FIXED_HALF      (1 << (FIXED_SHIFT-1))
431848b8605Smrg#define FIXED_FRAC_MASK (FIXED_ONE - 1)
432848b8605Smrg#define FIXED_INT_MASK  (~FIXED_FRAC_MASK)
433848b8605Smrg#define FIXED_EPSILON   1
434848b8605Smrg#define FIXED_SCALE     ((float) FIXED_ONE)
435848b8605Smrg#define FIXED_DBL_SCALE ((double) FIXED_ONE)
436848b8605Smrg#define FloatToFixed(X) (IROUND((X) * FIXED_SCALE))
437848b8605Smrg#define FixedToDouble(X) ((X) * (1.0 / FIXED_DBL_SCALE))
438848b8605Smrg#define IntToFixed(I)   ((I) << FIXED_SHIFT)
439848b8605Smrg#define FixedToInt(X)   ((X) >> FIXED_SHIFT)
440848b8605Smrg#define FixedToUns(X)   (((unsigned int)(X)) >> FIXED_SHIFT)
441848b8605Smrg#define FixedCeil(X)    (((X) + FIXED_ONE - FIXED_EPSILON) & FIXED_INT_MASK)
442848b8605Smrg#define FixedFloor(X)   ((X) & FIXED_INT_MASK)
443848b8605Smrg#define FixedToFloat(X) ((X) * (1.0F / FIXED_SCALE))
444848b8605Smrg#define PosFloatToFixed(X)      FloatToFixed(X)
445848b8605Smrg#define SignedFloatToFixed(X)   FloatToFixed(X)
446848b8605Smrg
447848b8605Smrg
448848b8605Smrg
449848b8605Smrg/*
450848b8605Smrg * XXX these macros are just bandages for now in order to make
451848b8605Smrg * CHAN_BITS==32 compile cleanly.
452848b8605Smrg * These should probably go elsewhere at some point.
453848b8605Smrg */
454848b8605Smrg#if CHAN_TYPE == GL_FLOAT
455848b8605Smrg#define ChanToFixed(X)  (X)
456848b8605Smrg#define FixedToChan(X)  (X)
457848b8605Smrg#else
458848b8605Smrg#define ChanToFixed(X)  IntToFixed(X)
459848b8605Smrg#define FixedToChan(X)  FixedToInt(X)
460848b8605Smrg#endif
461848b8605Smrg
462848b8605Smrg
463848b8605Smrg/**
464848b8605Smrg * For looping over fragment attributes in the pointe, line
465848b8605Smrg * triangle rasterizers.
466848b8605Smrg */
467848b8605Smrg#define ATTRIB_LOOP_BEGIN                                \
468848b8605Smrg   {                                                     \
469848b8605Smrg      GLuint a;                                          \
470848b8605Smrg      for (a = 0; a < swrast->_NumActiveAttribs; a++) {  \
471848b8605Smrg         const GLuint attr = swrast->_ActiveAttribs[a];
472848b8605Smrg
473848b8605Smrg#define ATTRIB_LOOP_END } }
474848b8605Smrg
475848b8605Smrg
476848b8605Smrg/**
477848b8605Smrg * Return the address of a pixel value in a mapped renderbuffer.
478848b8605Smrg */
479848b8605Smrgstatic inline GLubyte *
480848b8605Smrg_swrast_pixel_address(struct gl_renderbuffer *rb, GLint x, GLint y)
481848b8605Smrg{
482848b8605Smrg   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
483848b8605Smrg   const GLint bpp = _mesa_get_format_bytes(rb->Format);
484848b8605Smrg   const GLint rowStride = srb->RowStride;
485848b8605Smrg   assert(x >= 0);
486848b8605Smrg   assert(y >= 0);
487848b8605Smrg   /* NOTE: using <= only because of s_tritemp.h which gets a pixel
488848b8605Smrg    * address but doesn't necessarily access it.
489848b8605Smrg    */
490848b8605Smrg   assert(x <= (GLint) rb->Width);
491848b8605Smrg   assert(y <= (GLint) rb->Height);
492848b8605Smrg   assert(srb->Map);
493848b8605Smrg   return (GLubyte *) srb->Map + y * rowStride + x * bpp;
494848b8605Smrg}
495848b8605Smrg
496848b8605Smrg
497848b8605Smrg
498848b8605Smrg#endif
499