Ignore:
Timestamp:
Aug 18, 2012, 5:49:40 PM (8 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.