本文整理汇总了C++中ProgramPtr类的典型用法代码示例。如果您正苦于以下问题:C++ ProgramPtr类的具体用法?C++ ProgramPtr怎么用?C++ ProgramPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProgramPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: drawSphereBackground
void EdvsRiftApp::drawSphereBackground(int camera_id)
{
static ProgramPtr program = oria::loadProgram("./resources/sphere_background.vs", "./resources/sphere_background.fs");
static ShapeWrapperPtr geometry = ShapeWrapperPtr(new shapes::ShapeWrapper({ "Position" }, shapes::ObjMesh(mesh_input.stream), *program));
// Reset before application exit
Platform::addShutdownHook([]
{
program.reset();
geometry.reset();
});
MatrixStack & mv = Stacks::modelview();
mv.withPush([&]
{
// Binds the program
program->Use();
// Matrices as uniforms
Mat4Uniform(*program, "ModelView").Set(Stacks::modelview().top());
Mat4Uniform(*program, "Projection").Set(Stacks::projection().top());
// Draw this
geometry->Use();
geometry->Draw();
});
// Unbind
oglplus::NoProgram().Bind();
oglplus::NoVertexArray().Bind();
}
示例2: zOffset
void GlUtils::draw3dGrid() {
using namespace gl;
GL_CHECK_ERROR;
static GeometryPtr g;
if (!g) {
Mesh m;
for (int i = 0; i < 5; ++i) {
float offset = ((float) i * 0.2f) + 0.2f;
glm::vec3 zOffset(0, 0, offset);
glm::vec3 xOffset(offset, 0, 0);
m.addVertex(-X_AXIS + zOffset);
m.addVertex(X_AXIS + zOffset);
m.addVertex(-X_AXIS - zOffset);
m.addVertex(X_AXIS - zOffset);
m.addVertex(-Z_AXIS + xOffset);
m.addVertex(Z_AXIS + xOffset);
m.addVertex(-Z_AXIS - xOffset);
m.addVertex(Z_AXIS - xOffset);
}
m.addVertex(X_AXIS);
m.addVertex(-X_AXIS);
m.addVertex(Z_AXIS);
m.addVertex(-Z_AXIS);
g = m.getGeometry(GL_LINES);
}
ProgramPtr program = getProgram(Resource::SHADERS_SIMPLE_VS, Resource::SHADERS_COLORED_FS);
GL_CHECK_ERROR;
program->use();
GL_CHECK_ERROR;
program->setUniform("Color", glm::vec4(Colors::gray,1));
GL_CHECK_ERROR;
renderGeometry(g, program);
GL_CHECK_ERROR;
}
示例3: program
Shader::~Shader()
{
if (m_shader) {
ProgramPtr prog = program();
if (prog) prog->removeShader(shared_from_this());
glDeleteShader(m_shader);
}
}
示例4: getMesh
void GlUtils::renderBunny() {
static GeometryPtr bunnyGeometry =
getMesh(Resource::MESHES_BUNNY2_CTM).getGeometry();
ProgramPtr program = GlUtils::getProgram(
Resource::SHADERS_LITCOLORED_VS,
Resource::SHADERS_LITCOLORED_FS);
program->use();
program->setUniform("Color", glm::vec4(1));
renderGeometry(bunnyGeometry, program);
}
示例5: loadSrc
bool Shader::loadSrc(const QString& data)
{
if (m_src != data) {
m_src = data;
m_needCompile = true;
// Tell the program object, that it needs to recompile stuff
ProgramPtr p = m_prog.lock();
if (p) p->setIsCompiled(false);
return true;
}
return false;
}
示例6: getProgram
void GlUtils::draw3dVector(glm::vec3 vec, const glm::vec3 & col) {
Mesh m;
m.color = Colors::gray;
m.addVertex(glm::vec3());
m.addVertex(glm::vec3(vec.x, 0, vec.z));
m.addVertex(glm::vec3(vec.x, 0, vec.z));
m.addVertex(vec);
m.fillColors(true);
m.color = col;
m.addVertex(vec);
m.addVertex(glm::vec3());
m.fillColors();
static GeometryPtr g = m.getGeometry(GL_LINES);
g->updateVertices(m.buildVertices());
ProgramPtr program = getProgram(
Resource::SHADERS_COLORED_VS,
Resource::SHADERS_COLORED_FS);
program->use();
renderGeometry(g, program);
gl::Program::clear();
// lineWidth(1.0f);
// float len = glm::length(vec);
// if (len > 1.0f) {
// vec /= len;
// }
// gl::Program::clear();
//
// glLineWidth(2.0f + len);
// glBegin(GL_LINES);
// gl::color(col);
// gl::vertex();
// gl::vertex();
// glEnd();
//
// glLineWidth(1.0f);
// glBegin(GL_LINE_STRIP);
// gl::color(Colors::gray);
// gl::vertex(glm::vec3());
// gl::vertex(glm::vec3(vec.x, 0, vec.z));
// gl::vertex(vec);
// glEnd();
}
示例7: remEntryPoints
ProgramPtr Program::remEntryPoints(NodeManager& manager, const ProgramPtr& program, const ExpressionList& entryPoints) {
ExpressionList list;
for_each(program->getEntryPoints(), [&list, &entryPoints](const ExpressionPtr& cur) {
if(!contains(entryPoints, cur, equal_target<ExpressionPtr>())) { list.push_back(cur); }
});
return manager.get(Program(list));
}
示例8: useProgram
void State::useProgram(ProgramPtr prog)
{
if (prog)
glRun(glUseProgram(prog->id()));
else
glRun(glUseProgram(0));
m_data.back().m_prog = prog;
}
示例9: clone
ShaderPtr Shader::clone(ProgramPtr prog) const
{
ShaderPtr s(new Shader(prog, m_type));
s->setFilename(rawFilename());
s->m_src = m_src;
s->m_needCompile = true;
if (prog) prog->setIsCompiled(false);
return s;
}
示例10: dumpTo
bool dumpTo(const ProgramPtr& program, const std::string& dir) {
// first of all, we want to dump the callgraph
auto callgraph = analysis::callgraph::getCallGraph(program);
if (!dumpTo(dir + "/callgraph.dot", toString(callgraph))) return false;
// finally, generate a file for each function
for (const auto& fun : program->getFunctions()) {
if (!dumpTo(dir + "/" + analysis::callgraph::getFunctionName(fun) + ".dot", toString(*fun))) return false;
}
return true;
}
示例11: tan
void GlUtils::drawAngleTicks() {
using namespace gl;
static GeometryPtr g;
if (!g) {
float offsets[] = { //
(float) tan( PI / 6.0f), // 30 degrees
(float) tan( PI / 4.0f), // 45 degrees
(float) tan( PI / 3.0f) // 60 degrees
};
Mesh m;
// 43.9 degrees puts tick on the inner edge of the screen
// 42.6 degrees is the effective fov for wide screen
// 43.9 degrees puts tick on the inner edge of the screen
m.addVertex(glm::vec3(-2, 0, 0));
m.addVertex(glm::vec3(2, 0, 0));
m.addVertex(glm::vec3(0, -2, 0));
m.addVertex(glm::vec3(0, 2, 0));
// By keeping the camera locked at 1 unit away from the origin, all our
// distances can be computed as tan(angle)
for (float offset : offsets) {
m.addVertex(glm::vec3(offset, -0.05, 0));
m.addVertex(glm::vec3(offset, 0.05, 0));
m.addVertex(glm::vec3(-offset, -0.05, 0));
m.addVertex(glm::vec3(-offset, 0.05, 0));
}
for (float offset : offsets) {
m.addVertex(glm::vec3(-0.05, offset, 0));
m.addVertex(glm::vec3(0.05, offset, 0));
m.addVertex(glm::vec3(-0.05, -offset, 0));
m.addVertex(glm::vec3(0.05, -offset, 0));
}
g = m.getGeometry(GL_LINES);
}
// Fix the modelview at exactly 1 unit away from the origin, no rotation
gl::Stacks::modelview().push(glm::mat4(1)).translate(glm::vec3(0, 0, -1));
ProgramPtr program = getProgram(Resource::SHADERS_SIMPLE_VS, Resource::SHADERS_COLORED_FS);
program->use();
renderGeometry(g, program);
gl::Stacks::modelview().pop();
}
示例12: glGetProgramStageiv
void
UniformGroup::apply_subroutines(ProgramPtr prog, GLenum shadertype,
const std::unordered_map<std::string, std::string>& subroutines)
{
assert_gl("apply_subroutines:enter");
GLint num_uniform_locations;
glGetProgramStageiv(prog->get_id(), shadertype, GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS, &num_uniform_locations);
std::vector<GLuint> subroutine_mappings;
for(int i = 0; i < num_uniform_locations; ++i)
{
char name[256];
GLsizei length;
glGetActiveSubroutineUniformName(prog->get_id(), shadertype, i, sizeof(name), &length, name);
const auto& it = subroutines.find(name);
if (it == subroutines.end())
{
log_error("unmapped subroutine: %s", name);
}
else
{
GLuint loc = glGetSubroutineIndex(prog->get_id(), shadertype, it->second.c_str());
if (loc == GL_INVALID_INDEX)
{
log_error("unknown subroutine: %s", it->second);
}
else
{
subroutine_mappings.emplace_back(loc);
}
}
}
glUniformSubroutinesuiv(shadertype, subroutine_mappings.size(), subroutine_mappings.data());
assert_gl("apply_subroutines:exit");
}
示例13: parse
bool Parser::parse(const wchar_t* code, const ProgramPtr& program)
{
tokenizer->set(code);
try
{
Token token;
while(peek(token))
{
StatementPtr statement = parseStatement();
if(!statement)
break;
program->addStatement(statement);
match(L";");
}
}
catch(...)
{
return false;
}
return true;
}
示例14: switch
void
Uniform<UniformSymbol>::apply(ProgramPtr prog, const RenderContext& ctx)
{
assert_gl("Uniform<UniformSymbol>::apply:enter");
switch(m_value)
{
case UniformSymbol::NormalMatrix:
prog->set_uniform(m_name, glm::mat3(ctx.get_view_matrix() * ctx.get_model_matrix()));
break;
case UniformSymbol::ViewMatrix:
prog->set_uniform(m_name, ctx.get_view_matrix());
break;
case UniformSymbol::ModelMatrix:
prog->set_uniform(m_name, ctx.get_model_matrix());
break;
case UniformSymbol::ModelViewMatrix:
prog->set_uniform(m_name, ctx.get_view_matrix() * ctx.get_model_matrix());
break;
case UniformSymbol::ProjectionMatrix:
prog->set_uniform(m_name, ctx.get_projection_matrix());
break;
case UniformSymbol::ModelViewProjectionMatrix:
prog->set_uniform(m_name, ctx.get_projection_matrix() * ctx.get_view_matrix() * ctx.get_model_matrix());
break;
default:
log_error("unknown UniformSymbol %d", static_cast<int>(m_value));
break;
}
assert_gl("Uniform<UniformSymbol>::apply:exit");
}
示例15: setProgram
/** Bind a program
Program have bindings globalVar->parameter
*/
void GLEngine::setProgram(ProgramPtr program)
{
if(mCurrentProgram.get() == program.get())
return;
mCurrentProgram = program;
}