diff options
Diffstat (limited to 'mesalib/src')
23 files changed, 840 insertions, 781 deletions
diff --git a/mesalib/src/gallium/auxiliary/util/u_blit.c b/mesalib/src/gallium/auxiliary/util/u_blit.c index a10fd17cb..127973388 100644 --- a/mesalib/src/gallium/auxiliary/util/u_blit.c +++ b/mesalib/src/gallium/auxiliary/util/u_blit.c @@ -321,6 +321,26 @@ regions_overlap(int srcX0, int srcY0, /** + * Can we blit from src format to dest format with a simple copy? + */ +static boolean +formats_compatible(enum pipe_format src_format, + enum pipe_format dst_format) +{ + if (src_format == dst_format) { + return TRUE; + } + else { + const struct util_format_description *src_desc = + util_format_description(src_format); + const struct util_format_description *dst_desc = + util_format_description(dst_format); + return util_is_format_compatible(src_desc, dst_desc); + } +} + + +/** * Copy pixel block from src surface to dst surface. * Overlapping regions are acceptable. * Flipping and stretching are supported. @@ -377,7 +397,7 @@ util_blit_pixels_writemask(struct blit_state *ctx, * no overlapping. * Filter mode should not matter since there's no stretching. */ - if (dst_format == src_format && + if (formats_compatible(src_format, dst_format) && srcX0 < srcX1 && dstX0 < dstX1 && srcY0 < srcY1 && diff --git a/mesalib/src/gallium/auxiliary/util/u_blitter.c b/mesalib/src/gallium/auxiliary/util/u_blitter.c index 48808ae08..5784a7ceb 100644 --- a/mesalib/src/gallium/auxiliary/util/u_blitter.c +++ b/mesalib/src/gallium/auxiliary/util/u_blitter.c @@ -351,12 +351,12 @@ static void blitter_unset_running_flag(struct blitter_context_priv *ctx) static void blitter_check_saved_vertex_states(struct blitter_context_priv *ctx) { - assert(ctx->base.saved_num_vertex_buffers != ~0 && - ctx->base.saved_velem_state != INVALID_PTR && - ctx->base.saved_vs != INVALID_PTR && - (!ctx->has_geometry_shader || ctx->base.saved_gs != INVALID_PTR) && - (!ctx->has_stream_out || ctx->base.saved_num_so_targets != ~0) && - ctx->base.saved_rs_state != INVALID_PTR); + assert(ctx->base.saved_num_vertex_buffers != ~0); + assert(ctx->base.saved_velem_state != INVALID_PTR); + assert(ctx->base.saved_vs != INVALID_PTR); + assert(!ctx->has_geometry_shader || ctx->base.saved_gs != INVALID_PTR); + assert(!ctx->has_stream_out || ctx->base.saved_num_so_targets != ~0); + assert(ctx->base.saved_rs_state != INVALID_PTR); } static void blitter_restore_vertex_states(struct blitter_context_priv *ctx) @@ -410,9 +410,9 @@ static void blitter_restore_vertex_states(struct blitter_context_priv *ctx) static void blitter_check_saved_fragment_states(struct blitter_context_priv *ctx) { - assert(ctx->base.saved_fs != INVALID_PTR && - ctx->base.saved_dsa_state != INVALID_PTR && - ctx->base.saved_blend_state != INVALID_PTR); + assert(ctx->base.saved_fs != INVALID_PTR); + assert(ctx->base.saved_dsa_state != INVALID_PTR); + assert(ctx->base.saved_blend_state != INVALID_PTR); } static void blitter_restore_fragment_states(struct blitter_context_priv *ctx) @@ -453,8 +453,8 @@ static void blitter_restore_fb_state(struct blitter_context_priv *ctx) static void blitter_check_saved_textures(struct blitter_context_priv *ctx) { - assert(ctx->base.saved_num_sampler_states != ~0 && - ctx->base.saved_num_sampler_views != ~0); + assert(ctx->base.saved_num_sampler_states != ~0); + assert(ctx->base.saved_num_sampler_views != ~0); } static void blitter_restore_textures(struct blitter_context_priv *ctx) diff --git a/mesalib/src/gallium/auxiliary/util/u_format.h b/mesalib/src/gallium/auxiliary/util/u_format.h index 874ea7eb1..b9ae7c190 100644 --- a/mesalib/src/gallium/auxiliary/util/u_format.h +++ b/mesalib/src/gallium/auxiliary/util/u_format.h @@ -578,8 +578,9 @@ boolean util_format_is_pure_uint(enum pipe_format format); /** - * Whether the src format can be blitted to destation format with a simple - * memcpy. + * Check if the src format can be blitted to the destination format with + * a simple memcpy. For example, blitting from RGBA to RGBx is OK, but not + * the reverse. */ boolean util_is_format_compatible(const struct util_format_description *src_desc, diff --git a/mesalib/src/glsl/builtin_variables.cpp b/mesalib/src/glsl/builtin_variables.cpp index ed6b922ca..66b3abdd8 100644 --- a/mesalib/src/glsl/builtin_variables.cpp +++ b/mesalib/src/glsl/builtin_variables.cpp @@ -870,13 +870,25 @@ generate_ARB_draw_instanced_variables(exec_list *instructions, /* gl_InstanceIDARB is only available in the vertex shader. */ if (target == vertex_shader) { - ir_variable *const inst = + ir_variable *inst = add_variable(instructions, state->symbols, "gl_InstanceIDARB", glsl_type::int_type, ir_var_system_value, SYSTEM_VALUE_INSTANCE_ID); if (warn) inst->warn_extension = "GL_ARB_draw_instanced"; + + /* Originally ARB_draw_instanced only specified that ARB decorated name. + * Since no vendor actually implemented that behavior and some apps use + * the undecorated name, the extension now specifies that both names are + * available. + */ + inst = add_variable(instructions, state->symbols, + "gl_InstanceID", glsl_type::int_type, + ir_var_system_value, SYSTEM_VALUE_INSTANCE_ID); + + if (warn) + inst->warn_extension = "GL_ARB_draw_instanced"; } } diff --git a/mesalib/src/mesa/Makefile b/mesalib/src/mesa/Makefile index 0e15d61bd..71e22b9cb 100644 --- a/mesalib/src/mesa/Makefile +++ b/mesalib/src/mesa/Makefile @@ -206,8 +206,6 @@ install-headers: install-libgl: default gl.pc install-headers $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR) $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig - $(MINSTALL) $(TOP)/$(LIB_DIR)/$(GL_LIB_GLOB) \ - $(DESTDIR)$(INSTALL_LIB_DIR) $(INSTALL) -m 644 gl.pc $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig install-osmesa: default osmesa.pc diff --git a/mesalib/src/mesa/main/api_validate.c b/mesalib/src/mesa/main/api_validate.c index 1ae491f25..4e94f47e3 100644 --- a/mesalib/src/mesa/main/api_validate.c +++ b/mesalib/src/mesa/main/api_validate.c @@ -383,6 +383,12 @@ _mesa_validate_DrawArraysInstanced(struct gl_context *ctx, GLenum mode, GLint fi return GL_FALSE; } + if (first < 0) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glDrawArraysInstanced(start=%d)", first); + return GL_FALSE; + } + if (!_mesa_valid_prim_mode(ctx, mode)) { _mesa_error(ctx, GL_INVALID_ENUM, "glDrawArraysInstanced(mode=0x%x)", mode); @@ -399,12 +405,6 @@ _mesa_validate_DrawArraysInstanced(struct gl_context *ctx, GLenum mode, GLint fi if (!check_valid_to_render(ctx, "glDrawArraysInstanced(invalid to render)")) return GL_FALSE; - if (ctx->CompileFlag) { - _mesa_error(ctx, GL_INVALID_OPERATION, - "glDrawArraysInstanced(display list"); - return GL_FALSE; - } - if (ctx->Const.CheckArrayBounds) { if (first + count > (GLint) ctx->Array.ArrayObj->_MaxElement) return GL_FALSE; diff --git a/mesalib/src/mesa/main/bufferobj.c b/mesalib/src/mesa/main/bufferobj.c index b6137d0f6..ada42c515 100644 --- a/mesalib/src/mesa/main/bufferobj.c +++ b/mesalib/src/mesa/main/bufferobj.c @@ -1172,17 +1172,17 @@ _mesa_GetBufferParameterivARB(GLenum target, GLenum pname, GLint *params) *params = _mesa_bufferobj_mapped(bufObj); return; case GL_BUFFER_ACCESS_FLAGS: - if (ctx->VersionMajor < 3) + if (!ctx->Extensions.ARB_map_buffer_range) goto invalid_pname; *params = bufObj->AccessFlags; return; case GL_BUFFER_MAP_OFFSET: - if (ctx->VersionMajor < 3) + if (!ctx->Extensions.ARB_map_buffer_range) goto invalid_pname; *params = (GLint) bufObj->Offset; return; case GL_BUFFER_MAP_LENGTH: - if (ctx->VersionMajor < 3) + if (!ctx->Extensions.ARB_map_buffer_range) goto invalid_pname; *params = (GLint) bufObj->Length; return; @@ -1223,7 +1223,7 @@ _mesa_GetBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params) *params = simplified_access_mode(bufObj->AccessFlags); return; case GL_BUFFER_ACCESS_FLAGS: - if (ctx->VersionMajor < 3) + if (!ctx->Extensions.ARB_map_buffer_range) goto invalid_pname; *params = bufObj->AccessFlags; return; @@ -1231,12 +1231,12 @@ _mesa_GetBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params) *params = _mesa_bufferobj_mapped(bufObj); return; case GL_BUFFER_MAP_OFFSET: - if (ctx->VersionMajor < 3) + if (!ctx->Extensions.ARB_map_buffer_range) goto invalid_pname; *params = bufObj->Offset; return; case GL_BUFFER_MAP_LENGTH: - if (ctx->VersionMajor < 3) + if (!ctx->Extensions.ARB_map_buffer_range) goto invalid_pname; *params = bufObj->Length; return; diff --git a/mesalib/src/mesa/main/dlist.c b/mesalib/src/mesa/main/dlist.c index 677debffc..3db7bebae 100644 --- a/mesalib/src/mesa/main/dlist.c +++ b/mesalib/src/mesa/main/dlist.c @@ -1300,6 +1300,43 @@ save_BlendEquationSeparatei(GLuint buf, GLenum modeRGB, GLenum modeA) } +/* GL_ARB_draw_instanced. */ +static void GLAPIENTRY +save_DrawArraysInstancedARB(GLenum mode, + GLint first, + GLsizei count, + GLsizei primcount) +{ + GET_CURRENT_CONTEXT(ctx); + _mesa_error(ctx, GL_INVALID_OPERATION, + "glDrawArraysInstanced() during display list compile"); +} + +static void GLAPIENTRY +save_DrawElementsInstancedARB(GLenum mode, + GLsizei count, + GLenum type, + const GLvoid *indices, + GLsizei primcount) +{ + GET_CURRENT_CONTEXT(ctx); + _mesa_error(ctx, GL_INVALID_OPERATION, + "glDrawElementsInstanced() during display list compile"); +} + +static void GLAPIENTRY +save_DrawElementsInstancedBaseVertexARB(GLenum mode, + GLsizei count, + GLenum type, + const GLvoid *indices, + GLsizei primcount, + GLint basevertex) +{ + GET_CURRENT_CONTEXT(ctx); + _mesa_error(ctx, GL_INVALID_OPERATION, + "glDrawElementsInstancedBaseVertex() during display list compile"); +} + static void invalidate_saved_current_state( struct gl_context *ctx ) { GLint i; @@ -9672,8 +9709,6 @@ exec_MultiModeDrawElementsIBM(const GLenum * mode, modestride)); } - - /** * Setup the given dispatch table to point to Mesa's display list * building functions. @@ -10751,6 +10786,13 @@ _mesa_save_vtxfmt_init(GLvertexformat * vfmt) vfmt->Rectf = save_Rectf; + /* GL_ARB_draw_instanced */ + vfmt->DrawArraysInstanced = save_DrawArraysInstancedARB; + vfmt->DrawElementsInstanced = save_DrawElementsInstancedARB; + + /* GL_ARB_draw_elements_base_vertex */ + vfmt->DrawElementsInstancedBaseVertex = save_DrawElementsInstancedBaseVertexARB; + /* The driver is required to implement these as * 1) They can probably do a better job. * 2) A lot of new mechanisms would have to be added to this module diff --git a/mesalib/src/mesa/main/enable.c b/mesalib/src/mesa/main/enable.c index 270b24045..515dda952 100644 --- a/mesalib/src/mesa/main/enable.c +++ b/mesalib/src/mesa/main/enable.c @@ -118,7 +118,7 @@ client_state(struct gl_context *ctx, GLenum cap, GLboolean state) CHECK_EXTENSION(NV_vertex_program, cap); { GLint n = (GLint) cap - GL_VERTEX_ATTRIB_ARRAY0_NV; - ASSERT(VERT_ATTRIB_GENERIC(n) < Elements(ctx->Array.ArrayObj->VertexAttrib)); + ASSERT(VERT_ATTRIB_GENERIC(n) < Elements(arrayObj->VertexAttrib)); var = &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(n)].Enabled; flag = VERT_BIT_GENERIC(n); } @@ -149,9 +149,9 @@ client_state(struct gl_context *ctx, GLenum cap, GLboolean state) *var = state; if (state) - ctx->Array.ArrayObj->_Enabled |= flag; + arrayObj->_Enabled |= flag; else - ctx->Array.ArrayObj->_Enabled &= ~flag; + arrayObj->_Enabled &= ~flag; if (ctx->Driver.Enable) { ctx->Driver.Enable( ctx, cap, state ); diff --git a/mesalib/src/mesa/main/light.c b/mesalib/src/mesa/main/light.c index a16d0e998..962a3e689 100644 --- a/mesalib/src/mesa/main/light.c +++ b/mesalib/src/mesa/main/light.c @@ -161,11 +161,9 @@ _mesa_light(struct gl_context *ctx, GLuint lnum, GLenum pname, const GLfloat *pa return; FLUSH_VERTICES(ctx, _NEW_LIGHT); light->SpotCutoff = params[0]; - light->_CosCutoffNeg = (GLfloat) (cos(light->SpotCutoff * DEG2RAD)); - if (light->_CosCutoffNeg < 0) + light->_CosCutoff = (GLfloat) (cos(light->SpotCutoff * DEG2RAD)); + if (light->_CosCutoff < 0) light->_CosCutoff = 0; - else - light->_CosCutoff = light->_CosCutoffNeg; if (light->SpotCutoff != 180.0F) light->_Flags |= LIGHT_SPOT; else @@ -623,11 +621,6 @@ _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 @@ -699,14 +692,6 @@ _mesa_update_material( struct gl_context *ctx, GLuint bitmask ) mat[MAT_ATTRIB_BACK_SPECULAR]); } } - - if (bitmask & MAT_BIT_FRONT_SHININESS) { - invalidate_shine_table( ctx, 0 ); - } - - if (bitmask & MAT_BIT_BACK_SHININESS) { - invalidate_shine_table( ctx, 1 ); - } } @@ -876,126 +861,6 @@ _mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params ) -/**********************************************************************/ -/***** Lighting computation *****/ -/**********************************************************************/ - - -/* - * Notes: - * When two-sided lighting is enabled we compute the color (or index) - * for both the front and back side of the primitive. Then, when the - * orientation of the facet is later learned, we can determine which - * color (or index) to use for rendering. - * - * KW: We now know orientation in advance and only shade for - * the side or sides which are actually required. - * - * Variables: - * n = normal vector - * V = vertex position - * P = light source position - * Pe = (0,0,0,1) - * - * Precomputed: - * IF P[3]==0 THEN - * // light at infinity - * IF local_viewer THEN - * _VP_inf_norm = unit vector from V to P // Precompute - * ELSE - * // eye at infinity - * _h_inf_norm = Normalize( VP + <0,0,1> ) // Precompute - * ENDIF - * ENDIF - * - * Functions: - * Normalize( v ) = normalized vector v - * Magnitude( v ) = length of vector v - */ - - - -/* 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. - */ -static void -invalidate_shine_table( struct gl_context *ctx, GLuint side ) -{ - ASSERT(side < 2); - if (ctx->_ShineTable[side]) - ctx->_ShineTable[side]->refcount--; - ctx->_ShineTable[side] = NULL; -} - - -static void -validate_shine_table( struct gl_context *ctx, GLuint side, GLfloat shininess ) -{ - struct gl_shine_tab *list = ctx->_ShineTabList; - struct gl_shine_tab *s; - - ASSERT(side < 2); - - foreach(s, list) - if ( s->shininess == shininess ) - break; - - if (s == list) { - GLint j; - GLfloat *m; - - foreach(s, list) - if (s->refcount == 0) - break; - - m = s->tab; - m[0] = 0.0; - if (shininess == 0.0) { - for (j = 1 ; j <= SHINE_TABLE_SIZE ; j++) - m[j] = 1.0; - } - else { - for (j = 1 ; j < SHINE_TABLE_SIZE ; j++) { - GLdouble t, x = j / (GLfloat) (SHINE_TABLE_SIZE - 1); - if (x < 0.005) /* underflow check */ - x = 0.005; - t = pow(x, shininess); - if (t > 1e-20) - m[j] = (GLfloat) t; - else - m[j] = 0.0; - } - m[SHINE_TABLE_SIZE] = 1.0; - } - - s->shininess = shininess; - } - - if (ctx->_ShineTable[side]) - ctx->_ShineTable[side]->refcount--; - - ctx->_ShineTable[side] = s; - move_to_tail( list, s ); - s->refcount++; -} - - -void -_mesa_validate_all_lighting_tables( struct gl_context *ctx ) -{ - GLfloat shininess; - - shininess = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_SHININESS][0]; - if (!ctx->_ShineTable[0] || ctx->_ShineTable[0]->shininess != shininess) - validate_shine_table( ctx, 0, shininess ); - - 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 ); -} - - /** * Examine current lighting parameters to determine if the optimized lighting * function can be used. @@ -1005,23 +870,23 @@ _mesa_validate_all_lighting_tables( struct gl_context *ctx ) void _mesa_update_lighting( struct gl_context *ctx ) { + GLbitfield flags = 0; struct gl_light *light; ctx->Light._NeedEyeCoords = GL_FALSE; - ctx->Light._Flags = 0; if (!ctx->Light.Enabled) return; foreach(light, &ctx->Light.EnabledList) { - ctx->Light._Flags |= light->_Flags; + flags |= light->_Flags; } ctx->Light._NeedVertices = - ((ctx->Light._Flags & (LIGHT_POSITIONAL|LIGHT_SPOT)) || + ((flags & (LIGHT_POSITIONAL|LIGHT_SPOT)) || ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR || ctx->Light.Model.LocalViewer); - ctx->Light._NeedEyeCoords = ((ctx->Light._Flags & LIGHT_POSITIONAL) || + ctx->Light._NeedEyeCoords = ((flags & LIGHT_POSITIONAL) || ctx->Light.Model.LocalViewer); /* XXX: This test is overkill & needs to be fixed both for software and @@ -1081,9 +946,6 @@ compute_light_positions( struct gl_context *ctx ) TRANSFORM_NORMAL( ctx->_EyeZDir, eye_z, ctx->ModelviewMatrixStack.Top->m ); } - /* Make sure all the light tables are updated before the computation */ - _mesa_validate_all_lighting_tables(ctx); - foreach (light, &ctx->Light.EnabledList) { if (ctx->_NeedEyeCoords) { @@ -1260,7 +1122,6 @@ init_light( struct gl_light *l, GLuint n ) ASSIGN_3V( l->SpotDirection, 0.0, 0.0, -1.0 ); l->SpotExponent = 0.0; l->SpotCutoff = 180.0; - l->_CosCutoffNeg = -1.0f; l->_CosCutoff = 0.0; /* KW: -ve values not admitted */ l->ConstantAttenuation = 1.0; l->LinearAttenuation = 0.0; @@ -1337,17 +1198,6 @@ _mesa_init_lighting( struct gl_context *ctx ) ctx->Light.ColorMaterialEnabled = GL_FALSE; ctx->Light.ClampVertexColor = GL_TRUE; - /* Lighting miscellaneous */ - ctx->_ShineTabList = MALLOC_STRUCT( gl_shine_tab ); - make_empty_list( ctx->_ShineTabList ); - /* Allocate 10 (arbitrary) shininess lookup tables */ - for (i = 0 ; i < 10 ; i++) { - struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab ); - s->shininess = -1; - s->refcount = 0; - insert_at_tail( ctx->_ShineTabList, s ); - } - /* Miscellaneous */ ctx->Light._NeedEyeCoords = GL_FALSE; ctx->_NeedEyeCoords = GL_FALSE; @@ -1362,11 +1212,4 @@ _mesa_init_lighting( struct gl_context *ctx ) void _mesa_free_lighting_data( struct gl_context *ctx ) { - struct gl_shine_tab *s, *tmps; - - /* Free lighting shininess exponentiation table */ - foreach_s( s, tmps, ctx->_ShineTabList ) { - free( s ); - } - free( ctx->_ShineTabList ); } diff --git a/mesalib/src/mesa/main/light.h b/mesalib/src/mesa/main/light.h index 996698793..c751d6d6b 100644 --- a/mesalib/src/mesa/main/light.h +++ b/mesalib/src/mesa/main/light.h @@ -87,33 +87,11 @@ extern void _mesa_light(struct gl_context *ctx, GLuint lnum, GLenum pname, const GLfloat *params); -/* - * 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). - */ -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, GLenum face, GLenum pname, GLuint legal, const char * ); -extern void _mesa_validate_all_lighting_tables( struct gl_context *ctx ); - extern void _mesa_update_lighting( struct gl_context *ctx ); extern void _mesa_update_tnl_spaces( struct gl_context *ctx, GLuint new_state ); @@ -132,7 +110,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_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 9200f3fc4..480b1cf28 100644 --- a/mesalib/src/mesa/main/mtypes.h +++ b/mesalib/src/mesa/main/mtypes.h @@ -77,6 +77,8 @@ struct gl_texture_object; struct gl_context; struct st_context; struct gl_uniform_storage; +struct prog_instruction; +struct gl_program_parameter_list; /*@}*/ @@ -86,19 +88,6 @@ struct gl_uniform_storage; #define PRIM_UNKNOWN (GL_POLYGON+3) -/** - * Shader stages. Note that these will become 5 with tessellation. - * These MUST have the same values as gallium's PIPE_SHADER_* - */ -typedef enum -{ - MESA_SHADER_VERTEX = 0, - MESA_SHADER_FRAGMENT = 1, - MESA_SHADER_GEOMETRY = 2, - MESA_SHADER_TYPES = 3 -} gl_shader_type; - - /** * Indexes for vertex program attributes. @@ -640,21 +629,6 @@ struct gl_config /*@}*/ -#define EXP_TABLE_SIZE 512 /**< Specular exponent lookup table sizes */ -#define SHINE_TABLE_SIZE 256 /**< Material shininess lookup table sizes */ - -/** - * Material shininess lookup table. - */ -struct gl_shine_tab -{ - struct gl_shine_tab *next, *prev; - GLfloat tab[SHINE_TABLE_SIZE+1]; - GLfloat shininess; - GLuint refcount; -}; - - /** * Light source state. */ @@ -670,7 +644,6 @@ struct gl_light GLfloat SpotDirection[4]; /**< spotlight direction in eye coordinates */ GLfloat SpotExponent; GLfloat SpotCutoff; /**< in degrees */ - GLfloat _CosCutoffNeg; /**< = cos(SpotCutoff) */ GLfloat _CosCutoff; /**< = MAX(0, cos(SpotCutoff)) */ GLfloat ConstantAttenuation; GLfloat LinearAttenuation; @@ -916,23 +889,6 @@ struct gl_fog_attrib }; -/** - * \brief Layout qualifiers for gl_FragDepth. - * - * Extension AMD_conservative_depth allows gl_FragDepth to be redeclared with - * a layout qualifier. - * - * \see enum ir_depth_layout - */ -enum gl_frag_depth_layout { - FRAG_DEPTH_LAYOUT_NONE, /**< No layout is specified. */ - FRAG_DEPTH_LAYOUT_ANY, - FRAG_DEPTH_LAYOUT_GREATER, - FRAG_DEPTH_LAYOUT_LESS, - FRAG_DEPTH_LAYOUT_UNCHANGED -}; - - /** * Hint attribute group (GL_HINT_BIT). * @@ -995,7 +951,6 @@ struct gl_light_attrib /*@{*/ GLboolean _NeedEyeCoords; GLboolean _NeedVertices; /**< Use fast shader? */ - GLbitfield _Flags; /**< LIGHT_* flags, see above */ GLfloat _BaseColor[2][3]; /*@}*/ }; @@ -1773,6 +1728,107 @@ struct gl_evaluators }; +struct gl_transform_feedback_varying_info +{ + char *Name; + GLenum Type; + GLint Size; +}; + + +/** + * Per-output info vertex shaders for transform feedback. + */ +struct gl_transform_feedback_output +{ + unsigned OutputRegister; + unsigned OutputBuffer; + unsigned NumComponents; + + /** offset (in DWORDs) of this output within the interleaved structure */ + unsigned DstOffset; + + /** + * Offset into the output register of the data to output. For example, + * if NumComponents is 2 and ComponentOffset is 1, then the data to + * offset is in the y and z components of the output register. + */ + unsigned ComponentOffset; +}; + + +/** Post-link transform feedback info. */ +struct gl_transform_feedback_info +{ + unsigned NumOutputs; + + /** + * Number of transform feedback buffers in use by this program. + */ + unsigned NumBuffers; + + struct gl_transform_feedback_output *Outputs; + + /** Transform feedback varyings used for the linking of this shader program. + * + * Use for glGetTransformFeedbackVarying(). + */ + struct gl_transform_feedback_varying_info *Varyings; + GLint NumVarying; + + /** + * Total number of components stored in each buffer. This may be used by + * hardware back-ends to determine the correct stride when interleaving + * multiple transform feedback outputs in the same buffer. + */ + unsigned BufferStride[MAX_FEEDBACK_ATTRIBS]; +}; + + +/** + * Transform feedback object state + */ +struct gl_transform_feedback_object +{ + GLuint Name; /**< AKA the object ID */ + GLint RefCount; + GLboolean Active; /**< Is transform feedback enabled? */ + GLboolean Paused; /**< Is transform feedback paused? */ + GLboolean EndedAnytime; /**< Has EndTransformFeedback been called + at least once? */ + + /** The feedback buffers */ + GLuint BufferNames[MAX_FEEDBACK_ATTRIBS]; + struct gl_buffer_object *Buffers[MAX_FEEDBACK_ATTRIBS]; + + /** Start of feedback data in dest buffer */ + GLintptr Offset[MAX_FEEDBACK_ATTRIBS]; + /** Max data to put into dest buffer (in bytes) */ + GLsizeiptr Size[MAX_FEEDBACK_ATTRIBS]; +}; + + +/** + * Context state for transform feedback. + */ +struct gl_transform_feedback_state +{ + GLenum Mode; /**< GL_POINTS, GL_LINES or GL_TRIANGLES */ + + /** The general binding point (GL_TRANSFORM_FEEDBACK_BUFFER) */ + struct gl_buffer_object *CurrentBuffer; + + /** The table of all transform feedback objects */ + struct _mesa_HashTable *Objects; + + /** The current xform-fb object (GL_TRANSFORM_FEEDBACK_BINDING) */ + struct gl_transform_feedback_object *CurrentObject; + + /** The default xform-fb object (Name==0) */ + struct gl_transform_feedback_object *DefaultObject; +}; + + /** * Names of the various vertex/fragment program register files, etc. * @@ -1834,58 +1890,23 @@ enum glsl_interp_qualifier }; -/** Vertex and fragment instructions */ -struct prog_instruction; -struct gl_program_parameter_list; -struct gl_uniform_list; - -struct gl_transform_feedback_varying_info { - char *Name; - GLenum Type; - GLint Size; -}; - -struct gl_transform_feedback_output { - unsigned OutputRegister; - unsigned OutputBuffer; - unsigned NumComponents; - - /** offset (in DWORDs) of this output within the interleaved structure */ - unsigned DstOffset; - - /** - * Offset into the output register of the data to output. For example, - * if NumComponents is 2 and ComponentOffset is 1, then the data to - * offset is in the y and z components of the output register. - */ - unsigned ComponentOffset; +/** + * \brief Layout qualifiers for gl_FragDepth. + * + * Extension AMD_conservative_depth allows gl_FragDepth to be redeclared with + * a layout qualifier. + * + * \see enum ir_depth_layout + */ +enum gl_frag_depth_layout +{ + FRAG_DEPTH_LAYOUT_NONE, /**< No layout is specified. */ + FRAG_DEPTH_LAYOUT_ANY, + FRAG_DEPTH_LAYOUT_GREATER, + FRAG_DEPTH_LAYOUT_LESS, + FRAG_DEPTH_LAYOUT_UNCHANGED }; -/** Post-link transform feedback info. */ -struct gl_transform_feedback_info { - unsigned NumOutputs; - - /** - * Number of transform feedback buffers in use by this program. - */ - unsigned NumBuffers; - - struct gl_transform_feedback_output *Outputs; - - /** Transform feedback varyings used for the linking of this shader program. - * - * Use for glGetTransformFeedbackVarying(). - */ - struct gl_transform_feedback_varying_info *Varyings; - GLint NumVarying; - - /** - * Total number of components stored in each buffer. This may be used by - * hardware back-ends to determine the correct stride when interleaving - * multiple transform feedback outputs in the same buffer. - */ - unsigned BufferStride[MAX_FEEDBACK_ATTRIBS]; -}; /** * Base class for any kind of program object @@ -2128,57 +2149,6 @@ struct gl_ati_fragment_shader_state }; -/** - * Occlusion/timer query object. - */ -struct gl_query_object -{ - GLenum Target; /**< The query target, when active */ - GLuint Id; /**< hash table ID/name */ - GLuint64EXT Result; /**< the counter */ - GLboolean Active; /**< inside Begin/EndQuery */ - GLboolean Ready; /**< result is ready? */ -}; - - -/** - * Context state for query objects. - */ -struct gl_query_state -{ - struct _mesa_HashTable *QueryObjects; - struct gl_query_object *CurrentOcclusionObject; /* GL_ARB_occlusion_query */ - struct gl_query_object *CurrentTimerObject; /* GL_EXT_timer_query */ - - /** GL_NV_conditional_render */ - struct gl_query_object *CondRenderQuery; - - /** GL_EXT_transform_feedback */ - struct gl_query_object *PrimitivesGenerated; - struct gl_query_object *PrimitivesWritten; - - /** GL_ARB_timer_query */ - struct gl_query_object *TimeElapsed; - - GLenum CondRenderMode; -}; - - -/** Sync object state */ -struct gl_sync_object { - struct simple_node link; - GLenum Type; /**< GL_SYNC_FENCE */ - GLuint Name; /**< Fence name */ - GLint RefCount; /**< Reference count */ - GLboolean DeletePending; /**< Object was deleted while there were still - * live references (e.g., sync not yet finished) - */ - GLenum SyncCondition; - GLbitfield Flags; /**< Flags passed to glFenceSync */ - GLuint StatusFlag:1; /**< Has the sync object been signaled? */ -}; - - /** Set by #pragma directives */ struct gl_sl_pragmas { @@ -2235,6 +2205,19 @@ struct gl_shader /** + * Shader stages. Note that these will become 5 with tessellation. + * These MUST have the same values as gallium's PIPE_SHADER_* + */ +typedef enum +{ + MESA_SHADER_VERTEX = 0, + MESA_SHADER_FRAGMENT = 1, + MESA_SHADER_GEOMETRY = 2, + MESA_SHADER_TYPES = 3 +} gl_shader_type; + + +/** * A GLSL program object. * Basically a linked collection of vertex and fragment shaders. */ @@ -2392,6 +2375,7 @@ struct gl_shader_state GLbitfield Flags; /**< Mask of GLSL_x flags */ }; + /** * Compiler options for a single GLSL shaders type */ @@ -2424,50 +2408,58 @@ struct gl_shader_compiler_options struct gl_sl_pragmas DefaultPragmas; /**< Default #pragma settings */ }; + /** - * Transform feedback object state + * Occlusion/timer query object. */ -struct gl_transform_feedback_object +struct gl_query_object { - GLuint Name; /**< AKA the object ID */ - GLint RefCount; - GLboolean Active; /**< Is transform feedback enabled? */ - GLboolean Paused; /**< Is transform feedback paused? */ - GLboolean EndedAnytime; /**< Has EndTransformFeedback been called - at least once? */ - - /** The feedback buffers */ - GLuint BufferNames[MAX_FEEDBACK_ATTRIBS]; - struct gl_buffer_object *Buffers[MAX_FEEDBACK_ATTRIBS]; - - /** Start of feedback data in dest buffer */ - GLintptr Offset[MAX_FEEDBACK_ATTRIBS]; - /** Max data to put into dest buffer (in bytes) */ - GLsizeiptr Size[MAX_FEEDBACK_ATTRIBS]; + GLenum Target; /**< The query target, when active */ + GLuint Id; /**< hash table ID/name */ + GLuint64EXT Result; /**< the counter */ + GLboolean Active; /**< inside Begin/EndQuery */ + GLboolean Ready; /**< result is ready? */ }; /** - * Context state for transform feedback. + * Context state for query objects. */ -struct gl_transform_feedback +struct gl_query_state { - GLenum Mode; /**< GL_POINTS, GL_LINES or GL_TRIANGLES */ + struct _mesa_HashTable *QueryObjects; + struct gl_query_object *CurrentOcclusionObject; /* GL_ARB_occlusion_query */ + struct gl_query_object *CurrentTimerObject; /* GL_EXT_timer_query */ - /** The general binding point (GL_TRANSFORM_FEEDBACK_BUFFER) */ - struct gl_buffer_object *CurrentBuffer; + /** GL_NV_conditional_render */ + struct gl_query_object *CondRenderQuery; - /** The table of all transform feedback objects */ - struct _mesa_HashTable *Objects; + /** GL_EXT_transform_feedback */ + struct gl_query_object *PrimitivesGenerated; + struct gl_query_object *PrimitivesWritten; - /** The current xform-fb object (GL_TRANSFORM_FEEDBACK_BINDING) */ - struct gl_transform_feedback_object *CurrentObject; + /** GL_ARB_timer_query */ + struct gl_query_object *TimeElapsed; - /** The default xform-fb object (Name==0) */ - struct gl_transform_feedback_object *DefaultObject; + GLenum CondRenderMode; }; +/** Sync object state */ +struct gl_sync_object +{ + struct simple_node link; + GLenum Type; /**< GL_SYNC_FENCE */ + GLuint Name; /**< Fence name */ + GLint RefCount; /**< Reference count */ + GLboolean DeletePending; /**< Object was deleted while there were still + * live references (e.g., sync not yet finished) + */ + GLenum SyncCondition; + GLbitfield Flags; /**< Flags passed to glFenceSync */ + GLuint StatusFlag:1; /**< Has the sync object been signaled? */ +}; + /** * State which can be shared by multiple contexts: @@ -3337,7 +3329,7 @@ struct gl_context struct gl_query_state Query; /**< occlusion, timer queries */ - struct gl_transform_feedback TransformFeedback; + struct gl_transform_feedback_state TransformFeedback; struct gl_buffer_object *CopyReadBuffer; /**< GL_ARB_copy_buffer */ struct gl_buffer_object *CopyWriteBuffer; /**< GL_ARB_copy_buffer */ @@ -3380,10 +3372,6 @@ struct gl_context GLuint TextureStateTimestamp; /**< detect changes to shared state */ - struct gl_shine_tab *_ShineTable[2]; /**< Active shine tables */ - struct gl_shine_tab *_ShineTabList; /**< MRU list of inactive shine tables */ - /**@}*/ - struct gl_list_extensions *ListExt; /**< driver dlist extensions */ /** \name For debugging/development only */ diff --git a/mesalib/src/mesa/main/teximage.c b/mesalib/src/mesa/main/teximage.c index 5328ae296..4fb81e62d 100644 --- a/mesalib/src/mesa/main/teximage.c +++ b/mesalib/src/mesa/main/teximage.c @@ -1844,23 +1844,25 @@ subtexture_error_check2( struct gl_context *ctx, GLuint dimensions, return GL_TRUE; } if (dimensions > 1) { - if (yoffset < -((GLint)destTex->Border)) { + GLint yBorder = (target == GL_TEXTURE_1D_ARRAY) ? 0 : destTex->Border; + if (yoffset < -yBorder) { _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset)", dimensions); return GL_TRUE; } - if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) { + if (yoffset + height > (GLint) destTex->Height + yBorder) { _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset+height)", dimensions); return GL_TRUE; } } if (dimensions > 2) { - if (zoffset < -((GLint)destTex->Border)) { + GLint zBorder = (target == GL_TEXTURE_2D_ARRAY) ? 0 : destTex->Border; + if (zoffset < -zBorder) { _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)"); return GL_TRUE; } - if (zoffset + depth > (GLint) (destTex->Depth + destTex->Border)) { + if (zoffset + depth > (GLint) destTex->Depth + zBorder) { _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)"); return GL_TRUE; } @@ -2163,13 +2165,14 @@ copytexsubimage_error_check2( struct gl_context *ctx, GLuint dimensions, return GL_TRUE; } if (dimensions > 1) { - if (yoffset < -((GLint)teximage->Border)) { + GLint yBorder = (target == GL_TEXTURE_1D_ARRAY) ? 0 : teximage->Border; + if (yoffset < -yBorder) { _mesa_error(ctx, GL_INVALID_VALUE, "glCopyTexSubImage%dD(yoffset=%d)", dimensions, yoffset); return GL_TRUE; } /* NOTE: we're adding the border here, not subtracting! */ - if (yoffset + height > (GLint) (teximage->Height + teximage->Border)) { + if (yoffset + height > (GLint) teximage->Height + yBorder) { _mesa_error(ctx, GL_INVALID_VALUE, "glCopyTexSubImage%dD(yoffset+height)", dimensions); return GL_TRUE; @@ -2178,12 +2181,13 @@ copytexsubimage_error_check2( struct gl_context *ctx, GLuint dimensions, /* check z offset */ if (dimensions > 2) { - if (zoffset < -((GLint)teximage->Border)) { + GLint zBorder = (target == GL_TEXTURE_2D_ARRAY) ? 0 : teximage->Border; + if (zoffset < -zBorder) { _mesa_error(ctx, GL_INVALID_VALUE, "glCopyTexSubImage%dD(zoffset)", dimensions); return GL_TRUE; } - if (zoffset > (GLint) (teximage->Depth + teximage->Border)) { + if (zoffset > (GLint) teximage->Depth + zBorder) { _mesa_error(ctx, GL_INVALID_VALUE, "glCopyTexSubImage%dD(zoffset+depth)", dimensions); return GL_TRUE; @@ -2759,10 +2763,12 @@ texsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, /* If we have a border, offset=-1 is legal. Bias by border width. */ switch (dims) { case 3: - zoffset += texImage->Border; + if (target != GL_TEXTURE_2D_ARRAY) + zoffset += texImage->Border; /* fall-through */ case 2: - yoffset += texImage->Border; + if (target != GL_TEXTURE_1D_ARRAY) + yoffset += texImage->Border; /* fall-through */ case 1: xoffset += texImage->Border; @@ -3034,10 +3040,12 @@ copytexsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, /* If we have a border, offset=-1 is legal. Bias by border width. */ switch (dims) { case 3: - zoffset += texImage->Border; + if (target != GL_TEXTURE_2D_ARRAY) + zoffset += texImage->Border; /* fall-through */ case 2: - yoffset += texImage->Border; + if (target != GL_TEXTURE_1D_ARRAY) + yoffset += texImage->Border; /* fall-through */ case 1: xoffset += texImage->Border; diff --git a/mesalib/src/mesa/main/varray.c b/mesalib/src/mesa/main/varray.c index 39d3a27e0..a402c7b22 100644 --- a/mesalib/src/mesa/main/varray.c +++ b/mesalib/src/mesa/main/varray.c @@ -1117,8 +1117,9 @@ _mesa_PrimitiveRestartIndex(GLuint index) void GLAPIENTRY _mesa_VertexAttribDivisor(GLuint index, GLuint divisor) { + struct gl_client_array *array; GET_CURRENT_CONTEXT(ctx); - ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); + ASSERT_OUTSIDE_BEGIN_END(ctx); if (!ctx->Extensions.ARB_instanced_arrays) { _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()"); @@ -1133,7 +1134,12 @@ _mesa_VertexAttribDivisor(GLuint index, GLuint divisor) ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->VertexAttrib)); - ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].InstanceDivisor = divisor; + array = &ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)]; + if (array->InstanceDivisor != divisor) { + FLUSH_VERTICES(ctx, _NEW_ARRAY); + array->InstanceDivisor = divisor; + ctx->Array.NewState |= VERT_BIT(VERT_ATTRIB_GENERIC(index)); + } } diff --git a/mesalib/src/mesa/main/vtxfmt.c b/mesalib/src/mesa/main/vtxfmt.c index f3cca937d..6fb016b9e 100644 --- a/mesalib/src/mesa/main/vtxfmt.c +++ b/mesalib/src/mesa/main/vtxfmt.c @@ -41,7 +41,7 @@ #if FEATURE_beginend /** - * Use the per-vertex functions found in <vfmt> to initialoze the given + * Use the per-vertex functions found in <vfmt> to initialize the given * API dispatch table. */ static void diff --git a/mesalib/src/mesa/state_tracker/st_draw.c b/mesalib/src/mesa/state_tracker/st_draw.c index c4b2caccd..eb187519f 100644 --- a/mesalib/src/mesa/state_tracker/st_draw.c +++ b/mesalib/src/mesa/state_tracker/st_draw.c @@ -905,7 +905,6 @@ st_validate_varrays(struct gl_context *ctx, unsigned num_vbuffers, num_velements; GLuint attr; unsigned i; - unsigned old_num_user_attribs; /* must get these after state validation! */ vp = st->vp; @@ -914,7 +913,9 @@ st_validate_varrays(struct gl_context *ctx, memset(velements, 0, sizeof(struct pipe_vertex_element) * vpv->num_inputs); /* Unreference any user vertex buffers. */ - old_num_user_attribs = st->num_user_attribs; + for (i = 0; i < st->num_user_attribs; i++) { + pipe_resource_reference(&st->user_attrib[i].buffer, NULL); + } st->num_user_attribs = 0; /* @@ -953,10 +954,6 @@ st_validate_varrays(struct gl_context *ctx, assert(!vbuffer[attr].buffer); } - for (i = old_num_user_attribs; i < st->num_user_attribs; i++) { - pipe_resource_reference(&st->user_attrib[i].buffer, NULL); - } - return GL_TRUE; } @@ -1016,9 +1013,6 @@ st_draw_vbo(struct gl_context *ctx, if (st->dirty.st) { GLboolean vertDataEdgeFlags; - /* sanity check for pointer arithmetic below */ - assert(sizeof(arrays[0]->Ptr[0]) == 1); - vertDataEdgeFlags = arrays[VERT_ATTRIB_EDGEFLAG]->BufferObj && arrays[VERT_ATTRIB_EDGEFLAG]->BufferObj->Name; if (vertDataEdgeFlags != st->vertdata_edgeflags) { diff --git a/mesalib/src/mesa/tnl/t_context.c b/mesalib/src/mesa/tnl/t_context.c index 1ded44ccf..dbda7a5fc 100644 --- a/mesalib/src/mesa/tnl/t_context.c +++ b/mesalib/src/mesa/tnl/t_context.c @@ -46,6 +46,7 @@ GLboolean _tnl_CreateContext( struct gl_context *ctx ) { TNLcontext *tnl; + GLuint i; /* Create the TNLcontext structure */ @@ -76,10 +77,21 @@ _tnl_CreateContext( struct gl_context *ctx ) */ tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts; tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts; - tnl->Driver.NotifyMaterialChange = _mesa_validate_all_lighting_tables; + tnl->Driver.NotifyMaterialChange = _tnl_validate_shine_tables; tnl->nr_blocks = 0; + /* Lighting miscellaneous */ + tnl->_ShineTabList = MALLOC_STRUCT( tnl_shine_tab ); + make_empty_list( tnl->_ShineTabList ); + /* Allocate 10 (arbitrary) shininess lookup tables */ + for (i = 0 ; i < 10 ; i++) { + struct tnl_shine_tab *s = MALLOC_STRUCT( tnl_shine_tab ); + s->shininess = -1; + s->refcount = 0; + insert_at_tail( tnl->_ShineTabList, s ); + } + /* plug in the VBO drawing function */ vbo_set_draw_func(ctx, _tnl_vbo_draw_prims); @@ -93,8 +105,15 @@ _tnl_CreateContext( struct gl_context *ctx ) void _tnl_DestroyContext( struct gl_context *ctx ) { + struct tnl_shine_tab *s, *tmps; TNLcontext *tnl = TNL_CONTEXT(ctx); + /* Free lighting shininess exponentiation table */ + foreach_s( s, tmps, tnl->_ShineTabList ) { + free( s ); + } + free( tnl->_ShineTabList ); + _tnl_destroy_pipeline( ctx ); FREE(tnl); @@ -151,8 +170,7 @@ _tnl_InvalidateState( struct gl_context *ctx, GLuint new_state ) if (ctx->RenderMode == GL_FEEDBACK) tnl->render_inputs_bitset |= BITFIELD64_BIT(_TNL_ATTRIB_TEX0); - if (ctx->Point._Attenuated || - (ctx->VertexProgram._Enabled && ctx->VertexProgram.PointSizeEnabled)) + if (ctx->Point._Attenuated || ctx->VertexProgram.PointSizeEnabled) tnl->render_inputs_bitset |= BITFIELD64_BIT(_TNL_ATTRIB_POINTSIZE); /* check for varying vars which are written by the vertex program */ diff --git a/mesalib/src/mesa/tnl/t_context.h b/mesalib/src/mesa/tnl/t_context.h index c5a902082..8f18ddeb1 100644 --- a/mesalib/src/mesa/tnl/t_context.h +++ b/mesalib/src/mesa/tnl/t_context.h @@ -384,6 +384,20 @@ struct tnl_clipspace }; +#define SHINE_TABLE_SIZE 256 /**< Material shininess lookup table sizes */ + +/** + * Material shininess lookup table. + */ +struct tnl_shine_tab +{ + struct tnl_shine_tab *next, *prev; + GLfloat tab[SHINE_TABLE_SIZE+1]; + GLfloat shininess; + GLuint refcount; +}; + + struct tnl_device_driver { /*** @@ -518,6 +532,10 @@ typedef struct GLuint nr_blocks; GLuint CurInstance; + + struct tnl_shine_tab *_ShineTable[2]; /**< Active shine tables */ + struct tnl_shine_tab *_ShineTabList; /**< MRU list of inactive shine tables */ + /**@}*/ } TNLcontext; diff --git a/mesalib/src/mesa/tnl/t_rasterpos.c b/mesalib/src/mesa/tnl/t_rasterpos.c index 17611cd21..50b5fcb4c 100644 --- a/mesalib/src/mesa/tnl/t_rasterpos.c +++ b/mesalib/src/mesa/tnl/t_rasterpos.c @@ -123,8 +123,6 @@ shade_rastpos(struct gl_context *ctx, const struct gl_light *light; GLfloat diffuseColor[4], specularColor[4]; /* for RGB mode only */ - _mesa_validate_all_lighting_tables( ctx ); - COPY_3V(diffuseColor, base[0]); diffuseColor[3] = CLAMP( ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3], 0.0F, 1.0F ); @@ -214,7 +212,11 @@ shade_rastpos(struct gl_context *ctx, n_dot_h = DOT3(normal, h); if (n_dot_h > 0.0F) { - GLfloat spec_coef = _mesa_lookup_shininess(ctx, 0, n_dot_h); + GLfloat shine; + GLfloat spec_coef; + + shine = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_SHININESS][0]; + spec_coef = powf(n_dot_h, shine); if (spec_coef > 1.0e-10) { if (ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR) { diff --git a/mesalib/src/mesa/tnl/t_vb_light.c b/mesalib/src/mesa/tnl/t_vb_light.c index 0760e6630..39467fac7 100644 --- a/mesalib/src/mesa/tnl/t_vb_light.c +++ b/mesalib/src/mesa/tnl/t_vb_light.c @@ -1,343 +1,473 @@ -/*
- * Mesa 3-D graphics library
- * Version: 6.5
- *
- * Copyright (C) 1999-2006 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.
- */
-
-
-
-#include "main/glheader.h"
-#include "main/colormac.h"
-#include "main/light.h"
-#include "main/macros.h"
-#include "main/imports.h"
-#include "main/simple_list.h"
-#include "main/mtypes.h"
-
-#include "math/m_translate.h"
-
-#include "t_context.h"
-#include "t_pipeline.h"
-
-#define LIGHT_TWOSIDE 0x1
-#define LIGHT_MATERIAL 0x2
-#define MAX_LIGHT_FUNC 0x4
-
-typedef void (*light_func)( struct gl_context *ctx,
- struct vertex_buffer *VB,
- struct tnl_pipeline_stage *stage,
- GLvector4f *input );
-
-/**
- * Information for updating current material attributes from vertex color,
- * for GL_COLOR_MATERIAL.
- */
-struct material_cursor {
- const GLfloat *ptr; /* points to src vertex color (in VB array) */
- GLuint stride; /* stride to next vertex color (bytes) */
- GLfloat *current; /* points to material attribute to update */
- GLuint size; /* vertex/color size: 1, 2, 3 or 4 */
-};
-
-/**
- * Data private to this pipeline stage.
- */
-struct light_stage_data {
- GLvector4f Input;
- GLvector4f LitColor[2];
- GLvector4f LitSecondary[2];
- light_func *light_func_tab;
-
- struct material_cursor mat[MAT_ATTRIB_MAX];
- GLuint mat_count;
- GLuint mat_bitmask;
-};
-
-
-#define LIGHT_STAGE_DATA(stage) ((struct light_stage_data *)(stage->privatePtr))
-
-
-
-/**
- * In the case of colormaterial, the effected material attributes
- * should already have been bound to point to the incoming color data,
- * prior to running the pipeline.
- * This function copies the vertex's color to the material attributes
- * which are tracking glColor.
- * It's called per-vertex in the lighting loop.
- */
-static void
-update_materials(struct gl_context *ctx, struct light_stage_data *store)
-{
- GLuint i;
-
- for (i = 0 ; i < store->mat_count ; i++) {
- /* update the material */
- COPY_CLEAN_4V(store->mat[i].current, store->mat[i].size, store->mat[i].ptr);
- /* increment src vertex color pointer */
- STRIDE_F(store->mat[i].ptr, store->mat[i].stride);
- }
-
- /* recompute derived light/material values */
- _mesa_update_material( ctx, store->mat_bitmask );
- /* XXX we should only call this if we're tracking/changing the specular
- * exponent.
- */
- _mesa_validate_all_lighting_tables( ctx );
-}
-
-
-/**
- * Prepare things prior to running the lighting stage.
- * Return number of material attributes which will track vertex color.
- */
-static GLuint
-prepare_materials(struct gl_context *ctx,
- struct vertex_buffer *VB, struct light_stage_data *store)
-{
- GLuint i;
-
- store->mat_count = 0;
- store->mat_bitmask = 0;
-
- /* Examine the ColorMaterialBitmask to determine which materials
- * track vertex color. Override the material attribute's pointer
- * with the color pointer for each one.
- */
- if (ctx->Light.ColorMaterialEnabled) {
- const GLuint bitmask = ctx->Light.ColorMaterialBitmask;
- for (i = 0 ; i < MAT_ATTRIB_MAX ; i++)
- if (bitmask & (1<<i))
- VB->AttribPtr[_TNL_ATTRIB_MAT_FRONT_AMBIENT + i] = VB->AttribPtr[_TNL_ATTRIB_COLOR0];
- }
-
- /* Now, for each material attribute that's tracking vertex color, save
- * some values (ptr, stride, size, current) that we'll need in
- * update_materials(), above, that'll actually copy the vertex color to
- * the material attribute(s).
- */
- for (i = _TNL_FIRST_MAT; i <= _TNL_LAST_MAT; i++) {
- if (VB->AttribPtr[i]->stride) {
- const GLuint j = store->mat_count++;
- const GLuint attr = i - _TNL_ATTRIB_MAT_FRONT_AMBIENT;
- store->mat[j].ptr = VB->AttribPtr[i]->start;
- store->mat[j].stride = VB->AttribPtr[i]->stride;
- store->mat[j].size = VB->AttribPtr[i]->size;
- store->mat[j].current = ctx->Light.Material.Attrib[attr];
- store->mat_bitmask |= (1<<attr);
- }
- }
-
- /* FIXME: Is this already done?
- */
- _mesa_update_material( ctx, ~0 );
- _mesa_validate_all_lighting_tables( ctx );
-
- return store->mat_count;
-}
-
-/* Tables for all the shading functions.
- */
-static light_func _tnl_light_tab[MAX_LIGHT_FUNC];
-static light_func _tnl_light_fast_tab[MAX_LIGHT_FUNC];
-static light_func _tnl_light_fast_single_tab[MAX_LIGHT_FUNC];
-static light_func _tnl_light_spec_tab[MAX_LIGHT_FUNC];
-
-#define TAG(x) x
-#define IDX (0)
-#include "t_vb_lighttmp.h"
-
-#define TAG(x) x##_twoside
-#define IDX (LIGHT_TWOSIDE)
-#include "t_vb_lighttmp.h"
-
-#define TAG(x) x##_material
-#define IDX (LIGHT_MATERIAL)
-#include "t_vb_lighttmp.h"
-
-#define TAG(x) x##_twoside_material
-#define IDX (LIGHT_TWOSIDE|LIGHT_MATERIAL)
-#include "t_vb_lighttmp.h"
-
-
-static void init_lighting_tables( void )
-{
- static int done;
-
- if (!done) {
- init_light_tab();
- init_light_tab_twoside();
- init_light_tab_material();
- init_light_tab_twoside_material();
- done = 1;
- }
-}
-
-
-static GLboolean run_lighting( struct gl_context *ctx,
- struct tnl_pipeline_stage *stage )
-{
- struct light_stage_data *store = LIGHT_STAGE_DATA(stage);
- TNLcontext *tnl = TNL_CONTEXT(ctx);
- struct vertex_buffer *VB = &tnl->vb;
- GLvector4f *input = ctx->_NeedEyeCoords ? VB->EyePtr : VB->AttribPtr[_TNL_ATTRIB_POS];
- GLuint idx;
-
- if (!ctx->Light.Enabled || ctx->VertexProgram._Current)
- return GL_TRUE;
-
- /* Make sure we can talk about position x,y and z:
- */
- if (input->size <= 2 && input == VB->AttribPtr[_TNL_ATTRIB_POS]) {
-
- _math_trans_4f( store->Input.data,
- VB->AttribPtr[_TNL_ATTRIB_POS]->data,
- VB->AttribPtr[_TNL_ATTRIB_POS]->stride,
- GL_FLOAT,
- VB->AttribPtr[_TNL_ATTRIB_POS]->size,
- 0,
- VB->Count );
-
- if (input->size <= 2) {
- /* Clean z.
- */
- _mesa_vector4f_clean_elem(&store->Input, VB->Count, 2);
- }
-
- if (input->size <= 1) {
- /* Clean y.
- */
- _mesa_vector4f_clean_elem(&store->Input, VB->Count, 1);
- }
-
- input = &store->Input;
- }
-
- idx = 0;
-
- if (prepare_materials( ctx, VB, store ))
- idx |= LIGHT_MATERIAL;
-
- if (ctx->Light.Model.TwoSide)
- idx |= LIGHT_TWOSIDE;
-
- /* The individual functions know about replaying side-effects
- * vs. full re-execution.
- */
- store->light_func_tab[idx]( ctx, VB, stage, input );
-
- return GL_TRUE;
-}
-
-
-/* Called in place of do_lighting when the light table may have changed.
- */
-static void validate_lighting( struct gl_context *ctx,
- struct tnl_pipeline_stage *stage )
-{
- light_func *tab;
-
- if (!ctx->Light.Enabled || ctx->VertexProgram._Current)
- return;
-
- if (ctx->Light._NeedVertices) {
- if (ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)
- tab = _tnl_light_spec_tab;
- else
- tab = _tnl_light_tab;
- }
- else {
- if (ctx->Light.EnabledList.next == ctx->Light.EnabledList.prev)
- tab = _tnl_light_fast_single_tab;
- else
- tab = _tnl_light_fast_tab;
- }
-
-
- LIGHT_STAGE_DATA(stage)->light_func_tab = tab;
-
- /* This and the above should only be done on _NEW_LIGHT:
- */
- TNL_CONTEXT(ctx)->Driver.NotifyMaterialChange( ctx );
-}
-
-
-
-/* Called the first time stage->run is called. In effect, don't
- * allocate data until the first time the stage is run.
- */
-static GLboolean init_lighting( struct gl_context *ctx,
- struct tnl_pipeline_stage *stage )
-{
- TNLcontext *tnl = TNL_CONTEXT(ctx);
- struct light_stage_data *store;
- GLuint size = tnl->vb.Size;
-
- stage->privatePtr = MALLOC(sizeof(*store));
- store = LIGHT_STAGE_DATA(stage);
- if (!store)
- return GL_FALSE;
-
- /* Do onetime init.
- */
- init_lighting_tables();
-
- _mesa_vector4f_alloc( &store->Input, 0, size, 32 );
- _mesa_vector4f_alloc( &store->LitColor[0], 0, size, 32 );
- _mesa_vector4f_alloc( &store->LitColor[1], 0, size, 32 );
- _mesa_vector4f_alloc( &store->LitSecondary[0], 0, size, 32 );
- _mesa_vector4f_alloc( &store->LitSecondary[1], 0, size, 32 );
-
- store->LitColor[0].size = 4;
- store->LitColor[1].size = 4;
- store->LitSecondary[0].size = 3;
- store->LitSecondary[1].size = 3;
-
- return GL_TRUE;
-}
-
-
-
-
-static void dtr( struct tnl_pipeline_stage *stage )
-{
- struct light_stage_data *store = LIGHT_STAGE_DATA(stage);
-
- if (store) {
- _mesa_vector4f_free( &store->Input );
- _mesa_vector4f_free( &store->LitColor[0] );
- _mesa_vector4f_free( &store->LitColor[1] );
- _mesa_vector4f_free( &store->LitSecondary[0] );
- _mesa_vector4f_free( &store->LitSecondary[1] );
- FREE( store );
- stage->privatePtr = NULL;
- }
-}
-
-const struct tnl_pipeline_stage _tnl_lighting_stage =
-{
- "lighting", /* name */
- NULL, /* private_data */
- init_lighting,
- dtr, /* destroy */
- validate_lighting,
- run_lighting
-};
+/* + * Mesa 3-D graphics library + * Version: 6.5 + * + * Copyright (C) 1999-2006 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. + */ + + + +#include "main/glheader.h" +#include "main/colormac.h" +#include "main/light.h" +#include "main/macros.h" +#include "main/imports.h" +#include "main/simple_list.h" +#include "main/mtypes.h" + +#include "math/m_translate.h" + +#include "t_context.h" +#include "t_pipeline.h" +#include "tnl.h" + +#define LIGHT_TWOSIDE 0x1 +#define LIGHT_MATERIAL 0x2 +#define MAX_LIGHT_FUNC 0x4 + +typedef void (*light_func)( struct gl_context *ctx, + struct vertex_buffer *VB, + struct tnl_pipeline_stage *stage, + GLvector4f *input ); + +/** + * Information for updating current material attributes from vertex color, + * for GL_COLOR_MATERIAL. + */ +struct material_cursor { + const GLfloat *ptr; /* points to src vertex color (in VB array) */ + GLuint stride; /* stride to next vertex color (bytes) */ + GLfloat *current; /* points to material attribute to update */ + GLuint size; /* vertex/color size: 1, 2, 3 or 4 */ +}; + +/** + * Data private to this pipeline stage. + */ +struct light_stage_data { + GLvector4f Input; + GLvector4f LitColor[2]; + GLvector4f LitSecondary[2]; + light_func *light_func_tab; + + struct material_cursor mat[MAT_ATTRIB_MAX]; + GLuint mat_count; + GLuint mat_bitmask; +}; + + +#define LIGHT_STAGE_DATA(stage) ((struct light_stage_data *)(stage->privatePtr)) + + + +/**********************************************************************/ +/***** Lighting computation *****/ +/**********************************************************************/ + + +/* + * Notes: + * When two-sided lighting is enabled we compute the color (or index) + * for both the front and back side of the primitive. Then, when the + * orientation of the facet is later learned, we can determine which + * color (or index) to use for rendering. + * + * KW: We now know orientation in advance and only shade for + * the side or sides which are actually required. + * + * Variables: + * n = normal vector + * V = vertex position + * P = light source position + * Pe = (0,0,0,1) + * + * Precomputed: + * IF P[3]==0 THEN + * // light at infinity + * IF local_viewer THEN + * _VP_inf_norm = unit vector from V to P // Precompute + * ELSE + * // eye at infinity + * _h_inf_norm = Normalize( VP + <0,0,1> ) // Precompute + * ENDIF + * ENDIF + * + * Functions: + * Normalize( v ) = normalized vector v + * Magnitude( v ) = length of vector v + */ + + + +static void +validate_shine_table( struct gl_context *ctx, GLuint side, GLfloat shininess ) +{ + TNLcontext *tnl = TNL_CONTEXT(ctx); + struct tnl_shine_tab *list = tnl->_ShineTabList; + struct tnl_shine_tab *s; + + ASSERT(side < 2); + + foreach(s, list) + if ( s->shininess == shininess ) + break; + + if (s == list) { + GLint j; + GLfloat *m; + + foreach(s, list) + if (s->refcount == 0) + break; + + m = s->tab; + m[0] = 0.0; + if (shininess == 0.0) { + for (j = 1 ; j <= SHINE_TABLE_SIZE ; j++) + m[j] = 1.0; + } + else { + for (j = 1 ; j < SHINE_TABLE_SIZE ; j++) { + GLdouble t, x = j / (GLfloat) (SHINE_TABLE_SIZE - 1); + if (x < 0.005) /* underflow check */ + x = 0.005; + t = pow(x, shininess); + if (t > 1e-20) + m[j] = (GLfloat) t; + else + m[j] = 0.0; + } + m[SHINE_TABLE_SIZE] = 1.0; + } + + s->shininess = shininess; + } + + if (tnl->_ShineTable[side]) + tnl->_ShineTable[side]->refcount--; + + tnl->_ShineTable[side] = s; + move_to_tail( list, s ); + s->refcount++; +} + + +void +_tnl_validate_shine_tables( struct gl_context *ctx ) +{ + TNLcontext *tnl = TNL_CONTEXT(ctx); + GLfloat shininess; + + shininess = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_SHININESS][0]; + if (!tnl->_ShineTable[0] || tnl->_ShineTable[0]->shininess != shininess) + validate_shine_table( ctx, 0, shininess ); + + shininess = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_SHININESS][0]; + if (!tnl->_ShineTable[1] || tnl->_ShineTable[1]->shininess != shininess) + validate_shine_table( ctx, 1, shininess ); +} + + +/** + * In the case of colormaterial, the effected material attributes + * should already have been bound to point to the incoming color data, + * prior to running the pipeline. + * This function copies the vertex's color to the material attributes + * which are tracking glColor. + * It's called per-vertex in the lighting loop. + */ +static void +update_materials(struct gl_context *ctx, struct light_stage_data *store) +{ + GLuint i; + + for (i = 0 ; i < store->mat_count ; i++) { + /* update the material */ + COPY_CLEAN_4V(store->mat[i].current, store->mat[i].size, store->mat[i].ptr); + /* increment src vertex color pointer */ + STRIDE_F(store->mat[i].ptr, store->mat[i].stride); + } + + /* recompute derived light/material values */ + _mesa_update_material( ctx, store->mat_bitmask ); + /* XXX we should only call this if we're tracking/changing the specular + * exponent. + */ + _tnl_validate_shine_tables( ctx ); +} + + +/** + * Prepare things prior to running the lighting stage. + * Return number of material attributes which will track vertex color. + */ +static GLuint +prepare_materials(struct gl_context *ctx, + struct vertex_buffer *VB, struct light_stage_data *store) +{ + GLuint i; + + store->mat_count = 0; + store->mat_bitmask = 0; + + /* Examine the ColorMaterialBitmask to determine which materials + * track vertex color. Override the material attribute's pointer + * with the color pointer for each one. + */ + if (ctx->Light.ColorMaterialEnabled) { + const GLuint bitmask = ctx->Light.ColorMaterialBitmask; + for (i = 0 ; i < MAT_ATTRIB_MAX ; i++) + if (bitmask & (1<<i)) + VB->AttribPtr[_TNL_ATTRIB_MAT_FRONT_AMBIENT + i] = VB->AttribPtr[_TNL_ATTRIB_COLOR0]; + } + + /* Now, for each material attribute that's tracking vertex color, save + * some values (ptr, stride, size, current) that we'll need in + * update_materials(), above, that'll actually copy the vertex color to + * the material attribute(s). + */ + for (i = _TNL_FIRST_MAT; i <= _TNL_LAST_MAT; i++) { + if (VB->AttribPtr[i]->stride) { + const GLuint j = store->mat_count++; + const GLuint attr = i - _TNL_ATTRIB_MAT_FRONT_AMBIENT; + store->mat[j].ptr = VB->AttribPtr[i]->start; + store->mat[j].stride = VB->AttribPtr[i]->stride; + store->mat[j].size = VB->AttribPtr[i]->size; + store->mat[j].current = ctx->Light.Material.Attrib[attr]; + store->mat_bitmask |= (1<<attr); + } + } + + /* FIXME: Is this already done? + */ + _mesa_update_material( ctx, ~0 ); + + _tnl_validate_shine_tables( ctx ); + + return store->mat_count; +} + +/* + * 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). + */ +static inline GLfloat +lookup_shininess(const struct gl_context *ctx, GLuint face, GLfloat dp) +{ + TNLcontext *tnl = TNL_CONTEXT(ctx); + const struct tnl_shine_tab *tab = tnl->_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]); +} + +/* Tables for all the shading functions. + */ +static light_func _tnl_light_tab[MAX_LIGHT_FUNC]; +static light_func _tnl_light_fast_tab[MAX_LIGHT_FUNC]; +static light_func _tnl_light_fast_single_tab[MAX_LIGHT_FUNC]; +static light_func _tnl_light_spec_tab[MAX_LIGHT_FUNC]; + +#define TAG(x) x +#define IDX (0) +#include "t_vb_lighttmp.h" + +#define TAG(x) x##_twoside +#define IDX (LIGHT_TWOSIDE) +#include "t_vb_lighttmp.h" + +#define TAG(x) x##_material +#define IDX (LIGHT_MATERIAL) +#include "t_vb_lighttmp.h" + +#define TAG(x) x##_twoside_material +#define IDX (LIGHT_TWOSIDE|LIGHT_MATERIAL) +#include "t_vb_lighttmp.h" + + +static void init_lighting_tables( void ) +{ + static int done; + + if (!done) { + init_light_tab(); + init_light_tab_twoside(); + init_light_tab_material(); + init_light_tab_twoside_material(); + done = 1; + } +} + + +static GLboolean run_lighting( struct gl_context *ctx, + struct tnl_pipeline_stage *stage ) +{ + struct light_stage_data *store = LIGHT_STAGE_DATA(stage); + TNLcontext *tnl = TNL_CONTEXT(ctx); + struct vertex_buffer *VB = &tnl->vb; + GLvector4f *input = ctx->_NeedEyeCoords ? VB->EyePtr : VB->AttribPtr[_TNL_ATTRIB_POS]; + GLuint idx; + + if (!ctx->Light.Enabled || ctx->VertexProgram._Current) + return GL_TRUE; + + /* Make sure we can talk about position x,y and z: + */ + if (input->size <= 2 && input == VB->AttribPtr[_TNL_ATTRIB_POS]) { + + _math_trans_4f( store->Input.data, + VB->AttribPtr[_TNL_ATTRIB_POS]->data, + VB->AttribPtr[_TNL_ATTRIB_POS]->stride, + GL_FLOAT, + VB->AttribPtr[_TNL_ATTRIB_POS]->size, + 0, + VB->Count ); + + if (input->size <= 2) { + /* Clean z. + */ + _mesa_vector4f_clean_elem(&store->Input, VB->Count, 2); + } + + if (input->size <= 1) { + /* Clean y. + */ + _mesa_vector4f_clean_elem(&store->Input, VB->Count, 1); + } + + input = &store->Input; + } + + idx = 0; + + if (prepare_materials( ctx, VB, store )) + idx |= LIGHT_MATERIAL; + + if (ctx->Light.Model.TwoSide) + idx |= LIGHT_TWOSIDE; + + /* The individual functions know about replaying side-effects + * vs. full re-execution. + */ + store->light_func_tab[idx]( ctx, VB, stage, input ); + + return GL_TRUE; +} + + +/* Called in place of do_lighting when the light table may have changed. + */ +static void validate_lighting( struct gl_context *ctx, + struct tnl_pipeline_stage *stage ) +{ + light_func *tab; + + if (!ctx->Light.Enabled || ctx->VertexProgram._Current) + return; + + if (ctx->Light._NeedVertices) { + if (ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR) + tab = _tnl_light_spec_tab; + else + tab = _tnl_light_tab; + } + else { + if (ctx->Light.EnabledList.next == ctx->Light.EnabledList.prev) + tab = _tnl_light_fast_single_tab; + else + tab = _tnl_light_fast_tab; + } + + + LIGHT_STAGE_DATA(stage)->light_func_tab = tab; + + /* This and the above should only be done on _NEW_LIGHT: + */ + TNL_CONTEXT(ctx)->Driver.NotifyMaterialChange( ctx ); +} + + + +/* Called the first time stage->run is called. In effect, don't + * allocate data until the first time the stage is run. + */ +static GLboolean init_lighting( struct gl_context *ctx, + struct tnl_pipeline_stage *stage ) +{ + TNLcontext *tnl = TNL_CONTEXT(ctx); + struct light_stage_data *store; + GLuint size = tnl->vb.Size; + + stage->privatePtr = MALLOC(sizeof(*store)); + store = LIGHT_STAGE_DATA(stage); + if (!store) + return GL_FALSE; + + /* Do onetime init. + */ + init_lighting_tables(); + + _mesa_vector4f_alloc( &store->Input, 0, size, 32 ); + _mesa_vector4f_alloc( &store->LitColor[0], 0, size, 32 ); + _mesa_vector4f_alloc( &store->LitColor[1], 0, size, 32 ); + _mesa_vector4f_alloc( &store->LitSecondary[0], 0, size, 32 ); + _mesa_vector4f_alloc( &store->LitSecondary[1], 0, size, 32 ); + + store->LitColor[0].size = 4; + store->LitColor[1].size = 4; + store->LitSecondary[0].size = 3; + store->LitSecondary[1].size = 3; + + return GL_TRUE; +} + + + + +static void dtr( struct tnl_pipeline_stage *stage ) +{ + struct light_stage_data *store = LIGHT_STAGE_DATA(stage); + + if (store) { + _mesa_vector4f_free( &store->Input ); + _mesa_vector4f_free( &store->LitColor[0] ); + _mesa_vector4f_free( &store->LitColor[1] ); + _mesa_vector4f_free( &store->LitSecondary[0] ); + _mesa_vector4f_free( &store->LitSecondary[1] ); + FREE( store ); + stage->privatePtr = NULL; + } +} + +const struct tnl_pipeline_stage _tnl_lighting_stage = +{ + "lighting", /* name */ + NULL, /* private_data */ + init_lighting, + dtr, /* destroy */ + validate_lighting, + run_lighting +}; diff --git a/mesalib/src/mesa/tnl/t_vb_lighttmp.h b/mesalib/src/mesa/tnl/t_vb_lighttmp.h index 1041a24e7..1944e5ddc 100644 --- a/mesalib/src/mesa/tnl/t_vb_lighttmp.h +++ b/mesalib/src/mesa/tnl/t_vb_lighttmp.h @@ -204,7 +204,7 @@ static void TAG(light_rgba_spec)( struct gl_context *ctx, n_dot_h = correction * DOT3(normal, h); if (n_dot_h > 0.0F) { - GLfloat spec_coef = _mesa_lookup_shininess(ctx, side, n_dot_h); + GLfloat spec_coef = lookup_shininess(ctx, side, n_dot_h); if (spec_coef > 1.0e-10) { spec_coef *= attenuation; ACC_SCALE_SCALAR_3V( spec[side], spec_coef, @@ -383,7 +383,7 @@ static void TAG(light_rgba)( struct gl_context *ctx, n_dot_h = correction * DOT3(normal, h); if (n_dot_h > 0.0F) { - GLfloat spec_coef = _mesa_lookup_shininess(ctx, side, n_dot_h); + GLfloat spec_coef = lookup_shininess(ctx, side, n_dot_h); ACC_SCALE_SCALAR_3V( contrib, spec_coef, light->_MatSpecular[side]); } @@ -483,7 +483,7 @@ static void TAG(light_fast_rgba_single)( struct gl_context *ctx, 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); + GLfloat spec = lookup_shininess(ctx, 1, n_dot_h); ACC_SCALE_SCALAR_3V(sum, spec, light->_MatSpecular[1]); } COPY_3V(Bcolor[j], sum ); @@ -497,7 +497,7 @@ static void TAG(light_fast_rgba_single)( struct gl_context *ctx, 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); + GLfloat spec = lookup_shininess(ctx, 0, n_dot_h); ACC_SCALE_SCALAR_3V(sum, spec, light->_MatSpecular[0]); } COPY_3V(Fcolor[j], sum ); @@ -589,7 +589,7 @@ static void TAG(light_fast_rgba)( struct gl_context *ctx, 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); + spec = lookup_shininess(ctx, 0, n_dot_h); ACC_SCALE_SCALAR_3V( sum[0], spec, light->_MatSpecular[0]); } } @@ -598,7 +598,7 @@ static void TAG(light_fast_rgba)( struct gl_context *ctx, 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); + spec = lookup_shininess(ctx, 1, n_dot_h); ACC_SCALE_SCALAR_3V( sum[1], spec, light->_MatSpecular[1]); } } diff --git a/mesalib/src/mesa/tnl/tnl.h b/mesalib/src/mesa/tnl/tnl.h index d3889811e..434bd7fcd 100644 --- a/mesalib/src/mesa/tnl/tnl.h +++ b/mesalib/src/mesa/tnl/tnl.h @@ -101,4 +101,7 @@ _mesa_load_tracked_matrices(struct gl_context *ctx); extern void _tnl_RasterPos(struct gl_context *ctx, const GLfloat vObj[4]); +extern void +_tnl_validate_shine_tables( struct gl_context *ctx ); + #endif diff --git a/mesalib/src/mesa/x86/gen_matypes.c b/mesalib/src/mesa/x86/gen_matypes.c index 7af82b4ae..4fe99e799 100644 --- a/mesalib/src/mesa/x86/gen_matypes.c +++ b/mesalib/src/mesa/x86/gen_matypes.c @@ -103,7 +103,6 @@ int main( int argc, char **argv ) OFFSET( "CTX_LIGHT_COLOR_MAT_ENABLED ", struct gl_context, Light.ColorMaterialEnabled ); OFFSET( "CTX_LIGHT_ENABLED_LIST ", struct gl_context, Light.EnabledList ); OFFSET( "CTX_LIGHT_NEED_VERTS ", struct gl_context, Light._NeedVertices ); - OFFSET( "CTX_LIGHT_FLAGS ", struct gl_context, Light._Flags ); OFFSET( "CTX_LIGHT_BASE_COLOR ", struct gl_context, Light._BaseColor ); |