GXSL.UserShader.pas 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // Graphic Scene Engine, http://glscene.org
  3. //
  4. (*
  5. A shader that passes control of the DoApply and DoUnApply
  6. methods through published events. This component is
  7. designed to make it a little easier to implement a
  8. customized shader. Be sure to keep the shader balanced
  9. by returning the OpenGL state to how you found it.
  10. *)
  11. unit GXSL.UserShader;
  12. interface
  13. uses
  14. System.Classes,
  15. GXS.Material,
  16. GXS.RenderContextInfo;
  17. type
  18. TOnDoApplyEvent = procedure (Sender : TObject; var rci : TgxRenderContextInfo) of Object;
  19. TOnDoUnApplyEvent = procedure (Sender : TObject; Pass:Integer; var rci : TgxRenderContextInfo; var Continue : Boolean) of Object;
  20. TgxUserShader = class(TgxShader)
  21. private
  22. FPass : Integer;
  23. FOnDoApply : TOnDoApplyEvent;
  24. FOnDoUnApply : TOnDoUnApplyEvent;
  25. protected
  26. procedure DoApply(var rci : TgxRenderContextInfo; Sender : TObject); override;
  27. function DoUnApply(var rci : TgxRenderContextInfo) : Boolean; override;
  28. published
  29. property OnDoApply : TOnDoApplyEvent read FOnDoApply write FOnDoApply;
  30. property OnDoUnApply : TOnDoUnApplyEvent read FOnDoUnApply write FOnDoUnApply;
  31. property ShaderStyle;
  32. end;
  33. // ------------------------------------------------------------------
  34. // ------------------------------------------------------------------
  35. // ------------------------------------------------------------------
  36. implementation
  37. // ------------------
  38. // ------------------ TgxUserShader ------------------
  39. // ------------------
  40. // DoApply
  41. //
  42. procedure TgxUserShader.DoApply(var rci: TgxRenderContextInfo; Sender : TObject);
  43. begin
  44. FPass:=1;
  45. if Assigned(FOnDoApply) and (not (csDesigning in ComponentState)) then
  46. FOnDoApply(Self,rci);
  47. end;
  48. // DoUnApply
  49. //
  50. function TgxUserShader.DoUnApply(var rci: TgxRenderContextInfo): Boolean;
  51. begin
  52. Result:=False;
  53. if Assigned(FOnDoUnApply) and (not (csDesigning in ComponentState)) then begin
  54. FOnDoUnApply(Self,FPass,rci,Result);
  55. Inc(FPass);
  56. end;
  57. end;
  58. end.