void renderEye(StereoEye eye) { viewport(eye); gl::ProgramPtr distortProgram = GlUtils::getProgram( Resource::SHADERS_TEXTURED_VS, chroma ? Resource::SHADERS_RIFTCHROMAWARP_FS : Resource::SHADERS_RIFTWARP_FS); distortProgram->use(); distortProgram->setUniform1i("Scene", 1); distortProgram->setUniform1i("OffsetMap", 0); glActiveTexture(GL_TEXTURE1); sceneTextures[eye]->bind(); glActiveTexture(GL_TEXTURE0); lookupTextures[eye]->bind(); quadGeometry->bindVertexArray(); #ifdef DISTORTION_TIMING query->begin(); #endif quadGeometry->draw(); #ifdef DISTORTION_TIMING query->end(); static long accumulator = 0; static long count = 0; accumulator += query->getResult(); count++; SAY("%d ns", accumulator / count); #endif gl::VertexArray::unbind(); gl::Texture2d::unbind(); gl::Program::clear(); }
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 gl::GeometryPtr g = m.getGeometry(GL_LINES); g->updateVertices(m.buildVertices()); gl::ProgramPtr program = getProgram( Resource::SHADERS_COLORED_VS, Resource::SHADERS_COLORED_FS); program->use(); renderGeometry(g, program); gl::Program::clear(); }
void draw() { glClearColor(0, 1, 0, 1); glClear(GL_COLOR_BUFFER_BIT); GL_CHECK_ERROR; for (int i = 0; i < 2; ++i) { const EyeArg & eyeArg = eyeArgs[i]; frameBuffer.activate(); renderScene(eyeArg); frameBuffer.deactivate(); glDisable(GL_DEPTH_TEST); glDisable(GL_BLEND); gl::viewport(eyeArg.viewportLocation, eyeSize); distortProgram->use(); distortProgram->setUniform("LensOffset", eyeArg.lensOffset); frameBuffer.color->bind(); quadGeometry->bindVertexArray(); quadGeometry->draw(); gl::Geometry::unbindVertexArray(); gl::Program::clear(); } }
void GlUtils::renderGeometry( const gl::GeometryPtr & geometry, gl::ProgramPtr program) { program->use(); gl::Stacks::lights().apply(program); gl::Stacks::projection().apply(program); gl::Stacks::modelview().apply(program); geometry->bindVertexArray(); geometry->draw(); gl::VertexArray::unbind(); gl::Program::clear(); }
void initParticles(uint32_t num_particles) { m_geom = gl::Geometry::create(); m_geom->setPrimitiveType(GL_POINTS); m_mesh = gl::Mesh::create(m_geom, m_pointMaterial); m_numParticles = num_particles; GLsizei numBytes = m_numParticles * sizeof(vec4); m_geom->vertices().resize(m_numParticles, vec3(0)); m_geom->colors().resize(m_numParticles, vec4(1)); m_geom->point_sizes().resize(m_numParticles, 9.f); m_geom->createGLBuffers(); m_mesh->material()->setPointSize(2.f); scene().addObject(m_mesh); try { // shared position buffer for OpenGL / OpenCL m_positions = cl::BufferGL(m_context, CL_MEM_READ_WRITE, m_geom->vertexBuffer().id()); m_colors = cl::BufferGL(m_context, CL_MEM_READ_WRITE, m_geom->colorBuffer().id()); //create the OpenCL only arrays m_velocities = cl::Buffer( m_context, CL_MEM_WRITE_ONLY, numBytes ); m_positionGen = cl::Buffer( m_context, CL_MEM_WRITE_ONLY, numBytes ); m_velocityGen = cl::Buffer( m_context, CL_MEM_WRITE_ONLY, numBytes ); vector<vec4> posGen, velGen; for (int i = 0; i < m_numParticles; i++) { posGen.push_back( vec4(glm::ballRand(20.0f), 1.f) ); vec2 tmp = glm::linearRand(vec2(-100), vec2(100)); float life = kinski::random(2.f, 5.f); float yVel = kinski::random<float>(5, 15); velGen.push_back(vec4(tmp.x, yVel, tmp.y, life)); m_geom->point_sizes()[i] = kinski::random(5.f, 15.f); } m_geom->createGLBuffers(); m_queue.enqueueWriteBuffer(m_velocities, CL_TRUE, 0, numBytes, &velGen[0]); m_queue.enqueueWriteBuffer(m_positionGen, CL_TRUE, 0, numBytes, &posGen[0]); m_queue.enqueueWriteBuffer(m_velocityGen, CL_TRUE, 0, numBytes, &velGen[0]); m_particleKernel.setArg(0, m_positions); m_particleKernel.setArg(1, m_colors); m_particleKernel.setArg(2, m_velocities); m_particleKernel.setArg(3, m_positionGen); m_particleKernel.setArg(4, m_velocityGen); } catch(cl::Error &error) { LOG_ERROR << error.what() << "(" << oclErrorString(error.err()) << ")"; } }
void cubeRecurseDraw(gl::GeometryPtr & cubeGeometry, gl::ProgramPtr & renderProgram, int depth, float elapsed, int axisIndex) { if (0 == depth) { return; } static glm::vec3 translation(0, 0, 1.5); const glm::vec3 & axis = AXES[axisIndex % 3]; float angle = elapsed * 0.2f * ((rand() % 10) - 5); float scale = 0.7f; gl::MatrixStack & mv = gl::Stacks::modelview(); mv.with_push([&]{ mv.rotate(angle, axis).translate(translation).scale(scale).apply(renderProgram); cubeGeometry->draw(); cubeRecurseDraw(cubeGeometry, renderProgram, depth - 1, elapsed, axisIndex + 1); }); mv.with_push([&]{ mv.rotate(angle + PI, axis).translate(translation).scale(scale).apply(renderProgram); cubeGeometry->draw(); cubeRecurseDraw(cubeGeometry, renderProgram, depth - 1, elapsed, axisIndex + 1); }); }