clean up code

This commit is contained in:
Sam Gateau 2015-03-19 15:23:50 -07:00
parent 619a323196
commit 65727dd613
2 changed files with 61 additions and 393 deletions

View file

@ -93,46 +93,7 @@ Model::Model(QObject* parent) :
Model::~Model() { Model::~Model() {
deleteGeometry(); deleteGeometry();
} }
/*
ProgramObject Model::_POprogram;
ProgramObject Model::_POnormalMapProgram;
ProgramObject Model::_POspecularMapProgram;
ProgramObject Model::_POnormalSpecularMapProgram;
ProgramObject Model::_POtranslucentProgram;
ProgramObject Model::_POlightmapProgram;
ProgramObject Model::_POlightmapNormalMapProgram;
ProgramObject Model::_POlightmapSpecularMapProgram;
ProgramObject Model::_POlightmapNormalSpecularMapProgram;
ProgramObject Model::_POshadowProgram;
ProgramObject Model::_POskinProgram;
ProgramObject Model::_POskinNormalMapProgram;
ProgramObject Model::_POskinSpecularMapProgram;
ProgramObject Model::_POskinNormalSpecularMapProgram;
ProgramObject Model::_POskinTranslucentProgram;
ProgramObject Model::_POskinShadowProgram;
Model::Locations Model::_POlocations;
Model::Locations Model::_POnormalMapLocations;
Model::Locations Model::_POspecularMapLocations;
Model::Locations Model::_POnormalSpecularMapLocations;
Model::Locations Model::_POtranslucentLocations;
Model::Locations Model::_POlightmapLocations;
Model::Locations Model::_POlightmapNormalMapLocations;
Model::Locations Model::_POlightmapSpecularMapLocations;
Model::Locations Model::_POlightmapNormalSpecularMapLocations;
Model::SkinLocations Model::_POskinLocations;
Model::SkinLocations Model::_POskinNormalMapLocations;
Model::SkinLocations Model::_POskinSpecularMapLocations;
Model::SkinLocations Model::_POskinNormalSpecularMapLocations;
Model::SkinLocations Model::_POskinShadowLocations;
Model::SkinLocations Model::_POskinTranslucentLocations;
*/
gpu::ShaderPointer Model::_program; gpu::ShaderPointer Model::_program;
gpu::ShaderPointer Model::_normalMapProgram; gpu::ShaderPointer Model::_normalMapProgram;
gpu::ShaderPointer Model::_specularMapProgram; gpu::ShaderPointer Model::_specularMapProgram;
@ -232,100 +193,6 @@ void Model::initSkinProgram(gpu::ShaderPointer& program, Model::SkinLocations& l
locations.clusterIndices = program->getInputs().findLocation("clusterIndices");; locations.clusterIndices = program->getInputs().findLocation("clusterIndices");;
locations.clusterWeights = program->getInputs().findLocation("clusterWeights");; locations.clusterWeights = program->getInputs().findLocation("clusterWeights");;
} }
/*
void Model::initProgram(ProgramObject& program, Model::Locations& locations, bool link) {
if (link) {
program.bindAttributeLocation("tangent", gpu::Stream::TANGENT);
program.bindAttributeLocation("texcoord1", gpu::Stream::TEXCOORD1);
program.link();
}
program.bind();
locations.tangent = program.attributeLocation("tangent");
locations.alphaThreshold = program.uniformLocation("alphaThreshold");
locations.texcoordMatrices = program.uniformLocation("texcoordMatrices");
locations.emissiveParams = program.uniformLocation("emissiveParams");
locations.glowIntensity = program.uniformLocation("glowIntensity");
program.setUniformValue("diffuseMap", 0);
program.setUniformValue("normalMap", 1);
int loc = program.uniformLocation("specularMap");
if (loc >= 0) {
program.setUniformValue("specularMap", 2);
locations.specularTextureUnit = 2;
} else {
locations.specularTextureUnit = -1;
}
loc = program.uniformLocation("emissiveMap");
if (loc >= 0) {
program.setUniformValue("emissiveMap", 3);
locations.emissiveTextureUnit = 3;
} else {
locations.emissiveTextureUnit = -1;
}
// bindable uniform version
#if (GPU_FEATURE_PROFILE == GPU_CORE)
loc = glGetUniformBlockIndex(program.programId(), "materialBuffer");
if (loc >= 0) {
glUniformBlockBinding(program.programId(), loc, MATERIAL_GPU_SLOT);
locations.materialBufferUnit = MATERIAL_GPU_SLOT;
} else {
locations.materialBufferUnit = -1;
}
#else
loc = program.uniformLocation("materialBuffer");
if (loc >= 0) {
locations.materialBufferUnit = loc;
} else {
locations.materialBufferUnit = -1;
}
#endif
#if (GPU_FEATURE_PROFILE == GPU_CORE)
loc = glGetUniformBlockIndex(program.programId(), "transformObjectBuffer");
if (loc >= 0) {
glUniformBlockBinding(program.programId(), loc, gpu::TRANSFORM_OBJECT_SLOT);
// locations.materialBufferUnit = 1;
}
#endif
#if (GPU_FEATURE_PROFILE == GPU_CORE)
loc = glGetUniformBlockIndex(program.programId(), "transformCameraBuffer");
if (loc >= 0) {
glUniformBlockBinding(program.programId(), loc, gpu::TRANSFORM_CAMERA_SLOT);
// locations.materialBufferUnit = 1;
}
#endif
//program.link();
if (!program.isLinked()) {
program.release();
}
program.release();
}*/
/*
void Model::initSkinProgram(ProgramObject& program, Model::SkinLocations& locations) {
program.bindAttributeLocation("tangent", gpu::Stream::TANGENT);
program.bindAttributeLocation("texcoord1", gpu::Stream::TEXCOORD1);
program.bindAttributeLocation("clusterIndices", gpu::Stream::SKIN_CLUSTER_INDEX);
program.bindAttributeLocation("clusterWeights", gpu::Stream::SKIN_CLUSTER_WEIGHT);
program.link();
initProgram(program, locations, false);
program.bind();
locations.clusterMatrices = program.uniformLocation("clusterMatrices");
locations.clusterIndices = program.attributeLocation("clusterIndices");
locations.clusterWeights = program.attributeLocation("clusterWeights");
program.release();
}*/
QVector<JointState> Model::createJointStates(const FBXGeometry& geometry) { QVector<JointState> Model::createJointStates(const FBXGeometry& geometry) {
QVector<JointState> jointStates; QVector<JointState> jointStates;
@ -361,8 +228,6 @@ void Model::initJointTransforms() {
void Model::init() { void Model::init() {
if (_program.isNull()) { if (_program.isNull()) {
// if (!_program.isLinked()) {
//Work in progress not used yet
gpu::Shader::BindingSet slotBindings; gpu::Shader::BindingSet slotBindings;
slotBindings.insert(gpu::Shader::Binding(std::string("materialBuffer"), MATERIAL_GPU_SLOT)); slotBindings.insert(gpu::Shader::Binding(std::string("materialBuffer"), MATERIAL_GPU_SLOT));
slotBindings.insert(gpu::Shader::Binding(std::string("diffuseMap"), 0)); slotBindings.insert(gpu::Shader::Binding(std::string("diffuseMap"), 0));
@ -460,78 +325,6 @@ void Model::init() {
_skinTranslucentProgram = gpu::ShaderPointer(gpu::Shader::createProgram(skinModelVertex, modelTranslucentPixel)); _skinTranslucentProgram = gpu::ShaderPointer(gpu::Shader::createProgram(skinModelVertex, modelTranslucentPixel));
makeResult = gpu::Shader::makeProgram(*_skinTranslucentProgram, slotBindings); makeResult = gpu::Shader::makeProgram(*_skinTranslucentProgram, slotBindings);
initSkinProgram(_skinTranslucentProgram, _skinTranslucentLocations); initSkinProgram(_skinTranslucentProgram, _skinTranslucentLocations);
/*
_POprogram.addShaderFromSourceCode(QGLShader::Vertex, model_vert);
_POprogram.addShaderFromSourceCode(QGLShader::Fragment, model_frag);
initProgram(_POprogram, _POlocations);
_POnormalMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_normal_map_vert);
_POnormalMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_normal_map_frag);
initProgram(_POnormalMapProgram, _POnormalMapLocations);
_POspecularMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_vert);
_POspecularMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_specular_map_frag);
initProgram(_POspecularMapProgram, _POspecularMapLocations);
_POnormalSpecularMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_normal_map_vert);
_POnormalSpecularMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_normal_specular_map_frag);
initProgram(_POnormalSpecularMapProgram, _POnormalSpecularMapLocations);
_POtranslucentProgram.addShaderFromSourceCode(QGLShader::Vertex, model_vert);
_POtranslucentProgram.addShaderFromSourceCode(QGLShader::Fragment, model_translucent_frag);
initProgram(_POtranslucentProgram, _POtranslucentLocations);
// Lightmap
_POlightmapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_lightmap_vert);
_POlightmapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_lightmap_frag);
initProgram(_POlightmapProgram, _POlightmapLocations);
_POlightmapNormalMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_lightmap_normal_map_vert);
_POlightmapNormalMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_lightmap_normal_map_frag);
initProgram(_POlightmapNormalMapProgramddd, _POlightmapNormalMapLocations);
_POlightmapSpecularMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_lightmap_vert);
_POlightmapSpecularMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_lightmap_specular_map_frag);
initProgram(_POlightmapSpecularMapProgram, _POlightmapSpecularMapLocations);
_POlightmapNormalSpecularMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_lightmap_normal_map_vert);
_POlightmapNormalSpecularMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_lightmap_normal_specular_map_frag);
initProgram(_POlightmapNormalSpecularMapProgram, _POlightmapNormalSpecularMapLocations);
// end lightmap
_POshadowProgram.addShaderFromSourceCode(QGLShader::Vertex, model_shadow_vert);
_POshadowProgram.addShaderFromSourceCode(QGLShader::Fragment, model_shadow_frag);
// Shadow program uses the same locations as standard rendering path but we still need to set the bindings
Model::Locations tempLoc;
initProgram(_POshadowProgram, tempLoc);
_POskinProgram.addShaderFromSourceCode(QGLShader::Vertex, skin_model_vert);
_POskinProgram.addShaderFromSourceCode(QGLShader::Fragment, model_frag);
initSkinProgram(_POskinProgram, _POskinLocations);
_POskinNormalMapProgram.addShaderFromSourceCode(QGLShader::Vertex, skin_model_normal_map_vert);
_POskinNormalMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_normal_map_frag);
initSkinProgram(_POskinNormalMapProgram, _PaOskinNormalMapLocations);
_POskinSpecularMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_vert);
_POskinSpecularMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_specular_map_frag);
initSkinProgram(_POskinSpecularMapProgram, _POskinSpecularMapLocations);
_POskinNormalSpecularMapProgram.addShaderFromSourceCode(QGLShader::Vertex, skin_model_normal_map_vert);
_POskinNormalSpecularMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_normal_specular_map_frag);
initSkinProgram(_POskinNormalSpecularMapProgram, _POskinNormalSpecularMapLocations);
_POskinShadowProgram.addShaderFromSourceCode(QGLShader::Vertex, skin_model_shadow_vert);
_POskinShadowProgram.addShaderFromSourceCode(QGLShader::Fragment, model_shadow_frag);
initSkinProgram(_POskinShadowProgram, _POskinShadowLocations);
_POskinTranslucentProgram.addShaderFromSourceCode(QGLShader::Vertex, skin_model_vert);
_POskinTranslucentProgram.addShaderFromSourceCode(QGLShader::Fragment, model_translucent_frag);
initSkinProgram(_POskinTranslucentProgram, _POskinTranslucentLocations);
*/
} }
} }
@ -2397,165 +2190,80 @@ QVector<int>* Model::pickMeshList(bool translucent, float alphaThreshold, bool h
void Model::pickPrograms(gpu::Batch& batch, RenderMode mode, bool translucent, float alphaThreshold, void Model::pickPrograms(gpu::Batch& batch, RenderMode mode, bool translucent, float alphaThreshold,
bool hasLightmap, bool hasTangents, bool hasSpecular, bool isSkinned, RenderArgs* args, bool hasLightmap, bool hasTangents, bool hasSpecular, bool isSkinned, RenderArgs* args,
Locations*& locations, SkinLocations*& skinLocations) { Locations*& locations, SkinLocations*& skinLocations) {
/* if (false) gpu::ShaderPointer program = _program;
{ locations = &_locations;
ProgramObject* program = &_POprogram; gpu::ShaderPointer skinProgram = _skinProgram;
locations = &_POlocations; skinLocations = &_skinLocations;
ProgramObject* skinProgram = &_POskinProgram; if (mode == SHADOW_RENDER_MODE) {
skinLocations = &_POskinLocations; program = _shadowProgram;
if (mode == SHADOW_RENDER_MODE) { skinProgram = _skinShadowProgram;
program = &_POshadowProgram; skinLocations = &_skinShadowLocations;
skinProgram = &_POskinShadowProgram; } else if (translucent && alphaThreshold == 0.0f) {
skinLocations = &_POskinShadowLocations; program = _translucentProgram;
} else if (translucent && alphaThreshold == 0.0f) { locations = &_translucentLocations;
program = &_POtranslucentProgram; skinProgram = _skinTranslucentProgram;
locations = &_POtranslucentLocations; skinLocations = &_skinTranslucentLocations;
skinProgram = &_POskinTranslucentProgram;
skinLocations = &_POskinTranslucentLocations;
} else if (hasLightmap) { } else if (hasLightmap) {
if (hasTangents) { if (hasTangents) {
if (hasSpecular) { if (hasSpecular) {
program = &_POlightmapNormalSpecularMapProgram; program = _lightmapNormalSpecularMapProgram;
locations = &_POlightmapNormalSpecularMapLocations; locations = &_lightmapNormalSpecularMapLocations;
skinProgram = NULL; skinProgram.reset(nullptr);
skinLocations = NULL;
} else {
program = &_POlightmapNormalMapProgram;
locations = &_POlightmapNormalMapLocations;
skinProgram = NULL;
skinLocations = NULL;
}
} else if (hasSpecular) {
program = &_POlightmapSpecularMapProgram;
locations = &_POlightmapSpecularMapLocations;
skinProgram = NULL;
skinLocations = NULL; skinLocations = NULL;
} else { } else {
program = &_POlightmapProgram; program = _lightmapNormalMapProgram;
locations = &_POlightmapLocations; locations = &_lightmapNormalMapLocations;
skinProgram = NULL; skinProgram.reset(nullptr);
skinLocations = NULL; skinLocations = NULL;
} }
} else if (hasSpecular) {
program = _lightmapSpecularMapProgram;
locations = &_lightmapSpecularMapLocations;
skinProgram.reset(nullptr);
skinLocations = NULL;
} else { } else {
if (hasTangents) { program = _lightmapProgram;
if (hasSpecular) { locations = &_lightmapLocations;
program = &_POnormalSpecularMapProgram; skinProgram.reset(nullptr);
locations = &_POnormalSpecularMapLocations; skinLocations = NULL;
skinProgram = &_POskinNormalSpecularMapProgram; }
skinLocations = &_POskinNormalSpecularMapLocations; } else {
} else { if (hasTangents) {
program = &_POnormalMapProgram; if (hasSpecular) {
locations = &_POnormalMapLocations; program = _normalSpecularMapProgram;
skinProgram = &_POskinNormalMapProgram; locations = &_normalSpecularMapLocations;
skinLocations = &_POskinNormalMapLocations; skinProgram = _skinNormalSpecularMapProgram;
} skinLocations = &_skinNormalSpecularMapLocations;
} else if (hasSpecular) { } else {
program = &_POspecularMapProgram; program = _normalMapProgram;
locations = &_POspecularMapLocations; locations = &_normalMapLocations;
skinProgram = &_POskinSpecularMapProgram; skinProgram = _skinNormalMapProgram;
skinLocations = &_POskinSpecularMapLocations; skinLocations = &_skinNormalMapLocations;
} }
} } else if (hasSpecular) {
program = _specularMapProgram;
ProgramObject* activeProgram = program; locations = &_specularMapLocations;
Locations* activeLocations = locations; skinProgram = _skinSpecularMapProgram;
skinLocations = &_skinSpecularMapLocations;
if (isSkinned) {
activeProgram = skinProgram;
activeLocations = skinLocations;
locations = skinLocations;
}
// This code replace the "bind()" on the QGLProgram
if (!activeProgram->isLinked()) {
activeProgram->link();
} }
}
GLBATCH(glUseProgram)(activeProgram->programId()); gpu::ShaderPointer activeProgram = program;
Locations* activeLocations = locations;
if ((activeLocations->alphaThreshold > -1) && (mode != SHADOW_RENDER_MODE)) {
GLBATCH(glUniform1f)(activeLocations->alphaThreshold, alphaThreshold);
}
if (isSkinned) {
activeProgram = skinProgram;
activeLocations = skinLocations;
locations = skinLocations;
} }
else */
{
gpu::ShaderPointer program = _program;
locations = &_locations;
gpu::ShaderPointer skinProgram = _skinProgram;
skinLocations = &_skinLocations;
if (mode == SHADOW_RENDER_MODE) {
program = _shadowProgram;
skinProgram = _skinShadowProgram;
skinLocations = &_skinShadowLocations;
} else if (translucent && alphaThreshold == 0.0f) {
program = _translucentProgram;
locations = &_translucentLocations;
skinProgram = _skinTranslucentProgram;
skinLocations = &_skinTranslucentLocations;
} else if (hasLightmap) {
if (hasTangents) {
if (hasSpecular) {
program = _lightmapNormalSpecularMapProgram;
locations = &_lightmapNormalSpecularMapLocations;
skinProgram.reset(nullptr);
skinLocations = NULL;
} else {
program = _lightmapNormalMapProgram;
locations = &_lightmapNormalMapLocations;
skinProgram.reset(nullptr);
skinLocations = NULL;
}
} else if (hasSpecular) {
program = _lightmapSpecularMapProgram;
locations = &_lightmapSpecularMapLocations;
skinProgram.reset(nullptr);
skinLocations = NULL;
} else {
program = _lightmapProgram;
locations = &_lightmapLocations;
skinProgram.reset(nullptr);
skinLocations = NULL;
}
} else {
if (hasTangents) {
if (hasSpecular) {
program = _normalSpecularMapProgram;
locations = &_normalSpecularMapLocations;
skinProgram = _skinNormalSpecularMapProgram;
skinLocations = &_skinNormalSpecularMapLocations;
} else {
program = _normalMapProgram;
locations = &_normalMapLocations;
skinProgram = _skinNormalMapProgram;
skinLocations = &_skinNormalMapLocations;
}
} else if (hasSpecular) {
program = _specularMapProgram;
locations = &_specularMapLocations;
skinProgram = _skinSpecularMapProgram;
skinLocations = &_skinSpecularMapLocations;
}
}
gpu::ShaderPointer activeProgram = program; GLuint glprogram = gpu::GLBackend::getShaderID(activeProgram);
Locations* activeLocations = locations; GLBATCH(glUseProgram)(glprogram);
if (isSkinned) {
activeProgram = skinProgram;
activeLocations = skinLocations;
locations = skinLocations;
}
GLuint glprogram = gpu::GLBackend::getShaderID(activeProgram);
GLBATCH(glUseProgram)(glprogram);
if ((activeLocations->alphaThreshold > -1) && (mode != SHADOW_RENDER_MODE)) { if ((activeLocations->alphaThreshold > -1) && (mode != SHADOW_RENDER_MODE)) {
GLBATCH(glUniform1f)(activeLocations->alphaThreshold, alphaThreshold); GLBATCH(glUniform1f)(activeLocations->alphaThreshold, alphaThreshold);
}
} }
} }

View file

@ -315,28 +315,6 @@ private:
int _blendNumber; int _blendNumber;
int _appliedBlendNumber; int _appliedBlendNumber;
/*
static ProgramObject _POprogram;
static ProgramObject _POnormalMapProgram;
static ProgramObject _POspecularMapProgram;
static ProgramObject _POnormalSpecularMapProgram;
static ProgramObject _POtranslucentProgram;
static ProgramObject _POlightmapProgram;
static ProgramObject _POlightmapNormalMapProgram;
static ProgramObject _POlightmapSpecularMapProgram;
static ProgramObject _POlightmapNormalSpecularMapProgram;
static ProgramObject _POshadowProgram;
static ProgramObject _POskinProgram;
static ProgramObject _POskinNormalMapProgram;
static ProgramObject _POskinSpecularMapProgram;
static ProgramObject _POskinNormalSpecularMapProgram;
static ProgramObject _POskinTranslucentProgram;
static ProgramObject _POskinShadowProgram;
*/
static gpu::ShaderPointer _program; static gpu::ShaderPointer _program;
static gpu::ShaderPointer _normalMapProgram; static gpu::ShaderPointer _normalMapProgram;
static gpu::ShaderPointer _specularMapProgram; static gpu::ShaderPointer _specularMapProgram;
@ -380,18 +358,7 @@ private:
static Locations _lightmapNormalMapLocations; static Locations _lightmapNormalMapLocations;
static Locations _lightmapSpecularMapLocations; static Locations _lightmapSpecularMapLocations;
static Locations _lightmapNormalSpecularMapLocations; static Locations _lightmapNormalSpecularMapLocations;
/*
static Locations _POlocations;
static Locations _POnormalMapLocations;
static Locations _POspecularMapLocations;
static Locations _POnormalSpecularMapLocations;
static Locations _POtranslucentLocations;
static Locations _POlightmapLocations;
static Locations _POlightmapNormalMapLocations;
static Locations _POlightmapSpecularMapLocations;
static Locations _POlightmapNormalSpecularMapLocations;
*/
static void initProgram(ProgramObject& program, Locations& locations, bool link = true); static void initProgram(ProgramObject& program, Locations& locations, bool link = true);
static void initProgram(gpu::ShaderPointer& program, Locations& locations); static void initProgram(gpu::ShaderPointer& program, Locations& locations);
@ -408,14 +375,7 @@ private:
static SkinLocations _skinNormalSpecularMapLocations; static SkinLocations _skinNormalSpecularMapLocations;
static SkinLocations _skinShadowLocations; static SkinLocations _skinShadowLocations;
static SkinLocations _skinTranslucentLocations; static SkinLocations _skinTranslucentLocations;
/*
static SkinLocations _POskinLocations;
static SkinLocations _POskinNormalMapLocations;
static SkinLocations _POskinSpecularMapLocations;
static SkinLocations _POskinNormalSpecularMapLocations;
static SkinLocations _POskinShadowLocations;
static SkinLocations _POskinTranslucentLocations;
*/
static void initSkinProgram(ProgramObject& program, SkinLocations& locations); static void initSkinProgram(ProgramObject& program, SkinLocations& locations);
static void initSkinProgram(gpu::ShaderPointer& program, SkinLocations& locations); static void initSkinProgram(gpu::ShaderPointer& program, SkinLocations& locations);