void Savanna::init(int argc, char* argv[]) { SN_LOG("*** Savanna BenchMark for Gepard, 2016. *** "); SN_LOG("Usage: " << argv[0] << " [config-file]"); std::string configFile = ""; if (argc > 1) { configFile = argv[1]; } // Set default configs. configs["iterateCount"] = 10; configs["maxVelocity"] = 51; configs["paintRectSize"] = 30; configs["rectHeight"] = 5; configs["rectNumbers"] = 20; configs["rectWidth"] = 5; configs["seed"] = 1985; configs["warmupCount"] = 3; configs["windowHeight"] = 500; configs["windowWidth"] = 500; SN_LOG("Read config file..."); if (!configFile.empty()) { std::fstream fs(configFile, std::fstream::in); std::string line; while (std::getline(fs, line)) { // Romove '#' comment part and ' ' chars. line = line.substr(0, line.find('#')); if (std::remove(line.begin(), line.end(), ' ') == line.end()) { continue; } std::istringstream issLine(line); std::string key; if (std::getline(issLine, key, '=')) { std::string value; if (std::getline(issLine, value)) { configs[key] = atoi(value.c_str()); } } } SN_LOG("...done."); } else { SN_LOG("...not found. Use default configs."); } SN_LOG(""); SN_LOG(" * Configs:"); for (ConfigMap::iterator config = configs.begin(); config != configs.end(); ++config) { SN_LOG(config->first << "=" << config->second); } SN_LOG(""); surface = makeUnique(new gepard::XSurface(configs["windowWidth"], configs["windowHeight"])); }
int Savanna::run() { SN_LOG("Savanna BenchMark START"); Savanna::React reaction; for (std::list<ZygoteMark*>::iterator it = benchMarks.begin(); it != benchMarks.end() && reaction.isPass(); ++it) { (*it)->init(surface.get()); if ((*it)->start().isPass()) { reaction = (*it)->run(); (*it)->stop(); } } SN_LOG("Savanna BenchMark STOP"); return reaction.isFail() ? int(reaction.ra()) : 0; }
//------------------------------------------------------------------------------ void ObjectTypeDatabase::unregisterModule(const std::string & name) { if (name.empty()) { SN_ERROR("ObjectTypeDatabase::unregisterModule: name is empty"); return; } unsigned int count = 0; for (auto it = m_types.begin(); it != m_types.end(); ++it) { const ObjectType * t = *it; if (t && t->getModuleName() == name) { *it = nullptr; ++count; } } if (count == 0) { SN_LOG("ObjectTypeDatabase::unregisterModule: no type found in module \"" << name << "\""); } }
void debugStackDump(HSQUIRRELVM v) { SN_LOG("Squirrel stack dump:"); for (SQInteger n = 1; n <= sq_gettop(v); ++n) { std::string s = "[" + std::to_string(n) + "] "; s += squirrel::getTypeName(sq_gettype(v, n)); SN_MORE(s); } }
//------------------------------------------------------------------------------ GLContextImpl::GLContextImpl(GLContext & context, GLContextSettings & settings, GLContextImpl * sharedContext) : r_context(context), m_hrc(nullptr), m_dc(nullptr), m_ownHwnd(nullptr) { // Get the HWND from either the passed window or an internal one HWND hwnd = nullptr; const Window * win = r_context.getWindow(); if (win) { // A window was given, go with it hwnd = (HWND)win->getHandle(); } else { // No window was given... // On Windows, we still have to create a dummy window to get a valid DC m_ownHwnd = ::CreateWindow("STATIC", "", WS_POPUP | WS_DISABLED, 0, 0, 1, 1, NULL, NULL, GetModuleHandle(NULL), NULL); ShowWindow(m_ownHwnd, SW_HIDE); hwnd = m_ownHwnd; } m_dc = GetDC(hwnd); if (m_dc) { GLContextSettings initialSettings = settings; createContext(sharedContext ? sharedContext->m_hrc : nullptr, settings, hwnd); if (settings != initialSettings) { SN_WARNING("ContextSettings have been changed for compatibility."); SN_LOG("Requested: " << r_context.getSettings().toString()); SN_LOG("Changed to: " << settings.toString()); } } }
//------------------------------------------------------------------------------ // Static bool ShaderProgram::loadShaderFromSourceCode(GLuint & outShaderID, ShaderType typeGeneric, const std::string & source) { SN_LOG("Compiling shader type " << toString(typeGeneric) << "... "); // Create and compile shader GLenum type = shaderTypeToGL(typeGeneric); outShaderID = glCreateShader(type); // TODO Verify output? if (outShaderID == 0) { SN_ERROR("ShaderProgram::loadShaderFromSourceCode: Unable to create shader. Cause: unknown type (" << toString(typeGeneric) << ")"); return false; } const GLchar * sourceStr = source.c_str(); glCheck(glShaderSource(outShaderID, 1, &sourceStr, 0)); glCheck(glCompileShader(outShaderID)); // Check compilation GLint isCompiled = 0; glCheck(glGetShaderiv(outShaderID, GL_COMPILE_STATUS, &isCompiled)); if (isCompiled != GL_TRUE) { // Retrieve error log size GLint errorSize = 0; glCheck(glGetShaderiv(outShaderID, GL_INFO_LOG_LENGTH, &errorSize)); // This string will contain the error message char * errorStr = new char[errorSize + 1]; errorStr[errorSize] = '\0'; // Retrieve the error log glCheck(glGetShaderInfoLog(outShaderID, errorSize, &errorSize, errorStr)); // Display the error SN_ERROR("ShaderProgram::loadShader: Compile error(s). (shader type is " << toString(typeGeneric) << ")"); SN_ERROR(errorStr); // Free memory and return delete[] errorStr; glCheck(glDeleteShader(outShaderID)); return false; // Error } return true; // Fine ! }
void ZygoteMark::step() { steps++; time(¤tTime); const time_t oneSec = 1; if (currentTime - oldTime >= oneSec) { float avg = 0; sampleCount++; if (sampleCount > 0) { sum += steps; avg = float(sum) / float(sampleCount); } SN_LOG(sampleCount << ". FPS: " << steps << ", AVG: " << avg << ""); // Reset. steps = 0; time(&oldTime); } }
//------------------------------------------------------------------------------ bool ShaderProgram::loadFromSourceCode(const std::unordered_map<ShaderType, std::string> & sources) { // Check if none of the sources is empty if (sources.empty()) { SN_ERROR("ShaderProgram::loadFromSourceCode: source code is empty"); return false; } for (auto it = sources.begin(); it != sources.end(); ++it) { if (it->second.empty()) { SN_ERROR("ShaderProgram::loadFromSourceCode: source code is empty for shader type " << toString(it->first)); return false; } } // Deletes the old program if it was already loaded unload(); // Reset uniforms because they might change if the shader is reloading m_uniforms.clear(); // Create shaders GLuint sID; for (auto it = sources.begin(); it != sources.end(); ++it) { ShaderType shaderType = it->first; if (!loadShaderFromSourceCode(sID, shaderType, it->second)) { // Error unload(); return false; } if (static_cast<u32>(shaderType) >= m_shaders.size()) // Note: enums are ints, not uints m_shaders.resize(shaderType + 1, nullptr); m_shaders[shaderType] = new Shader(sID); } // Link shaders into a program SN_LOG("linking shader program..."); m_programID = glCreateProgram(); // TODO Verify output value? // Attach shaders to the program for (auto it = m_shaders.begin(); it != m_shaders.end(); ++it) { Shader * shader = *it; if (shader) { glCheck(glAttachShader(m_programID, shader->ID)); } } // Generic input shader variables glCheck(glBindAttribLocation(m_programID, VertexAttribute::USE_POSITION, "in_Position")); glCheck(glBindAttribLocation(m_programID, VertexAttribute::USE_COLOR, "in_Color")); glCheck(glBindAttribLocation(m_programID, VertexAttribute::USE_TEXCOORD, "in_TexCoord")); glCheck(glBindAttribLocation(m_programID, VertexAttribute::USE_NORMAL, "in_Normal")); // Link glCheck(glLinkProgram(m_programID)); // Check errors GLint isLinked = 0; glCheck(glGetProgramiv(m_programID, GL_LINK_STATUS, &isLinked)); if (isLinked != GL_TRUE) { // Retrieve error log size GLint errorSize = 0; glCheck(glGetProgramiv(m_programID, GL_INFO_LOG_LENGTH, &errorSize)); // This string will contain the error message char * errorStr = new char[errorSize + 1]; errorStr[errorSize] = '\0'; // Retrieve the error log glCheck(glGetProgramInfoLog(m_programID, errorSize, &errorSize, errorStr)); // Display the error SN_ERROR("ShaderProgram::load: Link error(s)."); SN_ERROR(errorStr); // Free memory and return delete[] errorStr; unload(); // Rollback return false; // Error } return true; // Fine ! }