GLSL.UserShader.pas 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // The multimedia graphics platform GLScene https://github.com/glscene
  3. //
  4. unit GLSL.UserShader;
  5. (*
  6. A shader that passes control of the DoApply and DoUnApply
  7. methods through published events. This component is
  8. designed to make it a little easier to implement a
  9. customized shader. Be sure to keep the shader balanced
  10. by returning the OpenGL state to how you found it.
  11. *)
  12. interface
  13. uses
  14. System.Classes,
  15. GLS.Material,
  16. GLS.RenderContextInfo;
  17. type
  18. TOnDoApplyEvent = procedure (Sender : TObject; var rci : TGLRenderContextInfo) of Object;
  19. TOnDoUnApplyEvent = procedure (Sender : TObject; Pass:Integer; var rci : TGLRenderContextInfo; var Continue : Boolean) of Object;
  20. TGLUserShader = class(TGLShader)
  21. private
  22. FPass : Integer;
  23. FOnDoApply : TOnDoApplyEvent;
  24. FOnDoUnApply : TOnDoUnApplyEvent;
  25. protected
  26. procedure DoApply(var rci : TGLRenderContextInfo; Sender : TObject); override;
  27. function DoUnApply(var rci : TGLRenderContextInfo) : 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. implementation
  35. // ------------------------------------------------------------------
  36. // ------------------
  37. // ------------------ TGLUserShader ------------------
  38. // ------------------
  39. procedure TGLUserShader.DoApply(var rci: TGLRenderContextInfo; Sender : TObject);
  40. begin
  41. FPass:=1;
  42. if Assigned(FOnDoApply) and (not (csDesigning in ComponentState)) then
  43. FOnDoApply(Self,rci);
  44. end;
  45. function TGLUserShader.DoUnApply(var rci: TGLRenderContextInfo): Boolean;
  46. begin
  47. Result:=False;
  48. if Assigned(FOnDoUnApply) and (not (csDesigning in ComponentState)) then begin
  49. FOnDoUnApply(Self,FPass,rci,Result);
  50. Inc(FPass);
  51. end;
  52. end;
  53. end.