unit RegisterCombiners;

interface

uses Windows, SysUtils, Classes, GL, GLu, GLext, WGLext, GLtools, NV_parse;

type
  TRegisterCombiner = class
  protected
    FCombiner           : GLuint;
    FSource             : TStringList;
    FLog                : string;
    FCompiled           : boolean;
  public
    constructor Create; virtual;
    destructor Destroy; override;
    procedure Load(filename: string); virtual;
    procedure Save(filename: string); virtual;
    procedure Compile; virtual;
    procedure Enable; virtual;
    procedure Disable; virtual;
    property Combiner: GLuint read FCombiner;
    property Log: string read FLog;
    property Compiled: boolean read FCompiled;
  end;

implementation

constructor TRegisterCombiner.Create;
begin
  if not Load_GL_NV_register_combiners then
    raise Exception.Create('GL_NV_register_combiners required!');

  inherited Create;

  FCombiner := glGenLists(1);
  FSource := TStringList.Create;
  FLog := '';
  FCompiled := false;
end;

destructor TRegisterCombiner.Destroy;
begin
  glDeleteLists(FCombiner, 1);
  FSource.Free;

  inherited Destroy;
end;

procedure TRegisterCombiner.Load;
begin
  FSource.LoadFromFile(filename);
end;

procedure TRegisterCombiner.Save;
begin
  FSource.SaveToFile(filename);
end;

procedure TRegisterCombiner.Compile;
begin
  glNewList(FCombiner, GL_COMPILE);
    NVparse(PChar(FSource.Text));
  glEndList;
  FLog := NVparseErrorStrings;
  FCompiled := true;
end;

procedure TRegisterCombiner.Enable;
begin
  if not FCompiled then Compile;
  glEnable(GL_REGISTER_COMBINERS_NV);
  glCallList(FCombiner);
end;

procedure TRegisterCombiner.Disable;
begin
  glDisable(GL_REGISTER_COMBINERS_NV);
end;

end.
