From 549566cbf1741b949d16b9fcf7468a0c6ee3ad2b Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 19 Sep 2012 22:23:59 +0000 Subject: [PATCH] lolfx: use square brackets to indicate shader sections. --- src/easymesh/shiny.lolfx | 8 ++++---- src/gpu/shader.cpp | 22 ++++++++++++++-------- src/gpu/testmaterial.lolfx | 7 +++---- src/gpu/tile.lolfx | 8 ++++---- src/gradient.lolfx | 8 ++++---- tutorial/01_triangle.lolfx | 23 ++++++++++++++++------- tutorial/02_cube.lolfx | 8 ++++---- tutorial/03_noise.lolfx | 8 ++++---- tutorial/08_fbo.lolfx | 8 ++++---- tutorial/11_fractal.lolfx | 8 ++++---- 10 files changed, 61 insertions(+), 47 deletions(-) diff --git a/src/easymesh/shiny.lolfx b/src/easymesh/shiny.lolfx index c415bd28..6294d09d 100644 --- a/src/easymesh/shiny.lolfx +++ b/src/easymesh/shiny.lolfx @@ -1,5 +1,5 @@ --- GLSL.Vert -- +[vert.glsl] #version 120 attribute vec3 in_Vertex; @@ -26,7 +26,7 @@ void main(void) gl_Position = in_Proj * eye; } --- GLSL.Frag -- +[frag.glsl] #version 120 #if defined GL_ES @@ -72,7 +72,7 @@ void main(void) gl_FragColor = real_color * vec4(light, 1.0); } --- HLSL.Vert -- +[vert.hlsl] void main(float3 in_Vertex : POSITION, float3 in_Normal : NORMAL, @@ -99,7 +99,7 @@ void main(float3 in_Vertex : POSITION, out_Position = mul(in_Proj, eye); } --- HLSL.Frag -- +[frag.hlsl] void main(float4 pass_Eye : TEXCOORD0, float3 pass_TNormal : TEXCOORD1, diff --git a/src/gpu/shader.cpp b/src/gpu/shader.cpp index b200e7cf..9ca003df 100644 --- a/src/gpu/shader.cpp +++ b/src/gpu/shader.cpp @@ -93,13 +93,13 @@ Shader *Shader::Create(char const *lolfx) for (char *parser = src; *parser; ) { if (key == NULL && (parser[0] == '\n' || parser[0] == '\r') - && parser[1] == '-' && parser[2] == '-' && parser[3] == ' ') + && parser[1] == '[') { *parser = '\0'; - parser += 4; + parser += 2; key = parser; } - else if (key && parser[0] == ' ') + else if (key && parser[0] == ']') { *parser++ = '\0'; } @@ -119,18 +119,24 @@ Shader *Shader::Create(char const *lolfx) for (int i = 0; i < sections.Count(); i++) { #if !defined __CELLOS_LV2__ && !defined _XBOX && !defined USE_D3D9 - if (!strcmp(sections[i].m1, "GLSL.Vert")) + if (!strcmp(sections[i].m1, "vert.glsl")) vert = sections[i].m2; - if (!strcmp(sections[i].m1, "GLSL.Frag")) + if (!strcmp(sections[i].m1, "frag.glsl")) frag = sections[i].m2; #else - if (!strcmp(sections[i].m1, "HLSL.Vert")) + if (!strcmp(sections[i].m1, "vert.hlsl")) vert = sections[i].m2; - if (!strcmp(sections[i].m1, "HLSL.Frag")) + if (!strcmp(sections[i].m1, "frag.hlsl")) frag = sections[i].m2; #endif } + /* FIXME: we don’t know how to handle these yet. */ + if (!vert) + Log::Error("no vertex shader found… sorry, I’m gonna crash now.\n"); + if (!frag) + Log::Error("no fragment shader found… sorry, I’m gonna crash now.\n"); + uint32_t new_vert_crc = Hash::Crc32(vert); uint32_t new_frag_crc = Hash::Crc32(frag); @@ -495,7 +501,7 @@ void Shader::SetUniform(ShaderUniform const &uni, mat3 const &m) { #if defined USE_D3D9 || defined _XBOX /* Padding matrix columns is necessary on DirectX. We need to create - * a new data structure; a 4×4 matrix will do. */ + * a new data structure; a 4×4 matrix will do. */ mat4 tmp(m, 1.0f); if (uni.flags & 1) g_d3ddevice->SetPixelShaderConstantF((UINT)uni.frag, &tmp[0][0], 3); diff --git a/src/gpu/testmaterial.lolfx b/src/gpu/testmaterial.lolfx index 86792a79..4b572ea4 100644 --- a/src/gpu/testmaterial.lolfx +++ b/src/gpu/testmaterial.lolfx @@ -66,8 +66,7 @@ technique Foo /* Defines GLSL shader "Prout" */ -#pragma lolfx vertexshader(lang=GLSL 1.20, name=prout) - +[prout.glsl] #version 120 /* Valid with my GLSL compiler */ @@ -84,7 +83,7 @@ void main(void) } /* Defines GLSL shader "Zob" */ -#pragma lolfx vertexshader(lang=GLSL 1.20, name=zob) +[zob.glsl] void main(void) { @@ -93,7 +92,7 @@ void main(void) /* Defines HLSL vertex shader "Prout" */ -#pragma lolfx vertexshader(lang=HLSL, name=prout) +[prout.hlsl] void main(void) { diff --git a/src/gpu/tile.lolfx b/src/gpu/tile.lolfx index f28bc10e..962a569d 100644 --- a/src/gpu/tile.lolfx +++ b/src/gpu/tile.lolfx @@ -1,4 +1,4 @@ --- GLSL.Vert -- +[vert.glsl] #version 130 @@ -17,7 +17,7 @@ void main() pass_TexCoord = in_TexCoord; } --- GLSL.Frag -- +[frag.glsl] #version 130 @@ -68,7 +68,7 @@ void main() gl_FragColor = col; } --- HLSL.Vert -- +[vert.hlsl] void main(float4 in_Position : POSITION, float2 in_TexCoord : TEXCOORD0, @@ -82,7 +82,7 @@ void main(float4 in_Position : POSITION, out_TexCoord = in_TexCoord; } --- HLSL.Frag -- +[frag.hlsl] void main(float2 in_TexCoord : TEXCOORD0, #if 0 diff --git a/src/gradient.lolfx b/src/gradient.lolfx index 9b672cad..f2c75e80 100644 --- a/src/gradient.lolfx +++ b/src/gradient.lolfx @@ -1,4 +1,4 @@ --- GLSL.Vert -- +[vert.glsl] #version 130 @@ -17,7 +17,7 @@ void main() pass_Color = in_Color; } --- GLSL.Frag -- +[frag.glsl] #version 130 @@ -49,7 +49,7 @@ void main() gl_FragColor = col; } --- HLSL.Vert -- +[vert.hlsl] void main(float4 in_Vertex : POSITION, float4 in_Color : COLOR, @@ -63,7 +63,7 @@ void main(float4 in_Vertex : POSITION, out_Color = in_Color; } --- HLSL.Frag -- +[frag.hlsl] float4x4 bayer = float4x4( 0.0, 12.0, 3.0, 15.0, 8.0, 4.0, 11.0, 7.0, diff --git a/tutorial/01_triangle.lolfx b/tutorial/01_triangle.lolfx index 6ec78e29..5d7abca7 100644 --- a/tutorial/01_triangle.lolfx +++ b/tutorial/01_triangle.lolfx @@ -1,5 +1,17 @@ --- GLSL.Vert -- +/* + * Awesome triangle shader + */ +technique Triangle +{ + pass FirstPass + { + vertexshader = vert; + pixelshader = frag; + } +} + +[vert.glsl] #version 120 attribute vec2 in_Position; @@ -9,8 +21,7 @@ void main(void) gl_Position = vec4(in_Position, 0.0, 1.0); } --- GLSL.Frag -- - +[frag.glsl] #version 120 void main(void) @@ -18,16 +29,14 @@ void main(void) gl_FragColor = vec4(0.7, 0.2, 0.5, 1.0); } --- HLSL.Vert -- - +[vert.hlsl] void main(float2 in_Position : POSITION, out float4 out_Position : POSITION) { out_Position = float4(in_Position, 0.0, 1.0); } --- HLSL.Frag -- - +[frag.hlsl] void main(out float4 out_FragColor : COLOR) { out_FragColor = float4(0.7, 0.2, 0.5, 1.0); diff --git a/tutorial/02_cube.lolfx b/tutorial/02_cube.lolfx index 9ec39d6b..3d143e4c 100644 --- a/tutorial/02_cube.lolfx +++ b/tutorial/02_cube.lolfx @@ -1,4 +1,4 @@ --- GLSL.Vert -- +[vert.glsl] #version 120 @@ -13,7 +13,7 @@ void main(void) pass_Color = in_Color; } --- GLSL.Frag -- +[frag.glsl] #version 120 @@ -24,7 +24,7 @@ void main(void) gl_FragColor = vec4(pass_Color, 1.0); } --- HLSL.Vert -- +[vert.hlsl] void main(float3 in_Vertex : POSITION, float3 in_Color : COLOR, @@ -36,7 +36,7 @@ void main(float3 in_Vertex : POSITION, out_Position = mul(in_Matrix, float4(in_Vertex, 1.0)); } --- HLSL.Frag -- +[frag.hlsl] void main(float3 pass_Color : COLOR, out float4 out_FragColor : COLOR) diff --git a/tutorial/03_noise.lolfx b/tutorial/03_noise.lolfx index 091fd371..5d779fc6 100644 --- a/tutorial/03_noise.lolfx +++ b/tutorial/03_noise.lolfx @@ -1,4 +1,4 @@ --- GLSL.Vert -- +[vert.glsl] #version 120 @@ -42,7 +42,7 @@ void main(void) gl_Position = vec4(in_Position, 0.0, 1.0); } --- GLSL.Frag -- +[frag.glsl] #version 120 @@ -134,7 +134,7 @@ void main(void) gl_FragColor = color; } --- HLSL.Vert -- +[vert.hlsl] float mod289(float x) { @@ -173,7 +173,7 @@ void main(float2 in_Position : POSITION, out_Position = float4(in_Position, 0.0, 1.0); } --- HLSL.Frag -- +[frag.hlsl] float4 mod289(float4 x) { diff --git a/tutorial/08_fbo.lolfx b/tutorial/08_fbo.lolfx index 0181d579..d47db363 100644 --- a/tutorial/08_fbo.lolfx +++ b/tutorial/08_fbo.lolfx @@ -1,4 +1,4 @@ --- GLSL.Vert -- +[vert.glsl] #version 120 @@ -12,7 +12,7 @@ void main() gl_Position = vec4(in_Position, 0.0, 1.0); } --- GLSL.Frag -- +[frag.glsl] #version 120 @@ -50,7 +50,7 @@ void main(void) } } --- HLSL.Vert -- +[vert.hlsl] void main(float2 in_Position : POSITION, out float2 pass_Position : TEXCOORD0, @@ -60,7 +60,7 @@ void main(float2 in_Position : POSITION, out_Position = float4(in_Position, 0.0, 1.0); } --- HLSL.Frag -- +[frag.hlsl] void main(in float2 pass_Position : TEXCOORD0, uniform sampler2D in_Texture, diff --git a/tutorial/11_fractal.lolfx b/tutorial/11_fractal.lolfx index f5ed9d1a..f028eeea 100644 --- a/tutorial/11_fractal.lolfx +++ b/tutorial/11_fractal.lolfx @@ -1,4 +1,4 @@ --- GLSL.Vert -- +[vert.glsl] #version 120 @@ -49,7 +49,7 @@ void main(void) v_IndexY = v_CenterY * u_ScreenSize.w - offsets.zwwz; } --- GLSL.Frag -- +[frag.glsl] #version 120 @@ -131,7 +131,7 @@ void main(void) #endif } --- HLSL.Vert -- +[vert.hlsl] void main(float2 a_Vertex : POSITION, float2 a_TexCoord : TEXCOORD0, @@ -166,7 +166,7 @@ void main(float2 a_Vertex : POSITION, v_IndexY = v_CenterY * u_ScreenSize.w - offsets.zwwz; } --- HLSL.Frag -- +[frag.hlsl] void main(in float4 v_CenterX : TEXCOORD0, in float4 v_CenterY : TEXCOORD1,