Option<Vec2> sb::Intersection::get(const Ray& a, const Polygon& b) { Option<Vec2> pt = nullptr; Option<bool> inside = nullptr; float t = std::numeric_limits<float>::max(); auto eCount = b.edgeCount(); for (ptrdiff_t i = 0; i < eCount; i++) { const auto ed = b.edge(i); auto r = Intersection::get(a, ed); if (!r) continue; if (aeq(r.value(), ed.pointA())) { if (!inside.hasValue()) inside = test(b, a.m_point); if (!inside.value() && !(-a.direction()).isBetween(b.normal(i), b.normal(i - 1))) continue; } else if (aeq(r.value(), ed.pointB())) { if (!inside.hasValue()) inside = test(b, a.m_point); if (!inside.value() && !(-a.direction()).isBetween(b.normal(i), b.normal(i + 1))) continue; } auto u = a.computeT(r.value()); if (u < t) { t = u; pt = r; } } return pt; }
Option<Shader*> Shader::combine(const Option<uint>& vs, const Option<uint>& fs, const Option<uint>& gs) { if(!vs.hasValue() || !fs.hasValue()) { _lastLinkError.clear(); if(!vs.hasValue()) _lastLinkError += "Vertex shader missing.\n"; if(!fs.hasValue()) _lastLinkError += "Fragment shader missing.\n"; return Option<Shader*>(); } uint id = glCreateProgram(); glAttachShader(id, vs.value()); glAttachShader(id, fs.value()); if(gs.hasValue() && fs.value() != 0) glAttachShader(id, gs.value()); glBindAttribLocation(id, 0, "vertex"); glBindAttribLocation(id, 1, "normal"); glBindAttribLocation(id, 2, "texCoord"); glBindAttribLocation(id, 3, "tangent"); glBindAttribLocation(id, 4, "drawId"); glLinkProgram(id); int linkStatus = GL_TRUE; glGetProgramiv(id, GL_LINK_STATUS, &linkStatus); if(linkStatus != GL_TRUE) { int logSize; glGetProgramiv(id, GL_INFO_LOG_LENGTH, &logSize); char* log = new char[logSize]; glGetProgramInfoLog(id, logSize, &logSize, log); _lastLinkError = std::string(log); delete[] log; glDeleteProgram(id); return Option<Shader*>(); } Shader* prog = new Shader; prog->_id = id; prog->loadEngineUniform(); return Option<Shader*>(prog); }
int EnumerationManager::action(Option &option) { if (option.hasValue()) print(cout, String::toLower(option.toString())); else for (enums_t::iterator it = enums.begin(); it != enums.end(); it++) cout << it->first << '\n'; cout << flush; exit(0); // TODO Option calls the action so we have to exit(). FIXME! return -1; }
int CommandLine::usageAction(Option &option) { if (option.hasValue()) { string name = option.toString(); SmartPointer<Option> opt; if (has(string("--") + name)) opt = get(string("--") + name); else if (keywords && keywords->has(name)) opt = keywords->get(name); else THROWS("Unrecognized command line option or keyword '" << name << "'"); opt->printHelp(cout) << endl; } else usage(cout, name); exit(0); // TODO cb::Option calls this action so we have to exit(0). FIXME! return -1; }
Option<Shader*> Shader::linkComputeShader(const Option<uint>& cs) { if(!cs.hasValue()) { _lastLinkError = "Compute Shader missing.\n"; return Option<Shader*>(); } uint id = glCreateProgram(); glAttachShader(id, cs.value()); glLinkProgram(id); int linkStatus = GL_TRUE; glGetProgramiv(id, GL_LINK_STATUS, &linkStatus); if(linkStatus != GL_TRUE) { int logSize; glGetProgramiv(id, GL_INFO_LOG_LENGTH, &logSize); char* log = new char[logSize]; glGetProgramInfoLog(id, logSize, &logSize, log); _lastLinkError = std::string(log); delete[] log; glDeleteProgram(id); return Option<Shader*>(); } Shader* prog = new Shader; prog->_id = id; prog->bind(); prog->loadEngineUniform(); prog->setUniform(vec4(0,0,0,0), prog->_engineUniform[EngineUniform::CLIP_PLAN_0]); prog->setUniform(vec4(0,0,0,0), prog->_engineUniform[EngineUniform::CLIP_PLAN_1]); prog->setUniform(vec4(0,0,0,0), prog->_engineUniform[EngineUniform::CLIP_PLAN_2]); prog->setUniform(vec4(0,0,0,0), prog->_engineUniform[EngineUniform::CLIP_PLAN_3]); return prog; }