Changeset 1241


Ignore:
Timestamp:
Apr 20, 2012, 6:33:09 PM (8 years ago)
Author:
sam
Message:

gpu: fix a great lot of Direct3D problems, spotted using PIX.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/deushax/deushax.cpp

    r1229 r1241  
    3232    Application app("Map Test", ivec2(640, 480), 30.0f);
    3333
    34 #if defined _WIN32
     34#if defined _WIN32 && !defined _XBOX
    3535    _chdir(".."); /* Temporary Win32 hack */
    3636#endif
  • trunk/src/gpu/shader.cpp

    r1228 r1241  
    426426    cgGLEnableProfile(cgGLGetLatestProfile(CG_GL_FRAGMENT));
    427427    cgGLBindProgram(data->frag_id);
     428#endif
     429}
     430
     431void Shader::Unbind() const
     432{
     433#if defined USE_D3D9 || defined _XBOX
     434    HRESULT hr;
     435    hr = g_d3ddevice->SetVertexShader(NULL);
     436    hr = g_d3ddevice->SetPixelShader(NULL);
     437#elif !defined __CELLOS_LV2__
     438    /* FIXME: untested */
     439    glUseProgram(0);
     440#else
     441    /* FIXME: untested */
     442    cgGLDisableProfile(cgGLGetLatestProfile(CG_GL_VERTEX));
     443    cgGLDisableProfile(cgGLGetLatestProfile(CG_GL_FRAGMENT));
    428444#endif
    429445}
  • trunk/src/gpu/shader.h

    r1228 r1241  
    7070
    7171    void Bind() const;
     72    void Unbind() const;
    7273
    7374protected:
  • trunk/src/gpu/vertexbuffer.cpp

    r1236 r1241  
    146146{
    147147#if defined _XBOX || defined USE_D3D9
    148     /* FIXME: Nothing to do? */
     148    int stream = -1;
     149    for (int i = 0; i < m_count; i++)
     150        if (m_streams[i].index != stream)
     151        {
     152            stream = m_streams[i].index;
     153            if (FAILED(g_d3ddevice->SetStreamSource(stream, 0, 0, 0)))
     154                Abort();
     155        }
     156    if (FAILED(g_d3ddevice->SetVertexDeclaration(NULL)))
     157        Abort();
    149158#else
    150159    /* FIXME: we need to unbind what we bound */
     
    298307        D3DDECLUSAGE_BINORMAL,
    299308        D3DDECLUSAGE_TESSFACTOR,
     309#if defined _XBOX
     310        D3DDECLUSAGE_TEXCOORD, /* FIXME: nonexistent */
     311#else
    300312        D3DDECLUSAGE_POSITIONT,
     313#endif
    301314        D3DDECLUSAGE_COLOR,
    302315        D3DDECLUSAGE_FOG,
  • trunk/src/platform/sdl/sdlapp.cpp

    r1236 r1241  
    103103    {
    104104#if defined USE_SDL && defined USE_D3D9
    105         if (FAILED(g_d3ddevice->BeginScene()))
     105        HRESULT hr;
     106        hr = g_d3ddevice->BeginScene();
     107        if (FAILED(hr))
    106108            Abort();
    107109#endif
     
    110112#if defined USE_SDL
    111113#   if defined USE_D3D9
    112         if (FAILED(g_d3ddevice->EndScene()))
     114        hr = g_d3ddevice->EndScene();
     115        if (FAILED(hr))
    113116            Abort();
    114         if (FAILED(g_d3ddevice->Present(NULL, NULL, NULL, NULL)))
     117        hr = g_d3ddevice->Present(NULL, NULL, NULL, NULL);
     118        if (FAILED(hr))
    115119            Abort();
    116120#   else
  • trunk/src/scene.cpp

    r1236 r1241  
    386386    data->ntiles = 0;
    387387
     388    stdshader->Unbind();
     389
    388390#if defined USE_D3D9 || defined _XBOX
    389391    /* TODO */
  • trunk/src/tileset.cpp

    r1233 r1241  
    143143           format = D3DFMT_R8G8B8;
    144144#elif defined _XBOX
    145            format = D3DFMT_LIN_R8G8B8; /* FIXME */
     145           format = D3DFMT_LIN_A8R8G8B8; /* FIXME */
    146146#else
    147147           format = GL_RGB;
     
    154154           format = D3DFMT_A8R8G8B8;
    155155#elif defined _XBOX
     156            /* By default the X360 will swizzle the texture. Ask for linear. */
    156157           format = D3DFMT_LIN_A8R8G8B8;
    157158#else
     
    178179#if defined USE_D3D9 || defined _XBOX
    179180        D3DLOCKED_RECT rect;
     181        HRESULT hr;
    180182#   if defined USE_D3D9
    181         g_d3ddevice->CreateTexture(w, h, 1, D3DUSAGE_DYNAMIC, format,
    182                                    D3DPOOL_SYSTEMMEM, &data->m_tex, NULL);
    183         data->m_tex->LockRect(0, &rect, NULL, D3DLOCK_DISCARD | D3DLOCK_NOOVERWRITE);
     183        hr = g_d3ddevice->CreateTexture(w, h, 1, D3DUSAGE_DYNAMIC, format,
     184                                        D3DPOOL_DEFAULT, &data->m_tex, NULL);
    184185#   elif defined _XBOX
    185         /* By default the X360 will swizzle the texture. Ask for linear. */
    186         g_d3ddevice->CreateTexture(w, h, 1, D3DUSAGE_WRITEONLY, format,
    187                                    D3DPOOL_DEFAULT, &data->m_tex, NULL);
    188         data->m_tex->LockRect(0, &rect, NULL, D3DLOCK_NOOVERWRITE);
     186        hr = g_d3ddevice->CreateTexture(w, h, 1, D3DUSAGE_WRITEONLY, format,
     187                                        D3DPOOL_DEFAULT, &data->m_tex, NULL);
    189188#   endif
     189        if (FAILED(hr))
     190            Abort();
     191#   if defined USE_D3D9
     192        hr = data->m_tex->LockRect(0, &rect, NULL, D3DLOCK_DISCARD);
     193#   else
     194        hr = data->m_tex->LockRect(0, &rect, NULL, 0);
     195#   endif
     196        if (FAILED(hr))
     197            Abort();
    190198        for (int j = 0; j < h; j++)
    191199            memcpy((uint8_t *)rect.pBits + j * rect.Pitch, pixels + w * j * 4, w * 4);
    192         data->m_tex->UnlockRect(0);
     200        hr = data->m_tex->UnlockRect(0);
     201        if (FAILED(hr))
     202            Abort();
    193203#else
    194204        glGenTextures(1, &data->m_tex);
     
    230240    {
    231241#if defined USE_D3D9 || defined _XBOX
    232         g_d3ddevice->SetTexture(0, data->m_tex);
     242        HRESULT hr = g_d3ddevice->SetTexture(0, data->m_tex);
     243        if (FAILED(hr))
     244            Abort();
    233245#else
    234246        glActiveTexture(GL_TEXTURE0);
     
    240252void TileSet::Unbind()
    241253{
    242 #if defined USE_D3D9 || defined _XBOX
    243     g_d3ddevice->SetTexture(0, NULL);
    244 #else
    245     glActiveTexture(GL_TEXTURE0);
    246     glBindTexture(GL_TEXTURE_2D, 0);
    247 #endif
     254    if (!data->img && data->m_tex)
     255    {
     256#if defined USE_D3D9 || defined _XBOX
     257        HRESULT hr = g_d3ddevice->SetTexture(0, NULL);
     258        if (FAILED(hr))
     259            Abort();
     260#else
     261        glActiveTexture(GL_TEXTURE0);
     262        glBindTexture(GL_TEXTURE_2D, 0);
     263#endif
     264    }
    248265}
    249266
  • trunk/test/tutorial/tut02.cpp

    r1238 r1241  
    179179        if (FAILED(g_d3ddevice->SetIndices(m_ibo)))
    180180            Abort();
    181         if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 0, 0, sizeof(m_indices) / sizeof(*m_indices))))
     181        if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, sizeof(m_indices) / sizeof(*m_indices))))
    182182            Abort();
    183183#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
Note: See TracChangeset for help on using the changeset viewer.