void Shader::ShaderProgram::addActiveAttributesFromProgram() { // Length of the longest variable name GLint maxLength; // Number of uniform variables GLint attributeCount; // Get the number of uniforms, and the length of the longest name. glGetProgramiv(glShaderProgramObject(), GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxLength); glGetProgramiv(glShaderProgramObject(), GL_ACTIVE_ATTRIBUTES, &attributeCount); GLchar* name = (GLchar *) System::malloc(maxLength * sizeof(GLchar)); // Get the sizes, types and names if (maxLength > 0) { // If the names are blank, don't try to get them. // Loop over glGetActiveAttribute and store the results away. for (GLuint i = 0; i < (GLuint)attributeCount; ++i) { AttributeDeclaration d; glGetActiveAttrib(glShaderProgramObject(), i, maxLength, NULL, &d.elementNum, &d.type, name); d.location = glGetAttribLocation(glShaderProgramObject(), name); const String n(name); // Ignore empty and incorrect variables, which are occasionally returned by the driver. const bool bogus = ((d.location == -1) && n.empty()) || beginsWith(n, "_main") || beginsWith(n, "_noset_"); if (! bogus) { d.name = n; debugAssert(!attributeDeclarationTable.containsKey(n)); attributeDeclarationTable.set(name, d); } } } System::free(name); name = NULL; }
/** True if the next token begins the close tag */ static bool atClose(TextInput& t, const std::string name) { if ((t.peek().type() == Token::SYMBOL) && (t.peek().string() == "<")) { // Need to keep looking ahead Token p0 = t.read(); if ((t.peek().type() == Token::SYMBOL) && (t.peek().string() == "/")) { // Check the name on the close tag. It *must* match if // this is a well-formed document, but there might be a // tag error. Token p1 = t.read(); Token p2 = t.peek(); std::string s = p2.string(); debugAssertM(beginsWith(name, s), "Mismatched close tag"); // Put the tokens back t.push(p1); t.push(p0); return true; } else { // Put the read token back t.push(p0); return false; } } else { return false; } }
Matrix4::Matrix4(const Any& any) { any.verifyNameBeginsWith("Matrix4", "CFrame", "CoordinateFrame"); any.verifyType(Any::ARRAY); const std::string& name = any.name(); if (name == "Matrix4") { any.verifySize(16); for (int r = 0; r < 4; ++r) { for (int c = 0; c < 4; ++c) { elt[r][c] = any[r * 4 + c]; } } } else if (name == "Matrix4::scale") { if (any.size() == 1) { *this = scale(any[0].floatValue()); } else if (any.size() == 3) { *this = scale(any[0], any[1], any[2]); } else { any.verify(false, "Matrix4::scale() takes either 1 or 3 arguments"); } } else if (name == "Matrix4::rollDegrees") { any.verifySize(1); *this = rollDegrees(any[0].floatValue()); } else if (name == "Matrix4::yawDegrees") { any.verifySize(1); *this = yawDegrees(any[0].floatValue()); } else if (name == "Matrix4::pitchDegrees") { any.verifySize(1); *this = pitchDegrees(any[0].floatValue()); } else if (name == "Matrix4::translation") { if (any.size() == 3) { *this = translation(any[0], any[1], any[2]); } else { any.verify(false, "Matrix4::translation() requires 3 arguments"); } } else if (name == "Matrix4::diagonal") { any.verifySize(4); *this = diagonal(any[0], any[1], any[2], any[3]); } else if (name == "Matrix4::identity") { *this = identity(); } else if (beginsWith(name, "CFrame") || beginsWith(name, "CoordinateFrame")) { *this = CFrame(any); } else { any.verify(false, "Expected Matrix4 constructor"); } }
void Shader::ShaderProgram::addUniformsFromCode(const String& code, const Args& args) { TextInput ti(TextInput::FROM_STRING, code); while (ti.hasMore()) { const Token nextToken = ti.peek(); if ((nextToken.type() == Token::SYMBOL) && (nextToken.string() != "#")) { bool isUniform = false; const GLenum type = getDeclarationType(ti, isUniform); if (isUniform && (type != GL_NONE)) { // Read the name const String& name = ti.readSymbol(); if (isValidIdentifier(name) && !beginsWith(name, "_noset_")) { int arraySize = -1; if ((ti.peek().type() == Token::SYMBOL) && (ti.peek().string() == "[")) { ti.readSymbol("["); parseTokenIntoIntegerLiteral(ti.read(), args, arraySize); ti.readSymbol("]"); } // Read until the semi-colon while (ti.read().string() != ";"); if (arraySize < 0) { // Not an array bool created; UniformDeclaration& d = uniformDeclarationTable.getCreate(name, created); // See if this variable is already declared. if (created) { int index = -1; d.fillOutDummy(name, index, type); } } else { // An array bool created; for (int i = 0; i < arraySize; ++i) { UniformDeclaration& d = uniformDeclarationTable.getCreate(name + format("[%d]", i), created); // See if this variable is already declared. if (created) { d.fillOutDummy(name, i, type); } } } } } else { ti.readUntilNewlineAsString(); } } else { // Consume the entire line ti.readUntilNewlineAsString(); } } }
CoordinateFrame::CoordinateFrame(const Any& any) { *this = CFrame(); const std::string& n = toUpper(any.name()); if (beginsWith(n, "VECTOR3")) { translation = any; } else if (beginsWith(n, "MATRIX3")) { rotation = any; } else if ((n == "CFRAME") || (n == "COORDINATEFRAME")) { any.verifyType(Any::TABLE, Any::ARRAY); if (any.type() == Any::ARRAY) { any.verifySize(2); rotation = any[0]; translation = any[1]; } else { for (Any::AnyTable::Iterator it = any.table().begin(); it.hasMore(); ++it) { const std::string& n = toLower(it->key); if (n == "translation") { translation = Vector3(it->value); } else if (n == "rotation") { rotation = Matrix3(it->value); } else { any.verify(false, "Illegal table key: " + it->key); } } } } else if (beginsWith(n, "PHYSICSFRAME") || beginsWith(n, "PFRAME")) { *this = PhysicsFrame(any); } else { any.verifyName("CFrame::fromXYZYPRDegrees", "CoordinateFrame::fromXYZYPRDegrees"); any.verifyType(Any::ARRAY); any.verifySize(3, 6); int s = any.size(); *this = fromXYZYPRDegrees(any[0], any[1], any[2], (s > 3) ? any[3].number() : 0.0f, (s > 4) ? any[4].number() : 0.0f, (s > 5) ? any[5].number() : 0.0f); } }
bool str::beginsWithWholeWord(const char* pString, char seperator) const { // After comparison, the char must be a space or null terminated int len = strlen(pString); if (len > getLen()) { return false; } const char c = mpStr[len]; return beginsWith(pString) && (seperator == c || '\0' == c); }
PhysicsFrame::PhysicsFrame(const Any& a) { const std::string& n = toLower(a.name()); *this = PhysicsFrame(); if (beginsWith(n, "vector3")) { *this = PhysicsFrame(Vector3(a)); } else if (beginsWith(n, "matrix3")) { *this = PhysicsFrame(Matrix3(a)); } else if (beginsWith(n, "cframe") || beginsWith(n, "coordinateframe")) { *this = PhysicsFrame(CoordinateFrame(a)); } else if (beginsWith(n, "pframe") || beginsWith(n, "physicsframe")) { if (a.type() == Any::ARRAY) { a.verifySize(2); rotation = a[0]; translation = a[1]; } else { for (Any::AnyTable::Iterator it = a.table().begin(); it.hasMore(); ++it) { const std::string& n = toLower(it->key); if (n == "translation") { translation = it->value; } else if (n == "rotation") { rotation = it->value; } else { a.verify(false, "Illegal table key: " + it->key); } } } } }
Quat::Quat(const class Any& a) { *this = Quat(); if (beginsWith(toLower(a.name()), "matrix3")) { *this = a; } else { a.verifyName("Quat"); a.verifyType(Any::ARRAY); x = a[0]; y = a[1]; z = a[2]; w = a[3]; } }
Texture::Specification::Specification(const Any& any, bool assumesRGBForAuto, Dimension defaultDimension) { *this = Specification(); assumeSRGBSpaceForAuto = assumesRGBForAuto; dimension = defaultDimension; if (any.type() == Any::STRING) { filename = any.string(); if (filename == "<whiteCube>") { filename = "<white>"; dimension = Texture::DIM_CUBE_MAP; } if (! beginsWith(filename, "<")) { filename = any.resolveStringAsFilename(); if (FilePath::containsWildcards(filename)) { // Assume this is a cube map dimension = Texture::DIM_CUBE_MAP; } } } else if ((any.type() == Any::NUMBER) || any.nameBeginsWith("Color4") || anyNameIsColor3Variant(any)) { filename = "<white>"; encoding.readMultiplyFirst = Color4(any); } else { any.verifyNameBeginsWith("Texture::Specification"); AnyTableReader r(any); r.getFilenameIfPresent("filename", filename); r.getFilenameIfPresent("alphaFilename", alphaFilename); r.getIfPresent("encoding", encoding); r.getIfPresent("assumeSRGBSpaceForAuto", assumeSRGBSpaceForAuto); { Any a; if (r.getIfPresent("dimension", a)) { dimension = toDimension(a); } } r.getIfPresent("generateMipMaps", generateMipMaps); r.getIfPresent("preprocess", preprocess); r.getIfPresent("visualization", visualization); r.getIfPresent("cachable", cachable); r.verifyDone(); if (! any.containsKey("dimension") && FilePath::containsWildcards(filename)) { // Assume this is a cube map dimension = Texture::DIM_CUBE_MAP; } } }
GLenum GPUProgram::getUnitFromCode(const std::string& code, Extension& extension) { if (beginsWith(code, "!!ARBvp1.0")) { extension = ARB; return GL_VERTEX_PROGRAM_ARB; } if (beginsWith(code, "!!ARBfp1.0")) { extension = ARB; return GL_FRAGMENT_PROGRAM_ARB; } if (beginsWith(code, "!!VP2.0")) { extension = NVIDIA; return GL_VERTEX_PROGRAM_NV; } if (beginsWith(code, "!!VP1.0")) { extension = NVIDIA; return GL_VERTEX_PROGRAM_NV; } if (beginsWith(code, "!!FP1.0")) { extension = NVIDIA; return GL_FRAGMENT_PROGRAM_NV; } if (beginsWith(code, "!!FP1.1")) { extension = NVIDIA; return GL_FRAGMENT_PROGRAM_NV; } if (beginsWith(code, "!!FP2.0")) { extension = NVIDIA; return GL_FRAGMENT_PROGRAM_NV; } else { return GL_NONE; } }
bool getCommandArguments(const std::string &input, const std::string &command, std::string &arguments) { if (!beginsWith(input, command)) return false; if (input.size() == command.size()) return true; if (input.at(command.size()) != ' ') return false; arguments = input.substr(command.size() + 1); return true; }
TEST(StringOps, beginsWith) { EXPECT_TRUE(beginsWith("!test", "!test")); EXPECT_FALSE(beginsWith("!toost", "!test")); EXPECT_TRUE(beginsWith("!test", "!test")); EXPECT_TRUE(beginsWith("!test!", "!test")); EXPECT_FALSE(beginsWith("!tes", "!test")); EXPECT_FALSE(beginsWith("?test", "!test")); }
static void readAndAppendShaderLog(const char* glInfoLog, String& messages, const String& name, const Table<int, String>& indexToNameTable){ int c = 0; // Copy the result to the output string while (glInfoLog[c] != '\0') { // Copy until the next newline or end of string String line; while (glInfoLog[c] != '\n' && glInfoLog[c] != '\r' && glInfoLog[c] != '\0') { line += glInfoLog[c]; ++c; } if (beginsWith(line, "ERROR: ")) { // NVIDIA likes to preface messages with "ERROR: "; strip it off line = line.substr(7); } TextInput::Settings settings; settings.simpleFloatSpecials = false; TextInput t(TextInput::FROM_STRING, line, settings); if ((t.peek().extendedType() == Token::INTEGER_TYPE) || (t.peek().extendedType() == Token::HEX_INTEGER_TYPE)) { // Now parse the file index into a file name const int index = t.readInteger(); line = t.readUntilNewlineAsString(); line = indexToNameTable.get(index) + line; } else { line = ": " + line; } messages += line; if (glInfoLog[c] == '\r' && glInfoLog[c + 1] == '\n') { // Windows newline c += 2; } else if ((glInfoLog[c] == '\r' && glInfoLog[c + 1] != '\n') || // Dangling \r; treat it as a newline glInfoLog[c] == '\n') { ++c; } messages += NEWLINE; } }
void App::countBugs() { bugCount = 0; logPrintf("\n\nBugs:\n"); if (GLCaps::hasBug_glMultiTexCoord3fvARB()) { ++bugCount; logPrintf(" Detected glMultiTexCoord3fvARB bug\n\n"); } if (GLCaps::hasBug_normalMapTexGen()) { ++bugCount; logPrintf(" Detected normalMapTexGen bug\n\n"); } if (GLCaps::hasBug_slowVBO()) { ++bugCount; logPrintf(" Detected slowVBO bug\n\n"); } if (GLCaps::hasBug_redBlueMipmapSwap()) { ++bugCount; logPrintf(" Detected redBlueMipmapSwap bug\n\n"); } if (beginsWith(GLCaps::renderer(), "RADEON") && GLCaps::supports_GL_ARB_shadow() && GLCaps::supports_GL_ARB_shading_language_100()) { // Slow shadow map and GLSL texture binding bugs. // TODO: add actual tests logPrintf(" Detected slowShadowMap bug\n\n"); logPrintf(" Detected GLSL Texture Binding bug\n\n"); bugCount += 2; } if (GLCaps::hasBug_mipmapGeneration()) { ++bugCount; logPrintf(" Detected mipmapGeneration bug\n\n"); } }
void onRelationStart(const QXmlAttributes& attrs) { if (m_bTargetIsUrl) { QString qstrType (attrs.value("type")); if ("AmazonAsin" == qstrType) { m_albumInfo.m_strAmazonLink = convStr(attrs.value("target")); } else if ("CoverArtLink" == qstrType) { string strUrl (convStr(attrs.value("target"))); if (beginsWith(strUrl, "http://")) { m_albumInfo.m_vstrImageNames.push_back(strUrl); } else { //ttt2 perhaps tell the user qDebug("Unsupported image link"); } } } }
CoordinateFrame::CoordinateFrame(const Any& any) { *this = CFrame(); const String& n = toUpper(any.name()); if (beginsWith(n, "VECTOR3") || beginsWith(n, "POINT3")) { translation = Point3(any); } else if (beginsWith(n, "MATRIX3")) { rotation = Matrix3(any); } else if (beginsWith(n, "MATRIX4")) { *this = Matrix4(any).approxCoordinateFrame(); } else if ((n == "CFRAME") || (n == "COORDINATEFRAME")) { any.verifyType(Any::TABLE, Any::ARRAY); if (any.type() == Any::ARRAY) { any.verifySize(2); rotation = any[0]; translation = any[1]; } else { AnyTableReader r(any); r.getIfPresent("translation", translation); r.getIfPresent("rotation", rotation); r.verifyDone(); } } else if (beginsWith(n, "PHYSICSFRAME") || beginsWith(n, "PFRAME")) { *this = PhysicsFrame(any); // } else if (beginsWith(n, "UPRIGHTFRAME") || beginsWith(n, "UFRAME")) { // *this = UprightFrame(any); } else { any.verifyName("CFrame::fromXYZYPRDegrees", "CoordinateFrame::fromXYZYPRDegrees"); any.verifyType(Any::ARRAY); any.verifySize(3, 6); int s = any.size(); *this = fromXYZYPRDegrees(any[0], any[1], any[2], (s > 3) ? (float)any[3].number() : 0.0f, (s > 4) ? (float)any[4].number() : 0.0f, (s > 5) ? (float)any[5].number() : 0.0f); } }
void App::onGraphics (RenderDevice *rd, Array< SurfaceRef > &posed3D, Array< Surface2DRef > &posed2D) { rd->setColorClearValue(Color3::white()); rd->clear(); doFunStuff(); rd->push2D(); int w = rd->width(); int h = rd->height(); /////////////////////////////////////// // Left panel # define LABEL(str) p.y += titleFont->draw2D(rd, str, p - Vector2((float)w * 0.0075f, 0), s * 2, Color3::white() * 0.4f).y # define PRINT(str) p.y += reportFont->draw2D(rd, str, p, s, Color3::black()).y int x0 = int(w * 0.015f); // Cursor position Vector2 p(x0, h * 0.02f); // Font size float s = w * 0.013; LABEL("Shaders"); PRINT(std::string("Combiners: ") + combineShader); PRINT(std::string("Assembly: ") + asmShader); PRINT(std::string("GLSL: ") + glslShader); p.y += s * 2; LABEL("Extensions"); PRINT(std::string("FSAA: ") + ((GLCaps::supports("WGL_ARB_multisample") || GLCaps::supports("GL_ARB_multisample")) ? "Yes" : "No")); PRINT(std::string("Two-sided Stencil: ") + ((GLCaps::supports_two_sided_stencil() ? "Yes" : "No"))); PRINT(std::string("Stencil Wrap: ") + (GLCaps::supports("GL_EXT_stencil_wrap") ? "Yes" : "No")); PRINT(std::string("Texture Compression: ") + (GLCaps::supports("GL_EXT_texture_compression_s3tc") ? "Yes" : "No")); PRINT(std::string("Shadow Maps: ") + (GLCaps::supports("GL_ARB_shadow") ? "Yes" : "No")); PRINT(std::string("Frame Buffer Object: ") + (GLCaps::supports("GL_EXT_framebuffer_object") ? "Yes" : "No")); PRINT(std::string("Vertex Arrays: ") + (GLCaps::supports_GL_ARB_vertex_buffer_object() ? "Yes" : "No")); /////////////////////////////////////// // Right Panel x0 = int(w * 0.6f); // Cursor position p = Vector2(x0, h * 0.02f); // Graphics Card LABEL("Graphics Card"); rd->setTexture(0, cardLogo); Draw::rect2D(Rect2D::xywh(p.x - s * 6, p.y, s * 5, s * 5), rd); rd->setTexture(0, NULL); PRINT(GLCaps::vendor().c_str()); PRINT(GLCaps::renderer().c_str()); PRINT(format("Driver Version %s", GLCaps::driverVersion().c_str())); # ifdef G3D_WIN32 PRINT(format("%d MB Video RAM", DXCaps::videoMemorySize() / (1024 * 1024))); { uint32 ver = DXCaps::version(); PRINT(format("DirectX %d.%d", ver/100, ver%100)); } # endif p.y += s * 2; // Processor LABEL("Processor"); rd->setTexture(0, chipLogo); Draw::rect2D(Rect2D::xywh(p.x - s * 6, p.y, s * 5, s * 5), rd); rd->setTexture(0, NULL); PRINT(System::cpuVendor().c_str()); PRINT(System::cpuArchitecture().c_str()); Array<std::string> features; if (System::has3DNow()) { features.append("3DNow"); } if (System::hasMMX()) { features.append("MMX"); } if (System::hasSSE()) { features.append("SSE"); } if (System::hasSSE2()) { features.append("SSE2"); } if (chipSpeed != "") { PRINT(chipSpeed + " " + stringJoin(features, '/')); } else { PRINT(stringJoin(features, '/')); } p.y += s * 2; // Operating System LABEL("OS"); rd->setTexture(0, osLogo); Draw::rect2D(Rect2D::xywh(p.x - s * 6, p.y - s * 2, s * 5, s * 5), rd); rd->setTexture(0, NULL); if (beginsWith(System::operatingSystem(), "Windows 5.0")) { PRINT("Windows 2000"); } else if (beginsWith(System::operatingSystem(), "Windows 5.1")) { PRINT("Windows XP"); } PRINT(System::operatingSystem().c_str()); p.y += s * 3; x0 = int(w - s * 10); titleFont->draw2D(rd, "Features", p - Vector2(w * 0.0075f, 0), s * 2, Color3::white() * 0.4f); p.y += reportFont->draw2D(rd, format("f%d", featureRating), Vector2(x0, p.y), s*2, Color3::red() * 0.5).y; drawBar(rd, featureRating, p); // Designed to put NV40 at 50 performanceRating = log(rd->stats().frameRate) * 15.0f; p.y += s * 4; performanceButton = Rect2D::xywh(p, titleFont->draw2D(rd, "Speed", p - Vector2(w * 0.0075f, 0), s * 2, Color3::white() * 0.4f)); { float spd = iRound(performanceRating * 10) / 10.0f; p.y += reportFont->draw2D(rd, format("%5.1f", spd), Vector2(x0 - s*2, p.y), s*2, Color3::red() * 0.5).y; } drawBar(rd, (int)min(performanceRating, 100.0f), p); p.y += s * 4; titleFont->draw2D(rd, "Quality", p - Vector2(w * 0.0075f, 0), s * 2, Color3::white() * 0.4f); p.y += reportFont->draw2D(rd, quality(bugCount), Vector2(x0, p.y), s*2, Color3::red() * 0.5f).y; drawBar(rd, iClamp(100 - bugCount * 10, 0, 100), p); # undef PRINT p.y = h - 50; # define PRINT(str) p.y += reportFont->draw2D(rd, str, p, 8, Color3::black()).y; PRINT("These ratings are based on the performance of G3D apps."); PRINT("They may not be representative of overall 3D performance."); PRINT("Speed is based on both processor and graphics card. Upgrading"); PRINT("your graphics driver may improve Quality and Features."); # undef PRINT # undef LABEL switch (popup) { case NONE: break; case PERFORMANCE: { // Draw the popup box Rect2D box = drawPopup("Performance Details"); p.x = box.x0() + 10; p.y = box.y0() + 30; Vector2 spacing(box.width() / 6.5, 0); std::string str; float factor = 3 * vertexPerformance.numTris / 1e6; # define PRINT(cap, val) \ reportFont->draw2D(rd, cap, p, s, Color3::black());\ reportFont->draw2D(rd, (vertexPerformance.val[0] > 0) ? \ format("%5.1f", vertexPerformance.val[0]) : \ std::string("X"), p + spacing * 3, s, Color3::red() * 0.5, Color4::clear(), GFont::XALIGN_RIGHT);\ reportFont->draw2D(rd, (vertexPerformance.val[0] > 0) ? \ format("%5.1f", factor * vertexPerformance.val[0]) : \ std::string("X"), p + spacing * 4, s, Color3::red() * 0.5, Color4::clear(), GFont::XALIGN_RIGHT);\ reportFont->draw2D(rd, (vertexPerformance.val[1] > 0) ? \ format("%5.1f", vertexPerformance.val[1]) : \ std::string("X"), p + spacing * 5, s, Color3::red() * 0.5, Color4::clear(), GFont::XALIGN_RIGHT);\ p.y += reportFont->draw2D(rd, (vertexPerformance.val[1] > 0) ? \ format("%5.1f", factor * vertexPerformance.val[1]) : \ std::string("X"), p + spacing * 6, s, Color3::red() * 0.5, Color4::clear(), GFont::XALIGN_RIGHT).y; reportFont->draw2D(rd, "Incoherent", p + spacing * 3.5, s, Color3::black(), Color4::clear(), GFont::XALIGN_RIGHT); p.y += reportFont->draw2D(rd, "Coherent", p + spacing * 5.5, s, Color3::black(), Color4::clear(), GFont::XALIGN_RIGHT).y; reportFont->draw2D(rd, "FPS*", p + spacing * 3, s, Color3::black(), Color4::clear(), GFont::XALIGN_RIGHT); reportFont->draw2D(rd, "MVerts/s", p + spacing * 4, s, Color3::black(), Color4::clear(), GFont::XALIGN_RIGHT); reportFont->draw2D(rd, "FPS*", p + spacing * 5, s, Color3::black(), Color4::clear(), GFont::XALIGN_RIGHT).y; p.y += reportFont->draw2D(rd, "MVerts/s", p + spacing * 6, s, Color3::black(), Color4::clear(), GFont::XALIGN_RIGHT).y; PRINT("glBegin/glEnd", beginEndFPS); PRINT("glDrawElements", drawElementsRAMFPS); PRINT(" + VBO", drawElementsVBOFPS); PRINT(" + uint16", drawElementsVBO16FPS); PRINT(" + gl interleave", drawElementsVBOIFPS); PRINT(" + manual interleave", drawElementsVBOIMFPS); PRINT(" (without shading)", drawElementsVBOPeakFPS); reportFont->draw2D(rd, "glDrawArrays", p, s, Color3::black()); reportFont->draw2D(rd, (vertexPerformance.drawArraysVBOPeakFPS > 0) ? \ format("%5.1f", vertexPerformance.drawArraysVBOPeakFPS) : \ std::string("X"), p + spacing * 5, s, Color3::red() * 0.5, Color4::clear(), GFont::XALIGN_RIGHT);\ p.y += reportFont->draw2D(rd, (vertexPerformance.drawArraysVBOPeakFPS > 0) ? \ format("%5.1f", factor * vertexPerformance.drawArraysVBOPeakFPS) : \ std::string("X"), p + spacing * 6, s, Color3::red() * 0.5, Color4::clear(), GFont::XALIGN_RIGHT).y; # undef PRINT p.y += s; p.y += reportFont->draw2D(rd, format("* FPS at %d k polys/frame.", iRound(vertexPerformance.numTris / 1000.0)), p + Vector2(20, 0), s, Color3::black()).y; } } rd->pop2D(); }
void Any::verifyName(const std::string& n) const { beforeRead(); verify(beginsWith(toUpper(name()), toUpper(n)), "Name must begin with " + n); }
// There is no "ParseOFF" because OFF parsing is trivial--it has no subparts or materials, // and is directly an indexed format. void ArticulatedModel::loadOFF(const Specification& specification) { Part* part = addPart(m_name); Geometry* geom = addGeometry("geom"); Mesh* mesh = addMesh("mesh", part, geom); mesh->material = UniversalMaterial::create(); TextInput::Settings s; s.cppBlockComments = false; s.cppLineComments = false; s.otherCommentCharacter = '#'; TextInput ti(specification.filename, s); /////////////////////////////////////////////////////////////// // Parse header std::string header = ti.readSymbol(); bool hasTexCoords = false; bool hasColors = false; bool hasNormals = false; bool hasHomogeneous = false; bool hasHighDimension = false; if (beginsWith(header, "ST")) { hasTexCoords = true; header = header.substr(2); } if (beginsWith(header, "C")) { hasColors = true; header = header.substr(1); } if (beginsWith(header, "N")) { hasNormals = true; header = header.substr(1); } if (beginsWith(header, "4")) { hasHomogeneous = true; header = header.substr(1); } if (beginsWith(header, "n")) { hasHighDimension = true; header = header.substr(1); } geom->cpuVertexArray.hasTexCoord0 = hasTexCoords; geom->cpuVertexArray.hasTangent = false; // Remaining header should be "OFF", but is not required according to the spec Token t = ti.peek(); if ((t.type() == Token::SYMBOL) && (t.string() == "BINARY")) { throw std::string("BINARY OFF files are not supported by this version of G3D::ArticulatedModel"); } int ndim = 3; if (hasHighDimension) { ndim = int(ti.readNumber()); } if (hasHomogeneous) { ++ndim; } if (ndim < 3) { throw std::string("OFF files must contain at least 3 dimensions"); } int nV = iFloor(ti.readNumber()); int nF = iFloor(ti.readNumber()); int nE = iFloor(ti.readNumber()); (void)nE; /////////////////////////////////////////////////// Array<int>& index = mesh->cpuIndexArray; geom->cpuVertexArray.vertex.resize(nV); // Read the per-vertex data for (int v = 0; v < nV; ++v) { CPUVertexArray::Vertex& vertex = geom->cpuVertexArray.vertex[v]; // Position for (int i = 0; i < 3; ++i) { vertex.position[i] = float(ti.readNumber()); } // Ignore higher dimensions for (int i = 3; i < ndim; ++i) { (void)ti.readNumber(); } if (hasNormals) { // Normal (assume always 3 components) for (int i = 0; i < 3; ++i) { vertex.normal[i] = float(ti.readNumber()); } } else { vertex.normal.x = fnan(); } if (hasColors) { // Color (assume always 3 components) for (int i = 0; i < 3; ++i) { ti.readNumber(); } } if (hasTexCoords) { // Texcoords (assume always 2 components) for (int i = 0; i < 2; ++i) { vertex.texCoord0[i] = float(ti.readNumber()); } } // Skip to the end of the line. If the file was corrupt we'll at least get the next vertex right ti.readUntilNewlineAsString(); } // Faces // Convert arbitrary triangle fans to triangles Array<int> poly; for (int i = 0; i < nF; ++i) { poly.fastClear(); int polySize = iFloor(ti.readNumber()); debugAssert(polySize > 2); if (polySize == 3) { // Triangle (common case) for (int j = 0; j < 3; ++j) { index.append(iFloor(ti.readNumber())); } } else { poly.resize(polySize); for (int j = 0; j < polySize; ++j) { poly[j] = iFloor(ti.readNumber()); debugAssertM(poly[j] < nV, "OFF file contained an index greater than the number of vertices."); } // Expand the poly into triangles MeshAlg::toIndexedTriList(poly, PrimitiveType::TRIANGLE_FAN, index); } // Trim to the end of the line, except on the last line of the // file (where it doesn't matter) if (i != nF - 1) { // Ignore per-face colors ti.readUntilNewlineAsString(); } } }
void beginsWith(const char *kw, AzIntArr *ia_fxs) const { AzStrPool sp_kw; sp_kw.put(kw); beginsWith(&sp_kw, ia_fxs); }
void TS3::telnetMessage(bufferevent *bev, void *parentPtr) { auto parent = static_cast<TS3*>(parentPtr); std::string s; char buf[1024]; int n; evbuffer *input = bufferevent_get_input(bev); while ((n = evbuffer_remove(input, buf, sizeof(buf))) > 0) s.append(buf, n); // trim CR LF if (s.size() > 2) s.erase(s.size() - 2); else LOG(ERROR) << "Received telnet line that is too short!"; // Pong messages clutter INFO log badly // LOG(INFO) << s; switch (parent->_sqState) { case TS3::State::NotConnected: // FIXME: very poor criteria for connection static const std::string welcome = "Welcome to the TeamSpeak 3 ServerQuery interface"; if (s.find(welcome) != s.npos) { LOG(INFO) << "Connected to ServerQuery interface"; parent->_sqState = TS3::State::ServerQueryConnected; evbuffer_add_printf(bufferevent_get_output(bev), "login %s %s\n", parent->GetRawConfigValue("Teamspeak.Login").c_str(), parent->GetRawConfigValue("Teamspeak.Password").c_str()); } break; case TS3::State::ServerQueryConnected: static const std::string okMsg = "error id=0 msg=ok"; if (beginsWith(s, okMsg)) { LOG(INFO) << "Authorized on TS3 server"; parent->_sqState = TS3::State::Authrozied; evbuffer_add_printf(bufferevent_get_output(bev), "use port=9987\n"); } break; case TS3::State::Authrozied: if (beginsWith(s, okMsg)) { LOG(INFO) << "Connected to Virtual Server"; parent->_sqState = TS3::State::VirtualServerConnected; evbuffer_add_printf(bufferevent_get_output(bev), "clientupdate client_nickname=%s\n", parent->_nickname.c_str()); } break; case TS3::State::VirtualServerConnected: if (beginsWith(s, okMsg)) { LOG(INFO) << "Nickname is set"; parent->_sqState = TS3::State::NickSet; evbuffer_add_printf(bufferevent_get_output(bev), "servernotifyregister event=server\n"); } break; case TS3::State::NickSet: if (beginsWith(s, okMsg)) { LOG(INFO) << "Subscribed to connects/disconnects"; parent->_sqState = TS3::State::Subscribed; evbuffer_add_printf(bufferevent_get_output(bev), "servernotifyregister event=textchannel id=%ld\n", parent->_channelID); } break; case TS3::State::Subscribed: if (beginsWith(s, "notifycliententerview")) { auto tokens = tokenize(s, ' '); try { parent->TS3Connected(tokens.at(4).substr(5), tokens.at(6).substr(16)); } catch (std::exception &e) { LOG(ERROR) << "Can't parse message: \"" << s << "\" | Exception: " << e.what(); } break; } if (beginsWith(s, "notifyclientleftview")) { auto tokens = tokenize(s, ' '); try { parent->TS3Disconnected(tokens.at(5).substr(5, tokens.at(5).size() - 5)); } catch (std::exception &e) { LOG(ERROR) << "Can't parse message: \"" << s << "\" | Exception: " << e.what(); } break; } if (beginsWith(s, "notifytextmessage")) { auto tokens = tokenize(s, ' '); try { auto nick = ReplaceTS3Spaces(tokens.at(4).substr(12)); auto message = ReplaceTS3Spaces(tokens.at(2).substr(4)); parent->TS3Message(nick, message); } catch (std::exception &e) { LOG(ERROR) << "Can't parse message: \"" << s << "\" | Exceptions: " << e.what(); } break; } break; } }
void Shader::ShaderProgram::addActiveUniformsFromProgram() { // Length of the longest variable name GLint maxLength; // Number of uniform variables GLint uniformCount; // Get the number of uniforms, and the length of the longest name. glGetProgramiv(glShaderProgramObject(), GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength); glGetProgramiv(glShaderProgramObject(), GL_ACTIVE_UNIFORMS, &uniformCount); GLchar* name = (GLchar *) malloc(maxLength * sizeof(GLchar)); // Get the sizes, types and names int lastTextureUnit = -1; int lastImageUnit = -1; // Loop over glGetActiveUniform and store the results away. for (int i = 0; i < uniformCount; ++i) { const GLuint uniformIndex = i; GLuint programObject = glShaderProgramObject(); GLint elementNum; GLenum type; glGetActiveUniform(programObject, uniformIndex, maxLength, NULL, &elementNum, &type, name); UniformDeclaration& d = uniformDeclarationTable.getCreate(name); d.name = name; d.location = glGetUniformLocation(glShaderProgramObject(), name); d.type = type; d.elementNum = elementNum; bool isGLBuiltIn = (d.location == -1) || ((strlen(name) > 3) && beginsWith(String(name), "gl_")); d.dummy = isGLBuiltIn; d.index = -1; if (! isGLBuiltIn) { if (isSamplerType(d.type)) { ++lastTextureUnit; d.glUnit = lastTextureUnit; } else if (isImageType(d.type)) { ++lastImageUnit; d.glUnit = lastImageUnit; } else if (d.elementNum == 1) { // Not array d.glUnit = -1; } else { // Is an array, remove from uniform declaration table, and add it's elements GLint type = d.type; int arraySize = (int)d.elementNum; int glUnit = -1; uniformDeclarationTable.remove(name); // Get rid of [0] if it exists (depends on driver) String arrayName = name; if (arrayName[arrayName.length()-1] == ']') { size_t bracketLoc = arrayName.rfind('['); // TODO: error handle if "[" doesn't exist arrayName = arrayName.substr(0, bracketLoc); } for (int i = 0; i < arraySize; ++i) { const String appendedName = format("%s[%d]", arrayName.c_str(), i); UniformDeclaration& elementDeclaration = uniformDeclarationTable.getCreate(appendedName); GLint location = glGetUniformLocation(glShaderProgramObject(), appendedName.c_str()); debugAssertGLOk(); bool dummy = (location == -1); elementDeclaration.setAllFields(appendedName, i, type, location, dummy, glUnit); } } } } free(name); }
void threadLoop(gpointer data) { GAsyncQueue *privCommandQueue = g_async_queue_ref(((OBD2Source*)data)->commandQueue); GAsyncQueue *privResponseQueue = g_async_queue_ref(((OBD2Source*)data)->responseQueue); GAsyncQueue *privSingleShotQueue = g_async_queue_ref(((OBD2Source*)data)->singleShotQueue); GAsyncQueue *privSubscriptionAddQueue = g_async_queue_ref(((OBD2Source*)data)->subscriptionAddQueue); GAsyncQueue *privSubscriptionRemoveQueue = g_async_queue_ref(((OBD2Source*)data)->subscriptionRemoveQueue); GAsyncQueue *privStatusQueue = g_async_queue_ref(((OBD2Source*)data)->statusQueue); obdLib *obd = new obdLib(); OBD2Source *source = (OBD2Source*)data; obd->setCommsCallback([](const char* mssg, void* data) { DebugOut(6)<<mssg<<endl; },NULL); obd->setDebugCallback([](const char* mssg, void* data, obdLib::DebugLevel debugLevel) { DebugOut(debugLevel)<<mssg<<endl; },NULL); std::list<ObdPid*> reqList; std::list<ObdPid*> repeatReqList; ObdPid::ByteArray replyVector; std::string reply; std::string port; std::string baud; bool connected=false; int emptycount = 0; int timeoutCount = 0; while (source->m_threadLive) { //gpointer query = g_async_queue_pop(privCommandQueue); gpointer query = g_async_queue_try_pop(privSingleShotQueue); if (query != nullptr) { //printf("Got request!\n"); ObdPid *req = (ObdPid*)query; DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Got single shot request: " << req->pid.substr(0,req->pid.length()-1) << ":" << req->property <<endl; repeatReqList.push_back(req); } query = g_async_queue_try_pop(privSubscriptionAddQueue); if (query != nullptr) { ObdPid *req = (ObdPid*)query; //DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Got subscription request for "<<req->req<<endl; reqList.push_back(req); } query = g_async_queue_try_pop(privCommandQueue); if (query != nullptr) { //ObdPid *req = (ObdPid*)query; CommandRequest *req = (CommandRequest*)query; //commandMap[req->req] = req->arg; //printf("Command: %s\n",req->req.c_str()); DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Command:" << req->req << endl; if (req->req == "connect" ) { if (source->m_isBluetooth) { BluetoothDevice bt; std::string tempPort = bt.getDeviceForAddress(source->m_btDeviceAddress, source->m_btAdapterAddress); if(tempPort != "") { DebugOut(3)<<"Using bluetooth device \""<<source->m_btDeviceAddress<<"\" bound to: "<<tempPort<<endl; port = tempPort; } } else { port = req->arglist[0]; baud = req->arglist[1]; } connected = connect(obd,port,baud); if(connected) { StatusMessage *statusreq = new StatusMessage(); statusreq->statusStr = "connected"; g_async_queue_push(privStatusQueue,statusreq); } else { StatusMessage *statusreq = new StatusMessage(); statusreq->statusStr = "disconnected"; g_async_queue_push(privStatusQueue,statusreq); } } else if (req->req == "connectifnot") { if (!connected) { if (source->m_isBluetooth) { BluetoothDevice bt; std::string tempPort = bt.getDeviceForAddress(source->m_btDeviceAddress, source->m_btAdapterAddress); if(tempPort != "") { DebugOut(3)<<"Using bluetooth device \""<<source->m_btDeviceAddress<<"\" bound to: "<<tempPort<<endl; port = tempPort; } else { DebugOut(DebugOut::Error)<<"Error creating bluetooth device"<<endl; continue; } } connected = connect(obd,port,baud); if(connected) { StatusMessage *statusreq = new StatusMessage(); statusreq->statusStr = "connected"; g_async_queue_push(privStatusQueue,statusreq); } else { StatusMessage *statusreq = new StatusMessage(); statusreq->statusStr = "disconnected"; g_async_queue_push(privStatusQueue,statusreq); } } } else if (req->req == "setportandbaud") { port = req->arglist[0]; baud = req->arglist[1]; } else if (req->req == "disconnect") { DebugOut() << __SMALLFILE__ << ":" << __LINE__ << "Using queued disconnect" << (ulong)req << endl; obd->closePort(); BluetoothDevice bt; bt.disconnect(source->m_btDeviceAddress, source->m_btAdapterAddress); connected = false; StatusMessage *statusreq = new StatusMessage(); statusreq->statusStr = "disconnected"; g_async_queue_push(privStatusQueue,statusreq); } delete req; } query = g_async_queue_try_pop(privSubscriptionRemoveQueue); if (query != nullptr) { DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Got unsubscription request"<<endl; ObdPid *req = (ObdPid*)query; for (std::list<ObdPid*>::iterator i=reqList.begin();i!= reqList.end();i++) { if ((*i)->property == req->property) { reqList.erase(i); delete (*i); i--; if (reqList.size() == 0) { break; } } } //reqList.push_back(req->req); delete req; } if (reqList.size() > 0 && !connected) { /*CommandRequest *req = new CommandRequest(); req->req = "connect"; req->arglist.push_back(port); req->arglist.push_back(baud); g_async_queue_push(privCommandQueue,req); continue;*/ } else if (reqList.size() == 0 && connected) { emptycount++; if (emptycount < 1000) { usleep(10000); continue; } emptycount = 0; CommandRequest *req = new CommandRequest(); req->req = "disconnect"; g_async_queue_push(privCommandQueue,req); continue; } if (!connected) { usleep(10000); continue; } for (std::list<ObdPid*>::iterator i=reqList.begin();i!= reqList.end();i++) { repeatReqList.push_back(*i); } int badloop = 0; for (std::list<ObdPid*>::iterator i=repeatReqList.begin();i!= repeatReqList.end();i++) { DebugOut(10) << __SMALLFILE__ << ":" << __LINE__ << "Requesting pid: " << (*i)->pid.substr(0,(*i)->pid.length()-1) << (*i)->property << endl; if (source->m_blacklistPidCountMap.find((*i)->pid) != source->m_blacklistPidCountMap.end()) { //Don't erase the pid, just skip over it. int count = (*source->m_blacklistPidCountMap.find((*i)->pid)).second; if (count > 10) { continue; } } badloop++; bool result = false; if(beginsWith((*i)->pid,"AT") || beginsWith((*i)->pid, "ST")) { result = obd->sendObdRequestString((*i)->pid.c_str(),(*i)->pid.length(),&replyVector); } else result = obd->sendObdRequestString((*i)->pid.c_str(),(*i)->pid.length(),&replyVector,5,3); if (!result) { //This only happens during a error with the com port. Close it and re-open it later. DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Unable to send request:" << (*i)->pid.substr(0,(*i)->pid.length()-1) << endl; if (obd->lastError() == obdLib::NODATA) { DebugOut() << __SMALLFILE__ << ":" << __LINE__ << "OBDLib::NODATA for pid" << (*i)->pid.substr(0,(*i)->pid.length()-1) << " expected property: " << (*i)->property << endl; if (source->m_blacklistPidCountMap.find((*i)->pid) != source->m_blacklistPidCountMap.end()) { //pid value i not yet in the list. int count = (*source->m_blacklistPidCountMap.find((*i)->pid)).second; if (count > 10) { } source->m_blacklistPidCountMap.erase(source->m_blacklistPidCountMap.find((*i)->pid)); source->m_blacklistPidCountMap.insert(pair<std::string,int>((*i)->pid,count)); } else { source->m_blacklistPidCountMap.insert(pair<std::string,int>((*i)->pid,1)); } StatusMessage *statusreq = new StatusMessage(); statusreq->statusStr = "error:nodata"; statusreq->property = (*i)->property; g_async_queue_push(privStatusQueue,statusreq); continue; } else if (obd->lastError() == obdLib::TIMEOUT) { timeoutCount++; if (timeoutCount < 2) { DebugOut() << __SMALLFILE__ << ":" << __LINE__ << "OBDLib::TIMEOUT for pid" << (*i)->pid << endl; StatusMessage *statusreq = new StatusMessage(); statusreq->statusStr = "error:timeout"; g_async_queue_push(privStatusQueue,statusreq); continue; } } else { DebugOut() << __SMALLFILE__ << ":" << __LINE__ << "OBD Other error:" << obd->lastError() << endl; } CommandRequest *req = new CommandRequest(); DebugOut() << __SMALLFILE__ << ":" << __LINE__ << "Queuing up a disconnect" << (ulong)req << endl; req->req = "disconnect"; g_async_queue_push(privCommandQueue,req); i = repeatReqList.end(); i--; continue; } if (source->m_blacklistPidCountMap.find((*i)->pid) != source->m_blacklistPidCountMap.end()) { //If we get the pid response, then we want to clear out the blacklist list. source->m_blacklistPidCountMap.erase(source->m_blacklistPidCountMap.find((*i)->pid)); } timeoutCount = 0; //ObdPid *pid = ObdPid::pidFromReply(replyVector); ObdPid *pid = obd2AmbInstance->createPidFromReply(replyVector); if (!pid) { //Invalid reply DebugOut() << "Invalid reply"<<endl; continue; } else { DebugOut(11) << __SMALLFILE__ <<":"<< __LINE__ << "Reply recieved and queued for:" << (*i)->pid.substr(0,(*i)->pid.length()-1) << endl; std::string repstr; for (int i=0;i<replyVector.size();i++) { if (replyVector[i] != 13) { repstr += (char)replyVector[i]; } //DebugOut(11) << replyVector[i]; } DebugOut(11) << "Reply:" << repstr << endl; } g_async_queue_push(privResponseQueue,pid); } if (badloop == 0) { //We had zero non-blacklisted events. Pause for a moment here to keep from burning CPU. //usleep(10000); } repeatReqList.clear(); } if (connected) { obd->closePort(); } }
bool str::beginsWithWholeWord(const char* pString, char seperator) const { // After comparison, the char must be a space or null terminated const char c = mpStr[strlen(pString)]; return beginsWith(pString) && (seperator == c || '\0' == c); }
inline bool beginsAsFlag(const std::string& mStr) const noexcept { return beginsWith(mStr, Impl::flagPrefixShort) || beginsWith(mStr, Impl::flagPrefixLong); }
Error parseLatexLog(const FilePath& logFilePath, LogEntries* pLogEntries) { static boost::regex regexOverUnderfullLines(" at lines (\\d+)--(\\d+)\\s*(?:\\[])?$"); static boost::regex regexWarning("^(?:.*?) Warning: (.+)"); static boost::regex regexWarningEnd(" input line (\\d+)\\.$"); static boost::regex regexLnn("^l\\.(\\d+)\\s"); static boost::regex regexCStyleError("^(.+):(\\d+):\\s(.+)$"); std::vector<std::string> lines; Error error = readStringVectorFromFile(logFilePath, &lines, false); if (error) return error; std::vector<size_t> linesUnwrapped; unwrapLines(&lines, &linesUnwrapped); FilePath rootDir = logFilePath.parent(); FileStack fileStack(rootDir); for (std::vector<std::string>::const_iterator it = lines.begin(); it != lines.end(); it++) { const std::string& line = *it; int logLineNum = (it - lines.begin()) + 1; // We slurp overfull/underfull messages with no further processing // (i.e. not manipulating the file stack) if (beginsWith(line, "Overfull ", "Underfull ")) { std::string msg = line; int lineNum = -1; // Parse lines, if present boost::smatch overUnderfullLinesMatch; if (boost::regex_search(line, overUnderfullLinesMatch, regexOverUnderfullLines)) { lineNum = safe_convert::stringTo<int>(overUnderfullLinesMatch[1], -1); } // Single line case bool singleLine = boost::algorithm::ends_with(line, "[]"); if (singleLine) { msg.erase(line.size()-2, 2); boost::algorithm::trim_right(msg); } pLogEntries->push_back(LogEntry(logFilePath, calculateWrappedLine(linesUnwrapped, logLineNum), LogEntry::Box, fileStack.currentFile(), lineNum, msg)); if (singleLine) continue; for (; it != lines.end(); it++) { // For multi-line case, we're looking for " []" on a line by itself if (*it == " []") break; } // The iterator would be incremented by the outer for loop, must not // let it go past the end! (If we did get to the end, it would // mean the log file was malformed, but we still can't crash in this // situation.) if (it == lines.end()) break; else continue; } fileStack.processLine(line); // Now see if it's an error or warning if (beginsWith(line, "! ")) { std::string errorMsg = line.substr(2); int lineNum = -1; boost::smatch match; for (it++; it != lines.end(); it++) { if (boost::regex_search(*it, match, regexLnn)) { lineNum = safe_convert::stringTo<int>(match[1], -1); break; } } pLogEntries->push_back(LogEntry(logFilePath, calculateWrappedLine(linesUnwrapped, logLineNum), LogEntry::Error, fileStack.currentFile(), lineNum, errorMsg)); // The iterator would be incremented by the outer for loop, must not // let it go past the end! (If we did get to the end, it would // mean the log file was malformed, but we still can't crash in this // situation.) if (it == lines.end()) break; else continue; } boost::smatch warningMatch; if (boost::regex_search(line, warningMatch, regexWarning)) { std::string warningMsg = warningMatch[1]; int lineNum = -1; while (true) { if (boost::algorithm::ends_with(warningMsg, ".")) { boost::smatch warningEndMatch; if (boost::regex_search(*it, warningEndMatch, regexWarningEnd)) { lineNum = safe_convert::stringTo<int>(warningEndMatch[1], -1); } break; } if (++it == lines.end()) break; warningMsg.append(*it); } pLogEntries->push_back(LogEntry(logFilePath, calculateWrappedLine(linesUnwrapped, logLineNum), LogEntry::Warning, fileStack.currentFile(), lineNum, warningMsg)); // The iterator would be incremented by the outer for loop, must not // let it go past the end! (If we did get to the end, it would // mean the log file was malformed, but we still can't crash in this // situation.) if (it == lines.end()) break; else continue; } boost::smatch cStyleErrorMatch; if (boost::regex_search(line, cStyleErrorMatch, regexCStyleError)) { FilePath cstyleFile = resolveFilename(rootDir, cStyleErrorMatch[1]); if (cstyleFile.exists()) { int lineNum = safe_convert::stringTo<int>(cStyleErrorMatch[2], -1); pLogEntries->push_back(LogEntry(logFilePath, calculateWrappedLine(linesUnwrapped, logLineNum), LogEntry::Error, cstyleFile, lineNum, cStyleErrorMatch[3])); } } } return Success(); }
void App::onInit() { defaultController->setActive(false); showDebugText = false; showRenderingStats = false; popup = NONE; defaultCamera.setPosition(Vector3(0, 2, 10)); defaultCamera.lookAt(Vector3(0, 2, 0)); // Init the fun stuff (MD2s) knight.load("pknight"); knight.cframe.translation = Vector3(-5, 0, 0); ogre.load("ogro"); ogre.cframe.translation = Vector3(-1.5, 0, 0); knight.cframe.lookAt(ogre.cframe.translation + Vector3(0,0,1)); ogre.cframe.lookAt(knight.cframe.translation + Vector3(0,0,1)); //window()->swapGLBuffers();while(true); // Choose a card logo { std::string filename = ""; if (beginsWith(GLCaps::vendor(), "NVIDIA")) { filename = "nvidia.jpg"; } else if (beginsWith(GLCaps::vendor(), "ATI")) { filename = "ati.jpg"; } if (filename != "") { Texture::Settings textureSettings; textureSettings.wrapMode = WrapMode::CLAMP; cardLogo = Texture::fromFile(filename, ImageFormat::AUTO(), Texture::DIM_2D, textureSettings); } } // Choose chip logo { std::string filename = ""; if (endsWith(toLower(System::cpuVendor()), "intel")) { filename = "intel.jpg"; } else if (endsWith(toLower(System::cpuVendor()), "amd")) { filename = "amd.jpg"; } if (filename != "") { Texture::Settings textureSettings; textureSettings.wrapMode = WrapMode::CLAMP; chipLogo = Texture::fromFile(filename, ImageFormat::AUTO(), Texture::DIM_2D, textureSettings); } # ifdef G3D_WIN32 { double speed = CPU_speed_in_MHz() * 1e6; if (speed > 1e9) { chipSpeed = format("%.1f GHz", speed / 1e9); } else if (speed > 10e6) { chipSpeed = format("%.1f MHz", speed / 1e6); } // Probably a bad result if speed is less than 1 MHz } # endif } // Choose os logo { std::string filename = ""; std::string os = System::operatingSystem (); if (beginsWith(os, "Windows 5.0")) { filename = "win2k.jpg"; } else if (beginsWith(os, "Windows 5.1")) { filename = "winxp.jpg"; } if (filename != "") { Texture::Settings textureSettings; textureSettings.wrapMode = WrapMode::CLAMP; osLogo = Texture::fromFile(filename, ImageFormat::AUTO(), Texture::DIM_2D, textureSettings); } } titleFont = GFont::fromFile(dataDir + "carbon.fnt"); shaderVersions(combineShader, asmShader, glslShader); computeFeatureRating(); logPrintf("Shaders:\n"); logPrintf(" Combiners: %s\n", combineShader.c_str()); logPrintf(" Assembly: %s\n", asmShader.c_str()); logPrintf(" GLSL: %s\n", glslShader.c_str()); logPrintf("\n\n"); # ifndef FAST { measureVertexPerformance( window(), vertexPerformance.numTris, vertexPerformance.beginEndFPS, vertexPerformance.drawElementsRAMFPS, vertexPerformance.drawElementsVBOFPS, vertexPerformance.drawElementsVBO16FPS, vertexPerformance.drawElementsVBOIFPS, vertexPerformance.drawElementsVBOIMFPS, vertexPerformance.drawElementsVBOPeakFPS, vertexPerformance.drawArraysVBOPeakFPS); logPrintf("\nDetailed Performance Tests\n\n"); logPrintf(" * Vertex Rate\n"); logPrintf(" %d tris, 2 lights, 1 texture, and 4 attributes\n\n", vertexPerformance.numTris); logPrintf(" Low Coherence [ High Coherence ]\n"); logPrintf(" Method FPS [ FPS |Mverts/sec]\n"); logPrintf(" ------------------------------------------------+---------\n"); logPrintf(" glBegin/glEndFPS: %5.1f [ %5.1f | %5.1f ]\n", vertexPerformance.beginEndFPS[0], vertexPerformance.beginEndFPS[1], vertexPerformance.beginEndFPS[1] * 3 * vertexPerformance.numTris / 1e6); logPrintf(" glDrawElements: %5.1f [ %5.1f | %5.1f ]\n", vertexPerformance.drawElementsRAMFPS[0], vertexPerformance.drawElementsRAMFPS[1], vertexPerformance.drawElementsRAMFPS[1] * 3 * vertexPerformance.numTris / 1e6); logPrintf(" + VBO %5.1f [ %5.1f | %5.1f ]\n", vertexPerformance.drawElementsVBOFPS[0], vertexPerformance.drawElementsVBOFPS[1], vertexPerformance.drawElementsVBOFPS[1] * 3 * vertexPerformance.numTris / 1e6); logPrintf(" + uint16 index %5.1f [ %5.1f | %5.1f ]\n", vertexPerformance.drawElementsVBO16FPS[0], vertexPerformance.drawElementsVBO16FPS[1], vertexPerformance.drawElementsVBO16FPS[1] * 3 * vertexPerformance.numTris / 1e6); logPrintf(" + gl interleaved %5.1f [ %5.1f | %5.1f ]\n", vertexPerformance.drawElementsVBOIFPS[0], vertexPerformance.drawElementsVBOIFPS[1], vertexPerformance.drawElementsVBOIFPS[1] * 3 * vertexPerformance.numTris / 1e6); logPrintf(" + manual interleaved %5.1f [ %5.1f | %5.1f ]\n", vertexPerformance.drawElementsVBOIMFPS[0], vertexPerformance.drawElementsVBOIMFPS[1], vertexPerformance.drawElementsVBOIMFPS[1] * 3 * vertexPerformance.numTris / 1e6); logPrintf(" without shading %5.1f [ %5.1f | %5.1f ]\n", vertexPerformance.drawElementsVBOPeakFPS[0], vertexPerformance.drawElementsVBOPeakFPS[1], vertexPerformance.drawElementsVBOPeakFPS[1] * 3 * vertexPerformance.numTris / 1e6); logPrintf(" glDrawArrays Peak: [ %5.1f | %5.1f ]\n", vertexPerformance.drawArraysVBOPeakFPS, vertexPerformance.drawArraysVBOPeakFPS * 3 * vertexPerformance.numTris / 1e6); logPrintf("\n\n"); } # endif countBugs(); sky = NULL; }