321
321
cache_dirty = false;
322
322
return blur_texture_;
325
nux::ObjectPtr<nux::IOpenGLBaseTexture> BackgroundEffectHelper::GetRegion(nux::Geometry geo, bool force_update)
327
bool should_update = force_update || cache_dirty;
329
/* Static blur: only update when the size changed */
331
&& blur_texture_.IsValid()
332
&& (geo == blur_geometry_))
334
return blur_texture_;
337
nux::GraphicsEngine* graphics_engine = nux::GetGraphicsDisplay()->GetGraphicsEngine();
339
int monitor_width = BackgroundEffectHelper::monitor_rect_.width;
340
int monitor_height = BackgroundEffectHelper::monitor_rect_.height;
342
nux::Geometry temp = geo;
343
temp.OffsetPosition(-monitor_rect_.x, -monitor_rect_.y);
344
blur_geometry_ = nux::Geometry(0, 0, monitor_width, monitor_height).Intersect(temp);
346
nux::GpuDevice* gpu_device = nux::GetGraphicsDisplay()->GetGpuDevice();
347
if (blur_geometry_.IsNull() || !gpu_device->backup_texture0_.IsValid())
349
return nux::ObjectPtr<nux::IOpenGLBaseTexture>();
352
// save the current fbo
353
nux::ObjectPtr<nux::IOpenGLFrameBufferObject> current_fbo = gpu_device->GetCurrentFrameBufferObject();
354
gpu_device->DeactivateFrameBuffer();
356
// Set a viewport to the requested size
357
// FIXME: We need to do multiple passes for the dirty region
358
// on the underlying backup texture so that we're only updating
359
// the bits that we need
360
graphics_engine->SetViewport(0, 0, blur_geometry_.width, blur_geometry_.height);
361
graphics_engine->SetScissor(0, 0, blur_geometry_.width, blur_geometry_.height);
362
// Disable nux scissoring
363
graphics_engine->GetRenderStates ().EnableScissor (false);
365
// The background texture is the same size as the monitor where we are rendering.
366
nux::TexCoordXForm texxform__bg;
367
texxform__bg.flip_v_coord = false;
368
texxform__bg.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
369
texxform__bg.uoffset = ((float) blur_geometry_.x) / monitor_width;
370
texxform__bg.voffset = ((float) monitor_height - blur_geometry_.y - blur_geometry_.height) / monitor_height;
373
nux::ObjectPtr<nux::IOpenGLBaseTexture> device_texture = gpu_device->backup_texture0_;
374
nux::ObjectPtr<nux::CachedBaseTexture> noise_device_texture = graphics_engine->CacheResource(noise_texture_);
376
unsigned int offset = 0;
377
int quad_width = blur_geometry_.width;
378
int quad_height = blur_geometry_.height;
380
unsigned int buffer_width = quad_width + 2 * offset;
381
unsigned int buffer_height = quad_height + 2 * offset;
383
texxform__bg.SetFilter(nux::TEXFILTER_NEAREST, nux::TEXFILTER_NEAREST);
384
texxform__bg.flip_v_coord = true;
386
// Copy source texture
387
graphics_engine->QRP_GetCopyTexture(buffer_width, buffer_height,
388
blur_texture_, device_texture,
389
texxform__bg, nux::color::White);
392
if (current_fbo.IsValid())
394
current_fbo->Activate(true);
395
graphics_engine->Push2DWindow(current_fbo->GetWidth(), current_fbo->GetHeight());
396
graphics_engine->GetRenderStates ().EnableScissor (true);
400
graphics_engine->SetViewport(0, 0, monitor_width, monitor_height);
401
graphics_engine->Push2DWindow(monitor_width, monitor_height);
403
graphics_engine->ApplyClippingRectangle();
407
return blur_texture_;