Browse Source

MeshViewer : Added Basic shader to "RenderProof" (ahem...) emscripten

undefined
Benjamin ‘Touky’ Huet Sam Hocevar <sam@hocevar.net> 11 years ago
parent
commit
3fde4eaa8e
5 changed files with 73 additions and 3 deletions
  1. +1
    -1
      test/Makefile.am
  2. +1
    -1
      test/data/mesh-buffer.txt
  3. +38
    -1
      test/meshviewer.cpp
  4. +1
    -0
      test/meshviewer.vcxproj
  5. +32
    -0
      test/mviewer_em_test.lolfx

+ 1
- 1
test/Makefile.am View File

@@ -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


+ 1
- 1
test/data/mesh-buffer.txt View File

@@ -1,4 +1,4 @@
sc#fff ab 2 tx 2 tz 1 splt 6 bdzy -90
sc#fff ab 2
//splt 0
//test


+ 38
- 1
test/meshviewer.cpp View File

@@ -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;


+ 1
- 0
test/meshviewer.vcxproj View File

@@ -70,6 +70,7 @@
<None Include="TypeDictionnary.js" />
</ItemGroup>
<ItemGroup>
<LolFxCompile Include="mviewer_em_test.lolfx" />
<LolFxCompile Include="shinyfur.lolfx" />
<LolFxCompile Include="shinymvtexture.lolfx" />
</ItemGroup>


+ 32
- 0
test/mviewer_em_test.lolfx View File

@@ -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;
}

Loading…
Cancel
Save