void CHudFlagCarrier::OnThink( void ) { if ( NeedsUpdate() ) { Update(); } }
void VideoPreviewer::ReadVideoFrame(unsigned int width, unsigned int height, const uint8_t* data, int stride, AVPixelFormat format, int64_t timestamp) { Q_UNUSED(timestamp); QSize image_size; { SharedLock lock(&m_shared_data); // check the timestamp if(lock->m_next_frame_time == SINK_TIMESTAMP_ASAP) { lock->m_next_frame_time = timestamp + 1000000 / lock->m_frame_rate; } else { if(timestamp < lock->m_next_frame_time - 1000000 / lock->m_frame_rate) return; lock->m_next_frame_time = std::max(lock->m_next_frame_time + 1000000 / lock->m_frame_rate, timestamp); } // don't do anything if the preview window is invisible if(!lock->m_is_visible) return; // check the size (the scaler can't handle sizes below 2) if(width < 2 || height < 2 || lock->m_widget_size.width() < 2 || lock->m_widget_size.height() < 2) return; // calculate the scaled size lock->m_source_size = QSize(width, height); image_size = CalculateScaledSize(lock->m_source_size, lock->m_widget_size); } // allocate the image int image_stride = grow_align16(image_size.width() * 4); std::shared_ptr<TempBuffer<uint8_t> > image_buffer = std::make_shared<TempBuffer<uint8_t> >(); image_buffer->Alloc(image_stride * image_size.height()); uint8_t *image_data = image_buffer->GetData(); // scale the image m_fast_scaler.Scale(width, height, format, &data, &stride, image_size.width(), image_size.height(), AV_PIX_FMT_BGRA, &image_data, &image_stride); // set the alpha channel to 0xff (just to be sure) // Some applications (e.g. firefox) generate alpha values that are not 0xff. // I'm not sure whether Qt cares about this, apparently Qt 4.8 with the 'native' back-end doesn't, // but I'm not sure about the other back-ends. /*for(int y = 0; y < image_size.height(); ++y) { uint8_t *row = image_data + image_stride * y; for(int x = 0; x < image_size.width(); ++x) { row[x * 4 + 3] = 0xff; // third byte is alpha because we're little-endian } }*/ // store the image SharedLock lock(&m_shared_data); lock->m_image_buffer = std::move(image_buffer); image_buffer.reset(); lock->m_image_stride = image_stride; lock->m_image_size = image_size; emit NeedsUpdate(); }
SyncDiagram::SyncDiagram(size_t channels) { assert(channels > 0); { SharedLock lock(&m_shared_data); lock->m_time_channels.resize(channels); for(auto &c : lock->m_time_channels) { c.m_name = ""; c.m_current_time = 0.0; c.m_time_shift = std::numeric_limits<double>::max() * 0.5; c.m_time_shift_v = 0.0; } } m_height = CHANNEL_SPACING + (CHANNEL_HEIGHT + CHANNEL_SPACING) * channels; m_font = QFont("Sans"); m_font.setPixelSize(12); setWindowTitle(tr("Synchronization Diagram") + " - " + MainWindow::WINDOW_CAPTION); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_update_timer = new QTimer(this); m_update_timer->setSingleShot(true); connect(this, SIGNAL(NeedsUpdate()), this, SLOT(DelayedUpdate()), Qt::QueuedConnection); connect(m_update_timer, SIGNAL(timeout()), this, SLOT(update())); setMinimumSize(minimumSizeHint()); // workaround for Qt bug }
void VideoPreviewer::ReadVideoFrame(unsigned int width, unsigned int height, const uint8_t* data, int stride, PixelFormat format, int64_t timestamp) { Q_UNUSED(timestamp); SharedLock lock(&m_shared_data); // don't do anything if the preview window is invisible if(!lock->m_is_visible) return; // check the size if(width < 2 || height < 2 || lock->m_widget_size.width() < 2 || lock->m_widget_size.height() < 2) return; // check the timestamp if(lock->m_next_frame_time == SINK_TIMESTAMP_ANY) { lock->m_next_frame_time = timestamp + 1000000 / lock->m_frame_rate; } else { if(timestamp < lock->m_next_frame_time - 1000000 / lock->m_frame_rate) return; lock->m_next_frame_time = std::max(lock->m_next_frame_time + 1000000 / lock->m_frame_rate, timestamp); } // calculate the scaled size lock->m_source_size = QSize(width, height); QSize image_size = CalculateScaledSize(lock->m_source_size, lock->m_widget_size); // allocate the image if(lock->m_image.size() != image_size) { lock->m_image = QImage(image_size, QImage::Format_RGB32); } // scale the image uint8_t *out_data = lock->m_image.bits(); int out_stride = lock->m_image.bytesPerLine(); m_fast_scaler.Scale(width, height, &data, &stride, format, image_size.width(), image_size.height(), &out_data, &out_stride, PIX_FMT_BGRA); // set the alpha channel to 0xff (just to be sure) // Some applications (e.g. firefox) generate alpha values that are not 0xff. // I'm not sure whether Qt cares about this, apparently Qt 4.8 with the 'native' back-end doesn't, // but I'm not sure about the other back-ends. for(int y = 0; y < image_size.height(); ++y) { uint8_t *row = lock->m_image.scanLine(y); for(int x = 0; x < image_size.width(); ++x) { row[x * 4 + 3] = 0xff; // third byte is alpha because we're little-endian } } emit NeedsUpdate(); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CPotentialFieldMgr::FrameUpdatePreEntityThink() { VPROF_BUDGET( "CPotentialFieldMgr::FrameUpdatePreEntityThink", VPROF_BUDGETGROUP_POTENTIALFIELD ); if( !m_bActive ) return; if( !NeedsUpdate() ) return; m_fNeedsUpdate = gpGlobals->curtime + 0.1f; m_pPotentialField->Reset(); m_pPotentialField->Update(); }
VideoPreviewer::VideoPreviewer(QWidget* parent) : QWidget(parent) { { SharedLock lock(&m_shared_data); lock->m_next_frame_time = SINK_TIMESTAMP_ANY; lock->m_is_visible = false; lock->m_source_size = QSize(0, 0); lock->m_widget_size = QSize(0, 0); lock->m_frame_rate = 10; } setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); connect(this, SIGNAL(NeedsUpdate()), this, SLOT(update()), Qt::QueuedConnection); }
/** Draws the surrounding scene into the cubemap */ void D3D11PointLight::RenderCubemap(bool forceUpdate) { if(!InitDone) return; //if(!GetAsyncKeyState('X')) // return; D3D11GraphicsEngineBase* engineBase = (D3D11GraphicsEngineBase *)Engine::GraphicsEngine; D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *) engineBase; // TODO: Remove and use newer system! D3DXVECTOR3 vEyePt = LightInfo->Vob->GetPositionWorld(); //vEyePt += D3DXVECTOR3(0,1,0) * 20.0f; // Move lightsource out of the ground or other objects (torches!) // TODO: Move the actual lightsource up too! /*if(WantsUpdate()) { // Move lights with colorchanges around a bit to make it look more light torches vEyePt.y += (float4(LastUpdateColor).x - 0.5f) * LIGHT_COLORCHANGE_POS_MOD; vEyePt.x += (float4(LastUpdateColor).y - 0.5f) * LIGHT_COLORCHANGE_POS_MOD; vEyePt.z += (float4(LastUpdateColor).y - 0.5f) * LIGHT_COLORCHANGE_POS_MOD; }*/ D3DXVECTOR3 vLookDir; D3DXVECTOR3 vUpDir; if(!NeedsUpdate() && !WantsUpdate()) { if(!forceUpdate) return; // Don't update when we don't need to }else { if(LightInfo->Vob->GetPositionWorld() != LastUpdatePosition) { // Position changed, refresh our caches VobCache.clear(); SkeletalVobCache.clear(); // Invalidate worldcache WorldCacheInvalid = true; } } // Update indoor/outdoor-state LightInfo->IsIndoorVob = LightInfo->Vob->IsIndoorVob(); D3DXMATRIX proj; const bool dbg = false; // Generate cubemap view-matrices vLookDir = D3DXVECTOR3( 1.0f, 0.0f, 0.0f ) + vEyePt; vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ); if(dbg)Engine::GraphicsEngine->GetLineRenderer()->AddLine(LineVertex(vEyePt, float4(1.0f,0,0,1)), LineVertex((vLookDir - vEyePt) * 50.0f + vEyePt, float4(1.0f,1.0f,0,1))); D3DXMatrixLookAtLH( &CubeMapViewMatrices[0], &vEyePt, &vLookDir, &vUpDir ); vLookDir = D3DXVECTOR3( -1.0f, 0.0f, 0.0f ) + vEyePt; vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ); if(dbg)Engine::GraphicsEngine->GetLineRenderer()->AddLine(LineVertex(vEyePt, float4(1.0f,0,0,1)), LineVertex((vLookDir - vEyePt) * 50.0f + vEyePt, float4(1.0f,1.0f,0,1))); D3DXMatrixLookAtLH( &CubeMapViewMatrices[1], &vEyePt, &vLookDir, &vUpDir ); vLookDir = D3DXVECTOR3( 0.0f, 0.0f + 1.0f, 0.0f ) + vEyePt; vUpDir = D3DXVECTOR3( 0.0f, 0.0f, -1.0f ); if(dbg)Engine::GraphicsEngine->GetLineRenderer()->AddLine(LineVertex(vEyePt, float4(1.0f,0,0,1)), LineVertex((vLookDir - vEyePt) * 50.0f + vEyePt, float4(1.0f,1.0f,0,1))); D3DXMatrixLookAtLH( &CubeMapViewMatrices[2], &vEyePt, &vLookDir, &vUpDir ); vLookDir = D3DXVECTOR3( 0.0f, 0.0f - 1.0f, 0.0f ) + vEyePt; vUpDir = D3DXVECTOR3( 0.0f, 0.0f, 1.0f ); if(dbg)Engine::GraphicsEngine->GetLineRenderer()->AddLine(LineVertex(vEyePt, float4(1.0f,0,0,1)), LineVertex((vLookDir - vEyePt) * 50.0f + vEyePt, float4(1.0f,1.0f,0,1))); D3DXMatrixLookAtLH( &CubeMapViewMatrices[3], &vEyePt, &vLookDir, &vUpDir ); vLookDir = D3DXVECTOR3( 0.0f, 0.0f, 1.0f ) + vEyePt; vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ); if(dbg)Engine::GraphicsEngine->GetLineRenderer()->AddLine(LineVertex(vEyePt, float4(1.0f,0,0,1)), LineVertex((vLookDir - vEyePt) * 50.0f + vEyePt, float4(1.0f,1.0f,0,1))); D3DXMatrixLookAtLH( &CubeMapViewMatrices[4], &vEyePt, &vLookDir, &vUpDir ); vLookDir = D3DXVECTOR3( 0.0f, 0.0f, -1.0f ) + vEyePt; vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ); if(dbg)Engine::GraphicsEngine->GetLineRenderer()->AddLine(LineVertex(vEyePt, float4(1.0f,0,0,1)), LineVertex((vLookDir - vEyePt) * 50.0f + vEyePt, float4(1.0f,1.0f,0,1))); D3DXMatrixLookAtLH( &CubeMapViewMatrices[5], &vEyePt, &vLookDir, &vUpDir ); for(int i=0;i<6;i++) D3DXMatrixTranspose(&CubeMapViewMatrices[i], &CubeMapViewMatrices[i]); // Create the projection matrix float zNear = 15.0f; float zFar = LightInfo->Vob->GetLightRange() * 2.0f; D3DXMatrixPerspectiveFovLH( &proj, ((float)D3DX_PI * 0.5f), 1.0f, zNear, zFar ); D3DXMatrixTranspose(&proj, &proj); // Setup near/far-planes. We need linear viewspace depth for the cubic shadowmaps. Engine::GAPI->GetRendererState()->GraphicsState.FF_zNear = zNear; Engine::GAPI->GetRendererState()->GraphicsState.FF_zFar = zFar; Engine::GAPI->GetRendererState()->GraphicsState.SetGraphicsSwitch(GSWITCH_LINEAR_DEPTH, true); bool oldDepthClip = Engine::GAPI->GetRendererState()->RasterizerState.DepthClipEnable; Engine::GAPI->GetRendererState()->RasterizerState.DepthClipEnable = true; // Upload view-matrices to the GPU CubemapGSConstantBuffer gcb; for(int i=0;i<6;i++) { gcb.PCR_View[i] = CubeMapViewMatrices[i]; gcb.PCR_ViewProj[i] = proj * CubeMapViewMatrices[i]; } ViewMatricesCB->UpdateBuffer(&gcb); ViewMatricesCB->BindToGeometryShader(2); //for(int i=0;i<6;i++) // RenderCubemapFace(CubeMapViewMatrices[i], proj, i); RenderFullCubemap(); if(dbg) { for(auto it = VobCache.begin();it!=VobCache.end();it++) Engine::GraphicsEngine->GetLineRenderer()->AddLine(LineVertex(vEyePt, float4(1.0f,0,0,1)), LineVertex((*it)->Vob->GetPositionWorld(), float4(1.0f,1.0f,0,1))); } Engine::GAPI->GetRendererState()->RasterizerState.DepthClipEnable = oldDepthClip; Engine::GAPI->GetRendererState()->GraphicsState.SetGraphicsSwitch(GSWITCH_LINEAR_DEPTH, false); LastUpdateColor = LightInfo->Vob->GetLightColor(); LastUpdatePosition = vEyePt; DrawnOnce = true; }
void VideoPreviewer::Reset() { SharedLock lock(&m_shared_data); lock->m_image = QImage(); emit NeedsUpdate(); }
void SyncDiagram::Update() { emit NeedsUpdate(); }