X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fswrast%2Fs_context.h;h=49c30a3de3b10f9fa44d84efa2c86f6a3e799a18;hb=e426286e21f8a90f40aff2e7617287bfc3306652;hp=46a5fa24f85985ef6a231e23bd52fbf60274fc27;hpb=81ca8b93f212d1946c70660041ce97d98f352608;p=mesa.git diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h index 46a5fa24f85..49c30a3de3b 100644 --- a/src/mesa/swrast/s_context.h +++ b/src/mesa/swrast/s_context.h @@ -1,6 +1,5 @@ /* * Mesa 3-D graphics library - * Version: 6.5.3 * * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. * @@ -17,16 +16,17 @@ * 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. */ /** * \file swrast/s_context.h * \brief Software rasterization context and private types. - * \author Keith Whitwell + * \author Keith Whitwell */ /** @@ -44,31 +44,34 @@ #define S_CONTEXT_H #include "main/mtypes.h" -#include "shader/prog_execute.h" +#include "main/texcompress.h" +#include "program/prog_execute.h" #include "swrast.h" +#include "s_fragprog.h" #include "s_span.h" -typedef void (*texture_sample_func)(GLcontext *ctx, +typedef void (*texture_sample_func)(struct gl_context *ctx, + const struct gl_sampler_object *samp, 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, - const GLubyte mask[], - GLvoid *src, const GLvoid *dst, - GLenum chanType); +typedef void (*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 +111,103 @@ typedef void (*validate_texture_image_func)(GLcontext *ctx, _NEW_DEPTH) +struct swrast_texture_image; + + +/** + * Fetch a texel from texture image at given position. + */ +typedef void (*FetchTexelFunc)(const struct swrast_texture_image *texImage, + GLint col, GLint row, GLint img, + GLfloat *texelOut); + + +/** + * Subclass of gl_texture_image. + * We need extra fields/info to keep tracking of mapped texture buffers, + * strides and Fetch functions. + */ +struct swrast_texture_image +{ + struct gl_texture_image Base; + + GLboolean _IsPowerOfTwo; /**< Are all dimensions powers of two? */ + + /** used for mipmap LOD computation */ + GLfloat WidthScale, HeightScale, DepthScale; + + /** + * Byte stride between rows in ImageSlices. + * + * For compressed textures, this is the byte stride between one row of + * blocks and the next row of blocks. + * + * Only valid while one of the ImageSlices is mapped, and must be the same + * between all slices. + */ + GLint RowStride; + /** + * When a texture image is mapped for swrast, this array contains pointers + * to the beginning of each slice. + * + * For swrast-allocated textures, these pointers will always stay + * initialized to point within Buffer. + */ + void **ImageSlices; + + /** Malloc'd texture memory */ + GLubyte *Buffer; + + FetchTexelFunc FetchTexel; + + /** For fetching texels from compressed textures */ + compressed_fetch_func FetchCompressedTexel; +}; + + +/** 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; +} + + +/** + * Subclass of gl_renderbuffer with extra fields needed for software + * rendering. + */ +struct swrast_renderbuffer +{ + struct gl_renderbuffer Base; + + GLubyte *Buffer; /**< The malloc'd memory for buffer */ + + /** These fields are only valid while buffer is mapped for rendering */ + GLubyte *Map; + GLint RowStride; /**< in bytes */ + + /** For span rendering */ + GLenum ColorType; +}; + + +/** cast wrapper */ +static inline struct swrast_renderbuffer * +swrast_renderbuffer(struct gl_renderbuffer *img) +{ + return (struct swrast_renderbuffer *) img; +} + + + /** * \struct SWcontext * \brief Per-context state that's private to the software rasterizer module. @@ -131,24 +231,18 @@ typedef struct 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; GLboolean _DeferredTexture; - GLenum _FogMode; /* either GL_FOG_MODE or fragment program's fog mode */ /** List/array of the fragment attributes to interpolate */ - GLuint _ActiveAttribs[FRAG_ATTRIB_MAX]; - /** Same info, but as a bitmask */ - GLbitfield _ActiveAttribMask; + GLuint _ActiveAttribs[VARYING_SLOT_MAX]; + /** Same info, but as a bitmask of VARYING_BIT_x bits */ + GLbitfield64 _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. - */ - GLboolean _IntegerAccumMode; /**< Storing unscaled integers? */ - GLfloat _IntegerAccumScaler; /**< Implicit scale factor */ + GLenum _InterpMode[VARYING_SLOT_MAX]; /* GL_FLAT or GL_SMOOTH (for now) */ /* Working values: */ @@ -157,8 +251,9 @@ typedef struct 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 @@ -175,9 +270,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 * ); /*@}*/ /** @@ -216,57 +311,101 @@ typedef struct /** Internal hooks, kept up to date by the same mechanism as above. */ blend_func BlendFunc; - texture_sample_func TextureSample[MAX_TEXTURE_IMAGE_UNITS]; + texture_sample_func TextureSample[MAX_COMBINED_TEXTURE_IMAGE_UNITS]; /** Buffer for saving the sampled texture colors. * Needed for GL_ARB_texture_env_crossbar implementation. */ - GLchan *TexelBuffer; + GLfloat *TexelBuffer; validate_texture_image_func ValidateTextureImage; /** State used during execution of fragment programs */ struct gl_program_machine FragProgMachine; + /** Temporary arrays for stencil operations. To avoid large stack + * allocations. + */ + struct { + GLubyte *buf1, *buf2, *buf3, *buf4; + } stencil_temp; + } SWcontext; 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); -/** Return SWcontext for the given GLcontext */ -static INLINE SWcontext * -SWRAST_CONTEXT(GLcontext *ctx) +/** Return SWcontext for the given struct gl_context */ +static inline SWcontext * +SWRAST_CONTEXT(struct gl_context *ctx) { return (SWcontext *) ctx->swrast_context; } /** const version of above */ -static INLINE const SWcontext * -CONST_SWRAST_CONTEXT(const GLcontext *ctx) +static inline const SWcontext * +CONST_SWRAST_CONTEXT(const struct gl_context *ctx) { return (const SWcontext *) ctx->swrast_context; } -#define RENDER_START(SWctx, GLctx) \ - do { \ - if ((SWctx)->Driver.SpanRenderStart) { \ - (*(SWctx)->Driver.SpanRenderStart)(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); +} + + +extern void +_swrast_span_render_start(struct gl_context *ctx); + +extern void +_swrast_span_render_finish(struct gl_context *ctx); + +extern void +_swrast_map_textures(struct gl_context *ctx); + +extern void +_swrast_unmap_textures(struct gl_context *ctx); + +extern unsigned int +_swrast_teximage_slice_height(struct gl_texture_image *texImage); + +extern void +_swrast_map_texture(struct gl_context *ctx, struct gl_texture_object *texObj); + +extern void +_swrast_unmap_texture(struct gl_context *ctx, struct gl_texture_object *texObj); -#define RENDER_FINISH(SWctx, GLctx) \ - do { \ - if ((SWctx)->Driver.SpanRenderFinish) { \ - (*(SWctx)->Driver.SpanRenderFinish)(GLctx); \ - } \ - } while (0) +extern void +_swrast_map_renderbuffers(struct gl_context *ctx); + +extern void +_swrast_unmap_renderbuffers(struct gl_context *ctx); /** @@ -279,6 +418,34 @@ CONST_SWRAST_CONTEXT(const 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. @@ -306,5 +473,26 @@ CONST_SWRAST_CONTEXT(const GLcontext *ctx) #define ATTRIB_LOOP_END } } +/** + * Return the address of a pixel value in a mapped renderbuffer. + */ +static inline GLubyte * +_swrast_pixel_address(struct gl_renderbuffer *rb, GLint x, GLint y) +{ + struct swrast_renderbuffer *srb = swrast_renderbuffer(rb); + const GLint bpp = _mesa_get_format_bytes(rb->Format); + const GLint rowStride = srb->RowStride; + assert(x >= 0); + assert(y >= 0); + /* NOTE: using <= only because of s_tritemp.h which gets a pixel + * address but doesn't necessarily access it. + */ + assert(x <= (GLint) rb->Width); + assert(y <= (GLint) rb->Height); + assert(srb->Map); + return (GLubyte *) srb->Map + y * rowStride + x * bpp; +} + + #endif