Ignore:
Timestamp:
Feb 5, 2013, 5:07:09 PM (7 years ago)
Author:
touky
Message:

render : Added DebugRenderMode & corresponding shaders. naive (VERY) implementation in MeshViewer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/easymesh/easymesh.cpp

    r2350 r2370  
    3737
    3838LOLFX_RESOURCE_DECLARE(shiny);
     39LOLFX_RESOURCE_DECLARE(shinydebugwireframe);
     40LOLFX_RESOURCE_DECLARE(shinydebuglighting);
     41LOLFX_RESOURCE_DECLARE(shinydebugnormal);
     42LOLFX_RESOURCE_DECLARE(shinydebugUV);
     43LOLFX_RESOURCE_DECLARE(shiny_SK);
    3944
    4045namespace lol
     
    6570void EasyMesh::MeshConvert(Shader* provided_shader)
    6671{
    67     if(provided_shader == NULL)
    68     {
    69         m_gpu.shader = Shader::Create(LOLFX_RESOURCE_NAME(shiny));
    70     }
    71     else
    72     {
    73         m_gpu.shader = provided_shader;
    74     }
    75 
    76     m_gpu.modelview = m_gpu.shader->GetUniformLocation("in_ModelView");
    77     m_gpu.view = m_gpu.shader->GetUniformLocation("in_View");
    78     m_gpu.invview = m_gpu.shader->GetUniformLocation("in_Inv_View");
    79     m_gpu.proj = m_gpu.shader->GetUniformLocation("in_Proj");
    80     m_gpu.normalmat = m_gpu.shader->GetUniformLocation("in_NormalMat");
    81     m_gpu.damage = m_gpu.shader->GetUniformLocation("in_Damage");
    82     m_gpu.lights = m_gpu.shader->GetUniformLocation("u_Lights");
    83     m_gpu.coord = m_gpu.shader->GetAttribLocation("in_Vertex",
    84                                           VertexUsage::Position, 0);
    85     m_gpu.norm = m_gpu.shader->GetAttribLocation("in_Normal",
    86                                          VertexUsage::Normal, 0);
    87     m_gpu.color = m_gpu.shader->GetAttribLocation("in_Color",
    88                                           VertexUsage::Color, 0);
     72    for (int i = 0; i < DebugRenderMode::Max; i++)
     73    {
     74        if (i == DebugRenderMode::Default)
     75        {
     76            if(provided_shader == NULL)
     77                m_gpu.shader << Shader::Create(LOLFX_RESOURCE_NAME(shiny));
     78            else
     79                m_gpu.shader << provided_shader;
     80        }
     81        else if (i == DebugRenderMode::Wireframe)
     82                m_gpu.shader << Shader::Create(LOLFX_RESOURCE_NAME(shinydebugwireframe));
     83        else if (i == DebugRenderMode::Lighting)
     84                m_gpu.shader << Shader::Create(LOLFX_RESOURCE_NAME(shinydebuglighting));
     85        else if (i == DebugRenderMode::Normal)
     86                m_gpu.shader << Shader::Create(LOLFX_RESOURCE_NAME(shinydebugnormal));
     87        else if (i == DebugRenderMode::UV)
     88                m_gpu.shader << Shader::Create(LOLFX_RESOURCE_NAME(shinydebugUV));
     89
     90        m_gpu.modelview << m_gpu.shader.Last()->GetUniformLocation("in_ModelView");
     91        m_gpu.view << m_gpu.shader.Last()->GetUniformLocation("in_View");
     92        m_gpu.invview << m_gpu.shader.Last()->GetUniformLocation("in_Inv_View");
     93        m_gpu.proj << m_gpu.shader.Last()->GetUniformLocation("in_Proj");
     94        m_gpu.normalmat << m_gpu.shader.Last()->GetUniformLocation("in_NormalMat");
     95        m_gpu.damage << m_gpu.shader.Last()->GetUniformLocation("in_Damage");
     96        m_gpu.lights << m_gpu.shader.Last()->GetUniformLocation("u_Lights");
     97        m_gpu.coord << m_gpu.shader.Last()->GetAttribLocation("in_Vertex",
     98                                              VertexUsage::Position, 0);
     99        m_gpu.norm << m_gpu.shader.Last()->GetAttribLocation("in_Normal",
     100                                             VertexUsage::Normal, 0);
     101        m_gpu.color << m_gpu.shader.Last()->GetAttribLocation("in_Color",
     102                                              VertexUsage::Color, 0);
     103    }
    89104
    90105    m_gpu.vdecl = new VertexDeclaration(
     
    123138void EasyMesh::Render(mat4 const &model, float damage)
    124139{
     140    DebugRenderMode d = Video::GetDebugRenderMode();
     141
    125142    mat4 modelview = Scene::GetDefault()->GetViewMatrix() * model;
    126143    mat3 normalmat = transpose(inverse(mat3(modelview)));
    127144
    128     m_gpu.shader->Bind();
     145    m_gpu.shader[d]->Bind();
    129146
    130147    /* FIXME: this should be hidden in the shader */
     
    136153    while (light_data.Count() < 8)
    137154        light_data << vec4(0.f) << vec4(0.f);
    138     m_gpu.shader->SetUniform(m_gpu.lights, light_data);
    139 
    140     m_gpu.shader->SetUniform(m_gpu.modelview, modelview);
    141     m_gpu.shader->SetUniform(m_gpu.view, Scene::GetDefault()->GetViewMatrix());
    142     m_gpu.shader->SetUniform(m_gpu.invview, inverse(Scene::GetDefault()->GetViewMatrix()));
    143     m_gpu.shader->SetUniform(m_gpu.proj, Scene::GetDefault()->GetProjMatrix());
    144     m_gpu.shader->SetUniform(m_gpu.normalmat, normalmat);
    145     m_gpu.shader->SetUniform(m_gpu.damage, damage);
     155    m_gpu.shader[d]->SetUniform(m_gpu.lights[d], light_data);
     156
     157    m_gpu.shader[d]->SetUniform(m_gpu.modelview[d], modelview);
     158    m_gpu.shader[d]->SetUniform(m_gpu.view[d], Scene::GetDefault()->GetViewMatrix());
     159    m_gpu.shader[d]->SetUniform(m_gpu.invview[d], inverse(Scene::GetDefault()->GetViewMatrix()));
     160    m_gpu.shader[d]->SetUniform(m_gpu.proj[d], Scene::GetDefault()->GetProjMatrix());
     161    m_gpu.shader[d]->SetUniform(m_gpu.normalmat[d], normalmat);
     162    m_gpu.shader[d]->SetUniform(m_gpu.damage[d], damage);
    146163    m_gpu.vdecl->Bind();
    147     m_gpu.vdecl->SetStream(m_gpu.vbo, m_gpu.coord, m_gpu.norm, m_gpu.color);
     164    m_gpu.vdecl->SetStream(m_gpu.vbo, m_gpu.coord[d], m_gpu.norm[d], m_gpu.color[d]);
    148165    m_gpu.ibo->Bind();
    149166    m_gpu.vdecl->DrawIndexedElements(MeshPrimitive::Triangles,
Note: See TracChangeset for help on using the changeset viewer.