void MemExploreApp::draw() { mTexture = gl::Texture(mDataPointer, GL_RGBA, mVolumeDim * mTilesDim, mVolumeDim * mTilesDim); mTexture.setWrap(GL_REPEAT, GL_REPEAT); mTexture.setMinFilter(GL_NEAREST); mTexture.setMagFilter(GL_NEAREST); float frustum[6]; mCamera.getFrustum(&frustum[0], &frustum[1], &frustum[2], &frustum[3], &frustum[4], &frustum[5]); mFbo.bindFramebuffer(); gl::setMatricesWindow(mFbo.getSize(), false); mProgram.bind(); mProgram.uniform("uTexture", 0); mProgram.uniform("uVolumeDim", mVolumeDim); mProgram.uniform("uTilesDim", mTilesDim); mProgram.uniform("uTime", (float)getElapsedSeconds()); mProgram.uniform("uEyePoint", mCamera.getEyePoint()); mProgram.uniform("uXAxis", mCamera.getOrientation() * Vec3f::xAxis()); mProgram.uniform("uYAxis", mCamera.getOrientation() * Vec3f::yAxis()); mProgram.uniform("uViewDistance", mCamera.getAspectRatio() / abs(frustum[2] - frustum[0]) * mCamera.getNearClip()); mProgram.uniform("uNegViewDir", -mCamera.getViewDirection().normalized()); mProgram.uniform("uAspectRatio", mCamera.getAspectRatio()); mTexture.enableAndBind(); gl::drawSolidRect(mFbo.getBounds()); mTexture.unbind(); mProgram.unbind(); mFbo.unbindFramebuffer(); gl::setMatricesWindow(getWindowSize()); gl::draw(mFbo.getTexture(), getWindowBounds()); }
void PTWeekend::draw() { /* * BEGIN - each frame part */ /* Enqueue kernel for execution */ glm::vec3 origin,lower_left, hor, ver; float theta = camera.getFov() * M_PI / 180.0f; float half_height = tan(theta / 2.0f); float half_width = camera.getAspectRatio() * half_height; origin = camera.getEyePoint(); glm::vec3 u, v, w; w = -glm::normalize(camera.getViewDirection()); //odd... u = glm::normalize(glm::cross(glm::vec3(0,1,0), w)); v = glm::cross(w, u); lower_left = origin - half_width * u - half_height * v - w; hor = 2.0f * half_width * u; ver = 2.0f * half_height * v; pt_assert(cl_set_pinhole_cam_arg(origin, lower_left, hor, ver, cam_buffer, cmd_queue), "Could not fill camera buffer"); clStatus = cmd_queue.enqueueAcquireGLObjects(&img_buffer, NULL, NULL); pt_assert(clStatus, "Could not acquire gl objects"); cl::Event profiling_evt; clStatus = cmd_queue.enqueueNDRangeKernel(kernel, cl::NDRange(0,0), cl::NDRange(img_width, img_height), cl::NDRange(local_width,local_height), NULL, &profiling_evt); profiling_evt.wait(); pt_assert(clStatus, "Could not enqueue the kernel"); clStatus = cmd_queue.enqueueReleaseGLObjects(&img_buffer, NULL, NULL); pt_assert(clStatus, "Could not release gl objects"); cmd_queue.finish(); cl_ulong time_start = profiling_evt.getProfilingInfo<CL_PROFILING_COMMAND_START>(); cl_ulong time_end = profiling_evt.getProfilingInfo<CL_PROFILING_COMMAND_END>(); cl_ulong total_time = time_end - time_start; std::cout << "Total time: " << total_time * 0.001 * 0.001 << " ms \n"; /* * END - each frame part */ gl::draw(imgTex, Rectf(0, 0, getWindowWidth(), getWindowHeight())); }
void gpuPSApp::computeAttractorPosition() { // The attractor is positioned at the intersection of a ray // from the mouse to a plane perpendicular to the camera. float t = 0; Vec3f right, up; mMayaCam.getCamera().getBillboardVectors(&right, &up); CameraPersp cam = mMayaCam.getCamera(); float u = mMousePos.x / (float) getWindowWidth(); float v = mMousePos.y / (float) getWindowHeight(); Ray ray = cam.generateRay(u , 1.0f - v, cam.getAspectRatio() ); if (ray.calcPlaneIntersection(Vec3f(0.0f,0.0f,0.0f), right.cross(up), &t)) { mAttractor.set(ray.calcPosition(t)); } }