• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

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

Member
3rd Party Target Dev
Joined
Jun 21, 2017
Messages
88
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.
 
Always go with the no DLL option when you can. Less things to go wrong.
 
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.
 
Back
Top Bottom