void FOpenGLViewport::Resize(uint32 InSizeX,uint32 InSizeY,bool bInIsFullscreen) { if ((InSizeX == SizeX) && (InSizeY == SizeY) && (bInIsFullscreen == bIsFullscreen)) { return; } VERIFY_GL_SCOPE(); if (IsValidRef(CustomPresent)) { CustomPresent->OnBackBufferResize(); } BackBuffer.SafeRelease(); // when the rest of the engine releases it, its framebuffers will be released too (those the engine knows about) BackBuffer = (FOpenGLTexture2D*)PlatformCreateBuiltinBackBuffer(OpenGLRHI, InSizeX, InSizeY); if (!BackBuffer) { BackBuffer = (FOpenGLTexture2D*)OpenGLRHI->CreateOpenGLTexture(InSizeX, InSizeY, false, false, PixelFormat, 1, 1, 1, TexCreate_RenderTargetable, FClearValueBinding::None); } PlatformResizeGLContext(OpenGLRHI->PlatformDevice, OpenGLContext, InSizeX, InSizeY, bInIsFullscreen, bIsFullscreen, BackBuffer->Target, BackBuffer->Resource); SizeX = InSizeX; SizeY = InSizeY; bIsFullscreen = bInIsFullscreen; }
FOpenGLTextureUnorderedAccessView::FOpenGLTextureUnorderedAccessView( FTextureRHIParamRef InTextureRHI): TextureRHI(InTextureRHI) { VERIFY_GL_SCOPE(); FOpenGLTextureBase* Texture = GetOpenGLTextureFromRHITexture(TextureRHI); const FOpenGLTextureFormat& GLFormat = GOpenGLTextureFormats[TextureRHI->GetFormat()]; this->Resource = Texture->Resource; this->Format = GLFormat.InternalFormat[0]; }
void PlatformResizeGLContext( FPlatformOpenGLDevice* Device, FPlatformOpenGLContext* Context, uint32 SizeX, uint32 SizeY, bool bFullscreen, bool bWasFullscreen, GLenum BackBufferTarget, GLuint BackBufferResource) { check(Context); VERIFY_GL_SCOPE(); UE_LOG(LogHTML5OpenGL, Verbose, TEXT("SDL_SetWindowSize(%d,%d)"), SizeX, SizeY); SDL_SetWindowSize(Device->WindowHandle,SizeX,SizeY); #if PLATFORM_HTML5_BROWSER // let the browser know of possible new width:height ratio EM_ASM( window.dispatchEvent(new Event('resize')); );
void PlatformResizeGLContext( FPlatformOpenGLDevice* Device, FPlatformOpenGLContext* Context, uint32 SizeX, uint32 SizeY, bool bFullscreen, bool bWasFullscreen, GLenum BackBufferTarget, GLuint BackBufferResource) { check(Context); VERIFY_GL_SCOPE(); UE_LOG(LogHTML5OpenGL, Verbose, TEXT("SDL_SetWindowSize(%d,%d)"), SizeX, SizeY); SDL_SetWindowSize(Device->WindowHandle,SizeX,SizeY); glViewport(0, 0, SizeX, SizeY); //@todo-mobile Do we need to clear here? glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); }
void PlatformResizeGLContext( FPlatformOpenGLDevice* Device, FPlatformOpenGLContext* Context, uint32 SizeX, uint32 SizeY, bool bFullscreen, bool bWasFullscreen, GLenum BackBufferTarget, GLuint BackBufferResource) { check(Context); VERIFY_GL_SCOPE(); // we can't resize with the win32 emu right now -- we have no way of resizing the window. #if !PLATFORM_HTML5_WIN32 emscripten_set_canvas_size(SizeX, SizeY); #endif glViewport(0, 0, SizeX, SizeY); //@todo-mobile Do we need to clear here? glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); }
FIndexBufferRHIRef FOpenGLDynamicRHI::RHICreateIndexBuffer(uint32 Stride,uint32 Size, uint32 InUsage, FRHIResourceCreateInfo& CreateInfo) { VERIFY_GL_SCOPE(); const void *Data = NULL; // If a resource array was provided for the resource, create the resource pre-populated if(CreateInfo.ResourceArray) { check(Size == CreateInfo.ResourceArray->GetResourceDataSize()); Data = CreateInfo.ResourceArray->GetResourceData(); } TRefCountPtr<FOpenGLIndexBuffer> IndexBuffer = new FOpenGLIndexBuffer(Stride, Size, InUsage, Data); return IndexBuffer.GetReference(); }
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()); } }
FOpenGLVertexBufferUnorderedAccessView::FOpenGLVertexBufferUnorderedAccessView( FOpenGLDynamicRHI* InOpenGLRHI, FVertexBufferRHIParamRef InVertexBufferRHI, uint8 Format): VertexBufferRHI(InVertexBufferRHI), OpenGLRHI(InOpenGLRHI) { VERIFY_GL_SCOPE(); FOpenGLVertexBuffer* InVertexBuffer = FOpenGLDynamicRHI::ResourceCast(InVertexBufferRHI); const FOpenGLTextureFormat& GLFormat = GOpenGLTextureFormats[Format]; GLuint TextureID = 0; FOpenGL::GenTextures(1,&TextureID); // Use a texture stage that's not likely to be used for draws, to avoid waiting OpenGLRHI->CachedSetupTextureStage(OpenGLRHI->GetContextStateForCurrentContext(), FOpenGL::GetMaxCombinedTextureImageUnits() - 1, GL_TEXTURE_BUFFER, TextureID, -1, 1); FOpenGL::TexBuffer(GL_TEXTURE_BUFFER, GLFormat.InternalFormat[0], InVertexBuffer->Resource); // No need to restore texture stage; leave it like this, // and the next draw will take care of cleaning it up; or // next operation that needs the stage will switch something else in on it. this->Resource = TextureID; this->Format = GLFormat.InternalFormat[0]; }
void FOpenGLDynamicRHI::RHIEndDrawingViewport(FViewportRHIParamRef ViewportRHI,bool bPresent,bool bLockToVsync) { VERIFY_GL_SCOPE(); DYNAMIC_CAST_OPENGLRESOURCE(Viewport,Viewport); SCOPE_CYCLE_COUNTER(STAT_OpenGLPresentTime); check(DrawingViewport.GetReference() == Viewport); FOpenGLTexture2D* BackBuffer = Viewport->GetBackBuffer(); uint32 IdleStart = FPlatformTime::Cycles(); PlatformBlitToViewport(PlatformDevice, Viewport->OpenGLContext, BackBuffer->GetSizeX(), BackBuffer->GetSizeY(), bPresent, bLockToVsync, RHIOpenGLConsoleVariables::SyncInterval ); DrawingViewport = NULL; // Don't wait on the GPU when using SLI, let the driver determine how many frames behind the GPU should be allowed to get if (GNumActiveGPUsForRendering == 1) { static const auto CFinishFrameVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.FinishCurrentFrame")); if (!CFinishFrameVar->GetValueOnRenderThread()) { // Wait for the GPU to finish rendering the previous frame before finishing this frame. Viewport->WaitForFrameEventCompletion(); Viewport->IssueFrameEvent(); } else { // Finish current frame immediately to reduce latency Viewport->IssueFrameEvent(); Viewport->WaitForFrameEventCompletion(); } // If the input latency timer has been triggered, block until the GPU is completely // finished displaying this frame and calculate the delta time. if ( GInputLatencyTimer.RenderThreadTrigger ) { Viewport->WaitForFrameEventCompletion(); uint32 EndTime = FPlatformTime::Cycles(); GInputLatencyTimer.DeltaTime = EndTime - GInputLatencyTimer.StartTime; GInputLatencyTimer.RenderThreadTrigger = false; } } GRenderThreadIdle[ERenderThreadIdleTypes::WaitingForGPUPresent] += FPlatformTime::Cycles() - IdleStart; if (bRevertToSharedContextAfterDrawingViewport) { PlatformSharedContextSetup(PlatformDevice); bRevertToSharedContextAfterDrawingViewport = false; } }
void FOpenGLDynamicRHI::RHIUnlockIndexBuffer(FIndexBufferRHIParamRef IndexBufferRHI) { VERIFY_GL_SCOPE(); FOpenGLIndexBuffer* IndexBuffer = ResourceCast(IndexBufferRHI); IndexBuffer->Unlock(); }
void* FOpenGLDynamicRHI::RHILockIndexBuffer(FIndexBufferRHIParamRef IndexBufferRHI,uint32 Offset,uint32 Size,EResourceLockMode LockMode) { VERIFY_GL_SCOPE(); FOpenGLIndexBuffer* IndexBuffer = ResourceCast(IndexBufferRHI); return IndexBuffer->Lock(Offset, Size, LockMode == RLM_ReadOnly, IndexBuffer->IsDynamic()); }