Exemple #1
0
static void make_state_key( GLcontext *ctx, struct state_key *key )
{
   const struct gl_fragment_program *fp;
   GLuint i;

   memset(key, 0, sizeof(struct state_key));
   fp = ctx->FragmentProgram._Current;

   /* This now relies on texenvprogram.c being active:
    */
   assert(fp);

   key->need_eye_coords = ctx->_NeedEyeCoords;

   key->fragprog_inputs_read = fp->Base.InputsRead;
   key->varying_vp_inputs = ctx->varying_vp_inputs;

   if (ctx->RenderMode == GL_FEEDBACK) {
      /* make sure the vertprog emits color and tex0 */
      key->fragprog_inputs_read |= (FRAG_BIT_COL0 | FRAG_BIT_TEX0);
   }

   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_mask = ctx->Light.ColorMaterialBitmask;
      }

      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 (check_active_shininess(ctx, key, 0)) {
         key->material_shininess_is_zero = 0;
      }
      else if (key->light_twoside &&
               check_active_shininess(ctx, key, 1)) {
         key->material_shininess_is_zero = 0;
      }
      else {
         key->material_shininess_is_zero = 1;
      }
   }

   if (ctx->Transform.Normalize)
      key->normalize = 1;

   if (ctx->Transform.RescaleNormals)
      key->rescale_normals = 1;

   if (ctx->Fog.FogCoordinateSource == GL_FRAGMENT_DEPTH_EXT)
      key->fog_source_is_depth = 1;

   if (ctx->Point._Attenuated)
      key->point_attenuated = 1;

#if FEATURE_point_size_array
   if (ctx->Array.ArrayObj->PointSize.Enabled)
      key->point_array = 1;
#endif

   if (ctx->Texture._TexGenEnabled ||
       ctx->Texture._TexMatEnabled ||
       ctx->Texture._EnabledUnits)
      key->texture_enabled_global = 1;

   for (i = 0; i < MAX_TEXTURE_COORD_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->GenS.Mode );
	 key->unit[i].texgen_mode1 =
	    translate_texgen( texUnit->TexGenEnabled & (1<<1),
			      texUnit->GenT.Mode );
	 key->unit[i].texgen_mode2 =
	    translate_texgen( texUnit->TexGenEnabled & (1<<2),
			      texUnit->GenR.Mode );
	 key->unit[i].texgen_mode3 =
	    translate_texgen( texUnit->TexGenEnabled & (1<<3),
			      texUnit->GenQ.Mode );
      }
   }
}
Exemple #2
0
static void make_state_key( struct gl_context *ctx, struct state_key *key )
{
   const struct gl_program *fp = ctx->FragmentProgram._Current;
   GLbitfield mask;

   memset(key, 0, sizeof(struct state_key));

   /* This now relies on texenvprogram.c being active:
    */
   assert(fp);

   key->need_eye_coords = ctx->_NeedEyeCoords;

   key->fragprog_inputs_read = fp->info.inputs_read;
   key->varying_vp_inputs = ctx->varying_vp_inputs;

   if (ctx->RenderMode == GL_FEEDBACK) {
      /* make sure the vertprog emits color and tex0 */
      key->fragprog_inputs_read |= (VARYING_BIT_COL0 | VARYING_BIT_TEX0);
   }

   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_mask = ctx->Light._ColorMaterialBitmask;
      }

      mask = ctx->Light._EnabledLights;
      while (mask) {
         const int i = u_bit_scan(&mask);
         struct gl_light *light = &ctx->Light.Light[i];

         key->unit[i].light_enabled = 1;

         if (light->EyePosition[3] == 0.0F)
            key->unit[i].light_eyepos3_is_zero = 1;

         if (light->SpotCutoff == 180.0F)
            key->unit[i].light_spotcutoff_is_180 = 1;

         if (light->ConstantAttenuation != 1.0F ||
             light->LinearAttenuation != 0.0F ||
             light->QuadraticAttenuation != 0.0F)
            key->unit[i].light_attenuated = 1;
      }

      if (check_active_shininess(ctx, key, 0)) {
         key->material_shininess_is_zero = 0;
      }
      else if (key->light_twoside &&
               check_active_shininess(ctx, key, 1)) {
         key->material_shininess_is_zero = 0;
      }
      else {
         key->material_shininess_is_zero = 1;
      }
   }

   if (ctx->Transform.Normalize)
      key->normalize = 1;

   if (ctx->Transform.RescaleNormals)
      key->rescale_normals = 1;

   if (ctx->Fog.FogCoordinateSource == GL_FRAGMENT_DEPTH_EXT) {
      key->fog_source_is_depth = 1;
      key->fog_distance_mode = translate_fog_distance_mode(ctx->Fog.FogDistanceMode);
   }

   if (ctx->Point._Attenuated)
      key->point_attenuated = 1;

   if (ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled)
      key->point_array = 1;

   if (ctx->Texture._TexGenEnabled ||
       ctx->Texture._TexMatEnabled ||
       ctx->Texture._MaxEnabledTexImageUnit != -1)
      key->texture_enabled_global = 1;

   mask = ctx->Texture._EnabledCoordUnits | ctx->Texture._TexGenEnabled
      | ctx->Texture._TexMatEnabled | ctx->Point.CoordReplace;
   while (mask) {
      const int i = u_bit_scan(&mask);
      struct gl_texture_unit *texUnit = &ctx->Texture.Unit[i];

      if (texUnit->_Current)
	 key->unit[i].texunit_really_enabled = 1;

      if (ctx->Point.PointSprite)
	 if (ctx->Point.CoordReplace & (1u << i))
	    key->unit[i].coord_replace = 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->GenS.Mode );
	 key->unit[i].texgen_mode1 =
	    translate_texgen( texUnit->TexGenEnabled & (1<<1),
			      texUnit->GenT.Mode );
	 key->unit[i].texgen_mode2 =
	    translate_texgen( texUnit->TexGenEnabled & (1<<2),
			      texUnit->GenR.Mode );
	 key->unit[i].texgen_mode3 =
	    translate_texgen( texUnit->TexGenEnabled & (1<<3),
			      texUnit->GenQ.Mode );
      }
   }
}