1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 11:22:45 +01:00

Fix texture lookup index

Alpha texture name is actually important.
This commit is contained in:
Daniel Evans 2014-06-18 06:59:24 +01:00
parent 9f257ea4c4
commit 692cfaa335
4 changed files with 13 additions and 12 deletions

View File

@ -207,7 +207,7 @@ public:
/**
* Loaded Textures and their atlas entries.
*/
std::map<std::string, TextureInfo> textures;
std::map<std::pair<std::string, std::string>, TextureInfo> textures;
/**
* Texture atlases.

View File

@ -167,7 +167,6 @@ Model* LoaderDFF::loadFromMemory(char *data, GameData *gameData)
materiallistsec.getNextChildSection(matI);
geom->materials.resize(materialList.nummaterials);
std::map<std::string, TextureInfo> availableTextures;
for (size_t m = 0; m < materialList.nummaterials; ++m) {
auto materialsec = materiallistsec.getNextChildSection(matI);
@ -214,12 +213,6 @@ Model* LoaderDFF::loadFromMemory(char *data, GameData *gameData)
}
if(geom->materials[m].textures.size() < 1) continue;
auto textureIt = gameData->textures
.find(geom->materials[m].textures[0].name);
if(textureIt != gameData->textures.end()) {
availableTextures.insert({textureIt->first, textureIt->second});
}
}
if(item.hasMoreData(secI))

View File

@ -208,11 +208,14 @@ bool TextureLoader::loadFromMemory(char *data, GameData *gameData)
RW::BSTextureNative texNative = rootSection.readStructure<RW::BSTextureNative>();
std::string name = std::string(texNative.diffuseName);
std::string alpha = std::string(texNative.alphaName);
std::transform(name.begin(), name.end(), name.begin(), ::tolower );
std::transform(alpha.begin(), alpha.end(), alpha.begin(), ::tolower );
bool transparent = false;
GLuint id = createTexture(texNative, rootSection, &transparent);
gameData->textures.insert({name, {id, transparent}});
gameData->textures.insert({{name, alpha}, {id, transparent}});
gameData->textures.insert({{name, ""}, {id, transparent}});
}
return true;

View File

@ -246,7 +246,6 @@ void GameRenderer::renderWorld(float alpha)
rendered = culled = 0;
glActiveTexture(GL_TEXTURE0);
glUniform1i(uniTexture, 0);
for(size_t i = 0; i < engine->pedestrians.size(); ++i) {
@ -395,7 +394,7 @@ void GameRenderer::renderWorld(float alpha)
glm::vec2 waterOffset { -WATER_WORLD_SIZE/2.f, -WATER_WORLD_SIZE/2.f };
glUniform1i(waterTexture, 0);
glUniform2f(waterWave, WATER_SCALE, WATER_HEIGHT);
auto waterTex = engine->gameData.textures["water_old"];
auto waterTex = engine->gameData.textures[{"water_old",""}];
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, waterTex.texName);
@ -567,14 +566,20 @@ bool GameRenderer::renderSubgeometry(Model* model, size_t g, size_t sg, const gl
Model::Material& mat = model->geometries[g]->materials[subgeom.material];
if(mat.textures.size() > 0 ) {
auto t = engine->gameData.textures.find(mat.textures[0].name);
auto& tC = mat.textures[0].name;
auto& tA = mat.textures[0].alphaName;
auto t = engine->gameData.textures.find({tC, tA});
if(t != engine->gameData.textures.end()) {
TextureInfo& tex = t->second;
if(tex.transparent && queueTransparent) {
return false;
}
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex.texName);
}
else {
// Texture pair is missing?
}
}
if( (model->geometries[g]->flags & RW::BSGeometry::ModuleMaterialColor) == RW::BSGeometry::ModuleMaterialColor) {