Changeset 2770


Ignore:
Timestamp:
Jun 23, 2013, 12:18:31 PM (8 years ago)
Author:
sam
Message:

gpu: get rid of the global D3D device pointer and move D3D initialisation
code from the Video to the Renderer class.

Location:
trunk/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gpu/framebuffer.cpp

    r2768 r2770  
    2424using namespace std;
    2525
    26 #if defined USE_D3D9
    27 extern IDirect3DDevice9 *g_d3ddevice;
    28 #elif defined _XBOX
    29 extern D3DDevice *g_d3ddevice;
    30 #endif
    31 
    3226namespace lol
    3327{
     
    4741
    4842#if defined USE_D3D9
     43    IDirect3DDevice9 *m_dev;
    4944    IDirect3DTexture9 *m_texture;
    5045    IDirect3DSurface9 *m_surface, *m_back_surface;
    5146#elif defined _XBOX
     47    D3DDevice9 *m_dev;
    5248    D3DTexture *m_texture;
    5349    D3DSurface *m_surface, *m_back_surface;
     
    293289    m_data->m_bound = false;
    294290#if defined USE_D3D9
    295     if (FAILED(g_d3ddevice->CreateTexture(size.x, size.y, 1,
     291    m_data->m_dev = (IDirect3DDevice9 *)g_renderer->GetDevice();
     292
     293    if (FAILED(m_data->m_dev->CreateTexture(size.x, size.y, 1,
    296294                                          D3DUSAGE_RENDERTARGET,
    297295                                          (D3DFORMAT)fbo_format.GetFormat(), D3DPOOL_DEFAULT,
     
    301299        Abort();
    302300#elif defined _XBOX
    303     if (FAILED(g_d3ddevice->CreateTexture(size.x, size.y, 1, 0,
     301    m_data->m_dev = (D3DDevice9 *)g_renderer->GetDevice();
     302
     303    if (FAILED(m_data->m_dev->CreateTexture(size.x, size.y, 1, 0,
    304304                                          fbo_format.GetFormat(), D3DPOOL_DEFAULT,
    305305                                          &m_data->m_texture, nullptr)))
    306306        Abort();
    307     if (FAILED(g_d3ddevice->CreateRenderTarget(size.x, size.y,
     307    if (FAILED(m_data->m_dev->CreateRenderTarget(size.x, size.y,
    308308                                               fbo_format.GetFormat(),
    309309                                               D3DMULTISAMPLE_NONE, 0, 0,
     
    423423
    424424#if defined USE_D3D9 || defined _XBOX
    425     if (FAILED(g_d3ddevice->GetRenderTarget(0, &m_data->m_back_surface)))
    426         Abort();
    427     if (FAILED(g_d3ddevice->SetRenderTarget(0, m_data->m_surface)))
     425    if (FAILED(m_data->m_dev->GetRenderTarget(0, &m_data->m_back_surface)))
     426        Abort();
     427    if (FAILED(m_data->m_dev->SetRenderTarget(0, m_data->m_surface)))
    428428        Abort();
    429429#else
     
    449449#if defined USE_D3D9 || defined _XBOX
    450450#   if defined _XBOX
    451     if (FAILED(g_d3ddevice->Resolve(D3DRESOLVE_RENDERTARGET0, nullptr,
     451    if (FAILED(m_data->m_dev->Resolve(D3DRESOLVE_RENDERTARGET0, nullptr,
    452452                                    m_data->m_texture, nullptr, 0, 0, nullptr,
    453453                                    0, 0, nullptr)))
    454454        Abort();
    455455#   endif
    456     if (FAILED(g_d3ddevice->SetRenderTarget(0, m_data->m_back_surface)))
     456    if (FAILED(m_data->m_dev->SetRenderTarget(0, m_data->m_back_surface)))
    457457        Abort();
    458458    m_data->m_back_surface->Release();
  • trunk/src/gpu/indexbuffer.cpp

    r2506 r2770  
    2424using namespace std;
    2525
    26 #if defined USE_D3D9
    27 extern IDirect3DDevice9 *g_d3ddevice;
    28 #elif defined _XBOX
    29 extern D3DDevice *g_d3ddevice;
    30 #endif
    31 
    3226namespace lol
    3327{
     
    4539
    4640#if defined USE_D3D9
     41    IDirect3DDevice9 *m_dev;
    4742    IDirect3DIndexBuffer9 *m_ibo;
    4843#elif defined _XBOX
     44    D3DDevice9 *m_dev;
    4945    D3DIndexBuffer *m_ibo;
    5046#else
     
    6662        return;
    6763#if defined USE_D3D9 || defined _XBOX
    68     if (FAILED(g_d3ddevice->CreateIndexBuffer(size, D3DUSAGE_WRITEONLY,
     64#   if defined USE_D3D9
     65    m_data->m_dev = (IDirect3DDevice9 *)g_renderer->GetDevice();
     66#   elif defined _XBOX
     67    m_data->m_dev = (D3DDevice9 *)g_renderer->GetDevice();
     68#   endif
     69
     70    if (FAILED(m_data->m_dev->CreateIndexBuffer(size, D3DUSAGE_WRITEONLY,
    6971                                              D3DFMT_INDEX16, D3DPOOL_MANAGED,
    7072                                              &m_data->m_ibo, nullptr)))
     
    127129
    128130#if defined USE_D3D9 || defined _XBOX
    129     if (FAILED(g_d3ddevice->SetIndices(m_data->m_ibo)))
     131    if (FAILED(m_data->m_dev->SetIndices(m_data->m_ibo)))
    130132        Abort();
    131133#else
     
    143145
    144146#if defined USE_D3D9 || defined _XBOX
    145     if (FAILED(g_d3ddevice->SetIndices(nullptr)))
     147    if (FAILED(m_data->m_dev->SetIndices(nullptr)))
    146148        Abort();
    147149#else
  • trunk/src/gpu/renderer.cpp

    r2769 r2770  
    3232#include "lolgl.h"
    3333
     34/* FIXME: find a way to pass g_hwnd from the windowing system */
    3435#if defined USE_D3D9
    35 extern IDirect3DDevice9 *g_d3ddevice;
     36extern HWND g_hwnd;
    3637#elif defined _XBOX
    37 extern D3DDevice *g_d3ddevice;
     38HWND g_hwnd = 0;
    3839#endif
    3940
     
    6364    CullMode m_face_culling;
    6465
     66private:
    6567#if defined USE_D3D9
     68    IDirect3D9 *m_d3d_ctx;
    6669    IDirect3DDevice9 *m_d3d_dev;
    6770#elif defined _XBOX
     71    Direct3D *m_d3d_ctx;
    6872    D3DDevice *m_d3d_dev;
    6973#endif
     
    7882{
    7983#if defined USE_D3D9 || defined _XBOX
    80     /* FIXME: we should be in charge of creating this */
    81     m_data->m_d3d_dev = g_d3ddevice;
     84    /* Create Direct3D context */
     85    m_data->m_d3d_ctx = Direct3DCreate9(D3D_SDK_VERSION);
     86    if (!m_data->m_d3d_ctx)
     87    {
     88        Log::Error("cannot initialise D3D\n");
     89        exit(EXIT_FAILURE);
     90    }
     91
     92    /* Create Direct3D device */
     93#   if defined _XBOX
     94    XVIDEO_MODE VideoMode;
     95    XGetVideoMode(&VideoMode);
     96    size = lol::min(size, ivec2(VideoMode.dwDisplayWidth,
     97                                VideoMode.dwDisplayHeight);
     98#   endif
     99    D3DPRESENT_PARAMETERS d3dpp;
     100    memset(&d3dpp, 0, sizeof(d3dpp));
     101    d3dpp.BackBufferWidth = size.x;
     102    d3dpp.BackBufferHeight = size.y;
     103    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
     104    d3dpp.BackBufferCount = 1;
     105    d3dpp.hDeviceWindow = g_hwnd;
     106#   if defined USE_SDL
     107    d3dpp.Windowed = TRUE;
     108#   endif
     109    d3dpp.EnableAutoDepthStencil = TRUE;
     110    d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
     111    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
     112    d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
     113
     114    HRESULT hr = VideoData::d3d_ctx->CreateDevice(0, D3DDEVTYPE_HAL, g_hwnd,
     115                                                  D3DCREATE_HARDWARE_VERTEXPROCESSING,
     116                                                  &d3dpp, &m_data->m_d3d_dev);
     117    if (FAILED(hr))
     118    {
     119        Log::Error("cannot create D3D device\n");
     120        exit(EXIT_FAILURE);
     121    }
     122
    82123#else
    83124#   if defined USE_GLEW && !defined __APPLE__
     
    129170{
    130171    delete m_data;
     172}
     173
     174void *Renderer::GetDevice()
     175{
     176#if defined USE_D3D9 || defined _XBOX
     177    return m_data->m_d3d_dev;
     178#else
     179    return nullptr;
     180#endif
    131181}
    132182
  • trunk/src/gpu/shader.cpp

    r2743 r2770  
    3333using namespace std;
    3434
    35 #if defined USE_D3D9
    36 extern IDirect3DDevice9 *g_d3ddevice;
    37 #elif defined _XBOX
    38 extern D3DDevice *g_d3ddevice;
    39 #endif
    40 
    4135namespace lol
    4236{
     
    5246private:
    5347#if defined USE_D3D9
     48    IDirect3DDevice9 *m_dev;
    5449    IDirect3DVertexShader9 *vert_shader;
    5550    IDirect3DPixelShader9 *frag_shader;
    5651    ID3DXConstantTable *vert_table, *frag_table;
    5752#elif defined _XBOX
     53    D3DDevice9 *m_dev;
    5854    D3DVertexShader *vert_shader;
    5955    D3DPixelShader *frag_shader;
     
    194190    data->vert_crc = ShaderData::hash(vert);
    195191#if defined USE_D3D9 || defined _XBOX
     192#   if defined USE_D3D9
     193    data->m_dev = (IDirect3DDevice9 *)g_renderer->GetDevice();
     194#   elif defined _XBOX
     195    data->m_dev = (D3DDevice9 *)g_renderer->GetDevice();
     196#   endif
     197
    196198    hr = D3DXCompileShader(vert, (UINT)strlen(vert), macros, nullptr, "main",
    197199                           "vs_3_0", 0, &shader_code, &error_msg,
     
    203205        Log::Error("shader source:\n%s\n", vert);
    204206    }
    205     g_d3ddevice->CreateVertexShader((DWORD *)shader_code->GetBufferPointer(),
     207    data->m_dev->CreateVertexShader((DWORD *)shader_code->GetBufferPointer(),
    206208                                    &data->vert_shader);
    207209    shader_code->Release();
     
    247249        Log::Error("shader source:\n%s\n", frag);
    248250    }
    249     g_d3ddevice->CreatePixelShader((DWORD *)shader_code->GetBufferPointer(),
     251    data->m_dev->CreatePixelShader((DWORD *)shader_code->GetBufferPointer(),
    250252                                   &data->frag_shader);
    251253    shader_code->Release();
     
    420422#if defined USE_D3D9 || defined _XBOX
    421423    if (uni.flags & 1)
    422         g_d3ddevice->SetPixelShaderConstantI((UINT)uni.frag, &v[0], 1);
     424        data->m_dev->SetPixelShaderConstantI((UINT)uni.frag, &v[0], 1);
    423425    if (uni.flags & 2)
    424         g_d3ddevice->SetVertexShaderConstantI((UINT)uni.vert, &v[0], 1);
     426        data->m_dev->SetVertexShaderConstantI((UINT)uni.vert, &v[0], 1);
    425427#elif !defined __CELLOS_LV2__
    426428    glUniform4i(uni.frag, v.x, v.y, v.z, v.w);
     
    476478#if defined USE_D3D9 || defined _XBOX
    477479    if (uni.flags & 1)
    478         g_d3ddevice->SetPixelShaderConstantF((UINT)uni.frag, &v[0], 1);
     480        data->m_dev->SetPixelShaderConstantF((UINT)uni.frag, &v[0], 1);
    479481    if (uni.flags & 2)
    480         g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert, &v[0], 1);
     482        data->m_dev->SetVertexShaderConstantF((UINT)uni.vert, &v[0], 1);
    481483#elif !defined __CELLOS_LV2__
    482484    glUniform4fv(uni.frag, 1, &v[0]);
     
    494496    /* FIXME: do we need padding here like for the mat3 version? */
    495497    if (uni.flags & 1)
    496         g_d3ddevice->SetPixelShaderConstantF((UINT)uni.frag, &m[0][0], 1);
     498        data->m_dev->SetPixelShaderConstantF((UINT)uni.frag, &m[0][0], 1);
    497499    if (uni.flags & 2)
    498         g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert, &m[0][0], 1);
     500        data->m_dev->SetVertexShaderConstantF((UINT)uni.vert, &m[0][0], 1);
    499501#elif !defined __CELLOS_LV2__
    500502    glUniformMatrix2fv(uni.frag, 1, GL_FALSE, &m[0][0]);
     
    515517    mat4 tmp(m, 1.0f);
    516518    if (uni.flags & 1)
    517         g_d3ddevice->SetPixelShaderConstantF((UINT)uni.frag, &tmp[0][0], 3);
     519        data->m_dev->SetPixelShaderConstantF((UINT)uni.frag, &tmp[0][0], 3);
    518520    if (uni.flags & 2)
    519         g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert, &tmp[0][0], 3);
     521        data->m_dev->SetVertexShaderConstantF((UINT)uni.vert, &tmp[0][0], 3);
    520522#elif !defined __CELLOS_LV2__
    521523    glUniformMatrix3fv(uni.frag, 1, GL_FALSE, &m[0][0]);
     
    534536#if defined USE_D3D9 || defined _XBOX
    535537    if (uni.flags & 1)
    536         g_d3ddevice->SetPixelShaderConstantF((UINT)uni.frag, &m[0][0], 4);
     538        data->m_dev->SetPixelShaderConstantF((UINT)uni.frag, &m[0][0], 4);
    537539    if (uni.flags & 2)
    538         g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert, &m[0][0], 4);
     540        data->m_dev->SetVertexShaderConstantF((UINT)uni.vert, &m[0][0], 4);
    539541#elif !defined __CELLOS_LV2__
    540542    glUniformMatrix4fv(uni.frag, 1, GL_FALSE, &m[0][0]);
     
    550552{
    551553#if defined USE_D3D9 || defined _XBOX
    552     g_d3ddevice->SetTexture(index, (LPDIRECT3DTEXTURE9)tex.m_flags);
    553     g_d3ddevice->SetSamplerState(index, D3DSAMP_MAGFILTER, tex.m_attrib & 0xff);
    554     g_d3ddevice->SetSamplerState(index, D3DSAMP_MINFILTER, (tex.m_attrib >> 8) & 0xff);
    555     g_d3ddevice->SetSamplerState(index, D3DSAMP_MIPFILTER, (tex.m_attrib >> 16) & 0xff);
     554    data->m_dev->SetTexture(index, (LPDIRECT3DTEXTURE9)tex.m_flags);
     555    data->m_dev->SetSamplerState(index, D3DSAMP_MAGFILTER, tex.m_attrib & 0xff);
     556    data->m_dev->SetSamplerState(index, D3DSAMP_MINFILTER, (tex.m_attrib >> 8) & 0xff);
     557    data->m_dev->SetSamplerState(index, D3DSAMP_MIPFILTER, (tex.m_attrib >> 16) & 0xff);
    556558#elif !defined __CELLOS_LV2__
    557559    glActiveTexture(GL_TEXTURE0 + index);
     
    574576     * it's a bunch of floats instead of vec4. */
    575577    if (uni.flags & 1)
    576         g_d3ddevice->SetPixelShaderConstantF((UINT)uni.frag,
     578        data->m_dev->SetPixelShaderConstantF((UINT)uni.frag,
    577579                                             &v[0], v.Count() / 4);
    578580    if (uni.flags & 2)
    579         g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert,
     581        data->m_dev->SetVertexShaderConstantF((UINT)uni.vert,
    580582                                              &v[0], v.Count() / 4);
    581583#elif !defined __CELLOS_LV2__
     
    597599     * it's a bunch of vec2 instead of vec4. */
    598600    if (uni.flags & 1)
    599         g_d3ddevice->SetPixelShaderConstantF((UINT)uni.frag,
     601        data->m_dev->SetPixelShaderConstantF((UINT)uni.frag,
    600602                                             &v[0][0], v.Count() / 2);
    601603    if (uni.flags & 2)
    602         g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert,
     604        data->m_dev->SetVertexShaderConstantF((UINT)uni.vert,
    603605                                              &v[0][0], v.Count() / 2);
    604606#elif !defined __CELLOS_LV2__
     
    620622     * it's a bunch of vec3 instead of vec4. */
    621623    if (uni.flags & 1)
    622         g_d3ddevice->SetPixelShaderConstantF((UINT)uni.frag,
     624        data->m_dev->SetPixelShaderConstantF((UINT)uni.frag,
    623625                                             &v[0][0], v.Count());
    624626    if (uni.flags & 2)
    625         g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert,
     627        data->m_dev->SetVertexShaderConstantF((UINT)uni.vert,
    626628                                              &v[0][0], v.Count());
    627629#elif !defined __CELLOS_LV2__
     
    641643#if defined USE_D3D9 || defined _XBOX
    642644    if (uni.flags & 1)
    643         g_d3ddevice->SetPixelShaderConstantF((UINT)uni.frag,
     645        data->m_dev->SetPixelShaderConstantF((UINT)uni.frag,
    644646                                             &v[0][0], v.Count());
    645647    if (uni.flags & 2)
    646         g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert,
     648        data->m_dev->SetVertexShaderConstantF((UINT)uni.vert,
    647649                                              &v[0][0], v.Count());
    648650#elif !defined __CELLOS_LV2__
     
    662664#if defined USE_D3D9 || defined _XBOX
    663665    HRESULT hr;
    664     hr = g_d3ddevice->SetVertexShader(data->vert_shader);
    665     hr = g_d3ddevice->SetPixelShader(data->frag_shader);
     666    hr = data->m_dev->SetVertexShader(data->vert_shader);
     667    hr = data->m_dev->SetPixelShader(data->frag_shader);
    666668#elif !defined __CELLOS_LV2__
    667669    glUseProgram(data->prog_id);
     
    678680#if defined USE_D3D9 || defined _XBOX
    679681    HRESULT hr;
    680     hr = g_d3ddevice->SetVertexShader(nullptr);
    681     hr = g_d3ddevice->SetPixelShader(nullptr);
     682    hr = data->m_dev->SetVertexShader(nullptr);
     683    hr = data->m_dev->SetPixelShader(nullptr);
    682684#elif !defined __CELLOS_LV2__
    683685    /* FIXME: untested */
  • trunk/src/gpu/texture.cpp

    r2766 r2770  
    2424using namespace std;
    2525
    26 #if defined USE_D3D9
    27 extern IDirect3DDevice9 *g_d3ddevice;
    28 #elif defined _XBOX
    29 extern D3DDevice *g_d3ddevice;
    30 #endif
    31 
    3226namespace lol
    3327{
     
    4640
    4741#if defined USE_D3D9
     42    IDirect3DDevice9 *m_dev;
    4843    IDirect3DTexture9 *m_texture;
    4944    D3DTEXTUREFILTERTYPE m_mag_filter;
    50     D3DTEXTUREFILTERTYPE  m_min_filter;
    51     D3DTEXTUREFILTERTYPE  m_mip_filter;
     45    D3DTEXTUREFILTERTYPE m_min_filter;
     46    D3DTEXTUREFILTERTYPE m_mip_filter;
    5247#elif defined _XBOX
     48    D3DDevice9 *m_dev;
    5349    D3DTexture *m_texture;
    5450#else
     
    7672
    7773#if defined USE_D3D9 || defined _XBOX
     74#   if defined USE_D3D9
     75    m_data->m_dev = (IDirect3DDevice9 *)g_renderer->GetDevice();
     76#   elif defined _XBOX
     77    m_data->m_dev = (D3DDevice9 *)g_renderer->GetDevice();
     78#   endif
     79
    7880    static struct
    7981    {
     
    110112#   endif
    111113
    112     g_d3ddevice->CreateTexture(m_data->m_size.x, m_data->m_size.y, 1,
     114    m_data->m_dev->CreateTexture(m_data->m_size.x, m_data->m_size.y, 1,
    113115                               d3d_usage, d3d_format,
    114116                               D3DPOOL_DEFAULT, &m_data->m_texture, nullptr);
     
    186188{
    187189#if defined _XBOX || defined USE_D3D9
    188     g_d3ddevice->SetTexture(0, m_data->m_texture);
     190    m_data->m_dev->SetTexture(0, m_data->m_texture);
    189191#else
    190192#   if !defined HAVE_GLES_2X
  • trunk/src/gpu/vertexbuffer.cpp

    r2761 r2770  
    2424using namespace std;
    2525
    26 #if defined USE_D3D9
    27 extern IDirect3DDevice9 *g_d3ddevice;
    28 #elif defined _XBOX
    29 extern D3DDevice *g_d3ddevice;
    30 #endif
    31 
    3226namespace lol
    3327{
     
    4640
    4741#if defined USE_D3D9
     42    IDirect3DDevice9 *m_dev;
    4843    IDirect3DVertexBuffer9 *m_vbo;
    4944#elif defined _XBOX
     45    D3DDevice9 *m_dev;
    5046    D3DVertexBuffer *m_vbo;
    5147#else
    5248    GLuint m_vbo;
    5349    uint8_t *m_memory;
     50#endif
     51};
     52
     53//
     54// The VertexDeclarationData class
     55// -------------------------------
     56//
     57
     58class VertexDeclarationData
     59{
     60    friend class VertexBuffer;
     61    friend class VertexDeclaration;
     62
     63#if defined USE_D3D9
     64    IDirect3DDevice9 *m_dev;
     65    IDirect3DVertexDeclaration9 *m_vdecl;
     66#elif defined _XBOX
     67    D3DDevice9 *m_dev;
     68    D3DVertexDeclaration *m_vdecl;
     69#else
    5470#endif
    5571};
     
    7389                                     VertexStreamBase const &s10,
    7490                                     VertexStreamBase const &s11,
    75                                      VertexStreamBase const &s12) : m_count(0)
     91                                     VertexStreamBase const &s12)
     92  : m_count(0),
     93    m_data(new VertexDeclarationData())
    7694{
    7795    if (&s1 != &VertexStreamBase::Empty) AddStream(s1);
     
    93111{
    94112#if defined _XBOX || defined USE_D3D9
    95 #   if defined USE_D3D9
    96     IDirect3DVertexDeclaration9 *vdecl = (IDirect3DVertexDeclaration9 *)m_data;
    97 #   elif defined _XBOX
    98     D3DVertexDeclaration *vdecl = (D3DVertexDeclaration *)m_data;
    99 #   endif
    100 
    101     if (FAILED(vdecl->Release()))
     113    if (FAILED(m_data->m_vdecl->Release()))
    102114        Abort();
    103115#else
    104116
    105117#endif
     118
     119    delete m_data;
    106120}
    107121
     
    109123{
    110124#if defined _XBOX || defined USE_D3D9
    111 #   if defined USE_D3D9
    112     IDirect3DVertexDeclaration9 *vdecl = (IDirect3DVertexDeclaration9 *)m_data;
    113 #   elif defined _XBOX
    114     D3DVertexDeclaration *vdecl = (D3DVertexDeclaration *)m_data;
    115 #   endif
    116 
    117     if (FAILED(g_d3ddevice->SetVertexDeclaration(vdecl)))
     125    if (FAILED(m_data->m_dev->SetVertexDeclaration(m_data->m_vdecl)))
    118126        Abort();
    119127#else
     
    131139    {
    132140    case MeshPrimitive::Triangles:
    133         if (FAILED(g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST,
    134                                               skip, count)))
     141        if (FAILED(m_data->m_dev->DrawPrimitive(D3DPT_TRIANGLELIST,
     142                                                skip, count)))
    135143            Abort();
    136144        break;
    137145    case MeshPrimitive::TriangleStrips:
    138         if (FAILED(g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,
    139                                               skip, count)))
     146        if (FAILED(m_data->m_dev->DrawPrimitive(D3DPT_TRIANGLESTRIP,
     147                                                skip, count)))
    140148            Abort();
    141149        break;
    142150    case MeshPrimitive::TriangleFans:
    143         if (FAILED(g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
    144                                               skip, count)))
     151        if (FAILED(m_data->m_dev->DrawPrimitive(D3DPT_TRIANGLEFAN,
     152                                                skip, count)))
    145153            Abort();
    146154        break;
    147155    case MeshPrimitive::Points:
    148         if (FAILED(g_d3ddevice->DrawPrimitive(D3DPT_POINTLIST,
    149                                               skip, count)))
     156        if (FAILED(m_data->m_dev->DrawPrimitive(D3DPT_POINTLIST,
     157                                                skip, count)))
    150158            Abort();
    151159        break;
    152160    case MeshPrimitive::Lines:
    153         if (FAILED(g_d3ddevice->DrawPrimitive(D3DPT_LINELIST,
    154                                               skip, count)))
     161        if (FAILED(m_data->m_dev->DrawPrimitive(D3DPT_LINELIST,
     162                                                skip, count)))
    155163            Abort();
    156164        break;
     
    191199    case MeshPrimitive::Triangles:
    192200        count = count / 3;
    193         if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,
     201        if (FAILED(m_data->m_dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,
    194202                                           vbase, vskip, vcount, skip, count)))
    195203            Abort();
     
    197205    case MeshPrimitive::TriangleStrips:
    198206        count = count - 2;
    199         if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP,
     207        if (FAILED(m_data->m_dev->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP,
    200208                                           vbase, vskip, vcount, skip, count)))
    201209            Abort();
     
    203211    case MeshPrimitive::TriangleFans:
    204212        count = count - 2;
    205         if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLEFAN,
     213        if (FAILED(m_data->m_dev->DrawIndexedPrimitive(D3DPT_TRIANGLEFAN,
    206214                                           vbase, vskip, vcount, skip, count)))
    207215            Abort();
    208216        break;
    209217    case MeshPrimitive::Points:
    210         if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_POINTLIST,
     218        if (FAILED(m_data->m_dev->DrawIndexedPrimitive(D3DPT_POINTLIST,
    211219                                           vbase, vskip, vcount, skip, count)))
    212220            Abort();
    213221        break;
    214222    case MeshPrimitive::Lines:
    215         if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_LINELIST,
     223        if (FAILED(m_data->m_dev->DrawIndexedPrimitive(D3DPT_LINELIST,
    216224                                           vbase, vskip, vcount, skip, count)))
    217225            Abort();
     
    259267        {
    260268            stream = m_streams[i].index;
    261             if (FAILED(g_d3ddevice->SetStreamSource(stream, 0, 0, 0)))
     269            if (FAILED(m_data->m_dev->SetStreamSource(stream, 0, 0, 0)))
    262270                Abort();
    263271        }
     
    330338    if (stream >= 0)
    331339    {
    332         if (FAILED(g_d3ddevice->SetStreamSource(stream, vb->m_data->m_vbo, 0, stride)))
     340        if (FAILED(m_data->m_dev->SetStreamSource(stream, vb->m_data->m_vbo,
     341                                                  0, stride)))
    333342            Abort();
    334343    }
     
    554563
    555564#   if defined USE_D3D9
    556     IDirect3DVertexDeclaration9 *vdecl;
     565    m_data->m_dev = (IDirect3DDevice9 *)g_renderer->GetDevice();
    557566#   elif defined _XBOX
    558     D3DVertexDeclaration *vdecl;
     567    m_data->m_dev = (D3DDevice9 *)g_renderer->GetDevice();
    559568#   endif
    560569
    561     if (FAILED(g_d3ddevice->CreateVertexDeclaration(elements, &vdecl)))
     570    if (FAILED(m_data->m_dev->CreateVertexDeclaration(elements,
     571                                                      &m_data->m_vdecl)))
    562572        Abort();
    563 
    564     m_data = vdecl;
    565573#else
    566574
     
    637645        return;
    638646#if defined USE_D3D9 || defined _XBOX
    639     if (FAILED(g_d3ddevice->CreateVertexBuffer(size, D3DUSAGE_WRITEONLY, nullptr,
     647#   if defined USE_D3D9
     648    m_data->m_dev = (IDirect3DDevice9 *)g_renderer->GetDevice();
     649#   elif defined _XBOX
     650    m_data->m_dev = (D3DDevice9 *)g_renderer->GetDevice();
     651#   endif
     652
     653    if (FAILED(m_data->m_dev->CreateVertexBuffer(size, D3DUSAGE_WRITEONLY, nullptr,
    640654                                               D3DPOOL_MANAGED, &m_data->m_vbo, nullptr)))
    641655        Abort();
  • trunk/src/lol/gpu/renderer.h

    r2769 r2770  
    139139    ~Renderer();
    140140
     141    void *GetDevice();
     142
    141143public:
    142144    void Clear(ClearMask mask);
  • trunk/src/lol/gpu/vertexbuffer.h

    r2731 r2770  
    312312    int m_count;
    313313
    314     void *m_data;
     314private:
     315    class VertexDeclarationData *m_data;
    315316};
    316317
  • trunk/src/platform/sdl/sdlapp.cpp

    r2644 r2770  
    3535#if defined USE_SDL && defined USE_D3D9
    3636HWND g_hwnd = nullptr;
    37 extern IDirect3DDevice9 *g_d3ddevice;
    3837#endif
    3938
     
    116115{
    117116#if defined USE_SDL && defined USE_D3D9
     117    IDirect3DDevice9 *d3d_dev = (IDirect3DDevice9 *)g_renderer->GetDevice();
    118118    HRESULT hr;
    119     hr = g_d3ddevice->BeginScene();
     119    hr = d3d_dev->BeginScene();
    120120    if (FAILED(hr))
    121121        Abort();
    122122#endif
     123
    123124    /* Tick the renderer, show the frame and clamp to desired framerate. */
    124125    Ticker::TickDraw();
    125 #if defined USE_SDL
    126 #   if defined USE_D3D9
    127     hr = g_d3ddevice->EndScene();
     126
     127#if defined USE_SDL && defined USE_D3D9
     128    hr = d3d_dev->EndScene();
    128129    if (FAILED(hr))
    129130        Abort();
    130     hr = g_d3ddevice->Present(nullptr, nullptr, nullptr, nullptr);
     131    hr = d3d_dev->Present(nullptr, nullptr, nullptr, nullptr);
    131132    if (FAILED(hr))
    132133        Abort();
    133 #   else
     134#elif defined USE_SDL
    134135    SDL_GL_SwapBuffers();
    135 #   endif
    136136#endif
    137137}
  • trunk/src/platform/xbox/xboxapp.cpp

    r2506 r2770  
    2020#include "xboxapp.h"
    2121#include "xboxinput.h"
    22 
    23 #if defined _XBOX
    24 extern D3DDevice *g_d3ddevice;
    25 #endif
    2622
    2723namespace lol
     
    6864
    6965#if defined _XBOX
    70     g_d3ddevice->Present(nullptr, nullptr, nullptr, nullptr);
     66    D3DDevice9 *d3d_dev = (D3DDevice9 *)g_renderer->GetDevice();
     67    d3d_dev->Present(nullptr, nullptr, nullptr, nullptr);
    7168#endif
    7269}
  • trunk/src/video.cpp

    r2769 r2770  
    3232using namespace std;
    3333
    34 /* FIXME: g_d3ddevice should never be exported */
    35 #if defined USE_D3D9
    36 IDirect3DDevice9 *g_d3ddevice;
    37 extern HWND g_hwnd;
    38 #elif defined _XBOX
    39 D3DDevice *g_d3ddevice;
    40 HWND g_hwnd = 0;
    41 #endif
    42 
    4334namespace lol
    4435{
     
    5041private:
    5142    static DebugRenderMode render_mode;
    52 #if defined USE_D3D9 || defined _XBOX
    53 #   if defined USE_D3D9
    54     static IDirect3D9 *d3d_ctx;
    55     static IDirect3DDevice9 *d3d_dev;
    56 #   elif defined _XBOX
    57     static Direct3D *d3d_ctx;
    58     static D3DDevice *d3d_dev;
    59 #   endif
    60 #endif
    6143};
    6244
    6345DebugRenderMode VideoData::render_mode = DebugRenderMode::Default;
    64 
    65 #if defined USE_D3D9 || defined _XBOX
    66 #   if defined USE_D3D9
    67 IDirect3D9 *VideoData::d3d_ctx;
    68 IDirect3DDevice9 *VideoData::d3d_dev;
    69 #   elif defined _XBOX
    70 Direct3D *VideoData::d3d_ctx;
    71 D3DDevice *VideoData::d3d_dev;
    72 #   endif
    73 #endif
    7446
    7547/*
     
    7951void Video::Setup(ivec2 size)
    8052{
    81 #if defined USE_D3D9 || defined _XBOX
    82     VideoData::d3d_ctx = Direct3DCreate9(D3D_SDK_VERSION);
    83     if (!VideoData::d3d_ctx)
    84     {
    85         Log::Error("cannot initialise D3D\n");
    86         exit(EXIT_FAILURE);
    87     }
    88 
    89     /* Choose best viewport size */
    90 #   if defined _XBOX
    91     XVIDEO_MODE VideoMode;
    92     XGetVideoMode(&VideoMode);
    93     size = lol::min(size, ivec2(VideoMode.dwDisplayWidth,
    94                                 VideoMode.dwDisplayHeight);
    95 #   endif
    96     D3DPRESENT_PARAMETERS d3dpp;
    97     memset(&d3dpp, 0, sizeof(d3dpp));
    98     d3dpp.BackBufferWidth = size.x;
    99     d3dpp.BackBufferHeight = size.y;
    100     d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    101     d3dpp.BackBufferCount = 1;
    102     d3dpp.hDeviceWindow = g_hwnd;
    103 #   if defined USE_SDL
    104     d3dpp.Windowed = TRUE;
    105 #   endif
    106     d3dpp.EnableAutoDepthStencil = TRUE;
    107     d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
    108     d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    109     d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
    110 
    111     HRESULT hr = VideoData::d3d_ctx->CreateDevice(0, D3DDEVTYPE_HAL, g_hwnd,
    112                                                   D3DCREATE_HARDWARE_VERTEXPROCESSING,
    113                                                   &d3dpp, &VideoData::d3d_dev);
    114     if (FAILED(hr))
    115     {
    116         Log::Error("cannot create D3D device\n");
    117         exit(EXIT_FAILURE);
    118     }
    119 
    120     g_d3ddevice = VideoData::d3d_dev;
    121 
    12253    g_renderer = new Renderer(size);
    123 #else
    124     /* Initialise OpenGL */
    125     g_renderer = new Renderer(size);
    126 #endif
    12754
    12855    /* Initialise reasonable scene default properties */
Note: See TracChangeset for help on using the changeset viewer.