本文整理汇总了C++中Program::compile方法的典型用法代码示例。如果您正苦于以下问题:C++ Program::compile方法的具体用法?C++ Program::compile怎么用?C++ Program::compile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Program
的用法示例。
在下文中一共展示了Program::compile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main( int argc, char** argv ) {
using namespace gfx;
using namespace std;
VideoManager testManager;
Window testWindow = testManager.create_window( WindowSettings()
.title( "First Window" )
.x_pos( 256 )
.use_opengl() );
Context testContext = testManager.create_context( testWindow,
ContextSettings()
.major_version(3)
.minor_version(3)
.depth_size(24)
.double_buffered() );
testManager.attach_context( testWindow, testContext );
//testManager.activate_context( testContext );
GLuint framebuf_ID;
gl::GenFramebuffers( 1, &framebuf_ID );
gl::BindFramebuffer( gl::DRAW_FRAMEBUFFER, framebuf_ID);
GLuint renderbuf_ID;
gl::GenRenderbuffers( 1, &renderbuf_ID );
gl::BindRenderbuffer( gl::RENDERBUFFER, renderbuf_ID );
gl::RenderbufferStorage( gl::RENDERBUFFER, gl::RGBA8, 512, 512 );
gl::FramebufferRenderbuffer( gl::DRAW_FRAMEBUFFER,
gl::COLOR_ATTACHMENT0,
gl::RENDERBUFFER,
renderbuf_ID );
GLenum fb_status = gl::CheckFramebufferStatus( gl::DRAW_FRAMEBUFFER );
gl::BindFramebuffer( gl::DRAW_FRAMEBUFFER, 0 );
if( fb_status == gl::FRAMEBUFFER_COMPLETE ) {
cout << "Framebuffer is complete, thank god." << endl;
} else {
cout << "Framebuffer is not complete, god dammit." << endl;
}
Program testProgram = testManager.create_program( ProgramSettings()
.uses_vert( "./shader/testVert.glsl" )
.uses_frag( "./shader/testFrag.glsl" ) );
try {
testProgram.compile();
} catch (compilation_error e) {
cout << e.what() << endl;
}
checkGLError( "compiled program" );
//GLenum drawbuffers[] = { gl::BACK_LEFT };
//gl::DrawBuffers( 1, drawbuffers );
Buffer testBuffer = testManager.create_buffer( BufferSettings()
.blocks(3)
.static_draw()
.for_array());
checkGLError( "vertex attribute buffer created" );
testBuffer.block_format( BlockSpec().attribute( type<vec2>() ) );
vector< vec2 > position;
position.push_back( vec2( 1.0f ));
position.push_back( vec2( 1.0f, -1.0f ));
position.push_back( vec2( -1.0f ));
//position.push_back( vec2( -0.5f, 0.5f ));
testBuffer.fill_attribute( 0, position );
testBuffer.load_data();
checkGLError( "loaded vertex data" );
testBuffer.align_vertices();
checkGLError( "aligned vertex data" );
//GLuint testElements[] = { 0, 1, 2 };
Buffer testElementBuffer = testManager.create_buffer( BufferSettings()
.blocks(3)
.for_element_array() );
testElementBuffer.block_format( BlockSpec()
.attribute( type<uint32>() ) );
vector< uint32 > indices;
indices.push_back( 0 );
indices.push_back( 1 );
indices.push_back( 2 );
testElementBuffer.fill_attribute( 0, indices );
testElementBuffer.load_data();
checkGLError( "loading element data" );
//testElementBuffer.align_vertices();
try {
//.........这里部分代码省略.........
示例2: main
int main(int argc, char **argv)
{
if (argc != 3) {
std::cerr << "Usage: springs <path to simit code> <path to data>" << std::endl;
return -1;
}
std::string codefile = argv[1];
std::string datafile = argv[2];
simit::init("cpu", sizeof(double));
// Load mesh data using Simit's mesh loader.
MeshVol mesh;
mesh.loadTet(datafile+".node", datafile+".ele");
mesh.makeTetSurf();
// Create a graph and initialize it with mesh data
Set verts;
Set tets(verts, verts, verts, verts);
simit::FieldRef<double,3> x = verts.addField<double,3>("x");
simit::FieldRef<double,3> v = verts.addField<double,3>("v");
simit::FieldRef<double,3> fe = verts.addField<double,3>("fe");
simit::FieldRef<int> c = verts.addField<int>("c");
simit::FieldRef<double> m = verts.addField<double>("m");
simit::FieldRef<double> u = tets.addField<double>("u");
simit::FieldRef<double> l = tets.addField<double>("l");
simit::FieldRef<double> W = tets.addField<double>("W");
simit::FieldRef<double,3,3> B = tets.addField<double,3,3>("B");
// Compile program and bind arguments
Program program;
program.loadFile(codefile);
Function precompute = program.compile("initializeTet");
Function timestep = program.compile("main");
timestep.bind("verts", &verts);
timestep.bind("tets", &tets);
timestep.init();
// Create a graph and initialize it with mesh data
Set points;
Set springs(points, points);
// Take 100 time steps
for (int i = 1; i <= 100; ++i) {
std::cout << "timestep " << i << std::endl;
timestep.unmapArgs(); // Move data to compute memory space (e.g. GPU)
timestep.run(); // Run the timestep function
timestep.mapArgs(); // Move data back to this memory space
// Copy the x field to the mesh and save it to an obj file
int vi = 0;
for (auto &vert : points) {
for(int ii = 0; ii < 3; ii++){
mesh.v[vi][ii] = x.get(vert)(ii);
}
vi++;
}
mesh.updateSurfVert();
mesh.saveTetObj(std::to_string(i)+".obj");
}
}