DLL or no DLL

Use d3dx9_43.dll or no DLL?

  • Use d3dx9_43.dll

    Votes: 0 0.0%
  • No DLL

    Votes: 3 100.0%

  • Total voters
    3

Ferdi

New member
3rd Party Target Dev
Joined
Jun 21, 2017
Messages
87
The last example I had to include a d3dx9_43.dll. I added that DLL because of this one line:

C++:
//    HRESULT result = D3DXCreateTextureFromFileEx(
//        _dx9fwD3dDev,                // LPDIRECT3DDEVICE9 pDevice
//        path.ToCString<char>(),        // LPCTSTR pSrcFile
//        D3DX_DEFAULT_NONPOW2,        // UINT Width
//        D3DX_DEFAULT_NONPOW2,        // UINT Height
//        1,                            // UINT MipLevels
//        0,                            // DWORD Usage
//        D3DFMT_UNKNOWN,             // D3DFORMAT Format
//        D3DPOOL_MANAGED,            // D3DPOOL Pool
//        D3DX_DEFAULT,                // DWORD Filter
//        D3DX_DEFAULT,                // DWORD MipFilter
//        0,                            // D3DCOLOR ColorKey
//        &imageInfo,                    // D3DXIMAGE_INFO *pSrcInfo
//        NULL,                        // PALETTEENTRY *pPalette
//        &d3dTex);                    // LPDIRECT3DTEXTURE9 *ppTexture

I use d3dx to load and create the texture. But in GLFW, images are loaded using stb_image.h. This stb_image.h code is very stable. Any C++ target, I think uses this stb_image.h file (like ios target). I can reuse stb_image.h and try to create the texture myself. The code below is to create a texture:

C++:
    texWidth  = width;
    texHeight = height;

    HRESULT result;
    result = _dx9fwD3dDev->CreateTexture(width, height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &d3dTex, NULL);
    if(FAILED(result))
    {
        texWidth  = Pow2Size(width);
        texHeight = Pow2Size(height);

        result = _dx9fwD3dDev->CreateTexture(texWidth, texHeight, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &d3dTex, NULL);
        if(FAILED(result))
        {
            dx9fwError(__FILE__, __LINE__, "CreateTexture FAILED!");
        }
    }

//        bbPrint(String("texWidth = ") + texWidth + String(" texHeight = ") + texHeight);

    D3DLOCKED_RECT lockedRect;

    d3dTex->LockRect(0, &lockedRect, NULL, 0);

    unsigned char * dstRow = (unsigned char *)lockedRect.pBits;
    unsigned char * dst;
    unsigned char * src = data;

    switch( depth )
    {
    case 1:
        for (int yp = 0; yp < height; yp++)
        {
            dst = dstRow;
            for (int xp = 0; xp < width; xp++)
            {
                dst[0] = src[0];    // blue
                dst[1] = src[0];    // green
                dst[2] = src[0];    // red
                dst[3] = 0xFF;        // alpha
                dst += 4;
                src += 1;
            }
            dstRow += lockedRect.Pitch;
        }
        break;

    case 2:
        for (int yp = 0; yp < height; yp++)
        {
            dst = dstRow;
            for (int xp = 0; xp < width; xp++)
            {
                dst[0] = src[0] * src[1] / 255;    // blue
                dst[1] = dst[0];    // green
                dst[2] = dst[0];    // red
                dst[3] = src[1];    // alpha
                dst += 4;
                src += 2;
            }
            dstRow += lockedRect.Pitch;
        }
        break;

    case 3:
        for (int yp = 0; yp < height; yp++)
        {
            dst = dstRow;
            for (int xp = 0; xp < width; xp++)
            {
                dst[0] = src[2];    // blue
                dst[1] = src[1];    // green
                dst[2] = src[0];    // red
                dst[3] = 0xFF;        // alpha
                dst += 4;
                src += 3;
            }
            dstRow += lockedRect.Pitch;
        }
        break;

    case 4:
        for (int yp = 0; yp < height; yp++)
        {
            dst = dstRow;
            for (int xp = 0; xp < width; xp++)
            {
                dst[0] = src[2] * src[3] / 255;    // blue
                dst[1] = src[1] * src[3] / 255;    // green
                dst[2] = src[0] * src[3] / 255;    // red
                dst[3] = src[3];                // alpha
                dst += 4;
                src += 4;
            }
            dstRow += lockedRect.Pitch;
        }
        break;
    }

    d3dTex->UnlockRect(0);

I am not sure how compatible the above create texture code is. I also should point out that in mojotest images are loaded and discarded every update. And I notice if I use d3dx there is a small memory leak. May be ~100 bytes per call. And if your PC is now 16GB, I think it is a non-issue.

Just to summarise:

Use d3dx9_43.dll
* There is a small memory leak in D3DXCreateTextureFromFileEx, when I test it using mojotest.
* d3dx9_43.dll has to be included with your executable.
* May be better compatibility.

No DLL
* No memory leak. My test using mojotest show stable memory.
* No DLL.
* May not be as compatible.
 

MikeHart

Administrator
3rd Party Module Dev
3rd Party Target Dev
3rd Party Tool Dev
Joined
Jun 19, 2017
Messages
3,346
No dll cause no leak.
 

nullterm

New member
Joined
Jun 21, 2017
Messages
20
Always go with the no DLL option when you can. Less things to go wrong.
 

Ferdi

New member
3rd Party Target Dev
Joined
Jun 21, 2017
Messages
87
Yes I went with no DLL. But I comment out the DLL code, incase the compatibility is not very good. Should just let git worry about it.
 
Top Bottom