Changeset 2370


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

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

Location:
trunk
Files:
5 added
8 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,
  • trunk/src/easymesh/easymesh.h

    r2356 r2370  
    155155    struct
    156156    {
    157         Shader *shader;
    158         ShaderAttrib coord, norm, color;
    159         ShaderUniform modelview, view, invview, proj, normalmat, damage, lights;
     157        /* FIXME: very naughty way of handling debug render modes */
     158        Array<Shader *>shader;
     159        Array<ShaderAttrib> coord, norm, color;
     160        Array<ShaderUniform> modelview, view, invview, proj, normalmat, damage, lights;
     161
    160162        VertexDeclaration *vdecl;
    161163        VertexBuffer *vbo;
  • trunk/src/gpu/vertexbuffer.cpp

    r2216 r2370  
    159159    /* FIXME: this has nothing to do here! */
    160160    glFrontFace(GL_CCW);
    161     glEnable(GL_CULL_FACE);
    162161    glEnable(GL_BLEND);
    163162    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     
    223222    /* FIXME: this has nothing to do here! */
    224223    glFrontFace(GL_CCW);
    225     glEnable(GL_CULL_FACE);
    226224    glEnable(GL_BLEND);
    227225    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  • trunk/src/lolcore.vcxproj

    r2359 r2370  
    643643  <ItemGroup>
    644644    <LolFxCompile Include="easymesh\shiny.lolfx" />
     645    <LolFxCompile Include="easymesh\shinydebuglighting.lolfx" />
     646    <LolFxCompile Include="easymesh\shinydebugnormal.lolfx" />
     647    <LolFxCompile Include="easymesh\shinydebugUV.lolfx" />
     648    <LolFxCompile Include="easymesh\shinydebugwireframe.lolfx" />
     649    <LolFxCompile Include="easymesh\shiny_SK.lolfx" />
    645650    <LolFxCompile Include="gpu\defaultmaterial.lolfx" />
    646651    <LolFxCompile Include="gpu\emptymaterial.lolfx" />
  • trunk/src/lolcore.vcxproj.filters

    r2367 r2370  
    16991699    <LolFxCompile Include="gpu\tile.lolfx">
    17001700      <Filter>...</Filter>
     1701    </LolFxCompile>
     1702    <LolFxCompile Include="easymesh\shiny_SK.lolfx">
     1703      <Filter>easymesh</Filter>
     1704    </LolFxCompile>
     1705    <LolFxCompile Include="easymesh\shinydebuglighting.lolfx">
     1706      <Filter>easymesh</Filter>
     1707    </LolFxCompile>
     1708    <LolFxCompile Include="easymesh\shinydebugnormal.lolfx">
     1709      <Filter>easymesh</Filter>
     1710    </LolFxCompile>
     1711    <LolFxCompile Include="easymesh\shinydebugUV.lolfx">
     1712      <Filter>easymesh</Filter>
     1713    </LolFxCompile>
     1714    <LolFxCompile Include="easymesh\shinydebugwireframe.lolfx">
     1715      <Filter>easymesh</Filter>
    17011716    </LolFxCompile>
    17021717  </ItemGroup>
  • trunk/src/video.cpp

    r2216 r2370  
    5252    static mat4 proj_matrix;
    5353    static ivec2 saved_viewport;
     54    static DebugRenderMode render_mode;
    5455#if defined USE_D3D9 || defined _XBOX
    5556#   if defined USE_D3D9
     
    6768mat4 VideoData::proj_matrix;
    6869ivec2 VideoData::saved_viewport(0, 0);
     70DebugRenderMode VideoData::render_mode = DebugRenderMode::Default;
    6971
    7072#if defined USE_D3D9 || defined _XBOX
     
    154156    SetClearColor(vec4(0.1f, 0.2f, 0.3f, 1.0f));
    155157    SetClearDepth(1.f);
     158    SetDebugRenderMode(DebugRenderMode::Default);
    156159}
    157160
     
    231234    glClearDepth(f);
    232235#endif
     236}
     237
     238void Video::SetDebugRenderMode(DebugRenderMode d)
     239{
     240    if (d == DebugRenderMode::Max)
     241        return;
     242
     243    switch(d)
     244    {
     245        //All these modes are handled in the shaders.
     246        case DebugRenderMode::Default:
     247        case DebugRenderMode::Lighting:
     248        case DebugRenderMode::Normal:
     249        case DebugRenderMode::UV:
     250        {
     251#if defined USE_D3D9 || defined _XBOX
     252#else
     253            glEnable(GL_CULL_FACE);
     254            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
     255#endif
     256            break;
     257        }
     258        case DebugRenderMode::Wireframe:
     259        {
     260            if (VideoData::render_mode == DebugRenderMode::Wireframe)
     261            {
     262#if defined USE_D3D9 || defined _XBOX
     263#else
     264                if (glIsEnabled(GL_CULL_FACE) == GL_TRUE)
     265                    glDisable(GL_CULL_FACE);
     266                else
     267                    glEnable(GL_CULL_FACE);
     268#endif
     269            }
     270            else
     271            {
     272#if defined USE_D3D9 || defined _XBOX
     273#else
     274                glDisable(GL_CULL_FACE);
     275#endif
     276            }
     277#if defined USE_D3D9 || defined _XBOX
     278#else
     279            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
     280#endif
     281            break;
     282        }
     283    }
     284    VideoData::render_mode = d;
     285}
     286
     287DebugRenderMode Video::GetDebugRenderMode()
     288{
     289    return VideoData::render_mode;
    233290}
    234291
  • trunk/src/video.h

    r2183 r2370  
    4242};
    4343
     44struct DebugRenderMode
     45{
     46    enum Value
     47    {
     48        //Add your new rendermode at your convenience
     49        Default,
     50        Wireframe,
     51        Lighting,
     52        Normal,
     53        UV,
     54
     55        Max
     56    }
     57    m_value;
     58
     59    inline DebugRenderMode(Value v) : m_value(v) {}
     60    inline operator Value() { return m_value; }
     61};
     62
    4463class Video
    4564{
     
    5170    static void SetClearColor(vec4 color);
    5271    static void SetClearDepth(float f);
     72    static void SetDebugRenderMode(DebugRenderMode d);
     73    static DebugRenderMode GetDebugRenderMode();
    5374    static void Clear(ClearMask m);
    5475    static void Capture(uint32_t *buffer);
  • trunk/test/MeshViewer.cpp

    r2364 r2370  
    5151        //FOV compensation doesn't work
    5252        ivec2 video_size = Video::GetSize();
    53         float near = -video_size.x - video_size.y;
    54         float far = video_size.x + video_size.y;
     53        float near = (float)-video_size.x - video_size.y;
     54        float far = (float)video_size.x + video_size.y;
    5555        float t1 = tanf(new_fov / 2);
    56         float dist = video_size.x / (2.0f * t1);
     56        float dist = (float)video_size.x / (2.0f * t1);
    5757        //m_fov_compensation = mat4::translate(-0.5f * video_size.x, -0.5f * video_size.y, -dist);
    5858        m_fov_compensation = mat4::translate(vec3(.0f));
     
    157157        WorldEntity::TickGame(seconds);
    158158
    159         //Shutdown logic
    160         if (Input::WasReleased(Key::Escape))
    161             Ticker::Shutdown();
     159        //TODO : This should probably be "standard LoL behaviour"
     160        {
     161            //Shutdown logic
     162            if (Input::WasReleased(Key::Escape))
     163                Ticker::Shutdown();
     164        }
    162165
    163166        //Update Mesh BBox - Get the Min/Max needed
     
    283286    {
    284287        WorldEntity::TickDraw(seconds);
     288
     289        //TODO : This should probably be "standard LoL behaviour"
     290        {
     291            if (Input::WasReleased(Key::F1))
     292                Video::SetDebugRenderMode(DebugRenderMode::Default);
     293            if (Input::WasReleased(Key::F2))
     294                Video::SetDebugRenderMode(DebugRenderMode::Wireframe);
     295            if (Input::WasReleased(Key::F3))
     296                Video::SetDebugRenderMode(DebugRenderMode::Lighting);
     297            if (Input::WasReleased(Key::F4))
     298                Video::SetDebugRenderMode(DebugRenderMode::Normal);
     299            if (Input::WasReleased(Key::F5))
     300                Video::SetDebugRenderMode(DebugRenderMode::UV);
     301        }
    285302
    286303        for (int i = 0; i < m_meshes.Count(); i++)
Note: See TracChangeset for help on using the changeset viewer.