17117f1b4Smrg/* 27117f1b4Smrg * Mesa 3-D graphics library 37117f1b4Smrg * 47117f1b4Smrg * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 57117f1b4Smrg * 67117f1b4Smrg * Permission is hereby granted, free of charge, to any person obtaining a 77117f1b4Smrg * copy of this software and associated documentation files (the "Software"), 87117f1b4Smrg * to deal in the Software without restriction, including without limitation 97117f1b4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 107117f1b4Smrg * and/or sell copies of the Software, and to permit persons to whom the 117117f1b4Smrg * Software is furnished to do so, subject to the following conditions: 127117f1b4Smrg * 137117f1b4Smrg * The above copyright notice and this permission notice shall be included 147117f1b4Smrg * in all copies or substantial portions of the Software. 157117f1b4Smrg * 167117f1b4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 177117f1b4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 187117f1b4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20af69d88dSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21af69d88dSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22af69d88dSmrg * OTHER DEALINGS IN THE SOFTWARE. 237117f1b4Smrg */ 247117f1b4Smrg 257117f1b4Smrg 267117f1b4Smrg/** 277117f1b4Smrg * \file swrast/s_context.h 287117f1b4Smrg * \brief Software rasterization context and private types. 29af69d88dSmrg * \author Keith Whitwell <keithw@vmware.com> 307117f1b4Smrg */ 317117f1b4Smrg 327117f1b4Smrg/** 337117f1b4Smrg * \mainpage swrast module 347117f1b4Smrg * 357117f1b4Smrg * This module, software rasterization, contains the software fallback 367117f1b4Smrg * routines for drawing points, lines, triangles, bitmaps and images. 377117f1b4Smrg * All rendering boils down to writing spans (arrays) of pixels with 387117f1b4Smrg * particular colors. The span-writing routines must be implemented 397117f1b4Smrg * by the device driver. 407117f1b4Smrg */ 417117f1b4Smrg 427117f1b4Smrg 437117f1b4Smrg#ifndef S_CONTEXT_H 447117f1b4Smrg#define S_CONTEXT_H 457117f1b4Smrg 46c1f859d4Smrg#include "main/mtypes.h" 47af69d88dSmrg#include "main/texcompress.h" 483464ebd5Sriastradh#include "program/prog_execute.h" 497117f1b4Smrg#include "swrast.h" 50af69d88dSmrg#include "s_fragprog.h" 517117f1b4Smrg#include "s_span.h" 527ec681f3Smrg#include "util/rounding.h" 537117f1b4Smrg 547117f1b4Smrg 553464ebd5Sriastradhtypedef void (*texture_sample_func)(struct gl_context *ctx, 56af69d88dSmrg const struct gl_sampler_object *samp, 577117f1b4Smrg const struct gl_texture_object *tObj, 587117f1b4Smrg GLuint n, const GLfloat texcoords[][4], 594a49301eSmrg const GLfloat lambda[], GLfloat rgba[][4]); 607117f1b4Smrg 617ec681f3Smrgtypedef void (*swrast_blend_func)(struct gl_context *ctx, GLuint n, 627ec681f3Smrg const GLubyte mask[], 637ec681f3Smrg GLvoid *src, const GLvoid *dst, 647ec681f3Smrg GLenum chanType); 657117f1b4Smrg 663464ebd5Sriastradhtypedef void (*swrast_point_func)( struct gl_context *ctx, const SWvertex *); 677117f1b4Smrg 683464ebd5Sriastradhtypedef void (*swrast_line_func)( struct gl_context *ctx, 697117f1b4Smrg const SWvertex *, const SWvertex *); 707117f1b4Smrg 713464ebd5Sriastradhtypedef void (*swrast_tri_func)( struct gl_context *ctx, const SWvertex *, 727117f1b4Smrg const SWvertex *, const SWvertex *); 737117f1b4Smrg 747117f1b4Smrg 753464ebd5Sriastradhtypedef void (*validate_texture_image_func)(struct gl_context *ctx, 767117f1b4Smrg struct gl_texture_object *texObj, 777117f1b4Smrg GLuint face, GLuint level); 787117f1b4Smrg 797117f1b4Smrg 807117f1b4Smrg/** 817117f1b4Smrg * \defgroup Bitmasks 827117f1b4Smrg * Bitmasks to indicate which rasterization options are enabled 837117f1b4Smrg * (RasterMask) 847117f1b4Smrg */ 857117f1b4Smrg/*@{*/ 867117f1b4Smrg#define ALPHATEST_BIT 0x001 /**< Alpha-test pixels */ 877117f1b4Smrg#define BLEND_BIT 0x002 /**< Blend pixels */ 887117f1b4Smrg#define DEPTH_BIT 0x004 /**< Depth-test pixels */ 897117f1b4Smrg#define FOG_BIT 0x008 /**< Fog pixels */ 907117f1b4Smrg#define LOGIC_OP_BIT 0x010 /**< Apply logic op in software */ 917117f1b4Smrg#define CLIP_BIT 0x020 /**< Scissor or window clip pixels */ 927117f1b4Smrg#define STENCIL_BIT 0x040 /**< Stencil pixels */ 937117f1b4Smrg#define MASKING_BIT 0x080 /**< Do glColorMask or glIndexMask */ 947117f1b4Smrg#define MULTI_DRAW_BIT 0x400 /**< Write to more than one color- */ 957117f1b4Smrg /**< buffer or no buffers. */ 967117f1b4Smrg#define OCCLUSION_BIT 0x800 /**< GL_HP_occlusion_test enabled */ 977117f1b4Smrg#define TEXTURE_BIT 0x1000 /**< Texturing really enabled */ 987117f1b4Smrg#define FRAGPROG_BIT 0x2000 /**< Fragment program enabled */ 997117f1b4Smrg#define ATIFRAGSHADER_BIT 0x4000 /**< ATI Fragment shader enabled */ 1007117f1b4Smrg#define CLAMPING_BIT 0x8000 /**< Clamp colors to [0,1] */ 1017117f1b4Smrg/*@}*/ 1027117f1b4Smrg 1037117f1b4Smrg#define _SWRAST_NEW_RASTERMASK (_NEW_BUFFERS| \ 1047117f1b4Smrg _NEW_SCISSOR| \ 1057117f1b4Smrg _NEW_COLOR| \ 1067117f1b4Smrg _NEW_DEPTH| \ 1077117f1b4Smrg _NEW_FOG| \ 1087117f1b4Smrg _NEW_PROGRAM| \ 1097117f1b4Smrg _NEW_STENCIL| \ 1107117f1b4Smrg _NEW_TEXTURE| \ 1117117f1b4Smrg _NEW_VIEWPORT| \ 1127117f1b4Smrg _NEW_DEPTH) 1137117f1b4Smrg 1147117f1b4Smrg 115af69d88dSmrgstruct swrast_texture_image; 116af69d88dSmrg 117af69d88dSmrg 118af69d88dSmrg/** 119af69d88dSmrg * Fetch a texel from texture image at given position. 120af69d88dSmrg */ 121af69d88dSmrgtypedef void (*FetchTexelFunc)(const struct swrast_texture_image *texImage, 122af69d88dSmrg GLint col, GLint row, GLint img, 123af69d88dSmrg GLfloat *texelOut); 124af69d88dSmrg 125af69d88dSmrg 126af69d88dSmrg/** 127af69d88dSmrg * Subclass of gl_texture_image. 128af69d88dSmrg * We need extra fields/info to keep tracking of mapped texture buffers, 129af69d88dSmrg * strides and Fetch functions. 130af69d88dSmrg */ 131af69d88dSmrgstruct swrast_texture_image 132af69d88dSmrg{ 133af69d88dSmrg struct gl_texture_image Base; 134af69d88dSmrg 135af69d88dSmrg GLboolean _IsPowerOfTwo; /**< Are all dimensions powers of two? */ 136af69d88dSmrg 137af69d88dSmrg /** used for mipmap LOD computation */ 138af69d88dSmrg GLfloat WidthScale, HeightScale, DepthScale; 139af69d88dSmrg 140af69d88dSmrg /** 141af69d88dSmrg * Byte stride between rows in ImageSlices. 142af69d88dSmrg * 143af69d88dSmrg * For compressed textures, this is the byte stride between one row of 144af69d88dSmrg * blocks and the next row of blocks. 145af69d88dSmrg * 146af69d88dSmrg * Only valid while one of the ImageSlices is mapped, and must be the same 147af69d88dSmrg * between all slices. 148af69d88dSmrg */ 149af69d88dSmrg GLint RowStride; 150af69d88dSmrg /** 151af69d88dSmrg * When a texture image is mapped for swrast, this array contains pointers 152af69d88dSmrg * to the beginning of each slice. 153af69d88dSmrg * 154af69d88dSmrg * For swrast-allocated textures, these pointers will always stay 155af69d88dSmrg * initialized to point within Buffer. 156af69d88dSmrg */ 157af69d88dSmrg void **ImageSlices; 158af69d88dSmrg 159af69d88dSmrg /** Malloc'd texture memory */ 160af69d88dSmrg GLubyte *Buffer; 161af69d88dSmrg 162af69d88dSmrg FetchTexelFunc FetchTexel; 163af69d88dSmrg 164af69d88dSmrg /** For fetching texels from compressed textures */ 165af69d88dSmrg compressed_fetch_func FetchCompressedTexel; 166af69d88dSmrg}; 167af69d88dSmrg 168af69d88dSmrg 169af69d88dSmrg/** cast wrapper */ 170af69d88dSmrgstatic inline struct swrast_texture_image * 171af69d88dSmrgswrast_texture_image(struct gl_texture_image *img) 172af69d88dSmrg{ 173af69d88dSmrg return (struct swrast_texture_image *) img; 174af69d88dSmrg} 175af69d88dSmrg 176af69d88dSmrg/** cast wrapper */ 177af69d88dSmrgstatic inline const struct swrast_texture_image * 178af69d88dSmrgswrast_texture_image_const(const struct gl_texture_image *img) 179af69d88dSmrg{ 180af69d88dSmrg return (const struct swrast_texture_image *) img; 181af69d88dSmrg} 182af69d88dSmrg 183af69d88dSmrg 184af69d88dSmrg/** 185af69d88dSmrg * Subclass of gl_renderbuffer with extra fields needed for software 186af69d88dSmrg * rendering. 187af69d88dSmrg */ 188af69d88dSmrgstruct swrast_renderbuffer 189af69d88dSmrg{ 190af69d88dSmrg struct gl_renderbuffer Base; 191af69d88dSmrg 192af69d88dSmrg GLubyte *Buffer; /**< The malloc'd memory for buffer */ 193af69d88dSmrg 194af69d88dSmrg /** These fields are only valid while buffer is mapped for rendering */ 195af69d88dSmrg GLubyte *Map; 196af69d88dSmrg GLint RowStride; /**< in bytes */ 197af69d88dSmrg 198af69d88dSmrg /** For span rendering */ 199af69d88dSmrg GLenum ColorType; 200af69d88dSmrg}; 201af69d88dSmrg 202af69d88dSmrg 203af69d88dSmrg/** cast wrapper */ 204af69d88dSmrgstatic inline struct swrast_renderbuffer * 205af69d88dSmrgswrast_renderbuffer(struct gl_renderbuffer *img) 206af69d88dSmrg{ 207af69d88dSmrg return (struct swrast_renderbuffer *) img; 208af69d88dSmrg} 209af69d88dSmrg 210af69d88dSmrg 211af69d88dSmrg 2127117f1b4Smrg/** 2137117f1b4Smrg * \struct SWcontext 2147117f1b4Smrg * \brief Per-context state that's private to the software rasterizer module. 2157117f1b4Smrg */ 2167117f1b4Smrgtypedef struct 2177117f1b4Smrg{ 2187117f1b4Smrg /** Driver interface: 2197117f1b4Smrg */ 2207117f1b4Smrg struct swrast_device_driver Driver; 2217117f1b4Smrg 2227117f1b4Smrg /** Configuration mechanisms to make software rasterizer match 2237117f1b4Smrg * characteristics of the hardware rasterizer (if present): 2247117f1b4Smrg */ 2257117f1b4Smrg GLboolean AllowVertexFog; 2267117f1b4Smrg GLboolean AllowPixelFog; 2277117f1b4Smrg 2287117f1b4Smrg /** Derived values, invalidated on statechanges, updated from 2297117f1b4Smrg * _swrast_validate_derived(): 2307117f1b4Smrg */ 2317117f1b4Smrg GLbitfield _RasterMask; 2327117f1b4Smrg GLfloat _BackfaceSign; /** +1 or -1 */ 2337117f1b4Smrg GLfloat _BackfaceCullSign; /** +1, 0, or -1 */ 2347117f1b4Smrg GLboolean _PreferPixelFog; /* Compute fog blend factor per fragment? */ 2354a49301eSmrg GLboolean _TextureCombinePrimary; 2367117f1b4Smrg GLboolean _FogEnabled; 237c1f859d4Smrg GLboolean _DeferredTexture; 2387117f1b4Smrg 2397117f1b4Smrg /** List/array of the fragment attributes to interpolate */ 240af69d88dSmrg GLuint _ActiveAttribs[VARYING_SLOT_MAX]; 241af69d88dSmrg /** Same info, but as a bitmask of VARYING_BIT_x bits */ 242af69d88dSmrg GLbitfield64 _ActiveAttribMask; 2437117f1b4Smrg /** Number of fragment attributes to interpolate */ 2447117f1b4Smrg GLuint _NumActiveAttribs; 245c1f859d4Smrg /** Indicates how each attrib is to be interpolated (lines/tris) */ 246af69d88dSmrg GLenum _InterpMode[VARYING_SLOT_MAX]; /* GL_FLAT or GL_SMOOTH (for now) */ 2477117f1b4Smrg 2487117f1b4Smrg /* Working values: 2497117f1b4Smrg */ 2507117f1b4Smrg GLuint StippleCounter; /**< Line stipple counter */ 2517117f1b4Smrg GLuint PointLineFacing; 2527117f1b4Smrg GLbitfield NewState; 2537117f1b4Smrg GLuint StateChanges; 2547117f1b4Smrg GLenum Primitive; /* current primitive being drawn (ala glBegin) */ 2554a49301eSmrg GLboolean SpecularVertexAdd; /**< Add specular/secondary color per vertex */ 2567117f1b4Smrg 2573464ebd5Sriastradh void (*InvalidateState)( struct gl_context *ctx, GLbitfield new_state ); 2587117f1b4Smrg 2597117f1b4Smrg /** 2607117f1b4Smrg * When the NewState mask intersects these masks, we invalidate the 2617117f1b4Smrg * Point/Line/Triangle function pointers below. 2627117f1b4Smrg */ 2637117f1b4Smrg /*@{*/ 2647117f1b4Smrg GLbitfield InvalidatePointMask; 2657117f1b4Smrg GLbitfield InvalidateLineMask; 2667117f1b4Smrg GLbitfield InvalidateTriangleMask; 2677117f1b4Smrg /*@}*/ 2687117f1b4Smrg 2697117f1b4Smrg /** 2707117f1b4Smrg * Device drivers plug in functions for these callbacks. 2717117f1b4Smrg * Will be called when the GL state change mask intersects the above masks. 2727117f1b4Smrg */ 2737117f1b4Smrg /*@{*/ 2743464ebd5Sriastradh void (*choose_point)( struct gl_context * ); 2753464ebd5Sriastradh void (*choose_line)( struct gl_context * ); 2763464ebd5Sriastradh void (*choose_triangle)( struct gl_context * ); 2777117f1b4Smrg /*@}*/ 2787117f1b4Smrg 2797117f1b4Smrg /** 2807117f1b4Smrg * Current point, line and triangle drawing functions. 2817117f1b4Smrg */ 2827117f1b4Smrg /*@{*/ 2837117f1b4Smrg swrast_point_func Point; 2847117f1b4Smrg swrast_line_func Line; 2857117f1b4Smrg swrast_tri_func Triangle; 2867117f1b4Smrg /*@}*/ 2877117f1b4Smrg 2887117f1b4Smrg /** 2897117f1b4Smrg * Placeholders for when separate specular (or secondary color) is 2907117f1b4Smrg * enabled but texturing is not. 2917117f1b4Smrg */ 2927117f1b4Smrg /*@{*/ 2937117f1b4Smrg swrast_point_func SpecPoint; 2947117f1b4Smrg swrast_line_func SpecLine; 2957117f1b4Smrg swrast_tri_func SpecTriangle; 2967117f1b4Smrg /*@}*/ 2977117f1b4Smrg 2987117f1b4Smrg /** 2997117f1b4Smrg * Typically, we'll allocate a sw_span structure as a local variable 3007117f1b4Smrg * and set its 'array' pointer to point to this object. The reason is 3017117f1b4Smrg * this object is big and causes problems when allocated on the stack 3027117f1b4Smrg * on some systems. 3037117f1b4Smrg */ 3047117f1b4Smrg SWspanarrays *SpanArrays; 305c1f859d4Smrg SWspanarrays *ZoomedArrays; /**< For pixel zooming */ 3067117f1b4Smrg 3077117f1b4Smrg /** 3087117f1b4Smrg * Used to buffer N GL_POINTS, instead of rendering one by one. 3097117f1b4Smrg */ 3107117f1b4Smrg SWspan PointSpan; 3117117f1b4Smrg 3127117f1b4Smrg /** Internal hooks, kept up to date by the same mechanism as above. 3137117f1b4Smrg */ 3147ec681f3Smrg swrast_blend_func BlendFunc; 315af69d88dSmrg texture_sample_func TextureSample[MAX_COMBINED_TEXTURE_IMAGE_UNITS]; 3167117f1b4Smrg 3177117f1b4Smrg /** Buffer for saving the sampled texture colors. 3187117f1b4Smrg * Needed for GL_ARB_texture_env_crossbar implementation. 3197117f1b4Smrg */ 3204a49301eSmrg GLfloat *TexelBuffer; 3217117f1b4Smrg 3227117f1b4Smrg validate_texture_image_func ValidateTextureImage; 3237117f1b4Smrg 3247117f1b4Smrg /** State used during execution of fragment programs */ 3257117f1b4Smrg struct gl_program_machine FragProgMachine; 3267117f1b4Smrg 327af69d88dSmrg /** Temporary arrays for stencil operations. To avoid large stack 328af69d88dSmrg * allocations. 329af69d88dSmrg */ 330af69d88dSmrg struct { 331af69d88dSmrg GLubyte *buf1, *buf2, *buf3, *buf4; 332af69d88dSmrg } stencil_temp; 333af69d88dSmrg 3347117f1b4Smrg} SWcontext; 3357117f1b4Smrg 3367117f1b4Smrg 3377117f1b4Smrgextern void 3383464ebd5Sriastradh_swrast_validate_derived( struct gl_context *ctx ); 3397117f1b4Smrg 3407117f1b4Smrgextern void 3413464ebd5Sriastradh_swrast_update_texture_samplers(struct gl_context *ctx); 3427117f1b4Smrg 3437117f1b4Smrg 3443464ebd5Sriastradh/** Return SWcontext for the given struct gl_context */ 345af69d88dSmrgstatic inline SWcontext * 3463464ebd5SriastradhSWRAST_CONTEXT(struct gl_context *ctx) 3474a49301eSmrg{ 3484a49301eSmrg return (SWcontext *) ctx->swrast_context; 3494a49301eSmrg} 3504a49301eSmrg 3514a49301eSmrg/** const version of above */ 352af69d88dSmrgstatic inline const SWcontext * 3533464ebd5SriastradhCONST_SWRAST_CONTEXT(const struct gl_context *ctx) 3544a49301eSmrg{ 3554a49301eSmrg return (const SWcontext *) ctx->swrast_context; 3564a49301eSmrg} 3574a49301eSmrg 3584a49301eSmrg 3594a49301eSmrg/** 3604a49301eSmrg * Called prior to framebuffer reading/writing. 3614a49301eSmrg * For drivers that rely on swrast for fallback rendering, this is the 3624a49301eSmrg * driver's opportunity to map renderbuffers and textures. 3634a49301eSmrg */ 364af69d88dSmrgstatic inline void 3653464ebd5Sriastradhswrast_render_start(struct gl_context *ctx) 3664a49301eSmrg{ 3674a49301eSmrg SWcontext *swrast = SWRAST_CONTEXT(ctx); 3684a49301eSmrg if (swrast->Driver.SpanRenderStart) 3694a49301eSmrg swrast->Driver.SpanRenderStart(ctx); 3704a49301eSmrg} 3717117f1b4Smrg 3727117f1b4Smrg 3734a49301eSmrg/** Called after framebuffer reading/writing */ 374af69d88dSmrgstatic inline void 3753464ebd5Sriastradhswrast_render_finish(struct gl_context *ctx) 3764a49301eSmrg{ 3774a49301eSmrg SWcontext *swrast = SWRAST_CONTEXT(ctx); 3784a49301eSmrg if (swrast->Driver.SpanRenderFinish) 3794a49301eSmrg swrast->Driver.SpanRenderFinish(ctx); 3804a49301eSmrg} 3817117f1b4Smrg 3827117f1b4Smrg 383af69d88dSmrgextern void 384af69d88dSmrg_swrast_span_render_start(struct gl_context *ctx); 385af69d88dSmrg 386af69d88dSmrgextern void 387af69d88dSmrg_swrast_span_render_finish(struct gl_context *ctx); 388af69d88dSmrg 389af69d88dSmrgextern void 390af69d88dSmrg_swrast_map_textures(struct gl_context *ctx); 391af69d88dSmrg 392af69d88dSmrgextern void 393af69d88dSmrg_swrast_unmap_textures(struct gl_context *ctx); 394af69d88dSmrg 395af69d88dSmrgextern unsigned int 396af69d88dSmrg_swrast_teximage_slice_height(struct gl_texture_image *texImage); 397af69d88dSmrg 398af69d88dSmrgextern void 399af69d88dSmrg_swrast_map_texture(struct gl_context *ctx, struct gl_texture_object *texObj); 400af69d88dSmrg 401af69d88dSmrgextern void 402af69d88dSmrg_swrast_unmap_texture(struct gl_context *ctx, struct gl_texture_object *texObj); 403af69d88dSmrg 404af69d88dSmrg 405af69d88dSmrgextern void 406af69d88dSmrg_swrast_map_renderbuffers(struct gl_context *ctx); 407af69d88dSmrg 408af69d88dSmrgextern void 409af69d88dSmrg_swrast_unmap_renderbuffers(struct gl_context *ctx); 410af69d88dSmrg 4117117f1b4Smrg 4127117f1b4Smrg/** 4137117f1b4Smrg * Size of an RGBA pixel, in bytes, for given datatype. 4147117f1b4Smrg */ 4157117f1b4Smrg#define RGBA_PIXEL_SIZE(TYPE) \ 4167117f1b4Smrg ((TYPE == GL_UNSIGNED_BYTE) ? 4 * sizeof(GLubyte) : \ 4177117f1b4Smrg ((TYPE == GL_UNSIGNED_SHORT) ? 4 * sizeof(GLushort) \ 4187117f1b4Smrg : 4 * sizeof(GLfloat))) 4197117f1b4Smrg 4207117f1b4Smrg 4217117f1b4Smrg 4224a49301eSmrg/* 4234a49301eSmrg * Fixed point arithmetic macros 4244a49301eSmrg */ 4254a49301eSmrg#ifndef FIXED_FRAC_BITS 4264a49301eSmrg#define FIXED_FRAC_BITS 11 4274a49301eSmrg#endif 4284a49301eSmrg 4294a49301eSmrg#define FIXED_SHIFT FIXED_FRAC_BITS 4304a49301eSmrg#define FIXED_ONE (1 << FIXED_SHIFT) 4314a49301eSmrg#define FIXED_HALF (1 << (FIXED_SHIFT-1)) 4324a49301eSmrg#define FIXED_FRAC_MASK (FIXED_ONE - 1) 4334a49301eSmrg#define FIXED_INT_MASK (~FIXED_FRAC_MASK) 4344a49301eSmrg#define FIXED_EPSILON 1 4354a49301eSmrg#define FIXED_SCALE ((float) FIXED_ONE) 4364a49301eSmrg#define FIXED_DBL_SCALE ((double) FIXED_ONE) 4377ec681f3Smrg#define FloatToFixed(X) (lroundf((X) * FIXED_SCALE)) 4384a49301eSmrg#define FixedToDouble(X) ((X) * (1.0 / FIXED_DBL_SCALE)) 4394a49301eSmrg#define IntToFixed(I) ((I) << FIXED_SHIFT) 4404a49301eSmrg#define FixedToInt(X) ((X) >> FIXED_SHIFT) 4414a49301eSmrg#define FixedToUns(X) (((unsigned int)(X)) >> FIXED_SHIFT) 4424a49301eSmrg#define FixedCeil(X) (((X) + FIXED_ONE - FIXED_EPSILON) & FIXED_INT_MASK) 4434a49301eSmrg#define FixedFloor(X) ((X) & FIXED_INT_MASK) 4444a49301eSmrg#define FixedToFloat(X) ((X) * (1.0F / FIXED_SCALE)) 4454a49301eSmrg#define PosFloatToFixed(X) FloatToFixed(X) 4464a49301eSmrg#define SignedFloatToFixed(X) FloatToFixed(X) 4474a49301eSmrg 4484a49301eSmrg 4494a49301eSmrg 4507117f1b4Smrg/* 4517117f1b4Smrg * XXX these macros are just bandages for now in order to make 4527117f1b4Smrg * CHAN_BITS==32 compile cleanly. 4537117f1b4Smrg * These should probably go elsewhere at some point. 4547117f1b4Smrg */ 4557117f1b4Smrg#if CHAN_TYPE == GL_FLOAT 4567117f1b4Smrg#define ChanToFixed(X) (X) 4577117f1b4Smrg#define FixedToChan(X) (X) 4587117f1b4Smrg#else 4597117f1b4Smrg#define ChanToFixed(X) IntToFixed(X) 4607117f1b4Smrg#define FixedToChan(X) FixedToInt(X) 4617117f1b4Smrg#endif 4627117f1b4Smrg 4637117f1b4Smrg 4647117f1b4Smrg/** 4657117f1b4Smrg * For looping over fragment attributes in the pointe, line 4667117f1b4Smrg * triangle rasterizers. 4677117f1b4Smrg */ 4687117f1b4Smrg#define ATTRIB_LOOP_BEGIN \ 4697117f1b4Smrg { \ 4707117f1b4Smrg GLuint a; \ 4717117f1b4Smrg for (a = 0; a < swrast->_NumActiveAttribs; a++) { \ 4727117f1b4Smrg const GLuint attr = swrast->_ActiveAttribs[a]; 4737117f1b4Smrg 4747117f1b4Smrg#define ATTRIB_LOOP_END } } 4757117f1b4Smrg 4767117f1b4Smrg 477af69d88dSmrg/** 478af69d88dSmrg * Return the address of a pixel value in a mapped renderbuffer. 479af69d88dSmrg */ 480af69d88dSmrgstatic inline GLubyte * 481af69d88dSmrg_swrast_pixel_address(struct gl_renderbuffer *rb, GLint x, GLint y) 482af69d88dSmrg{ 483af69d88dSmrg struct swrast_renderbuffer *srb = swrast_renderbuffer(rb); 484af69d88dSmrg const GLint bpp = _mesa_get_format_bytes(rb->Format); 485af69d88dSmrg const GLint rowStride = srb->RowStride; 486af69d88dSmrg assert(x >= 0); 487af69d88dSmrg assert(y >= 0); 488af69d88dSmrg /* NOTE: using <= only because of s_tritemp.h which gets a pixel 489af69d88dSmrg * address but doesn't necessarily access it. 490af69d88dSmrg */ 491af69d88dSmrg assert(x <= (GLint) rb->Width); 492af69d88dSmrg assert(y <= (GLint) rb->Height); 493af69d88dSmrg assert(srb->Map); 494af69d88dSmrg return (GLubyte *) srb->Map + y * rowStride + x * bpp; 495af69d88dSmrg} 496af69d88dSmrg 497af69d88dSmrg 4987117f1b4Smrg 4997117f1b4Smrg#endif 500