Ignore:
Timestamp:
Apr 10, 2012, 3:12:52 AM (8 years ago)
Author:
sam
Message:

win32: start porting the graphical backend to DirectX 9. Apparently I
cannot used DirectX 10 because my video card only supports DX9, and there
is no compatibility layer. DX11 has feature levels for older hardware so
it would work with a DX9 card, but it's not available for WinXP.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/video.cpp

    r1199 r1208  
    1515#include <cmath>
    1616
    17 #if _XBOX
     17#if defined USE_D3D9
     18#   include <d3d9.h>
     19#elif defined _XBOX
    1820#   include <xtl.h>
    1921#   undef near /* Fuck Microsoft */
     
    3133using namespace std;
    3234
    33 #if defined _XBOX
    3435/* FIXME: g_d3ddevice should never be exported */
     36#if defined USE_D3D9
     37IDirect3DDevice9 *g_d3ddevice;
     38#   if defined USE_SDL
     39extern HWND g_hwnd;
     40#   endif
     41#elif defined _XBOX
    3542D3DDevice *g_d3ddevice;
    3643#endif
     
    4653    static mat4 proj_matrix, view_matrix;
    4754    static ivec2 saved_viewport;
    48 #if defined _XBOX
     55#if defined USE_D3D9
     56    static IDirect3D9 *d3d_ctx;
     57    static IDirect3DDevice9 *d3d_dev;
     58    static D3DCOLOR clear_color;
     59#elif defined _XBOX
    4960    static Direct3D *d3d_ctx;
    5061    static D3DDevice *d3d_dev;
     
    5768ivec2 VideoData::saved_viewport(0, 0);
    5869
    59 #if defined _XBOX
     70#if defined USE_D3D9
     71IDirect3D9 *VideoData::d3d_ctx;
     72IDirect3DDevice9 *VideoData::d3d_dev;
     73D3DCOLOR VideoData::clear_color;
     74#elif defined _XBOX
    6075Direct3D *VideoData::d3d_ctx;
    6176D3DDevice *VideoData::d3d_dev;
     
    6984void Video::Setup(ivec2 size)
    7085{
    71 #if defined _XBOX
     86#if defined USE_D3D9 || defined _XBOX
    7287    VideoData::d3d_ctx = Direct3DCreate9(D3D_SDK_VERSION);
    7388    if (!VideoData::d3d_ctx)
     
    7792    }
    7893
     94    HWND window = 0;
    7995    D3DPRESENT_PARAMETERS d3dpp;
    8096    memset(&d3dpp, 0, sizeof(d3dpp));
    8197
     98#   if defined USE_SDL
     99    window = g_hwnd;
     100    d3dpp.hDeviceWindow = g_hwnd;
     101    d3dpp.Windowed = TRUE;
     102#   elif defined _XBOX
    82103    XVIDEO_MODE VideoMode;
    83104    XGetVideoMode( &VideoMode );
     
    86107    if (size.y > VideoMode.dwDisplayHeight)
    87108        size.y = VideoMode.dwDisplayHeight;
     109#   endif
    88110    VideoData::saved_viewport = size;
    89111
     
    99121    d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
    100122
    101     if (FAILED(VideoData::d3d_ctx->CreateDevice(0, D3DDEVTYPE_HAL, NULL,
    102                                                 D3DCREATE_HARDWARE_VERTEXPROCESSING,
    103                                                 &d3dpp, &VideoData::d3d_dev)))
     123    HRESULT hr = VideoData::d3d_ctx->CreateDevice(0, D3DDEVTYPE_HAL, window,
     124                                                  D3DCREATE_HARDWARE_VERTEXPROCESSING,
     125                                                  &d3dpp, &VideoData::d3d_dev);
     126    if (FAILED(hr))
    104127    {
    105128        Log::Error("cannot create D3D device\n");
     
    178201void Video::SetDepth(bool set)
    179202{
    180 #if defined _XBOX
     203#if defined USE_D3D9 || defined _XBOX
    181204#   define STR0(x) #x
    182205#   define STR(x) STR0(x)
     
    192215void Video::SetClearColor(vec4 color)
    193216{
    194 #if defined _XBOX
     217#if defined USE_D3D9 || defined _XBOX
    195218    VideoData::clear_color = D3DCOLOR_XRGB((int)(color.r * 255.999f),
    196219                                           (int)(color.g * 255.999f),
     
    204227{
    205228    ivec2 size = GetSize();
    206 #if defined _XBOX
     229#if defined USE_D3D9 || defined _XBOX
    207230    VideoData::d3d_dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER
    208231                                        | D3DCLEAR_STENCIL,
     
    223246void Video::Capture(uint32_t *buffer)
    224247{
    225 #if _XBOX
     248#if defined USE_D3D9 || defined _XBOX
    226249    /* TODO */
    227250#else
     
    259282ivec2 Video::GetSize()
    260283{
    261 #if _XBOX
     284#if defined USE_D3D9 || defined _XBOX
    262285    return VideoData::saved_viewport;
    263286#elif 1
Note: See TracChangeset for help on using the changeset viewer.