From 3fde4eaa8e5ae33f3de54af98b4d1a7a7b98dce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20=E2=80=98Touky=E2=80=99=20Huet?= Date: Wed, 25 Sep 2013 19:04:32 +0000 Subject: [PATCH] MeshViewer : Added Basic shader to "RenderProof" (ahem...) emscripten --- test/Makefile.am | 2 +- test/data/mesh-buffer.txt | 2 +- test/meshviewer.cpp | 39 +++++++++++++++++++++++++++++++++++++- test/meshviewer.vcxproj | 1 + test/mviewer_em_test.lolfx | 32 +++++++++++++++++++++++++++++++ 5 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 test/mviewer_em_test.lolfx diff --git a/test/Makefile.am b/test/Makefile.am index 4d692813..1345bd13 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -58,7 +58,7 @@ nacl_phystest_DEPENDENCIES = @LOL_DEPS@ nacl_phystest_LDFLAGS = $(AM_LDFLAGS) meshviewer_SOURCES = meshviewer.cpp \ - shinymvtexture.lolfx shinyfur.lolfx + shinymvtexture.lolfx shinyfur.lolfx mviewer_em_test.lolfx meshviewer_CPPFLAGS = $(AM_CPPFLAGS) meshviewer_DEPENDENCIES = @LOL_DEPS@ if USE_EMSCRIPTEN diff --git a/test/data/mesh-buffer.txt b/test/data/mesh-buffer.txt index f9c435ee..7513af44 100644 --- a/test/data/mesh-buffer.txt +++ b/test/data/mesh-buffer.txt @@ -1,4 +1,4 @@ -sc#fff ab 2 tx 2 tz 1 splt 6 bdzy -90 +sc#fff ab 2 //splt 0 //test diff --git a/test/meshviewer.cpp b/test/meshviewer.cpp index dcac805e..d766d583 100644 --- a/test/meshviewer.cpp +++ b/test/meshviewer.cpp @@ -45,6 +45,7 @@ static int const TEXTURE_WIDTH = 256; #define HST_CLAMP 1.f #define WITH_TEXTURE 0 +#define EM_TEST (1 && EMSCRIPTEN) #define NO_NACL_EM (!__native_client__ && !EMSCRIPTEN) #define NACL_EM (__native_client__ || EMSCRIPTEN) @@ -84,6 +85,38 @@ enum MessageType MSG_MAX }; +LOLFX_RESOURCE_DECLARE(mviewer_em_test); + +class MVTestShaderData : public GpuShaderData +{ +public: + //----------------------------------------------------------------------------- + MVTestShaderData::MVTestShaderData() + { + m_render_mode = DebugRenderMode::Default; + m_vert_decl_flags = (1 << VertexUsage::Position) | (1 << VertexUsage::Color); + m_shader = Shader::Create(LOLFX_RESOURCE_NAME(mviewer_em_test)); + SetupDefaultData(false); + } + + //----------------------------------------------------------------------------- + void MVTestShaderData::SetupDefaultData(bool with_UV) + { + AddUniform("in_ModelView"); + AddUniform("in_Proj"); + } + + //----------------------------------------------------------------------------- + void MVTestShaderData::SetupShaderDatas(mat4 const &model) + { + mat4 proj = g_scene->GetCamera()->GetProjection(); + mat4 view = g_scene->GetCamera()->GetView(); + + m_shader->SetUniform(*GetUniform("in_ModelView"), view * model); + m_shader->SetUniform(*GetUniform("in_Proj"), proj); + } +}; + class MeshViewer : public WorldEntity { public: @@ -458,7 +491,9 @@ public: { if (m_meshes[i]->GetMeshState() == MeshRender::NeedConvert) { -#if WITH_TEXTURE +#if EM_TEST + m_meshes[i]->MeshConvert(new MVTestShaderData()); +#elif WITH_TEXTURE m_meshes[i]->MeshConvert(new DefaultShaderData(((1 << VertexUsage::Position) | (1 << VertexUsage::Normal) | (1 << VertexUsage::Color) | (1 << VertexUsage::TexCoord)), m_texture_shader, true)); @@ -536,6 +571,8 @@ private: float m_stream_update_time; float m_stream_update_timer; + Shader * m_test_shader; + //misc datas Shader * m_texture_shader; TileSet * m_default_texture; diff --git a/test/meshviewer.vcxproj b/test/meshviewer.vcxproj index 8b422b03..e40c2711 100644 --- a/test/meshviewer.vcxproj +++ b/test/meshviewer.vcxproj @@ -70,6 +70,7 @@ + diff --git a/test/mviewer_em_test.lolfx b/test/mviewer_em_test.lolfx new file mode 100644 index 00000000..f5cc223c --- /dev/null +++ b/test/mviewer_em_test.lolfx @@ -0,0 +1,32 @@ + +[vert.glsl] +#version 120 + +attribute vec3 in_Position; +attribute vec4 in_Color; + +uniform mat4 in_ModelView; +uniform mat4 in_Proj; + +varying vec4 pass_Color; + +void main(void) +{ + pass_Color = in_Color; + + gl_Position = in_Proj * in_ModelView * vec4(in_Position, 1.0); +} + +[frag.glsl] +#version 120 + +#if defined GL_ES +precision highp float; +#endif + +varying vec4 pass_Color; + +void main(void) +{ + gl_FragColor = pass_Color; +}