Changeset 2761


Ignore:
Timestamp:
Jun 22, 2013, 4:10:11 PM (6 years ago)
Author:
sam
Message:

gpu: implement face culling mode in render contexts.

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core.h

    r2704 r2761  
    8686
    8787
     88/* XXX: workaround for X11 headers that try to #define None */
     89#undef None
     90#define None None
     91
     92
    8893/* External declaration for LolFx files. */
    8994#define LOLFX_RESOURCE_DECLARE(name) \
  • trunk/src/gpu/rendercontext.cpp

    r2760 r2761  
    6262    TrackedState<bool> m_alpha_test;
    6363    TrackedState<bool> m_depth_test;
    64     TrackedState<bool> m_face_culling;
     64    TrackedState<CullMode> m_face_culling;
    6565};
    6666
     
    152152}
    153153
    154 void RenderContext::SetFaceCulling(bool set)
     154void RenderContext::SetFaceCulling(CullMode mode)
    155155{
    156156    if (!m_data->m_face_culling.HasChanged())
    157157        m_data->m_face_culling.TrackValue(g_renderer->GetFaceCulling());
    158158
    159     g_renderer->SetFaceCulling(set);
     159    g_renderer->SetFaceCulling(mode);
    160160}
    161161
  • trunk/src/gpu/renderer.cpp

    r2760 r2761  
    3232#include "lolgl.h"
    3333
     34#if defined USE_D3D9
     35extern IDirect3DDevice9 *g_d3ddevice;
     36#elif defined _XBOX
     37extern D3DDevice *g_d3ddevice;
     38#endif
     39
    3440namespace lol
    3541{
     
    5157    float m_clear_depth;
    5258    BlendFactor m_blend_src, m_blend_dst;
    53     bool m_alpha_blend, m_alpha_test, m_depth_test, m_face_culling;
     59    CullMode m_face_culling;
     60    bool m_alpha_blend, m_alpha_test, m_depth_test;
     61
     62#if defined USE_D3D9
     63    IDirect3DDevice9 *m_d3d_dev;
     64#elif defined _XBOX
     65    D3DDevice *m_d3d_dev;
     66#endif
    5467};
    5568
     
    6275{
    6376#if defined USE_D3D9 || defined _XBOX
    64     /* TODO */
     77    /* FIXME: we should be in charge of creating this */
     78    m_data->m_d3d_dev = g_d3ddevice;
    6579#else
    6680#   if defined USE_GLEW && !defined __APPLE__
     
    95109    SetDepthTest(true);
    96110
    97     m_data->m_face_culling = false;
    98     SetFaceCulling(true);
     111    m_data->m_face_culling = CullMode::None;
     112    SetFaceCulling(CullMode::CCW);
    99113
    100114    /* Add some rendering states that we don't export to the user */
     
    350364 */
    351365
    352 void Renderer::SetFaceCulling(bool set)
    353 {
    354     if (m_data->m_face_culling == set)
     366void Renderer::SetFaceCulling(CullMode mode)
     367{
     368    if (m_data->m_face_culling == mode)
    355369        return;
    356370
    357371#if defined USE_D3D9 || defined _XBOX
    358 #   define STR0(x) #x
    359 #   define STR(x) STR0(x)
    360 #   pragma message(__FILE__ "(" STR(__LINE__) "): warning: Renderer::SetFaceCulling() not implemented")
    361 #else
    362     if (set)
     372    switch (mode)
     373    {
     374    case CullMode::None:
     375        m_data->m_d3d_dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
     376        break;
     377    case CullMode::CW:
     378        m_data->m_d3d_dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
     379        break;
     380    case CullMode::CCW:
     381        m_data->m_d3d_dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
     382        break;
     383    }
     384#else
     385    switch (mode)
     386    {
     387    case CullMode::None:
     388        glDisable(GL_CULL_FACE);
     389        break;
     390    case CullMode::CW:
    363391        glEnable(GL_CULL_FACE);
    364     else
    365         glDisable(GL_CULL_FACE);
    366 #endif
    367 
    368     m_data->m_face_culling = set;
    369 }
    370 
    371 bool Renderer::GetFaceCulling() const
     392        glFrontFace(GL_CW);
     393        break;
     394    case CullMode::CCW:
     395        glEnable(GL_CULL_FACE);
     396        glFrontFace(GL_CCW);
     397        break;
     398    }
     399#endif
     400
     401    m_data->m_face_culling = mode;
     402}
     403
     404CullMode Renderer::GetFaceCulling() const
    372405{
    373406    return m_data->m_face_culling;
  • trunk/src/gpu/vertexbuffer.cpp

    r2760 r2761  
    128128
    129129#if defined _XBOX || defined USE_D3D9
    130     if (FAILED(g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW)))
    131         Abort();
    132130    switch (type)
    133131    {
     
    160158#else
    161159    /* FIXME: this has nothing to do here! */
    162     glFrontFace(GL_CCW);
    163 
    164160    switch (type)
    165161    {
     
    191187
    192188#if defined _XBOX || defined USE_D3D9
    193     if (FAILED(g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW)))
    194         Abort();
    195189    switch (type)
    196190    {
     
    226220#else
    227221    /* FIXME: this has nothing to do here! */
    228     glFrontFace(GL_CCW);
    229 
    230222    switch (type)
    231223    {
  • trunk/src/lol/gpu/rendercontext.h

    r2760 r2761  
    3434    void SetAlphaTest(bool set);
    3535    void SetDepthTest(bool set);
    36     void SetFaceCulling(bool set);
     36    void SetFaceCulling(CullMode mode);
    3737
    3838private:
  • trunk/src/lol/gpu/renderer.h

    r2760 r2761  
    4949};
    5050
     51/* A safe enum to indicate the face culling mode. */
     52struct CullMode
     53{
     54    enum Value
     55    {
     56        None,
     57        CW,
     58        CCW,
     59    }
     60    m_value;
     61
     62    inline CullMode() : m_value(None) {}
     63    inline CullMode(Value v) : m_value(v) {}
     64    inline operator Value() { return m_value; }
     65};
     66
    5167class Renderer
    5268{
     
    7894    bool GetDepthTest() const;
    7995
    80     void SetFaceCulling(bool set);
    81     bool GetFaceCulling() const;
     96    void SetFaceCulling(CullMode mode);
     97    CullMode GetFaceCulling() const;
    8298
    8399private:
  • trunk/src/video.cpp

    r2754 r2761  
    181181#if defined USE_D3D9 || defined _XBOX
    182182#elif defined HAVE_GLES_2X
    183             glEnable(GL_CULL_FACE);
     183//            glEnable(GL_CULL_FACE);
    184184#else
    185185//            if (VideoData::render_mode == d && glIsEnabled(GL_CULL_FACE) == GL_TRUE)
Note: See TracChangeset for help on using the changeset viewer.