in roboschool/cpp-household/render-simple.cpp [475:572]
void ContextViewport::paint(float user_x, float user_y, float user_z, float wheel, float zrot, float xrot, Household::Camera* camera, int floor_visible, uint32_t view_options, float ruler_size)
{
if (!cx->program_tex) {
cx->initGL();
cx->_generate_ruler_vao();
}
if (camera) floor_visible = 65535; // disable visibility_123 for robot cameras
//fprintf(stderr, "0x%p render %ix%i\n", this, W, H);
#ifdef USE_SSAO
glBindFramebuffer(GL_FRAMEBUFFER, fbuf_scene->handle);
#else
// For rendering without shadows, just keep rendering on default framebuffer
if (camera)
glBindFramebuffer(GL_FRAMEBUFFER, fbuf_scene->handle); // unless we render offscreen for camera
#endif
glViewport(0,0,W,H);
float clear_color[4] = { 0.8, 0.8, 0.9, 1.0 };
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClearBufferfv(GL_COLOR, 0, clear_color);
glClearDepth(1.0);
glClear(GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
double xmin, xmax;
xmax = near * tanf(hfov * M_PI / 180 * 0.5);
xmin = -xmax;
QMatrix4x4 projection;
projection.frustum(xmin, xmax, xmin*H/W, xmax*H/W, near, far);
QMatrix4x4 matrix_view;
if (!camera) {
matrix_view.translate(0, 0, -0.5*wheel);
matrix_view.rotate(xrot, QVector3D(1.0, 0.0, 0.0));
matrix_view.rotate(zrot, QVector3D(0.0, 0.0, 1.0));
matrix_view.translate(-user_x, -user_y, -user_z);
//gl_Position = projMat * viewMat * modelMat * vec4(position, 1.0);
} else {
shared_ptr<Thingy> attached = camera->camera_attached_to.lock();
btTransform t = attached ? attached->bullet_position.inverse() : camera->camera_pose.inverse();
btScalar m[16];
t.getOpenGLMatrix(m);
for (int i=0; i<16; i++) matrix_view.data()[i] = m[i];
}
modelview = projection * matrix_view;
modelview_inverse_transpose = modelview.inverted().transposed();
if (cx->need_load_missing_textures) {
cx->need_load_missing_textures = false;
cx->load_missing_textures();
}
cx->program_tex->bind();
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
cx->program_tex->setUniformValue(cx->location_enable_texture, false);
cx->program_tex->setUniformValue(cx->location_uni_color, 0,0,0,0.8);
cx->program_tex->setUniformValue(cx->location_texture, 0);
cx->program_tex->setUniformValue(cx->location_input_matrix_modelview, modelview);
cx->program_tex->setUniformValue(cx->location_input_matrix_modelview_inverse_transpose, modelview_inverse_transpose);
if (~view_options & VIEW_CAMERA_BIT) {
glBindVertexArray(cx->ruler_vao->handle);
CHECK_GL_ERROR; // error often here, when context different, also set if (1) above to always enter this code block
glDrawArrays(GL_LINES, 0, sizeof(line_vertex)/sizeof(float)/3);
glBindVertexArray(0);
}
visible_object_count = _objects_loop(floor_visible, view_options);
cx->program_tex->release();
#ifdef USE_SSAO
if (cx->ssao_enable) {
_hbao_prepare(projection.data());
_depthlinear_paint(0);
_ssao_run(0);
}
if (camera) {
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbuf_scene->handle); // buffer stays bound so camera can read pixels
return;
}
glBindFramebuffer(GL_FRAMEBUFFER, fbuf_scene->handle);
// if (ssao_debug==0) glBindFramebuffer(GL_READ_FRAMEBUFFER, fbuf_scene->handle);
// else if (ssao_debug==1) glBindFramebuffer(GL_READ_FRAMEBUFFER, fbuf_depthlinear->handle);
// glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
// if (ssao_debug < 2) {
// glBlitFramebuffer(0,0,W,H, 0,0,W,H, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// } else if (ssao_debug==2) {
// //_texture_paint( cx->cached_bind_texture("roboschool/models_furniture/IKEA_denimcloth.jpg") );
// _texture_paint( tex_depthlinear->handle );
// } else if (ssao_debug==3) {
// _texture_paint( tex_depthstencil->handle );
// }
// glBindFramebuffer(GL_FRAMEBUFFER, 0);
#endif
}