int loadTexture(const char* buffer, size_t size) { char name[64] = ""; snprintf(name, 64, "_res%i", _res_loaded++); H3DRes res = h3dAddResource(H3DResTypes::Texture, name, 0); if(!h3dLoadResource(res, buffer, size)) { dumpMessages(); throw tgException("unable to load texture resource"); } int handle = TextureManager::addTexture(res); dumpMessages(); return handle; }
int loadTexture(const char* filename) { H3DRes res; try { res = _loadResource(H3DResTypes::Texture, filename); } catch(...) { dumpMessages(); throw; } int handle = TextureManager::addTexture(res); dumpMessages(); return handle; }
void setGeo(const char* filename) { H3DRes res; try { res = _loadResource(H3DResTypes::Geometry, filename); } catch(...) { dumpMessages(); throw; } if(_geometry) h3dUnloadResource(_geometry); _geometry = res; if(_geometry != 0 && _shader != 0) Viewer::newModel(_geometry, _mat_builder->getRes()); dumpMessages(); }
void setPipeline(const char* buffer, size_t size) { char name[64] = ""; snprintf(name, 64, "_res%i", _res_loaded++); H3DRes res = h3dAddResource(H3DResTypes::Pipeline, name, 0); if(!h3dLoadResource(res, buffer, size)) { dumpMessages(); throw tgException("unable to load pipeline resource"); } else { if(_pipeline) h3dUnloadResource(_pipeline); _pipeline = res; Viewer::newCamera(res); dumpMessages(); } }
void setShader(const char* buffer, size_t size) { char name[64] = ""; snprintf(name, 64, "_res%i", _res_loaded++); H3DRes res = h3dAddResource(H3DResTypes::Shader, name, 0); if(!h3dLoadResource(res, buffer, size)) { dumpMessages(); throw tgException("unable to load shader resource"); } else { if(_shader) h3dUnloadResource(_shader); _shader = res; _mat_builder->setShader(name); _mat_builder->build(); dumpMessages(); } }
void setGeo(const char* buffer, size_t size) { char name[64] = ""; snprintf(name, 64, "_res%i", _res_loaded++); H3DRes res = h3dAddResource(H3DResTypes::Geometry, name, 0); if(!h3dLoadResource(res, buffer, size)) { dumpMessages(); throw tgException("unable to load shader resource"); } else { if(_geometry) h3dUnloadResource(_geometry); _geometry = res; if(_geometry != 0 && _shader != 0) Viewer::newModel(_geometry, _mat_builder->getRes()); dumpMessages(); } }
void setPipeline(const char* filename) { char buffer[64] = ""; snprintf(buffer, 64, "_res%i", _res_loaded++); H3DRes res = h3dAddResource(H3DResTypes::Pipeline, buffer, 0); try { _loadXmlResource(res, filename); } catch(...) { dumpMessages(); throw; } if(_pipeline) h3dUnloadResource(_pipeline); _pipeline = res; Viewer::newCamera(res); dumpMessages(); }
void setShader(const char* filename) { H3DRes res; char res_name[64]; snprintf(res_name, 64, "_res%i", _res_loaded++); try { res = _loadResource(res_name, H3DResTypes::Shader, filename); } catch(...) { dumpMessages(); throw; } if(_shader) h3dUnloadResource(_shader); _shader = res; _mat_builder->setShader(res_name); _mat_builder->build(); dumpMessages(); }
void unbindSampler(const char* sampler_name) { const char* res_name = _mat_builder->getSamplerRes(sampler_name); _mat_builder->removeSampler(sampler_name); _mat_builder->build(); if(res_name != nullptr) { H3DRes res = h3dFindResource(H3DResTypes::Texture, res_name); if(res != 0) { TextureManager::removeResource(res); if(h3dIsResLoaded(res)) h3dUnloadResource(res); h3dRemoveResource(res); } } dumpMessages(); }
void bindSampler(int tex, const char* sampler_name) { const char* res_name = _mat_builder->getSamplerRes(sampler_name); if(res_name != nullptr) { H3DRes res = h3dFindResource(H3DResTypes::Texture, res_name); if(res != 0) { TextureManager::removeResource(res); if(h3dIsResLoaded(res)) h3dUnloadResource(res); h3dRemoveResource(res); } } H3DRes res = TextureManager::getTexRes(tex); res_name = h3dGetResName(res); _mat_builder->setSampler(sampler_name, res_name); _mat_builder->build(); dumpMessages(); }
int main( int argc, char **argv ) { app = argv[0]; QApplication qapp( argc, argv, FALSE ); QStringList configs; QString prefix; bool buildIde = TRUE; for ( int i = 1; i < qapp.argc(); i++ ) { QString arg = qapp.argv()[i]; if ( arg.startsWith( "--" ) ) arg = arg.mid( 1 ); if ( arg == "-help" ) { ; // handled by the configure script } else if ( arg == "-thread" ) { configs << "thread"; } else if ( arg == "-prefix" ) { if ( i + 1 < qapp.argc() ) { prefix = qapp.argv()[++i]; } else { qWarning( "-prefix option requires path argument" ); exit( 2 ); } } else if ( arg == "-no-ide" ) { buildIde = FALSE; configs << "noide"; } else { qWarning( "Unknown option: %s", qapp.argv()[i] ); exit( 1 ); } } // these are here in case .qmake.cache is missing #if defined(QT_MODULE_XML) configs.append( "xml" ); #endif #if defined(QT_MODULE_TABLE) configs.append( "table" ); #endif #if defined(QT_MODULE_SQL) configs.append( "sql" ); #endif #if defined(QT_MODULE_NETWORK) configs.append( "network" ); #endif qtDir = new QString( getenv( "QTDIR" ) ); if ( qtDir->isEmpty() ) { qWarning( "%s: QTDIR not set", app ); dumpMessages(); return 1; } *qtDir += "/"; if ( !checkLicense() ) { dumpMessages(); return 1; } if( !writeQSConfig( buildIde ) ) { dumpMessages(); return 1; } if ( !prefix ) copyQSAHeaders(); //installDocs(); runQMake( configs, prefix ); int retVal = processes > 0 ? qapp.exec() : 0; if( retVal || errors ) { message( "\nThere were errors during configure!" ); } else if( warnings ) { message( "\nThere were errors during configure, but these" "\ndo not appear to be fatal, so you should still be" "\nable to build QSA." "\nRun your make tool to build QSA." ); } else { message( "\n" "Configuration completed successfully\n" "Run your make tool to build QSA" ); } dumpMessages(); return retVal || errors; }
void replaceSamplerRes(const char* old_name, const char* new_name) { _mat_builder->replaceSamplerRes(old_name, new_name); _mat_builder->build(); dumpMessages(); }
void disableShaderFlag(int flag) { _mat_builder->unsetShaderFlag(flag); _mat_builder->build(); dumpMessages(); }
void removeUniform(const char* name) { _mat_builder->removeUniform(name); _mat_builder->build(); dumpMessages(); }
void setUniform(const char* name, float a, float b, float c, float d) { _mat_builder->setUniform(name, a, b, c, d); _mat_builder->build(); dumpMessages(); }
void setGeo( std::vector<float> verts, std::vector<float> normals, std::vector<float> tangents, std::vector<float> binormals, std::vector<float> texcoords1, std::vector<float> texcoords2, std::vector<unsigned> indices, bool get_tanspace) { if(indices.size() <= 0) throw tgException("no triangle indices supplied"); else if(indices.size() % 3 != 0) throw tgException("triangle indices must come in packs of three"); unsigned num_verts = verts.size(); if(num_verts <= 0) throw tgException("no vertices supplied"); else if(num_verts % 3 != 0) throw tgException("vertices must have three components each"); num_verts /= 3; std::unique_ptr<int16_t[]> norms, tangs, binorms; float *tex1, *tex2; if(normals.empty()) { norms = nullptr; tangs = nullptr; binorms = nullptr; } else if(normals.size() != num_verts * 3) throw tgException("number of normals does not match number of vertices"); else { norms.reset(new int16_t[num_verts * 3]); for(unsigned i = 0; i < num_verts * 3; ++i) { norms[i] = (int16_t)(normals[i] * std::numeric_limits<int16_t>::max()); } if(tangents.empty()) tangs = nullptr; else if(tangents.size() != num_verts * 3) throw tgException("number of tangents does not match number of vertices"); else { tangs.reset(new int16_t[num_verts * 3]); for(unsigned i = 0; i < num_verts * 3; ++i) { tangs[i] = (int16_t)(tangents[i] * std::numeric_limits<int16_t>::max()); } } if(binormals.empty()) binorms = nullptr; else if(binormals.size() != num_verts * 3) throw tgException("number of binormals does not match number of vertices"); else { binorms.reset(new int16_t[num_verts * 3]); for(unsigned i = 0; i < num_verts * 3; ++i) { binorms[i] = (int16_t)(binormals[i] * std::numeric_limits<int16_t>::max()); } } if((bool)binorms != (bool)tangs && get_tanspace) { if((bool)tangs) { binorms.reset(new int16_t[num_verts * 3]); for(unsigned i = 0; i < num_verts * 3; i += 3) { Eigen::Vector3f norm(normals[i], normals[i + 1], normals[i + 2]); Eigen::Vector3f tang(tangents[i], tangents[i + 1], tangents[i + 2]); Eigen::Vector3f bin = norm.cross(tang); binorms[i] = (int16_t)(bin[0] * std::numeric_limits<int16_t>::max()); binorms[i + 1] = (int16_t)(bin[1] * std::numeric_limits<int16_t>::max()); binorms[i + 2] = (int16_t)(bin[2] * std::numeric_limits<int16_t>::max()); } } else { tangs.reset(new int16_t[num_verts * 3]); for(unsigned i = 0; i < num_verts * 3; i += 3) { Eigen::Vector3f norm(normals[i], normals[i + 1], normals[i + 2]); Eigen::Vector3f bin(binormals[i], binormals[i + 1], binormals[i + 2]); Eigen::Vector3f tang = bin.cross(norm); tangs[i] = (int16_t)(tang[0] * std::numeric_limits<int16_t>::max()); tangs[i + 1] = (int16_t)(tang[1] * std::numeric_limits<int16_t>::max()); tangs[i + 2] = (int16_t)(tang[2] * std::numeric_limits<int16_t>::max()); } } } } if(texcoords1.empty()) tex1 = nullptr; else if(texcoords1.size() != num_verts * 2) throw tgException( "number if texcoords stream 1 does not match number of vertices"); else tex1 = texcoords1.data(); if(texcoords2.empty()) tex2 = nullptr; else if(texcoords2.size() != num_verts * 2) throw tgException( "number if texcoords stream 2 does not match number of vertices"); else tex2 = texcoords2.data(); H3DRes res; try { res = _makeGeometry(num_verts, verts.data(), norms.get(), tangs.get(), binorms.get(), tex1, tex2, indices.size() / 3, indices.data()); } catch(...) { dumpMessages(); throw; } if(_geometry) h3dUnloadResource(_geometry); _geometry = res; if(_geometry != 0 && _shader != 0) Viewer::newModel(_geometry, _mat_builder->getRes()); dumpMessages(); }