Domanda

I'm trying to make a texture handler so that I can load texture file names from a text file and then load the textures and store them into a vector and get them whenever I need to draw.

Problem is, i'm getting the C2259 error which breaks before it can compile and was wondering if anyone could help me out.

TextureManager.h

class TextureManager{
private:
    std::vector<ID3D11ShaderResourceView> * textures;
public:
    TextureManager();
    ~TextureManager();
    void TMLoadTexture(ID3D11Device* d);
    ID3D11ShaderResourceView * TMgetTexture(int index);
};

TextureManager.cpp - TMLoadTexture / TMGetTexture

void TextureManager::TMLoadTexture(ID3D11Device* d)
{
    std::vector<std::string> files;
    files = readFile("textures");

    D3DX11_IMAGE_LOAD_INFO loadInfo;
    ZeroMemory(&loadInfo, sizeof(D3DX11_IMAGE_LOAD_INFO));
    loadInfo.BindFlags = D3D11_BIND_SHADER_RESOURCE;
    loadInfo.Format = DXGI_FORMAT_BC1_UNORM;

for(int i = 0; i < files.size(); i++)
{
    std::wstring stemp = std::wstring(files.at(i).begin(), files.at(i).end());
    LPCWSTR sw = stemp.c_str();

    ID3D11ShaderResourceView* temp;
    D3DX11CreateShaderResourceViewFromFile(d, sw, &loadInfo, NULL, &temp, NULL);
    textures->push_back(*temp);
    delete temp;
}
}

ID3D11ShaderResourceView * TextureManager::TMgetTexture(int index)
{
    return &textures->at(index);
}

Thanks :)

È stato utile?

Soluzione

Since ID3D11ShaderResourceView is an interface, you must use a pointer to access these kind of objects. So:

std::vector<ID3D11ShaderResourceView*> * textures;

Btw, are you sure that you want to use a vector-pointer? I see no reason why a plain vector<...> wouldn't be sufficient.

Then when loading the texture, put the pointer in the vector:

textures.push_back(temp);

And don't delete the texture you just created.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top