Skip to content

Commit 829bb66

Browse files
authored
define __GL__ (#2546)
* define __GL__ * update docs
1 parent 24bd5d6 commit 829bb66

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

Documentation/articles/content/custom_effects.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ These are some tips for writing or converting effects for use with KNI.
6565
| * `__KNIFX__` |
6666
| * `__DEBUG__` when building with the Debug flag |
6767
| * `__DIRECTX__` when targeting DirectX |
68-
| * `__OPENGL__` when targeting OpenGL |
69-
| * `__MOJOSHADER__` when building with MojoShader, targeting OpenGL |
68+
| * `__GL__` when targeting OpenGL/GLES/WebGL |
69+
| * `__OPENGL__` when targeting desktop OpenGL |
70+
| * `__GLES__` when targeting GLES/WebGL |
71+
| * `__MOJOSHADER__` when building with MojoShader, targeting OpenGL/GLES/WebGL |
7072
|---|
7173

7274

src/Xna.Framework.Content.Pipeline.Graphics.MojoProcessor/EffectCompiler/ShaderProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected ShaderProfile()
4444
/// </summary>
4545
public abstract ShaderProfileType ProfileType { get; }
4646

47-
internal abstract IEnumerable<KeyValuePair<string,string>> GetMacros();
47+
internal abstract IEnumerable<KeyValuePair<string,string>> GetMacros(GraphicsBackend backend);
4848

4949
internal abstract void ValidateShaderModels(PassInfo pass, string shaderFunction, string shaderModel, ShaderStage shaderStage, ShaderVersion shaderVersion);
5050

src/Xna.Framework.Content.Pipeline.Graphics.MojoProcessor/EffectCompiler/ShaderProfileDX11.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public ShaderProfileDX11()
2525
{
2626
}
2727

28-
internal override IEnumerable<KeyValuePair<string, string>> GetMacros()
28+
internal override IEnumerable<KeyValuePair<string, string>> GetMacros(GraphicsBackend backend)
2929
{
3030
yield return new KeyValuePair<string, string>("__DIRECTX__", "1");
3131
}

src/Xna.Framework.Content.Pipeline.Graphics.MojoProcessor/EffectCompiler/ShaderProfileGL.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,22 @@ public ShaderProfileGL()
2828
{
2929
}
3030

31-
internal override IEnumerable<KeyValuePair<string, string>> GetMacros()
31+
internal override IEnumerable<KeyValuePair<string, string>> GetMacros(GraphicsBackend backend)
3232
{
33-
yield return new KeyValuePair<string, string>("__OPENGL__", "1");
33+
yield return new KeyValuePair<string, string>("__GL__", "1");
3434
yield return new KeyValuePair<string, string>("__MOJOSHADER__", "1");
35+
36+
switch(backend)
37+
{
38+
case GraphicsBackend.OpenGL:
39+
yield return new KeyValuePair<string, string>("__OPENGL__", "1");
40+
break;
41+
42+
case GraphicsBackend.GLES:
43+
case GraphicsBackend.WebGL:
44+
yield return new KeyValuePair<string, string>("__GLES__", "1");
45+
break;
46+
}
3547
}
3648

3749
internal override void ValidateShaderModels(PassInfo pass, string shaderFunction, string shaderModel, ShaderStage shaderStage, ShaderVersion shaderVersion)

src/Xna.Framework.Content.Pipeline.Graphics.MojoProcessor/Processors/MojoEffectProcessor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public override CompiledEffectContent Process(EffectContent input, ContentProces
9898
string fullFilePath = Path.GetFullPath(input.Identity.SourceFilename);
9999

100100
// Preprocess the FX file expanding includes and macros.
101-
string effectCode = Preprocess(input, context, shaderProfile, fullFilePath);
101+
string effectCode = Preprocess(input, context, backend, shaderProfile, fullFilePath);
102102

103103
EffectObject effectObject = ProcessTechniques(input, context, backend, shaderProfile, fullFilePath, effectCode);
104104

@@ -242,7 +242,7 @@ public static ShaderProfile ShaderProfileFromBackend(GraphicsBackend backend)
242242

243243
// Pre-process the file,
244244
// resolving all #includes and macros.
245-
private string Preprocess(EffectContent input, ContentProcessorContext context, ShaderProfile shaderProfile, string fullFilePath)
245+
private string Preprocess(EffectContent input, ContentProcessorContext context, GraphicsBackend backend, ShaderProfile shaderProfile, string fullFilePath)
246246
{
247247
Preprocessor pp = new Preprocessor(input, context, fullFilePath);
248248

@@ -252,7 +252,7 @@ private string Preprocess(EffectContent input, ContentProcessorContext context,
252252
if (DebugMode == EffectProcessorDebugMode.Debug)
253253
pp.AddMacro("__DEBUG__", "1");
254254

255-
foreach (KeyValuePair<string, string> macro in shaderProfile.GetMacros())
255+
foreach (KeyValuePair<string, string> macro in shaderProfile.GetMacros(backend))
256256
pp.AddMacro(macro.Key, macro.Value);
257257

258258
if (!string.IsNullOrEmpty(Defines))

0 commit comments

Comments
 (0)