2
// This unit is part of the GLScene Engine https://github.com/glscene
5
A simple shader that adds an outline to an object.
8
1. Object can be transparent (color alpha < 1) if it doesn't
9
overlap itself. Texture transparency doesn't work.
10
2. Doesn't work with objects (e.g. TGLFreeForm) having it's own
12
3. Doesn't Works with visible backfaces.
15
12/02/11 - Yar - Added skipping shader when enabled stencil test to avvoid conflict with shadow volume
16
23/08/10 - Yar - Added OpenGLTokens to uses, replaced OpenGL1x functions to OpenGLAdapter
17
22/04/10 - Yar - Fixes after GLState revision
18
05/03/10 - DanB - More state added to TGLStateCache
19
06/06/07 - DaStr - Added $I GLScene.inc
20
Added GLColor to uses (BugtrackerID = 1732211)
21
25/02/07 - DaStr - Moved registration to GLSceneRegister.pas
22
05/06/04 - NelC - Fixed bug with textured object
23
14/12/03 - NelC - Removed BlendLine, automatically determine if blend
24
20/10/03 - NelC - Removed unnecessary properties. Shader now honors
26
04/09/03 - NelC - Converted into a component from the TOutlineShader
27
in the multipass demo.
37
Classes, GLMaterial, GLCrossPlatform, GLColor, GLRenderContextInfo;
43
TGLOutlineShader = class(TGLShader)
48
FOutlineSmooth: Boolean;
49
FOutlineWidth: Single;
51
procedure SetOutlineWidth(v: single);
52
procedure SetOutlineSmooth(v: boolean);
56
procedure DoApply(var rci: TGLRenderContextInfo; Sender: TObject); override;
57
function DoUnApply(var rci: TGLRenderContextInfo): Boolean; override;
61
constructor Create(AOwner: TComponent); override;
62
destructor Destroy; override;
66
property LineColor: TGLColor read FLineColor write FLineColor;
67
{ Line smoothing control }
68
property LineSmooth: Boolean read FOutlineSmooth write SetOutlineSmooth
70
property LineWidth: Single read FOutlineWidth write SetOutlineWidth;
73
// ------------------------------------------------------------------
74
// ------------------------------------------------------------------
75
// ------------------------------------------------------------------
77
// ------------------------------------------------------------------
78
// ------------------------------------------------------------------
79
// ------------------------------------------------------------------
81
uses OpenGLTokens, GLContext, GLState, GLTextureFormat;
84
// ------------------ TGLOutlineShader ------------------
90
constructor TGLOutlineShader.Create(AOwner: TComponent);
93
FOutlineSmooth := False;
95
FLineColor := TGLColor.CreateInitialized(Self, clrBlack);
96
ShaderStyle := ssLowLevel;
102
destructor TGLOutlineShader.Destroy;
111
procedure TGLOutlineShader.DoApply(var rci: TGLRenderContextInfo; Sender:
114
// We first draw the object as usual in the first pass. This allows objects
115
// with color alpha < 1 to be rendered correctly with outline.
122
function TGLOutlineShader.DoUnApply(var rci: TGLRenderContextInfo): Boolean;
124
if rci.ignoreMaterials or (stStencilTest in rci.GLStates.States) then
133
// Now set up to draw the outline in the second pass
137
if FOutlineSmooth then
139
LineSmoothHint := hintNicest;
140
Enable(stLineSmooth);
143
Disable(stLineSmooth);
145
if FOutlineSmooth or (FlineColor.Alpha < 1) then
148
SetBlendFunc(bfSrcAlpha, bfOneMinusSrcAlpha);
153
GL.Color4fv(FlineColor.AsAddress);
154
LineWidth := FOutlineWidth;
155
Disable(stLineStipple);
156
PolygonMode := pmLines;
157
CullFaceMode := cmFront;
158
DepthFunc := cfLEqual;
159
ActiveTextureEnabled[ttTexture2D] := False;
162
Result := True; // go for next pass
168
PolygonMode := pmFill;
169
CullFaceMode := cmBack;
170
DepthFunc := cfLequal;
171
Result := False; // we're done
182
procedure TGLOutlineShader.SetOutlineWidth(v: single);
184
if FOutlineWidth <> v then
194
procedure TGLOutlineShader.SetOutlineSmooth(v: boolean);
196
if FOutlineSmooth <> v then