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

Improve material rendering, fix texture loading

This commit is contained in:
Daniel Evans 2014-06-19 16:31:01 +01:00
parent 74d6bed7f3
commit 15c41d137d
4 changed files with 33 additions and 10 deletions

View File

@ -116,7 +116,7 @@ GLuint createTexture(RW::BSTextureNative& texNative, RW::BinaryStreamSection& ro
auto coldata = rootSection.raw() + sizeof(RW::BSTextureNative);
coldata += sizeof(uint32_t);
GLenum type, format;
GLenum type = GL_UNSIGNED_BYTE, format = GL_RGBA;
switch(texNative.rasterformat)
{
case RW::BSTextureNative::FORMAT_1555:
@ -132,6 +132,8 @@ GLuint createTexture(RW::BSTextureNative& texNative, RW::BinaryStreamSection& ro
format = GL_BGRA;
type = GL_UNSIGNED_BYTE;
break;
default:
break;
}
glGenTextures(1, &textureName);
@ -211,11 +213,15 @@ bool TextureLoader::loadFromMemory(char *data, GameData *gameData)
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, alpha}, {id, transparent}});
gameData->textures.insert({{name, ""}, {id, transparent}});
gameData->textures[{name, alpha}] = {id, transparent};
if( !alpha.empty() ) {
gameData->textures[{name, ""}] = {id, transparent};
}
}
return true;

View File

@ -246,6 +246,7 @@ void GameRenderer::renderWorld(float alpha)
rendered = culled = 0;
glActiveTexture(GL_TEXTURE0);
glUniform1i(uniTexture, 0);
for(size_t i = 0; i < engine->pedestrians.size(); ++i) {
@ -574,16 +575,19 @@ bool GameRenderer::renderSubgeometry(Model* model, size_t g, size_t sg, const gl
if(tex.transparent && queueTransparent) {
return false;
}
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex.texName);
}
else {
// Texture pair is missing?
}
}
else {
glBindTexture(GL_TEXTURE_2D, 0);
}
if( (model->geometries[g]->flags & RW::BSGeometry::ModuleMaterialColor) == RW::BSGeometry::ModuleMaterialColor) {
auto col = mat.colour;
if(col.a < 255 && queueTransparent) return false;
if( object && object->type() == GameObject::Vehicle ) {
auto vehicle = static_cast<VehicleObject*>(object);
if( (mat.flags&Model::MTF_PrimaryColour) != 0 ) {
@ -593,11 +597,11 @@ bool GameRenderer::renderSubgeometry(Model* model, size_t g, size_t sg, const gl
oudata.colour = glm::vec4(vehicle->colourSecondary, 1.f);
}
else {
oudata.colour = {col.r/255.f, col.g/255.f, col.b/255.f, 1.f};
oudata.colour = {col.r/255.f, col.g/255.f, col.b/255.f, col.a/255.f};
}
}
else {
oudata.colour = {col.r/255.f, col.g/255.f, col.b/255.f, 1.f};
oudata.colour = {col.r/255.f, col.g/255.f, col.b/255.f, col.a/255.f};
}
}

View File

@ -2,22 +2,35 @@
#include <render/Model.hpp>
#include <glm/gtx/string_cast.hpp>
void ModelFramesWidget::updateInfoBox(ModelFrame *f)
void ModelFramesWidget::updateInfoBox(Model* model, ModelFrame *f)
{
if( f == nullptr ) {
_frameLabel->setText("");
}
else {
auto labText = QString("Name: %1\nTranslation: %2")
auto labText = QString("Name: %1\nTranslation: %2\nTextures:%3")
.arg(QString::fromStdString(f->getName()))
.arg(QString::fromStdString(glm::to_string(f->getDefaultTranslation())));
QString geomString;
for(size_t gi : f->getGeometries()) {
auto& g = model->geometries[gi];
//for(Model::SubGeometry& sg : g->subgeom)
for(Model::Material& m : g->materials) {
for(Model::Texture& t : m.textures) {
geomString += QString("\n %1 (%2)")
.arg(t.name.c_str())
.arg(t.alphaName.c_str());
}
}
}
labText = labText.arg(geomString);
_frameLabel->setText(labText);
}
}
void ModelFramesWidget::selectedModelChanged(const QModelIndex & n, const QModelIndex &)
{
updateInfoBox( (ModelFrame*) n.internalPointer() );
updateInfoBox( gmodel, (ModelFrame*) n.internalPointer() );
}
ModelFramesWidget::ModelFramesWidget(QWidget* parent, Qt::WindowFlags flags)

View File

@ -22,7 +22,7 @@ class ModelFramesWidget : public QDockWidget
private slots:
void updateInfoBox(ModelFrame* f);
void updateInfoBox(Model* model, ModelFrame* f);
void selectedModelChanged(const QModelIndex&,const QModelIndex&);