@@ -54,7 +54,7 @@ SUFFIXES = .lolfx | |||||
%.lolfx.cpp: %.lolfx | %.lolfx.cpp: %.lolfx | ||||
echo "/* This file was autogenerated. DO NOT MODIFY IT. */" > $@.tmp | echo "/* This file was autogenerated. DO NOT MODIFY IT. */" > $@.tmp | ||||
echo "char const *lolfx_$(notdir $(^:%.lolfx=%)) =" >> $@.tmp | echo "char const *lolfx_$(notdir $(^:%.lolfx=%)) =" >> $@.tmp | ||||
$(SED) 's/"/\\"/g' $^ | $(SED) 's/.*/"&"/' >> $@.tmp | |||||
$(SED) 's/"/\\"/g' $^ | $(SED) 's/.*/"&\\n"/' >> $@.tmp | |||||
echo ";" >> $@.tmp | echo ";" >> $@.tmp | ||||
mv $@.tmp $@ | mv $@.tmp $@ | ||||
@@ -82,6 +82,65 @@ int ShaderData::nshaders = 0; | |||||
* Public Shader class | * Public Shader class | ||||
*/ | */ | ||||
Shader *Shader::Create(char const *lolfx) | |||||
{ | |||||
char *src = new char[strlen(lolfx) + 2]; | |||||
memcpy(src + 1, lolfx, strlen(lolfx) + 1); | |||||
src[0] = '\n'; | |||||
/* Parse the crap */ | |||||
Array<char const *, char const *> sections; | |||||
char *key = NULL; | |||||
for (char *parser = src; *parser; ) | |||||
{ | |||||
if (key == NULL && (parser[0] == '\n' || parser[0] == '\r') | |||||
&& parser[1] == '-' && parser[2] == '-' && parser[3] == ' ') | |||||
{ | |||||
*parser = '\0'; | |||||
parser += 4; | |||||
key = parser; | |||||
} | |||||
else if (key && parser[0] == ' ') | |||||
{ | |||||
*parser++ = '\0'; | |||||
} | |||||
else if (key && (parser[0] == '\n' || parser[0] == '\r')) | |||||
{ | |||||
sections.Push(key, parser); | |||||
parser++; | |||||
key = NULL; | |||||
} | |||||
else | |||||
{ | |||||
parser++; | |||||
} | |||||
} | |||||
char const *vert = NULL, *frag = NULL; | |||||
for (int i = 0; i < sections.Count(); i++) | |||||
{ | |||||
#if !defined __CELLOS_LV2__ && !defined _XBOX && !defined USE_D3D9 | |||||
if (!strcmp(sections[i].m1, "GLSL.Vert")) | |||||
vert = sections[i].m2; | |||||
if (!strcmp(sections[i].m1, "GLSL.Frag")) | |||||
frag = sections[i].m2; | |||||
#else | |||||
if (!strcmp(sections[i].m1, "HLSL.Vert")) | |||||
vert = sections[i].m2; | |||||
if (!strcmp(sections[i].m1, "HLSL.Frag")) | |||||
frag = sections[i].m2; | |||||
#endif | |||||
} | |||||
Shader *ret = NULL; | |||||
if (vert && frag) | |||||
ret = Create(vert, frag); | |||||
delete[] src; | |||||
return ret; | |||||
} | |||||
Shader *Shader::Create(char const *vert, char const *frag) | Shader *Shader::Create(char const *vert, char const *frag) | ||||
{ | { | ||||
uint32_t new_vert_crc = Hash::Crc32(vert); | uint32_t new_vert_crc = Hash::Crc32(vert); | ||||
@@ -51,6 +51,7 @@ class ShaderData; | |||||
class Shader | class Shader | ||||
{ | { | ||||
public: | public: | ||||
static Shader *Create(char const *lolfx); | |||||
static Shader *Create(char const *vert, char const *frag); | static Shader *Create(char const *vert, char const *frag); | ||||
static void Destroy(Shader *shader); | static void Destroy(Shader *shader); | ||||
@@ -31,6 +31,8 @@ using namespace lol; | |||||
# include <direct.h> | # include <direct.h> | ||||
#endif | #endif | ||||
extern char const *lolfx_01_triangle; | |||||
class Triangle : public WorldEntity | class Triangle : public WorldEntity | ||||
{ | { | ||||
public: | public: | ||||
@@ -48,29 +50,7 @@ public: | |||||
if (!m_ready) | if (!m_ready) | ||||
{ | { | ||||
m_shader = Shader::Create( | |||||
#if !defined __CELLOS_LV2__ && !defined _XBOX && !defined USE_D3D9 | |||||
"#version 120\n" | |||||
"attribute vec2 in_Position;" | |||||
"void main(void) {" | |||||
" gl_Position = vec4(in_Position, 0.0, 1.0);" | |||||
"}", | |||||
"#version 120\n" | |||||
"void main(void) {" | |||||
" gl_FragColor = vec4(0.7, 0.2, 0.5, 1.0);" | |||||
"}" | |||||
#else | |||||
"void main(float2 in_Position : POSITION," | |||||
" out float4 out_Position : POSITION) {" | |||||
" out_Position = float4(in_Position, 0.0, 1.0);" | |||||
"}", | |||||
"void main(out float4 out_FragColor : COLOR) {" | |||||
" out_FragColor = float4(0.7, 0.2, 0.5, 1.0);" | |||||
"}" | |||||
#endif | |||||
); | |||||
m_shader = Shader::Create(lolfx_01_triangle); | |||||
m_coord = m_shader->GetAttribLocation("in_Position", VertexUsage::Position, 0); | m_coord = m_shader->GetAttribLocation("in_Position", VertexUsage::Position, 0); | ||||
m_vdecl = new VertexDeclaration(VertexStream<vec2>(VertexUsage::Position)); | m_vdecl = new VertexDeclaration(VertexStream<vec2>(VertexUsage::Position)); | ||||
@@ -0,0 +1,35 @@ | |||||
-- GLSL.Vert -- | |||||
#version 120 | |||||
attribute vec2 in_Position; | |||||
void main(void) | |||||
{ | |||||
gl_Position = vec4(in_Position, 0.0, 1.0); | |||||
} | |||||
-- GLSL.Frag -- | |||||
#version 120 | |||||
void main(void) | |||||
{ | |||||
gl_FragColor = vec4(0.7, 0.2, 0.5, 1.0); | |||||
} | |||||
-- HLSL.Vert -- | |||||
void main(float2 in_Position : POSITION, | |||||
out float4 out_Position : POSITION) | |||||
{ | |||||
out_Position = float4(in_Position, 0.0, 1.0); | |||||
} | |||||
-- HLSL.Frag -- | |||||
void main(out float4 out_FragColor : COLOR) | |||||
{ | |||||
out_FragColor = float4(0.7, 0.2, 0.5, 1.0); | |||||
} | |||||
@@ -10,9 +10,18 @@ CLEANFILES = $(noinst_PROGRAMS:%$(EXEEXT)=%.self) \ | |||||
$(noinst_PROGRAMS:%$(EXEEXT)=%.elf) \ | $(noinst_PROGRAMS:%$(EXEEXT)=%.elf) \ | ||||
$(noinst_PROGRAMS:%$(EXEEXT)=%.exe) | $(noinst_PROGRAMS:%$(EXEEXT)=%.exe) | ||||
SUFFIXES = .lolfx | |||||
%.lolfx.cpp: %.lolfx | |||||
echo "/* This file was autogenerated. DO NOT MODIFY IT. */" > $@.tmp | |||||
echo "char const *lolfx_$(notdir $(^:%.lolfx=%)) =" >> $@.tmp | |||||
$(SED) 's/"/\\"/g' $^ | $(SED) 's/.*/"&\\n"/' >> $@.tmp | |||||
echo ";" >> $@.tmp | |||||
mv $@.tmp $@ | |||||
noinst_PROGRAMS = 01_triangle 02_cube 03_fractal | noinst_PROGRAMS = 01_triangle 02_cube 03_fractal | ||||
01_triangle_SOURCES = 01_triangle.cpp | 01_triangle_SOURCES = 01_triangle.cpp | ||||
nodist_01_triangle_SOURCES = 01_triangle.lolfx.cpp | |||||
01_triangle_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@ | 01_triangle_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@ | ||||
01_triangle_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@ | 01_triangle_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@ | ||||
01_triangle_DEPENDENCIES = $(top_builddir)/src/liblol.a | 01_triangle_DEPENDENCIES = $(top_builddir)/src/liblol.a | ||||
@@ -29,6 +29,9 @@ | |||||
<ItemGroup> | <ItemGroup> | ||||
<ClCompile Include="..\test\tutorial\01_triangle.cpp" /> | <ClCompile Include="..\test\tutorial\01_triangle.cpp" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | |||||
<LolFxCompile Include="..\test\tutorial\01_triangle.lolfx" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="lolcore.vcxproj"> | <ProjectReference Include="lolcore.vcxproj"> | ||||
<Project>{9e62f2fe-3408-4eae-8238-fd84238ceeda}</Project> | <Project>{9e62f2fe-3408-4eae-8238-fd84238ceeda}</Project> | ||||