2
// This unit is part of the GLScene Engine https://github.com/glscene
7
23/03/11 - Yar - Creation
10
unit FShaderUniformEditor;
33
TShaderUniformEditor = class(TForm)
36
AutoSetBox: TComboBox;
37
SamplerBox: TComboBox;
39
RedGroup: TRadioGroup;
40
GreenGroup: TRadioGroup;
41
BlueGroup: TRadioGroup;
42
AlphaGroup: TRadioGroup;
47
TextureBox: TComboBox;
49
procedure FormDestroy(Sender: TObject);
50
procedure LBUniformsClick(Sender: TObject);
51
procedure ColorGroupClick(Sender: TObject);
52
procedure AutoSetBoxChange(Sender: TObject);
53
procedure TextureBoxChange(Sender: TObject);
54
procedure SamplerBoxChange(Sender: TObject);
55
procedure LBUniformsKeyPress(Sender: TObject; var Key: Char);
57
FUniformList: array of IShaderParameter;
60
procedure AddTextureName(const S: string);
61
procedure AddSamplerName(const S: string);
62
procedure AddUniform(AValue: IShaderParameter);
68
function ShaderUniformEditor: TShaderUniformEditor;
69
procedure ReleaseShaderUniformEditor;
71
//============================================
73
//============================================
78
vShaderUniformEditor: TShaderUniformEditor;
80
function ShaderUniformEditor: TShaderUniformEditor;
82
if not Assigned(vShaderUniformEditor) then
83
vShaderUniformEditor := TShaderUniformEditor.Create(nil);
84
Result := vShaderUniformEditor;
87
procedure ReleaseShaderUniformEditor;
89
if Assigned(vShaderUniformEditor) then
91
vShaderUniformEditor.Free;
92
vShaderUniformEditor := nil;
96
{ TShaderUniformEditor }
98
procedure TShaderUniformEditor.AddUniform(AValue: IShaderParameter);
100
if AValue <> nil then
102
SetLength(FUniformList, Length(FUniformList)+1);
103
FUniformList[High(FUniformList)] := AValue;
107
procedure TShaderUniformEditor.AutoSetBoxChange(Sender: TObject);
109
if LBUniforms.ItemIndex >= 0 then
111
FUniformList[LBUniforms.ItemIndex].AutoSetMethod := AutoSetBox.Items[AutoSetBox.ItemIndex];
115
procedure TShaderUniformEditor.Clear;
119
for I := 0 to High(FUniformList) do
120
FUniformList[I] := nil;
121
SetLength(FUniformList, 0);
122
LBUniforms.Items.Clear;
123
LBUniforms.ItemIndex := -1;
124
AutoSetBox.Items.Clear;
125
TextureBox.Items.Clear;
126
SamplerBox.Items.Clear;
127
AutoSetBox.Items.Add(rstrNothing);
128
TextureBox.Items.Add(rstrNothing);
129
SamplerBox.Items.Add(rstrNothing);
130
AutoSetBox.ItemIndex := 0;
131
TextureBox.ItemIndex := 0;
132
SamplerBox.ItemIndex := 0;
133
RedGroup.ItemIndex := -1;
134
GreenGroup.ItemIndex := -1;
135
BlueGroup.ItemIndex := -1;
136
AlphaGroup.ItemIndex := -1;
139
procedure TShaderUniformEditor.Execute;
144
for I := 0 to High(FUniformList) do
146
if FUniformList[I].GLSLType <> GLSLTypeUndefined then
147
str := cGLSLTypeString[FUniformList[I].GLSLType];
148
if FUniformList[I].GLSLSamplerType <> GLSLSamplerUndefined then
149
str := cGLSLSamplerString[FUniformList[I].GLSLSamplerType];
150
LBUniforms.Items.Add(FUniformList[I].Name+': '+string(str));
155
procedure TShaderUniformEditor.FormDestroy(Sender: TObject);
160
procedure TShaderUniformEditor.LBUniformsClick(Sender: TObject);
163
IParam: IShaderParameter;
165
if LBUniforms.ItemIndex >= 0 then
167
AutoSetBox.Items.Clear;
168
AutoSetBox.Items.Add(rstrNothing);
169
IParam := FUniformList[LBUniforms.ItemIndex];
170
if IParam.GLSLSamplerType <> GLSLSamplerUndefined then
172
FillUniformAutoSetMethodList(AutoSetBox.Items, IParam.GLSLSamplerType);
173
AutoSetBox.ItemIndex :=
174
MaxInteger(AutoSetBox.Items.IndexOf(IParam.AutoSetMethod), 0);
175
TextureBox.Enabled := True;
176
SamplerBox.Enabled := True;
177
TextureBox.ItemIndex :=
178
MaxInteger(TextureBox.Items.IndexOf(IParam.TextureName), 0);
179
SamplerBox.ItemIndex :=
180
MaxInteger(SamplerBox.Items.IndexOf(IParam.SamplerName), 0);
181
SV := IParam.GetTextureSwizzle;
182
RedGroup.ItemIndex := Ord(SV[0]);
183
GreenGroup.ItemIndex := Ord(SV[1]);
184
BlueGroup.ItemIndex := Ord(SV[2]);
185
AlphaGroup.ItemIndex := Ord(SV[3]);
189
TextureBox.Enabled := False;
190
SamplerBox.Enabled := False;
191
FillUniformAutoSetMethodList(AutoSetBox.Items, IParam.GLSLType);
192
AutoSetBox.ItemIndex :=
193
MaxInteger(AutoSetBox.Items.IndexOf(IParam.AutoSetMethod), 0);
194
RedGroup.ItemIndex := -1;
195
GreenGroup.ItemIndex := -1;
196
BlueGroup.ItemIndex := -1;
197
AlphaGroup.ItemIndex := -1;
202
procedure TShaderUniformEditor.LBUniformsKeyPress(Sender: TObject; var Key: Char);
204
LBUniformsClick(Self);
207
procedure TShaderUniformEditor.SamplerBoxChange(Sender: TObject);
209
if LBUniforms.ItemIndex >= 0 then
211
FUniformList[LBUniforms.ItemIndex].SamplerName :=
212
SamplerBox.Items[SamplerBox.ItemIndex];
216
procedure TShaderUniformEditor.TextureBoxChange(Sender: TObject);
218
if LBUniforms.ItemIndex >= 0 then
220
FUniformList[LBUniforms.ItemIndex].TextureName :=
221
TextureBox.Items[TextureBox.ItemIndex];
225
procedure TShaderUniformEditor.ColorGroupClick(Sender: TObject);
229
if LBUniforms.ItemIndex >= 0 then
231
if FUniformList[LBUniforms.ItemIndex].GLSLSamplerType = GLSLSamplerUndefined then
233
SV := FUniformList[LBUniforms.ItemIndex].GetTextureSwizzle;
234
SV[TRadioGroup(Sender).Tag] := TGLTextureSwizzle(TRadioGroup(Sender).ItemIndex);
235
FUniformList[LBUniforms.ItemIndex].SetTextureSwizzle(SV);
239
procedure TShaderUniformEditor.AddTextureName(const S: string);
241
TextureBox.Items.Add(S);
244
procedure TShaderUniformEditor.AddSamplerName(const S: string);
246
SamplerBox.Items.Add(S);
251
{$i FShaderUniformEditor.lrs}
255
ReleaseShaderUniformEditor;