/** * Update fragment program state/atom. This involves translating the * Mesa fragment program into a gallium fragment program and binding it. */ static void update_fp( struct st_context *st ) { struct st_fragment_program *stfp; struct st_fp_variant_key key; assert(st->ctx->FragmentProgram._Current); stfp = st_fragment_program(st->ctx->FragmentProgram._Current); assert(stfp->Base.Base.Target == GL_FRAGMENT_PROGRAM_ARB); memset(&key, 0, sizeof(key)); key.st = st->has_shareable_shaders ? NULL : st; /* _NEW_FRAG_CLAMP */ key.clamp_color = st->clamp_frag_color_in_shader && st->ctx->Color._ClampFragmentColor; /* _NEW_MULTISAMPLE | _NEW_BUFFERS */ key.persample_shading = st->force_persample_in_shader && _mesa_is_multisample_enabled(st->ctx) && st->ctx->Multisample.SampleShading && st->ctx->Multisample.MinSampleShadingValue * _mesa_geometric_samples(st->ctx->DrawBuffer) > 1; if (stfp->ati_fs) { unsigned u; if (st->ctx->Fog.Enabled) { key.fog = translate_fog_mode(st->ctx->Fog.Mode); } for (u = 0; u < MAX_NUM_FRAGMENT_REGISTERS_ATI; u++) { key.texture_targets[u] = get_texture_target(st->ctx, u); } } st->fp_variant = st_get_fp_variant(st, stfp, &key); st_reference_fragprog(st, &st->fp, stfp); cso_set_fragment_shader_handle(st->cso_context, st->fp_variant->driver_shader); }
static void make_state_key( GLcontext *ctx, struct state_key *key ) { struct brw_context *brw = brw_context(ctx); const struct gl_fragment_program *fp = brw->fragment_program; GLuint i; /* This now relies on texenvprogram.c being active: */ assert(fp); memset(key, 0, sizeof(*key)); /* BRW_NEW_FRAGMENT_PROGRAM */ key->fragprog_inputs_read = fp->Base.InputsRead; /* _NEW_LIGHT */ key->separate_specular = (brw->attribs.Light->Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR); /* _NEW_LIGHT */ if (brw->attribs.Light->Enabled) { key->light_global_enabled = 1; if (brw->attribs.Light->Model.LocalViewer) key->light_local_viewer = 1; if (brw->attribs.Light->Model.TwoSide) key->light_twoside = 1; if (brw->attribs.Light->ColorMaterialEnabled) { key->light_color_material = 1; key->light_color_material_mask = brw->attribs.Light->ColorMaterialBitmask; } /* BRW_NEW_INPUT_VARYING */ /* For these programs, material values are stuffed into the * generic slots: */ for (i = 0 ; i < MAT_ATTRIB_MAX ; i++) if (brw->vb.info.varying & (1<<(VERT_ATTRIB_GENERIC0 + i))) key->light_material_mask |= 1<<i; for (i = 0; i < MAX_LIGHTS; i++) { struct gl_light *light = &brw->attribs.Light->Light[i]; if (light->Enabled) { key->unit[i].light_enabled = 1; if (light->EyePosition[3] == 0.0) key->unit[i].light_eyepos3_is_zero = 1; if (light->SpotCutoff == 180.0) key->unit[i].light_spotcutoff_is_180 = 1; if (light->ConstantAttenuation != 1.0 || light->LinearAttenuation != 0.0 || light->QuadraticAttenuation != 0.0) key->unit[i].light_attenuated = 1; } } } /* _NEW_TRANSFORM */ if (brw->attribs.Transform->Normalize) key->normalize = 1; if (brw->attribs.Transform->RescaleNormals) key->rescale_normals = 1; /* BRW_NEW_FRAGMENT_PROGRAM */ key->fog_option = translate_fog_mode(fp->FogOption); if (key->fog_option) key->fragprog_inputs_read |= FRAG_BIT_FOGC; /* _NEW_FOG */ if (brw->attribs.Fog->FogCoordinateSource == GL_FRAGMENT_DEPTH_EXT) key->fog_source_is_depth = 1; /* _NEW_HINT, ??? */ if (1) key->tnl_do_vertex_fog = 1; /* _NEW_POINT */ if (brw->attribs.Point->_Attenuated) key->point_attenuated = 1; /* _NEW_TEXTURE */ if (brw->attribs.Texture->_TexGenEnabled || brw->attribs.Texture->_TexMatEnabled || brw->attribs.Texture->_EnabledUnits) key->texture_enabled_global = 1; for (i = 0; i < MAX_TEXTURE_UNITS; i++) { struct gl_texture_unit *texUnit = &brw->attribs.Texture->Unit[i]; if (texUnit->_ReallyEnabled) key->unit[i].texunit_really_enabled = 1; if (brw->attribs.Texture->_TexMatEnabled & ENABLE_TEXMAT(i)) key->unit[i].texmat_enabled = 1; if (texUnit->TexGenEnabled) { key->unit[i].texgen_enabled = 1; key->unit[i].texgen_mode0 = translate_texgen( texUnit->TexGenEnabled & (1<<0), texUnit->GenModeS ); key->unit[i].texgen_mode1 = translate_texgen( texUnit->TexGenEnabled & (1<<1), texUnit->GenModeT ); key->unit[i].texgen_mode2 = translate_texgen( texUnit->TexGenEnabled & (1<<2), texUnit->GenModeR ); key->unit[i].texgen_mode3 = translate_texgen( texUnit->TexGenEnabled & (1<<3), texUnit->GenModeQ ); } } }
static struct state_key *make_state_key( GLcontext *ctx ) { TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; const struct gl_fragment_program *fp = ctx->FragmentProgram._Current; struct state_key *key = CALLOC_STRUCT(state_key); GLuint i; /* This now relies on texenvprogram.c being active: */ assert(fp); key->fragprog_inputs_read = fp->Base.InputsRead; key->separate_specular = (ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR); if (ctx->Light.Enabled) { key->light_global_enabled = 1; if (ctx->Light.Model.LocalViewer) key->light_local_viewer = 1; if (ctx->Light.Model.TwoSide) key->light_twoside = 1; if (ctx->Light.ColorMaterialEnabled) { key->light_color_material = 1; key->light_color_material_mask = ctx->Light.ColorMaterialBitmask; } for (i = _TNL_FIRST_MAT; i <= _TNL_LAST_MAT; i++) if (VB->AttribPtr[i]->stride) key->light_material_mask |= 1<<(i-_TNL_ATTRIB_MAT_FRONT_AMBIENT); for (i = 0; i < MAX_LIGHTS; i++) { struct gl_light *light = &ctx->Light.Light[i]; if (light->Enabled) { key->unit[i].light_enabled = 1; if (light->EyePosition[3] == 0.0) key->unit[i].light_eyepos3_is_zero = 1; if (light->SpotCutoff == 180.0) key->unit[i].light_spotcutoff_is_180 = 1; if (light->ConstantAttenuation != 1.0 || light->LinearAttenuation != 0.0 || light->QuadraticAttenuation != 0.0) key->unit[i].light_attenuated = 1; } } } if (ctx->Transform.Normalize) key->normalize = 1; if (ctx->Transform.RescaleNormals) key->rescale_normals = 1; key->fog_mode = translate_fog_mode(fp->FogOption); if (ctx->Fog.FogCoordinateSource == GL_FRAGMENT_DEPTH_EXT) key->fog_source_is_depth = 1; if (tnl->_DoVertexFog) key->tnl_do_vertex_fog = 1; if (ctx->Point._Attenuated) key->point_attenuated = 1; if (ctx->Texture._TexGenEnabled || ctx->Texture._TexMatEnabled || ctx->Texture._EnabledUnits) key->texture_enabled_global = 1; for (i = 0; i < MAX_TEXTURE_UNITS; i++) { struct gl_texture_unit *texUnit = &ctx->Texture.Unit[i]; if (texUnit->_ReallyEnabled) key->unit[i].texunit_really_enabled = 1; if (ctx->Texture._TexMatEnabled & ENABLE_TEXMAT(i)) key->unit[i].texmat_enabled = 1; if (texUnit->TexGenEnabled) { key->unit[i].texgen_enabled = 1; key->unit[i].texgen_mode0 = translate_texgen( texUnit->TexGenEnabled & (1<<0), texUnit->GenModeS ); key->unit[i].texgen_mode1 = translate_texgen( texUnit->TexGenEnabled & (1<<1), texUnit->GenModeT ); key->unit[i].texgen_mode2 = translate_texgen( texUnit->TexGenEnabled & (1<<2), texUnit->GenModeR ); key->unit[i].texgen_mode3 = translate_texgen( texUnit->TexGenEnabled & (1<<3), texUnit->GenModeQ ); } } return key; }