diff options
author | marha <marha@users.sourceforge.net> | 2012-02-13 08:47:19 +0100 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2012-02-13 08:47:19 +0100 |
commit | eaa70945cb3f1a432b8c505ecede9ebc7769f36d (patch) | |
tree | 8e44ff4da739e384a2c6a34c1b42ecfb8e212344 /mesalib/src | |
parent | 474621addc25cb22865c54b70ffbec07c82eb04c (diff) | |
download | vcxsrv-eaa70945cb3f1a432b8c505ecede9ebc7769f36d.tar.gz vcxsrv-eaa70945cb3f1a432b8c505ecede9ebc7769f36d.tar.bz2 vcxsrv-eaa70945cb3f1a432b8c505ecede9ebc7769f36d.zip |
libX11 libxcb mesa xserver mkfontscale git update 13 feb 2012
Diffstat (limited to 'mesalib/src')
31 files changed, 1049 insertions, 1106 deletions
diff --git a/mesalib/src/glsl/Android.mk b/mesalib/src/glsl/Android.mk index 754f3cced..cf793d65e 100644 --- a/mesalib/src/glsl/Android.mk +++ b/mesalib/src/glsl/Android.mk @@ -39,6 +39,7 @@ LOCAL_SRC_FILES := \ $(LIBGLSL_CXX_FILES) LOCAL_C_INCLUDES := \ + external/astl/include \ $(MESA_TOP)/src/mapi \ $(MESA_TOP)/src/mesa diff --git a/mesalib/src/glsl/loop_unroll.cpp b/mesalib/src/glsl/loop_unroll.cpp index 5b84e1014..d0bcaa670 100644 --- a/mesalib/src/glsl/loop_unroll.cpp +++ b/mesalib/src/glsl/loop_unroll.cpp @@ -56,6 +56,7 @@ loop_unroll_visitor::visit_leave(ir_loop *ir) { loop_variable_state *const ls = this->state->get(ir); int iterations; + unsigned ir_count; /* If we've entered a loop that hasn't been analyzed, something really, * really bad has happened. @@ -78,6 +79,20 @@ loop_unroll_visitor::visit_leave(ir_loop *ir) if (iterations > (int) max_iterations) return visit_continue; + /* Don't try to unroll nested loops and loops with a huge body. + */ + ir_count = 0; + foreach_list(node, &ir->body_instructions) { + ++ir_count; + + /* If the loop body gets to huge, do not unroll. */ + if (5*max_iterations < ir_count*iterations) + return visit_continue; + /* Do not unroll loops with child loop nodes. */ + if (((ir_instruction *) node)->as_loop()) + return visit_continue; + } + if (ls->num_loop_jumps > 1) return visit_continue; else if (ls->num_loop_jumps) { diff --git a/mesalib/src/mesa/drivers/common/meta.c b/mesalib/src/mesa/drivers/common/meta.c index aa5fef873..0cf1028c4 100644 --- a/mesalib/src/mesa/drivers/common/meta.c +++ b/mesalib/src/mesa/drivers/common/meta.c @@ -3029,7 +3029,8 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target, /* sanity check */ status = _mesa_CheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { - abort(); + _mesa_problem(ctx, "Unexpected incomplete framebuffer in " + "_mesa_meta_GenerateMipmap()"); break; } diff --git a/mesalib/src/mesa/main/extensions.c b/mesalib/src/mesa/main/extensions.c index b02a49de4..d945124d2 100644 --- a/mesalib/src/mesa/main/extensions.c +++ b/mesalib/src/mesa/main/extensions.c @@ -931,9 +931,6 @@ _mesa_get_enabled_extension(struct gl_context *ctx, GLuint index) size_t n; const struct extension *i; - if (index < 0) - return NULL; - base = (GLboolean*) &ctx->Extensions; n = 0; for (i = extension_table; i->name != 0; ++i) { diff --git a/mesalib/src/mesa/main/light.c b/mesalib/src/mesa/main/light.c index bf4bee3d6..a16d0e998 100644 --- a/mesalib/src/mesa/main/light.c +++ b/mesalib/src/mesa/main/light.c @@ -154,7 +154,6 @@ _mesa_light(struct gl_context *ctx, GLuint lnum, GLenum pname, const GLfloat *pa return; FLUSH_VERTICES(ctx, _NEW_LIGHT); light->SpotExponent = params[0]; - _mesa_invalidate_spot_exp_table(light); break; case GL_SPOT_CUTOFF: ASSERT(params[0] == 180.0 || (params[0] >= 0.0 && params[0] <= 90.0)); @@ -624,6 +623,11 @@ _mesa_material_bitmask( struct gl_context *ctx, GLenum face, GLenum pname, +static void +invalidate_shine_table( struct gl_context *ctx, GLuint side ); + + + /* Update derived values following a change in ctx->Light.Material */ void @@ -697,11 +701,11 @@ _mesa_update_material( struct gl_context *ctx, GLuint bitmask ) } if (bitmask & MAT_BIT_FRONT_SHININESS) { - _mesa_invalidate_shine_table( ctx, 0 ); + invalidate_shine_table( ctx, 0 ); } if (bitmask & MAT_BIT_BACK_SHININESS) { - _mesa_invalidate_shine_table( ctx, 1 ); + invalidate_shine_table( ctx, 1 ); } } @@ -911,52 +915,12 @@ _mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params ) -/* - * Whenever the spotlight exponent for a light changes we must call - * this function to recompute the exponent lookup table. - */ -void -_mesa_invalidate_spot_exp_table( struct gl_light *l ) -{ - l->_SpotExpTable[0][0] = -1; -} - - -static void -validate_spot_exp_table( struct gl_light *l ) -{ - GLint i; - GLdouble exponent = l->SpotExponent; - GLdouble tmp = 0; - GLint clamp = 0; - - l->_SpotExpTable[0][0] = 0.0; - - for (i = EXP_TABLE_SIZE - 1; i > 0 ;i--) { - if (clamp == 0) { - tmp = pow(i / (GLdouble) (EXP_TABLE_SIZE - 1), exponent); - if (tmp < FLT_MIN * 100.0) { - tmp = 0.0; - clamp = 1; - } - } - l->_SpotExpTable[i][0] = (GLfloat) tmp; - } - for (i = 0; i < EXP_TABLE_SIZE - 1; i++) { - l->_SpotExpTable[i][1] = (l->_SpotExpTable[i+1][0] - - l->_SpotExpTable[i][0]); - } - l->_SpotExpTable[EXP_TABLE_SIZE-1][1] = 0.0; -} - - - /* Calculate a new shine table. Doing this here saves a branch in * lighting, and the cost of doing it early may be partially offset * by keeping a MRU cache of shine tables for various shine values. */ -void -_mesa_invalidate_shine_table( struct gl_context *ctx, GLuint side ) +static void +invalidate_shine_table( struct gl_context *ctx, GLuint side ) { ASSERT(side < 2); if (ctx->_ShineTable[side]) @@ -1020,7 +984,6 @@ validate_shine_table( struct gl_context *ctx, GLuint side, GLfloat shininess ) void _mesa_validate_all_lighting_tables( struct gl_context *ctx ) { - GLuint i; GLfloat shininess; shininess = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_SHININESS][0]; @@ -1030,10 +993,6 @@ _mesa_validate_all_lighting_tables( struct gl_context *ctx ) shininess = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_SHININESS][0]; if (!ctx->_ShineTable[1] || ctx->_ShineTable[1]->shininess != shininess) validate_shine_table( ctx, 1, shininess ); - - for (i = 0; i < ctx->Const.MaxLights; i++) - if (ctx->Light.Light[i]._SpotExpTable[0][0] == -1) - validate_spot_exp_table( &ctx->Light.Light[i] ); } @@ -1180,11 +1139,8 @@ compute_light_positions( struct gl_context *ctx ) light->_NormSpotDirection); if (PV_dot_dir > light->_CosCutoff) { - double x = PV_dot_dir * (EXP_TABLE_SIZE-1); - int k = (int) x; light->_VP_inf_spot_attenuation = - (GLfloat) (light->_SpotExpTable[k][0] + - (x-k)*light->_SpotExpTable[k][1]); + powf(PV_dot_dir, light->SpotExponent); } else { light->_VP_inf_spot_attenuation = 0; @@ -1303,7 +1259,6 @@ init_light( struct gl_light *l, GLuint n ) ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 ); ASSIGN_3V( l->SpotDirection, 0.0, 0.0, -1.0 ); l->SpotExponent = 0.0; - _mesa_invalidate_spot_exp_table( l ); l->SpotCutoff = 180.0; l->_CosCutoffNeg = -1.0f; l->_CosCutoff = 0.0; /* KW: -ve values not admitted */ diff --git a/mesalib/src/mesa/main/light.h b/mesalib/src/mesa/main/light.h index 9b66c7ed8..996698793 100644 --- a/mesalib/src/mesa/main/light.h +++ b/mesalib/src/mesa/main/light.h @@ -87,22 +87,24 @@ extern void _mesa_light(struct gl_context *ctx, GLuint lnum, GLenum pname, const GLfloat *params); -/* Lerp between adjacent values in the f(x) lookup table, giving a - * continuous function, with adequeate overall accuracy. (Though - * still pretty good compared to a straight lookup). - * Result should be a GLfloat. +/* + * Compute dp ^ SpecularExponent. + * Lerp between adjacent values in the f(x) lookup table, giving a + * continuous function, with adequate overall accuracy. (Though still + * pretty good compared to a straight lookup). */ -#define GET_SHINE_TAB_ENTRY( table, dp, result ) \ -do { \ - struct gl_shine_tab *_tab = table; \ - float f = (dp * (SHINE_TABLE_SIZE-1)); \ - int k = (int) f; \ - if (k < 0 /* gcc may cast an overflow float value to negative int value*/ \ - || k > SHINE_TABLE_SIZE-2) \ - result = (GLfloat) pow( dp, _tab->shininess ); \ - else \ - result = _tab->tab[k] + (f-k)*(_tab->tab[k+1]-_tab->tab[k]); \ -} while (0) +static inline GLfloat +_mesa_lookup_shininess(const struct gl_context *ctx, GLuint face, GLfloat dp) +{ + const struct gl_shine_tab *tab = ctx->_ShineTable[face]; + float f = dp * (SHINE_TABLE_SIZE - 1); + int k = (int) f; + if (k < 0 /* gcc may cast an overflow float value to negative int value */ + || k > SHINE_TABLE_SIZE - 2) + return powf(dp, tab->shininess); + else + return tab->tab[k] + (f - k) * (tab->tab[k+1] - tab->tab[k]); +} extern GLuint _mesa_material_bitmask( struct gl_context *ctx, @@ -110,10 +112,6 @@ extern GLuint _mesa_material_bitmask( struct gl_context *ctx, GLuint legal, const char * ); -extern void _mesa_invalidate_spot_exp_table( struct gl_light *l ); - -extern void _mesa_invalidate_shine_table( struct gl_context *ctx, GLuint i ); - extern void _mesa_validate_all_lighting_tables( struct gl_context *ctx ); extern void _mesa_update_lighting( struct gl_context *ctx ); @@ -135,7 +133,6 @@ extern void _mesa_allow_light_in_model( struct gl_context *ctx, GLboolean flag ) #else #define _mesa_update_color_material( c, r ) ((void)0) #define _mesa_validate_all_lighting_tables( c ) ((void)0) -#define _mesa_invalidate_spot_exp_table( l ) ((void)0) #define _mesa_material_bitmask( c, f, p, l, s ) 0 #define _mesa_init_lighting( c ) ((void)0) #define _mesa_free_lighting_data( c ) ((void)0) diff --git a/mesalib/src/mesa/main/mtypes.h b/mesalib/src/mesa/main/mtypes.h index d3001d35c..5ef97c86c 100644 --- a/mesalib/src/mesa/main/mtypes.h +++ b/mesalib/src/mesa/main/mtypes.h @@ -689,7 +689,6 @@ struct gl_light GLfloat _NormSpotDirection[4]; /**< normalized spotlight direction */ GLfloat _VP_inf_spot_attenuation; - GLfloat _SpotExpTable[EXP_TABLE_SIZE][2]; /**< to replace a pow() call */ GLfloat _MatAmbient[2][3]; /**< material ambient * light ambient */ GLfloat _MatDiffuse[2][3]; /**< material diffuse * light diffuse */ GLfloat _MatSpecular[2][3]; /**< material spec * light specular */ @@ -1046,7 +1045,6 @@ struct gl_pixelmap { GLint Size; GLfloat Map[MAX_PIXEL_MAP_TABLE]; - GLubyte Map8[MAX_PIXEL_MAP_TABLE]; /**< converted to 8-bit color */ }; @@ -2529,8 +2527,6 @@ struct gl_shared_state /** GL_ARB_sampler_objects */ struct _mesa_HashTable *SamplerObjects; - - void *DriverData; /**< Device driver shared state */ }; @@ -2829,7 +2825,7 @@ struct gl_constants * borders and mipmapped textures. (Note: not static border color, but the * old 1-pixel border around each edge). Implementations then have to do * slow fallbacks to be correct, or just ignore the border and be fast but - * wrong. Setting the flag stripts the border off of TexImage calls, + * wrong. Setting the flag strips the border off of TexImage calls, * providing "fast but wrong" at significantly reduced driver complexity. * * Texture borders are deprecated in GL 3.0. diff --git a/mesalib/src/mesa/main/pixel.c b/mesalib/src/mesa/main/pixel.c index e73c5a49a..450c936b7 100644 --- a/mesalib/src/mesa/main/pixel.c +++ b/mesalib/src/mesa/main/pixel.c @@ -137,7 +137,6 @@ store_pixelmap(struct gl_context *ctx, GLenum map, GLsizei mapsize, for (i = 0; i < mapsize; i++) { GLfloat val = CLAMP(values[i], 0.0F, 1.0F); pm->Map[i] = val; - pm->Map8[i] = (GLint) (val * 255.0F); } } } @@ -683,7 +682,6 @@ init_pixelmap(struct gl_pixelmap *map) { map->Size = 1; map->Map[0] = 0.0; - map->Map8[0] = 0; } diff --git a/mesalib/src/mesa/main/pixeltransfer.c b/mesalib/src/mesa/main/pixeltransfer.c index 5c167e0a9..c6172b9fd 100644 --- a/mesalib/src/mesa/main/pixeltransfer.c +++ b/mesalib/src/mesa/main/pixeltransfer.c @@ -125,32 +125,6 @@ _mesa_map_ci_to_rgba( const struct gl_context *ctx, GLuint n, } -/** - * Map ubyte color indexes to ubyte/RGBA values. - */ -void -_mesa_map_ci8_to_rgba8(const struct gl_context *ctx, - GLuint n, const GLubyte index[], - GLubyte rgba[][4]) -{ - GLuint rmask = ctx->PixelMaps.ItoR.Size - 1; - GLuint gmask = ctx->PixelMaps.ItoG.Size - 1; - GLuint bmask = ctx->PixelMaps.ItoB.Size - 1; - GLuint amask = ctx->PixelMaps.ItoA.Size - 1; - const GLubyte *rMap = ctx->PixelMaps.ItoR.Map8; - const GLubyte *gMap = ctx->PixelMaps.ItoG.Map8; - const GLubyte *bMap = ctx->PixelMaps.ItoB.Map8; - const GLubyte *aMap = ctx->PixelMaps.ItoA.Map8; - GLuint i; - for (i=0;i<n;i++) { - rgba[i][RCOMP] = rMap[index[i] & rmask]; - rgba[i][GCOMP] = gMap[index[i] & gmask]; - rgba[i][BCOMP] = bMap[index[i] & bmask]; - rgba[i][ACOMP] = aMap[index[i] & amask]; - } -} - - void _mesa_scale_and_bias_depth(const struct gl_context *ctx, GLuint n, GLfloat depthValues[]) diff --git a/mesalib/src/mesa/main/pixeltransfer.h b/mesalib/src/mesa/main/pixeltransfer.h index a8c14757f..3cd7ebe77 100644 --- a/mesalib/src/mesa/main/pixeltransfer.h +++ b/mesalib/src/mesa/main/pixeltransfer.h @@ -46,12 +46,6 @@ _mesa_map_ci_to_rgba(const struct gl_context *ctx, extern void -_mesa_map_ci8_to_rgba8(const struct gl_context *ctx, - GLuint n, const GLubyte index[], - GLubyte rgba[][4]); - - -extern void _mesa_scale_and_bias_depth(const struct gl_context *ctx, GLuint n, GLfloat depthValues[]); diff --git a/mesalib/src/mesa/main/texcompress.c b/mesalib/src/mesa/main/texcompress.c index 44590ea96..c376b970e 100644 --- a/mesalib/src/mesa/main/texcompress.c +++ b/mesalib/src/mesa/main/texcompress.c @@ -465,6 +465,8 @@ _mesa_compressed_image_address(GLint col, GLint row, GLint img, /** * Decompress a compressed texture image, returning a GL_RGBA/GL_FLOAT image. + * \param srcRowStride stride in bytes between rows of blocks in the + * compressed source image. */ void _mesa_decompress_image(gl_format format, GLuint width, GLuint height, @@ -475,11 +477,19 @@ _mesa_decompress_image(gl_format format, GLuint width, GLuint height, GLint i, GLint j, GLint k, GLfloat *texel); struct swrast_texture_image texImage; /* dummy teximage */ GLuint i, j; + GLuint bytes, bw, bh; + + bytes = _mesa_get_format_bytes(format); + _mesa_get_format_block_size(format, &bw, &bh); /* setup dummy texture image info */ memset(&texImage, 0, sizeof(texImage)); texImage.Map = (void *) src; - texImage.RowStride = srcRowStride; + + /* XXX This line is a bit of a hack to adapt to the row stride + * convention used by the texture decompression functions. + */ + texImage.RowStride = srcRowStride * bh / bytes; switch (format) { /* DXT formats */ diff --git a/mesalib/src/mesa/main/texgetimage.c b/mesalib/src/mesa/main/texgetimage.c index bff003d24..a02a49156 100644 --- a/mesalib/src/mesa/main/texgetimage.c +++ b/mesalib/src/mesa/main/texgetimage.c @@ -246,23 +246,12 @@ get_tex_rgba_compressed(struct gl_context *ctx, GLuint dimensions, { GLubyte *srcMap; GLint srcRowStride; - GLuint bytes, bw, bh; - - bytes = _mesa_get_format_bytes(texFormat); - _mesa_get_format_block_size(texFormat, &bw, &bh); ctx->Driver.MapTextureImage(ctx, texImage, 0, 0, 0, width, height, GL_MAP_READ_BIT, &srcMap, &srcRowStride); if (srcMap) { - /* XXX This line is a bit of a hack to work around the - * mismatch of compressed row strides as returned by - * MapTextureImage() vs. what the texture decompression code - * uses. This will be fixed in the future. - */ - srcRowStride = srcRowStride * bh / bytes; - _mesa_decompress_image(texFormat, width, height, srcMap, srcRowStride, tempImage); @@ -270,6 +259,8 @@ get_tex_rgba_compressed(struct gl_context *ctx, GLuint dimensions, } else { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage"); + free(tempImage); + return; } } @@ -496,52 +487,17 @@ get_tex_memcpy(struct gl_context *ctx, GLenum format, GLenum type, GLboolean memCopy = GL_FALSE; /* - * Check if the src/dst formats are compatible. - * Also note that GL's pixel transfer ops don't apply to glGetTexImage() - * so we don't have to worry about those. - * XXX more format combinations could be supported here. + * Check if we can use memcpy to copy from the hardware texture + * format to the user's format/type. + * Note that GL's pixel transfer ops don't apply to glGetTexImage() */ if (target == GL_TEXTURE_1D || target == GL_TEXTURE_2D || target == GL_TEXTURE_RECTANGLE || _mesa_is_cube_face(target)) { - if ((texImage->TexFormat == MESA_FORMAT_ARGB8888 || - texImage->TexFormat == MESA_FORMAT_SARGB8) && - format == GL_BGRA && - (type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_INT_8_8_8_8_REV) && - !ctx->Pack.SwapBytes && - _mesa_little_endian()) { - memCopy = GL_TRUE; - } - else if ((texImage->TexFormat == MESA_FORMAT_AL88 || - texImage->TexFormat == MESA_FORMAT_SLA8) && - format == GL_LUMINANCE_ALPHA && - type == GL_UNSIGNED_BYTE && - !ctx->Pack.SwapBytes && - _mesa_little_endian()) { - memCopy = GL_TRUE; - } - else if ((texImage->TexFormat == MESA_FORMAT_L8 || - texImage->TexFormat == MESA_FORMAT_SL8) && - format == GL_LUMINANCE && - type == GL_UNSIGNED_BYTE) { - memCopy = GL_TRUE; - } - else if (texImage->TexFormat == MESA_FORMAT_L16 && - format == GL_LUMINANCE && - type == GL_UNSIGNED_SHORT) { - memCopy = GL_TRUE; - } - else if (texImage->TexFormat == MESA_FORMAT_A8 && - format == GL_ALPHA && - type == GL_UNSIGNED_BYTE) { - memCopy = GL_TRUE; - } - else if (texImage->TexFormat == MESA_FORMAT_A16 && - format == GL_ALPHA && - type == GL_UNSIGNED_SHORT) { - memCopy = GL_TRUE; - } + memCopy = _mesa_format_matches_format_and_type(texImage->TexFormat, + format, type, + ctx->Pack.SwapBytes); } if (memCopy) { diff --git a/mesalib/src/mesa/main/teximage.c b/mesalib/src/mesa/main/teximage.c index 25da75369..e4eb7f67d 100644 --- a/mesalib/src/mesa/main/teximage.c +++ b/mesalib/src/mesa/main/teximage.c @@ -1179,7 +1179,7 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level, switch (target) { case GL_PROXY_TEXTURE_1D: maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); - if (width < 2 * border || width > maxSize) + if (width < 2 * border || width > 2 * border + maxSize) return GL_FALSE; if (level >= ctx->Const.MaxTextureLevels) return GL_FALSE; @@ -1191,9 +1191,9 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level, case GL_PROXY_TEXTURE_2D: maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); - if (width < 2 * border || width > maxSize) + if (width < 2 * border || width > 2 * border + maxSize) return GL_FALSE; - if (height < 2 * border || height > maxSize) + if (height < 2 * border || height > 2 * border + maxSize) return GL_FALSE; if (level >= ctx->Const.MaxTextureLevels) return GL_FALSE; @@ -1207,11 +1207,11 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level, case GL_PROXY_TEXTURE_3D: maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1); - if (width < 2 * border || width > maxSize) + if (width < 2 * border || width > 2 * border + maxSize) return GL_FALSE; - if (height < 2 * border || height > maxSize) + if (height < 2 * border || height > 2 * border + maxSize) return GL_FALSE; - if (depth < 2 * border || depth > maxSize) + if (depth < 2 * border || depth > 2 * border + maxSize) return GL_FALSE; if (level >= ctx->Const.Max3DTextureLevels) return GL_FALSE; @@ -1237,9 +1237,9 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level, case GL_PROXY_TEXTURE_CUBE_MAP_ARB: maxSize = 1 << (ctx->Const.MaxCubeTextureLevels - 1); - if (width < 2 * border || width > maxSize) + if (width < 2 * border || width > 2 * border + maxSize) return GL_FALSE; - if (height < 2 * border || height > maxSize) + if (height < 2 * border || height > 2 * border + maxSize) return GL_FALSE; if (level >= ctx->Const.MaxCubeTextureLevels) return GL_FALSE; @@ -1253,7 +1253,7 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level, case GL_PROXY_TEXTURE_1D_ARRAY_EXT: maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); - if (width < 2 * border || width > maxSize) + if (width < 2 * border || width > 2 * border + maxSize) return GL_FALSE; if (height < 1 || height > ctx->Const.MaxArrayTextureLayers) return GL_FALSE; @@ -1267,9 +1267,9 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level, case GL_PROXY_TEXTURE_2D_ARRAY_EXT: maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); - if (width < 2 * border || width > maxSize) + if (width < 2 * border || width > 2 * border + maxSize) return GL_FALSE; - if (height < 2 * border || height > maxSize) + if (height < 2 * border || height > 2 * border + maxSize) return GL_FALSE; if (depth < 1 || depth > ctx->Const.MaxArrayTextureLayers) return GL_FALSE; diff --git a/mesalib/src/mesa/main/texparam.c b/mesalib/src/mesa/main/texparam.c index 0f92a5b98..9a2ec518f 100644 --- a/mesalib/src/mesa/main/texparam.c +++ b/mesalib/src/mesa/main/texparam.c @@ -1233,19 +1233,19 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params ) switch (pname) { case GL_TEXTURE_MAG_FILTER: *params = (GLint) obj->Sampler.MagFilter; - break;; + break; case GL_TEXTURE_MIN_FILTER: *params = (GLint) obj->Sampler.MinFilter; - break;; + break; case GL_TEXTURE_WRAP_S: *params = (GLint) obj->Sampler.WrapS; - break;; + break; case GL_TEXTURE_WRAP_T: *params = (GLint) obj->Sampler.WrapT; - break;; + break; case GL_TEXTURE_WRAP_R: *params = (GLint) obj->Sampler.WrapR; - break;; + break; case GL_TEXTURE_BORDER_COLOR: { GLfloat b[4]; @@ -1258,25 +1258,25 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params ) params[2] = FLOAT_TO_INT(b[2]); params[3] = FLOAT_TO_INT(b[3]); } - break;; + break; case GL_TEXTURE_RESIDENT: *params = 1; - break;; + break; case GL_TEXTURE_PRIORITY: *params = FLOAT_TO_INT(obj->Priority); - break;; + break; case GL_TEXTURE_MIN_LOD: *params = (GLint) obj->Sampler.MinLod; - break;; + break; case GL_TEXTURE_MAX_LOD: *params = (GLint) obj->Sampler.MaxLod; - break;; + break; case GL_TEXTURE_BASE_LEVEL: *params = obj->BaseLevel; - break;; + break; case GL_TEXTURE_MAX_LEVEL: *params = obj->MaxLevel; - break;; + break; case GL_TEXTURE_MAX_ANISOTROPY_EXT: if (!ctx->Extensions.EXT_texture_filter_anisotropic) goto invalid_pname; diff --git a/mesalib/src/mesa/main/texstate.c b/mesalib/src/mesa/main/texstate.c index 8e9537fae..cc49916a9 100644 --- a/mesalib/src/mesa/main/texstate.c +++ b/mesalib/src/mesa/main/texstate.c @@ -682,20 +682,25 @@ _mesa_update_texture( struct gl_context *ctx, GLuint new_state ) static GLboolean alloc_proxy_textures( struct gl_context *ctx ) { + /* NOTE: these values must be in the same order as the TEXTURE_x_INDEX + * values! + */ static const GLenum targets[] = { - GL_TEXTURE_1D, - GL_TEXTURE_2D, - GL_TEXTURE_3D, + GL_TEXTURE_BUFFER, + GL_TEXTURE_2D_ARRAY_EXT, + GL_TEXTURE_1D_ARRAY_EXT, + GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_CUBE_MAP_ARB, + GL_TEXTURE_3D, GL_TEXTURE_RECTANGLE_NV, - GL_TEXTURE_1D_ARRAY_EXT, - GL_TEXTURE_2D_ARRAY_EXT, - GL_TEXTURE_BUFFER, - GL_TEXTURE_EXTERNAL_OES + GL_TEXTURE_2D, + GL_TEXTURE_1D, }; GLint tgt; STATIC_ASSERT(Elements(targets) == NUM_TEXTURE_TARGETS); + assert(targets[TEXTURE_2D_INDEX] == GL_TEXTURE_2D); + assert(targets[TEXTURE_CUBE_INDEX] == GL_TEXTURE_CUBE_MAP); for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) { if (!(ctx->Texture.ProxyTex[tgt] diff --git a/mesalib/src/mesa/main/version.h b/mesalib/src/mesa/main/version.h index 8723c1f57..35bf53392 100644 --- a/mesalib/src/mesa/main/version.h +++ b/mesalib/src/mesa/main/version.h @@ -33,7 +33,7 @@ struct gl_context; /* Mesa version */ #define MESA_MAJOR 8 -#define MESA_MINOR 0 +#define MESA_MINOR 1 #define MESA_PATCH 0 #define MESA_VERSION_STRING "8.0-devel" diff --git a/mesalib/src/mesa/state_tracker/st_atom.c b/mesalib/src/mesa/state_tracker/st_atom.c index 95010d1b2..d9cd4aab4 100644 --- a/mesalib/src/mesa/state_tracker/st_atom.c +++ b/mesalib/src/mesa/state_tracker/st_atom.c @@ -1,205 +1,205 @@ -/**************************************************************************
- *
- * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
- * 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, sub license, 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 (including the
- * next paragraph) 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 NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
- *
- **************************************************************************/
-
-
-#include "main/glheader.h"
-#include "main/context.h"
-
-#include "pipe/p_defines.h"
-#include "st_context.h"
-#include "st_atom.h"
-#include "st_cb_bitmap.h"
-#include "st_program.h"
-#include "st_manager.h"
-
-
-/**
- * This is used to initialize st->atoms[].
- */
-static const struct st_tracked_state *atoms[] =
-{
- &st_update_depth_stencil_alpha,
- &st_update_clip,
-
- &st_finalize_textures,
- &st_update_fp,
- &st_update_gp,
- &st_update_vp,
-
- &st_update_rasterizer,
- &st_update_polygon_stipple,
- &st_update_viewport,
- &st_update_scissor,
- &st_update_blend,
- &st_update_sampler,
- &st_update_vertex_texture,
- &st_update_texture,
- &st_update_framebuffer,
- &st_update_msaa,
- &st_update_vs_constants,
- &st_update_gs_constants,
- &st_update_fs_constants,
- &st_update_pixel_transfer
-};
-
-
-void st_init_atoms( struct st_context *st )
-{
- /* no-op */
-}
-
-
-void st_destroy_atoms( struct st_context *st )
-{
- /* no-op */
-}
-
-
-/***********************************************************************
- */
-
-static GLboolean check_state( const struct st_state_flags *a,
- const struct st_state_flags *b )
-{
- return ((a->mesa & b->mesa) ||
- (a->st & b->st));
-}
-
-static void accumulate_state( struct st_state_flags *a,
- const struct st_state_flags *b )
-{
- a->mesa |= b->mesa;
- a->st |= b->st;
-}
-
-
-static void xor_states( struct st_state_flags *result,
- const struct st_state_flags *a,
- const struct st_state_flags *b )
-{
- result->mesa = a->mesa ^ b->mesa;
- result->st = a->st ^ b->st;
-}
-
-
-/* Too complex to figure out, just check every time:
- */
-static void check_program_state( struct st_context *st )
-{
- struct gl_context *ctx = st->ctx;
-
- if (ctx->VertexProgram._Current != &st->vp->Base)
- st->dirty.st |= ST_NEW_VERTEX_PROGRAM;
-
- if (ctx->FragmentProgram._Current != &st->fp->Base)
- st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
-
- if (ctx->GeometryProgram._Current != &st->gp->Base)
- st->dirty.st |= ST_NEW_GEOMETRY_PROGRAM;
-}
-
-
-/***********************************************************************
- * Update all derived state:
- */
-
-void st_validate_state( struct st_context *st )
-{
- struct st_state_flags *state = &st->dirty;
- GLuint i;
-
- /* The bitmap cache is immune to pixel unpack changes.
- * Note that GLUT makes several calls to glPixelStore for each
- * bitmap char it draws so this is an important check.
- */
- if (state->mesa & ~_NEW_PACKUNPACK)
- st_flush_bitmap_cache(st);
-
- check_program_state( st );
-
- st_manager_validate_framebuffers(st);
-
- if (state->st == 0)
- return;
-
- /*printf("%s %x/%x\n", __FUNCTION__, state->mesa, state->st);*/
-
-#ifdef NDEBUG
- if (0) {
-#else
- if (1) {
-#endif
- /* Debug version which enforces various sanity checks on the
- * state flags which are generated and checked to help ensure
- * state atoms are ordered correctly in the list.
- */
- struct st_state_flags examined, prev;
- memset(&examined, 0, sizeof(examined));
- prev = *state;
-
- for (i = 0; i < Elements(atoms); i++) {
- const struct st_tracked_state *atom = atoms[i];
- struct st_state_flags generated;
-
- /*printf("atom %s %x/%x\n", atom->name, atom->dirty.mesa, atom->dirty.st);*/
-
- if (!(atom->dirty.mesa || atom->dirty.st) ||
- !atom->update) {
- printf("malformed atom %s\n", atom->name);
- assert(0);
- }
-
- if (check_state(state, &atom->dirty)) {
- atoms[i]->update( st );
- /*printf("after: %x\n", atom->dirty.mesa);*/
- }
-
- accumulate_state(&examined, &atom->dirty);
-
- /* generated = (prev ^ state)
- * if (examined & generated)
- * fail;
- */
- xor_states(&generated, &prev, state);
- assert(!check_state(&examined, &generated));
- prev = *state;
- }
- /*printf("\n");*/
-
- }
- else {
- for (i = 0; i < Elements(atoms); i++) {
- if (check_state(state, &atoms[i]->dirty))
- atoms[i]->update( st );
- }
- }
-
- memset(state, 0, sizeof(*state));
-}
-
-
-
+/************************************************************************** + * + * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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, sub license, 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 (including the + * next paragraph) 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 NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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. + * + **************************************************************************/ + + +#include "main/glheader.h" +#include "main/context.h" + +#include "pipe/p_defines.h" +#include "st_context.h" +#include "st_atom.h" +#include "st_cb_bitmap.h" +#include "st_program.h" +#include "st_manager.h" + + +/** + * This is used to initialize st->atoms[]. + */ +static const struct st_tracked_state *atoms[] = +{ + &st_update_depth_stencil_alpha, + &st_update_clip, + + &st_finalize_textures, + &st_update_fp, + &st_update_gp, + &st_update_vp, + + &st_update_rasterizer, + &st_update_polygon_stipple, + &st_update_viewport, + &st_update_scissor, + &st_update_blend, + &st_update_sampler, + &st_update_vertex_texture, + &st_update_texture, + &st_update_framebuffer, + &st_update_msaa, + &st_update_vs_constants, + &st_update_gs_constants, + &st_update_fs_constants, + &st_update_pixel_transfer +}; + + +void st_init_atoms( struct st_context *st ) +{ + /* no-op */ +} + + +void st_destroy_atoms( struct st_context *st ) +{ + /* no-op */ +} + + +/*********************************************************************** + */ + +static GLboolean check_state( const struct st_state_flags *a, + const struct st_state_flags *b ) +{ + return ((a->mesa & b->mesa) || + (a->st & b->st)); +} + +static void accumulate_state( struct st_state_flags *a, + const struct st_state_flags *b ) +{ + a->mesa |= b->mesa; + a->st |= b->st; +} + + +static void xor_states( struct st_state_flags *result, + const struct st_state_flags *a, + const struct st_state_flags *b ) +{ + result->mesa = a->mesa ^ b->mesa; + result->st = a->st ^ b->st; +} + + +/* Too complex to figure out, just check every time: + */ +static void check_program_state( struct st_context *st ) +{ + struct gl_context *ctx = st->ctx; + + if (ctx->VertexProgram._Current != &st->vp->Base) + st->dirty.st |= ST_NEW_VERTEX_PROGRAM; + + if (ctx->FragmentProgram._Current != &st->fp->Base) + st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; + + if (ctx->GeometryProgram._Current != &st->gp->Base) + st->dirty.st |= ST_NEW_GEOMETRY_PROGRAM; +} + + +/*********************************************************************** + * Update all derived state: + */ + +void st_validate_state( struct st_context *st ) +{ + struct st_state_flags *state = &st->dirty; + GLuint i; + + /* The bitmap cache is immune to pixel unpack changes. + * Note that GLUT makes several calls to glPixelStore for each + * bitmap char it draws so this is an important check. + */ + if (state->mesa & ~_NEW_PACKUNPACK) + st_flush_bitmap_cache(st); + + check_program_state( st ); + + st_manager_validate_framebuffers(st); + + if (state->st == 0) + return; + + /*printf("%s %x/%x\n", __FUNCTION__, state->mesa, state->st);*/ + +#ifdef DEBUG + if (1) { +#else + if (0) { +#endif + /* Debug version which enforces various sanity checks on the + * state flags which are generated and checked to help ensure + * state atoms are ordered correctly in the list. + */ + struct st_state_flags examined, prev; + memset(&examined, 0, sizeof(examined)); + prev = *state; + + for (i = 0; i < Elements(atoms); i++) { + const struct st_tracked_state *atom = atoms[i]; + struct st_state_flags generated; + + /*printf("atom %s %x/%x\n", atom->name, atom->dirty.mesa, atom->dirty.st);*/ + + if (!(atom->dirty.mesa || atom->dirty.st) || + !atom->update) { + printf("malformed atom %s\n", atom->name); + assert(0); + } + + if (check_state(state, &atom->dirty)) { + atoms[i]->update( st ); + /*printf("after: %x\n", atom->dirty.mesa);*/ + } + + accumulate_state(&examined, &atom->dirty); + + /* generated = (prev ^ state) + * if (examined & generated) + * fail; + */ + xor_states(&generated, &prev, state); + assert(!check_state(&examined, &generated)); + prev = *state; + } + /*printf("\n");*/ + + } + else { + for (i = 0; i < Elements(atoms); i++) { + if (check_state(state, &atoms[i]->dirty)) + atoms[i]->update( st ); + } + } + + memset(state, 0, sizeof(*state)); +} + + + diff --git a/mesalib/src/mesa/state_tracker/st_atom_pixeltransfer.c b/mesalib/src/mesa/state_tracker/st_atom_pixeltransfer.c index fb1e4092c..8d2317ea1 100644 --- a/mesalib/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/mesalib/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -116,11 +116,12 @@ load_color_map_texture(struct gl_context *ctx, struct pipe_resource *pt) for (j = 0; j < texSize; j++) { union util_color uc; int k = (i * texSize + j); - ubyte r = ctx->PixelMaps.RtoR.Map8[j * rSize / texSize]; - ubyte g = ctx->PixelMaps.GtoG.Map8[i * gSize / texSize]; - ubyte b = ctx->PixelMaps.BtoB.Map8[j * bSize / texSize]; - ubyte a = ctx->PixelMaps.AtoA.Map8[i * aSize / texSize]; - util_pack_color_ub(r, g, b, a, pt->format, &uc); + float rgba[4]; + rgba[0] = ctx->PixelMaps.RtoR.Map[j * rSize / texSize]; + rgba[1] = ctx->PixelMaps.GtoG.Map[i * gSize / texSize]; + rgba[2] = ctx->PixelMaps.BtoB.Map[j * bSize / texSize]; + rgba[3] = ctx->PixelMaps.AtoA.Map[i * aSize / texSize]; + util_pack_color(rgba, pt->format, &uc); *(dest + k) = uc.ui; } } diff --git a/mesalib/src/mesa/state_tracker/st_atom_sampler.c b/mesalib/src/mesa/state_tracker/st_atom_sampler.c index 8845fed51..ee69fc390 100644 --- a/mesalib/src/mesa/state_tracker/st_atom_sampler.c +++ b/mesalib/src/mesa/state_tracker/st_atom_sampler.c @@ -233,29 +233,33 @@ update_fragment_samplers(struct st_context *st) const struct gl_context *ctx = st->ctx; struct gl_fragment_program *fprog = ctx->FragmentProgram._Current; GLuint su; + GLuint samplers_used = fprog->Base.SamplersUsed; + GLuint old_max = st->state.num_samplers; st->state.num_samplers = 0; /* loop over sampler units (aka tex image units) */ - for (su = 0; su < ctx->Const.MaxTextureImageUnits; su++) { + for (su = 0; su < ctx->Const.MaxTextureImageUnits; su++, samplers_used >>= 1) { struct pipe_sampler_state *sampler = st->state.samplers + su; - - if (fprog->Base.SamplersUsed & (1 << su)) { + if (samplers_used & 1) { GLuint texUnit; - texUnit = fprog->Base.SamplerUnits[su]; + texUnit = fprog->Base.SamplerUnits[su]; - convert_sampler(st, sampler, texUnit); + convert_sampler(st, sampler, texUnit); st->state.num_samplers = su + 1; /*printf("%s su=%u non-null\n", __FUNCTION__, su);*/ cso_single_sampler(st->cso_context, su, sampler); } - else { + else if (samplers_used != 0 || su < old_max) { /*printf("%s su=%u null\n", __FUNCTION__, su);*/ cso_single_sampler(st->cso_context, su, NULL); + } else { + /* if we've reset all the old views and we have no more new ones */ + break; } } diff --git a/mesalib/src/mesa/state_tracker/st_atom_texture.c b/mesalib/src/mesa/state_tracker/st_atom_texture.c index d241527cc..e8941da8d 100644 --- a/mesalib/src/mesa/state_tracker/st_atom_texture.c +++ b/mesalib/src/mesa/state_tracker/st_atom_texture.c @@ -300,24 +300,31 @@ update_fragment_textures(struct st_context *st) const struct gl_context *ctx = st->ctx; struct gl_fragment_program *fprog = ctx->FragmentProgram._Current; GLuint su; + int old_max = st->state.num_textures; + GLbitfield samplers_used = fprog->Base.SamplersUsed; st->state.num_textures = 0; /* loop over sampler units (aka tex image units) */ - for (su = 0; su < ctx->Const.MaxTextureImageUnits; su++) { + for (su = 0; su < ctx->Const.MaxTextureImageUnits; su++, samplers_used >>= 1) { struct pipe_sampler_view *sampler_view = NULL; - if (fprog->Base.SamplersUsed & (1 << su)) { + + if (samplers_used & 1) { GLboolean retval; GLuint texUnit; - texUnit = fprog->Base.SamplerUnits[su]; + texUnit = fprog->Base.SamplerUnits[su]; - retval = update_single_texture(st, &sampler_view, texUnit); - if (retval == GL_FALSE) - continue; + retval = update_single_texture(st, &sampler_view, texUnit); + if (retval == GL_FALSE) + continue; st->state.num_textures = su + 1; + } else if (samplers_used == 0 && su >= old_max) { + /* if we've reset all the old views and we have no more new ones */ + break; } + pipe_sampler_view_reference(&st->state.sampler_views[su], sampler_view); } diff --git a/mesalib/src/mesa/state_tracker/st_cb_blit.c b/mesalib/src/mesa/state_tracker/st_cb_blit.c index 750f541b5..27da2c633 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_blit.c +++ b/mesalib/src/mesa/state_tracker/st_cb_blit.c @@ -178,7 +178,8 @@ st_BlitFramebuffer(struct gl_context *ctx, st->pipe->render_condition(st->pipe, NULL, 0); } - if (readFB->Visual.sampleBuffers > drawFB->Visual.sampleBuffers) { + if (readFB->Visual.sampleBuffers > drawFB->Visual.sampleBuffers && + readFB->Visual.samples > 1) { struct pipe_resolve_info info; if (dstX0 < dstX1) { diff --git a/mesalib/src/mesa/state_tracker/st_extensions.c b/mesalib/src/mesa/state_tracker/st_extensions.c index 443cb4bdf..fb36a6809 100644 --- a/mesalib/src/mesa/state_tracker/st_extensions.c +++ b/mesalib/src/mesa/state_tracker/st_extensions.c @@ -146,8 +146,8 @@ void st_init_limits(struct st_context *st) = CLAMP(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS), 1, MAX_DRAW_BUFFERS); - /* Quads always follow GL provoking rules. */ - c->QuadsFollowProvokingVertexConvention = GL_FALSE; + c->QuadsFollowProvokingVertexConvention = screen->get_param( + screen, PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION); for (sh = 0; sh < MESA_SHADER_TYPES; ++sh) { struct gl_shader_compiler_options *options = diff --git a/mesalib/src/mesa/swrast/s_context.h b/mesalib/src/mesa/swrast/s_context.h index 363bdf03a..9388c3569 100644 --- a/mesalib/src/mesa/swrast/s_context.h +++ b/mesalib/src/mesa/swrast/s_context.h @@ -176,6 +176,9 @@ struct swrast_renderbuffer /** These fields are only valid while buffer is mapped for rendering */ GLubyte *Map; GLint RowStride; /**< in bytes */ + + /** For span rendering */ + GLenum ColorType; }; diff --git a/mesalib/src/mesa/swrast/s_renderbuffer.c b/mesalib/src/mesa/swrast/s_renderbuffer.c index 637a7b6dc..d8a7467b0 100644 --- a/mesalib/src/mesa/swrast/s_renderbuffer.c +++ b/mesalib/src/mesa/swrast/s_renderbuffer.c @@ -615,8 +615,31 @@ unmap_attachment(struct gl_context *ctx, srb->Map = NULL; } - - + + +/** + * Determine what type to use (ubyte vs. float) for span colors for the + * given renderbuffer. + * See also _swrast_write_rgba_span(). + */ +static void +find_renderbuffer_colortype(struct gl_renderbuffer *rb) +{ + struct swrast_renderbuffer *srb = swrast_renderbuffer(rb); + GLuint rbMaxBits = _mesa_get_format_max_bits(rb->Format); + GLenum rbDatatype = _mesa_get_format_datatype(rb->Format); + + if (rbDatatype == GL_UNSIGNED_NORMALIZED && rbMaxBits <= 8) { + /* the buffer's values fit in GLubyte values */ + srb->ColorType = GL_UNSIGNED_BYTE; + } + else { + /* use floats otherwise */ + srb->ColorType = GL_FLOAT; + } +} + + /** * Map the renderbuffers we'll use for tri/line/point rendering. */ @@ -641,6 +664,7 @@ _swrast_map_renderbuffers(struct gl_context *ctx) for (buf = 0; buf < fb->_NumColorDrawBuffers; buf++) { map_attachment(ctx, fb, fb->_ColorDrawBufferIndexes[buf]); + find_renderbuffer_colortype(fb->_ColorDrawBuffers[buf]); } } diff --git a/mesalib/src/mesa/swrast/s_span.c b/mesalib/src/mesa/swrast/s_span.c index 422d86c00..025e7b207 100644 --- a/mesalib/src/mesa/swrast/s_span.c +++ b/mesalib/src/mesa/swrast/s_span.c @@ -1320,15 +1320,15 @@ _swrast_write_rgba_span( struct gl_context *ctx, SWspan *span) if (rb) { GLchan rgbaSave[MAX_WIDTH][4]; + struct swrast_renderbuffer *srb = swrast_renderbuffer(rb); + GLenum colorType = srb->ColorType; - GLenum datatype; - GLuint comps; + assert(colorType == GL_UNSIGNED_BYTE || + colorType == GL_FLOAT); - _mesa_format_to_type_and_comps(rb->Format, &datatype, &comps); - - /* set span->array->rgba to colors for render buffer's datatype */ - if (datatype != span->array->ChanType) { - convert_color_type(span, datatype, 0); + /* set span->array->rgba to colors for renderbuffer's datatype */ + if (span->array->ChanType != colorType) { + convert_color_type(span, colorType, 0); } else { if (span->array->ChanType == GL_UNSIGNED_BYTE) { diff --git a/mesalib/src/mesa/tnl/t_rasterpos.c b/mesalib/src/mesa/tnl/t_rasterpos.c index a7e4397b6..17611cd21 100644 --- a/mesalib/src/mesa/tnl/t_rasterpos.c +++ b/mesalib/src/mesa/tnl/t_rasterpos.c @@ -167,10 +167,7 @@ shade_rastpos(struct gl_context *ctx, continue; } else { - double x = PV_dot_dir * (EXP_TABLE_SIZE-1); - int k = (int) x; - GLfloat spot = (GLfloat) (light->_SpotExpTable[k][0] - + (x-k)*light->_SpotExpTable[k][1]); + GLfloat spot = powf(PV_dot_dir, light->SpotExponent); attenuation *= spot; } } @@ -217,8 +214,7 @@ shade_rastpos(struct gl_context *ctx, n_dot_h = DOT3(normal, h); if (n_dot_h > 0.0F) { - GLfloat spec_coef; - GET_SHINE_TAB_ENTRY( ctx->_ShineTable[0], n_dot_h, spec_coef ); + GLfloat spec_coef = _mesa_lookup_shininess(ctx, 0, n_dot_h); if (spec_coef > 1.0e-10) { if (ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR) { diff --git a/mesalib/src/mesa/tnl/t_vb_lighttmp.h b/mesalib/src/mesa/tnl/t_vb_lighttmp.h index 63b817ab6..1041a24e7 100644 --- a/mesalib/src/mesa/tnl/t_vb_lighttmp.h +++ b/mesalib/src/mesa/tnl/t_vb_lighttmp.h @@ -1,651 +1,632 @@ -/*
- * Mesa 3-D graphics library
- * Version: 5.1
- *
- * Copyright (C) 1999-2003 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.
- *
- *
- * Authors:
- * Brian Paul
- * Keith Whitwell <keith@tungstengraphics.com>
- */
-
-
-#if IDX & LIGHT_TWOSIDE
-# define NR_SIDES 2
-#else
-# define NR_SIDES 1
-#endif
-
-
-/* define TRACE to trace lighting code */
-/* #define TRACE 1 */
-
-/*
- * ctx is the current context
- * VB is the vertex buffer
- * stage is the lighting stage-private data
- * input is the vector of eye or object-space vertex coordinates
- */
-static void TAG(light_rgba_spec)( struct gl_context *ctx,
- struct vertex_buffer *VB,
- struct tnl_pipeline_stage *stage,
- GLvector4f *input )
-{
- struct light_stage_data *store = LIGHT_STAGE_DATA(stage);
- GLfloat (*base)[3] = ctx->Light._BaseColor;
- GLfloat sumA[2];
- GLuint j;
-
- const GLuint vstride = input->stride;
- const GLfloat *vertex = (GLfloat *)input->data;
- const GLuint nstride = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->stride;
- const GLfloat *normal = (GLfloat *)VB->AttribPtr[_TNL_ATTRIB_NORMAL]->data;
-
- GLfloat (*Fcolor)[4] = (GLfloat (*)[4]) store->LitColor[0].data;
- GLfloat (*Fspec)[4] = (GLfloat (*)[4]) store->LitSecondary[0].data;
-#if IDX & LIGHT_TWOSIDE
- GLfloat (*Bcolor)[4] = (GLfloat (*)[4]) store->LitColor[1].data;
- GLfloat (*Bspec)[4] = (GLfloat (*)[4]) store->LitSecondary[1].data;
-#endif
-
- const GLuint nr = VB->Count;
-
-#ifdef TRACE
- fprintf(stderr, "%s\n", __FUNCTION__ );
-#endif
-
- VB->AttribPtr[_TNL_ATTRIB_COLOR0] = &store->LitColor[0];
- VB->AttribPtr[_TNL_ATTRIB_COLOR1] = &store->LitSecondary[0];
- sumA[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3];
-
-#if IDX & LIGHT_TWOSIDE
- VB->BackfaceColorPtr = &store->LitColor[1];
- VB->BackfaceSecondaryColorPtr = &store->LitSecondary[1];
- sumA[1] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3];
-#endif
-
-
- store->LitColor[0].stride = 16;
- store->LitColor[1].stride = 16;
-
- for (j = 0; j < nr; j++,STRIDE_F(vertex,vstride),STRIDE_F(normal,nstride)) {
- GLfloat sum[2][3], spec[2][3];
- struct gl_light *light;
-
-#if IDX & LIGHT_MATERIAL
- update_materials( ctx, store );
- sumA[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3];
-#if IDX & LIGHT_TWOSIDE
- sumA[1] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3];
-#endif
-#endif
-
- COPY_3V(sum[0], base[0]);
- ZERO_3V(spec[0]);
-
-#if IDX & LIGHT_TWOSIDE
- COPY_3V(sum[1], base[1]);
- ZERO_3V(spec[1]);
-#endif
-
- /* Add contribution from each enabled light source */
- foreach (light, &ctx->Light.EnabledList) {
- GLfloat n_dot_h;
- GLfloat correction;
- GLint side;
- GLfloat contrib[3];
- GLfloat attenuation;
- GLfloat VP[3]; /* unit vector from vertex to light */
- GLfloat n_dot_VP; /* n dot VP */
- GLfloat *h;
-
- /* compute VP and attenuation */
- if (!(light->_Flags & LIGHT_POSITIONAL)) {
- /* directional light */
- COPY_3V(VP, light->_VP_inf_norm);
- attenuation = light->_VP_inf_spot_attenuation;
- }
- else {
- GLfloat d; /* distance from vertex to light */
-
- SUB_3V(VP, light->_Position, vertex);
-
- d = (GLfloat) LEN_3FV( VP );
-
- if (d > 1e-6) {
- GLfloat invd = 1.0F / d;
- SELF_SCALE_SCALAR_3V(VP, invd);
- }
-
- attenuation = 1.0F / (light->ConstantAttenuation + d *
- (light->LinearAttenuation + d *
- light->QuadraticAttenuation));
-
- /* spotlight attenuation */
- if (light->_Flags & LIGHT_SPOT) {
- GLfloat PV_dot_dir = - DOT3(VP, light->_NormSpotDirection);
-
- if (PV_dot_dir<light->_CosCutoff) {
- continue; /* this light makes no contribution */
- }
- else {
- GLdouble x = PV_dot_dir * (EXP_TABLE_SIZE-1);
- GLint k = (GLint) x;
- GLfloat spot = (GLfloat) (light->_SpotExpTable[k][0]
- + (x-k)*light->_SpotExpTable[k][1]);
- attenuation *= spot;
- }
- }
- }
-
- if (attenuation < 1e-3)
- continue; /* this light makes no contribution */
-
- /* Compute dot product or normal and vector from V to light pos */
- n_dot_VP = DOT3( normal, VP );
-
- /* Which side gets the diffuse & specular terms? */
- if (n_dot_VP < 0.0F) {
- ACC_SCALE_SCALAR_3V(sum[0], attenuation, light->_MatAmbient[0]);
-#if IDX & LIGHT_TWOSIDE
- side = 1;
- correction = -1;
- n_dot_VP = -n_dot_VP;
-#else
- continue;
-#endif
- }
- else {
-#if IDX & LIGHT_TWOSIDE
- ACC_SCALE_SCALAR_3V( sum[1], attenuation, light->_MatAmbient[1]);
-#endif
- side = 0;
- correction = 1;
- }
-
- /* diffuse term */
- COPY_3V(contrib, light->_MatAmbient[side]);
- ACC_SCALE_SCALAR_3V(contrib, n_dot_VP, light->_MatDiffuse[side]);
- ACC_SCALE_SCALAR_3V(sum[side], attenuation, contrib );
-
- /* specular term - cannibalize VP... */
- if (ctx->Light.Model.LocalViewer) {
- GLfloat v[3];
- COPY_3V(v, vertex);
- NORMALIZE_3FV(v);
- SUB_3V(VP, VP, v); /* h = VP + VPe */
- h = VP;
- NORMALIZE_3FV(h);
- }
- else if (light->_Flags & LIGHT_POSITIONAL) {
- h = VP;
- ACC_3V(h, ctx->_EyeZDir);
- NORMALIZE_3FV(h);
- }
- else {
- h = light->_h_inf_norm;
- }
-
- n_dot_h = correction * DOT3(normal, h);
-
- if (n_dot_h > 0.0F) {
- GLfloat spec_coef;
- struct gl_shine_tab *tab = ctx->_ShineTable[side];
- GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec_coef );
-
- if (spec_coef > 1.0e-10) {
- spec_coef *= attenuation;
- ACC_SCALE_SCALAR_3V( spec[side], spec_coef,
- light->_MatSpecular[side]);
- }
- }
- } /*loop over lights*/
-
- COPY_3V( Fcolor[j], sum[0] );
- COPY_3V( Fspec[j], spec[0] );
- Fcolor[j][3] = sumA[0];
-
-#if IDX & LIGHT_TWOSIDE
- COPY_3V( Bcolor[j], sum[1] );
- COPY_3V( Bspec[j], spec[1] );
- Bcolor[j][3] = sumA[1];
-#endif
- }
-}
-
-
-static void TAG(light_rgba)( struct gl_context *ctx,
- struct vertex_buffer *VB,
- struct tnl_pipeline_stage *stage,
- GLvector4f *input )
-{
- struct light_stage_data *store = LIGHT_STAGE_DATA(stage);
- GLuint j;
-
- GLfloat (*base)[3] = ctx->Light._BaseColor;
- GLfloat sumA[2];
-
- const GLuint vstride = input->stride;
- const GLfloat *vertex = (GLfloat *) input->data;
- const GLuint nstride = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->stride;
- const GLfloat *normal = (GLfloat *)VB->AttribPtr[_TNL_ATTRIB_NORMAL]->data;
-
- GLfloat (*Fcolor)[4] = (GLfloat (*)[4]) store->LitColor[0].data;
-#if IDX & LIGHT_TWOSIDE
- GLfloat (*Bcolor)[4] = (GLfloat (*)[4]) store->LitColor[1].data;
-#endif
-
- const GLuint nr = VB->Count;
-
-#ifdef TRACE
- fprintf(stderr, "%s\n", __FUNCTION__ );
-#endif
-
- VB->AttribPtr[_TNL_ATTRIB_COLOR0] = &store->LitColor[0];
- sumA[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3];
-
-#if IDX & LIGHT_TWOSIDE
- VB->BackfaceColorPtr = &store->LitColor[1];
- sumA[1] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3];
-#endif
-
- store->LitColor[0].stride = 16;
- store->LitColor[1].stride = 16;
-
- for (j = 0; j < nr; j++,STRIDE_F(vertex,vstride),STRIDE_F(normal,nstride)) {
- GLfloat sum[2][3];
- struct gl_light *light;
-
-#if IDX & LIGHT_MATERIAL
- update_materials( ctx, store );
- sumA[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3];
-#if IDX & LIGHT_TWOSIDE
- sumA[1] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3];
-#endif
-#endif
-
- COPY_3V(sum[0], base[0]);
-
-#if IDX & LIGHT_TWOSIDE
- COPY_3V(sum[1], base[1]);
-#endif
-
- /* Add contribution from each enabled light source */
- foreach (light, &ctx->Light.EnabledList) {
-
- GLfloat n_dot_h;
- GLfloat correction;
- GLint side;
- GLfloat contrib[3];
- GLfloat attenuation = 1.0;
- GLfloat VP[3]; /* unit vector from vertex to light */
- GLfloat n_dot_VP; /* n dot VP */
- GLfloat *h;
-
- /* compute VP and attenuation */
- if (!(light->_Flags & LIGHT_POSITIONAL)) {
- /* directional light */
- COPY_3V(VP, light->_VP_inf_norm);
- attenuation = light->_VP_inf_spot_attenuation;
- }
- else {
- GLfloat d; /* distance from vertex to light */
-
-
- SUB_3V(VP, light->_Position, vertex);
-
- d = (GLfloat) LEN_3FV( VP );
-
- if ( d > 1e-6) {
- GLfloat invd = 1.0F / d;
- SELF_SCALE_SCALAR_3V(VP, invd);
- }
-
- attenuation = 1.0F / (light->ConstantAttenuation + d *
- (light->LinearAttenuation + d *
- light->QuadraticAttenuation));
-
- /* spotlight attenuation */
- if (light->_Flags & LIGHT_SPOT) {
- GLfloat PV_dot_dir = - DOT3(VP, light->_NormSpotDirection);
-
- if (PV_dot_dir<light->_CosCutoff) {
- continue; /* this light makes no contribution */
- }
- else {
- GLdouble x = PV_dot_dir * (EXP_TABLE_SIZE-1);
- GLint k = (GLint) x;
- GLfloat spot = (GLfloat) (light->_SpotExpTable[k][0]
- + (x-k)*light->_SpotExpTable[k][1]);
- attenuation *= spot;
- }
- }
- }
-
- if (attenuation < 1e-3)
- continue; /* this light makes no contribution */
-
- /* Compute dot product or normal and vector from V to light pos */
- n_dot_VP = DOT3( normal, VP );
-
- /* which side are we lighting? */
- if (n_dot_VP < 0.0F) {
- ACC_SCALE_SCALAR_3V(sum[0], attenuation, light->_MatAmbient[0]);
-#if IDX & LIGHT_TWOSIDE
- side = 1;
- correction = -1;
- n_dot_VP = -n_dot_VP;
-#else
- continue;
-#endif
- }
- else {
-#if IDX & LIGHT_TWOSIDE
- ACC_SCALE_SCALAR_3V( sum[1], attenuation, light->_MatAmbient[1]);
-#endif
- side = 0;
- correction = 1;
- }
-
- COPY_3V(contrib, light->_MatAmbient[side]);
-
- /* diffuse term */
- ACC_SCALE_SCALAR_3V(contrib, n_dot_VP, light->_MatDiffuse[side]);
-
- /* specular term - cannibalize VP... */
- {
- if (ctx->Light.Model.LocalViewer) {
- GLfloat v[3];
- COPY_3V(v, vertex);
- NORMALIZE_3FV(v);
- SUB_3V(VP, VP, v); /* h = VP + VPe */
- h = VP;
- NORMALIZE_3FV(h);
- }
- else if (light->_Flags & LIGHT_POSITIONAL) {
- h = VP;
- ACC_3V(h, ctx->_EyeZDir);
- NORMALIZE_3FV(h);
- }
- else {
- h = light->_h_inf_norm;
- }
-
- n_dot_h = correction * DOT3(normal, h);
-
- if (n_dot_h > 0.0F)
- {
- GLfloat spec_coef;
- struct gl_shine_tab *tab = ctx->_ShineTable[side];
-
- GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec_coef );
-
- ACC_SCALE_SCALAR_3V( contrib, spec_coef,
- light->_MatSpecular[side]);
- }
- }
-
- ACC_SCALE_SCALAR_3V( sum[side], attenuation, contrib );
- }
-
- COPY_3V( Fcolor[j], sum[0] );
- Fcolor[j][3] = sumA[0];
-
-#if IDX & LIGHT_TWOSIDE
- COPY_3V( Bcolor[j], sum[1] );
- Bcolor[j][3] = sumA[1];
-#endif
- }
-}
-
-
-
-
-/* As below, but with just a single light.
- */
-static void TAG(light_fast_rgba_single)( struct gl_context *ctx,
- struct vertex_buffer *VB,
- struct tnl_pipeline_stage *stage,
- GLvector4f *input )
-
-{
- struct light_stage_data *store = LIGHT_STAGE_DATA(stage);
- const GLuint nstride = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->stride;
- const GLfloat *normal = (GLfloat *)VB->AttribPtr[_TNL_ATTRIB_NORMAL]->data;
- GLfloat (*Fcolor)[4] = (GLfloat (*)[4]) store->LitColor[0].data;
-#if IDX & LIGHT_TWOSIDE
- GLfloat (*Bcolor)[4] = (GLfloat (*)[4]) store->LitColor[1].data;
-#endif
- const struct gl_light *light = ctx->Light.EnabledList.next;
- GLuint j = 0;
- GLfloat base[2][4];
-#if IDX & LIGHT_MATERIAL
- const GLuint nr = VB->Count;
-#else
- const GLuint nr = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->count;
-#endif
-
-#ifdef TRACE
- fprintf(stderr, "%s\n", __FUNCTION__ );
-#endif
-
- (void) input; /* doesn't refer to Eye or Obj */
-
- VB->AttribPtr[_TNL_ATTRIB_COLOR0] = &store->LitColor[0];
-#if IDX & LIGHT_TWOSIDE
- VB->BackfaceColorPtr = &store->LitColor[1];
-#endif
-
- if (nr > 1) {
- store->LitColor[0].stride = 16;
- store->LitColor[1].stride = 16;
- }
- else {
- store->LitColor[0].stride = 0;
- store->LitColor[1].stride = 0;
- }
-
- for (j = 0; j < nr; j++, STRIDE_F(normal,nstride)) {
-
- GLfloat n_dot_VP;
-
-#if IDX & LIGHT_MATERIAL
- update_materials( ctx, store );
-#endif
-
- /* No attenuation, so incoporate _MatAmbient into base color.
- */
-#if !(IDX & LIGHT_MATERIAL)
- if ( j == 0 )
-#endif
- {
- COPY_3V(base[0], light->_MatAmbient[0]);
- ACC_3V(base[0], ctx->Light._BaseColor[0] );
- base[0][3] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3];
-
-#if IDX & LIGHT_TWOSIDE
- COPY_3V(base[1], light->_MatAmbient[1]);
- ACC_3V(base[1], ctx->Light._BaseColor[1]);
- base[1][3] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3];
-#endif
- }
-
- n_dot_VP = DOT3(normal, light->_VP_inf_norm);
-
- if (n_dot_VP < 0.0F) {
-#if IDX & LIGHT_TWOSIDE
- GLfloat n_dot_h = -DOT3(normal, light->_h_inf_norm);
- GLfloat sum[3];
- COPY_3V(sum, base[1]);
- ACC_SCALE_SCALAR_3V(sum, -n_dot_VP, light->_MatDiffuse[1]);
- if (n_dot_h > 0.0F) {
- GLfloat spec;
- GET_SHINE_TAB_ENTRY( ctx->_ShineTable[1], n_dot_h, spec );
- ACC_SCALE_SCALAR_3V(sum, spec, light->_MatSpecular[1]);
- }
- COPY_3V(Bcolor[j], sum );
- Bcolor[j][3] = base[1][3];
-#endif
- COPY_4FV(Fcolor[j], base[0]);
- }
- else {
- GLfloat n_dot_h = DOT3(normal, light->_h_inf_norm);
- GLfloat sum[3];
- COPY_3V(sum, base[0]);
- ACC_SCALE_SCALAR_3V(sum, n_dot_VP, light->_MatDiffuse[0]);
- if (n_dot_h > 0.0F) {
- GLfloat spec;
- GET_SHINE_TAB_ENTRY( ctx->_ShineTable[0], n_dot_h, spec );
- ACC_SCALE_SCALAR_3V(sum, spec, light->_MatSpecular[0]);
-
- }
- COPY_3V(Fcolor[j], sum );
- Fcolor[j][3] = base[0][3];
-#if IDX & LIGHT_TWOSIDE
- COPY_4FV(Bcolor[j], base[1]);
-#endif
- }
- }
-}
-
-
-/* Light infinite lights
- */
-static void TAG(light_fast_rgba)( struct gl_context *ctx,
- struct vertex_buffer *VB,
- struct tnl_pipeline_stage *stage,
- GLvector4f *input )
-{
- struct light_stage_data *store = LIGHT_STAGE_DATA(stage);
- GLfloat sumA[2];
- const GLuint nstride = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->stride;
- const GLfloat *normal = (GLfloat *)VB->AttribPtr[_TNL_ATTRIB_NORMAL]->data;
- GLfloat (*Fcolor)[4] = (GLfloat (*)[4]) store->LitColor[0].data;
-#if IDX & LIGHT_TWOSIDE
- GLfloat (*Bcolor)[4] = (GLfloat (*)[4]) store->LitColor[1].data;
-#endif
- GLuint j = 0;
-#if IDX & LIGHT_MATERIAL
- const GLuint nr = VB->Count;
-#else
- const GLuint nr = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->count;
-#endif
- const struct gl_light *light;
-
-#ifdef TRACE
- fprintf(stderr, "%s %d\n", __FUNCTION__, nr );
-#endif
-
- (void) input;
-
- sumA[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3];
- sumA[1] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3];
-
- VB->AttribPtr[_TNL_ATTRIB_COLOR0] = &store->LitColor[0];
-#if IDX & LIGHT_TWOSIDE
- VB->BackfaceColorPtr = &store->LitColor[1];
-#endif
-
- if (nr > 1) {
- store->LitColor[0].stride = 16;
- store->LitColor[1].stride = 16;
- }
- else {
- store->LitColor[0].stride = 0;
- store->LitColor[1].stride = 0;
- }
-
- for (j = 0; j < nr; j++, STRIDE_F(normal,nstride)) {
-
- GLfloat sum[2][3];
-
-#if IDX & LIGHT_MATERIAL
- update_materials( ctx, store );
-
- sumA[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3];
-#if IDX & LIGHT_TWOSIDE
- sumA[1] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3];
-#endif
-#endif
-
-
- COPY_3V(sum[0], ctx->Light._BaseColor[0]);
-#if IDX & LIGHT_TWOSIDE
- COPY_3V(sum[1], ctx->Light._BaseColor[1]);
-#endif
-
- foreach (light, &ctx->Light.EnabledList) {
- GLfloat n_dot_h, n_dot_VP, spec;
-
- ACC_3V(sum[0], light->_MatAmbient[0]);
-#if IDX & LIGHT_TWOSIDE
- ACC_3V(sum[1], light->_MatAmbient[1]);
-#endif
-
- n_dot_VP = DOT3(normal, light->_VP_inf_norm);
-
- if (n_dot_VP > 0.0F) {
- ACC_SCALE_SCALAR_3V(sum[0], n_dot_VP, light->_MatDiffuse[0]);
- n_dot_h = DOT3(normal, light->_h_inf_norm);
- if (n_dot_h > 0.0F) {
- struct gl_shine_tab *tab = ctx->_ShineTable[0];
- GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec );
- ACC_SCALE_SCALAR_3V( sum[0], spec, light->_MatSpecular[0]);
- }
- }
-#if IDX & LIGHT_TWOSIDE
- else {
- ACC_SCALE_SCALAR_3V(sum[1], -n_dot_VP, light->_MatDiffuse[1]);
- n_dot_h = -DOT3(normal, light->_h_inf_norm);
- if (n_dot_h > 0.0F) {
- struct gl_shine_tab *tab = ctx->_ShineTable[1];
- GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec );
- ACC_SCALE_SCALAR_3V( sum[1], spec, light->_MatSpecular[1]);
- }
- }
-#endif
- }
-
- COPY_3V( Fcolor[j], sum[0] );
- Fcolor[j][3] = sumA[0];
-
-#if IDX & LIGHT_TWOSIDE
- COPY_3V( Bcolor[j], sum[1] );
- Bcolor[j][3] = sumA[1];
-#endif
- }
-}
-
-
-
-
-static void TAG(init_light_tab)( void )
-{
- _tnl_light_tab[IDX] = TAG(light_rgba);
- _tnl_light_fast_tab[IDX] = TAG(light_fast_rgba);
- _tnl_light_fast_single_tab[IDX] = TAG(light_fast_rgba_single);
- _tnl_light_spec_tab[IDX] = TAG(light_rgba_spec);
-}
-
-
-#undef TAG
-#undef IDX
-#undef NR_SIDES
+/* + * Mesa 3-D graphics library + * Version: 5.1 + * + * Copyright (C) 1999-2003 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. + * + * + * Authors: + * Brian Paul + * Keith Whitwell <keith@tungstengraphics.com> + */ + + +#if IDX & LIGHT_TWOSIDE +# define NR_SIDES 2 +#else +# define NR_SIDES 1 +#endif + + +/* define TRACE to trace lighting code */ +/* #define TRACE 1 */ + +/* + * ctx is the current context + * VB is the vertex buffer + * stage is the lighting stage-private data + * input is the vector of eye or object-space vertex coordinates + */ +static void TAG(light_rgba_spec)( struct gl_context *ctx, + struct vertex_buffer *VB, + struct tnl_pipeline_stage *stage, + GLvector4f *input ) +{ + struct light_stage_data *store = LIGHT_STAGE_DATA(stage); + GLfloat (*base)[3] = ctx->Light._BaseColor; + GLfloat sumA[2]; + GLuint j; + + const GLuint vstride = input->stride; + const GLfloat *vertex = (GLfloat *)input->data; + const GLuint nstride = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->stride; + const GLfloat *normal = (GLfloat *)VB->AttribPtr[_TNL_ATTRIB_NORMAL]->data; + + GLfloat (*Fcolor)[4] = (GLfloat (*)[4]) store->LitColor[0].data; + GLfloat (*Fspec)[4] = (GLfloat (*)[4]) store->LitSecondary[0].data; +#if IDX & LIGHT_TWOSIDE + GLfloat (*Bcolor)[4] = (GLfloat (*)[4]) store->LitColor[1].data; + GLfloat (*Bspec)[4] = (GLfloat (*)[4]) store->LitSecondary[1].data; +#endif + + const GLuint nr = VB->Count; + +#ifdef TRACE + fprintf(stderr, "%s\n", __FUNCTION__ ); +#endif + + VB->AttribPtr[_TNL_ATTRIB_COLOR0] = &store->LitColor[0]; + VB->AttribPtr[_TNL_ATTRIB_COLOR1] = &store->LitSecondary[0]; + sumA[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3]; + +#if IDX & LIGHT_TWOSIDE + VB->BackfaceColorPtr = &store->LitColor[1]; + VB->BackfaceSecondaryColorPtr = &store->LitSecondary[1]; + sumA[1] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3]; +#endif + + + store->LitColor[0].stride = 16; + store->LitColor[1].stride = 16; + + for (j = 0; j < nr; j++,STRIDE_F(vertex,vstride),STRIDE_F(normal,nstride)) { + GLfloat sum[2][3], spec[2][3]; + struct gl_light *light; + +#if IDX & LIGHT_MATERIAL + update_materials( ctx, store ); + sumA[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3]; +#if IDX & LIGHT_TWOSIDE + sumA[1] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3]; +#endif +#endif + + COPY_3V(sum[0], base[0]); + ZERO_3V(spec[0]); + +#if IDX & LIGHT_TWOSIDE + COPY_3V(sum[1], base[1]); + ZERO_3V(spec[1]); +#endif + + /* Add contribution from each enabled light source */ + foreach (light, &ctx->Light.EnabledList) { + GLfloat n_dot_h; + GLfloat correction; + GLint side; + GLfloat contrib[3]; + GLfloat attenuation; + GLfloat VP[3]; /* unit vector from vertex to light */ + GLfloat n_dot_VP; /* n dot VP */ + GLfloat *h; + + /* compute VP and attenuation */ + if (!(light->_Flags & LIGHT_POSITIONAL)) { + /* directional light */ + COPY_3V(VP, light->_VP_inf_norm); + attenuation = light->_VP_inf_spot_attenuation; + } + else { + GLfloat d; /* distance from vertex to light */ + + SUB_3V(VP, light->_Position, vertex); + + d = (GLfloat) LEN_3FV( VP ); + + if (d > 1e-6) { + GLfloat invd = 1.0F / d; + SELF_SCALE_SCALAR_3V(VP, invd); + } + + attenuation = 1.0F / (light->ConstantAttenuation + d * + (light->LinearAttenuation + d * + light->QuadraticAttenuation)); + + /* spotlight attenuation */ + if (light->_Flags & LIGHT_SPOT) { + GLfloat PV_dot_dir = - DOT3(VP, light->_NormSpotDirection); + + if (PV_dot_dir<light->_CosCutoff) { + continue; /* this light makes no contribution */ + } + else { + GLfloat spot = powf(PV_dot_dir, light->SpotExponent); + attenuation *= spot; + } + } + } + + if (attenuation < 1e-3) + continue; /* this light makes no contribution */ + + /* Compute dot product or normal and vector from V to light pos */ + n_dot_VP = DOT3( normal, VP ); + + /* Which side gets the diffuse & specular terms? */ + if (n_dot_VP < 0.0F) { + ACC_SCALE_SCALAR_3V(sum[0], attenuation, light->_MatAmbient[0]); +#if IDX & LIGHT_TWOSIDE + side = 1; + correction = -1; + n_dot_VP = -n_dot_VP; +#else + continue; +#endif + } + else { +#if IDX & LIGHT_TWOSIDE + ACC_SCALE_SCALAR_3V( sum[1], attenuation, light->_MatAmbient[1]); +#endif + side = 0; + correction = 1; + } + + /* diffuse term */ + COPY_3V(contrib, light->_MatAmbient[side]); + ACC_SCALE_SCALAR_3V(contrib, n_dot_VP, light->_MatDiffuse[side]); + ACC_SCALE_SCALAR_3V(sum[side], attenuation, contrib ); + + /* specular term - cannibalize VP... */ + if (ctx->Light.Model.LocalViewer) { + GLfloat v[3]; + COPY_3V(v, vertex); + NORMALIZE_3FV(v); + SUB_3V(VP, VP, v); /* h = VP + VPe */ + h = VP; + NORMALIZE_3FV(h); + } + else if (light->_Flags & LIGHT_POSITIONAL) { + h = VP; + ACC_3V(h, ctx->_EyeZDir); + NORMALIZE_3FV(h); + } + else { + h = light->_h_inf_norm; + } + + n_dot_h = correction * DOT3(normal, h); + + if (n_dot_h > 0.0F) { + GLfloat spec_coef = _mesa_lookup_shininess(ctx, side, n_dot_h); + if (spec_coef > 1.0e-10) { + spec_coef *= attenuation; + ACC_SCALE_SCALAR_3V( spec[side], spec_coef, + light->_MatSpecular[side]); + } + } + } /*loop over lights*/ + + COPY_3V( Fcolor[j], sum[0] ); + COPY_3V( Fspec[j], spec[0] ); + Fcolor[j][3] = sumA[0]; + +#if IDX & LIGHT_TWOSIDE + COPY_3V( Bcolor[j], sum[1] ); + COPY_3V( Bspec[j], spec[1] ); + Bcolor[j][3] = sumA[1]; +#endif + } +} + + +static void TAG(light_rgba)( struct gl_context *ctx, + struct vertex_buffer *VB, + struct tnl_pipeline_stage *stage, + GLvector4f *input ) +{ + struct light_stage_data *store = LIGHT_STAGE_DATA(stage); + GLuint j; + + GLfloat (*base)[3] = ctx->Light._BaseColor; + GLfloat sumA[2]; + + const GLuint vstride = input->stride; + const GLfloat *vertex = (GLfloat *) input->data; + const GLuint nstride = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->stride; + const GLfloat *normal = (GLfloat *)VB->AttribPtr[_TNL_ATTRIB_NORMAL]->data; + + GLfloat (*Fcolor)[4] = (GLfloat (*)[4]) store->LitColor[0].data; +#if IDX & LIGHT_TWOSIDE + GLfloat (*Bcolor)[4] = (GLfloat (*)[4]) store->LitColor[1].data; +#endif + + const GLuint nr = VB->Count; + +#ifdef TRACE + fprintf(stderr, "%s\n", __FUNCTION__ ); +#endif + + VB->AttribPtr[_TNL_ATTRIB_COLOR0] = &store->LitColor[0]; + sumA[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3]; + +#if IDX & LIGHT_TWOSIDE + VB->BackfaceColorPtr = &store->LitColor[1]; + sumA[1] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3]; +#endif + + store->LitColor[0].stride = 16; + store->LitColor[1].stride = 16; + + for (j = 0; j < nr; j++,STRIDE_F(vertex,vstride),STRIDE_F(normal,nstride)) { + GLfloat sum[2][3]; + struct gl_light *light; + +#if IDX & LIGHT_MATERIAL + update_materials( ctx, store ); + sumA[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3]; +#if IDX & LIGHT_TWOSIDE + sumA[1] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3]; +#endif +#endif + + COPY_3V(sum[0], base[0]); + +#if IDX & LIGHT_TWOSIDE + COPY_3V(sum[1], base[1]); +#endif + + /* Add contribution from each enabled light source */ + foreach (light, &ctx->Light.EnabledList) { + + GLfloat n_dot_h; + GLfloat correction; + GLint side; + GLfloat contrib[3]; + GLfloat attenuation = 1.0; + GLfloat VP[3]; /* unit vector from vertex to light */ + GLfloat n_dot_VP; /* n dot VP */ + GLfloat *h; + + /* compute VP and attenuation */ + if (!(light->_Flags & LIGHT_POSITIONAL)) { + /* directional light */ + COPY_3V(VP, light->_VP_inf_norm); + attenuation = light->_VP_inf_spot_attenuation; + } + else { + GLfloat d; /* distance from vertex to light */ + + + SUB_3V(VP, light->_Position, vertex); + + d = (GLfloat) LEN_3FV( VP ); + + if ( d > 1e-6) { + GLfloat invd = 1.0F / d; + SELF_SCALE_SCALAR_3V(VP, invd); + } + + attenuation = 1.0F / (light->ConstantAttenuation + d * + (light->LinearAttenuation + d * + light->QuadraticAttenuation)); + + /* spotlight attenuation */ + if (light->_Flags & LIGHT_SPOT) { + GLfloat PV_dot_dir = - DOT3(VP, light->_NormSpotDirection); + + if (PV_dot_dir<light->_CosCutoff) { + continue; /* this light makes no contribution */ + } + else { + GLfloat spot = powf(PV_dot_dir, light->SpotExponent); + attenuation *= spot; + } + } + } + + if (attenuation < 1e-3) + continue; /* this light makes no contribution */ + + /* Compute dot product or normal and vector from V to light pos */ + n_dot_VP = DOT3( normal, VP ); + + /* which side are we lighting? */ + if (n_dot_VP < 0.0F) { + ACC_SCALE_SCALAR_3V(sum[0], attenuation, light->_MatAmbient[0]); +#if IDX & LIGHT_TWOSIDE + side = 1; + correction = -1; + n_dot_VP = -n_dot_VP; +#else + continue; +#endif + } + else { +#if IDX & LIGHT_TWOSIDE + ACC_SCALE_SCALAR_3V( sum[1], attenuation, light->_MatAmbient[1]); +#endif + side = 0; + correction = 1; + } + + COPY_3V(contrib, light->_MatAmbient[side]); + + /* diffuse term */ + ACC_SCALE_SCALAR_3V(contrib, n_dot_VP, light->_MatDiffuse[side]); + + /* specular term - cannibalize VP... */ + { + if (ctx->Light.Model.LocalViewer) { + GLfloat v[3]; + COPY_3V(v, vertex); + NORMALIZE_3FV(v); + SUB_3V(VP, VP, v); /* h = VP + VPe */ + h = VP; + NORMALIZE_3FV(h); + } + else if (light->_Flags & LIGHT_POSITIONAL) { + h = VP; + ACC_3V(h, ctx->_EyeZDir); + NORMALIZE_3FV(h); + } + else { + h = light->_h_inf_norm; + } + + n_dot_h = correction * DOT3(normal, h); + + if (n_dot_h > 0.0F) { + GLfloat spec_coef = _mesa_lookup_shininess(ctx, side, n_dot_h); + ACC_SCALE_SCALAR_3V( contrib, spec_coef, + light->_MatSpecular[side]); + } + } + + ACC_SCALE_SCALAR_3V( sum[side], attenuation, contrib ); + } + + COPY_3V( Fcolor[j], sum[0] ); + Fcolor[j][3] = sumA[0]; + +#if IDX & LIGHT_TWOSIDE + COPY_3V( Bcolor[j], sum[1] ); + Bcolor[j][3] = sumA[1]; +#endif + } +} + + + + +/* As below, but with just a single light. + */ +static void TAG(light_fast_rgba_single)( struct gl_context *ctx, + struct vertex_buffer *VB, + struct tnl_pipeline_stage *stage, + GLvector4f *input ) + +{ + struct light_stage_data *store = LIGHT_STAGE_DATA(stage); + const GLuint nstride = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->stride; + const GLfloat *normal = (GLfloat *)VB->AttribPtr[_TNL_ATTRIB_NORMAL]->data; + GLfloat (*Fcolor)[4] = (GLfloat (*)[4]) store->LitColor[0].data; +#if IDX & LIGHT_TWOSIDE + GLfloat (*Bcolor)[4] = (GLfloat (*)[4]) store->LitColor[1].data; +#endif + const struct gl_light *light = ctx->Light.EnabledList.next; + GLuint j = 0; + GLfloat base[2][4]; +#if IDX & LIGHT_MATERIAL + const GLuint nr = VB->Count; +#else + const GLuint nr = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->count; +#endif + +#ifdef TRACE + fprintf(stderr, "%s\n", __FUNCTION__ ); +#endif + + (void) input; /* doesn't refer to Eye or Obj */ + + VB->AttribPtr[_TNL_ATTRIB_COLOR0] = &store->LitColor[0]; +#if IDX & LIGHT_TWOSIDE + VB->BackfaceColorPtr = &store->LitColor[1]; +#endif + + if (nr > 1) { + store->LitColor[0].stride = 16; + store->LitColor[1].stride = 16; + } + else { + store->LitColor[0].stride = 0; + store->LitColor[1].stride = 0; + } + + for (j = 0; j < nr; j++, STRIDE_F(normal,nstride)) { + + GLfloat n_dot_VP; + +#if IDX & LIGHT_MATERIAL + update_materials( ctx, store ); +#endif + + /* No attenuation, so incoporate _MatAmbient into base color. + */ +#if !(IDX & LIGHT_MATERIAL) + if ( j == 0 ) +#endif + { + COPY_3V(base[0], light->_MatAmbient[0]); + ACC_3V(base[0], ctx->Light._BaseColor[0] ); + base[0][3] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3]; + +#if IDX & LIGHT_TWOSIDE + COPY_3V(base[1], light->_MatAmbient[1]); + ACC_3V(base[1], ctx->Light._BaseColor[1]); + base[1][3] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3]; +#endif + } + + n_dot_VP = DOT3(normal, light->_VP_inf_norm); + + if (n_dot_VP < 0.0F) { +#if IDX & LIGHT_TWOSIDE + GLfloat n_dot_h = -DOT3(normal, light->_h_inf_norm); + GLfloat sum[3]; + COPY_3V(sum, base[1]); + ACC_SCALE_SCALAR_3V(sum, -n_dot_VP, light->_MatDiffuse[1]); + if (n_dot_h > 0.0F) { + GLfloat spec = _mesa_lookup_shininess(ctx, 1, n_dot_h); + ACC_SCALE_SCALAR_3V(sum, spec, light->_MatSpecular[1]); + } + COPY_3V(Bcolor[j], sum ); + Bcolor[j][3] = base[1][3]; +#endif + COPY_4FV(Fcolor[j], base[0]); + } + else { + GLfloat n_dot_h = DOT3(normal, light->_h_inf_norm); + GLfloat sum[3]; + COPY_3V(sum, base[0]); + ACC_SCALE_SCALAR_3V(sum, n_dot_VP, light->_MatDiffuse[0]); + if (n_dot_h > 0.0F) { + GLfloat spec = _mesa_lookup_shininess(ctx, 0, n_dot_h); + ACC_SCALE_SCALAR_3V(sum, spec, light->_MatSpecular[0]); + } + COPY_3V(Fcolor[j], sum ); + Fcolor[j][3] = base[0][3]; +#if IDX & LIGHT_TWOSIDE + COPY_4FV(Bcolor[j], base[1]); +#endif + } + } +} + + +/* Light infinite lights + */ +static void TAG(light_fast_rgba)( struct gl_context *ctx, + struct vertex_buffer *VB, + struct tnl_pipeline_stage *stage, + GLvector4f *input ) +{ + struct light_stage_data *store = LIGHT_STAGE_DATA(stage); + GLfloat sumA[2]; + const GLuint nstride = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->stride; + const GLfloat *normal = (GLfloat *)VB->AttribPtr[_TNL_ATTRIB_NORMAL]->data; + GLfloat (*Fcolor)[4] = (GLfloat (*)[4]) store->LitColor[0].data; +#if IDX & LIGHT_TWOSIDE + GLfloat (*Bcolor)[4] = (GLfloat (*)[4]) store->LitColor[1].data; +#endif + GLuint j = 0; +#if IDX & LIGHT_MATERIAL + const GLuint nr = VB->Count; +#else + const GLuint nr = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->count; +#endif + const struct gl_light *light; + +#ifdef TRACE + fprintf(stderr, "%s %d\n", __FUNCTION__, nr ); +#endif + + (void) input; + + sumA[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3]; + sumA[1] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3]; + + VB->AttribPtr[_TNL_ATTRIB_COLOR0] = &store->LitColor[0]; +#if IDX & LIGHT_TWOSIDE + VB->BackfaceColorPtr = &store->LitColor[1]; +#endif + + if (nr > 1) { + store->LitColor[0].stride = 16; + store->LitColor[1].stride = 16; + } + else { + store->LitColor[0].stride = 0; + store->LitColor[1].stride = 0; + } + + for (j = 0; j < nr; j++, STRIDE_F(normal,nstride)) { + + GLfloat sum[2][3]; + +#if IDX & LIGHT_MATERIAL + update_materials( ctx, store ); + + sumA[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3]; +#if IDX & LIGHT_TWOSIDE + sumA[1] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3]; +#endif +#endif + + + COPY_3V(sum[0], ctx->Light._BaseColor[0]); +#if IDX & LIGHT_TWOSIDE + COPY_3V(sum[1], ctx->Light._BaseColor[1]); +#endif + + foreach (light, &ctx->Light.EnabledList) { + GLfloat n_dot_h, n_dot_VP, spec; + + ACC_3V(sum[0], light->_MatAmbient[0]); +#if IDX & LIGHT_TWOSIDE + ACC_3V(sum[1], light->_MatAmbient[1]); +#endif + + n_dot_VP = DOT3(normal, light->_VP_inf_norm); + + if (n_dot_VP > 0.0F) { + ACC_SCALE_SCALAR_3V(sum[0], n_dot_VP, light->_MatDiffuse[0]); + n_dot_h = DOT3(normal, light->_h_inf_norm); + if (n_dot_h > 0.0F) { + spec = _mesa_lookup_shininess(ctx, 0, n_dot_h); + ACC_SCALE_SCALAR_3V( sum[0], spec, light->_MatSpecular[0]); + } + } +#if IDX & LIGHT_TWOSIDE + else { + ACC_SCALE_SCALAR_3V(sum[1], -n_dot_VP, light->_MatDiffuse[1]); + n_dot_h = -DOT3(normal, light->_h_inf_norm); + if (n_dot_h > 0.0F) { + spec = _mesa_lookup_shininess(ctx, 1, n_dot_h); + ACC_SCALE_SCALAR_3V( sum[1], spec, light->_MatSpecular[1]); + } + } +#endif + } + + COPY_3V( Fcolor[j], sum[0] ); + Fcolor[j][3] = sumA[0]; + +#if IDX & LIGHT_TWOSIDE + COPY_3V( Bcolor[j], sum[1] ); + Bcolor[j][3] = sumA[1]; +#endif + } +} + + + + +static void TAG(init_light_tab)( void ) +{ + _tnl_light_tab[IDX] = TAG(light_rgba); + _tnl_light_fast_tab[IDX] = TAG(light_fast_rgba); + _tnl_light_fast_single_tab[IDX] = TAG(light_fast_rgba_single); + _tnl_light_spec_tab[IDX] = TAG(light_rgba_spec); +} + + +#undef TAG +#undef IDX +#undef NR_SIDES diff --git a/mesalib/src/mesa/vbo/vbo_save.h b/mesalib/src/mesa/vbo/vbo_save.h index 4d4a5bf17..0b4d563a7 100644 --- a/mesalib/src/mesa/vbo/vbo_save.h +++ b/mesalib/src/mesa/vbo/vbo_save.h @@ -187,6 +187,14 @@ void vbo_save_playback_vertex_list( struct gl_context *ctx, void *data ); void vbo_save_api_init( struct vbo_save_context *save ); +GLfloat * +vbo_save_map_vertex_store(struct gl_context *ctx, + struct vbo_save_vertex_store *vertex_store); + +void +vbo_save_unmap_vertex_store(struct gl_context *ctx, + struct vbo_save_vertex_store *vertex_store); + #else /* FEATURE_dlist */ static inline void diff --git a/mesalib/src/mesa/vbo/vbo_save_api.c b/mesalib/src/mesa/vbo/vbo_save_api.c index 952136747..13604333e 100644 --- a/mesalib/src/mesa/vbo/vbo_save_api.c +++ b/mesalib/src/mesa/vbo/vbo_save_api.c @@ -237,9 +237,9 @@ free_vertex_store(struct gl_context *ctx, } -static GLfloat * -map_vertex_store(struct gl_context *ctx, - struct vbo_save_vertex_store *vertex_store) +GLfloat * +vbo_save_map_vertex_store(struct gl_context *ctx, + struct vbo_save_vertex_store *vertex_store) { assert(vertex_store->bufferobj); assert(!vertex_store->buffer); @@ -259,9 +259,9 @@ map_vertex_store(struct gl_context *ctx, } -static void -unmap_vertex_store(struct gl_context *ctx, - struct vbo_save_vertex_store *vertex_store) +void +vbo_save_unmap_vertex_store(struct gl_context *ctx, + struct vbo_save_vertex_store *vertex_store) { if (vertex_store->bufferobj->Size > 0) { ctx->Driver.UnmapBuffer(ctx, vertex_store->bufferobj); @@ -407,7 +407,7 @@ _save_compile_vertex_list(struct gl_context *ctx) /* Unmap old store: */ - unmap_vertex_store(ctx, save->vertex_store); + vbo_save_unmap_vertex_store(ctx, save->vertex_store); /* Release old reference: */ @@ -418,7 +418,7 @@ _save_compile_vertex_list(struct gl_context *ctx) /* Allocate and map new store: */ save->vertex_store = alloc_vertex_store(ctx); - save->buffer_ptr = map_vertex_store(ctx, save->vertex_store); + save->buffer_ptr = vbo_save_map_vertex_store(ctx, save->vertex_store); save->out_of_memory = save->buffer_ptr == NULL; } @@ -1398,7 +1398,7 @@ vbo_save_NewList(struct gl_context *ctx, GLuint list, GLenum mode) if (!save->vertex_store) save->vertex_store = alloc_vertex_store(ctx); - save->buffer_ptr = map_vertex_store(ctx, save->vertex_store); + save->buffer_ptr = vbo_save_map_vertex_store(ctx, save->vertex_store); _save_reset_vertex(ctx); _save_reset_counters(ctx); @@ -1435,7 +1435,7 @@ vbo_save_EndList(struct gl_context *ctx) _mesa_install_save_vtxfmt(ctx, &ctx->ListState.ListVtxfmt); } - unmap_vertex_store(ctx, save->vertex_store); + vbo_save_unmap_vertex_store(ctx, save->vertex_store); assert(save->vertex_size == 0); } diff --git a/mesalib/src/mesa/vbo/vbo_save_draw.c b/mesalib/src/mesa/vbo/vbo_save_draw.c index b903757c0..b8e1e7883 100644 --- a/mesalib/src/mesa/vbo/vbo_save_draw.c +++ b/mesalib/src/mesa/vbo/vbo_save_draw.c @@ -249,6 +249,19 @@ vbo_save_playback_vertex_list(struct gl_context *ctx, void *data) (const struct vbo_save_vertex_list *) data; struct vbo_save_context *save = &vbo_context(ctx)->save; struct vbo_exec_context *exec = &vbo_context(ctx)->exec; + GLboolean remap_vertex_store = GL_FALSE; + + if (save->vertex_store->buffer) { + /* The vertex store is currently mapped but we're about to replay + * a display list. This can happen when a nested display list is + * being build with GL_COMPILE_AND_EXECUTE. + * We never want to have mapped vertex buffers when we're drawing. + * Unmap the vertex store, execute the list, then remap the vertex + * store. + */ + vbo_save_unmap_vertex_store(ctx, save->vertex_store); + remap_vertex_store = GL_TRUE; + } FLUSH_CURRENT(ctx, 0); @@ -264,14 +277,16 @@ vbo_save_playback_vertex_list(struct gl_context *ctx, void *data) printf("displaylist recursive begin"); vbo_save_loopback_vertex_list( ctx, node ); - return; + + goto end; } else if (save->replay_flags) { /* Various degnerate cases: translate into immediate mode * calls rather than trying to execute in place. */ vbo_save_loopback_vertex_list( ctx, node ); - return; + + goto end; } if (ctx->NewState) @@ -310,6 +325,11 @@ vbo_save_playback_vertex_list(struct gl_context *ctx, void *data) /* Copy to current? */ _playback_copy_to_current( ctx, node ); + +end: + if (remap_vertex_store) { + save->buffer_ptr = vbo_save_map_vertex_store(ctx, save->vertex_store); + } } diff --git a/mesalib/src/mesa/x86/gen_matypes.c b/mesalib/src/mesa/x86/gen_matypes.c index 97f71f92c..7af82b4ae 100644 --- a/mesalib/src/mesa/x86/gen_matypes.c +++ b/mesalib/src/mesa/x86/gen_matypes.c @@ -209,7 +209,6 @@ int main( int argc, char **argv ) OFFSET( "LIGHT_NORM_DIRECTION ", struct gl_light, _NormSpotDirection ); OFFSET( "LIGHT_VP_INF_SPOT_ATTEN ", struct gl_light, _VP_inf_spot_attenuation ); printf( "\n" ); - OFFSET( "LIGHT_SPOT_EXP_TABLE ", struct gl_light, _SpotExpTable ); OFFSET( "LIGHT_MAT_AMBIENT ", struct gl_light, _MatAmbient ); OFFSET( "LIGHT_MAT_DIFFUSE ", struct gl_light, _MatDiffuse ); OFFSET( "LIGHT_MAT_SPECULAR ", struct gl_light, _MatSpecular ); |