diff options
author | Patrick Mours <pmours@nvidia.com> | 2022-04-20 14:40:48 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2022-04-29 20:19:39 +0300 |
commit | fc2c22e90c252f683a42574d4382f7e3c23940e1 (patch) | |
tree | 371a8b746554ec7fc5f4d6bf82ad68c972656821 /intern/cycles/hydra/display_driver.cpp | |
parent | 9b92ce9dc00971cd9f7f0d0ba6109a9cba2090bd (diff) |
Cycles: Hydra fixes for stageMetersPerUnit and OpenGL context on Windows
Add "stageMetersPerUnit" render setting for USD files that have that set to
something other than the default (e.g. exported by Blender).
And fix a crash when an application creates a Hydra render pass on a thread
that does not have an OpenGL context current.
Diffstat (limited to 'intern/cycles/hydra/display_driver.cpp')
-rw-r--r-- | intern/cycles/hydra/display_driver.cpp | 74 |
1 files changed, 49 insertions, 25 deletions
diff --git a/intern/cycles/hydra/display_driver.cpp b/intern/cycles/hydra/display_driver.cpp index 6f6ca35cd31..a809ace63e2 100644 --- a/intern/cycles/hydra/display_driver.cpp +++ b/intern/cycles/hydra/display_driver.cpp @@ -19,44 +19,66 @@ HDCYCLES_NAMESPACE_OPEN_SCOPE HdCyclesDisplayDriver::HdCyclesDisplayDriver(HdCyclesSession *renderParam, Hgi *hgi) : _renderParam(renderParam), _hgi(hgi) { +} + +HdCyclesDisplayDriver::~HdCyclesDisplayDriver() +{ + deinit(); +} + +void HdCyclesDisplayDriver::init() +{ #ifdef _WIN32 - hdc_ = GetDC(CreateWindowA("STATIC", - "HdCycles", - WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, - 0, - 0, - 64, - 64, - NULL, - NULL, - GetModuleHandle(NULL), - NULL)); - - int pixelFormat = GetPixelFormat(wglGetCurrentDC()); - PIXELFORMATDESCRIPTOR pfd = {sizeof(pfd)}; - DescribePixelFormat((HDC)hdc_, pixelFormat, sizeof(pfd), &pfd); - SetPixelFormat((HDC)hdc_, pixelFormat, &pfd); - - TF_VERIFY(gl_context_ = wglCreateContext((HDC)hdc_)); - TF_VERIFY(wglShareLists(wglGetCurrentContext(), (HGLRC)gl_context_)); + if (!gl_context_) { + hdc_ = GetDC(CreateWindowA("STATIC", + "HdCycles", + WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, + 0, + 0, + 64, + 64, + NULL, + NULL, + GetModuleHandle(NULL), + NULL)); + + int pixelFormat = GetPixelFormat(wglGetCurrentDC()); + PIXELFORMATDESCRIPTOR pfd = {sizeof(pfd)}; + DescribePixelFormat((HDC)hdc_, pixelFormat, sizeof(pfd), &pfd); + SetPixelFormat((HDC)hdc_, pixelFormat, &pfd); + + TF_VERIFY(gl_context_ = wglCreateContext((HDC)hdc_)); + TF_VERIFY(wglShareLists(wglGetCurrentContext(), (HGLRC)gl_context_)); + } + if (!gl_context_) { + return; + } #endif - glewInit(); + if (!gl_pbo_id_) { + if (glewInit() != GLEW_OK) { + return; + } - glGenBuffers(1, &gl_pbo_id_); + glGenBuffers(1, &gl_pbo_id_); + } } -HdCyclesDisplayDriver::~HdCyclesDisplayDriver() +void HdCyclesDisplayDriver::deinit() { if (texture_) { _hgi->DestroyTexture(&texture_); } - glDeleteBuffers(1, &gl_pbo_id_); + if (gl_pbo_id_) { + glDeleteBuffers(1, &gl_pbo_id_); + } #ifdef _WIN32 - TF_VERIFY(wglDeleteContext((HGLRC)gl_context_)); - DestroyWindow(WindowFromDC((HDC)hdc_)); + if (gl_context_) { + TF_VERIFY(wglDeleteContext((HGLRC)gl_context_)); + DestroyWindow(WindowFromDC((HDC)hdc_)); + } #endif } @@ -192,6 +214,8 @@ void HdCyclesDisplayDriver::draw(const Params ¶ms) return; } + init(); + // Cycles 'DisplayDriver' only supports 'half4' format TF_VERIFY(renderBuffer->GetFormat() == HdFormatFloat16Vec4); |