From 3adf42b00cd6b897340085b048a0f18a8a89e849 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 25 Jan 2013 15:48:37 +0000 Subject: [PATCH] build: hide LolFx external declarations behind macros. --- build/autotools/common.am | 2 +- src/core.h | 5 +++++ src/easymesh/easymesh.cpp | 4 ++-- src/gradient.cpp | 4 ++-- src/scene.cpp | 4 ++-- tutorial/01_triangle.cpp | 4 ++-- tutorial/02_cube.cpp | 4 ++-- tutorial/03_noise.cpp | 4 ++-- tutorial/04_texture.cpp | 4 ++-- tutorial/08_fbo.cpp | 4 ++-- tutorial/11_fractal.cpp | 4 ++-- 11 files changed, 24 insertions(+), 19 deletions(-) diff --git a/build/autotools/common.am b/build/autotools/common.am index 60c1d007..555a5369 100644 --- a/build/autotools/common.am +++ b/build/autotools/common.am @@ -61,7 +61,7 @@ SUFFIXES += .lolfx .lolfx.o: $(lolfx_gen) $(AM_V_at)(echo "char const *"; \ - echo "lolfx_$(notdir $(basename $(filter %.lolfx, $^))) ="; \ + echo "lolfx_resource_$(notdir $(basename $(filter %.lolfx, $^))) ="; \ $(SED) 's/"/\\"/g' $(filter %.lolfx, $^) | $(SED) 's/\([^\r]*\).*/"\1\\n"/'; \ echo ";") \ | $(CXXCOMPILE) -xc++ -c - -o $@ diff --git a/src/core.h b/src/core.h index c56fd78a..ca338a51 100644 --- a/src/core.h +++ b/src/core.h @@ -61,6 +61,11 @@ static inline int isnan(float f) } #endif +/* External declaration for LolFx files. */ +#define LOLFX_RESOURCE_DECLARE(name) \ + extern "C" char const *LOLFX_RESOURCE_NAME(name) +#define LOLFX_RESOURCE_NAME(name) lolfx_resource_##name + /* If using NaCl or Android, override main() with our version */ #if defined __native_client__ # define main lol_nacl_main diff --git a/src/easymesh/easymesh.cpp b/src/easymesh/easymesh.cpp index fcc4c7d1..18c0f52a 100644 --- a/src/easymesh/easymesh.cpp +++ b/src/easymesh/easymesh.cpp @@ -35,7 +35,7 @@ #include "core.h" #include "easymesh/easymesh-compiler.h" -extern char const *lolfx_shiny; +LOLFX_RESOURCE_DECLARE(shiny); namespace lol { @@ -66,7 +66,7 @@ void EasyMesh::MeshConvert(Shader* provided_shader) { if(provided_shader == NULL) { - m_gpu.shader = Shader::Create(lolfx_shiny); + m_gpu.shader = Shader::Create(LOLFX_RESOURCE_NAME(shiny)); } else { diff --git a/src/gradient.cpp b/src/gradient.cpp index cc7320d0..6522ff24 100644 --- a/src/gradient.cpp +++ b/src/gradient.cpp @@ -17,7 +17,7 @@ using namespace std; -extern char const *lolfx_gradient; +LOLFX_RESOURCE_DECLARE(gradient); namespace lol { @@ -76,7 +76,7 @@ void Gradient::TickDraw(float seconds) if (!data->shader) { - data->shader = Shader::Create(lolfx_gradient); + data->shader = Shader::Create(LOLFX_RESOURCE_NAME(gradient)); data->m_vbo = new VertexBuffer(sizeof(vertex)); data->m_cbo = new VertexBuffer(sizeof(color)); diff --git a/src/scene.cpp b/src/scene.cpp index 8d0f8d45..a3765145 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -22,7 +22,7 @@ #include "core.h" #include "lolgl.h" -extern char const *lolfx_tile; +LOLFX_RESOURCE_DECLARE(tile); namespace lol { @@ -156,7 +156,7 @@ void Scene::Render() // XXX: rename to Blit() return; if (!data->m_shader) - data->m_shader = Shader::Create(lolfx_tile); + data->m_shader = Shader::Create(LOLFX_RESOURCE_NAME(tile)); #if 0 // Randomise, then sort. diff --git a/tutorial/01_triangle.cpp b/tutorial/01_triangle.cpp index 538d790b..3b481f81 100644 --- a/tutorial/01_triangle.cpp +++ b/tutorial/01_triangle.cpp @@ -18,7 +18,7 @@ using namespace std; using namespace lol; -extern char const *lolfx_01_triangle; +LOLFX_RESOURCE_DECLARE(01_triangle); class Triangle : public WorldEntity { @@ -37,7 +37,7 @@ public: if (!m_ready) { - m_shader = Shader::Create(lolfx_01_triangle); + m_shader = Shader::Create(LOLFX_RESOURCE_NAME(01_triangle)); m_coord = m_shader->GetAttribLocation("in_Position", VertexUsage::Position, 0); m_vdecl = new VertexDeclaration(VertexStream(VertexUsage::Position)); diff --git a/tutorial/02_cube.cpp b/tutorial/02_cube.cpp index 8d38bd1a..60d48488 100644 --- a/tutorial/02_cube.cpp +++ b/tutorial/02_cube.cpp @@ -18,7 +18,7 @@ using namespace std; using namespace lol; -extern char const *lolfx_02_cube; +LOLFX_RESOURCE_DECLARE(02_cube); class Cube : public WorldEntity { @@ -74,7 +74,7 @@ public: if (!m_ready) { - m_shader = Shader::Create(lolfx_02_cube); + m_shader = Shader::Create(LOLFX_RESOURCE_NAME(02_cube)); m_mvp = m_shader->GetUniformLocation("in_Matrix"); m_coord = m_shader->GetAttribLocation("in_Vertex", diff --git a/tutorial/03_noise.cpp b/tutorial/03_noise.cpp index 21c6e913..35531e19 100644 --- a/tutorial/03_noise.cpp +++ b/tutorial/03_noise.cpp @@ -18,7 +18,7 @@ using namespace std; using namespace lol; -extern char const *lolfx_03_noise; +LOLFX_RESOURCE_DECLARE(03_noise); class NoiseDemo : public WorldEntity { @@ -44,7 +44,7 @@ public: if (!m_ready) { - m_shader = Shader::Create(lolfx_03_noise); + m_shader = Shader::Create(LOLFX_RESOURCE_NAME(03_noise)); m_coord = m_shader->GetAttribLocation("in_Position", VertexUsage::Position, 0); m_time_uni = m_shader->GetUniformLocation("u_Time"); diff --git a/tutorial/04_texture.cpp b/tutorial/04_texture.cpp index d9501a26..b670c4ea 100644 --- a/tutorial/04_texture.cpp +++ b/tutorial/04_texture.cpp @@ -20,7 +20,7 @@ using namespace lol; static int const TEXTURE_WIDTH = 256; -extern char const *lolfx_04_texture; +LOLFX_RESOURCE_DECLARE(04_texture); class TextureDemo : public WorldEntity { @@ -74,7 +74,7 @@ public: { m_texture = new Texture(ivec2(TEXTURE_WIDTH, 1), PixelFormat::A8R8G8B8); - m_shader = Shader::Create(lolfx_04_texture); + m_shader = Shader::Create(LOLFX_RESOURCE_NAME(04_texture)); m_coord = m_shader->GetAttribLocation("in_Position", VertexUsage::Position, 0); m_vdecl = new VertexDeclaration(VertexStream(VertexUsage::Position)); diff --git a/tutorial/08_fbo.cpp b/tutorial/08_fbo.cpp index 683e50cd..b0f89ff2 100644 --- a/tutorial/08_fbo.cpp +++ b/tutorial/08_fbo.cpp @@ -18,7 +18,7 @@ using namespace std; using namespace lol; -extern char const *lolfx_08_fbo; +LOLFX_RESOURCE_DECLARE(08_fbo); class FBO : public WorldEntity { @@ -56,7 +56,7 @@ public: if (!m_ready) { - m_shader = Shader::Create(lolfx_08_fbo); + m_shader = Shader::Create(LOLFX_RESOURCE_NAME(08_fbo)); m_coord = m_shader->GetAttribLocation("in_Position", VertexUsage::Position, 0); m_uni_flag = m_shader->GetUniformLocation("in_Flag"); m_uni_point = m_shader->GetUniformLocation("in_Point"); diff --git a/tutorial/11_fractal.cpp b/tutorial/11_fractal.cpp index c90dc313..c9a4b7c2 100644 --- a/tutorial/11_fractal.cpp +++ b/tutorial/11_fractal.cpp @@ -20,7 +20,7 @@ using namespace lol; -extern char const *lolfx_11_fractal; +LOLFX_RESOURCE_DECLARE(11_fractal); class Fractal : public WorldEntity { @@ -448,7 +448,7 @@ public: * uploading subimages will not work. */ m_texture->SetData(&m_pixels[0]); - m_shader = Shader::Create(lolfx_11_fractal); + m_shader = Shader::Create(LOLFX_RESOURCE_NAME(11_fractal)); m_vertexattrib = m_shader->GetAttribLocation("a_Vertex", VertexUsage::Position, 0); m_texattrib = m_shader->GetAttribLocation("a_TexCoord", VertexUsage::TexCoord, 0);