Changeset 1771


Ignore:
Timestamp:
Aug 18, 2012, 5:49:40 PM (7 years ago)
Author:
sam
Message:

gpu: get rid of the glClearColor, glClearDepth and glClear calls in all
projects, we now use Video::SetClearColor, Video::SetClearDepth and
Video::Clear instead, so that the Direct3D equivalents can be called.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ticker.cpp

    r1718 r1771  
    363363        case Entity::DRAWGROUP_BEGIN:
    364364            Scene::GetDefault()->Reset();
    365             Video::Clear();
     365            Video::Clear(ClearMask::All);
    366366            break;
    367367        case Entity::DRAWGROUP_HUD:
  • trunk/src/video.cpp

    r1513 r1771  
    5252    static mat4 proj_matrix;
    5353    static ivec2 saved_viewport;
    54 #if defined USE_D3D9
     54#if defined USE_D3D9 || defined _XBOX
     55#   if defined USE_D3D9
    5556    static IDirect3D9 *d3d_ctx;
    5657    static IDirect3DDevice9 *d3d_dev;
    57     static D3DCOLOR clear_color;
    58 #elif defined _XBOX
     58#   elif defined _XBOX
    5959    static Direct3D *d3d_ctx;
    6060    static D3DDevice *d3d_dev;
     61#   endif
    6162    static D3DCOLOR clear_color;
     63    static float clear_depth;
    6264#endif
    6365};
     
    6668ivec2 VideoData::saved_viewport(0, 0);
    6769
    68 #if defined USE_D3D9
     70#if defined USE_D3D9 || defined _XBOX
     71#   if defined USE_D3D9
    6972IDirect3D9 *VideoData::d3d_ctx;
    7073IDirect3DDevice9 *VideoData::d3d_dev;
    71 D3DCOLOR VideoData::clear_color;
    72 #elif defined _XBOX
     74#   elif defined _XBOX
    7375Direct3D *VideoData::d3d_ctx;
    7476D3DDevice *VideoData::d3d_dev;
     77#   endif
    7578D3DCOLOR VideoData::clear_color;
     79float VideoData::clear_depth;
    7680#endif
    7781
     
    108112    VideoData::saved_viewport = size;
    109113
    110     VideoData::clear_color = D3DCOLOR_XRGB(26, 51, 77);
    111 
    112114    d3dpp.BackBufferWidth = size.x;
    113115    d3dpp.BackBufferHeight = size.y;
     
    144146    VideoData::saved_viewport = size;
    145147
    146     glClearColor(0.1f, 0.2f, 0.3f, 1.0f);
    147     glClearDepth(1.0);
    148 
    149148#   if defined HAVE_GL_2X && !defined __APPLE__
    150149    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    151150#   endif
    152151#endif
     152
     153    /* Initialise reasonable scene default properties */
     154    SetClearColor(vec4(0.1f, 0.2f, 0.3f, 1.0f));
     155    SetClearDepth(1.f);
    153156}
    154157
     
    219222}
    220223
    221 void Video::Clear()
    222 {
     224void Video::SetClearDepth(float f)
     225{
     226#if defined USE_D3D9 || defined _XBOX
     227    VideoData::clear_depth = f;
     228#else
     229    glClearDepth(f);
     230#endif
     231}
     232
     233void Video::Clear(ClearMask m)
     234{
     235#if defined USE_D3D9 || defined _XBOX
     236    /* Note: D3D9 doesn't appear to support the accumulation buffer. */
     237    int mask = 0;
     238    if (m & ClearMask::Color)
     239        mask |= D3DCLEAR_TARGET;
     240    if (m & ClearMask::Depth)
     241        mask |= D3DCLEAR_ZBUFFER;
     242    if (m & ClearMask::Stencil)
     243        mask |= D3DCLEAR_STENCIL;
     244    if (FAILED(VideoData::d3d_dev->Clear(0, NULL, mask,
     245                                         VideoData::clear_color,
     246                                         VideoData::clear_depth, 0)))
     247        Abort();
     248#else
     249    /* FIXME: is this necessary here? */
    223250    ivec2 size = GetSize();
    224 #if defined USE_D3D9 || defined _XBOX
    225     if (FAILED(VideoData::d3d_dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER
    226                                         | D3DCLEAR_STENCIL,
    227                               VideoData::clear_color, 1.0f, 0)))
    228         Abort();
    229 #else
    230251    glViewport(0, 0, size.x, size.y);
    231     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
     252
     253    GLbitfield mask = 0;
     254    if (m & ClearMask::Color)
     255        mask |= GL_COLOR_BUFFER_BIT;
     256    if (m & ClearMask::Depth)
     257        mask |= GL_DEPTH_BUFFER_BIT;
     258    if (m & ClearMask::Accum)
     259        mask |= GL_ACCUM_BUFFER_BIT;
     260    if (m & ClearMask::Stencil)
     261        mask |= GL_STENCIL_BUFFER_BIT;
     262    glClear(mask);
    232263#endif
    233264
  • trunk/src/video.h

    r1325 r1771  
    2323{
    2424
     25struct ClearMask
     26{
     27    enum Value
     28    {
     29        Color   = 1 << 0,
     30        Depth   = 1 << 1,
     31        Accum   = 1 << 2,
     32        Stencil = 1 << 3,
     33
     34        All     = 0xffffffff
     35    }
     36    m_value;
     37
     38    inline ClearMask(Value v) { m_value = v; }
     39    inline ClearMask(uint64_t i) { m_value = (Value)i; }
     40    inline operator Value() { return m_value; }
     41};
     42
    2543class Video
    2644{
     
    3149    static void SetDepth(bool set);
    3250    static void SetClearColor(vec4 color);
    33     static void Clear();
     51    static void SetClearDepth(float f);
     52    static void Clear(ClearMask m);
    3453    static void Capture(uint32_t *buffer);
    3554    static ivec2 GetSize();
  • trunk/tools/neercs/video/render.cpp

    r1763 r1771  
    819819    /* Clear the back buffer */
    820820    glEnable(GL_BLEND);
    821     glBlendFunc(GL_SRC_COLOR,GL_DST_ALPHA);
    822     glClearColor(screen_color.r, screen_color.g, screen_color.b, 1.0f);
    823     glClearDepth(1.0f); // set depth buffer
    824     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     821    glBlendFunc(GL_SRC_COLOR, GL_DST_ALPHA);
     822
     823    Video::SetClearColor(vec4(screen_color, 1.f));
     824    Video::SetClearDepth(1.0f); // set depth buffer
     825    Video::Clear(ClearMask::Color | ClearMask::Depth);
    825826
    826827    text_render->Blit(border, canvas_size);
  • trunk/tutorial/08_fbo.cpp

    r1737 r1771  
    1515#include "core.h"
    1616#include "loldebug.h"
    17 #include "lolgl.h"
    1817
    1918using namespace std;
     
    7877            m_fbo = new FrameBuffer(Video::GetSize());
    7978            m_fbo->Bind();
    80             glClearColor(0.0, 0.0, 0.0, 1.0f);
    81             glClearDepth(1.0f);
    82             glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     79            Video::SetClearColor(vec4(0.f, 0.f, 0.f, 1.f));
     80            Video::SetClearDepth(1.f);
     81            Video::Clear(ClearMask::Color | ClearMask::Depth);
    8382            m_fbo->Unbind();
    8483
     
    9089        m_fbo->Bind();
    9190        /* FIXME: we should just disable depth test in the shader */
    92         glClear(GL_DEPTH_BUFFER_BIT);
     91        Video::Clear(ClearMask::Depth);
    9392        m_shader->Bind();
    9493        m_shader->SetUniform(m_uni_flag, 0.f);
Note: See TracChangeset for help on using the changeset viewer.