public void apply() {
    if (isSupported()) {
      RenderContext context = DisplaySystem.getDisplaySystem().getCurrentContext();
      FragmentProgramStateRecord record =
          (FragmentProgramStateRecord) context.getStateRecord(RS_FRAGMENT_PROGRAM);

      context.currentStates[RS_FRAGMENT_PROGRAM] = this;

      if (!record.isValid() || record.getReference() != this) {
        record.setReference(this);
        if (isEnabled()) {
          // Fragment program not yet loaded
          if (programID == -1)
            if (program != null) create();
            else return;

          GL11.glEnable(ARBFragmentProgram.GL_FRAGMENT_PROGRAM_ARB);
          ARBProgram.glBindProgramARB(ARBFragmentProgram.GL_FRAGMENT_PROGRAM_ARB, programID);

          // load environmental parameters...
          // TODO: Reevaluate how this is done.
          /*
           * for (int i = 0; i < envparameters.length; i++) if
           * (envparameters[i] != null)
           * ARBFragmentProgram.glProgramEnvParameter4fARB(
           * ARBFragmentProgram.GL_FRAGMENT_PROGRAM_ARB, i,
           * envparameters[i][0], envparameters[i][1],
           * envparameters[i][2], envparameters[i][3]);
           */

          // load local parameters...
          if (usingParameters) // No sense checking array if we are sure
            // no parameters are used
            for (int i = 0; i < parameters.length; i++)
              if (parameters[i] != null)
                ARBProgram.glProgramLocalParameter4fARB(
                    ARBFragmentProgram.GL_FRAGMENT_PROGRAM_ARB,
                    i,
                    parameters[i][0],
                    parameters[i][1],
                    parameters[i][2],
                    parameters[i][3]);

        } else {
          GL11.glDisable(ARBFragmentProgram.GL_FRAGMENT_PROGRAM_ARB);
        }
      }

      if (!record.isValid()) record.validate();
    }
  }
  /**
   * <code>set</code> sets the OpenGL fog values if the state is enabled.
   *
   * @see com.jme.scene.state.RenderState#apply()
   */
  public void apply() {
    final GL gl = GLU.getCurrentGL();

    // ask for the current state record
    RenderContext<?> context = DisplaySystem.getDisplaySystem().getCurrentContext();
    FogStateRecord record = (FogStateRecord) context.getStateRecord(RS_FOG);
    context.currentStates[RS_FOG] = this;

    if (isEnabled()) {
      enableFog(true, record);

      if (record.isValid()) {
        if (record.fogStart != start) {
          gl.glFogf(GL.GL_FOG_START, start);
          record.fogStart = start;
        }
        if (record.fogEnd != end) {
          gl.glFogf(GL.GL_FOG_END, end);
          record.fogEnd = end;
        }
        if (record.density != density) {
          gl.glFogf(GL.GL_FOG_DENSITY, density);
          record.density = density;
        }
      } else {
        gl.glFogf(GL.GL_FOG_START, start);
        record.fogStart = start;
        gl.glFogf(GL.GL_FOG_END, end);
        record.fogEnd = end;
        gl.glFogf(GL.GL_FOG_DENSITY, density);
        record.density = density;
      }

      applyFogColor(getColor(), record);
      applyFogMode(densityFunction, record);
      applyFogHint(quality, record);
      applyFogSource(source, record);
    } else {
      enableFog(false, record);
    }

    if (!record.isValid()) record.validate();
  }