FOpenGLViewport::FOpenGLViewport(FOpenGLDynamicRHI* InOpenGLRHI,void* InWindowHandle,uint32 InSizeX,uint32 InSizeY,bool bInIsFullscreen,EPixelFormat PreferredPixelFormat) : OpenGLRHI(InOpenGLRHI) , OpenGLContext(NULL) , SizeX(0) , SizeY(0) , bIsFullscreen(false) , PixelFormat(PreferredPixelFormat) , bIsValid(true) , FrameSyncEvent(InOpenGLRHI) { check(OpenGLRHI); //@to-do spurious check for HTML5, will need to go away. #if !PLATFORM_HTML5 check(InWindowHandle); #endif check(IsInGameThread()); PlatformGlGetError(); // flush out old errors. OpenGLRHI->Viewports.Add(this); check(PlatformOpenGLCurrentContext(OpenGLRHI->PlatformDevice) == CONTEXT_Shared); OpenGLContext = PlatformCreateOpenGLContext(OpenGLRHI->PlatformDevice, InWindowHandle); Resize(InSizeX, InSizeY, bInIsFullscreen); check(PlatformOpenGLCurrentContext(OpenGLRHI->PlatformDevice) == CONTEXT_Shared); BeginInitResource(&FrameSyncEvent); }
void FOpenGLDynamicRHI::RHIBeginDrawingViewport(FViewportRHIParamRef ViewportRHI, FTextureRHIParamRef RenderTarget) { VERIFY_GL_SCOPE(); FOpenGLViewport* Viewport = ResourceCast(ViewportRHI); SCOPE_CYCLE_COUNTER(STAT_OpenGLPresentTime); check(!DrawingViewport); DrawingViewport = Viewport; bRevertToSharedContextAfterDrawingViewport = false; EOpenGLCurrentContext CurrentContext = PlatformOpenGLCurrentContext( PlatformDevice ); if( CurrentContext != CONTEXT_Rendering ) { check(CurrentContext == CONTEXT_Shared); check(!bIsRenderingContextAcquired || !GUseThreadedRendering); bRevertToSharedContextAfterDrawingViewport = true; PlatformRenderingContextSetup(PlatformDevice); } if(!GPUProfilingData.FrameTiming.IsInitialized()) { GPUProfilingData.FrameTiming.InitResource(); } // Set the render target and viewport. if( RenderTarget ) { FRHIRenderTargetView RTV(RenderTarget); RHISetRenderTargets(1, &RTV, nullptr, 0, NULL); } else { FRHIRenderTargetView RTV(DrawingViewport->GetBackBuffer()); RHISetRenderTargets(1, &RTV, nullptr, 0, NULL); } }
void FOpenGLDynamicRHI::RHIBeginDrawingViewport(FViewportRHIParamRef ViewportRHI, FTextureRHIParamRef RenderTarget) { VERIFY_GL_SCOPE(); DYNAMIC_CAST_OPENGLRESOURCE(Viewport,Viewport); SCOPE_CYCLE_COUNTER(STAT_OpenGLPresentTime); check(!DrawingViewport); DrawingViewport = Viewport; bRevertToSharedContextAfterDrawingViewport = false; EOpenGLCurrentContext CurrentContext = PlatformOpenGLCurrentContext( PlatformDevice ); if( CurrentContext != CONTEXT_Rendering ) { check(CurrentContext == CONTEXT_Shared); check(!bIsRenderingContextAcquired); bRevertToSharedContextAfterDrawingViewport = true; PlatformRenderingContextSetup(PlatformDevice); } if(!GPUProfilingData.FrameTiming.IsInitialized()) { GPUProfilingData.FrameTiming.InitResource(); } // Set the render target and viewport. if( RenderTarget ) { RHISetRenderTarget(RenderTarget, FTextureRHIRef()); } else { RHISetRenderTarget(DrawingViewport->GetBackBuffer(), FTextureRHIRef()); } }